Ok, I tried this and it seems to behave well at a basic level:
from sympy.core.singleton import Singleton
class BoltzmannConstant(NumberSymbol):
__metaclass__ = Singleton
is_real = True
is_positive = True
is_negative = False
is_irrational = None
__slots__ = []
@staticmethod
def __abs__():
return S.BoltzmannConstant
def __int__(self):
return 0
def _eval_evalf(self,prec):
return N(1.3806488e-23,prec)
kB = S.BoltzmannConstant
Does that look like a reasonable implementation?
How would I associate the symbol "k_B" with this Singleton? Right now when
I enter kB, it displays as 'BoltzmannConstant()' (whereas pi somehow knows
to display as \pi).
On Sunday, February 2, 2014 5:40:21 PM UTC-8, Aaron Meurer wrote:
>
> I don't think pi and Exp1 are good examples because they are already
> implemented in mpmath, and can be computed to an arbitrary number of
> digits. That's what the mpf stuff is doing. For your case, I think you
> just need to define _eval_evalf(self, prec), which should return a
> Float to prec digits.
>
> _sage_ is just to convert the objects to Sage equivalents. If you
> don't intend for you code to ever be used within Sage you don't need
> to worry about it.
>
> Aaron Meurer
>
> On Sun, Feb 2, 2014 at 7:12 PM, G B <[email protected] <javascript:>>
> wrote:
> > I'd like to set up values that display as symbols but evaluate to
> numbers
> > when called with .n(). I think this is similar to how pi and E are
> handled.
> > In my case it's constants such as the speed of light, and Boltzmann's
> > constant. When I look at the symbolic representation, I'd like to see
> these
> > values represented as symbols (c, k_B), but when I evaluate I'd like
> their
> > true value used without the need for explicit substitution.
> >
> > Is there an easy way to set up such values?
> >
> > Looking through the source, I found Pi and Exp1 defined in
> > sympy.core.numbers-- and it looks like each is a custom class. Is there
> a
> > trick to setting up _as_mpf_val and approximation_interval for physical
> > constants such as these? Does _sage_ need to be implemented if I'm not
> > running within Sage?
> >
> > Thanks--
> > Greg
> >
> > --
> > 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] <javascript:>.
> > To post to this group, send email to [email protected]<javascript:>.
>
> > Visit this group at http://groups.google.com/group/sympy.
> > 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.