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 sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
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.

Reply via email to