-
Notifications
You must be signed in to change notification settings - Fork 1
/
SingSolve.m2
88 lines (73 loc) · 2.96 KB
/
SingSolve.m2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
-- SingSolve.m2
--
-- Copyright (C) 2009 Thomas Kahle <[email protected]>
--
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or (at
-- your option) any later version.
--
-- This program is distributed in the hope that it will be useful, but
-- WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along
-- with this program; if not, write to the Free Software Foundation, Inc.,
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
--
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
newPackage(
"SingSolve",
Version => "0.1.1",
Date => "January 8 , 2009",
Authors => {
{Name => "Thomas Kahle", Email => "[email protected]", HomePage => "http://personal-homepages.mis.mpg.de/kahle/"}},
Headline => "Interface to Singulars solve facility",
Configuration => { "path" => "Singular" },
DebuggingMode => true
)
export {singsolve}
path'singular = (options SingSolve).Configuration#"path"
-- NOTE: the absolute path should be put into the .init file for 4ti2 inside the .Macaulay2 directory.
singsolve = method(TypicalValue => List)
singsolve Ideal := List => I -> (
-- This function numerically solves a 0-dim'l ideal using singular
if dim I != 0 then error "Expected 0-dim'l ideal !";
print Configuration;
-- We coerce the ideal to singular
F := openInOut ("!" | path'singular);
varlist := gens ring I;
-- We create the ring:
F << "ring R = 0,(";
F << concatenate (between_"," varlist/toString);
F << "),dp;" << endl;
F << "ideal I = ";
ge = flatten entries gens I;
-- We convert the generators to a string representation
F << concatenate(between_"," ge/toString, ";");
-- Lets solve the ideal
F <<"LIB \"solve.lib\"; ";
F <<"def S = solve(I);" << endl;
F <<"setring S;" << endl;
F <<"print (SOL,\"%s\");" << endl;
F << endl;
F << "quit;";
-- Done with programming
F << closeOut;
print "Running Singular";
outlines := lines get F;
-- Second to last line contains the result
-- Singular uses "i" as the complex unit.
cl := toList value replace("i","ii",outlines#-2);
-- cl now contains a flat list of values like
-- x_0,y_0,z_0,x_1,y_1,z_1, ..
-- print cl;
numvars := #varlist; -- Number of variables should divide length of cl.
numsols := #cl // numvars; -- ... and give number of solutions
print ("Number of solutions: " | numsols);
return pack (numvars, cl);
)
endPackage "SingSolve"