diff --git a/legrandchien.py b/legrandchien.py new file mode 100644 index 0000000..056b0da --- /dev/null +++ b/legrandchien.py @@ -0,0 +1,69 @@ +from enum import Enum +import numpy as np + +class Operation(Enum): + VAR = 1 + CONST = 2 + ADD = 3 + SUB = 4 + MULT = 5 + DIV = 6 + EXP = 7 + +# const class +class Const: + def __init__(self, value) -> None: + self.value = value + self.type = "Const" + + def __add__(self, other): + if other.type == "Const": + return Equation( + Operation.CONST, + None, + None, + self.value + ) + Equation( + Operation.CONST, + None, + None, + other.value + ) + if other.type == "Var": + return Equation( + Operation.CONST, + None, + None, + self.value + ) + Equation( + Operation.VAR, + None, + None, + other.name + ) + if other.type == "Equation": + return Equation( + Operation.CONST, + None, + None, + self.value + ) + other + +# var class +class Var: + def __init__(self, name) -> None: + self.name = name + self.type = "Var" + +# equation class +class Equation: + def __init__(self, op, left, right, value): + self.op = op + self.left = left + self.right = right + self.value = value + self.type = "Equation" + + def __add__(self, other): + if other.type == "Equation": + return Equation(Operation.ADD, self, other, None) diff --git a/main.py b/main.py new file mode 100644 index 0000000..0a8f06e --- /dev/null +++ b/main.py @@ -0,0 +1,7 @@ +from legrandchien import * + +if __name__ == "__main__": + k = Const(3) + kk = Const(4) + + eq = k + kk