Ask Your Question

Simplify shenanigans

asked 2013-05-18 02:48:32 +0200

bolverk gravatar image

updated 2023-01-09 23:59:31 +0200

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 08:08:20 +0200

Volker Braun gravatar image

I made #14608 to track this error.

edit flag offensive delete link more

answered 2013-05-18 07:02:45 +0200

tmonteil gravatar image

updated 2013-05-18 07:08:53 +0200

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

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-18 02:48:32 +0200

Seen: 606 times

Last updated: May 18 '13