DeRhamComputation/superelliptic.ipynb

420 lines
10 KiB
Plaintext
Raw Normal View History

2021-08-19 22:35:11 +02:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 219,
"metadata": {},
"outputs": [],
"source": [
"class superelliptic:\n",
" def __init__(self, f, m, p):\n",
" R.<x> = PolynomialRing(GF(p))\n",
" self.polynomial = R(f)\n",
" self.exponent = m\n",
" self.characteristic = p\n",
" \n",
" \n",
" def __repr__(self):\n",
" f = self.polynomial\n",
" m = self.exponent\n",
" p = self.characteristic\n",
" return 'Superelliptic curve with the equation y^' + str(m) + ' = ' + str(f)+' over finite field with ' + str(p) + ' elements.'\n",
" \n",
" def genus(self):\n",
" r = self.polynomial.degree()\n",
" m = self.exponent\n",
" delta = GCD(r, m)\n",
" return 1/2*((r-1)*(m-1) - delta + 1)\n",
" \n",
" def basis_holomorphic_differentials(self, j = 'all'):\n",
" f = self.polynomial\n",
" m = self.exponent\n",
" p = self.characteristic\n",
" r = f.degree()\n",
" delta = GCD(r, m)\n",
" \n",
" basis = {}\n",
" if j == 'all':\n",
" k = 0\n",
" for i in range(1, r):\n",
" for j in range(1, m):\n",
" if (r*j - m*i >= delta):\n",
" basis[k] = superelliptic_form(C, x^(i-1)/y^j)\n",
" k = k+1\n",
" return basis\n",
" else:\n",
" k = 0\n",
" for i in range(1, r):\n",
" if (r*j - m*i >= delta):\n",
" basis[k] = superelliptic_form(C, x^(i-1)/y^j)\n",
" k = k+1\n",
" return basis\n",
" \n",
"def reduction(C, g):\n",
" p = C.characteristic\n",
" R.<x, y> = PolynomialRing(GF(p), 2)\n",
" RR = FractionField(R)\n",
" f = C.polynomial\n",
" r = f.degree()\n",
" m = C.exponent\n",
" g = RR(g)\n",
" g1 = g.numerator()\n",
" g2 = g.denominator()\n",
" \n",
" R1.<x> = PolynomialRing(GF(p))\n",
" R2 = FractionField(R1)\n",
" R3.<y> = PolynomialRing(R2) \n",
" (A, B, C) = xgcd(R3(g2), R3(y^m - f))\n",
" g = R3(g1*B/A)\n",
" \n",
" while(g.degree(R(y)) >= m):\n",
" d = g.degree(R(y))\n",
" G = g.coefficient(R(y^d))\n",
" i = floor(d/m)\n",
" g = g - G*y^d + f^i * y^(d%m) *G\n",
" \n",
" return(R3(g))\n",
"\n",
"def reduction_form(C, g):\n",
" p = C.characteristic\n",
" R.<x, y> = PolynomialRing(GF(p), 2)\n",
" RR = FractionField(R)\n",
" f = C.polynomial\n",
" r = f.degree()\n",
" m = C.exponent\n",
" g = reduction(C, g)\n",
"\n",
" g1 = RR(0)\n",
" R1.<x> = PolynomialRing(GF(p))\n",
" R2 = FractionField(R1)\n",
" R3.<y> = PolynomialRing(R2)\n",
" \n",
" g = R3(g)\n",
" for j in range(0, m):\n",
" G = g.coefficients(sparse = false)[j]\n",
" g1 += RR(y^(j-m)*f*G)\n",
" \n",
" return(g1)\n",
" \n",
"class superelliptic_function:\n",
" def __init__(self, C, g):\n",
" R.<x, y> = PolynomialRing(GF(p), 2)\n",
" RR = FractionField(R)\n",
" f = C.polynomial\n",
" r = f.degree()\n",
" m = C.exponent\n",
" \n",
" self.curve = C\n",
" g = reduction(C, g)\n",
" self.function = g\n",
" \n",
" def __repr__(self):\n",
" return str(self.function)\n",
" \n",
" def jth_component(self, j):\n",
" g = self.function\n",
" R.<x, y> = PolynomialRing(GF(p), 2)\n",
" g = R(g)\n",
" return g.coefficient(y^j)\n",
" \n",
" def __add__(self, other):\n",
" C = self.curve\n",
" g1 = self.function\n",
" g2 = other.function\n",
" g = reduction(C, g1 + g2)\n",
" return superelliptic_function(C, g)\n",
" \n",
" def __sub__(self, other):\n",
" C = self.curve\n",
" g1 = self.function\n",
" g2 = other.function\n",
" g = reduction(C, g1 - g2)\n",
" return superelliptic_function(C, g)\n",
" \n",
" def __mul__(self, other):\n",
" C = self.curve\n",
" g1 = self.function\n",
" g2 = other.function\n",
" g = reduction(C, g1 * g2)\n",
" return superelliptic_function(C, g)\n",
" \n",
" def __truediv__(self, other):\n",
" C = self.curve\n",
" g1 = self.function\n",
" g2 = other.function\n",
" g = reduction(C, g1 / g2)\n",
" return superelliptic_function(C, g)\n",
" \n",
"def diffn(self):\n",
" C = self.curve\n",
" f = C.polynomial\n",
" m = C.exponent\n",
" g = self.function\n",
" A = g.derivative(x)\n",
" B = g.derivative(y)*f.derivative(x)/(m*y^(m-1))\n",
" return superelliptic_form(C, A+B)\n",
" \n",
"class superelliptic_form:\n",
" def __init__(self, C, g):\n",
" R.<x, y> = PolynomialRing(GF(p), 2)\n",
" RR = FractionField(R)\n",
" g = RR(reduction_form(C, g))\n",
" self.form = g\n",
" self.curve = C \n",
" \n",
" def __add__(self, other):\n",
" C = self.curve\n",
" g1 = self.form\n",
" g2 = other.form\n",
" g = reduction(C, g1 + g2)\n",
" return superelliptic_form(C, g)\n",
" \n",
" def __sub__(self, other):\n",
" C = self.curve\n",
" g1 = self.form\n",
" g2 = other.form\n",
" g = reduction(C, g1 - g2)\n",
" return superelliptic_form(C, g)\n",
" \n",
" def __repr__(self):\n",
" g = self.form\n",
" if len(str(g)) == 1:\n",
" return str(g) + ' dx'\n",
" return '('+str(g) + ') dx'\n",
" \n",
" def jth_component(self, j):\n",
" g = self.form\n",
" R.<x, y> = PolynomialRing(GF(p), 2)\n",
" g = R(g)\n",
" return g.coefficient(y^j)"
]
},
{
"cell_type": "code",
"execution_count": 220,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{0: (1/y) dx}"
]
},
"execution_count": 220,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"C = superelliptic(x^3 + x + 2, 2, 5)\n",
"C.basis_holomorphic_differentials()"
]
},
{
"cell_type": "code",
"execution_count": 179,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 179,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A.degree(y)"
]
},
{
"cell_type": "code",
"execution_count": 180,
"metadata": {},
"outputs": [],
"source": [
"p = 5\n",
"R.<x, y> = PolynomialRing(GF(p), 2)\n",
"g = x^6*y^2 + y^2"
]
},
{
"cell_type": "code",
"execution_count": 181,
"metadata": {},
"outputs": [],
"source": [
"omega = diffn(superelliptic_function(C, y^2))"
]
},
{
"cell_type": "code",
"execution_count": 183,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-2*x^2 + 1"
]
},
"execution_count": 183,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"omega.jth_component(0)"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"y"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"R.<x, y> = PolynomialRing(GF(p), 2)\n",
"g1 = x^3*y^7 + x^2*y^9\n",
"g2 = x^2*y + y^6\n",
"R1.<x> = PolynomialRing(GF(p))\n",
"R2 = FractionField(R1)\n",
"R3.<y> = PolynomialRing(R2)\n",
"\n",
"xgcd(R3(g1), R3(g2))[1]*R3(g1) + xgcd(R3(g1), R3(g2))[2]*R3(g2)"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
"H = HyperellipticCurve(x^5 - x + 1)"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Hyperelliptic Curve over Finite Field of size 5 defined by y^2 = x^5 + 4*x + 1"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"H"
]
},
{
"cell_type": "code",
"execution_count": 84,
"metadata": {},
"outputs": [],
"source": [
"f = x^3 + x + 2"
]
},
{
"cell_type": "code",
"execution_count": 86,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-2*x^2 + 1"
]
},
"execution_count": 86,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f.derivative(x)"
]
},
{
"cell_type": "code",
"execution_count": 213,
"metadata": {},
"outputs": [],
"source": [
"R1.<x> = PolynomialRing(GF(p))\n",
"R2 = FractionField(R1)\n",
"R3.<y> = PolynomialRing(R2)\n",
"g = y^2/x + y/(x+1) "
]
},
{
"cell_type": "code",
"execution_count": 218,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[0, 1/(x + 1), 1/x]"
]
},
"execution_count": 218,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"g.coefficients(sparse = false)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "SageMath 9.1",
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}