My Project
Toggle main menu visibility
Loading...
Searching...
No Matches
Singular
dyn_modules
gfanlib
tropical.cc
Go to the documentation of this file.
1
#include "
polys/monomials/p_polys.h
"
2
#include "
coeffs/coeffs.h
"
3
4
#include "
callgfanlib_conversion.h
"
5
#include "
bbcone.h
"
6
#include "
ppinitialReduction.h
"
7
#include "
containsMonomial.h
"
8
#include "
initial.h
"
9
#include "
witness.h
"
10
#include "
tropicalCurves.h
"
11
#include "
tropicalStrategy.h
"
12
#include "
startingCone.h
"
13
#include "
groebnerFan.h
"
14
#include "
groebnerComplex.h
"
15
#include "
tropicalVariety.h
"
16
17
VAR
int
tropicalVerboseLevel
= 0;
18
19
gfan::ZCone
homogeneitySpace
(ideal I, ring r)
20
{
21
int
n = rVar(r);
22
poly
g
;
23
int
* leadexpv = (
int
*)
omAlloc
((n+1)*
sizeof
(
int
));
24
int
* tailexpv = (
int
*)
omAlloc
((n+1)*
sizeof
(
int
));
25
gfan::ZVector leadexpw = gfan::ZVector(n);
26
gfan::ZVector tailexpw = gfan::ZVector(n);
27
gfan::ZMatrix
equations
= gfan::ZMatrix(0,n);
28
for
(
int
i
=0;
i
<
IDELEMS
(I);
i
++)
29
{
30
g
= (poly) I->m[
i
];
31
if
(
g
)
32
{
33
p_GetExpV(
g
,leadexpv,r);
34
leadexpw =
intStar2ZVector
(n,leadexpv);
35
pIter
(
g
);
36
while
(
g
)
37
{
38
p_GetExpV(
g
,tailexpv,r);
39
tailexpw =
intStar2ZVector
(n,tailexpv);
40
equations
.appendRow(leadexpw-tailexpw);
41
pIter
(
g
);
42
}
43
}
44
}
45
omFreeSize
(leadexpv,(n+1)*
sizeof
(
int
));
46
omFreeSize
(tailexpv,(n+1)*
sizeof
(
int
));
47
return
gfan::ZCone(gfan::ZMatrix(0,
equations
.getWidth()),
equations
);
48
}
49
50
51
BOOLEAN
homogeneitySpace
(
leftv
res
,
leftv
args)
52
{
53
leftv
u = args;
54
if
((u !=
NULL
) && (u->
Typ
() ==
POLY_CMD
))
55
{
56
leftv
v
= u->
next
;
57
if
(
v
==
NULL
)
58
{
59
poly
g
= (poly) u->
Data
();
60
ideal I =
idInit
(1);
61
I->m[0] =
g
;
62
res
->rtyp =
coneID
;
63
res
->data = (
void
*)
new
gfan::ZCone(
homogeneitySpace
(I,
currRing
));
64
I->m[0] =
NULL
;
65
id_Delete
(&I,
currRing
);
66
return
FALSE
;
67
}
68
}
69
if
((u !=
NULL
) && (u->
Typ
() ==
IDEAL_CMD
))
70
{
71
leftv
v
= u->
next
;
72
if
(
v
==
NULL
)
73
{
74
ideal I = (ideal) u->
Data
();
75
res
->rtyp =
coneID
;
76
res
->data = (
void
*)
new
gfan::ZCone(
homogeneitySpace
(I,
currRing
));
77
return
FALSE
;
78
}
79
}
80
WerrorS
(
"homogeneitySpace: unexpected parameters"
);
81
return
TRUE
;
82
}
83
84
85
gfan::ZCone
lowerHomogeneitySpace
(ideal I, ring r)
86
{
87
int
n = rVar(r);
88
poly
g
;
89
int
* leadexpv = (
int
*)
omAlloc
((n+1)*
sizeof
(
int
));
90
int
* tailexpv = (
int
*)
omAlloc
((n+1)*
sizeof
(
int
));
91
gfan::ZVector leadexpw = gfan::ZVector(n);
92
gfan::ZVector tailexpw = gfan::ZVector(n);
93
gfan::ZMatrix
equations
= gfan::ZMatrix(0,n);
94
for
(
int
i
=0;
i
<
IDELEMS
(I);
i
++)
95
{
96
g
= (poly) I->m[
i
];
97
if
(
g
)
98
{
99
p_GetExpV(
g
,leadexpv,r);
100
leadexpw =
intStar2ZVector
(n,leadexpv);
101
pIter
(
g
);
102
while
(
g
)
103
{
104
p_GetExpV(
g
,tailexpv,r);
105
tailexpw =
intStar2ZVector
(n,tailexpv);
106
equations
.appendRow(leadexpw-tailexpw);
107
pIter
(
g
);
108
}
109
}
110
}
111
gfan::ZMatrix
inequalities
= gfan::ZMatrix(0,n);
112
gfan::ZVector lowerHalfSpaceCondition = gfan::ZVector(n);
113
lowerHalfSpaceCondition[0] = -1;
114
inequalities
.appendRow(lowerHalfSpaceCondition);
115
116
omFreeSize
(leadexpv,(n+1)*
sizeof
(
int
));
117
omFreeSize
(tailexpv,(n+1)*
sizeof
(
int
));
118
return
gfan::ZCone(
inequalities
,
equations
);
119
}
120
121
122
BOOLEAN
lowerHomogeneitySpace
(
leftv
res
,
leftv
args)
123
{
124
leftv
u = args;
125
if
((u !=
NULL
) && (u->
Typ
() ==
POLY_CMD
))
126
{
127
leftv
v
= u->
next
;
128
if
(
v
==
NULL
)
129
{
130
poly
g
= (poly) u->
Data
();
131
ideal I =
idInit
(1);
132
I->m[0] =
g
;
133
res
->rtyp =
coneID
;
134
res
->data = (
void
*)
new
gfan::ZCone(
lowerHomogeneitySpace
(I,
currRing
));
135
I->m[0] =
NULL
;
136
id_Delete
(&I,
currRing
);
137
return
FALSE
;
138
}
139
}
140
if
((u !=
NULL
) && (u->
Typ
() ==
IDEAL_CMD
))
141
{
142
leftv
v
= u->
next
;
143
if
(
v
==
NULL
)
144
{
145
ideal I = (ideal) u->
Data
();
146
res
->rtyp =
coneID
;
147
res
->data = (
void
*)
new
gfan::ZCone(
lowerHomogeneitySpace
(I,
currRing
));
148
return
FALSE
;
149
}
150
}
151
WerrorS
(
"lowerHomogeneitySpace: unexpected parameters"
);
152
return
TRUE
;
153
}
154
155
156
gfan::ZCone
groebnerCone
(
const
ideal I,
const
ring r,
const
gfan::ZVector &
w
)
157
{
158
int
n = rVar(r);
159
poly
g
=
NULL
;
160
int
* leadexpv = (
int
*)
omAlloc
((n+1)*
sizeof
(
int
));
161
int
* tailexpv = (
int
*)
omAlloc
((n+1)*
sizeof
(
int
));
162
gfan::ZVector leadexpw = gfan::ZVector(n);
163
gfan::ZVector tailexpw = gfan::ZVector(n);
164
165
gfan::ZMatrix
inequalities
= gfan::ZMatrix(0,n);
166
for
(
int
i
=0;
i
<
IDELEMS
(I);
i
++)
167
{
168
g
= (poly) I->m[
i
];
169
if
(
g
!=
NULL
)
170
{
171
p_GetExpV(
g
,leadexpv,
currRing
);
172
leadexpw =
intStar2ZVector
(n, leadexpv);
173
pIter
(
g
);
174
while
(
g
!=
NULL
)
175
{
176
p_GetExpV(
g
,tailexpv,
currRing
);
177
tailexpw =
intStar2ZVector
(n, tailexpv);
178
inequalities
.appendRow(leadexpw-tailexpw);
179
pIter
(
g
);
180
}
181
}
182
}
183
184
ideal inI =
initial
(I,
currRing
,
w
);
185
gfan::ZMatrix
equations
= gfan::ZMatrix(0,n);
186
for
(
int
i
=0;
i
<
IDELEMS
(I);
i
++)
187
{
188
g
= (poly) inI->m[
i
];
189
if
(
g
!=
NULL
)
190
{
191
p_GetExpV(
g
,leadexpv,
currRing
);
192
leadexpw =
intStar2ZVector
(n, leadexpv);
193
pIter
(
g
);
194
while
(
g
!=
NULL
)
195
{
196
p_GetExpV(
g
,tailexpv,
currRing
);
197
tailexpw =
intStar2ZVector
(n, tailexpv);
198
equations
.appendRow(leadexpw-tailexpw);
199
pIter
(
g
);
200
}
201
}
202
}
203
204
omFreeSize
(leadexpv,(n+1)*
sizeof
(
int
));
205
omFreeSize
(tailexpv,(n+1)*
sizeof
(
int
));
206
id_Delete
(&inI,
currRing
);
207
return
gfan::ZCone(
inequalities
,
equations
);
208
}
209
210
211
BOOLEAN
groebnerCone
(
leftv
res
,
leftv
args)
212
{
213
leftv
u = args;
214
if
((u !=
NULL
) && (u->
Typ
() ==
POLY_CMD
))
215
{
216
leftv
v
= u->
next
;
217
if
((
v
!=
NULL
) && ((
v
->Typ() ==
BIGINTMAT_CMD
) || (
v
->Typ() ==
INTVEC_CMD
)))
218
{
219
try
220
{
221
poly
g
= (poly) u->
Data
();
222
ideal I =
idInit
(1);
223
I->m[0] =
g
;
224
gfan::ZVector* weightVector;
225
if
(
v
->Typ() ==
INTVEC_CMD
)
226
{
227
intvec
* w0 = (
intvec
*)
v
->Data();
228
bigintmat
* w1 =
iv2bim
(w0,
coeffs_BIGINT
);
229
w1->
inpTranspose
();
230
weightVector =
bigintmatToZVector
(*w1);
231
delete
w1;
232
}
233
else
234
{
235
bigintmat
* w1 = (
bigintmat
*)
v
->Data();
236
weightVector =
bigintmatToZVector
(*w1);
237
}
238
res
->rtyp =
coneID
;
239
res
->data = (
void
*)
new
gfan::ZCone(
groebnerCone
(I,
currRing
,*weightVector));
240
delete
weightVector;
241
I->m[0] =
NULL
;
242
id_Delete
(&I,
currRing
);
243
return
FALSE
;
244
}
245
catch
(
const
std::exception& ex)
246
{
247
Werror
(
"ERROR: %s"
,ex.what());
248
return
TRUE
;
249
}
250
}
251
}
252
if
((u !=
NULL
) && (u->
Typ
() ==
IDEAL_CMD
))
253
{
254
leftv
v
= u->
next
;
255
if
((
v
!=
NULL
) && ((
v
->Typ() ==
BIGINTMAT_CMD
) || (
v
->Typ() ==
INTVEC_CMD
)))
256
{
257
try
258
{
259
ideal I = (ideal) u->
Data
();
260
gfan::ZVector* weightVector;
261
if
(
v
->Typ() ==
INTVEC_CMD
)
262
{
263
intvec
* w0 = (
intvec
*)
v
->Data();
264
bigintmat
* w1 =
iv2bim
(w0,
coeffs_BIGINT
);
265
w1->
inpTranspose
();
266
weightVector =
bigintmatToZVector
(*w1);
267
delete
w1;
268
}
269
else
270
{
271
bigintmat
* w1 = (
bigintmat
*)
v
->Data();
272
weightVector =
bigintmatToZVector
(*w1);
273
}
274
res
->rtyp =
coneID
;
275
res
->data = (
void
*)
new
gfan::ZCone(
groebnerCone
(I,
currRing
,*weightVector));
276
delete
weightVector;
277
return
FALSE
;
278
}
279
catch
(
const
std::exception& ex)
280
{
281
Werror
(
"ERROR: %s"
,ex.what());
282
return
TRUE
;
283
}
284
}
285
}
286
WerrorS
(
"groebnerCone: unexpected parameters"
);
287
return
TRUE
;
288
}
289
290
291
gfan::ZCone
maximalGroebnerCone
(
const
ideal &I,
const
ring &r)
292
{
293
int
n = rVar(r);
294
poly
g
=
NULL
;
295
int
* leadexpv = (
int
*)
omAlloc
((n+1)*
sizeof
(
int
));
296
int
* tailexpv = (
int
*)
omAlloc
((n+1)*
sizeof
(
int
));
297
gfan::ZVector leadexpw = gfan::ZVector(n);
298
gfan::ZVector tailexpw = gfan::ZVector(n);
299
gfan::ZMatrix
inequalities
= gfan::ZMatrix(0,n);
300
for
(
int
i
=0;
i
<
IDELEMS
(I);
i
++)
301
{
302
g
= (poly) I->m[
i
];
303
if
(
g
!=
NULL
&&
pNext
(
g
) !=
NULL
)
304
{
305
p_GetExpV(
g
,leadexpv,r);
306
leadexpw =
intStar2ZVector
(n, leadexpv);
307
pIter
(
g
);
308
while
(
g
!=
NULL
)
309
{
310
p_GetExpV(
g
,tailexpv,r);
311
tailexpw =
intStar2ZVector
(n, tailexpv);
312
inequalities
.appendRow(leadexpw-tailexpw);
313
pIter
(
g
);
314
}
315
}
316
}
317
omFreeSize
(leadexpv,(n+1)*
sizeof
(
int
));
318
omFreeSize
(tailexpv,(n+1)*
sizeof
(
int
));
319
return
gfan::ZCone(
inequalities
,gfan::ZMatrix(0,
inequalities
.getWidth()));
320
}
321
322
323
BOOLEAN
maximalGroebnerCone
(
leftv
res
,
leftv
args)
324
{
325
leftv
u = args;
326
if
((u !=
NULL
) && (u->
Typ
() ==
POLY_CMD
))
327
{
328
leftv
v
= u->
next
;
329
if
(
v
==
NULL
)
330
{
331
try
332
{
333
poly
g
= (poly) u->
Data
();
334
ideal I =
idInit
(1);
335
I->m[0] =
g
;
336
res
->rtyp =
coneID
;
337
res
->data = (
void
*)
new
gfan::ZCone(
maximalGroebnerCone
(I,
currRing
));
338
I->m[0] =
NULL
;
339
id_Delete
(&I,
currRing
);
340
return
FALSE
;
341
}
342
catch
(
const
std::exception& ex)
343
{
344
Werror
(
"ERROR: %s"
,ex.what());
345
return
TRUE
;
346
}
347
}
348
}
349
if
((u !=
NULL
) && (u->
Typ
() ==
IDEAL_CMD
))
350
{
351
leftv
v
= u->
next
;
352
if
(
v
==
NULL
)
353
{
354
try
355
{
356
ideal I = (ideal) u->
Data
();
357
res
->rtyp =
coneID
;
358
res
->data = (
void
*)
new
gfan::ZCone(
maximalGroebnerCone
(I,
currRing
));
359
return
FALSE
;
360
}
361
catch
(
const
std::exception& ex)
362
{
363
Werror
(
"ERROR: %s"
,ex.what());
364
return
TRUE
;
365
}
366
}
367
}
368
WerrorS
(
"maximalGroebnerCone: unexpected parameters"
);
369
return
TRUE
;
370
}
371
372
373
BOOLEAN
initial
(
leftv
res
,
leftv
args)
374
{
375
leftv
u = args;
376
if
((u !=
NULL
) && (u->
Typ
() ==
POLY_CMD
))
377
{
378
leftv
v
= u->
next
;
379
if
((
v
!=
NULL
) && ((
v
->Typ() ==
BIGINTMAT_CMD
) || (
v
->Typ() ==
INTVEC_CMD
)))
380
{
381
poly
p
= (poly) u->
Data
();
382
gfan::ZVector* weightVector;
383
if
(
v
->Typ() ==
INTVEC_CMD
)
384
{
385
intvec
* w0 = (
intvec
*)
v
->Data();
386
bigintmat
* w1 =
iv2bim
(w0,
coeffs_BIGINT
);
387
w1->
inpTranspose
();
388
weightVector =
bigintmatToZVector
(*w1);
389
delete
w1;
390
}
391
else
392
{
393
bigintmat
* w1 = (
bigintmat
*)
v
->Data();
394
weightVector =
bigintmatToZVector
(*w1);
395
}
396
res
->rtyp =
POLY_CMD
;
397
res
->data = (
void
*)
initial
(
p
,
currRing
, *weightVector);
398
delete
weightVector;
399
return
FALSE
;
400
}
401
}
402
if
((u !=
NULL
) && (u->
Typ
() ==
IDEAL_CMD
))
403
{
404
leftv
v
= u->
next
;
405
if
((
v
!=
NULL
) && ((
v
->Typ() ==
BIGINTMAT_CMD
) || (
v
->Typ() ==
INTVEC_CMD
)))
406
{
407
try
408
{
409
ideal I = (ideal) u->
Data
();
410
gfan::ZVector* weightVector;
411
if
(
v
->Typ() ==
INTVEC_CMD
)
412
{
413
intvec
* w0 = (
intvec
*)
v
->Data();
414
bigintmat
* w1 =
iv2bim
(w0,
coeffs_BIGINT
);
415
w1->
inpTranspose
();
416
weightVector =
bigintmatToZVector
(*w1);
417
delete
w1;
418
}
419
else
420
{
421
bigintmat
* w1 = (
bigintmat
*)
v
->Data();
422
weightVector =
bigintmatToZVector
(*w1);
423
}
424
res
->rtyp =
IDEAL_CMD
;
425
res
->data = (
void
*)
initial
(I,
currRing
, *weightVector);
426
delete
weightVector;
427
return
FALSE
;
428
}
429
catch
(
const
std::exception& ex)
430
{
431
Werror
(
"ERROR: %s"
,ex.what());
432
return
TRUE
;
433
}
434
}
435
}
436
WerrorS
(
"initial: unexpected parameters"
);
437
return
TRUE
;
438
}
439
440
441
void
tropical_setup
(
SModulFunctions
*
p
)
442
{
443
p
->iiAddCproc(
"tropical.lib"
,
"groebnerConeInternal"
,
FALSE
,
groebnerCone
);
444
p
->iiAddCproc(
"tropical.lib"
,
"maximalGroebnerConeInternal"
,
FALSE
,
maximalGroebnerCone
);
445
p
->iiAddCproc(
"tropical.lib"
,
"homogeneitySpaceInternal"
,
FALSE
,
homogeneitySpace
);
446
// p->iiAddCproc("","lowerHomogeneitySpaceInternal",FALSE,lowerHomogeneitySpace);
447
p
->iiAddCproc(
"tropical.lib"
,
"initialInternal"
,
FALSE
,
initial
);
448
p
->iiAddCproc(
"tropical.lib"
,
"tropicalVarietyInternal"
,
FALSE
,
tropicalVariety
);
449
p
->iiAddCproc(
"tropical.lib"
,
"groebnerFanInternal"
,
FALSE
,
groebnerFan
);
450
p
->iiAddCproc(
"tropical.lib"
,
"groebnerComplexInternal"
,
FALSE
,
groebnerComplex
);
451
// p->iiAddCproc("","ppreduceInitiallyInternal",FALSE,ppreduceInitially);
452
// p->iiAddCproc("","ttreduceInitiallyInternal",FALSE,ttreduceInitially);
453
}
BOOLEAN
int BOOLEAN
Definition
auxiliary.h:88
TRUE
#define TRUE
Definition
auxiliary.h:101
FALSE
#define FALSE
Definition
auxiliary.h:97
equations
BOOLEAN equations(leftv res, leftv args)
Definition
bbcone.cc:577
inequalities
BOOLEAN inequalities(leftv res, leftv args)
Definition
bbcone.cc:560
coneID
VAR int coneID
Definition
bbcone.cc:25
bbcone.h
iv2bim
bigintmat * iv2bim(intvec *b, const coeffs C)
Definition
bigintmat.cc:347
intStar2ZVector
gfan::ZVector intStar2ZVector(const int d, const int *i)
Definition
callgfanlib_conversion.cc:86
bigintmatToZVector
gfan::ZVector * bigintmatToZVector(const bigintmat &bim)
Definition
callgfanlib_conversion.cc:73
callgfanlib_conversion.h
i
int i
Definition
cfEzgcd.cc:132
p
int p
Definition
cfModGcd.cc:4086
g
g
Definition
cfModGcd.cc:4098
bigintmat
Matrices of numbers.
Definition
bigintmat.h:51
bigintmat::inpTranspose
void inpTranspose()
transpose in place
Definition
bigintmat.cc:48
groebnerCone
Definition
groebnerCone.h:28
groebnerCone::groebnerCone
groebnerCone()
Definition
groebnerCone.cc:69
intvec
Definition
intvec.h:24
sleftv::Typ
int Typ()
Definition
subexpr.cc:1048
sleftv::Data
void * Data()
Definition
subexpr.cc:1192
sleftv::next
leftv next
Definition
subexpr.h:86
coeffs.h
Coefficient rings, fields and other domains suitable for Singular polynomials.
containsMonomial.h
res
CanonicalForm res
Definition
facAbsFact.cc:60
w
const CanonicalForm & w
Definition
facAbsFact.cc:51
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition
facBivar.h:39
WerrorS
void WerrorS(const char *s)
Definition
feFopen.cc:24
VAR
#define VAR
Definition
globaldefs.h:5
IDEAL_CMD
@ IDEAL_CMD
Definition
grammar.cc:285
BIGINTMAT_CMD
@ BIGINTMAT_CMD
Definition
grammar.cc:278
POLY_CMD
@ POLY_CMD
Definition
grammar.cc:290
groebnerComplex
gfan::ZFan * groebnerComplex(const tropicalStrategy currentStrategy)
Definition
groebnerComplex.cc:11
groebnerComplex.h
groebnerFan
gfan::ZFan * groebnerFan(const tropicalStrategy currentStrategy)
Definition
groebnerFan.cc:28
groebnerFan.h
initial
poly initial(const poly p, const ring r, const gfan::ZVector &w)
Returns the initial form of p with respect to w.
Definition
initial.cc:30
initial.h
pIter
#define pIter(p)
Definition
monomials.h:37
pNext
#define pNext(p)
Definition
monomials.h:36
omFreeSize
#define omFreeSize(addr, size)
Definition
omAllocDecl.h:260
omAlloc
#define omAlloc(size)
Definition
omAllocDecl.h:210
NULL
#define NULL
Definition
omList.c:12
p_polys.h
coeffs_BIGINT
VAR coeffs coeffs_BIGINT
Definition
polys.cc:14
currRing
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition
polys.cc:13
ppinitialReduction.h
Werror
void Werror(const char *fmt,...)
Definition
reporter.cc:189
idInit
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition
simpleideals.cc:35
id_Delete
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
Definition
simpleideals.cc:123
IDELEMS
#define IDELEMS(i)
Definition
simpleideals.h:23
startingCone.h
SModulFunctions
Definition
ipid.h:69
leftv
sleftv * leftv
Definition
structs.h:53
INTVEC_CMD
@ INTVEC_CMD
Definition
tok.h:101
tropicalCurves.h
tropicalStrategy.h
implementation of the class tropicalStrategy
tropicalVariety
BOOLEAN tropicalVariety(leftv res, leftv args)
Definition
tropicalVariety.cc:43
tropicalVariety.h
tropical_setup
void tropical_setup(SModulFunctions *p)
Definition
tropical.cc:441
homogeneitySpace
gfan::ZCone homogeneitySpace(ideal I, ring r)
Definition
tropical.cc:19
maximalGroebnerCone
gfan::ZCone maximalGroebnerCone(const ideal &I, const ring &r)
Definition
tropical.cc:291
lowerHomogeneitySpace
gfan::ZCone lowerHomogeneitySpace(ideal I, ring r)
Definition
tropical.cc:85
tropicalVerboseLevel
VAR int tropicalVerboseLevel
Definition
tropical.cc:17
witness.h
Generated on
for My Project by
doxygen 1.18.0
for
Singular