Sure, it sounds useful.

I think the assumptions should mirror the assumptions of self.value
(currently, Floats set is_rational to None), which I believe is
intentional.

For lambdify, I suppose LambdaPrinter ought to define its own print
method. That might break existing code that expects it to use str, so
we should make sure it falls back.

Aaron Meurer


On Thu, Mar 31, 2016 at 11:13 AM, Henry Schreiner
<[email protected]> wrote:
> Is there a way to make a constant symbol in Sympy? I haven't found one yet.
> Basically, it would be a lot like pi and other constants, but you could make
> your own. In other words,
>
>>>> c = ConstantSymbol('c', 1.23)
>>>> c + 1
> c+1
>>>> _.evalf()
> 2.23
>
> That way, formulas could stay in a nice form until evaluation occurs. Also,
> subs will still allow changing out constants.
>
> Here's example code that does that:
>
> class ConstantSymbol(s.NumberSymbol):
>     is_real = True
>     is_irrational = False
>     is_algebraic = True
>     __slots__ = ['name', 'value']
>
>     def __new__(cls, name, value):
>         self = super(ConstantSymbol,cls).__new__(cls)
>         self.name=name
>         self.value=s.Float(value)
>
>         return self
>
>     def __getnewargs__(self):
>         return (self.name,self.value)
>
>     def _latex(self, printer):
>         return printer.doprint(s.Symbol(self.name))
>
>     def _sympystr(self, printer):
>         return printer.doprint(s.Symbol(self.name))
>
>     def _sympyrepr(self, printer):
>         return printer.doprint(s.Symbol(self.name))
>
>     def _mathml(self, printer):
>         return printer.doprint(s.Symbol(self.name))
>
>     def _as_mpf_val(self, prec):
>         return self.value._as_mpf_val(price)
>
>
> The problem with the above code is that sympy.lamdify uses _sympystr()
> instead of evaluating it first.
>
>
> Is there something like this, or would something like this be useful?
>
> --
> 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 https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/c5ac54f3-1012-4bc9-86d4-88a7740ce27b%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 https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6J6mwoBoE3qVjNkpwBUL%3D-C0FcAR3-tiiOfyML0w5q%2Bdg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to