Colin Gillespie | 1 Apr 2008 11:41
Picon
Favicon

Re: sympify of 'lambda' and 'E'


I've just found out that it's not 'E' that's causing the problem, it's
'S'.

sympify('S') #works
sympify('S*X') #doesn't work

Cheers

Colin

On Mar 31, 5:29 pm, Colin Gillespie <c.gilles...@...> wrote:
> Dear All,
>
> I suspect that sympify is getting confused by python's builtin lambda
> and E
>
> So are the following examples bugs? If not, should the documentation
> be updated with a warning?
>
> >>> sympify('S*lambda')
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "/pythonModules/lib/python2.4/site-packages/sympy-0.5.13_hg-
> py2.4.egg/sympy/core/sympify.py", line 127, in sympify
>     raise SympifyError(a, exc)
> sympy.core.sympify.SympifyError: Sympify of expression 'S*lambda'
> failed, because of exception being raised:
> SyntaxError: unexpected EOF while parsing (line 1)
(Continue reading)

Ondrej Certik | 1 Apr 2008 11:51
Picon
Gravatar

Re: sympify of 'lambda' and 'E'


On Tue, Apr 1, 2008 at 11:41 AM, Colin Gillespie
<c.gillespie@...> wrote:
>
>  I've just found out that it's not 'E' that's causing the problem, it's
>  'S'.
>
>  sympify('S') #works
>  sympify('S*X') #doesn't work

That's because S is imported in the sympy module:

In [1]: S
Out[1]: S

In [2]: S?
Type:		instance
Base Class:	sympy.core.basic.SingletonFactory
String Form:	S
Namespace:	Interactive
Docstring:
    A map between singleton classes and the corresponding instances.
    E.g. S.Exp == C.Exp()

However, I think sympify shouldn't try to use imported modules imho. i.e:

In [1]: sympify("ab")
Out[1]: ab

In [2]: sympify("abc")
(Continue reading)

Mateusz Paprocki | 1 Apr 2008 11:54
Picon
Gravatar

Re: sympify of 'lambda' and 'E'


Hi Colin,

The problem with 'S' is that it is a singleton factory:

In [8]: sympify('S.Zero')
Out[8]: 0

In [9]: sympify('S.One')
Out[9]: 1

So sympify('S*x') can't work:

In [10]: sympify('S')
Out[10]: S

In [11]: type(_)
Out[11]: <type 'instance'>

For the similar reason sympify('lambda') does not work:

In [13]: sympify('lambda x: x')
Out[13]: Lambda(x, x)

In [14]: sympify('lambda')
SympifyError: Sympify of expression 'lambda' failed, because of
exception being raised:
SyntaxError: unexpected EOF while parsing (line 1)

Our parser should be more intelligent in those cases.
(Continue reading)

Ondrej Certik | 1 Apr 2008 11:59
Picon
Gravatar

Re: sympify of 'lambda' and 'E'


On Tue, Apr 1, 2008 at 11:54 AM, Mateusz Paprocki <mattpap@...> wrote:
>
>  Hi Colin,
>
>  The problem with 'S' is that it is a singleton factory:
>
>  In [8]: sympify('S.Zero')
>  Out[8]: 0
>
>  In [9]: sympify('S.One')
>  Out[9]: 1
>
>  So sympify('S*x') can't work:
>
>  In [10]: sympify('S')
>  Out[10]: S
>
>  In [11]: type(_)
>  Out[11]: <type 'instance'>
>
>  For the similar reason sympify('lambda') does not work:
>
>  In [13]: sympify('lambda x: x')
>  Out[13]: Lambda(x, x)
>
>  In [14]: sympify('lambda')
>  SympifyError: Sympify of expression 'lambda' failed, because of
>
> exception being raised:
(Continue reading)

Colin Gillespie | 1 Apr 2008 12:40
Picon
Favicon

Re: sympify of 'lambda' and 'E'


> I created:
>
> http://code.google.com/p/sympy/issues/detail?id=773
>
> anyone feel free to fix it. :)
Many thanks.

Colin
Colin Gillespie | 1 Apr 2008 12:44
Picon
Favicon

easy_install and pypi


Dear All,

Just a quick note to say that pypi is slightly out of date. Also, I
use easy_install to install python packages, and although easy_install
works with sympy, there are a lot of warning messages.

The warning messages are mainly about not having __init__.py files in
your directories.

For example,

$ easy_install sympy
Searching for sympy
Reading http://www.python.org/pypi/sympy/
Couldn't find index page for 'sympy' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://www.python.org/pypi/
Reading http://www.python.org/pypi/SymPy/0.5.11
Reading http://code.google.com/p/sympy/
Best match: sympy 0.5.13
Downloading http://sympy.googlecode.com/files/sympy-0.5.13.tar.gz
Processing sympy-0.5.13.tar.gz
Running sympy-0.5.13/setup.py -q bdist_egg --dist-dir /tmp/
easy_install-B3updq/sympy-0.5.13/egg-dist-tmp-as5Xhj
package init file 'sympy/concrete/tests/__init__.py' not found (or not
a regular file)
<snip>
package init file 'sympy/utilities/tests/__init__.py' not found (or
not a regular file)
(Continue reading)

Ondrej Certik | 1 Apr 2008 13:10
Picon
Gravatar

Re: easy_install and pypi


On Tue, Apr 1, 2008 at 12:44 PM, Colin Gillespie
<c.gillespie@...> wrote:
>
>  Dear All,
>
>  Just a quick note to say that pypi is slightly out of date. Also, I
>  use easy_install to install python packages, and although easy_install
>  works with sympy, there are a lot of warning messages.
>
>  The warning messages are mainly about not having __init__.py files in
>  your directories.
>
>  For example,
>
>  $ easy_install sympy
>  Searching for sympy
>  Reading http://www.python.org/pypi/sympy/
>  Couldn't find index page for 'sympy' (maybe misspelled?)
>  Scanning index of all packages (this may take a while)
>  Reading http://www.python.org/pypi/
>  Reading http://www.python.org/pypi/SymPy/0.5.11
>  Reading http://code.google.com/p/sympy/
>  Best match: sympy 0.5.13
>  Downloading http://sympy.googlecode.com/files/sympy-0.5.13.tar.gz
>  Processing sympy-0.5.13.tar.gz
>  Running sympy-0.5.13/setup.py -q bdist_egg --dist-dir /tmp/
>  easy_install-B3updq/sympy-0.5.13/egg-dist-tmp-as5Xhj
>  package init file 'sympy/concrete/tests/__init__.py' not found (or not
>  a regular file)
(Continue reading)

Colin Gillespie | 1 Apr 2008 14:19
Picon
Favicon

Re: easy_install and pypi


Hi Ondrej,

Warning: I'm not an expert on pypi or setup.py file, so these are only
suggestions.
>
> Thanks for noticing. The tests/ directories are our tests, so I don't
> think they should be imported. Why should there by __init__ files in
> it?
Could it be because  in setup.py you have:

packages = ['sympy'] + [ m[1] for m in modules ] + tests +
pyglet_packages,

i.e. you are installing tests
>
> To be honest, I never use pypi, as I find it not so convenient (and
> the web interface messy).
I quite like the easy_install option.

> However I understand some people use it and
> it helps for them, so I'd like to fix it. Do you know how to do it
> from the command line?
>
> This is what I get:
>
> $ ./setup.py register
> running register
> warning: register: missing meta-data: either (author and author_email)
> or (maintainer and maintainer_email) must be supplied
(Continue reading)

atir ajnopse | 1 Apr 2008 14:59
Picon
Picon

wildcard symbols


Hi.

I'm new to this list and was interested in sympy to use it to help
implement a DSL for audio synthesis.

I had a question: I would like to have a symbol, say "_" --without the
quotation marks ;-) , which creates unique copies of itself so that
the following is possible:

f = _ + _  -> would behave as f = x + y  (given x and y are Symbols),
a bit like it is used in many functional languages (and not like 2 *
_ )

It should also be possible to then substitute each symbol with a value
or with another symbol individually.

How could something like that be implemented?

cheers!

atir
Vinzent Steinberg | 1 Apr 2008 15:09

Re: compiling functions to machine code


Yeah, I tried to use from math import * (to avoid look ups), but I
failed somehow.

Anyway, here the result of Sage's timeit for evaluating f(1.0r)
(finally I got the point of the r :):

compiled:    625 loops, best of 3: 2.12 µs per loop
lambda:      625 loops, best of 3: 15.8 µs per loop
fast_float:  625 loops, best of 3: 4.54 µs per loop (roughly matches
with yours)

fast_float seems to be 3.5 times faster than pure Python, this matches
with my other benchmark (which is affected by Python's loop overhead).

Thank you for your support.

Vinzent

On 31 Mrz., 22:03, Mike Hansen <mhan...@...> wrote:

> This is probably because in Sage, sin, cos, pi, exp, etc. are all
> symbolic and talk to Maxima.  Note that in my  code posted about, I
> explicitly used math.sin etc. to test lambdas.
>
> --Mike

Gmane