diff options
Diffstat (limited to 'macros/luatex/latex/luacas/tex/test/polynomials/roots.lua')
-rw-r--r-- | macros/luatex/latex/luacas/tex/test/polynomials/roots.lua | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/macros/luatex/latex/luacas/tex/test/polynomials/roots.lua b/macros/luatex/latex/luacas/tex/test/polynomials/roots.lua new file mode 100644 index 0000000000..01975ab1ec --- /dev/null +++ b/macros/luatex/latex/luacas/tex/test/polynomials/roots.lua @@ -0,0 +1,43 @@ +local a = PolynomialRing({Integer(1), Integer(2), Integer(3), Integer(4), Integer(5)}, "x") +local b = PolynomialRing({Integer(1) / Integer(3), Integer(1) / Integer(12), Integer(6) / Integer(3)}, "x") +local c = PolynomialRing({Integer(12), Integer(4)}, "x") +local d = PolynomialRing({Integer(21), Integer(10), Integer(1)}, "x") +local e = PolynomialRing({Integer(-6), Integer(1), Integer(1)}, "x") +local f = PolynomialRing({Integer(-1), Integer(-2), Integer(15), Integer(36)}, "x") +local g = PolynomialRing({Integer(1), Integer(7), Integer(15), Integer(9)}, "x") +local h = PolynomialRing({Integer(2), Integer(3), Integer(1)}, "x") +local i = PolynomialRing({Integer(8), Integer(20), Integer(18), Integer(7), Integer(1)}, "x") +local j = PolynomialRing({Integer(108), Integer(324), Integer(387), Integer(238), Integer(80), Integer(14), Integer(1)}, "x") +local k = PolynomialRing({Integer(30), Integer(11), Integer(1)}, "x") +local l = PolynomialRing({Integer(6), Integer(11), Integer(6), Integer(1)}, "z") +local m = PolynomialRing({Integer(1), Integer(10), Integer(45), Integer(120), Integer(210), Integer(252), Integer(210), Integer(120), Integer(45), Integer(10), Integer(1)}, "x") +local n = PolynomialRing({Integer(24), Integer(50), Integer(35), Integer(10), Integer(1), Integer(0), Integer(24), Integer(50), Integer(35), Integer(10), Integer(1)}, "x") +local o = PolynomialRing({Integer(24), Integer(50), Integer(59), Integer(60), Integer(36), Integer(10), Integer(1)}, "x") +local p = PolynomialRing({Integer(-110592), Integer(59904), Integer(-5760), Integer(720), Integer(-48), Integer(1)}, "x") +local q = PolynomialRing({Integer(3), Integer(-9), Integer(27), Integer(-36), Integer(36)}, "z") +local r = PolynomialRing({Integer(0), Integer(0), Integer(0), Integer(0), Integer(0), Integer(0), Integer(4)}, "x") +local s = PolynomialRing({Integer(1), Integer(0), Integer(-4), Integer(0), Integer(1)}, "x") +local t = PolynomialRing({Integer(1), Integer(-1), Integer(1), Integer(1)}, "t") + +starttest("polynomial root-finding") +testeq(a:roots(), "{Root Of: (5x^4+4x^3+3x^2+2x^1+1x^0)}", a, true) +testeq(b:roots(), "{-1/48 + (-1/48 * (383 ^ (1/2)) * i), -1/48 + (1/48 * (383 ^ (1/2)) * i)}", b, true) +testeq(c:roots(), "{-3}", c, true) +testeq(d:roots(), "{-7, -3}", d, true) +testeq(e:roots(), "{-3, 2}", e, true) +testeq(f:roots(), "{-1/3, 1/4}", f, true) +testeq(g:roots(), "{-1, -1/3}", g, true) +testeq(h:roots(), "{-2, -1}", h, true) +testeq(i:roots(), "{-2, -1}", i, true) +testeq(j:roots(), "{-3, -2, -1}", j, true) +testeq(k:roots(), "{-6, -5}", k, true) +testeq(l:roots(), "{-3, -2, -1}", l, true) +testeq(m:roots(), "{-1}", m, true) +testeq(n:roots(), "{-4, -3, -2, -1, i, -1 * i, -1/2 * ((2 + (-2 * (3 ^ (1/2)) * i)) ^ (1/2)), 1/2 * ((2 + (-2 * (3 ^ (1/2)) * i)) ^ (1/2)), -1/2 * ((2 + (2 * (3 ^ (1/2)) * i)) ^ (1/2)), 1/2 * ((2 + (2 * (3 ^ (1/2)) * i)) ^ (1/2))}", n, true) +testeq(o:roots(), "{-4, -3, -2, -1, i, -1 * i}", o, true) +testeq(p:roots(), "{24, 12 + (-4 * (6 ^ (1/2))), 12 + (4 * (6 ^ (1/2))), -4 * (6 ^ (1/2)) * i, 4 * (6 ^ (1/2)) * i}", p, true) +testeq(q:roots(), "{1/4 + (-1/2 * ((-3/4 + (-1/3 * (3 ^ (1/2)) * i)) ^ (1/2))), 1/4 + (1/2 * ((-3/4 + (-1/3 * (3 ^ (1/2)) * i)) ^ (1/2))), 1/4 + (-1/2 * ((-3/4 + (1/3 * (3 ^ (1/2)) * i)) ^ (1/2))), 1/4 + (1/2 * ((-3/4 + (1/3 * (3 ^ (1/2)) * i)) ^ (1/2)))}", q, true) +testeq(r:roots(), "{0}", r, true) +testeq(s:roots(), "{-1/2 * ((8 + (-4 * (3 ^ (1/2)))) ^ (1/2)), 1/2 * ((8 + (-4 * (3 ^ (1/2)))) ^ (1/2)), -1/2 * ((8 + (4 * (3 ^ (1/2)))) ^ (1/2)), 1/2 * ((8 + (4 * (3 ^ (1/2)))) ^ (1/2))}", s, true) +testeq(t:roots(), "{-1/3 + (-4/3 * ((19 + (3 * (33 ^ (1/2)))) ^ (-1/3))) + (-1/3 * ((19 + (3 * (33 ^ (1/2)))) ^ (1/3))), -1/3 + (-4/3 * ((19 + (3 * (33 ^ (1/2)))) ^ (-1/3)) * ((-1/2 + (1/2 * (3 ^ (1/2)) * i)) ^ -1)) + (-1/3 * ((19 + (3 * (33 ^ (1/2)))) ^ (1/3)) * (-1/2 + (1/2 * (3 ^ (1/2)) * i))), -1/3 + (-4/3 * ((19 + (3 * (33 ^ (1/2)))) ^ (-1/3)) * ((-1/2 + (1/2 * (3 ^ (1/2)) * i)) ^ -2)) + (-1/3 * ((19 + (3 * (33 ^ (1/2)))) ^ (1/3)) * ((-1/2 + (1/2 * (3 ^ (1/2)) * i)) ^ 2))}", t, true) +endtest()
\ No newline at end of file |