Ask Your Question
2

Simplify shenanigans

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

bolverk gravatar image

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

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

2 Answers

Sort by ยป oldest newest most voted
1

answered 2013-05-18 08:08:20 +0100

Volker Braun gravatar image

I made #14608 to track this error.

edit flag offensive delete link more
1

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

tmonteil gravatar image

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

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).

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

Stats

Asked: 2013-05-18 02:48:32 +0100

Seen: 698 times

Last updated: May 18 '13