start to reorganise files
This commit is contained in:
parent
a0cf4c1f67
commit
881de6dcb1
@ -1,11 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
from .expression import Expression
|
from .calculus import *
|
||||||
from .polynom import Polynom
|
|
||||||
from .fraction import Fraction
|
|
||||||
from .random_expression import random_str
|
|
||||||
from .render import txt,tex
|
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
|
14
pymath/calculus/__init__.py
Normal file
14
pymath/calculus/__init__.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
from .expression import Expression
|
||||||
|
from .polynom import Polynom
|
||||||
|
from .fraction import Fraction
|
||||||
|
from .random_expression import random_str
|
||||||
|
#from .render import txt,tex
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------------------
|
||||||
|
# Reglages pour 'vim'
|
||||||
|
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||||
|
# cursor: 16 del
|
@ -199,8 +199,8 @@ class AbstractPolynom(Explicable):
|
|||||||
>>> p = AbstractPolynom([1,[-2,-3]])
|
>>> p = AbstractPolynom([1,[-2,-3]])
|
||||||
>>> p.postfix_tokens
|
>>> p.postfix_tokens
|
||||||
[2, 'x', '*', '-', 3, 'x', '*', '-', 1, '+']
|
[2, 'x', '*', '-', 3, 'x', '*', '-', 1, '+']
|
||||||
>>> from pymath.expression import Expression
|
>>> from pymath.calculus.expression import Expression
|
||||||
>>> from pymath.operator import op
|
>>> from pymath.calculus.operator import op
|
||||||
>>> e = Expression([2,3,op.add])
|
>>> e = Expression([2,3,op.add])
|
||||||
>>> p = AbstractPolynom([1,e])
|
>>> p = AbstractPolynom([1,e])
|
||||||
>>> p.postfix_tokens
|
>>> p.postfix_tokens
|
||||||
@ -280,9 +280,9 @@ class AbstractPolynom(Explicable):
|
|||||||
|
|
||||||
>>> P = AbstractPolynom([1,2,3])
|
>>> P = AbstractPolynom([1,2,3])
|
||||||
>>> P.conv2poly(1)
|
>>> P.conv2poly(1)
|
||||||
< <class 'pymath.abstract_polynom.AbstractPolynom'> [1]>
|
< <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [1]>
|
||||||
>>> P.conv2poly(0)
|
>>> P.conv2poly(0)
|
||||||
< <class 'pymath.abstract_polynom.AbstractPolynom'> [0]>
|
< <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [0]>
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if isNumber(other) and not isPolynom(other):
|
if isNumber(other) and not isPolynom(other):
|
||||||
@ -300,20 +300,20 @@ class AbstractPolynom(Explicable):
|
|||||||
>>> P = AbstractPolynom([1,2,3])
|
>>> P = AbstractPolynom([1,2,3])
|
||||||
>>> Q = P.reduce()
|
>>> Q = P.reduce()
|
||||||
>>> Q
|
>>> Q
|
||||||
< <class 'pymath.abstract_polynom.AbstractPolynom'> [1, 2, 3]>
|
< <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [1, 2, 3]>
|
||||||
>>> Q.steps
|
>>> Q.steps
|
||||||
[]
|
[]
|
||||||
>>> P = AbstractPolynom([[1,2], [3,4,5], 6])
|
>>> P = AbstractPolynom([[1,2], [3,4,5], 6])
|
||||||
>>> Q = P.reduce()
|
>>> Q = P.reduce()
|
||||||
>>> Q
|
>>> Q
|
||||||
< <class 'pymath.abstract_polynom.AbstractPolynom'> [3, 12, 6]>
|
< <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [3, 12, 6]>
|
||||||
>>> for i in Q.explain():
|
>>> for i in Q.explain():
|
||||||
... print(i)
|
... print(i)
|
||||||
6 x^{ 2 } + ( 3 + 4 + 5 ) x + 1 + 2
|
6 x^{ 2 } + ( 3 + 4 + 5 ) x + 1 + 2
|
||||||
6 x^{ 2 } + ( 7 + 5 ) x + 3
|
6 x^{ 2 } + ( 7 + 5 ) x + 3
|
||||||
6 x^{ 2 } + 12 x + 3
|
6 x^{ 2 } + 12 x + 3
|
||||||
>>> Q.steps
|
>>> Q.steps
|
||||||
[< <class 'pymath.abstract_polynom.AbstractPolynom'> [< <class 'pymath.expression.Expression'> [1, 2, '+'] >, < <class 'pymath.expression.Expression'> [3, 4, '+', 5, '+'] >, 6]>, < <class 'pymath.abstract_polynom.AbstractPolynom'> [3, < <class 'pymath.expression.Expression'> [7, 5, '+'] >, 6]>]
|
[< <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [< <class 'pymath.calculus.expression.Expression'> [1, 2, '+'] >, < <class 'pymath.calculus.expression.Expression'> [3, 4, '+', 5, '+'] >, 6]>, < <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [3, < <class 'pymath.calculus.expression.Expression'> [7, 5, '+'] >, 6]>]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# TODO: It doesn't not compute quick enough |ven. févr. 27 18:04:01 CET 2015
|
# TODO: It doesn't not compute quick enough |ven. févr. 27 18:04:01 CET 2015
|
||||||
@ -407,9 +407,9 @@ class AbstractPolynom(Explicable):
|
|||||||
>>> Q = AbstractPolynom([4,5])
|
>>> Q = AbstractPolynom([4,5])
|
||||||
>>> R = P+Q
|
>>> R = P+Q
|
||||||
>>> R
|
>>> R
|
||||||
< <class 'pymath.abstract_polynom.AbstractPolynom'> [5, 7, 3]>
|
< <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [5, 7, 3]>
|
||||||
>>> R.steps
|
>>> R.steps
|
||||||
[< <class 'pymath.expression.Expression'> [3, 'x', 2, '^', '*', 2, 'x', '*', '+', 1, '+', 5, 'x', '*', 4, '+', '+'] >, < <class 'pymath.abstract_polynom.AbstractPolynom'> [< <class 'pymath.expression.Expression'> [1, 4, '+'] >, < <class 'pymath.expression.Expression'> [2, 5, '+'] >, 3]>]
|
[< <class 'pymath.calculus.expression.Expression'> [3, 'x', 2, '^', '*', 2, 'x', '*', '+', 1, '+', 5, 'x', '*', 4, '+', '+'] >, < <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [< <class 'pymath.calculus.expression.Expression'> [1, 4, '+'] >, < <class 'pymath.calculus.expression.Expression'> [2, 5, '+'] >, 3]>]
|
||||||
"""
|
"""
|
||||||
o_poly = self.conv2poly(other)
|
o_poly = self.conv2poly(other)
|
||||||
|
|
||||||
@ -431,9 +431,9 @@ class AbstractPolynom(Explicable):
|
|||||||
>>> P = AbstractPolynom([1,2,3])
|
>>> P = AbstractPolynom([1,2,3])
|
||||||
>>> Q = -P
|
>>> Q = -P
|
||||||
>>> Q
|
>>> Q
|
||||||
< <class 'pymath.abstract_polynom.AbstractPolynom'> [-1, -2, -3]>
|
< <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [-1, -2, -3]>
|
||||||
>>> Q.steps
|
>>> Q.steps
|
||||||
[< <class 'pymath.expression.Expression'> [3, 'x', 2, '^', '*', 2, 'x', '*', '+', 1, '+', '-'] >]
|
[< <class 'pymath.calculus.expression.Expression'> [3, 'x', 2, '^', '*', 2, 'x', '*', '+', 1, '+', '-'] >]
|
||||||
"""
|
"""
|
||||||
ini_step = [Expression(self.postfix_tokens + [op.sub1])]
|
ini_step = [Expression(self.postfix_tokens + [op.sub1])]
|
||||||
ans = AbstractPolynom([-i for i in self._coef], letter = self._letter).simplify()
|
ans = AbstractPolynom([-i for i in self._coef], letter = self._letter).simplify()
|
||||||
@ -447,9 +447,9 @@ class AbstractPolynom(Explicable):
|
|||||||
>>> Q = AbstractPolynom([4,5,6])
|
>>> Q = AbstractPolynom([4,5,6])
|
||||||
>>> R = P - Q
|
>>> R = P - Q
|
||||||
>>> R
|
>>> R
|
||||||
< <class 'pymath.abstract_polynom.AbstractPolynom'> [-3, -3, -3]>
|
< <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [-3, -3, -3]>
|
||||||
>>> R.steps
|
>>> R.steps
|
||||||
[< <class 'pymath.expression.Expression'> [3, 'x', 2, '^', '*', 2, 'x', '*', '+', 1, '+', 6, 'x', 2, '^', '*', 5, 'x', '*', '+', 4, '+', '-'] >, < <class 'pymath.expression.Expression'> [3, 'x', 2, '^', '*', 2, 'x', '*', '+', 1, '+', 6, 'x', 2, '^', '*', '-', 5, 'x', '*', '-', 4, '-', '+'] >, < <class 'pymath.abstract_polynom.AbstractPolynom'> [< <class 'pymath.expression.Expression'> [1, -4, '+'] >, < <class 'pymath.expression.Expression'> [2, -5, '+'] >, < <class 'pymath.expression.Expression'> [3, -6, '+'] >]>]
|
[< <class 'pymath.calculus.expression.Expression'> [3, 'x', 2, '^', '*', 2, 'x', '*', '+', 1, '+', 6, 'x', 2, '^', '*', 5, 'x', '*', '+', 4, '+', '-'] >, < <class 'pymath.calculus.expression.Expression'> [3, 'x', 2, '^', '*', 2, 'x', '*', '+', 1, '+', 6, 'x', 2, '^', '*', '-', 5, 'x', '*', '-', 4, '-', '+'] >, < <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [< <class 'pymath.calculus.expression.Expression'> [1, -4, '+'] >, < <class 'pymath.calculus.expression.Expression'> [2, -5, '+'] >, < <class 'pymath.calculus.expression.Expression'> [3, -6, '+'] >]>]
|
||||||
>>> for i in R.explain():
|
>>> for i in R.explain():
|
||||||
... print(i)
|
... print(i)
|
||||||
3 x^{ 2 } + 2 x + 1 - ( 6 x^{ 2 } + 5 x + 4 )
|
3 x^{ 2 } + 2 x + 1 - ( 6 x^{ 2 } + 5 x + 4 )
|
||||||
@ -477,29 +477,29 @@ class AbstractPolynom(Explicable):
|
|||||||
|
|
||||||
>>> p = AbstractPolynom([1,2])
|
>>> p = AbstractPolynom([1,2])
|
||||||
>>> p*3
|
>>> p*3
|
||||||
< <class 'pymath.abstract_polynom.AbstractPolynom'> [3, 6]>
|
< <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [3, 6]>
|
||||||
>>> (p*3).steps
|
>>> (p*3).steps
|
||||||
[[< <class 'pymath.expression.Expression'> [2, 'x', '*', 1, '+', 3, '*'] >], < <class 'pymath.abstract_polynom.AbstractPolynom'> [3, < <class 'pymath.expression.Expression'> [2, 3, '*'] >]>]
|
[[< <class 'pymath.calculus.expression.Expression'> [2, 'x', '*', 1, '+', 3, '*'] >], < <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [3, < <class 'pymath.calculus.expression.Expression'> [2, 3, '*'] >]>]
|
||||||
>>> q = AbstractPolynom([0,0,4])
|
>>> q = AbstractPolynom([0,0,4])
|
||||||
>>> q*3
|
>>> q*3
|
||||||
< <class 'pymath.abstract_polynom.AbstractPolynom'> [0, 0, 12]>
|
< <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [0, 0, 12]>
|
||||||
>>> (q*3).steps
|
>>> (q*3).steps
|
||||||
[[< <class 'pymath.expression.Expression'> [4, 'x', 2, '^', '*', 3, '*'] >], < <class 'pymath.abstract_polynom.AbstractPolynom'> [0, 0, < <class 'pymath.expression.Expression'> [4, 3, '*'] >]>]
|
[[< <class 'pymath.calculus.expression.Expression'> [4, 'x', 2, '^', '*', 3, '*'] >], < <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [0, 0, < <class 'pymath.calculus.expression.Expression'> [4, 3, '*'] >]>]
|
||||||
>>> r = AbstractPolynom([0,1])
|
>>> r = AbstractPolynom([0,1])
|
||||||
>>> r*3
|
>>> r*3
|
||||||
< <class 'pymath.abstract_polynom.AbstractPolynom'> [0, 3]>
|
< <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [0, 3]>
|
||||||
>>> (r*3).steps
|
>>> (r*3).steps
|
||||||
[[< <class 'pymath.expression.Expression'> ['x', 3, '*'] >]]
|
[[< <class 'pymath.calculus.expression.Expression'> ['x', 3, '*'] >]]
|
||||||
>>> p*q
|
>>> p*q
|
||||||
< <class 'pymath.abstract_polynom.AbstractPolynom'> [0, 0, 4, 8]>
|
< <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [0, 0, 4, 8]>
|
||||||
>>> (p*q).steps
|
>>> (p*q).steps
|
||||||
[[< <class 'pymath.expression.Expression'> [2, 'x', '*', 1, '+', 4, 'x', 2, '^', '*', '*'] >], < <class 'pymath.abstract_polynom.AbstractPolynom'> [0, 0, 4, < <class 'pymath.expression.Expression'> [2, 4, '*'] >]>]
|
[[< <class 'pymath.calculus.expression.Expression'> [2, 'x', '*', 1, '+', 4, 'x', 2, '^', '*', '*'] >], < <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [0, 0, 4, < <class 'pymath.calculus.expression.Expression'> [2, 4, '*'] >]>]
|
||||||
>>> p*r
|
>>> p*r
|
||||||
< <class 'pymath.abstract_polynom.AbstractPolynom'> [0, 1, 2]>
|
< <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [0, 1, 2]>
|
||||||
>>> P = AbstractPolynom([1,2,3])
|
>>> P = AbstractPolynom([1,2,3])
|
||||||
>>> Q = AbstractPolynom([4,5,6])
|
>>> Q = AbstractPolynom([4,5,6])
|
||||||
>>> P*Q
|
>>> P*Q
|
||||||
< <class 'pymath.abstract_polynom.AbstractPolynom'> [4, 13, 28, 27, 18]>
|
< <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [4, 13, 28, 27, 18]>
|
||||||
"""
|
"""
|
||||||
# TODO: Je trouve qu'elle grille trop d'étapes... |ven. févr. 27 19:08:44 CET 2015
|
# TODO: Je trouve qu'elle grille trop d'étapes... |ven. févr. 27 19:08:44 CET 2015
|
||||||
o_poly = self.conv2poly(other)
|
o_poly = self.conv2poly(other)
|
||||||
@ -542,20 +542,20 @@ class AbstractPolynom(Explicable):
|
|||||||
|
|
||||||
>>> p = AbstractPolynom([0,0,3])
|
>>> p = AbstractPolynom([0,0,3])
|
||||||
>>> p**2
|
>>> p**2
|
||||||
< <class 'pymath.abstract_polynom.AbstractPolynom'> [0, 0, 0, 0, 9]>
|
< <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [0, 0, 0, 0, 9]>
|
||||||
>>> (p**2).steps
|
>>> (p**2).steps
|
||||||
[< <class 'pymath.expression.Expression'> [3, 'x', 2, '^', '*', 2, '^'] >, < <class 'pymath.abstract_polynom.AbstractPolynom'> [0, 0, 0, 0, < <class 'pymath.expression.Expression'> [3, 2, '^'] >]>]
|
[< <class 'pymath.calculus.expression.Expression'> [3, 'x', 2, '^', '*', 2, '^'] >, < <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [0, 0, 0, 0, < <class 'pymath.calculus.expression.Expression'> [3, 2, '^'] >]>]
|
||||||
>>> p = AbstractPolynom([1,2])
|
>>> p = AbstractPolynom([1,2])
|
||||||
>>> p**2
|
>>> p**2
|
||||||
< <class 'pymath.abstract_polynom.AbstractPolynom'> [1, 4, 4]>
|
< <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [1, 4, 4]>
|
||||||
>>> (p**2).steps
|
>>> (p**2).steps
|
||||||
[< <class 'pymath.expression.Expression'> [2, 'x', '*', 1, '+', 2, '^'] >, [< <class 'pymath.expression.Expression'> [2, 'x', '*', 1, '+', 2, 'x', '*', 1, '+', '*'] >], < <class 'pymath.abstract_polynom.AbstractPolynom'> [1, < <class 'pymath.expression.Expression'> [2, 2, '+'] >, < <class 'pymath.expression.Expression'> [2, 2, '*'] >]>]
|
[< <class 'pymath.calculus.expression.Expression'> [2, 'x', '*', 1, '+', 2, '^'] >, [< <class 'pymath.calculus.expression.Expression'> [2, 'x', '*', 1, '+', 2, 'x', '*', 1, '+', '*'] >], < <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [1, < <class 'pymath.calculus.expression.Expression'> [2, 2, '+'] >, < <class 'pymath.calculus.expression.Expression'> [2, 2, '*'] >]>]
|
||||||
>>> p = AbstractPolynom([0,0,1])
|
>>> p = AbstractPolynom([0,0,1])
|
||||||
>>> p**3
|
>>> p**3
|
||||||
< <class 'pymath.abstract_polynom.AbstractPolynom'> [0, 0, 0, 0, 0, 0, 1]>
|
< <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [0, 0, 0, 0, 0, 0, 1]>
|
||||||
>>> p = AbstractPolynom([1,2,3])
|
>>> p = AbstractPolynom([1,2,3])
|
||||||
>>> p**2
|
>>> p**2
|
||||||
< <class 'pymath.abstract_polynom.AbstractPolynom'> [1, 4, 10, 12, 9]>
|
< <class 'pymath.calculus.abstract_polynom.AbstractPolynom'> [1, 4, 10, 12, 9]>
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not type(power):
|
if not type(power):
|
@ -56,11 +56,11 @@ class Expression(Explicable):
|
|||||||
>>> with Expression.tmp_render():
|
>>> with Expression.tmp_render():
|
||||||
... for i in exp.simplify().explain():
|
... for i in exp.simplify().explain():
|
||||||
... i
|
... i
|
||||||
< <class 'pymath.expression.Expression'> [2, 3, 5, '/', '*'] >
|
< <class 'pymath.calculus.expression.Expression'> [2, 3, 5, '/', '*'] >
|
||||||
< <class 'pymath.expression.Expression'> [2, < Fraction 3 / 5>, '*'] >
|
< <class 'pymath.calculus.expression.Expression'> [2, < Fraction 3 / 5>, '*'] >
|
||||||
< <class 'pymath.expression.Expression'> [3, 5, '/', 2, '*'] >
|
< <class 'pymath.calculus.expression.Expression'> [3, 5, '/', 2, '*'] >
|
||||||
< <class 'pymath.expression.Expression'> [3, 2, '*', 5, '/'] >
|
< <class 'pymath.calculus.expression.Expression'> [3, 2, '*', 5, '/'] >
|
||||||
< <class 'pymath.expression.Expression'> [6, 5, '/'] >
|
< <class 'pymath.calculus.expression.Expression'> [6, 5, '/'] >
|
||||||
>>> from .render import txt
|
>>> from .render import txt
|
||||||
>>> with Expression.tmp_render(txt):
|
>>> with Expression.tmp_render(txt):
|
||||||
... for i in exp.simplify().explain():
|
... for i in exp.simplify().explain():
|
@ -142,28 +142,28 @@ class Fraction(Explicable):
|
|||||||
>>> f + g
|
>>> f + g
|
||||||
< Fraction 7 / 6>
|
< Fraction 7 / 6>
|
||||||
>>> print("\\n".join([repr(i) for i in (f+g).steps]))
|
>>> print("\\n".join([repr(i) for i in (f+g).steps]))
|
||||||
< <class 'pymath.expression.Expression'> [1, 2, '/', 2, 3, '/', '+'] >
|
< <class 'pymath.calculus.expression.Expression'> [1, 2, '/', 2, 3, '/', '+'] >
|
||||||
< <class 'pymath.expression.Expression'> [1, 3, '*', 2, 3, '*', '/', 2, 2, '*', 3, 2, '*', '/', '+'] >
|
< <class 'pymath.calculus.expression.Expression'> [1, 3, '*', 2, 3, '*', '/', 2, 2, '*', 3, 2, '*', '/', '+'] >
|
||||||
< <class 'pymath.expression.Expression'> [3, 6, '/', 4, 6, '/', '+'] >
|
< <class 'pymath.calculus.expression.Expression'> [3, 6, '/', 4, 6, '/', '+'] >
|
||||||
< <class 'pymath.expression.Expression'> [< Fraction 3 / 6>, < Fraction 4 / 6>, '+'] >
|
< <class 'pymath.calculus.expression.Expression'> [< Fraction 3 / 6>, < Fraction 4 / 6>, '+'] >
|
||||||
< <class 'pymath.expression.Expression'> [3, 6, '/', 4, 6, '/', '+'] >
|
< <class 'pymath.calculus.expression.Expression'> [3, 6, '/', 4, 6, '/', '+'] >
|
||||||
< <class 'pymath.expression.Expression'> [3, 4, '+', 6, '/'] >
|
< <class 'pymath.calculus.expression.Expression'> [3, 4, '+', 6, '/'] >
|
||||||
>>> f + 2
|
>>> f + 2
|
||||||
< Fraction 5 / 2>
|
< Fraction 5 / 2>
|
||||||
>>> print("\\n".join([repr(i) for i in (f+2).steps]))
|
>>> print("\\n".join([repr(i) for i in (f+2).steps]))
|
||||||
< <class 'pymath.expression.Expression'> [1, 2, '/', 2, '+'] >
|
< <class 'pymath.calculus.expression.Expression'> [1, 2, '/', 2, '+'] >
|
||||||
< <class 'pymath.expression.Expression'> [1, 1, '*', 2, 1, '*', '/', 2, 2, '*', 1, 2, '*', '/', '+'] >
|
< <class 'pymath.calculus.expression.Expression'> [1, 1, '*', 2, 1, '*', '/', 2, 2, '*', 1, 2, '*', '/', '+'] >
|
||||||
< <class 'pymath.expression.Expression'> [1, 2, '/', 4, 2, '/', '+'] >
|
< <class 'pymath.calculus.expression.Expression'> [1, 2, '/', 4, 2, '/', '+'] >
|
||||||
< <class 'pymath.expression.Expression'> [< Fraction 1 / 2>, < Fraction 4 / 2>, '+'] >
|
< <class 'pymath.calculus.expression.Expression'> [< Fraction 1 / 2>, < Fraction 4 / 2>, '+'] >
|
||||||
< <class 'pymath.expression.Expression'> [1, 2, '/', 4, 2, '/', '+'] >
|
< <class 'pymath.calculus.expression.Expression'> [1, 2, '/', 4, 2, '/', '+'] >
|
||||||
< <class 'pymath.expression.Expression'> [1, 4, '+', 2, '/'] >
|
< <class 'pymath.calculus.expression.Expression'> [1, 4, '+', 2, '/'] >
|
||||||
>>> f = Fraction(3, 4)
|
>>> f = Fraction(3, 4)
|
||||||
>>> g = Fraction(5, 4)
|
>>> g = Fraction(5, 4)
|
||||||
>>> f + g
|
>>> f + g
|
||||||
2
|
2
|
||||||
>>> print("\\n".join([repr(i) for i in (f+g).steps]))
|
>>> print("\\n".join([repr(i) for i in (f+g).steps]))
|
||||||
< <class 'pymath.expression.Expression'> [3, 4, '/', 5, 4, '/', '+'] >
|
< <class 'pymath.calculus.expression.Expression'> [3, 4, '/', 5, 4, '/', '+'] >
|
||||||
< <class 'pymath.expression.Expression'> [3, 5, '+', 4, '/'] >
|
< <class 'pymath.calculus.expression.Expression'> [3, 5, '+', 4, '/'] >
|
||||||
>>> f+0
|
>>> f+0
|
||||||
< Fraction 3 / 4>
|
< Fraction 3 / 4>
|
||||||
>>> (f+0).steps
|
>>> (f+0).steps
|
||||||
@ -211,12 +211,12 @@ class Fraction(Explicable):
|
|||||||
>>> f - g
|
>>> f - g
|
||||||
< Fraction -1 / 6>
|
< Fraction -1 / 6>
|
||||||
>>> print("\\n".join([repr(i) for i in (f-g).steps]))
|
>>> print("\\n".join([repr(i) for i in (f-g).steps]))
|
||||||
< <class 'pymath.expression.Expression'> [1, 2, '/', 2, 3, '/', '-'] >
|
< <class 'pymath.calculus.expression.Expression'> [1, 2, '/', 2, 3, '/', '-'] >
|
||||||
< <class 'pymath.expression.Expression'> [1, 3, '*', 2, 3, '*', '/', 2, 2, '*', 3, 2, '*', '/', '-'] >
|
< <class 'pymath.calculus.expression.Expression'> [1, 3, '*', 2, 3, '*', '/', 2, 2, '*', 3, 2, '*', '/', '-'] >
|
||||||
< <class 'pymath.expression.Expression'> [3, 6, '/', 4, 6, '/', '-'] >
|
< <class 'pymath.calculus.expression.Expression'> [3, 6, '/', 4, 6, '/', '-'] >
|
||||||
< <class 'pymath.expression.Expression'> [< Fraction 3 / 6>, < Fraction 4 / 6>, '-'] >
|
< <class 'pymath.calculus.expression.Expression'> [< Fraction 3 / 6>, < Fraction 4 / 6>, '-'] >
|
||||||
< <class 'pymath.expression.Expression'> [3, 6, '/', 4, 6, '/', '-'] >
|
< <class 'pymath.calculus.expression.Expression'> [3, 6, '/', 4, 6, '/', '-'] >
|
||||||
< <class 'pymath.expression.Expression'> [3, 4, '-', 6, '/'] >
|
< <class 'pymath.calculus.expression.Expression'> [3, 4, '-', 6, '/'] >
|
||||||
>>> f - 0
|
>>> f - 0
|
||||||
< Fraction 1 / 2>
|
< Fraction 1 / 2>
|
||||||
>>> (f-0).steps
|
>>> (f-0).steps
|
||||||
@ -269,7 +269,7 @@ class Fraction(Explicable):
|
|||||||
>>> -f
|
>>> -f
|
||||||
< Fraction 1 / 2>
|
< Fraction 1 / 2>
|
||||||
>>> (-f).steps
|
>>> (-f).steps
|
||||||
[< <class 'pymath.expression.Expression'> [-1, -2, '/'] >]
|
[< <class 'pymath.calculus.expression.Expression'> [-1, -2, '/'] >]
|
||||||
|
|
||||||
"""
|
"""
|
||||||
f = Fraction(-self._num, self._denom)
|
f = Fraction(-self._num, self._denom)
|
||||||
@ -285,11 +285,11 @@ class Fraction(Explicable):
|
|||||||
>>> f*g
|
>>> f*g
|
||||||
< Fraction 1 / 3>
|
< Fraction 1 / 3>
|
||||||
>>> print("\\n".join([repr(i) for i in (f*g).steps]))
|
>>> print("\\n".join([repr(i) for i in (f*g).steps]))
|
||||||
< <class 'pymath.expression.Expression'> [1, 2, '/', 2, 3, '/', '*'] >
|
< <class 'pymath.calculus.expression.Expression'> [1, 2, '/', 2, 3, '/', '*'] >
|
||||||
< <class 'pymath.expression.Expression'> [1, 1, 2, '*', '*', 1, 2, '*', 3, '*', '/'] >
|
< <class 'pymath.calculus.expression.Expression'> [1, 1, 2, '*', '*', 1, 2, '*', 3, '*', '/'] >
|
||||||
< <class 'pymath.expression.Expression'> [1, 2, '*', 2, 3, '*', '/'] >
|
< <class 'pymath.calculus.expression.Expression'> [1, 2, '*', 2, 3, '*', '/'] >
|
||||||
< <class 'pymath.expression.Expression'> [2, 6, '/'] >
|
< <class 'pymath.calculus.expression.Expression'> [2, 6, '/'] >
|
||||||
< <class 'pymath.expression.Expression'> [1, 2, '*', 3, 2, '*', '/'] >
|
< <class 'pymath.calculus.expression.Expression'> [1, 2, '*', 3, 2, '*', '/'] >
|
||||||
>>> f * 0
|
>>> f * 0
|
||||||
0
|
0
|
||||||
>>> (f*0).steps
|
>>> (f*0).steps
|
||||||
@ -301,9 +301,9 @@ class Fraction(Explicable):
|
|||||||
>>> f*4
|
>>> f*4
|
||||||
2
|
2
|
||||||
>>> print("\\n".join([repr(i) for i in (f*4).steps]))
|
>>> print("\\n".join([repr(i) for i in (f*4).steps]))
|
||||||
< <class 'pymath.expression.Expression'> [1, 2, '/', 4, '*'] >
|
< <class 'pymath.calculus.expression.Expression'> [1, 2, '/', 4, '*'] >
|
||||||
< <class 'pymath.expression.Expression'> [1, 2, '*', 2, '*', 1, 2, '*', '/'] >
|
< <class 'pymath.calculus.expression.Expression'> [1, 2, '*', 2, '*', 1, 2, '*', '/'] >
|
||||||
< <class 'pymath.expression.Expression'> [2, 2, '*', 2, '/'] >
|
< <class 'pymath.calculus.expression.Expression'> [2, 2, '*', 2, '/'] >
|
||||||
|
|
||||||
"""
|
"""
|
||||||
steps = []
|
steps = []
|
||||||
@ -409,16 +409,16 @@ class Fraction(Explicable):
|
|||||||
>>> f**3
|
>>> f**3
|
||||||
< Fraction 27 / 64>
|
< Fraction 27 / 64>
|
||||||
>>> print("\\n".join([repr(i) for i in (f**3).steps]))
|
>>> print("\\n".join([repr(i) for i in (f**3).steps]))
|
||||||
< <class 'pymath.expression.Expression'> [3, 4, '/', 3, '^'] >
|
< <class 'pymath.calculus.expression.Expression'> [3, 4, '/', 3, '^'] >
|
||||||
< <class 'pymath.expression.Expression'> [3, 3, '^', 4, 3, '^', '/'] >
|
< <class 'pymath.calculus.expression.Expression'> [3, 3, '^', 4, 3, '^', '/'] >
|
||||||
>>> f = Fraction(6, 4)
|
>>> f = Fraction(6, 4)
|
||||||
>>> f**3
|
>>> f**3
|
||||||
< Fraction 27 / 8>
|
< Fraction 27 / 8>
|
||||||
>>> print("\\n".join([repr(i) for i in (f**3).steps]))
|
>>> print("\\n".join([repr(i) for i in (f**3).steps]))
|
||||||
< <class 'pymath.expression.Expression'> [6, 4, '/', 3, '^'] >
|
< <class 'pymath.calculus.expression.Expression'> [6, 4, '/', 3, '^'] >
|
||||||
< <class 'pymath.expression.Expression'> [6, 3, '^', 4, 3, '^', '/'] >
|
< <class 'pymath.calculus.expression.Expression'> [6, 3, '^', 4, 3, '^', '/'] >
|
||||||
< <class 'pymath.expression.Expression'> [216, 64, '/'] >
|
< <class 'pymath.calculus.expression.Expression'> [216, 64, '/'] >
|
||||||
< <class 'pymath.expression.Expression'> [27, 8, '*', 8, 8, '*', '/'] >
|
< <class 'pymath.calculus.expression.Expression'> [27, 8, '*', 8, 8, '*', '/'] >
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not type(power) == int:
|
if not type(power) == int:
|
@ -314,7 +314,7 @@ def isPolynom(exp):
|
|||||||
:param exp: an expression
|
:param exp: an expression
|
||||||
:returns: True if the expression can be a polynom and false otherwise
|
:returns: True if the expression can be a polynom and false otherwise
|
||||||
|
|
||||||
>>> from pymath.polynom import Polynom
|
>>> from pymath.calculus.polynom import Polynom
|
||||||
>>> p = Polynom([1,2])
|
>>> p = Polynom([1,2])
|
||||||
>>> isPolynom(p)
|
>>> isPolynom(p)
|
||||||
1
|
1
|
||||||
@ -335,11 +335,11 @@ def isNumerand(exp):
|
|||||||
|
|
||||||
>>> isNumerand(1)
|
>>> isNumerand(1)
|
||||||
1
|
1
|
||||||
>>> from pymath.polynom import Polynom
|
>>> from pymath.calculus.polynom import Polynom
|
||||||
>>> p = Polynom([1,2])
|
>>> p = Polynom([1,2])
|
||||||
>>> isNumerand(p)
|
>>> isNumerand(p)
|
||||||
1
|
1
|
||||||
>>> from pymath.fraction import Fraction
|
>>> from pymath.calculus.fraction import Fraction
|
||||||
>>> f = Fraction(12)
|
>>> f = Fraction(12)
|
||||||
>>> isNumerand(f)
|
>>> isNumerand(f)
|
||||||
1
|
1
|
@ -58,15 +58,15 @@ class Polynom(AbstractPolynom):
|
|||||||
/!\ variables need to be in brackets {}
|
/!\ variables need to be in brackets {}
|
||||||
|
|
||||||
>>> Polynom.random(["{b}", "{a}"]) # doctest:+ELLIPSIS
|
>>> Polynom.random(["{b}", "{a}"]) # doctest:+ELLIPSIS
|
||||||
< <class 'pymath.polynom.Polynom'> ...
|
< <class 'pymath.calculus.polynom.Polynom'> ...
|
||||||
>>> Polynom.random(degree = 2) # doctest:+ELLIPSIS
|
>>> Polynom.random(degree = 2) # doctest:+ELLIPSIS
|
||||||
< <class 'pymath.polynomDeg2.Polynom_deg2'> ...
|
< <class 'pymath.calculus.polynomDeg2.Polynom_deg2'> ...
|
||||||
>>> Polynom.random(degree = 3) # doctest:+ELLIPSIS
|
>>> Polynom.random(degree = 3) # doctest:+ELLIPSIS
|
||||||
< <class 'pymath.polynom.Polynom'> ...
|
< <class 'pymath.calculus.polynom.Polynom'> ...
|
||||||
>>> Polynom.random(degree = 2, conditions=["{b**2-4*a*c}>0"]) # Polynom deg 2 with positive Delta (ax^2 + bx + c)
|
>>> Polynom.random(degree = 2, conditions=["{b**2-4*a*c}>0"]) # Polynom deg 2 with positive Delta (ax^2 + bx + c)
|
||||||
< <class 'pymath.polynomDeg2.Polynom_deg2'> ...
|
< <class 'pymath.calculus.polynomDeg2.Polynom_deg2'> ...
|
||||||
>>> Polynom.random(["{c}", "{b}", "{a}"], conditions=["{b**2-4*a*c}>0"]) # Same as above
|
>>> Polynom.random(["{c}", "{b}", "{a}"], conditions=["{b**2-4*a*c}>0"]) # Same as above
|
||||||
< <class 'pymath.polynomDeg2.Polynom_deg2'> ...
|
< <class 'pymath.calculus.polynomDeg2.Polynom_deg2'> ...
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if (degree > 0 and degree < 26):
|
if (degree > 0 and degree < 26):
|
||||||
@ -151,7 +151,7 @@ class Polynom(AbstractPolynom):
|
|||||||
>>> P = Polynom([1, 2, 3])
|
>>> P = Polynom([1, 2, 3])
|
||||||
>>> Q = P.derivate()
|
>>> Q = P.derivate()
|
||||||
>>> Q
|
>>> Q
|
||||||
< <class 'pymath.polynom.Polynom'> [2, 6]>
|
< <class 'pymath.calculus.polynom.Polynom'> [2, 6]>
|
||||||
>>> print(Q.name)
|
>>> print(Q.name)
|
||||||
P'
|
P'
|
||||||
>>> for i in Q.explain():
|
>>> for i in Q.explain():
|
@ -2,7 +2,7 @@
|
|||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
from .generic import Stack, isOperator, isNumber, isPolynom
|
from .generic import Stack, isOperator, isNumber, isPolynom
|
||||||
from pymath.operator import op
|
from .operator import op
|
||||||
|
|
||||||
def str2tokens(exp):
|
def str2tokens(exp):
|
||||||
""" Parse the string into tokens then turn it into postfix form
|
""" Parse the string into tokens then turn it into postfix form
|
||||||
@ -12,7 +12,7 @@ def str2tokens(exp):
|
|||||||
>>> str2tokens('2*3+4')
|
>>> str2tokens('2*3+4')
|
||||||
[2, 3, '*', 4, '+']
|
[2, 3, '*', 4, '+']
|
||||||
>>> str2tokens('2x+4')
|
>>> str2tokens('2x+4')
|
||||||
[2, < <class 'pymath.polynom.Polynom'> [0, 1]>, '*', 4, '+']
|
[2, < <class 'pymath.calculus.polynom.Polynom'> [0, 1]>, '*', 4, '+']
|
||||||
"""
|
"""
|
||||||
in_tokens = str2in_tokens(exp)
|
in_tokens = str2in_tokens(exp)
|
||||||
post_tokens = in2post_fix(in_tokens)
|
post_tokens = in2post_fix(in_tokens)
|
||||||
@ -71,7 +71,7 @@ def str2in_tokens(exp):
|
|||||||
or tokens[-1] == ")" \
|
or tokens[-1] == ")" \
|
||||||
or isPolynom(tokens[-1]):
|
or isPolynom(tokens[-1]):
|
||||||
tokens.append("*")
|
tokens.append("*")
|
||||||
from pymath.polynom import Polynom
|
from pymath.calculus.polynom import Polynom
|
||||||
tokens.append(Polynom([0,1], letter = character))
|
tokens.append(Polynom([0,1], letter = character))
|
||||||
|
|
||||||
elif character == ".":
|
elif character == ".":
|
Loading…
Reference in New Issue
Block a user