Implemented crisscross algorithm for solving LP problems.
[sympycore.git] / sympycore / calculus / constants.py
blobc02796302436165bb7e6088c2ced9dbb685c7939
2 # Created January 2008 by Pearu Peterson
4 """ Provides Constant class.
5 """
6 __docformat__ = "restructuredtext"
7 __all__ = ['Constant', 'const_pi', 'const_E', 'const_gamma']
9 from ..core import classes
10 from ..utils import SYMBOL, NUMBER
11 from ..arithmetic.evalf import evalf
12 from ..arithmetic import mpmath, setdps
14 class Constant(str):
16 def __repr__(self):
17 return '%s(%r)' % (self.__class__.__name__, str(self))
19 def evalf(self, n=None):
20 if n:
21 setdps(n)
22 if self == 'pi':
23 return +mpmath.pi
24 if self == 'E':
25 return +mpmath.e
26 if self == 'gamma':
27 return +mpmath.euler
28 raise NotImplementedError('%s(%r).evalf'
29 % (self.__class__.__name__, self))
31 def as_algebra(self, cls):
32 if cls is classes.Calculus:
33 return cls.Symbol(self)
34 return cls.convert(self)
36 def get_direction(self):
37 if self in ['pi', 'E']:
38 return 1
39 return NotImplemented
41 @property
42 def is_bounded(self):
43 if self in ['pi', 'E']:
44 return True
45 return None
47 const_pi = Constant('pi')
48 const_E = Constant('E')
49 const_gamma = Constant('gamma')