-
Notifications
You must be signed in to change notification settings - Fork 5
/
ExampleSystems.m2
executable file
·162 lines (144 loc) · 5.18 KB
/
ExampleSystems.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
-- -*- coding: utf-8 -*-
newPackage(
"ExampleSystems",
AuxiliaryFiles => true,
Version => "0.1",
Date => "June, 2016",
Authors => {{
Name => "Anton Leykin",
Email => "leykin@math.gatech.edu"
}},
PackageExports => {"NumericalAlgebraicGeometry"},
Headline => "examples of polynomial systems",
DebuggingMode => false
)
examples'names = {
"boon",
"butcher",
"cyclic",
"eco8",
"geneig",
"heart",
"ipp",
"katsura",
"ku10",
"lumped",
"puma",
"quadgrid",
"rabmo",
"randomGeneralizedEigenvalueProblem",
"randomSystem",
"rbpl24s",
"reimer5",
"sendra"
}
for e in examples'names do
needs("./ExampleSystems/"|e|".m2")
beginDocumentation()
multidoc ///
Node
Key
ExampleSystems
Headline
examples of polynomial systems
///
end
-- Here place M2 code that you find useful while developing this
-- package. None of it will be executed when the file is loaded,
-- because loading stops when the symbol "end" is encountered.
restart
uninstallPackage "ExampleSystems"
installPackage "ExampleSystems"
installPackage("ExampleSystems", RemakeAllDocumentation=>true)
check "ExampleSystems"
help "ExampleSystems"
-- Local Variables:
-- compile-command: "make -C $M2BUILDDIR/Macaulay2/packages PACKAGES=PackageTemplate pre-install"
-- End:
ExampleTable = new Type of HashTable
box = method()
example = method(Options=>{CoefficientRing => ZZ/32003,
Ring => null})
findExamples = method()
findExamples(ExampleTable, String) := (E,regex) -> (
K := keys E;
select(K, k -> match(regex, K#k#0))
)
show(ExampleTable, ZZ) := (H,x) -> print ("-------------------" || ("-- "|H#x#0) || H#x#1)
show(ExampleTable, List) := (H,x) -> scan(x, x1 -> show(H,x1))
show(ExampleTable, String) := (H,re) -> show(H,findExamples(H,re))
show(ExampleTable) := (H) -> show(H, sort keys H)
box(ExampleTable, ZZ) := (H,x) -> box(H,{x})
box(ExampleTable, List) := (H,x) -> netList apply(x, x1 -> {x1, ("-- "|H#x1#0) || H#x1#1})
box(ExampleTable, String) := (H,re) -> box(H,findExamples(H,re))
box(ExampleTable) := (H) -> box(H, sort keys H)
example(ExampleTable, ZZ) :=
example(ExampleTable, String) := opts -> (H,x) -> (
R1 := if opts#?Ring then opts#Ring else null;
kk := if R1 === null
then opts.CoefficientRing
else coefficientRing R1;
I := value replace("kk", toString kk, H#x#1);
if R1 =!= null then (
nvars := numgens ring I;
if numgens R1 < nvars then
error ("expected ring with at least "|nvars|" variables");
substitute(I, (vars R1)_{0..nvars-1})
)
else I)
readExampleFile = method()
-* -- remove this code
readExampleFile(String,Ring) := (filename, coeffring) -> (
G := separateRegexp("---+", get (ExampleIdeals#"source directory"|filename));
G = apply(G, s -> select(lines s, t -> #t > 0));
-- now for each example, find its name/number and make the string
G = select(G, s -> #s > 0);
new ExampleTable from apply(#G, i -> (
s := substring(2,G#i#0); -- remove the first two -- characters
i+1 => s => replace("kk", toString coeffring, demark("\n",drop(G#i,1)))))
)
readExampleFile(String) := (filename) -> (
G := separateRegexp("---+", get (ExampleIdeals#"source directory"|filename));
G = apply(G, s -> select(lines s, t -> #t > 0));
-- now for each example, find its name/number and make the string
G = select(G, s -> #s > 0);
new ExampleTable from apply(#G, i -> (
s := substring(2,G#i#0); -- remove the first two -- characters
i+1 => s => demark("\n",drop(G#i,1))))
)
*-
getExampleFile = method()
-* -- remove this code
getExampleFile(String,String) := (filename,kkstring) -> (
G := separateRegexp("---+", get filename);
G = apply(G, s -> select(lines s, t -> #t > 0));
-- now for each example, find its name/number and make the string
G = select(G, s -> #s > 0);
new ExampleTable from apply(#G, i -> (
s := substring(2,G#i#0); -- remove the first two -- characters
i+1 => s => replace("kk", kkstring, demark("\n",drop(G#i,1)))))
)
getExampleFile(String) := (filename) -> getExampleFile(filename,"")
*-
-- New code
getExampleFile(String) := (filename) -> (
G := separateRegexp("---+", get filename);
G = apply(G, s -> select(lines s, t -> #t > 0));
-- now for each example, find its name/number and make the string
G = select(G, s -> #s > 0);
new ExampleTable from apply(#G, i -> (
s := substring(2,G#i#0); -- remove the first two -- characters
i+1 => s => demark("\n",drop(G#i,1))))
)
readExampleFile(String) := (filename) ->
getExampleFile(ExampleIdeals#"source directory"|"ExampleIdeals/"|filename)
replaceStrings = (L, str) -> (scan(L, v -> str = replace(v#0,v#1,str)); str)
substitute(ExampleTable, List) := (E, L) -> (
-- L is a list of options: str => newstr, (or regex => newstr).
-- return a new ExampleTable where each final string has the given strings in L
-- replaced (in order).
new ExampleTable from apply(pairs E, (k,v) -> (
k => (v#0 => replaceStrings(L, v#1))
))
)
substitute(ExampleTable, Option) := (E,subs) -> substitute(E, {subs})