Differences

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

Link to this comparison view

Both sides previous revision Previous revision
user_guide:tutorials:properties [2019/02/11 16:24]
oroehrig ↷ Links adapted because of a move operation
user_guide:tutorials:properties [2019/02/11 16:24] (current)
oroehrig restored.
Line 1: Line 1:
-====== Objects, Properties and Rules ====== +{{page>.:​latest:​@FILEID@}}
-==== Objects ==== +
-In polymake, there is two kinds of objects. A //Big Object// models a complex mathematical concept, like a Polytope or a SimplicialComplex,​ while a //small object// is an instance of one of the many data types commonly used in computer science, like Integers, Matrices, Sets or Maps. A big object consists of a collection of other objects (big or small) describing it, called //​properties//,​ and functions to compute more properties from the ones already known, called //​production rules//.+
  
-To find out the type of an object ''​$c'',​ enter 
-<​code>​ 
-print $c->​type->​full_name;​ 
-</​code>​ 
- 
-To get a more detailed explanation of the ''​polymake''​ object model and properties, check out the [[..:​howto:​scripting#​most_important_interfaces|scripting guide]]. 
- 
-You can save polymake objects to disc, as explained [[..:​howto:​data|here]]. 
- 
-==== Properties ==== 
- 
-Each (big) object has a list of properties of various types. ​ When an object is '​born'​ it comes with an initial list of properties, and all other properties will be derived from those. ​ Let's look at example from the ''​polytope''​ application. ​ The following creates a 3-dimensional cube: 
- 
-<​code>​ 
-polytope > $c=cube(3); 
-</​code>​ 
- 
-To find out what the initial set of properties is, use the ''​list_properties''​ method. ​ It returns an array of strings. ​ The extra code is just there to print this list nicely. 
- 
-<​code>​ 
-polytope > print join(",​ ", $c->​list_properties);​ 
-CONE_AMBIENT_DIM,​ CONE_DIM, FACETS, AFFINE_HULL,​ VERTICES_IN_FACETS,​ BOUNDED 
-</​code>​ 
- 
-To see what a property contains, use the ''​->''​ syntax: 
-<​code>​ 
-polytope > print $c->​FACETS;​ 
- 
-1 1 0 0 
-1 -1 0 0 
-1 0 1 0 
-1 0 -1 0 
-1 0 0 1 
-1 0 0 -1 
-</​code>​ 
- 
-You can also get the content of all properties using the ''​properties''​ method: 
-<​code>​ 
-polytope > $c->​properties;​ 
-name: c 
-type: Polytope<​Rational>​ 
-description:​ cube of dimension 3 
- 
- 
-CONE_AMBIENT_DIM 
-4 
- 
-CONE_DIM 
-4 
- 
-FACETS 
-1 1 0 0 
-1 -1 0 0 
-1 0 1 0 
-1 0 -1 0 
-1 0 0 1 
-1 0 0 -1 
- 
- 
-AFFINE_HULL 
- 
- 
-VERTICES_IN_FACETS 
-{0 2 4 6} 
-{1 3 5 7} 
-{0 1 4 5} 
-{2 3 6 7} 
-{0 1 2 3} 
-{4 5 6 7} 
- 
- 
-BOUNDED 
-1 
-</​code>​ 
- 
-==== Production Rules ==== 
- 
-The object is changed if we ask for a property which has not been computed before. 
- 
-<​code>​ 
-polytope > print $c->​VERTICES;​ 
-1 -1 -1 -1 
-1 1 -1 -1 
-1 -1 1 -1 
-1 1 1 -1 
-1 -1 -1 1 
-1 1 -1 1 
-1 -1 1 1 
-1 1 1 1 
- 
-polytope > print join(",​ ", $c->​list_properties);​ 
-CONE_AMBIENT_DIM,​ CONE_DIM, FACETS, AFFINE_HULL,​ VERTICES_IN_FACETS,​ BOUNDED, FEASIBLE, POINTED, N_FACETS, FULL_DIM, N_VERTICES, VERTICES, LINEALITY_SPACE 
-</​code>​ 
- 
-The property ''​VERTICES''​ was added, but a few others were computed on the way, too. ''​polymake''​ applied a sequence of //​production rules// that add new properties to the object that can be computed from the properties the object already posesses. 
- 
-What properties //can// be computed for a given object depends on the set of rules defined for it. Here is a short sequence of commands which lets you find out. 
-<​code>​ 
-polytope>​ $t=$c->​type->​full_name;​ 
-polytope>​ print join(",​ ", sorted_uniq(sort { $a cmp $b } map { keys %{$_->​properties} } $t, @{$t->​super}));​ 
-</​code>​ 
- 
-Instead of showing the (lengthy) enumeration have a look at the [[release_docs:​latest:​polytope.html|documentation]] for a complete list of properties known for objects of the application ''​polytope''​. 
- 
- 
-=== Schedules === 
- 
-You may wonder what sequence of rules led to the computation of a property you request. There usually are several mathematical ways to compute a property. ''​polymake''​ uses a nice scheduling algorithm to find the most efficient procedure, and you can look at what it returns. 
- 
-Suppose we want to see which sequence of rules leads to the computation of the F_VECTOR. 
- 
-<​code>​ 
-polytope > $schedule=$c->​get_schedule("​F_VECTOR"​);​ 
-polytope > print join("​\n",​ $schedule->​list);​ 
-HASSE_DIAGRAM : RAYS_IN_FACETS 
-F_VECTOR : HASSE_DIAGRAM 
-</​code>​ 
-So if you ask for the f-vector, ''​polymake''​ will first compute the Hasse diagram from the vertex-facet-incidences,​ and then compute the f-vector form the Hasse diagram. Applying the schedule to the object yields the same as asking for the property right away: 
-<​code>​ 
-polytope > $schedule->​apply($c);​ 
-polytope > print join(",​ ", $c->​list_properties);​ 
-POLYTOPE_AMBIENT_DIM,​ POLYTOPE_DIM,​ FACETS, VERTICES_IN_FACETS,​ BOUNDED, HASSE_DIAGRAM,​ F_VECTOR 
-</​code>​ 
-As you can see, the things ''​polymake''​ needed to compute in order to get to the f-vector are stored in the object as well, so you don't have to recompute them later. 
- 
-If you're interested, read more about rule scheduling in the [[..:​howto:​scripting#​rule_planning|scripting guide]] and the article on [[..:​extend:​rules|writing rules yourself]]. 
  • user_guide/tutorials/properties.txt
  • Last modified: 2019/02/11 16:24
  • by oroehrig