compatibility.py 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  1. """Compatibility interface between dense and sparse polys. """
  2. from sympy.polys.densearith import dup_add_term
  3. from sympy.polys.densearith import dmp_add_term
  4. from sympy.polys.densearith import dup_sub_term
  5. from sympy.polys.densearith import dmp_sub_term
  6. from sympy.polys.densearith import dup_mul_term
  7. from sympy.polys.densearith import dmp_mul_term
  8. from sympy.polys.densearith import dup_add_ground
  9. from sympy.polys.densearith import dmp_add_ground
  10. from sympy.polys.densearith import dup_sub_ground
  11. from sympy.polys.densearith import dmp_sub_ground
  12. from sympy.polys.densearith import dup_mul_ground
  13. from sympy.polys.densearith import dmp_mul_ground
  14. from sympy.polys.densearith import dup_quo_ground
  15. from sympy.polys.densearith import dmp_quo_ground
  16. from sympy.polys.densearith import dup_exquo_ground
  17. from sympy.polys.densearith import dmp_exquo_ground
  18. from sympy.polys.densearith import dup_lshift
  19. from sympy.polys.densearith import dup_rshift
  20. from sympy.polys.densearith import dup_abs
  21. from sympy.polys.densearith import dmp_abs
  22. from sympy.polys.densearith import dup_neg
  23. from sympy.polys.densearith import dmp_neg
  24. from sympy.polys.densearith import dup_add
  25. from sympy.polys.densearith import dmp_add
  26. from sympy.polys.densearith import dup_sub
  27. from sympy.polys.densearith import dmp_sub
  28. from sympy.polys.densearith import dup_add_mul
  29. from sympy.polys.densearith import dmp_add_mul
  30. from sympy.polys.densearith import dup_sub_mul
  31. from sympy.polys.densearith import dmp_sub_mul
  32. from sympy.polys.densearith import dup_mul
  33. from sympy.polys.densearith import dmp_mul
  34. from sympy.polys.densearith import dup_sqr
  35. from sympy.polys.densearith import dmp_sqr
  36. from sympy.polys.densearith import dup_pow
  37. from sympy.polys.densearith import dmp_pow
  38. from sympy.polys.densearith import dup_pdiv
  39. from sympy.polys.densearith import dup_prem
  40. from sympy.polys.densearith import dup_pquo
  41. from sympy.polys.densearith import dup_pexquo
  42. from sympy.polys.densearith import dmp_pdiv
  43. from sympy.polys.densearith import dmp_prem
  44. from sympy.polys.densearith import dmp_pquo
  45. from sympy.polys.densearith import dmp_pexquo
  46. from sympy.polys.densearith import dup_rr_div
  47. from sympy.polys.densearith import dmp_rr_div
  48. from sympy.polys.densearith import dup_ff_div
  49. from sympy.polys.densearith import dmp_ff_div
  50. from sympy.polys.densearith import dup_div
  51. from sympy.polys.densearith import dup_rem
  52. from sympy.polys.densearith import dup_quo
  53. from sympy.polys.densearith import dup_exquo
  54. from sympy.polys.densearith import dmp_div
  55. from sympy.polys.densearith import dmp_rem
  56. from sympy.polys.densearith import dmp_quo
  57. from sympy.polys.densearith import dmp_exquo
  58. from sympy.polys.densearith import dup_max_norm
  59. from sympy.polys.densearith import dmp_max_norm
  60. from sympy.polys.densearith import dup_l1_norm
  61. from sympy.polys.densearith import dmp_l1_norm
  62. from sympy.polys.densearith import dup_l2_norm_squared
  63. from sympy.polys.densearith import dmp_l2_norm_squared
  64. from sympy.polys.densearith import dup_expand
  65. from sympy.polys.densearith import dmp_expand
  66. from sympy.polys.densebasic import dup_LC
  67. from sympy.polys.densebasic import dmp_LC
  68. from sympy.polys.densebasic import dup_TC
  69. from sympy.polys.densebasic import dmp_TC
  70. from sympy.polys.densebasic import dmp_ground_LC
  71. from sympy.polys.densebasic import dmp_ground_TC
  72. from sympy.polys.densebasic import dup_degree
  73. from sympy.polys.densebasic import dmp_degree
  74. from sympy.polys.densebasic import dmp_degree_in
  75. from sympy.polys.densebasic import dmp_to_dict
  76. from sympy.polys.densetools import dup_integrate
  77. from sympy.polys.densetools import dmp_integrate
  78. from sympy.polys.densetools import dmp_integrate_in
  79. from sympy.polys.densetools import dup_diff
  80. from sympy.polys.densetools import dmp_diff
  81. from sympy.polys.densetools import dmp_diff_in
  82. from sympy.polys.densetools import dup_eval
  83. from sympy.polys.densetools import dmp_eval
  84. from sympy.polys.densetools import dmp_eval_in
  85. from sympy.polys.densetools import dmp_eval_tail
  86. from sympy.polys.densetools import dmp_diff_eval_in
  87. from sympy.polys.densetools import dup_trunc
  88. from sympy.polys.densetools import dmp_trunc
  89. from sympy.polys.densetools import dmp_ground_trunc
  90. from sympy.polys.densetools import dup_monic
  91. from sympy.polys.densetools import dmp_ground_monic
  92. from sympy.polys.densetools import dup_content
  93. from sympy.polys.densetools import dmp_ground_content
  94. from sympy.polys.densetools import dup_primitive
  95. from sympy.polys.densetools import dmp_ground_primitive
  96. from sympy.polys.densetools import dup_extract
  97. from sympy.polys.densetools import dmp_ground_extract
  98. from sympy.polys.densetools import dup_real_imag
  99. from sympy.polys.densetools import dup_mirror
  100. from sympy.polys.densetools import dup_scale
  101. from sympy.polys.densetools import dup_shift
  102. from sympy.polys.densetools import dup_transform
  103. from sympy.polys.densetools import dup_compose
  104. from sympy.polys.densetools import dmp_compose
  105. from sympy.polys.densetools import dup_decompose
  106. from sympy.polys.densetools import dmp_lift
  107. from sympy.polys.densetools import dup_sign_variations
  108. from sympy.polys.densetools import dup_clear_denoms
  109. from sympy.polys.densetools import dmp_clear_denoms
  110. from sympy.polys.densetools import dup_revert
  111. from sympy.polys.euclidtools import dup_half_gcdex
  112. from sympy.polys.euclidtools import dmp_half_gcdex
  113. from sympy.polys.euclidtools import dup_gcdex
  114. from sympy.polys.euclidtools import dmp_gcdex
  115. from sympy.polys.euclidtools import dup_invert
  116. from sympy.polys.euclidtools import dmp_invert
  117. from sympy.polys.euclidtools import dup_euclidean_prs
  118. from sympy.polys.euclidtools import dmp_euclidean_prs
  119. from sympy.polys.euclidtools import dup_primitive_prs
  120. from sympy.polys.euclidtools import dmp_primitive_prs
  121. from sympy.polys.euclidtools import dup_inner_subresultants
  122. from sympy.polys.euclidtools import dup_subresultants
  123. from sympy.polys.euclidtools import dup_prs_resultant
  124. from sympy.polys.euclidtools import dup_resultant
  125. from sympy.polys.euclidtools import dmp_inner_subresultants
  126. from sympy.polys.euclidtools import dmp_subresultants
  127. from sympy.polys.euclidtools import dmp_prs_resultant
  128. from sympy.polys.euclidtools import dmp_zz_modular_resultant
  129. from sympy.polys.euclidtools import dmp_zz_collins_resultant
  130. from sympy.polys.euclidtools import dmp_qq_collins_resultant
  131. from sympy.polys.euclidtools import dmp_resultant
  132. from sympy.polys.euclidtools import dup_discriminant
  133. from sympy.polys.euclidtools import dmp_discriminant
  134. from sympy.polys.euclidtools import dup_rr_prs_gcd
  135. from sympy.polys.euclidtools import dup_ff_prs_gcd
  136. from sympy.polys.euclidtools import dmp_rr_prs_gcd
  137. from sympy.polys.euclidtools import dmp_ff_prs_gcd
  138. from sympy.polys.euclidtools import dup_zz_heu_gcd
  139. from sympy.polys.euclidtools import dmp_zz_heu_gcd
  140. from sympy.polys.euclidtools import dup_qq_heu_gcd
  141. from sympy.polys.euclidtools import dmp_qq_heu_gcd
  142. from sympy.polys.euclidtools import dup_inner_gcd
  143. from sympy.polys.euclidtools import dmp_inner_gcd
  144. from sympy.polys.euclidtools import dup_gcd
  145. from sympy.polys.euclidtools import dmp_gcd
  146. from sympy.polys.euclidtools import dup_rr_lcm
  147. from sympy.polys.euclidtools import dup_ff_lcm
  148. from sympy.polys.euclidtools import dup_lcm
  149. from sympy.polys.euclidtools import dmp_rr_lcm
  150. from sympy.polys.euclidtools import dmp_ff_lcm
  151. from sympy.polys.euclidtools import dmp_lcm
  152. from sympy.polys.euclidtools import dmp_content
  153. from sympy.polys.euclidtools import dmp_primitive
  154. from sympy.polys.euclidtools import dup_cancel
  155. from sympy.polys.euclidtools import dmp_cancel
  156. from sympy.polys.factortools import dup_trial_division
  157. from sympy.polys.factortools import dmp_trial_division
  158. from sympy.polys.factortools import dup_zz_mignotte_bound
  159. from sympy.polys.factortools import dmp_zz_mignotte_bound
  160. from sympy.polys.factortools import dup_zz_hensel_step
  161. from sympy.polys.factortools import dup_zz_hensel_lift
  162. from sympy.polys.factortools import dup_zz_zassenhaus
  163. from sympy.polys.factortools import dup_zz_irreducible_p
  164. from sympy.polys.factortools import dup_cyclotomic_p
  165. from sympy.polys.factortools import dup_zz_cyclotomic_poly
  166. from sympy.polys.factortools import dup_zz_cyclotomic_factor
  167. from sympy.polys.factortools import dup_zz_factor_sqf
  168. from sympy.polys.factortools import dup_zz_factor
  169. from sympy.polys.factortools import dmp_zz_wang_non_divisors
  170. from sympy.polys.factortools import dmp_zz_wang_lead_coeffs
  171. from sympy.polys.factortools import dup_zz_diophantine
  172. from sympy.polys.factortools import dmp_zz_diophantine
  173. from sympy.polys.factortools import dmp_zz_wang_hensel_lifting
  174. from sympy.polys.factortools import dmp_zz_wang
  175. from sympy.polys.factortools import dmp_zz_factor
  176. from sympy.polys.factortools import dup_qq_i_factor
  177. from sympy.polys.factortools import dup_zz_i_factor
  178. from sympy.polys.factortools import dmp_qq_i_factor
  179. from sympy.polys.factortools import dmp_zz_i_factor
  180. from sympy.polys.factortools import dup_ext_factor
  181. from sympy.polys.factortools import dmp_ext_factor
  182. from sympy.polys.factortools import dup_gf_factor
  183. from sympy.polys.factortools import dmp_gf_factor
  184. from sympy.polys.factortools import dup_factor_list
  185. from sympy.polys.factortools import dup_factor_list_include
  186. from sympy.polys.factortools import dmp_factor_list
  187. from sympy.polys.factortools import dmp_factor_list_include
  188. from sympy.polys.factortools import dup_irreducible_p
  189. from sympy.polys.factortools import dmp_irreducible_p
  190. from sympy.polys.rootisolation import dup_sturm
  191. from sympy.polys.rootisolation import dup_root_upper_bound
  192. from sympy.polys.rootisolation import dup_root_lower_bound
  193. from sympy.polys.rootisolation import dup_step_refine_real_root
  194. from sympy.polys.rootisolation import dup_inner_refine_real_root
  195. from sympy.polys.rootisolation import dup_outer_refine_real_root
  196. from sympy.polys.rootisolation import dup_refine_real_root
  197. from sympy.polys.rootisolation import dup_inner_isolate_real_roots
  198. from sympy.polys.rootisolation import dup_inner_isolate_positive_roots
  199. from sympy.polys.rootisolation import dup_inner_isolate_negative_roots
  200. from sympy.polys.rootisolation import dup_isolate_real_roots_sqf
  201. from sympy.polys.rootisolation import dup_isolate_real_roots
  202. from sympy.polys.rootisolation import dup_isolate_real_roots_list
  203. from sympy.polys.rootisolation import dup_count_real_roots
  204. from sympy.polys.rootisolation import dup_count_complex_roots
  205. from sympy.polys.rootisolation import dup_isolate_complex_roots_sqf
  206. from sympy.polys.rootisolation import dup_isolate_all_roots_sqf
  207. from sympy.polys.rootisolation import dup_isolate_all_roots
  208. from sympy.polys.sqfreetools import (
  209. dup_sqf_p, dmp_sqf_p, dup_sqf_norm, dmp_sqf_norm, dup_gf_sqf_part, dmp_gf_sqf_part,
  210. dup_sqf_part, dmp_sqf_part, dup_gf_sqf_list, dmp_gf_sqf_list, dup_sqf_list,
  211. dup_sqf_list_include, dmp_sqf_list, dmp_sqf_list_include, dup_gff_list, dmp_gff_list)
  212. from sympy.polys.galoistools import (
  213. gf_degree, gf_LC, gf_TC, gf_strip, gf_from_dict,
  214. gf_to_dict, gf_from_int_poly, gf_to_int_poly, gf_neg, gf_add_ground, gf_sub_ground,
  215. gf_mul_ground, gf_quo_ground, gf_add, gf_sub, gf_mul, gf_sqr, gf_add_mul, gf_sub_mul,
  216. gf_expand, gf_div, gf_rem, gf_quo, gf_exquo, gf_lshift, gf_rshift, gf_pow, gf_pow_mod,
  217. gf_gcd, gf_lcm, gf_cofactors, gf_gcdex, gf_monic, gf_diff, gf_eval, gf_multi_eval,
  218. gf_compose, gf_compose_mod, gf_trace_map, gf_random, gf_irreducible, gf_irred_p_ben_or,
  219. gf_irred_p_rabin, gf_irreducible_p, gf_sqf_p, gf_sqf_part, gf_Qmatrix,
  220. gf_berlekamp, gf_ddf_zassenhaus, gf_edf_zassenhaus, gf_ddf_shoup, gf_edf_shoup,
  221. gf_zassenhaus, gf_shoup, gf_factor_sqf, gf_factor)
  222. from sympy.utilities import public
  223. @public
  224. class IPolys:
  225. symbols = None
  226. ngens = None
  227. domain = None
  228. order = None
  229. gens = None
  230. def drop(self, gen):
  231. pass
  232. def clone(self, symbols=None, domain=None, order=None):
  233. pass
  234. def to_ground(self):
  235. pass
  236. def ground_new(self, element):
  237. pass
  238. def domain_new(self, element):
  239. pass
  240. def from_dict(self, d):
  241. pass
  242. def wrap(self, element):
  243. from sympy.polys.rings import PolyElement
  244. if isinstance(element, PolyElement):
  245. if element.ring == self:
  246. return element
  247. else:
  248. raise NotImplementedError("domain conversions")
  249. else:
  250. return self.ground_new(element)
  251. def to_dense(self, element):
  252. return self.wrap(element).to_dense()
  253. def from_dense(self, element):
  254. return self.from_dict(dmp_to_dict(element, self.ngens-1, self.domain))
  255. def dup_add_term(self, f, c, i):
  256. return self.from_dense(dup_add_term(self.to_dense(f), c, i, self.domain))
  257. def dmp_add_term(self, f, c, i):
  258. return self.from_dense(dmp_add_term(self.to_dense(f), self.wrap(c).drop(0).to_dense(), i, self.ngens-1, self.domain))
  259. def dup_sub_term(self, f, c, i):
  260. return self.from_dense(dup_sub_term(self.to_dense(f), c, i, self.domain))
  261. def dmp_sub_term(self, f, c, i):
  262. return self.from_dense(dmp_sub_term(self.to_dense(f), self.wrap(c).drop(0).to_dense(), i, self.ngens-1, self.domain))
  263. def dup_mul_term(self, f, c, i):
  264. return self.from_dense(dup_mul_term(self.to_dense(f), c, i, self.domain))
  265. def dmp_mul_term(self, f, c, i):
  266. return self.from_dense(dmp_mul_term(self.to_dense(f), self.wrap(c).drop(0).to_dense(), i, self.ngens-1, self.domain))
  267. def dup_add_ground(self, f, c):
  268. return self.from_dense(dup_add_ground(self.to_dense(f), c, self.domain))
  269. def dmp_add_ground(self, f, c):
  270. return self.from_dense(dmp_add_ground(self.to_dense(f), c, self.ngens-1, self.domain))
  271. def dup_sub_ground(self, f, c):
  272. return self.from_dense(dup_sub_ground(self.to_dense(f), c, self.domain))
  273. def dmp_sub_ground(self, f, c):
  274. return self.from_dense(dmp_sub_ground(self.to_dense(f), c, self.ngens-1, self.domain))
  275. def dup_mul_ground(self, f, c):
  276. return self.from_dense(dup_mul_ground(self.to_dense(f), c, self.domain))
  277. def dmp_mul_ground(self, f, c):
  278. return self.from_dense(dmp_mul_ground(self.to_dense(f), c, self.ngens-1, self.domain))
  279. def dup_quo_ground(self, f, c):
  280. return self.from_dense(dup_quo_ground(self.to_dense(f), c, self.domain))
  281. def dmp_quo_ground(self, f, c):
  282. return self.from_dense(dmp_quo_ground(self.to_dense(f), c, self.ngens-1, self.domain))
  283. def dup_exquo_ground(self, f, c):
  284. return self.from_dense(dup_exquo_ground(self.to_dense(f), c, self.domain))
  285. def dmp_exquo_ground(self, f, c):
  286. return self.from_dense(dmp_exquo_ground(self.to_dense(f), c, self.ngens-1, self.domain))
  287. def dup_lshift(self, f, n):
  288. return self.from_dense(dup_lshift(self.to_dense(f), n, self.domain))
  289. def dup_rshift(self, f, n):
  290. return self.from_dense(dup_rshift(self.to_dense(f), n, self.domain))
  291. def dup_abs(self, f):
  292. return self.from_dense(dup_abs(self.to_dense(f), self.domain))
  293. def dmp_abs(self, f):
  294. return self.from_dense(dmp_abs(self.to_dense(f), self.ngens-1, self.domain))
  295. def dup_neg(self, f):
  296. return self.from_dense(dup_neg(self.to_dense(f), self.domain))
  297. def dmp_neg(self, f):
  298. return self.from_dense(dmp_neg(self.to_dense(f), self.ngens-1, self.domain))
  299. def dup_add(self, f, g):
  300. return self.from_dense(dup_add(self.to_dense(f), self.to_dense(g), self.domain))
  301. def dmp_add(self, f, g):
  302. return self.from_dense(dmp_add(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain))
  303. def dup_sub(self, f, g):
  304. return self.from_dense(dup_sub(self.to_dense(f), self.to_dense(g), self.domain))
  305. def dmp_sub(self, f, g):
  306. return self.from_dense(dmp_sub(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain))
  307. def dup_add_mul(self, f, g, h):
  308. return self.from_dense(dup_add_mul(self.to_dense(f), self.to_dense(g), self.to_dense(h), self.domain))
  309. def dmp_add_mul(self, f, g, h):
  310. return self.from_dense(dmp_add_mul(self.to_dense(f), self.to_dense(g), self.to_dense(h), self.ngens-1, self.domain))
  311. def dup_sub_mul(self, f, g, h):
  312. return self.from_dense(dup_sub_mul(self.to_dense(f), self.to_dense(g), self.to_dense(h), self.domain))
  313. def dmp_sub_mul(self, f, g, h):
  314. return self.from_dense(dmp_sub_mul(self.to_dense(f), self.to_dense(g), self.to_dense(h), self.ngens-1, self.domain))
  315. def dup_mul(self, f, g):
  316. return self.from_dense(dup_mul(self.to_dense(f), self.to_dense(g), self.domain))
  317. def dmp_mul(self, f, g):
  318. return self.from_dense(dmp_mul(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain))
  319. def dup_sqr(self, f):
  320. return self.from_dense(dup_sqr(self.to_dense(f), self.domain))
  321. def dmp_sqr(self, f):
  322. return self.from_dense(dmp_sqr(self.to_dense(f), self.ngens-1, self.domain))
  323. def dup_pow(self, f, n):
  324. return self.from_dense(dup_pow(self.to_dense(f), n, self.domain))
  325. def dmp_pow(self, f, n):
  326. return self.from_dense(dmp_pow(self.to_dense(f), n, self.ngens-1, self.domain))
  327. def dup_pdiv(self, f, g):
  328. q, r = dup_pdiv(self.to_dense(f), self.to_dense(g), self.domain)
  329. return (self.from_dense(q), self.from_dense(r))
  330. def dup_prem(self, f, g):
  331. return self.from_dense(dup_prem(self.to_dense(f), self.to_dense(g), self.domain))
  332. def dup_pquo(self, f, g):
  333. return self.from_dense(dup_pquo(self.to_dense(f), self.to_dense(g), self.domain))
  334. def dup_pexquo(self, f, g):
  335. return self.from_dense(dup_pexquo(self.to_dense(f), self.to_dense(g), self.domain))
  336. def dmp_pdiv(self, f, g):
  337. q, r = dmp_pdiv(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  338. return (self.from_dense(q), self.from_dense(r))
  339. def dmp_prem(self, f, g):
  340. return self.from_dense(dmp_prem(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain))
  341. def dmp_pquo(self, f, g):
  342. return self.from_dense(dmp_pquo(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain))
  343. def dmp_pexquo(self, f, g):
  344. return self.from_dense(dmp_pexquo(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain))
  345. def dup_rr_div(self, f, g):
  346. q, r = dup_rr_div(self.to_dense(f), self.to_dense(g), self.domain)
  347. return (self.from_dense(q), self.from_dense(r))
  348. def dmp_rr_div(self, f, g):
  349. q, r = dmp_rr_div(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  350. return (self.from_dense(q), self.from_dense(r))
  351. def dup_ff_div(self, f, g):
  352. q, r = dup_ff_div(self.to_dense(f), self.to_dense(g), self.domain)
  353. return (self.from_dense(q), self.from_dense(r))
  354. def dmp_ff_div(self, f, g):
  355. q, r = dmp_ff_div(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  356. return (self.from_dense(q), self.from_dense(r))
  357. def dup_div(self, f, g):
  358. q, r = dup_div(self.to_dense(f), self.to_dense(g), self.domain)
  359. return (self.from_dense(q), self.from_dense(r))
  360. def dup_rem(self, f, g):
  361. return self.from_dense(dup_rem(self.to_dense(f), self.to_dense(g), self.domain))
  362. def dup_quo(self, f, g):
  363. return self.from_dense(dup_quo(self.to_dense(f), self.to_dense(g), self.domain))
  364. def dup_exquo(self, f, g):
  365. return self.from_dense(dup_exquo(self.to_dense(f), self.to_dense(g), self.domain))
  366. def dmp_div(self, f, g):
  367. q, r = dmp_div(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  368. return (self.from_dense(q), self.from_dense(r))
  369. def dmp_rem(self, f, g):
  370. return self.from_dense(dmp_rem(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain))
  371. def dmp_quo(self, f, g):
  372. return self.from_dense(dmp_quo(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain))
  373. def dmp_exquo(self, f, g):
  374. return self.from_dense(dmp_exquo(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain))
  375. def dup_max_norm(self, f):
  376. return dup_max_norm(self.to_dense(f), self.domain)
  377. def dmp_max_norm(self, f):
  378. return dmp_max_norm(self.to_dense(f), self.ngens-1, self.domain)
  379. def dup_l1_norm(self, f):
  380. return dup_l1_norm(self.to_dense(f), self.domain)
  381. def dmp_l1_norm(self, f):
  382. return dmp_l1_norm(self.to_dense(f), self.ngens-1, self.domain)
  383. def dup_l2_norm_squared(self, f):
  384. return dup_l2_norm_squared(self.to_dense(f), self.domain)
  385. def dmp_l2_norm_squared(self, f):
  386. return dmp_l2_norm_squared(self.to_dense(f), self.ngens-1, self.domain)
  387. def dup_expand(self, polys):
  388. return self.from_dense(dup_expand(list(map(self.to_dense, polys)), self.domain))
  389. def dmp_expand(self, polys):
  390. return self.from_dense(dmp_expand(list(map(self.to_dense, polys)), self.ngens-1, self.domain))
  391. def dup_LC(self, f):
  392. return dup_LC(self.to_dense(f), self.domain)
  393. def dmp_LC(self, f):
  394. LC = dmp_LC(self.to_dense(f), self.domain)
  395. if isinstance(LC, list):
  396. return self[1:].from_dense(LC)
  397. else:
  398. return LC
  399. def dup_TC(self, f):
  400. return dup_TC(self.to_dense(f), self.domain)
  401. def dmp_TC(self, f):
  402. TC = dmp_TC(self.to_dense(f), self.domain)
  403. if isinstance(TC, list):
  404. return self[1:].from_dense(TC)
  405. else:
  406. return TC
  407. def dmp_ground_LC(self, f):
  408. return dmp_ground_LC(self.to_dense(f), self.ngens-1, self.domain)
  409. def dmp_ground_TC(self, f):
  410. return dmp_ground_TC(self.to_dense(f), self.ngens-1, self.domain)
  411. def dup_degree(self, f):
  412. return dup_degree(self.to_dense(f))
  413. def dmp_degree(self, f):
  414. return dmp_degree(self.to_dense(f), self.ngens-1)
  415. def dmp_degree_in(self, f, j):
  416. return dmp_degree_in(self.to_dense(f), j, self.ngens-1)
  417. def dup_integrate(self, f, m):
  418. return self.from_dense(dup_integrate(self.to_dense(f), m, self.domain))
  419. def dmp_integrate(self, f, m):
  420. return self.from_dense(dmp_integrate(self.to_dense(f), m, self.ngens-1, self.domain))
  421. def dup_diff(self, f, m):
  422. return self.from_dense(dup_diff(self.to_dense(f), m, self.domain))
  423. def dmp_diff(self, f, m):
  424. return self.from_dense(dmp_diff(self.to_dense(f), m, self.ngens-1, self.domain))
  425. def dmp_diff_in(self, f, m, j):
  426. return self.from_dense(dmp_diff_in(self.to_dense(f), m, j, self.ngens-1, self.domain))
  427. def dmp_integrate_in(self, f, m, j):
  428. return self.from_dense(dmp_integrate_in(self.to_dense(f), m, j, self.ngens-1, self.domain))
  429. def dup_eval(self, f, a):
  430. return dup_eval(self.to_dense(f), a, self.domain)
  431. def dmp_eval(self, f, a):
  432. result = dmp_eval(self.to_dense(f), a, self.ngens-1, self.domain)
  433. return self[1:].from_dense(result)
  434. def dmp_eval_in(self, f, a, j):
  435. result = dmp_eval_in(self.to_dense(f), a, j, self.ngens-1, self.domain)
  436. return self.drop(j).from_dense(result)
  437. def dmp_diff_eval_in(self, f, m, a, j):
  438. result = dmp_diff_eval_in(self.to_dense(f), m, a, j, self.ngens-1, self.domain)
  439. return self.drop(j).from_dense(result)
  440. def dmp_eval_tail(self, f, A):
  441. result = dmp_eval_tail(self.to_dense(f), A, self.ngens-1, self.domain)
  442. if isinstance(result, list):
  443. return self[:-len(A)].from_dense(result)
  444. else:
  445. return result
  446. def dup_trunc(self, f, p):
  447. return self.from_dense(dup_trunc(self.to_dense(f), p, self.domain))
  448. def dmp_trunc(self, f, g):
  449. return self.from_dense(dmp_trunc(self.to_dense(f), self[1:].to_dense(g), self.ngens-1, self.domain))
  450. def dmp_ground_trunc(self, f, p):
  451. return self.from_dense(dmp_ground_trunc(self.to_dense(f), p, self.ngens-1, self.domain))
  452. def dup_monic(self, f):
  453. return self.from_dense(dup_monic(self.to_dense(f), self.domain))
  454. def dmp_ground_monic(self, f):
  455. return self.from_dense(dmp_ground_monic(self.to_dense(f), self.ngens-1, self.domain))
  456. def dup_extract(self, f, g):
  457. c, F, G = dup_extract(self.to_dense(f), self.to_dense(g), self.domain)
  458. return (c, self.from_dense(F), self.from_dense(G))
  459. def dmp_ground_extract(self, f, g):
  460. c, F, G = dmp_ground_extract(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  461. return (c, self.from_dense(F), self.from_dense(G))
  462. def dup_real_imag(self, f):
  463. p, q = dup_real_imag(self.wrap(f).drop(1).to_dense(), self.domain)
  464. return (self.from_dense(p), self.from_dense(q))
  465. def dup_mirror(self, f):
  466. return self.from_dense(dup_mirror(self.to_dense(f), self.domain))
  467. def dup_scale(self, f, a):
  468. return self.from_dense(dup_scale(self.to_dense(f), a, self.domain))
  469. def dup_shift(self, f, a):
  470. return self.from_dense(dup_shift(self.to_dense(f), a, self.domain))
  471. def dup_transform(self, f, p, q):
  472. return self.from_dense(dup_transform(self.to_dense(f), self.to_dense(p), self.to_dense(q), self.domain))
  473. def dup_compose(self, f, g):
  474. return self.from_dense(dup_compose(self.to_dense(f), self.to_dense(g), self.domain))
  475. def dmp_compose(self, f, g):
  476. return self.from_dense(dmp_compose(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain))
  477. def dup_decompose(self, f):
  478. components = dup_decompose(self.to_dense(f), self.domain)
  479. return list(map(self.from_dense, components))
  480. def dmp_lift(self, f):
  481. result = dmp_lift(self.to_dense(f), self.ngens-1, self.domain)
  482. return self.to_ground().from_dense(result)
  483. def dup_sign_variations(self, f):
  484. return dup_sign_variations(self.to_dense(f), self.domain)
  485. def dup_clear_denoms(self, f, convert=False):
  486. c, F = dup_clear_denoms(self.to_dense(f), self.domain, convert=convert)
  487. if convert:
  488. ring = self.clone(domain=self.domain.get_ring())
  489. else:
  490. ring = self
  491. return (c, ring.from_dense(F))
  492. def dmp_clear_denoms(self, f, convert=False):
  493. c, F = dmp_clear_denoms(self.to_dense(f), self.ngens-1, self.domain, convert=convert)
  494. if convert:
  495. ring = self.clone(domain=self.domain.get_ring())
  496. else:
  497. ring = self
  498. return (c, ring.from_dense(F))
  499. def dup_revert(self, f, n):
  500. return self.from_dense(dup_revert(self.to_dense(f), n, self.domain))
  501. def dup_half_gcdex(self, f, g):
  502. s, h = dup_half_gcdex(self.to_dense(f), self.to_dense(g), self.domain)
  503. return (self.from_dense(s), self.from_dense(h))
  504. def dmp_half_gcdex(self, f, g):
  505. s, h = dmp_half_gcdex(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  506. return (self.from_dense(s), self.from_dense(h))
  507. def dup_gcdex(self, f, g):
  508. s, t, h = dup_gcdex(self.to_dense(f), self.to_dense(g), self.domain)
  509. return (self.from_dense(s), self.from_dense(t), self.from_dense(h))
  510. def dmp_gcdex(self, f, g):
  511. s, t, h = dmp_gcdex(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  512. return (self.from_dense(s), self.from_dense(t), self.from_dense(h))
  513. def dup_invert(self, f, g):
  514. return self.from_dense(dup_invert(self.to_dense(f), self.to_dense(g), self.domain))
  515. def dmp_invert(self, f, g):
  516. return self.from_dense(dmp_invert(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain))
  517. def dup_euclidean_prs(self, f, g):
  518. prs = dup_euclidean_prs(self.to_dense(f), self.to_dense(g), self.domain)
  519. return list(map(self.from_dense, prs))
  520. def dmp_euclidean_prs(self, f, g):
  521. prs = dmp_euclidean_prs(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  522. return list(map(self.from_dense, prs))
  523. def dup_primitive_prs(self, f, g):
  524. prs = dup_primitive_prs(self.to_dense(f), self.to_dense(g), self.domain)
  525. return list(map(self.from_dense, prs))
  526. def dmp_primitive_prs(self, f, g):
  527. prs = dmp_primitive_prs(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  528. return list(map(self.from_dense, prs))
  529. def dup_inner_subresultants(self, f, g):
  530. prs, sres = dup_inner_subresultants(self.to_dense(f), self.to_dense(g), self.domain)
  531. return (list(map(self.from_dense, prs)), sres)
  532. def dmp_inner_subresultants(self, f, g):
  533. prs, sres = dmp_inner_subresultants(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  534. return (list(map(self.from_dense, prs)), sres)
  535. def dup_subresultants(self, f, g):
  536. prs = dup_subresultants(self.to_dense(f), self.to_dense(g), self.domain)
  537. return list(map(self.from_dense, prs))
  538. def dmp_subresultants(self, f, g):
  539. prs = dmp_subresultants(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  540. return list(map(self.from_dense, prs))
  541. def dup_prs_resultant(self, f, g):
  542. res, prs = dup_prs_resultant(self.to_dense(f), self.to_dense(g), self.domain)
  543. return (res, list(map(self.from_dense, prs)))
  544. def dmp_prs_resultant(self, f, g):
  545. res, prs = dmp_prs_resultant(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  546. return (self[1:].from_dense(res), list(map(self.from_dense, prs)))
  547. def dmp_zz_modular_resultant(self, f, g, p):
  548. res = dmp_zz_modular_resultant(self.to_dense(f), self.to_dense(g), self.domain_new(p), self.ngens-1, self.domain)
  549. return self[1:].from_dense(res)
  550. def dmp_zz_collins_resultant(self, f, g):
  551. res = dmp_zz_collins_resultant(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  552. return self[1:].from_dense(res)
  553. def dmp_qq_collins_resultant(self, f, g):
  554. res = dmp_qq_collins_resultant(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  555. return self[1:].from_dense(res)
  556. def dup_resultant(self, f, g): #, includePRS=False):
  557. return dup_resultant(self.to_dense(f), self.to_dense(g), self.domain) #, includePRS=includePRS)
  558. def dmp_resultant(self, f, g): #, includePRS=False):
  559. res = dmp_resultant(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain) #, includePRS=includePRS)
  560. if isinstance(res, list):
  561. return self[1:].from_dense(res)
  562. else:
  563. return res
  564. def dup_discriminant(self, f):
  565. return dup_discriminant(self.to_dense(f), self.domain)
  566. def dmp_discriminant(self, f):
  567. disc = dmp_discriminant(self.to_dense(f), self.ngens-1, self.domain)
  568. if isinstance(disc, list):
  569. return self[1:].from_dense(disc)
  570. else:
  571. return disc
  572. def dup_rr_prs_gcd(self, f, g):
  573. H, F, G = dup_rr_prs_gcd(self.to_dense(f), self.to_dense(g), self.domain)
  574. return (self.from_dense(H), self.from_dense(F), self.from_dense(G))
  575. def dup_ff_prs_gcd(self, f, g):
  576. H, F, G = dup_ff_prs_gcd(self.to_dense(f), self.to_dense(g), self.domain)
  577. return (self.from_dense(H), self.from_dense(F), self.from_dense(G))
  578. def dmp_rr_prs_gcd(self, f, g):
  579. H, F, G = dmp_rr_prs_gcd(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  580. return (self.from_dense(H), self.from_dense(F), self.from_dense(G))
  581. def dmp_ff_prs_gcd(self, f, g):
  582. H, F, G = dmp_ff_prs_gcd(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  583. return (self.from_dense(H), self.from_dense(F), self.from_dense(G))
  584. def dup_zz_heu_gcd(self, f, g):
  585. H, F, G = dup_zz_heu_gcd(self.to_dense(f), self.to_dense(g), self.domain)
  586. return (self.from_dense(H), self.from_dense(F), self.from_dense(G))
  587. def dmp_zz_heu_gcd(self, f, g):
  588. H, F, G = dmp_zz_heu_gcd(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  589. return (self.from_dense(H), self.from_dense(F), self.from_dense(G))
  590. def dup_qq_heu_gcd(self, f, g):
  591. H, F, G = dup_qq_heu_gcd(self.to_dense(f), self.to_dense(g), self.domain)
  592. return (self.from_dense(H), self.from_dense(F), self.from_dense(G))
  593. def dmp_qq_heu_gcd(self, f, g):
  594. H, F, G = dmp_qq_heu_gcd(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  595. return (self.from_dense(H), self.from_dense(F), self.from_dense(G))
  596. def dup_inner_gcd(self, f, g):
  597. H, F, G = dup_inner_gcd(self.to_dense(f), self.to_dense(g), self.domain)
  598. return (self.from_dense(H), self.from_dense(F), self.from_dense(G))
  599. def dmp_inner_gcd(self, f, g):
  600. H, F, G = dmp_inner_gcd(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  601. return (self.from_dense(H), self.from_dense(F), self.from_dense(G))
  602. def dup_gcd(self, f, g):
  603. H = dup_gcd(self.to_dense(f), self.to_dense(g), self.domain)
  604. return self.from_dense(H)
  605. def dmp_gcd(self, f, g):
  606. H = dmp_gcd(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  607. return self.from_dense(H)
  608. def dup_rr_lcm(self, f, g):
  609. H = dup_rr_lcm(self.to_dense(f), self.to_dense(g), self.domain)
  610. return self.from_dense(H)
  611. def dup_ff_lcm(self, f, g):
  612. H = dup_ff_lcm(self.to_dense(f), self.to_dense(g), self.domain)
  613. return self.from_dense(H)
  614. def dup_lcm(self, f, g):
  615. H = dup_lcm(self.to_dense(f), self.to_dense(g), self.domain)
  616. return self.from_dense(H)
  617. def dmp_rr_lcm(self, f, g):
  618. H = dmp_rr_lcm(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  619. return self.from_dense(H)
  620. def dmp_ff_lcm(self, f, g):
  621. H = dmp_ff_lcm(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  622. return self.from_dense(H)
  623. def dmp_lcm(self, f, g):
  624. H = dmp_lcm(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain)
  625. return self.from_dense(H)
  626. def dup_content(self, f):
  627. cont = dup_content(self.to_dense(f), self.domain)
  628. return cont
  629. def dup_primitive(self, f):
  630. cont, prim = dup_primitive(self.to_dense(f), self.domain)
  631. return cont, self.from_dense(prim)
  632. def dmp_content(self, f):
  633. cont = dmp_content(self.to_dense(f), self.ngens-1, self.domain)
  634. if isinstance(cont, list):
  635. return self[1:].from_dense(cont)
  636. else:
  637. return cont
  638. def dmp_primitive(self, f):
  639. cont, prim = dmp_primitive(self.to_dense(f), self.ngens-1, self.domain)
  640. if isinstance(cont, list):
  641. return (self[1:].from_dense(cont), self.from_dense(prim))
  642. else:
  643. return (cont, self.from_dense(prim))
  644. def dmp_ground_content(self, f):
  645. cont = dmp_ground_content(self.to_dense(f), self.ngens-1, self.domain)
  646. return cont
  647. def dmp_ground_primitive(self, f):
  648. cont, prim = dmp_ground_primitive(self.to_dense(f), self.ngens-1, self.domain)
  649. return (cont, self.from_dense(prim))
  650. def dup_cancel(self, f, g, include=True):
  651. result = dup_cancel(self.to_dense(f), self.to_dense(g), self.domain, include=include)
  652. if not include:
  653. cf, cg, F, G = result
  654. return (cf, cg, self.from_dense(F), self.from_dense(G))
  655. else:
  656. F, G = result
  657. return (self.from_dense(F), self.from_dense(G))
  658. def dmp_cancel(self, f, g, include=True):
  659. result = dmp_cancel(self.to_dense(f), self.to_dense(g), self.ngens-1, self.domain, include=include)
  660. if not include:
  661. cf, cg, F, G = result
  662. return (cf, cg, self.from_dense(F), self.from_dense(G))
  663. else:
  664. F, G = result
  665. return (self.from_dense(F), self.from_dense(G))
  666. def dup_trial_division(self, f, factors):
  667. factors = dup_trial_division(self.to_dense(f), list(map(self.to_dense, factors)), self.domain)
  668. return [ (self.from_dense(g), k) for g, k in factors ]
  669. def dmp_trial_division(self, f, factors):
  670. factors = dmp_trial_division(self.to_dense(f), list(map(self.to_dense, factors)), self.ngens-1, self.domain)
  671. return [ (self.from_dense(g), k) for g, k in factors ]
  672. def dup_zz_mignotte_bound(self, f):
  673. return dup_zz_mignotte_bound(self.to_dense(f), self.domain)
  674. def dmp_zz_mignotte_bound(self, f):
  675. return dmp_zz_mignotte_bound(self.to_dense(f), self.ngens-1, self.domain)
  676. def dup_zz_hensel_step(self, m, f, g, h, s, t):
  677. D = self.to_dense
  678. G, H, S, T = dup_zz_hensel_step(m, D(f), D(g), D(h), D(s), D(t), self.domain)
  679. return (self.from_dense(G), self.from_dense(H), self.from_dense(S), self.from_dense(T))
  680. def dup_zz_hensel_lift(self, p, f, f_list, l):
  681. D = self.to_dense
  682. polys = dup_zz_hensel_lift(p, D(f), list(map(D, f_list)), l, self.domain)
  683. return list(map(self.from_dense, polys))
  684. def dup_zz_zassenhaus(self, f):
  685. factors = dup_zz_zassenhaus(self.to_dense(f), self.domain)
  686. return [ (self.from_dense(g), k) for g, k in factors ]
  687. def dup_zz_irreducible_p(self, f):
  688. return dup_zz_irreducible_p(self.to_dense(f), self.domain)
  689. def dup_cyclotomic_p(self, f, irreducible=False):
  690. return dup_cyclotomic_p(self.to_dense(f), self.domain, irreducible=irreducible)
  691. def dup_zz_cyclotomic_poly(self, n):
  692. F = dup_zz_cyclotomic_poly(n, self.domain)
  693. return self.from_dense(F)
  694. def dup_zz_cyclotomic_factor(self, f):
  695. result = dup_zz_cyclotomic_factor(self.to_dense(f), self.domain)
  696. if result is None:
  697. return result
  698. else:
  699. return list(map(self.from_dense, result))
  700. # E: List[ZZ], cs: ZZ, ct: ZZ
  701. def dmp_zz_wang_non_divisors(self, E, cs, ct):
  702. return dmp_zz_wang_non_divisors(E, cs, ct, self.domain)
  703. # f: Poly, T: List[(Poly, int)], ct: ZZ, A: List[ZZ]
  704. #def dmp_zz_wang_test_points(f, T, ct, A):
  705. # dmp_zz_wang_test_points(self.to_dense(f), T, ct, A, self.ngens-1, self.domain)
  706. # f: Poly, T: List[(Poly, int)], cs: ZZ, E: List[ZZ], H: List[Poly], A: List[ZZ]
  707. def dmp_zz_wang_lead_coeffs(self, f, T, cs, E, H, A):
  708. mv = self[1:]
  709. T = [ (mv.to_dense(t), k) for t, k in T ]
  710. uv = self[:1]
  711. H = list(map(uv.to_dense, H))
  712. f, HH, CC = dmp_zz_wang_lead_coeffs(self.to_dense(f), T, cs, E, H, A, self.ngens-1, self.domain)
  713. return self.from_dense(f), list(map(uv.from_dense, HH)), list(map(mv.from_dense, CC))
  714. # f: List[Poly], m: int, p: ZZ
  715. def dup_zz_diophantine(self, F, m, p):
  716. result = dup_zz_diophantine(list(map(self.to_dense, F)), m, p, self.domain)
  717. return list(map(self.from_dense, result))
  718. # f: List[Poly], c: List[Poly], A: List[ZZ], d: int, p: ZZ
  719. def dmp_zz_diophantine(self, F, c, A, d, p):
  720. result = dmp_zz_diophantine(list(map(self.to_dense, F)), self.to_dense(c), A, d, p, self.ngens-1, self.domain)
  721. return list(map(self.from_dense, result))
  722. # f: Poly, H: List[Poly], LC: List[Poly], A: List[ZZ], p: ZZ
  723. def dmp_zz_wang_hensel_lifting(self, f, H, LC, A, p):
  724. uv = self[:1]
  725. mv = self[1:]
  726. H = list(map(uv.to_dense, H))
  727. LC = list(map(mv.to_dense, LC))
  728. result = dmp_zz_wang_hensel_lifting(self.to_dense(f), H, LC, A, p, self.ngens-1, self.domain)
  729. return list(map(self.from_dense, result))
  730. def dmp_zz_wang(self, f, mod=None, seed=None):
  731. factors = dmp_zz_wang(self.to_dense(f), self.ngens-1, self.domain, mod=mod, seed=seed)
  732. return [ self.from_dense(g) for g in factors ]
  733. def dup_zz_factor_sqf(self, f):
  734. coeff, factors = dup_zz_factor_sqf(self.to_dense(f), self.domain)
  735. return (coeff, [ self.from_dense(g) for g in factors ])
  736. def dup_zz_factor(self, f):
  737. coeff, factors = dup_zz_factor(self.to_dense(f), self.domain)
  738. return (coeff, [ (self.from_dense(g), k) for g, k in factors ])
  739. def dmp_zz_factor(self, f):
  740. coeff, factors = dmp_zz_factor(self.to_dense(f), self.ngens-1, self.domain)
  741. return (coeff, [ (self.from_dense(g), k) for g, k in factors ])
  742. def dup_qq_i_factor(self, f):
  743. coeff, factors = dup_qq_i_factor(self.to_dense(f), self.domain)
  744. return (coeff, [ (self.from_dense(g), k) for g, k in factors ])
  745. def dmp_qq_i_factor(self, f):
  746. coeff, factors = dmp_qq_i_factor(self.to_dense(f), self.ngens-1, self.domain)
  747. return (coeff, [ (self.from_dense(g), k) for g, k in factors ])
  748. def dup_zz_i_factor(self, f):
  749. coeff, factors = dup_zz_i_factor(self.to_dense(f), self.domain)
  750. return (coeff, [ (self.from_dense(g), k) for g, k in factors ])
  751. def dmp_zz_i_factor(self, f):
  752. coeff, factors = dmp_zz_i_factor(self.to_dense(f), self.ngens-1, self.domain)
  753. return (coeff, [ (self.from_dense(g), k) for g, k in factors ])
  754. def dup_ext_factor(self, f):
  755. coeff, factors = dup_ext_factor(self.to_dense(f), self.domain)
  756. return (coeff, [ (self.from_dense(g), k) for g, k in factors ])
  757. def dmp_ext_factor(self, f):
  758. coeff, factors = dmp_ext_factor(self.to_dense(f), self.ngens-1, self.domain)
  759. return (coeff, [ (self.from_dense(g), k) for g, k in factors ])
  760. def dup_gf_factor(self, f):
  761. coeff, factors = dup_gf_factor(self.to_dense(f), self.domain)
  762. return (coeff, [ (self.from_dense(g), k) for g, k in factors ])
  763. def dmp_gf_factor(self, f):
  764. coeff, factors = dmp_gf_factor(self.to_dense(f), self.ngens-1, self.domain)
  765. return (coeff, [ (self.from_dense(g), k) for g, k in factors ])
  766. def dup_factor_list(self, f):
  767. coeff, factors = dup_factor_list(self.to_dense(f), self.domain)
  768. return (coeff, [ (self.from_dense(g), k) for g, k in factors ])
  769. def dup_factor_list_include(self, f):
  770. factors = dup_factor_list_include(self.to_dense(f), self.domain)
  771. return [ (self.from_dense(g), k) for g, k in factors ]
  772. def dmp_factor_list(self, f):
  773. coeff, factors = dmp_factor_list(self.to_dense(f), self.ngens-1, self.domain)
  774. return (coeff, [ (self.from_dense(g), k) for g, k in factors ])
  775. def dmp_factor_list_include(self, f):
  776. factors = dmp_factor_list_include(self.to_dense(f), self.ngens-1, self.domain)
  777. return [ (self.from_dense(g), k) for g, k in factors ]
  778. def dup_irreducible_p(self, f):
  779. return dup_irreducible_p(self.to_dense(f), self.domain)
  780. def dmp_irreducible_p(self, f):
  781. return dmp_irreducible_p(self.to_dense(f), self.ngens-1, self.domain)
  782. def dup_sturm(self, f):
  783. seq = dup_sturm(self.to_dense(f), self.domain)
  784. return list(map(self.from_dense, seq))
  785. def dup_sqf_p(self, f):
  786. return dup_sqf_p(self.to_dense(f), self.domain)
  787. def dmp_sqf_p(self, f):
  788. return dmp_sqf_p(self.to_dense(f), self.ngens-1, self.domain)
  789. def dup_sqf_norm(self, f):
  790. s, F, R = dup_sqf_norm(self.to_dense(f), self.domain)
  791. return (s, self.from_dense(F), self.to_ground().from_dense(R))
  792. def dmp_sqf_norm(self, f):
  793. s, F, R = dmp_sqf_norm(self.to_dense(f), self.ngens-1, self.domain)
  794. return (s, self.from_dense(F), self.to_ground().from_dense(R))
  795. def dup_gf_sqf_part(self, f):
  796. return self.from_dense(dup_gf_sqf_part(self.to_dense(f), self.domain))
  797. def dmp_gf_sqf_part(self, f):
  798. return self.from_dense(dmp_gf_sqf_part(self.to_dense(f), self.domain))
  799. def dup_sqf_part(self, f):
  800. return self.from_dense(dup_sqf_part(self.to_dense(f), self.domain))
  801. def dmp_sqf_part(self, f):
  802. return self.from_dense(dmp_sqf_part(self.to_dense(f), self.ngens-1, self.domain))
  803. def dup_gf_sqf_list(self, f, all=False):
  804. coeff, factors = dup_gf_sqf_list(self.to_dense(f), self.domain, all=all)
  805. return (coeff, [ (self.from_dense(g), k) for g, k in factors ])
  806. def dmp_gf_sqf_list(self, f, all=False):
  807. coeff, factors = dmp_gf_sqf_list(self.to_dense(f), self.ngens-1, self.domain, all=all)
  808. return (coeff, [ (self.from_dense(g), k) for g, k in factors ])
  809. def dup_sqf_list(self, f, all=False):
  810. coeff, factors = dup_sqf_list(self.to_dense(f), self.domain, all=all)
  811. return (coeff, [ (self.from_dense(g), k) for g, k in factors ])
  812. def dup_sqf_list_include(self, f, all=False):
  813. factors = dup_sqf_list_include(self.to_dense(f), self.domain, all=all)
  814. return [ (self.from_dense(g), k) for g, k in factors ]
  815. def dmp_sqf_list(self, f, all=False):
  816. coeff, factors = dmp_sqf_list(self.to_dense(f), self.ngens-1, self.domain, all=all)
  817. return (coeff, [ (self.from_dense(g), k) for g, k in factors ])
  818. def dmp_sqf_list_include(self, f, all=False):
  819. factors = dmp_sqf_list_include(self.to_dense(f), self.ngens-1, self.domain, all=all)
  820. return [ (self.from_dense(g), k) for g, k in factors ]
  821. def dup_gff_list(self, f):
  822. factors = dup_gff_list(self.to_dense(f), self.domain)
  823. return [ (self.from_dense(g), k) for g, k in factors ]
  824. def dmp_gff_list(self, f):
  825. factors = dmp_gff_list(self.to_dense(f), self.ngens-1, self.domain)
  826. return [ (self.from_dense(g), k) for g, k in factors ]
  827. def dup_root_upper_bound(self, f):
  828. return dup_root_upper_bound(self.to_dense(f), self.domain)
  829. def dup_root_lower_bound(self, f):
  830. return dup_root_lower_bound(self.to_dense(f), self.domain)
  831. def dup_step_refine_real_root(self, f, M, fast=False):
  832. return dup_step_refine_real_root(self.to_dense(f), M, self.domain, fast=fast)
  833. def dup_inner_refine_real_root(self, f, M, eps=None, steps=None, disjoint=None, fast=False, mobius=False):
  834. return dup_inner_refine_real_root(self.to_dense(f), M, self.domain, eps=eps, steps=steps, disjoint=disjoint, fast=fast, mobius=mobius)
  835. def dup_outer_refine_real_root(self, f, s, t, eps=None, steps=None, disjoint=None, fast=False):
  836. return dup_outer_refine_real_root(self.to_dense(f), s, t, self.domain, eps=eps, steps=steps, disjoint=disjoint, fast=fast)
  837. def dup_refine_real_root(self, f, s, t, eps=None, steps=None, disjoint=None, fast=False):
  838. return dup_refine_real_root(self.to_dense(f), s, t, self.domain, eps=eps, steps=steps, disjoint=disjoint, fast=fast)
  839. def dup_inner_isolate_real_roots(self, f, eps=None, fast=False):
  840. return dup_inner_isolate_real_roots(self.to_dense(f), self.domain, eps=eps, fast=fast)
  841. def dup_inner_isolate_positive_roots(self, f, eps=None, inf=None, sup=None, fast=False, mobius=False):
  842. return dup_inner_isolate_positive_roots(self.to_dense(f), self.domain, eps=eps, inf=inf, sup=sup, fast=fast, mobius=mobius)
  843. def dup_inner_isolate_negative_roots(self, f, inf=None, sup=None, eps=None, fast=False, mobius=False):
  844. return dup_inner_isolate_negative_roots(self.to_dense(f), self.domain, inf=inf, sup=sup, eps=eps, fast=fast, mobius=mobius)
  845. def dup_isolate_real_roots_sqf(self, f, eps=None, inf=None, sup=None, fast=False, blackbox=False):
  846. return dup_isolate_real_roots_sqf(self.to_dense(f), self.domain, eps=eps, inf=inf, sup=sup, fast=fast, blackbox=blackbox)
  847. def dup_isolate_real_roots(self, f, eps=None, inf=None, sup=None, basis=False, fast=False):
  848. return dup_isolate_real_roots(self.to_dense(f), self.domain, eps=eps, inf=inf, sup=sup, basis=basis, fast=fast)
  849. def dup_isolate_real_roots_list(self, polys, eps=None, inf=None, sup=None, strict=False, basis=False, fast=False):
  850. return dup_isolate_real_roots_list(list(map(self.to_dense, polys)), self.domain, eps=eps, inf=inf, sup=sup, strict=strict, basis=basis, fast=fast)
  851. def dup_count_real_roots(self, f, inf=None, sup=None):
  852. return dup_count_real_roots(self.to_dense(f), self.domain, inf=inf, sup=sup)
  853. def dup_count_complex_roots(self, f, inf=None, sup=None, exclude=None):
  854. return dup_count_complex_roots(self.to_dense(f), self.domain, inf=inf, sup=sup, exclude=exclude)
  855. def dup_isolate_complex_roots_sqf(self, f, eps=None, inf=None, sup=None, blackbox=False):
  856. return dup_isolate_complex_roots_sqf(self.to_dense(f), self.domain, eps=eps, inf=inf, sup=sup, blackbox=blackbox)
  857. def dup_isolate_all_roots_sqf(self, f, eps=None, inf=None, sup=None, fast=False, blackbox=False):
  858. return dup_isolate_all_roots_sqf(self.to_dense(f), self.domain, eps=eps, inf=inf, sup=sup, fast=fast, blackbox=blackbox)
  859. def dup_isolate_all_roots(self, f, eps=None, inf=None, sup=None, fast=False):
  860. return dup_isolate_all_roots(self.to_dense(f), self.domain, eps=eps, inf=inf, sup=sup, fast=fast)
  861. def fateman_poly_F_1(self):
  862. from sympy.polys.specialpolys import dmp_fateman_poly_F_1
  863. return tuple(map(self.from_dense, dmp_fateman_poly_F_1(self.ngens-1, self.domain)))
  864. def fateman_poly_F_2(self):
  865. from sympy.polys.specialpolys import dmp_fateman_poly_F_2
  866. return tuple(map(self.from_dense, dmp_fateman_poly_F_2(self.ngens-1, self.domain)))
  867. def fateman_poly_F_3(self):
  868. from sympy.polys.specialpolys import dmp_fateman_poly_F_3
  869. return tuple(map(self.from_dense, dmp_fateman_poly_F_3(self.ngens-1, self.domain)))
  870. def to_gf_dense(self, element):
  871. return gf_strip([ self.domain.dom.convert(c, self.domain) for c in self.wrap(element).to_dense() ])
  872. def from_gf_dense(self, element):
  873. return self.from_dict(dmp_to_dict(element, self.ngens-1, self.domain.dom))
  874. def gf_degree(self, f):
  875. return gf_degree(self.to_gf_dense(f))
  876. def gf_LC(self, f):
  877. return gf_LC(self.to_gf_dense(f), self.domain.dom)
  878. def gf_TC(self, f):
  879. return gf_TC(self.to_gf_dense(f), self.domain.dom)
  880. def gf_strip(self, f):
  881. return self.from_gf_dense(gf_strip(self.to_gf_dense(f)))
  882. def gf_trunc(self, f):
  883. return self.from_gf_dense(gf_strip(self.to_gf_dense(f), self.domain.mod))
  884. def gf_normal(self, f):
  885. return self.from_gf_dense(gf_strip(self.to_gf_dense(f), self.domain.mod, self.domain.dom))
  886. def gf_from_dict(self, f):
  887. return self.from_gf_dense(gf_from_dict(f, self.domain.mod, self.domain.dom))
  888. def gf_to_dict(self, f, symmetric=True):
  889. return gf_to_dict(self.to_gf_dense(f), self.domain.mod, symmetric=symmetric)
  890. def gf_from_int_poly(self, f):
  891. return self.from_gf_dense(gf_from_int_poly(f, self.domain.mod))
  892. def gf_to_int_poly(self, f, symmetric=True):
  893. return gf_to_int_poly(self.to_gf_dense(f), self.domain.mod, symmetric=symmetric)
  894. def gf_neg(self, f):
  895. return self.from_gf_dense(gf_neg(self.to_gf_dense(f), self.domain.mod, self.domain.dom))
  896. def gf_add_ground(self, f, a):
  897. return self.from_gf_dense(gf_add_ground(self.to_gf_dense(f), a, self.domain.mod, self.domain.dom))
  898. def gf_sub_ground(self, f, a):
  899. return self.from_gf_dense(gf_sub_ground(self.to_gf_dense(f), a, self.domain.mod, self.domain.dom))
  900. def gf_mul_ground(self, f, a):
  901. return self.from_gf_dense(gf_mul_ground(self.to_gf_dense(f), a, self.domain.mod, self.domain.dom))
  902. def gf_quo_ground(self, f, a):
  903. return self.from_gf_dense(gf_quo_ground(self.to_gf_dense(f), a, self.domain.mod, self.domain.dom))
  904. def gf_add(self, f, g):
  905. return self.from_gf_dense(gf_add(self.to_gf_dense(f), self.to_gf_dense(g), self.domain.mod, self.domain.dom))
  906. def gf_sub(self, f, g):
  907. return self.from_gf_dense(gf_sub(self.to_gf_dense(f), self.to_gf_dense(g), self.domain.mod, self.domain.dom))
  908. def gf_mul(self, f, g):
  909. return self.from_gf_dense(gf_mul(self.to_gf_dense(f), self.to_gf_dense(g), self.domain.mod, self.domain.dom))
  910. def gf_sqr(self, f):
  911. return self.from_gf_dense(gf_sqr(self.to_gf_dense(f), self.domain.mod, self.domain.dom))
  912. def gf_add_mul(self, f, g, h):
  913. return self.from_gf_dense(gf_add_mul(self.to_gf_dense(f), self.to_gf_dense(g), self.to_gf_dense(h), self.domain.mod, self.domain.dom))
  914. def gf_sub_mul(self, f, g, h):
  915. return self.from_gf_dense(gf_sub_mul(self.to_gf_dense(f), self.to_gf_dense(g), self.to_gf_dense(h), self.domain.mod, self.domain.dom))
  916. def gf_expand(self, F):
  917. return self.from_gf_dense(gf_expand(list(map(self.to_gf_dense, F)), self.domain.mod, self.domain.dom))
  918. def gf_div(self, f, g):
  919. q, r = gf_div(self.to_gf_dense(f), self.to_gf_dense(g), self.domain.mod, self.domain.dom)
  920. return self.from_gf_dense(q), self.from_gf_dense(r)
  921. def gf_rem(self, f, g):
  922. return self.from_gf_dense(gf_rem(self.to_gf_dense(f), self.to_gf_dense(g), self.domain.mod, self.domain.dom))
  923. def gf_quo(self, f, g):
  924. return self.from_gf_dense(gf_quo(self.to_gf_dense(f), self.to_gf_dense(g), self.domain.mod, self.domain.dom))
  925. def gf_exquo(self, f, g):
  926. return self.from_gf_dense(gf_exquo(self.to_gf_dense(f), self.to_gf_dense(g), self.domain.mod, self.domain.dom))
  927. def gf_lshift(self, f, n):
  928. return self.from_gf_dense(gf_lshift(self.to_gf_dense(f), n, self.domain.dom))
  929. def gf_rshift(self, f, n):
  930. return self.from_gf_dense(gf_rshift(self.to_gf_dense(f), n, self.domain.dom))
  931. def gf_pow(self, f, n):
  932. return self.from_gf_dense(gf_pow(self.to_gf_dense(f), n, self.domain.mod, self.domain.dom))
  933. def gf_pow_mod(self, f, n, g):
  934. return self.from_gf_dense(gf_pow_mod(self.to_gf_dense(f), n, self.to_gf_dense(g), self.domain.mod, self.domain.dom))
  935. def gf_cofactors(self, f, g):
  936. h, cff, cfg = gf_cofactors(self.to_gf_dense(f), self.to_gf_dense(g), self.domain.mod, self.domain.dom)
  937. return self.from_gf_dense(h), self.from_gf_dense(cff), self.from_gf_dense(cfg)
  938. def gf_gcd(self, f, g):
  939. return self.from_gf_dense(gf_gcd(self.to_gf_dense(f), self.to_gf_dense(g), self.domain.mod, self.domain.dom))
  940. def gf_lcm(self, f, g):
  941. return self.from_gf_dense(gf_lcm(self.to_gf_dense(f), self.to_gf_dense(g), self.domain.mod, self.domain.dom))
  942. def gf_gcdex(self, f, g):
  943. return self.from_gf_dense(gf_gcdex(self.to_gf_dense(f), self.to_gf_dense(g), self.domain.mod, self.domain.dom))
  944. def gf_monic(self, f):
  945. return self.from_gf_dense(gf_monic(self.to_gf_dense(f), self.domain.mod, self.domain.dom))
  946. def gf_diff(self, f):
  947. return self.from_gf_dense(gf_diff(self.to_gf_dense(f), self.domain.mod, self.domain.dom))
  948. def gf_eval(self, f, a):
  949. return gf_eval(self.to_gf_dense(f), a, self.domain.mod, self.domain.dom)
  950. def gf_multi_eval(self, f, A):
  951. return gf_multi_eval(self.to_gf_dense(f), A, self.domain.mod, self.domain.dom)
  952. def gf_compose(self, f, g):
  953. return self.from_gf_dense(gf_compose(self.to_gf_dense(f), self.to_gf_dense(g), self.domain.mod, self.domain.dom))
  954. def gf_compose_mod(self, g, h, f):
  955. return self.from_gf_dense(gf_compose_mod(self.to_gf_dense(g), self.to_gf_dense(h), self.to_gf_dense(f), self.domain.mod, self.domain.dom))
  956. def gf_trace_map(self, a, b, c, n, f):
  957. a = self.to_gf_dense(a)
  958. b = self.to_gf_dense(b)
  959. c = self.to_gf_dense(c)
  960. f = self.to_gf_dense(f)
  961. U, V = gf_trace_map(a, b, c, n, f, self.domain.mod, self.domain.dom)
  962. return self.from_gf_dense(U), self.from_gf_dense(V)
  963. def gf_random(self, n):
  964. return self.from_gf_dense(gf_random(n, self.domain.mod, self.domain.dom))
  965. def gf_irreducible(self, n):
  966. return self.from_gf_dense(gf_irreducible(n, self.domain.mod, self.domain.dom))
  967. def gf_irred_p_ben_or(self, f):
  968. return gf_irred_p_ben_or(self.to_gf_dense(f), self.domain.mod, self.domain.dom)
  969. def gf_irred_p_rabin(self, f):
  970. return gf_irred_p_rabin(self.to_gf_dense(f), self.domain.mod, self.domain.dom)
  971. def gf_irreducible_p(self, f):
  972. return gf_irreducible_p(self.to_gf_dense(f), self.domain.mod, self.domain.dom)
  973. def gf_sqf_p(self, f):
  974. return gf_sqf_p(self.to_gf_dense(f), self.domain.mod, self.domain.dom)
  975. def gf_sqf_part(self, f):
  976. return self.from_gf_dense(gf_sqf_part(self.to_gf_dense(f), self.domain.mod, self.domain.dom))
  977. def gf_sqf_list(self, f, all=False):
  978. coeff, factors = gf_sqf_part(self.to_gf_dense(f), self.domain.mod, self.domain.dom)
  979. return coeff, [ (self.from_gf_dense(g), k) for g, k in factors ]
  980. def gf_Qmatrix(self, f):
  981. return gf_Qmatrix(self.to_gf_dense(f), self.domain.mod, self.domain.dom)
  982. def gf_berlekamp(self, f):
  983. factors = gf_berlekamp(self.to_gf_dense(f), self.domain.mod, self.domain.dom)
  984. return [ self.from_gf_dense(g) for g in factors ]
  985. def gf_ddf_zassenhaus(self, f):
  986. factors = gf_ddf_zassenhaus(self.to_gf_dense(f), self.domain.mod, self.domain.dom)
  987. return [ (self.from_gf_dense(g), k) for g, k in factors ]
  988. def gf_edf_zassenhaus(self, f, n):
  989. factors = gf_edf_zassenhaus(self.to_gf_dense(f), self.domain.mod, self.domain.dom)
  990. return [ self.from_gf_dense(g) for g in factors ]
  991. def gf_ddf_shoup(self, f):
  992. factors = gf_ddf_shoup(self.to_gf_dense(f), self.domain.mod, self.domain.dom)
  993. return [ (self.from_gf_dense(g), k) for g, k in factors ]
  994. def gf_edf_shoup(self, f, n):
  995. factors = gf_edf_shoup(self.to_gf_dense(f), self.domain.mod, self.domain.dom)
  996. return [ self.from_gf_dense(g) for g in factors ]
  997. def gf_zassenhaus(self, f):
  998. factors = gf_zassenhaus(self.to_gf_dense(f), self.domain.mod, self.domain.dom)
  999. return [ self.from_gf_dense(g) for g in factors ]
  1000. def gf_shoup(self, f):
  1001. factors = gf_shoup(self.to_gf_dense(f), self.domain.mod, self.domain.dom)
  1002. return [ self.from_gf_dense(g) for g in factors ]
  1003. def gf_factor_sqf(self, f, method=None):
  1004. coeff, factors = gf_factor_sqf(self.to_gf_dense(f), self.domain.mod, self.domain.dom, method=method)
  1005. return coeff, [ self.from_gf_dense(g) for g in factors ]
  1006. def gf_factor(self, f):
  1007. coeff, factors = gf_factor(self.to_gf_dense(f), self.domain.mod, self.domain.dom)
  1008. return coeff, [ (self.from_gf_dense(g), k) for g, k in factors ]