replace letter in abstact_poly and minor change in polynom

This commit is contained in:
Benjamin Bertrand 2016-03-09 09:27:47 +03:00
parent b1c4860964
commit e02687c91b
2 changed files with 27 additions and 6 deletions

View File

@ -426,6 +426,31 @@ class AbstractPolynom(Explicable):
ans.this_append_before(steps)
return ans
def replace_letter(self, letter):
""" Replace the letter in the expression
:param letter: the new letter.
:returns: The expression with the new letter.
>>> A = AbstractPolynom([1, 2])
>>> A
< AbstractPolynom x [1, 2]>
>>> B = A.replace_letter("y")
>>> B
< Expression [2, < Polynom y [0, 1]>, *, 1, +]>
>>> C = A.replace_letter(2)
>>> C
< Expression [2, 2, *, 1, +]>
"""
postfix_exp = [
Expression(letter) if i == self._letter
else i
for i in self.postfix_tokens
]
return Expression(postfix_exp)
def __eq__(self, other):
try:
o_poly = self.conv2poly(other)

View File

@ -147,13 +147,9 @@ class Polynom(AbstractPolynom):
3 h^{ 2 } + 8 h + 6
>>> R = P(Q)
"""
postfix_exp = [
Expression(value) if i == self._letter
else i
for i in self.postfix_tokens
]
eval_exp = self.replace_letter(value)
return Expression(postfix_exp).simplify()
return eval_exp.simplify()
def derivate(self):
""" Return the derivated polynom