diff --git a/python_symb/tools.py b/python_symb/IndependantTools/tools.py similarity index 52% rename from python_symb/tools.py rename to python_symb/IndependantTools/tools.py index 3d3b00a..b200348 100644 --- a/python_symb/tools.py +++ b/python_symb/IndependantTools/tools.py @@ -3,6 +3,12 @@ from typing import * def gcd(a, b): + """ + Greatest common divisor + work with any object that support modulo and comparison (contrary to math.gcd) + + used in type : Fraction + """ if b > a: return gcd(b, a) diff --git a/python_symb/symbols.py b/python_symb/MathTypes/symbols.py similarity index 53% rename from python_symb/symbols.py rename to python_symb/MathTypes/symbols.py index 1922db7..00c620a 100644 --- a/python_symb/symbols.py +++ b/python_symb/MathTypes/symbols.py @@ -1,5 +1,5 @@ from __future__ import annotations -# from expr import Expr + class Symbols: @@ -18,6 +18,22 @@ class Symbols: 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): """ @@ -29,6 +45,4 @@ class Var(Symbols): super().__init__(name) self.__class__.instances.append(self) - """def __add__(self, other) -> Expr: - return Expr('+', [self, other])"""