-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.py
51 lines (40 loc) · 1.27 KB
/
node.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""node"""
class Node:
"""Abstract base class Node for the binary tree."""
def copy(self):
"""Returns a deep copy of a node
:return: Copied node
:rtype: Node
"""
def evaluate(self, value) -> float:
"""Evaluates the result of a Expression recursively, substituting
x with value.
:param value: value for x
:type value: int | float
:return: Result of calculation
:rtype: float
"""
def to_infix(self):
"""Converts a Expression to infix-notation, recursively."""
def diff(self):
"Returns a Expression Tree representing the derivative of the function"
def simplify(self):
"""Tries to simplify the Expression as much as possible
Trying to implement:
- Calculate Explicit Numbers
- x + 0 -> x
- x - 0 -> x
- 0 - x -> -x
- x * 0 -> 0
- x * 1 -> x
- x / 1 -> x
- x ^ 0 -> 1
- x ^ 1 -> x
- x * (y / z) -> (x * y) / z
TODO:
- Simplifying Fractions
- Unifiying same denominator / Fraction Rules
- Power Rules
- Extended Parenthesis Rules
"""
return self