replace_letter now steal the history of the letter.

This commit is contained in:
Benjamin Bertrand 2016-03-09 10:00:36 +03:00
parent e02687c91b
commit 6428ab2c9e
1 changed files with 17 additions and 2 deletions

View File

@ -441,15 +441,30 @@ class AbstractPolynom(Explicable):
>>> C = A.replace_letter(2)
>>> C
< Expression [2, 2, *, 1, +]>
>>> e = Expression('2+3').simplify()
>>> D = A.replace_letter(e)
>>> D
< Expression [2, 5, *, 1, +]>
>>> for i in D.explain():
... print(i)
2 ( 2 + 3 ) + 1
2 \times 5 + 1
"""
exp_to_replace = Expression(letter)
exp_to_replace.steal_history(letter)
postfix_exp = [
Expression(letter) if i == self._letter
exp_to_replace if i == self._letter
else i
for i in self.postfix_tokens
]
ini_step = Expression.develop_steps(postfix_exp)
return Expression(postfix_exp)
ans = Expression(postfix_exp)
ans.this_append_before(ini_step)
return ans
def __eq__(self, other):
try: