Refactor code in directories + add doc strings
This commit is contained in:
parent
0d9a636da6
commit
77c8973eb7
2 changed files with 23 additions and 3 deletions
48
python_symb/MathTypes/symbols.py
Normal file
48
python_symb/MathTypes/symbols.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
from __future__ import annotations
|
||||
|
||||
|
||||
|
||||
class Symbols:
|
||||
"""
|
||||
All maths things (other than number) that will be parsed need to be of "Symbols" class
|
||||
"""
|
||||
instances = []
|
||||
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
Symbols.instances.append(self)
|
||||
|
||||
def __repr__(self):
|
||||
return self.name
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def __add__(self, other):
|
||||
from python_symb.Expressions.expr import Expr
|
||||
return Expr('+', [self, other])
|
||||
|
||||
def __radd__(self, other):
|
||||
from python_symb.Expressions.expr import Expr
|
||||
return Expr('+', [other, self])
|
||||
|
||||
def __mul__(self, other):
|
||||
from python_symb.Expressions.expr import Expr
|
||||
return Expr('*', [self, other])
|
||||
|
||||
def __rmul__(self, other):
|
||||
from python_symb.Expressions.expr import Expr
|
||||
return Expr('*', [other, self])
|
||||
|
||||
|
||||
class Var(Symbols):
|
||||
"""
|
||||
variable, like 'x' in x+2
|
||||
"""
|
||||
instances = []
|
||||
|
||||
def __init__(self, name):
|
||||
super().__init__(name)
|
||||
self.__class__.instances.append(self)
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue