Fix for Issue #1133 with Test#1136
Conversation
|
@isuruf ping. |
|
Can you add some examples like |
|
@certik @isuruf I'm on it. Edit 2: Using str printer: @isuruf |
|
@ShikharJ, with this, I think |
|
@isuruf Indeed, |
|
@isuruf A review? |
certik
left a comment
There was a problem hiding this comment.
Otherwise it looks good to me.
symengine/printer.cpp
Outdated
| s2 = s2.substr(0, s2.size() - 1); | ||
| if (den > 1) { | ||
| str_ = s + "/(" + s2 + ")"; | ||
| } else if (s2[0] == 'e' and s2[1] == 'x' and s2[2] == 'p') { |
There was a problem hiding this comment.
Can this run out of bounds if len(s2) < 3?
There was a problem hiding this comment.
Cannot this be written simply as s2.substr(3) == "exp"?
|
@certik Using s2.substr(3) == "exp" is setting off errors in other tests: |
|
Post the output of |
|
|
I see, the line should have been: s2.substr(0, 3) == "exp"See http://en.cppreference.com/w/cpp/string/basic_string/substr |
symengine/printer.cpp
Outdated
| if (den > 1) { | ||
| str_ = s + "/(" + s2 + ")"; | ||
| } else if (s2.substr(0, 3) == "exp") { | ||
| str_ = s + "*" + s2; |
There was a problem hiding this comment.
This logic will fail when it's something like exp(-1)/x
symengine/printer.cpp
Outdated
| || (is_a<Rational>(*p.second) | ||
| and rcp_static_cast<const Rational>(p.second)->is_negative())) { | ||
| if (eq(*(p.second), *minus_one)) { | ||
| if (eq(*(p.second), *minus_one) and neq(*(p.first), *E)) { |
There was a problem hiding this comment.
You need to use this check in the if statement in line no. 362. Then all the other changes below are not needed.
symengine/printer.cpp
Outdated
|
|
||
| for (const auto &p : x.dict_) { | ||
| if ((is_a<Integer>(*p.second) | ||
| if ((is_a<Integer>(*p.second) and neq(*(p.first), *E) |
There was a problem hiding this comment.
This should be for the whole || not just integer condition.
There was a problem hiding this comment.
@isuruf Like this?
if (((is_a<Integer>(*p.second)
and rcp_static_cast<const Integer>(p.second)->is_negative())
|| (is_a<Rational>(*p.second)
and rcp_static_cast<const Rational>(p.second)->is_negative())) and neq(*(p.first), *E))
There was a problem hiding this comment.
Yes, you can simplify this a bit by doing,
if ((is_a<Integer>(*p.second) or is_a<Rational>(*p.second)) and static_cast<const Number &>(*p.second).is_negative() and neq(*p.first, *E))
symengine/printer.cpp
Outdated
| if (eq(*b, *rational(1, 2))) { | ||
| if (eq(*b, *rational(1, 2)) and neq(*a, *E)) { | ||
| o << "sqrt(" << apply(a) << ")"; | ||
| } else if (eq(*a, *E)) { |
There was a problem hiding this comment.
Can you make this the first condition, so that it is simpler ?
Additional Fix using substr() Incorporated Suggestions Corrections Fix for Negative Exponents and Additional Changes
Please suggest any necessary changes if required.
Fixes #1133