From 77c8973eb7a2bae8316538d0e04476a9f1a5cad3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Barth=C3=A9lemy?= Date: Tue, 20 Feb 2024 00:01:55 +0100 Subject: [PATCH] Refactor code in directories + add doc strings --- python_symb/{ => IndependantTools}/tools.py | 6 ++++++ python_symb/{ => MathTypes}/symbols.py | 20 +++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) rename python_symb/{ => IndependantTools}/tools.py (52%) rename python_symb/{ => MathTypes}/symbols.py (53%) 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])"""