Skip to content

Instantly share code, notes, and snippets.

@defeo
Last active October 25, 2017 13:02
Show Gist options
  • Select an option

  • Save defeo/89b80a1903a3f0ef95b1a239ab30c62f to your computer and use it in GitHub Desktop.

Select an option

Save defeo/89b80a1903a3f0ef95b1a239ab30c62f to your computer and use it in GitHub Desktop.
MA2-ace TD 5
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercice 5.2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"On peut construire en Sage l'ordre de l'exercice (pour des variables $x_1,x_2,y_1,y_2,y_3$) avec le constructeur `TermOrder`"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Block term order with blocks:\n",
"(Lexicographic term order of length 2,\n",
" Degree reverse lexicographic term order of length 3)"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"o = TermOrder('lex', 2) + TermOrder('degrevlex', 3)\n",
"o"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Multivariate Polynomial Ring in x1, x2, y1, y2, y3 over Rational Field"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A.<x1,x2,y1,y2,y3> = PolynomialRing(QQ, order=o)\n",
"A"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x1*y1*y2 < x1*y1^2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercice 5.3"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"A.<x,y,z> = PolynomialRing(QQ, order='lex')\n",
"I = A.ideal([x^2-2*x*z+5, x*y^2+y*z^3, 3*y^2-8*z^3])"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"[x^2 - 2*x*z + 5, x*z^3 + 9/640*z^8 - 3/20*z^7 + 3/16*z^5, y^2 - 8/3*z^3, y*z^3 - 3/80*z^8 + 2/5*z^7 - 1/2*z^5, z^9 - 32/3*z^8 + 80/3*z^6 + 1600/9*z^3]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"I.groebner_basis()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[y^4 + 16/3*y^3*z + 320/9*y^2, x*y^2 + 3/8*y^3, z^3 - 3/8*y^2, x^2 - 2*x*z + 5]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"J = I.change_ring(A.change_ring(order='degrevlex'))\n",
"J.groebner_basis()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercice 7.1"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[x, y]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A.<x,y> = PolynomialRing(QQ, order='lex')\n",
"I = A.ideal(x^2*y^2 - x, x*y^3 + y)\n",
"G = I.groebner_basis()\n",
"G"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(True, True)"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x in I, y in I"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"I.reduce(x)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(-1/2*x*y^2 - 1, 1/2*x^2*y)"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a, b = x.lift(I)\n",
"a, b"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"x"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a*I.0 + b*I.1"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"P = x^3*y^2 + 2*x*y^4\n",
"P.mod(I)"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"## Exercice 7.2"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[z^5, y*z^3, x*y*z + z^3, y^2]"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A.<x,y,z> = QQ[]\n",
"I = A.ideal(x*y*z + z^3, y^2)\n",
"I.groebner_basis()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercice 7.4"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"I = A.ideal(x + y + z, x*y + y*z + z*x, x*y*z + 1)\n",
"I.reduce(x^3 + 1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"En regardant la base de Gröbner, et par symétrie de l'ensemble générateur, on aurait pu conclure directement que $x^3+1∈I$ "
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[z^3 + 1, y^2 + y*z + z^2, x + y + z]"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"I.groebner_basis()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercice 7.6"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"A.<x,y,z,t> = PolynomialRing(QQ, order='lex')\n",
"I = A.ideal(z^5-y^3*t^2, x^2*t - y*z^2, x^2*z^3 - y^4*t, x^4*z - y^5)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[x^4*z - y^5, x^2*z^3 - y^4*t, x^2*t - y*z^2, y^3*t^2 - z^5]"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"G = I.groebner_basis()\n",
"G"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"On vérifie que la base de Gröbner calculée par Sage coïncide (à des constantes près) avec les générateurs"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"([-y^3*t^2 + z^5, x^2*t - y*z^2, x^2*z^3 - y^4*t, x^4*z - y^5],\n",
" [y^3*t^2 - z^5, x^2*t - y*z^2, x^2*z^3 - y^4*t, x^4*z - y^5])"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sorted(I.gens()), sorted(G)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"...o, plus simplement:"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"I.basis_is_groebner()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Une petite fonction pour changer l'ordre de $I$ et renvoyer les termes de tête de sa base de Gröbner"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# `ord` et `names` prennent des valeurs par défaut,\n",
"# s'ils ne sont pas donnés explicitement\n",
"def LT(I, ord='lex', names='x,y,z,t'):\n",
" A = I.ring()\n",
" J = I.change_ring(A.change_ring(names=names, order=ord))\n",
" G = J.groebner_basis()\n",
" return [g.lt() for g in G]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"sans parametres `ord` et `names`, les valeurs par défaut sont prises"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[x^4*z, x^2*z^3, x^2*t, y^3*t^2]"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"LT(I)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[y^5, x^2*z^3, z^5, y*z^2]"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"LT(I, 'degrevlex')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"syntaxe équivalente à la précédente"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[y^5, x^2*z^3, z^5, y*z^2]"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"LT(I, ord='degrevlex')"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[y^3*t^2, y^4*t, x^2*t, x^4*z]"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"LT(I, 'invlex')"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[x^4*z, x^2*z^3, y^3*t^2, x^2*t]"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"LT(I, 'deglex')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"En utilisant `TermOrder`, on peut construire d'autres ordres, par exemple l'ordre degrevlex *gradué*:"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"sage.rings.polynomial.term_order?"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[y^5, y^4*t, y^3*t^2, x^2*t]"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"LT(I, TermOrder('wdegrevlex', (2,2,1,1)))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Et, finalement, la solution, avec un autre ordre lexicographique"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[y^5, y^4*t, y^3*t^2, y^2*t^3*x^2, y*z^2, y*t^4*x^4, z^11]"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"LT(I, names='y,z,t,x')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Le même ordre, exprimé de façon matricielle"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(1,2,3,4)"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"p = SymmetricGroup(4)([2,3,4,1])\n",
"p"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[0 1 0 0]\n",
"[0 0 1 0]\n",
"[0 0 0 1]\n",
"[1 0 0 0]"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"p.matrix()"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[y^5, y^4*t, y^3*t^2, x^2*y^2*t^3, y*z^2, x^4*y*t^4, z^11]"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lt = LT(I, ord=TermOrder(p.matrix()))\n",
"lt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"On peut s'arrêter là, mais si vraiement on a envie de tester tous les ordres lexicographiques possibles, on peut s'appuyer sur les capacités\n",
"- de Sage en combinatoire, pour énumérer toutes les permutations de $x,y,z,t$ ;\n",
"- de Python en manipulation de chaînes de caractères, pour former les paramètres à passer aux fonctions."
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Permutations of the set ['x', 'y', 'z', 't']"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"S = Permutations(['x','y','z','t'])\n",
"S"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(['x', 'y', 'z', 't'], [x^4*z, x^2*z^3, x^2*t, y^3*t^2])\n",
"(['x', 'y', 't', 'z'], [x^4*z, x^2*t, x^2*z^3, y^3*t^2])\n",
"(['x', 'z', 'y', 't'], [x^4*z, x^2*z^3, x^2*t, z^5])\n",
"(['x', 'z', 't', 'y'], [x^4*z, x^2*z^3, x^2*t, z^5])\n",
"(['x', 't', 'y', 'z'], [x^4*z, x^2*t, x^2*z^3, t^2*y^3])\n",
"(['x', 't', 'z', 'y'], [x^4*z, x^2*t, x^2*z^3, t^2*y^3])\n",
"(['y', 'x', 'z', 't'], [y^5, y^4*t, y^3*t^2, y^2*x^2*t^3, y*x^4*t^4, y*z^2, x^6*t^5])\n",
"(['y', 'x', 't', 'z'], [y^5, y^4*t, y^3*t^2, y^2*x^2*t^3, y*x^4*t^4, y*z^2, x^6*t^5])\n",
"(['y', 'z', 'x', 't'], [y^5, y^4*t, y^3*t^2, y^2*x^2*t^3, y*z^2, y*x^4*t^4, z^11])\n",
"(['y', 'z', 't', 'x'], [y^5, y^4*t, y^3*t^2, y^2*t^3*x^2, y*z^2, y*t^4*x^4, z^11])\n",
"(['y', 't', 'x', 'z'], [y^5, y^4*t, y^3*t^2, y^2*t^3*x^2, y*t^4*x^4, y*z^2, t^5*x^6])\n",
"(['y', 't', 'z', 'x'], [y^5, y^4*t, y^3*t^2, y^2*t^3*x^2, y*t^4*x^4, y*z^2, t^5*x^6])\n",
"(['z', 'x', 'y', 't'], [z^5, z^3*x^2, z^2*y, z*x^4, z*y^6, x^10*t])\n",
"(['z', 'x', 't', 'y'], [z^5, z^3*x^2, z^2*y, z*x^4, z*y^6, x^10*t])\n",
"(['z', 'y', 'x', 't'], [z^5, z^3*x^2, z^2*y, z*y^6, z*x^4, y^11])\n",
"(['z', 'y', 't', 'x'], [z^5, z^3*x^2, z^2*y, z*y^6, z*x^4, y^11])\n",
"(['z', 't', 'x', 'y'], [z^5, z^3*x^2, z^2*y, z*x^4, z*y^6, t*x^10])\n",
"(['z', 't', 'y', 'x'], [z^5, z^3*x^2, z^2*y, z*y^6, z*x^4, t*x^10])\n",
"(['t', 'x', 'y', 'z'], [t^2*y^3, t*x^2, t*y^4, x^4*z])\n",
"(['t', 'x', 'z', 'y'], [t^2*y^3, t*x^2, t*y^4, x^4*z])\n",
"(['t', 'y', 'x', 'z'], [t^2*y^3, t*y^4, t*x^2, y^5])\n",
"(['t', 'y', 'z', 'x'], [t^2*y^3, t*y^4, t*x^2, y^5])\n",
"(['t', 'z', 'x', 'y'], [t^2*y^3, t*x^2, t*y^4, z*x^4])\n",
"(['t', 'z', 'y', 'x'], [t^2*y^3, t*y^4, t*x^2, z*x^4])\n"
]
}
],
"source": [
"for s in S:\n",
" print(s, LT(I, names=','.join(s)))"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"## Exercice 7.7"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[x^2 - x, x*y - x, y^2 - x]"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A.<x,y> = QQ[]\n",
"I = A.ideal(x - y^2, x*y - x)\n",
"I.groebner_basis()"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[x - y^2, y^3 - y^2]"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"I.change_ring(A.change_ring(order='lex')).groebner_basis()"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[y^2 - x, x*y - x, x^2 - x]"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"I.change_ring(A.change_ring(order='invlex')).groebner_basis()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"L'ensemble $G = \\{x^2 - x,\\; xy - x,\\; y^2 - x,\\; y^3 - y^2\\}$ forme une base de Gröbner de l'idéal pour tous les ordres ci-dessus.\n",
"\n",
"Selon l'ordre monomial choisi l'*escalier* de cette base (ensemble des monômes **pas** contenus dans $〈\\mathrm{LT}(G)〉$) contient les monômes\n",
"\n",
"$$\\begin{cases}\n",
"\\{1, x, y\\} &\\text{si $x < y^2$,}\\\\\n",
"\\{1, y, y^2\\} &\\text{sinon.}\n",
"\\end{cases}$$\n",
"\n",
"Dans tous les cas, ceci coincide avec la dimension de l'algèbre quotient $ℚ[x,y]/I$, qui est $3$ (l'idéal est de dimension $0$). "
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(0, 3)"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"I.dimension(), I.vector_space_dimension()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Puisque $G⊂I$, ceux-ci sont aussi les deux seuls escaliers possibles pour $\\mathrm{LT}(I)$. Par conséquent, les monomes de tête de $G$ engendrent $\\mathrm{LT}(I)$ pour n'importe quel ordre monomial."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "SageMath 8.0",
"language": "",
"name": "sagemath"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.13"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment