"Testing 1st"

check(abs(-1.0) == 1.0)
check(adj(((a,b),(c,d))) == ((d,-b),(-c,a)))
check(adj(((a11,a12,a13),(a21,a22,a23),(a31,a32,a33))) == ((a22 a33 - a23 a32,-a12 a33 + a13 a32,a12 a23 - a13 a22),(-a21 a33 + a23 a31,a11 a33 - a13 a31,-a11 a23 + a13 a21),(a21 a32 - a22 a31,-a11 a32 + a12 a31,a11 a22 - a12 a21)))
check(and(1,2) == 1)
check(arccos(1.0) == 0.0)
check(arccosh(1.0) == 0.0)
check(arcsin(0.0) == 0.0)
check(arcsinh(0.0) == 0.0)
check(arctan(0.0) == 0.0)
check(arctanh(0.0) == 0.0)
check(arg(0.0) == 0.0)
check(ceiling(1.2) == 2)
check(circexp(sin(x)) == -1/2 i exp(i x) + 1/2 i exp(-i x))
check(prefixform(clock(1-i)) == "(* (^ 2 1/2) (^ -1 -1/4))")
check(conj(1 - i) == 1 + i)
check(contract(((a,b),(c,d))) == a + d)
check(cos(0.0) == 1.0)
check(cosh(0.0) == 1.0)
check(defint(x,x,1,2) == 3/2)
check(denominator(a/b) == b)
check(derivative(x,x) == 1)
check(det(((a,b),(c,d))) == a d - b c)
check(do(a,b,c) == c)
check(dot((a,b),(c,d)) == a c + b d)
check(eval(2 x,x,3) == 6)
check(exp(0.0) == 1.0)
check(expcos(x) == 1/2 exp(i x) + 1/2 exp(-i x))
check(expcosh(x) == 1/2 exp(-x) + 1/2 exp(x))
check(expsin(x) == -1/2 i exp(i x) + 1/2 i exp(-i x))
check(expsinh(x) == -1/2 exp(-x) + 1/2 exp(x))
check(exptan(x) == i / (exp(2 i x) + 1) - i exp(2 i x) / (exp(2 i x) + 1))
check(exptanh(x) == -1 / (exp(2 x) + 1) + exp(2 x) / (exp(2 x) + 1))
check(factorial(6) == 720)
check(prefixform(float(1/2)) == "0.5")
check(floor(3/2) == 1)
check(for(k,1,3,k) == nil)
check(imag(2 - 3 i) == -3)
check(inner((a,b),(c,d)) == a c + b d)
check(integral(x,x) == 1/2 x^2)
check(inv(((a,b),(c,d))) == ((d / (a d - b c),-b / (a d - b c)),(-c / (a d - b c),a / (a d - b c))))
check(log(1.0) == 0.0)
check(mag(2 - 3 i) == 13^(1/2))
check(not(0) == 1)
check(number(1) == 1)
check(numerator(a/b) == a)
check(or(0,0) == 0)
check(outer((a,b),(c,d)) == ((a c,a d),(b c,b d)))
check(prefixform(polar(2 - 3 i)) == "(* (^ 13 1/2) (^ $e (* -1 (^ -1 1/2) (arctan 3 2))))")
check(product(k,1,4,k) == 24)
check(prefixform(quote(1 + 2)) == "(+ 1 2)")
check(rank(outer((1,2),(3,4),(5,6))) == 3)
check(prefixform(rationalize(1/a + 1/b)) == "(* (^ a -1) (^ b -1) (+ a b))")
check(real(2 - 3 i) == 2)
check(rect((-1)^(1/8)) == cos(1/8 pi) + i sin(1/8 pi))
check(sin(0) == 0)
check(sinh(0) == 0)
check(prefixform(sqrt(2)) == "(^ 2 1/2)")
check(sum(k,1,4,k) == 10)
check(tan(0) == 0)
check(tanh(0) == 0)
check(test(a == b,1,0) == 0)
check(transpose(((a,b),(c,d))) == ((a,c),(b,d)))
check(unit(2) == ((1,0),(0,1)))
check(zero(2,3) == ((0,0,0),(0,0,0)))

check(prefixform(a-b)="(+ a (* -1 b))")
check(prefixform(b-a)="(+ (* -1 a) b)")

-- test parser

T =
+
1
check(T=1)

T =
-
1
check(T=-1)

T =
1 +
2
check(T=3)

T =
2 *
3
check(T=6)

T =
(
1
+
2
)
check(T=3)

T =
a[
1
]
check(T=a[1])

T =
a[
1
,
2
]
check(T=a[1,2])

T =
f(
1
)
check(T=f(1))

T = f(
1
,
2
)
check(T=f(1,2))

-- test sort order

T = 3+4*i
check(infixform(T)="3 + 4 i")
T = x^2*y
check(infixform(T)="x^2 y")
T = y*x^2
check(infixform(T)="x^2 y")
T = x*y^2
check(infixform(T)="x y^2")
T = y^2*x
check(infixform(T)="x y^2")
T = (x+1)^2
check(infixform(T)="x^2 + 2 x + 1")
T = (a+b)^2
check(infixform(T)="a^2 + 2 a b + b^2")
T = (a+b)^3
check(infixform(T)="a^3 + 3 a^2 b + 3 a b^2 + b^3")
T = x*cos(x)
check(infixform(T)="x cos(x)")
T = cos(x)*x
check(infixform(T)="x cos(x)")

-- term sort ignores coeff

check(prefixform(a-b)="(+ a (* -1 b))")
check(prefixform(b-a)="(+ (* -1 a) b)")

-- test addition

A=((0,0),(0,0))
B=((0,0),(0,0))
T = A+B
check(infixform(T)="((0,0),(0,0))")

A=2
B=3
check(A-B=-1)
check(B-A=1)
A=-2
B=3
check(A-B=-5)
check(B-A=5)
A=2
B=-3
check(A-B=5)
check(B-A=-5)
A=-2
B=-3
check(A-B=1)
check(B-A=-1)
A=quote(A)
B=quote(B)

-- test multiplication

N = 2*3^100
M = N/sqrt(2)
check(M^2=N^2/2)
check(infixform(M) = "515377520732011331036461129765621272702107522001 2^(1/2)")
M = sqrt(2)/N
check(M^2=2/N^2)
check(infixform(M) = "1 / (515377520732011331036461129765621272702107522001 2^(1/2))")
M = N/2^(2/3)
check(M^3=N^3/4)
check(infixform(M) = "515377520732011331036461129765621272702107522001 2^(1/3)")
M = 2^(2/3)/N
check(M^3=4/N^3)
check(infixform(M) = "1 / (515377520732011331036461129765621272702107522001 2^(1/3))")

N = -2^10 * 3^10 / 5^10 / 7^10 * x * y
M = 2^(2/3) * 3^(2/3) / 5^(2/3) / 7^(2/3)
check(N/M = -2^(10-2/3) * 3^(10-2/3) / 5^(10-2/3) / 7^(10-2/3) * x * y)
check(N*M = -2^(10+2/3) * 3^(10+2/3) / 5^(10+2/3) / 7^(10+2/3) * x * y)

A = 1.0 * sqrt(2) * sqrt(3) * x * y
B = sqrt(2.0) * sqrt(3.0) * x * y
check(infixform(A) = "2.44949 x y")
check(infixform(B) = "2.44949 x y")

-- test power function

clear

T = 0^a
check(infixform(T)="0^a")

T = 2^(3/2)
check(infixform(T)="2 2^(1/2)")

T = 858/sqrt(2)
check(infixform(T)="429 2^(1/2)")

T = (-3)^(3/2)
check(infixform(T)="-3 3^(1/2) i")

T = (10^10)^(4/3)
check(infixform(T)="10000000000 10000000000^(1/3)")

check(exp(i*pi)=-1)
check(prefixform(exp(i*pi+a))="(* -1 (^ $e a))")

T = 6*sqrt(2)*sqrt(3)
check(infixform(T)="6 2^(1/2) 3^(1/2)")

T = (a+b)*(a+b)
check(infixform(T)="a^2 + 2 a b + b^2")

T = (a+b)*(a+b)*(a+b)
check(infixform(T)="a^3 + 3 a^2 b + 3 a b^2 + b^3")

T = 1/(a+b)^2
check(infixform(T)="1 / (a + b)^2")

T = (a+b*i)/(c+d*i)
check(infixform(T)="a / (c + i d) + i b / (c + i d)")

T = ((2+3*i)^2)^(-1)
check(infixform(T)="-5/169 - 12/169 i")

T = ((2+3*i)^(-1))^2
check(infixform(T)="-5/169 - 12/169 i")

T = s^(-8*pi*i)
check(infixform(T)="s^(-8 i pi)")

T = exp(-8*pi*i)
check(T=1)

N = 102/2^64
M = sqrt(N)
T = N - M^2
check(T=0)

N = 2^64/102
M = sqrt(N)
T = N - M^2
check(T=0)

-- set component

clear
I = ((1,1,1,1),(1,1,1,1))
A = (I,I,I)
A[1] = a I
A[2] = b I
A[3] = c I
check(A == (((a,a,a,a),(a,a,a,a)),((b,b,b,b),(b,b,b,b)),((c,c,c,c),(c,c,c,c))))

-- setq

clear
check(infixform(A) == "A")
check(infixform(binding(A)) == "A")

A = nil
check(infixform(A) == "A")
check(infixform(binding(A)) == "A")

A = quote(A)
check(infixform(A) == "A")
check(infixform(binding(A)) == "A")

A = A
check(infixform(A) == "A")
check(infixform(binding(A)) == "A")
