source: git/Singular/LIB/normaliz.lib @ 0dd77c2

spielwiese
Last change on this file since 0dd77c2 was 0610f0e, checked in by Hans Schoenemann <hannes@…>, 14 years ago
format git-svn-id: file:///usr/local/Singular/svn/trunk@12790 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 51.6 KB
Line 
1// Singular library normaliz.lib
2
3version="$Id$"
4category="Commutative algebra"
5info="
6LIBRARY: normaliz.lib  Provides an interface for the use of Normaliz 2.2
7         within SINGULAR.
8AUTHORS:  Winfried Bruns, Winfried.Bruns@Uni-Osnabrueck.de
9          Christof Soeger, Christof.Soeger@Uni-Osnabrueck.de
10
11OVERVIEW:
12@texinfo
13The library normaliz.lib provides an interface for the use of Normaliz 2.2
14within SINGULAR. The exchange of data is via files, the only possibility
15offered by Normaliz in its present version. In addition to the top level
16functions that aim at objects of type ideal or ring, several other auxiliary
17functions allow the user to apply Normaliz to data of type intmat. Therefore
18SINGULAR can be used as a comfortable environment for the work with Normaliz.
19@* Please see the @code{Normaliz2.2Documentation.pdf} and @code{nmz_sing.pdf}
20(both are included in the Normaliz distribution) for a more extensive
21documentation of Normaliz.
22@*
23@*Singular and Normaliz exchange data via files. These files are automatically
24created and erased behind the scenes. As long as one wants to use only the
25ring-theoretic functions there is no need for file management.
26@*
27@*Note that the numerical invariants computed by Normaliz can be
28accessed in this \"automatic file mode\".
29@*
30@*However, if Singular is used as a frontend for Normaliz or the user
31wants to inspect data not automatically returned to Singular, then
32an explicit filename and a path can be specified for the exchange of
33data. Moreover, the library provides functions for access to these files.
34Deletion of the files is left to the user.
35@*
36@* Use of this library requires the program Normaliz to be installed.
37You can download it from
38@uref{http://www.mathematik.uni-osnabrueck.de/normaliz/}. Please make sure
39that the executables are in the search path or use setNmzExecPath
40(@ref{setNmzExecPath}).
41@end texinfo
42NOTE:    These library functions use @code{sed} to transfer the Normaliz
43output into a SINGULAR compliant format.
44
45
46KEYWORDS: integral closure; normalization
47
48PROCEDURES:
49 intclToricRing(ideal I)      computes the integral closure of the toric ring
50                              generated by the leading monomials of the
51                              elements of I in the basering
52 normalToricRing(ideal I)     computes the normalization of the toric ring
53                              generated by the leading monomials of the
54                              elements of I
55 ehrhartRing(ideal I)         computes the monomials representing the lattice
56                              points of the polytop generated leading monomials
57                              of the elements of I
58 intclMonIdeal(ideal I)       the exponent vectors of the leading monomials of
59                              the elements of I are considered as generators of
60                              a monomial ideal whose Rees algebra is computed
61
62 torusInvariants(intmat T)    computes the ring of invariants of a torus action
63 valRing(intmat V)            computes the intersection of the polynomial ring
64                              with the valuation rings of monomial valuations
65 valRingIdeal(intmat V)       computes ideals of monomial valuations
66
67 showNuminvs()                prints the numerical invariants
68 exportNuminvs()              exports the numerical invariants
69
70 setNmzOption(string s, int onoff) sets the option s to onoff
71 showNmzOptions()             prints the enabled options to the standard output
72
73 normaliz(intmat sgr,int nmz_mode) applies Normaliz
74 setNmzVersion(string nmz_version_name) sets the version of the Normaliz
75                                        executable
76 setNmzExecPath(string nmz_exec_path_name) sets the path to the Normaliz
77                                           executable
78
79 writeNmzData(intmat sgr, int n_mode) creates an input file for Normaliz
80 readNmzData(string nmz_suffix) reads the Normaliz output file with the
81                                specified suffix
82
83 setNmzFilename(string nmz_filename_name) sets the filename for the exchange
84                                          of data
85 setNmzDataPath(string nmz_data_path_name) sets the directory for the exchange
86                                           of data
87 writeNmzPaths()              writes the path names into two files
88 startNmz()                   retrieves the path names written by writeNmzPaths
89 rmNmzFiles()                 removes the files created for and by Normaliz
90
91 mons2intmat(ideal I)         returns the intmat whose rows represent the
92                              leading exponents of the elements of I
93 intmat2mons(intmat expo_vecs) returns the ideal generated by the monomials
94                               which have the rows of expo_vecs as
95                               exponent vector
96";
97
98
99// helpers
100
101static proc desInt(string intname, int value)
102// define, export and set an integer
103{
104    int exists;
105    if(defined(`intname`)){exists=1;}
106    if(!exists)
107    {
108        int `intname`=value;export(`intname`);
109    }
110    `intname`=value;
111}
112
113static proc desString(string stringname, string value)
114// define, export and set a string
115{
116    int exists;
117    if(defined(`stringname`)){exists=1;}
118    if(!exists)
119    {
120        string `stringname`=value;export(`stringname`);
121    }
122    `stringname`=value;
123}
124
125static proc queryInt(string intname)
126// if intname is defined, return(intname), else return(0)
127{
128    int exists,value;
129    if(defined(`intname`)){exists=1;}
130    if(!exists)
131    {
132        return(0);
133    }
134    return(`intname`);
135}
136
137static proc queryString(string stringname)
138// if stringname is defined, return(stringname), else return("")
139{
140    int exists;
141    string value;
142    if(defined(`stringname`)){exists=1;}
143    if(!exists)
144    {
145        return("");
146    }
147    return(`stringname`);
148}
149
150static proc fileExists(string f)
151{
152    return(status (f,"exists")=="yes");
153}
154
155static proc appendSlash(string s)
156// if nonempty and / is not the terminating char
157{
158    if(size(s)>0)
159    {
160        if(s[size(s)]!="/")
161        {
162            s=s+"/";
163            return(s);
164        }
165    }
166    return(s);
167}
168
169// filenames and paths
170
171proc setNmzExecPath(string nmz_exec_path_name)
172"USAGE:   setNmzExecPath(string s);   @code{s} path to the Normaliz executable
173CREATE:   @code{Normaliz::nmz_exec_path} to save the given path @code{s}
174NOTE:     It is not necessary to use this function if the Normaliz executable
175          is in the search path of the system.
176SEE ALSO: setNmzVersion
177EXAMPLE:  example setNmzExecPath; shows an example"
178{
179    desString("nmz_exec_path",nmz_exec_path_name);
180    nmz_exec_path=appendSlash(nmz_exec_path);
181}
182example
183{ "EXAMPLE:";echo = 2;
184  setNmzExecPath("../Normaliz/");
185}
186
187proc setNmzVersion(string nmz_version_name)
188"USAGE:   setNmzVersion(string s);  @code{s} version of the Normaliz executable
189CREATE:   @code{Normaliz::nmz_version} to save the given version @code{s}
190NOTE:     The version coincides with the filename of the Normaliz executable.
191          Possible arguments are:
192          @* @code{norm32} for 32bit integer precision
193          @* @code{norm64} for 64bit integer precision (default)
194          @* @code{normbig} for arbitrary precision
195SEE ALSO: setNmzExecPath
196EXAMPLE:  example setNmzVersion; shows an example
197"
198{
199    desString("nmz_version",nmz_version_name);
200}
201example
202{ "EXAMPLE:";echo = 2;
203  setNmzVersion("normbig");
204}
205
206
207proc setNmzFilename(string nmz_filename_name)
208"USAGE:   setNmzFilename(string s);
209CREATE:   @code{Normaliz::nmz_filename} to save the given filename @code{s}
210NOTE:     The function sets the filename for the exchange of data. Unless a
211          path is set by setNmzDataPath, files will be created in the current
212          directory.
213          @* If a non-empty filename is set, the files created for and by
214             Normaliz are kept. This is mandatory for the data access functions
215             (see @ref{writeNmzData} and @ref{readNmzData}).
216          @* Resetting the filename by setNmzFilename(\"\") forces the library
217             to return to deletion of temporary files, but the files created
218             while the filename had been set will not be erased.
219SEE ALSO: writeNmzData, readNmzData, setNmzDataPath, rmNmzFiles
220EXAMPLE:  example setNmzFilename; shows an example"
221{
222    desString("nmz_filename",nmz_filename_name);
223    if(nmz_filename_name!="")
224    {
225        desInt("nmz_files_keep_switch",1);
226    }
227    else
228    {
229        desInt("nmz_files_keep_switch",0);
230    }
231}
232example
233{ "EXAMPLE:";echo = 2;
234  setNmzDataPath("examples/");
235  setNmzFilename("example1");
236  //now the files for the exchange with Normaliz are examples/example1.SUFFIX
237}
238
239proc setNmzDataPath(string nmz_data_path_name)
240"USAGE:   setNmzDataPath(string s);
241CREATE:   @code{Normaliz::nmz_data_path} to save the given path @code{s}
242NOTE:     The function sets the path for the exchange of data. By default the
243          files will be created in the current directory.
244          @* It seems that Singular cannot use filenames starting with @code{~}
245             or @code{$HOME} in its input/output functions.
246          @* You must also avoid path names starting with @code{/} if you work
247             under Cygwin, since Singular and Normaliz interpret them in
248             different ways.
249SEE ALSO: writeNmzData, readNmzData, rmNmzFiles, setNmzFilename
250EXAMPLE:  example setNmzDataPath; shows an example"
251{
252    desString("nmz_data_path",nmz_data_path_name);
253    nmz_data_path=appendSlash(nmz_data_path);
254}example
255{ "EXAMPLE:";echo = 2;
256  setNmzDataPath("examples/");
257  setNmzFilename("example1");
258  //now the files for the exchange with Normalize are examples/example1.SUFFIX
259}
260
261proc writeNmzPaths();
262"USAGE:   writeNmzPaths();
263CREATE:   the file nmz_sing_exec.path where the path to the Normaliz executable
264          is saved
265          @* the file nmz_sing_data.path where the directory for the exchange
266          of data is saved
267NOTE:     Both files are saved in the current directory. If one of the names
268          has not been defined, the corresponding file is created, but
269          contains nothing.
270SEE ALSO: setNmzDataPath, setNmzExecPath, startNmz
271EXAMPLE:  example writeNmzPaths; shows an example
272"{
273    link outf=":w nmz_sing_exec.path";
274    write(outf, queryString("nmz_exec_path"));
275    close(outf);
276
277    outf=":w nmz_sing_data.path";
278    write(outf, queryString("nmz_data_path"));
279    close(outf);
280}
281example
282{ "EXAMPLE:";echo = 2;
283  setNmzExecPath("../Normaliz/");
284  writeNmzPaths();
285  int dummy=system("sh","cat nmz_sing_exec.path");
286  dummy=system("sh","cat nmz_sing_data.path");
287}
288
289proc startNmz()
290"USAGE:   startNmz();
291PURPOSE:  This function reads the files written by @code{writeNmzPaths()},
292          retrieves the path names, and types them on the standard output
293          (as far as they have been set). Thus, once the path names have been
294          stored, a Normaliz session can simply be opened by this function.
295SEE ALSO: setNmzDataPath, setNmzExecPath, writeNmzPaths
296EXAMPLE:  example startNmz; shows an example
297"
298{
299    link inf=":r nmz_sing_exec.path";
300    string s=read(inf);
301    int i,p;
302    p=findWord("/",s,1);
303    if(p!=-1)
304    {
305        for(i=size(s);i>=1;i--)
306        {
307            if(s[i]=="/")
308            {
309                s=s[1..i];
310                break;
311            }
312        }
313        desString("nmz_exec_path",s);
314        "nmz_exec_path is",nmz_exec_path;
315    }
316    else
317    {
318        "nmz_exec_path not set";
319    }
320
321    inf=":r nmz_sing_data.path";
322    s=read(inf);
323    p=findWord("/",s,1);
324    if(p!=-1)
325    {
326        for(i=size(s);i>=1;i--)
327        {
328            if(s[i]=="/")
329            {
330                s=s[1..i];
331                break;
332            }
333        }
334        desString("nmz_data_path",s);
335        "nmz_data_path is",nmz_data_path;
336    }
337    else
338    {
339        "nmz_data_path not set";
340    }
341}
342example
343{ "EXAMPLE:"; echo=2;
344  startNmz();
345}
346
347static proc getNmzFile()
348{
349    if(queryInt("nmz_files_keep_switch"))
350    {
351        return(queryString("nmz_data_path")+queryString("nmz_filename"));
352    }
353    else
354    {
355        return(queryString("nmz_filename"));
356    }
357}
358
359static proc makeTempNmzDataPath()
360{
361    string testdir, testdir1;
362    int i,dummy;
363
364    testdir1="/tmp/nmz_sing_"+string(system("pid"));
365    testdir=testdir1;
366    while(fileExists(testdir))
367    {
368        i++;
369        testdir=testdir1+string(i);
370    }
371    dummy=system("sh","mkdir "+ testdir);
372    desString("nmz_filename",testdir+"/nmz"); //files are nmz+suffix in testdir
373}
374
375static proc eraseTempNmzDataPath();
376{
377    int dummy;
378
379    string tmpdir=getNmzFile();
380    tmpdir=tmpdir[1..size(tmpdir)-4]; // remove "/nmz"
381    dummy=system("sh","rm -r "+tmpdir);
382    setNmzFilename("");
383}
384
385static proc setNmzExec()
386{
387    if(queryString("nmz_exec")=="")
388    {
389        return(queryString("nmz_exec_path")+"norm64");
390    }
391    return(queryString("nmz_exec_path")+queryString("nmz_exec"));
392}
393
394proc rmNmzFiles()
395"USAGE:  rmNmzFiles();
396PURPOSE: This function removes the files created for and by Normaliz, using
397         the last filename specified.
398         It needs an explicit filename set (see @ref{setNmzFilename}).
399SEE ALSO: writeNmzData, readNmzData, setNmzFilename, setNmzDataPath
400EXAMPLE:  example rmNmzFiles; shows an example
401"{
402
403    if(!queryInt("nmz_files_keep_switch"))
404    {
405        ERROR("rmNmzFiles: no filename specified");
406    }
407
408    list suffixes="in","gen","out","sup","typ","egn","esp","inv","tri","ht1",
409                  "ext";
410    int i,dummy;
411    string f;
412
413    for(i=1;i<=size(suffixes);i++)
414    {
415        f=getNmzFile()+"."+suffixes[i];
416        dummy=system("sh","rm "+f+ "&> /dev/null");
417    }
418}
419example
420{ "EXAMPLE:"; echo=2;
421  setNmzFilename("VeryInteresting");
422  rmNmzFiles();
423}
424
425
426
427// parsing normaliz output
428
429static proc digit(string s)
430{
431    if(s==" ") // skip blanks quickly
432    {
433        return(0);
434    }
435
436    if((s[1]>="0" && s[1]<="9")||s[1]=="-")
437    {
438        return(1);
439    }
440    return(0);
441}
442
443static proc nextWord(string s, int p)
444{
445    int j,sw,ew;
446
447    for(;p<=size(s);p++) // must start with a letter
448    {
449
450        if((s[p]>="a" && s[p]<="z")||
451             (s[p]>="A" && s[p]<="Z"))
452        {
453            sw=p; break;
454        }
455    }
456    if(p>size(s))
457    {
458        return(-1,-1); // no word found
459    }
460
461    for(;p<=size(s);p++) // now numerals and -_ allowed
462    {
463        if(!((s[p]>="a" && s[p]<="z")||
464             (s[p]>="A" && s[p]<="Z")||
465             (s[p]>="0" && s[p]<="9")||
466              s[p]=="_"||s[p]=="-"))
467        {
468            break;
469        }
470    }
471    return(sw,p);
472}
473
474static proc getInt(string s, int p)
475{
476
477    string nst;
478    int i,j,en,sn;
479
480    for(;p<=size(s);p++)
481    {
482
483        if(digit(s[p]))
484        {
485            sn=p; break;
486        }
487    }
488    if(not(sn))
489    {
490        return(0,-1); // -1 indicates: no number found
491    }
492    p++;
493    for(;p<=size(s);p++)
494    {
495        if(!digit(s[p]))
496        {
497            en=p-1; break;
498        }
499    }
500    if(p>size(s))
501    {
502        en=size(s);
503    }
504    nst="i="+s[sn,en-sn+1];
505    execute(nst);
506    return(i,p);
507}
508
509static proc getRational(string s, int p)
510{
511
512    string nst;
513    int i,j,en,sn;
514
515    for(;p<=size(s);p++)
516    {
517        if(digit(s[p]))
518        {
519            sn=p; break;
520        }
521    }
522    if(not(sn))
523    {
524        return(0,-1); // -1 indicates: no number found
525    }
526    p++;
527    int slash_at;
528    for(;p<=size(s);p++)
529    {
530        if(s[p]=="/")
531        {
532            slash_at=p;
533            p++;
534            continue;
535        }
536        if(!digit(s[p]))
537        {
538            en=p-1; break;
539        }
540    }
541    if(p>size(s))
542    {
543        en=size(s);
544    }
545    if(slash_at)
546    {
547        nst="i="+s[sn,slash_at-sn];
548        execute(nst);
549        nst="j="+s[slash_at+1,en-slash_at];
550        execute(nst);
551        return(i,p,j);
552    }
553    nst="i="+s[sn,en-sn+1];
554    execute(nst);
555    return(i,p);
556}
557
558static proc findWord(string s, string t, int p)
559{
560    for(;p<=size(t)-size(s)+1;p++)
561    {
562        if(t[p]==s[1])
563        {
564            if(t[p,size(s)]==s)
565            {
566                 return(p+size(s));
567            }
568        }
569    }
570    return(-1);
571}
572
573static proc skipEqualsign(string s,int p)
574{
575    for(;p<=size(s);p++)
576    {
577        if(s[p]=="=")
578        {
579            break;
580        }
581    }
582    return(p+1);
583}
584
585
586// input and output to/from normaliz
587
588static proc doWriteNmzData(intmat sgr, int num_cols, n_mode)
589{
590    string s;
591    int j;
592    link outf=":w "+ getNmzFile() +".in";  // also sets the filename
593    write(outf,nrows(sgr));
594    write(outf,num_cols);
595
596    for(int i=1;i<=nrows(sgr);i++)
597    {
598        s="";
599        for(j=1;j<=num_cols;j++)
600        {
601             s=s+string(sgr[i,j])+" ";
602        }
603        write(outf,s);
604    }
605    write(outf,n_mode);
606    close(outf);
607}
608
609proc writeNmzData(intmat sgr, int n_mode)
610"USAGE:   writeNmzData(intmat M, int mode);
611CREATE:   Creates an input file for Normaliz from the matrix M. The second
612          parameter sets the mode. How the matrix is interpreted depends on the
613          mode. See the Normaliz documentation for more information.
614NOTE:     Needs an explicit filename set. The filename is created from the
615          current filename and the suffix given to the function.
616   @*     Note that all functions in normaliz.lib write and read their data
617          automatically to and from the hard disk so that writeNmzData will
618          hardly ever be used explicitly.
619SEE ALSO: readNmzData, rmNmzFiles, setNmzFilename, setNmzDataPath
620EXAMPLE:  example writeNmzData; shows an example"
621{
622    if(queryString("nmz_filename")=="")
623    {
624        ERROR("writeNmzData: no filename specified");
625    }
626    doWriteNmzData(sgr, ncols(sgr), n_mode);
627}
628example
629{ "EXAMPLE:"; echo=2;
630  setNmzFilename("VeryInteresting");
631  intmat sgr[3][3]=1,2,3,4,5,6,7,8,10;
632  writeNmzData(sgr,1);
633  int dummy=system("sh","cat VeryInteresting.in");
634}
635
636
637proc readNmzData(string nmz_suffix)
638"USAGE:  readNmzData(string suffix);
639RETURN:  Reads an output file of Normaliz containing an integer matrix and
640         returns it as an intmat. For example, this function is useful if one
641         wants to inspect the support hyperplanes. The filename is created
642         from the current  filename and the suffix given to the function.
643NOTE:    Needs an explicit filename set by setNmzFilename.
644   @*    Note that all functions in normaliz.lib write and read their data
645         automatically so that readNmzData will usually not be used explicitly.
646   @*    This function uses the command @code{sed} to transfer the normaliz
647         output into a singular conform format.
648SEE ALSO: writeNmzData, rmNmzFiles, setNmzFilename, setNmzDataPath
649EXAMPLE:  example readNmzData; shows an example"
650{
651    if(queryString("nmz_filename")=="")
652    {
653        ERROR("readNmzData: no filename specified");
654    }
655
656    string s;
657    int n_rows,n_cols;            //number of rows/columns
658    int p, q;                     //positions
659    int returnvalue;
660
661    string filename = getNmzFile() + "."+ nmz_suffix;
662    string tmpfilename = filename+".tmp";
663//"// ** readNmzData: initialisiert";    //TODO debugoutput wieder rausnehmen
664    returnvalue = system("sh","sed 's/ /,/g' < "+filename+" > "+tmpfilename);
665//"// ** readNmzData: sed ausgefuehrt";
666    link in_f=":r "+ tmpfilename;
667
668    s=read(in_f);
669    close(in_f);
670    returnvalue = system("sh","rm "+tmpfilename);
671//"// ** readNmzData: datei eingelesen";
672    p=1; q=size(s);
673    (n_rows,p)=getInt(s,p);
674    (n_cols,p)=getInt(s,p);
675    //intmat nmz_gen[n_rows][n_cols];
676    while(s[q]!=",")
677    {
678      q--;
679    }
680    //string c = "nmz_gen=" + s[p,q-p] + ";";
681    string c = "intmat nmz_gen["+ string(n_rows) +"]["+ string(n_cols) +"]="
682             + s[p,q-p] + ";";
683//"// ** readNmzData: string gebastelt";
684    execute(c);
685//"// ** readNmzData: string ausgefuehrt";
686    return(nmz_gen);
687}
688example
689{ "EXAMPLE:"; echo=2;
690  setNmzFilename("VeryInteresting");
691  intmat sgr[3][3]=1,2,3,4,5,6,7,8,10;
692  intmat sgrnormal=normaliz(sgr,0);
693  readNmzData("sup");
694  readNmzData("typ");
695}
696
697
698// running normaliz (with options)
699
700// component 1 is name of option
701// 2 is default value
702// 3 is command line option to be passed to Normaliz
703// 4 indictes whether file "gen" is generated
704// value 2 of 4 indicates "no influence"
705
706static proc defNmzOptions()
707{
708    if(!defined(nmz_options)) // can be defined only once
709    {
710        list nmz_options=
711        list("hvect",0,"-p",0),
712        list("triang",0,"-v",0),
713        list("supp",0,"-s",0),
714        list("normal",0,"-n",1),
715        list("hilb",0,"-h",1),
716        list("dual",0,"-d",1),
717        list("control",0,"-c",2),
718        list("allf",0,"-a",2),
719        list("ignore",1,"-i",2),
720        list("errorcheck",0,"-e",2);
721        export(nmz_options);
722    }
723}
724
725proc setNmzOption(string s, int onoff)
726"USAGE:   setNmzOption(string s, int onoff);
727PURPOSE:  If @code{onoff=1} the option @code{s} is activated, and
728          if @code{onoff=0} it is deactivated.
729The Normaliz options are accessible via the following names:
730@* @code{-s:  supp}
731@* @code{-v:  triang}
732@* @code{-p:  hvect}
733@* @code{-n:  normal}
734@* @code{-h:  hilb}
735@* @code{-d:  dual}
736@* @code{-a:  allf}
737@* @code{-c:  control}
738@* @code{-i:  ignore}
739@* @code{-e:  errorcheck}
740SEE ALSO: showNmzOptions
741EXAMPLE:  example setNmzOption; shows an example
742"
743{
744    defNmzOptions();
745    for(int i=1;i<=size(nmz_options);i++)
746    {
747        if(s==nmz_options[i][1])
748        {
749            nmz_options[i][2]=onoff;
750            return(1);
751        }
752    }
753    "Invalid option ", s;
754    return(0);
755}
756example
757{ "EXAMPLE:"; echo=2;
758  setNmzOption("hilb",1);
759  showNmzOptions();
760}
761
762static proc collectNmzOptions()
763{
764    defNmzOptions();
765    string run_options=" -f ";
766    desInt("GenGen",1); // indicates whether "gen" is generated
767    for(int i=1;i<=size(nmz_options);i++)
768    {
769        if(nmz_options[i][2])
770        {
771            run_options=run_options+nmz_options[i][3]+" ";
772            if(nmz_options[i][4]!=2)
773            {
774                GenGen=nmz_options[i][4];
775            }
776        }
777    }
778    return(run_options+" ");
779}
780
781proc showNmzOptions()
782"USAGE:   showNmzOptions();
783RETURN:   Returns the string of activated options.
784NOTE:     This string is used as parameter when calling Normaliz.
785SEE ALSO: setNmzOption
786EXAMPLE:  example showNmzOption; shows an example
787"
788{
789    return(collectNmzOptions());
790}
791example
792{ "EXAMPLE:"; echo=2;
793  setNmzOption("hilb",1);
794  showNmzOptions();
795}
796
797
798static proc runNormaliz(intmat sgr,int num_cols, nmz_mode)
799{
800    if(!queryInt("nmz_files_keep_switch"))
801    {
802        makeTempNmzDataPath();
803    }
804
805    doWriteNmzData(sgr,num_cols,nmz_mode);
806
807    if(queryInt("nmz_files_keep_switch"))
808    {
809       int dummy=system("sh",setNmzExec()+ collectNmzOptions() + getNmzFile());
810    }
811    else
812    {
813        string gotodir="/tmp";
814        string fname=getNmzFile();
815        fname=fname[6..size(fname)];
816        string exec="cd "+gotodir+" ; ";
817        exec=exec+setNmzExec()+ collectNmzOptions()+" ";
818        exec=exec+fname+" ;";
819        int dummy=system("sh",exec);
820    }
821
822    if(!GenGen) // return input matrix if "gen" has not been generated
823    {
824        if(!queryInt("nmz_files_keep_switch"))
825        {
826            eraseTempNmzDataPath();
827        }
828        return(sgr);
829    }
830    intmat Gen=readNmzData("gen");
831
832    if(!defined(Num_Invs))
833    {
834        list Num_Invs;
835        export Num_Invs;
836    }
837    Num_Invs=getNuminvs();
838
839    if(!queryInt("nmz_files_keep_switch"))
840    {
841        eraseTempNmzDataPath();
842    }
843
844    return(Gen);
845
846}
847
848proc normaliz(intmat sgr,int nmz_mode)
849"USAGE:   normaliz(intmat sgr,int nmz_mode);
850RETURN:   The function applies Normaliz to the parameter sgr in the mode set
851          by nmz_mode. The function returns the intmat defined by the file
852          with suffix gen.
853NOTE:     You will find procedures for many applications of Normaliz in this
854          library, so the explicit call of this procedure may not be necessary.
855SEE ALSO: intclToricRing, normalToricRing, ehrhartRing, intclMonIdeal,
856          torusInvariants, valRing, valRingIdeal
857EXAMPLE:  example normaliz; shows an example
858"
859{
860    return(runNormaliz(sgr,ncols(sgr),nmz_mode));
861}
862example
863{ "EXAMPLE:"; echo=2;
864  ring R=0,(x,y,z),dp;
865  intmat M[3][2]=3,1,
866                 3,2,
867                 1,3;
868  normaliz(M,1);
869}
870
871
872// retrieving normaliz numerical invariants
873
874static proc getNuminvs()
875{
876    string s;
877    list num_invs;
878    int p,sw,v_length,i,dummy_int;
879    intvec dummy_vec;
880    string type_inv,name_inv,dummy_bool;
881
882    link in_f=":r "+ getNmzFile() + "."+"inv";
883    s=read(in_f);
884
885    p=1;
886    while(p<size(s))
887    {
888        (sw,p)=nextWord(s,p);
889        if(sw==-1)
890        {
891            break;
892        }
893        type_inv=s[sw..p-1];
894        if(type_inv=="vector")
895        {
896            (v_length,p)=getInt(s,p);
897            (sw,p)=nextWord(s,p);
898            name_inv=s[sw..p-1];
899            if(name_inv=="h-vector")
900            {
901                name_inv="h_vector";
902            }
903            if(name_inv!="hilbert_polynomial")
904            {
905                for(i=1;i<=v_length;i++)
906                {
907                    if(i==1)
908                    {
909                        (dummy_int,p)=getInt(s,p);
910                        dummy_vec=dummy_int;
911                    }
912                    else
913                    {
914                        (dummy_int,p)=getInt(s,p);
915                        dummy_vec=dummy_vec,dummy_int;
916                    }
917                }
918                num_invs=num_invs+list(list(name_inv,dummy_vec,"intvec"));
919            }
920            else
921            {
922                p=skipEqualsign(s,p);
923            }
924        }
925        if(type_inv=="integer")
926        {
927            (sw,p)=nextWord(s,p);
928            name_inv=s[sw..p-1];
929            (dummy_int,p)=getInt(s,p);
930            num_invs=num_invs+list(list(name_inv,dummy_int,"int"));
931        }
932        if(type_inv=="boolean")
933        {
934            (sw,p)=nextWord(s,p);
935            name_inv=s[sw..p-1];
936            p=skipEqualsign(s,p);
937            (sw,p)=nextWord(s,p);
938            dummy_bool=s[sw..p-1];
939            dummy_int=0;
940            if(dummy_bool=="true")
941            {
942                dummy_int=1;
943            }
944            num_invs=num_invs+list(list(name_inv,dummy_int,"int"));
945        }
946    }
947    return(num_invs);
948}
949
950proc showNuminvs()
951"USAGE:   showNuminvs();
952PURPOSE:  prints the numerical invariants
953SEE ALSO: exportNuminvs
954EXAMPLE:  example showNuminvs(); shows an example
955"
956{
957    list dummy;
958    int i;
959    for(i=1;i<=size(Num_Invs);i++)
960    {
961        dummy=Num_Invs[i];
962        dummy[1],":", dummy[2];
963    }
964}
965example
966{ "EXAMPLE:"; echo=2;
967  ring R=0,(x,y,z,t),dp;
968  ideal I=x^2,y^2,z^3;
969  list l=intclMonIdeal(I);
970  showNuminvs();
971}
972
973
974proc exportNuminvs()
975"USAGE:   exportNuminvs();
976CREATE:   Creates top-level variables which contain the numerical invariants.
977          Depending on the options of normaliz different invariants are
978          calculated. Use showNuminvs (@ref{showNuminvs}) to see which
979          invariants are available.
980SEE ALSO: showNuminvs
981EXAMPLE:  example exportNuminvs; shows an example
982"
983{
984    list dummy;
985    int i;
986    string s;
987    for(i=1;i<=size(Num_Invs);i++)
988    {
989        dummy=Num_Invs[i];
990        s=dummy[3]+" nmz_" + dummy[1] + "=dummy[2]; exportto(Top," + "nmz_" + dummy[1] + ");";
991        execute(s);
992    }
993}
994example
995{ "EXAMPLE:"; echo=2;
996  ring R=0,(x,y,z,t),dp;
997  ideal I=x^2,y^2,z^3;
998  list l=intclMonIdeal(I);
999  exportNuminvs();
1000  // now the following variables are set:
1001  nmz_hilbert_basis_elements;
1002  nmz_number_extreme_rays;
1003  nmz_rank;
1004  nmz_index;
1005  nmz_number_support_hyperplanes;
1006  nmz_homogeneous;
1007  nmz_primary;
1008  nmz_ideal_multiplicity;
1009}
1010
1011
1012// intmats to/from monomials
1013
1014proc mons2intmat(ideal I)
1015"USAGE:   mons2intmat(ideal I);
1016RETURN:   Returns the intmat whose rows represent the leading exponents of the
1017          (non-zero) elements of I. The length of each row is nvars(basering).
1018SEE ALSO: intmat2mons
1019EXAMPLE:  example mons2intmat; shows an example"
1020{
1021    int i,j,k;
1022    intmat expo_vecs[size(I)][nvars(basering)];
1023    intvec expo_v;
1024
1025    int last_comp;
1026    k=0;
1027    for(i=1;i<=ncols(I);i++)
1028    {
1029        if(I[i]!=0)
1030        {
1031            k++;
1032            expo_v=leadexp(I[i]);
1033            for(j=1;j<=nvars(basering);j++)
1034            {
1035                expo_vecs[k,j]=expo_v[j];
1036            }
1037        }
1038    }
1039    return(expo_vecs);
1040}
1041example
1042{ "EXAMPLE:"; echo=2;
1043  ring R=0,(x,y,z),dp;
1044  ideal I=x2,y2,x2yz3;
1045  mons2intmat(I);
1046}
1047
1048proc intmat2mons(intmat expo_vecs)
1049"USAGE:   intmat2mons(intmat M);
1050RETURN:   an ideal generated by the monomials which correspond to the exponent
1051          vectors given by the rows of @code{M}
1052NOTE:     The number of variables in the basering @code{nvars(basering)} has to
1053          be at least the number of columns @code{ncols(M)}, otherwise the
1054          function exits with an error.
1055          is thrown (see @ref{ERROR}).
1056SEE ALSO: mons2intmat
1057EXAMPLE:  example intmat2mons; shows an example
1058"
1059{
1060    int i,j;
1061    poly m;
1062    ideal mons;
1063
1064    if(nvars(basering)<ncols(expo_vecs))
1065    {
1066        ERROR("intmat2mons: not enough variables in ring");
1067    }
1068
1069    for(i=1;i<=nrows(expo_vecs);i++)
1070    {
1071        m=1;
1072        for(j=1;j<=ncols(expo_vecs);j++)
1073        {
1074            m=m*var(j)^expo_vecs[i,j];
1075        }
1076        mons=mons,m;
1077    }
1078     mons=simplify(mons,2);    // get rid of starting 0
1079     return(mons);
1080}
1081example
1082{ "EXAMPLE:"; echo=2;
1083  ring R=0,(x,y,z),dp;
1084  intmat expo_vecs[3][3] =
1085  2,0,0,
1086  0,2,0,
1087  2,1,3;
1088  intmat2mons(expo_vecs);
1089}
1090
1091static proc intmat2monsSel(intmat expo_vecs, int d)
1092{
1093    int i,j;
1094    poly m;
1095    ideal mons;
1096
1097    if(nvars(basering)<ncols(expo_vecs)-1)
1098    {
1099        ERROR("intmat2monsSel: not enough variables in ring");
1100    }
1101
1102    for(i=1;i<=nrows(expo_vecs);i++)
1103    {
1104        if(expo_vecs[i,ncols(expo_vecs)]==d)
1105        {
1106
1107            m=1;
1108            for(j=1;j<=ncols(expo_vecs)-1;j++)
1109            {
1110                m=m*var(j)^expo_vecs[i,j];
1111            }
1112            mons=mons,m;
1113        }
1114    }
1115     mons=simplify(mons,2);    // get rid of starting 0
1116     return(mons);
1117}
1118
1119
1120
1121// integral closure of rings and ideals
1122
1123static proc runIntclToricRing(ideal I, int nmz_mode)
1124{
1125    intmat expo_vecs=mons2intmat(I);
1126
1127    string dummy=collectNmzOptions(); // only to set GenGen
1128
1129/*    if(!GenGen) // return I
1130    {
1131        runNormaliz(expo_vecs,ncols(expo_vecs),nmz_mode);
1132        return(I);
1133    }
1134*/    return( intmat2mons( runNormaliz(expo_vecs,ncols(expo_vecs),nmz_mode) ) );
1135}
1136
1137proc intclToricRing(ideal I)
1138"USAGE:   intclToricRing(ideal I);
1139RETURN:   The toric ring S is the subalgebra of the basering generated by the
1140          leading monomials of the elements of I. The function computes the
1141          integral closure T of S in the basering and returns an ideal listing
1142          the algebra generators of T over the coefficient field.
1143@*        The function returns the input ideal I if one of the options
1144          @code{supp}, @code{triang}, or @code{hvect} has been activated.
1145          However, in this case some numerical invariants are computed, and
1146          some other data may be contained in files that you can read into
1147          Singular (see @ref{showNuminvs}, @ref{exportNuminvs}).
1148NOTE:     A mathematical remark: the toric ring depends on the list of
1149          monomials given, and not only on the ideal they generate!
1150SEE ALSO:  normalToricRing, ehrhartRing, intclMonIdeal
1151EXAMPLE:   example intclToricRing; shows an example
1152"
1153{
1154    return(runIntclToricRing(I,0));
1155}
1156example
1157{ "EXAMPLE:"; echo=2;
1158  ring R=37,(x,y,t),dp;
1159  ideal I=x3,x2y,y3;
1160  intclToricRing(I);
1161}
1162
1163proc normalToricRing(ideal I)
1164"USAGE:   normalToricRing(ideal I);
1165RETURN:   The toric ring S is the subalgebra of the basering generated by the
1166          leading monomials of the elements of I. The function computes the
1167          normalisation T of S and returns an ideal listing the algebra
1168          generators of T over the coefficient field.
1169@*        The function returns the input ideal I if one of the options
1170          @code{supp}, @code{triang}, or @code{hvect} has been activated.
1171          However, in this case some numerical invariants are computed, and
1172          some other data may be contained in files that you can read into
1173          Singular (see @ref{showNuminvs}, @ref{exportNuminvs}).
1174NOTE:     A mathematical remark: the toric ring depends on the list of
1175          monomials given, and not only on the ideal they generate!
1176SEE ALSO: intclToricRing, ehrhartRing, intclMonIdeal
1177EXAMPLE:  example normalToricRing; shows an example
1178"
1179{
1180    return(runIntclToricRing(I,1));
1181}
1182example
1183{ "EXAMPLE:"; echo=2;
1184  ring R=37,(x,y,t),dp;
1185  ideal I=x3,x2y,y3;
1186  normalToricRing(I);
1187}
1188
1189static proc runIntclMonIdeal(ideal I, int nmz_mode)
1190{
1191    intmat expo_vecs=mons2intmat(I);
1192    int i,last_comp;
1193
1194    // we test if there is room for the Rees algebra
1195
1196    for(i=1;i<=nrows(expo_vecs);i++)
1197    {
1198        if(expo_vecs[i,ncols(expo_vecs)]!=0)
1199        {
1200            last_comp=1;  break; // no
1201        }
1202    }
1203
1204    string dummy=collectNmzOptions(); // only to set GenGen
1205
1206/*    if(!GenGen) // return I
1207    {
1208        runNormaliz(expo_vecs,ncols(expo_vecs),nmz_mode);
1209        return(list(I));
1210    }
1211*/
1212    intmat nmz_data=runNormaliz(expo_vecs,ncols(expo_vecs)-1+last_comp,
1213                                                                  nmz_mode);
1214
1215    if(last_comp)
1216    {
1217        ideal I1=intmat2monsSel(nmz_data,1);
1218        return(list(I1));
1219    }
1220    else
1221    {
1222        ideal I1=intmat2monsSel(nmz_data,1);
1223        ideal I2=intmat2mons(nmz_data);
1224        return(list(I1,I2));
1225    }
1226}
1227
1228proc ehrhartRing(ideal I)
1229"USAGE:    ehrhartRing(ideal I);
1230RETURN:    The exponent vectors of the leading monomials of the elements of I
1231           are considered as vertices of a lattice polytope P.
1232           The Ehrhart ring of a (lattice) polytope P is the monoid algebra
1233           defined by the monoid of lattice points in the cone over the
1234           polytope P; see Bruns and Gubeladze, Polytopes, Rings, and K-theory,
1235           Springer 2009, pp. 228, 229.
1236           The function returns a list of ideals:
1237@*         (i) If the last ring variable is not used by the monomials, it is
1238               treated as the auxiliary variable of the Ehrhart ring. The
1239               function returns two ideals, the first containing the monomials
1240               representing the lattice points of the polytope, the second
1241               containing the algebra generators of the Ehrhart ring over the
1242                    coefficient field.
1243@*         (ii) If the last ring variable is used by the monomials, the list
1244                returned contains only one ideal, namely the monomials
1245                representing the lattice points of the polytope.
1246@*
1247@*        The function returns the a list containing the input ideal I if one
1248          of the options @code{supp}, @code{triang}, or @code{hvect} has been
1249          activated.
1250          However, in this case some numerical invariants are computed, and
1251          some other data may be contained in files that you can read into
1252          Singular (see @ref{showNuminvs}, @ref{exportNuminvs}).
1253NOTE:      A mathematical remark: the Ehrhart ring depends on the list of
1254           monomials given, and not only on the ideal they generate!
1255SEE ALSO: intclToricRing, normalToricRing, intclMonIdeal
1256EXAMPLE:  example ehrhartRing; shows an example
1257"
1258{
1259    return(runIntclMonIdeal(I,2));
1260}
1261example
1262{ "EXAMPLE:"; echo=2;
1263  ring R=37,(x,y,t),dp;
1264  ideal J=x3,x2y,y3,xy2t7;
1265  ehrhartRing(J);
1266}
1267
1268proc intclMonIdeal(ideal I)
1269"USAGE:   intclMonIdeal(ideal I);
1270RETURN:   The exponent vectors of the leading monomials of the elements of I
1271          are considered as generators of a monomial ideal for which the
1272          normalization of its Rees algebra is computed. For a Definiton of the
1273          Rees algebra (or Rees ring) see Bruns and Herzog, Cohen-Macaulay
1274          rings, Cambridge University Press 1998, p. 182.
1275          The function returns a list of ideals:
1276@* (i) If the last ring variable is not used by the monomials, it is treated
1277       as the auxiliary variable of the Rees algebra. The function returns two
1278       ideals, the first containing the monomials generating the integral
1279       closure of the monomial ideal, the second containing the algebra
1280         generators of the normalization of the Rees algebra.
1281@* (ii) If the last ring variable is used by the monomials, the list returned
1282        contains only one ideal, namely the monomials generating the integral
1283        closure of the ideal.
1284@*        The function returns the a list containing the input ideal I if one
1285          of the options @code{supp}, @code{triang}, or @code{hvect} has been
1286          activated.
1287          However, in this case some numerical invariants are computed, and
1288          some other data may be contained in files that you can read into
1289          Singular (see @ref{showNuminvs}, @ref{exportNuminvs}).
1290NOTE:     A mathematical remark: the Rees algebra depends on the list of
1291          monomials given, and not only on the ideal they generate!
1292SEE ALSO: intclToricRing, normalToricRing, ehrhartRing
1293EXAMPLE:  example intclMonIdeal; shows an example
1294"
1295{
1296    return(runIntclMonIdeal(I,3));
1297}
1298example
1299{ "EXAMPLE"; echo=2;
1300    ring R=0,(x,y,z,t),dp;
1301    ideal I=x^2,y^2,z^3;
1302    list l=intclMonIdeal(I);
1303    l[1]; // integral closure of I
1304    l[2];  // monomials generating the integral closure of the Rees algebra
1305}
1306
1307// torus invariants and valuation rings and ideals
1308
1309proc torusInvariants(intmat T)
1310"USAGE:   torusInvariants(intmat A);
1311RETURN:   @texinfo
1312Returns an ideal representing the list of monomials generating the ring of
1313invariants as an algebra over the coefficient field.
1314@tex
1315$R^T$.
1316@end tex
1317@*        The function returns the ideal given by the input matrix T if one of
1318          the options @code{supp}, @code{triang}, or @code{hvect} has been
1319          activated.
1320          However, in this case some numerical invariants are computed, and
1321          some other data may be contained in files that you can read into
1322          Singular (see @ref{showNuminvs}, @ref{exportNuminvs}).
1323@end texinfo
1324BACKGROUND: @texinfo
1325@tex
1326 Let $T = (K^*)^r$ be the $r$-dimensional torus acting on the polynomial ring
1327 $R = K[X_1 ,\ldots,X_n]$ diagonally. Such an action can be described as
1328 follows: there are integers $a_{i,j}$, $i=1,\ldots,r$, $j=1,\ldots,n$, such
1329 that $(\lambda_1,\ldots,\lambda_r)\in T$ acts by the substitution
1330$$ X_j \mapsto \lambda_1^{a_{1,j}} \cdots \lambda_r^{a_{r,j}}X_j,
1331   \quad j=1,\ldots,n.$$
1332In order to compute the ring of invariants $R^T$ one must specify the matrix
1333$A=(a_{i,j})$.
1334@end tex
1335@end texinfo
1336NOTE:@texinfo
1337@tex
1338It is of course possible that $R^T=K$. At present, Normaliz cannot deal with
1339the zero cone and will issue the (wrong) error message that the cone is not
1340pointed. The function also gives an error message if the matrix $T$ has the
1341wrong number of columns.
1342@end tex
1343@end texinfo
1344SEE ALSO: valRing, valRingIdeal
1345EXAMPLE:  example torusInvariants; shows an example
1346"
1347{
1348    if(nvars(basering)!=ncols(T))
1349    {
1350        ERROR("torusInvariants: wrong number of columns in matrix");
1351    }
1352
1353    string dummy=collectNmzOptions();  // only to set GenGen
1354
1355/*    if(!GenGen) // return T
1356    {
1357        runNormaliz(T,ncols(T),5);
1358        return(T);
1359    }
1360*/    return( intmat2mons( runNormaliz(T,ncols(T),5) ) );
1361}
1362example
1363{ "EXAMPLE:"; echo=2;
1364  ring R=0,(x,y,z,w),dp;
1365  intmat V0[2][4]=0,1,2,3, -1,1,2,1;
1366  valRing(V0);
1367}
1368
1369proc valRing(intmat V)
1370"USAGE:   valRing(intmat V);
1371RETURN:   The function returns a monomial ideal, to be considered as the list
1372          of monomials generating @math{S} as an algebra over the coefficient
1373          field.
1374BACKGROUND: @texinfo
1375@tex
1376A discrete monomial valuation $v$ on $R = K[X_1 ,\ldots,X_n]$ is determined by
1377the values $v(X_j)$ of the indeterminates. This function computes the
1378subalgebra $S = \{ f \in R : v_i ( f ) \geq 0,\ i = 1,\ldots,r\}$ for several
1379such valuations $v_i$, $i=1,\ldots,r$. It needs the matrix $V = (v_i(X_j))$ as
1380its input.
1381@end tex
1382@end texinfo
1383@*        The function returns the ideal given by the input matrix V if one of
1384          the options @code{supp}, @code{triang}, or @code{hvect} has been
1385          activated.
1386          However, in this case some numerical invariants are computed, and
1387          some other data may be contained in files that you can read into
1388          Singular (see @ref{showNuminvs}, @ref{exportNuminvs}).
1389NOTE:@texinfo
1390@tex
1391It is of course possible that $S=K$. At present, Normaliz cannot deal with the
1392zero cone and will issue the (wrong) error message that the cone is not
1393pointed. The function also gives an error message if the matrix $V$ has the
1394wrong number of columns.
1395@end tex
1396@end texinfo
1397SEE ALSO: torusInvariants, valRingIdeal
1398EXAMPLE:  example valRing; shows an example
1399"
1400{
1401
1402    if(nvars(basering)!=ncols(V))
1403    {
1404        ERROR("valRing: wrong number of columns in matrix");
1405    }
1406
1407    intmat V1[nrows(V)+ncols(V)][ncols(V)];
1408    int i,j;
1409
1410    for(i=1;i<=ncols(V);i++)
1411    {
1412        V1[i,i]=1;
1413    }
1414    for(i=1;i<=nrows(V);i++)
1415    {
1416        for(j=1;j<=ncols(V);j++)
1417        {
1418            V1[i+ncols(V),j]=V[i,j];
1419        }
1420    }
1421
1422
1423    string dummy=collectNmzOptions();  // only to set GenGen
1424
1425/*    if(!GenGen) // return V
1426    {
1427        runNormaliz(V1,ncols(V),4);
1428        return(V);
1429    }
1430*/
1431    return(intmat2mons(runNormaliz(V1,ncols(V),4)));
1432}
1433example
1434{ "EXAMPLE:"; echo=2;
1435  ring R=0,(x,y,z,w),dp;
1436  intmat V0[2][4]=0,1,2,3, -1,1,2,1;
1437  valRing(V0);
1438}
1439
1440proc valRingIdeal(intmat V)
1441"USAGE:   valRingIdeal(intmat V);
1442RETURN:   The function returns two ideals, both to be considered as lists of
1443          monomials which generate an algebra over the coefficient field. The
1444          first is the system of monomial generators of @math{S}, the second
1445          the system of generators of @math{M}.
1446@*        The function returns a list consisting of the ideal given by the
1447          input matrix T if one of the options @code{supp}, @code{triang}, or
1448          @code{hvect} has been activated.
1449          However, in this case some numerical invariants are computed, and
1450          some other data may be contained in files that you can read into
1451          Singular (see @ref{showNuminvs}, @ref{exportNuminvs}).
1452BACKGROUND: @texinfo
1453@tex
1454A discrete monomial valuation $v$ on $R = K[X_1 ,\ldots,X_n]$ is determined by
1455the values $v(X_j)$ of the indeterminates. This function computes the
1456subalgebra $S = \{ f \in R : v_i ( f ) \geq 0,\ i = 1,\ldots,r\}$ for several
1457such valuations $v_i$, $i=1,\ldots,r$. It needs the matrix $V = (v_i(X_j))$ as
1458its input.
1459
1460This function simultaneously determines the $S$-submodule
1461$M = \{ f \in R : v_i(f) \geq w_i ,\ i = 1,\ldots,r\}$ for integers
1462$w_1,\ldots\,w_r$. (If $w_i \geq 0$ for all $i$, $M$ is an ideal of $S$.)
1463The numbers $w_i$ form the $(n+1)$th column of the input matrix.
1464@end tex
1465@end texinfo
1466NOTE:@texinfo
1467@tex
1468It is of course possible that $S=K$. At present, Normaliz cannot deal with the
1469zero cone and will issue the (wrong) error message that the cone is not
1470pointed. The function also gives an error message if the matrix $T$ has the
1471wrong number of columns.
1472@end tex
1473@end texinfo
1474SEE ALSO: torusInvariants, valRing
1475EXAMPLE:  example valRingIdeal; shows an example
1476"
1477{
1478    if(nvars(basering)!=ncols(V)-1)
1479    {
1480        ERROR("valRingIdeal: wrong number of columns in matrix");
1481    }
1482
1483    intmat V1[nrows(V)+ncols(V)][ncols(V)];
1484    int i,j;
1485
1486    for(i=1;i<=ncols(V);i++)
1487    {
1488        V1[i,i]=1;
1489    }
1490    for(i=1;i<=nrows(V);i++)
1491    {
1492        for(j=1;j<=ncols(V);j++)
1493        {
1494            V1[i+ncols(V),j]=V[i,j];
1495        }
1496    }
1497    for(i=1;i<=nrows(V);i++)
1498    {
1499        V1[i+ncols(V),ncols(V)]=-V1[i+ncols(V),ncols(V)];
1500    }
1501
1502    string dummy=collectNmzOptions();  // only to set GenGen
1503
1504/*    if(!GenGen) // return V
1505    {
1506        runNormaliz(V1,ncols(V),4);
1507        return(V);
1508    }
1509*/
1510    intmat nmz_data=runNormaliz(V1,ncols(V),4);
1511
1512    ideal I1=intmat2monsSel(nmz_data,0);
1513    ideal I2=intmat2monsSel(nmz_data,1);
1514    return(list(I1,I2));
1515}
1516example
1517{ "EXAMPLE:"; echo=2;
1518 ring R=0,(x,y,z,w),dp;
1519 intmat V[2][5]=0,1,2,3,4, -1,1,2,1,3;
1520 valRingIdeal(V);
1521}
1522//---------------------------------------------------------------------------
1523// a library file is a bad place for examples (it has to be parsed
1524// every time and one has to be carefull to make it ALL to a comment),
1525// but some authors prefer it that way.....
1526// and, the information is in the same file.
1527//
1528/*
1529// This example is taken from Bruns and Gubeladze, Polytopal linear groups,
1530// J. Algebra 218 (1999), 715--737.
1531// The generators of the monoid are the facet-vertex incidence vectors of
1532// the minimal triangulation of the real projective plane.
1533// It is our goal to show that the normalization of
1534// the corresponding algebra and the algebra itself differ
1535// only by a vector space of dimension 1.
1536//
1537// Computing times extremely small (< 1 sec) on every system.
1538//
1539LIB "normaliz.lib";
1540ring A=2,(a(1..6)),dp;
1541intmat M[10][6]=
15421, 1, 1, 0, 0, 0,
15431, 1, 0, 1, 0, 0,
15441, 0, 1, 0, 1, 0,
15451, 0, 0, 1, 0, 1,
15461, 0, 0, 0, 1, 1,
15470, 1, 1, 0, 0, 1,
15480, 1, 0, 1, 1, 0,
15490, 1, 0, 0, 1, 1,
15500, 0, 1, 1, 1, 0,
15510, 0, 1, 1, 0, 1;
1552ideal R=intmat2mons(M);
1553print(R);
1554setNmzOption("hilb",1);
1555ideal S=normalToricRing(R); // S is the normalization
1556print(S);
1557showNuminvs();
1558ideal Z=0;
1559ring P=2,(x(1..10)),dp;
1560ring Q=2,(y(1..10),z),dp;
1561setring A;
1562map f=P,R;
1563map g=Q,S;
1564setring P;
1565ideal I=preimage(A,f,Z);
1566hilb(std(I));
1567ring T=0,t,dp;
1568poly H1=1+4t+11t2+4t3+t4; // numerator polynomial of Hilbert series of S
1569poly H2=1+4t+10t2+10t3-14t4+20t5-15t6+6t7-1t^8; // the same for R itself
1570factorize(H1-H2); // this shows the claim about S/R
1571setring Q; // now we verify it additionally by the defining ideal of S
1572ideal J=preimage(A,g,Z);
1573print(J);
1574// Computing times extremely small (< 1 sec) on every system.
1575
1576===========================================================================
1577
1578// The following example is the first one not covered by the classification
1579// of Ohsugi and Hibi of normality of monoids derived from contingency
1580// tables. (See H.Ohsugi and T. Hibi, Toric ideals arising from
1581// contingency tables. In: Commutative Algebra and Combinatorics.
1582// In: Ramanujan Mathematical Society Lecture Note Series 4
1583// (2006), 87--111.)
1584// The gaps in the classification have meanwhile been closed computationall=
1585y.
1586// See Bruns, R. Hemmecke, B. Ichim, M. K=F6ppe, and C.
1587// S=F6ger, Challenging computations of Hilbert bases of cones
1588// associated with algebraic statistics. Experimental Math., to appear.
1589//
1590// For the currently public version of Normaliz this is a very large exampl=
1591e
1592// On a SUN Fire X4450 it takes about an hour in version 2.2 and needs
1593about 20 GB
1594// of RAM. In the next version (already realized experimentally, expected u=
1595pload
1596// July 2010) it will be a matter of seconds due to algorithmic improvement=
1597s for
1598// this type of example and parallelization. Also memory usage will be redu=
1599ced
1600// significantly.
1601//
1602LIB "normaliz.lib";
1603intmat M[48][40]=
16041, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
16050, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
16060, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
16070, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
16080, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
16090, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
16100, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
16110, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
16120, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
16130, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
16140, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
16150, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
16160, 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1700setNmzOption("control",1);
1701intmat N=normaliz(M,1);
1702showNuminvs(); // shows that the monoid generated by the rows of M is norma=
1703l
1704
1705
1706*/
1707
Note: See TracBrowser for help on using the repository browser.