passagemath-categories 10.6.32__cp314-cp314t-musllinux_1_2_aarch64.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.
Files changed (719) hide show
  1. passagemath_categories-10.6.32.dist-info/METADATA +156 -0
  2. passagemath_categories-10.6.32.dist-info/RECORD +719 -0
  3. passagemath_categories-10.6.32.dist-info/WHEEL +5 -0
  4. passagemath_categories-10.6.32.dist-info/top_level.txt +2 -0
  5. passagemath_categories.libs/libgcc_s-2d945d6c.so.1 +0 -0
  6. passagemath_categories.libs/libgmp-28992bcb.so.10.5.0 +0 -0
  7. passagemath_categories.libs/libstdc++-85f2cd6d.so.6.0.33 +0 -0
  8. sage/all__sagemath_categories.py +28 -0
  9. sage/arith/all.py +38 -0
  10. sage/arith/constants.pxd +27 -0
  11. sage/arith/functions.cpython-314t-aarch64-linux-musl.so +0 -0
  12. sage/arith/functions.pxd +4 -0
  13. sage/arith/functions.pyx +221 -0
  14. sage/arith/misc.py +6552 -0
  15. sage/arith/multi_modular.cpython-314t-aarch64-linux-musl.so +0 -0
  16. sage/arith/multi_modular.pxd +39 -0
  17. sage/arith/multi_modular.pyx +994 -0
  18. sage/arith/rational_reconstruction.cpython-314t-aarch64-linux-musl.so +0 -0
  19. sage/arith/rational_reconstruction.pxd +4 -0
  20. sage/arith/rational_reconstruction.pyx +115 -0
  21. sage/arith/srange.cpython-314t-aarch64-linux-musl.so +0 -0
  22. sage/arith/srange.pyx +571 -0
  23. sage/calculus/all__sagemath_categories.py +2 -0
  24. sage/calculus/functional.py +481 -0
  25. sage/calculus/functions.py +151 -0
  26. sage/categories/additive_groups.py +73 -0
  27. sage/categories/additive_magmas.py +1044 -0
  28. sage/categories/additive_monoids.py +114 -0
  29. sage/categories/additive_semigroups.py +184 -0
  30. sage/categories/affine_weyl_groups.py +238 -0
  31. sage/categories/algebra_ideals.py +95 -0
  32. sage/categories/algebra_modules.py +96 -0
  33. sage/categories/algebras.py +349 -0
  34. sage/categories/algebras_with_basis.py +377 -0
  35. sage/categories/all.py +160 -0
  36. sage/categories/aperiodic_semigroups.py +29 -0
  37. sage/categories/associative_algebras.py +47 -0
  38. sage/categories/bialgebras.py +101 -0
  39. sage/categories/bialgebras_with_basis.py +414 -0
  40. sage/categories/bimodules.py +206 -0
  41. sage/categories/chain_complexes.py +268 -0
  42. sage/categories/classical_crystals.py +480 -0
  43. sage/categories/coalgebras.py +405 -0
  44. sage/categories/coalgebras_with_basis.py +232 -0
  45. sage/categories/coercion_methods.cpython-314t-aarch64-linux-musl.so +0 -0
  46. sage/categories/coercion_methods.pyx +52 -0
  47. sage/categories/commutative_additive_groups.py +104 -0
  48. sage/categories/commutative_additive_monoids.py +45 -0
  49. sage/categories/commutative_additive_semigroups.py +48 -0
  50. sage/categories/commutative_algebra_ideals.py +87 -0
  51. sage/categories/commutative_algebras.py +94 -0
  52. sage/categories/commutative_ring_ideals.py +58 -0
  53. sage/categories/commutative_rings.py +736 -0
  54. sage/categories/complete_discrete_valuation.py +293 -0
  55. sage/categories/complex_reflection_groups.py +145 -0
  56. sage/categories/complex_reflection_or_generalized_coxeter_groups.py +1249 -0
  57. sage/categories/coxeter_group_algebras.py +186 -0
  58. sage/categories/coxeter_groups.py +3402 -0
  59. sage/categories/crystals.py +2628 -0
  60. sage/categories/cw_complexes.py +216 -0
  61. sage/categories/dedekind_domains.py +137 -0
  62. sage/categories/discrete_valuation.py +325 -0
  63. sage/categories/distributive_magmas_and_additive_magmas.py +100 -0
  64. sage/categories/division_rings.py +114 -0
  65. sage/categories/domains.py +95 -0
  66. sage/categories/drinfeld_modules.py +789 -0
  67. sage/categories/dual.py +42 -0
  68. sage/categories/enumerated_sets.py +1146 -0
  69. sage/categories/euclidean_domains.py +271 -0
  70. sage/categories/examples/algebras_with_basis.py +102 -0
  71. sage/categories/examples/all.py +1 -0
  72. sage/categories/examples/commutative_additive_monoids.py +130 -0
  73. sage/categories/examples/commutative_additive_semigroups.py +199 -0
  74. sage/categories/examples/coxeter_groups.py +8 -0
  75. sage/categories/examples/crystals.py +236 -0
  76. sage/categories/examples/cw_complexes.py +163 -0
  77. sage/categories/examples/facade_sets.py +187 -0
  78. sage/categories/examples/filtered_algebras_with_basis.py +204 -0
  79. sage/categories/examples/filtered_modules_with_basis.py +154 -0
  80. sage/categories/examples/finite_coxeter_groups.py +252 -0
  81. sage/categories/examples/finite_dimensional_algebras_with_basis.py +148 -0
  82. sage/categories/examples/finite_dimensional_lie_algebras_with_basis.py +495 -0
  83. sage/categories/examples/finite_enumerated_sets.py +208 -0
  84. sage/categories/examples/finite_monoids.py +150 -0
  85. sage/categories/examples/finite_semigroups.py +190 -0
  86. sage/categories/examples/finite_weyl_groups.py +191 -0
  87. sage/categories/examples/graded_connected_hopf_algebras_with_basis.py +152 -0
  88. sage/categories/examples/graded_modules_with_basis.py +168 -0
  89. sage/categories/examples/graphs.py +122 -0
  90. sage/categories/examples/hopf_algebras_with_basis.py +145 -0
  91. sage/categories/examples/infinite_enumerated_sets.py +190 -0
  92. sage/categories/examples/lie_algebras.py +352 -0
  93. sage/categories/examples/lie_algebras_with_basis.py +196 -0
  94. sage/categories/examples/magmas.py +162 -0
  95. sage/categories/examples/manifolds.py +94 -0
  96. sage/categories/examples/monoids.py +144 -0
  97. sage/categories/examples/posets.py +178 -0
  98. sage/categories/examples/semigroups.py +580 -0
  99. sage/categories/examples/semigroups_cython.cpython-314t-aarch64-linux-musl.so +0 -0
  100. sage/categories/examples/semigroups_cython.pyx +221 -0
  101. sage/categories/examples/semirings.py +249 -0
  102. sage/categories/examples/sets_cat.py +706 -0
  103. sage/categories/examples/sets_with_grading.py +101 -0
  104. sage/categories/examples/with_realizations.py +542 -0
  105. sage/categories/fields.py +991 -0
  106. sage/categories/filtered_algebras.py +63 -0
  107. sage/categories/filtered_algebras_with_basis.py +548 -0
  108. sage/categories/filtered_hopf_algebras_with_basis.py +138 -0
  109. sage/categories/filtered_modules.py +210 -0
  110. sage/categories/filtered_modules_with_basis.py +1209 -0
  111. sage/categories/finite_complex_reflection_groups.py +1506 -0
  112. sage/categories/finite_coxeter_groups.py +1138 -0
  113. sage/categories/finite_crystals.py +103 -0
  114. sage/categories/finite_dimensional_algebras_with_basis.py +1860 -0
  115. sage/categories/finite_dimensional_bialgebras_with_basis.py +33 -0
  116. sage/categories/finite_dimensional_coalgebras_with_basis.py +33 -0
  117. sage/categories/finite_dimensional_graded_lie_algebras_with_basis.py +231 -0
  118. sage/categories/finite_dimensional_hopf_algebras_with_basis.py +38 -0
  119. sage/categories/finite_dimensional_lie_algebras_with_basis.py +2774 -0
  120. sage/categories/finite_dimensional_modules_with_basis.py +1407 -0
  121. sage/categories/finite_dimensional_nilpotent_lie_algebras_with_basis.py +167 -0
  122. sage/categories/finite_dimensional_semisimple_algebras_with_basis.py +270 -0
  123. sage/categories/finite_enumerated_sets.py +769 -0
  124. sage/categories/finite_fields.py +252 -0
  125. sage/categories/finite_groups.py +256 -0
  126. sage/categories/finite_lattice_posets.py +242 -0
  127. sage/categories/finite_monoids.py +316 -0
  128. sage/categories/finite_permutation_groups.py +339 -0
  129. sage/categories/finite_posets.py +1994 -0
  130. sage/categories/finite_semigroups.py +136 -0
  131. sage/categories/finite_sets.py +93 -0
  132. sage/categories/finite_weyl_groups.py +39 -0
  133. sage/categories/finitely_generated_lambda_bracket_algebras.py +112 -0
  134. sage/categories/finitely_generated_lie_conformal_algebras.py +114 -0
  135. sage/categories/finitely_generated_magmas.py +57 -0
  136. sage/categories/finitely_generated_semigroups.py +214 -0
  137. sage/categories/function_fields.py +76 -0
  138. sage/categories/g_sets.py +77 -0
  139. sage/categories/gcd_domains.py +65 -0
  140. sage/categories/generalized_coxeter_groups.py +94 -0
  141. sage/categories/graded_algebras.py +85 -0
  142. sage/categories/graded_algebras_with_basis.py +258 -0
  143. sage/categories/graded_bialgebras.py +32 -0
  144. sage/categories/graded_bialgebras_with_basis.py +32 -0
  145. sage/categories/graded_coalgebras.py +65 -0
  146. sage/categories/graded_coalgebras_with_basis.py +51 -0
  147. sage/categories/graded_hopf_algebras.py +41 -0
  148. sage/categories/graded_hopf_algebras_with_basis.py +169 -0
  149. sage/categories/graded_lie_algebras.py +91 -0
  150. sage/categories/graded_lie_algebras_with_basis.py +44 -0
  151. sage/categories/graded_lie_conformal_algebras.py +74 -0
  152. sage/categories/graded_modules.py +133 -0
  153. sage/categories/graded_modules_with_basis.py +329 -0
  154. sage/categories/graphs.py +138 -0
  155. sage/categories/group_algebras.py +430 -0
  156. sage/categories/groupoid.py +94 -0
  157. sage/categories/groups.py +667 -0
  158. sage/categories/h_trivial_semigroups.py +64 -0
  159. sage/categories/hecke_modules.py +185 -0
  160. sage/categories/highest_weight_crystals.py +980 -0
  161. sage/categories/hopf_algebras.py +219 -0
  162. sage/categories/hopf_algebras_with_basis.py +309 -0
  163. sage/categories/infinite_enumerated_sets.py +115 -0
  164. sage/categories/integral_domains.py +203 -0
  165. sage/categories/j_trivial_semigroups.py +29 -0
  166. sage/categories/kac_moody_algebras.py +82 -0
  167. sage/categories/kahler_algebras.py +203 -0
  168. sage/categories/l_trivial_semigroups.py +63 -0
  169. sage/categories/lambda_bracket_algebras.py +280 -0
  170. sage/categories/lambda_bracket_algebras_with_basis.py +107 -0
  171. sage/categories/lattice_posets.py +89 -0
  172. sage/categories/left_modules.py +49 -0
  173. sage/categories/lie_algebras.py +1070 -0
  174. sage/categories/lie_algebras_with_basis.py +261 -0
  175. sage/categories/lie_conformal_algebras.py +350 -0
  176. sage/categories/lie_conformal_algebras_with_basis.py +147 -0
  177. sage/categories/lie_groups.py +73 -0
  178. sage/categories/loop_crystals.py +1290 -0
  179. sage/categories/magmas.py +1189 -0
  180. sage/categories/magmas_and_additive_magmas.py +149 -0
  181. sage/categories/magmatic_algebras.py +365 -0
  182. sage/categories/manifolds.py +352 -0
  183. sage/categories/matrix_algebras.py +40 -0
  184. sage/categories/metric_spaces.py +387 -0
  185. sage/categories/modular_abelian_varieties.py +78 -0
  186. sage/categories/modules.py +989 -0
  187. sage/categories/modules_with_basis.py +2794 -0
  188. sage/categories/monoid_algebras.py +38 -0
  189. sage/categories/monoids.py +739 -0
  190. sage/categories/noetherian_rings.py +87 -0
  191. sage/categories/number_fields.py +242 -0
  192. sage/categories/ore_modules.py +189 -0
  193. sage/categories/partially_ordered_monoids.py +49 -0
  194. sage/categories/permutation_groups.py +63 -0
  195. sage/categories/pointed_sets.py +42 -0
  196. sage/categories/polyhedra.py +74 -0
  197. sage/categories/poor_man_map.py +270 -0
  198. sage/categories/posets.py +722 -0
  199. sage/categories/principal_ideal_domains.py +270 -0
  200. sage/categories/quantum_group_representations.py +543 -0
  201. sage/categories/quotient_fields.py +728 -0
  202. sage/categories/r_trivial_semigroups.py +45 -0
  203. sage/categories/regular_crystals.py +898 -0
  204. sage/categories/regular_supercrystals.py +170 -0
  205. sage/categories/right_modules.py +49 -0
  206. sage/categories/ring_ideals.py +74 -0
  207. sage/categories/rings.py +1904 -0
  208. sage/categories/rngs.py +175 -0
  209. sage/categories/schemes.py +393 -0
  210. sage/categories/semigroups.py +1060 -0
  211. sage/categories/semirings.py +71 -0
  212. sage/categories/semisimple_algebras.py +114 -0
  213. sage/categories/sets_with_grading.py +235 -0
  214. sage/categories/shephard_groups.py +43 -0
  215. sage/categories/signed_tensor.py +120 -0
  216. sage/categories/simplicial_complexes.py +134 -0
  217. sage/categories/simplicial_sets.py +1206 -0
  218. sage/categories/super_algebras.py +149 -0
  219. sage/categories/super_algebras_with_basis.py +144 -0
  220. sage/categories/super_hopf_algebras_with_basis.py +126 -0
  221. sage/categories/super_lie_conformal_algebras.py +193 -0
  222. sage/categories/super_modules.py +229 -0
  223. sage/categories/super_modules_with_basis.py +193 -0
  224. sage/categories/supercommutative_algebras.py +99 -0
  225. sage/categories/supercrystals.py +406 -0
  226. sage/categories/tensor.py +110 -0
  227. sage/categories/topological_spaces.py +170 -0
  228. sage/categories/triangular_kac_moody_algebras.py +439 -0
  229. sage/categories/tutorial.py +58 -0
  230. sage/categories/unique_factorization_domains.py +318 -0
  231. sage/categories/unital_algebras.py +426 -0
  232. sage/categories/vector_bundles.py +159 -0
  233. sage/categories/vector_spaces.py +357 -0
  234. sage/categories/weyl_groups.py +853 -0
  235. sage/combinat/all__sagemath_categories.py +34 -0
  236. sage/combinat/backtrack.py +180 -0
  237. sage/combinat/combinat.py +2269 -0
  238. sage/combinat/combinat_cython.cpython-314t-aarch64-linux-musl.so +0 -0
  239. sage/combinat/combinat_cython.pxd +6 -0
  240. sage/combinat/combinat_cython.pyx +390 -0
  241. sage/combinat/combination.py +796 -0
  242. sage/combinat/combinatorial_map.py +416 -0
  243. sage/combinat/composition.py +2192 -0
  244. sage/combinat/dlx.py +510 -0
  245. sage/combinat/integer_lists/__init__.py +7 -0
  246. sage/combinat/integer_lists/base.cpython-314t-aarch64-linux-musl.so +0 -0
  247. sage/combinat/integer_lists/base.pxd +16 -0
  248. sage/combinat/integer_lists/base.pyx +713 -0
  249. sage/combinat/integer_lists/invlex.cpython-314t-aarch64-linux-musl.so +0 -0
  250. sage/combinat/integer_lists/invlex.pxd +4 -0
  251. sage/combinat/integer_lists/invlex.pyx +1650 -0
  252. sage/combinat/integer_lists/lists.py +328 -0
  253. sage/combinat/integer_lists/nn.py +48 -0
  254. sage/combinat/integer_vector.py +1818 -0
  255. sage/combinat/integer_vector_weighted.py +413 -0
  256. sage/combinat/matrices/all__sagemath_categories.py +5 -0
  257. sage/combinat/matrices/dancing_links.cpython-314t-aarch64-linux-musl.so +0 -0
  258. sage/combinat/matrices/dancing_links.pyx +1159 -0
  259. sage/combinat/matrices/dancing_links_c.h +380 -0
  260. sage/combinat/matrices/dlxcpp.py +136 -0
  261. sage/combinat/partition.py +10070 -0
  262. sage/combinat/partitions.cpython-314t-aarch64-linux-musl.so +0 -0
  263. sage/combinat/partitions.pyx +743 -0
  264. sage/combinat/permutation.py +10168 -0
  265. sage/combinat/permutation_cython.cpython-314t-aarch64-linux-musl.so +0 -0
  266. sage/combinat/permutation_cython.pxd +11 -0
  267. sage/combinat/permutation_cython.pyx +407 -0
  268. sage/combinat/q_analogues.py +1090 -0
  269. sage/combinat/ranker.py +268 -0
  270. sage/combinat/subset.py +1561 -0
  271. sage/combinat/subsets_hereditary.py +202 -0
  272. sage/combinat/subsets_pairwise.py +184 -0
  273. sage/combinat/tools.py +63 -0
  274. sage/combinat/tuple.py +348 -0
  275. sage/data_structures/all.py +2 -0
  276. sage/data_structures/all__sagemath_categories.py +2 -0
  277. sage/data_structures/binary_matrix.pxd +138 -0
  278. sage/data_structures/binary_search.cpython-314t-aarch64-linux-musl.so +0 -0
  279. sage/data_structures/binary_search.pxd +3 -0
  280. sage/data_structures/binary_search.pyx +66 -0
  281. sage/data_structures/bitset.cpython-314t-aarch64-linux-musl.so +0 -0
  282. sage/data_structures/bitset.pxd +40 -0
  283. sage/data_structures/bitset.pyx +2385 -0
  284. sage/data_structures/bitset_base.cpython-314t-aarch64-linux-musl.so +0 -0
  285. sage/data_structures/bitset_base.pxd +926 -0
  286. sage/data_structures/bitset_base.pyx +117 -0
  287. sage/data_structures/bitset_intrinsics.h +487 -0
  288. sage/data_structures/blas_dict.cpython-314t-aarch64-linux-musl.so +0 -0
  289. sage/data_structures/blas_dict.pxd +12 -0
  290. sage/data_structures/blas_dict.pyx +469 -0
  291. sage/data_structures/list_of_pairs.cpython-314t-aarch64-linux-musl.so +0 -0
  292. sage/data_structures/list_of_pairs.pxd +16 -0
  293. sage/data_structures/list_of_pairs.pyx +122 -0
  294. sage/data_structures/mutable_poset.py +3312 -0
  295. sage/data_structures/pairing_heap.cpython-314t-aarch64-linux-musl.so +0 -0
  296. sage/data_structures/pairing_heap.h +346 -0
  297. sage/data_structures/pairing_heap.pxd +88 -0
  298. sage/data_structures/pairing_heap.pyx +1464 -0
  299. sage/data_structures/sparse_bitset.pxd +62 -0
  300. sage/data_structures/stream.py +5070 -0
  301. sage/databases/all__sagemath_categories.py +7 -0
  302. sage/databases/sql_db.py +2236 -0
  303. sage/ext/all__sagemath_categories.py +3 -0
  304. sage/ext/fast_callable.cpython-314t-aarch64-linux-musl.so +0 -0
  305. sage/ext/fast_callable.pxd +4 -0
  306. sage/ext/fast_callable.pyx +2746 -0
  307. sage/ext/fast_eval.cpython-314t-aarch64-linux-musl.so +0 -0
  308. sage/ext/fast_eval.pxd +1 -0
  309. sage/ext/fast_eval.pyx +102 -0
  310. sage/ext/interpreters/__init__.py +1 -0
  311. sage/ext/interpreters/all__sagemath_categories.py +2 -0
  312. sage/ext/interpreters/wrapper_el.cpython-314t-aarch64-linux-musl.so +0 -0
  313. sage/ext/interpreters/wrapper_el.pxd +18 -0
  314. sage/ext/interpreters/wrapper_el.pyx +148 -0
  315. sage/ext/interpreters/wrapper_py.cpython-314t-aarch64-linux-musl.so +0 -0
  316. sage/ext/interpreters/wrapper_py.pxd +17 -0
  317. sage/ext/interpreters/wrapper_py.pyx +133 -0
  318. sage/functions/airy.py +937 -0
  319. sage/functions/all.py +97 -0
  320. sage/functions/bessel.py +2102 -0
  321. sage/functions/error.py +784 -0
  322. sage/functions/exp_integral.py +1529 -0
  323. sage/functions/gamma.py +1087 -0
  324. sage/functions/generalized.py +672 -0
  325. sage/functions/hyperbolic.py +747 -0
  326. sage/functions/hypergeometric.py +1156 -0
  327. sage/functions/jacobi.py +1705 -0
  328. sage/functions/log.py +1402 -0
  329. sage/functions/min_max.py +338 -0
  330. sage/functions/orthogonal_polys.py +3106 -0
  331. sage/functions/other.py +2303 -0
  332. sage/functions/piecewise.py +1505 -0
  333. sage/functions/prime_pi.cpython-314t-aarch64-linux-musl.so +0 -0
  334. sage/functions/prime_pi.pyx +262 -0
  335. sage/functions/special.py +1212 -0
  336. sage/functions/spike_function.py +278 -0
  337. sage/functions/transcendental.py +690 -0
  338. sage/functions/trig.py +1062 -0
  339. sage/functions/wigner.py +726 -0
  340. sage/geometry/abc.cpython-314t-aarch64-linux-musl.so +0 -0
  341. sage/geometry/abc.pyx +82 -0
  342. sage/geometry/all__sagemath_categories.py +1 -0
  343. sage/groups/all__sagemath_categories.py +11 -0
  344. sage/groups/generic.py +1733 -0
  345. sage/groups/groups_catalog.py +113 -0
  346. sage/groups/perm_gps/all__sagemath_categories.py +1 -0
  347. sage/groups/perm_gps/partn_ref/all.py +1 -0
  348. sage/groups/perm_gps/partn_ref/all__sagemath_categories.py +1 -0
  349. sage/groups/perm_gps/partn_ref/automorphism_group_canonical_label.cpython-314t-aarch64-linux-musl.so +0 -0
  350. sage/groups/perm_gps/partn_ref/automorphism_group_canonical_label.pxd +52 -0
  351. sage/groups/perm_gps/partn_ref/automorphism_group_canonical_label.pyx +906 -0
  352. sage/groups/perm_gps/partn_ref/canonical_augmentation.cpython-314t-aarch64-linux-musl.so +0 -0
  353. sage/groups/perm_gps/partn_ref/canonical_augmentation.pxd +85 -0
  354. sage/groups/perm_gps/partn_ref/canonical_augmentation.pyx +534 -0
  355. sage/groups/perm_gps/partn_ref/data_structures.cpython-314t-aarch64-linux-musl.so +0 -0
  356. sage/groups/perm_gps/partn_ref/data_structures.pxd +576 -0
  357. sage/groups/perm_gps/partn_ref/data_structures.pyx +1792 -0
  358. sage/groups/perm_gps/partn_ref/double_coset.cpython-314t-aarch64-linux-musl.so +0 -0
  359. sage/groups/perm_gps/partn_ref/double_coset.pxd +45 -0
  360. sage/groups/perm_gps/partn_ref/double_coset.pyx +739 -0
  361. sage/groups/perm_gps/partn_ref/refinement_lists.cpython-314t-aarch64-linux-musl.so +0 -0
  362. sage/groups/perm_gps/partn_ref/refinement_lists.pxd +18 -0
  363. sage/groups/perm_gps/partn_ref/refinement_lists.pyx +82 -0
  364. sage/groups/perm_gps/partn_ref/refinement_python.cpython-314t-aarch64-linux-musl.so +0 -0
  365. sage/groups/perm_gps/partn_ref/refinement_python.pxd +16 -0
  366. sage/groups/perm_gps/partn_ref/refinement_python.pyx +564 -0
  367. sage/groups/perm_gps/partn_ref/refinement_sets.cpython-314t-aarch64-linux-musl.so +0 -0
  368. sage/groups/perm_gps/partn_ref/refinement_sets.pxd +60 -0
  369. sage/groups/perm_gps/partn_ref/refinement_sets.pyx +858 -0
  370. sage/interfaces/abc.py +140 -0
  371. sage/interfaces/all.py +58 -0
  372. sage/interfaces/all__sagemath_categories.py +1 -0
  373. sage/interfaces/expect.py +1643 -0
  374. sage/interfaces/interface.py +1682 -0
  375. sage/interfaces/process.cpython-314t-aarch64-linux-musl.so +0 -0
  376. sage/interfaces/process.pxd +5 -0
  377. sage/interfaces/process.pyx +288 -0
  378. sage/interfaces/quit.py +167 -0
  379. sage/interfaces/sage0.py +604 -0
  380. sage/interfaces/sagespawn.cpython-314t-aarch64-linux-musl.so +0 -0
  381. sage/interfaces/sagespawn.pyx +308 -0
  382. sage/interfaces/tab_completion.py +101 -0
  383. sage/misc/all__sagemath_categories.py +78 -0
  384. sage/misc/allocator.cpython-314t-aarch64-linux-musl.so +0 -0
  385. sage/misc/allocator.pxd +6 -0
  386. sage/misc/allocator.pyx +47 -0
  387. sage/misc/binary_tree.cpython-314t-aarch64-linux-musl.so +0 -0
  388. sage/misc/binary_tree.pxd +29 -0
  389. sage/misc/binary_tree.pyx +537 -0
  390. sage/misc/callable_dict.cpython-314t-aarch64-linux-musl.so +0 -0
  391. sage/misc/callable_dict.pyx +89 -0
  392. sage/misc/citation.cpython-314t-aarch64-linux-musl.so +0 -0
  393. sage/misc/citation.pyx +159 -0
  394. sage/misc/converting_dict.py +293 -0
  395. sage/misc/defaults.py +129 -0
  396. sage/misc/derivative.cpython-314t-aarch64-linux-musl.so +0 -0
  397. sage/misc/derivative.pyx +223 -0
  398. sage/misc/functional.py +2005 -0
  399. sage/misc/html.py +589 -0
  400. sage/misc/latex.py +2673 -0
  401. sage/misc/latex_macros.py +236 -0
  402. sage/misc/latex_standalone.py +1833 -0
  403. sage/misc/map_threaded.py +38 -0
  404. sage/misc/mathml.py +76 -0
  405. sage/misc/method_decorator.py +88 -0
  406. sage/misc/mrange.py +755 -0
  407. sage/misc/multireplace.py +41 -0
  408. sage/misc/object_multiplexer.py +92 -0
  409. sage/misc/parser.cpython-314t-aarch64-linux-musl.so +0 -0
  410. sage/misc/parser.pyx +1107 -0
  411. sage/misc/random_testing.py +264 -0
  412. sage/misc/rest_index_of_methods.py +377 -0
  413. sage/misc/search.cpython-314t-aarch64-linux-musl.so +0 -0
  414. sage/misc/search.pxd +2 -0
  415. sage/misc/search.pyx +68 -0
  416. sage/misc/stopgap.cpython-314t-aarch64-linux-musl.so +0 -0
  417. sage/misc/stopgap.pyx +95 -0
  418. sage/misc/table.py +853 -0
  419. sage/monoids/all__sagemath_categories.py +1 -0
  420. sage/monoids/indexed_free_monoid.py +1071 -0
  421. sage/monoids/monoid.py +82 -0
  422. sage/numerical/all__sagemath_categories.py +1 -0
  423. sage/numerical/backends/all__sagemath_categories.py +1 -0
  424. sage/numerical/backends/generic_backend.cpython-314t-aarch64-linux-musl.so +0 -0
  425. sage/numerical/backends/generic_backend.pxd +61 -0
  426. sage/numerical/backends/generic_backend.pyx +1893 -0
  427. sage/numerical/backends/generic_sdp_backend.cpython-314t-aarch64-linux-musl.so +0 -0
  428. sage/numerical/backends/generic_sdp_backend.pxd +38 -0
  429. sage/numerical/backends/generic_sdp_backend.pyx +755 -0
  430. sage/parallel/all.py +6 -0
  431. sage/parallel/decorate.py +575 -0
  432. sage/parallel/map_reduce.py +1997 -0
  433. sage/parallel/multiprocessing_sage.py +76 -0
  434. sage/parallel/ncpus.py +35 -0
  435. sage/parallel/parallelism.py +364 -0
  436. sage/parallel/reference.py +47 -0
  437. sage/parallel/use_fork.py +333 -0
  438. sage/rings/abc.cpython-314t-aarch64-linux-musl.so +0 -0
  439. sage/rings/abc.pxd +31 -0
  440. sage/rings/abc.pyx +526 -0
  441. sage/rings/algebraic_closure_finite_field.py +1154 -0
  442. sage/rings/all__sagemath_categories.py +91 -0
  443. sage/rings/big_oh.py +227 -0
  444. sage/rings/continued_fraction.py +2754 -0
  445. sage/rings/continued_fraction_gosper.py +220 -0
  446. sage/rings/factorint.cpython-314t-aarch64-linux-musl.so +0 -0
  447. sage/rings/factorint.pyx +295 -0
  448. sage/rings/fast_arith.cpython-314t-aarch64-linux-musl.so +0 -0
  449. sage/rings/fast_arith.pxd +21 -0
  450. sage/rings/fast_arith.pyx +535 -0
  451. sage/rings/finite_rings/all__sagemath_categories.py +9 -0
  452. sage/rings/finite_rings/conway_polynomials.py +542 -0
  453. sage/rings/finite_rings/element_base.cpython-314t-aarch64-linux-musl.so +0 -0
  454. sage/rings/finite_rings/element_base.pxd +12 -0
  455. sage/rings/finite_rings/element_base.pyx +1176 -0
  456. sage/rings/finite_rings/finite_field_base.cpython-314t-aarch64-linux-musl.so +0 -0
  457. sage/rings/finite_rings/finite_field_base.pxd +7 -0
  458. sage/rings/finite_rings/finite_field_base.pyx +2171 -0
  459. sage/rings/finite_rings/finite_field_constructor.py +827 -0
  460. sage/rings/finite_rings/finite_field_prime_modn.py +372 -0
  461. sage/rings/finite_rings/galois_group.py +154 -0
  462. sage/rings/finite_rings/hom_finite_field.cpython-314t-aarch64-linux-musl.so +0 -0
  463. sage/rings/finite_rings/hom_finite_field.pxd +23 -0
  464. sage/rings/finite_rings/hom_finite_field.pyx +856 -0
  465. sage/rings/finite_rings/hom_prime_finite_field.cpython-314t-aarch64-linux-musl.so +0 -0
  466. sage/rings/finite_rings/hom_prime_finite_field.pxd +15 -0
  467. sage/rings/finite_rings/hom_prime_finite_field.pyx +164 -0
  468. sage/rings/finite_rings/homset.py +357 -0
  469. sage/rings/finite_rings/integer_mod.cpython-314t-aarch64-linux-musl.so +0 -0
  470. sage/rings/finite_rings/integer_mod.pxd +56 -0
  471. sage/rings/finite_rings/integer_mod.pyx +4586 -0
  472. sage/rings/finite_rings/integer_mod_limits.h +11 -0
  473. sage/rings/finite_rings/integer_mod_ring.py +2044 -0
  474. sage/rings/finite_rings/residue_field.cpython-314t-aarch64-linux-musl.so +0 -0
  475. sage/rings/finite_rings/residue_field.pxd +30 -0
  476. sage/rings/finite_rings/residue_field.pyx +1811 -0
  477. sage/rings/finite_rings/stdint.pxd +19 -0
  478. sage/rings/fraction_field.py +1452 -0
  479. sage/rings/fraction_field_element.cpython-314t-aarch64-linux-musl.so +0 -0
  480. sage/rings/fraction_field_element.pyx +1357 -0
  481. sage/rings/function_field/all.py +7 -0
  482. sage/rings/function_field/all__sagemath_categories.py +2 -0
  483. sage/rings/function_field/constructor.py +218 -0
  484. sage/rings/function_field/element.cpython-314t-aarch64-linux-musl.so +0 -0
  485. sage/rings/function_field/element.pxd +11 -0
  486. sage/rings/function_field/element.pyx +1008 -0
  487. sage/rings/function_field/element_rational.cpython-314t-aarch64-linux-musl.so +0 -0
  488. sage/rings/function_field/element_rational.pyx +513 -0
  489. sage/rings/function_field/extensions.py +230 -0
  490. sage/rings/function_field/function_field.py +1468 -0
  491. sage/rings/function_field/function_field_rational.py +1005 -0
  492. sage/rings/function_field/ideal.py +1155 -0
  493. sage/rings/function_field/ideal_rational.py +629 -0
  494. sage/rings/function_field/jacobian_base.py +826 -0
  495. sage/rings/function_field/jacobian_hess.py +1053 -0
  496. sage/rings/function_field/jacobian_khuri_makdisi.py +1027 -0
  497. sage/rings/function_field/maps.py +1039 -0
  498. sage/rings/function_field/order.py +281 -0
  499. sage/rings/function_field/order_basis.py +586 -0
  500. sage/rings/function_field/order_rational.py +576 -0
  501. sage/rings/function_field/place.py +426 -0
  502. sage/rings/function_field/place_rational.py +181 -0
  503. sage/rings/generic.py +320 -0
  504. sage/rings/homset.py +332 -0
  505. sage/rings/ideal.py +1885 -0
  506. sage/rings/ideal_monoid.py +215 -0
  507. sage/rings/infinity.py +1890 -0
  508. sage/rings/integer.cpython-314t-aarch64-linux-musl.so +0 -0
  509. sage/rings/integer.pxd +45 -0
  510. sage/rings/integer.pyx +7874 -0
  511. sage/rings/integer_ring.cpython-314t-aarch64-linux-musl.so +0 -0
  512. sage/rings/integer_ring.pxd +8 -0
  513. sage/rings/integer_ring.pyx +1693 -0
  514. sage/rings/laurent_series_ring.py +931 -0
  515. sage/rings/laurent_series_ring_element.cpython-314t-aarch64-linux-musl.so +0 -0
  516. sage/rings/laurent_series_ring_element.pxd +11 -0
  517. sage/rings/laurent_series_ring_element.pyx +1927 -0
  518. sage/rings/lazy_series.py +7815 -0
  519. sage/rings/lazy_series_ring.py +4356 -0
  520. sage/rings/localization.py +1043 -0
  521. sage/rings/morphism.cpython-314t-aarch64-linux-musl.so +0 -0
  522. sage/rings/morphism.pxd +39 -0
  523. sage/rings/morphism.pyx +3299 -0
  524. sage/rings/multi_power_series_ring.py +1145 -0
  525. sage/rings/multi_power_series_ring_element.py +2184 -0
  526. sage/rings/noncommutative_ideals.cpython-314t-aarch64-linux-musl.so +0 -0
  527. sage/rings/noncommutative_ideals.pyx +423 -0
  528. sage/rings/number_field/all__sagemath_categories.py +1 -0
  529. sage/rings/number_field/number_field_base.cpython-314t-aarch64-linux-musl.so +0 -0
  530. sage/rings/number_field/number_field_base.pxd +8 -0
  531. sage/rings/number_field/number_field_base.pyx +507 -0
  532. sage/rings/number_field/number_field_element_base.cpython-314t-aarch64-linux-musl.so +0 -0
  533. sage/rings/number_field/number_field_element_base.pxd +6 -0
  534. sage/rings/number_field/number_field_element_base.pyx +36 -0
  535. sage/rings/number_field/number_field_ideal.py +3550 -0
  536. sage/rings/padics/all__sagemath_categories.py +4 -0
  537. sage/rings/padics/local_generic.py +1670 -0
  538. sage/rings/padics/local_generic_element.cpython-314t-aarch64-linux-musl.so +0 -0
  539. sage/rings/padics/local_generic_element.pxd +5 -0
  540. sage/rings/padics/local_generic_element.pyx +1017 -0
  541. sage/rings/padics/misc.py +256 -0
  542. sage/rings/padics/padic_generic.py +1911 -0
  543. sage/rings/padics/pow_computer.cpython-314t-aarch64-linux-musl.so +0 -0
  544. sage/rings/padics/pow_computer.pxd +38 -0
  545. sage/rings/padics/pow_computer.pyx +671 -0
  546. sage/rings/padics/precision_error.py +24 -0
  547. sage/rings/polynomial/all__sagemath_categories.py +25 -0
  548. sage/rings/polynomial/commutative_polynomial.cpython-314t-aarch64-linux-musl.so +0 -0
  549. sage/rings/polynomial/commutative_polynomial.pxd +6 -0
  550. sage/rings/polynomial/commutative_polynomial.pyx +24 -0
  551. sage/rings/polynomial/cyclotomic.cpython-314t-aarch64-linux-musl.so +0 -0
  552. sage/rings/polynomial/cyclotomic.pyx +404 -0
  553. sage/rings/polynomial/flatten.py +711 -0
  554. sage/rings/polynomial/ideal.py +102 -0
  555. sage/rings/polynomial/infinite_polynomial_element.py +1768 -0
  556. sage/rings/polynomial/infinite_polynomial_ring.py +1653 -0
  557. sage/rings/polynomial/laurent_polynomial.cpython-314t-aarch64-linux-musl.so +0 -0
  558. sage/rings/polynomial/laurent_polynomial.pxd +18 -0
  559. sage/rings/polynomial/laurent_polynomial.pyx +2190 -0
  560. sage/rings/polynomial/laurent_polynomial_ideal.py +590 -0
  561. sage/rings/polynomial/laurent_polynomial_ring.py +832 -0
  562. sage/rings/polynomial/laurent_polynomial_ring_base.py +708 -0
  563. sage/rings/polynomial/multi_polynomial.cpython-314t-aarch64-linux-musl.so +0 -0
  564. sage/rings/polynomial/multi_polynomial.pxd +12 -0
  565. sage/rings/polynomial/multi_polynomial.pyx +3082 -0
  566. sage/rings/polynomial/multi_polynomial_element.py +2570 -0
  567. sage/rings/polynomial/multi_polynomial_ideal.py +5771 -0
  568. sage/rings/polynomial/multi_polynomial_ring.py +947 -0
  569. sage/rings/polynomial/multi_polynomial_ring_base.cpython-314t-aarch64-linux-musl.so +0 -0
  570. sage/rings/polynomial/multi_polynomial_ring_base.pxd +15 -0
  571. sage/rings/polynomial/multi_polynomial_ring_base.pyx +1855 -0
  572. sage/rings/polynomial/multi_polynomial_sequence.py +2204 -0
  573. sage/rings/polynomial/polydict.cpython-314t-aarch64-linux-musl.so +0 -0
  574. sage/rings/polynomial/polydict.pxd +45 -0
  575. sage/rings/polynomial/polydict.pyx +2701 -0
  576. sage/rings/polynomial/polynomial_compiled.cpython-314t-aarch64-linux-musl.so +0 -0
  577. sage/rings/polynomial/polynomial_compiled.pxd +59 -0
  578. sage/rings/polynomial/polynomial_compiled.pyx +509 -0
  579. sage/rings/polynomial/polynomial_element.cpython-314t-aarch64-linux-musl.so +0 -0
  580. sage/rings/polynomial/polynomial_element.pxd +64 -0
  581. sage/rings/polynomial/polynomial_element.pyx +13255 -0
  582. sage/rings/polynomial/polynomial_element_generic.py +1637 -0
  583. sage/rings/polynomial/polynomial_fateman.py +97 -0
  584. sage/rings/polynomial/polynomial_quotient_ring.py +2465 -0
  585. sage/rings/polynomial/polynomial_quotient_ring_element.py +779 -0
  586. sage/rings/polynomial/polynomial_ring.py +3784 -0
  587. sage/rings/polynomial/polynomial_ring_constructor.py +1051 -0
  588. sage/rings/polynomial/polynomial_ring_homomorphism.cpython-314t-aarch64-linux-musl.so +0 -0
  589. sage/rings/polynomial/polynomial_ring_homomorphism.pxd +5 -0
  590. sage/rings/polynomial/polynomial_ring_homomorphism.pyx +121 -0
  591. sage/rings/polynomial/polynomial_singular_interface.py +549 -0
  592. sage/rings/polynomial/symmetric_ideal.py +989 -0
  593. sage/rings/polynomial/symmetric_reduction.cpython-314t-aarch64-linux-musl.so +0 -0
  594. sage/rings/polynomial/symmetric_reduction.pxd +8 -0
  595. sage/rings/polynomial/symmetric_reduction.pyx +669 -0
  596. sage/rings/polynomial/term_order.py +2279 -0
  597. sage/rings/polynomial/toy_buchberger.py +449 -0
  598. sage/rings/polynomial/toy_d_basis.py +387 -0
  599. sage/rings/polynomial/toy_variety.py +362 -0
  600. sage/rings/power_series_mpoly.cpython-314t-aarch64-linux-musl.so +0 -0
  601. sage/rings/power_series_mpoly.pxd +9 -0
  602. sage/rings/power_series_mpoly.pyx +161 -0
  603. sage/rings/power_series_poly.cpython-314t-aarch64-linux-musl.so +0 -0
  604. sage/rings/power_series_poly.pxd +10 -0
  605. sage/rings/power_series_poly.pyx +1317 -0
  606. sage/rings/power_series_ring.py +1441 -0
  607. sage/rings/power_series_ring_element.cpython-314t-aarch64-linux-musl.so +0 -0
  608. sage/rings/power_series_ring_element.pxd +12 -0
  609. sage/rings/power_series_ring_element.pyx +3028 -0
  610. sage/rings/puiseux_series_ring.py +487 -0
  611. sage/rings/puiseux_series_ring_element.cpython-314t-aarch64-linux-musl.so +0 -0
  612. sage/rings/puiseux_series_ring_element.pxd +7 -0
  613. sage/rings/puiseux_series_ring_element.pyx +1055 -0
  614. sage/rings/qqbar_decorators.py +167 -0
  615. sage/rings/quotient_ring.py +1598 -0
  616. sage/rings/quotient_ring_element.py +979 -0
  617. sage/rings/rational.cpython-314t-aarch64-linux-musl.so +0 -0
  618. sage/rings/rational.pxd +20 -0
  619. sage/rings/rational.pyx +4284 -0
  620. sage/rings/rational_field.py +1730 -0
  621. sage/rings/real_double.cpython-314t-aarch64-linux-musl.so +0 -0
  622. sage/rings/real_double.pxd +16 -0
  623. sage/rings/real_double.pyx +2218 -0
  624. sage/rings/real_lazy.cpython-314t-aarch64-linux-musl.so +0 -0
  625. sage/rings/real_lazy.pxd +30 -0
  626. sage/rings/real_lazy.pyx +1773 -0
  627. sage/rings/ring.cpython-314t-aarch64-linux-musl.so +0 -0
  628. sage/rings/ring.pxd +30 -0
  629. sage/rings/ring.pyx +850 -0
  630. sage/rings/semirings/all.py +3 -0
  631. sage/rings/semirings/non_negative_integer_semiring.py +107 -0
  632. sage/rings/semirings/tropical_mpolynomial.py +972 -0
  633. sage/rings/semirings/tropical_polynomial.py +997 -0
  634. sage/rings/semirings/tropical_semiring.cpython-314t-aarch64-linux-musl.so +0 -0
  635. sage/rings/semirings/tropical_semiring.pyx +676 -0
  636. sage/rings/semirings/tropical_variety.py +1701 -0
  637. sage/rings/sum_of_squares.cpython-314t-aarch64-linux-musl.so +0 -0
  638. sage/rings/sum_of_squares.pxd +3 -0
  639. sage/rings/sum_of_squares.pyx +336 -0
  640. sage/rings/tests.py +504 -0
  641. sage/schemes/affine/affine_homset.py +508 -0
  642. sage/schemes/affine/affine_morphism.py +1574 -0
  643. sage/schemes/affine/affine_point.py +460 -0
  644. sage/schemes/affine/affine_rational_point.py +308 -0
  645. sage/schemes/affine/affine_space.py +1264 -0
  646. sage/schemes/affine/affine_subscheme.py +592 -0
  647. sage/schemes/affine/all.py +25 -0
  648. sage/schemes/all__sagemath_categories.py +5 -0
  649. sage/schemes/generic/algebraic_scheme.py +2092 -0
  650. sage/schemes/generic/all.py +5 -0
  651. sage/schemes/generic/ambient_space.py +400 -0
  652. sage/schemes/generic/divisor.py +465 -0
  653. sage/schemes/generic/divisor_group.py +313 -0
  654. sage/schemes/generic/glue.py +84 -0
  655. sage/schemes/generic/homset.py +820 -0
  656. sage/schemes/generic/hypersurface.py +234 -0
  657. sage/schemes/generic/morphism.py +2107 -0
  658. sage/schemes/generic/point.py +237 -0
  659. sage/schemes/generic/scheme.py +1190 -0
  660. sage/schemes/generic/spec.py +199 -0
  661. sage/schemes/product_projective/all.py +6 -0
  662. sage/schemes/product_projective/homset.py +236 -0
  663. sage/schemes/product_projective/morphism.py +517 -0
  664. sage/schemes/product_projective/point.py +568 -0
  665. sage/schemes/product_projective/rational_point.py +550 -0
  666. sage/schemes/product_projective/space.py +1301 -0
  667. sage/schemes/product_projective/subscheme.py +466 -0
  668. sage/schemes/projective/all.py +24 -0
  669. sage/schemes/projective/proj_bdd_height.py +453 -0
  670. sage/schemes/projective/projective_homset.py +718 -0
  671. sage/schemes/projective/projective_morphism.py +2792 -0
  672. sage/schemes/projective/projective_point.py +1484 -0
  673. sage/schemes/projective/projective_rational_point.py +569 -0
  674. sage/schemes/projective/projective_space.py +2571 -0
  675. sage/schemes/projective/projective_subscheme.py +1574 -0
  676. sage/sets/all.py +17 -0
  677. sage/sets/cartesian_product.py +376 -0
  678. sage/sets/condition_set.py +525 -0
  679. sage/sets/disjoint_set.cpython-314t-aarch64-linux-musl.so +0 -0
  680. sage/sets/disjoint_set.pxd +36 -0
  681. sage/sets/disjoint_set.pyx +998 -0
  682. sage/sets/disjoint_union_enumerated_sets.py +625 -0
  683. sage/sets/family.cpython-314t-aarch64-linux-musl.so +0 -0
  684. sage/sets/family.pxd +12 -0
  685. sage/sets/family.pyx +1556 -0
  686. sage/sets/finite_enumerated_set.py +406 -0
  687. sage/sets/finite_set_map_cy.cpython-314t-aarch64-linux-musl.so +0 -0
  688. sage/sets/finite_set_map_cy.pxd +34 -0
  689. sage/sets/finite_set_map_cy.pyx +708 -0
  690. sage/sets/finite_set_maps.py +591 -0
  691. sage/sets/image_set.py +448 -0
  692. sage/sets/integer_range.py +829 -0
  693. sage/sets/non_negative_integers.py +241 -0
  694. sage/sets/positive_integers.py +93 -0
  695. sage/sets/primes.py +188 -0
  696. sage/sets/real_set.py +2760 -0
  697. sage/sets/recursively_enumerated_set.cpython-314t-aarch64-linux-musl.so +0 -0
  698. sage/sets/recursively_enumerated_set.pxd +31 -0
  699. sage/sets/recursively_enumerated_set.pyx +2082 -0
  700. sage/sets/set.py +2083 -0
  701. sage/sets/set_from_iterator.py +1021 -0
  702. sage/sets/totally_ordered_finite_set.py +329 -0
  703. sage/symbolic/all__sagemath_categories.py +1 -0
  704. sage/symbolic/function.cpython-314t-aarch64-linux-musl.so +0 -0
  705. sage/symbolic/function.pxd +29 -0
  706. sage/symbolic/function.pyx +1488 -0
  707. sage/symbolic/symbols.py +56 -0
  708. sage/tests/all__sagemath_categories.py +1 -0
  709. sage/tests/cython.cpython-314t-aarch64-linux-musl.so +0 -0
  710. sage/tests/cython.pyx +37 -0
  711. sage/tests/stl_vector.cpython-314t-aarch64-linux-musl.so +0 -0
  712. sage/tests/stl_vector.pyx +171 -0
  713. sage/typeset/all.py +6 -0
  714. sage/typeset/ascii_art.py +295 -0
  715. sage/typeset/character_art.py +789 -0
  716. sage/typeset/character_art_factory.py +572 -0
  717. sage/typeset/symbols.py +334 -0
  718. sage/typeset/unicode_art.py +183 -0
  719. sage/typeset/unicode_characters.py +101 -0
@@ -0,0 +1,2303 @@
1
+ # sage_setup: distribution = sagemath-categories
2
+ """
3
+ Other functions
4
+
5
+ TESTS:
6
+
7
+ Check that gamma function imports are deprecated (:issue:`24411`)::
8
+
9
+ sage: from sage.functions.other import beta
10
+ sage: beta(x, x) # needs sage.symbolic
11
+ doctest:warning...: DeprecationWarning:
12
+ Importing beta from here is deprecated; please use "from sage.functions.gamma import beta" instead.
13
+ See https://github.com/sagemath/sage/issues/24411 for details.
14
+ beta(x, x)
15
+ """
16
+
17
+ import math
18
+
19
+ from sage.arith.misc import binomial as arith_binomial
20
+ from sage.functions.trig import arctan2
21
+ from sage.misc.functional import sqrt
22
+ from sage.misc.lazy_import import lazy_import
23
+ from sage.rings.integer import Integer
24
+ from sage.rings.integer_ring import ZZ
25
+ from sage.rings.rational import Rational
26
+ from sage.structure.element import coercion_model, Element, Expression
27
+ # avoid name conflicts with `parent` as a function parameter
28
+ from sage.structure.element import parent as s_parent
29
+ from sage.symbolic.function import GinacFunction, BuiltinFunction
30
+ from sage.symbolic.symbols import register_symbol, symbol_table
31
+
32
+ lazy_import('sage.misc.latex', 'latex')
33
+ lazy_import('sage.rings.complex_mpfr', 'ComplexField')
34
+
35
+ lazy_import('sage.symbolic.ring', 'SR')
36
+
37
+
38
+ lazy_import('sage.functions.gamma',
39
+ ('gamma', 'log_gamma', 'gamma_inc',
40
+ 'gamma_inc_lower', 'psi', 'beta'), deprecation=24411)
41
+
42
+
43
+ class Function_abs(GinacFunction):
44
+ def __init__(self):
45
+ r"""
46
+ The absolute value function.
47
+
48
+ EXAMPLES::
49
+
50
+ sage: abs(-2)
51
+ 2
52
+
53
+ sage: # needs sage.symbolic
54
+ sage: var('x y')
55
+ (x, y)
56
+ sage: abs(x)
57
+ abs(x)
58
+ sage: abs(x^2 + y^2)
59
+ abs(x^2 + y^2)
60
+ sage: sqrt(x^2)
61
+ sqrt(x^2)
62
+ sage: abs(sqrt(x))
63
+ sqrt(abs(x))
64
+ sage: complex(abs(3*I))
65
+ (3+0j)
66
+
67
+ sage: f = sage.functions.other.Function_abs()
68
+ sage: latex(f)
69
+ \mathrm{abs}
70
+ sage: latex(abs(x)) # needs sage.symbolic
71
+ {\left| x \right|}
72
+ sage: abs(x)._sympy_() # needs sympy sage.symbolic
73
+ Abs(x)
74
+
75
+ Test pickling::
76
+
77
+ sage: loads(dumps(abs(x))) # needs sage.symbolic
78
+ abs(x)
79
+
80
+ TESTS:
81
+
82
+ Check that :issue:`12588` is fixed::
83
+
84
+ sage: # needs sage.symbolic
85
+ sage: abs(pi*I)
86
+ pi
87
+ sage: abs(pi*I*catalan)
88
+ catalan*pi
89
+ sage: abs(pi*catalan*x)
90
+ catalan*pi*abs(x)
91
+ sage: abs(pi*I*catalan*x)
92
+ catalan*pi*abs(x)
93
+ sage: abs(1.0j*pi)
94
+ 1.00000000000000*pi
95
+ sage: abs(I*x)
96
+ abs(x)
97
+ sage: abs(I*pi)
98
+ pi
99
+ sage: abs(I*log(2))
100
+ log(2)
101
+ sage: abs(I*e^5)
102
+ e^5
103
+ sage: abs(log(1/2))
104
+ -log(1/2)
105
+ sage: abs(log(3/2))
106
+ log(3/2)
107
+ sage: abs(log(1/2)*log(1/3))
108
+ log(1/2)*log(1/3)
109
+ sage: abs(log(1/2)*log(1/3)*log(1/4))
110
+ -log(1/2)*log(1/3)*log(1/4)
111
+ sage: abs(log(1/2)*log(1/3)*log(1/4)*i)
112
+ -log(1/2)*log(1/3)*log(1/4)
113
+ sage: abs(log(x))
114
+ abs(log(x))
115
+ sage: abs(zeta(I))
116
+ abs(zeta(I))
117
+ sage: abs(e^2*x)
118
+ abs(x)*e^2
119
+ sage: abs((pi+e)*x)
120
+ (pi + e)*abs(x)
121
+
122
+ sage: fricas(abs(x)).sage().derivative() # optional - fricas # needs sage.symbolic
123
+ 1/2*(x + conjugate(x))/abs(x)
124
+ """
125
+ GinacFunction.__init__(self, "abs", latex_name=r"\mathrm{abs}",
126
+ conversions=dict(sympy='Abs',
127
+ mathematica='Abs',
128
+ giac='abs',
129
+ fricas='abs'))
130
+
131
+
132
+ abs = abs_symbolic = Function_abs()
133
+
134
+
135
+ def _eval_floor_ceil(self, x, method, bits=0, **kwds):
136
+ """
137
+ Helper function to compute ``floor(x)`` or ``ceil(x)``.
138
+
139
+ INPUT:
140
+
141
+ - ``x`` -- a number
142
+
143
+ - ``method`` -- should be either ``'floor'`` or ``'ceil'``
144
+
145
+ - ``bits`` -- how many bits to use before giving up
146
+
147
+ See :class:`Function_floor` and :class:`Function_ceil` for examples
148
+ and tests.
149
+
150
+ TESTS::
151
+
152
+ sage: numbers = [SR(10^100 + exp(-100)), SR(10^100 - exp(-100)), SR(10^100)] # needs sage.symbolic
153
+ sage: numbers += [-n for n in numbers] # needs sage.symbolic
154
+ sage: for n in numbers: # needs sage.symbolic
155
+ ....: f = floor(n)
156
+ ....: c = ceil(n)
157
+ ....: if f == c:
158
+ ....: assert n in ZZ
159
+ ....: else:
160
+ ....: assert f + 1 == c
161
+
162
+ A test from :issue:`12121`::
163
+
164
+ sage: # needs sage.symbolic
165
+ sage: e1 = pi - continued_fraction(pi).convergent(2785)
166
+ sage: e2 = e - continued_fraction(e).convergent(1500)
167
+ sage: f = e1/e2
168
+ sage: f = 1 / (f - continued_fraction(f).convergent(1000))
169
+ sage: f = f - continued_fraction(f).convergent(1)
170
+ sage: floor(f, bits=10000)
171
+ -1
172
+ sage: ceil(f, bits=10000)
173
+ 0
174
+
175
+ These do not work but fail gracefully::
176
+
177
+ sage: ceil(Infinity) # needs sage.rings.real_interval_field
178
+ Traceback (most recent call last):
179
+ ...
180
+ ValueError: Calling ceil() on infinity or NaN
181
+ sage: ceil(NaN) # needs sage.symbolic
182
+ Traceback (most recent call last):
183
+ ...
184
+ ValueError: Calling ceil() on infinity or NaN
185
+
186
+ Test that elements of symbolic subrings work in the same way as
187
+ elements of ``SR``, :issue:`32724`::
188
+
189
+ sage: SCR = SR.subring(no_variables=True) # needs sage.symbolic
190
+ sage: floor(log(2^(3/2)) / log(2) + 1/2) # needs sage.symbolic
191
+ 2
192
+ sage: floor(SCR(log(2^(-3/2)) / log(2) + 1/2)) # needs sage.symbolic
193
+ -1
194
+ """
195
+ # First, some obvious things...
196
+ try:
197
+ m = getattr(x, method)
198
+ except AttributeError:
199
+ pass
200
+ else:
201
+ return m()
202
+
203
+ if isinstance(x, int):
204
+ return Integer(x)
205
+ if isinstance(x, (float, complex)):
206
+ m = getattr(math, method)
207
+ return Integer(m(x))
208
+ if type(x).__module__ == 'numpy':
209
+ import numpy
210
+ m = getattr(numpy, method)
211
+ return m(x)
212
+
213
+ # The strategy is to convert the number to an interval field and
214
+ # hope that this interval will have a unique floor/ceiling.
215
+ #
216
+ # There are 2 reasons why this could fail:
217
+ # (A) The expression is very complicated and we simply require
218
+ # more bits.
219
+ # (B) The expression is a non-obvious exact integer. In this
220
+ # case, adding bits will not help since an interval around
221
+ # an integer will not have a unique floor/ceiling, no matter
222
+ # how many bits are used.
223
+ #
224
+ # The strategy is to first reduce the absolute diameter of the
225
+ # interval until its size is at most 10^(-6). Then we check for
226
+ # (B) by simplifying the expression.
227
+ from sage.rings.real_mpfi import RealIntervalField
228
+
229
+ # Might it be needed to simplify x? This only applies for
230
+ # elements of SR (or its subrings)
231
+ need_to_simplify = isinstance(x, Expression)
232
+
233
+ # An integer which is close to x. We use this to increase precision
234
+ # by subtracting this guess before converting to an interval field.
235
+ # This mostly helps with the case that x is close to, but not equal
236
+ # to, an exact integer.
237
+ guess = Integer(0)
238
+
239
+ # We do not use the target number of bits immediately, we just use
240
+ # it as indication of when to stop.
241
+ target_bits = bits
242
+ bits = 32
243
+ attempts = 5
244
+ while attempts:
245
+ attempts -= 1
246
+ if not attempts and bits < target_bits:
247
+ # Add one more attempt as long as the precision is less
248
+ # than requested
249
+ attempts = 1
250
+
251
+ RIF = RealIntervalField(bits)
252
+ if guess:
253
+ y = x - guess
254
+ else:
255
+ y = x
256
+ try:
257
+ y_interval = RIF(y)
258
+ except TypeError:
259
+ # If we cannot compute a numerical enclosure, leave the
260
+ # expression unevaluated.
261
+ return BuiltinFunction.__call__(self, SR(x))
262
+ diam = y_interval.absolute_diameter()
263
+ if diam.is_infinity():
264
+ # We have a very bad approximation => increase the number
265
+ # of bits a lot
266
+ bits *= 4
267
+ continue
268
+ fdiam = float(diam)
269
+ if fdiam >= 1.0:
270
+ # Increase number of bits to get to a diameter less than
271
+ # 2^(-32), assuming that the diameter scales as 2^(-bits)
272
+ bits += 32 + int(diam.log2())
273
+ continue
274
+
275
+ # Compute ceil/floor of both ends of the interval:
276
+ # if these match, we are done!
277
+ a = getattr(y_interval.lower(), method)()
278
+ b = getattr(y_interval.upper(), method)()
279
+ if a == b:
280
+ return a + guess
281
+
282
+ # Compute a better guess for the next attempt. Since diam < 1,
283
+ # there is a unique integer in our interval. This integer equals
284
+ # the ceil of the lower bound and the floor of the upper bound.
285
+ if self is floor:
286
+ guess += b
287
+ else:
288
+ assert self is ceil
289
+ guess += a
290
+
291
+ if need_to_simplify and fdiam <= 1e-6:
292
+ x = x.full_simplify().canonicalize_radical()
293
+ need_to_simplify = False
294
+ continue
295
+
296
+ bits *= 2
297
+
298
+ raise ValueError("cannot compute {}({!r}) using {} bits of precision".format(method, x, RIF.precision()))
299
+
300
+
301
+ class Function_ceil(BuiltinFunction):
302
+ def __init__(self):
303
+ r"""
304
+ The ceiling function.
305
+
306
+ The ceiling of `x` is computed in the following manner.
307
+
308
+
309
+ #. The ``x.ceil()`` method is called and returned if it
310
+ is there. If it is not, then Sage checks if `x` is one of
311
+ Python's native numeric data types. If so, then it calls and
312
+ returns ``Integer(math.ceil(x))``.
313
+
314
+ #. Sage tries to convert `x` into a
315
+ ``RealIntervalField`` with 53 bits of precision. Next,
316
+ the ceilings of the endpoints are computed. If they are the same,
317
+ then that value is returned. Otherwise, the precision of the
318
+ ``RealIntervalField`` is increased until they do match
319
+ up or it reaches ``bits`` of precision.
320
+
321
+ #. If none of the above work, Sage returns a
322
+ ``Expression`` object.
323
+
324
+ EXAMPLES::
325
+
326
+ sage: # needs sage.symbolic
327
+ sage: a = ceil(2/5 + x); a
328
+ ceil(x + 2/5)
329
+ sage: a(x=4)
330
+ 5
331
+ sage: a(x=4.0)
332
+ 5
333
+ sage: ZZ(a(x=3))
334
+ 4
335
+ sage: a = ceil(x^3 + x + 5/2); a
336
+ ceil(x^3 + x + 5/2)
337
+ sage: a.simplify()
338
+ ceil(x^3 + x + 1/2) + 2
339
+ sage: a(x=2)
340
+ 13
341
+
342
+ ::
343
+
344
+ sage: ceil(sin(8)/sin(2)) # needs sage.symbolic
345
+ 2
346
+
347
+ ::
348
+
349
+ sage: ceil(5.4)
350
+ 6
351
+ sage: type(ceil(5.4))
352
+ <class 'sage.rings.integer.Integer'>
353
+
354
+ ::
355
+
356
+ sage: ceil(factorial(50)/exp(1)) # needs sage.symbolic
357
+ 11188719610782480504630258070757734324011354208865721592720336801
358
+ sage: ceil(SR(10^50 + 10^(-50))) # needs sage.symbolic
359
+ 100000000000000000000000000000000000000000000000001
360
+ sage: ceil(SR(10^50 - 10^(-50))) # needs sage.symbolic
361
+ 100000000000000000000000000000000000000000000000000
362
+
363
+ Small numbers which are extremely close to an integer are hard to
364
+ deal with::
365
+
366
+ sage: ceil((33^100 + 1)^(1/100)) # needs sage.symbolic
367
+ Traceback (most recent call last):
368
+ ...
369
+ ValueError: cannot compute ceil(...) using 256 bits of precision
370
+
371
+ This can be fixed by giving a sufficiently large ``bits`` argument::
372
+
373
+ sage: ceil((33^100 + 1)^(1/100), bits=500) # needs sage.symbolic
374
+ Traceback (most recent call last):
375
+ ...
376
+ ValueError: cannot compute ceil(...) using 512 bits of precision
377
+ sage: ceil((33^100 + 1)^(1/100), bits=1000) # needs sage.symbolic
378
+ 34
379
+
380
+ ::
381
+
382
+ sage: ceil(sec(e)) # needs sage.symbolic
383
+ -1
384
+
385
+ sage: latex(ceil(x)) # needs sage.symbolic
386
+ \left \lceil x \right \rceil
387
+ sage: ceil(x)._sympy_() # needs sympy sage.symbolic
388
+ ceiling(x)
389
+
390
+ ::
391
+
392
+ sage: import numpy # needs numpy
393
+ sage: a = numpy.linspace(0,2,6) # needs numpy
394
+ sage: ceil(a) # needs numpy
395
+ array([0., 1., 1., 2., 2., 2.])
396
+
397
+ Test pickling::
398
+
399
+ sage: loads(dumps(ceil))
400
+ ceil
401
+ """
402
+ BuiltinFunction.__init__(self, "ceil",
403
+ conversions=dict(maxima='ceiling',
404
+ sympy='ceiling',
405
+ giac='ceil'))
406
+
407
+ def _print_latex_(self, x):
408
+ r"""
409
+ EXAMPLES::
410
+
411
+ sage: latex(ceil(x)) # indirect doctest # needs sage.symbolic
412
+ \left \lceil x \right \rceil
413
+ """
414
+ return r"\left \lceil %s \right \rceil" % latex(x)
415
+
416
+ #FIXME: this should be moved to _eval_
417
+ def __call__(self, x, **kwds):
418
+ """
419
+ Allow an object of this class to behave like a function. If
420
+ ``ceil`` is an instance of this class, we can do ``ceil(n)`` to get
421
+ the ceiling of ``n``.
422
+
423
+ TESTS::
424
+
425
+ sage: ceil(SR(10^50 + 10^(-50))) # needs sage.symbolic
426
+ 100000000000000000000000000000000000000000000000001
427
+ sage: ceil(SR(10^50 - 10^(-50))) # needs sage.symbolic
428
+ 100000000000000000000000000000000000000000000000000
429
+ sage: ceil(int(10^50))
430
+ 100000000000000000000000000000000000000000000000000
431
+ sage: ceil((1725033*pi - 5419351)/(25510582*pi - 80143857)) # needs sage.symbolic
432
+ -2
433
+ """
434
+ return _eval_floor_ceil(self, x, "ceil", **kwds)
435
+
436
+ def _eval_(self, x):
437
+ """
438
+ EXAMPLES::
439
+
440
+ sage: ceil(x).subs(x==7.5) # needs sage.symbolic
441
+ 8
442
+ sage: ceil(x) # needs sage.symbolic
443
+ ceil(x)
444
+
445
+ sage: # needs sage.symbolic
446
+ sage: var('x', domain='integer')
447
+ x
448
+ sage: ceil(x)
449
+ x
450
+ sage: ceil(factorial(x) + binomial(x^2, x))
451
+ binomial(x^2, x) + factorial(x)
452
+ sage: ceil(gamma(abs(2*x)+1) * real(x))
453
+ x*gamma(2*abs(x) + 1)
454
+ sage: forget()
455
+ """
456
+ try:
457
+ if SR(x).variables() and x.is_integer():
458
+ return x
459
+ except TypeError:
460
+ pass
461
+ try:
462
+ return x.ceil()
463
+ except AttributeError:
464
+ if isinstance(x, int):
465
+ return Integer(x)
466
+ elif isinstance(x, (float, complex)):
467
+ return Integer(math.ceil(x))
468
+ return None
469
+
470
+
471
+ ceil = Function_ceil()
472
+
473
+
474
+ class Function_floor(BuiltinFunction):
475
+ def __init__(self):
476
+ r"""
477
+ The floor function.
478
+
479
+ The floor of `x` is computed in the following manner.
480
+
481
+
482
+ #. The ``x.floor()`` method is called and returned if
483
+ it is there. If it is not, then Sage checks if `x` is one
484
+ of Python's native numeric data types. If so, then it calls and
485
+ returns ``Integer(math.floor(x))``.
486
+
487
+ #. Sage tries to convert `x` into a
488
+ ``RealIntervalField`` with 53 bits of precision. Next,
489
+ the floors of the endpoints are computed. If they are the same,
490
+ then that value is returned. Otherwise, the precision of the
491
+ ``RealIntervalField`` is increased until they do match
492
+ up or it reaches ``bits`` of precision.
493
+
494
+ #. If none of the above work, Sage returns a
495
+ symbolic ``Expression`` object.
496
+
497
+ EXAMPLES::
498
+
499
+ sage: floor(5.4)
500
+ 5
501
+ sage: type(floor(5.4))
502
+ <class 'sage.rings.integer.Integer'>
503
+
504
+ sage: # needs sage.symbolic
505
+ sage: var('x')
506
+ x
507
+ sage: a = floor(5.25 + x); a
508
+ floor(x + 5.25000000000000)
509
+ sage: a.simplify()
510
+ floor(x + 0.25) + 5
511
+ sage: a(x=2)
512
+ 7
513
+
514
+ ::
515
+
516
+ sage: # needs sage.symbolic
517
+ sage: floor(cos(8) / cos(2))
518
+ 0
519
+ sage: floor(log(4) / log(2))
520
+ 2
521
+ sage: a = floor(5.4 + x); a
522
+ floor(x + 5.40000000000000)
523
+ sage: a.subs(x==2)
524
+ 7
525
+ sage: floor(log(2^(3/2)) / log(2) + 1/2)
526
+ 2
527
+ sage: floor(log(2^(-3/2)) / log(2) + 1/2)
528
+ -1
529
+
530
+ ::
531
+
532
+ sage: floor(factorial(50)/exp(1)) # needs sage.symbolic
533
+ 11188719610782480504630258070757734324011354208865721592720336800
534
+ sage: floor(SR(10^50 + 10^(-50))) # needs sage.symbolic
535
+ 100000000000000000000000000000000000000000000000000
536
+ sage: floor(SR(10^50 - 10^(-50))) # needs sage.symbolic
537
+ 99999999999999999999999999999999999999999999999999
538
+ sage: floor(int(10^50))
539
+ 100000000000000000000000000000000000000000000000000
540
+
541
+ Small numbers which are extremely close to an integer are hard to
542
+ deal with::
543
+
544
+ sage: floor((33^100 + 1)^(1/100)) # needs sage.symbolic
545
+ Traceback (most recent call last):
546
+ ...
547
+ ValueError: cannot compute floor(...) using 256 bits of precision
548
+
549
+ This can be fixed by giving a sufficiently large ``bits`` argument::
550
+
551
+ sage: floor((33^100 + 1)^(1/100), bits=500) # needs sage.symbolic
552
+ Traceback (most recent call last):
553
+ ...
554
+ ValueError: cannot compute floor(...) using 512 bits of precision
555
+ sage: floor((33^100 + 1)^(1/100), bits=1000) # needs sage.symbolic
556
+ 33
557
+
558
+ ::
559
+
560
+ sage: import numpy # needs numpy
561
+ sage: a = numpy.linspace(0,2,6) # needs numpy
562
+ sage: floor(a) # needs numpy
563
+ array([0., 0., 0., 1., 1., 2.])
564
+ sage: floor(x)._sympy_() # needs sympy sage.symbolic
565
+ floor(x)
566
+
567
+ Test pickling::
568
+
569
+ sage: loads(dumps(floor))
570
+ floor
571
+ """
572
+ BuiltinFunction.__init__(self, "floor",
573
+ conversions=dict(sympy='floor', giac='floor'))
574
+
575
+ def _print_latex_(self, x):
576
+ r"""
577
+ EXAMPLES::
578
+
579
+ sage: latex(floor(x)) # needs sage.symbolic
580
+ \left \lfloor x \right \rfloor
581
+ """
582
+ return r"\left \lfloor %s \right \rfloor" % latex(x)
583
+
584
+ #FIXME: this should be moved to _eval_
585
+ def __call__(self, x, **kwds):
586
+ """
587
+ Allow an object of this class to behave like a function. If
588
+ ``floor`` is an instance of this class, we can do ``floor(n)`` to
589
+ obtain the floor of ``n``.
590
+
591
+ TESTS::
592
+
593
+ sage: floor(SR(10^50 + 10^(-50))) # needs sage.symbolic
594
+ 100000000000000000000000000000000000000000000000000
595
+ sage: floor(SR(10^50 - 10^(-50))) # needs sage.symbolic
596
+ 99999999999999999999999999999999999999999999999999
597
+ sage: floor(int(10^50))
598
+ 100000000000000000000000000000000000000000000000000
599
+ sage: floor((1725033*pi - 5419351)/(25510582*pi - 80143857)) # needs sage.symbolic
600
+ -3
601
+ """
602
+ return _eval_floor_ceil(self, x, "floor", **kwds)
603
+
604
+ def _eval_(self, x):
605
+ """
606
+ EXAMPLES::
607
+
608
+ sage: floor(x).subs(x==7.5) # needs sage.symbolic
609
+ 7
610
+ sage: floor(x) # needs sage.symbolic
611
+ floor(x)
612
+
613
+ sage: # needs sage.symbolic
614
+ sage: var('x', domain='integer')
615
+ x
616
+ sage: floor(x)
617
+ x
618
+ sage: floor(factorial(x) + binomial(x^2, x))
619
+ binomial(x^2, x) + factorial(x)
620
+ sage: floor(gamma(abs(2*x)+1) * real(x))
621
+ x*gamma(2*abs(x) + 1)
622
+ sage: forget()
623
+ """
624
+ try:
625
+ if SR(x).variables() and x.is_integer():
626
+ return x
627
+ except TypeError:
628
+ pass
629
+ try:
630
+ return x.floor()
631
+ except AttributeError:
632
+ if isinstance(x, int):
633
+ return Integer(x)
634
+ elif isinstance(x, (float, complex)):
635
+ return Integer(math.floor(x))
636
+ return None
637
+
638
+
639
+ floor = Function_floor()
640
+
641
+
642
+ class Function_Order(GinacFunction):
643
+ def __init__(self):
644
+ r"""
645
+ The order function.
646
+
647
+ This function gives the order of magnitude of some expression,
648
+ similar to `O`-terms.
649
+
650
+ .. SEEALSO::
651
+
652
+ :meth:`~sage.symbolic.expression.Expression.Order`,
653
+ :mod:`~sage.rings.big_oh`
654
+
655
+ EXAMPLES::
656
+
657
+ sage: x = SR('x') # needs sage.symbolic
658
+ sage: x.Order() # needs sage.symbolic
659
+ Order(x)
660
+ sage: (x^2 + x).Order() # needs sage.symbolic
661
+ Order(x^2 + x)
662
+
663
+ TESTS:
664
+
665
+ Check that :issue:`19425` is resolved::
666
+
667
+ sage: x.Order().operator() # needs sage.symbolic
668
+ Order
669
+ """
670
+ GinacFunction.__init__(self, "Order",
671
+ conversions=dict(),
672
+ latex_name=r"\mathcal{O}")
673
+
674
+ def _sympy_(self, arg):
675
+ """
676
+ EXAMPLES::
677
+
678
+ sage: # needs sympy sage.symbolic
679
+ sage: x.Order()._sympy_()
680
+ O(x)
681
+ sage: SR(1).Order()._sympy_()
682
+ O(1)
683
+ sage: ((x-1)^3).Order()._sympy_()
684
+ O((x - 1)**3, (x, 1))
685
+ sage: exp(x).series(x==1, 3)._sympy_()
686
+ E + E*(x - 1) + E*(x - 1)**2/2 + O((x - 1)**3, (x, 1))
687
+
688
+ sage: (-(pi-x)^3).Order()._sympy_() # needs sympy sage.symbolic
689
+ O((x - pi)**3, (x, pi))
690
+ sage: cos(x).series(x==pi, 3)._sympy_() # needs sympy sage.symbolic
691
+ -1 + (pi - x)**2/2 + O((x - pi)**3, (x, pi))
692
+ """
693
+ roots = arg.solve(arg.default_variable(), algorithm='sympy',
694
+ multiplicities=False, explicit_solutions=True)
695
+ if len(roots) == 1:
696
+ arg = (arg, (roots[0].lhs(), roots[0].rhs()))
697
+ elif len(roots) > 1:
698
+ raise ValueError("order term %s has multiple roots" % arg)
699
+ # else there are no roots, e.g. O(1), so we leave arg unchanged
700
+ import sympy
701
+ return sympy.O(*sympy.sympify(arg, evaluate=False))
702
+
703
+
704
+ Order = Function_Order()
705
+
706
+
707
+ class Function_frac(BuiltinFunction):
708
+ def __init__(self):
709
+ r"""
710
+ The fractional part function `\{x\}`.
711
+
712
+ ``frac(x)`` is defined as `\{x\} = x - \lfloor x\rfloor`.
713
+
714
+ EXAMPLES::
715
+
716
+ sage: frac(5.4) # needs sage.rings.real_mpfr
717
+ 0.400000000000000
718
+ sage: type(frac(5.4)) # needs sage.rings.real_mpfr
719
+ <class 'sage.rings.real_mpfr.RealNumber'>
720
+ sage: frac(456/123)
721
+ 29/41
722
+
723
+ sage: # needs sage.symbolic
724
+ sage: var('x')
725
+ x
726
+ sage: a = frac(5.4 + x); a
727
+ frac(x + 5.40000000000000)
728
+ sage: frac(cos(8)/cos(2))
729
+ cos(8)/cos(2)
730
+ sage: latex(frac(x))
731
+ \operatorname{frac}\left(x\right)
732
+ sage: frac(x)._sympy_() # needs sympy
733
+ frac(x)
734
+
735
+ Test pickling::
736
+
737
+ sage: loads(dumps(floor))
738
+ floor
739
+ """
740
+ BuiltinFunction.__init__(self, "frac",
741
+ conversions=dict(sympy='frac'),
742
+ latex_name=r"\operatorname{frac}")
743
+
744
+ def _evalf_(self, x, **kwds):
745
+ """
746
+ EXAMPLES::
747
+
748
+ sage: frac(pi).n() # needs sage.symbolic
749
+ 0.141592653589793
750
+ sage: frac(pi).n(200) # needs sage.symbolic
751
+ 0.14159265358979323846264338327950288419716939937510582097494
752
+ """
753
+ return x - floor(x)
754
+
755
+ def _eval_(self, x):
756
+ """
757
+ EXAMPLES::
758
+
759
+ sage: frac(x).subs(x==7.5) # needs sage.symbolic
760
+ 0.500000000000000
761
+ sage: frac(x) # needs sage.symbolic
762
+ frac(x)
763
+ """
764
+ try:
765
+ return x - x.floor()
766
+ except AttributeError:
767
+ if isinstance(x, int):
768
+ return Integer(0)
769
+ elif isinstance(x, (float, complex)):
770
+ return x - Integer(math.floor(x))
771
+ elif isinstance(x, Expression):
772
+ ret = floor(x)
773
+ if not hasattr(ret, "operator") or not ret.operator() == floor:
774
+ return x - ret
775
+ return None
776
+
777
+
778
+ frac = Function_frac()
779
+
780
+
781
+ # register sqrt in pynac symbol_table for conversion back from other systems
782
+ register_symbol(sqrt, dict(mathematica='Sqrt'), 2)
783
+ symbol_table['functions']['sqrt'] = sqrt
784
+
785
+ Function_sqrt = type('deprecated_sqrt', (),
786
+ {'__call__': staticmethod(sqrt),
787
+ '__setstate__': lambda x, y: None})
788
+
789
+
790
+ class Function_real_nth_root(BuiltinFunction):
791
+ r"""
792
+ Real `n`-th root function `x^\frac{1}{n}`.
793
+
794
+ The function assumes positive integer `n` and real number `x`.
795
+
796
+ EXAMPLES::
797
+
798
+ sage: real_nth_root(2, 3) # needs sage.symbolic
799
+ 2^(1/3)
800
+ sage: real_nth_root(-2, 3) # needs sage.symbolic
801
+ -2^(1/3)
802
+ sage: real_nth_root(8, 3)
803
+ 2
804
+ sage: real_nth_root(-8, 3)
805
+ -2
806
+
807
+ sage: real_nth_root(-2, 4)
808
+ Traceback (most recent call last):
809
+ ...
810
+ ValueError: no real nth root of negative real number with even n
811
+
812
+ For numeric input, it gives a numerical approximation. ::
813
+
814
+ sage: real_nth_root(2., 3) # needs sage.rings.real_mpfr
815
+ 1.25992104989487
816
+ sage: real_nth_root(-2., 3) # needs sage.rings.real_mpfr
817
+ -1.25992104989487
818
+
819
+ Some symbolic calculus::
820
+
821
+ sage: # needs sage.symbolic
822
+ sage: f = real_nth_root(x, 5)^3; f
823
+ real_nth_root(x^3, 5)
824
+ sage: f.diff()
825
+ 3/5*x^2*real_nth_root(x^(-12), 5)
826
+ sage: result = f.integrate(x)
827
+ ...
828
+ sage: result
829
+ integrate((abs(x)^3)^(1/5)*sgn(x^3), x)
830
+ sage: _.diff()
831
+ (abs(x)^3)^(1/5)*sgn(x^3)
832
+ """
833
+ def __init__(self):
834
+ r"""
835
+ Initialize.
836
+
837
+ TESTS::
838
+
839
+ sage: cube_root = real_nth_root(x, 3) # needs sage.symbolic
840
+ sage: loads(dumps(cube_root)) # needs sage.symbolic
841
+ real_nth_root(x, 3)
842
+
843
+ ::
844
+
845
+ sage: f = real_nth_root(x, 3) # needs sage.symbolic
846
+ sage: f._sympy_() # needs sympy sage.symbolic
847
+ Piecewise((Abs(x)**(1/3)*sign(x), Eq(im(x), 0)), (x**(1/3), True))
848
+ """
849
+ BuiltinFunction.__init__(self, "real_nth_root", nargs=2,
850
+ conversions=dict(sympy='real_root',
851
+ mathematica='Surd',
852
+ maple='surd'))
853
+
854
+ def _print_latex_(self, base, exp):
855
+ r"""
856
+ TESTS::
857
+
858
+ sage: latex(real_nth_root(x, 3)) # needs sage.symbolic
859
+ x^{\frac{1}{3}}
860
+ sage: latex(real_nth_root(x^2 + x, 3)) # needs sage.symbolic
861
+ {\left(x^{2} + x\right)}^{\frac{1}{3}}
862
+ """
863
+ return latex(base**(1/exp))
864
+
865
+ def _evalf_(self, base, exp, parent=None):
866
+ """
867
+ TESTS::
868
+
869
+ sage: real_nth_root(RDF(-2), 3)
870
+ -1.25992104989487...
871
+ sage: real_nth_root(Reals(100)(2), 2) # needs sage.rings.real_mpfr
872
+ 1.4142135623730950488016887242
873
+ """
874
+ if hasattr(exp, 'real_part'):
875
+ # To allow complex "noise" while plotting, the fast_callable()
876
+ # interpreters used in plots will convert all intermediate
877
+ # expressions to CDF, returning only the final answer as a
878
+ # real number. However, for a symbolic function such as this,
879
+ # the "exp" argument is in fact an intermediate expression.
880
+ # Thus we are forced to deal with exponents of the form
881
+ # (n + 0*I), which a priori will throw a TypeError at the "%"
882
+ # below. Here we special-case only CDF and CC, leaving the
883
+ # python "complex" type unhandled: you have to try very hard
884
+ # to pass a python "complex" in as an exponent, and the extra
885
+ # effort/slowdown doesn't seem worth it.
886
+ if exp.imag_part().is_zero():
887
+ exp = exp.real_part()
888
+ else:
889
+ raise ValueError("exponent cannot be complex")
890
+ exp = ZZ(exp)
891
+
892
+ negative = base < 0
893
+
894
+ if negative:
895
+ if exp.mod(2) == 0:
896
+ raise ValueError('no real nth root of negative real number with even n')
897
+ base = -base
898
+
899
+ r = base**(1/exp)
900
+
901
+ if negative:
902
+ return -r
903
+ else:
904
+ return r
905
+
906
+ def _eval_(self, base, exp):
907
+ """
908
+ TESTS::
909
+
910
+ sage: real_nth_root(x, 1) # needs sage.symbolic
911
+ x
912
+ sage: real_nth_root(x, 3) # needs sage.symbolic
913
+ real_nth_root(x, 3)
914
+
915
+ sage: real_nth_root(RIF(2), 3) # needs sage.rings.real_interval_field
916
+ 1.259921049894873?
917
+ sage: real_nth_root(RBF(2), 3) # needs sage.libs.flint
918
+ [1.259921049894873 +/- 3.92e-16]
919
+ """
920
+ if not isinstance(base, Expression) and not isinstance(exp, Expression):
921
+ if isinstance(base, Integer):
922
+ try:
923
+ return base.nth_root(exp)
924
+ except ValueError:
925
+ pass
926
+ return self._evalf_(base, exp, parent=s_parent(base))
927
+
928
+ if isinstance(exp, Integer) and exp.is_one():
929
+ return base
930
+
931
+ def _power_(self, base, exp, power_param=None):
932
+ """
933
+ TESTS::
934
+
935
+ sage: f = real_nth_root(x, 3) # needs sage.symbolic
936
+ sage: f^5 # needs sage.symbolic
937
+ real_nth_root(x^5, 3)
938
+ """
939
+ return self(base**power_param, exp)
940
+
941
+ def _derivative_(self, base, exp, diff_param=None):
942
+ """
943
+ TESTS::
944
+
945
+ sage: # needs sage.symbolic
946
+ sage: f = real_nth_root(x, 3)
947
+ sage: f.diff()
948
+ 1/3*real_nth_root(x^(-2), 3)
949
+ sage: f = real_nth_root(-x, 3)
950
+ sage: f.diff()
951
+ -1/3*real_nth_root(x^(-2), 3)
952
+ sage: f = real_nth_root(x, 4)
953
+ sage: f.diff()
954
+ 1/4*real_nth_root(x^(-3), 4)
955
+ sage: f = real_nth_root(-x, 4)
956
+ sage: f.diff()
957
+ -1/4*real_nth_root(-1/x^3, 4)
958
+ """
959
+ return 1/exp * self(base, exp)**(1-exp)
960
+
961
+
962
+ real_nth_root = Function_real_nth_root()
963
+
964
+
965
+ class Function_arg(BuiltinFunction):
966
+ def __init__(self):
967
+ r"""
968
+ The argument function for complex numbers.
969
+
970
+ EXAMPLES::
971
+
972
+ sage: # needs sage.symbolic
973
+ sage: arg(3+i)
974
+ arctan(1/3)
975
+ sage: arg(-1+i)
976
+ 3/4*pi
977
+ sage: arg(2+2*i)
978
+ 1/4*pi
979
+ sage: arg(2+x)
980
+ arg(x + 2)
981
+ sage: arg(2.0+i+x)
982
+ arg(x + 2.00000000000000 + 1.00000000000000*I)
983
+ sage: arg(-3)
984
+ pi
985
+ sage: arg(3)
986
+ 0
987
+ sage: arg(0)
988
+ 0
989
+
990
+ sage: # needs sage.symbolic
991
+ sage: latex(arg(x))
992
+ {\rm arg}\left(x\right)
993
+ sage: maxima(arg(x))
994
+ atan2(0,_SAGE_VAR_x)
995
+ sage: maxima(arg(2+i))
996
+ atan(1/2)
997
+ sage: maxima(arg(sqrt(2)+i))
998
+ atan(1/sqrt(2))
999
+ sage: arg(x)._sympy_() # needs sympy
1000
+ arg(x)
1001
+
1002
+ sage: arg(2+i) # needs sage.symbolic
1003
+ arctan(1/2)
1004
+ sage: arg(sqrt(2)+i) # needs sage.symbolic
1005
+ arg(sqrt(2) + I)
1006
+ sage: arg(sqrt(2)+i).simplify() # needs sage.symbolic
1007
+ arctan(1/2*sqrt(2))
1008
+
1009
+ TESTS::
1010
+
1011
+ sage: arg(0.0) # needs sage.rings.complex_double
1012
+ 0.000000000000000
1013
+ sage: arg(3.0) # needs sage.rings.complex_double
1014
+ 0.000000000000000
1015
+ sage: arg(-2.5) # needs sage.rings.complex_double
1016
+ 3.14159265358979
1017
+ sage: arg(2.0+3*i) # needs sage.symbolic
1018
+ 0.982793723247329
1019
+ """
1020
+ BuiltinFunction.__init__(self, "arg",
1021
+ conversions=dict(maxima='carg',
1022
+ mathematica='Arg',
1023
+ sympy='arg',
1024
+ giac='arg'))
1025
+
1026
+ def _eval_(self, x):
1027
+ """
1028
+ EXAMPLES::
1029
+
1030
+ sage: # needs sage.symbolic
1031
+ sage: arg(3+i)
1032
+ arctan(1/3)
1033
+ sage: arg(-1+i)
1034
+ 3/4*pi
1035
+ sage: arg(2+2*i)
1036
+ 1/4*pi
1037
+ sage: arg(2+x)
1038
+ arg(x + 2)
1039
+ sage: arg(2.0+i+x)
1040
+ arg(x + 2.00000000000000 + 1.00000000000000*I)
1041
+ sage: arg(-3)
1042
+ pi
1043
+ sage: arg(3)
1044
+ 0
1045
+ sage: arg(0)
1046
+ 0
1047
+ sage: arg(sqrt(2)+i)
1048
+ arg(sqrt(2) + I)
1049
+ """
1050
+ if isinstance(x,Expression):
1051
+ if x.is_trivial_zero():
1052
+ return x
1053
+ else:
1054
+ if not x:
1055
+ return x
1056
+ else:
1057
+ return arctan2(imag_part(x),real_part(x))
1058
+
1059
+ def _evalf_(self, x, parent=None, algorithm=None):
1060
+ """
1061
+ EXAMPLES::
1062
+
1063
+ sage: # needs sage.rings.complex_double
1064
+ sage: arg(0.0)
1065
+ 0.000000000000000
1066
+ sage: arg(3.0)
1067
+ 0.000000000000000
1068
+ sage: arg(3.00000000000000000000000000)
1069
+ 0.00000000000000000000000000
1070
+ sage: arg(3.00000000000000000000000000).prec()
1071
+ 90
1072
+ sage: arg(RDF(3))
1073
+ 0.0
1074
+ sage: arg(RDF(3)).parent()
1075
+ Real Double Field
1076
+ sage: arg(-2.5)
1077
+ 3.14159265358979
1078
+
1079
+ sage: arg(ComplexIntervalField(90)(3)).prec() # needs sage.rings.complex_interval_field
1080
+ 90
1081
+ sage: arg(ComplexIntervalField(90)(3)).parent() # needs sage.rings.complex_interval_field
1082
+ Real Interval Field with 90 bits of precision
1083
+ sage: arg(3.0r) # needs sage.rings.real_mpfr
1084
+ 0.0
1085
+ sage: arg(2.0+3*i) # needs sage.symbolic
1086
+ 0.982793723247329
1087
+
1088
+ TESTS:
1089
+
1090
+ Make sure that the ``_evalf_`` method works when it receives a
1091
+ keyword argument ``parent`` :issue:`12289`::
1092
+
1093
+ sage: arg(5+I, hold=True).n() # needs sage.symbolic
1094
+ 0.197395559849881
1095
+ """
1096
+ try:
1097
+ return x.arg()
1098
+ except AttributeError:
1099
+ pass
1100
+ # try to find a parent that support .arg()
1101
+ if parent is None:
1102
+ parent = s_parent(x)
1103
+ try:
1104
+ parent = parent.complex_field()
1105
+ except AttributeError:
1106
+ try:
1107
+ parent = ComplexField(x.prec())
1108
+ except AttributeError:
1109
+ parent = ComplexField()
1110
+
1111
+ return parent(x).arg()
1112
+
1113
+
1114
+ arg = Function_arg()
1115
+
1116
+
1117
+ ############################
1118
+ # Real and Imaginary Parts #
1119
+ ############################
1120
+ class Function_real_part(GinacFunction):
1121
+ def __init__(self):
1122
+ r"""
1123
+ Return the real part of the (possibly complex) input.
1124
+
1125
+ It is possible to prevent automatic evaluation using the
1126
+ ``hold`` parameter::
1127
+
1128
+ sage: real_part(I, hold=True) # needs sage.symbolic
1129
+ real_part(I)
1130
+
1131
+ To then evaluate again, we currently must use Maxima via
1132
+ :meth:`sage.symbolic.expression.Expression.simplify`::
1133
+
1134
+ sage: real_part(I, hold=True).simplify() # needs sage.symbolic
1135
+ 0
1136
+
1137
+ EXAMPLES::
1138
+
1139
+ sage: z = 1+2*I # needs sage.symbolic
1140
+ sage: real(z) # needs sage.symbolic
1141
+ 1
1142
+ sage: real(5/3)
1143
+ 5/3
1144
+ sage: a = 2.5
1145
+ sage: real(a) # needs sage.rings.real_mpfr
1146
+ 2.50000000000000
1147
+ sage: type(real(a)) # needs sage.rings.real_mpfr
1148
+ <class 'sage.rings.real_mpfr.RealLiteral'>
1149
+ sage: real(1.0r)
1150
+ 1.0
1151
+ sage: real(complex(3, 4))
1152
+ 3.0
1153
+
1154
+ Sage can recognize some expressions as real and accordingly
1155
+ return the identical argument::
1156
+
1157
+ sage: # needs sage.symbolic
1158
+ sage: SR.var('x', domain='integer').real_part()
1159
+ x
1160
+ sage: SR.var('x', domain='integer').imag_part()
1161
+ 0
1162
+ sage: real_part(sin(x)+x)
1163
+ x + sin(x)
1164
+ sage: real_part(x*exp(x))
1165
+ x*e^x
1166
+ sage: imag_part(sin(x)+x)
1167
+ 0
1168
+ sage: real_part(real_part(x))
1169
+ x
1170
+ sage: forget()
1171
+
1172
+ TESTS::
1173
+
1174
+ sage: loads(dumps(real_part))
1175
+ real_part
1176
+ sage: real_part(x)._sympy_() # needs sympy sage.symbolic
1177
+ re(x)
1178
+
1179
+ Check if :issue:`6401` is fixed::
1180
+
1181
+ sage: latex(x.real()) # needs sage.symbolic
1182
+ \Re \left( x \right)
1183
+
1184
+ sage: f(x) = function('f')(x) # needs sage.symbolic
1185
+ sage: latex( f(x).real()) # needs sage.symbolic
1186
+ \Re \left( f\left(x\right) \right)
1187
+
1188
+ Check that some real part expansions evaluate correctly
1189
+ (:issue:`21614`)::
1190
+
1191
+ sage: real(sqrt(sin(x))).subs(x==0) # needs sage.symbolic
1192
+ 0
1193
+ """
1194
+ GinacFunction.__init__(self, "real_part",
1195
+ conversions=dict(maxima='realpart',
1196
+ sympy='re',
1197
+ mathematica='Re',
1198
+ giac='re', fricas='real'),
1199
+ alt_name='real')
1200
+
1201
+ def __call__(self, x, **kwargs):
1202
+ r"""
1203
+ TESTS::
1204
+
1205
+ sage: type(real(complex(3, 4)))
1206
+ <... 'float'>
1207
+ """
1208
+ if isinstance(x, complex):
1209
+ return x.real
1210
+ else:
1211
+ return GinacFunction.__call__(self, x, **kwargs)
1212
+
1213
+
1214
+ real = real_part = Function_real_part()
1215
+
1216
+
1217
+ class Function_imag_part(GinacFunction):
1218
+ def __init__(self):
1219
+ r"""
1220
+ Return the imaginary part of the (possibly complex) input.
1221
+
1222
+ It is possible to prevent automatic evaluation using the
1223
+ ``hold`` parameter::
1224
+
1225
+ sage: imag_part(I, hold=True) # needs sage.symbolic
1226
+ imag_part(I)
1227
+
1228
+ To then evaluate again, we currently must use Maxima via
1229
+ :meth:`sage.symbolic.expression.Expression.simplify`::
1230
+
1231
+ sage: imag_part(I, hold=True).simplify() # needs sage.symbolic
1232
+ 1
1233
+
1234
+ TESTS::
1235
+
1236
+ sage: z = 1+2*I # needs sage.symbolic
1237
+ sage: imaginary(z) # needs sage.symbolic
1238
+ 2
1239
+ sage: imag(z) # needs sage.symbolic
1240
+ 2
1241
+ sage: imag(complex(3, 4))
1242
+ 4.0
1243
+ sage: loads(dumps(imag_part))
1244
+ imag_part
1245
+ sage: imag_part(x)._sympy_() # needs sympy sage.symbolic
1246
+ im(x)
1247
+
1248
+ Check if :issue:`6401` is fixed::
1249
+
1250
+ sage: latex(x.imag()) # needs sage.symbolic
1251
+ \Im \left( x \right)
1252
+
1253
+ sage: f(x) = function('f')(x) # needs sage.symbolic
1254
+ sage: latex(f(x).imag()) # needs sage.symbolic
1255
+ \Im \left( f\left(x\right) \right)
1256
+ """
1257
+ GinacFunction.__init__(self, "imag_part",
1258
+ conversions=dict(maxima='imagpart',
1259
+ sympy='im',
1260
+ mathematica='Im',
1261
+ fricas='imag',
1262
+ giac='im'),
1263
+ alt_name='imag')
1264
+
1265
+ def __call__(self, x, **kwargs):
1266
+ r"""
1267
+ TESTS::
1268
+
1269
+ sage: type(imag(complex(3, 4)))
1270
+ <... 'float'>
1271
+ """
1272
+ if isinstance(x, complex):
1273
+ return x.imag
1274
+ else:
1275
+ return GinacFunction.__call__(self, x, **kwargs)
1276
+
1277
+
1278
+ imag = imag_part = imaginary = Function_imag_part()
1279
+
1280
+
1281
+ ############################
1282
+ # Complex Conjugate #
1283
+ ############################
1284
+ class Function_conjugate(GinacFunction):
1285
+ def __init__(self):
1286
+ r"""
1287
+ Return the complex conjugate of the input.
1288
+
1289
+ It is possible to prevent automatic evaluation using the
1290
+ ``hold`` parameter::
1291
+
1292
+ sage: conjugate(I, hold=True) # needs sage.symbolic
1293
+ conjugate(I)
1294
+
1295
+ To then evaluate again, we currently must use Maxima via
1296
+ :meth:`sage.symbolic.expression.Expression.simplify`::
1297
+
1298
+ sage: conjugate(I, hold=True).simplify() # needs sage.symbolic
1299
+ -I
1300
+
1301
+ TESTS::
1302
+
1303
+ sage: # needs sage.symbolic
1304
+ sage: x,y = var('x,y')
1305
+ sage: x.conjugate()
1306
+ conjugate(x)
1307
+ sage: _._sympy_() # needs sympy
1308
+ conjugate(x)
1309
+ sage: latex(conjugate(x))
1310
+ \overline{x}
1311
+ sage: f = function('f')
1312
+ sage: latex(f(x).conjugate())
1313
+ \overline{f\left(x\right)}
1314
+ sage: f = function('psi')(x,y)
1315
+ sage: latex(f.conjugate())
1316
+ \overline{\psi\left(x, y\right)}
1317
+ sage: x.conjugate().conjugate()
1318
+ x
1319
+ sage: x.conjugate().operator()
1320
+ conjugate
1321
+ sage: x.conjugate().operator() == conjugate
1322
+ True
1323
+
1324
+ Check if :issue:`8755` is fixed::
1325
+
1326
+ sage: # needs sage.symbolic
1327
+ sage: conjugate(sqrt(-3))
1328
+ conjugate(sqrt(-3))
1329
+ sage: conjugate(sqrt(3))
1330
+ sqrt(3)
1331
+ sage: conjugate(sqrt(x))
1332
+ conjugate(sqrt(x))
1333
+ sage: conjugate(x^2)
1334
+ conjugate(x)^2
1335
+ sage: var('y', domain='positive')
1336
+ y
1337
+ sage: conjugate(sqrt(y))
1338
+ sqrt(y)
1339
+
1340
+ Check if :issue:`10964` is fixed::
1341
+
1342
+ sage: # needs sage.symbolic
1343
+ sage: z = I*sqrt(-3); z
1344
+ I*sqrt(-3)
1345
+ sage: conjugate(z)
1346
+ -I*conjugate(sqrt(-3))
1347
+ sage: var('a')
1348
+ a
1349
+ sage: conjugate(a*sqrt(-2)*sqrt(-3))
1350
+ conjugate(sqrt(-2))*conjugate(sqrt(-3))*conjugate(a)
1351
+
1352
+ Check that sums are handled correctly::
1353
+
1354
+ sage: y = var('y', domain='real') # needs sage.symbolic
1355
+ sage: conjugate(y + I) # needs sage.symbolic
1356
+ y - I
1357
+
1358
+ Test pickling::
1359
+
1360
+ sage: loads(dumps(conjugate))
1361
+ conjugate
1362
+ """
1363
+ GinacFunction.__init__(self, "conjugate",
1364
+ conversions=dict(sympy='conjugate',
1365
+ giac='conj',
1366
+ mathematica='Conjugate',
1367
+ fricas='conjugate'))
1368
+
1369
+
1370
+ conjugate = Function_conjugate()
1371
+
1372
+
1373
+ class Function_factorial(GinacFunction):
1374
+ def __init__(self):
1375
+ r"""
1376
+ Return the factorial of `n`.
1377
+
1378
+ INPUT:
1379
+
1380
+ - ``n`` -- a nonnegative integer, a complex number (except negative
1381
+ integers) or any symbolic expression
1382
+
1383
+ OUTPUT: integer or symbolic expression
1384
+
1385
+ EXAMPLES::
1386
+
1387
+ sage: factorial(0)
1388
+ 1
1389
+ sage: factorial(4)
1390
+ 24
1391
+ sage: factorial(10)
1392
+ 3628800
1393
+ sage: factorial(6) == 6*5*4*3*2
1394
+ True
1395
+
1396
+ sage: # needs sage.symbolic
1397
+ sage: x = SR.var('x')
1398
+ sage: f = factorial(x + factorial(x)); f
1399
+ factorial(x + factorial(x))
1400
+ sage: f(x=3)
1401
+ 362880
1402
+ sage: factorial(x)^2
1403
+ factorial(x)^2
1404
+
1405
+ To prevent automatic evaluation use the ``hold`` argument::
1406
+
1407
+ sage: factorial(5, hold=True) # needs sage.symbolic
1408
+ factorial(5)
1409
+
1410
+ To then evaluate again, we currently must use Maxima via
1411
+ :meth:`sage.symbolic.expression.Expression.simplify`::
1412
+
1413
+ sage: factorial(5, hold=True).simplify() # needs sage.symbolic
1414
+ 120
1415
+
1416
+ We can also give input other than nonnegative integers. For
1417
+ other nonnegative numbers, the :func:`sage.functions.gamma.gamma`
1418
+ function is used::
1419
+
1420
+ sage: factorial(1/2) # needs sage.symbolic
1421
+ 1/2*sqrt(pi)
1422
+ sage: factorial(3/4) # needs sage.symbolic
1423
+ gamma(7/4)
1424
+ sage: factorial(2.3) # needs sage.symbolic
1425
+ 2.68343738195577
1426
+
1427
+ But negative input always fails::
1428
+
1429
+ sage: factorial(-32)
1430
+ Traceback (most recent call last):
1431
+ ...
1432
+ ValueError: factorial only defined for nonnegative integers
1433
+
1434
+ And very large integers remain unevaluated::
1435
+
1436
+ sage: factorial(2**64) # needs sage.symbolic
1437
+ factorial(18446744073709551616)
1438
+ sage: SR(2**64).factorial() # needs sage.symbolic
1439
+ factorial(18446744073709551616)
1440
+
1441
+ TESTS:
1442
+
1443
+ We verify that we can convert this function to Maxima and
1444
+ bring it back into Sage.::
1445
+
1446
+ sage: # needs sage.symbolic
1447
+ sage: z = var('z')
1448
+ sage: factorial._maxima_init_()
1449
+ 'factorial'
1450
+ sage: maxima(factorial(z))
1451
+ factorial(_SAGE_VAR_z)
1452
+ sage: _.sage()
1453
+ factorial(z)
1454
+ sage: _._sympy_() # needs sympy
1455
+ factorial(z)
1456
+ sage: k = var('k')
1457
+ sage: factorial(k)
1458
+ factorial(k)
1459
+
1460
+ sage: factorial(3.14) # needs sage.symbolic
1461
+ 7.173269190187...
1462
+
1463
+ Test latex typesetting::
1464
+
1465
+ sage: # needs sage.symbolic
1466
+ sage: latex(factorial(x))
1467
+ x!
1468
+ sage: latex(factorial(2*x))
1469
+ \left(2 \, x\right)!
1470
+ sage: latex(factorial(sin(x)))
1471
+ \sin\left(x\right)!
1472
+ sage: latex(factorial(sqrt(x+1)))
1473
+ \left(\sqrt{x + 1}\right)!
1474
+ sage: latex(factorial(sqrt(x)))
1475
+ \sqrt{x}!
1476
+ sage: latex(factorial(x^(2/3)))
1477
+ \left(x^{\frac{2}{3}}\right)!
1478
+
1479
+ sage: latex(factorial)
1480
+ {\rm factorial}
1481
+
1482
+ Check that :issue:`11539` is fixed::
1483
+
1484
+ sage: # needs sage.symbolic
1485
+ sage: (factorial(x) == 0).simplify()
1486
+ factorial(x) == 0
1487
+ sage: maxima(factorial(x) == 0).sage()
1488
+ factorial(x) == 0
1489
+ sage: y = var('y')
1490
+ sage: (factorial(x) == y).solve(x)
1491
+ [factorial(x) == y]
1492
+
1493
+ Check that :issue:`16166` is fixed::
1494
+
1495
+ sage: RBF = RealBallField(53) # needs sage.libs.flint
1496
+ sage: factorial(RBF(4.2)) # abs tol 1e-13 # needs sage.libs.flint
1497
+ [32.5780960503314 +/- 6.06e-14]
1498
+
1499
+ Test pickling::
1500
+
1501
+ sage: loads(dumps(factorial))
1502
+ factorial
1503
+ """
1504
+ GinacFunction.__init__(self, "factorial", latex_name='{\\rm factorial}',
1505
+ conversions=dict(maxima='factorial',
1506
+ mathematica='Factorial',
1507
+ sympy='factorial',
1508
+ fricas='factorial',
1509
+ giac='factorial'))
1510
+
1511
+ def _eval_(self, x):
1512
+ """
1513
+ Evaluate the factorial function.
1514
+
1515
+ Note that this method overrides the eval method defined in GiNaC
1516
+ which calls numeric evaluation on all numeric input. We preserve
1517
+ exact results if the input is a rational number.
1518
+
1519
+ EXAMPLES::
1520
+
1521
+ sage: # needs sage.symbolic
1522
+ sage: k = var('k')
1523
+ sage: k.factorial()
1524
+ factorial(k)
1525
+ sage: SR(1/2).factorial()
1526
+ 1/2*sqrt(pi)
1527
+ sage: SR(3/4).factorial()
1528
+ gamma(7/4)
1529
+ sage: SR(5).factorial()
1530
+ 120
1531
+ sage: SR(3245908723049857203948572398475r).factorial()
1532
+ factorial(3245908723049857203948572398475)
1533
+ sage: SR(3245908723049857203948572398475).factorial()
1534
+ factorial(3245908723049857203948572398475)
1535
+
1536
+ TESTS:
1537
+
1538
+ Check that :issue:`25421` is fixed::
1539
+
1540
+ sage: factorial(RBF(2)**64) # needs sage.libs.flint
1541
+ [+/- 2.30e+347382171326740403407]
1542
+
1543
+ Check that :issue:`26749` is fixed::
1544
+
1545
+ sage: factorial(float(3.2)) # abs tol 1e-14 # needs sage.symbolic
1546
+ 7.7566895357931776
1547
+ sage: type(factorial(float(3.2))) # needs sage.symbolic
1548
+ <class 'float'>
1549
+ """
1550
+ if isinstance(x, (int, Integer)):
1551
+ try:
1552
+ return x.factorial()
1553
+ except OverflowError:
1554
+ return
1555
+ elif isinstance(x, Rational):
1556
+ from sage.functions.gamma import gamma
1557
+ return gamma(x + 1)
1558
+ elif isinstance(x, Element) and hasattr(x.parent(), 'precision'):
1559
+ return (x + 1).gamma()
1560
+ elif self._is_numerical(x):
1561
+ from sage.functions.gamma import gamma
1562
+ return gamma(x + 1)
1563
+
1564
+
1565
+ factorial = Function_factorial()
1566
+
1567
+
1568
+ class Function_binomial(GinacFunction):
1569
+ def __init__(self):
1570
+ r"""
1571
+ Return the binomial coefficient.
1572
+
1573
+ .. MATH::
1574
+
1575
+ \binom{x}{m} = x (x-1) \cdots (x-m+1) / m!
1576
+
1577
+
1578
+ which is defined for `m \in \ZZ` and any
1579
+ `x`. We extend this definition to include cases when
1580
+ `x-m` is an integer but `m` is not by
1581
+
1582
+ .. MATH::
1583
+
1584
+ \binom{x}{m}= \binom{x}{x-m}
1585
+
1586
+ If `m < 0`, return `0`.
1587
+
1588
+ INPUT:
1589
+
1590
+ - ``x``, ``m`` -- numbers or symbolic expressions; either ``m``
1591
+ or ``x-m`` must be an integer, else the output is symbolic
1592
+
1593
+ OUTPUT: number or symbolic expression (if input is symbolic)
1594
+
1595
+ EXAMPLES::
1596
+
1597
+ sage: # needs sage.symbolic
1598
+ sage: binomial(5, 2)
1599
+ 10
1600
+ sage: binomial(2, 0)
1601
+ 1
1602
+ sage: binomial(1/2, 0) # needs sage.libs.pari
1603
+ 1
1604
+ sage: binomial(3, -1)
1605
+ 0
1606
+ sage: binomial(20, 10)
1607
+ 184756
1608
+ sage: binomial(-2, 5)
1609
+ -6
1610
+ sage: n = var('n'); binomial(n, 2)
1611
+ 1/2*(n - 1)*n
1612
+ sage: n = var('n'); binomial(n, n)
1613
+ 1
1614
+ sage: n = var('n'); binomial(n, n - 1)
1615
+ n
1616
+ sage: binomial(2^100, 2^100)
1617
+ 1
1618
+
1619
+ sage: binomial(RealField()('2.5'), 2) # needs sage.libs.pari sage.rings.real_mpfr
1620
+ 1.87500000000000
1621
+
1622
+ ::
1623
+
1624
+ sage: k, i = var('k,i') # needs sage.symbolic
1625
+ sage: binomial(k,i) # needs sage.symbolic
1626
+ binomial(k, i)
1627
+
1628
+ We can use a ``hold`` parameter to prevent automatic evaluation::
1629
+
1630
+ sage: SR(5).binomial(3, hold=True) # needs sage.symbolic
1631
+ binomial(5, 3)
1632
+ sage: SR(5).binomial(3, hold=True).simplify() # needs sage.symbolic
1633
+ 10
1634
+
1635
+ TESTS:
1636
+
1637
+ We verify that we can convert this function to Maxima and
1638
+ bring it back into Sage.
1639
+
1640
+ ::
1641
+
1642
+ sage: # needs sage.symbolic
1643
+ sage: n, k = var('n,k')
1644
+ sage: maxima(binomial(n,k))
1645
+ binomial(_SAGE_VAR_n,_SAGE_VAR_k)
1646
+ sage: _.sage()
1647
+ binomial(n, k)
1648
+ sage: _._sympy_() # needs sympy
1649
+ binomial(n, k)
1650
+ sage: binomial._maxima_init_()
1651
+ 'binomial'
1652
+
1653
+ For polynomials::
1654
+
1655
+ sage: y = polygen(QQ, 'y')
1656
+ sage: binomial(y, 2).parent() # needs sage.symbolic
1657
+ Univariate Polynomial Ring in y over Rational Field
1658
+
1659
+ :issue:`16726`::
1660
+
1661
+ sage: binomial(CIF(1), 2) # needs sage.symbolic
1662
+ 0
1663
+ sage: binomial(CIF(3), 2) # needs sage.symbolic
1664
+ 3
1665
+
1666
+ Test pickling::
1667
+
1668
+ sage: loads(dumps(binomial(n, k))) # needs sage.symbolic
1669
+ binomial(n, k)
1670
+ """
1671
+ GinacFunction.__init__(self, "binomial", nargs=2, preserved_arg=1,
1672
+ conversions=dict(maxima='binomial',
1673
+ mathematica='Binomial',
1674
+ sympy='binomial',
1675
+ fricas='binomial',
1676
+ giac='comb'))
1677
+
1678
+ def _binomial_sym(self, n, k):
1679
+ """
1680
+ Expand the binomial formula symbolically when the second argument
1681
+ is an integer.
1682
+
1683
+ EXAMPLES::
1684
+
1685
+ sage: # needs sage.symbolic
1686
+ sage: binomial._binomial_sym(x, 3)
1687
+ 1/6*(x - 1)*(x - 2)*x
1688
+ sage: binomial._binomial_sym(x, x)
1689
+ Traceback (most recent call last):
1690
+ ...
1691
+ ValueError: second argument must be an integer
1692
+ sage: binomial._binomial_sym(x, SR(3))
1693
+ 1/6*(x - 1)*(x - 2)*x
1694
+ sage: binomial._binomial_sym(x, 0r)
1695
+ 1
1696
+ sage: binomial._binomial_sym(x, -1)
1697
+ 0
1698
+
1699
+ sage: y = polygen(QQ, 'y')
1700
+ sage: binomial._binomial_sym(y, 2).parent()
1701
+ Univariate Polynomial Ring in y over Rational Field
1702
+ """
1703
+ if isinstance(k, Expression):
1704
+ if k.is_integer():
1705
+ k = k.pyobject()
1706
+ else:
1707
+ raise ValueError("second argument must be an integer")
1708
+
1709
+ if k < 0:
1710
+ return s_parent(k)(0)
1711
+ if k == 0:
1712
+ return s_parent(k)(1)
1713
+ if k == 1:
1714
+ return n
1715
+
1716
+ from sage.misc.misc_c import prod
1717
+ return prod(n - i for i in range(k)) / factorial(k)
1718
+
1719
+ def _method_arguments(self, n, k):
1720
+ """
1721
+ See :meth:`sage.symbolic.function.BuiltinFunction._method_arguments`.
1722
+
1723
+ TESTS::
1724
+
1725
+ sage: binomial._method_arguments(10, 5)
1726
+ (10, 5)
1727
+ """
1728
+ return (n, k)
1729
+
1730
+ def _eval_(self, n, k):
1731
+ """
1732
+ EXAMPLES::
1733
+
1734
+ sage: binomial._eval_(5, 3)
1735
+ 10
1736
+ sage: type(binomial._eval_(5, 3))
1737
+ <class 'sage.rings.integer.Integer'>
1738
+ sage: type(binomial._eval_(5., 3)) # needs sage.rings.real_mpfr
1739
+ <class 'sage.rings.real_mpfr.RealNumber'>
1740
+
1741
+ sage: # needs sage.symbolic
1742
+ sage: binomial._eval_(x, 3)
1743
+ 1/6*(x - 1)*(x - 2)*x
1744
+ sage: binomial._eval_(x, x-2)
1745
+ 1/2*(x - 1)*x
1746
+ sage: n = var('n')
1747
+ sage: binomial._eval_(x, n) is None
1748
+ True
1749
+
1750
+ TESTS::
1751
+
1752
+ sage: y = polygen(QQ, 'y')
1753
+ sage: binomial._eval_(y, 2).parent()
1754
+ Univariate Polynomial Ring in y over Rational Field
1755
+ """
1756
+ if not isinstance(k, Expression):
1757
+ if not isinstance(n, Expression):
1758
+ n, k = coercion_model.canonical_coercion(n, k)
1759
+ return self._evalf_(n, k)
1760
+ if k in ZZ:
1761
+ return self._binomial_sym(n, k)
1762
+ if (n - k) in ZZ:
1763
+ return self._binomial_sym(n, n - k)
1764
+
1765
+ return None
1766
+
1767
+ def _evalf_(self, n, k, parent=None, algorithm=None):
1768
+ """
1769
+ EXAMPLES::
1770
+
1771
+ sage: binomial._evalf_(5.r, 3)
1772
+ 10.0
1773
+ sage: type(binomial._evalf_(5.r, 3))
1774
+ <... 'float'>
1775
+ sage: binomial._evalf_(1/2, 1/1) # needs sage.libs.pari
1776
+ 1/2
1777
+ sage: binomial._evalf_(10^20 + 1/1, 10^20)
1778
+ 100000000000000000001
1779
+ sage: binomial._evalf_(SR(10**7), 10**7) # needs sage.symbolic
1780
+ 1
1781
+ sage: binomial._evalf_(3/2, SR(1/1)) # needs sage.symbolic
1782
+ 3/2
1783
+ """
1784
+ return arith_binomial(n, k)
1785
+
1786
+
1787
+ binomial = Function_binomial()
1788
+
1789
+
1790
+ class Function_sum(BuiltinFunction):
1791
+ """
1792
+ Placeholder symbolic sum function that is only accessible internally.
1793
+
1794
+ EXAMPLES::
1795
+
1796
+ sage: from sage.functions.other import symbolic_sum as ssum
1797
+ sage: r = ssum(x, x, 1, 10); r # needs sage.symbolic
1798
+ sum(x, x, 1, 10)
1799
+ sage: r.unhold() # needs sage.symbolic
1800
+ 55
1801
+ """
1802
+ def __init__(self):
1803
+ """
1804
+ EXAMPLES::
1805
+
1806
+ sage: from sage.functions.other import symbolic_sum as ssum
1807
+ sage: maxima(ssum(x, x, 1, 10)) # needs sage.symbolic
1808
+ 55
1809
+ """
1810
+ BuiltinFunction.__init__(self, "sum", nargs=4,
1811
+ conversions=dict(maxima='sum'))
1812
+
1813
+ def _print_latex_(self, x, var, a, b):
1814
+ r"""
1815
+ EXAMPLES::
1816
+
1817
+ sage: from sage.functions.other import symbolic_sum as ssum
1818
+ sage: latex(ssum(x^2, x, 1, 10)) # needs sage.symbolic
1819
+ {\sum_{x=1}^{10} x^{2}}
1820
+ """
1821
+ return r"{{\sum_{{{}={}}}^{{{}}} {}}}".format(latex(var), latex(a),
1822
+ latex(b), latex(x))
1823
+
1824
+ def _sympy_(self, term, k, a, n):
1825
+ """
1826
+ Convert to sympy Sum.
1827
+
1828
+ EXAMPLES::
1829
+
1830
+ sage: # needs sage.symbolic
1831
+ sage: var('k, n')
1832
+ (k, n)
1833
+ sage: s = sum(k, k, 1, n, hold=True); s
1834
+ sum(k, k, 1, n)
1835
+ sage: s._sympy_() # indirect test # needs sympy
1836
+ Sum(k, (k, 1, n))
1837
+ sage: s._sympy_().doit() # needs sympy
1838
+ n**2/2 + n/2
1839
+ """
1840
+ import sympy
1841
+ return sympy.Sum(term, (k, a, n))
1842
+
1843
+
1844
+ symbolic_sum = Function_sum()
1845
+
1846
+
1847
+ class Function_prod(BuiltinFunction):
1848
+ """
1849
+ Placeholder symbolic product function that is only accessible internally.
1850
+
1851
+ EXAMPLES::
1852
+
1853
+ sage: from sage.functions.other import symbolic_product as sprod
1854
+ sage: r = sprod(x, x, 1, 10); r # needs sage.symbolic
1855
+ product(x, x, 1, 10)
1856
+ sage: r.unhold() # needs sage.symbolic
1857
+ 3628800
1858
+ """
1859
+ def __init__(self):
1860
+ """
1861
+ EXAMPLES::
1862
+
1863
+ sage: # needs sage.symbolic
1864
+ sage: from sage.functions.other import symbolic_product as sprod
1865
+ sage: _ = var('m n', domain='integer')
1866
+ sage: r = maxima(sprod(sin(m), m, 1, n)).sage(); r
1867
+ product(sin(m), m, 1, n)
1868
+ sage: isinstance(r.operator(), sage.functions.other.Function_prod)
1869
+ True
1870
+ sage: r = sympy(sprod(sin(m), m, 1, n)).sage(); r # known bug # needs sympy
1871
+ product(sin(m), m, 1, n)
1872
+ sage: isinstance(r.operator(), # known bug # needs sympy
1873
+ ....: sage.functions.other.Function_prod)
1874
+ True
1875
+ sage: giac(sprod(m, m, 1, n)).sage() # needs giac
1876
+ factorial(n)
1877
+ """
1878
+ BuiltinFunction.__init__(self, "product", nargs=4,
1879
+ conversions=dict(maxima='product',
1880
+ sympy='Product', giac='product'))
1881
+
1882
+ def _print_latex_(self, x, var, a, b):
1883
+ r"""
1884
+ EXAMPLES::
1885
+
1886
+ sage: from sage.functions.other import symbolic_product as sprod
1887
+ sage: latex(sprod(x^2, x, 1, 10)) # needs sage.symbolic
1888
+ {\prod_{x=1}^{10} x^{2}}
1889
+ """
1890
+ return r"{{\prod_{{{}={}}}^{{{}}} {}}}".format(latex(var), latex(a),
1891
+ latex(b), latex(x))
1892
+
1893
+ def _sympy_(self, term, k, a, n):
1894
+ """
1895
+ Convert to sympy Product.
1896
+
1897
+ EXAMPLES::
1898
+
1899
+ sage: var('k, n') # needs sage.symbolic
1900
+ (k, n)
1901
+ sage: p = product(k^2 + k + 1, k, 1, n, hold=True) # needs sympy sage.symbolic
1902
+ sage: p._sympy_() # indirect test # needs sympy sage.symbolic
1903
+ Product(k**2 + k + 1, (k, 1, n))
1904
+ """
1905
+ import sympy
1906
+ return sympy.Product(term, (k, a, n))
1907
+
1908
+
1909
+ symbolic_product = Function_prod()
1910
+
1911
+
1912
+ class Function_limit(BuiltinFunction):
1913
+ """
1914
+ Placeholder symbolic limit function that is only accessible internally.
1915
+
1916
+ This function is called to create formal wrappers of limits that
1917
+ Maxima can't compute::
1918
+
1919
+ sage: a = lim(exp(x^2)*(1-erf(x)), x=infinity); a # needs sage.symbolic
1920
+ -limit((erf(x) - 1)*e^(x^2), x, +Infinity)
1921
+
1922
+ EXAMPLES::
1923
+
1924
+ sage: # needs sage.symbolic
1925
+ sage: from sage.functions.other import symbolic_limit as slimit
1926
+ sage: slimit(1/x, x, +oo)
1927
+ limit(1/x, x, +Infinity)
1928
+ sage: var('minus,plus')
1929
+ (minus, plus)
1930
+ sage: slimit(1/x, x, +oo)
1931
+ limit(1/x, x, +Infinity)
1932
+ sage: slimit(1/x, x, 0, plus)
1933
+ limit(1/x, x, 0, plus)
1934
+ sage: slimit(1/x, x, 0, minus)
1935
+ limit(1/x, x, 0, minus)
1936
+ """
1937
+ def __init__(self):
1938
+ """
1939
+ EXAMPLES::
1940
+
1941
+ sage: from sage.functions.other import symbolic_limit as slimit
1942
+ sage: maxima(slimit(1/x, x, +oo)) # needs sage.symbolic
1943
+ 0
1944
+ """
1945
+ BuiltinFunction.__init__(self, "limit", nargs=0,
1946
+ conversions=dict(maxima='limit'))
1947
+
1948
+ def _latex_(self):
1949
+ r"""
1950
+ EXAMPLES::
1951
+
1952
+ sage: from sage.functions.other import symbolic_limit as slimit
1953
+ sage: latex(slimit)
1954
+ \lim
1955
+ """
1956
+ return r'\lim'
1957
+
1958
+ def _print_latex_(self, ex, var, to, direction=''):
1959
+ r"""
1960
+ EXAMPLES::
1961
+
1962
+ sage: # needs sage.symbolic
1963
+ sage: from sage.functions.other import symbolic_limit as slimit
1964
+ sage: var('x,a')
1965
+ (x, a)
1966
+ sage: f = function('f')
1967
+ sage: latex(slimit(f(x), x, a))
1968
+ \lim_{x \to a}\, f\left(x\right)
1969
+ sage: latex(limit(f(x), x=oo))
1970
+ \lim_{x \to +\infty}\, f\left(x\right)
1971
+
1972
+ TESTS:
1973
+
1974
+ When one-sided limits are converted back from maxima, the direction
1975
+ argument becomes a symbolic variable. We check if typesetting these works::
1976
+
1977
+ sage: # needs sage.symbolic
1978
+ sage: from sage.functions.other import symbolic_limit as slimit
1979
+ sage: var('minus,plus')
1980
+ (minus, plus)
1981
+ sage: latex(slimit(f(x), x, a, minus))
1982
+ \lim_{x \to a^-}\, f\left(x\right)
1983
+ sage: latex(slimit(f(x), x, a, plus))
1984
+ \lim_{x \to a^+}\, f\left(x\right)
1985
+ sage: latex(limit(f(x),x=a,dir='+'))
1986
+ \lim_{x \to a^+}\, f\left(x\right)
1987
+ sage: latex(limit(f(x),x=a,dir='right'))
1988
+ \lim_{x \to a^+}\, f\left(x\right)
1989
+ sage: latex(limit(f(x),x=a,dir='-'))
1990
+ \lim_{x \to a^-}\, f\left(x\right)
1991
+ sage: latex(limit(f(x),x=a,dir='left'))
1992
+ \lim_{x \to a^-}\, f\left(x\right)
1993
+
1994
+ Check if :issue:`13181` is fixed::
1995
+
1996
+ sage: # needs sage.symbolic
1997
+ sage: t = var('t')
1998
+ sage: latex(limit(exp_integral_e(1/2, I*t - I*x)*sqrt(-t + x), t=x, dir='-'))
1999
+ \lim_{t \to x^-}\, \sqrt{-t + x} E_{\frac{1}{2}}\left(i \, t - i \, x\right)
2000
+ sage: latex(limit(exp_integral_e(1/2, I*t - I*x)*sqrt(-t + x), t=x, dir='+'))
2001
+ \lim_{t \to x^+}\, \sqrt{-t + x} E_{\frac{1}{2}}\left(i \, t - i \, x\right)
2002
+ sage: latex(limit(exp_integral_e(1/2, I*t - I*x)*sqrt(-t + x), t=x))
2003
+ \lim_{t \to x}\, \sqrt{-t + x} E_{\frac{1}{2}}\left(i \, t - i \, x\right)
2004
+ """
2005
+ if repr(direction) == 'minus':
2006
+ dir_str = '^-'
2007
+ elif repr(direction) == 'plus':
2008
+ dir_str = '^+'
2009
+ else:
2010
+ dir_str = ''
2011
+ return r"\lim_{{{} \to {}{}}}\, {}".format(latex(var),
2012
+ latex(to), dir_str, latex(ex))
2013
+
2014
+
2015
+ symbolic_limit = Function_limit()
2016
+
2017
+
2018
+ class Function_cases(GinacFunction):
2019
+ """
2020
+ Formal function holding ``(condition, expression)`` pairs.
2021
+
2022
+ Numbers are considered conditions with zero being ``False``.
2023
+ A true condition marks a default value. The function is not
2024
+ evaluated as long as it contains a relation that cannot be
2025
+ decided by Pynac.
2026
+
2027
+ EXAMPLES::
2028
+
2029
+ sage: # needs sage.symbolic
2030
+ sage: ex = cases([(x==0, pi), (True, 0)]); ex
2031
+ cases(((x == 0, pi), (1, 0)))
2032
+ sage: ex.subs(x==0)
2033
+ pi
2034
+ sage: ex.subs(x==2)
2035
+ 0
2036
+ sage: ex + 1
2037
+ cases(((x == 0, pi), (1, 0))) + 1
2038
+ sage: _.subs(x==0)
2039
+ pi + 1
2040
+
2041
+ The first encountered default is used, as well as the first relation
2042
+ that can be trivially decided::
2043
+
2044
+ sage: cases(((True, pi), (True, 0))) # needs sage.symbolic
2045
+ pi
2046
+
2047
+ sage: # needs sage.symbolic
2048
+ sage: _ = var('y')
2049
+ sage: ex = cases(((x==0, pi), (y==1, 0))); ex
2050
+ cases(((x == 0, pi), (y == 1, 0)))
2051
+ sage: ex.subs(x==0)
2052
+ pi
2053
+ sage: ex.subs(x==0, y==1)
2054
+ pi
2055
+ """
2056
+ def __init__(self):
2057
+ """
2058
+ EXAMPLES::
2059
+
2060
+ sage: loads(dumps(cases))
2061
+ cases
2062
+ """
2063
+ GinacFunction.__init__(self, "cases")
2064
+
2065
+ def __call__(self, l, **kwargs):
2066
+ """
2067
+ EXAMPLES::
2068
+
2069
+ sage: ex = cases([(x==0, pi), (True, 0)]); ex # needs sage.symbolic
2070
+ cases(((x == 0, pi), (1, 0)))
2071
+
2072
+ TESTS::
2073
+
2074
+ sage: cases()
2075
+ Traceback (most recent call last):
2076
+ ...
2077
+ TypeError: ...__call__() missing 1 required positional argument: 'l'
2078
+
2079
+ sage: cases(x) # needs sage.symbolic
2080
+ Traceback (most recent call last):
2081
+ ...
2082
+ RuntimeError: cases argument not a sequence
2083
+ """
2084
+ return GinacFunction.__call__(self,
2085
+ SR._force_pyobject(l), **kwargs)
2086
+
2087
+ def _print_latex_(self, l, **kwargs):
2088
+ r"""
2089
+ EXAMPLES::
2090
+
2091
+ sage: ex = cases([(x==0, pi), (True, 0)]); ex # needs sage.symbolic
2092
+ cases(((x == 0, pi), (1, 0)))
2093
+ sage: latex(ex) # needs sage.symbolic
2094
+ \begin{cases}{\pi} & {x = 0}\\{0} & {1}\end{cases}
2095
+
2096
+ TESTS:
2097
+
2098
+ Verify that :issue:`25624` is fixed::
2099
+
2100
+ sage: L = latex(cases([(x == 0, 0), (1, 1)])); L # needs sage.symbolic
2101
+ \begin{cases}{0} & {x = 0}\\{1} & {1}\end{cases}
2102
+ """
2103
+ if not isinstance(l, (list, tuple)):
2104
+ raise ValueError("cases() argument must be a list")
2105
+ str = r"\begin{cases}"
2106
+ for pair in l:
2107
+ left = None
2108
+ if (isinstance(pair, tuple)):
2109
+ right,left = pair
2110
+ else:
2111
+ right = pair
2112
+ str += r"{%s} & {%s}\\" % (latex(left), latex(right))
2113
+ return str[:-2] + r"\end{cases}"
2114
+
2115
+ def _sympy_(self, l):
2116
+ """
2117
+ Convert this cases expression to its SymPy equivalent.
2118
+
2119
+ EXAMPLES::
2120
+
2121
+ sage: ex = cases(((x<0, pi), (x==1, 1), (True, 0))) # needs sage.symbolic
2122
+ sage: assert ex == ex._sympy_()._sage_() # needs sympy sage.symbolic
2123
+ """
2124
+ from sympy import Piecewise as pw
2125
+ args = []
2126
+ for tup in l.operands():
2127
+ cond, expr = tup.operands()
2128
+ if SR(cond).is_numeric():
2129
+ args.append((SR(expr)._sympy_(), bool(SR(cond)._sympy_())))
2130
+ else:
2131
+ args.append((SR(expr)._sympy_(), SR(cond)._sympy_()))
2132
+ return pw(*args)
2133
+
2134
+
2135
+ cases = Function_cases()
2136
+
2137
+
2138
+ class Function_crootof(BuiltinFunction):
2139
+ """
2140
+ Formal function holding ``(polynomial, index)`` pairs.
2141
+
2142
+ The expression evaluates to a floating point value that is an
2143
+ approximation to a specific complex root of the polynomial. The
2144
+ ordering is fixed so you always get the same root.
2145
+
2146
+ The functionality is imported from SymPy, see
2147
+ http://docs.sympy.org/latest/_modules/sympy/polys/rootoftools.html
2148
+
2149
+ EXAMPLES::
2150
+
2151
+ sage: # needs sage.symbolic
2152
+ sage: c = complex_root_of(x^6 + x + 1, 1); c
2153
+ complex_root_of(x^6 + x + 1, 1)
2154
+ sage: c.n()
2155
+ -0.790667188814418 + 0.300506920309552*I
2156
+ sage: c.n(100)
2157
+ -0.79066718881441764449859281847 + 0.30050692030955162512001002521*I
2158
+ sage: (c^6 + c + 1).n(100) < 1e-25
2159
+ True
2160
+ """
2161
+ def __init__(self):
2162
+ """
2163
+ EXAMPLES::
2164
+
2165
+ sage: loads(dumps(complex_root_of))
2166
+ complex_root_of
2167
+ """
2168
+ BuiltinFunction.__init__(self, "complex_root_of", nargs=2,
2169
+ conversions=dict(sympy='CRootOf'),
2170
+ evalf_params_first=False)
2171
+
2172
+ def _eval_(self, poly, index):
2173
+ """
2174
+ TESTS::
2175
+
2176
+ sage: # needs sage.symbolic
2177
+ sage: _ = var('y')
2178
+ sage: complex_root_of(1, 1)
2179
+ Traceback (most recent call last):
2180
+ ...
2181
+ ValueError: polynomial in one variable required
2182
+ sage: complex_root_of(x+y, 1)
2183
+ Traceback (most recent call last):
2184
+ ...
2185
+ ValueError: polynomial in one variable required
2186
+ sage: complex_root_of(sin(x), 1)
2187
+ Traceback (most recent call last):
2188
+ ...
2189
+ ValueError: polynomial in one variable required
2190
+ """
2191
+ try:
2192
+ vars = poly.variables()
2193
+ except AttributeError:
2194
+ raise ValueError('polynomial in one variable required')
2195
+ if len(vars) != 1 or not poly.is_polynomial(vars[0]):
2196
+ raise ValueError('polynomial in one variable required')
2197
+
2198
+ def _evalf_(self, poly, index, parent=None, algorithm=None):
2199
+ """
2200
+ EXAMPLES::
2201
+
2202
+ sage: complex_root_of(x^2 - 2, 1).n() # needs sage.symbolic
2203
+ 1.41421356237309
2204
+ sage: complex_root_of(x^2 - 2, 3).n() # needs sage.symbolic
2205
+ Traceback (most recent call last):
2206
+ ...
2207
+ IndexError: root index out of [-2, 1] range, got 3
2208
+
2209
+ TESTS:
2210
+
2211
+ Check that low precision is handled (:issue:`24378`)::
2212
+
2213
+ sage: complex_root_of(x^8 - 1, 7).n(2) # needs sage.symbolic
2214
+ 0.75 + 0.75*I
2215
+ sage: complex_root_of(x^8 - 1, 7).n(20) # needs sage.symbolic
2216
+ 0.70711 + 0.70711*I
2217
+ """
2218
+ from mpmath.libmp import prec_to_dps
2219
+ from sympy.polys import CRootOf, Poly
2220
+ try:
2221
+ prec = parent.precision()
2222
+ except AttributeError:
2223
+ prec = 53
2224
+ sobj = CRootOf(Poly(poly._sympy_()), int(index))
2225
+ return parent(sobj.n(1 + prec_to_dps(prec))._sage_())
2226
+
2227
+
2228
+ complex_root_of = Function_crootof()
2229
+
2230
+
2231
+ class Function_elementof(BuiltinFunction):
2232
+ """
2233
+ Formal set membership function that is only accessible internally.
2234
+
2235
+ This function is called to express a set membership statement,
2236
+ usually as part of a solution set returned by :func:`solve`.
2237
+ See :class:`sage.sets.set.Set` and :class:`sage.sets.real_set.RealSet`
2238
+ for possible set arguments.
2239
+
2240
+ EXAMPLES::
2241
+
2242
+ sage: # needs sage.symbolic
2243
+ sage: from sage.functions.other import element_of
2244
+ sage: element_of(x, SR(ZZ))
2245
+ element_of(x, Integer Ring)
2246
+ sage: element_of(sin(x), SR(QQ))
2247
+ element_of(sin(x), Rational Field)
2248
+ sage: element_of(x, SR(RealSet.open_closed(0,1)))
2249
+ element_of(x, (0, 1])
2250
+ sage: element_of(x, SR(Set([4,6,8])))
2251
+ element_of(x, {8, 4, 6})
2252
+ """
2253
+ def __init__(self):
2254
+ """
2255
+ EXAMPLES::
2256
+
2257
+ sage: from sage.functions.other import element_of
2258
+ sage: loads(dumps(element_of))
2259
+ element_of
2260
+ """
2261
+ BuiltinFunction.__init__(self, "element_of", nargs=2,
2262
+ conversions=dict(sympy='Contains'))
2263
+
2264
+ def _eval_(self, x, s):
2265
+ """
2266
+ EXAMPLES::
2267
+
2268
+ sage: from sage.functions.other import element_of
2269
+ sage: element_of(x, SR(RealSet(-oo, oo))) # needs sage.symbolic
2270
+ element_of(x, (-oo, +oo))
2271
+ sage: element_of(x, 0) # needs sage.symbolic
2272
+ Traceback (most recent call last):
2273
+ ...
2274
+ ValueError: not a set: 0
2275
+ """
2276
+ from sage.categories.sets_cat import Sets
2277
+ if s not in Sets():
2278
+ raise ValueError("not a set: {}".format(s))
2279
+
2280
+ def _latex_(self):
2281
+ r"""
2282
+ EXAMPLES::
2283
+
2284
+ sage: from sage.functions.other import element_of
2285
+ sage: latex(element_of)
2286
+ \in
2287
+ """
2288
+ return r'\in'
2289
+
2290
+ def _print_latex_(self, ex, s):
2291
+ r"""
2292
+ EXAMPLES::
2293
+
2294
+ sage: from sage.functions.other import element_of
2295
+ sage: latex(element_of(x, SR(ZZ))) # needs sage.symbolic
2296
+ x \in \Bold{Z}
2297
+ sage: latex(element_of(x, SR(Set([4,6,8])))) # needs sage.symbolic
2298
+ x \in \left\{8, 4, 6\right\}
2299
+ """
2300
+ return r"{} \in {}".format(latex(ex), latex(s))
2301
+
2302
+
2303
+ element_of = Function_elementof()