Re: [sympy] Undesirable behavior from cse

2012-09-25 Thread Chris Smith
 if not b.q % a.q or not a.q % b.q:
 AttributeError: 'Infinity' object has no attribute 'q'

Infinity stopped inheriting from Rational a long time ago and this is
one of those lurking areas where it causes problems.

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



Re: [sympy] Undesirable behavior from cse

2012-09-25 Thread Ondřej Čertík
On Mon, Sep 24, 2012 at 11:38 PM, Chris Smith smi...@gmail.com wrote:
 if not b.q % a.q or not a.q % b.q:
 AttributeError: 'Infinity' object has no attribute 'q'

 Infinity stopped inheriting from Rational a long time ago and this is
 one of those lurking areas where it causes problems.

What would be the way to fix this?

Ondrej

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



Re: [sympy] Undesirable behavior from cse

2012-09-25 Thread Chris Smith
I only looked at this very quickly:

I get


 from sympy import *
 pg00 = Symbol('pg00')
 pg01 = Symbol('pg01')
 eq1 = sympify(pg01**2/pg00**2)
 eq2 = sympify(1.0 - 2*pg01/pg00)
 eq3 = sympify(pg01*(1.0 - pg01/pg00))
 eq = [eq1,eq2,eq3]
 print eq
[pg01**2/pg00**2, 1.0 - 2*pg01/pg00, pg01*(1.0 - pg01/pg00)]
 (red,rep) = cse(eq)
 red
[(x0, -pg01/pg00)]
 rep
[pg01**2/pg00**2, 1.0 - 2*pg01/pg00, pg01*(x0 + 1.0)]


after changing ndiv to be


def ndiv(a, b):
if b divides a in an extractive way (like 1/4 divides 1/2
but not vice versa, and 2/5 does not divide 1/3) then return
the integer number of times it divides, else return 0.

if a not in (S.Infinity, S.NegativeInfinity) and \
(not b.q % a.q or not a.q % b.q):
return int(a/b)
return 0

But it could be that the better fix is to not have infinity pulled out
-- by breakup?

Hopefully that can get someone started.

/c

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



Re: [sympy] Undesirable behavior from cse

2012-09-24 Thread Ondřej Čertík
Larry,

On Fri, Sep 7, 2012 at 2:50 PM, Larry Wigton lbw9...@aol.com wrote:


 On Thursday, September 6, 2012 6:26:38 PM UTC-7, smichr wrote:

 On Fri, Sep 7, 2012 at 1:40 AM, Larry Wigton lbw...@aol.com wrote:
  Python code using cse from sympy:
 
  from sympy import *
  x=Symbol('x')
  y=Symbol('y')
  eq1 = 5*x**3*y**2 + y**3
  eq2 = 4*x**2*y**3 + y**2
  eq = [eq1,eq2]
  print eq
  (red,rep) = cse(eq)
  print red
  print rep
  eq = [eq2,eq1]
  print eq
  (red,rep) = cse(eq)
  print red
  print rep
 
  ***
 
  Output from the code:
 
  [5*x**3*y**2 + y**3, 4*x**2*y**3 + y**2]
  [(x0, y**3), (x1, x0**(2/3))]
  [5*x**3*x1 + x0, 4*x**2*x0 + x1]
 
  [4*x**2*y**3 + y**2, 5*x**3*y**2 + y**3]
  [(x0, y**2), (x1, x0**(3/2))]
  [4*x**2*x1 + x0, 5*x**3*x0 + x1]
 
  **

 Current master gives

 [5*x**3*y**2 + y**3, 4*x**2*y**3 + y**2]
 [(x0, y**2)]
 [x0*(5*x**3 + y), x0*(4*x**2*y + 1)]
 [4*x**2*y**3 + y**2, 5*x**3*y**2 + y**3]
 [(x0, y**2)]
 [x0*(4*x**2*y + 1), x0*(5*x**3 + y)]

 googling sympy bleeding edge if you would like to get the most
 up-to-date (and soon to be released) 0.7.2 version.




 Thank you for telling me about the Bleeding edge version of sympy.

 Unfortunately it does not work for case which worked before.

 Test case for bleeding edge version of sympy:

 **

 pg00 = Symbol('pg00')
 pg01 = Symbol('pg01')
 eq1 = sympify(pg01**2/pg00**2)
 eq2 = sympify(1.0 - 2*pg01/pg00)
 eq3 = sympify(pg01*(1.0 - pg01/pg00))
 eq = [eq1,eq2,eq3]

 print eq
 (red,rep) = cse(eq)
 print red
 print rep

 

 Output from code:

 [pg01**2/pg00**2, 1.0 - 2*pg01/pg00, pg01*(1.0 - pg01/pg00)]
 Traceback (most recent call last):
   File mytest3.py, line 12, in module
 (red,rep) = cse(eq)
   File /acct/lbw9902/gitstuff/sympy/sympy/simplify/cse_main.py, line 313,
 in cse
 reduced_exprs[j] = update(expr)
   File /acct/lbw9902/gitstuff/sympy/sympy/simplify/cse_main.py, line 309,
 in lambda
 update = lambda x: x.subs(subtree, sym)
   File /acct/lbw9902/gitstuff/sympy/sympy/core/basic.py, line 852, in subs
 rv = rv._subs(old, new)
   File /acct/lbw9902/gitstuff/sympy/sympy/core/cache.py, line 88, in
 wrapper
 func_cache_it_cache[k] = r = func(*args, **kw_args)
   File /acct/lbw9902/gitstuff/sympy/sympy/core/basic.py, line 951, in
 _subs
 rv = fallback(self, old, new)
   File /acct/lbw9902/gitstuff/sympy/sympy/core/basic.py, line 938, in
 fallback
 arg = arg._subs(old, new, **hints)
   File /acct/lbw9902/gitstuff/sympy/sympy/core/cache.py, line 88, in
 wrapper
 func_cache_it_cache[k] = r = func(*args, **kw_args)
   File /acct/lbw9902/gitstuff/sympy/sympy/core/basic.py, line 949, in
 _subs
 rv = self._eval_subs(old, new)
   File /acct/lbw9902/gitstuff/sympy/sympy/core/mul.py, line 1276, in
 _eval_subs
 rat.append(ndiv(c_e, old_e))
   File /acct/lbw9902/gitstuff/sympy/sympy/core/mul.py, line 1186, in ndiv
 if not b.q % a.q or not a.q % b.q:
 AttributeError: 'Infinity' object has no attribute 'q'

 **

 Output from sympy 7.1

 [pg01**2/pg00**2, 1.0 - 2*pg01/pg00, pg01*(1.0 - pg01/pg00)]
 [(x0, 1/pg00), (x1, pg01*x0)]
 [x1**2, -2*x1 + 1.0, pg01*(-x1 + 1.0)]

 ***

 So it looks like bleeding edge version of sympy still needs some work.

This looks like a regression. Thanks for posting it.
If you want to help us debug it, just use git bisect to figure out a
patch that broke this.
Then it should be possible to see how to fix this.

Ondrej

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



Re: [sympy] Undesirable behavior from cse

2012-09-07 Thread Larry Wigton


On Thursday, September 6, 2012 6:26:38 PM UTC-7, smichr wrote:

 On Fri, Sep 7, 2012 at 1:40 AM, Larry Wigton lbw...@aol.com javascript: 
 wrote: 
  Python code using cse from sympy: 
  
  from sympy import * 
  x=Symbol('x') 
  y=Symbol('y') 
  eq1 = 5*x**3*y**2 + y**3 
  eq2 = 4*x**2*y**3 + y**2 
  eq = [eq1,eq2] 
  print eq 
  (red,rep) = cse(eq) 
  print red 
  print rep 
  eq = [eq2,eq1] 
  print eq 
  (red,rep) = cse(eq) 
  print red 
  print rep 
  
  *** 
  
  Output from the code: 
  
  [5*x**3*y**2 + y**3, 4*x**2*y**3 + y**2] 
  [(x0, y**3), (x1, x0**(2/3))] 
  [5*x**3*x1 + x0, 4*x**2*x0 + x1] 
  
  [4*x**2*y**3 + y**2, 5*x**3*y**2 + y**3] 
  [(x0, y**2), (x1, x0**(3/2))] 
  [4*x**2*x1 + x0, 5*x**3*x0 + x1] 
  
  ** 

 Current master gives 

 [5*x**3*y**2 + y**3, 4*x**2*y**3 + y**2] 
 [(x0, y**2)] 
 [x0*(5*x**3 + y), x0*(4*x**2*y + 1)] 
 [4*x**2*y**3 + y**2, 5*x**3*y**2 + y**3] 
 [(x0, y**2)] 
 [x0*(4*x**2*y + 1), x0*(5*x**3 + y)] 

 googling sympy bleeding edge if you would like to get the most 
 up-to-date (and soon to be released) 0.7.2 version. 




Thank you for telling me about the Bleeding edge version of sympy.

Unfortunately it does not work for case which worked before.

Test case for bleeding edge version of sympy:

**

pg00 = Symbol('pg00')
pg01 = Symbol('pg01')
eq1 = sympify(pg01**2/pg00**2)
eq2 = sympify(1.0 - 2*pg01/pg00)
eq3 = sympify(pg01*(1.0 - pg01/pg00))
eq = [eq1,eq2,eq3]
print eq
(red,rep) = cse(eq)
print red
print rep



Output from code:

[pg01**2/pg00**2, 1.0 - 2*pg01/pg00, pg01*(1.0 - pg01/pg00)]
Traceback (most recent call last):
  File mytest3.py, line 12, in module
(red,rep) = cse(eq)
  File /acct/lbw9902/gitstuff/sympy/sympy/simplify/cse_main.py, line 313, 
in cse
reduced_exprs[j] = update(expr)
  File /acct/lbw9902/gitstuff/sympy/sympy/simplify/cse_main.py, line 309, 
in lambda
update = lambda x: x.subs(subtree, sym)
  File /acct/lbw9902/gitstuff/sympy/sympy/core/basic.py, line 852, in subs
rv = rv._subs(old, new)
  File /acct/lbw9902/gitstuff/sympy/sympy/core/cache.py, line 88, in 
wrapper
func_cache_it_cache[k] = r = func(*args, **kw_args)
  File /acct/lbw9902/gitstuff/sympy/sympy/core/basic.py, line 951, in 
_subs
rv = fallback(self, old, new)
  File /acct/lbw9902/gitstuff/sympy/sympy/core/basic.py, line 938, in 
fallback
arg = arg._subs(old, new, **hints)
  File /acct/lbw9902/gitstuff/sympy/sympy/core/cache.py, line 88, in 
wrapper
func_cache_it_cache[k] = r = func(*args, **kw_args)
  File /acct/lbw9902/gitstuff/sympy/sympy/core/basic.py, line 949, in 
_subs
rv = self._eval_subs(old, new)
  File /acct/lbw9902/gitstuff/sympy/sympy/core/mul.py, line 1276, in 
_eval_subs
rat.append(ndiv(c_e, old_e))
  File /acct/lbw9902/gitstuff/sympy/sympy/core/mul.py, line 1186, in ndiv
if not b.q % a.q or not a.q % b.q:
AttributeError: 'Infinity' object has no attribute 'q'

**

Output from sympy 7.1

[pg01**2/pg00**2, 1.0 - 2*pg01/pg00, pg01*(1.0 - pg01/pg00)]
[(x0, 1/pg00), (x1, pg01*x0)]
[x1**2, -2*x1 + 1.0, pg01*(-x1 + 1.0)]

***

So it looks like bleeding edge version of sympy still needs some work.

   Larry Wigton

 

-- 
You received this message because you are subscribed to the Google Groups 
sympy group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sympy/-/HAC2fglIj6YJ.
To post to this group, send email to sympy@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.



Re: [sympy] Undesirable behavior from cse

2012-09-06 Thread Chris Smith
On Fri, Sep 7, 2012 at 1:40 AM, Larry Wigton lbw9...@aol.com wrote:
 Python code using cse from sympy:

 from sympy import *
 x=Symbol('x')
 y=Symbol('y')
 eq1 = 5*x**3*y**2 + y**3
 eq2 = 4*x**2*y**3 + y**2
 eq = [eq1,eq2]
 print eq
 (red,rep) = cse(eq)
 print red
 print rep
 eq = [eq2,eq1]
 print eq
 (red,rep) = cse(eq)
 print red
 print rep

 ***

 Output from the code:

 [5*x**3*y**2 + y**3, 4*x**2*y**3 + y**2]
 [(x0, y**3), (x1, x0**(2/3))]
 [5*x**3*x1 + x0, 4*x**2*x0 + x1]

 [4*x**2*y**3 + y**2, 5*x**3*y**2 + y**3]
 [(x0, y**2), (x1, x0**(3/2))]
 [4*x**2*x1 + x0, 5*x**3*x0 + x1]

 **

Current master gives

[5*x**3*y**2 + y**3, 4*x**2*y**3 + y**2]
[(x0, y**2)]
[x0*(5*x**3 + y), x0*(4*x**2*y + 1)]
[4*x**2*y**3 + y**2, 5*x**3*y**2 + y**3]
[(x0, y**2)]
[x0*(4*x**2*y + 1), x0*(5*x**3 + y)]

googling sympy bleeding edge if you would like to get the most
up-to-date (and soon to be released) 0.7.2 version.

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