/usr/share/singular/LIB/graphics.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 | //////////////////////////////////////////////////////////////////////////////
version="version graphics.lib 4.0.0.0 Jun_2013 "; // $Id: 36a4d2e5c43fecf40662744669851fd85cbbd2b1 $
category="Visualization";
info="
LIBRARY: graphics.lib Procedures to use Graphics with Mathematica
AUTHOR: Christian Gorzel, gorzelc@math.uni-muenster.de
PROCEDURES:
staircase(fname,I); Mathematica text for displaying staircase of I
mathinit(); string for loading Mathematica's ImplicitPlot
mplot(fname,I[# s]); Mathematica text for various plots
";
///////////////////////////////////////////////////////////////////////////////
proc staircase(string fname,ideal I)
"USAGE: staircase(s,I); s a string, I ideal in two variables
RETURN: string with Mathematica input for displaying staircase diagrams of an
ideal I, i.e. exponent vectors of the initial ideal of I
NOTE: ideal I should be given by a standard basis. Let s=\"\" and copy and
paste the result into a Mathematica notebook.
EXAMPLE: example staircase; shows an example
"
{
intvec v;
int maxx, maxy;
list l;
string s;
string el;
if(nvars(basering)!=2)
{ "-- Error: need two variables ";
return();
}
if (not(attrib(I,"isSB")))
{ " -- Warning: Ideal should be a standardbasis "; newline; }
for(int i=1; i<=ncols(I); i++)
{
if (i>1) { el = el + ",";}
v = leadexp(I[i]);
if (v[1] > maxx) { maxx = v[1];}
if (v[2] > maxy) { maxy = v[2];}
el = el + "{" + string(v) + "}";
}
el = "{" + el + "}";
maxx = maxx + 3;
maxy = maxy + 3;
s = newline +
"Show[Graphics[{" + newline +
"{GrayLevel[0.5],Map[Rectangle[#,{" +
string(maxx) + "," + string(maxy) + "}] &, " + el + "]}," + newline +
"{PointSize[0.03], Map[Point," + el + "]}," + newline +
"Table[Circle[{i,j},0.1],{i,0," +
string(maxx) + "},{j,0," + string(maxy) + "}]}," + newline +
" Axes->True,AspectRatio->Automatic]]";
s = s + endstr(fname);
return(s);
}
example
{ "EXAMPLE:"; echo =2;
ring r0 = 0,(x,y),ls;
ideal I = -1x2y6-1x4y2, 7x6y5+1/2x7y4+6x4y6;
staircase("",std(I));
ring r1 = 0,(x,y),dp;
ideal I = fetch(r0,I);
staircase("",std(I));
ring r2 = 0,(x,y),wp(2,3);
ideal I = fetch(r0,I);
staircase("",std(I));
// Paste the output into a Mathematica notebook
// active evalutation of the cell with SHIFT RETURN
}
///////////////////////////////////////////////////////////////////////////////
proc mathinit()
"USAGE: mathinit();
RETURN: initializing string for loading Mathematica's ImplicitPlot
EXAMPLE: example mathinit; shows an example
"
{
// write("init.m","<< Graphics`ImplicitPlot`");
return("<< Graphics`ImplicitPlot`");
}
example
{ "EXAMPLE:"; echo =2;
mathinit();
// Paste the output into a Mathematica notebook
// active evalutation of the cell with SHIFT RETURN
}
///////////////////////////////////////////////////////////////////////////////
static proc checkshort()
{
ring @r;
}
static proc determvars(ideal I)
// determine the variables which are in the ideal I
{
intvec v;
int i,j,k;
k=1;
for(j=1;j<=size(I);j++)
{ for(i=1;i<=nvars(basering);i++)
{ if(I[j]!=subst(I[j],var(i),0)) {v[k] = i; k++;}
}
}
ring @r=0,x,ls;
poly f;
for(i=1;i<=size(v);i++) // sort VARS
{ f = f + x^v[i]; }
v=0;
for (i=1;i<=size(f);i++)
{v[i]=leadexp(f[i])[1];}
return(v);
}
///////////////////////////////////////////////////////////////////////////////
static proc endstr(string filename)
{ int i;
string suffix,cmd,name;
if(size(filename))
{
for (i=size(filename);i;i--)
{ if (filename[i] == ".") {break;}
}
if (i>0)
{ suffix = filename[i,size(filename)-i+1];
name = ">" + filename[1,i-1]+ ".m";
}
else { print("--Error: Suffix of filename incorrect"); return("");}
// if (suffix ==".m") { cmd = "Display[\" " + filename + "\",% ]";}
if (suffix ==".mps") { cmd = "Display[\" " + filename + "\",%] ";}
if (suffix ==".ps") { cmd = "Display[\" ! psfix > " + filename + "\", %]";}
if (suffix ==".eps")
{ cmd = "Display[\" ! psfix -epsf > " + filename + "\", %]";}
}
return(newline + cmd);
}
///////////////////////////////////////////////////////////////////////////////
proc mplot(string fname,ideal I,list #)
"USAGE: mplot(fname, I [,I1,I2,..,s] ); fname=string; I,I1,I2,..=ideals,
s=string representing the plot region.@*
Use the ideals I1,I2,.. in order to produce multiple plots (they need
to have the same number of entries as I!).
RETURN: string, text with Mathematica commands to display a plot
NOTE: The plotregion is defaulted to -1,1 around zero.
For implicit given curves enter first the string returned by
procedure mathinit into Mathematica in order to load ImplicitPlot.
The following conventions for I are used:
@format
- ideal with 2 entries in one variable means a parametrised plane curve,
- ideal with 3 entries in one variable means a parametrised space curve,
- ideal with 3 entries in two variables means a parametrised surface,
- ideal with 2 entries in two variables means an implicit curve
given as I[1]==I[2],
- ideal with 1 entry (or one polynomial) in two variables means
an implicit curve given as f == 0,
@end format
EXAMPLE: example mplot; shows an example
"
{
int i,j,k,mapping;
int planecurve,spacecurve,implcrv,surface;
intvec VARS,v;
string xpart,ypart,zpart = "-1,1","-1,1","All";
string pstring,actstring,xname,yname,str,closing;
string basr = nameof(basering);
ideal J;
if (ncols(I)>3)
{ "-- Error: can only draw upto dimension 3";
return("");
}
ring @r = 0,(s,t),lp;
ideal @J,@I;
setring(`basr`);
// def d = basering;
// d;
// listvar(d);
str = newline;
VARS = determvars(I);
// "VARS: ";VARS;
if (size(VARS)>2 or VARS==0)
{ "-- Error: Need some variables, but can only draw in 2 or 3 dimensions";
return("");
}
if (size(matrix(I))==1 and size(VARS)==2)
{ i =size(I[1]);
//I[2]=I[1][(i/ 2 + 1)..i]; I[2];
// I[1]=I[1][1..(i/ 2)]; I[1];
I[2]=0;
}
if (size(matrix(I))==2)
{ if (size(VARS)==1) {planecurve=1; str = str + "ParametricPlot[";}
if (size(VARS)==2) {implcrv=1; str = str + "ImplicitPlot[";}
}
if (size(matrix(I))==3)
{ if (size(VARS)==1) {spacecurve=1;}
if (size(VARS)==2) {surface=1;}
str = str + "ParametricPlot3D[";
}
short = 0;
pstring = string(I);
// switch to another ring if necessary
checkshort();
// "short: "; short;
if (short!=1) // construct a map
{
mapping = 1;
setring @r;
@J = 0;
for(i=1;i<=size(VARS);i++)
{ @J[VARS[i]]=var(i);}
map phi = (`basr`,@J);
@I = phi(I);
short =0;
pstring = string(@I);
setring `basr`;
}
i = find(pstring,newline);
while(i)
{pstring[i]=" ";
i = find(pstring,newline,i);
}
if (implcrv)
{ i = find(pstring,",");
pstring = pstring[1,i-1] + "==" + pstring[i+1,size(pstring)-i];
}
else
{ pstring = "{" + pstring + "}";}
// "mapping "; mapping;
if (mapping)
{ xname = "s";
if (size(VARS)==2) {yname="t";}
}
else
{ xname = varstr(VARS[1]);
if (size(VARS)==2) {yname=varstr(VARS[2]);}
}
j =1;
for(k=1;k<=size(#);k++)
{ if (typeof(#[k])=="ideal" or typeof(#[k])=="poly")
{ //#[k] = ideal(#[k]);
v = determvars(#[k]);
J = #[k];
short =0;
if (size(matrix(J))==1 and size(VARS)==2 and implcrv)
{ i =size(J[1]);
// J[2]=J[1][(i/ 2 + 1)..i];
// J[1]=J[1][1..(i/ 2)];
J[2] =0;
}
if ((v!= VARS) or (size(J)!=size(I)))
{ print("--Error: ---- ");
return();
}
else
{ if (mapping)
{ setring @r;
short =0;
actstring = string(phi(J));
setring(`basr`);
}
else {actstring = string(J);}
i = find(actstring,newline);
while(i)
{ actstring[i]=" ";
i = find(actstring,newline,i);
}
if (implcrv)
{i = find(actstring,",");
actstring = actstring[1,i-1]+ "==" + actstring[i+1,size(actstring)-i];
pstring = pstring + "," + actstring;
}
else
{ pstring = pstring + ",{" + actstring +"}";
}
}
}
if (typeof(#[k])=="string")
{ if (j==3) {zpart = #[k];j++;}
if (j==2) {ypart = #[k];j++;}
if (j==1) {xpart = #[k];j++;}
}
}
if (spacecurve or planecurve or implcrv)
{ str = str + "{" + pstring + "},{" + xname + "," + xpart + "}";}
if (implcrv and (j==3)) {str = str + ",{" + yname + "," + ypart + "}";}
if (surface)
{ str = str + "{" + pstring + "},{" + xname + "," + xpart + "},{"
+ yname + "," + ypart + "}";}
if (planecurve) {closing = "," + newline +" AspectRatio->Automatic";}
if (implcrv) {closing = "," + newline +
" AxesLabel->{\"" + varstr(VARS[1]) + "\",\"" + varstr(VARS[2]) + "\"}";}
if (spacecurve) { closing = "," + newline + " ViewPoint->{1.3,-2.4,2}";}
if (surface)
{closing = "," +newline +
" Boxed->True, Axes->True, ViewPoint->{1.3,-2.4,2}";}
str = str + closing + "];" + endstr(fname);
return(str);
}
example
{ "EXAMPLE:"; echo =2;
// --------- plane curves ------------
ring rr0 = 0,x,dp; export rr0;
ideal I = x3 + x, x2;
ideal J = x2, -x+x3;
mplot("",I,J,"-2,2");
// Paste the output into a Mathematica notebook
// active evalutation of the cell with SHIFT RETURN
pause("Hit RETURN to continue");
// --------- space curves --------------
I = x3,-1/10x3+x2,x2;
mplot("",I);
// Paste the output into a Mathematica notebook
// active evalutation of the cell with SHIFT RETURN
pause("Hit RETURN to continue");
// ----------- surfaces -------------------
ring rr1 = 0,(x,y),dp; export rr1;
ideal J = xy,y,x2;
mplot("",J,"-2,1","1,2");
// Paste the output into a Mathematica notebook
// active evalutation of the cell with SHIFT RETURN
kill rr0,rr1;
}
///////////////////////////////////////////////////////////////////////////////
|