Another option would be to name your class something different and alias it to log (and also change the printers to print "log"). This way is probably simpler, though, as you only have to override the one evalf method rather than several printer methods.
Aaron Meurer On Sat, Sep 6, 2014 at 3:09 PM, Duane Nykamp <[email protected]> wrote: > Perfect. The following solution seems to work for me. Thanks! > > class log(Function): > > def _eval_evalf(self,prec): > pass > > def doit(self, **hints): > from sympy import log as sympy_log > return sympy_log(self.args[0]).doit(**hints) > > > > > > On Saturday, September 6, 2014 2:20:12 PM UTC-5, Aaron Meurer wrote: >> >> SymPy automatically defines evaluation based on mpmath function names. >> I think you can get around it by defining an empty _eval_evalf(self, >> prec) function. >> >> Aaron Meurer >> >> On Sat, Sep 6, 2014 at 1:50 PM, Duane Nykamp <[email protected]> wrote: >> > I really like the evaluate=False flag on parse_expr. But, since >> > log(0.1) >> > automatically evaluates to a float, I'm trying to create an unevaluated >> > version of log. However, I'm getting strange results where log is >> > implicitly defined. >> > >> > As shown below, once I define a function log that does nothing, sympy >> > somehow implicitly defines it to be the usual log function. >> > >> > Am I missing how this works or is this aberrant behavior? >> > >> > My eventual plan is to have log.doit() return the original sympy >> > function. >> > >> > If I call the function something else, like llog, then I don't run into >> > the >> > behavior. But, I'm not sure how to make printers display my llog >> > function >> > as log. >> > >> > Thanks, >> > Duane >> > >> > >> > >> > In [1]: from sympy import Function >> > >> > In [2]: log >> > >> > --------------------------------------------------------------------------- >> > NameError Traceback (most recent call >> > last) >> > <ipython-input-2-9a115ebc25a0> in <module>() >> > ----> 1 log >> > >> > NameError: name 'log' is not defined >> > >> > In [3]: class log(Function): >> > ...: pass >> > ...: >> > >> > In [4]: log >> > Out[4]: __main__.log >> > >> > In [5]: log(0.1) >> > Out[5]: -2.30258509299405 >> > >> > -- >> > 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 [email protected]. >> > To post to this group, send email to [email protected]. >> > 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/5df457b7-7ffc-4285-b9b5-b8ddce3f91ca%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 [email protected]. > To post to this group, send email to [email protected]. > 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/0957d959-bd5f-4327-872a-748a4f6c60c1%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 [email protected]. To post to this group, send email to [email protected]. 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%3D6%2B1Nt9xZKKj0Z42eGz6ybpzPmupMimT%3D3f8Dd1Wd3133w%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
