{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Call Singular from GAP\n", "\n", "Run the examples from [a blog post by Bill Hart](https://wbhart.blogspot.de/2017/01/singular-and-julia.html).\n", "\n", "First load the GAP package." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "LoadPackage( \"JuliaExperimental\", false );;" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A Nemo residue ring over Singular's ring of integers" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 2, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "R:= Julia.Nemo.ResidueRing( Julia.Singular.ZZ, 23 );" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 3, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "R(12) + R(7);" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\"Singular.n_Zn\"" ] }, "execution_count": 4, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "JuliaTypeInfo( R(12) );" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 5, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "Julia.Base.parent( R(12) );" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Polynomial rings" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "indetnames:= Julia.Base.convert( JuliaEvalString( \"Array{String,1}\" ),\n", "ConvertedToJulia( [ \"x\", \"y\", \"z\", \"t\" ] ) );;\n", "Rinfo:= Julia.Singular.PolynomialRing( Julia.Singular.QQ, indetnames );;" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 8, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "R:= Rinfo[1];" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[ , , , ]" ] }, "execution_count": 9, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "indets:= ConvertedFromJulia( Rinfo[2] );" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "x:= indets[1];; y:= indets[2];; z:= indets[3];; t:= indets[4];;" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Polynomials" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 14, "metadata": { "text/plain": "" }, "output_type": "execute_result" }, { "data": { "text/plain": [ "" ] }, "execution_count": 15, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "f:= (x+y+z)*(x^2*y + 2*x);\n", "g:= (x+y+z)*(x+z+t);" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 16, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "Julia.Base.gcd( f, g );" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Ideals" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 17, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "I1:= Julia.Singular.Ideal( R );" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 18, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "I2:= Julia.Singular.Ideal( R, x, t*z + x );" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 19, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "Julia.Singular.ngens( I2 );" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 20, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "I2[2];" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Groebner basis" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 21, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "I:= Julia.Singular.Ideal( R, x*y + 1, x+y, 2*x+y+z );" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 22, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "gbasis:= Julia.Base.std( I );" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 23, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "Julia.Singular.ngens( gbasis );" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Syzygy matrix" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 24, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "M:= Julia.Singular.syz( I );" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 25, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "# Currently there is no 'Julia.Singular.Matrix'.\n", "JuliaFunction( \"Matrix\", \"Singular\" )( M );" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Ideal arithmetic" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 26, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "I:= Julia.Singular.Ideal( R, x*y + 1, x+y, 2*x+y+z );" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 27, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "J:= Julia.Singular.Ideal( R, 2*x-y + 1, 2*z+x);" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 28, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "I^2;" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 29, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "I * J;" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 30, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "Julia.Singular.lead( I );" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Resolutions" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 31, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "I:= Julia.Singular.MaximalIdeal( R, 1 );" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 32, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "I:= Julia.Base.std( I );" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 33, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "r:= Julia.Singular.sres( I, 5 );" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Access to modules in the resolution" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 34, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "r[2];" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 35, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "r[3];" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 36, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "r[3][1];" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Arithmetic on module elements" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 37, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "r[2][1] * 3;" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 38, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "r[2][1] + r[2][2];" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Standard bases and resolutions of modules" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 39, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "J:= Julia.Base.std( r[3] );" ] }, { "cell_type": "code", "execution_count": 40, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 40, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "J1:= Julia.Singular.sres( J, 4 );" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 41, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "J1[2];" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Generic multivariate polynomial code in Nemo, over a Singular coefficient ring" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [], "source": [ "Rinfo:= Julia.Nemo.PolynomialRing( Julia.Singular.ZZ, indetnames );;\n", "R:= Rinfo[1];;\n", "indets:= ConvertedFromJulia( Rinfo[2] );;\n", "x:= indets[1];; y:= indets[2];; z:= indets[3];; t:= indets[4];;\n", "f:= (2*t^2078*z^15*y^53-28*t^1080*z^15*y^44+98*t^82*z^15*y^35)*x^9\n", "+(t^2003*y^40-14*t^1005*y^31+49*t^7*y^22)*x^7\n", "+((t^2100+t^2000)*y^40 +(-4*t^1079*z^16+156*t^1078*z^15)*y^33\n", "+(-14*t^1102-14*t^1002)*y^31+(28*t^81*z^16-1092*t^80*z^15)*y^24\n", "+(49*t^104+49*t^4)*y^22)*x^6\n", "+((-2*t^1004*z+78*t^1003)*y^20+(14*t^6*z-546*t^5)*y^11)*x^4\n", "+(((-2*t^1101-2*t^1001)*z+(78*t^1100+78*t^1000))*y^20\n", "+(2*t^80*z^17-156*t^79*z^16+3042*t^78*z^15)*y^13\n", "+((14*t^103+14*t^3)*z+(-546*t^102-546*t^2))*y^11)*x^3\n", "+(t^5*z^2-78*t^4*z+1521*t^3)*x\n", "+((t^102+t^2)*z^2+(-78*t^101-78*t)*z+(1521*t^100+1521));;\n", "g:= (4*t^1156*z^30*y^46-28*t^158*z^30*y^37)*x^9\n", "+(4*t^1081*z^15*y^33-28*t^83*z^15*y^24)*x^7\n", "+((4*t^1178+4*t^1078)*z^15*y^33+(-4*t^157*z^31+156*t^156*z^30)*y^26\n", "+(-28*t^180-28*t^80)*z^15*y^24)*x^6\n", "+(t^1006*y^20-7*t^8*y^11)*x^5\n", "+((2*t^1103+2*t^1003)*y^20+(-4*t^82*z^16+156*t^81*z^15)*y^13\n", "+(-14*t^105-14*t^5)*y^11)*x^4\n", "+((t^1200+2*t^1100+t^1000)*y^20+((-4*t^179-4*t^79)*z^16\n", "+(156*t^178+156*t^78)*z^15)*y^13+(-7*t^202-14*t^102-7*t^2)*y^11)*x^3\n", "+(-t^7*z+39*t^6)*x^2\n", "+((-2*t^104-2*t^4)*z+(78*t^103+78*t^3))*x\n", "+((-t^201-2*t^101-t)*z+(39*t^200+78*t^100+39));;" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 51, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "p:= Julia.Base.gcd( f, g );" ] } ], "metadata": { "kernelspec": { "display_name": "GAP 4 (native)", "language": "gap", "name": "gap-native" }, "language_info": { "codemirror_mode": "gap", "file_extension": ".g", "mimetype": "text/x-gap", "name": "GAP (native)", "nbconvert_exporter": "", "pygments_lexer": "gap", "version": "4.dev" } }, "nbformat": 4, "nbformat_minor": 2 }