# Wrapper around Pynac’s constants¶

Wrapper around Pynac’s constants

class sage.symbolic.constants_c.E

Dummy class to represent base of the natural logarithm.

The base of the natural logarithm e is not a constant in GiNaC/Sage. It is represented by exp(1).

This class provides a dummy object that behaves well under addition, multiplication, etc. and on exponentiation calls the function exp.

EXAMPLES:

The constant defined at the top level is just exp(1):

sage: e.operator()
exp
sage: e.operands()
[1]


Arithmetic works:

sage: e + 2
e + 2
sage: 2 + e
e + 2
sage: 2*e
2*e
sage: e*2
2*e
sage: x*e
x*e
sage: var('a,b')
(a, b)
sage: t = e^(a+b); t
e^(a + b)
sage: t.operands()
[a + b]


Numeric evaluation, conversion to other systems, and pickling works as expected. Note that these are properties of the exp() function, not this class:

sage: RR(e)
2.71828182845905
sage: R = RealField(200); R
Real Field with 200 bits of precision
sage: R(e)
2.7182818284590452353602874713526624977572470936999595749670
sage: em = 1 + e^(1-e); em
e^(-e + 1) + 1
sage: R(em)
1.1793740787340171819619895873183164984596816017589156131574
sage: maxima(e).float()
2.718281828459045
sage: t = mathematica(e)               # optional
sage: t                                # optional
E
sage: float(t)                         # optional
2.718281828459045...

e

sage: float(e)
2.718281828459045...
sage: e.__float__()
2.718281828459045...
sage: e._mpfr_(RealField(100))
2.7182818284590452353602874714
sage: e._real_double_(RDF)
2.71828182846
sage: import sympy
sage: sympy.E == e # indirect doctest
True


TESTS:

sage: t = e^a; t
e^a
sage: t^b
(e^a)^b
sage: SR(1).exp()
e


Testing that it works with matrices (see trac ticket #4735):

sage: m = matrix(QQ, 2, 2, [1,0,0,1])
sage: e^m
[e 0]
[0 e]

class sage.symbolic.constants_c.PynacConstant

Bases: object

x.__init__(...) initializes x; see help(type(x)) for signature

expression()

Returns this constant as an Expression.

EXAMPLES:

sage: from sage.symbolic.constants_c import PynacConstant
sage: f = PynacConstant('foo', 'foo', 'real')
sage: f + 2
Traceback (most recent call last):
...
TypeError: unsupported operand parent(s) for '+': '<type 'sage.symbolic.constants_c.PynacConstant'>' and 'Integer Ring'

sage: foo = f.expression(); foo
foo
sage: foo + 2
foo + 2

name()

Returns the name of this constant.

EXAMPLES:

sage: from sage.symbolic.constants_c import PynacConstant
sage: f = PynacConstant('foo', 'foo', 'real')
sage: f.name()
'foo'

serial()

Returns the underlying Pynac serial for this constant.

EXAMPLES:

sage: from sage.symbolic.constants_c import PynacConstant
sage: f = PynacConstant('foo', 'foo', 'real')
sage: f.serial()  #random
15


#### Previous topic

Mathematical constants