Problem with passing my own names for intermediate variables to cse.
***************************************************
Python code:
#! /usr/bin/env python
from sympy import *
class Myname:
def __init__(self):
self.value = -1
def __iter__(self):
return self
def next(self):
self.value += 1
val = '%s%.2d' % ('tt',self.value)
return val
pg00=Symbol('pg00')
pg01=Symbol('pg01')
pg02=Symbol('pg02')
pg03=Symbol('pg03')
eq1= pg03**2
eq2= 2*pg01*pg03
eq3= pg00 + pg01*pg03**2 - pg02
eq = [eq1,eq2,eq3]
print eq
(red,rep) = cse(eq)
print red
print rep
print eq
My = Myname()
Myi = iter(My)
(red,rep) = cse(eq,Myi)
print red
print rep
*******************************************************
Output when using sympy 7.1
[pg03**2, 2*pg01*pg03, pg00 + pg01*pg03**2 - pg02]
[(x0, pg03**2)]
[x0, 2*pg01*pg03, pg00 + pg01*x0 - pg02]
[pg03**2, 2*pg01*pg03, pg00 + pg01*pg03**2 - pg02]
[('tt00', pg03**2)]
[tt00, 2*pg01*pg03, pg00 + pg01*tt00 - pg02]
***************************************************
Output when using bleeding edge version of sympy:
[pg03**2, 2*pg01*pg03, pg00 + pg01*pg03**2 - pg02]
[(x0, pg03**2)]
[x0, 2*pg01*pg03, pg00 + pg01*x0 - pg02]
[pg03**2, 2*pg01*pg03, pg00 + pg01*pg03**2 - pg02]
Traceback (most recent call last):
File "mytest4.py", line 36, in <module>
(red,rep) = cse(eq,Myi)
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 307,
in <lambda>
update = lambda x: x.xreplace({subtree: sym, 1/subtree: 1/sym})
TypeError: unsupported operand type(s) for /: 'int' and 'str'
*************************************************************************
So bleeding edge code fails is this case when I try using my own
names for intermediate variables. I should point out this only happens
sometimes. Most of the time the bleeding edge code behaves properly.
I am guessing you sympy experts can find a work around for me.
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/-/aJeTrEB5_UkJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.