Пример #1
0
 def test_read_complex_exponent(self):
     ast = self.parse('x^{2y + 3}')
     self.assertEqual(
         ast,
         Exponentiation(
             Variable('x'),
             Addition(Multiplication(Constant('2'), Variable('y')),
                      Constant('3'))))
Пример #2
0
    def test_read_mixed(self):
        ast = self.parse('3x')
        self.assertEqual(ast, Multiplication(Constant('3'), Variable('x')))

        ast = self.parse('3xy')
        self.assertEqual(
            ast,
            Multiplication(Multiplication(Constant('3'), Variable('x')),
                           Variable('y')))
Пример #3
0
    def test_read_priority_of_operations(self):
        ast = self.parse('4a^2')

        self.assertEqual(
            ast,
            Multiplication(Constant('4'),
                           Exponentiation(Variable('a'), Constant('2'))))
Пример #4
0
 def test_read_atom_without_times(self):
     ast = self.parse(r'3! (2 + 1) 4^n')
     self.assertEqual(
         ast,
         Multiplication(
             Multiplication(Function(Func.FACTORIAL, Constant('3')),
                            Addition(Constant('2'), Constant('1'))),
             Exponentiation(Constant('4'), Variable('n'))))
Пример #5
0
 def test_read_sqrt(self):
     ast = self.parse('\\sqrt{2x + 3}')
     self.assertEqual(
         ast,
         Function(
             Func.SQRT,
             Addition(Multiplication(Constant('2'), Variable('x')),
                      Constant('3'))))
Пример #6
0
 def test_read_alternative_sin(self):
     ast = self.parse('sin(2x + 3)')
     self.assertEqual(
         ast,
         Function(
             Func.SIN,
             Addition(Multiplication(Constant('2'), Variable('x')),
                      Constant('3'))))
Пример #7
0
    def test_read_factorial(self):
        ast = self.parse('x!')
        self.assertEqual(ast, Function(Func.FACTORIAL, Variable('x')))

        ast = self.parse('3!')
        self.assertEqual(ast, Function(Func.FACTORIAL, Constant('3')))

        ast = self.parse('(2 * x)!')
        self.assertEqual(
            ast,
            Function(Func.FACTORIAL,
                     Multiplication(Constant('2'), Variable('x'))))

        ast = self.parse('4 * x!')
        self.assertEqual(
            ast,
            Multiplication(Constant('4'),
                           Function(Func.FACTORIAL, Variable('x'))))
Пример #8
0
 def test_read_priority_of_operations_two(self):
     ast = self.parse(r'\frac{1}{1 - 2^{1-s}}')
     one = Constant('1')
     self.assertEqual(
         ast,
         Division(
             one,
             Subtraction(
                 one,
                 Exponentiation(Constant('2'),
                                Subtraction(one, Variable('s'))))))
Пример #9
0
    def test_read_elliptic_curve(self):
        ast = self.parse('sn(u, m)')
        self.assertEqual(ast, Function(Func.ESIN, Variable('u'),
                                       Variable('m')))

        ast = self.parse('cn(u, m)')
        self.assertEqual(ast, Function(Func.ECOS, Variable('u'),
                                       Variable('m')))

        ast = self.parse('dn(u, m)')
        self.assertEqual(
            ast, Function(Func.EDELTAAMPLITUDE, Variable('u'), Variable('m')))
Пример #10
0
    def test_read_addition_of_variables(self):
        ast = self.parse('x + y')
        self.assertEqual(ast, Addition(Variable('x'), Variable('y')))

        ast = self.parse('x+y')
        self.assertEqual(ast, Addition(Variable('x'), Variable('y')))
Пример #11
0
 def test_read_zeta(self):
     ast = self.parse(r'\zeta(x)')
     self.assertEqual(ast, Function(Func.ZETA, Variable('x')))
Пример #12
0
 def test_read_n_choose_k(self):
     ast = self.parse(r'\binom{x}{y}')
     self.assertEqual(ast,
                      Function(Func.BINOMIAL, Variable('x'), Variable('y')))
Пример #13
0
 def test_read_frac_of_variables(self):
     ast = self.parse('\\frac{x}{y}')
     self.assertEqual(ast, Division(Variable('x'), Variable('y')))
Пример #14
0
 def test_read_variable(self):
     ast = self.parse('xyz')
     self.assertEqual(ast, Multiplication(Multiplication(Variable('x'), Variable('y')), Variable('z')))
Пример #15
0
 def test_read_subtraction_of_negate_variable(self):
     ast = self.parse('x - -y')
     self.assertEqual(ast, Subtraction(Variable('x'), Negate(Variable('y'))))
Пример #16
0
 def test_read_neville_theta_function(self):
     ast = self.parse(r'\theta_{c}(z, m)')
     self.assertEqual(ast,
                      Function(r'\theta_{c}', Variable('z'), Variable('m')))
Пример #17
0
 def test_read_mixed_without_times_frac(self):
     ast = self.parse(r'\frac{1}{4} \frac{x}{2}')
     self.assertEqual(
         ast,
         Multiplication(Division(Constant('1'), Constant('4')),
                        Division(Variable('x'), Constant('2'))))
Пример #18
0
 def test_read_variable_multiplication_without_times(self):
     ast = self.parse(r'x y')
     self.assertEqual(ast, Multiplication(Variable('x'), Variable('y')))
Пример #19
0
 def test_derivative_like(self):
     ast = self.parse('dx')
     self.assertEqual(ast, Multiplication(Variable('d'), Variable('x')))
Пример #20
0
 def test_read_multiplication_of_variables(self):
     ast = self.parse('x * y')
     self.assertEqual(ast, Multiplication(Variable('x'), Variable('y')))
Пример #21
0
 def test_read_addition_of_constant_and_variable(self):
     ast = self.parse('n+1')
     self.assertEqual(ast, Addition(Variable('n'), Constant('1')))
Пример #22
0
 def test_read_subtraction_of_variables(self):
     ast = self.parse('x - y')
     self.assertEqual(ast, Subtraction(Variable('x'), Variable('y')))
Пример #23
0
 def test_read_special_variable(self):
     ast = self.parse('\pi')
     self.assertEqual(ast, Variable('\pi'))
Пример #24
0
 def test_read_substraction_of_constant_and_variable(self):
     ast = self.parse('n-1')
     self.assertEqual(ast, Subtraction(Variable('n'), Constant('1')))
Пример #25
0
 def test_read_absolute(self):
     ast = self.parse('|x + 3|')
     self.assertEqual(
         ast, Function(Func.ABS, Addition(Variable('x'), Constant('3'))))
Пример #26
0
 def test_read_integer_division(self):
     ast = self.parse('n|m')
     self.assertEqual(
         ast, Function(Func.EXACTDIVISION, Variable('n'), Variable('m')))
Пример #27
0
 def test_read_division_of_variables(self):
     ast = self.parse('x / y')
     self.assertEqual(ast, Division(Variable('x'), Variable('y')))
Пример #28
0
 def test_read_normal_exponent(self):
     ast = self.parse('x^{2}')
     self.assertEqual(ast, Exponentiation(Variable('x'), Constant('2')))
Пример #29
0
 def test_read_negative_variable(self):
     ast = self.parse('-x')
     self.assertEqual(ast, Negate(Variable('x')))