passagemath-symbolics 10.6.40__cp314-cp314t-macosx_13_0_x86_64.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.

Potentially problematic release.


This version of passagemath-symbolics might be problematic. Click here for more details.

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