Exemplo n.º 1
0
    def testInteger(self):
        self.compare(mathics.Integer(0), sympy.Integer(0))
        self.compare(mathics.Integer(1), sympy.Integer(1))

        n = random.randint(-sys.maxsize, sys.maxsize)
        self.compare(mathics.Integer(n), sympy.Integer(n))

        n = random.randint(sys.maxsize, sys.maxsize * sys.maxsize)
        self.compare(mathics.Integer(n), sympy.Integer(n))
Exemplo n.º 2
0
    def testComplex(self):
        self.compare(
            mathics.Complex(mathics.Real('1.0'), mathics.Real('1.0')),
            sympy.Add(sympy.Float('1.0'),
                      sympy.Float('1.0') * sympy.I))

        self.compare(mathics.Complex(mathics.Integer(0), mathics.Integer(1)),
                     sympy.I)

        self.compare(mathics.Complex(mathics.Integer(-1), mathics.Integer(1)),
                     sympy.Integer(-1) + sympy.I)
Exemplo n.º 3
0
    def testComplex(self):
        self.compare(
            mathics.Complex(mathics.Real("1.0"), mathics.Real("1.0")),
            sympy.Add(sympy.Float("1.0"), sympy.Float("1.0") * sympy.I),
        )

        self.compare(mathics.Complex(mathics.Integer(0), mathics.Integer(1)), sympy.I)

        self.compare(
            mathics.Complex(mathics.Integer(-1), mathics.Integer(1)),
            sympy.Integer(-1) + sympy.I,
        )
Exemplo n.º 4
0
 def testAdd(self):
     self.compare(
         mathics.Expression(
             'Plus', mathics.Integer(1), mathics.Symbol('Global`x')),
         sympy.Add(
             sympy.Integer(1),
             sympy.Symbol('_Mathics_User_Global`x')))
Exemplo n.º 5
0
    def testDerivative2(self):
        kwargs = {'converted_functions': set(['Global`f'])}

        head = mathics.Expression(
            mathics.Expression('System`Derivative', mathics.Integer(1),
                               mathics.Integer(0)), mathics.Symbol('Global`f'))
        expr = mathics.Expression(head, mathics.Symbol('Global`x'),
                                  mathics.Symbol('Global`y'))

        sfxy = sympy.Function(str('_Mathics_User_Global`f'))(
            sympy.Symbol('_Mathics_User_Global`x'),
            sympy.Symbol('_Mathics_User_Global`y'))
        sym_expr = sympy.Derivative(sfxy,
                                    sympy.Symbol('_Mathics_User_Global`x'))

        self.compare_to_sympy(expr, sym_expr, **kwargs)
Exemplo n.º 6
0
    def testDerivative2(self):
        kwargs = {"converted_functions": set(["Global`f"])}

        head = mathics.Expression(
            mathics.Expression(
                "System`Derivative", mathics.Integer(1), mathics.Integer(0)
            ),
            mathics.Symbol("Global`f"),
        )
        expr = mathics.Expression(
            head, mathics.Symbol("Global`x"), mathics.Symbol("Global`y")
        )

        sfxy = sympy.Function(str("_Mathics_User_Global`f"))(
            sympy.Symbol("_Mathics_User_Global`x"),
            sympy.Symbol("_Mathics_User_Global`y"),
        )
        sym_expr = sympy.Derivative(sfxy, sympy.Symbol("_Mathics_User_Global`x"))

        self.compare_to_sympy(expr, sym_expr, **kwargs)
Exemplo n.º 7
0
    def testComplex(self):
        self.compare(mathics.Complex(mathics.Integer(1), mathics.Integer(1)), 1 + 1j)
        self.compare(
            mathics.Complex(mathics.MachineReal(1.0), mathics.MachineReal(1.0)),
            1.0 + 1.0j,
        )
        self.compare(
            mathics.Complex(mathics.Integer(1), mathics.MachineReal(1.0)), 1 + 1.0j
        )
        self.compare(
            mathics.Complex(mathics.MachineReal(1.0), mathics.Integer(1)), 1.0 + 1j
        )
        self.compare(
            mathics.Complex(mathics.Real("1.0", 5), mathics.Integer(1)), 1.0 + 1j
        )
        self.compare(
            mathics.Complex(mathics.Integer(1), mathics.Real("1.0", 20)), 1 + 1.0j
        )

        self.compare(mathics.Complex(mathics.Integer(0), mathics.Integer(1)), 1j)
        self.compare(mathics.Complex(mathics.Integer(1), mathics.Integer(0)), 1)
Exemplo n.º 8
0
 def testInteger(self):
     self.compare(mathics.Integer(1), 1)
Exemplo n.º 9
0
 def testList(self):
     self.compare(mathics.Expression('List', mathics.Integer(1)), [1])
Exemplo n.º 10
0
 def testAdd(self):
     self.compare(
         mathics.Expression("Plus", mathics.Integer(1), mathics.Symbol("Global`x")),
         sympy.Add(sympy.Integer(1), sympy.Symbol("_Mathics_User_Global`x")),
     )