Skip to content

cse does not seem to handle Piecewise well? #1952

@bjodah

Description

@bjodah

Consider this example:

auto x = symbol("x");                                                                                                                                                  
auto y = symbol("y");                                                                                                                                                  
auto i2 = integer(2);                                                                                                                                                  
// test cse within piecewise                                                                                                                                           
auto pw1 = piecewise({                                                                                                                                                 
    {pow(add(x, y), i2), Gt(x, y)},                                                                                                                                    
    {sqrt(add(x, y)), boolTrue}                                                                                                                                        
});                                                                                                                                                                    
                                                                                                                                                                       
vec_pair substs;                                                                                                                                                       
vec_basic reduced;                                                                                                                                                     
cse(substs, reduced, {pw1});                                                                                                                                           
std::cout << "substs.size() = " << substs.size() << std::endl;   

prints:

substs.size() = 0

I've tried stepping through the code in the debugger but couldn't quite figure out why it isn't identifying x+y as a common subexpression (I do find it hard to debug using gdb/lldb compared to e.g. Java or Python: many operators on standard containers e.g. [] seem to get inlined even with -DCMAKE_BUILD_TYPE=Debug)

Has anyone else experienced this/have any insight?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions