tutorial:perl_continued

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revisionBoth sides next revision
tutorial:perl_continued [2017/07/11 08:52] – removed bullet points oroehrigtutorial:perl_continued [2017/07/11 09:04] oroehrig
Line 5: Line 5:
 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:  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: 
 <code> <code>
-polytope > i=5;+ polytope > i=5;
 polymake:  ERROR: Unquoted string "i" may clash with future reserved word. polymake:  ERROR: Unquoted string "i" may clash with future reserved word.
 </code>\\ </code>\\
Line 40: Line 40:
 A complete list of these so-called "small objects" can be found in the [[:release_docs:latest:common.html|online documentation]] under the heading "Property types". To define a ''Perl''-variable of such a type, you initialize the variable via A complete list of these so-called "small objects" can be found in the [[:release_docs:latest:common.html|online documentation]] under the heading "Property types". To define a ''Perl''-variable of such a type, you initialize the variable via
 <code> <code>
-> $my_var=new [SMALL_OBJECT]([INITIALIZATION]);+ > $my_var = new [SMALL_OBJECT]([INITIALIZATION]);
 </code> </code>
 Note that the ''Perl''-type of the variable //my_var// is ''Scalar'', as the variable is internally treated as a reference to a ''C++''-object. You can find out the (''C++''-)type of your variable via Note that the ''Perl''-type of the variable //my_var// is ''Scalar'', as the variable is internally treated as a reference to a ''C++''-object. You can find out the (''C++''-)type of your variable via
 <code> <code>
-> print ref($my_var);+ > print ref($my_var);
 </code> </code>
 Here is a selection of three different structures that facilitate everyday work with ''polymake'': Here is a selection of three different structures that facilitate everyday work with ''polymake'':
Line 110: Line 110:
  
 ==="Big Objects": Objects with properties=== ==="Big Objects": Objects with properties===
 +A big object is an instance of a data type which represents a mathematical concept with clear semantics. They may have template parameters. 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. 
 <code> <code>
 > $p=new Polytope<Rational>(POINTS=>cube(4)->VERTICES); > $p=new Polytope<Rational>(POINTS=>cube(4)->VERTICES);
 > $lp=new LinearProgram<Rational>(LINEAR_OBJECTIVE=>[0,1,1,1,1]); > $lp=new LinearProgram<Rational>(LINEAR_OBJECTIVE=>[0,1,1,1,1]);
 +> # access the property named ''LP'':
 > $p->LP=$lp; > $p->LP=$lp;
 +> # properties can have properties themselves.
 > print $p->LP->MAXIMAL_VALUE; > print $p->LP->MAXIMAL_VALUE;
 </code> </code>
Line 119: Line 122:
 {{:points.demo|}} {{:points.demo|}}
 <code> <code>
-open(INPUT, "< $HOME/polymake/demo/Workshop2011/points.demo"); +open(INPUT, "< $HOME/polymake/demo/Workshop2011/points.demo"); 
-$matrix=new Matrix<Rational>(<INPUT>); +$matrix=new Matrix<Rational>(<INPUT>); 
-close(INPUT); +close(INPUT); 
-print $matrix; +print $matrix; 
- + 
-$p=new Polytope<Rational>(POINTS=>$matrix); +$p=new Polytope<Rational>(POINTS=>$matrix); 
-print $p->FACETS; +print $p->FACETS; 
-print $p->DIM; +print $p->DIM; 
-print $p->VERTEX_SIZES; +print $p->VERTEX_SIZES; 
-### choose "simple" vertices +### choose "simple" vertices 
-for(my $i=0;$i<scalar(@{$p->VERTEX_SIZES});$i++){ +for(my $i=0;$i<scalar(@{$p->VERTEX_SIZES});$i++){ 
->     if($p->VERTEX_SIZES->[$i]==$p->DIM){ +    if($p->VERTEX_SIZES->[$i]==$p->DIM){ 
-> print $i.": ".$p->VERTICES->row($i)."\n"; + print $i.": ".$p->VERTICES->row($i)."\n"; 
->     +    
-+
-$s=new Set<Int>(); +$s=new Set<Int>(); 
-for(my $i=0;$i<scalar(@{$p->VERTEX_SIZES});$i++){ +for(my $i=0;$i<scalar(@{$p->VERTEX_SIZES});$i++){ 
->     if($p->VERTEX_SIZES->[$i]==$p->DIM){ +    if($p->VERTEX_SIZES->[$i]==$p->DIM){ 
-> $s+=$i; + $s+=$i; 
->     +    
-+
-$special_points=$p->VERTICES->minor($s,All); print $special_points; +$special_points=$p->VERTICES->minor($s,All); print $special_points; 
- + 
-foreach(@{$s}){ +foreach(@{$s}){ 
->     print $p->VERTICES->row($_)."\n"; +    print $p->VERTICES->row($_)."\n"; 
-+
-foreach my $index(@{$s}){ +foreach my $index(@{$s}){ 
->     print $p->VERTICES->row($index)."\n"; +    print $p->VERTICES->row($index)."\n"; 
-}+}
 </code> </code>
  
-===Scripts=== +===Scripts===
 [[scripting:start|Scripting]] [[scripting:start|Scripting]]