Skip to content

CSE does not make use of previously found subexpressions when calculating new ones #745

@baggepinnen

Description

@baggepinnen

Consider the following result of calling cse, the expression (sin)(ˍ₋arg1[2]) appears as the second found subexpression, but this subex also appears in the first and third expressions. SymPy does the obvious thing here and makes (sin)(ˍ₋arg1[2]) the first subexpression and then uses this inside the others to make subexpressions progressively more complicated.

let var"var-160695432240896814761" = (+)(
        (*)(1.9620000000000002, (sin)(ˍ₋arg1[2])),
        (*)((*)(-0.16666666666666669, (+)((*)(-1, ˍ₋arg2[1]), (*)((*)(-0.1, (^)(ˍ₋arg1[4], 2)), (sin)(ˍ₋arg1[2])))), (cos)(ˍ₋arg1[2])),
    ),
    var"var-160695432240896814762" = (sin)(ˍ₋arg1[2]),
    var"var-160695432240896814763" = (/)(
        (+)(
            (+)((*)(0.9810000000000001, (cos)(ˍ₋arg1[2])), (*)((*)(0.008333333333333335, (^)(ˍ₋arg1[4], 2)), (^)((cos)(ˍ₋arg1[2]), 2))),
            (*)(
                (*)(-1, (+)((*)(0.08333333333333334, ˍ₋arg2[1]), (*)((*)(0.008333333333333335, (^)(ˍ₋arg1[4], 2)), (sin)(ˍ₋arg1[2])))),
                (sin)(ˍ₋arg1[2]),
            ),
        ),
        (^)((+)(-0.05, (*)(0.008333333333333335, (^)((cos)(ˍ₋arg1[2]), 2))), 2),
    ),

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions