How to use the expression.Operations.MINUS function in Expression

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 / tests.py View on Github external
def test_allowed_operation(self):
        node = Node(Operations.MINUS)
        self.assertEquals(node.operation, Operations.MINUS)
github StanislavUshakov / ArtificialImmuneSystem / tests.py View on Github external
def test_pickle_binary(self):
        operation = Operations.MINUS
        returned_operation = pickle.loads(pickle.dumps(operation))
        self._test_for_equality(operation, returned_operation)
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 / expression.py View on Github external
def __setstate__(self, state):
        """
        Initializes operation where unpickling
        """
        if state[self._dict_key] == 'number':
            operator = Operations.NUMBER
        elif state[self._dict_key] == 'variable':
            operator = Operations.IDENTITY
        elif state[self._dict_key] == '+':
            operator = Operations.PLUS
        elif state[self._dict_key] == '-':
            operator = Operations.MINUS
        elif state[self._dict_key] == '*':
            operator = Operations.MULTIPLICATION
        elif state[self._dict_key] == '/':
            operator = Operations.DIVISION
        elif state[self._dict_key] == 'sin':
            operator = Operations.SIN
        elif state[self._dict_key] == 'cos':
            operator = Operations.COS
        self._init_from_operation(operator)
github StanislavUshakov / ArtificialImmuneSystem / expression.py View on Github external
self.left = self.right = None
            return True

        #calculate x / x
        if (self.is_binary() and
            self.left.is_variable() and self.right.is_variable() and
            self.left.value == self.right.value and self.operation == Operations.DIVISION):
            self.value = 1
            self.operation = Operations.NUMBER
            self.left = self.right = None
            return True

        #calculate x - x
        if (self.is_binary() and
            self.left.is_variable() and self.right.is_variable() and
            self.left.value == self.right.value and self.operation == Operations.MINUS):
            self.value = 0
            self.operation = Operations.NUMBER
            self.left = self.right = None
            return True

        #calculate x * 1 and x / 1
        if (self.is_binary() and
            self.right.is_number() and abs(self.right.value - 1) < accuracy and
            (self.operation == Operations.DIVISION or self.operation == Operations.MULTIPLICATION)):
            self._init_with_node(self.left)
            self.simplify()
            return True

        #calculate 1 * x
        if (self.is_binary() and
            self.left.is_number() and abs(self.left.value - 1) < accuracy and