Import Step in smpl_abspoly refact

This commit is contained in:
Benjamin Bertrand
2016-03-10 13:27:08 +03:00
parent 219037e87a
commit 9a11549cc1
3 changed files with 97 additions and 134 deletions

View File

@@ -16,43 +16,6 @@ from .random_expression import RdExpression
__all__ = ['Expression']
# def pstf_factory(pstf_tokens):
# """Factory which tranform postfix tokens list into an Expression or the simpliest object type ready to be rendered
#
# :param pstf_tokens: a postfix tokens list
# :returns: the object
#
# >>> from .operator import op
# >>> pstf_t = [2, 3, op.add]
# >>> pstf_factory(pstf_t)
# < Expression [2, 3, +]>
# >>> pstf_factory([2])
# 2
# >>> type(pstf_factory([2]))
# <class 'pymath.calculus.explicable.Explicable_int'>
# >>> pstf_factory([2.45])
# Decimal('2.45')
# >>> type(pstf_factory([2.45]))
# <class 'pymath.calculus.explicable.Explicable_Decimal'>
# >>> from .fraction import Fraction
# >>> f = Fraction(1,2)
# >>> pstf_factory([f])
# < Fraction 1 / 2>
#
# """
# if len(pstf_tokens) == 1:
# if isinstance(pstf_tokens[0], int):
# return Explicable_int(pstf_tokens[0])
# elif isinstance(pstf_tokens[0], Decimal):
# return Explicable_Decimal(pstf_tokens[0])
# elif isinstance(pstf_tokens[0], float):
# return Explicable_Decimal(Decimal(str(pstf_tokens[0])))
# elif hasattr(pstf_tokens[0], 'STR_RENDER'):
# return pstf_tokens[0]
#
# return Expression(pstf_tokens)
class Expression(Explicable):
"""A calculus expression. Today it can andle only expression with numbers later it will be able to manipulate unknown"""
@@ -69,44 +32,6 @@ class Expression(Explicable):
random_generator = RdExpression(form, conditions)
return Expression(random_generator(val_min, val_max))
# @classmethod
# def tmp_render(cls, render=lambda _, x: pstf_factory(x)):
# """ Same ad tmp_render for Renderable but default render is Expression
# >>> exp = Expression("2*3/5")
# >>> print(exp)
# 2 \\times \\frac{ 3 }{ 5 }
# >>> for i in exp.simplify().explain():
# ... print(i)
# 2 \\times \\frac{ 3 }{ 5 }
# \\frac{ 3 }{ 5 } \\times 2
# \\frac{ 3 \\times 2 }{ 5 }
# \\frac{ 6 }{ 5 }
# >>> with Expression.tmp_render():
# ... for i in exp.simplify().explain():
# ... i
# < Expression [2, 3, 5, /, *]>
# < Expression [2, < Fraction 3 / 5>, *]>
# < Expression [< Fraction 3 / 5>, 2, *]>
# < Expression [3, 2, *, 5, /]>
# < Expression [6, 5, /]>
# >>> from .render import txt
# >>> with Expression.tmp_render(txt):
# ... for i in exp.simplify().explain():
# ... print(i)
# 2 * 3 / 5
# 3 / 5 * 2
# ( 3 * 2 ) / 5
# 6 / 5
# >>> for i in exp.simplify().explain():
# ... print(i)
# 2 \\times \\frac{ 3 }{ 5 }
# \\frac{ 3 }{ 5 } \\times 2
# \\frac{ 3 \\times 2 }{ 5 }
# \\frac{ 6 }{ 5 }
# """
# return super(Expression, cls).tmp_render(render)
def __init__(self, exp):
"""Create Expression objects