These are chat archives for symengine/symengine

26th
May 2017
Ranjith Kumar
@ranjithkumar007
May 26 2017 10:21
@isuruf , Can you have a look at #1274 .
Shikhar Jaiswal
@ShikharJ
May 26 2017 16:44

@isuruf In order to implement SymPy's reversed(self) function, I need to take an Inequality sub-class and swap its arguments and type. Would you prefer a templatized function like this:

template<typename T>
    const T reversed() const
    {
        SYMENGINE_ASSERT(is_a_Inequality(*this));
        const RCP<const Basic> &lhs = (this->get_lhs());
        const RCP<const Basic> &rhs = (this->get_rhs());
        if (is_a<StrictGreaterThan>(*this))
            return StrictLessThan(rhs, lhs);
        else if (is_a<GreaterThan>(*this))
            return LessThan(rhs, lhs);
        else if (is_a<StrictLessThan>(*this))
            return StrictGreaterThan(rhs, lhs);
        else
            return GreaterThan(rhs, lhs);
    }

or a virtual method instead?

Isuru Fernando
@isuruf
May 26 2017 16:45
virtual method is better
Shikhar Jaiswal
@ShikharJ
May 26 2017 16:47
Just out of curiosity, are we doing this because of speed improvements, or is there any other benefit as well?
Isuru Fernando
@isuruf
May 26 2017 16:47
makes the code readable
Shikhar Jaiswal
@ShikharJ
May 26 2017 18:52
@isuruf Will an implementation like this be safe?
const Equality &Equality::reversed() const
    {
        const Equality &e = Equality(get_rhs(), get_lhs());
        return e;
    }