Re: [sympy] How to equip a Symbol with an additional attribute?

2015-05-19 Thread Carsten Knoll
On 05/19/2015 07:48 AM, Joachim Durchholz wrote:
 
 An external dictionary isn't ideal but better than this, at least from
 the maintainer's perspective.
 
 Maybe we can give you better help if you describe your use case in some
 more detail.

 At some point I create symbols from which I know, that they are
 derivatives and I want to store their order. Using the classes Function
 and Derivative is no real option because I want the symbols to behave as
 symbols on most occasions.
 
 Ah. This sounds like a design problem in Derivative to me that we should
 fix.
 Can you post what you did, what you'd have needed to get out, and what
 SymPy gave you?

I think strongest argument for me was that the string representation of
the expressions gets too long for Functions and Derivatives. This
reduces my chance to see any structure.

Second argument is that I have a (own) library for modeling differential
forms which internally uses Symbol and does not straight forwardly work
with Function instances.

E.g.

x.name - 'x'
x(t).name - AttributeError

However, this discussions make me think, if using Functions would not be
the better alternative

 
 In general, I think there are situations, where it might be useful to
 store some algorithm-specific extra information to some symbols.
 
 For algorithms of SymPy itself, I think the algorithms should be fixed :-)
 
 It would be useful for coding external algorithms, but it does come with
 ramifications (most importantly the potential for namespace conflicts);
 from a maintenance perpective, it's far better if such an algorithm does
 its own data management.

OK. I can perfectly live with this.




-- 
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...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/555B0556.2040908%40gmx.de.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] How to equip a Symbol with an additional attribute?

2015-05-19 Thread Carsten Knoll
On 05/19/2015 02:39 AM, Aaron Meurer wrote:
 On Mon, May 18, 2015 at 12:29 PM, Joachim Durchholz j...@durchholz.org 
 wrote:
 Am 18.05.2015 um 15:56 schrieb Carsten Knoll:

 I want to equip an Symbol with an additional attribute to store some
 specific information right in place.

 For 'normal' Python classes it is no problem to dynamically create an
 additional attribute for an already existing instance.

 However, for sympy Symbols if I try

 x = Symbol('x')
 x.k = 0

 I get the error

 AttributeError: 'Symbol' object has no attribute 'k'


 That happens because we use __slots__ for performance reasons.
 However, storing attributes in that way is a bad idea in general, because
 you risk name conflicts with future versions of SymPy. (That's also the
 reason why using subclasses to extend a library tends to break over time.)
 
 I'm not so sure about this.
 
 The real reason that storing an attribute on x is a bad idea is that
 SymPy implicitly assumes that it can replace one expression with the
 same expression if the two are equal, so, e.g., if you had
 
 x1 = Symbol('x')
 x2 = Symbol('x')
 x1.k = 0
 
 and supposing it worked, along with x1 == x2 giving True, then SymPy
 would assume that it has the freedom at any point to swap x1 with x2
 and visa versa (and indeed, it does do this quite a bit with the
 cache).

Thanks for pointing that out. I will add it to my tests.

 
 I think what you really want to do is create a subclass of Symbol that
 stores the attributes in .args, so that they become part of the
 equality of the object.  Joachim's alternative 1 (store the
 information separately) also sounds like a good one (and probably much
 simpler to implement).


Subclassing and adding attributes in .args indeed seems more complicated.

I will stick with the external dict solution.


Regards,
Carsten.



-- 
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...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/555B0666.3060405%40gmx.de.
For more options, visit https://groups.google.com/d/optout.


[sympy] Bug with solve

2015-05-19 Thread Arnaud Usciati
Hello,

I tried to find the roots of : 2*sqrt(x)*sqrt(x**3 - x**2 + 1) + 2*x**3 - 
x**2 + x*sqrt(x**3 - x**2 + 1) + 2*x**1.5 + 2*x**2.5*sqrt(x**3 - x**2 + 1) 
- 3*x**2.5 - 4*x**3.5*sqrt(x**3 - x**2 + 1) - 2*x**3.5 + 5*x**4.5 - 
3*x**5.5 - 1 = 0.

x = symbols('x', real=True)
f = Lambda(x, 2*sqrt(x)*sqrt(x**3 - x**2 + 1) + 2*x**3 - x**2 + x*sqrt(x**3 
- x**2 + 1) + 2*x**1.5 + 2*x**2.5*sqrt(x**3 - x**2 + 1) - 3*x**2.5 - 
4*x**3.5*sqrt(x**3 - x**2 + 1) - 2*x**3.5 + 5*x**4.5 - 3*x**5.5 - 1)

Input : solve(f(x), x)
Output : [0.149910458676117, 0.865324593883105, 1.00, 
1.24896947842683, 2.56371129870321, 3.02429035798029]

But only 0.149910458676117 and 1 are really roots :
f(0.865324593883105) = 0.735269457206734
f(1.24896947842683) = -4.09736628717860
f(2.56371129870321) = -509.709822051607
f(3.02429035798029) = -1361.51149028959

Arnaud,

Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:15:05) [MSC v.1600 32 
bit (Intel)] on win32

-- 
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...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/ece1f69e-919b-4bde-ab31-9213adf06c35%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] Bug with solve

2015-05-19 Thread Arnaud Usciati
Hi,

I have : Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:15:05) [MSC 
v.1600 32 bit (Intel)] on win32

Le mardi 19 mai 2015 18:25:33 UTC+2, Aaron Meurer a écrit :

 What version of SymPy is this? On master I get 

 In [1]: x = symbols('x', real=True) 

 In [2]: f = Lambda(x, 2*sqrt(x)*sqrt(x**3 - x**2 + 1) + 2*x**3 - x**2 
 + x*sqrt(x**3 - x**2 + 1) + 2*x**1.5 + 2*x**2.5*sqrt(x**3 - x**2 + 1) 
 - 3*x**2.5 - 4*x**3.5*sqrt(x**3 - x**2 + 1) - 2*x**3.5 + 5*x**4.5 - 
 3*x**5.5 - 1) 

 In [3]:  solve(f(x), x) 
 Out[3]: [0.149910458676117, 1.0] 

 (note that it takes a while) 

 Aaron Meurer 


 On Tue, May 19, 2015 at 6:29 AM, Arnaud Usciati rai...@gmail.com 
 javascript: wrote: 
  Hello, 
  
  I tried to find the roots of : 2*sqrt(x)*sqrt(x**3 - x**2 + 1) + 2*x**3 
 - 
  x**2 + x*sqrt(x**3 - x**2 + 1) + 2*x**1.5 + 2*x**2.5*sqrt(x**3 - x**2 + 
 1) - 
  3*x**2.5 - 4*x**3.5*sqrt(x**3 - x**2 + 1) - 2*x**3.5 + 5*x**4.5 - 
 3*x**5.5 - 
  1 = 0. 
  
  x = symbols('x', real=True) 
  f = Lambda(x, 2*sqrt(x)*sqrt(x**3 - x**2 + 1) + 2*x**3 - x**2 + 
 x*sqrt(x**3 
  - x**2 + 1) + 2*x**1.5 + 2*x**2.5*sqrt(x**3 - x**2 + 1) - 3*x**2.5 - 
  4*x**3.5*sqrt(x**3 - x**2 + 1) - 2*x**3.5 + 5*x**4.5 - 3*x**5.5 - 1) 
  
  Input : solve(f(x), x) 
  Output : [0.149910458676117, 0.865324593883105, 1.00, 
  1.24896947842683, 2.56371129870321, 3.02429035798029] 
  
  But only 0.149910458676117 and 1 are really roots : 
  f(0.865324593883105) = 0.735269457206734 
  f(1.24896947842683) = -4.09736628717860 
  f(2.56371129870321) = -509.709822051607 
  f(3.02429035798029) = -1361.51149028959 
  
  Arnaud, 
  
  Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:15:05) [MSC v.1600 32 
 bit 
  (Intel)] on win32 
  
  -- 
  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+un...@googlegroups.com javascript:. 
  To post to this group, send email to sy...@googlegroups.com 
 javascript:. 
  Visit this group at http://groups.google.com/group/sympy. 
  To view this discussion on the web visit 
  
 https://groups.google.com/d/msgid/sympy/ece1f69e-919b-4bde-ab31-9213adf06c35%40googlegroups.com.
  

  For more options, visit https://groups.google.com/d/optout. 


-- 
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...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/b0503758-e6c6-4152-8bc4-c594526d4908%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] Bug with solve

2015-05-19 Thread Denis Akhiyarov
You gave Python version not sympy.__version__

-- 
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...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/d05d4cdb-11d4-4474-8543-a76bcf4e0018%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] Bug with solve

2015-05-19 Thread Arnaud Usciati
Right,

I have sympy-0.7.6.win32.

-- 
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...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/f0619d17-cdc0-47dd-858c-6a6415d212d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] How to equip a Symbol with an additional attribute?

2015-05-19 Thread Joachim Durchholz

Good points.
So I conclude that it would be nice if somebody came up with a way to 
allow user-defined attributes without running into namespace conflicts. 
Oh, and the mechanism should be easy to use for the casual user. I have 
some ideas in that direction, but I'd like to see what others think first.


Independently of that, I'd like to see somebody check whether the 
performace impact of __slots__ is still relevant; this may have changed 
with newer Python versions and I'd like to have some contemporary 
figures so we know what the actual trade-off is.


--
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...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/555B7F6B.10002%40durchholz.org.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] How to equip a Symbol with an additional attribute?

2015-05-19 Thread Aaron Meurer
On Tue, May 19, 2015 at 4:41 AM, Carsten Knoll carstenkn...@gmx.de wrote:
 On 05/19/2015 07:48 AM, Joachim Durchholz wrote:

 An external dictionary isn't ideal but better than this, at least from
 the maintainer's perspective.

 Maybe we can give you better help if you describe your use case in some
 more detail.

 At some point I create symbols from which I know, that they are
 derivatives and I want to store their order. Using the classes Function
 and Derivative is no real option because I want the symbols to behave as
 symbols on most occasions.

 Ah. This sounds like a design problem in Derivative to me that we should
 fix.
 Can you post what you did, what you'd have needed to get out, and what
 SymPy gave you?

 I think strongest argument for me was that the string representation of
 the expressions gets too long for Functions and Derivatives. This
 reduces my chance to see any structure.

 Second argument is that I have a (own) library for modeling differential
 forms which internally uses Symbol and does not straight forwardly work
 with Function instances.

 E.g.

 x.name - 'x'
 x(t).name - AttributeError

That's because x(t) is not really an instance of x. Symbol implements
__call__ so that x(t) returns a Function object (a completely
different class).

Aaron Meurer


 However, this discussions make me think, if using Functions would not be
 the better alternative


 In general, I think there are situations, where it might be useful to
 store some algorithm-specific extra information to some symbols.

 For algorithms of SymPy itself, I think the algorithms should be fixed :-)

 It would be useful for coding external algorithms, but it does come with
 ramifications (most importantly the potential for namespace conflicts);
 from a maintenance perpective, it's far better if such an algorithm does
 its own data management.

 OK. I can perfectly live with this.




 --
 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...@googlegroups.com.
 To post to this group, send email to sympy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sympy.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/sympy/555B0556.2040908%40gmx.de.
 For more options, visit https://groups.google.com/d/optout.

-- 
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...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6Kq9AqMk1O97Of%2BPN_NUJEwf2obaCbYa4fHo45PdbFOWg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[sympy] Magnitude of a complex number

2015-05-19 Thread Oscar Benjamin
Am I misunderstanding something here (using master):

$ isympy
Couldn't locate IPython. Having IPython installed is greatly recommended.
...
 z = (4+3*I)/(3-4*I)
 z
4 + 3⋅ⅈ
───
3 - 4⋅ⅈ
 abs(z)
  │   1   │
5⋅│───│
  │3 - 4⋅ⅈ│
 simplify(abs(z))
  │   1   │
5⋅│───│
  │3 - 4⋅ⅈ│
 abs(z).evalf()
1.00
 abs(z) ** 2
2
   │   1   │
25⋅│───│
   │3 - 4⋅ⅈ│
 z * z.conjugate()
(4 - 3⋅ⅈ)⋅(4 + 3⋅ⅈ)
───
(3 - 4⋅ⅈ)⋅(3 + 4⋅ⅈ)
 simplify(z * z.conjugate())
1

Why doesn't abs(z) simplify (or should I open an issue)?


--
Oscar

-- 
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...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAHVvXxS6DNZR8dPJ5AZ96V7MKtZQrvug_Pjs2%3DLejVOP6e73aw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] theano and sympy

2015-05-19 Thread Jason Moore
Theano is doing floating point computations whereas SymPy does the
computation using arbitrary precision.


Jason
moorepants.info
+01 530-601-9791

On Tue, May 19, 2015 at 3:14 PM, drazi...@gmail.com wrote:

 Hi,

 I was experimenting with the following code:

 import sympy
 from sympy.abc import x
 expr = sympy.exp(-x ** 2)
 from sympy.printing.theanocode import theano_function
 fn_theano  = theano_function([x], [expr], dims={x: 1}, dtypes={x:
 'float64'})
 print fn_theano([29.]),sympy.exp(-29.**2)

 I got


 [ 0.] 5.73245586032578e-366


 My question is why fn_theano does not  give the same value?

 Thank you,

 Costas



  --
 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...@googlegroups.com.
 To post to this group, send email to sympy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sympy.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/sympy/4662668c-68b0-482e-b467-92a6d2206d2e%40googlegroups.com
 https://groups.google.com/d/msgid/sympy/4662668c-68b0-482e-b467-92a6d2206d2e%40googlegroups.com?utm_medium=emailutm_source=footer
 .
 For more options, visit https://groups.google.com/d/optout.


-- 
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...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAP7f1Aj4gcgo-KGrH%2BBB%3DvPVbgZsiUckxVfiXQMd9UecZ0GqyA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] Bug with substituting derivatives

2015-05-19 Thread Jonathan Lindgren
Well, that is exactly the problem, and what I think is a bugit should 
not work like that..

Den tisdag 19 maj 2015 kl. 22:00:46 UTC+2 skrev Alexander Lindsay:

  Not to hijack this post, but why does subs(phi(z,t).diff(z),...) work 
 when phi(z,t).diff(t,2) does not contain any derivatives of phi with 
 respect to z? It seems like this substitution is saying that 
 phi(z,t).diff(z) = phi(z,t)

 I'm new to sympy, so I apologize if this is a stupid question.

 Alex

 On 05/19/2015 12:16 PM, Jonathan Lindgren wrote:
  
 I recently updated from sympy 0.7.4 (I tihnk) to 0.7.6 and now I have some 
 very strange behaviour with subs. The following code

 from sympy.abc import phi
 import sympy as sp

 z=sp.Symbol('z')
 t=sp.Symbol('t')

 sp.pprint((phi(z,t).diff(t,2)).subs(phi(z,t).diff(z),sp.Symbol('b')(z,t)).expand())


 gives me the output 
   2 
  ∂  
 ───(b(z, t))
   2 
 ∂t   
 but I would expect the output
   2 
  ∂  
 ───(φ(z, t))
   2 
 ∂t  

 This was working perfectly in my previous version of sympy.
  -- 
 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+un...@googlegroups.com javascript:.
 To post to this group, send email to sy...@googlegroups.com javascript:.
 Visit this group at http://groups.google.com/group/sympy.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/sympy/a50b1e03-3c37-4207-bc4b-7b6663c80c84%40googlegroups.com
  
 https://groups.google.com/d/msgid/sympy/a50b1e03-3c37-4207-bc4b-7b6663c80c84%40googlegroups.com?utm_medium=emailutm_source=footer
 .
 For more options, visit https://groups.google.com/d/optout.


 

-- 
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...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/6ba2478b-5aa0-429c-a0c9-f0cb21d0e720%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[sympy] theano and sympy

2015-05-19 Thread drazioti
Hi,

I was experimenting with the following code:

import sympy
from sympy.abc import x
expr = sympy.exp(-x ** 2)
from sympy.printing.theanocode import theano_function
fn_theano  = theano_function([x], [expr], dims={x: 1}, dtypes={x: 
'float64'})
print fn_theano([29.]),sympy.exp(-29.**2)

I got 


[ 0.] 5.73245586032578e-366


My question is why fn_theano does not  give the same value?

Thank you,

Costas



-- 
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...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/4662668c-68b0-482e-b467-92a6d2206d2e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] Bug with substituting derivatives

2015-05-19 Thread Alex Lindsay
Not to hijack this post, but why does subs(phi(z,t).diff(z),...) work 
when phi(z,t).diff(t,2) does not contain any derivatives of phi with 
respect to z? It seems like this substitution is saying that 
phi(z,t).diff(z) = phi(z,t)


I'm new to sympy, so I apologize if this is a stupid question.

Alex

On 05/19/2015 12:16 PM, Jonathan Lindgren wrote:
I recently updated from sympy 0.7.4 (I tihnk) to 0.7.6 and now I have 
some very strange behaviour with subs. The following code


from sympy.abc import phi
import sympy as sp

z=sp.Symbol('z')
t=sp.Symbol('t')
sp.pprint((phi(z,t).diff(t,2)).subs(phi(z,t).diff(z),sp.Symbol('b')(z,t)).expand())


gives me the output
  2
 ∂
───(b(z, t))
  2
∂t
but I would expect the output
  2
 ∂
───(φ(z, t))
  2
∂t

This was working perfectly in my previous version of sympy.
--
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...@googlegroups.com 
mailto:sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com 
mailto:sympy@googlegroups.com.

Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/a50b1e03-3c37-4207-bc4b-7b6663c80c84%40googlegroups.com 
https://groups.google.com/d/msgid/sympy/a50b1e03-3c37-4207-bc4b-7b6663c80c84%40googlegroups.com?utm_medium=emailutm_source=footer.

For more options, visit https://groups.google.com/d/optout.


--
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...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/555B966A.8080706%40ncsu.edu.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] Bug with solve

2015-05-19 Thread Aaron Meurer
What version of SymPy is this? On master I get

In [1]: x = symbols('x', real=True)

In [2]: f = Lambda(x, 2*sqrt(x)*sqrt(x**3 - x**2 + 1) + 2*x**3 - x**2
+ x*sqrt(x**3 - x**2 + 1) + 2*x**1.5 + 2*x**2.5*sqrt(x**3 - x**2 + 1)
- 3*x**2.5 - 4*x**3.5*sqrt(x**3 - x**2 + 1) - 2*x**3.5 + 5*x**4.5 -
3*x**5.5 - 1)

In [3]:  solve(f(x), x)
Out[3]: [0.149910458676117, 1.0]

(note that it takes a while)

Aaron Meurer


On Tue, May 19, 2015 at 6:29 AM, Arnaud Usciati rait...@gmail.com wrote:
 Hello,

 I tried to find the roots of : 2*sqrt(x)*sqrt(x**3 - x**2 + 1) + 2*x**3 -
 x**2 + x*sqrt(x**3 - x**2 + 1) + 2*x**1.5 + 2*x**2.5*sqrt(x**3 - x**2 + 1) -
 3*x**2.5 - 4*x**3.5*sqrt(x**3 - x**2 + 1) - 2*x**3.5 + 5*x**4.5 - 3*x**5.5 -
 1 = 0.

 x = symbols('x', real=True)
 f = Lambda(x, 2*sqrt(x)*sqrt(x**3 - x**2 + 1) + 2*x**3 - x**2 + x*sqrt(x**3
 - x**2 + 1) + 2*x**1.5 + 2*x**2.5*sqrt(x**3 - x**2 + 1) - 3*x**2.5 -
 4*x**3.5*sqrt(x**3 - x**2 + 1) - 2*x**3.5 + 5*x**4.5 - 3*x**5.5 - 1)

 Input : solve(f(x), x)
 Output : [0.149910458676117, 0.865324593883105, 1.00,
 1.24896947842683, 2.56371129870321, 3.02429035798029]

 But only 0.149910458676117 and 1 are really roots :
 f(0.865324593883105) = 0.735269457206734
 f(1.24896947842683) = -4.09736628717860
 f(2.56371129870321) = -509.709822051607
 f(3.02429035798029) = -1361.51149028959

 Arnaud,

 Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:15:05) [MSC v.1600 32 bit
 (Intel)] on win32

 --
 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...@googlegroups.com.
 To post to this group, send email to sympy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sympy.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/sympy/ece1f69e-919b-4bde-ab31-9213adf06c35%40googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.

-- 
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...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6K924%2BxJm25isfUaA%2BxhtH%3DdBcDyK5esyJKYEapK1siJg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] How to equip a Symbol with an additional attribute?

2015-05-19 Thread G B
Hi--

This seems as good a place as any to mention something I'd been trying to 
do some time ago where I ran into the same battle versus __slots__.  

I wanted to add a description attribute to my Symbols for documentation 
purposes.  I use Sympy almost exclusively inside of the IPython notebook 
for engineering work, and wind up with long sheets of derivations, 
substitutions, dead end attempts, etc.  I'm also trying to build up a 
personal library of formulas that I can import.

The problem I run in to is eventually, either due to complexity or time, I 
can't keep track of what all my symbols mean.  I like to keep the names 
themselves short so the symbolic output is easily understandable, but that 
relies on really strong conventions and a good memory to interpret-- which 
aren't always present...  =/

One solution was to put the description into the text of the notebook, 
which I often do, but then I have to find the place where that Symbol was 
defined to locate the descriptive text-- and then need to scroll back to 
the active cell to edit, then back and forth.

The solution I was after was to add a x.desc string to the Symbol, so I 
could just ask the Symbol itself what the hell I intended it to mean.  I 
then could modify Symbol to pretty print F_{B}: the force of the bat.  If 
I got really energetic, I'd change Expr to pretty print:

F_{B}=m_{b}*a_{b}
 Newton's Second Law of Motion where:
   F_{B}  is the force of the bat
   m_{b}  is the mass of the ball
   a_{b}   is the acceleration of the ball

For all the maintenance reasons you describe, these are changes that should 
happen in the Sympy library itself, but it's easier for me to experiment in 
my own sandbox without upsetting the core code and the __slots__ prevents 
this.  There's also the chance that I can't convince enough people this 
should be a core part of the library, or to implement it in the way I'd 
like, and then I'm stuck.

Maintenance isn't quite as big an issue for me as I'm not building long 
standing applications-- I'm generating documents.  Sure, I'd like those to 
remain viable for as long as possible so I can edit them in the future, but 
it's not the same has having deployed a large codebase.  If I have to go 
through and change all my references from .desc to .desc2 for my notebook 
to run, it's not the end of the world.

Storing all of this in an outside data structure does have the potential 
advantage in that I could then look up a symbol if I knew what it meant but 
not its symbolic representation:
   SymbolIndex['accel ball']

or find all the formulas I have involving the ball:
   ExpressionIIndex['ball']
   ExpressionIndex[a_{b}]

but that would have required some deeper hacking into the Symbol creation 
and destruction mechanisms.

Anyway, probably wandered off topic a bit, but I just wanted to put a vote 
in for user attributes and the possible elimination of __slots__  if that 
isn't a significant performance hit.

On Monday, May 18, 2015 at 10:29:42 AM UTC-7, Joachim Durchholz wrote:

 Am 18.05.2015 um 15:56 schrieb Carsten Knoll: 
  I want to equip an Symbol with an additional attribute to store some 
  specific information right in place. 
  
  For 'normal' Python classes it is no problem to dynamically create an 
  additional attribute for an already existing instance. 
  
  However, for sympy Symbols if I try 
  
  x = Symbol('x') 
  x.k = 0 
  
  I get the error 
  
  AttributeError: 'Symbol' object has no attribute 'k' 

 That happens because we use __slots__ for performance reasons. 
 However, storing attributes in that way is a bad idea in general, 
 because you risk name conflicts with future versions of SymPy. (That's 
 also the reason why using subclasses to extend a library tends to break 
 over time.) 

 Alternative 1: You could set up a dict with a Symbol-to-attributes 
 mapping: Symbols are hashable (that's a guaranteed property). 

 Alternative 2: We could add a `userdict` attribute in Symbol, so that 
 SymPy users can store additional attributes there. 

 I'm not too happy with either alternative. 
 Maybe we can give you better help if you describe your use case in some 
 more detail. 

 Regards, 
 Jo 


-- 
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...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/c81f5af8-ef92-4ddb-add0-eb0053c51a5f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[sympy] Bug with substituting derivatives

2015-05-19 Thread Jonathan Lindgren
I recently updated from sympy 0.7.4 (I tihnk) to 0.7.6 and now I have some 
very strange behaviour with subs. The following code

from sympy.abc import phi
import sympy as sp

z=sp.Symbol('z')
t=sp.Symbol('t')
sp.pprint((phi(z,t).diff(t,2)).subs(phi(z,t).diff(z),sp.Symbol('b')(z,t)).expand())


gives me the output 
  2 
 ∂  
───(b(z, t))
  2 
∂t   
but I would expect the output
  2 
 ∂  
───(φ(z, t))
  2 
∂t  

This was working perfectly in my previous version of sympy.

-- 
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...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/a50b1e03-3c37-4207-bc4b-7b6663c80c84%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.