Commit 32e57312 by Michael Barz

add BKK checker to a public repo

parents
Showing with 111 additions and 0 deletions
{
"cells": [
{
"cell_type": "markdown",
"id": "pressing-loading",
"metadata": {},
"source": [
"Starting with a set $ A \\subseteq \\mathbb{Z}^d, $ we figure out a set of equations defining $ X^A, $ and then compute the degree of $ X^A. $"
]
},
{
"cell_type": "code",
"execution_count": 155,
"id": "disabled-forth",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 155,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A = [ [1,0], [0,1], [2,0], [1,1], [1,2] ]\n",
"# Warning: Do not input [0,...,0] as a vector in A;\n",
"# it is automatically added to homogenize throughout\n",
"# the code execution.\n",
"\n",
"parameters = [ \"t\" + str(i+1) for i in range(len(A[0])) ]\n",
"variables = [ \"x\" + str(i+1) for i in range(len(A)) ]\n",
"\n",
"R = PolynomialRing(CC, parameters + variables)\n",
"\n",
"def make_term(i, exponent):\n",
" term = \"x\" + str(i+1) + \" - \"\n",
" second = \"1\"\n",
" for j in range(len(exponent)):\n",
" e = exponent[j]\n",
" if e > 0:\n",
" second = second + \" * \" + \"t\" + str(j+1) + \"^(\" + str(e) + \")\"\n",
" return (term + second)\n",
"\n",
"# this ideal is the affine variety; now we homogenize\n",
"I = R.ideal([make_term(i, A[i]) for i in range(len(variables))])\n",
"\n",
"S = PolynomialRing(CC, variables)\n",
"\n",
"# By elimination theory, if we take a Groebner basis of I, \n",
"# and then remove all the terms containing a 'ti' parameter,\n",
"# we get an equation for our affine variety.\n",
"def filter_basis(basis):\n",
" filtered_basis = []\n",
" for poly in basis:\n",
" poly_str = str(poly)\n",
" if not ('t' in poly_str):\n",
" filtered_basis.append(poly_str)\n",
" return filtered_basis\n",
"\n",
"# So, take the ideal of our affine variety,\n",
"# and then homogenize with a new variable x0.\n",
"J = S.ideal(filter_basis(I.groebner_basis()))\n",
"\n",
"K = J.homogenize(\"x0\")\n",
"\n",
"# now, we can compute deg(X^A), since\n",
"# the Hilbert polynomial of X^A is\n",
"# deg(X^A) * t^d/d! + O(t^{d-1})\n",
"hilbert_poly = K.hilbert_polynomial()\n",
"\n",
"# output degree!\n",
"\n",
"dimension = hilbert_poly.degree()\n",
"factorial(dimension) * hilbert_poly.coefficients()[-1]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "disabled-uncle",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "SageMath 9.2",
"language": "sage",
"name": "sagemath"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment