Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.

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.

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.