PageRenderTime 67ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/sage/rings/polynomial/multi_polynomial_ideal.py

https://bitbucket.org/tkluck/sage-main
Python | 4532 lines | 4412 code | 19 blank | 101 comment | 31 complexity | a698ba9da71429aa213a6477f583747f MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. # -*- coding: utf-8 -*-
  2. r"""
  3. Ideals in multivariate polynomial rings.
  4. Sage has a powerful system to compute with multivariate polynomial
  5. rings. Most algorithms dealing with these ideals are centered the
  6. computation of *Groebner bases*. Sage mainly uses Singular to
  7. implement this functionality. Singular is widely regarded as the best
  8. open-source system for Groebner basis calculation in multivariate
  9. polynomial rings over fields.
  10. AUTHORS:
  11. - William Stein
  12. - Kiran S. Kedlaya (2006-02-12): added Macaulay2 analogues of some
  13. Singular features
  14. - Martin Albrecht (2008,2007): refactoring, many Singular related
  15. functions
  16. - Martin Albrecht (2009): added Groebner basis over rings
  17. functionality from Singular 3.1
  18. - John Perry (2012): bug fixing equality & containment of ideals
  19. EXAMPLES:
  20. We compute a Groebner basis for some given ideal. The type returned by
  21. the ``groebner_basis`` method is ``PolynomialSequence``, i.e. it is not a
  22. :class:`MPolynomialIdeal`::
  23. sage: x,y,z = QQ['x,y,z'].gens()
  24. sage: I = ideal(x^5 + y^4 + z^3 - 1, x^3 + y^3 + z^2 - 1)
  25. sage: B = I.groebner_basis()
  26. sage: type(B)
  27. <class 'sage.rings.polynomial.multi_polynomial_sequence.PolynomialSequence_generic'>
  28. Groebner bases can be used to solve the ideal membership problem::
  29. sage: f,g,h = B
  30. sage: (2*x*f + g).reduce(B)
  31. 0
  32. sage: (2*x*f + g) in I
  33. True
  34. sage: (2*x*f + 2*z*h + y^3).reduce(B)
  35. y^3
  36. sage: (2*x*f + 2*z*h + y^3) in I
  37. False
  38. We compute a Groebner basis for Cyclic 6, which is a standard
  39. benchmark and test ideal. ::
  40. sage: R.<x,y,z,t,u,v> = QQ['x,y,z,t,u,v']
  41. sage: I = sage.rings.ideal.Cyclic(R,6)
  42. sage: B = I.groebner_basis()
  43. sage: len(B)
  44. 45
  45. We compute in a quotient of a polynomial ring over `\ZZ/17\ZZ`::
  46. sage: R.<x,y> = ZZ[]
  47. sage: S.<a,b> = R.quotient((x^2 + y^2, 17))
  48. sage: S
  49. Quotient of Multivariate Polynomial Ring in x, y over Integer Ring
  50. by the ideal (x^2 + y^2, 17)
  51. sage: a^2 + b^2 == 0
  52. True
  53. sage: a^3 - b^2
  54. -a*b^2 - b^2
  55. Note that the result of a computation is not necessarily reduced::
  56. sage: (a+b)^17
  57. 256*a*b^16 + 256*b^17
  58. sage: S(17) == 0
  59. True
  60. Or we can work with `\ZZ/17\ZZ`` directly::
  61. sage: R.<x,y> = Zmod(17)[]
  62. sage: S.<a,b> = R.quotient((x^2 + y^2,))
  63. sage: S
  64. Quotient of Multivariate Polynomial Ring in x, y over Ring of
  65. integers modulo 17 by the ideal (x^2 + y^2)
  66. sage: a^2 + b^2 == 0
  67. True
  68. sage: a^3 - b^2
  69. -a*b^2 - b^2
  70. sage: (a+b)^17
  71. a*b^16 + b^17
  72. sage: S(17) == 0
  73. True
  74. Working with a polynomial ring over `\ZZ`::
  75. sage: R.<x,y,z,w> = ZZ[]
  76. sage: I = ideal(x^2 + y^2 - z^2 - w^2, x-y)
  77. sage: J = I^2
  78. sage: J.groebner_basis()
  79. [4*y^4 - 4*y^2*z^2 + z^4 - 4*y^2*w^2 + 2*z^2*w^2 + w^4,
  80. 2*x*y^2 - 2*y^3 - x*z^2 + y*z^2 - x*w^2 + y*w^2,
  81. x^2 - 2*x*y + y^2]
  82. sage: y^2 - 2*x*y + x^2 in J
  83. True
  84. sage: 0 in J
  85. True
  86. We do a Groebner basis computation over a number field::
  87. sage: K.<zeta> = CyclotomicField(3)
  88. sage: R.<x,y,z> = K[]; R
  89. Multivariate Polynomial Ring in x, y, z over Cyclotomic Field of order 3 and degree 2
  90. sage: i = ideal(x - zeta*y + 1, x^3 - zeta*y^3); i
  91. Ideal (x + (-zeta)*y + 1, x^3 + (-zeta)*y^3) of Multivariate
  92. Polynomial Ring in x, y, z over Cyclotomic Field of order 3 and degree 2
  93. sage: i.groebner_basis()
  94. [y^3 + (2*zeta + 1)*y^2 + (zeta - 1)*y + (-1/3*zeta - 2/3), x + (-zeta)*y + 1]
  95. sage: S = R.quotient(i); S
  96. Quotient of Multivariate Polynomial Ring in x, y, z over
  97. Cyclotomic Field of order 3 and degree 2 by the ideal (x +
  98. (-zeta)*y + 1, x^3 + (-zeta)*y^3)
  99. sage: S.0 - zeta*S.1
  100. -1
  101. sage: S.0^3 - zeta*S.1^3
  102. 0
  103. Two examples from the Mathematica documentation (done in Sage):
  104. We compute a Groebner basis::
  105. sage: R.<x,y> = PolynomialRing(QQ, order='lex')
  106. sage: ideal(x^2 - 2*y^2, x*y - 3).groebner_basis()
  107. [x - 2/3*y^3, y^4 - 9/2]
  108. We show that three polynomials have no common root::
  109. sage: R.<x,y> = QQ[]
  110. sage: ideal(x+y, x^2 - 1, y^2 - 2*x).groebner_basis()
  111. [1]
  112. The next example shows how we can use Groebner bases over `\ZZ` to
  113. find the primes modulo which a system of equations has a solution,
  114. when the system has no solutions over the rationals.
  115. We first form a certain ideal `I` in `\ZZ[x, y, z]`, and note that
  116. the Groebner basis of `I` over `\QQ` contains 1, so there are no
  117. solutions over `\QQ` or an algebraic closure of it (this is not
  118. surprising as there are 4 equations in 3 unknowns). ::
  119. sage: P.<x,y,z> = PolynomialRing(ZZ,order='lex')
  120. sage: I = ideal(-y^2 - 3*y + z^2 + 3, -2*y*z + z^2 + 2*z + 1, \
  121. x*z + y*z + z^2, -3*x*y + 2*y*z + 6*z^2)
  122. sage: I.change_ring(P.change_ring(QQ)).groebner_basis()
  123. [1]
  124. However, when we compute the Groebner basis of I (defined over
  125. `\ZZ``), we note that there is a certain integer in the ideal
  126. which is not 1. ::
  127. sage: I.groebner_basis()
  128. [x + 130433*y + 59079*z, y^2 + 3*y + 17220, y*z + 5*y + 14504, 2*y + 158864, z^2 + 17223, 2*z + 41856, 164878]
  129. Now for each prime `p` dividing this integer 164878, the Groebner
  130. basis of I modulo `p` will be non-trivial and will thus give a
  131. solution of the original system modulo `p`. ::
  132. sage: factor(164878)
  133. 2 * 7 * 11777
  134. sage: I.change_ring(P.change_ring( GF(2) )).groebner_basis()
  135. [x + y + z, y^2 + y, y*z + y, z^2 + 1]
  136. sage: I.change_ring(P.change_ring( GF(7) )).groebner_basis()
  137. [x - 1, y + 3, z - 2]
  138. sage: I.change_ring(P.change_ring( GF(11777 ))).groebner_basis()
  139. [x + 5633, y - 3007, z - 2626]
  140. The Groebner basis modulo any product of the prime factors is also non-trivial. ::
  141. sage: I.change_ring(P.change_ring( IntegerModRing(2*7) )).groebner_basis()
  142. [x + y + z, y^2 + 3*y, y*z + 11*y + 4, 2*y + 6, z^2 + 3, 2*z + 10]
  143. Modulo any other prime the Groebner basis is trivial so there are
  144. no other solutions. For example::
  145. sage: I.change_ring( P.change_ring( GF(3) ) ).groebner_basis()
  146. [1]
  147. TESTS::
  148. sage: x,y,z = QQ['x,y,z'].gens()
  149. sage: I = ideal(x^5 + y^4 + z^3 - 1, x^3 + y^3 + z^2 - 1)
  150. sage: I == loads(dumps(I))
  151. True
  152. .. note::
  153. Sage distinguishes between lists or sequences of polynomials and
  154. ideals. Thus an ideal is not identified with a particular set of
  155. generators. For sequences of multivariate polynomials see
  156. :class:`sage.rings.polynomial.multi_polynomial_sequence.PolynomialSequence_generic`.
  157. """
  158. #*****************************************************************************
  159. #
  160. # Sage
  161. #
  162. # Copyright (C) 2005 William Stein <wstein@gmail.com>
  163. # Copyright (C) 2008,2009 Martin Albrecht <malb@informatik.uni-bremen.de>
  164. #
  165. # Distributed under the terms of the GNU General Public License (GPL)
  166. #
  167. # This code is distributed in the hope that it will be useful,
  168. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  169. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  170. # General Public License for more details.
  171. #
  172. # The full text of the GPL is available at:
  173. #
  174. # http://www.gnu.org/licenses/
  175. #*****************************************************************************
  176. from sage.interfaces.all import (singular as singular_default,
  177. macaulay2 as macaulay2_default,
  178. magma as magma_default)
  179. from sage.interfaces.expect import StdOutContext
  180. from sage.rings.ideal import Ideal_generic
  181. from sage.rings.noncommutative_ideals import Ideal_nc
  182. from sage.rings.integer import Integer
  183. from sage.structure.sequence import Sequence
  184. from sage.misc.cachefunc import cached_method
  185. from sage.misc.misc import prod, verbose, get_verbose
  186. from sage.misc.method_decorator import MethodDecorator
  187. from sage.rings.integer_ring import ZZ
  188. import sage.rings.polynomial.toy_buchberger as toy_buchberger
  189. import sage.rings.polynomial.toy_variety as toy_variety
  190. import sage.rings.polynomial.toy_d_basis as toy_d_basis
  191. from warnings import warn
  192. class LibSingularDefaultContext:
  193. def __init__(self, singular=singular_default):
  194. from sage.libs.singular.option import opt_ctx
  195. self.libsingular_option_context = opt_ctx
  196. def __enter__(self):
  197. """
  198. EXAMPLE::
  199. sage: from sage.rings.polynomial.multi_polynomial_ideal import SingularDefaultContext
  200. sage: P.<a,b,c> = PolynomialRing(QQ,3, order='lex')
  201. sage: I = sage.rings.ideal.Katsura(P,3)
  202. sage: singular.option('noredTail')
  203. sage: singular.option('noredThrough')
  204. sage: Is = I._singular_()
  205. sage: with SingularDefaultContext(): rgb = Is.groebner()
  206. sage: rgb
  207. 84*c^4-40*c^3+c^2+c,
  208. 7*b+210*c^3-79*c^2+3*c,
  209. 7*a-420*c^3+158*c^2+8*c-7
  210. """
  211. self.libsingular_option_context.__enter__()
  212. self.libsingular_option_context.opt.reset_default()
  213. self.libsingular_option_context.opt['red_sb'] = True
  214. self.libsingular_option_context.opt['red_tail'] = True
  215. self.libsingular_option_context.opt['deg_bound'] = 0
  216. self.libsingular_option_context.opt['mult_bound'] = 0
  217. def __exit__(self, typ, value, tb):
  218. """
  219. EXAMPLE::
  220. sage: from sage.rings.polynomial.multi_polynomial_ideal import SingularDefaultContext
  221. sage: P.<a,b,c> = PolynomialRing(QQ,3, order='lex')
  222. sage: I = sage.rings.ideal.Katsura(P,3)
  223. sage: singular.option('noredTail')
  224. sage: singular.option('noredThrough')
  225. sage: Is = I._singular_()
  226. sage: with SingularDefaultContext(): rgb = Is.groebner()
  227. sage: rgb
  228. 84*c^4-40*c^3+c^2+c,
  229. 7*b+210*c^3-79*c^2+3*c,
  230. 7*a-420*c^3+158*c^2+8*c-7
  231. """
  232. self.libsingular_option_context.__exit__(typ,value,tb)
  233. class SingularDefaultContext:
  234. """
  235. Within this context all Singular Groebner basis calculations are
  236. reduced automatically.
  237. AUTHORS:
  238. - Martin Albrecht
  239. - Simon King
  240. """
  241. def __init__(self, singular=singular_default):
  242. """
  243. Within this context all Singular Groebner basis calculations
  244. are reduced automatically.
  245. INPUT:
  246. - ``singular`` - Singular instance (default: default instance)
  247. EXAMPLE::
  248. sage: from sage.rings.polynomial.multi_polynomial_ideal import SingularDefaultContext
  249. sage: P.<a,b,c> = PolynomialRing(QQ,3, order='lex')
  250. sage: I = sage.rings.ideal.Katsura(P,3)
  251. sage: singular.option('noredTail')
  252. sage: singular.option('noredThrough')
  253. sage: Is = I._singular_()
  254. sage: gb = Is.groebner()
  255. sage: gb
  256. 84*c^4-40*c^3+c^2+c,
  257. 7*b+210*c^3-79*c^2+3*c,
  258. a+2*b+2*c-1
  259. ::
  260. sage: with SingularDefaultContext(): rgb = Is.groebner()
  261. sage: rgb
  262. 84*c^4-40*c^3+c^2+c,
  263. 7*b+210*c^3-79*c^2+3*c,
  264. 7*a-420*c^3+158*c^2+8*c-7
  265. Note that both bases are Groebner bases because they have
  266. pairwise prime leading monomials but that the monic version of
  267. the last element in ``rgb`` is smaller than the last element
  268. of ``gb`` with respect to the lexicographical term ordering. ::
  269. sage: (7*a-420*c^3+158*c^2+8*c-7)/7 < (a+2*b+2*c-1)
  270. True
  271. .. note::
  272. This context is used automatically internally whenever a
  273. Groebner basis is computed so the user does not need to use
  274. it manually.
  275. """
  276. self.singular = singular
  277. def __enter__(self):
  278. """
  279. EXAMPLE::
  280. sage: from sage.rings.polynomial.multi_polynomial_ideal import SingularDefaultContext
  281. sage: P.<a,b,c> = PolynomialRing(QQ,3, order='lex')
  282. sage: I = sage.rings.ideal.Katsura(P,3)
  283. sage: singular.option('noredTail')
  284. sage: singular.option('noredThrough')
  285. sage: Is = I._singular_()
  286. sage: with SingularDefaultContext(): rgb = Is.groebner()
  287. sage: rgb
  288. 84*c^4-40*c^3+c^2+c,
  289. 7*b+210*c^3-79*c^2+3*c,
  290. 7*a-420*c^3+158*c^2+8*c-7
  291. """
  292. try:
  293. self.bck_degBound = int(self.singular.eval('degBound'))
  294. except RuntimeError:
  295. self.bck_degBound = int(0)
  296. try:
  297. self.bck_multBound = int(self.singular.eval('multBound'))
  298. except RuntimeError:
  299. self.bck_multBound = int(0)
  300. self.o = self.singular.option("get")
  301. self.singular.option('set',self.singular._saved_options)
  302. self.singular.option("redSB")
  303. self.singular.option("redTail")
  304. try:
  305. self.singular.eval('degBound=0')
  306. except RuntimeError:
  307. pass
  308. try:
  309. self.singular.eval('multBound=0')
  310. except RuntimeError:
  311. pass
  312. def __exit__(self, typ, value, tb):
  313. """
  314. EXAMPLE::
  315. sage: from sage.rings.polynomial.multi_polynomial_ideal import SingularDefaultContext
  316. sage: P.<a,b,c> = PolynomialRing(QQ,3, order='lex')
  317. sage: I = sage.rings.ideal.Katsura(P,3)
  318. sage: singular.option('noredTail')
  319. sage: singular.option('noredThrough')
  320. sage: Is = I._singular_()
  321. sage: with SingularDefaultContext(): rgb = Is.groebner()
  322. sage: rgb
  323. 84*c^4-40*c^3+c^2+c,
  324. 7*b+210*c^3-79*c^2+3*c,
  325. 7*a-420*c^3+158*c^2+8*c-7
  326. """
  327. self.singular.option("set",self.o)
  328. try:
  329. self.singular.eval('degBound=%d'%self.bck_degBound)
  330. except RuntimeError:
  331. pass
  332. try:
  333. self.singular.eval('multBound=%d'%self.bck_multBound)
  334. except RuntimeError:
  335. pass
  336. def singular_standard_options(func):
  337. r"""
  338. Decorator to force a reduced Singular groebner basis.
  339. TESTS::
  340. sage: P.<a,b,c,d,e> = PolynomialRing(GF(127))
  341. sage: J = sage.rings.ideal.Cyclic(P).homogenize()
  342. sage: from sage.misc.sageinspect import sage_getsource
  343. sage: "buchberger" in sage_getsource(J.interreduced_basis) #indirect doctest
  344. True
  345. The following tests against a bug that was fixed in trac ticket #11298::
  346. sage: from sage.misc.sageinspect import sage_getsourcelines, sage_getargspec
  347. sage: P.<x,y> = QQ[]
  348. sage: I = P*[x,y]
  349. sage: sage_getargspec(I.interreduced_basis)
  350. ArgSpec(args=['self'], varargs=None, keywords=None, defaults=None)
  351. sage: sage_getsourcelines(I.interreduced_basis)
  352. ([' @singular_standard_options\n',
  353. ' @libsingular_standard_options\n',
  354. ' def interreduced_basis(self):\n',
  355. ...
  356. ' return ret\n'], ...)
  357. .. note::
  358. This decorator is used automatically internally so the user
  359. does not need to use it manually.
  360. """
  361. from sage.misc.decorators import sage_wraps
  362. @sage_wraps(func)
  363. def wrapper(*args, **kwds):
  364. # """
  365. # Execute function in ``SingularDefaultContext``.
  366. # """
  367. with SingularDefaultContext():
  368. return func(*args, **kwds)
  369. return wrapper
  370. def libsingular_standard_options(func):
  371. r"""
  372. Decorator to force a reduced Singular groebner basis.
  373. TESTS::
  374. sage: P.<a,b,c,d,e> = PolynomialRing(GF(127))
  375. sage: J = sage.rings.ideal.Cyclic(P).homogenize()
  376. sage: from sage.misc.sageinspect import sage_getsource
  377. sage: "buchberger" in sage_getsource(J.interreduced_basis)
  378. True
  379. The following tests against a bug that was fixed in trac ticket #11298::
  380. sage: from sage.misc.sageinspect import sage_getsourcelines, sage_getargspec
  381. sage: P.<x,y> = QQ[]
  382. sage: I = P*[x,y]
  383. sage: sage_getargspec(I.interreduced_basis)
  384. ArgSpec(args=['self'], varargs=None, keywords=None, defaults=None)
  385. sage: sage_getsourcelines(I.interreduced_basis)
  386. ([' @singular_standard_options\n',
  387. ' @libsingular_standard_options\n',
  388. ' def interreduced_basis(self):\n',
  389. ...
  390. ' return ret\n'], ...)
  391. .. note::
  392. This decorator is used automatically internally so the user
  393. does not need to use it manually.
  394. """
  395. from sage.misc.decorators import sage_wraps
  396. @sage_wraps(func)
  397. def wrapper(*args, **kwds):
  398. """
  399. Execute function in ``LibSingularDefaultContext``.
  400. """
  401. with LibSingularDefaultContext():
  402. return func(*args, **kwds)
  403. return wrapper
  404. class MagmaDefaultContext:
  405. """
  406. Context to force preservation of verbosity options for Magma's
  407. Groebner basis computation.
  408. """
  409. def __init__(self, magma=magma_default):
  410. """
  411. INPUT:
  412. - ``magma`` - (default: ``magma_default``)
  413. EXAMPLE::
  414. sage: from sage.rings.polynomial.multi_polynomial_ideal import MagmaDefaultContext
  415. sage: magma.SetVerbose('Groebner',1) # optional - magma
  416. sage: with MagmaDefaultContext(): magma.GetVerbose('Groebner') # optional - magma
  417. 0
  418. """
  419. self.magma = magma
  420. def __enter__(self):
  421. """
  422. EXAMPLE::
  423. sage: from sage.rings.polynomial.multi_polynomial_ideal import MagmaDefaultContext
  424. sage: magma.SetVerbose('Groebner',1) # optional - magma
  425. sage: with MagmaDefaultContext(): magma.GetVerbose('Groebner') # optional - magma
  426. 0
  427. """
  428. self.groebner_basis_verbose = self.magma.GetVerbose('Groebner')
  429. self.magma.SetVerbose('Groebner',0)
  430. def __exit__(self, typ, value, tb):
  431. """
  432. EXAMPLE::
  433. sage: from sage.rings.polynomial.multi_polynomial_ideal import MagmaDefaultContext
  434. sage: magma.SetVerbose('Groebner',1) # optional - magma
  435. sage: with MagmaDefaultContext(): magma.GetVerbose('Groebner') # optional - magma
  436. 0
  437. sage: magma.GetVerbose('Groebner') # optional - magma
  438. 1
  439. """
  440. self.magma.SetVerbose('Groebner',self.groebner_basis_verbose)
  441. def magma_standard_options(func):
  442. """
  443. Decorator to force default options for Magma.
  444. EXAMPLE::
  445. sage: P.<a,b,c,d,e> = PolynomialRing(GF(127))
  446. sage: J = sage.rings.ideal.Cyclic(P).homogenize()
  447. sage: from sage.misc.sageinspect import sage_getsource
  448. sage: "mself" in sage_getsource(J._groebner_basis_magma)
  449. True
  450. """
  451. from sage.misc.decorators import sage_wraps
  452. @sage_wraps(func)
  453. def wrapper(*args, **kwds):
  454. """
  455. Execute function in ``MagmaDefaultContext``.
  456. """
  457. with MagmaDefaultContext():
  458. return func(*args, **kwds)
  459. return wrapper
  460. class RequireField(MethodDecorator):
  461. """
  462. Decorator which throws an exception if a computation over a
  463. coefficient ring which is not a field is attempted.
  464. .. note::
  465. This decorator is used automatically internally so the user
  466. does not need to use it manually.
  467. """
  468. def __call__(self, *args, **kwds):
  469. """
  470. EXAMPLE::
  471. sage: P.<x,y,z> = PolynomialRing(ZZ)
  472. sage: I = ideal( x^2 - 3*y, y^3 - x*y, z^3 - x, x^4 - y*z + 1 )
  473. sage: from sage.rings.polynomial.multi_polynomial_ideal import RequireField
  474. sage: class Foo(I.__class__):
  475. ... @RequireField
  476. ... def bar(I):
  477. ... return I.groebner_basis()
  478. ...
  479. sage: J = Foo(I.ring(), I.gens())
  480. sage: J.bar()
  481. Traceback (most recent call last):
  482. ...
  483. ValueError: Coefficient ring must be a field for function 'bar'.
  484. """
  485. R = self._instance.ring()
  486. if not R.base_ring().is_field():
  487. raise ValueError("Coefficient ring must be a field for function '%s'."%(self.f.__name__))
  488. return self.f(self._instance, *args, **kwds)
  489. require_field = RequireField
  490. def is_MPolynomialIdeal(x):
  491. """
  492. Return ``True`` if the provided argument ``x`` is an ideal in the
  493. multivariate polynomial ring.
  494. INPUT:
  495. - ``x`` - an arbitrary object
  496. EXAMPLES::
  497. sage: from sage.rings.polynomial.all import is_MPolynomialIdeal
  498. sage: P.<x,y,z> = PolynomialRing(QQ)
  499. sage: I = [x + 2*y + 2*z - 1, x^2 + 2*y^2 + 2*z^2 - x, 2*x*y + 2*y*z - y]
  500. Sage distinguishes between a list of generators for an ideal and
  501. the ideal itself. This distinction is inconsistent with Singular
  502. but matches Magma's behavior. ::
  503. sage: is_MPolynomialIdeal(I)
  504. False
  505. ::
  506. sage: I = Ideal(I)
  507. sage: is_MPolynomialIdeal(I)
  508. True
  509. """
  510. return isinstance(x, MPolynomialIdeal)
  511. class MPolynomialIdeal_magma_repr:
  512. def _magma_init_(self, magma):
  513. """
  514. Returns a Magma ideal matching this ideal if the base ring
  515. coerces to Magma and Magma is available.
  516. INPUT:
  517. - ``magma`` - Magma instance
  518. EXAMPLES::
  519. sage: R.<a,b,c,d,e,f,g,h,i,j> = PolynomialRing(GF(127),10)
  520. sage: I = sage.rings.ideal.Cyclic(R,4) # indirect doctest
  521. sage: magma(I) # optional - magma
  522. Ideal of Polynomial ring of rank 10 over GF(127)
  523. Order: Graded Reverse Lexicographical
  524. Variables: a, b, c, d, e, f, g, h, i, j
  525. Basis:
  526. [
  527. a + b + c + d,
  528. a*b + b*c + a*d + c*d,
  529. a*b*c + a*b*d + a*c*d + b*c*d,
  530. a*b*c*d + 126
  531. ]
  532. """
  533. P = magma(self.ring())
  534. G = magma(self.gens())
  535. return 'ideal<%s|%s>'%(P.name(), G._ref())
  536. @magma_standard_options
  537. def _groebner_basis_magma(self, deg_bound=None, prot=False, magma=magma_default):
  538. """
  539. Computes a Groebner Basis for this ideal using Magma if
  540. available.
  541. INPUT:
  542. - ``deg_bound`` - only compute to degree ``deg_bound``, that
  543. is, ignore all S-polynomials of higher degree. (default:
  544. ``None``)
  545. - ``prot`` - if ``True`` Magma's protocol is printed to
  546. stdout.
  547. - ``magma`` - Magma instance or None (default instance) (default: None)
  548. EXAMPLES::
  549. sage: R.<a,b,c,d,e,f,g,h,i,j> = PolynomialRing(GF(127),10)
  550. sage: I = sage.rings.ideal.Cyclic(R,6)
  551. sage: gb = I.groebner_basis('magma:GroebnerBasis') # indirect doctest; optional - magma
  552. sage: len(gb) # optional - magma
  553. 45
  554. """
  555. R = self.ring()
  556. if not deg_bound:
  557. mself = magma(self)
  558. else:
  559. mself = magma(self.gens())
  560. if get_verbose() >= 2:
  561. prot = True
  562. from sage.interfaces.magma import MagmaGBLogPrettyPrinter
  563. if prot:
  564. log_parser = MagmaGBLogPrettyPrinter(verbosity=get_verbose()+ 1, style="sage" if prot=="sage" else "magma")
  565. else:
  566. log_parser = None
  567. ctx = StdOutContext(magma, silent=False if prot else True, stdout=log_parser)
  568. if prot:
  569. magma.SetVerbose('Groebner',1)
  570. with ctx:
  571. if deg_bound:
  572. mgb = mself.GroebnerBasis(deg_bound)
  573. else:
  574. mgb = mself.GroebnerBasis()
  575. if prot == "sage":
  576. print
  577. print "Highest degree reached during computation: %2d."%log_parser.max_deg
  578. # TODO: rewrite this to be much more sophisticated in multi-level nested cases.
  579. mgb = [str(mgb[i+1]) for i in range(len(mgb))]
  580. if R.base_ring().degree() > 1:
  581. a = str(R.base_ring().gen())
  582. mgb = [e.replace("$.1",a) for e in mgb]
  583. from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence
  584. B = PolynomialSequence([R(e) for e in mgb], R, immutable=True)
  585. return B
  586. class MPolynomialIdeal_singular_base_repr:
  587. @require_field
  588. def syzygy_module(self):
  589. r"""
  590. Computes the first syzygy (i.e., the module of relations of the
  591. given generators) of the ideal.
  592. EXAMPLE::
  593. sage: R.<x,y> = PolynomialRing(QQ)
  594. sage: f = 2*x^2 + y
  595. sage: g = y
  596. sage: h = 2*f + g
  597. sage: I = Ideal([f,g,h])
  598. sage: M = I.syzygy_module(); M
  599. [ -2 -1 1]
  600. [ -y 2*x^2 + y 0]
  601. sage: G = vector(I.gens())
  602. sage: M*G
  603. (0, 0)
  604. ALGORITHM: Uses Singular's syz command
  605. """
  606. import sage.libs.singular
  607. syz = sage.libs.singular.ff.syz
  608. from sage.matrix.constructor import matrix
  609. #return self._singular_().syz().transpose().sage_matrix(self.ring())
  610. S = syz(self)
  611. return matrix(self.ring(), S)
  612. @libsingular_standard_options
  613. def _groebner_basis_libsingular(self, algorithm="groebner", *args, **kwds):
  614. """
  615. Return the reduced Groebner basis of this ideal. If the
  616. Groebner basis for this ideal has been calculated before the
  617. cached Groebner basis is returned regardless of the requested
  618. algorithm.
  619. INPUT:
  620. - ``algorithm`` - see below for available algorithms
  621. - ``redsb`` - return a reduced Groebner basis (default: ``True``)
  622. - ``red_tail`` - perform tail reduction (default: ``True``)
  623. ALGORITHMS:
  624. 'groebner'
  625. Singular's heuristic script (default)
  626. 'std'
  627. Buchberger's algorithm
  628. 'slimgb'
  629. the *SlimGB* algorithm
  630. 'stdhilb'
  631. Hilbert Basis driven Groebner basis
  632. 'stdfglm'
  633. Buchberger and FGLM
  634. EXAMPLES:
  635. We compute a Groebner basis of 'cyclic 4' relative to
  636. lexicographic ordering. ::
  637. sage: R.<a,b,c,d> = PolynomialRing(QQ, 4, order='lex')
  638. sage: I = sage.rings.ideal.Cyclic(R,4); I
  639. Ideal (a + b + c + d, a*b + a*d + b*c + c*d, a*b*c + a*b*d
  640. + a*c*d + b*c*d, a*b*c*d - 1) of Multivariate Polynomial
  641. Ring in a, b, c, d over Rational Field
  642. ::
  643. sage: I._groebner_basis_libsingular()
  644. [c^2*d^6 - c^2*d^2 - d^4 + 1, c^3*d^2 + c^2*d^3 - c - d,
  645. b*d^4 - b + d^5 - d, b*c - b*d + c^2*d^4 + c*d - 2*d^2,
  646. b^2 + 2*b*d + d^2, a + b + c + d]
  647. ALGORITHM:
  648. Uses libSINGULAR.
  649. """
  650. from sage.rings.polynomial.multi_polynomial_ideal_libsingular import std_libsingular, slimgb_libsingular
  651. from sage.libs.singular import singular_function
  652. from sage.libs.singular.option import opt
  653. import sage.libs.singular
  654. groebner = sage.libs.singular.ff.groebner
  655. if get_verbose()>=2:
  656. opt['prot'] = True
  657. for name,value in kwds.iteritems():
  658. if value is not None:
  659. opt[name] = value
  660. T = self.ring().term_order()
  661. if algorithm == "std":
  662. S = std_libsingular(self)
  663. elif algorithm == "slimgb":
  664. S = slimgb_libsingular(self)
  665. elif algorithm == "groebner":
  666. S = groebner(self)
  667. else:
  668. try:
  669. fnc = singular_function(algorithm)
  670. S = fnc(self)
  671. except NameError:
  672. raise NameError("Algorithm '%s' unknown"%algorithm)
  673. return S
  674. class MPolynomialIdeal_singular_repr(
  675. MPolynomialIdeal_singular_base_repr):
  676. """
  677. An ideal in a multivariate polynomial ring, which has an
  678. underlying Singular ring associated to it.
  679. """
  680. def _singular_(self, singular=singular_default):
  681. """
  682. Return Singular ideal corresponding to this ideal.
  683. EXAMPLES::
  684. sage: R.<x,y> = PolynomialRing(QQ, 2)
  685. sage: I = R.ideal([x^3 + y, y])
  686. sage: S = I._singular_()
  687. sage: S
  688. x^3+y,
  689. y
  690. """
  691. try:
  692. self.ring()._singular_(singular).set_ring()
  693. I = self.__singular
  694. if not (I.parent() is singular):
  695. raise ValueError
  696. I._check_valid()
  697. return I
  698. except (AttributeError, ValueError):
  699. self.ring()._singular_(singular).set_ring()
  700. try:
  701. # this may fail for quotient ring elements, but is
  702. # faster
  703. gens = [str(x) for x in self.gens()]
  704. if len(gens) == 0:
  705. gens = ['0']
  706. self.__singular = singular.ideal(gens)
  707. except TypeError:
  708. gens = [str(x.lift()) for x in self.gens()]
  709. if len(gens) == 0:
  710. gens = ['0']
  711. self.__singular = singular.ideal(gens)
  712. return self.__singular
  713. @cached_method
  714. def _groebner_strategy(self):
  715. """
  716. Return Singular's Groebner Strategy object for the Groebner
  717. basis of this ideal which implements some optimized functions.
  718. EXAMPLE::
  719. sage: R.<x,y> = PolynomialRing(QQ,2)
  720. sage: I = R.ideal([y^3 - x^2])
  721. sage: I._groebner_strategy()
  722. Groebner Strategy for ideal generated by 1 elements over
  723. Multivariate Polynomial Ring in x, y over Rational Field
  724. .. note::
  725. This function is mainly used internally.
  726. """
  727. from sage.libs.singular.groebner_strategy import GroebnerStrategy
  728. return GroebnerStrategy(MPolynomialIdeal(self.ring(), self.groebner_basis()))
  729. def plot(self, singular=singular_default):
  730. """
  731. If you somehow manage to install surf, perhaps you can use
  732. this function to implicitly plot the real zero locus of this
  733. ideal (if principal).
  734. INPUT:
  735. - ``self`` - must be a principal ideal in 2 or 3 vars
  736. over QQ.
  737. EXAMPLES:
  738. Implicit plotting in 2-d::
  739. sage: R.<x,y> = PolynomialRing(QQ,2)
  740. sage: I = R.ideal([y^3 - x^2])
  741. sage: I.plot() # cusp
  742. sage: I = R.ideal([y^2 - x^2 - 1])
  743. sage: I.plot() # hyperbola
  744. sage: I = R.ideal([y^2 + x^2*(1/4) - 1])
  745. sage: I.plot() # ellipse
  746. sage: I = R.ideal([y^2-(x^2-1)*(x-2)])
  747. sage: I.plot() # elliptic curve
  748. Implicit plotting in 3-d::
  749. sage: R.<x,y,z> = PolynomialRing(QQ,3)
  750. sage: I = R.ideal([y^2 + x^2*(1/4) - z])
  751. sage: I.plot() # a cone; optional - surf
  752. sage: I = R.ideal([y^2 + z^2*(1/4) - x])
  753. sage: I.plot() # same code, from a different angle; optional - surf
  754. sage: I = R.ideal([x^2*y^2+x^2*z^2+y^2*z^2-16*x*y*z])
  755. sage: I.plot() # Steiner surface; optional - surf
  756. AUTHORS:
  757. - David Joyner (2006-02-12)
  758. """
  759. if self.ring().characteristic() != 0:
  760. raise TypeError, "base ring must have characteristic 0"
  761. if not self.is_principal():
  762. raise TypeError, "self must be principal"
  763. singular.lib('surf')
  764. I = singular(self)
  765. I.plot()
  766. @require_field
  767. @libsingular_standard_options
  768. def complete_primary_decomposition(self, algorithm="sy"):
  769. r"""
  770. Return a list of primary ideals and their associated primes such
  771. that the intersection of the primary ideal `Q_i` is
  772. `I` = ``self``.
  773. An ideal `Q` is called primary if it is a proper ideal of
  774. the ring `R` and if whenever `ab \in Q` and
  775. `a \not\in Q` then `b^n \in Q` for some
  776. `n \in \ZZ`.
  777. If `Q` is a primary ideal of the ring `R`, then the
  778. radical ideal `P` of `Q`, i.e.
  779. `P = \{a \in R, a^n \in Q\}` for some
  780. `n \in \ZZ`, is called the
  781. *associated prime* of `Q`.
  782. If `I` is a proper ideal of the ring `R` then there
  783. exists a decomposition in primary ideals `Q_i` such that
  784. - their intersection is `I`
  785. - none of the `Q_i` contains the intersection of the
  786. rest, and
  787. - the associated prime ideals of `Q_i` are pairwise
  788. different.
  789. This method returns these `Q_i` and their associated
  790. primes.
  791. INPUT:
  792. - ``algorithm`` - string:
  793. - ``'sy'`` - (default) use the shimoyama-yokoyama algorithm
  794. - ``'gtz'`` - use the gianni-trager-zacharias algorithm
  795. OUTPUT:
  796. - ``list`` - a list of primary ideals and their
  797. associated primes [(primary ideal, associated prime), ...]
  798. EXAMPLES::
  799. sage: R.<x,y,z> = PolynomialRing(QQ, 3, order='lex')
  800. sage: p = z^2 + 1; q = z^3 + 2
  801. sage: I = (p*q^2, y-z^2)*R
  802. sage: pd = I.complete_primary_decomposition(); pd
  803. [(Ideal (z^6 + 4*z^3 + 4, y - z^2) of Multivariate Polynomial Ring in x, y, z over Rational Field,
  804. Ideal (z^3 + 2, y - z^2) of Multivariate Polynomial Ring in x, y, z over Rational Field),
  805. (Ideal (z^2 + 1, y + 1) of Multivariate Polynomial Ring in x, y, z over Rational Field,
  806. Ideal (z^2 + 1, y + 1) of Multivariate Polynomial Ring in x, y, z over Rational Field)]
  807. sage: I.primary_decomposition_complete(algorithm = 'gtz')
  808. [(Ideal (z^6 + 4*z^3 + 4, y - z^2) of Multivariate Polynomial Ring in x, y, z over Rational Field,
  809. Ideal (z^3 + 2, y - z^2) of Multivariate Polynomial Ring in x, y, z over Rational Field),
  810. (Ideal (z^2 + 1, y - z^2) of Multivariate Polynomial Ring in x, y, z over Rational Field,
  811. Ideal (z^2 + 1, y - z^2) of Multivariate Polynomial Ring in x, y, z over Rational Field)]
  812. sage: reduce(lambda Qi,Qj: Qi.intersection(Qj), [Qi for (Qi,radQi) in pd]) == I
  813. True
  814. sage: [Qi.radical() == radQi for (Qi,radQi) in pd]
  815. [True, True]
  816. sage: P.<x,y,z> = PolynomialRing(ZZ)
  817. sage: I = ideal( x^2 - 3*y, y^3 - x*y, z^3 - x, x^4 - y*z + 1 )
  818. sage: I.complete_primary_decomposition()
  819. Traceback (most recent call last):
  820. ...
  821. ValueError: Coefficient ring must be a field for function 'complete_primary_decomposition'.
  822. ALGORITHM:
  823. Uses Singular.
  824. .. note::
  825. See [BW93]_ for an introduction to primary decomposition.
  826. """
  827. try:
  828. return self.__complete_primary_decomposition[algorithm]
  829. except AttributeError:
  830. self.__complete_primary_decomposition = {}
  831. except KeyError:
  832. pass
  833. import sage.libs.singular
  834. if algorithm == 'sy':
  835. primdecSY = sage.libs.singular.ff.primdec__lib.primdecSY
  836. P = primdecSY(self)
  837. elif algorithm == 'gtz':
  838. primdecGTZ = sage.libs.singular.ff.primdec__lib.primdecGTZ
  839. P = primdecGTZ(self)
  840. R = self.ring()
  841. V = [(R.ideal(X[0]), R.ideal(X[1])) for X in P]
  842. V = Sequence(V)
  843. self.__complete_primary_decomposition[algorithm] = V
  844. return self.__complete_primary_decomposition[algorithm]
  845. # Seems useful for Tab-Completion
  846. primary_decomposition_complete = complete_primary_decomposition
  847. @require_field
  848. def primary_decomposition(self, algorithm='sy'):
  849. r"""
  850. Return a list of primary ideals such that their intersection is
  851. `I` = ``self``.
  852. An ideal `Q` is called primary if it is a proper ideal of
  853. the ring `R` and if whenever `ab \in Q` and
  854. `a \not\in Q` then `b^n \in Q` for some
  855. `n \in \ZZ`.
  856. If `I` is a proper ideal of the ring `R` then there
  857. exists a decomposition in primary ideals `Q_i` such that
  858. - their intersection is `I`
  859. - none of the `Q_i` contains the intersection of the
  860. rest, and
  861. - the associated prime ideals of `Q_i` are pairwise
  862. different.
  863. This method returns these `Q_i`.
  864. INPUT:
  865. - ``algorithm`` - string:
  866. - ``'sy'`` - (default) use the shimoyama-yokoyama algorithm
  867. - ``'gtz'`` - use the gianni-trager-zacharias algorithm
  868. EXAMPLES::
  869. sage: R.<x,y,z> = PolynomialRing(QQ, 3, order='lex')
  870. sage: p = z^2 + 1; q = z^3 + 2
  871. sage: I = (p*q^2, y-z^2)*R
  872. sage: pd = I.primary_decomposition(); pd
  873. [Ideal (z^6 + 4*z^3 + 4, y - z^2) of Multivariate Polynomial Ring in x, y, z over Rational Field,
  874. Ideal (z^2 + 1, y + 1) of Multivariate Polynomial Ring in x, y, z over Rational Field]
  875. ::
  876. sage: reduce(lambda Qi,Qj: Qi.intersection(Qj), pd) == I
  877. True
  878. ALGORITHM:
  879. Uses Singular.
  880. REFERENCES:
  881. - Thomas Becker and Volker Weispfenning. Groebner Bases - A
  882. Computational Approach To Commutative Algebra. Springer, New
  883. York 1993.
  884. """
  885. return [I for I, _ in self.complete_primary_decomposition(algorithm)]
  886. @require_field
  887. def associated_primes(self, algorithm='sy'):
  888. r"""
  889. Return a list of the associated primes of primary ideals of
  890. which the intersection is `I` = ``self``.
  891. An ideal `Q` is called primary if it is a proper ideal of
  892. the ring `R` and if whenever `ab \in Q` and
  893. `a \not\in Q` then `b^n \in Q` for some
  894. `n \in \ZZ`.
  895. If `Q` is a primary ideal of the ring `R`, then the
  896. radical ideal `P` of `Q`, i.e.
  897. `P = \{a \in R, a^n \in Q\}` for some
  898. `n \in \ZZ`, is called the
  899. *associated prime* of `Q`.
  900. If `I` is a proper ideal of the ring `R` then there
  901. exists a decomposition in primary ideals `Q_i` such that
  902. - their intersection is `I`
  903. - none of the `Q_i` contains the intersection of the
  904. rest, and
  905. - the associated prime ideals of `Q_i` are pairwise
  906. different.
  907. This method returns the associated primes of the `Q_i`.
  908. INPUT:
  909. - ``algorithm`` - string:
  910. - ``'sy'`` - (default) use the shimoyama-yokoyama algorithm
  911. - ``'gtz'`` - use the gianni-trager-zacharias algorithm
  912. OUTPUT:
  913. - ``list`` - a list of associated primes
  914. EXAMPLES::
  915. sage: R.<x,y,z> = PolynomialRing(QQ, 3, order='lex')
  916. sage: p = z^2 + 1; q = z^3 + 2
  917. sage: I = (p*q^2, y-z^2)*R
  918. sage: pd = I.associated_primes(); pd
  919. [Ideal (z^3 + 2, y - z^2) of Multivariate Polynomial Ring in x, y, z over Rational Field,
  920. Ideal (z^2 + 1, y + 1) of Multivariate Polynomial Ring in x, y, z over Rational Field]
  921. ALGORITHM:
  922. Uses Singular.
  923. REFERENCES:
  924. - Thomas Becker and Volker Weispfenning. Groebner Bases - A
  925. Computational Approach To Commutative Algebra. Springer, New
  926. York 1993.
  927. """
  928. return [P for _,P in self.complete_primary_decomposition(algorithm)]
  929. def is_prime(self, **kwds):
  930. r"""
  931. Return ``True`` if this ideal is prime.
  932. INPUT:
  933. - keyword arguments are passed on to
  934. ``complete_primary_decomposition``; in this way you can
  935. specify the algorithm to use.
  936. EXAMPLES::
  937. sage: R.<x, y> = PolynomialRing(QQ, 2)
  938. sage: I = (x^2 - y^2 - 1)*R
  939. sage: I.is_prime()
  940. True
  941. sage: (I^2).is_prime()
  942. False
  943. sage: J = (x^2 - y^2)*R
  944. sage: J.is_prime()
  945. False
  946. sage: (J^3).is_prime()
  947. False
  948. sage: (I * J).is_prime()
  949. False
  950. The following is Trac #5982. Note that the quotient ring
  951. is not recognized as being a field at this time, so the
  952. fraction field is not the quotient ring itself::
  953. sage: Q = R.quotient(I); Q
  954. Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 - y^2 - 1)
  955. sage: Q.fraction_field()
  956. Fraction Field of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 - y^2 - 1)
  957. """
  958. if not self.ring().base_ring().is_field():
  959. raise NotImplementedError
  960. CPD = self.complete_primary_decomposition(**kwds)
  961. if len(CPD) != 1:
  962. return False
  963. _, P = CPD[0]
  964. return self == P
  965. @require_field
  966. @singular_standard_options
  967. @libsingular_standard_options
  968. def triangular_decomposition(self, algorithm=None, singular=singular_default):
  969. """
  970. Decompose zero-dimensional ideal ``self`` into triangular
  971. sets.
  972. This requires that the given basis is reduced w.r.t. to the
  973. lexicographical monomial ordering. If the basis of self does
  974. not have this property, the required Groebner basis is
  975. computed implicitly.
  976. INPUT:
  977. - ``algorithm`` - string or None (default: None)
  978. ALGORITHMS:
  979. - ``singular:triangL`` - decomposition of self into triangular
  980. systems (Lazard).
  981. - ``singular:triangLfak`` - decomp. of self into tri. systems
  982. plus factorization.
  983. - ``singular:triangM`` - decomposition of self into
  984. triangular systems (Moeller).
  985. OUTPUT: a list `T` of lists `t` such that the variety of
  986. ``self`` is the union of the varieties of `t` in `L` and each
  987. `t` is in triangular form.
  988. EXAMPLE::
  989. sage: P.<e,d,c,b,a> = PolynomialRing(QQ,5,order='lex')
  990. sage: I = sage.rings.ideal.Cyclic(P)
  991. sage: GB = Ideal(I.groebner_basis('libsingular:stdfglm'))
  992. sage: GB.triangular_decomposition('singular:triangLfak')
  993. [Ideal (a - 1, b - 1, c - 1, d^2 + 3*d + 1, e + d + 3) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field,
  994. Ideal (a - 1, b - 1, c^2 + 3*c + 1, d + c + 3, e - 1) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field,
  995. Ideal (a - 1, b^2 + 3*b + 1, c + b + 3, d - 1, e - 1) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field,
  996. Ideal (a - 1, b^4 + b^3 + b^2 + b + 1, -c + b^2, -d + b^3, e + b^3 + b^2 + b + 1) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field,
  997. Ideal (a^2 + 3*a + 1, b - 1, c - 1, d - 1, e + a + 3) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field,
  998. Ideal (a^2 + 3*a + 1, b + a + 3, c - 1, d - 1, e - 1) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field,
  999. Ideal (a^4 - 4*a^3 + 6*a^2 + a + 1, -11*b^2 + 6*b*a^3 - 26*b*a^2 + 41*b*a - 4*b - 8*a^3 + 31*a^2 - 40*a - 24, 11*c + 3*a^3 - 13*a^2 + 26*a - 2, 11*d + 3*a^3 - 13*a^2 + 26*a - 2, -11*e - 11*b + 6*a^3 - 26*a^2 + 41*a - 4) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field,
  1000. Ideal (a^4 + a^3 + a^2 + a + 1, b - 1, c + a^3 + a^2 + a + 1, -d + a^3, -e + a^2) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field,
  1001. Ideal (a^4 + a^3 + a^2 + a + 1, b - a, c - a, d^2 + 3*d*a + a^2, e + d + 3*a) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field,
  1002. Ideal (a^4 + a^3 + a^2 + a + 1, b - a, c^2 + 3*c*a + a^2, d + c + 3*a, e - a) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field,
  1003. Ideal (a^4 + a^3 + a^2 + a + 1, b^2 + 3*b*a + a^2, c + b + 3*a, d - a, e - a) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field,
  1004. Ideal (a^4 + a^3 + a^2 + a + 1, b^3 + b^2*a + b^2 + b*a^2 + b*a + b + a^3 + a^2 + a + 1, c + b^2*a^3 + b^2*a^2 + b^2*a + b^2, -d + b^2*a^2 + b^2*a + b^2 + b*a^2 + b*a + a^2, -e + b^2*a^3 - b*a^2 - b*a - b - a^2 - a) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field,
  1005. Ideal (a^4 + a^3 + 6*a^2 - 4*a + 1, -11*b^2 + 6*b*a^3 + 10*b*a^2 + 39*b*a + 2*b + 16*a^3 + 23*a^2 + 104*a - 24, 11*c + 3*a^3 + 5*a^2 + 25*a + 1, 11*d + 3*a^3 + 5*a^2 + 25*a + 1, -11*e - 11*b + 6*a^3 + 10*a^2 + 39*a + 2) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field]
  1006. sage: R.<x1,x2> = PolynomialRing(QQ, 2, order='lex')
  1007. sage: f1 = 1/2*((x1^2 + 2*x1 - 4)*x2^2 + 2*(x1^2 + x1)*x2 + x1^2)
  1008. sage: f2 = 1/2*((x1^2 + 2*x1 + 1)*x2^2 + 2*(x1^2 + x1)*x2 - 4*x1^2)
  1009. sage: I = Ideal(f1,f2)
  1010. sage: I.triangular_decomposition()
  1011. [Ideal (x2, x1^2) of Multivariate Polynomial Ring in x1, x2 over Rational Field,
  1012. Ideal (x2, x1^2) of Multivariate Polynomial Ring in x1, x2 over Rational Field,
  1013. Ideal (x2, x1^2) of Multivariate Polynomial Ring in x1, x2 over Rational Field,
  1014. Ideal (x2^4 + 4*x2^3 - 6*x2^2 - 20*x2 + 5, 8*x1 - x2^3 + x2^2 + 13*x2 - 5) of Multivariate Polynomial Ring in x1, x2 over Rational Field]
  1015. TESTS::
  1016. sage: R.<x,y> = QQ[]
  1017. sage: J = Ideal(x^2+y^2-2, y^2-1)
  1018. sage: J.triangular_decomposition()
  1019. [Ideal (y^2 - 1, x^2 - 1) of Multivariate Polynomial Ring in x, y over Rational Field]
  1020. """
  1021. P = self.ring()
  1022. is_groebner = self.basis_is_groebner()
  1023. # make sure to work w.r.t. 'lex'
  1024. if P.term_order() != 'lex':
  1025. Q = P.change_ring(order='lex')
  1026. else:
  1027. Q = P
  1028. # the Singular routines are quite picky about their input.
  1029. if is_groebner:
  1030. if Q == P:
  1031. I = MPolynomialIdeal(P, self.interreduced_basis()[::-1])
  1032. else:
  1033. I = self
  1034. I = MPolynomialIdeal(P, I.transformed_basis('fglm')[::-1]) # -> 'lex'
  1035. I = I.change_ring(Q) # transform to 'lex' GB
  1036. else:
  1037. if Q == P:
  1038. I = MPolynomialIdeal(P, self.groebner_basis()[::-1])
  1039. else:
  1040. I = self.change_ring(Q) # transform to 'lex' GB
  1041. I = MPolynomialIdeal(Q, I.groebner_basis()[::-1])
  1042. if I.dimension() != 0:
  1043. raise TypeError, "dimension must be zero"
  1044. from sage.libs.singular.function import singular_function
  1045. from sage.libs.singular.function import lib as singular_lib
  1046. singular_lib('triang.lib')
  1047. if algorithm is None:
  1048. algorithm = "singular:triangL"
  1049. if algorithm in ("singular:triangL","singular:triangLfak","singular:triangM"):
  1050. f = singular_function(algorithm[9:])
  1051. Tbar = f(I, attributes={I:{'isSB':1}})
  1052. else:
  1053. raise TypeError, "algorithm '%s' unknown"%algorithm
  1054. T = Sequence([ MPolynomialIdeal(Q,t) for t in Tbar])
  1055. f = lambda x,y: cmp(x.gens(), y.gens())
  1056. T.sort(f)
  1057. return T
  1058. @require_field
  1059. def dimension(self, singular=singular_default):
  1060. """
  1061. The dimension of the ring modulo this ideal.
  1062. EXAMPLE::
  1063. sage: P.<x,y,z> = PolynomialRing(GF(32003),order='degrevlex')
  1064. sage: I = ideal(x^2-y,x^3)
  1065. sage: I.dimension()
  1066. 1
  1067. For polynomials over a finite field of order too large for Singular,
  1068. this falls back on a toy implementation of Buchberger to compute
  1069. the Groebner basis, then uses the algorithm described in Chapter 9,
  1070. Section 1 of Cox, Little, and O'Shea's "Ideals, Varieties, and Algorithms".
  1071. EXAMPLE::
  1072. sage: R.<x,y> = PolynomialRing(GF(2147483659),order='lex')
  1073. sage: I = R.ideal([x*y,x*y+1])
  1074. sage: I.dimension()
  1075. verbose 0 (...: multi_polynomial_ideal.py, dimension) Warning: falling back to very slow toy implementation.
  1076. 0
  1077. sage: I=ideal([x*(x*y+1),y*(x*y+1)])
  1078. sage: I.dimension()
  1079. verbose 0 (...: multi_polynomial_ideal.py, dimension) Warning: falling back to very slow toy implementation.
  1080. 1
  1081. sage: I = R.ideal([x^3*y,x*y^2])
  1082. sage: I.dimension()
  1083. verbose 0 (...: multi_polynomial_ideal.py, dimension) Warning: falling back to very slow toy implementation.
  1084. 1
  1085. sage: R.<x,y> = PolynomialRing(GF(2147483659),order='lex')
  1086. sage: I = R.ideal(0)
  1087. sage: I.dimension()
  1088. verbose 0 (...: multi_polynomial_ideal.py, dimension) Warning: falling back to very slow toy implementation.
  1089. 2
  1090. ALGORITHM:
  1091. Uses Singular, unless

Large files files are truncated, but you can click here to view the full file