It may be late to reply on this topic.
but i just want to add that all functionality of sympy works with
evaluate=True on add/mul . If you are dealing with evaluate=False ,there
are lots of chances that you will face max recursion errors or some
unwanted results . I have faced similar issues while working on my project (
http://tuttr.com) and ended up writing overrides for these classes.
if you want I can share the possible issues/constraints in this regard

---
Thanks,
Ghanshyam Agrawal
Contact No : +919717167192
Core Team Member :tutrr.com

On Thu, Mar 14, 2013 at 4:46 AM, Aaron Meurer <asmeu...@gmail.com> wrote:

> The idea from https://code.google.com/p/sympy/issues/detail?id=3613
> might also interest you.  It's not simple to implement, but I think it
> wouldn't be too hard.
>
> Aaron Meurer
>
> On Wed, Mar 13, 2013 at 1:40 PM, Duane Nykamp <dqnyk...@comcast.net>
> wrote:
> > It was an interesting exercise trying to get an UnevaluatedAdd/Mul/Pow
> > implemented.  It ended up being trickier because the arguments weren't
> sympy
> > objects, so the latex and str print code didn't work outright.  What
> ended
> > up defeating me, though, was the term ordering.  Since I would use the
> > unevaluated expressions for intermediate steps in a solution, the folks
> who
> > would benefit from seeing the intermediate steps would presumably be
> those
> > for whom term reordering would confuse them.  The term reordering ended
> up
> > getting deeper into the fundamentals of sympy than I could understand.
> >
> > I recognize that this wouldn't be a standard use of sympy, so not a high
> > priority.  But, if someday, you do get around to rework the
> evaluate=False
> > functionality, that would be great.
> >
> > Duane
> >
> >
> >
> > On Tuesday, March 12, 2013 12:30:59 AM UTC-5, Aaron Meurer wrote:
> >>
> >> On Mar 11, 2013, at 10:58 PM, Duane Nykamp <dqny...@comcast.net> wrote:
> >>
> >> Getting closer.  With
> >>
> >> class UnevaluatedAdd(Expr):
> >>     def _sympystr(self, printer):
> >>         return "%s + %s" % (printer._print(self.args[0]),
> >> printer._print(self.args[1]))
> >>
> >> parse_expr("x+1").replace(Add,UnevaluatedAdd).subs(x,-1)
> >>
> >> returns 1+-1, for obvious reasons.  So I made it even uglier
> >>
> >> class UnevaluatedAdd(Expr):
> >>     def _sympystr(self, printer):
> >>         if(self.args[1] < 0):
> >>             return "%s %s" % (printer._print(self.args[0]),
> >> printer._print(self.args[1]))
> >>         else:
> >>             return "%s + %s" % (printer._print(self.args[0]),
> >> printer._print(self.args[1]))
> >>
> >>
> >> Add takes an arbitrary number of arguments. So you'll need to be a
> little
> >> more general than that. You can probably just set _sympystr equal to
> >> StrPrinter._print_Add (modulo some argument shuffling). Or if you find
> it
> >> needs to be modified just copy the source of StrPrinter._print_Add and
> >> modify it (it's BSD licensed for a reason).
> >>
> >>
> >> I don't know if this is a recommended way to do it, but it seems to
> work.
> >>
> >> Interestingly, I noticed with playing around that
> >> Add(x,1,evaluate=False).subs(x,-1)
> >> returns 0.  I don't know if that is intended.
> >>
> >>
> >> Yes, evaluate=False is somewhat of a hack. Many operations will undo it,
> >> because they rebuild expressions. That's actually what the other
> discussion
> >> going on in this thread is all about: a better replacement for
> >> evaluate=False.
> >>
> >> Aaron Meurer
> >>
> >>
> >> Duane
> >>
> >>
> >> On Monday, March 11, 2013 11:25:31 PM UTC-5, Aaron Meurer wrote:
> >>>
> >>> On Mon, Mar 11, 2013 at 9:38 PM, Duane Nykamp <dqny...@comcast.net>
> >>> wrote:
> >>> > Thanks for your responses.
> >>> >
> >>> > I was pretty sure parse_expr was secure, given how it tokenizes
> before
> >>> > it
> >>> > uses an eval.
> >>> >
> >>> > The UnevaluatedLog example does exactly what I want for log.
>  However,
> >>> > I
> >>> > cannot figure out how to extend it to an Add or Mul that I get from a
> >>> > parsed
> >>> > input.  In many of the examples, one calculates a function, then
> >>> > evaluates
> >>> > it at particular value.  For example, if f(x)=3+x, then I'd like to
> >>> > show
> >>> > f(5)=3+5 = 8 and f(-5) = 3 - 5 = -2 (where, in the second case, it
> does
> >>> > some
> >>> > simplification to avoid 3+-5).     Given your evaluate hint, I could
> do
> >>> > this
> >>> > with Add(-3,-2, evaluate=False).   But, there doesn't seem to be away
> >>> > to do
> >>> > this with the parser.  Unfortunately, I can't even do
> >>> > parse_expr("Add(-3,-2,
> >>> > evaluate=False)"), as parse_expr doesn't allow keywords.  If I
> >>> > understand
> >>> > the conversation right, this isn't possible with the current version.
> >>>
> >>> That bug has been fixed in the git version.
> >>>
> >>> I guess what you also could do for that case is create an
> >>> UnevaluatedAdd (in this case, you should just subclass Expr rather
> >>> than Function), and replace the Add with that.    Then replace the x
> >>> with the number in that.  The logic for this might be a little more
> >>> complicated, but it's doable.
> >>>
> >>> Aaron Meurer
> >>>
> >>> >
> >>> > Thanks for the tips.
> >>> >
> >>> >
> >>> > Duane
> >>> >
> >>> >
> >>> > --
> >>> > 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.
> >>> > To post to this group, send email to sy...@googlegroups.com.
> >>> > Visit this group at http://groups.google.com/group/sympy?hl=en.
> >>> > For more options, visit https://groups.google.com/groups/opt_out.
> >>> >
> >>> >
> >>
> >> --
> >> 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.
> >> To post to this group, send email to sy...@googlegroups.com.
> >> Visit this group at http://groups.google.com/group/sympy?hl=en.
> >> For more options, visit https://groups.google.com/groups/opt_out.
> >>
> >>
> >
> > --
> > 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?hl=en.
> > For more options, visit https://groups.google.com/groups/opt_out.
> >
> >
>
> --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to