How to use Expression - 10 common examples

To help you get started, we’ve selected a few Expression examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github StanislavUshakov / ArtificialImmuneSystem / main.py View on Github external
        lambda: [Expression.generate_random(max_height=max_height, variables=variables)
                for i in range(0, number_of_lymphocytes // 2)])
github StanislavUshakov / ArtificialImmuneSystem / tests.py View on Github external
def test_value_in_point(self):
        node = Node(Operations.MINUS,
                left=Node(Operations.IDENTITY, value='x'),
                right=Node(Operations.IDENTITY, value='y'))
        result = node.value_in_point({'x': 2, 'y': 1})
        self.assertEqual(result, 1.0)
github StanislavUshakov / ArtificialImmuneSystem / tests.py View on Github external
def setUp(self):
        root = Node(Operations.PLUS,
            Node(Operations.MULTIPLICATION,
                left=Node(Operations.IDENTITY, value='x'),
                right=Node(Operations.NUMBER, value=4)),
            Node(Operations.MULTIPLICATION,
                left=Node(Operations.IDENTITY, value='y'),
                right=Node(Operations.NUMBER, value=2)))
        self.f = Expression(root=root, variables=['x', 'y'])
github StanislavUshakov / ArtificialImmuneSystem / tests.py View on Github external
def test_wrong_value(self):
        wrong = Node(Operations.MINUS,
            Node(Operations.MULTIPLICATION,
                left=Node(Operations.IDENTITY, value='x'),
                right=Node(Operations.NUMBER, value=4)),
            Node(Operations.MULTIPLICATION,
                left=Node(Operations.IDENTITY, value='y'),
                right=Node(Operations.NUMBER, value=2)))
        e = Expression(root=wrong, variables=['x', 'y'])
        self.assertGreater(self.f.expression_value(e), 0.0)
github StanislavUshakov / ArtificialImmuneSystem / tests.py View on Github external
def test_pickle_node(self):
        node = Node(Operations.PLUS,
            Node(Operations.MULTIPLICATION,
                left=Node(Operations.IDENTITY, value='x'),
                right=Node(Operations.NUMBER, value=4)),
            Node(Operations.MULTIPLICATION,
                left=Node(Operations.IDENTITY, value='y'),
                right=Node(Operations.NUMBER, value=2)))
        returned_node = pickle.loads(pickle.dumps(node))
        self.assertEqual(node.operation._operation_type, returned_node.operation._operation_type)
        self.assertEqual(node.operation.action, returned_node.operation.action)
        self.assertEqual(node.value, returned_node.value)
        self.assertEqual(node.left.operation._operation_type, returned_node.left.operation._operation_type)
        self.assertEqual(node.left.operation.action, returned_node.left.operation.action)
        self.assertEqual(node.left.value, returned_node.left.value)
        self.assertEqual(node.right.operation._operation_type, returned_node.right.operation._operation_type)
        self.assertEqual(node.right.operation.action, returned_node.right.operation.action)
        self.assertEqual(node.right.value, returned_node.right.value)
github StanislavUshakov / ArtificialImmuneSystem / tests.py View on Github external
def test_wrong_value(self):
        wrong = Node(Operations.MINUS,
            Node(Operations.MULTIPLICATION,
                left=Node(Operations.IDENTITY, value='x'),
                right=Node(Operations.NUMBER, value=4)),
            Node(Operations.MULTIPLICATION,
                left=Node(Operations.IDENTITY, value='y'),
                right=Node(Operations.NUMBER, value=2)))
        e = Expression(root=wrong, variables=['x', 'y'])
        self.assertGreater(self.f.expression_value(e), 0.0)
github StanislavUshakov / ArtificialImmuneSystem / tests.py View on Github external
def test_simplify_identical_variables_division(self):
        node = Node(Operations.DIVISION,
            left=Node(Operations.IDENTITY, value='x'),
            right=Node(Operations.IDENTITY, value='x'))
        result = node.simplify()
        self.assertEqual(result, True)
        self.assertEqual(node.left, None)
        self.assertEqual(node.right, None)
        self.assertEqual(node.value, 1.0)
github StanislavUshakov / ArtificialImmuneSystem / tests.py View on Github external
def test_wrong_value(self):
        wrong = Node(Operations.MINUS,
            Node(Operations.MULTIPLICATION,
                left=Node(Operations.IDENTITY, value='x'),
                right=Node(Operations.NUMBER, value=4)),
            Node(Operations.MULTIPLICATION,
                left=Node(Operations.IDENTITY, value='y'),
                right=Node(Operations.NUMBER, value=2)))
        e = Expression(root=wrong, variables=['x', 'y'])
        self.assertGreater(self.f.expression_value(e), 0.0)
github StanislavUshakov / ArtificialImmuneSystem / tests.py View on Github external
def test_exact_value(self):
        answer = Node(Operations.PLUS,
            Node(Operations.MULTIPLICATION,
                left=Node(Operations.IDENTITY, value='x'),
                right=Node(Operations.NUMBER, value=4)),
            Node(Operations.MULTIPLICATION,
                left=Node(Operations.IDENTITY, value='y'),
                right=Node(Operations.NUMBER, value=2)))
        e = Expression(root=answer, variables=['x', 'y'])
        self.assertEqual(self.f.expression_value(e), 0.0)
github StanislavUshakov / ArtificialImmuneSystem / tests.py View on Github external
def test_simplify_multiply_by_one_left(self):
        node = Node(Operations.MULTIPLICATION,
            left=Node(Operations.NUMBER, value=1),
            right=Node(Operations.IDENTITY, value='x'))
        result = node.simplify()
        self.assertEqual(result, True)
        self.assertEqual(node.operation, Operations.IDENTITY)
        self.assertEqual(node.value, 'x')