[sympy] Re: pattern replacement for complex numbers and manual factorization

2014-06-06 Thread F. B.
As you have a string representation of your object, a non-sympy way is by using string regex: In [1]: expr = eval(Add(Mul(Integer(-1), Integer(2), Symbol('g'), Symbol('psi^ss_1'), conjugate(Symbol('psi^ss_1'))), Mul(Integer(-1), Integer(2), Symbol('g'), Symbol('psi^ss_2'),

[sympy] Re: pattern replacement for complex numbers and manual factorization

2014-06-06 Thread F. B.
A better alternative: In [1]: from sympy import * In [2]: expr = eval(Add(Mul(Integer(-1), Integer(2), Symbol('g'), Symbol('psi^ss_1'), conjugate(Symbol('psi^ss_1'))), Mul(Integer(-1), Integer(2), Symbol('g'), Symbol('psi^ss_2'), conjugate(Symbol('psi^ss_2'))), Symbol('omega_2'),

[sympy] Re: New user question: Expanding quotients of complex numbers

2014-06-06 Thread F. B.
On Friday, June 6, 2014 2:36:34 AM UTC+2, jeanbi...@gmail.com wrote: var('A,B,C,D,u,v,qi,qf') qi = 1/(u-I*v) qf = (A+B/qi)/(C+D/qi) First of all, you don't need to declare *qi* and *qf* in var( ... ), because they get overwritten in the next expressions. By the way, maybe you mean that

[sympy] Re: pattern replacement for complex numbers and manual factorization

2014-06-06 Thread Andrei Berceanu
Tnx! I think there is an error in the line (unbalanced paranthesis): return node.xreplace ({e: S.One, conjugate(e): S.One})*abs(e)**2) Also, do you know how I can force the factorization of the 2*g to get 2*g(|psi1|**2 + |psi2|**2)? On Friday, June 6, 2014 10:45:37 AM UTC+2, F. B. wrote: A

[sympy] Re: pattern replacement for complex numbers and manual factorization

2014-06-06 Thread F. B.
On Friday, June 6, 2014 12:22:14 PM UTC+2, Andrei Berceanu wrote: Tnx! I think there is an error in the line (unbalanced paranthesis): return node.xreplace ({e: S.One, conjugate(e): S.One})*abs(e)**2) Yes, sorry, just remove the last parenthesis. Also, do you know how I can force the

[sympy] Re: pattern replacement for complex numbers and manual factorization

2014-06-06 Thread Andrei Berceanu
That fixed the error, however, the problem is now if I apply this function to expressions like -2*g*conjugate(psi^ss_1)*conjugate(psi^ss_2) I get -2*g*conjugate(psi^ss_1)*Abs(psi^ss_2)**2 so it looks like the pattern matching is working overtime, since it should leave the expression

[sympy] Re: pattern replacement for complex numbers and manual factorization

2014-06-06 Thread Andrei Berceanu
The unflatten_mul function factorized the 2, but not the g, i.e. it returns 2(g*|psi1|**2 + g*|psi2|**2) instead of 2g*(|psi1|**2 + |psi2|**2) On Friday, June 6, 2014 1:07:26 PM UTC+2, F. B. wrote: On Friday, June 6, 2014 12:22:14 PM UTC+2, Andrei Berceanu wrote: Tnx! I think there is

Re: [sympy] Re: pattern replacement for complex numbers and manual factorization

2014-06-06 Thread Christophe Bal
Hello. All the receipts in this dicussion look very interesting.Maybe all of this ones could be put in the official documentation. Christophe BAL 2014-06-06 13:34 GMT+02:00 Andrei Berceanu andreiberce...@gmail.com: The unflatten_mul function factorized the 2, but not the g, i.e. it returns

Re: [sympy] Re: pattern replacement for complex numbers and manual factorization

2014-06-06 Thread Andrei Berceanu
I agree, this could be helpful to many people. But first let's make sure we iron out all the bugs. And then I suppose one could re-write the expressions in a more user-friendly form? What do you propose, Chris? On Friday, June 6, 2014 2:16:15 PM UTC+2, Christophe Bal wrote: Hello. All the

[sympy] Re: pattern replacement for complex numbers and manual factorization

2014-06-06 Thread F. B.
Try to use this one: from sympy.unify import unify def to_abs(node): if not isinstance(node, Mul): return node zm1, zm2 = symbols('zm1, zm2') m = unify(node, zm1 * zm2 * conjugate(zm2), {}, variables=[zm1, zm2]) try: m = next(m) except: return node

[sympy] Re: pattern replacement for complex numbers and manual factorization

2014-06-06 Thread F. B.
On Friday, June 6, 2014 1:34:04 PM UTC+2, Andrei Berceanu wrote: The unflatten_mul function factorized the 2, but not the g, i.e. it returns 2(g*|psi1|**2 + g*|psi2|**2) instead of 2g*(|psi1|**2 + |psi2|**2) Try to do so: def get_unflattener(m): m_args = list(m.args)

Re: [sympy] Re: pattern replacement for complex numbers and manual factorization

2014-06-06 Thread Christophe Bal
I have no special ideas to propose except to start with the examples in this discussion. Maybe different working methods can be shown. 2014-06-06 14:23 GMT+02:00 Andrei Berceanu andreiberce...@gmail.com: I agree, this could be helpful to many people. But first let's make sure we iron out all

Re: [sympy] Re: pattern replacement for complex numbers and manual factorization

2014-06-06 Thread F. B.
I think that SymPy needs a better term rewriting system. And also a better pattern matcher. -- You received this message because you are subscribed to the Google Groups sympy group. To unsubscribe from this group and stop receiving emails from it, send an email to

Re: [sympy] Re: pattern replacement for complex numbers and manual factorization

2014-06-06 Thread Christophe Bal
A easy to use treeview will be a great tool. No ? 2014-06-06 19:52 GMT+02:00 F. B. franz.bona...@gmail.com: I think that SymPy needs a better term rewriting system. And also a better pattern matcher. -- You received this message because you are subscribed to the Google Groups sympy group.

Re: [sympy] Re: pattern replacement for complex numbers and manual factorization

2014-06-06 Thread Andrei Berceanu
Well yes, but that doesn´t change the fact that in Mathematica I can just do expr /.{x_*Conj[x_] - Abs[x]^2} and it just works! On Friday, June 6, 2014 8:59:56 PM UTC+2, Christophe Bal wrote: A easy to use treeview will be a great tool. No ? 2014-06-06 19:52 GMT+02:00 F. B.

Re: [sympy] Re: pattern replacement for complex numbers and manual factorization

2014-06-06 Thread Andrei Berceanu
By the way, I just found another case where the modulus value squared substitution fails: a, b, c, d = symbols('a b c d') expr = a*b*conjugate(a)*conjugate(b) + c*d*conjugate(c)*conjugate(d) bottom_up(chain(rebuild, to_abs))(expr) -- a*conjugate(a)*Abs(b)**2 + c*conjugate(c)*Abs(d)**2 instead

[sympy] modify latex representation of user-defined function

2014-06-06 Thread Andrei Berceanu
I define a function gamma with the following code: from sympy import * x = Symbol('x') class gamma(Function): pass Its latex representation is print latex(gamma(x)) \Gamma\left(x\right) whereas I would like it to be \gamma\left(x\right) i.e. lowercase instead of capital. How can I achieve

[sympy] How can I call sympy by javascript with django / jquery or ajax

2014-06-06 Thread Peter
Hallo everybody, I'm sorry for this question, but I'm not realy familar with Python. Normally I'm working with PHP and JavaScript, but for my recent project I have to integrate some symbolic math to a webpage. In an Internet search, I came across Sympy. And sympy looks quite good. My problem

[sympy] Re: modify latex representation of user-defined function

2014-06-06 Thread Björn Dahlgren
On Friday, 6 June 2014 23:13:39 UTC+2, Andrei Berceanu wrote: I define a function gamma with the following code: from sympy import * x = Symbol('x') class gamma(Function): pass Its latex representation is print latex(gamma(x)) \Gamma\left(x\right) whereas I would like it to be

[sympy] Re: How can I call sympy by javascript with django / jquery or ajax

2014-06-06 Thread Björn Dahlgren
On Friday, 6 June 2014 23:18:19 UTC+2, Peter wrote: Hallo everybody, I'm sorry for this question, but I'm not realy familar with Python. Normally I'm working with PHP and JavaScript, but for my recent project I have to integrate some symbolic math to a webpage. In an Internet search, I

Re: [sympy] Writing Documentation for GA module

2014-06-06 Thread Alan Bromborsky
I am doing all check out of documentation locally. The pdf file (also rst and html) is on my computer. Note that I just upgraded my computer. Before (Amd Phenom II, 6 cores) the Mathjax took 15 seconds to render. On 06/06/2014 07:21 PM, Aaron Meurer wrote: Did that include time

[sympy] Re: How can I call sympy by javascript with django / jquery or ajax

2014-06-06 Thread Peter
Hi Björn, In the meantime, I tried to install SympyGamma and the Google app engine, as it is described in the manual. Unfortunately I don't know now how I can check if everything works fine, because some steps were discribed for a localhost and not on a remote server. Until today, I've never

Re: [sympy] Re: How can I call sympy by javascript with django / jquery or ajax

2014-06-06 Thread Alan Bromborsky
You might want to look at http://krum.rz.uni-mannheim.de/jas/ (Java Algebra System (JAS) Project) On 06/06/2014 08:16 PM, Peter wrote: Hi Björn, In the meantime, ItriedtoinstallSympyGammaandtheGoogleappengine,asitisdescribedinthemanual.

Re: [sympy] PRolog Equation Solving System

2014-06-06 Thread Aaron Meurer
These are all issues that Harsh should be addressing in his GSoC project. Aaron Meurer On Wed, Jun 4, 2014 at 6:56 AM, F. B. franz.bona...@gmail.com wrote: I had a look at SymPy, it looks like this: In [1]: solve(cos(3*x), x) Out[1]: ⎡π π⎤ ⎢─, ─⎥ ⎣6 2⎦ In [2]: solve(cos(n*x), x)

[sympy] How can I call sympy by javascript with django / jquery or ajax

2014-06-06 Thread SAHIL SHEKHAWAT
Peter! I dont understand what is it exactly that you want to do but still I would like to help. On 7 Jun 2014 06:00, Alan Bromborsky abro...@verizon.net javascript:_e(%7B%7D,'cvml','abro...@verizon.net'); wrote: In the meantime, I tried to install SympyGamma and the Google app engine, as it

[sympy] Re: Convert from a system of linear equations to a matrix

2014-06-06 Thread James Crist
I just answered this on gitter earlier today, but you can just take the jacobian of the system to get its matrix form. For example: In [1]: from sympy import * In [2]: a, b, c, d = symbols('a, b, c, d') In [3]: x1, x2, x3, x4 = symbols('x1:5') In [4]: x = Matrix([x1, x2, x3, x4]) In [5]: