David Joyner | 1 Nov 01:37 2011
Picon

Re: papers on sympy?

On Mon, Oct 31, 2011 at 7:31 PM, Aaron Meurer <asmeurer@...> wrote:
> Comments:
>
> - "as its beautiful logo"  should this be "as is its beautiful logo"?

fixed

>
> - "However, the most active are..." Maybe rather say "However, the
> most active as of October 2011 are..." to make it clear that this is a
> snapshot into this particular point in time.  For example, over the
> summer a different set of developers were most active (i.e., these
> people plus the GSoC students).

fixed

>
> - "For example, the following simple Python commands were run from the
> SymPy command line." I would reword this sentence.  It sounds like
> SymPy has it's own interpreter, and I think it especially would to a
> user of any other computer algebra system.  I'm not sure what the best
> wording is, but make it clear that SymPy just runs inside a normal
> Python interpreter, such as the one that comes with Python or IPython.
> Maybe it would be best to just include a short paragraph about the
> isympy script, which just paraphrases the docstring from that file.

revised, as suggested

>
> "Surprisingly, it seems Maxima cannot do this at the present time." If
(Continue reading)

Aaron Meurer | 1 Nov 17:22 2011
Picon

Re: papers on sympy?

On Mon, Oct 31, 2011 at 6:37 PM, David Joyner <wdjoyner@...> wrote:
> On Mon, Oct 31, 2011 at 7:31 PM, Aaron Meurer <asmeurer@...> wrote:
>> Comments:
>>
>> - "as its beautiful logo"  should this be "as is its beautiful logo"?
>
> fixed
>
>>
>> - "However, the most active are..." Maybe rather say "However, the
>> most active as of October 2011 are..." to make it clear that this is a
>> snapshot into this particular point in time.  For example, over the
>> summer a different set of developers were most active (i.e., these
>> people plus the GSoC students).
>
> fixed
>
>>
>> - "For example, the following simple Python commands were run from the
>> SymPy command line." I would reword this sentence.  It sounds like
>> SymPy has it's own interpreter, and I think it especially would to a
>> user of any other computer algebra system.  I'm not sure what the best
>> wording is, but make it clear that SymPy just runs inside a normal
>> Python interpreter, such as the one that comes with Python or IPython.
>> Maybe it would be best to just include a short paragraph about the
>> isympy script, which just paraphrases the docstring from that file.
>
> revised, as suggested
>
>>
(Continue reading)

a.lwtzky | 1 Nov 17:36 2011

convert sympy.Matrix to list of lists of python standard types or numpy array

Dear everyone,

I was wondering if there is a function in sympy that converts a
sympy.Matrix to a list of lists of python standard types. For example
if you have
>>> m = matrices.Matrix([[2,0],[0,2]])

it would be nice to have a function <f> that returns:
>>> res = <f>(m)
[[2,0],[0,2]]
>>> type(res)
list
>>> type(res[0][0])
int # or float or whatever seems appropriate.

as an alternative: return a 2D numpy array of integers/floats... But
this brings probably unnecessary dependencies to numpy. And if the
user really wants to have a numpy.array, he/she could just use
np.asarray(res).

I spent a couple of hours in order to find a (simple) solution for
this.
A similar idea was presented here:
http://weekinpse.wordpress.com/2010/01/06/how-to-convert-a-sympy-matrix-to-numpy-array/
This subject has already been discussed in sympy IRC channel with
ronan (thanks again).

-> Motivation - Use case
I would like to use numpy and sympy in the same project. Use sympy to
solve a ODE system symbolically, get its jacobian, the jacobian's
(Continue reading)

Mateusz Paprocki | 1 Nov 18:01 2011
Picon

Re: papers on sympy?

Hi,

On 1 November 2011 09:22, Aaron Meurer <asmeurer <at> gmail.com> wrote:
On Mon, Oct 31, 2011 at 6:37 PM, David Joyner <wdjoyner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> On Mon, Oct 31, 2011 at 7:31 PM, Aaron Meurer <asmeurer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>> Comments:
>>
>> - "as its beautiful logo"  should this be "as is its beautiful logo"?
>
> fixed
>
>>
>> - "However, the most active are..." Maybe rather say "However, the
>> most active as of October 2011 are..." to make it clear that this is a
>> snapshot into this particular point in time.  For example, over the
>> summer a different set of developers were most active (i.e., these
>> people plus the GSoC students).
>
> fixed
>
>>
>> - "For example, the following simple Python commands were run from the
>> SymPy command line." I would reword this sentence.  It sounds like
>> SymPy has it's own interpreter, and I think it especially would to a
>> user of any other computer algebra system.  I'm not sure what the best
>> wording is, but make it clear that SymPy just runs inside a normal
>> Python interpreter, such as the one that comes with Python or IPython.
>> Maybe it would be best to just include a short paragraph about the
>> isympy script, which just paraphrases the docstring from that file.
>
> revised, as suggested
>
>>
>> "Surprisingly, it seems Maxima cannot do this at the present time." If
>> I remember correctly, Maxima took the lazy route and only implemented
>> second order differential equations (or maybe they can also do higher
>> order but only if they are homogeneous, I can't remember).  The
>> general non-homogeneous case requires either undetermined coefficients
>> (if the non-homogeneous term has the correct form), or, in the general
>> case, the nth order version of variation of parameters, which is not
>> too difficult to implement if you have strong integration routines and
>> knowledge of linear algebra (Cramer's rule), but it seems is so rarely
>> actually taught that I only found two resources anywhere on the
>> internet that dealt with it in the nth case out of the thousands that
>> dealt with the 2nd order case, and neither was very good. I discussed
>> this on my blog back when I implemented it
>> (http://asmeurersympy.wordpress.com/2009/08/01/variation-of-parameters-and-more/).
>> In fact, at the time, I couldn't find another open source system that
>> implemented this, though I would definitely try to verify this fact
>> before putting it in the paper.
>>
>
> I made revisions but I think Axiom has more functionality that Maxima
> in this area:
> http://www.axiom-developer.org/axiom-website/hyperdoc/equdifferentiallinear.xhtml
>

Ah, that's not surprising.  Axiom probably implements something like
http://www-sop.inria.fr/cafe/Manuel.Bronstein/sumit/bernina_demo.html.

There are algorithms for solving certain classes of differential equations in full generality (e.g. linear with polynomial coefficients). See http://reference.wolfram.com/mathematica/tutorial/DSolveReferences.html and search for Bronstain and Abramov. Actually, one of those algorithms I implemented during my summer of code for the discrete case (recurrence solving), but it can be generalized to the continuous case. I'm not sure if they are implemented in Axiom, but most certainly they are implemented in various libraries (in Aldor) written by Bronstein.
 

Aaron Meurer

>
>> "On the
>> other hand, perhaps it is not surprising that SymPy is relatively strong in
>> the area of differential equations since many or the developers come from
>> physics and computational mathematics communities." Actually it's
>> mainly because of my GSoC project :)
>
>
> Good point.  I changed that.
>
> New version posted to the usual place:-)
>
> Thanks Aaron!
>
>>
>> Aaron Meurer
>>
>> On Mon, Oct 31, 2011 at 4:33 PM, David Joyner <wdjoyner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>>> On Sun, Oct 30, 2011 at 12:48 PM, Vladimir Perić <vlada.peric-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>>>
>>> ...
>>>
>>>>
>>>> I also think the "Capabilities" section is a bit.. short. You took it
>>>> from the website, I assume? That homepage hasn't been updated in a
>>>> long time (and writing that list is even one task for Google Code-In).
>>>> At the very least, I think you should give more mention to the physics
>>>> and quantum modules, which is a real advantage SymPy has over other
>>>> CAS systems.
>>>
>>>
>>> After a few emails from Brian Granger (thanks Brian!) I have
>>> created a new subsection on quanum physics. It is very sketchy
>>> but hopefully has enough for interested readers to pursue
>>> further leads.
>>>
>>> Latest version is at
>>> http://boxen.math.washington.edu/home/wdj/sigsam/sympy/oscas-sympy.pdf
>>> (and sources are in that directory too).
>>>
>>> BTW, if anyone wants to post this to github, that is fine with me.
>>> However, I know
>>> zip about git:-)
>>>
>>>
>>> Thanks to all of you for your great help!
>>>
>>>>
>>>
>>> ...
>>>
>>>> --
>>>> Vladimir Perić
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google Groups "sympy" group.
>>>> To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
>>>> To unsubscribe from this group, send email to sympy+unsubscribe <at> googlegroups.com.
>>>> For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
>>>>
>>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups "sympy" group.
>>> To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
>>> To unsubscribe from this group, send email to sympy+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
>>> For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
>>>
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups "sympy" group.
>> To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
>> To unsubscribe from this group, send email to sympy+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
>> For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
> To unsubscribe from this group, send email to sympy+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
> For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To unsubscribe from this group, send email to sympy+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit this group at http://groups.google.com/group/sympy?hl=en.


Mateusz

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to sympy+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
Mateusz Paprocki | 1 Nov 18:10 2011
Picon

Re: convert sympy.Matrix to list of lists of python standard types or numpy array

Hi,

On 1 November 2011 09:36, a.lwtzky <a.lwtzky <at> googlemail.com> wrote:
Dear everyone,

I was wondering if there is a function in sympy that converts a
sympy.Matrix to a list of lists of python standard types. For example
if you have
>>> m = matrices.Matrix([[2,0],[0,2]])

it would be nice to have a function <f> that returns:
>>> res = <f>(m)
[[2,0],[0,2]]
>>> type(res)
list
>>> type(res[0][0])
int # or float or whatever seems appropriate.

as an alternative: return a 2D numpy array of integers/floats... But
this brings probably unnecessary dependencies to numpy. And if the
user really wants to have a numpy.array, he/she could just use
np.asarray(res).

You can create an array from a matrix and convert a matrix to a list of lists, e.g.:

In [1]: import numpy as np

In [2]: a = Matrix([[1, 2], [3, 4]])

In [3]: a
Out[3]: 
⎡1  2⎤
⎢    ⎥
⎣3  4⎦

In [4]: a.tolist()
Out[4]: [[1, 2], [3, 4]]

In [5]: np.array(a)
Out[5]: 
 [[1 2]
 [3 4]]

This is for git version of SymPy, but should work for older versions too.
 

I spent a couple of hours in order to find a (simple) solution for
this.
A similar idea was presented here:
http://weekinpse.wordpress.com/2010/01/06/how-to-convert-a-sympy-matrix-to-numpy-array/
This subject has already been discussed in sympy IRC channel with
ronan (thanks again).

-> Motivation - Use case
I would like to use numpy and sympy in the same project. Use sympy to
solve a ODE system symbolically, get its jacobian, the jacobian's
eigenvectors at a critical point and so on. Then use this information
to plot it (with matplotlib) together with other functions, further
investigate it's properties (for example integrate it numerically with
numpy - plot the trajectories) and so on.

-> suggestions
It doesn't seem to be too bad implementing something like this. The
solution of hdahlol can be found at the link (see above).
ronan thought about something like:
def <f>(m):
   arr = np.asarray(map(int, m.mat)) # or float...
   arr.shape = m.shape
   return arr

But both of us agreed that using m.mat is pretty ugly at this point.
And it does explicitly take use of numpy. Of course there is a way to
copy value by value - but this might result in terribly slow code
without benefit.

In case a value can't be converted to standard types (for example a
variable x) the function could just throw an exception or leave the
sympy.object in the list and let the user care about this case.

I would really appreciate help in this question.

Thanks, Andy

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To unsubscribe from this group, send email to sympy+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit this group at http://groups.google.com/group/sympy?hl=en.


Mateusz

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to sympy+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
Vinzenz | 1 Nov 18:52 2011
Picon

Re: Numerical evaluation, how to speed up?

On 18 Okt., 16:47, Michael Hoffman <archangel.associ...@...>
wrote:
> Or at least an particularly nasty example of a matrix entry. pasting a 1 to
> 2 MB matrix is probably not advisable.
>
> Also, if you can give the desired input and output that would be helpful.
>
> Mike
>
> On Tue, Oct 18, 2011 at 8:25 AM, Chris Smith <smi...@...> wrote:
> > perhaps cse could help so you dn't have to keep recomputing
> > thing...can you pastebin the matrix so we can see it?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "sympy" group.
> > To post to this group, send email to sympy@...
> > To unsubscribe from this group, send email to
> > sympy+unsubscribe@...
> > For more options, visit this group at
> >http://groups.google.com/group/sympy?hl=en.
>
> --
> Michael Hoffman
> ROSE Compiler Group
> Lawrence Livermore National Laboratories
> Department of Energy

Thanks for your answers.
Here is a small expression of one element of the matrix:
http://pastebin.com/AYbUu66t
How would you simplify it?

Here is a simplified (to about 1-2% length in few seconds) version of
the expression obtained with Mathematica:
http://pastebin.com/VMiGK0dJ

I already found an old thread, stating that the algorithms to combine
sin/cos arguments is not implemented yet.
Is this still true?

Running lambdify with parallel python on a 6-core Xeon I get the
result much much faster than on a i5. I don't know yet, if this is
just because of the machines or also a software matter. Does atlas or
similar have an effect on lamdify?

However, I need the expression for further processing in python as
well as in Matlab in a simplified version. I already tried the cse
method, but got strange results, i.e. some subexpressions were not
used at all and the result was not the same. Besides that, the
computation became slowlier (there were many small subexpressions). I
will investigate it again, maybe my fault somewhere. I am also
checking if I can simplify the expressions numerically, i.e. replace
summands which have little effect with constants.

Vinzenz

--

-- 
You received this message because you are subscribed to the Google Groups "sympy" group.
To post to this group, send email to sympy@...
To unsubscribe from this group, send email to sympy+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/sympy?hl=en.

a.lwtzky | 1 Nov 19:26 2011

Re: convert sympy.Matrix to list of lists of python standard types or numpy array

Hi Mateusz,
True, but the dtype of this numpy array is object, which is unsuitable
e.g. for numerical ODE solver.
Try:
In [1] : a = Matrix([[1, 2], [3, 4]])
In [2]: type(a.tolist()[0][0])
Out[13]: <class 'sympy.core.numbers.One'>

same with the numpy array:
array([[1, 2],
       [3, 4]], dtype=object)

I've got the pypy version of sympy which is 0.7.1. Has the behavior
anything changed here?

Thanks for your help anyway,
  Andy

On 1 Nov., 18:10, Mateusz Paprocki <matt...@...> wrote:
> Hi,
>
> On 1 November 2011 09:36, a.lwtzky <a.lwt...@...> wrote:
>
>
>
>
>
>
>
>
>
> > Dear everyone,
>
> > I was wondering if there is a function in sympy that converts a
> > sympy.Matrix to a list of lists of python standard types. For example
> > if you have
> > >>> m = matrices.Matrix([[2,0],[0,2]])
>
> > it would be nice to have a function <f> that returns:
> > >>> res = <f>(m)
> > [[2,0],[0,2]]
> > >>> type(res)
> > list
> > >>> type(res[0][0])
> > int # or float or whatever seems appropriate.
>
> > as an alternative: return a 2D numpy array of integers/floats... But
> > this brings probably unnecessary dependencies to numpy. And if the
> > user really wants to have a numpy.array, he/she could just use
> > np.asarray(res).
>
> You can create an array from a matrix and convert a matrix to a list of
> lists, e.g.:
>
> In [1]: import numpy as np
>
> In [2]: a = Matrix([[1, 2], [3, 4]])
>
> In [3]: a
> Out[3]:
> ⎡1  2⎤
> ⎢    ⎥
> ⎣3  4⎦
>
> In [4]: a.tolist()
> Out[4]: [[1, 2], [3, 4]]
>
> In [5]: np.array(a)
> Out[5]:
>  [[1 2]
>  [3 4]]
>
> This is for git version of SymPy, but should work for older versions too.
>
>
>
>
>
>
>
>
>
>
>
> > I spent a couple of hours in order to find a (simple) solution for
> > this.
> > A similar idea was presented here:
>
> >http://weekinpse.wordpress.com/2010/01/06/how-to-convert-a-sympy-matr...
> > This subject has already been discussed in sympy IRC channel with
> > ronan (thanks again).
>
> > -> Motivation - Use case
> > I would like to use numpy and sympy in the same project. Use sympy to
> > solve a ODE system symbolically, get its jacobian, the jacobian's
> > eigenvectors at a critical point and so on. Then use this information
> > to plot it (with matplotlib) together with other functions, further
> > investigate it's properties (for example integrate it numerically with
> > numpy - plot the trajectories) and so on.
>
> > -> suggestions
> > It doesn't seem to be too bad implementing something like this. The
> > solution of hdahlol can be found at the link (see above).
> > ronan thought about something like:
> > def <f>(m):
> >    arr = np.asarray(map(int, m.mat)) # or float...
> >    arr.shape = m.shape
> >    return arr
>
> > But both of us agreed that using m.mat is pretty ugly at this point.
> > And it does explicitly take use of numpy. Of course there is a way to
> > copy value by value - but this might result in terribly slow code
> > without benefit.
>
> > In case a value can't be converted to standard types (for example a
> > variable x) the function could just throw an exception or leave the
> > sympy.object in the list and let the user care about this case.
>
> > I would really appreciate help in this question.
>
> > Thanks, Andy
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "sympy" group.
> > To post to this group, send email to sympy@...
> > To unsubscribe from this group, send email to
> > sympy+unsubscribe@...
> > For more options, visit this group at
> >http://groups.google.com/group/sympy?hl=en.
>
> Mateusz

--

-- 
You received this message because you are subscribed to the Google Groups "sympy" group.
To post to this group, send email to sympy@...
To unsubscribe from this group, send email to sympy+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sympy?hl=en.

Mateusz Paprocki | 1 Nov 19:36 2011
Picon

Re: Re: convert sympy.Matrix to list of lists of python standard types or numpy array

Hi,

On 1 November 2011 11:26, a.lwtzky <a.lwtzky <at> googlemail.com> wrote:
Hi Mateusz,
True, but the dtype of this numpy array is object, which is unsuitable
e.g. for numerical ODE solver.
Try:
In [1] : a = Matrix([[1, 2], [3, 4]])
In [2]: type(a.tolist()[0][0])
Out[13]: <class 'sympy.core.numbers.One'>

same with the numpy array:
array([[1, 2],
      [3, 4]], dtype=object)

This is correct behavior. I you want to get a minimal dtype (some sort of int) then a quick hack is to use lambdify(), e.g.:

In [1]: a = Matrix([[1, 2], [3, 4]])

In [2]: f = lambdify((), a, 'numpy')

In [3]: f()
Out[3]: 
 [[1 2]
 [3 4]]

In [4]: _.dtype
Out[4]: int64

f is a zero argument Python's native lambda with NumPy's data types.

Downcasting should work and would be a preferred solution, but it fails due to a bug in SymPy:

In [5]: import numpy as np

In [6]: b = np.array(a)

In [7]: b.astype(int)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/home/mateusz/repo/git/sympy/<ipython-input-7-523ae7d433be> in <module>()
----> 1 b.astype(int)

TypeError: long() argument must be a string or a number, not 'Integer'

For some reason NumPy uses long() when int dtype is give and currently in SymPy:

In [8]: int(Integer(10))
Out[8]: 10

In [9]: long(Integer(10))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/home/mateusz/repo/git/sympy/<ipython-input-9-5db2e38df86b> in <module>()
----> 1 long(Integer(10))

TypeError: long() argument must be a string or a number, not 'Integer'


I've got the pypy version of sympy which is 0.7.1. Has the behavior
anything changed here?

Thanks for your help anyway,
 Andy

On 1 Nov., 18:10, Mateusz Paprocki <matt...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> Hi,
>
> On 1 November 2011 09:36, a.lwtzky <a.lwt...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:
>
>
>
>
>
>
>
>
>
> > Dear everyone,
>
> > I was wondering if there is a function in sympy that converts a
> > sympy.Matrix to a list of lists of python standard types. For example
> > if you have
> > >>> m = matrices.Matrix([[2,0],[0,2]])
>
> > it would be nice to have a function <f> that returns:
> > >>> res = <f>(m)
> > [[2,0],[0,2]]
> > >>> type(res)
> > list
> > >>> type(res[0][0])
> > int # or float or whatever seems appropriate.
>
> > as an alternative: return a 2D numpy array of integers/floats... But
> > this brings probably unnecessary dependencies to numpy. And if the
> > user really wants to have a numpy.array, he/she could just use
> > np.asarray(res).
>
> You can create an array from a matrix and convert a matrix to a list of
> lists, e.g.:
>
> In [1]: import numpy as np
>
> In [2]: a = Matrix([[1, 2], [3, 4]])
>
> In [3]: a
> Out[3]:
> ⎡1  2⎤
> ⎢    ⎥
> ⎣3  4⎦
>
> In [4]: a.tolist()
> Out[4]: [[1, 2], [3, 4]]
>
> In [5]: np.array(a)
> Out[5]:
>  [[1 2]
>  [3 4]]
>
> This is for git version of SymPy, but should work for older versions too.
>
>
>
>
>
>
>
>
>
>
>
> > I spent a couple of hours in order to find a (simple) solution for
> > this.
> > A similar idea was presented here:
>
> >http://weekinpse.wordpress.com/2010/01/06/how-to-convert-a-sympy-matr...
> > This subject has already been discussed in sympy IRC channel with
> > ronan (thanks again).
>
> > -> Motivation - Use case
> > I would like to use numpy and sympy in the same project. Use sympy to
> > solve a ODE system symbolically, get its jacobian, the jacobian's
> > eigenvectors at a critical point and so on. Then use this information
> > to plot it (with matplotlib) together with other functions, further
> > investigate it's properties (for example integrate it numerically with
> > numpy - plot the trajectories) and so on.
>
> > -> suggestions
> > It doesn't seem to be too bad implementing something like this. The
> > solution of hdahlol can be found at the link (see above).
> > ronan thought about something like:
> > def <f>(m):
> >    arr = np.asarray(map(int, m.mat)) # or float...
> >    arr.shape = m.shape
> >    return arr
>
> > But both of us agreed that using m.mat is pretty ugly at this point.
> > And it does explicitly take use of numpy. Of course there is a way to
> > copy value by value - but this might result in terribly slow code
> > without benefit.
>
> > In case a value can't be converted to standard types (for example a
> > variable x) the function could just throw an exception or leave the
> > sympy.object in the list and let the user care about this case.
>
> > I would really appreciate help in this question.
>
> > Thanks, Andy
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "sympy" group.
> > To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
> > To unsubscribe from this group, send email to
> > sympy+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
> > For more options, visit this group at
> >http://groups.google.com/group/sympy?hl=en.
>
> Mateusz

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To unsubscribe from this group, send email to sympy+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit this group at http://groups.google.com/group/sympy?hl=en.


Mateusz

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to sympy+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
a.lwtzky | 1 Nov 20:27 2011

Re: convert sympy.Matrix to list of lists of python standard types or numpy array

Hi Mateusz,

the second solution is exactly what I was looking for.
Actually, I tried that as well but ran in the same type error.
Unfortunately I only tried it with integers, so I gave up hope that it
works like this.
Anyway, what's still confusing me is:
>>> a = Matrix([[1., 2.], [3., 4.]])
>>> b = np.array(a, dtype=float)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call
last)

/home/andy/≤ipython console> in <module>()

TypeError: __array__() takes exactly 1 argument (2 given)

I expected it to do exactly the same as array()&astype(), but that's
obviously wrong. It would be awesome, if it works like that.

Is the bug with the Integers in sympy known? Or should I file a bug
report for this?

Thank you very much for your help so far. I don't know if this is in
the scope of sympy, but it would be nice to have a nice interface to
numpy at this point.

Cheers, Andy

On 1 Nov., 19:36, Mateusz Paprocki <matt...@...> wrote:
> Hi,
>
> On 1 November 2011 11:26, a.lwtzky <a.lwt...@...> wrote:
>
> > Hi Mateusz,
> > True, but the dtype of this numpy array is object, which is unsuitable
> > e.g. for numerical ODE solver.
> > Try:
> > In [1] : a = Matrix([[1, 2], [3, 4]])
> > In [2]: type(a.tolist()[0][0])
> > Out[13]: <class 'sympy.core.numbers.One'>
>
> > same with the numpy array:
> > array([[1, 2],
> >       [3, 4]], dtype=object)
>
> This is correct behavior. I you want to get a minimal dtype (some sort of
> int) then a quick hack is to use lambdify(), e.g.:
>
> In [1]: a = Matrix([[1, 2], [3, 4]])
>
> In [2]: f = lambdify((), a, 'numpy')
>
> In [3]: f()
> Out[3]:
>  [[1 2]
>  [3 4]]
>
> In [4]: _.dtype
> Out[4]: int64
>
> f is a zero argument Python's native lambda with NumPy's data types.
>
> Downcasting should work and would be a preferred solution, but it fails due
> to a bug in SymPy:
>
> In [5]: import numpy as np
>
> In [6]: b = np.array(a)
>
> In [7]: b.astype(int)
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call last)
> /home/mateusz/repo/git/sympy/≤ipython-input-7-523ae7d433be> in <module>()
> ----> 1 b.astype(int)
>
> TypeError: long() argument must be a string or a number, not 'Integer'
>
> For some reason NumPy uses long() when int dtype is give and currently in
> SymPy:
>
> In [8]: int(Integer(10))
> Out[8]: 10
>
> In [9]: long(Integer(10))
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call last)
> /home/mateusz/repo/git/sympy/≤ipython-input-9-5db2e38df86b> in <module>()
> ----> 1 long(Integer(10))
>
> TypeError: long() argument must be a string or a number, not 'Integer'
>
>
>
>
>
>
>
>
>
> > I've got the pypy version of sympy which is 0.7.1. Has the behavior
> > anything changed here?
>
> > Thanks for your help anyway,
> >  Andy
>
> > On 1 Nov., 18:10, Mateusz Paprocki <matt...@...> wrote:
> > > Hi,
>
> > > On 1 November 2011 09:36, a.lwtzky <a.lwt...@...> wrote:
>
> > > > Dear everyone,
>
> > > > I was wondering if there is a function in sympy that converts a
> > > > sympy.Matrix to a list of lists of python standard types. For example
> > > > if you have
> > > > >>> m = matrices.Matrix([[2,0],[0,2]])
>
> > > > it would be nice to have a function <f> that returns:
> > > > >>> res = <f>(m)
> > > > [[2,0],[0,2]]
> > > > >>> type(res)
> > > > list
> > > > >>> type(res[0][0])
> > > > int # or float or whatever seems appropriate.
>
> > > > as an alternative: return a 2D numpy array of integers/floats... But
> > > > this brings probably unnecessary dependencies to numpy. And if the
> > > > user really wants to have a numpy.array, he/she could just use
> > > > np.asarray(res).
>
> > > You can create an array from a matrix and convert a matrix to a list of
> > > lists, e.g.:
>
> > > In [1]: import numpy as np
>
> > > In [2]: a = Matrix([[1, 2], [3, 4]])
>
> > > In [3]: a
> > > Out[3]:
> > > ⎡1  2⎤
> > > ⎢    ⎥
> > > ⎣3  4⎦
>
> > > In [4]: a.tolist()
> > > Out[4]: [[1, 2], [3, 4]]
>
> > > In [5]: np.array(a)
> > > Out[5]:
> > >  [[1 2]
> > >  [3 4]]
>
> > > This is for git version of SymPy, but should work for older versions too.
>
> > > > I spent a couple of hours in order to find a (simple) solution for
> > > > this.
> > > > A similar idea was presented here:
>
> > > >http://weekinpse.wordpress.com/2010/01/06/how-to-convert-a-sympy-matr.
> > ..
> > > > This subject has already been discussed in sympy IRC channel with
> > > > ronan (thanks again).
>
> > > > -> Motivation - Use case
> > > > I would like to use numpy and sympy in the same project. Use sympy to
> > > > solve a ODE system symbolically, get its jacobian, the jacobian's
> > > > eigenvectors at a critical point and so on. Then use this information
> > > > to plot it (with matplotlib) together with other functions, further
> > > > investigate it's properties (for example integrate it numerically with
> > > > numpy - plot the trajectories) and so on.
>
> > > > -> suggestions
> > > > It doesn't seem to be too bad implementing something like this. The
> > > > solution of hdahlol can be found at the link (see above).
> > > > ronan thought about something like:
> > > > def <f>(m):
> > > >    arr = np.asarray(map(int, m.mat)) # or float...
> > > >    arr.shape = m.shape
> > > >    return arr
>
> > > > But both of us agreed that using m.mat is pretty ugly at this point.
> > > > And it does explicitly take use of numpy. Of course there is a way to
> > > > copy value by value - but this might result in terribly slow code
> > > > without benefit.
>
> > > > In case a value can't be converted to standard types (for example a
> > > > variable x) the function could just throw an exception or leave the
> > > > sympy.object in the list and let the user care about this case.
>
> > > > I would really appreciate help in this question.
>
> > > > Thanks, Andy
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "sympy" group.
> > > > To post to this group, send email to sympy@...
> > > > To unsubscribe from this group, send email to
> > > > sympy+unsubscribe@...
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/sympy?hl=en.
>
> > > Mateusz
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "sympy" group.
> > To post to this group, send email to sympy@...
> > To unsubscribe from this group, send email to
> > sympy+unsubscribe@...
> > For more options, visit this group at
> >http://groups.google.com/group/sympy?hl=en.
>
> Mateusz

--

-- 
You received this message because you are subscribed to the Google Groups "sympy" group.
To post to this group, send email to sympy@...
To unsubscribe from this group, send email to sympy+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sympy?hl=en.

Ondřej Čertík | 2 Nov 00:19 2011
Picon

Re: papers on sympy?

On Mon, Oct 31, 2011 at 5:37 PM, David Joyner <wdjoyner@...> wrote:
> On Mon, Oct 31, 2011 at 7:31 PM, Aaron Meurer <asmeurer@...> wrote:
>> Comments:
>>
>> - "as its beautiful logo"  should this be "as is its beautiful logo"?
>
> fixed
>
>>
>> - "However, the most active are..." Maybe rather say "However, the
>> most active as of October 2011 are..." to make it clear that this is a
>> snapshot into this particular point in time.  For example, over the
>> summer a different set of developers were most active (i.e., these
>> people plus the GSoC students).
>
> fixed
>
>>
>> - "For example, the following simple Python commands were run from the
>> SymPy command line." I would reword this sentence.  It sounds like
>> SymPy has it's own interpreter, and I think it especially would to a
>> user of any other computer algebra system.  I'm not sure what the best
>> wording is, but make it clear that SymPy just runs inside a normal
>> Python interpreter, such as the one that comes with Python or IPython.
>> Maybe it would be best to just include a short paragraph about the
>> isympy script, which just paraphrases the docstring from that file.
>
> revised, as suggested
>
>>
>> "Surprisingly, it seems Maxima cannot do this at the present time." If
>> I remember correctly, Maxima took the lazy route and only implemented
>> second order differential equations (or maybe they can also do higher
>> order but only if they are homogeneous, I can't remember).  The
>> general non-homogeneous case requires either undetermined coefficients
>> (if the non-homogeneous term has the correct form), or, in the general
>> case, the nth order version of variation of parameters, which is not
>> too difficult to implement if you have strong integration routines and
>> knowledge of linear algebra (Cramer's rule), but it seems is so rarely
>> actually taught that I only found two resources anywhere on the
>> internet that dealt with it in the nth case out of the thousands that
>> dealt with the 2nd order case, and neither was very good. I discussed
>> this on my blog back when I implemented it
>> (http://asmeurersympy.wordpress.com/2009/08/01/variation-of-parameters-and-more/).
>> In fact, at the time, I couldn't find another open source system that
>> implemented this, though I would definitely try to verify this fact
>> before putting it in the paper.
>>
>
> I made revisions but I think Axiom has more functionality that Maxima
> in this area:
> http://www.axiom-developer.org/axiom-website/hyperdoc/equdifferentiallinear.xhtml
>
>
>> "On the
>> other hand, perhaps it is not surprising that SymPy is relatively strong in
>> the area of differential equations since many or the developers come from
>> physics and computational mathematics communities." Actually it's
>> mainly because of my GSoC project :)
>
>
> Good point.  I changed that.
>
> New version posted to the usual place:-)

Sorry for my late reply. So here I put your sources to github:

https://github.com/certik/oscas-sympy

then I sent a pull request with my proposed changes:

https://github.com/certik/oscas-sympy/pull/1

you can browse there the total diff, or individual patches. If you
want my latest tex file, just download it by clicking here:

https://raw.github.com/certik/oscas-sympy/changes/oscas-sympy.tex

I am posting here my licence quote that is quoted in the article, so
that it is public:
"
Some people say, that GPL had its place in history. Well, maybe
it had, maybe not, it's hard to say - let's leave it for historians.
But today in 2011,  I think that there is no advantage of GPL over
BSD. The only thing that matters is to have a solid
community, so that lots of people contribute to the project. Also it
seems that these days, there are a lot of people who come to
open-source, who don't really feel strongly about licensing, they just
want their code to be used (no matter how), and thus use BSD.
"

Ondrej

--

-- 
You received this message because you are subscribed to the Google Groups "sympy" group.
To post to this group, send email to sympy@...
To unsubscribe from this group, send email to sympy+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sympy?hl=en.


Gmane