[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'), conjugate(Symbol('p

[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'), Mul(Integer(

[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

[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 fo

[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 unchanged

[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 t

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 : > The unflatten_mul function factorized the 2, but not the g, i.e. it returns > > 2(g*|psi1|**2 + g*|p

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 t

[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)

[sympy] Help with Vector

2014-06-06 Thread Sachin Joglekar
Hello everyone, I have been working on a basic vector framework for sympy for some time now. I am still working on the classes for coordinate systems, so currently all operations occur in the _same_ frame. The PR for the code is here . To get you starte

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

2014-06-06 Thread jeanbigboute
On Friday, June 6, 2014 2:16:57 AM UTC-7, F. B. wrote: > > > > 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

[sympy] Re: Help with Vector

2014-06-06 Thread F. B.
On Friday, June 6, 2014 3:44:51 PM UTC+2, Sachin Joglekar wrote: > > > 1. How do I ensure methods like 'trigsimp' work with these classes? > Currently, passing a vector like *(sin(a)+cos(a))**2*i - j* to trigsimp > returns the correct answer mathematically, _but_ the instance is of type > Add

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 : > I agree, this could be helpful to many people. But first let's make sure > we iron out all the bugs. > And then I

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 sympy+unsubscr...@googlegro

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. : > 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 unsubscrib

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. >: > >> I

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 loo

[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

[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 sear

Re: [sympy] Writing Documentation for GA module

2014-06-06 Thread Aaron Meurer
The png math looks terrible on high resolution displays, so I am -1 for that reason. It's also less accessible (e.g., screen readers cannot do anything with it). I don't think 15 seconds is that bad. You will wait longer than that for a PDF to download. Aaron Meurer On Wed, Jun 4, 2014 at 8:49 A

Re: [sympy] Writing Documentation for GA module

2014-06-06 Thread Alan Bromborsky
Locally on my computer (i7, 6 cores, 3.2 GHz) it took 8 seconds for the mathjax to render. The pdf file (928 kB) took less than a second to load and display. I also agree that the png display looks really bad. On 06/06/2014 06:43 PM, Aaron Meurer wrote: The png math looks terrible on high res

Re: [sympy] Writing Documentation for GA module

2014-06-06 Thread Aaron Meurer
Did that include time downloading the pdf from the internet? Aaron Meurer On Fri, Jun 6, 2014 at 6:13 PM, Alan Bromborsky wrote: > Locally on my computer (i7, 6 cores, 3.2 GHz) it took 8 seconds for the > mathjax to render. The pdf file (928 kB) took less than a second to load > and display. >

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 downloading

[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 d

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. UnfortunatelyIdon'tknownowhowIcancheckifeverythingworks

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. 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) > Out[2]: > ⎡ π 3⋅

[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" > wrote: > 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

[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]: syst