コード例 #1
0
ファイル: test_integers.py プロジェクト: pawlaczyk/cypari2
    def cmp(self, a, b):
        pari = cypari2.Pari()
        pa = pari(a)
        pb = pari(b)

        self.assertTrue(pa == pa and a == pa and pa == a)
        self.assertEqual(a == b, pa == pb)
        self.assertEqual(a != b, pa != pb)
        self.assertEqual(a < b, pa < pb)
        self.assertEqual(a <= b, pa <= pb)
        self.assertEqual(a > b, pa > pb)
        self.assertEqual(a >= b, pa >= pb)
コード例 #2
0
ファイル: test_integers.py プロジェクト: pawlaczyk/cypari2
    def test_binop(self):
        pari = cypari2.Pari()

        for _ in range(100):
            a = self.randint()
            b = self.randint()

            self.assertEqual(a + b, pari(a) + pari(b))
            self.assertEqual(a - b, pari(a) - pari(b))
            self.assertEqual(a * b, pari(a) * pari(b))

            if b > 0:
                self.assertEqual(a % b, pari(a) % pari(b))
コード例 #3
0
ファイル: bound.py プロジェクト: RheaDutta/pMatrix-Code
            -> The element is simplified this way - (numerator//denominator)//n

calculate_bound() originally written by Kimia Tajik in Pari/GP.
Script written and implemented by Rhea Dutta in Python.

07/26/2018
"""
#______________________________________________________________________________________________#

#Scripts that generate the P-Matrix and the reduced P-Matrix. Use either one.
import generate_matrix as M  #Sequentially computed.
#import pMatrix_main_mp as M #Uses multiprocessing.

#Importing Pari to perform computations to guarantee greatest possible accuracy.
import cypari2 as CP
pari = CP.Pari()  #Pari object.

import math

#______________________________________________________________________________________________#


def calculate_bound(matrix, is_p_matrix, super_states=None):
    """

    RETURNS: The bound on mixing time for the given matrix.

    PARAMETERS: matrix: The matrix for which the bound on the mixing time must be calculated.
                        (The input is the output of the generate_matrix / pMatrix_main_mp script)
                is_p_matrix [bool]: True if given matrix is a P-Matrix, False otherwise.
                super_states [3D list]: List of super states (each super state is a list of
コード例 #4
0
ファイル: test_backward.py プロジェクト: pawlaczyk/cypari2
 def test_poldegree(self):
     pari = cypari2.Pari()
     self.assertEqual(pari('x + 1').poldegree(), 1)
     self.assertEqual(pari('x*y^2 + 1').poldegree(pari('x')), 1)
     self.assertEqual(pari('x*y^2 + 1').poldegree(pari('y')), 2)
コード例 #5
0
ファイル: test_backward.py プロジェクト: pawlaczyk/cypari2
 def test_sqrtint(self):
     pari = cypari2.Pari()
     self.assertEqual(pari(10).sqrtint(), 3)
コード例 #6
0
ファイル: test_backward.py プロジェクト: pawlaczyk/cypari2
 def test_polisirreducible(self):
     pari = cypari2.Pari()
     p = pari('x^2 + 1')
     self.assertTrue(p.polisirreducible())
コード例 #7
0
ファイル: rundoctest.py プロジェクト: vochong/cypari2
sys.path.append(path)
import autogen
import cypari2
import doctest

# The doctests assume utf-8 encoding
cypari2.string_utils.encoding = "utf-8"

# For doctests, we want exceptions to look the same,
# regardless of the Python version. Python 3 will put the
# module name in the traceback, which we avoid by faking
# the module to be __main__.
cypari2.handle_error.PariError.__module__ = "__main__"

# Disable stack size warning messages
pari = cypari2.Pari()
pari.default("debugmem", 0)

failed = 0
attempted = 0
for mod in [
        cypari2.closure, cypari2.convert, cypari2.gen, cypari2.handle_error,
        cypari2.pari_instance, cypari2.stack, cypari2.string_utils,
        autogen.doc, autogen.generator, autogen.parser, autogen.paths
]:

    print("=" * 80)
    print("Testing {}".format(mod.__name__))
    test = doctest.testmod(mod,
                           optionflags=doctest.ELLIPSIS | doctest.REPORT_NDIFF,
                           verbose=False)
コード例 #8
0
ファイル: test_integers.py プロジェクト: pawlaczyk/cypari2
 def test_zero_division(self):
     pari = cypari2.Pari()
     with self.assertRaises(cypari2.PariError):
         pari(2) / pari(0)