# Simplify shenanigans

I've noticed a strange (and annoying) behaviour in sage concerning symbolic substitution and simplification

def demonstrate_simplify_shenanigans():

sym_func = function('func',nargs=1)

my_expression = sym_func(0)+sym_func(1)+sym_func(2)

print
print 'without simplify'
print my_expression.subs(func(0)==1)

print
print 'with simplify in expression'
print my_expression.simplify().subs(func(0)==1)

print
print 'with simplify in both expression and substitution'
print my_expression.simplify().subs(func(0).simplify()==1)

demonstrate_simplify_shenanigans()


The output is

without simplify
func(1) + func(2) + 1

with simplify in expression
func(0) + func(1) + func(2)

with simplify in both expression and substitution
func(1) + func(2) + 1


Why is there a different behaviour depending on whether simplify was called? Even though func(0) and func(0).simplify() seem identical.

edit retag close merge delete

Sort by » oldest newest most voted

I made #14608 to track this error.

more

No idea. It may worth noticing that though:

sage: bool(func(0) == func(0).simplify())
True


Something inside the object is modified:

sage: hash(func(0)) == hash(func(0).simplify())
False

sage: hash(cos(x)) == hash(cos(x).simplify())
True


Which may explain why the method .subs() is not able to recognize that func(0).simplify() is the same as func(0).

more