passagemath-symbolics 10.8.1a1__cp311-cp311-macosx_13_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- passagemath_symbolics/.dylibs/libgmp.10.dylib +0 -0
- passagemath_symbolics/__init__.py +3 -0
- passagemath_symbolics-10.8.1a1.dist-info/METADATA +186 -0
- passagemath_symbolics-10.8.1a1.dist-info/RECORD +182 -0
- passagemath_symbolics-10.8.1a1.dist-info/WHEEL +6 -0
- passagemath_symbolics-10.8.1a1.dist-info/top_level.txt +3 -0
- sage/all__sagemath_symbolics.py +17 -0
- sage/calculus/all.py +14 -0
- sage/calculus/calculus.py +2838 -0
- sage/calculus/desolvers.py +1864 -0
- sage/calculus/predefined.py +51 -0
- sage/calculus/tests.py +225 -0
- sage/calculus/var.cpython-311-darwin.so +0 -0
- sage/calculus/var.pyx +401 -0
- sage/dynamics/all__sagemath_symbolics.py +6 -0
- sage/dynamics/complex_dynamics/all.py +5 -0
- sage/dynamics/complex_dynamics/mandel_julia.py +765 -0
- sage/dynamics/complex_dynamics/mandel_julia_helper.cpython-311-darwin.so +0 -0
- sage/dynamics/complex_dynamics/mandel_julia_helper.pyx +1034 -0
- sage/ext/all__sagemath_symbolics.py +1 -0
- sage/ext_data/kenzo/CP2.txt +45 -0
- sage/ext_data/kenzo/CP3.txt +349 -0
- sage/ext_data/kenzo/CP4.txt +4774 -0
- sage/ext_data/kenzo/README.txt +49 -0
- sage/ext_data/kenzo/S4.txt +20 -0
- sage/ext_data/magma/latex/latex.m +1021 -0
- sage/ext_data/magma/latex/latex.spec +1 -0
- sage/ext_data/magma/sage/basic.m +356 -0
- sage/ext_data/magma/sage/sage.spec +1 -0
- sage/ext_data/magma/spec +9 -0
- sage/geometry/all__sagemath_symbolics.py +8 -0
- sage/geometry/hyperbolic_space/all.py +5 -0
- sage/geometry/hyperbolic_space/hyperbolic_coercion.py +755 -0
- sage/geometry/hyperbolic_space/hyperbolic_constants.py +5 -0
- sage/geometry/hyperbolic_space/hyperbolic_geodesic.py +2419 -0
- sage/geometry/hyperbolic_space/hyperbolic_interface.py +206 -0
- sage/geometry/hyperbolic_space/hyperbolic_isometry.py +1083 -0
- sage/geometry/hyperbolic_space/hyperbolic_model.py +1502 -0
- sage/geometry/hyperbolic_space/hyperbolic_point.py +621 -0
- sage/geometry/riemannian_manifolds/all.py +7 -0
- sage/geometry/riemannian_manifolds/parametrized_surface3d.py +1632 -0
- sage/geometry/riemannian_manifolds/surface3d_generators.py +461 -0
- sage/interfaces/all__sagemath_symbolics.py +1 -0
- sage/interfaces/magma.py +2991 -0
- sage/interfaces/magma_free.py +90 -0
- sage/interfaces/maple.py +1402 -0
- sage/interfaces/mathematica.py +1345 -0
- sage/interfaces/mathics.py +1312 -0
- sage/interfaces/sympy.py +1398 -0
- sage/interfaces/sympy_wrapper.py +197 -0
- sage/interfaces/tides.py +938 -0
- sage/libs/all__sagemath_symbolics.py +6 -0
- sage/manifolds/all.py +7 -0
- sage/manifolds/calculus_method.py +553 -0
- sage/manifolds/catalog.py +437 -0
- sage/manifolds/chart.py +4010 -0
- sage/manifolds/chart_func.py +3416 -0
- sage/manifolds/continuous_map.py +2183 -0
- sage/manifolds/continuous_map_image.py +155 -0
- sage/manifolds/differentiable/affine_connection.py +2475 -0
- sage/manifolds/differentiable/all.py +1 -0
- sage/manifolds/differentiable/automorphismfield.py +1383 -0
- sage/manifolds/differentiable/automorphismfield_group.py +604 -0
- sage/manifolds/differentiable/bundle_connection.py +1445 -0
- sage/manifolds/differentiable/characteristic_cohomology_class.py +1840 -0
- sage/manifolds/differentiable/chart.py +1241 -0
- sage/manifolds/differentiable/curve.py +1028 -0
- sage/manifolds/differentiable/de_rham_cohomology.py +541 -0
- sage/manifolds/differentiable/degenerate.py +559 -0
- sage/manifolds/differentiable/degenerate_submanifold.py +1668 -0
- sage/manifolds/differentiable/diff_form.py +1660 -0
- sage/manifolds/differentiable/diff_form_module.py +1062 -0
- sage/manifolds/differentiable/diff_map.py +1315 -0
- sage/manifolds/differentiable/differentiable_submanifold.py +291 -0
- sage/manifolds/differentiable/examples/all.py +1 -0
- sage/manifolds/differentiable/examples/euclidean.py +2517 -0
- sage/manifolds/differentiable/examples/real_line.py +897 -0
- sage/manifolds/differentiable/examples/sphere.py +1186 -0
- sage/manifolds/differentiable/examples/symplectic_space.py +187 -0
- sage/manifolds/differentiable/examples/symplectic_space_test.py +40 -0
- sage/manifolds/differentiable/integrated_curve.py +4035 -0
- sage/manifolds/differentiable/levi_civita_connection.py +841 -0
- sage/manifolds/differentiable/manifold.py +4254 -0
- sage/manifolds/differentiable/manifold_homset.py +1826 -0
- sage/manifolds/differentiable/metric.py +3032 -0
- sage/manifolds/differentiable/mixed_form.py +1507 -0
- sage/manifolds/differentiable/mixed_form_algebra.py +559 -0
- sage/manifolds/differentiable/multivector_module.py +800 -0
- sage/manifolds/differentiable/multivectorfield.py +1522 -0
- sage/manifolds/differentiable/poisson_tensor.py +268 -0
- sage/manifolds/differentiable/pseudo_riemannian.py +755 -0
- sage/manifolds/differentiable/pseudo_riemannian_submanifold.py +1839 -0
- sage/manifolds/differentiable/scalarfield.py +1343 -0
- sage/manifolds/differentiable/scalarfield_algebra.py +472 -0
- sage/manifolds/differentiable/symplectic_form.py +912 -0
- sage/manifolds/differentiable/symplectic_form_test.py +220 -0
- sage/manifolds/differentiable/tangent_space.py +412 -0
- sage/manifolds/differentiable/tangent_vector.py +616 -0
- sage/manifolds/differentiable/tensorfield.py +4665 -0
- sage/manifolds/differentiable/tensorfield_module.py +963 -0
- sage/manifolds/differentiable/tensorfield_paral.py +2450 -0
- sage/manifolds/differentiable/tensorfield_paral_test.py +16 -0
- sage/manifolds/differentiable/vector_bundle.py +1725 -0
- sage/manifolds/differentiable/vectorfield.py +1717 -0
- sage/manifolds/differentiable/vectorfield_module.py +2445 -0
- sage/manifolds/differentiable/vectorframe.py +1832 -0
- sage/manifolds/family.py +270 -0
- sage/manifolds/local_frame.py +1490 -0
- sage/manifolds/manifold.py +3090 -0
- sage/manifolds/manifold_homset.py +452 -0
- sage/manifolds/operators.py +359 -0
- sage/manifolds/point.py +994 -0
- sage/manifolds/scalarfield.py +3718 -0
- sage/manifolds/scalarfield_algebra.py +629 -0
- sage/manifolds/section.py +3111 -0
- sage/manifolds/section_module.py +831 -0
- sage/manifolds/structure.py +229 -0
- sage/manifolds/subset.py +2721 -0
- sage/manifolds/subsets/all.py +1 -0
- sage/manifolds/subsets/closure.py +131 -0
- sage/manifolds/subsets/pullback.py +883 -0
- sage/manifolds/topological_submanifold.py +891 -0
- sage/manifolds/trivialization.py +733 -0
- sage/manifolds/utilities.py +1348 -0
- sage/manifolds/vector_bundle.py +1347 -0
- sage/manifolds/vector_bundle_fiber.py +332 -0
- sage/manifolds/vector_bundle_fiber_element.py +111 -0
- sage/matrix/all__sagemath_symbolics.py +1 -0
- sage/matrix/matrix_symbolic_dense.cpython-311-darwin.so +0 -0
- sage/matrix/matrix_symbolic_dense.pxd +6 -0
- sage/matrix/matrix_symbolic_dense.pyx +1030 -0
- sage/matrix/matrix_symbolic_sparse.cpython-311-darwin.so +0 -0
- sage/matrix/matrix_symbolic_sparse.pxd +6 -0
- sage/matrix/matrix_symbolic_sparse.pyx +1038 -0
- sage/modules/all__sagemath_symbolics.py +1 -0
- sage/modules/vector_callable_symbolic_dense.py +105 -0
- sage/modules/vector_symbolic_dense.py +116 -0
- sage/modules/vector_symbolic_sparse.py +118 -0
- sage/rings/all__sagemath_symbolics.py +4 -0
- sage/rings/asymptotic/all.py +6 -0
- sage/rings/asymptotic/asymptotic_expansion_generators.py +1485 -0
- sage/rings/asymptotic/asymptotic_ring.py +4858 -0
- sage/rings/asymptotic/asymptotics_multivariate_generating_functions.py +4106 -0
- sage/rings/asymptotic/growth_group.py +5373 -0
- sage/rings/asymptotic/growth_group_cartesian.py +1400 -0
- sage/rings/asymptotic/term_monoid.py +5205 -0
- sage/rings/function_field/all__sagemath_symbolics.py +2 -0
- sage/rings/polynomial/all__sagemath_symbolics.py +1 -0
- sage/symbolic/all.py +15 -0
- sage/symbolic/assumptions.py +987 -0
- sage/symbolic/benchmark.py +93 -0
- sage/symbolic/callable.py +456 -0
- sage/symbolic/callable.pyi +66 -0
- sage/symbolic/comparison_impl.pyi +38 -0
- sage/symbolic/complexity_measures.py +35 -0
- sage/symbolic/constants.py +1286 -0
- sage/symbolic/constants_c_impl.pyi +10 -0
- sage/symbolic/expression_conversion_algebraic.py +310 -0
- sage/symbolic/expression_conversion_sympy.py +317 -0
- sage/symbolic/expression_conversions.py +1727 -0
- sage/symbolic/function_factory.py +355 -0
- sage/symbolic/function_factory.pyi +41 -0
- sage/symbolic/getitem_impl.pyi +24 -0
- sage/symbolic/integration/all.py +1 -0
- sage/symbolic/integration/external.py +271 -0
- sage/symbolic/integration/integral.py +1075 -0
- sage/symbolic/maxima_wrapper.py +162 -0
- sage/symbolic/operators.py +267 -0
- sage/symbolic/operators.pyi +61 -0
- sage/symbolic/pynac_constant_impl.pyi +13 -0
- sage/symbolic/pynac_function_impl.pyi +8 -0
- sage/symbolic/random_tests.py +461 -0
- sage/symbolic/relation.py +2062 -0
- sage/symbolic/ring.cpython-311-darwin.so +0 -0
- sage/symbolic/ring.pxd +5 -0
- sage/symbolic/ring.pyi +110 -0
- sage/symbolic/ring.pyx +1393 -0
- sage/symbolic/series_impl.pyi +10 -0
- sage/symbolic/subring.py +1025 -0
- sage/symbolic/symengine.py +19 -0
- sage/symbolic/tests.py +40 -0
- sage/symbolic/units.py +1468 -0
|
@@ -0,0 +1,1286 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-symbolics
|
|
2
|
+
r"""
|
|
3
|
+
Mathematical constants
|
|
4
|
+
|
|
5
|
+
The following standard mathematical constants are defined in Sage,
|
|
6
|
+
along with support for coercing them into GAP, PARI/GP, KASH,
|
|
7
|
+
Maxima, Mathematica, Maple, Octave, and Singular::
|
|
8
|
+
|
|
9
|
+
sage: pi
|
|
10
|
+
pi
|
|
11
|
+
sage: e # base of the natural logarithm
|
|
12
|
+
e
|
|
13
|
+
sage: NaN # Not a number
|
|
14
|
+
NaN
|
|
15
|
+
sage: golden_ratio
|
|
16
|
+
golden_ratio
|
|
17
|
+
sage: log2 # natural logarithm of the real number 2
|
|
18
|
+
log2
|
|
19
|
+
sage: euler_gamma # Euler's gamma constant
|
|
20
|
+
euler_gamma
|
|
21
|
+
sage: catalan # the Catalan constant
|
|
22
|
+
catalan
|
|
23
|
+
sage: khinchin # Khinchin's constant
|
|
24
|
+
khinchin
|
|
25
|
+
sage: twinprime
|
|
26
|
+
twinprime
|
|
27
|
+
sage: mertens
|
|
28
|
+
mertens
|
|
29
|
+
|
|
30
|
+
Support for coercion into the various systems means that if, e.g.,
|
|
31
|
+
you want to create `\pi` in Maxima and Singular, you don't
|
|
32
|
+
have to figure out the special notation for each system. You just
|
|
33
|
+
type the following::
|
|
34
|
+
|
|
35
|
+
sage: maxima(pi)
|
|
36
|
+
%pi
|
|
37
|
+
sage: singular(pi) # needs sage.libs.singular
|
|
38
|
+
pi
|
|
39
|
+
sage: gap(pi) # needs sage.libs.gap
|
|
40
|
+
pi
|
|
41
|
+
sage: gp(pi) # needs sage.libs.pari
|
|
42
|
+
3.1415926535897932384626433832795028842
|
|
43
|
+
sage: pari(pi) # needs sage.libs.pari
|
|
44
|
+
3.14159265358979
|
|
45
|
+
sage: kash(pi) # optional - kash
|
|
46
|
+
3.14159265358979323846264338328
|
|
47
|
+
sage: mathematica(pi) # optional - mathematica
|
|
48
|
+
Pi
|
|
49
|
+
sage: pi._maple_init_()
|
|
50
|
+
'Pi'
|
|
51
|
+
sage: octave(pi) # optional - octave
|
|
52
|
+
3.14159
|
|
53
|
+
|
|
54
|
+
Arithmetic operations with constants also yield constants, which
|
|
55
|
+
can be coerced into other systems or evaluated.
|
|
56
|
+
|
|
57
|
+
::
|
|
58
|
+
|
|
59
|
+
sage: a = pi + e*4/5; a
|
|
60
|
+
pi + 4/5*e
|
|
61
|
+
sage: maxima(a)
|
|
62
|
+
%pi+(4*%e)/5
|
|
63
|
+
sage: RealField(15)(a) # 15 *bits* of precision
|
|
64
|
+
5.316
|
|
65
|
+
sage: gp(a) # needs sage.libs.pari
|
|
66
|
+
5.3162181163570294267508733603616328824
|
|
67
|
+
sage: print(mathematica(a)) # optional - mathematica
|
|
68
|
+
4 E
|
|
69
|
+
--- + Pi
|
|
70
|
+
5
|
|
71
|
+
|
|
72
|
+
EXAMPLES: Decimal expansions of constants
|
|
73
|
+
|
|
74
|
+
We can obtain floating point approximations to each of these
|
|
75
|
+
constants by coercing into the real field with given precision. For
|
|
76
|
+
example, to 200 binary places we have the following::
|
|
77
|
+
|
|
78
|
+
sage: R = RealField(200); R
|
|
79
|
+
Real Field with 200 bits of precision
|
|
80
|
+
|
|
81
|
+
::
|
|
82
|
+
|
|
83
|
+
sage: R(pi)
|
|
84
|
+
3.1415926535897932384626433832795028841971693993751058209749
|
|
85
|
+
|
|
86
|
+
::
|
|
87
|
+
|
|
88
|
+
sage: R(e)
|
|
89
|
+
2.7182818284590452353602874713526624977572470936999595749670
|
|
90
|
+
|
|
91
|
+
::
|
|
92
|
+
|
|
93
|
+
sage: R(NaN)
|
|
94
|
+
NaN
|
|
95
|
+
|
|
96
|
+
::
|
|
97
|
+
|
|
98
|
+
sage: R(golden_ratio)
|
|
99
|
+
1.6180339887498948482045868343656381177203091798057628621354
|
|
100
|
+
|
|
101
|
+
::
|
|
102
|
+
|
|
103
|
+
sage: R(log2)
|
|
104
|
+
0.69314718055994530941723212145817656807550013436025525412068
|
|
105
|
+
|
|
106
|
+
::
|
|
107
|
+
|
|
108
|
+
sage: R(euler_gamma)
|
|
109
|
+
0.57721566490153286060651209008240243104215933593992359880577
|
|
110
|
+
|
|
111
|
+
::
|
|
112
|
+
|
|
113
|
+
sage: R(catalan)
|
|
114
|
+
0.91596559417721901505460351493238411077414937428167213426650
|
|
115
|
+
|
|
116
|
+
::
|
|
117
|
+
|
|
118
|
+
sage: R(khinchin)
|
|
119
|
+
2.6854520010653064453097148354817956938203822939944629530512
|
|
120
|
+
|
|
121
|
+
EXAMPLES: Arithmetic with constants
|
|
122
|
+
|
|
123
|
+
::
|
|
124
|
+
|
|
125
|
+
sage: f = I*(e+1); f
|
|
126
|
+
I*e + I
|
|
127
|
+
sage: f^2
|
|
128
|
+
(I*e + I)^2
|
|
129
|
+
sage: _.expand()
|
|
130
|
+
-e^2 - 2*e - 1
|
|
131
|
+
|
|
132
|
+
::
|
|
133
|
+
|
|
134
|
+
sage: pp = pi+pi; pp
|
|
135
|
+
2*pi
|
|
136
|
+
sage: R(pp)
|
|
137
|
+
6.2831853071795864769252867665590057683943387987502116419499
|
|
138
|
+
|
|
139
|
+
::
|
|
140
|
+
|
|
141
|
+
sage: s = (1 + e^pi); s
|
|
142
|
+
e^pi + 1
|
|
143
|
+
sage: R(s)
|
|
144
|
+
24.140692632779269005729086367948547380266106242600211993445
|
|
145
|
+
sage: R(s-1)
|
|
146
|
+
23.140692632779269005729086367948547380266106242600211993445
|
|
147
|
+
|
|
148
|
+
::
|
|
149
|
+
|
|
150
|
+
sage: l = (1-log2)/(1+log2); l
|
|
151
|
+
-(log2 - 1)/(log2 + 1)
|
|
152
|
+
sage: R(l)
|
|
153
|
+
0.18123221829928249948761381864650311423330609774776013488056
|
|
154
|
+
|
|
155
|
+
::
|
|
156
|
+
|
|
157
|
+
sage: pim = maxima(pi)
|
|
158
|
+
sage: maxima.eval('fpprec : 100')
|
|
159
|
+
'100'
|
|
160
|
+
sage: pim.bfloat()
|
|
161
|
+
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068b0
|
|
162
|
+
|
|
163
|
+
AUTHORS:
|
|
164
|
+
|
|
165
|
+
- Alex Clemesha (2006-01-15)
|
|
166
|
+
|
|
167
|
+
- William Stein
|
|
168
|
+
|
|
169
|
+
- Alex Clemesha, William Stein (2006-02-20): added new constants;
|
|
170
|
+
removed todos
|
|
171
|
+
|
|
172
|
+
- Didier Deshommes (2007-03-27): added constants from RQDF (deprecated)
|
|
173
|
+
|
|
174
|
+
TESTS:
|
|
175
|
+
|
|
176
|
+
Coercing the sum of a bunch of the constants to many different
|
|
177
|
+
floating point rings::
|
|
178
|
+
|
|
179
|
+
sage: a = pi + e + golden_ratio + log2 + euler_gamma + catalan + khinchin + twinprime + mertens; a
|
|
180
|
+
mertens + twinprime + khinchin + log2 + golden_ratio + catalan + euler_gamma + pi + e
|
|
181
|
+
sage: parent(a)
|
|
182
|
+
Symbolic Ring
|
|
183
|
+
sage: RR(a) # abs tol 1e-13
|
|
184
|
+
13.2713479401972
|
|
185
|
+
sage: RealField(212)(a)
|
|
186
|
+
13.2713479401972493100988191995758139408711068200030748178329712
|
|
187
|
+
sage: RealField(230)(a)
|
|
188
|
+
13.271347940197249310098819199575813940871106820003074817832971189555
|
|
189
|
+
sage: RDF(a) # abs tol 1e-13
|
|
190
|
+
13.271347940197249
|
|
191
|
+
sage: CC(a) # abs tol 1e-13
|
|
192
|
+
13.2713479401972
|
|
193
|
+
sage: CDF(a) # abs tol 1e-13
|
|
194
|
+
13.271347940197249
|
|
195
|
+
sage: ComplexField(230)(a)
|
|
196
|
+
13.271347940197249310098819199575813940871106820003074817832971189555
|
|
197
|
+
|
|
198
|
+
Check that :issue:`8237` is fixed::
|
|
199
|
+
|
|
200
|
+
sage: maxima('infinity').sage()
|
|
201
|
+
Infinity
|
|
202
|
+
sage: maxima('inf').sage()
|
|
203
|
+
+Infinity
|
|
204
|
+
sage: maxima('minf').sage()
|
|
205
|
+
-Infinity
|
|
206
|
+
"""
|
|
207
|
+
###############################################################################
|
|
208
|
+
# Sage: Open Source Mathematical Software
|
|
209
|
+
# Copyright (C) 2008 William Stein <wstein@gmail.com>
|
|
210
|
+
# Copyright (C) 2008-2010 Burcin Erocal <burcin@erocal.org>
|
|
211
|
+
# 2009 Mike Hansen <mhansen@gmail.com>
|
|
212
|
+
# Distributed under the terms of the GNU General Public License (GPL),
|
|
213
|
+
# version 2 or any later version. The full text of the GPL is available at:
|
|
214
|
+
# https://www.gnu.org/licenses/
|
|
215
|
+
###############################################################################
|
|
216
|
+
|
|
217
|
+
import math
|
|
218
|
+
from functools import partial
|
|
219
|
+
|
|
220
|
+
from sage.rings.infinity import infinity, minus_infinity, unsigned_infinity
|
|
221
|
+
from sage.structure.richcmp import op_EQ, op_GE, op_LE, richcmp_method
|
|
222
|
+
from sage.symbolic.expression import E, init_pynac_I, register_symbol
|
|
223
|
+
|
|
224
|
+
constants_table = {}
|
|
225
|
+
constants_name_table = {}
|
|
226
|
+
constants_name_table[repr(infinity)] = infinity
|
|
227
|
+
constants_name_table[repr(unsigned_infinity)] = unsigned_infinity
|
|
228
|
+
constants_name_table[repr(minus_infinity)] = minus_infinity
|
|
229
|
+
|
|
230
|
+
I = init_pynac_I()
|
|
231
|
+
|
|
232
|
+
register_symbol(infinity, {'maxima': 'inf'}, 0)
|
|
233
|
+
register_symbol(minus_infinity, {'maxima': 'minf'}, 0)
|
|
234
|
+
register_symbol(unsigned_infinity, {'maxima': 'infinity'}, 0)
|
|
235
|
+
register_symbol(I, {'mathematica': 'I'}, 0)
|
|
236
|
+
register_symbol(True, {'giac': 'true',
|
|
237
|
+
'mathematica': 'True',
|
|
238
|
+
'maxima': 'true'}, 0)
|
|
239
|
+
register_symbol(False, {'giac': 'false',
|
|
240
|
+
'mathematica': 'False',
|
|
241
|
+
'maxima': 'false'}, 0)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def unpickle_Constant(class_name, name, conversions, latex, mathml, domain):
|
|
245
|
+
"""
|
|
246
|
+
EXAMPLES::
|
|
247
|
+
|
|
248
|
+
sage: from sage.symbolic.constants import unpickle_Constant
|
|
249
|
+
sage: a = unpickle_Constant('Constant', 'a', {}, 'aa', '', 'positive')
|
|
250
|
+
sage: a.domain()
|
|
251
|
+
'positive'
|
|
252
|
+
sage: latex(a)
|
|
253
|
+
aa
|
|
254
|
+
|
|
255
|
+
Note that if the name already appears in the
|
|
256
|
+
``constants_name_table``, then that will be returned instead of
|
|
257
|
+
constructing a new object::
|
|
258
|
+
|
|
259
|
+
sage: pi = unpickle_Constant('Pi', 'pi', None, None, None, None)
|
|
260
|
+
sage: pi._maxima_init_()
|
|
261
|
+
'%pi'
|
|
262
|
+
"""
|
|
263
|
+
if name in constants_name_table:
|
|
264
|
+
return constants_name_table[name]
|
|
265
|
+
if class_name == "Constant":
|
|
266
|
+
return Constant(name, conversions=conversions, latex=latex,
|
|
267
|
+
mathml=mathml, domain=domain)
|
|
268
|
+
else:
|
|
269
|
+
cls = globals()[class_name]
|
|
270
|
+
return cls(name=name)
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
@richcmp_method
|
|
274
|
+
class Constant:
|
|
275
|
+
def __init__(self, name, conversions=None, latex=None, mathml='',
|
|
276
|
+
domain='complex'):
|
|
277
|
+
"""
|
|
278
|
+
EXAMPLES::
|
|
279
|
+
|
|
280
|
+
sage: from sage.symbolic.constants import Constant
|
|
281
|
+
sage: p = Constant('p')
|
|
282
|
+
sage: loads(dumps(p))
|
|
283
|
+
p
|
|
284
|
+
"""
|
|
285
|
+
self._conversions = conversions if conversions is not None else {}
|
|
286
|
+
self._latex = latex if latex is not None else name
|
|
287
|
+
self._mathml = mathml
|
|
288
|
+
self._name = name
|
|
289
|
+
self._domain = domain
|
|
290
|
+
|
|
291
|
+
for system, value in self._conversions.items():
|
|
292
|
+
setattr(self, "_%s_" % system, partial(self._generic_interface, value))
|
|
293
|
+
setattr(self, "_%s_init_" % system, partial(self._generic_interface_init, value))
|
|
294
|
+
|
|
295
|
+
from sage.symbolic.expression import PynacConstant
|
|
296
|
+
self._pynac = PynacConstant(self._name, self._latex, self._domain)
|
|
297
|
+
self._serial = self._pynac.serial()
|
|
298
|
+
constants_table[self._serial] = self
|
|
299
|
+
constants_name_table[self._name] = self
|
|
300
|
+
|
|
301
|
+
register_symbol(self.expression(), self._conversions)
|
|
302
|
+
|
|
303
|
+
def __richcmp__(self, other, op):
|
|
304
|
+
"""
|
|
305
|
+
EXAMPLES::
|
|
306
|
+
|
|
307
|
+
sage: from sage.symbolic.constants import Constant
|
|
308
|
+
sage: p = Constant('p')
|
|
309
|
+
sage: s = Constant('s')
|
|
310
|
+
sage: p == p
|
|
311
|
+
True
|
|
312
|
+
sage: p == s
|
|
313
|
+
False
|
|
314
|
+
sage: p != s
|
|
315
|
+
True
|
|
316
|
+
"""
|
|
317
|
+
if self.__class__ == other.__class__ and self._name == other._name:
|
|
318
|
+
return op in [op_EQ, op_GE, op_LE]
|
|
319
|
+
else:
|
|
320
|
+
return NotImplemented
|
|
321
|
+
|
|
322
|
+
def __reduce__(self):
|
|
323
|
+
"""
|
|
324
|
+
Add support for pickling constants.
|
|
325
|
+
|
|
326
|
+
EXAMPLES::
|
|
327
|
+
|
|
328
|
+
sage: from sage.symbolic.constants import Constant
|
|
329
|
+
sage: p = Constant('p')
|
|
330
|
+
sage: p.__reduce__()
|
|
331
|
+
(<function unpickle_Constant at 0x...>,
|
|
332
|
+
('Constant', 'p', {}, 'p', '', 'complex'))
|
|
333
|
+
sage: loads(dumps(p))
|
|
334
|
+
p
|
|
335
|
+
|
|
336
|
+
sage: pi.pyobject().__reduce__()
|
|
337
|
+
(<function unpickle_Constant at 0x...>,
|
|
338
|
+
('Pi',
|
|
339
|
+
'pi',
|
|
340
|
+
...,
|
|
341
|
+
'\\pi',
|
|
342
|
+
'<mi>π</mi>',
|
|
343
|
+
'positive'))
|
|
344
|
+
sage: loads(dumps(pi.pyobject()))
|
|
345
|
+
pi
|
|
346
|
+
"""
|
|
347
|
+
return (unpickle_Constant, (self.__class__.__name__, self._name,
|
|
348
|
+
self._conversions, self._latex,
|
|
349
|
+
self._mathml, self._domain))
|
|
350
|
+
|
|
351
|
+
def domain(self):
|
|
352
|
+
"""
|
|
353
|
+
Return the domain of this constant. This is either positive,
|
|
354
|
+
real, or complex, and is used by Pynac to make inferences
|
|
355
|
+
about expressions containing this constant.
|
|
356
|
+
|
|
357
|
+
EXAMPLES::
|
|
358
|
+
|
|
359
|
+
sage: p = pi.pyobject(); p
|
|
360
|
+
pi
|
|
361
|
+
sage: type(_)
|
|
362
|
+
<class 'sage.symbolic.constants.Pi'>
|
|
363
|
+
sage: p.domain()
|
|
364
|
+
'positive'
|
|
365
|
+
"""
|
|
366
|
+
return self._domain
|
|
367
|
+
|
|
368
|
+
def expression(self):
|
|
369
|
+
"""
|
|
370
|
+
Return an expression for this constant.
|
|
371
|
+
|
|
372
|
+
EXAMPLES::
|
|
373
|
+
|
|
374
|
+
sage: a = pi.pyobject()
|
|
375
|
+
sage: pi2 = a.expression()
|
|
376
|
+
sage: pi2
|
|
377
|
+
pi
|
|
378
|
+
sage: pi2 + 2
|
|
379
|
+
pi + 2
|
|
380
|
+
sage: pi - pi2
|
|
381
|
+
0
|
|
382
|
+
"""
|
|
383
|
+
return self._pynac.expression()
|
|
384
|
+
|
|
385
|
+
def _symbolic_(self, SR):
|
|
386
|
+
"""
|
|
387
|
+
Return an expression for this constant.
|
|
388
|
+
|
|
389
|
+
INPUT:
|
|
390
|
+
|
|
391
|
+
- ``SR`` -- a symbolic ring parent
|
|
392
|
+
|
|
393
|
+
EXAMPLES::
|
|
394
|
+
|
|
395
|
+
sage: SR(pi.pyobject())
|
|
396
|
+
pi
|
|
397
|
+
sage: pi.pyobject()._symbolic_(SR)
|
|
398
|
+
pi
|
|
399
|
+
sage: f(x,y) = 2
|
|
400
|
+
sage: f.parent()(pi.pyobject())
|
|
401
|
+
(x, y) |--> pi
|
|
402
|
+
"""
|
|
403
|
+
return SR(self.expression())
|
|
404
|
+
|
|
405
|
+
def name(self):
|
|
406
|
+
"""
|
|
407
|
+
Return the name of this constant.
|
|
408
|
+
|
|
409
|
+
EXAMPLES::
|
|
410
|
+
|
|
411
|
+
sage: from sage.symbolic.constants import Constant
|
|
412
|
+
sage: c = Constant('c')
|
|
413
|
+
sage: c.name()
|
|
414
|
+
'c'
|
|
415
|
+
"""
|
|
416
|
+
return self._name
|
|
417
|
+
|
|
418
|
+
def __repr__(self):
|
|
419
|
+
"""
|
|
420
|
+
EXAMPLES::
|
|
421
|
+
|
|
422
|
+
sage: from sage.symbolic.constants import Constant
|
|
423
|
+
sage: c = Constant('c')
|
|
424
|
+
sage: c
|
|
425
|
+
c
|
|
426
|
+
"""
|
|
427
|
+
return self._name
|
|
428
|
+
|
|
429
|
+
def _latex_(self):
|
|
430
|
+
r"""
|
|
431
|
+
EXAMPLES::
|
|
432
|
+
|
|
433
|
+
sage: from sage.symbolic.constants import Constant
|
|
434
|
+
sage: c = Constant('c', latex=r'\xi')
|
|
435
|
+
sage: latex(c)
|
|
436
|
+
\xi
|
|
437
|
+
"""
|
|
438
|
+
return self._latex
|
|
439
|
+
|
|
440
|
+
def _mathml_(self):
|
|
441
|
+
"""
|
|
442
|
+
EXAMPLES::
|
|
443
|
+
|
|
444
|
+
sage: from sage.symbolic.constants import Constant
|
|
445
|
+
sage: c = Constant('c', mathml=r'<mi>c</mi>')
|
|
446
|
+
sage: mathml(c)
|
|
447
|
+
<mi>c</mi>
|
|
448
|
+
"""
|
|
449
|
+
return self._mathml
|
|
450
|
+
|
|
451
|
+
def _generic_interface(self, value, I):
|
|
452
|
+
"""
|
|
453
|
+
This is a helper method used in defining the ``_X_`` methods
|
|
454
|
+
where ``X`` is the name of some interface.
|
|
455
|
+
|
|
456
|
+
EXAMPLES::
|
|
457
|
+
|
|
458
|
+
sage: from sage.symbolic.constants import Constant
|
|
459
|
+
sage: p = Constant('p', conversions=dict(maxima='%pi'))
|
|
460
|
+
sage: p._maxima_(maxima)
|
|
461
|
+
%pi
|
|
462
|
+
|
|
463
|
+
The above ``_maxima_`` is constructed like ``m`` below::
|
|
464
|
+
|
|
465
|
+
sage: from functools import partial
|
|
466
|
+
sage: m = partial(p._generic_interface, '%pi')
|
|
467
|
+
sage: m(maxima)
|
|
468
|
+
%pi
|
|
469
|
+
"""
|
|
470
|
+
return I(value)
|
|
471
|
+
|
|
472
|
+
def _generic_interface_init(self, value):
|
|
473
|
+
"""
|
|
474
|
+
This is a helper method used in defining the ``_X_init_`` methods
|
|
475
|
+
where ``X`` is the name of some interface.
|
|
476
|
+
|
|
477
|
+
EXAMPLES::
|
|
478
|
+
|
|
479
|
+
sage: from sage.symbolic.constants import Constant
|
|
480
|
+
sage: p = Constant('p', conversions=dict(maxima='%pi'))
|
|
481
|
+
sage: p._maxima_init_()
|
|
482
|
+
'%pi'
|
|
483
|
+
|
|
484
|
+
The above ``_maxima_init_`` is constructed like ``mi`` below::
|
|
485
|
+
|
|
486
|
+
sage: from functools import partial
|
|
487
|
+
sage: mi = partial(p._generic_interface_init, '%pi')
|
|
488
|
+
sage: mi()
|
|
489
|
+
'%pi'
|
|
490
|
+
"""
|
|
491
|
+
return value
|
|
492
|
+
|
|
493
|
+
def _interface_(self, I):
|
|
494
|
+
"""
|
|
495
|
+
EXAMPLES::
|
|
496
|
+
|
|
497
|
+
sage: from sage.symbolic.constants import Constant
|
|
498
|
+
sage: p = Constant('p', conversions=dict(maxima='%pi'))
|
|
499
|
+
sage: p._interface_(maxima)
|
|
500
|
+
%pi
|
|
501
|
+
"""
|
|
502
|
+
try:
|
|
503
|
+
s = self._conversions[I.name()]
|
|
504
|
+
return I(s)
|
|
505
|
+
except KeyError:
|
|
506
|
+
pass
|
|
507
|
+
|
|
508
|
+
try:
|
|
509
|
+
return getattr(self, "_%s_" % (I.name()))(I)
|
|
510
|
+
except AttributeError:
|
|
511
|
+
pass
|
|
512
|
+
|
|
513
|
+
raise NotImplementedError
|
|
514
|
+
|
|
515
|
+
def _gap_(self, gap):
|
|
516
|
+
"""
|
|
517
|
+
Return the constant as a string in GAP. Since GAP does not
|
|
518
|
+
have floating point numbers, we simply return the constant as
|
|
519
|
+
a string.
|
|
520
|
+
|
|
521
|
+
EXAMPLES::
|
|
522
|
+
|
|
523
|
+
sage: from sage.symbolic.constants import Constant
|
|
524
|
+
sage: p = Constant('p')
|
|
525
|
+
sage: gap(p) # needs sage.libs.gap
|
|
526
|
+
p
|
|
527
|
+
"""
|
|
528
|
+
return gap('"%s"' % self)
|
|
529
|
+
|
|
530
|
+
def _singular_(self, singular):
|
|
531
|
+
"""
|
|
532
|
+
Return the constant as a string in Singular. Since Singular
|
|
533
|
+
does not always support floating point numbers, we simply
|
|
534
|
+
return the constant as a string. (Singular allows floating point
|
|
535
|
+
numbers if the current ring has floating point coefficients,
|
|
536
|
+
but not otherwise.)
|
|
537
|
+
|
|
538
|
+
EXAMPLES::
|
|
539
|
+
|
|
540
|
+
sage: from sage.symbolic.constants import Constant
|
|
541
|
+
sage: p = Constant('p')
|
|
542
|
+
sage: singular(p) # needs sage.libs.singular
|
|
543
|
+
p
|
|
544
|
+
"""
|
|
545
|
+
return singular('"%s"' % self)
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
class Pi(Constant):
|
|
549
|
+
def __init__(self, name='pi'):
|
|
550
|
+
r"""
|
|
551
|
+
TESTS::
|
|
552
|
+
|
|
553
|
+
sage: pi._latex_()
|
|
554
|
+
'\\pi'
|
|
555
|
+
sage: latex(pi)
|
|
556
|
+
\pi
|
|
557
|
+
sage: mathml(pi)
|
|
558
|
+
<mi>π</mi>
|
|
559
|
+
"""
|
|
560
|
+
conversions = dict(axiom='%pi', fricas='%pi', maxima='%pi', giac='pi',
|
|
561
|
+
gp='Pi', kash='PI',
|
|
562
|
+
mathematica='Pi', matlab='pi', maple='Pi',
|
|
563
|
+
octave='pi', pari='Pi', pynac='Pi')
|
|
564
|
+
Constant.__init__(self, name, conversions=conversions,
|
|
565
|
+
latex=r"\pi", mathml="<mi>π</mi>",
|
|
566
|
+
domain='positive')
|
|
567
|
+
|
|
568
|
+
def __float__(self):
|
|
569
|
+
"""
|
|
570
|
+
EXAMPLES::
|
|
571
|
+
|
|
572
|
+
sage: float(pi)
|
|
573
|
+
3.141592653589793
|
|
574
|
+
"""
|
|
575
|
+
return math.pi
|
|
576
|
+
|
|
577
|
+
def _mpfr_(self, R):
|
|
578
|
+
"""
|
|
579
|
+
EXAMPLES::
|
|
580
|
+
|
|
581
|
+
sage: pi._mpfr_(RealField(100))
|
|
582
|
+
3.1415926535897932384626433833
|
|
583
|
+
"""
|
|
584
|
+
return R.pi()
|
|
585
|
+
|
|
586
|
+
def _real_double_(self, R):
|
|
587
|
+
"""
|
|
588
|
+
EXAMPLES::
|
|
589
|
+
|
|
590
|
+
sage: pi._real_double_(RDF)
|
|
591
|
+
3.141592653589793
|
|
592
|
+
"""
|
|
593
|
+
return R.pi()
|
|
594
|
+
|
|
595
|
+
def _sympy_(self):
|
|
596
|
+
"""
|
|
597
|
+
Convert pi to sympy pi.
|
|
598
|
+
|
|
599
|
+
EXAMPLES::
|
|
600
|
+
|
|
601
|
+
sage: import sympy # needs sympy
|
|
602
|
+
sage: sympy.pi == pi # indirect doctest # needs sympy
|
|
603
|
+
True
|
|
604
|
+
"""
|
|
605
|
+
import sympy
|
|
606
|
+
return sympy.pi
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
pi = Pi().expression()
|
|
610
|
+
"""
|
|
611
|
+
The formal square root of -1.
|
|
612
|
+
|
|
613
|
+
EXAMPLES::
|
|
614
|
+
|
|
615
|
+
sage: SR.I()
|
|
616
|
+
I
|
|
617
|
+
sage: SR.I()^2
|
|
618
|
+
-1
|
|
619
|
+
|
|
620
|
+
Note that conversions to real fields will give TypeErrors::
|
|
621
|
+
|
|
622
|
+
sage: float(SR.I())
|
|
623
|
+
Traceback (most recent call last):
|
|
624
|
+
...
|
|
625
|
+
TypeError: unable to simplify to float approximation
|
|
626
|
+
sage: gp(SR.I()) # needs sage.libs.pari
|
|
627
|
+
I
|
|
628
|
+
sage: RR(SR.I())
|
|
629
|
+
Traceback (most recent call last):
|
|
630
|
+
...
|
|
631
|
+
TypeError: unable to convert '1.00000000000000*I' to a real number
|
|
632
|
+
|
|
633
|
+
Expressions involving I that are real-valued can be converted to real fields::
|
|
634
|
+
|
|
635
|
+
sage: float(I*I)
|
|
636
|
+
-1.0
|
|
637
|
+
sage: RR(I*I)
|
|
638
|
+
-1.00000000000000
|
|
639
|
+
|
|
640
|
+
We can convert to complex fields::
|
|
641
|
+
|
|
642
|
+
sage: C = ComplexField(200); C
|
|
643
|
+
Complex Field with 200 bits of precision
|
|
644
|
+
sage: C(SR.I())
|
|
645
|
+
1.0000000000000000000000000000000000000000000000000000000000*I
|
|
646
|
+
sage: SR.I()._complex_mpfr_field_(ComplexField(53))
|
|
647
|
+
1.00000000000000*I
|
|
648
|
+
|
|
649
|
+
sage: SR.I()._complex_double_(CDF)
|
|
650
|
+
1.0*I
|
|
651
|
+
sage: CDF(SR.I())
|
|
652
|
+
1.0*I
|
|
653
|
+
|
|
654
|
+
sage: z = SR.I() + I; z
|
|
655
|
+
2*I
|
|
656
|
+
sage: C(z)
|
|
657
|
+
2.0000000000000000000000000000000000000000000000000000000000*I
|
|
658
|
+
sage: 1e8*SR.I()
|
|
659
|
+
1.00000000000000e8*I
|
|
660
|
+
|
|
661
|
+
sage: complex(SR.I())
|
|
662
|
+
1j
|
|
663
|
+
|
|
664
|
+
sage: QQbar(SR.I())
|
|
665
|
+
I
|
|
666
|
+
|
|
667
|
+
sage: abs(SR.I())
|
|
668
|
+
1
|
|
669
|
+
|
|
670
|
+
sage: SR.I().minpoly()
|
|
671
|
+
x^2 + 1
|
|
672
|
+
sage: maxima(2*SR.I())
|
|
673
|
+
2*%i
|
|
674
|
+
|
|
675
|
+
TESTS::
|
|
676
|
+
|
|
677
|
+
sage: repr(SR.I())
|
|
678
|
+
'I'
|
|
679
|
+
sage: latex(SR.I())
|
|
680
|
+
i
|
|
681
|
+
"""
|
|
682
|
+
|
|
683
|
+
# The base of the natural logarithm, e, is not a constant in GiNaC/Sage. It is
|
|
684
|
+
# represented by exp(1). A dummy class to make this work with arithmetic and
|
|
685
|
+
# coercion is implemented in the module sage.symbolic.expression for speed.
|
|
686
|
+
e = E()
|
|
687
|
+
|
|
688
|
+
# Allow for backtranslation to this symbol from Mathematica (#29833).
|
|
689
|
+
register_symbol(e, {'mathematica': 'E'})
|
|
690
|
+
|
|
691
|
+
|
|
692
|
+
class NotANumber(Constant):
|
|
693
|
+
"""
|
|
694
|
+
Not a Number
|
|
695
|
+
"""
|
|
696
|
+
def __init__(self, name="NaN"):
|
|
697
|
+
"""
|
|
698
|
+
EXAMPLES::
|
|
699
|
+
|
|
700
|
+
sage: loads(dumps(NaN))
|
|
701
|
+
NaN
|
|
702
|
+
"""
|
|
703
|
+
conversions = dict(matlab='NaN')
|
|
704
|
+
Constant.__init__(self, name, conversions=conversions)
|
|
705
|
+
|
|
706
|
+
def __float__(self):
|
|
707
|
+
"""
|
|
708
|
+
EXAMPLES::
|
|
709
|
+
|
|
710
|
+
sage: float(NaN)
|
|
711
|
+
nan
|
|
712
|
+
"""
|
|
713
|
+
return float('nan')
|
|
714
|
+
|
|
715
|
+
def _mpfr_(self, R):
|
|
716
|
+
"""
|
|
717
|
+
EXAMPLES::
|
|
718
|
+
|
|
719
|
+
sage: NaN._mpfr_(RealField(53))
|
|
720
|
+
NaN
|
|
721
|
+
sage: type(_)
|
|
722
|
+
<class 'sage.rings.real_mpfr.RealNumber'>
|
|
723
|
+
"""
|
|
724
|
+
return R('NaN') # ??? nan in mpfr: void mpfr_set_nan (mpfr_t x)
|
|
725
|
+
|
|
726
|
+
def _real_double_(self, R):
|
|
727
|
+
"""
|
|
728
|
+
EXAMPLES::
|
|
729
|
+
|
|
730
|
+
sage: RDF(NaN)
|
|
731
|
+
NaN
|
|
732
|
+
"""
|
|
733
|
+
return R.NaN()
|
|
734
|
+
|
|
735
|
+
def _sympy_(self):
|
|
736
|
+
"""
|
|
737
|
+
Convert ``NaN`` to SymPy NaN.
|
|
738
|
+
|
|
739
|
+
EXAMPLES::
|
|
740
|
+
|
|
741
|
+
sage: bool(NaN._sympy_()._sage_() == NaN) # needs sympy
|
|
742
|
+
True
|
|
743
|
+
sage: import sympy # needs sympy
|
|
744
|
+
sage: sympy.nan == NaN # this should be fixed # needs sympy
|
|
745
|
+
False
|
|
746
|
+
"""
|
|
747
|
+
import sympy
|
|
748
|
+
return sympy.nan
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
NaN = NotANumber().expression()
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
class GoldenRatio(Constant):
|
|
755
|
+
"""
|
|
756
|
+
The number (1+sqrt(5))/2.
|
|
757
|
+
|
|
758
|
+
EXAMPLES::
|
|
759
|
+
|
|
760
|
+
sage: gr = golden_ratio
|
|
761
|
+
sage: RR(gr)
|
|
762
|
+
1.61803398874989
|
|
763
|
+
sage: R = RealField(200)
|
|
764
|
+
sage: R(gr)
|
|
765
|
+
1.6180339887498948482045868343656381177203091798057628621354
|
|
766
|
+
sage: grm = maxima(golden_ratio);grm
|
|
767
|
+
(sqrt(5)+1)/2
|
|
768
|
+
sage: grm + grm
|
|
769
|
+
sqrt(5)+1
|
|
770
|
+
sage: float(grm + grm)
|
|
771
|
+
3.23606797749979
|
|
772
|
+
"""
|
|
773
|
+
def __init__(self, name='golden_ratio'):
|
|
774
|
+
"""
|
|
775
|
+
EXAMPLES::
|
|
776
|
+
|
|
777
|
+
sage: loads(dumps(golden_ratio))
|
|
778
|
+
golden_ratio
|
|
779
|
+
"""
|
|
780
|
+
conversions = dict(mathematica='(1+Sqrt[5])/2', gp='(1+sqrt(5))/2',
|
|
781
|
+
maple='(1+sqrt(5))/2', maxima='(1+sqrt(5))/2',
|
|
782
|
+
pari='(1+sqrt(5))/2', octave='(1+sqrt(5))/2',
|
|
783
|
+
kash='(1+Sqrt(5))/2', giac='(1+sqrt(5))/2')
|
|
784
|
+
Constant.__init__(self, name, conversions=conversions,
|
|
785
|
+
latex=r'\phi', domain='positive')
|
|
786
|
+
|
|
787
|
+
def minpoly(self, bits=None, degree=None, epsilon=0):
|
|
788
|
+
"""
|
|
789
|
+
EXAMPLES::
|
|
790
|
+
|
|
791
|
+
sage: golden_ratio.minpoly()
|
|
792
|
+
x^2 - x - 1
|
|
793
|
+
"""
|
|
794
|
+
from sage.rings.rational_field import QQ
|
|
795
|
+
x = QQ['x'].gen(0)
|
|
796
|
+
return x**2 - x - 1
|
|
797
|
+
|
|
798
|
+
def __float__(self):
|
|
799
|
+
"""
|
|
800
|
+
EXAMPLES::
|
|
801
|
+
|
|
802
|
+
sage: float(golden_ratio)
|
|
803
|
+
1.618033988749895
|
|
804
|
+
sage: golden_ratio.__float__()
|
|
805
|
+
1.618033988749895
|
|
806
|
+
"""
|
|
807
|
+
return 0.5 + math.sqrt(1.25)
|
|
808
|
+
|
|
809
|
+
def _real_double_(self, R):
|
|
810
|
+
"""
|
|
811
|
+
EXAMPLES::
|
|
812
|
+
|
|
813
|
+
sage: RDF(golden_ratio)
|
|
814
|
+
1.618033988749895
|
|
815
|
+
"""
|
|
816
|
+
return R('1.61803398874989484820458')
|
|
817
|
+
|
|
818
|
+
def _mpfr_(self, R):
|
|
819
|
+
"""
|
|
820
|
+
EXAMPLES::
|
|
821
|
+
|
|
822
|
+
sage: golden_ratio._mpfr_(RealField(100))
|
|
823
|
+
1.6180339887498948482045868344
|
|
824
|
+
sage: RealField(100)(golden_ratio)
|
|
825
|
+
1.6180339887498948482045868344
|
|
826
|
+
"""
|
|
827
|
+
return (R(1) + R(5).sqrt()) / R(2)
|
|
828
|
+
|
|
829
|
+
def _algebraic_(self, field):
|
|
830
|
+
"""
|
|
831
|
+
EXAMPLES::
|
|
832
|
+
|
|
833
|
+
sage: # needs sage.libs.pari
|
|
834
|
+
sage: golden_ratio._algebraic_(QQbar)
|
|
835
|
+
1.618033988749895?
|
|
836
|
+
sage: QQbar(golden_ratio)
|
|
837
|
+
1.618033988749895?
|
|
838
|
+
"""
|
|
839
|
+
import sage.rings.qqbar
|
|
840
|
+
return field(sage.rings.qqbar.get_AA_golden_ratio())
|
|
841
|
+
|
|
842
|
+
def _sympy_(self):
|
|
843
|
+
"""
|
|
844
|
+
Convert ``golden_ratio`` to SymPy GoldenRatio.
|
|
845
|
+
|
|
846
|
+
EXAMPLES::
|
|
847
|
+
|
|
848
|
+
sage: import sympy # needs sympy
|
|
849
|
+
sage: sympy.GoldenRatio == golden_ratio # indirect doctest # needs sympy
|
|
850
|
+
True
|
|
851
|
+
"""
|
|
852
|
+
import sympy
|
|
853
|
+
return sympy.GoldenRatio
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
golden_ratio = GoldenRatio().expression()
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
class Log2(Constant):
|
|
860
|
+
"""
|
|
861
|
+
The natural logarithm of the real number 2.
|
|
862
|
+
|
|
863
|
+
EXAMPLES::
|
|
864
|
+
|
|
865
|
+
sage: log2
|
|
866
|
+
log2
|
|
867
|
+
sage: float(log2)
|
|
868
|
+
0.6931471805599453
|
|
869
|
+
sage: RR(log2)
|
|
870
|
+
0.693147180559945
|
|
871
|
+
sage: R = RealField(200); R
|
|
872
|
+
Real Field with 200 bits of precision
|
|
873
|
+
sage: R(log2)
|
|
874
|
+
0.69314718055994530941723212145817656807550013436025525412068
|
|
875
|
+
sage: l = (1-log2)/(1+log2); l
|
|
876
|
+
-(log2 - 1)/(log2 + 1)
|
|
877
|
+
sage: R(l)
|
|
878
|
+
0.18123221829928249948761381864650311423330609774776013488056
|
|
879
|
+
sage: maxima(log2)
|
|
880
|
+
log(2)
|
|
881
|
+
sage: maxima(log2).float()
|
|
882
|
+
0.6931471805599453
|
|
883
|
+
sage: gp(log2) # needs sage.libs.pari
|
|
884
|
+
0.69314718055994530941723212145817656807
|
|
885
|
+
sage: RealField(150)(2).log()
|
|
886
|
+
0.69314718055994530941723212145817656807550013
|
|
887
|
+
sage: giac(log2) # optional - giac
|
|
888
|
+
ln(2)
|
|
889
|
+
"""
|
|
890
|
+
def __init__(self, name='log2'):
|
|
891
|
+
"""
|
|
892
|
+
EXAMPLES::
|
|
893
|
+
|
|
894
|
+
sage: loads(dumps(log2))
|
|
895
|
+
log2
|
|
896
|
+
"""
|
|
897
|
+
conversions = dict(mathematica='Log[2]', kash='Log(2)',
|
|
898
|
+
maple='log(2)', maxima='log(2)', gp='log(2)',
|
|
899
|
+
pari='log(2)', octave='log(2)', giac='log(2)')
|
|
900
|
+
Constant.__init__(self, name, conversions=conversions,
|
|
901
|
+
latex=r'\log(2)', domain='positive')
|
|
902
|
+
|
|
903
|
+
def __float__(self):
|
|
904
|
+
"""
|
|
905
|
+
EXAMPLES::
|
|
906
|
+
|
|
907
|
+
sage: float(log2)
|
|
908
|
+
0.6931471805599453
|
|
909
|
+
sage: log2.__float__()
|
|
910
|
+
0.6931471805599453
|
|
911
|
+
"""
|
|
912
|
+
return math.log(2)
|
|
913
|
+
|
|
914
|
+
def _real_double_(self, R):
|
|
915
|
+
"""
|
|
916
|
+
EXAMPLES::
|
|
917
|
+
|
|
918
|
+
sage: RDF(log2)
|
|
919
|
+
0.6931471805599453
|
|
920
|
+
"""
|
|
921
|
+
return R.log2()
|
|
922
|
+
|
|
923
|
+
def _mpfr_(self, R):
|
|
924
|
+
"""
|
|
925
|
+
EXAMPLES::
|
|
926
|
+
|
|
927
|
+
sage: RealField(100)(log2)
|
|
928
|
+
0.69314718055994530941723212146
|
|
929
|
+
sage: log2._mpfr_(RealField(100))
|
|
930
|
+
0.69314718055994530941723212146
|
|
931
|
+
"""
|
|
932
|
+
return R.log2()
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
log2 = Log2().expression()
|
|
936
|
+
|
|
937
|
+
|
|
938
|
+
class EulerGamma(Constant):
|
|
939
|
+
"""
|
|
940
|
+
The limiting difference between the harmonic series and the natural
|
|
941
|
+
logarithm.
|
|
942
|
+
|
|
943
|
+
EXAMPLES::
|
|
944
|
+
|
|
945
|
+
sage: R = RealField()
|
|
946
|
+
sage: R(euler_gamma)
|
|
947
|
+
0.577215664901533
|
|
948
|
+
sage: R = RealField(200); R
|
|
949
|
+
Real Field with 200 bits of precision
|
|
950
|
+
sage: R(euler_gamma)
|
|
951
|
+
0.57721566490153286060651209008240243104215933593992359880577
|
|
952
|
+
sage: eg = euler_gamma + euler_gamma; eg
|
|
953
|
+
2*euler_gamma
|
|
954
|
+
sage: R(eg)
|
|
955
|
+
1.1544313298030657212130241801648048620843186718798471976115
|
|
956
|
+
"""
|
|
957
|
+
def __init__(self, name='euler_gamma'):
|
|
958
|
+
"""
|
|
959
|
+
EXAMPLES::
|
|
960
|
+
|
|
961
|
+
sage: loads(dumps(euler_gamma))
|
|
962
|
+
euler_gamma
|
|
963
|
+
"""
|
|
964
|
+
conversions = dict(kash='EulerGamma(R)', maple='gamma',
|
|
965
|
+
mathematica='EulerGamma', pari='Euler',
|
|
966
|
+
maxima='%gamma', pynac='Euler', giac='euler_gamma',
|
|
967
|
+
fricas='-digamma(1)')
|
|
968
|
+
Constant.__init__(self, name, conversions=conversions,
|
|
969
|
+
latex=r'\gamma', domain='positive')
|
|
970
|
+
|
|
971
|
+
def _mpfr_(self, R):
|
|
972
|
+
"""
|
|
973
|
+
EXAMPLES::
|
|
974
|
+
|
|
975
|
+
sage: RealField(100)(euler_gamma)
|
|
976
|
+
0.57721566490153286060651209008
|
|
977
|
+
sage: euler_gamma._mpfr_(RealField(100))
|
|
978
|
+
0.57721566490153286060651209008
|
|
979
|
+
"""
|
|
980
|
+
return R.euler_constant()
|
|
981
|
+
|
|
982
|
+
def __float__(self):
|
|
983
|
+
"""
|
|
984
|
+
EXAMPLES::
|
|
985
|
+
|
|
986
|
+
sage: float(euler_gamma)
|
|
987
|
+
0.5772156649015329
|
|
988
|
+
"""
|
|
989
|
+
return 0.57721566490153286060651209008
|
|
990
|
+
|
|
991
|
+
def _real_double_(self, R):
|
|
992
|
+
"""
|
|
993
|
+
EXAMPLES::
|
|
994
|
+
|
|
995
|
+
sage: RDF(euler_gamma)
|
|
996
|
+
0.5772156649015329
|
|
997
|
+
"""
|
|
998
|
+
return R.euler_constant()
|
|
999
|
+
|
|
1000
|
+
def _sympy_(self):
|
|
1001
|
+
"""
|
|
1002
|
+
Convert ``euler_gamma`` to SymPy EulerGamma.
|
|
1003
|
+
|
|
1004
|
+
EXAMPLES::
|
|
1005
|
+
|
|
1006
|
+
sage: import sympy # needs sympy
|
|
1007
|
+
sage: sympy.EulerGamma == euler_gamma # indirect doctest # needs sympy
|
|
1008
|
+
True
|
|
1009
|
+
"""
|
|
1010
|
+
import sympy
|
|
1011
|
+
return sympy.EulerGamma
|
|
1012
|
+
|
|
1013
|
+
|
|
1014
|
+
euler_gamma = EulerGamma().expression()
|
|
1015
|
+
|
|
1016
|
+
|
|
1017
|
+
class Catalan(Constant):
|
|
1018
|
+
"""
|
|
1019
|
+
A number appearing in combinatorics defined as the Dirichlet beta
|
|
1020
|
+
function evaluated at the number 2.
|
|
1021
|
+
|
|
1022
|
+
EXAMPLES::
|
|
1023
|
+
|
|
1024
|
+
sage: catalan^2 + mertens
|
|
1025
|
+
mertens + catalan^2
|
|
1026
|
+
"""
|
|
1027
|
+
def __init__(self, name='catalan'):
|
|
1028
|
+
"""
|
|
1029
|
+
EXAMPLES::
|
|
1030
|
+
|
|
1031
|
+
sage: loads(dumps(catalan))
|
|
1032
|
+
catalan
|
|
1033
|
+
"""
|
|
1034
|
+
# kash: R is default prec
|
|
1035
|
+
conversions = dict(mathematica='Catalan', kash='Catalan(R)',
|
|
1036
|
+
maple='Catalan', maxima='catalan',
|
|
1037
|
+
pynac='Catalan')
|
|
1038
|
+
Constant.__init__(self, name, conversions=conversions,
|
|
1039
|
+
domain='positive')
|
|
1040
|
+
|
|
1041
|
+
def _mpfr_(self, R):
|
|
1042
|
+
"""
|
|
1043
|
+
EXAMPLES::
|
|
1044
|
+
|
|
1045
|
+
sage: RealField(100)(catalan)
|
|
1046
|
+
0.91596559417721901505460351493
|
|
1047
|
+
sage: catalan._mpfr_(RealField(100))
|
|
1048
|
+
0.91596559417721901505460351493
|
|
1049
|
+
"""
|
|
1050
|
+
return R.catalan_constant()
|
|
1051
|
+
|
|
1052
|
+
def _real_double_(self, R):
|
|
1053
|
+
"""
|
|
1054
|
+
EXAMPLES: We coerce to the real double field::
|
|
1055
|
+
|
|
1056
|
+
sage: RDF(catalan)
|
|
1057
|
+
0.915965594177219
|
|
1058
|
+
"""
|
|
1059
|
+
return R('0.91596559417721901505460351493252')
|
|
1060
|
+
|
|
1061
|
+
def __float__(self):
|
|
1062
|
+
"""
|
|
1063
|
+
EXAMPLES::
|
|
1064
|
+
|
|
1065
|
+
sage: float(catalan)
|
|
1066
|
+
0.915965594177219
|
|
1067
|
+
"""
|
|
1068
|
+
return 0.91596559417721901505460351493252
|
|
1069
|
+
|
|
1070
|
+
def _sympy_(self):
|
|
1071
|
+
"""
|
|
1072
|
+
Convert ``catalan`` to SymPy Catalan.
|
|
1073
|
+
|
|
1074
|
+
EXAMPLES::
|
|
1075
|
+
|
|
1076
|
+
sage: import sympy # needs sympy
|
|
1077
|
+
sage: sympy.Catalan == catalan # indirect doctest # needs sympy
|
|
1078
|
+
True
|
|
1079
|
+
"""
|
|
1080
|
+
import sympy
|
|
1081
|
+
return sympy.Catalan
|
|
1082
|
+
|
|
1083
|
+
|
|
1084
|
+
catalan = Catalan().expression()
|
|
1085
|
+
|
|
1086
|
+
|
|
1087
|
+
class Khinchin(Constant):
|
|
1088
|
+
"""
|
|
1089
|
+
The geometric mean of the continued fraction expansion of any
|
|
1090
|
+
(almost any) real number.
|
|
1091
|
+
|
|
1092
|
+
EXAMPLES::
|
|
1093
|
+
|
|
1094
|
+
sage: float(khinchin)
|
|
1095
|
+
2.6854520010653062
|
|
1096
|
+
sage: khinchin.n(digits=60)
|
|
1097
|
+
2.68545200106530644530971483548179569382038229399446295305115
|
|
1098
|
+
sage: m = mathematica(khinchin); m # optional - mathematica
|
|
1099
|
+
Khinchin
|
|
1100
|
+
sage: m.N(200) # optional - mathematica
|
|
1101
|
+
2.685452001065306445309714835481795693820382293...32852204481940961807
|
|
1102
|
+
"""
|
|
1103
|
+
def __init__(self, name='khinchin'):
|
|
1104
|
+
"""
|
|
1105
|
+
EXAMPLES::
|
|
1106
|
+
|
|
1107
|
+
sage: loads(dumps(khinchin))
|
|
1108
|
+
khinchin
|
|
1109
|
+
"""
|
|
1110
|
+
conversions = dict(maxima='khinchin', mathematica='Khinchin',
|
|
1111
|
+
pynac='Khinchin')
|
|
1112
|
+
Constant.__init__(self, name, conversions=conversions,
|
|
1113
|
+
domain='positive')
|
|
1114
|
+
|
|
1115
|
+
def _mpfr_(self, R):
|
|
1116
|
+
"""
|
|
1117
|
+
EXAMPLES::
|
|
1118
|
+
|
|
1119
|
+
sage: khinchin._mpfr_(RealField(100))
|
|
1120
|
+
2.6854520010653064453097148355
|
|
1121
|
+
sage: RealField(100)(khinchin)
|
|
1122
|
+
2.6854520010653064453097148355
|
|
1123
|
+
"""
|
|
1124
|
+
import sage.libs.mpmath.all as a
|
|
1125
|
+
return a.eval_constant('khinchin', R)
|
|
1126
|
+
|
|
1127
|
+
def __float__(self):
|
|
1128
|
+
"""
|
|
1129
|
+
EXAMPLES::
|
|
1130
|
+
|
|
1131
|
+
sage: float(khinchin)
|
|
1132
|
+
2.6854520010653062
|
|
1133
|
+
"""
|
|
1134
|
+
return 2.6854520010653064453097148355
|
|
1135
|
+
|
|
1136
|
+
|
|
1137
|
+
khinchin = Khinchin().expression()
|
|
1138
|
+
|
|
1139
|
+
|
|
1140
|
+
class TwinPrime(Constant):
|
|
1141
|
+
r"""
|
|
1142
|
+
The Twin Primes constant is defined as
|
|
1143
|
+
`\prod 1 - 1/(p-1)^2` for primes `p > 2`.
|
|
1144
|
+
|
|
1145
|
+
EXAMPLES::
|
|
1146
|
+
|
|
1147
|
+
sage: float(twinprime)
|
|
1148
|
+
0.6601618158468696
|
|
1149
|
+
sage: twinprime.n(digits=60)
|
|
1150
|
+
0.660161815846869573927812110014555778432623360284733413319448
|
|
1151
|
+
"""
|
|
1152
|
+
def __init__(self, name='twinprime'):
|
|
1153
|
+
"""
|
|
1154
|
+
EXAMPLES::
|
|
1155
|
+
|
|
1156
|
+
sage: loads(dumps(twinprime))
|
|
1157
|
+
twinprime
|
|
1158
|
+
"""
|
|
1159
|
+
conversions = dict(maxima='twinprime', pynac='TwinPrime')
|
|
1160
|
+
Constant.__init__(self, name, conversions=conversions,
|
|
1161
|
+
domain='positive')
|
|
1162
|
+
|
|
1163
|
+
def _mpfr_(self, R):
|
|
1164
|
+
"""
|
|
1165
|
+
EXAMPLES::
|
|
1166
|
+
|
|
1167
|
+
sage: twinprime._mpfr_(RealField(100))
|
|
1168
|
+
0.66016181584686957392781211001
|
|
1169
|
+
sage: RealField(100)(twinprime)
|
|
1170
|
+
0.66016181584686957392781211001
|
|
1171
|
+
"""
|
|
1172
|
+
import sage.libs.mpmath.all as a
|
|
1173
|
+
return a.eval_constant('twinprime', R)
|
|
1174
|
+
|
|
1175
|
+
def __float__(self):
|
|
1176
|
+
"""
|
|
1177
|
+
EXAMPLES::
|
|
1178
|
+
|
|
1179
|
+
sage: float(twinprime)
|
|
1180
|
+
0.6601618158468696
|
|
1181
|
+
"""
|
|
1182
|
+
return 0.66016181584686957392781211001
|
|
1183
|
+
|
|
1184
|
+
|
|
1185
|
+
twinprime = TwinPrime().expression()
|
|
1186
|
+
|
|
1187
|
+
|
|
1188
|
+
class Mertens(Constant):
|
|
1189
|
+
"""
|
|
1190
|
+
The Mertens constant is related to the Twin Primes constant and
|
|
1191
|
+
appears in Mertens' second theorem.
|
|
1192
|
+
|
|
1193
|
+
EXAMPLES::
|
|
1194
|
+
|
|
1195
|
+
sage: float(mertens)
|
|
1196
|
+
0.26149721284764277
|
|
1197
|
+
sage: mertens.n(digits=60)
|
|
1198
|
+
0.261497212847642783755426838608695859051566648261199206192064
|
|
1199
|
+
"""
|
|
1200
|
+
def __init__(self, name='mertens'):
|
|
1201
|
+
"""
|
|
1202
|
+
EXAMPLES::
|
|
1203
|
+
|
|
1204
|
+
sage: loads(dumps(mertens))
|
|
1205
|
+
mertens
|
|
1206
|
+
"""
|
|
1207
|
+
conversions = dict(maxima='mertens', pynac='Mertens')
|
|
1208
|
+
Constant.__init__(self, name, conversions=conversions,
|
|
1209
|
+
domain='positive')
|
|
1210
|
+
|
|
1211
|
+
def _mpfr_(self, R):
|
|
1212
|
+
"""
|
|
1213
|
+
EXAMPLES::
|
|
1214
|
+
|
|
1215
|
+
sage: mertens._mpfr_(RealField(100))
|
|
1216
|
+
0.26149721284764278375542683861
|
|
1217
|
+
sage: RealField(100)(mertens)
|
|
1218
|
+
0.26149721284764278375542683861
|
|
1219
|
+
"""
|
|
1220
|
+
import sage.libs.mpmath.all as a
|
|
1221
|
+
return a.eval_constant('mertens', R)
|
|
1222
|
+
|
|
1223
|
+
def __float__(self):
|
|
1224
|
+
"""
|
|
1225
|
+
EXAMPLES::
|
|
1226
|
+
|
|
1227
|
+
sage: float(mertens)
|
|
1228
|
+
0.26149721284764277
|
|
1229
|
+
"""
|
|
1230
|
+
return 0.26149721284764278375542683861
|
|
1231
|
+
|
|
1232
|
+
|
|
1233
|
+
mertens = Mertens().expression()
|
|
1234
|
+
|
|
1235
|
+
|
|
1236
|
+
class Glaisher(Constant):
|
|
1237
|
+
r"""
|
|
1238
|
+
The Glaisher-Kinkelin constant `A = \exp(\frac{1}{12}-\zeta'(-1))`.
|
|
1239
|
+
|
|
1240
|
+
EXAMPLES::
|
|
1241
|
+
|
|
1242
|
+
sage: float(glaisher)
|
|
1243
|
+
1.2824271291006226
|
|
1244
|
+
sage: glaisher.n(digits=60)
|
|
1245
|
+
1.28242712910062263687534256886979172776768892732500119206374
|
|
1246
|
+
sage: a = glaisher + 2
|
|
1247
|
+
sage: a
|
|
1248
|
+
glaisher + 2
|
|
1249
|
+
sage: parent(a)
|
|
1250
|
+
Symbolic Ring
|
|
1251
|
+
"""
|
|
1252
|
+
def __init__(self, name='glaisher'):
|
|
1253
|
+
"""
|
|
1254
|
+
EXAMPLES::
|
|
1255
|
+
|
|
1256
|
+
sage: loads(dumps(glaisher))
|
|
1257
|
+
glaisher
|
|
1258
|
+
"""
|
|
1259
|
+
conversions = dict(maxima='glaisher', pynac='Glaisher',
|
|
1260
|
+
mathematica='Glaisher')
|
|
1261
|
+
Constant.__init__(self, name, conversions=conversions,
|
|
1262
|
+
domain='positive')
|
|
1263
|
+
|
|
1264
|
+
def _mpfr_(self, R):
|
|
1265
|
+
"""
|
|
1266
|
+
EXAMPLES::
|
|
1267
|
+
|
|
1268
|
+
sage: glaisher._mpfr_(RealField(100))
|
|
1269
|
+
1.2824271291006226368753425689
|
|
1270
|
+
sage: RealField(100)(glaisher)
|
|
1271
|
+
1.2824271291006226368753425689
|
|
1272
|
+
"""
|
|
1273
|
+
import sage.libs.mpmath.all as a
|
|
1274
|
+
return a.eval_constant('glaisher', R)
|
|
1275
|
+
|
|
1276
|
+
def __float__(self):
|
|
1277
|
+
"""
|
|
1278
|
+
EXAMPLES::
|
|
1279
|
+
|
|
1280
|
+
sage: float(glaisher)
|
|
1281
|
+
1.2824271291006226
|
|
1282
|
+
"""
|
|
1283
|
+
return 1.2824271291006226368753425689
|
|
1284
|
+
|
|
1285
|
+
|
|
1286
|
+
glaisher = Glaisher().expression()
|