{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Call Singular from GAP\n", "\n", "Show the example from the [Computeralgebra-Rundrief Nr. 55, Oktober 2014](http://www.fachgruppe-computeralgebra.de/rundbrief/).\n", "\n", "First load the GAP package." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "LoadPackage( \"JuliaExperimental\", false );;" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Part 1: Just call the appropriate Julia functions from GAP.\n", "\n", "Define the ring with the default monomial ordering.\n", "The syntax looks complicated; the reason is that the Julia syntax\n", "for specifying the monomial ordering ('named arguments')\n", "is not available in the low level interface.\n", "(As a workaround, we can provide some Julia code, see Part 2 below.)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 2, "metadata": { "text/plain": "" }, "output_type": "execute_result" }, { "data": { "text/plain": [ "" ] }, "execution_count": 3, "metadata": { "text/plain": "" }, "output_type": "execute_result" }, { "data": { "text/plain": [ "" ] }, "execution_count": 4, "metadata": { "text/plain": "" }, "output_type": "execute_result" }, { "data": { "text/plain": [ "" ] }, "execution_count": 5, "metadata": { "text/plain": "" }, "output_type": "execute_result" }, { "data": { "text/plain": [ "[ , , , ]" ] }, "execution_count": 6, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "indetnames:= ConvertedToJulia( [ \"x0\", \"x1\", \"x2\", \"x3\" ] );\n", "indetnames:= Julia.Base.convert( JuliaEvalString( \"Array{String,1}\" ),\n", " indetnames );\n", "Rinfo:= Julia.Singular.PolynomialRing( Julia.Singular.QQ, indetnames );\n", "R:= Rinfo[1];\n", "indets:= ConvertedFromJulia( Rinfo[2] );\n", "x0:= indets[1];; x1:= indets[2];; x2:= indets[3];; x3:= indets[4];;" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define the polynomial $( x_1 + x_3 )^2$." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 11, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "p:= (x1+x3)^2;" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define the ideal in R generated by $x_0^2 - x_1 x_3$ and $x_0 x_1 - x_2 x_3$." ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 12, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "I:= Julia.Singular.Ideal( R, x0^2 - x1*x3, x0*x1 - x2*x3 );" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The corresponding matrix $i$ (of ideal generators)." ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 13, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "i:= JuliaFunction( \"Matrix\", \"Singular\" )( I );" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The sum $I + I$ means the sum of ideals." ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 14, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "J:= I + I;" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Whereas $i + i$ means the sum of Singular matrices." ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 15, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "i + i;" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The squared ideal $I^2$ inside $R$:" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 16, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "I2 := I^2;" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The Gröbner basis of the ideal $I$\n", "is returned as a new different (but mathematically equal) ideal $G$." ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 17, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "G:= Julia.Base.std( I );" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The syzygies of the generators of $G$ are the columns of a Singular module." ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 18, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "S:= Julia.Singular.syz( G );" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To access the second column of $S$ use:" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 19, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "S[2];" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To create a matrix in `Singular.jl`, use the following.\n", "```\n", "Singular.matrix( R, 3, 2, [ x0, x3, x1, x2, x3, x0 ] )'\n", "```\n", "Via the GAP interface, the following works.\n", "(We have to adjust the Julia type of the array,\n", "in order to make it acceptable for `AbstractAlgebra.matrix`.)" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 22, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "arr1:= ConvertedToJulia( [ x0, x3, x1, x2, x3, x0 ] );;\n", "arr2:= Julia.Base.convert(\n", "JuliaEvalString( \"Array{Singular.spoly{Singular.n_Q},1}\" ),\n", "arr1 );;\n", "m:= Julia.AbstractAlgebra.matrix( R, 3, 2, arr2 );" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To extract the $(2,1)$-entry from the matrix use the following.\n", "(Access to 'rows' or 'columns' of such a matrix is not supported.)" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 23, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "m[ 2, 1 ];" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Part 2: Use some GAP structures on top of the Julia interface.\n", "\n", "Define the ring with the monomial ordering `\"degrevlex\"`." ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "#I Global variable `x0' is already defined and will be overwritten\n", "#I Global variable `x1' is already defined and will be overwritten\n", "#I Global variable `x2' is already defined and will be overwritten\n", "#I Global variable `x3' is already defined and will be overwritten\n", "#I Assigned the global variables [ x0, x1, x2, x3 ]\n" ] }, { "data": { "text/plain": [ "Singular_QQ[x0,x1,x2,x3]" ] }, "execution_count": 24, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "R:= SingularPolynomialRing( Rationals, [ \"x0\", \"x1\", \"x2\", \"x3\" ] :\n", " ordering:= \"dp\" );\n", "AssignGeneratorVariables( R );" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define the polynomial $( x_1 + x_3 )^2$." ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "<>" ] }, "execution_count": 26, "metadata": { "text/plain": "" }, "output_type": "execute_result" }, { "data": { "text/plain": [ "true" ] }, "execution_count": 27, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "p:= (x1+x3)^2;\n", "IsSingularPolynomial( p );" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define the ideal in $R$ generated by $x_0^2 - x_1 x_3$ and $x_0 x_1 - x_2 x_3$." ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 28, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "I:= Ideal( R, [ x0^2 - x1*x3, x0*x1 - x2*x3 ] );" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Do not mix up the ideal and its list of generators." ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[ <>, <> ]" ] }, "execution_count": 29, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "i:= GeneratorsOfIdeal( I );" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The Gröbner basis of the ideal $I$\n", "is returned as a new different (but mathematically equal) ideal $G$." ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 30, "metadata": { "text/plain": "" }, "output_type": "execute_result" }, { "data": { "text/plain": [ "[ <>, <>, <> ]" ] }, "execution_count": 31, "metadata": { "text/plain": "" }, "output_type": "execute_result" } ], "source": [ "G:= GroebnerBasisIdeal( I );\n", "GeneratorsOfIdeal( 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 }