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,2005 @@
1
+ # sage_setup: distribution = sagemath-categories
2
+ """
3
+ Functional notation
4
+
5
+ These are functions so that you can write ``foo(x)`` instead of ``x.foo()``
6
+ in certain common cases.
7
+
8
+ AUTHORS:
9
+
10
+ - William Stein: Initial version
11
+
12
+ - David Joyner (2005-12-20): More Examples
13
+ """
14
+ # ****************************************************************************
15
+ # Copyright (C) 2004 William Stein <wstein@gmail.com>
16
+ #
17
+ # This program is free software: you can redistribute it and/or modify
18
+ # it under the terms of the GNU General Public License as published by
19
+ # the Free Software Foundation, either version 2 of the License, or
20
+ # (at your option) any later version.
21
+ # https://www.gnu.org/licenses/
22
+ # ****************************************************************************
23
+ import builtins
24
+ import math
25
+
26
+ from sage.misc.lazy_import import lazy_import
27
+ from sage.misc.superseded import deprecation
28
+
29
+ lazy_import('sage.rings.complex_double', 'CDF')
30
+ lazy_import('sage.rings.real_double', ['RDF', 'RealDoubleElement'])
31
+ lazy_import('sage.rings.integer_ring', 'ZZ')
32
+ lazy_import('sage.rings.integer', 'Integer')
33
+
34
+ ##############################################################################
35
+ # There are many functions on elements of a ring, which mathematicians
36
+ # usually write f(x), e.g., it is weird to write x.log() and natural
37
+ # to write log(x). The functions below allow for the more familiar syntax.
38
+ ##############################################################################
39
+
40
+
41
+ def additive_order(x):
42
+ """
43
+ Return the additive order of ``x``.
44
+
45
+ EXAMPLES::
46
+
47
+ sage: additive_order(5)
48
+ +Infinity
49
+ sage: additive_order(Mod(5,11))
50
+ 11
51
+ sage: additive_order(Mod(4,12))
52
+ 3
53
+ """
54
+ return x.additive_order()
55
+
56
+
57
+ def base_ring(x):
58
+ """
59
+ Return the base ring over which ``x`` is defined.
60
+
61
+ EXAMPLES::
62
+
63
+ sage: R = PolynomialRing(GF(7), 'x')
64
+ sage: base_ring(R)
65
+ Finite Field of size 7
66
+ """
67
+ return x.base_ring()
68
+
69
+
70
+ def base_field(x):
71
+ """
72
+ Return the base field over which ``x`` is defined.
73
+
74
+ EXAMPLES::
75
+
76
+ sage: R = PolynomialRing(GF(7), 'x')
77
+ sage: base_ring(R)
78
+ Finite Field of size 7
79
+ sage: base_field(R)
80
+ Finite Field of size 7
81
+
82
+ This catches base rings which are fields as well, but does
83
+ not implement a ``base_field`` method for objects which do
84
+ not have one::
85
+
86
+ sage: R.base_field()
87
+ Traceback (most recent call last):
88
+ ...
89
+ AttributeError: 'PolynomialRing_dense_mod_p_with_category' object has no attribute 'base_field'...
90
+ """
91
+ try:
92
+ return x.base_field()
93
+ except AttributeError:
94
+ y = x.base_ring()
95
+ if y.is_field():
96
+ return y
97
+ else:
98
+ raise AttributeError("The base ring of %s is not a field" % x)
99
+
100
+
101
+ def basis(x):
102
+ """
103
+ Return the fixed basis of ``x``.
104
+
105
+ EXAMPLES::
106
+
107
+ sage: V = VectorSpace(QQ, 3) # needs sage.modules
108
+ sage: S = V.subspace([[1,2,0], [2,2,-1]]) # needs sage.modules
109
+ sage: basis(S) # needs sage.modules
110
+ [(1, 0, -1), (0, 1, 1/2)]
111
+ """
112
+ return x.basis()
113
+
114
+
115
+ def category(x):
116
+ """
117
+ Return the category of ``x``.
118
+
119
+ EXAMPLES::
120
+
121
+ sage: V = VectorSpace(QQ, 3) # needs sage.modules
122
+ sage: category(V) # needs sage.modules
123
+ Category of finite dimensional vector spaces with basis over
124
+ (number fields and quotient fields and metric spaces)
125
+ """
126
+ try:
127
+ return x.category()
128
+ except AttributeError:
129
+ from sage.categories.objects import Objects
130
+ return Objects()
131
+
132
+
133
+ def characteristic_polynomial(x, var='x'):
134
+ """
135
+ Return the characteristic polynomial of ``x`` in the given variable.
136
+
137
+ EXAMPLES::
138
+
139
+ sage: # needs sage.libs.pari sage.modules
140
+ sage: M = MatrixSpace(QQ, 3, 3)
141
+ sage: A = M([1,2,3,4,5,6,7,8,9])
142
+ sage: charpoly(A)
143
+ x^3 - 15*x^2 - 18*x
144
+ sage: charpoly(A, 't')
145
+ t^3 - 15*t^2 - 18*t
146
+
147
+ sage: k.<alpha> = GF(7^10); k # needs sage.rings.finite_rings
148
+ Finite Field in alpha of size 7^10
149
+ sage: alpha.charpoly('T') # needs sage.rings.finite_rings
150
+ T^10 + T^6 + T^5 + 4*T^4 + T^3 + 2*T^2 + 3*T + 3
151
+ sage: characteristic_polynomial(alpha, 'T') # needs sage.rings.finite_rings
152
+ T^10 + T^6 + T^5 + 4*T^4 + T^3 + 2*T^2 + 3*T + 3
153
+
154
+ Ensure the variable name of the polynomial does not conflict with
155
+ variables used within the matrix, and that non-integral powers of
156
+ variables do not confuse the computation (:issue:`14403`)::
157
+
158
+ sage: # needs sage.libs.pari sage.symbolic
159
+ sage: y = var('y')
160
+ sage: a = matrix([[x,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]])
161
+ sage: characteristic_polynomial(a).list()
162
+ [x, -3*x - 1, 3*x + 3, -x - 3, 1]
163
+ sage: b = matrix([[y^(1/2),0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]])
164
+ sage: charpoly(b).list()
165
+ [sqrt(y), -3*sqrt(y) - 1, 3*sqrt(y) + 3, -sqrt(y) - 3, 1]
166
+ """
167
+ try:
168
+ return x.charpoly(var)
169
+ except AttributeError:
170
+ raise NotImplementedError("computation of charpoly of M (={}) not implemented".format(x))
171
+
172
+
173
+ charpoly = characteristic_polynomial
174
+
175
+
176
+ def coerce(P, x):
177
+ """
178
+ Coerce ``x`` to type ``P`` if possible.
179
+
180
+ EXAMPLES::
181
+
182
+ sage: type(5)
183
+ <class 'sage.rings.integer.Integer'>
184
+ sage: type(coerce(QQ,5))
185
+ <class 'sage.rings.rational.Rational'>
186
+ """
187
+ try:
188
+ return P.coerce(x)
189
+ except AttributeError:
190
+ return P(x)
191
+
192
+
193
+ def cyclotomic_polynomial(n, var='x'):
194
+ """
195
+ Return the `n`-th cyclotomic polynomial.
196
+
197
+ EXAMPLES::
198
+
199
+ sage: # needs sage.libs.pari
200
+ sage: cyclotomic_polynomial(3)
201
+ x^2 + x + 1
202
+ sage: cyclotomic_polynomial(4)
203
+ x^2 + 1
204
+ sage: cyclotomic_polynomial(9)
205
+ x^6 + x^3 + 1
206
+ sage: cyclotomic_polynomial(10)
207
+ x^4 - x^3 + x^2 - x + 1
208
+ sage: cyclotomic_polynomial(11)
209
+ x^10 + x^9 + x^8 + x^7 + x^6 + x^5 + x^4 + x^3 + x^2 + x + 1
210
+ """
211
+ return ZZ[var].cyclotomic_polynomial(n)
212
+
213
+
214
+ def decomposition(x):
215
+ """
216
+ Return the decomposition of ``x``.
217
+
218
+ EXAMPLES::
219
+
220
+ sage: M = matrix([[2, 3], [3, 4]]) # needs sage.libs.pari sage.modules
221
+ sage: M.decomposition() # needs sage.libs.pari sage.modules
222
+ [(Ambient free module of rank 2 over the principal ideal domain Integer Ring,
223
+ True)]
224
+
225
+ sage: # needs sage.schemes
226
+ sage: G.<a,b> = DirichletGroup(20)
227
+ sage: c = a * b
228
+ sage: d = c.decomposition(); d
229
+ [Dirichlet character modulo 4 of conductor 4 mapping 3 |--> -1,
230
+ Dirichlet character modulo 5 of conductor 5 mapping 2 |--> zeta4]
231
+ sage: d[0].parent()
232
+ Group of Dirichlet characters modulo 4
233
+ with values in Cyclotomic Field of order 4 and degree 2
234
+ """
235
+ return x.decomposition()
236
+
237
+
238
+ def denominator(x):
239
+ """
240
+ Return the denominator of ``x``.
241
+
242
+ EXAMPLES::
243
+
244
+ sage: denominator(17/11111)
245
+ 11111
246
+ sage: R.<x> = PolynomialRing(QQ)
247
+ sage: F = FractionField(R)
248
+ sage: r = (x+1)/(x-1)
249
+ sage: denominator(r)
250
+ x - 1
251
+ """
252
+ if isinstance(x, int):
253
+ return 1
254
+ return x.denominator()
255
+
256
+
257
+ def det(x):
258
+ """
259
+ Return the determinant of ``x``.
260
+
261
+ EXAMPLES::
262
+
263
+ sage: M = MatrixSpace(QQ, 3, 3) # needs sage.modules
264
+ sage: A = M([1,2,3, 4,5,6, 7,8,9]) # needs sage.modules
265
+ sage: det(A) # needs sage.modules
266
+ 0
267
+ """
268
+ return x.det()
269
+
270
+
271
+ def dimension(x):
272
+ """
273
+ Return the dimension of ``x``.
274
+
275
+ EXAMPLES::
276
+
277
+ sage: V = VectorSpace(QQ, 3) # needs sage.modules
278
+ sage: S = V.subspace([[1,2,0], [2,2,-1]]) # needs sage.modules
279
+ sage: dimension(S) # needs sage.modules
280
+ 2
281
+ """
282
+ return x.dimension()
283
+
284
+
285
+ dim = dimension
286
+
287
+
288
+ def discriminant(x):
289
+ """
290
+ Return the discriminant of ``x``.
291
+
292
+ EXAMPLES::
293
+
294
+ sage: R.<x> = PolynomialRing(QQ)
295
+ sage: S = R.quotient(x^29 - 17*x - 1, 'alpha') # needs sage.libs.pari
296
+ sage: K = S.number_field() # needs sage.libs.pari sage.rings.number_field
297
+ sage: discriminant(K) # needs sage.libs.pari sage.rings.number_field
298
+ -15975100446626038280218213241591829458737190477345113376757479850566957249523
299
+ """
300
+ return x.discriminant()
301
+
302
+
303
+ disc = discriminant
304
+
305
+
306
+ def eta(x):
307
+ r"""
308
+ Return the value of the `\eta` function at ``x``, which must be
309
+ in the upper half plane.
310
+
311
+ The `\eta` function is
312
+
313
+ .. MATH::
314
+
315
+ \eta(z) = e^{\pi i z / 12} \prod_{n=1}^{\infty}(1-e^{2\pi inz})
316
+
317
+ EXAMPLES::
318
+
319
+ sage: eta(1 + I) # needs sage.symbolic
320
+ 0.7420487758365647 + 0.1988313702299107*I
321
+ """
322
+ try:
323
+ return x.eta()
324
+ except AttributeError:
325
+ return CDF(x).eta()
326
+
327
+
328
+ def fcp(x, var='x'):
329
+ """
330
+ Return the factorization of the characteristic polynomial of ``x``.
331
+
332
+ EXAMPLES::
333
+
334
+ sage: M = MatrixSpace(QQ, 3, 3) # needs sage.modules
335
+ sage: A = M([1,2,3, 4,5,6, 7,8,9]) # needs sage.modules
336
+ sage: fcp(A, 'x') # needs sage.libs.pari sage.modules
337
+ x * (x^2 - 15*x - 18)
338
+ """
339
+ try:
340
+ return x.fcp(var)
341
+ except AttributeError:
342
+ return charpoly(x, var).factor()
343
+
344
+
345
+ def gen(x):
346
+ """
347
+ Return the generator of ``x``.
348
+
349
+ EXAMPLES::
350
+
351
+ sage: R.<x> = QQ[]; R
352
+ Univariate Polynomial Ring in x over Rational Field
353
+ sage: gen(R)
354
+ x
355
+ sage: gen(GF(7))
356
+ 1
357
+ sage: A = AbelianGroup(1, [23]) # needs sage.modules
358
+ sage: gen(A) # needs sage.modules
359
+ f
360
+ """
361
+ return x.gen()
362
+
363
+
364
+ def gens(x):
365
+ """
366
+ Return the generators of ``x``.
367
+
368
+ EXAMPLES::
369
+
370
+ sage: R.<x,y> = SR[] # needs sage.symbolic
371
+ sage: R # needs sage.symbolic
372
+ Multivariate Polynomial Ring in x, y over Symbolic Ring
373
+ sage: gens(R) # needs sage.symbolic
374
+ (x, y)
375
+
376
+ sage: A = AbelianGroup(5, [5,5,7,8,9]) # needs sage.modules
377
+ sage: gens(A) # needs sage.modules
378
+ (f0, f1, f2, f3, f4)
379
+ """
380
+ return x.gens()
381
+
382
+
383
+ def hecke_operator(x, n):
384
+ r"""
385
+ Return the `n`-th Hecke operator `T_n` acting on ``x``.
386
+
387
+ EXAMPLES::
388
+
389
+ sage: M = ModularSymbols(1,12) # needs sage.modular
390
+ sage: hecke_operator(M,5) # needs sage.modular
391
+ Hecke operator T_5 on Modular Symbols space of dimension 3 for Gamma_0(1)
392
+ of weight 12 with sign 0 over Rational Field
393
+ """
394
+ return x.hecke_operator(n)
395
+
396
+
397
+ def image(x):
398
+ """
399
+ Return the image of ``x``.
400
+
401
+ EXAMPLES::
402
+
403
+ sage: M = MatrixSpace(QQ, 3, 3) # needs sage.modules
404
+ sage: A = M([1,2,3, 4,5,6, 7,8,9]) # needs sage.modules
405
+ sage: image(A) # needs sage.modules
406
+ Vector space of degree 3 and dimension 2 over Rational Field
407
+ Basis matrix:
408
+ [ 1 0 -1]
409
+ [ 0 1 2]
410
+ """
411
+ return x.image()
412
+
413
+
414
+ def symbolic_sum(expression, *args, **kwds):
415
+ r"""
416
+ Return the symbolic sum `\sum_{v = a}^b expression` with respect
417
+ to the variable `v` with endpoints `a` and `b`.
418
+
419
+ INPUT:
420
+
421
+ - ``expression`` -- a symbolic expression
422
+
423
+ - ``v`` -- a variable or variable name
424
+
425
+ - ``a`` -- lower endpoint of the sum
426
+
427
+ - ``b`` -- upper endpoint of the sum
428
+
429
+ - ``algorithm`` -- (default: ``'maxima'``) one of
430
+
431
+ - ``'maxima'`` -- use Maxima (the default)
432
+
433
+ - ``'maple'`` -- (optional) use Maple
434
+
435
+ - ``'mathematica'`` -- (optional) use Mathematica
436
+
437
+ - ``'giac'`` -- (optional) use Giac
438
+
439
+ - ``'sympy'`` -- use SymPy
440
+
441
+ EXAMPLES::
442
+
443
+ sage: k, n = var('k,n') # needs sage.symbolic
444
+ sage: sum(k, k, 1, n).factor() # needs sage.symbolic
445
+ 1/2*(n + 1)*n
446
+
447
+ ::
448
+
449
+ sage: sum(1/k^4, k, 1, oo) # needs sage.symbolic
450
+ 1/90*pi^4
451
+
452
+ ::
453
+
454
+ sage: sum(1/k^5, k, 1, oo) # needs sage.symbolic
455
+ zeta(5)
456
+
457
+ .. WARNING::
458
+
459
+ This function only works with symbolic expressions. To sum any
460
+ other objects like list elements or function return values,
461
+ please use python summation, see
462
+ http://docs.python.org/library/functions.html#sum
463
+
464
+ In particular, this does not work::
465
+
466
+ sage: n = var('n') # needs sage.symbolic
467
+ sage: mylist = [1,2,3,4,5]
468
+ sage: sum(mylist[n], n, 0, 3) # needs sage.symbolic
469
+ Traceback (most recent call last):
470
+ ...
471
+ TypeError: unable to convert n to an integer
472
+
473
+ Use python ``sum()`` instead::
474
+
475
+ sage: sum(mylist[n] for n in range(4))
476
+ 10
477
+
478
+ Also, only a limited number of functions are recognized in symbolic sums::
479
+
480
+ sage: sum(valuation(n, 2), n, 1, 5) # needs sage.symbolic
481
+ Traceback (most recent call last):
482
+ ...
483
+ TypeError: unable to convert n to an integer
484
+
485
+ Again, use python ``sum()``::
486
+
487
+ sage: sum(valuation(n + 1, 2) for n in range(5))
488
+ 3
489
+
490
+ (now back to the Sage ``sum`` examples)
491
+
492
+ A well known binomial identity::
493
+
494
+ sage: sum(binomial(n, k), k, 0, n) # needs sage.symbolic
495
+ 2^n
496
+
497
+ The binomial theorem::
498
+
499
+ sage: x, y = var('x, y') # needs sage.symbolic
500
+ sage: sum(binomial(n, k) * x^k * y^(n-k), k, 0, n) # needs sage.symbolic
501
+ (x + y)^n
502
+
503
+ ::
504
+
505
+ sage: sum(k * binomial(n, k), k, 1, n) # needs sage.symbolic
506
+ 2^(n - 1)*n
507
+
508
+ ::
509
+
510
+ sage: sum((-1)^k * binomial(n, k), k, 0, n) # needs sage.symbolic
511
+ 0
512
+
513
+ ::
514
+
515
+ sage: sum(2^(-k)/(k*(k+1)), k, 1, oo) # needs sage.symbolic
516
+ -log(2) + 1
517
+
518
+ Another binomial identity (:issue:`7952`)::
519
+
520
+ sage: t, k, i = var('t,k,i') # needs sage.symbolic
521
+ sage: sum(binomial(i + t, t), i, 0, k) # needs sage.symbolic
522
+ binomial(k + t + 1, t + 1)
523
+
524
+ Summing a hypergeometric term::
525
+
526
+ sage: sum(binomial(n, k) * factorial(k) / factorial(n+1+k), k, 0, n) # needs sage.symbolic
527
+ 1/2*sqrt(pi)/factorial(n + 1/2)
528
+
529
+ We check a well known identity::
530
+
531
+ sage: bool(sum(k^3, k, 1, n) == sum(k, k, 1, n)^2) # needs sage.symbolic
532
+ True
533
+
534
+ A geometric sum::
535
+
536
+ sage: a, q = var('a, q') # needs sage.symbolic
537
+ sage: sum(a*q^k, k, 0, n) # needs sage.symbolic
538
+ (a*q^(n + 1) - a)/(q - 1)
539
+
540
+ The geometric series::
541
+
542
+ sage: assume(abs(q) < 1) # needs sage.symbolic
543
+ sage: sum(a * q^k, k, 0, oo) # needs sage.symbolic
544
+ -a/(q - 1)
545
+
546
+ A divergent geometric series. Don't forget
547
+ to forget your assumptions::
548
+
549
+ sage: forget() # needs sage.symbolic
550
+ sage: assume(q > 1) # needs sage.symbolic
551
+ sage: sum(a * q^k, k, 0, oo) # needs sage.symbolic
552
+ Traceback (most recent call last):
553
+ ...
554
+ ValueError: Sum is divergent.
555
+
556
+ This summation only Mathematica can perform::
557
+
558
+ sage: sum(1/(1+k^2), k, -oo, oo, algorithm='mathematica') # optional - mathematica, needs sage.symbolic
559
+ pi*coth(pi)
560
+
561
+ Use Maple as a backend for summation::
562
+
563
+ sage: sum(binomial(n, k) * x^k, k, 0, n, algorithm='maple') # optional - maple, needs sage.symbolic
564
+ (x + 1)^n
565
+
566
+ Python ints should work as limits of summation (:issue:`9393`)::
567
+
568
+ sage: sum(x, x, 1r, 5r) # needs sage.symbolic
569
+ 15
570
+
571
+ .. NOTE::
572
+
573
+ #. Sage can currently only understand a subset of the output of Maxima, Maple and
574
+ Mathematica, so even if the chosen backend can perform the summation the
575
+ result might not be convertible into a Sage expression.
576
+
577
+ TESTS:
578
+
579
+ Check that :issue:`34007` is fixed::
580
+
581
+ sage: sum([1, 2], start=1)
582
+ 4
583
+ sage: sum([[1], [2]], start=[])
584
+ [1, 2]
585
+ """
586
+ if hasattr(expression, 'sum'):
587
+ return expression.sum(*args, **kwds)
588
+ if max(len(args), len(kwds)) <= 1:
589
+ return sum(expression, *args, **kwds)
590
+ from sage.symbolic.ring import SR
591
+ return SR(expression).sum(*args, **kwds)
592
+
593
+
594
+ def symbolic_prod(expression, *args, **kwds):
595
+ r"""
596
+ Return the symbolic product `\prod_{v = a}^b expression` with respect
597
+ to the variable `v` with endpoints `a` and `b`.
598
+
599
+ INPUT:
600
+
601
+ - ``expression`` -- a symbolic expression
602
+
603
+ - ``v`` -- a variable or variable name
604
+
605
+ - ``a`` -- lower endpoint of the product
606
+
607
+ - ``b`` -- upper endpoint of the prduct
608
+
609
+ - ``algorithm`` -- (default: ``'maxima'``) one of
610
+
611
+ - ``'maxima'`` -- use Maxima (the default)
612
+
613
+ - ``'giac'`` -- (optional) use Giac
614
+
615
+ - ``'sympy'`` -- use SymPy
616
+
617
+ - ``hold`` -- boolean (default: ``False``); if ``True`` don't evaluate
618
+
619
+ EXAMPLES::
620
+
621
+ sage: # needs sage.symbolic
622
+ sage: i, k, n = var('i,k,n')
623
+ sage: product(k, k, 1, n)
624
+ factorial(n)
625
+ sage: product(x + i*(i+1)/2, i, 1, 4)
626
+ x^4 + 20*x^3 + 127*x^2 + 288*x + 180
627
+ sage: product(i^2, i, 1, 7)
628
+ 25401600
629
+ sage: f = function('f')
630
+ sage: product(f(i), i, 1, 7)
631
+ f(7)*f(6)*f(5)*f(4)*f(3)*f(2)*f(1)
632
+ sage: product(f(i), i, 1, n)
633
+ product(f(i), i, 1, n)
634
+ sage: assume(k>0)
635
+ sage: product(integrate(x^k, x, 0, 1), k, 1, n)
636
+ 1/factorial(n + 1)
637
+ sage: product(f(i), i, 1, n).log().log_expand()
638
+ sum(log(f(i)), i, 1, n)
639
+ """
640
+ from .misc_c import prod as c_prod
641
+ if hasattr(expression, 'prod'):
642
+ return expression.prod(*args, **kwds)
643
+ elif len(args) <= 1:
644
+ return c_prod(expression, *args)
645
+ else:
646
+ from sage.symbolic.ring import SR
647
+ return SR(expression).prod(*args, **kwds)
648
+
649
+
650
+ def integral(x, *args, **kwds):
651
+ """
652
+ Return an indefinite or definite integral of an object ``x``.
653
+
654
+ First call ``x.integral()`` and if that fails make an object and
655
+ integrate it using Maxima, maple, etc, as specified by algorithm.
656
+
657
+ For symbolic expression calls
658
+ :func:`sage.calculus.calculus.integral` - see this function for
659
+ available options.
660
+
661
+ EXAMPLES::
662
+
663
+ sage: f = cyclotomic_polynomial(10)
664
+ sage: integral(f)
665
+ 1/5*x^5 - 1/4*x^4 + 1/3*x^3 - 1/2*x^2 + x
666
+
667
+ ::
668
+
669
+ sage: integral(sin(x), x) # needs sage.symbolic
670
+ -cos(x)
671
+
672
+ ::
673
+
674
+ sage: y = var('y') # needs sage.symbolic
675
+ sage: integral(sin(x), y) # needs sage.symbolic
676
+ y*sin(x)
677
+
678
+ ::
679
+
680
+ sage: integral(sin(x), x, 0, pi/2) # needs sage.symbolic
681
+ 1
682
+ sage: sin(x).integral(x, 0, pi/2) # needs sage.symbolic
683
+ 1
684
+ sage: integral(exp(-x), (x, 1, oo)) # needs sage.symbolic
685
+ e^(-1)
686
+
687
+ Numerical approximation::
688
+
689
+ sage: h = integral(tan(x)/x, (x, 1, pi/3)) # needs sage.symbolic
690
+ ...
691
+ sage: h # needs sage.symbolic
692
+ integrate(tan(x)/x, x, 1, 1/3*pi)
693
+ sage: h.n() # needs sage.symbolic
694
+ 0.07571599101...
695
+
696
+ Specific algorithm can be used for integration::
697
+
698
+ sage: integral(sin(x)^2, x, algorithm='maxima') # needs sage.symbolic
699
+ 1/2*x - 1/4*sin(2*x)
700
+ sage: integral(sin(x)^2, x, algorithm='sympy') # needs sage.symbolic
701
+ -1/2*cos(x)*sin(x) + 1/2*x
702
+
703
+ TESTS:
704
+
705
+ A symbolic integral from :issue:`11445` that was incorrect in
706
+ earlier versions of Maxima::
707
+
708
+ sage: f = abs(x - 1) + abs(x + 1) - 2*abs(x) # needs sage.symbolic
709
+ sage: integrate(f, (x, -Infinity, Infinity)) # needs sage.symbolic
710
+ 2
711
+
712
+ Another symbolic integral, from :issue:`11238`, that used to return
713
+ zero incorrectly; with Maxima 5.26.0 one gets
714
+ ``1/2*sqrt(pi)*e^(1/4)``, whereas with 5.29.1, and even more so
715
+ with 5.33.0, the expression is less pleasant, but still has the
716
+ same value. Unfortunately, the computation takes a very long time
717
+ with the default settings, so we temporarily use the Maxima
718
+ setting ``domain: real``::
719
+
720
+ sage: # needs sage.symbolic
721
+ sage: sage.calculus.calculus.maxima('domain: real')
722
+ real
723
+ sage: f = exp(-x) * sinh(sqrt(x))
724
+ sage: t = integrate(f, x, 0, Infinity); t # long time
725
+ 1/4*sqrt(pi)*(erf(1) - 1)*e^(1/4)
726
+ - 1/4*(sqrt(pi)*(erf(1) - 1) - sqrt(pi) + 2*e^(-1) - 2)*e^(1/4)
727
+ + 1/4*sqrt(pi)*e^(1/4) - 1/2*e^(1/4) + 1/2*e^(-3/4)
728
+ sage: t.canonicalize_radical() # long time
729
+ 1/2*sqrt(pi)*e^(1/4)
730
+ sage: sage.calculus.calculus.maxima('domain: complex')
731
+ complex
732
+
733
+ An integral which used to return -1 before maxima 5.28. See :issue:`12842`::
734
+
735
+ sage: f = e^(-2*x)/sqrt(1-e^(-2*x)) # needs sage.symbolic
736
+ sage: integrate(f, x, 0, infinity) # needs sage.symbolic
737
+ 1
738
+
739
+ This integral would cause a stack overflow in earlier versions of
740
+ Maxima, crashing sage. See :issue:`12377`. We don't care about the
741
+ result here, just that the computation completes successfully::
742
+
743
+ sage: y = (x^2)*exp(x) / (1 + exp(x))^2 # needs sage.symbolic
744
+ sage: _ = integrate(y, x, -1000, 1000) # needs sage.symbolic
745
+
746
+ When SymPy cannot solve an integral it gives it back, so we must
747
+ be able to convert SymPy's ``Integral`` (:issue:`14723`)::
748
+
749
+ sage: # needs sage.symbolic
750
+ sage: x, y, z = var('x,y,z')
751
+ sage: f = function('f')
752
+ sage: integrate(f(x), x, algorithm='sympy')
753
+ integrate(f(x), x)
754
+ sage: integrate(f(x), x, 0, 1, algorithm='sympy')
755
+ integrate(f(x), x, 0, 1)
756
+ sage: integrate(integrate(integrate(f(x,y,z), x, algorithm='sympy'),
757
+ ....: y, algorithm='sympy'),
758
+ ....: z, algorithm='sympy')
759
+ integrate(integrate(integrate(f(x, y, z), x), y), z)
760
+ sage: integrate(sin(x)*tan(x)/(1-cos(x)), x, algorithm='sympy')
761
+ -integrate(sin(x)*tan(x)/(cos(x) - 1), x)
762
+ sage: _ = var('a,b,x')
763
+ sage: integrate(sin(x)*tan(x)/(1-cos(x)), x, a, b, algorithm='sympy')
764
+ -integrate(sin(x)*tan(x)/(cos(x) - 1), x, a, b)
765
+
766
+ sage: # needs sympy
767
+ sage: import sympy
768
+ sage: x, y, z = sympy.symbols('x y z')
769
+ sage: f = sympy.Function('f')
770
+ sage: SR(sympy.Integral(f(x,y,z), x, y, z)) # needs sage.symbolic
771
+ integrate(integrate(integrate(f(x, y, z), x), y), z)
772
+
773
+ Ensure that the following integral containing a signum term from
774
+ :issue:`11590` can be integrated::
775
+
776
+ sage: x = SR.symbol('x', domain='real') # needs sage.symbolic
777
+ sage: result = integrate(x * sgn(x^2 - 1/4), x, -1, 0) # needs sage.symbolic
778
+ ...
779
+ sage: result # needs sage.symbolic
780
+ -1/4
781
+
782
+ Verify that :issue:`33034` is fixed::
783
+
784
+ sage: f(x) = (x + sin(3*x)) * exp(-3*x*I) # needs sage.symbolic
785
+ sage: h(x) = f(x) - f(x).expand() # needs sage.symbolic
786
+ sage: integral(h(x), (x, 0, 2*pi)) # needs sage.symbolic
787
+ 0
788
+ """
789
+ if hasattr(x, 'integral'):
790
+ return x.integral(*args, **kwds)
791
+ else:
792
+ from sage.symbolic.ring import SR
793
+ return SR(x).integral(*args, **kwds)
794
+
795
+
796
+ integrate = integral
797
+
798
+
799
+ def integral_closure(x):
800
+ """
801
+ Return the integral closure of ``x``.
802
+
803
+ EXAMPLES::
804
+
805
+ sage: integral_closure(QQ)
806
+ Rational Field
807
+ sage: K.<a> = QuadraticField(5) # needs sage.rings.number_field
808
+ sage: O2 = K.order(2 * a); O2 # needs sage.rings.number_field
809
+ Order of conductor 4 generated by 2*a in Number Field in a
810
+ with defining polynomial x^2 - 5 with a = 2.236067977499790?
811
+ sage: integral_closure(O2) # needs sage.rings.number_field
812
+ Maximal Order generated by 1/2*a + 1/2 in Number Field in a
813
+ with defining polynomial x^2 - 5 with a = 2.236067977499790?
814
+ """
815
+ return x.integral_closure()
816
+
817
+
818
+ def interval(a, b):
819
+ r"""
820
+ Integers between `a` and `b` *inclusive* (`a` and `b` integers).
821
+
822
+ EXAMPLES::
823
+
824
+ sage: I = interval(1,3)
825
+ sage: 2 in I
826
+ True
827
+ sage: 1 in I
828
+ True
829
+ sage: 4 in I
830
+ False
831
+ """
832
+ return list(range(a, b + 1))
833
+
834
+
835
+ def xinterval(a, b):
836
+ r"""
837
+ Iterator over the integers between `a` and `b`, *inclusive*.
838
+
839
+ EXAMPLES::
840
+
841
+ sage: I = xinterval(2,5); I
842
+ range(2, 6)
843
+ sage: 5 in I
844
+ True
845
+ sage: 6 in I
846
+ False
847
+ """
848
+ return range(a, b + 1)
849
+
850
+
851
+ def is_even(x):
852
+ """
853
+ Return whether or not an integer ``x`` is even, e.g., divisible by 2.
854
+
855
+ EXAMPLES::
856
+
857
+ sage: is_even(-1)
858
+ False
859
+ sage: is_even(4)
860
+ True
861
+ sage: is_even(-2)
862
+ True
863
+ """
864
+ try:
865
+ return x.is_even()
866
+ except AttributeError:
867
+ return x % 2 == 0
868
+
869
+
870
+ def is_odd(x):
871
+ """
872
+ Return whether or not ``x`` is odd.
873
+
874
+ This is by definition the complement of :func:`is_even`.
875
+
876
+ EXAMPLES::
877
+
878
+ sage: is_odd(-2)
879
+ False
880
+ sage: is_odd(-3)
881
+ True
882
+ sage: is_odd(0)
883
+ False
884
+ sage: is_odd(1)
885
+ True
886
+ """
887
+ return not is_even(x)
888
+
889
+
890
+ def kernel(x):
891
+ """
892
+ Return the left kernel of ``x``.
893
+
894
+ EXAMPLES::
895
+
896
+ sage: # needs sage.modules
897
+ sage: M = MatrixSpace(QQ, 3, 2)
898
+ sage: A = M([1,2, 3,4, 5,6])
899
+ sage: kernel(A)
900
+ Vector space of degree 3 and dimension 1 over Rational Field
901
+ Basis matrix:
902
+ [ 1 -2 1]
903
+ sage: kernel(A.transpose())
904
+ Vector space of degree 2 and dimension 0 over Rational Field
905
+ Basis matrix:
906
+ []
907
+
908
+ Here are two corner cases::
909
+
910
+ sage: # needs sage.modules
911
+ sage: M = MatrixSpace(QQ, 0, 3)
912
+ sage: A = M([])
913
+ sage: kernel(A)
914
+ Vector space of degree 0 and dimension 0 over Rational Field
915
+ Basis matrix:
916
+ []
917
+ sage: kernel(A.transpose()).basis()
918
+ [(1, 0, 0), (0, 1, 0), (0, 0, 1)]
919
+ """
920
+ return x.kernel()
921
+
922
+
923
+ def krull_dimension(x):
924
+ """
925
+ Return the Krull dimension of ``x``.
926
+
927
+ EXAMPLES::
928
+
929
+ sage: krull_dimension(QQ)
930
+ doctest:warning...:
931
+ DeprecationWarning: please use the krull_dimension method
932
+ See https://github.com/sagemath/sage/issues/39311 for details.
933
+ 0
934
+ sage: ZZ.krull_dimension()
935
+ 1
936
+ sage: ZZ[sqrt(5)].krull_dimension() # needs fpylll sage.rings.number_field sage.symbolic
937
+ 1
938
+ sage: U.<x,y,z> = PolynomialRing(ZZ, 3); U
939
+ Multivariate Polynomial Ring in x, y, z over Integer Ring
940
+ sage: U.krull_dimension()
941
+ 4
942
+ """
943
+ deprecation(39311, "please use the krull_dimension method")
944
+ return x.krull_dimension()
945
+
946
+
947
+ def lift(x):
948
+ """
949
+ Lift an object of a quotient ring `R/I` to `R`.
950
+
951
+ EXAMPLES:
952
+
953
+ We lift an integer modulo `3`::
954
+
955
+ sage: Mod(2,3).lift()
956
+ 2
957
+
958
+ We lift an element of a quotient polynomial ring::
959
+
960
+ sage: R.<x> = QQ['x']
961
+ sage: S.<xmod> = R.quo(x^2 + 1) # needs sage.libs.pari
962
+ sage: lift(xmod - 7) # needs sage.libs.pari
963
+ x - 7
964
+ """
965
+ try:
966
+ return x.lift()
967
+ except AttributeError:
968
+ raise ArithmeticError("no lift defined.")
969
+
970
+
971
+ def log(*args, **kwds):
972
+ """
973
+ Return the logarithm of the first argument to the base of
974
+ the second argument which if missing defaults to ``e``.
975
+
976
+ It calls the ``log`` method of the first argument when computing
977
+ the logarithm, thus allowing the use of logarithm on any object
978
+ containing a ``log`` method. In other words, ``log`` works
979
+ on more than just real numbers.
980
+
981
+ .. NOTE::
982
+
983
+ In Magma, the order of arguments is reversed from in Sage,
984
+ i.e., the base is given first. We use the opposite ordering, so
985
+ the base can be viewed as an optional second argument.
986
+
987
+ EXAMPLES::
988
+
989
+ sage: log(e^2) # needs sage.symbolic
990
+ 2
991
+
992
+ To change the base of the logarithm, add a second parameter::
993
+
994
+ sage: log(1000,10)
995
+ 3
996
+
997
+ The synonym ``ln`` can only take one argument::
998
+
999
+ sage: # needs sage.symbolic
1000
+ sage: ln(RDF(10))
1001
+ 2.302585092994046
1002
+ sage: ln(2.718)
1003
+ 0.999896315728952
1004
+ sage: ln(2.0)
1005
+ 0.693147180559945
1006
+ sage: ln(float(-1))
1007
+ 3.141592653589793j
1008
+
1009
+ sage: ln(complex(-1))
1010
+ 3.141592653589793j
1011
+
1012
+ You can use
1013
+ :class:`RDF<sage.rings.real_double.RealDoubleField_class>`,
1014
+ :class:`~sage.rings.real_mpfr.RealField` or ``n`` to get a
1015
+ numerical real approximation::
1016
+
1017
+ sage: log(1024, 2)
1018
+ 10
1019
+ sage: RDF(log(1024, 2))
1020
+ 10.0
1021
+
1022
+ sage: # needs sage.symbolic
1023
+ sage: log(10, 4)
1024
+ 1/2*log(10)/log(2)
1025
+ sage: RDF(log(10, 4))
1026
+ 1.6609640474436813
1027
+ sage: log(10, 2)
1028
+ log(10)/log(2)
1029
+ sage: n(log(10, 2))
1030
+ 3.32192809488736
1031
+ sage: log(10, e)
1032
+ log(10)
1033
+ sage: n(log(10, e))
1034
+ 2.30258509299405
1035
+
1036
+ The log function works for negative numbers, complex
1037
+ numbers, and symbolic numbers too, picking the branch
1038
+ with angle between `-\\pi` and `\\pi`::
1039
+
1040
+ sage: log(-1+0*I) # needs sage.symbolic
1041
+ I*pi
1042
+ sage: log(CC(-1)) # needs sage.rings.real_mpfr
1043
+ 3.14159265358979*I
1044
+ sage: log(-1.0) # needs sage.symbolic
1045
+ 3.14159265358979*I
1046
+
1047
+ Small integer powers are factored out immediately::
1048
+
1049
+ sage: # needs sage.symbolic
1050
+ sage: log(4)
1051
+ 2*log(2)
1052
+ sage: log(1000000000)
1053
+ 9*log(10)
1054
+ sage: log(8) - 3*log(2)
1055
+ 0
1056
+ sage: bool(log(8) == 3*log(2))
1057
+ True
1058
+
1059
+ The ``hold`` parameter can be used to prevent automatic evaluation::
1060
+
1061
+ sage: # needs sage.symbolic
1062
+ sage: log(-1, hold=True)
1063
+ log(-1)
1064
+ sage: log(-1)
1065
+ I*pi
1066
+ sage: I.log(hold=True)
1067
+ log(I)
1068
+ sage: I.log(hold=True).simplify()
1069
+ 1/2*I*pi
1070
+
1071
+ For input zero, the following behavior occurs::
1072
+
1073
+ sage: log(0) # needs sage.symbolic
1074
+ -Infinity
1075
+ sage: log(CC(0)) # needs sage.rings.real_mpfr
1076
+ -infinity
1077
+ sage: log(0.0) # needs sage.symbolic
1078
+ -infinity
1079
+
1080
+ The log function also works in finite fields as long as the
1081
+ argument lies in the multiplicative group generated by the base::
1082
+
1083
+ sage: # needs sage.libs.pari
1084
+ sage: F = GF(13); g = F.multiplicative_generator(); g
1085
+ 2
1086
+ sage: a = F(8)
1087
+ sage: log(a, g); g^log(a, g)
1088
+ 3
1089
+ 8
1090
+ sage: log(a, 3)
1091
+ Traceback (most recent call last):
1092
+ ...
1093
+ ValueError: no logarithm of 8 found to base 3 modulo 13
1094
+ sage: log(F(9), 3)
1095
+ 2
1096
+
1097
+ The log function also works for `p`-adics (see documentation for
1098
+ `p`-adics for more information)::
1099
+
1100
+ sage: R = Zp(5); R # needs sage.rings.padics
1101
+ 5-adic Ring with capped relative precision 20
1102
+ sage: a = R(16); a # needs sage.rings.padics
1103
+ 1 + 3*5 + O(5^20)
1104
+ sage: log(a) # needs sage.rings.padics
1105
+ 3*5 + 3*5^2 + 3*5^4 + 3*5^5 + 3*5^6 + 4*5^7 + 2*5^8 + 5^9 +
1106
+ 5^11 + 2*5^12 + 5^13 + 3*5^15 + 2*5^16 + 4*5^17 + 3*5^18 +
1107
+ 3*5^19 + O(5^20)
1108
+
1109
+
1110
+ TESTS:
1111
+
1112
+ Check if :issue:`10136` is fixed::
1113
+
1114
+ sage: ln(x).operator() is ln # needs sage.symbolic
1115
+ True
1116
+ sage: log(x).operator() is ln # needs sage.symbolic
1117
+ True
1118
+
1119
+ sage: log(1000, 10)
1120
+ 3
1121
+ sage: log(3, -1) # needs sage.symbolic
1122
+ -I*log(3)/pi
1123
+ sage: log(int(8), 2) # needs sage.symbolic
1124
+ 3
1125
+ sage: log(8, int(2))
1126
+ 3
1127
+ sage: log(8, 2)
1128
+ 3
1129
+ sage: log(1/8, 2)
1130
+ -3
1131
+ sage: log(1/8, 1/2)
1132
+ 3
1133
+ sage: log(8, 1/2)
1134
+ -3
1135
+
1136
+ sage: log(1000, 10, base=5)
1137
+ Traceback (most recent call last):
1138
+ ...
1139
+ TypeError: log takes at most 2 arguments (3 given)
1140
+
1141
+ Check if :issue:`29164` is fixed::
1142
+
1143
+ sage: log(0, 2)
1144
+ -Infinity
1145
+
1146
+ Check if :issue:`37794` is fixed::
1147
+
1148
+ sage: log(int(0), 2) # needs sage.symbolic
1149
+ -Infinity
1150
+ sage: log(int(0), 1/2) # needs sage.symbolic
1151
+ +Infinity
1152
+
1153
+ Check if sub-issue detailed in :issue:`38971` is fixed::
1154
+
1155
+ sage: log(6, base=0) # needs sage.symbolic
1156
+ 0
1157
+ sage: log(e, base=0) # needs sage.symbolic
1158
+ 0
1159
+ """
1160
+ base = kwds.pop('base', None)
1161
+ if base is not None:
1162
+ args = args + (base,)
1163
+ if not args:
1164
+ raise TypeError("log takes at least 1 arguments (0 given)")
1165
+ if len(args) == 1:
1166
+ from sage.functions.log import ln
1167
+ return ln(args[0], **kwds)
1168
+ if len(args) > 2:
1169
+ raise TypeError("log takes at most 2 arguments (%s given)" % (len(args) + 1 - (base is not None)))
1170
+ try:
1171
+ return args[0].log(args[1])
1172
+ except ValueError as ex:
1173
+ if ex.args[0].startswith("no logarithm"):
1174
+ raise
1175
+ except (AttributeError, TypeError):
1176
+ pass
1177
+ from sage.functions.log import logb
1178
+ return logb(args[0], args[1])
1179
+
1180
+
1181
+ def minimal_polynomial(x, var='x'):
1182
+ """
1183
+ Return the minimal polynomial of ``x``.
1184
+
1185
+ EXAMPLES::
1186
+
1187
+ sage: # needs sage.libs.pari sage.modules
1188
+ sage: a = matrix(ZZ, 2, [1..4])
1189
+ sage: minpoly(a)
1190
+ x^2 - 5*x - 2
1191
+ sage: minpoly(a, 't')
1192
+ t^2 - 5*t - 2
1193
+ sage: minimal_polynomial(a)
1194
+ x^2 - 5*x - 2
1195
+ sage: minimal_polynomial(a, 'theta')
1196
+ theta^2 - 5*theta - 2
1197
+ """
1198
+ try:
1199
+ return x.minpoly(var=var)
1200
+ except AttributeError:
1201
+ return x.minimal_polynomial(var=var)
1202
+
1203
+
1204
+ minpoly = minimal_polynomial
1205
+
1206
+
1207
+ def multiplicative_order(x):
1208
+ r"""
1209
+ Return the multiplicative order of ``x``, if ``x`` is a unit, or
1210
+ raise :exc:`ArithmeticError` otherwise.
1211
+
1212
+ EXAMPLES::
1213
+
1214
+ sage: a = mod(5, 11)
1215
+ sage: multiplicative_order(a) # needs sage.libs.pari
1216
+ 5
1217
+ sage: multiplicative_order(mod(2, 11)) # needs sage.libs.pari
1218
+ 10
1219
+ sage: multiplicative_order(mod(2, 12)) # needs sage.libs.pari
1220
+ Traceback (most recent call last):
1221
+ ...
1222
+ ArithmeticError: multiplicative order of 2 not defined since it is not a unit modulo 12
1223
+ """
1224
+ return x.multiplicative_order()
1225
+
1226
+
1227
+ def ngens(x):
1228
+ """
1229
+ Return the number of generators of ``x``.
1230
+
1231
+ EXAMPLES::
1232
+
1233
+ sage: R.<x,y> = SR[]; R # needs sage.symbolic
1234
+ Multivariate Polynomial Ring in x, y over Symbolic Ring
1235
+ sage: ngens(R) # needs sage.symbolic
1236
+ 2
1237
+ sage: A = AbelianGroup(5, [5,5,7,8,9]) # needs sage.modules
1238
+ sage: ngens(A) # needs sage.modules
1239
+ 5
1240
+ sage: ngens(ZZ)
1241
+ 1
1242
+ """
1243
+ return x.ngens()
1244
+
1245
+
1246
+ def norm(x):
1247
+ r"""
1248
+ Return the norm of ``x``.
1249
+
1250
+ For matrices and vectors, this returns the L2-norm. The L2-norm of a
1251
+ vector `\textbf{v} = (v_1, v_2, \dots, v_n)`, also called the Euclidean
1252
+ norm, is defined as
1253
+
1254
+ .. MATH::
1255
+
1256
+ |\textbf{v}|
1257
+ =
1258
+ \sqrt{\sum_{i=1}^n |v_i|^2}
1259
+
1260
+ where `|v_i|` is the complex modulus of `v_i`. The Euclidean norm is often
1261
+ used for determining the distance between two points in two- or
1262
+ three-dimensional space.
1263
+
1264
+ For complex numbers, the function returns the field norm. If
1265
+ `c = a + bi` is a complex number, then the norm of `c` is defined as the
1266
+ product of `c` and its complex conjugate:
1267
+
1268
+ .. MATH::
1269
+
1270
+ \text{norm}(c)
1271
+ =
1272
+ \text{norm}(a + bi)
1273
+ =
1274
+ c \cdot \overline{c}
1275
+ =
1276
+ a^2 + b^2.
1277
+
1278
+ The norm of a complex number is different from its absolute value.
1279
+ The absolute value of a complex number is defined to be the square
1280
+ root of its norm. A typical use of the complex norm is in the
1281
+ integral domain `\ZZ[i]` of Gaussian integers, where the norm of
1282
+ each Gaussian integer `c = a + bi` is defined as its complex norm.
1283
+
1284
+ For vector fields on a pseudo-Riemannian manifold `(M,g)`, the function
1285
+ returns the norm with respect to the metric `g`:
1286
+
1287
+ .. MATH::
1288
+
1289
+ |v| = \sqrt{g(v,v)}
1290
+
1291
+ .. SEEALSO::
1292
+
1293
+ - :meth:`sage.matrix.matrix2.Matrix.norm`
1294
+
1295
+ - :meth:`sage.modules.free_module_element.FreeModuleElement.norm`
1296
+
1297
+ - :meth:`sage.rings.complex_double.ComplexDoubleElement.norm`
1298
+
1299
+ - :meth:`sage.rings.complex_mpfr.ComplexNumber.norm`
1300
+
1301
+ - :meth:`sage.symbolic.expression.Expression.norm`
1302
+
1303
+ - :meth:`sage.manifolds.differentiable.vectorfield.VectorField.norm`
1304
+
1305
+ EXAMPLES:
1306
+
1307
+ The norm of vectors::
1308
+
1309
+ sage: # needs sage.modules sage.symbolic
1310
+ sage: z = 1 + 2*I
1311
+ sage: norm(vector([z]))
1312
+ sqrt(5)
1313
+ sage: v = vector([-1,2,3])
1314
+ sage: norm(v)
1315
+ sqrt(14)
1316
+ sage: _ = var("a b c d", domain='real')
1317
+ sage: v = vector([a, b, c, d])
1318
+ sage: norm(v)
1319
+ sqrt(a^2 + b^2 + c^2 + d^2)
1320
+
1321
+ The norm of matrices::
1322
+
1323
+ sage: # needs scipy sage.modules sage.symbolic
1324
+ sage: z = 1 + 2*I
1325
+ sage: norm(matrix([[z]]))
1326
+ 2.23606797749979
1327
+ sage: M = matrix(ZZ, [[1,2,4,3], [-1,0,3,-10]])
1328
+ sage: norm(M) # abs tol 1e-14
1329
+ 10.690331129154467
1330
+ sage: norm(CDF(z))
1331
+ 5.0
1332
+ sage: norm(CC(z))
1333
+ 5.00000000000000
1334
+
1335
+ The norm of complex numbers::
1336
+
1337
+ sage: # needs sage.symbolic
1338
+ sage: z = 2 - 3*I
1339
+ sage: norm(z)
1340
+ 13
1341
+ sage: a = randint(-10^10, 100^10)
1342
+ sage: b = randint(-10^10, 100^10)
1343
+ sage: z = a + b*I
1344
+ sage: bool(norm(z) == a^2 + b^2)
1345
+ True
1346
+
1347
+ The complex norm of symbolic expressions::
1348
+
1349
+ sage: # needs sage.symbolic
1350
+ sage: a, b, c = var("a, b, c")
1351
+ sage: assume((a, 'real'), (b, 'real'), (c, 'real'))
1352
+ sage: z = a + b*I
1353
+ sage: bool(norm(z).simplify() == a^2 + b^2)
1354
+ True
1355
+ sage: norm(a + b).simplify()
1356
+ a^2 + 2*a*b + b^2
1357
+ sage: v = vector([a, b, c])
1358
+ sage: bool(norm(v).simplify() == sqrt(a^2 + b^2 + c^2))
1359
+ True
1360
+ sage: forget()
1361
+ """
1362
+ return x.norm()
1363
+
1364
+
1365
+ def numerator(x):
1366
+ """
1367
+ Return the numerator of ``x``.
1368
+
1369
+ EXAMPLES::
1370
+
1371
+ sage: R.<x> = PolynomialRing(QQ)
1372
+ sage: F = FractionField(R)
1373
+ sage: r = (x+1)/(x-1)
1374
+ sage: numerator(r)
1375
+ x + 1
1376
+ sage: numerator(17/11111)
1377
+ 17
1378
+ """
1379
+ if isinstance(x, int):
1380
+ return x
1381
+ return x.numerator()
1382
+
1383
+
1384
+ def numerical_approx(x, prec=None, digits=None, algorithm=None):
1385
+ r"""
1386
+ Return a numerical approximation of ``self`` with ``prec`` bits
1387
+ (or decimal ``digits``) of precision.
1388
+
1389
+ No guarantee is made about the accuracy of the result.
1390
+
1391
+ .. NOTE::
1392
+
1393
+ Lower case :func:`n` is an alias for :func:`numerical_approx`
1394
+ and may be used as a method.
1395
+
1396
+ INPUT:
1397
+
1398
+ - ``prec`` -- precision in bits
1399
+
1400
+ - ``digits`` -- precision in decimal digits (only used if
1401
+ ``prec`` is not given)
1402
+
1403
+ - ``algorithm`` -- which algorithm to use to compute this
1404
+ approximation (the accepted algorithms depend on the object)
1405
+
1406
+ If neither ``prec`` nor ``digits`` is given, the default
1407
+ precision is 53 bits (roughly 16 digits).
1408
+
1409
+ EXAMPLES::
1410
+
1411
+ sage: # needs sage.symbolic
1412
+ sage: numerical_approx(pi, 10)
1413
+ 3.1
1414
+ sage: numerical_approx(pi, digits=10)
1415
+ 3.141592654
1416
+ sage: numerical_approx(pi^2 + e, digits=20)
1417
+ 12.587886229548403854
1418
+ sage: n(pi^2 + e)
1419
+ 12.5878862295484
1420
+ sage: N(pi^2 + e)
1421
+ 12.5878862295484
1422
+ sage: n(pi^2 + e, digits=50)
1423
+ 12.587886229548403854194778471228813633070946500941
1424
+
1425
+ sage: # needs sage.rings.real_mpfr
1426
+ sage: a = CC(-5).n(prec=40)
1427
+ sage: b = ComplexField(40)(-5)
1428
+ sage: a == b
1429
+ True
1430
+ sage: parent(a) is parent(b)
1431
+ True
1432
+ sage: numerical_approx(9)
1433
+ 9.00000000000000
1434
+
1435
+ You can also usually use method notation::
1436
+
1437
+ sage: (pi^2 + e).n() # needs sage.symbolic
1438
+ 12.5878862295484
1439
+ sage: (pi^2 + e).numerical_approx() # needs sage.symbolic
1440
+ 12.5878862295484
1441
+
1442
+ Vectors and matrices may also have their entries approximated::
1443
+
1444
+ sage: v = vector(RDF, [1,2,3]) # needs sage.modules
1445
+ sage: v.n() # needs sage.modules
1446
+ (1.00000000000000, 2.00000000000000, 3.00000000000000)
1447
+
1448
+ sage: # needs sage.modules
1449
+ sage: v = vector(CDF, [1,2,3])
1450
+ sage: v.n()
1451
+ (1.00000000000000, 2.00000000000000, 3.00000000000000)
1452
+ sage: _.parent()
1453
+ Vector space of dimension 3 over Complex Field with 53 bits of precision
1454
+ sage: v.n(prec=20)
1455
+ (1.0000, 2.0000, 3.0000)
1456
+
1457
+ sage: u = vector(QQ, [1/2, 1/3, 1/4]) # needs sage.modules
1458
+ sage: n(u, prec=15) # needs sage.modules
1459
+ (0.5000, 0.3333, 0.2500)
1460
+ sage: n(u, digits=5) # needs sage.modules
1461
+ (0.50000, 0.33333, 0.25000)
1462
+
1463
+ sage: # needs sage.modules
1464
+ sage: v = vector(QQ, [1/2, 0, 0, 1/3, 0, 0, 0, 1/4], sparse=True)
1465
+ sage: u = v.numerical_approx(digits=4)
1466
+ sage: u.is_sparse()
1467
+ True
1468
+ sage: u
1469
+ (0.5000, 0.0000, 0.0000, 0.3333, 0.0000, 0.0000, 0.0000, 0.2500)
1470
+
1471
+ sage: # needs sage.modules
1472
+ sage: A = matrix(QQ, 2, 3, range(6))
1473
+ sage: A.n()
1474
+ [0.000000000000000 1.00000000000000 2.00000000000000]
1475
+ [ 3.00000000000000 4.00000000000000 5.00000000000000]
1476
+ sage: B = matrix(Integers(12), 3, 8, srange(24))
1477
+ sage: N(B, digits=2)
1478
+ [0.00 1.0 2.0 3.0 4.0 5.0 6.0 7.0]
1479
+ [ 8.0 9.0 10. 11. 0.00 1.0 2.0 3.0]
1480
+ [ 4.0 5.0 6.0 7.0 8.0 9.0 10. 11.]
1481
+
1482
+ Internally, numerical approximations of real numbers are stored in base-2.
1483
+ Therefore, numbers which look the same in their decimal expansion might be
1484
+ different::
1485
+
1486
+ sage: x = N(pi, digits=3); x # needs sage.symbolic
1487
+ 3.14
1488
+ sage: y = N(3.14, digits=3); y # needs sage.rings.real_mpfr
1489
+ 3.14
1490
+ sage: x == y # needs sage.rings.real_mpfr sage.symbolic
1491
+ False
1492
+ sage: x.str(base=2) # needs sage.symbolic
1493
+ '11.001001000100'
1494
+ sage: y.str(base=2) # needs sage.rings.real_mpfr
1495
+ '11.001000111101'
1496
+
1497
+ Increasing the precision of a floating point number is not allowed::
1498
+
1499
+ sage: CC(-5).n(prec=100) # needs sage.rings.real_mpfr
1500
+ Traceback (most recent call last):
1501
+ ...
1502
+ TypeError: cannot approximate to a precision of 100 bits, use at most 53 bits
1503
+ sage: n(1.3r, digits=20) # needs sage.rings.real_mpfr
1504
+ Traceback (most recent call last):
1505
+ ...
1506
+ TypeError: cannot approximate to a precision of 70 bits, use at most 53 bits
1507
+ sage: RealField(24).pi().n() # needs sage.rings.real_mpfr
1508
+ Traceback (most recent call last):
1509
+ ...
1510
+ TypeError: cannot approximate to a precision of 53 bits, use at most 24 bits
1511
+
1512
+ As an exceptional case, ``digits=1`` usually leads to 2 digits (one
1513
+ significant) in the decimal output (see :issue:`11647`)::
1514
+
1515
+ sage: # needs sage.symbolic
1516
+ sage: N(pi, digits=1)
1517
+ 3.2
1518
+ sage: N(pi, digits=2)
1519
+ 3.1
1520
+ sage: N(100*pi, digits=1)
1521
+ 320.
1522
+ sage: N(100*pi, digits=2)
1523
+ 310.
1524
+
1525
+ In the following example, ``pi`` and ``3`` are both approximated to two
1526
+ bits of precision and then subtracted, which kills two bits of precision::
1527
+
1528
+ sage: N(pi, prec=2) # needs sage.symbolic
1529
+ 3.0
1530
+ sage: N(3, prec=2) # needs sage.rings.real_mpfr
1531
+ 3.0
1532
+ sage: N(pi - 3, prec=2) # needs sage.symbolic
1533
+ 0.00
1534
+
1535
+ TESTS::
1536
+
1537
+ sage: numerical_approx(I) # needs sage.symbolic
1538
+ 1.00000000000000*I
1539
+ sage: x = QQ['x'].gen()
1540
+ sage: F.<k> = NumberField(x^2 + 2, embedding=sqrt(CC(2))*CC.0) # needs sage.rings.number_field sage.symbolic
1541
+ sage: numerical_approx(k) # needs sage.rings.number_field sage.symbolic
1542
+ 1.41421356237309*I
1543
+
1544
+ sage: type(numerical_approx(CC(1/2))) # needs sage.rings.real_mpfr
1545
+ <class 'sage.rings.complex_mpfr.ComplexNumber'>
1546
+
1547
+ The following tests :issue:`10761`, in which ``n()`` would break when
1548
+ called on complex-valued algebraic numbers. ::
1549
+
1550
+ sage: E = matrix(3, [3,1,6,5,2,9,7,3,13]).eigenvalues(); E # needs sage.modules sage.rings.number_field
1551
+ [18.16815365088822?, -0.08407682544410650? - 0.2190261484802906?*I, -0.08407682544410650? + 0.2190261484802906?*I]
1552
+ sage: E[1].parent() # needs sage.modules sage.rings.number_field
1553
+ Algebraic Field
1554
+ sage: [a.n() for a in E] # needs sage.modules sage.rings.number_field
1555
+ [18.1681536508882, -0.0840768254441065 - 0.219026148480291*I, -0.0840768254441065 + 0.219026148480291*I]
1556
+
1557
+ Make sure we've rounded up log(10,2) enough to guarantee
1558
+ sufficient precision (:issue:`10164`)::
1559
+
1560
+ sage: ks = 4*10**5, 10**6
1561
+ sage: check_str_length = lambda k: len(str(numerical_approx(1+10**-k,digits=k+1)))-1 >= k+1
1562
+ sage: check_precision = lambda k: numerical_approx(1+10**-k,digits=k+1)-1 > 0
1563
+ sage: all(check_str_length(k) and check_precision(k) for k in ks) # needs sage.rings.real_mpfr
1564
+ True
1565
+
1566
+ Testing we have sufficient precision for the golden ratio (:issue:`12163`), note
1567
+ that the decimal point adds 1 to the string length::
1568
+
1569
+ sage: len(str(n(golden_ratio, digits=5000))) # needs sage.symbolic
1570
+ 5001
1571
+ sage: len(str(n(golden_ratio, digits=5000000))) # long time (4s on sage.math, 2012), needs sage.symbolic
1572
+ 5000001
1573
+
1574
+ Check that :issue:`14778` is fixed::
1575
+
1576
+ sage: n(0, algorithm='foo') # needs sage.rings.real_mpfr
1577
+ 0.000000000000000
1578
+ """
1579
+ if prec is None:
1580
+ from sage.arith.numerical_approx import digits_to_bits
1581
+ prec = digits_to_bits(digits)
1582
+ try:
1583
+ n = x.numerical_approx
1584
+ except AttributeError:
1585
+ from sage.arith.numerical_approx import numerical_approx_generic
1586
+ return numerical_approx_generic(x, prec)
1587
+ else:
1588
+ return n(prec, algorithm=algorithm)
1589
+
1590
+
1591
+ n = numerical_approx
1592
+ N = numerical_approx
1593
+
1594
+
1595
+ def objgens(x):
1596
+ """
1597
+ EXAMPLES::
1598
+
1599
+ sage: R, x = objgens(PolynomialRing(QQ,3, 'x'))
1600
+ sage: R
1601
+ Multivariate Polynomial Ring in x0, x1, x2 over Rational Field
1602
+ sage: x
1603
+ (x0, x1, x2)
1604
+ """
1605
+ return x.objgens()
1606
+
1607
+
1608
+ def objgen(x):
1609
+ """
1610
+ EXAMPLES::
1611
+
1612
+ sage: R, x = objgen(FractionField(QQ['x']))
1613
+ sage: R
1614
+ Fraction Field of Univariate Polynomial Ring in x over Rational Field
1615
+ sage: x
1616
+ x
1617
+ """
1618
+ return x.objgen()
1619
+
1620
+
1621
+ def order(x):
1622
+ """
1623
+ Return the order of ``x``.
1624
+
1625
+ If ``x`` is a ring or module element, this is
1626
+ the additive order of ``x``.
1627
+
1628
+ EXAMPLES::
1629
+
1630
+ sage: C = CyclicPermutationGroup(10) # needs sage.groups
1631
+ sage: order(C) # needs sage.groups
1632
+ 10
1633
+ sage: F = GF(7)
1634
+ sage: order(F)
1635
+ 7
1636
+ """
1637
+ return x.order()
1638
+
1639
+
1640
+ def rank(x):
1641
+ """
1642
+ Return the rank of ``x``.
1643
+
1644
+ EXAMPLES:
1645
+
1646
+ We compute the rank of a matrix::
1647
+
1648
+ sage: M = MatrixSpace(QQ, 3, 3) # needs sage.modules
1649
+ sage: A = M([1,2,3, 4,5,6, 7,8,9]) # needs sage.modules
1650
+ sage: rank(A) # needs sage.modules
1651
+ 2
1652
+
1653
+ We compute the rank of an elliptic curve::
1654
+
1655
+ sage: E = EllipticCurve([0,0,1,-1,0]) # needs sage.schemes
1656
+ sage: rank(E) # needs eclib sage.schemes
1657
+ 1
1658
+ """
1659
+ return x.rank()
1660
+
1661
+
1662
+ def regulator(x):
1663
+ """
1664
+ Return the regulator of ``x``.
1665
+
1666
+ EXAMPLES::
1667
+
1668
+ sage: x = polygen(ZZ, 'x')
1669
+ sage: regulator(NumberField(x^2 - 2, 'a')) # needs sage.rings.number_field
1670
+ 0.881373587019543
1671
+ sage: regulator(EllipticCurve('11a')) # needs eclib sage.schemes
1672
+ 1.00000000000000
1673
+ """
1674
+ return x.regulator()
1675
+
1676
+
1677
+ def round(x, ndigits=0):
1678
+ """
1679
+ round(number[, ndigits]) - double-precision real number
1680
+
1681
+ Round a number to a given precision in decimal digits (default 0
1682
+ digits). If no precision is specified this just calls the element's
1683
+ .round() method.
1684
+
1685
+ EXAMPLES::
1686
+
1687
+ sage: # needs sage.symbolic
1688
+ sage: round(sqrt(2), 2)
1689
+ 1.41
1690
+ sage: q = round(sqrt(2), 5); q
1691
+ 1.41421
1692
+ sage: type(q)
1693
+ <class 'sage.rings.real_double...RealDoubleElement...'>
1694
+ sage: q = round(sqrt(2)); q
1695
+ 1
1696
+ sage: type(q)
1697
+ <class 'sage.rings.integer.Integer'>
1698
+ sage: round(pi)
1699
+ 3
1700
+
1701
+ sage: b = 5.4999999999999999
1702
+ sage: round(b)
1703
+ 5
1704
+
1705
+ This example addresses :issue:`23502`::
1706
+
1707
+ sage: n = round(6); type(n)
1708
+ <class 'sage.rings.integer.Integer'>
1709
+
1710
+ Since we use floating-point with a limited range, some roundings can't
1711
+ be performed::
1712
+
1713
+ sage: round(sqrt(Integer('1'*1000)), 2) # needs sage.symbolic
1714
+ +infinity
1715
+
1716
+ IMPLEMENTATION: If ndigits is specified, it calls Python's builtin
1717
+ round function, and converts the result to a real double field
1718
+ element. Otherwise, it tries the argument's .round() method; if
1719
+ that fails, it reverts to the builtin round function, converted to
1720
+ a real double field element.
1721
+
1722
+ .. NOTE::
1723
+
1724
+ This is currently slower than the builtin round function, since it does
1725
+ more work - i.e., allocating an RDF element and initializing it. To
1726
+ access the builtin version do ``import builtins; builtins.round``.
1727
+ """
1728
+ try:
1729
+ if ndigits:
1730
+ x = float(x)
1731
+ return RealDoubleElement(builtins.round(x, ndigits))
1732
+ else:
1733
+ try:
1734
+ return x.round()
1735
+ except AttributeError:
1736
+ return RealDoubleElement(builtins.round(x, 0))
1737
+ except ArithmeticError:
1738
+ if not isinstance(x, RealDoubleElement):
1739
+ return round(RDF(x), ndigits)
1740
+ else:
1741
+ raise
1742
+
1743
+
1744
+ def quotient(x, y, *args, **kwds):
1745
+ """
1746
+ Return the quotient object x/y, e.g., a quotient of numbers or of a
1747
+ polynomial ring x by the ideal generated by y, etc.
1748
+
1749
+ EXAMPLES::
1750
+
1751
+ sage: quotient(5, 6)
1752
+ 5/6
1753
+ sage: quotient(5., 6.)
1754
+ 0.833333333333333
1755
+ sage: R.<x> = ZZ[]; R
1756
+ Univariate Polynomial Ring in x over Integer Ring
1757
+ sage: I = Ideal(R, x^2 + 1)
1758
+ sage: quotient(R, I) # needs sage.libs.pari
1759
+ Univariate Quotient Polynomial Ring in xbar over Integer Ring with modulus x^2 + 1
1760
+ """
1761
+ try:
1762
+ return x.quotient(y, *args, **kwds)
1763
+ except AttributeError:
1764
+ return x / y
1765
+
1766
+
1767
+ quo = quotient
1768
+
1769
+
1770
+ def isqrt(x):
1771
+ """
1772
+ Return an integer square root, i.e., the floor of a square root.
1773
+
1774
+ EXAMPLES::
1775
+
1776
+ sage: isqrt(10)
1777
+ 3
1778
+ sage: isqrt(10r)
1779
+ 3
1780
+ """
1781
+ try:
1782
+ return x.isqrt()
1783
+ except AttributeError:
1784
+ from sage.functions.all import floor
1785
+ n = Integer(floor(x))
1786
+ return n.isqrt()
1787
+
1788
+
1789
+ def squarefree_part(x):
1790
+ """
1791
+ Return the square free part of ``x``, i.e., a divisor
1792
+ `z` such that `x = z y^2`, for a perfect square
1793
+ `y^2`.
1794
+
1795
+ EXAMPLES::
1796
+
1797
+ sage: squarefree_part(100)
1798
+ 1
1799
+ sage: squarefree_part(12)
1800
+ 3
1801
+ sage: squarefree_part(10)
1802
+ 10
1803
+ sage: squarefree_part(216r) # see #8976
1804
+ 6
1805
+
1806
+ ::
1807
+
1808
+ sage: x = QQ['x'].0
1809
+ sage: S = squarefree_part(-9*x*(x-6)^7*(x-3)^2); S
1810
+ -9*x^2 + 54*x
1811
+ sage: S.factor() # needs sage.libs.pari
1812
+ (-9) * (x - 6) * x
1813
+
1814
+ ::
1815
+
1816
+ sage: f = (x^3 + x + 1)^3*(x-1); f
1817
+ x^10 - x^9 + 3*x^8 + 3*x^5 - 2*x^4 - x^3 - 2*x - 1
1818
+ sage: g = squarefree_part(f); g
1819
+ x^4 - x^3 + x^2 - 1
1820
+ sage: g.factor() # needs sage.libs.pari
1821
+ (x - 1) * (x^3 + x + 1)
1822
+ """
1823
+ try:
1824
+ return x.squarefree_part()
1825
+ except AttributeError:
1826
+ pass
1827
+ from sage.arith.misc import factor
1828
+ from sage.structure.all import parent
1829
+ F = factor(x)
1830
+ n = parent(x)(1)
1831
+ for p, e in F:
1832
+ if e % 2:
1833
+ n *= p
1834
+ return n * F.unit()
1835
+
1836
+
1837
+ def _do_sqrt(x, prec=None, extend=True, all=False):
1838
+ r"""
1839
+ Used internally to compute the square root of ``x``.
1840
+
1841
+ INPUT:
1842
+
1843
+ - ``x`` -- a number
1844
+
1845
+ - ``prec`` -- positive integer (default: ``None``); when specified,
1846
+ compute the square root with ``prec`` bits of precision
1847
+
1848
+ - ``extend`` -- boolean (default: ``True``); this is a placeholder, and is
1849
+ always ignored since in the symbolic ring everything
1850
+ has a square root
1851
+
1852
+ - ``extend`` -- boolean (default: ``True``); whether to extend
1853
+ the base ring to find roots. The extend parameter is ignored if
1854
+ ``prec`` is a positive integer.
1855
+
1856
+ - ``all`` -- boolean (default: ``False``); whether to return
1857
+ a list of all the square roots of ``x``
1858
+
1859
+ EXAMPLES::
1860
+
1861
+ sage: from sage.misc.functional import _do_sqrt
1862
+ sage: _do_sqrt(3) # needs sage.symbolic
1863
+ sqrt(3)
1864
+ sage: _do_sqrt(3, prec=10) # needs sage.rings.real_mpfr
1865
+ 1.7
1866
+ sage: _do_sqrt(3, prec=100) # needs sage.rings.real_mpfr
1867
+ 1.7320508075688772935274463415
1868
+ sage: _do_sqrt(3, all=True) # needs sage.symbolic
1869
+ [sqrt(3), -sqrt(3)]
1870
+
1871
+ Note that the extend parameter is ignored in the symbolic ring::
1872
+
1873
+ sage: _do_sqrt(3, extend=False) # needs sage.symbolic
1874
+ sqrt(3)
1875
+ """
1876
+ if prec:
1877
+ if x >= 0:
1878
+ from sage.rings.real_mpfr import RealField
1879
+ return RealField(prec)(x).sqrt(all=all)
1880
+ else:
1881
+ from sage.rings.complex_mpfr import ComplexField
1882
+ return ComplexField(prec)(x).sqrt(all=all)
1883
+ if x == -1:
1884
+ from sage.symbolic.constants import I as z
1885
+ else:
1886
+ from sage.symbolic.ring import SR
1887
+ z = SR(x).sqrt()
1888
+
1889
+ if all:
1890
+ if z:
1891
+ return [z, -z]
1892
+ else:
1893
+ return [z]
1894
+ return z
1895
+
1896
+
1897
+ def sqrt(x, *args, **kwds):
1898
+ r"""
1899
+ INPUT:
1900
+
1901
+ - ``x`` -- a number
1902
+
1903
+ - ``prec`` -- integer (default: ``None``); if ``None``, returns
1904
+ an exact square root. Otherwise returns a numerical square root if
1905
+ necessary, to the given bits of precision.
1906
+
1907
+ - ``extend`` -- boolean (default: ``True``); this is a placeholder, and
1908
+ is always ignored or passed to the ``sqrt`` method of ``x``,
1909
+ since in the symbolic ring everything has a square root
1910
+
1911
+ - ``all`` -- boolean (default: ``False``); if ``True``, return all
1912
+ square roots of ``self``, instead of just one
1913
+
1914
+ EXAMPLES::
1915
+
1916
+ sage: sqrt(4)
1917
+ 2
1918
+ sage: sqrt(4, all=True)
1919
+ [2, -2]
1920
+
1921
+ sage: # needs sage.symbolic
1922
+ sage: sqrt(-1)
1923
+ I
1924
+ sage: sqrt(2)
1925
+ sqrt(2)
1926
+ sage: sqrt(2)^2
1927
+ 2
1928
+ sage: sqrt(x^2)
1929
+ sqrt(x^2)
1930
+
1931
+ For a non-symbolic square root, there are a few options.
1932
+ The best is to numerically approximate afterward::
1933
+
1934
+ sage: sqrt(2).n() # needs sage.symbolic
1935
+ 1.41421356237310
1936
+ sage: sqrt(2).n(prec=100) # needs sage.symbolic
1937
+ 1.4142135623730950488016887242
1938
+
1939
+ Or one can input a numerical type::
1940
+
1941
+ sage: sqrt(2.)
1942
+ 1.41421356237310
1943
+ sage: sqrt(2.000000000000000000000000)
1944
+ 1.41421356237309504880169
1945
+ sage: sqrt(4.0)
1946
+ 2.00000000000000
1947
+
1948
+ To prevent automatic evaluation, one can use the ``hold`` parameter
1949
+ after coercing to the symbolic ring::
1950
+
1951
+ sage: sqrt(SR(4), hold=True) # needs sage.symbolic
1952
+ sqrt(4)
1953
+ sage: sqrt(4, hold=True)
1954
+ Traceback (most recent call last):
1955
+ ...
1956
+ TypeError: ..._do_sqrt() got an unexpected keyword argument 'hold'
1957
+
1958
+ This illustrates that the bug reported in :issue:`6171` has been fixed::
1959
+
1960
+ sage: a = 1.1
1961
+ sage: a.sqrt(prec=100) # this is supposed to fail
1962
+ Traceback (most recent call last):
1963
+ ...
1964
+ TypeError: ...sqrt() got an unexpected keyword argument 'prec'
1965
+ sage: sqrt(a, prec=100) # needs sage.rings.real_mpfr
1966
+ 1.0488088481701515469914535137
1967
+ sage: sqrt(4.00, prec=250) # needs sage.rings.real_mpfr
1968
+ 2.0000000000000000000000000000000000000000000000000000000000000000000000000
1969
+
1970
+ One can use numpy input as well::
1971
+
1972
+ sage: import numpy # needs numpy
1973
+ sage: a = numpy.arange(2,5) # needs numpy
1974
+ sage: sqrt(a) # needs numpy
1975
+ array([1.41421356, 1.73205081, 2. ])
1976
+ """
1977
+ if isinstance(x, float):
1978
+ return math.sqrt(x)
1979
+ elif type(x).__module__ == 'numpy':
1980
+ from numpy import sqrt
1981
+ return sqrt(x)
1982
+ try:
1983
+ return x.sqrt(*args, **kwds)
1984
+ # The following includes TypeError to catch cases where sqrt
1985
+ # is called with a "prec" keyword, for example, but the sqrt
1986
+ # method for x doesn't accept such a keyword.
1987
+ except (AttributeError, TypeError):
1988
+ pass
1989
+ return _do_sqrt(x, *args, **kwds)
1990
+
1991
+
1992
+ def transpose(x):
1993
+ """
1994
+ Return the transpose of ``x``.
1995
+
1996
+ EXAMPLES::
1997
+
1998
+ sage: M = MatrixSpace(QQ, 3, 3) # needs sage.modules
1999
+ sage: A = M([1,2,3, 4,5,6, 7,8,9]) # needs sage.modules
2000
+ sage: transpose(A) # needs sage.modules
2001
+ [1 4 7]
2002
+ [2 5 8]
2003
+ [3 6 9]
2004
+ """
2005
+ return x.transpose()