This file is indexed.

/usr/share/singular/LIB/surf.lib is in singular-data 4.0.3+ds-1.

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
////////////////////////////////////////////////////////////////////////////
version="version surf.lib 4.0.0.0 Jun_2013 "; // $Id: 4941ace9657fdbc969215d0661db113cf540815e $
category="Visualization";
info="
LIBRARY: surf.lib    Procedures for Graphics with Surf
AUTHOR: Hans Schoenemann, Frank Seelisch

NOTE:
 @texinfo
 Using this library requires the program @code{surf} to be installed.
 You can download @code{surf} either from
  @uref{http://sourceforge.net/projects/surf}
  or from @uref{ftp://www.mathematik.uni-kl.de/pub/Math/Singular/utils/}.
 The procedure surfer requires the program @code{surfer} to be installed.
 You can download @code{surfer} from
  @uref{http://www.imaginary2008.de/surfer.imaginary2008.de}
 @*Under Windows, version 159 or newer of @code{surfer} is required.
 Under Mac OS X please move SURFER.app from http://www.mathematik.uni-kl.de/~motsak/files/SURFER.dmg
 under your /Applications.
 @end texinfo

SEE ALSO: surfex_lib

PROCEDURES:
 plot(I);    plots plane curves and surfaces
 surfer(I);  plots surfaces interactivly
";

///////////////////////////////////////////////////////////////////////////////
proc num_of_vars(ideal I)
"USAGE: num_of_vars(ideal I)

RETURN: an intvec containing one entry for each ring variable.
each contains the sums of all degrees in this variable of all monomials
occuring in the ideal.
An entry is zero if and only if the corresponding variable does not occur in the ideal.
"
{
  intvec v;
  int i;
  poly p;
  for(i=ncols(I);i>0;i--)
  {
    p=I[i];
    while(p!=0)
    {
      v=v+leadexp(p);
      p=p-lead(p);
    }
  }
  return(v);
}
example
{
  "EXAMPLE:"; echo = 2;
  ring r = 0, (x,y,z),dp;
  ideal j0 = x^2-x*y;
  num_of_vars(j0);
  ideal j1 = x^2-x*y-y;
  num_of_vars(j1);
  ideal j2 = x^2-x*y-y, x^3-2*y;
  num_of_vars(j2);
}

proc plot(ideal I,list #)
"USAGE:   plot(I);  I ideal or poly
ASSUME: I defines a plane curve or a surface given by one equation
RETURN: nothing
NOTE: requires the external program `surf` to be installed,
      to close the graphical interface just press `Q`
EXAMPLE: example plot; shows an example
"
{
  string l = "/tmp/surf" + string(system("pid"));
  string err_mes; // string containing error messages
  def base=basering;
  intvec v=num_of_vars(I);
  int i,j,n;
  for(i=size(v);i>0;i--)
  {
    if (v[i]!=0) { n++; }
  }
  if (n==0 or n>3)
  {
    err_mes="Cannot plot equations with "+string(n)+" variables";
    ERROR(err_mes);
  }
  ring r=0,(x,y,z),dp;
  short=0;
  map phi=base,0;
  j=1;
  for(i=1;i<=size(v);i++)
  {
    if (v[i]!=0)
    {
      phi[i]=var(j);
      j++;
      if(j==4) break;
    }
  }
  ideal I=simplify(phi(I),2);
  if (leadcoef(I[1]) <0) { I[1]=-I[1]; }
  if (ncols(I)==1 and n<=2 and nvars(base)!=3) // curve
  {
    write(":w "+l,"clip=none;");
      write(l, "width=500; height=500; set_size; do_background=yes;
               background_red=255; background_green=255;
               background_blue=255;");
    write(l,
    "root_finder=d_chain_bisection;epsilon=0.0000000001;iterations=20000;");
    write(l, "curve_green=0; curve_blue=0; curve_width=1.5;");
    if (size(#)>0)
    {
      write(l,#[1]);
    }
    write(l,"curve=",I[1],";");
    write(l,"draw_curve;");
  }
  else
  {
    if (ncols(I)==1 and (n==3 or nvars(base)==3)) // surface
    {
      write(":w " + l,
            "root_finder=d_chain_bisection;epsilon=0.0000000001;iterations=20000;");
      write(l, "width=500; height=500; set_size; do_background=yes; background_red=255; background_green=255; background_blue=255;");
      write(l, "rot_x=0.14; rot_y=-0.3;");
      if (size(#) > 0)
      {
          write(l, #[1]);
      }
      write(l, "surface=",I[1],";");
      write(l, "draw_surface;");
    }
    else
    {
      err_mes = "cannot plot " + string(ncols(I)) + " equations in "
              + string(n) + " variables";
      ERROR(err_mes);
    }
  }

  string surf_call; i = 0;
  if (isWindows())
  {
    string surferPath = getShellOutput("which surfer");
    if (find(surferPath, "no surfer in") != 0)
    { /* did not find surfer: either not installed or
         not yet included in $PATH variable */
      err_mes = "calling `surfer` failed" + newline
      + " (Either the program Surfer is not installed," + newline
      + "  or it has not yet been included in $PATH.)";
      ERROR(err_mes);
    }
    else
    {
      surf_call = "((xwin -multiwindow -clipboard -silent-dup-error";
      surf_call = surf_call + " >/dev/null 2>&1 &) && sleep 5 && (sinngularsurf ";
      surf_call = surf_call + l + ">/dev/null 2>&1))";
      surf_call = surf_call + "&& command rm " + l;
      "Press q to exit from `surf`.";
        " (You may leave the XServer running for further" + newline
      + "  invocations of `plot`.)";
      i = system("sh", surf_call);
      if (i != 0)
      {
        err_mes = "calling `surf` failed" + newline
                + " (The shell returned the error code "
                + string(i) + "." + newline
                + "  Perhaps the XServer was not properly set up, so" + newline
                + "  try your plot command again. If `plot` fails" + newline
                + "  again, then make sure that the program Surfer" + newline
                + "  is installed and included in your $PATH variable.)";
        ERROR(err_mes);
      }
    }
  }
  else
  {
    surf_call = "singularsurf ";
    surf_call = surf_call + l + " >/dev/null 2>&1";
    "Close window to exit from `singularsurf`.";

    i = system("sh", surf_call);
    if (i != 0)
    {
      err_mes = "calling `surf` failed" + newline
              + " (The shell returned the error code "
              + string(i) + ".";
      ERROR(err_mes);
    }
  }
  system("sh", "command rm " + l);
}
example
{ "EXAMPLE:"; echo = 2;
  // ---------  plane curves ------------
  ring rr0 = 0,(x1,x2),dp;

  ideal I = x1^3 - x2^2;
  plot(I);

  ring rr1 = 0,(x,y,z),dp;
  ideal I(1) = 2x2-1/2x3 +1-y+1;
  plot(I(1));

  //  ---- Singular Logo --------------
  poly logo = ((x+3)^3 + 2*(x+3)^2 - y^2)*(x^3 - y^2)*((x-3)^3-2*(x-3)^2-y^2);
  plot(logo);

  // Steiner surface
  ideal J(2) = x^2*y^2+x^2*z^2+y^2*z^2-17*x*y*z;
  plot(J(2));

  // --------------------
  plot(x*(x2-y2)+z2);

  // E7
  plot(x^3-x*y^3+z^2);

  // Whitney umbrella
  plot(z^2-x^2*y);

}

proc surfer(ideal I)
"USAGE:   surfer(f);  f poly
ASSUME: f defines a surface given by one equation
RETURN: nothing
NOTE: requires the external program `surfer` to be installed,
      to close the graphical interface just close the window of surfer
EXAMPLE: example surfer; shows an example
"
{
  string lForWindows = "surfer" + string(system("pid"));
  string l = "./" + lForWindows;
  string err_mes; // string containing error messages
  def base=basering;
  intvec v=num_of_vars(I);
  int i,j,n;
  for(i=size(v);i>0;i--)
  {
    if (v[i]!=0) { n++; }
  }
  if (n==0 or n>3)
  {
    err_mes="Cannot plot equations with "+string(n)+" variables";
    ERROR(err_mes);
  }
  ring r=0,(x,y,z),dp;
  short=0;
  map phi=base,0;
  j=1;
  for(i=1;i<=size(v);i++)
  {
    if (v[i]!=0)
    {
      phi[i]=var(j);
      j++;
      if(j==4) break;
    }
  }
  ideal I=simplify(phi(I),2);
  if (leadcoef(I[1]) <0) { I[1]=-I[1]; }
  if (ncols(I)==1 and (n==3 or nvars(base)==3)) // surface
  {
    write(":w " + l, "surface=" + string(I[1]) + ";");
  }
  else
  {
    err_mes = "cannot plot " + string(ncols(I)) + " equations in "
            + string(n) + " variables";
    ERROR(err_mes);
  }

  string surf_call; i = 0;

  if (isWindows())
  {
    string surferPath = getShellOutput("which surfer");
    if (find(surferPath, "no surfer in") != 0)
    { /* did not find surfer: either not installed or
         not yet included in $PATH variable */
      err_mes = "calling `surfer` failed" + newline
      + " (Either the program Surfer is not installed," + newline
      + "  or it has not yet been included in $PATH.)";
      ERROR(err_mes);
    }
    else
    {
      string singularPath = getShellOutput("pwd");
      surferPath = windowsCorrection(surferPath);
      surferPath = surferPath[1..size(surferPath)-size("/surfer")];
      singularPath = windowsCorrection(singularPath);
      link ll = "|: cygpath -w " + singularPath;
      singularPath = "'\""+read(ll)+"\"'"; close(ll);
      surf_call = "cygstart -w -d " + surferPath + " ";
      surf_call = surf_call + surferPath + "/surfer ";
      surf_call = surf_call + singularPath + "/" + lForWindows;
      "Close window to exit from `surfer`.";
      i = system("sh", surf_call);
    }
  }
  else
  {
    surf_call = "surfer";
    surf_call = surf_call + " " + l + " >/dev/null 2>&1";
    "Close window to exit from `surfer`.";
    i = system("sh", surf_call);

    if ( (i != 0) && isMacOSX() )
    {
      "*!* Sorry: calling `surfer` failed ['"+surf_call+"']" + newline
      + " (The shell returned the error code " + string(i) + "." + newline
      + "But since we are on Mac OS X, let us try to open SURFER.app instead..." + newline
      + "Appropriate SURFER.app is available for instance at http://www.mathematik.uni-kl.de/~motsak/files/SURFER.dmg";

      // fallback, will only work if SURFER.app is available (e.g. in /Applications)
      // get SURFER.app e.g. from http://www.mathematik.uni-kl.de/~motsak/files/SURFER.dmg
      // note that the newer (Java-based) variant of Surfer may not support command line usage yet :(

      surf_call = "open -a SURFER -W --args -t -s";
      surf_call = surf_call + " " + l + " >/dev/null 2>&1";
      "Close window to exit from `surfer`.";
      i = system("sh", surf_call);
    }



  }
  system("sh", "command rm " + l);

  if (i != 0)
  {
    err_mes = "calling `surfer` failed" + newline
              + " (The shell returned the error code "
              + string(i) + ".";
    ERROR(err_mes);
  }
}
example
{ "EXAMPLE:"; echo = 2;
  ring rr1 = 0,(x,y,z),dp;
  // Steiner surface
  ideal J(2) = x^2*y^2+x^2*z^2+y^2*z^2-17*x*y*z;
  surfer(J(2));

  // --------------------
  surfer(x*(x2-y2)+z2);

  // E7
  surfer(x^3-x*y^3+z^2);

  // Whitney umbrella
  surfer(z^2-x^2*y);
}

static proc isWindows()
"returns 1 if this SINGULAR instance runs under (some) Windows OS;
0 otherwise"
{
  string s = system("uname");
  for (int i = 1; i <= size(s)-2; i = i + 1)
  {
    if (s[i] == "W")
    {
      if (s[i+1] == "i")
      {
        if (s[i+2] == "n")
        {
          return (1);
        }
      }
    }
  }
  return (0);
}

static proc isMacOSX()
"returns 1 if this SINGULAR instance runs under (some) Mac OS X;
0 otherwise"
{
  string s = system("uname");

  for (int i = 1; i <= size(s)-2; i = i + 1)
  {
    if (s[i] == "d" or s[i] == "D")
    {
      if (s[i+1] == "a" or s[i+1] == "A")
      {
        if (s[i+2] == "r" or s[i+2] == "R")
        {
          return (1);
        }
      }
    }
  }
  return (0);
}

static proc getShellOutput(string shellCommand)
"returns the console output when executing the given shellCommand"
{
   int s;
   string tempFilename = "tmp" + string(system("pid"));
   s = system("sh", shellCommand + " > " + tempFilename + " 2>&1");
   string r1 = read(tempFilename);
   s = size(r1) - 1;
   string r2 = r1[1..s];
   s = system("sh", "command rm " + tempFilename);
   return (r2);
}

static proc windowsCorrection(string windowsPath)
"puts a backslash in front of each space and each special character
and returns the resulting string"
{
  string s = ""; int i;
  for (i = 1; i <= size(windowsPath); i++)
  {
    if (find(" ()", windowsPath[i]) != 0)
    {
      s = s + "\\";
    }
    s = s + windowsPath[i];
  }
  return (s);
}
///////////////////////////////////////////////////////////////////////////////