/usr/share/singular/LIB/tropicalNewton.lib is in singular-data 1:4.1.0-p3+ds-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 | ///////////////////////////////////////////////////////////////////////////////
version="version tropical.lib 4.0.3.3 Nov_2016 "; // $Id: 5cf6b6a19bfc3f72916c42f0d8b9890c334149f5 $
category="Tropical Geometry";
info="
LIBRARY: tropicalNewton.lib Computations in Tropical Geometry
using Newton Polygon methods
AUTHORS: Tommy Hofman, email: thofmann@mathematik.uni.kl.de
Yue Ren, email: reny@cs.bgu.ac.il
OVERVIEW:
This libraries contains algorithms for computing
- non-trivial points on tropical varieties,
- zero-dimensional tropical varieties,
- one-codimensional links of tropical varieties
based on Newton polygon methods.
REFERENCES: Hofmann, Ren: Computing tropical points and tropical links, arXiv:1611.02878
(WARNING: this library follows the max convention instead
and triangular sets follow the definition of the Singular book)
SEE ALSO: tropicalVariety, tropical_lib
KEYWORDS: tropical geometry; tropical varieties; Newton polygons
PROCEDURES:
setUniformizingParameter() sets the uniformizingParameter
val() returns valuation of element in ground field
newtonPolygonNegSlopes() returns negative of the Newton Polyong slopes
cccMatrixToPositiveIntvec() helper function to turn a computed valuation vector
into a usable weight vector in Singular
tropicalPointNewton() computes point on tropical variety
switchRingsAndComputeInitialIdeal()
switches rings and computes initial ideal
tropicalVarietyNewton() computes tropical variety of zero-dimensional ideal
tropicalLinkNewton() computes tropical variety that is polyhedral fan
and has codimension one lineality space
";
///////////////////////////////////////////////////////////////////////////////
LIB "gfan.lib";
LIB "triang.lib";
LIB "linalg.lib";
///////////////////////////////////////////////////////////////////////////////
proc setUniformizingParameter(number p)
"USAGE: setUniformizingParameter(p); p number
RETURN: none, sets the uniformizing parameter as p
ASSUME: char(K)==0 and p prime number or
trdeg(K)>0 and p transcendental variable or
p==0
EXAMPLE: example setUniformizingParameter; shows an example
"
{
// kill uniformizingParemeter if previously defined
if (defined(uniformizingParameter))
{
kill uniformizingParameter;
}
// input sanity check
if (p!=0)
{
if (pardeg(p)==0)
{
if(char(basering)!=0 && prime(int(p))!=p)
{
ERROR("setUniformizingParameter: unexpected parameters");
}
}
else
{
if (size(p)!=2 || pardeg(p)!=1)
{
ERROR("setUniformizingParameter: unexpected parameters");
}
}
}
// set uniformizingParameter and export it
number uniformizingParameter = p;
export(uniformizingParameter);
}
example
{ "EXAMPLE:"; echo = 2;
// poor man's polynomials over Puiseux series:
ring r = (0,t),x,dp;
setUniformizingParameter(t);
val(t2+t3);
val(t^-2+t^-3);
// poor man's polynomials over p-adic numbers:
ring s = 0,x,dp;
setUniformizingParameter(2);
val(12);
val(1/12);
}
proc val(number c)
"USAGE: val(c); c number
RETURN: int, the valuation of a element in the ground field
ASSUME: uniformizingParameter is set and c!=0
EXAMPLE: example val; shows an example
"
{
if (defined(uniformizingParameter)==0)
{
ERROR("val: uniformizingParameter not set");
}
if (c==0)
{
ERROR("val: input is 0");
}
if (uniformizingParameter==0)
{
return (0);
}
int vc = 0;
if (pardeg(uniformizingParameter)>0)
{
def origin = basering;
number c_denom = denominator(c);
number c_num = numerator(c);
execute("ring r_Val=0,"+string(uniformizingParameter)+",ds");
poly c_denom = imap(origin,c_denom);
poly c_num = imap(origin,c_num);
vc = ord(c_num)-ord(c_denom);
setring origin;
}
else
{
int c_denom = int(denominator(c));
int c_num = int(numerator(c));
int p = int(uniformizingParameter);
while (c_num mod p==0)
{
c_num = c_num div p;
vc++;
}
while (c_denom mod p==0)
{
c_denom = c_denom div p;
vc--;
}
}
return (vc);
}
example
{ "EXAMPLE:"; echo = 2;
// poor man's polynomials over Puiseux series:
ring r = (0,t),x,dp;
setUniformizingParameter(t);
val(t2+t3);
val(t^-2+t^-3);
// poor man's polynomials over p-adic numbers:
ring s = 0,x,dp;
setUniformizingParameter(2);
val(12);
val(1/12);
}
proc newtonPolygonNegSlopes(poly g, list #)
"USAGE: newtonPolygonNegSlopes(g,b); g poly, b int
RETURN: list, the negative slopes of the Newton Polygon of g
if b==1, computes root (type poly) instead if (easily) possible
ASSUME: uniformizingParameter is set and g univariate
EXAMPLE: example newtonPolygonNegSlopes; shows an example
"
{
if (size(#)>0)
{
if (#[1]==1 && size(g)==2)
{
if (deg(g[1])==1 && deg(g[2])==0)
{
poly root = -leadcoef(g[2])/leadcoef(g[1]);
return (list(root));
}
}
}
if (defined(uniformizingParameter)==0)
{
ERROR("newtonPolygonNegSlopes: uniformizingParameter not set");
}
int k = size(g);
intmat M [k+1][3];
for (int i=1; i<=k; i++)
{
M[i,1] = 1;
M[i,2] = deg(g[i]);
M[i,3] = val(leadcoef(g[i]));
}
M[k+1,1] = 0;
M[k+1,2] = 0;
M[k+1,3] = 1;
cone Delta = coneViaPoints(M);
bigintmat F = facets(Delta);
list slopes;
number slope;
for (i=1; i<=nrows(F); i++)
{
if (F[i,3]!=0)
{
slope = number(F[i,2])/number(F[i,3]);
slopes[size(slopes)+1] = slope;
}
}
return (slopes);
}
example
{ "EXAMPLE:"; echo = 2;
ring r = (0,t),x,dp;
setUniformizingParameter(t);
poly g = tx2+x+1;
newtonPolygonNegSlopes(g);
// poor man's polynomials over p-adic numbers:
ring s = 0,x,dp;
setUniformizingParameter(3);
poly g = x2+9x+1;
newtonPolygonNegSlopes(g);
}
static proc listDot(list VV, intvec expv)
{
number ld;
for (int i=1; i<=size(expv); i++)
{
if (expv[i]>0)
{
if (typeof(VV[i])=="number")
{
ld = ld + VV[i]*expv[i];
}
else
{
ERROR("listDot: unkown or invalid relevant entry");
}
}
}
return (ld);
}
static proc lexSmallestVariableIndex(poly g)
{
intvec alpha = leadexp(g);
for (int i=1; i<=nvars(basering); i++)
{
if (alpha[i]>0)
{
return (i);
}
}
return (-1);
}
static proc numbersLessThanAsRationalNumbers(number a, number b)
{
int a_num = int(numerator(a));
int a_denom = int(denominator(a));
int b_num = int(numerator(b));
int b_denom = int(denominator(b));
return (a_num*b_denom-b_num*a_denom<0);
}
static proc expectedValuation(poly h, list VV)
{
number vh = val(leadcoef(h[1]))+listDot(VV,leadexp(h[1]));
number vhh;
int amb = 0;
for (int i=2; i<=size(h); i++)
{
vhh = val(leadcoef(h[i]))+listDot(VV,leadexp(h[i]));
if (vh == vhh)
{
amb = 1;
}
if (numbersLessThanAsRationalNumbers(vhh,vh))
{
vh = vhh;
amb = 0;
}
}
if (amb > 0)
{
"h:"; h;
"VV:"; VV;
ERROR("expectedValuation: valuation ambiguous");
}
return (vh);
}
static proc expectedNewtonPolygonNegSlopes(poly g, list VV, list #)
{
int k = size(VV);
for (int i=1; i<=size(VV); i++)
{
if (typeof(VV[i])=="poly")
{
g = subst(g,var(i),VV[i]);
}
}
if (size(#)>0)
{
if (#[1]==1 && size(g)==2)
{
if (deg(g[1])==1 && deg(g[2])==0)
{
poly root = -leadcoef(g[2])/leadcoef(g[1]);
return (list(root));
}
}
}
int n = lexSmallestVariableIndex(g);
matrix G = coef(g,var(n));
k = ncols(G);
intmat M[k+1][3];
number vh;
for (i=1; i<=k; i++)
{
vh = expectedValuation(G[2,i],VV);
M[i,1] = int(denominator(vh));
M[i,2] = deg(G[1,i]);
M[i,3] = int(numerator(vh));
}
M[k+1,1] = 0;
M[k+1,2] = 0;
M[k+1,3] = 1;
cone Delta = coneViaPoints(M);
bigintmat F = facets(Delta);
list slopes;
number slope;
for (i=1; i<=nrows(F); i++)
{
if (F[i,3]!=0)
{
slope = number(F[i,2])/number(F[i,3]);
slopes[size(slopes)+1] = slope;
}
}
return (slopes);
}
static proc randomValuedNumber(list #)
{
int n = 99;
if (size(#)>0)
{
n = #[1];
}
int v = random(0,n);
number c = random(1,99)*uniformizingParameter^v;
c = c+random(0,99)*uniformizingParameter^(v+random(0,n div 3));
c = c+random(0,99)*uniformizingParameter^(v+random(0,n div 3));
return (c);
}
static proc listOfNumbersToMatrix(list L)
{
int k = size(L);
matrix Lmat[1][k];
for (int i=1; i<=k; i++)
{
if (typeof(L[i]) == "number")
{
Lmat[1,i] = L[i];
}
if (typeof(L[i]) == "poly")
{
Lmat[1,i] = val(number(L[i]));
}
}
return (Lmat);
}
proc cccMatrixToPositiveIntvec(matrix L)
"USAGE: cccMatrixToPositiveIntvec(M); M matrix
RETURN: intvec, strictly positive equivalent as weight vector to row vector in M
ASSUME: constant coefficient case only,
will scale weight vector and add vectors of ones to it
EXAMPLE: example cccMatrixToPositiveIntvec; shows an example
"
{
int k = ncols(L);
intvec denoms;
intvec enums;
int denoms_gcd = int(denominator(number(L[1,1])));
int denoms_prod = int(denominator(number(L[1,1])));
for (int i=2; i<=k; i++)
{
denoms_gcd = gcd(denoms_gcd,int(denominator(number(L[1,i]))));
denoms_prod = denoms_prod*int(denominator(number(L[1,i])));
}
int denoms_lcm = denoms_prod div denoms_gcd;
intvec w;
for (i=1; i<=k; i++)
{
w[i] = int(number(L[1,i])*denoms_lcm);
}
return (addOneVectorUntilPositive(w));
}
example
{ "EXAMPLE:"; echo = 2;
ring r = (0,t),(p01,p02,p12,p03,p13,p23,p04,p14,p24,p34),dp;
number uniformizingParameter = t;
export(uniformizingParameter);
ideal I =
p23*p14-p13*p24+p12*p34,
p23*p04-p03*p24+p02*p34,
p13*p04-p03*p14+p01*p34,
p12*p04-p02*p14+p01*p24,
p12*p03-p02*p13+p01*p23;
system("--random",1337);
matrix p = tropicalPointNewton(I);
print(p);
intvec w = cccMatrixToPositiveIntvec(p);
print(w);
def s = switchRingsAndComputeInitialIdeal(I,w);
kill uniformizingParameter;
}
static proc oneVector(int n)
{
intvec w;
for (int i=1; i<=n; i++)
{
w[i] = 1;
}
return (w);
}
static proc addOneVectorUntilPositive(intvec w)
{
int n = size(w);
int w_min = w[1];
for (int i=2; i<=n; i++)
{
if (w[i]<w_min)
{
w_min = w[i];
}
}
return (w-(w_min-1)*oneVector(n));
}
proc tropicalPointNewton(ideal I, list #)
"USAGE: tropicalPointsLasVegas(I); I ideal
RETURN: matrix, a matrix containing a tropical point as row vector
ASSUME: uniformizingParameter is set and I monomial free
NOTE: if printlevel sufficiently high will print intermediate data and timings
returns error if randomly chosen hyperplanes are not generic
EXAMPLE: example tropicalPointNewton; shows an example
"
{
if (defined(uniformizingParameter)==0)
{
ERROR("tropicalPointNewton: uniformizingParameter not set");
}
int ttotal = timer;
ring origin = basering;
int tindepSet = timer;
ideal stdI = std(I);
attrib(stdI,"isSB",1);
intvec u = indepSet(stdI);
tindepSet = timer - tindepSet;
dbprint("maximal independent set: "+string(u));
int n = nvars(origin);
string vars;
string subststr = "ideal J = subst(I,";
list VV;
number c;
for (int i=1; i<=n; i++)
{
if (u[i]==0)
{
vars = vars+varstr(i)+",";
}
else
{
c = randomValuedNumber(#);
VV[i]=number(val(c));
dbprint("substituting "+string(var(i))+" with number of valuation "+string(VV[i]));
subststr = subststr+varstr(i)+","+string(c)+",";
}
}
vars = vars[1..size(vars)-1];
subststr = string(subststr[1..size(subststr)-1])+");";
execute(subststr);
execute("ring s = ("+charstr(origin)+"),("+vars+"),lp;");
ideal J = imap(origin,J);
int tstdlp = timer;
dbprint("computing triangular decomposition (picking first factor)");
J = satstd(J);
attrib(J,"isSB",1);
if (dim(J)>0)
{
dbprint("not zero-dimensional, please restart algorithm");
bigintmat O[1][1];
return (O);
}
if (!isTriangularSet(J))
{
J = triangL(J)[1];
}
tstdlp = timer - tstdlp;
dbprint("starting analysis of Newton polygons");
setring origin;
J = imap(s,J);
int tnewton = timer;
list Vlocal = newtonPolygonNegSlopes(J[1],1);
int l = lexSmallestVariableIndex(J[1]);
VV[l] = Vlocal[1];
dbprint("possible valuations for "+string(var(l))+" (picking first): "+string(Vlocal));
for (i=2; i<=size(J); i++)
{
Vlocal = expectedNewtonPolygonNegSlopes(J[i],VV,1);
l = lexSmallestVariableIndex(J[i]);
dbprint("possible valuations for "+string(var(l))+" (picking first): "+string(Vlocal));
VV[l] = Vlocal[1];
}
tnewton = timer-tnewton;
matrix w = -listOfNumbersToMatrix(VV);
ttotal = timer-ttotal;
dbprint("time used total: "+string(ttotal));
dbprint("computing independent set: "+string(tindepSet));
dbprint("computing triangular decomposition: "+string(tstdlp));
dbprint("analyzing newton polygons: "+string(tnewton));
return (w);
}
example
{ "EXAMPLE:"; echo = 2;
ring r = (0,t),(p01,p02,p12,p03,p13,p23,p04,p14,p24,p34),dp;
number uniformizingParameter = t;
export(uniformizingParameter);
ideal I =
p23*p14-p13*p24+p12*p34,
p23*p04-p03*p24+p02*p34,
p13*p04-p03*p14+p01*p34,
p12*p04-p02*p14+p01*p24,
p12*p03-p02*p13+p01*p23;
system("--random",1337);
printlevel = 3;
matrix p = tropicalPointNewton(I);
print(p);
intvec w = cccMatrixToPositiveIntvec(p);
print(w);
def s = switchRingsAndComputeInitialIdeal(I,w);
kill uniformizingParameter;
}
static proc sumOfLeadExpV(poly f)
{
intvec expvSum;
expvSum = leadexp(f[1]);
for (int i=2; i<=size(f); i++)
{
expvSum = expvSum + leadexp(f[i]);
}
return (expvSum);
}
static proc isTriangularSet(ideal F)
{
// checks whether F has the right amount of elements
int n = size(F);
if (n!=nvars(basering))
{
return (0);
}
int i,j;
poly fi;
intvec expvSum;
for (i=1; i<=n; i++)
{
fi = F[i];
expvSum = sumOfLeadExpV(fi);
// checks whether fi has monomial containing x_i
if (expvSum[n-i+1]==0)
{
return (0);
}
// checks whether fi has no monomial containing x_j, j>i
for (j=i+1; j<=n; j++)
{
if (expvSum[n-j+1]>0)
{
return (0);
}
}
}
return (1);
}
proc tropicalVarietyNewton(ideal I)
"USAGE: tropicalVarietyNewton(I); I ideal
RETURN: matrix, a matrix containing all elements of the tropical variety
ASSUME: uniformizingParameter is set, I monomial free and zero-dimensional
EXAMPLE: example tropicalVarietyNewton; shows an example
"
{
if (defined(uniformizingParameter)==0)
{
ERROR("tropicalVarietyNewton: uniformizingParameter not set");
}
if(ordstr(basering)[1,2]!="lp")
{
ERROR("tropicalVarietyNewton: order must be lp");
}
if (!isTriangularSet(I))
{
I = satstd(I);
attrib(I,"isSB",1);
if (!isTriangularSet(I))
{
list triangI = triangL(I);
}
else
{
list triangI = I;
}
}
else
{
list triangI = I;
}
int i,ii,j,jj,k,l;
list Vlocal;
ideal J;
list VV;
for (ii=1; ii<=size(triangI); ii++)
{
J = triangI[ii];
Vlocal = newtonPolygonNegSlopes(J[1],1);
for (jj=1; jj<=size(Vlocal); jj++)
{
list Vjj;
l = lexSmallestVariableIndex(J[1]);
Vjj[l] = Vlocal[jj];
VV[jj] = Vjj;
kill Vjj;
}
for (i=2; i<=size(J); i++)
{
k = size(VV);
for (jj=1; jj<=k; jj++)
{
list Vlocal(jj) = expectedNewtonPolygonNegSlopes(J[i],VV[jj],1);
}
l = lexSmallestVariableIndex(J[i]);
for (jj=1; jj<=k; jj++)
{
for (j=1; j<=size(Vlocal(jj)); j++)
{
if (j==1)
{
VV[jj][l] = Vlocal(jj)[1];
}
else
{
VV[size(VV)+1] = VV[jj];
VV[size(VV)][l] = Vlocal(jj)[j];
}
}
}
for (jj=1; jj<=k; jj++)
{
kill Vlocal(jj);
}
}
}
list TI;
list VVjj;
for (jj=1; jj<=size(VV); jj++)
{
VVjj = VV[jj];
matrix Vjj[1][size(VVjj)] = VVjj[1..size(VVjj)];
TI[jj] = -Vjj;
kill Vjj;
}
return (TI);
}
example
{ "EXAMPLE:"; echo = 2;
ring r = (0,t),(z,y,x),lp;
number uniformizingParameter = t;
export(uniformizingParameter);
ideal I = tx2+x+1,txy2+xy+1,xyz+1;
list TI = tropicalVarietyNewton(I);
for (int i=1; i<=size(TI); i++)
{ print(TI[i]); }
kill uniformizingParameter;
}
proc switchRingsAndComputeInitialIdeal(ideal I, intvec w)
"USAGE: switchRingsAndComputeInitialIdeal(I,w); I ideal, w intvec
RETURN: ring, a ring containing the initial ideal with respect to w
ASSUME: constant coefficient case and w strictly positive integer
NOTE: if printlevel sufficiently high will print timing
EXAMPLE: example switchRingsAndComputeInitialIdeal; shows an example
"
{
def origin = basering;
intvec wOne = oneVector(nvars(origin));
execute("ring rInitialIdeal = ("+charstr(origin)+"),("+varstr(origin)+"),(a(wOne),wp(w));");
ideal I = imap(origin,I);
int tinI = timer;
option(redSB);
ideal stdI = satstd(I);
ideal inI = initial(stdI,w);
tinI = timer-tinI;
dbprint("time used computing initial ideal: "+string(tinI));
export(I);
export(stdI);
export(inI);
return (rInitialIdeal);
}
example
{ "EXAMPLE:"; echo = 2;
ring r = (0,t),(p01,p02,p12,p03,p13,p23,p04,p14,p24,p34),dp;
number uniformizingParameter = t;
export(uniformizingParameter);
ideal I =
p23*p14-p13*p24+p12*p34,
p23*p04-p03*p24+p02*p34,
p13*p04-p03*p14+p01*p34,
p12*p04-p02*p14+p01*p24,
p12*p03-p02*p13+p01*p23;
system("--random",1337);
printlevel = 3;
matrix p = tropicalPointNewton(I);
print(p);
intvec w = cccMatrixToPositiveIntvec(p);
print(w);
def s = switchRingsAndComputeInitialIdeal(I,w);
kill uniformizingParameter;
}
static proc pivotIndices(matrix H)
{
intvec p;
p[ncols(H)]=0;
int pp;
int i,j;
for (i=1; i<=ncols(H); i++)
{
for (j=nrows(H); j>=0; j--)
{
if (H[j,i]!=0)
{
if (j>pp)
{
p[i] = 1;
pp = j;
}
break;
}
}
}
return (p);
}
static proc varstrIntvec(intvec p)
{
string s;
for (int i=1; i<=size(p); i++)
{
s = s+varstr(p[i])+",";
}
s = s[1..size(s)-1];
return (s);
}
static proc substRing(int i, string orderstring)
{
int n = nvars(basering);
if (i==1)
{
intvec p = 2..n;
}
else
{
if (i==n)
{
intvec p = 1..n-1;
}
else
{
intvec p = 1..i-1,i+1..n;
}
}
execute("ring ssub = (0,t),("+varstrIntvec(p)+"),"+orderstring+";");
return (ssub);
}
static proc extendTropNewton(matrix Ti, int i, number toAdd, intvec toFill)
{
// extend TI by one, inserting toAdd in position i
int n = ncols(Ti)+1;
matrix Tii[1][n];
Tii[1,i] = toAdd;
if (i==1)
{
Tii[1,2..n] = Ti[1,1..n-1];
}
else
{
if (i==n)
{
Tii[1,1..n-1] = Ti[1,1..n-1];
}
else
{
Tii[1,1..i-1] = Ti[1,1..i-1];
Tii[1,i+1..n] = Ti[1,i..n-1];
}
}
// extend Tii, inserting 0 in the 1 positions of toFill
n = n+sum(toFill);
matrix Tiii[1][n];
int TiiCounter=1;
for (int j=1; j<=n; j++)
{
if (toFill[j]==1)
{
Tiii[1,j]=0;
}
else
{
Tiii[1,j]=Tii[1,TiiCounter];
TiiCounter++;
}
}
return (Tiii);
}
static proc mergeTropNewton(list T, list Ti, int i, number toAdd, intvec toFill)
{
int ii,j;
matrix Tii;
for (ii=1; ii<=size(Ti); ii++)
{
Tii=extendTropNewton(Ti[ii],i,toAdd,toFill);
for (j=1; j<=size(T); j++)
{
if (T[j]==Tii)
{
break;
}
}
if (j>size(T))
{
T[size(T)+1] = Tii;
}
}
return (T);
}
proc tropicalLinkNewton(ideal inI)
"USAGE: tropicalLinkNewton(inI); inI ideal
RETURN: matrix, a matrix containing generators of all rays of the tropical variety
ASSUME: constant coefficient case, inI is monomial free,
its tropical variety has codimension one lineality space and
is a polyhedral fan
NOTE: if printlevel sufficiently high will print intermediate results
EXAMPLE: example tropicalLinkNewton; shows an example
"
{
ring origin=basering;
dbprint("reducing to one-dimensional fan");
cone C0 = homogeneitySpace(inI);
intmat HH = intmat(generatorsOfLinealitySpace(C0));
matrix H = gauss_nf(HH);
intvec p = pivotIndices(H);
string resVars;
ideal resImage;
for (int i=1; i<=nvars(basering); i++)
{
if (p[i]==1)
{
resImage[i]=1;
}
else
{
resImage[i]=var(i);
resVars = resVars+varstr(i)+",";
}
}
resVars = resVars[1..size(resVars)-1];
execute("ring srestr = ("+string(char(origin))+",t),("+resVars+"),dp;");
number uniformizingParameter = t;
map resMap = origin,imap(origin,resImage);
ideal inI = resMap(inI);
inI = satstd(inI);
dbprint("intersecting with pairs of affine hyperplanes");
ideal substImagePos;
ideal substImageNeg;
int n = nvars(srestr);
list T;
int j;
for (i=1; i<=n; i++)
{
setring srestr;
substImagePos = maxideal(1);
substImagePos[i] = t;
substImageNeg = maxideal(1);
substImageNeg[i] = t^(-1);
def ssubstDP = substRing(i,"dp");
setring ssubstDP;
ideal substImagePos = imap(srestr,substImagePos);
map substMapPos = srestr,substImagePos;
ideal inIPos = substMapPos(inI);
if (dim(std(inIPos))<0)
{
setring srestr;
kill ssubstDP;
dbprint(string(i)+": empty");
i++;
continue;
}
dbprint(string(i)+": non-empty, computing tropical variety");
setring srestr;
kill ssubstDP;
def ssubstLP = substRing(i,"lp");
setring ssubstLP;
ideal substImagePos = imap(srestr,substImagePos);
map substMapPos = srestr,substImagePos;
ideal inIPos = std(substMapPos(inI));
number uniformizingParameter=t;
export(uniformizingParameter);
list Tpos = tropicalVarietyNewton(inIPos);
ideal substImageNeg = imap(srestr,substImageNeg);
map substMapNeg = srestr,substImageNeg;
ideal inINeg = std(substMapNeg(inI));
list Tneg = tropicalVarietyNewton(inINeg);
setring srestr;
list Tpos = imap(ssubstLP,Tpos);
list Tneg = imap(ssubstLP,Tneg);
kill ssubstLP;
T = mergeTropNewton(T,Tpos,i,number(1),p);
T = mergeTropNewton(T,Tneg,i,number(-1),p);
dbprint("total number of rays: "+string(size(T)));
kill Tpos;
kill Tneg;
}
setring origin;
return(imap(srestr,T));
}
example
{ "EXAMPLE:"; echo = 2;
// a 10 valent facet in tropical Grass(3,7)
ring r = (0,t),
(p012,p013,p023,p123,p014,p024,p124,p034,p134,p234,
p015,p025,p125,p035,p135,p235,p045,p145,p245,p345,
p016,p026,p126,p036,p136,p236,p046,p146,p246,p346,
p056,p156,p256,p356,p456),
wp(4,7,5,7,4,4,4,7,5,7,2,1,2,4,4,4,2,1,2,4,7,5,7,7,
5,7,7,5,7,4,4,4,4,4,4);
number uniformizingParameter = t;
export(uniformizingParameter);
ideal inI =
p345*p136+p134*p356, p125*p045+p015*p245, p124*p015-p014*p125,
p135*p245-p125*p345, p135*p045+p015*p345, p124*p045+p014*p245,
p024*p125-p012*p245, p145*p236-p124*p356, p124*p135-p123*p145,
p024*p015+p012*p045, p134*p026+p023*p146-p024*p136,
p145*p036+p014*p356, p014*p135-p013*p145, p234*p145+p124*p345,
p034*p145-p014*p345, p024*p135-p012*p345, p125*p035+p015*p235,
p235*p045-p035*p245, p234*p136-p134*p236, p134*p036-p034*p136,
p146*p356-p136*p456, p135*p146-p134*p156,
p135*p026+p023*p156+p012*p356, p124*p035+p014*p235,
p123*p025+p012*p235, p013*p025-p012*p035, p345*p146+p134*p456,
p125*p036+p015*p236, p345*p026-p023*p456+p024*p356,
p123*p015-p013*p125, p234*p025-p024*p235, p034*p025-p024*p035,
p234*p125+p123*p245, p245*p036-p045*p236, p123*p045+p013*p245,
p034*p125-p013*p245, p234*p015+p013*p245, p245*p156+p125*p456,
p034*p015+p013*p045, p045*p156-p015*p456, p135*p236-p123*p356,
p235*p146-p134*p256, p135*p036+p013*p356, p124*p036+p014*p236,
p123*p014-p013*p124, p035*p146-p134*p056, p145*p126+p124*p156,
p234*p045-p034*p245, p235*p026+p023*p256-p025*p236,
p145*p016+p014*p156, p035*p026+p023*p056-p025*p036,
p345*p236+p234*p356, p234*p135+p123*p345, p345*p036+p034*p356,
p034*p135-p013*p345, p345*p156+p135*p456, p124*p034+p014*p234,
p145*p246-p124*p456, p123*p024+p012*p234, p145*p046+p014*p456,
p013*p024-p012*p034, p024*p156+p012*p456, p125*p056+p015*p256,
p245*p056-p045*p256, p236*p146-p136*p246, p134*p126+p123*p146,
p136*p046-p036*p146, p235*p036-p035*p236, p134*p016+p013*p146,
p123*p035+p013*p235, p235*p156-p135*p256,
p123*p026-p023*p126+p012*p236, p135*p056-p035*p156,
p023*p016-p013*p026+p012*p036, p124*p056+p014*p256,
p234*p146-p134*p246, p025*p126-p012*p256, p134*p046-p034*p146,
p025*p016+p012*p056, p234*p035-p034*p235, p345*p256+p235*p456,
p234*p026+p023*p246-p024*p236, p345*p056+p035*p456,
p034*p026+p023*p046-p024*p036, p125*p016-p015*p126,
p025*p246-p024*p256, p025*p046-p024*p056, p245*p126-p125*p246,
p125*p046+p015*p246, p045*p126+p015*p246, p245*p016-p015*p246,
p045*p016-p015*p046, p123*p036+p013*p236, p236*p156+p126*p356,
p135*p126+p123*p156, p036*p156-p016*p356, p135*p016+p013*p156,
p124*p016-p014*p126, p235*p056-p035*p256, p245*p046-p045*p246,
p234*p036-p034*p236, p123*p034+p013*p234, p246*p356-p236*p456,
p234*p156-p123*p456, p135*p246-p123*p456, p345*p126-p123*p456,
p046*p356-p036*p456, p034*p156+p013*p456, p135*p046+p013*p456,
p345*p016-p013*p456, p124*p046+p014*p246, p024*p126-p012*p246,
p024*p016+p012*p046, p345*p246+p234*p456, p345*p046+p034*p456,
p235*p126+p123*p256, p236*p056-p036*p256, p123*p056+p013*p256,
p035*p126-p013*p256, p235*p016+p013*p256, p035*p016+p013*p056,
p235*p246-p234*p256, p234*p056-p034*p256, p035*p246-p034*p256,
p235*p046-p034*p256, p035*p046-p034*p056, p126*p036+p016*p236,
p123*p016-p013*p126, p234*p126+p123*p246, p236*p046-p036*p246,
p123*p046+p013*p246, p034*p126-p013*p246, p234*p016+p013*p246,
p246*p156+p126*p456, p034*p016+p013*p046, p046*p156-p016*p456,
p234*p046-p034*p246, p126*p056+p016*p256, p246*p056-p046*p256,
p126*p046+p016*p246, p024*p235*p145+p124*p025*p345,
p024*p035*p145-p014*p025*p345, p123*p145*p245-p124*p125*p345,
p013*p145*p245-p014*p125*p345, p013*p045*p145+p014*p015*p345,
p024*p235*p136-p134*p025*p236, p123*p245*p136+p134*p125*p236,
p013*p245*p136+p134*p015*p236, p034*p245*p136-p134*p045*p236,
p134*p156*p356-p135*p136*p456, p123*p145*p146-p124*p134*p156,
p013*p145*p146-p014*p134*p156, p013*p145*p026+p023*p014*p156+p012*p014*p356,
p124*p025*p156+p012*p145*p256, p012*p145*p056-p014*p025*p156,
p024*p145*p256-p124*p025*p456, p024*p145*p056+p014*p025*p456,
p034*p235*p136-p134*p035*p236, p134*p256*p356-p235*p136*p456,
p134*p056*p356-p035*p136*p456, p025*p036*p146-p024*p136*p056,
p013*p125*p026-p023*p015*p126+p012*p015*p236,
p123*p245*p146+p134*p125*p246, p013*p245*p146+p134*p015*p246,
p013*p245*p026-p023*p015*p246-p012*p045*p236,
p013*p045*p026-p023*p015*p046-p012*p045*p036,
p034*p245*p146-p134*p045*p246, p013*p124*p026-p023*p014*p126+p012*p014*p236,
p013*p145*p056-p014*p035*p156, p024*p256*p356-p025*p236*p456,
p024*p056*p356-p025*p036*p456, p234*p256*p356-p235*p236*p456,
p034*p256*p356-p035*p236*p456, p034*p056*p356-p035*p036*p456,
p012*p235*p145*p245+p124*p025*p125*p345,
p012*p035*p145*p245-p014*p025*p125*p345,
p012*p035*p045*p145+p014*p015*p025*p345,
p012*p235*p245*p136-p134*p025*p125*p236,
p012*p035*p245*p136+p134*p015*p025*p236,
p024*p035*p245*p136-p134*p025*p045*p236,
p014*p025*p125*p156+p012*p015*p145*p256,
p012*p145*p245*p256-p124*p025*p125*p456,
p012*p045*p145*p256+p014*p025*p125*p456,
p012*p245*p256*p356-p025*p125*p236*p456,
p012*p045*p256*p356+p015*p025*p236*p456,
p012*p045*p056*p356+p015*p025*p036*p456,
p123*p245*p256*p356+p125*p235*p236*p456,
p013*p245*p256*p356+p015*p235*p236*p456,
p013*p045*p256*p356+p015*p035*p236*p456,
p013*p045*p056*p356+p015*p035*p036*p456;
system("--random",1337);
printlevel = 3;
list TinI = tropicalLinkNewton(inI);
for (int i=1; i<=size(TinI); i++)
{ print(TinI[i]); }
}
// disabled routines to check characteristic-freeness of tropical points
// proc saturateWithRespectToVariable(ideal I, int k)
// {
// ASSUME(1,k>=1);
// ASSUME(1,k<=nvars(basering));
// def origin = basering;
// int n = nvars(basering);
// intvec weightVector = ringlist(origin)[3][1][2];
// string newVars;
// for (int i=1; i<k; i++)
// {
// newVars = newVars+string(var(i))+",";
// }
// for (i=k+1; i<=n; i++)
// {
// newVars = newVars+string(var(i))+",";
// }
// newVars = newVars+string(var(k));
// execute("ring ringForSaturation = ("+charstr(origin)+"),("+newVars+"),dp;");
// ideal I = satstd(imap(origin,I));
// if (I==-1)
// {
// return (-1);
// }
// I = simplify(I,2+4+32);
// setring origin;
// I = imap(ringForSaturation,I);
// return (I);
// }
// proc stepwiseSaturation(ideal I)
// {
// if (I!=1)
// {
// list variablesToBeSaturated;
// int l = nvars(basering);
// for (int i=1; i<=l; i++)
// { variablesToBeSaturated[i]=l-i+1; }
// while (size(variablesToBeSaturated)>0)
// {
// dbprint("variablesToBeSaturated: "+string(variablesToBeSaturated));
// I = saturateWithRespectToVariable(I,variablesToBeSaturated[1]);
// variablesToBeSaturated = delete(variablesToBeSaturated,1);
// if ((I==1) || (I==-1))
// {
// break;
// }
// }
// }
// return (I);
// }
// proc checkForContainmentInTropicalVariety(ideal I, intvec w, int charInt)
// {
// def origin = basering;
// intvec wOne = oneVector(nvars(origin));
// execute("ring rInitialIdeal = ("+string(charInt)+"),("+varstr(origin)+"),(a(wOne),wp(w));");
// ideal I = imap(origin,I);
// int tinI = timer;
// option(redSB);
// ideal stdI = satstd(I);
// attrib(stdI,"isSB",1);
// ideal inI = initial(stdI,w);
// tinI = timer-tinI;
// dbprint("time used computing initial ideal: "+string(tinI));
// int tsat = timer;
// ideal satinI = stepwiseSaturation(inI);
// tsat = timer-tsat;
// dbprint("time used computing saturation: "+string(tsat));
// export(I);
// export(stdI);
// export(inI);
// export(satinI);
// return (rInitialIdeal);
// }
|