Gabor Takacs | 2 Oct 2011 23:14
Picon

evaluate=False by default?

Hi,

I experienced that sympy applies automatic evaluation at expression
creation by default
(the evaluate parameter is True in the constructors).

Therefore, e.g.
- I**3 evaluates to -I
- Pow(I, 3, evaluate=False) evaluates to I**3, but
  Pow(I, 3, evaluate=False) * 1 evaluates to -I

Is it possible to change the default behaviour to "no automatic
evaluation at expression creation"?
(so that I**3 evaluates to I**3)

Gabor

--

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

gsagrawal | 3 Oct 2011 06:44
Picon

Re: evaluate=False by default?

yes , i am facing the same problems.

specially when you try to convert a string format user input into a valid sympy expression using simpify(expr) which internally calls Add and Mul with default parameter (evaluate=true). is there any way to control this ?

On Mon, Oct 3, 2011 at 2:44 AM, Gabor Takacs <gtakacs23-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Hi,

I experienced that sympy applies automatic evaluation at expression
creation by default
(the evaluate parameter is True in the constructors).

Therefore, e.g.
- I**3 evaluates to -I
- Pow(I, 3, evaluate=False) evaluates to I**3, but
 Pow(I, 3, evaluate=False) * 1 evaluates to -I

Is it possible to change the default behaviour to "no automatic
evaluation at expression creation"?
(so that I**3 evaluates to I**3)

Gabor

--
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-/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.
Sean Vig | 3 Oct 2011 08:33
Picon
Gravatar

Extending physics.spin for coupling arbitrary numbers of spin spaces

Hi everyone,


Since finishing up my GSoC project, I've put in a bit of time to finish some of the project up, namely, extending the coupling of spin spaces to an arbitrary number of spaces (I only finished the coupling of 2 spaces during the project run). The working branch is here [0]. I have what I think is a working implementation, I still need to implement tests before I'm willing to say for sure it works, and  some of the functions are pretty messy. Nevertheless, I figured I'd get some input on the changes, especially the syntax for defining these couplings, before I started polishing it up.

To make sure everyone is on the same page, I'll outline what exactly I'm trying to do. With anyone with experience with coupled spin states will know, when you define a coupled state, you must not only define the quantum numbers of the state, but also the angular momentum numbers of the states that are being coupled together. Currently, in the master, the additional j-values are added as options when creating the state, e.g. |1,1,j1=1/2,j2=1/2> is given by JzCoupledKet(1,1,1/2,1/2). For coupling two spaces, this coupling is trivial, but for more than two spaces, the order in which the spaces are coupled matters. For example, if you have a j1, j2 and j3, you can couple j1 and j2 to j12, then j12 and j3 to j, which is different from coupling j1 and j3 to j13 then j13 and j2 to j. Defining this order is what I'm working to define in the current states.

The current implementation changes the __new__ method to take not only the jvals list as before, but also has an option to define a jcoupling parameter. This parameter is an array of lists, the lists being length 3. For these inner lists, the first and second parameters give the j values of the states to be coupled and the third parameter gives the angular momentum j-value of the coupled space, so if you were to couple j1 and j2 to j12, the corresponding list element would be (1,2,j12). Thus, if one wanted to define a coupled spin state, coupling 3 spaces and coupling j1 and j2 to j12, i.e. |j,m,j1,j2,(j12),j3>, in would be defined as JzCoupledKet(j,m,(j1,j2,j3),jcoupling=((1,2,j12),)). If jcoupling isn't defined, it currently defaults to coupling j1 and j2 to j12, then j12 and j3 to j123, etc, where j1...n=j1+...+jn. Note that jcoupling must have n-2 couplings defined for coupling n spaces, as the last coupling is made implicitly to the final j value of the state, so to couple 4 spaces, would need 2 couplings defined, e.g. jcoupling=((1,2,j12),(3,4,j34)). To anyone who plays with it, if you want to couple a space that is already coupled, for example coupling some j34 to another spin space, you must use the smallest value, in this example 3, to define which space is being coupled in the jcoupling parameter.

While this implementation allows for full generality in defining spin states, it seems to me to be quite messy. If anyone has any suggestions or would be willing to look at some of the code, I'd greatly appreciate it. If anything isn't clear or something isn't working right, please let me know.

Thanks to anyone for any feedback on this,
Sean 

--
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.
Aaron Meurer | 3 Oct 2011 17:43
Picon
Gravatar

Re: evaluate=False by default?

Currently there is not, but I don't think it would be very difficult
to add the behavior in as a global parameter at least.  If you want to
just make it an option to sympify (like sympify('1 + 1',
evaluate=False)), I don't know how difficult that would be, since the
parser would have to be modified, but it should be doable.  But we
definitely would accept a patch that does so. Please open an issue for
it in any case.

As for multiplying by something causing an unevaluated expression to
evaluate, I consider this to be a bug.  It no longer does it in master
with 1 (because the constructor ignores the identity), but it will
still do it with any other number.

Aaron Meurer

On Sun, Oct 2, 2011 at 10:44 PM, gsagrawal <gsagrawal@...> wrote:
> yes , i am facing the same problems.
> specially when you try to convert a string format user input into a valid
> sympy expression using simpify(expr) which internally calls Add and Mul with
> default parameter (evaluate=true). is there any way to control this ?
> On Mon, Oct 3, 2011 at 2:44 AM, Gabor Takacs <gtakacs23@...> wrote:
>>
>> Hi,
>>
>> I experienced that sympy applies automatic evaluation at expression
>> creation by default
>> (the evaluate parameter is True in the constructors).
>>
>> Therefore, e.g.
>> - I**3 evaluates to -I
>> - Pow(I, 3, evaluate=False) evaluates to I**3, but
>>  Pow(I, 3, evaluate=False) * 1 evaluates to -I
>>
>> Is it possible to change the default behaviour to "no automatic
>> evaluation at expression creation"?
>> (so that I**3 evaluates to I**3)
>>
>> Gabor
>>
>> --
>> 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.
>>
>
> --
> 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.
>

--

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

gsagrawal | 4 Oct 2011 07:53
Picon

Re: evaluate=False by default?

i was using one global variable to achieve this.
i have modified core->operation-> AssocOp with the version 0.6.5
and sympify('1 + 1',evaluate=False)) was working exactly fine returning "1+1"
but recently i have shifted to version 0.7.1
Issue is now when i call sympify("2*x+3*x) , this is not even going in to AssocOp class __new_ method.
and somehow it returns 5*x
could you please tell which class does sympify uses to evaluate Add.
i am kind of stucked here.

On Mon, Oct 3, 2011 at 9:13 PM, Aaron Meurer <asmeurer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Currently there is not, but I don't think it would be very difficult
to add the behavior in as a global parameter at least.  If you want to
just make it an option to sympify (like sympify('1 + 1',
evaluate=False)), I don't know how difficult that would be, since the
parser would have to be modified, but it should be doable.  But we
definitely would accept a patch that does so. Please open an issue for
it in any case.

As for multiplying by something causing an unevaluated expression to
evaluate, I consider this to be a bug.  It no longer does it in master
with 1 (because the constructor ignores the identity), but it will
still do it with any other number.

Aaron Meurer

On Sun, Oct 2, 2011 at 10:44 PM, gsagrawal <gsagrawal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> yes , i am facing the same problems.
> specially when you try to convert a string format user input into a valid
> sympy expression using simpify(expr) which internally calls Add and Mul with
> default parameter (evaluate=true). is there any way to control this ?
> On Mon, Oct 3, 2011 at 2:44 AM, Gabor Takacs <gtakacs23-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>>
>> Hi,
>>
>> I experienced that sympy applies automatic evaluation at expression
>> creation by default
>> (the evaluate parameter is True in the constructors).
>>
>> Therefore, e.g.
>> - I**3 evaluates to -I
>> - Pow(I, 3, evaluate=False) evaluates to I**3, but
>>  Pow(I, 3, evaluate=False) * 1 evaluates to -I
>>
>> Is it possible to change the default behaviour to "no automatic
>> evaluation at expression creation"?
>> (so that I**3 evaluates to I**3)
>>
>> Gabor
>>
>> --
>> 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-/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.
gsagrawal | 4 Oct 2011 10:07
Picon

Re: evaluate=False by default?

Found the issue,
Actually my below issue was because of catching. i was trying to parse same expression twice ,1st with evaluate=True and 2nd time with evaluate =False. so because of catching it is returning the previous result only
but again my problem remain as caching is there. so any way to fix this ?

On Tue, Oct 4, 2011 at 11:23 AM, gsagrawal <gsagrawal <at> gmail.com> wrote:
i was using one global variable to achieve this.
i have modified core->operation-> AssocOp with the version 0.6.5
and sympify('1 + 1',evaluate=False)) was working exactly fine returning "1+1"
but recently i have shifted to version 0.7.1
Issue is now when i call sympify("2*x+3*x) , this is not even going in to AssocOp class __new_ method.
and somehow it returns 5*x
could you please tell which class does sympify uses to evaluate Add.
i am kind of stucked here.


On Mon, Oct 3, 2011 at 9:13 PM, Aaron Meurer <asmeurer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Currently there is not, but I don't think it would be very difficult
to add the behavior in as a global parameter at least.  If you want to
just make it an option to sympify (like sympify('1 + 1',
evaluate=False)), I don't know how difficult that would be, since the
parser would have to be modified, but it should be doable.  But we
definitely would accept a patch that does so. Please open an issue for
it in any case.

As for multiplying by something causing an unevaluated expression to
evaluate, I consider this to be a bug.  It no longer does it in master
with 1 (because the constructor ignores the identity), but it will
still do it with any other number.

Aaron Meurer

On Sun, Oct 2, 2011 at 10:44 PM, gsagrawal <gsagrawal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> yes , i am facing the same problems.
> specially when you try to convert a string format user input into a valid
> sympy expression using simpify(expr) which internally calls Add and Mul with
> default parameter (evaluate=true). is there any way to control this ?
> On Mon, Oct 3, 2011 at 2:44 AM, Gabor Takacs <gtakacs23-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>>
>> Hi,
>>
>> I experienced that sympy applies automatic evaluation at expression
>> creation by default
>> (the evaluate parameter is True in the constructors).
>>
>> Therefore, e.g.
>> - I**3 evaluates to -I
>> - Pow(I, 3, evaluate=False) evaluates to I**3, but
>>  Pow(I, 3, evaluate=False) * 1 evaluates to -I
>>
>> Is it possible to change the default behaviour to "no automatic
>> evaluation at expression creation"?
>> (so that I**3 evaluates to I**3)
>>
>> Gabor
>>
>> --
>> 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 <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-/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.
Aaron Meurer | 4 Oct 2011 18:24
Picon
Gravatar

Re: evaluate=False by default?

You can turn caching off.  See the "How do I turn off caching" section
of https://github.com/sympy/sympy/wiki/faq.  You need to set the
SYMPY_USE_CACHE environment variable to "no".

This will slow parts of SymPy down by quite a bit, so if the
performance is too slow when you do this, you might find the specific
part that is being cached and either modify it to include evaluate in
the cache or remove the caching there.  The caching is handled by the
 <at> cacheit decorator.

Aaron Meurer

On Tue, Oct 4, 2011 at 2:07 AM, gsagrawal <gsagrawal@...> wrote:
> Found the issue,
> Actually my below issue was because of catching. i was trying to parse same
> expression twice ,1st with evaluate=True and 2nd time with evaluate =False.
> so because of catching it is returning the previous result only
> but again my problem remain as caching is there. so any way to fix this ?
>
> On Tue, Oct 4, 2011 at 11:23 AM, gsagrawal <gsagrawal@...> wrote:
>>
>> i was using one global variable to achieve this.
>> i have modified core->operation-> AssocOp with the version 0.6.5
>> and sympify('1 + 1',evaluate=False)) was working exactly fine returning
>> "1+1"
>> but recently i have shifted to version 0.7.1
>> Issue is now when i call sympify("2*x+3*x) , this is not even going in to
>> AssocOp class __new_ method.
>> and somehow it returns 5*x
>> could you please tell which class does sympify uses to evaluate Add.
>> i am kind of stucked here.
>>
>> On Mon, Oct 3, 2011 at 9:13 PM, Aaron Meurer <asmeurer@...> wrote:
>>>
>>> Currently there is not, but I don't think it would be very difficult
>>> to add the behavior in as a global parameter at least.  If you want to
>>> just make it an option to sympify (like sympify('1 + 1',
>>> evaluate=False)), I don't know how difficult that would be, since the
>>> parser would have to be modified, but it should be doable.  But we
>>> definitely would accept a patch that does so. Please open an issue for
>>> it in any case.
>>>
>>> As for multiplying by something causing an unevaluated expression to
>>> evaluate, I consider this to be a bug.  It no longer does it in master
>>> with 1 (because the constructor ignores the identity), but it will
>>> still do it with any other number.
>>>
>>> Aaron Meurer
>>>
>>> On Sun, Oct 2, 2011 at 10:44 PM, gsagrawal <gsagrawal@...> wrote:
>>> > yes , i am facing the same problems.
>>> > specially when you try to convert a string format user input into a
>>> > valid
>>> > sympy expression using simpify(expr) which internally calls Add and Mul
>>> > with
>>> > default parameter (evaluate=true). is there any way to control this ?
>>> > On Mon, Oct 3, 2011 at 2:44 AM, Gabor Takacs <gtakacs23@...>
>>> > wrote:
>>> >>
>>> >> Hi,
>>> >>
>>> >> I experienced that sympy applies automatic evaluation at expression
>>> >> creation by default
>>> >> (the evaluate parameter is True in the constructors).
>>> >>
>>> >> Therefore, e.g.
>>> >> - I**3 evaluates to -I
>>> >> - Pow(I, 3, evaluate=False) evaluates to I**3, but
>>> >>  Pow(I, 3, evaluate=False) * 1 evaluates to -I
>>> >>
>>> >> Is it possible to change the default behaviour to "no automatic
>>> >> evaluation at expression creation"?
>>> >> (so that I**3 evaluates to I**3)
>>> >>
>>> >> Gabor
>>> >>
>>> >> --
>>> >> 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.
>>> >>
>>> >
>>> > --
>>> > 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.
>>> >
>>>
>>> --
>>> 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.
>>>
>>
>
> --
> 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.
>

--

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

Vinzenz | 5 Oct 2011 09:53
Picon
Favicon

[sympy] Re: Gröbner Bases / Modulus / Algebraic Relations

On 29 Sep., 23:51, Mateusz Paprocki <matt...@...> wrote:
> Hi,
>
> On 29 September 2011 05:07, Vinzenz <vbargs...@...> wrote:
>
>
> > Hi,
>
> > I'm trying to port a Mathematica project to sympy. Therefore, I would
> > like to use an algorithm to decompose an expression using Gröbner
> > Bases as described in
>
> > 8.3 Algebraic Relations, Gröbner Bases: A Short Introduction for
> > Systems Theorists (http://people.reed.edu/~davidp/pcmi/buchberger.pdf
> > )
>
> > I already figured out, that sympy offers a function to compute Gröbner
> > Bases.
> > However, what could a solution, similar to what Mathematica's
> > PolynomialReduce does in this case, look like in sympy?
> > Alternatively, I could for now solve my problem with simple variables
> > instead of polynomials and use something similar to Mathematica's
> > Coefficient[] to pull out the according coefficients from the
> > expression.
>
> You may find this http://mattpap.github.com/masters-thesis/html/src/groebner.html#algeb...
>  interesting.
>
> Coefficient[] can be replaced with either Expr.coeff() (partially) or
> Poly.nth(), e.g.:
>
> In [2]: (x**2 + 2*x + 3).coeff(x**2)
> Out[2]: 1
>
> In [3]: (x**2 + 2*x + 3).coeff(x**1)
> Out[3]: 2
>
> Unfortunately (x**2 + 2*x + 3).coeff(x**0) does something different than
> expected (seehttp://code.google.com/p/sympy/issues/detail?id=2558).
>
> In [5]: Poly(x**2 + 2*x + 3).nth(2)
> Out[5]: 1
>
> In [6]: Poly(x**2 + 2*x + 3).nth(1)
> Out[6]: 2
>
> In [7]: Poly(x**2 + 2*x + 3).nth(0)
> Out[7]: 3
>
>
>
>
>
>
>
>
>
>
>
> > This is my Mathematica code for the example:
> > ---------------------------------------------------------------------------
> > pv = {x1^2 + x2^2,  x]^2*x2^2,  x1^3*x2 - x1*x2^3}
> > tau1 =  x1^7*x2 - x1*x2^7
> > Vars = {x1, x2, Subscript[j, 3], Subscript[j, 2], Subscript[j, 1]};
> > Table[-Subscript[j, i] + pv[[i]], {i, Length[pv]}]
> > G = FullSimplify[
> >       GroebnerBasis[
> >            Table[-Subscript[j, i] + pv[[i]], {i, Length[pv]}], Vars]
> >       ];
>
> > MatrixForm[G]
>
> > {Cf, mRest} = PolynomialReduce[tau1, G, Vars];
> > Cf
> > mRest
> > --------------------------------------------------------------------------
>
> Mateusz

On 29 Sep., 16:05, Jeremias Yehdegho <j.yehde...@...> wrote:
> Hi, ``reduced`` from polytools.py does this.
>
> Regards,
> Jeremias

Thank you very much!

"reduced" is what I searched for, "coef"/"nth" is used afterwards.

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 <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sympy?hl=en.

Germán | 6 Oct 2011 15:58
Picon
Gravatar

Re: Using SymPy in a Python script

Thanks a lot, I had that silly error too.

On Oct 16 2010, 1:33 am, Ondrej Certik <ond...@...> wrote:
> On Fri, Oct 15, 2010 at 8:48 PM, HappyMac
<youngjin.lee...@...> wrote:
> > Dear all,
>
> > I am new to SymPy and trying to learning how to use.
> > I have installed the latest SymPy (v. 0.6.7) and tried the following
> > Python script:
>
> > sympy_test.py
>
> > from sympy import Symbol
> > from math import *
>
> ^^^ Never ever use implicit imports (if possible). By writing this explicitly:
>
> from math import sqrt, exp
>
> it becomes clear, what is happening:
>
>
>
> > x = Symbol('x')
> > i = 0
> > prior = 1 / sqrt(2*pi) * exp(-1*x**2 / 2)
>
> You are using math.exp() here, so it needs a floating point number,
> but sympy doesn't know how to convert "x" to a floating point number,
> thus you get the exception below. The solution is to replace the line
>
> from math import sqrt, exp
>
> with
>
> from sympy import sqrt, exp
>
>
>
>
>
>
>
>
>
> > p = 1 / (1 + exp(-1*discriminations[i]*(x - difficulties[1])))
> > q = 1 - p
> > posterior = prior * q
> > print posterior
>
> > But, when I ran this Python code, I got the following error message:
> > Traceback (most recent call last):
> >  File "/Applications/eclipse/plugins/
> > org.python.pydev.debug_1.5.7.2010050621/pysrc/pydevd.py", line 978, in
> > <module>
> >    debugger.run(setup['file'], None, None)
> >  File "/Applications/eclipse/plugins/
> > org.python.pydev.debug_1.5.7.2010050621/pysrc/pydevd.py", line 780, in
> > run
> >    execfile(file, globals, locals) #execute the script
> >  File "/Users/yjlee/Documents/Worx/EclipseWorx/SymPyProjects/src/
> > sympy_test.py", line 44, in <module>
> >    prior = 1 / sqrt(2*pi) * exp(-1*x**2 / 2)
> >  File "/Library/Python/2.6/site-packages/sympy/core/basic.py", line
> > 2103, in __float__
> >    raise ValueError("Symbolic value, can't compute")
> > ValueError: Symbolic value, can't compute
>
> > All I was trying to do was to get a product of two functions, and I
> > could not figure out what I did wrong.
>
> > Could anyone tell me what I did wrong?
>
> 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.

David Joyner | 6 Oct 2011 17:57
Picon
Gravatar

papers on sympy?

Hi:

I was wondering if there is a list of papers on/using sympy
on the sympy website, analogous to
http://www.sagemath.org/library-publications.html?

- David

--

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


Gmane