diff --git a/pymath/calculus/abstract_polynom.py b/pymath/calculus/abstract_polynom.py index efdc1ab..28a6a62 100644 --- a/pymath/calculus/abstract_polynom.py +++ b/pymath/calculus/abstract_polynom.py @@ -126,7 +126,10 @@ class AbstractPolynom(Explicable): return str(Expression(self.postfix_tokens)) def __repr__(self): - return "< " + str(self.__class__) + " " + str(self._coef) + ">" + return "< {cls} {letter} {coefs}>".format( + cls = str(self.__class__).split('.')[-1][:-2], + letter = str(self._letter), + coefs = str(self._coef)) def coef_postfix(self, a, i): """Return the postfix display of a coeficient @@ -275,9 +278,9 @@ class AbstractPolynom(Explicable): >>> P = AbstractPolynom([1,2,3]) >>> P.conv2poly(1) - < [1]> + < AbstractPolynom x [1]> >>> P.conv2poly(0) - < [0]> + < AbstractPolynom x [0]> """ if isNumber(other) and not isPolynom(other): @@ -296,13 +299,13 @@ class AbstractPolynom(Explicable): >>> P = AbstractPolynom([1,2,3]) >>> Q = P.reduce() >>> Q - < [1, 2, 3]> + < AbstractPolynom x [1, 2, 3]> >>> Q.steps [] >>> P = AbstractPolynom([[1,2], [3,4,5], 6]) >>> Q = P.reduce() >>> Q - < [3, 12, 6]> + < AbstractPolynom x [3, 12, 6]> >>> for i in Q.explain(): ... print(i) 6 x^{ 2 } + 3 x + 4 x + 5 x + 1 + 2 @@ -310,7 +313,7 @@ class AbstractPolynom(Explicable): 6 x^{ 2 } + ( 7 + 5 ) x + 3 6 x^{ 2 } + 12 x + 3 >>> Q.steps - [< [[1, 2], [3, 4, 5], 6]>, < [< [1, 2, +] >, < [3, 4, +, 5, +] >, 6]>, < [3, < [7, 5, +] >, 6]>] + [< AbstractPolynom x [[1, 2], [3, 4, 5], 6]>, < AbstractPolynom x [< [1, 2, +] >, < [3, 4, +, 5, +] >, 6]>, < AbstractPolynom x [3, < [7, 5, +] >, 6]>] """ # TODO: It doesn't not compute quick enough |ven. févr. 27 18:04:01 CET @@ -382,7 +385,7 @@ class AbstractPolynom(Explicable): >>> Q = AbstractPolynom([4,5]) >>> R = P+Q >>> R - < [5, 7, 3]> + < AbstractPolynom x [5, 7, 3]> >>> for i in R.explain(): ... print(i) 3 x^{ 2 } + 2 x + 1 + 5 x + 4 @@ -390,7 +393,7 @@ class AbstractPolynom(Explicable): 3 x^{ 2 } + ( 2 + 5 ) x + 1 + 4 3 x^{ 2 } + 7 x + 5 >>> R.steps - [< [3, 'x', 2, ^, *, 2, 'x', *, +, 1, +, 5, 'x', *, 4, +, +] >, < [[1, 4], [2, 5], 3]>, < [< [1, 4, +] >, < [2, 5, +] >, 3]>] + [< [3, 'x', 2, ^, *, 2, 'x', *, +, 1, +, 5, 'x', *, 4, +, +] >, < AbstractPolynom x [[1, 4], [2, 5], 3]>, < AbstractPolynom x [< [1, 4, +] >, < [2, 5, +] >, 3]>] """ o_poly = self.conv2poly(other) @@ -413,7 +416,7 @@ class AbstractPolynom(Explicable): >>> P = AbstractPolynom([1,2,3]) >>> Q = -P >>> Q - < [-1, -2, -3]> + < AbstractPolynom x [-1, -2, -3]> >>> Q.steps [< [3, 'x', 2, ^, *, 2, 'x', *, +, 1, +, -] >] """ @@ -430,7 +433,7 @@ class AbstractPolynom(Explicable): >>> Q = AbstractPolynom([4,5,6]) >>> R = P - Q >>> R - < [-3, -3, -3]> + < AbstractPolynom x [-3, -3, -3]> >>> for i in R.explain(): ... print(i) 3 x^{ 2 } + 2 x + 1 - ( 6 x^{ 2 } + 5 x + 4 ) @@ -439,7 +442,7 @@ class AbstractPolynom(Explicable): ( 3 - 6 ) x^{ 2 } + ( 2 - 5 ) x + 1 - 4 - 3 x^{ 2 } - 3 x - 3 >>> R.steps - [< [3, 'x', 2, ^, *, 2, 'x', *, +, 1, +, 6, 'x', 2, ^, *, 5, 'x', *, +, 4, +, -] >, < [3, 'x', 2, ^, *, 2, 'x', *, +, 1, +, 6, 'x', 2, ^, *, -, 5, 'x', *, -, 4, -, +] >, < [[1, -4], [2, -5], [3, -6]]>, < [< [1, -4, +] >, < [2, -5, +] >, < [3, -6, +] >]>] + [< [3, 'x', 2, ^, *, 2, 'x', *, +, 1, +, 6, 'x', 2, ^, *, 5, 'x', *, +, 4, +, -] >, < [3, 'x', 2, ^, *, 2, 'x', *, +, 1, +, 6, 'x', 2, ^, *, -, 5, 'x', *, -, 4, -, +] >, < AbstractPolynom x [[1, -4], [2, -5], [3, -6]]>, < AbstractPolynom x [< [1, -4, +] >, < [2, -5, +] >, < [3, -6, +] >]>] """ o_poly = self.conv2poly(other) ini_step = [Expression(self.postfix_tokens + @@ -461,34 +464,34 @@ class AbstractPolynom(Explicable): >>> p = AbstractPolynom([1,2]) >>> p*3 - < [3, 6]> + < AbstractPolynom x [3, 6]> >>> for i in (p*3).explain(): ... print(i) ( 2 x + 1 ) \times 3 2 \times 3 x + 3 6 x + 3 >>> (p*3).steps - [< [2, 'x', *, 1, +, 3, *] >, < [3, < [2, 3, *] >]>] + [< [2, 'x', *, 1, +, 3, *] >, < AbstractPolynom x [3, < [2, 3, *] >]>] >>> q = AbstractPolynom([0,0,4]) >>> q*3 - < [0, 0, 12]> + < AbstractPolynom x [0, 0, 12]> >>> (q*3).steps - [< [4, 'x', 2, ^, *, 3, *] >, < [0, 0, < [4, 3, *] >]>] + [< [4, 'x', 2, ^, *, 3, *] >, < AbstractPolynom x [0, 0, < [4, 3, *] >]>] >>> r = AbstractPolynom([0,1]) >>> r*3 - < [0, 3]> + < AbstractPolynom x [0, 3]> >>> (r*3).steps [< ['x', 3, *] >] >>> p*q - < [0, 0, 4, 8]> + < AbstractPolynom x [0, 0, 4, 8]> >>> (p*q).steps - [< [2, 'x', *, 1, +, 4, 'x', 2, ^, *, *] >, < [0, 0, 4, < [2, 4, *] >]>] + [< [2, 'x', *, 1, +, 4, 'x', 2, ^, *, *] >, < AbstractPolynom x [0, 0, 4, < [2, 4, *] >]>] >>> p*r - < [0, 1, 2]> + < AbstractPolynom x [0, 1, 2]> >>> P = AbstractPolynom([1,2,3]) >>> Q = AbstractPolynom([4,5,6]) >>> P*Q - < [4, 13, 28, 27, 18]> + < AbstractPolynom x [4, 13, 28, 27, 18]> """ o_poly = self.conv2poly(other) @@ -531,20 +534,20 @@ class AbstractPolynom(Explicable): >>> p = AbstractPolynom([0,0,3]) >>> p**2 - < [0, 0, 0, 0, 9]> + < AbstractPolynom x [0, 0, 0, 0, 9]> >>> (p**2).steps - [< [3, 'x', 2, ^, *, 2, ^] >, < [0, 0, 0, 0, < [3, 2, ^] >]>] + [< [3, 'x', 2, ^, *, 2, ^] >, < AbstractPolynom x [0, 0, 0, 0, < [3, 2, ^] >]>] >>> p = AbstractPolynom([1,2]) >>> p**2 - < [1, 4, 4]> + < AbstractPolynom x [1, 4, 4]> >>> (p**2).steps - [< [2, 'x', *, 1, +, 2, ^] >, < [2, 'x', *, 1, +, 2, 'x', *, 1, +, *] >, < [1, [2, 2], < [2, 2, *] >]>, < [1, < [2, 2, +] >, 4]>] + [< [2, 'x', *, 1, +, 2, ^] >, < [2, 'x', *, 1, +, 2, 'x', *, 1, +, *] >, < AbstractPolynom x [1, [2, 2], < [2, 2, *] >]>, < AbstractPolynom x [1, < [2, 2, +] >, 4]>] >>> p = AbstractPolynom([0,0,1]) >>> p**3 - < [0, 0, 0, 0, 0, 0, 1]> + < AbstractPolynom x [0, 0, 0, 0, 0, 0, 1]> >>> p = AbstractPolynom([1,2,3]) >>> p**2 - < [1, 4, 10, 12, 9]> + < AbstractPolynom x [1, 4, 10, 12, 9]> """ if not type(power): diff --git a/pymath/calculus/polynom.py b/pymath/calculus/polynom.py index ea6ffd1..dccfb3f 100644 --- a/pymath/calculus/polynom.py +++ b/pymath/calculus/polynom.py @@ -67,15 +67,15 @@ class Polynom(AbstractPolynom): /!\ variables need to be in brackets {} >>> Polynom.random(["{b}", "{a}"]) # doctest:+ELLIPSIS - < ... + < Polynom x ... >>> Polynom.random(degree = 2) # doctest:+ELLIPSIS - < ... + < Polynom_deg2 x ...> >>> Polynom.random(degree = 3) # doctest:+ELLIPSIS - < ... + < Polynom x ...> >>> Polynom.random(degree = 2, conditions=["{b**2-4*a*c}>0"]) # Polynom deg 2 with positive Delta (ax^2 + bx + c) - < ... + < Polynom_deg2 x ...> >>> Polynom.random(["{c}", "{b}", "{a}"], conditions=["{b**2-4*a*c}>0"]) # Same as above - < ... + < Polynom_deg2 x ...> """ if (degree > 0 and degree < 26): @@ -161,7 +161,7 @@ class Polynom(AbstractPolynom): >>> P = Polynom([1, 2, 3]) >>> Q = P.derivate() >>> Q - < [2, 6]> + < Polynom x [2, 6]> >>> print(Q.name) P' >>> for i in Q.explain(): diff --git a/pymath/calculus/str2tokens.py b/pymath/calculus/str2tokens.py index 7e997d3..e9c70b6 100644 --- a/pymath/calculus/str2tokens.py +++ b/pymath/calculus/str2tokens.py @@ -17,7 +17,7 @@ def str2tokens(exp): >>> str2tokens('2*3+4') [2, 3, *, 4, +] >>> str2tokens('2x+4') - [2, < [0, 1]>, *, 4, +] + [2, < Polynom x [0, 1]>, *, 4, +] """ in_tokens = str2in_tokens(exp) post_tokens = in2post_fix(in_tokens) @@ -40,7 +40,7 @@ def str2in_tokens(exp): >>> str2in_tokens('2.3*3+4') [Decimal('2.3'), '*', 3, '+', 4] >>> str2in_tokens('a*3+4') - [< [0, 1]>, '*', 3, '+', 4] + [< Polynom a [0, 1]>, '*', 3, '+', 4] """ tokens = ['', '']