Skip to content

Instantly share code, notes, and snippets.

@defeo
Last active October 17, 2017 12:56
Show Gist options
  • Select an option

  • Save defeo/1986c494e878b2d93b4534bbca2f9642 to your computer and use it in GitHub Desktop.

Select an option

Save defeo/1986c494e878b2d93b4534bbca2f9642 to your computer and use it in GitHub Desktop.
MA2-ace TD 3
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercice 2.1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Avec des anneaux de polynômes"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"A.<x,y> = QQ[]\n",
"P = x*y^5 + 2*y^4 + 3*y^3*x^3 + 4*x^2*y^2 + 5*x*y^2 + 6*y*x^3 + 7*y"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"6"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"P.degree()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(3*y^3 + 6*y)*x^3 + 4*y^2*x^2 + (y^5 + 5*y^2)*x + 2*y^4 + 7*y"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Q = P.polynomial(x)\n",
"Q"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Univariate Polynomial Ring in x over Univariate Polynomial Ring in y over Rational Field"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Q.parent()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Une syntaxe équivalente"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Univariate Polynomial Ring in x over Univariate Polynomial Ring in y over Rational Field"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"B = QQ['y']['x']\n",
"B"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(3*y^3 + 6*y)*x^3 + 4*y^2*x^2 + (y^5 + 5*y^2)*x + 2*y^4 + 7*y"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"B(P)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"avec des variables symboliques"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercice 2.2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Avec des variables symboliques"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(x, y)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"var('x,y')"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"P = (x^2 + x*y + x + y)*(x + y)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(x^2 + x*y + x + y)*(x + y)"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"P"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"x^3 + 2*x^2*y + x*y^2 + x^2 + 2*x*y + y^2"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"P.expand()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(x + y)^2*(x + 1)"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"P.factor()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"x^3 + x^2*(2*y + 1) + (y^2 + 2*y)*x + y^2"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"P.expand().collect(x)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"x^3 + (x + 1)*y^2 + x^2 + 2*(x^2 + x)*y"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"P.expand().collect(y)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Avec des anneaux de polynômes"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"A.<x,y> = QQ[]"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"x^3 + 2*x^2*y + x*y^2 + x^2 + 2*x*y + y^2"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"P = (x^2 + x*y + x + y)*(x + y)\n",
"P"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(x + 1) * (x + y)^2"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"P.factor()"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"x^3 + (2*y + 1)*x^2 + (y^2 + 2*y)*x + y^2"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"P.polynomial(x)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(x + 1)*y^2 + (2*x^2 + 2*x)*y + x^3 + x^2"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"P.polynomial(y)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercice 3.1"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"A.<x,y> = QQ[]"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Degree reverse lexicographic term order"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A.term_order()"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x > y"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"P = x*y^5 + 2*y^4 + 3*y^3*x^3 + 4*x^2*y^2 + 5*x*y^2 + 6*y*x^3 + 7*y"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"3*x^3*y^3 + x*y^5 + 6*x^3*y + 4*x^2*y^2 + 2*y^4 + 5*x*y^2 + 7*y"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"P"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Lexicographic term order"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"B.<x,y> = PolynomialRing(QQ, order='lex')\n",
"B.term_order()"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"3*x^3*y^3 + 6*x^3*y + 4*x^2*y^2 + x*y^5 + 5*x*y^2 + 2*y^4 + 7*y"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"B(P)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Multivariate Polynomial Ring in x, y over Rational Field"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"C = B.change_ring(order='deglex')\n",
"C"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Degree lexicographic term order"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"C.term_order()"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"3*x^3*y^3 + x*y^5 + 6*x^3*y + 4*x^2*y^2 + 2*y^4 + 5*x*y^2 + 7*y"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"C(P)"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"3*x^3*y^3 + x*y^5 + 6*x^3*y + 4*x^2*y^2 + 2*y^4 + 5*x*y^2 + 7*y"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"P.change_ring(B.change_ring(order='degrevlex'))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Excercice 3.7"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A.<z,y,x> = PolynomialRing(QQ, order=\"lex\")\n",
"z > y > x"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"I = A.ideal([y - x^2, z - x^3])"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"I.basis_is_groebner()"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(z^2 - x^4*y).mod(I)"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(-x^4, z + x^3)"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"h1, h2 = (z^2 - x^4*y).lift(I)\n",
"h1, h2"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"z^2 - y*x^4"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"h1*I.gen(0) + h2*I.gen(1)"
]
}
],
"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