This file is indexed.

/usr/share/polymake/demo/perl_intro.ipynb is in polymake-common 3.2r2-3.

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
{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# polymake for the Perl Newbie\n",
    "\n",
    "The language that the interactive version of `polymake` speaks is a dialect of Perl that we refer to as `polymake`/Perl. See [www.perl.org](http://www.perl.org) for comprehensive Perl information.  Note also that the ordinary Perl manual pages are particularly useful, especially the perlintro man page which is also available on [perldoc](http://perldoc.perl.org/perlintro.html).  This short section here cannot be a replacement for a thorough introduction to this language, but we want to focus on a few key points that are relevant to `polymake`.\n",
    "\n",
    "### Standard data structures\n",
    "\n",
    "The Perl programming language originally provides three different data structures, scalars($), arrays(@), and hashes(%). The user always has to specify the type of a variable using the appropriate symbol `$`, `@`, or `%`. If you forget to do so, you will receive the following error message:\n",
    "\n",
    "    \n",
    "     polytope > i=5;\n",
    "    polymake:  ERROR: Unquoted string \"i\" may clash with future reserved word.\n",
    "    </code>\n",
    "\n",
    "\n",
    "    Here are some simple commands illustrating how to use the different data structures:\n",
    "    ==Scalars==\n",
    "    <code>\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "$i=5;\n",
    "$j=6;\n",
    "$sum=$i+$j; print $sum;"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "##### Arrays\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "@array=(\"a\",\"b\",\"c\"); print scalar(@array);\n",
    "push(@array,\"d\"); print \"@array\"; \n",
    "$first_entry=$array[0]; print $first_entry;\n",
    "print join(\"\\n\",@array);\n",
    "@array2=(3,1,4,2);\n",
    "print sort(@array2);"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "##### Hashes\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%hash=();\n",
    "$hash{\"zero\"}=0;\n",
    "$hash{\"four\"}=4;\n",
    "print keys %hash;\n",
    "print join(\", \",keys %hash);\n",
    "print join(\", \",values %hash);\n",
    "%hash=(\"one\",1,\"two\",2);\n",
    "%hash=(\"one\"=>1,\"two\"=>2);"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "### `polymake`-Perl\n",
    "\n",
    "In addition to the three standard data structures, the enriched version of `Perl` used in `polymake` also provides special data structures for dealing with more complicated structures. `polymake`'s object hierarchy is completely reflected on the Perl side. Let us create a small polytope as an example object.\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "$p = new Polytope(POINTS=>[[1,0,1],[1,0,-1],[1,1,0],[1,-1,0]]);"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "Note that the `Perl`-type of the variable `$p` is `Scalar`, as the variable is internally treated as a reference to a `C++`-object. The true nature of the object becomes visible if it is printed:\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Polymake::polytope::Polytope__Rational=ARRAY(0x2f2f1c0)\n",
       "\n"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $p;"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this case it is a `polymake` object from the application `polytope`, and it happens to be of type `Polytope<Rational>. Technically, $p is a reference to an array (but it should be never treated as an array unless you are deliberately trying to crash polymake). If you want less technical information on the type of your object, use this:\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Polytope<Rational>\n",
       "\n"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $p->type->full_name;"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "#### \"Small objects\": Data structures inherited from C++\n",
    "\n",
    "You can use objects that are inherited from the `C++`-side of `polymake` in the interactive shell. A complete list of so-called \"small objects\" can be found in the [online documentation](/release_docs/latest/common.html) under the heading \"Property types\".\n",
    "Here is a selection of three different structures that facilitate everyday work with `polymake`:\n",
    "##### Arrays\n",
    "\n",
    "The small object `Array` can be initialized in different ways and with different template parameters:\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "@array=(\"a\",\"b\",\"c\");\n",
    "$arr1=new Array<String>(\\@array); print $arr1;\n",
    "$arr2=new Array<Int>([3,2,5]); print $arr2;\n",
    "$arr3=new Array<Int>(0,1,2,3); print $arr3;\n",
    "$arr4=new Array<Int>(0..4); print $arr4;\n",
    "$arr5=new Array<Int>($arr4); print $arr5;"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "You have random access:\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100 1 2 3 4\n",
       "\n"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "$arr5->[0] = 100;\n",
    "print $arr5;"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " It is also possible to convert the `C++`-object `Array` into a `Perl`-array by writing <code>\n",
    "> @arr4=@{$arr4}; print $arr2;\n",
    "</code> or simply<code>\n",
    "> @arr4=@$arr4;\n",
    "</code>\n",
    "##### Sets\n",
    "\n",
    "On `C++`-side sets are stored in a balanced binary search (AVL) tree. For more information see the [PTL-documentation](https///polymake.org/release_docs/master/PTL/classpm_1_1Set.html). In many cases, the small objects can be converted into `Perl`-types in the expected way: <code>\n",
    "> $set=new Set<Int>(3,2,5); print $set;\n",
    "> print $set->size;\n",
    "> @array_from_set=@$set;\n",
    "</code>\n",
    "##### Matrices\n",
    "\n",
    "Here is a simple way to initialize a matrix:<code>\n",
    "> $mat=new Matrix<Rational>([2,1,4,0,0],[3,1,5,2,1],[1,0,4,0,6](2,1,4,0,0],[3,1,5,2,1],[1,0,4,0,6));\n",
    "> print $mat;\n",
    "</code> You could also define it by passing a reference to an (`Perl`-)array of `Vectors`. The single entries are interpreted as different rows: <code>\n",
    "> $row1=new Vector<Rational>([2,1,4,0,0]);\n",
    "> $row2=new Vector<Rational>([3,1,5,2,1]);\n",
    "> $row3=new Vector<Rational>([1,0,4,0,6]);\n",
    "> @matrix_rows=($row1,$row2,$row3);\n",
    "> $matrix_from_array=new Matrix<Rational>(\\@matrix_rows);\n",
    "</code> You can change a single entry of a matrix in the following way (if it is not already assigned to an immutable property like `VERTICES`!):<code>\n",
    "> $mat->row(1)->[1]=7; print $mat->row(1)->[1];\n",
    "> print $mat;\n",
    "> $mat->(1,2)=8; print $mat;\n",
    "</code> A unit matrix of a certain dimension can be defined via the user-function `unit_matrix<COORDINATE_TYPE>(.)`: <code>\n",
    "> $unit_mat=4*unit_matrix<Rational>(3);\n",
    "> print $unit_mat;\n",
    "</code> The reason for the \"strange output\" is the implementation as *sparse matrix*: <code>\n",
    "> print ref($unit_mat);\n",
    "</code>However, some functions cannot deal with this special type of matrix. In this case it is necessary to transform the sparse matrix into a dense matrix first via:<code>\n",
    "> $dense=new Matrix<Rational>($unit_mat);print $dense;\n",
    "</code> or just<code>\n",
    "> $dense2=dense($unit_mat);print $dense2;\n",
    "</code> You can also work with matrices that have different types of coordinates like `Rational`, `Float`, or `Int`: <code>\n",
    "> $m_rat=new Matrix<Rational>(3/5*unit_matrix<Rational>(5)); print $m_rat; \n",
    "> $m2=$mat/$m_rat; print $m2;\n",
    "> $m_int=new Matrix<Int>(unit_matrix<Rational>(5)); print $m_int;\n",
    "> $m3=$m_rat/$m_int;\n",
    "</code> The error message <code>\n",
    "polymake:  ERROR: undefined operator Matrix<Rational> / Matrix<Int> at input line 1.\n",
    "</code>indicates that you need to convert the integer matrix to a rational matrix first:<code>\n",
    "> $m3=$m_rat/convert_to<Rational>($m_int); print $m3;\n",
    "</code> By \"/\" you can add rows to a matrix, whereas \"|\" adds columns. By the way, this also works for `Vector`.<code>\n",
    "> $z_vec=zero_vector<Int>($m_int->rows);\n",
    "> $extended_matrix=($z_vec|$m_int); print $extended_matrix;\n",
    "</code>\n",
    "It is also possible to nest template parameters in any way you like, e.g.\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "$set=new Set<Int>(3,2,5);\n",
    "$template_Ex=new Array<Set<Int>>(new Set<Int>(5,2,6), $set); print $template_Ex; print ref($template_Ex);"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "However, if you use a template combination, you have never used before, it may take some time until you see the result. This is due to the fact that `polymake` compiles your new combination *on the fly*. But this is only a one-time effect, and next time you use this combination it will work without delay.\n",
    "\n",
    "#### \"Big Objects\": Objects with properties\n",
    "\n",
    "A big object is an instance of a data type which represents a mathematical concept with clear semantics. They may have template parameters.\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "$p=new Polytope<Rational>(POINTS=>cube(4)->VERTICES);\n",
    "$lp=new LinearProgram<Rational>(LINEAR_OBJECTIVE=>[0,1,1,1,1]);"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "Big objects have properties which come with a type, which is either built-in or a small object type or a big object type, and which can be accessed using the `-``>` operator.\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# access the property named `LP`:\n",
    "$p->LP=$lp;\n",
    "# properties can have properties themselves.\n",
    "print $p->LP->MAXIMAL_VALUE;"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "\n",
    "Scalar properties can be used in arithmetic expressions right away.\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "$i = ($p->N_FACETS * $p->N_FACETS) * 15;"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2940\n",
       "\n"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $i;"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Check out the tutorial on [properties](properties) to learn more about the way properties are used and computed.\n",
    "\n",
    "### A small example script...\n",
    "\n",
    "...to demonstrate the usage of `polymake`/Perl. You can download the matrix file {{:points.demo| here}}.\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "> \n"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "### load matrix from file\n",
    "open(INPUT, \"< demo/Workshop2011/points.demo\");\n",
    "$matrix=new Matrix<Rational>(<INPUT>);\n",
    "close(INPUT);\n",
    "print $matrix;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "> \n"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "### create a polytope from the matrix\n",
    "$p=new Polytope<Rational>(POINTS=>$matrix);\n",
    "print $p->FACETS;\n",
    "print $p->DIM;\n",
    "print $p->VERTEX_SIZES;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "> \n"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "### print \"simple\" vertices\n",
    "for(my $i=0;$i<scalar(@{$p->VERTEX_SIZES});$i++){\n",
    "    if($p->VERTEX_SIZES->[$i]==$p->DIM){\n",
    "    print $i.\": \".$p->VERTICES->row($i).\"\\n\";\n",
    "    }\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "> \n"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "### put their indices in a set\n",
    "$s=new Set<Int>();\n",
    "for(my $i=0;$i<scalar(@{$p->VERTEX_SIZES});$i++){\n",
    "    if($p->VERTEX_SIZES->[$i]==$p->DIM){\n",
    "    $s+=$i;\n",
    "    }\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "> \n"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "### iterate the set in two different ways\n",
    "foreach(@{$s}){\n",
    "    print $p->VERTICES->row($_).\"\\n\";\n",
    "}\n",
    "foreach my $index(@{$s}){\n",
    "    print $p->VERTICES->row($index).\"\\n\";\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### create a minor of the vertices matrix that only contains the simple ones\n",
    "$special_points=$p->VERTICES->minor($s,All); print $special_points;"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "\n",
    "### Writing scripts\n",
    "\n",
    "Comprehensive information on how to use scripts within `polymake` can be found [here](scripting/start).\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "polymake",
   "language": "polymake",
   "name": "polymake"
  },
  "language_info": {
   "codemirror_mode": "perl",
   "file_extension": ".pm",
   "mimetype": "text/x-polymake",
   "name": "polymake"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}