Ask Your Question

Simplify shenanigans

asked 2013-05-17 19:48:32 -0600

bolverk gravatar image

updated 2014-01-24 02:07:07 -0600

tmonteil gravatar image

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 'without simplify'
    print my_expression.subs(func(0)==1)

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

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


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 flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2013-05-18 00:02:45 -0600

tmonteil gravatar image

updated 2013-05-18 00:08:53 -0600

No idea. It may worth noticing that though:

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

Something inside the object is modified:

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

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

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

edit flag offensive delete link more

answered 2013-05-18 01:08:20 -0600

Volker Braun gravatar image

I made #14608 to track this error.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-05-17 19:48:32 -0600

Seen: 251 times

Last updated: May 18 '13