|
| 1 | +#!/usr/bin/env python |
| 2 | +#***************************************************************************** |
| 3 | +# Copyright (C) 2020 Vincent Delecroix <vincent.delecroix@labri.fr> |
| 4 | +# |
| 5 | +# Distributed under the terms of the GNU General Public License (GPL) |
| 6 | +# as published by the Free Software Foundation; either version 2 of |
| 7 | +# the License, or (at your option) any later version. |
| 8 | +# http://www.gnu.org/licenses/ |
| 9 | +#***************************************************************************** |
| 10 | + |
| 11 | +import cypari2 |
| 12 | +import unittest |
| 13 | + |
| 14 | +class TestBackward(unittest.TestCase): |
| 15 | + def test_polisirreducible(self): |
| 16 | + pari = cypari2.Pari() |
| 17 | + p = pari('x^2 + 1') |
| 18 | + self.assertTrue(p.polisirreducible()) |
| 19 | + |
| 20 | + def test_sqrtint(self): |
| 21 | + pari = cypari2.Pari() |
| 22 | + self.assertEqual(pari(10).sqrtint(), 3) |
| 23 | + |
| 24 | + def test_poldegree(self): |
| 25 | + pari = cypari2.Pari() |
| 26 | + self.assertEqual(pari('x + 1').poldegree(), 1) |
| 27 | + self.assertEqual(pari('x*y^2 + 1').poldegree(pari('x')), 1) |
| 28 | + self.assertEqual(pari('x*y^2 + 1').poldegree(pari('y')), 2) |
| 29 | + |
| 30 | + def test_nfbasis(self): |
| 31 | + pari = cypari2.Pari() |
| 32 | + x = pari('x') |
| 33 | + third = pari('1/3') |
| 34 | + self.assertEqual(pari(x**3 - 17).nfbasis(), [1, x, third*x**2 - third*x + third]) |
| 35 | + |
| 36 | + p = pari(10**10).nextprime() |
| 37 | + q = (p+1).nextprime() |
| 38 | + x = pari('x') |
| 39 | + f = x**2 + p**2*q |
| 40 | + # Correct result |
| 41 | + frac = pari('1/10000000019') |
| 42 | + self.assertEqual(pari(f).nfbasis(), [1, frac*x]) |
| 43 | + |
| 44 | + # Wrong result |
| 45 | + self.assertEqual(pari.nfbasis([f,1]), [1, x]) |
| 46 | + # Check primes up to 10^6: wrong result |
| 47 | + self.assertEqual(pari.nfbasis([f, 10**6]), [1, x]) |
| 48 | + # Correct result and faster |
| 49 | + self.assertEqual(pari.nfbasis([f, pari("[2,2; %s,2]"%p)]), [1, frac*x]) |
| 50 | + # Equivalent with the above |
| 51 | + self.assertEqual(pari.nfbasis([f, [2,p]]), [1, frac*x]) |
| 52 | + |
| 53 | +if __name__ == '__main__': |
| 54 | + unittest.main() |
0 commit comments