These are chat archives for symengine/symengine

20th
Apr 2018
Isuru Fernando
@isuruf
Apr 20 2018 01:28
@tgn3000, other than replacing, not really
xreplace
Gary Tan
@tgn3000
Apr 20 2018 01:32
I am coding a recursive function that checks if a MUL object has arguments like sqrt(Integer). If so, get factors of those integers, modify the arguments of that MUL, and then re-evaluate
Isuru Fernando
@isuruf
Apr 20 2018 01:33
Have a look at TransformVisitor
Might make your implementation easier
I don't mind factoring small integers. SymPy should have some heuristics about when to factor or not. For example,
In [178]: from sympy import *

In [179]: sqrt(179425033*179424977*179425033)
Out[179]: sqrt(5776289731703764901649953)

In [180]: sqrt(5*5*2)
Out[180]: 5*sqrt(2)
Gary Tan
@tgn3000
Apr 20 2018 01:38
Yeah, you pointed me to that before. It works in some cases, but when it comes to doing some big modifications of some subexpressions, I don't know how to use TransformVisitor properly.
like I once wanted to expand sin(sin(x+y)+sin(z+w)) to something like sin(sin(x)*cos(y))*cos(sin(z)*cos(w)) + ......
Isuru Fernando
@isuruf
Apr 20 2018 01:41
SymPy already has expand_trig that does this. We'd love to have such functionality. Maybe as a flag to expand
Gary Tan
@tgn3000
Apr 20 2018 01:44
I see. Before then it seems that recursing with args I could see better what's going on inside. With TransformVisitor I have less control though...... Maybe I don't quite understand how to make the most of TransformVisitor yet.
Gary Tan
@tgn3000
Apr 20 2018 03:58
BTW, how to initialize RCP<const Integer> with mpz_t?
Isuru Fernando
@isuruf
Apr 20 2018 04:00
integer(integer_class(a))
Gary Tan
@tgn3000
Apr 20 2018 04:02
wow, cool! Thanks!