first template
This commit is contained in:
parent
f8dea939be
commit
5d891505eb
2 changed files with 76 additions and 0 deletions
69
legrandchien.py
Normal file
69
legrandchien.py
Normal file
|
|
@ -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)
|
||||||
7
main.py
Normal file
7
main.py
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
from legrandchien import *
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
k = Const(3)
|
||||||
|
kk = Const(4)
|
||||||
|
|
||||||
|
eq = k + kk
|
||||||
Loading…
Reference in a new issue