These are chat archives for symengine/symengine

2nd
Jun 2014
Ondřej Čertík
@certik
Jun 02 2014 17:05
hi
Sushant Hiray
@sushant-hiray
Jun 02 2014 17:05
hey!
Ondřej Čertík
@certik
Jun 02 2014 17:07
is your question regarding the 1/sqrt(2)?
Sushant Hiray
@sushant-hiray
Jun 02 2014 17:07
yeap!
Ondřej Čertík
@certik
Jun 02 2014 17:07
I think I commented on the issue, essentially we have to do the same as sympy does
Sushant Hiray
@sushant-hiray
Jun 02 2014 17:08
i was just confirming with @thilinarmtb if he was facing the same issue
Ondřej Čertík
@certik
Jun 02 2014 17:09
I am trying to find the place in sympy which does this simplification
I think it happens in Mul.flatten
Aaron Meurer
@asmeurer
Jun 02 2014 17:13
it would be in Pow
1/sqrt(2) is not a Mul
Mul.flatten does do stuff like that though. like `sqrt(8)` -> `2*sqrt(2)`
Ondřej Čertík
@certik
Jun 02 2014 17:14
@asmeurer right. But 2/sqrt(2) is a mul
Aaron Meurer
@asmeurer
Jun 02 2014 17:15
I think it is `Integer._eval_power`
Ondřej Čertík
@certik
Jun 02 2014 17:15
so `2**(-1/2)` returns `2**(1/2) / 2`
Aaron Meurer
@asmeurer
Jun 02 2014 17:16
there is also logic in Mul.flatten as you say, but Integer._eval_power is what inverts square roots in the denominator
``````        if expt.is_negative:
# invert base and change sign on exponent
ne = -expt
if self.is_negative:
if expt.q != 1:
return -(S.NegativeOne)**((expt.p % expt.q) /
S(expt.q))*Rational(1, -self)**ne
else:
return (S.NegativeOne)**ne*Rational(1, -self)**ne
else:
return Rational(1, self.p)**ne``````
Ondřej Čertík
@certik
Jun 02 2014 17:16
Yes, that's it. thanks!
Aaron Meurer
@asmeurer
Jun 02 2014 17:16
from line 1760 in numbers.py
Ondřej Čertík
@certik
Jun 02 2014 17:18
@asmeurer do you know when `_eval_power` is called in sympy?
@sushant-hiray so it seems to me that Pow::is_canonical() should have a check, that you never have things like `2**(-1/2)`, but only positive exponents. That will raise an exception if this expression every creeps into csympy. Finally we need to add the logic that @asmeurer posted, and I think it needs to go into the `pow` function.
I.e. this function needs to be extended:
``````RCP<const Basic> pow(const RCP<const Basic> &a, const RCP<const Basic> &b)
{
if (eq(b, zero)) return one;
if (eq(b, one)) return a;
if (eq(a, zero)) return zero;
if (eq(a, one)) return one;
if (is_a_Number(*a) && is_a<Integer>(*b))
return pownum(rcp_static_cast<const Number>(a), rcp_static_cast<const Integer>(b));
if (is_a<Mul>(*a))
return rcp_static_cast<const Mul>(a)->power_all_terms(b);
if (is_a<Pow>(*a)) {
RCP<const Pow> A = rcp_static_cast<const Pow>(a);
return pow(A->base_, mul(A->exp_, b));
}
return rcp(new Pow(a, b));
}``````
Sushant Hiray
@sushant-hiray
Jun 02 2014 17:27
@certik sure I'll look into it and put a fix!
@asmeurer thanks :smile:
Ondřej Čertík
@certik
Jun 02 2014 17:31
@sushant-hiray you are doing great work, thanks for reporting all these issues and fixing them. That's tremendously useful.
Sushant Hiray
@sushant-hiray
Jun 02 2014 17:32
happy to help! :smile:
Ondřej Čertík
@certik
Jun 02 2014 17:32
My apologies for being a bit busy. Once I have some time, hopefully next week, I'll update the Python wrappers so that we can use your new functionality from Python and we can ask people to test it out.
Also I'll create Conda and Hashdist packages for csympy, so that it's easy to install.
Sushant Hiray
@sushant-hiray
Jun 02 2014 17:33
That'll be great!
Ondřej Čertík
@certik
Jun 02 2014 17:34
That way we'll get some feedback, and I am sure more issues will pop up. Now when the basic trig functions are in, what are your next plans?
Sushant Hiray
@sushant-hiray
Jun 02 2014 17:36
As per the proposal I had decided to work on an exponential module something similar to `exponential.py`
Ondřej Čertík
@certik
Jun 02 2014 17:36
@asmeurer --- csympy is by default build in a release mode, which is fast, but there are no checks (no asserts). I would like to also add a package to conda, that enables all these checks, and that is important just to make sure no asserts are ever triggered, sort of like the debug build of Python. I assume the best way is to simply create two separate packages, one called csympy, the other csympy-debug?
@sushant-hiray yes, that's a good plan