getType command
The XCas getType() command is not synonymous with type or TYPE cmds, the important thing about this command that is not included in the hpprime
is that it groups several types of objects by common characteristics, for example
getType(5.0 ), getType( 5 ), getType( 3/4 ) [enter] "NUM", "NUM", "NUM"
Mathematical expressions as"EXPR" and math constants
getType( 3+4*i ), getType( x+i*y ), getType( 3*pi ), getType( sqrt(-1) ) , getType( e ) [enter]"EXPR", "EXPR", "EXPR", "EXPR", "EXPR"
Lists, sequences, sets and polynomials as “LIST"
seq1:=(1,2,3)
getType( seq1), getType( [9,[8,7],[6,5,4]]), getType( [9 ,8 ,7] ), getType( set[a , b, c, a] ), getType( poly1[1 ,-6 , 11 ,-6] ) [enter] "LIST", "LIST","LIST","LIST","LIST"
Difference matrix of lists
getType( [[1,2],[3,4]] ), getType( [[1,2,3,4]], getType( [[1],[2],[3],[4]] ) [enter] "MAT", "MAT", "MAT"
getType( var01 ) [enter] "VAR"
getType( "Hello" ) [enter] "STR"
getType( f(x):=x+1) [enter] "FUNC"
getType(5.0 ), getType( 5 ), getType( 3+4*i ), getType( x+i*y ), getType( [9,[8,7],[6,5,4]]), getType( [9 ,8 ,7] ), getType( set[a , b, c, a] ), getType( poly1[1 ,-6 , 11 ,-6] ), getType( [[1,2],[3,4]] ), getType( var01 ), getType( "Hello" ), getType( f(x):=x+1)
"NUM","NUM","EXPR","EXPR","LIST","LIST","LIST","LIST","MAT","VAR","STR","FUNC"
Example of use of the getType function.
PHP Code:
#Xcas
def legendre_( n, evalX="" ):
local px, x, type2arg; purge(x)
if getType(n) == "NUM":
px := 1/(2^n*n!)*diff((x^2-1)^n,x,n)
type2arg := getType(evalX)
if type2arg == "NUM" or type2arg == "EXPR" or type2arg == "VAR":
px := subst(px,x=evalX)
elif type2arg == "STR" and evalX=="LIST":
px:=e2r(px)
return px
return "Error: an integer number is expected in the first argument"
#end
legendre_(2),legendre_(2,y),legendre_(2,"LIST"),legendre_(2,10),legendre_(2,cos(t)) enter
1/8*(12*x^2-4), 1/8*(12*y^2-4), poly1[3/2,0,-1/2],2 99/2, 1/8*(12*cos(t)**2-4)