-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlegacycode.m2
More file actions
302 lines (283 loc) · 10.7 KB
/
Copy pathlegacycode.m2
File metadata and controls
302 lines (283 loc) · 10.7 KB
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
LCRing = method(Options => {
Start => 1,
Symbols => (getSymbol "x", getSymbol "y"),
CoefficientRing => QQ
})
LCRing(ZZ, List) := Ring => opts -> (n, params) -> (
-*
-- n: This is the dimension of the projective space P^n x P^n, indexed 1..n by default
-- params: a list of parameter symbols (or ring variables that can be used as variables in a new ring)
-- output: A ring R that is the coordinate ring of P^n x P^n
-- R_0..R_(n-1): are the coordinate functions for the first factor
-- R_n..R_(2n-1): are the coordinate functions for the second factor
-- R_(2n).. are the parameters
*-
kk := opts.CoefficientRing;
s := opts#Symbols#1;
c := opts#Symbols#0;
start := opts#Start;
R := if #params > 0
then kk[c_start..c_(start+n-1), s_start..s_(start+n-1),params,MonomialOrder=>{2*n,#params}]
else kk[c_start..c_(start+n-1), s_start..s_(start+n-1)];
-- R.numOscillators = n;
R
)
LCRing ZZ := Ring => opts -> n -> LCRing(n, {}, opts)
computeIndependenceLC = method()
computeIndependenceLC(ZZ, ZZ) := Ideal => (m, n) -> (
-*
Here we can describe inputs and outputs
*-
p := local p;
u := local u;
x := local x;
R := ZZ/32003[p_(1,1)..p_(m,n), u_(1,1)..u_(m,n), x];
P := transpose(genericMatrix(R,p_(1,1),n,m));
Lcol := matrix {for i from 1 to m list sum(for j from 1 to n list u_(i,j))};
Lrow := for i from 1 to n list sum(for j from 1 to m list u_(j,i));
Lrow = matrix {append(Lrow,x)};
P = P | transpose(Lcol);
P = P || Lrow;
I := eliminate({x}, minors(2, P));
S := ZZ/32003[p_(1,1)..p_(m,n), u_(1,1)..u_(m,n)];
f := map(S,R,gens S | {0});
f(I))
computeToricLC = method()
computeToricLC(Matrix) := Ideal => A -> (
p := local p;
u := local u;
numcol := local numcol;
M := local M;
numcol = numColumns(A);
R := ZZ/32003[p_1..p_numcol, u_1..u_numcol, Degrees => {numcol:{1,0}, numcol:{0,1}}];
toric := toricIdeal(A,R);
M = reshape(R^numcol,R^2,matrix({gens R}));
I := toric+minors(2,A*M);
L := saturate(I,sum entries M_0);
L)
computeToricLCwithToric = method()
computeToricLCwithToric(Matrix) := Ideal => A -> (
p := local p;
u := local u;
numcol := local numcol;
M := local M;
numcol = numColumns(A);
R := ZZ/32003[p_1..p_numcol, u_1..u_numcol, Degrees => {numcol:{1,0}, numcol:{0,1}}];
toric := toricIdeal(A,R);
M = reshape(R^numcol,R^2,matrix({gens R}));
I := toric+minors(2,A*M);
L := saturate(I,sum entries M_0);
L,toric)
--take a sequence of matrices, first the full A matrix, then the A_i submatrices
--This is to test daves suggested method that the u*p actually need to be split
computeToricLCwithToricSeq = method()
computeToricLCwithToricSeq(List) := Ideal => A -> (
p := local p;
u := local u;
numcol := local numcol;
M := local M;
numcol = numColumns(A_0);
R := ZZ/32003[p_1..p_numcol, u_1..u_numcol, Degrees => {numcol:{1,0}, numcol:{0,1}}];
toric := toricIdeal(A_0,R);
M = reshape(R^numcol,R^2,matrix({gens R}));
I := toric+ (sum for i from 1 to #A-1 list minors(2,A_i*M));
L := saturate(I,sum entries M_0);
L2 := saturate((toric + minors(2,A_0*M)),sum entries M_0);
L,toric,L2)
computeLC = method()
computeLC(Ideal) := Ideal => I -> (
U := local U;
d := local d;
u := local u;
pmat := local pmat;
umat := local umat;
R := ring(I);
n := numgens R;
S := coefficientRing(R)[gens R, u_1..u_n];
varList := for i from 0 to #(gens R) -1 list S_i;
varList2 := for i from 0 to #(gens R) -1 list 1_S;
f := map(S,R,varList);
J := (matrix {varList2}) || transpose(f jacobian(I));
Q := minors(codim(I)+1,jacobian(I));
U = reshape(S^n,S^2,matrix{gens S});
pmat = transpose(matrix{U_0});
umat = transpose(matrix{U_1});
Jaug := umat || J*diagonalMatrix(varList);
H := ideal((sum flatten entries pmat)*(product flatten entries pmat));
L := saturate(f(I) + minors(codim(I)+2,Jaug),H+(f(Q)));
L)
computenwayIndependenceLC = method()
computenwayIndependenceLC(List) := Ideal => inplist -> (
-*
Input: A matrix A describing the polytope of a toric ideal
*-
p := local p;
u := local u;
curM := local curM;
curu := local curu;
currow := local currow;
inplist = new Sequence from inplist;
ilist := new List from inplist;
nums := for i from 0 to #inplist-1 list fold((n,m)->n*m, ilist)/ilist_i;
fixListsEnding := for i from 1 to #inplist list (
if i == 1 then (
for j from 1 to inplist_(i-1) list (1:j)| new Sequence from inplist_{1 ..#inplist-1}
);
if i == #inplist then (
for j from 1 to inplist_(i-1) list (new Sequence from inplist_{0 ..#inplist-2}) | (1:j)
);
for j from 1 to inplist_(i-1) list (new Sequence from inplist_{0 ..i-2}) |(1:j)| (new Sequence from inplist_{i..#inplist-1})
);
fixListsStart := for i from 1 to #inplist list (
if i == 1 then (
for j from 1 to inplist_(i-1) list (1:j)| (#inplist-1 : 1)
);
if i == #inplist then (
for j from 1 to inplist_(i-1) list (#inplist-1:1) | (1:j)
);
for j from 1 to inplist_(i-1) list (i-1:1) |(1:j)| (#inplist-i:1)
);
deglist1 := fold((n,m)->n*m,ilist) : {1,0};
deglist2 := fold((n,m)->n*m,ilist) : {0,1};
deglist := new List from join(deglist1,deglist2);
start := #inplist:1;
R := ZZ/32003[p_start..p_inplist,u_start..u_inplist, Degrees => deglist];
Ms := {};
for i from 0 to #inplist-1 do (
curM = {};
for j from 0 to #fixListsStart_i-1 do(
currow = new List from p_(fixListsStart_i_j)..p_(fixListsEnding_i_j);
curu = sum new List from u_(fixListsStart_i_j)..u_(fixListsEnding_i_j);
currow = append(currow,curu);
curM = append(curM,currow);
);
Ms = append(Ms,matrix curM)
);
Ilist := for i from 0 to #Ms-1 list minors(2,Ms_i);
I := sum Ilist;
I)
--------- The below is for testing conjectures. I pull out the matrices that create the ideal in the method above.
nwayindependenceMatrices = method()
nwayindependenceMatrices(List) := List => inplist -> (
p := local p;
u := local u;
curM := local curM;
curu := local curu;
currow := local currow;
inplist = new Sequence from inplist;
ilist := new List from inplist;
nums := for i from 0 to #inplist-1 list fold((n,m)->n*m, ilist)/ilist_i;
fixListsEnding := for i from 1 to #inplist list (
if i == 1 then (
for j from 1 to inplist_(i-1) list (1:j)| new Sequence from inplist_{1 ..#inplist-1}
);
if i == #inplist then (
for j from 1 to inplist_(i-1) list (new Sequence from inplist_{0 ..#inplist-2}) | (1:j)
);
for j from 1 to inplist_(i-1) list (new Sequence from inplist_{0 ..i-2}) |(1:j)| (new Sequence from inplist_{i..#inplist-1})
);
fixListsStart := for i from 1 to #inplist list (
if i == 1 then (
for j from 1 to inplist_(i-1) list (1:j)| (#inplist-1 : 1)
);
if i == #inplist then (
for j from 1 to inplist_(i-1) list (#inplist-1:1) | (1:j)
);
for j from 1 to inplist_(i-1) list (i-1:1) |(1:j)| (#inplist-i:1)
);
deglist1 := fold((n,m)->n*m,ilist) : {1,0};
deglist2 := fold((n,m)->n*m,ilist) : {0,1};
deglist := new List from join(deglist1,deglist2);
start := #inplist:1;
R := ZZ/32003[p_start..p_inplist,u_start..u_inplist, Degrees => deglist];
Ms := {};
for i from 0 to #inplist-1 do (
curM = {};
for j from 0 to #fixListsStart_i-1 do(
currow = new List from p_(fixListsStart_i_j)..p_(fixListsEnding_i_j);
curu = sum new List from u_(fixListsStart_i_j)..u_(fixListsEnding_i_j);
currow = append(currow,curu);
curM = append(curM,currow);
);
Ms = append(Ms,matrix curM)
);
Ms)
--------- The below is for testing conjectures. I pull out the matrices that create the ideal of the model
computenwayindependenceModel = method()
computenwayindependenceModel(List) := Ideal => inplist -> (
p := local p;
u := local u;
curM := local curM;
curu := local curu;
currow := local currow;
inplist = new Sequence from inplist;
ilist := new List from inplist;
nums := for i from 0 to #inplist-1 list fold((n,m)->n*m, ilist)/ilist_i;
fixListsEnding := for i from 1 to #inplist list (
if i == 1 then (
for j from 1 to inplist_(i-1) list (1:j)| new Sequence from inplist_{1 ..#inplist-1}
);
if i == #inplist then (
for j from 1 to inplist_(i-1) list (new Sequence from inplist_{0 ..#inplist-2}) | (1:j)
);
for j from 1 to inplist_(i-1) list (new Sequence from inplist_{0 ..i-2}) |(1:j)| (new Sequence from inplist_{i..#inplist-1})
);
fixListsStart := for i from 1 to #inplist list (
if i == 1 then (
for j from 1 to inplist_(i-1) list (1:j)| (#inplist-1 : 1)
);
if i == #inplist then (
for j from 1 to inplist_(i-1) list (#inplist-1:1) | (1:j)
);
for j from 1 to inplist_(i-1) list (i-1:1) |(1:j)| (#inplist-i:1)
);
deglist1 := fold((n,m)->n*m,ilist) : {1,0};
deglist2 := fold((n,m)->n*m,ilist) : {0,1};
deglist := new List from join(deglist1,deglist2);
start := #inplist:1;
R := ZZ/32003[p_start..p_inplist,u_start..u_inplist, Degrees => deglist];
Ms := {};
for i from 0 to #inplist-1 do (
curM = {};
for j from 0 to #fixListsStart_i-1 do(
currow = new List from p_(fixListsStart_i_j)..p_(fixListsEnding_i_j);
curM = append(curM,currow);
);
Ms = append(Ms,matrix curM)
);
Ilist := for i from 0 to #Ms-1 list minors(2,Ms_i);
I := sum Ilist;
I)
computenwayToricMatrix = method()
computenwayToricMatrix(List) := Ideal => inplist -> (
-*
Input: A matrix A describing the polytope of a toric ideal
*-
p := local p;
u := local u;
currow := local currow;
curM := local curM;
curu := local curu;
--currow := local currow;
inplist = new Sequence from inplist;
start := #inplist:1;
theSeq := start .. inplist;
ilist := new List from inplist;
nums := fold((n,m)->n*m, ilist);
firstRow := new List from (nums:1);
AMatrix := {firstRow};
for i from 0 to #inplist-1 do (
for j from 1 to inplist_i-1 do (
currow = {};
for k in theSeq list (
if k_i == inplist_i then (
currow = append(currow, 1);
continue;
);
currow = append(currow, 0);
);
);
AMatrix = append(AMatrix,currow);
);
matrix AMatrix)
-- We could separate out the helper functions here.