/usr/share/polymake/demo/properties.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 | {
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Tutorial on Properties and Rules\n",
"\n",
"\n",
"### Properties\n",
"\n",
"Each 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. Here we discuss an example from the `polytope` application. The following creates a 3-dimensional cube.\n",
"\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"$c=cube(3);"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
"The object is defined by calling some function, but how does one find out what the initial set of properties is? Of course, one could look at the source code, but the following is the direct way from the interpreter.\n",
"\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"AMBIENT_DIM, DIM, FACETS, VERTICES_IN_FACETS, BOUNDED\n",
"\n"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print join(\", \", $c->list_properties);"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"The relevant method, which is defined for any `polymake` object, is called `list_properties`. It returns an array of strings. The extra code is just there to print this list nicely. The object is changed if we ask for a property which has not been computed before.\n",
"\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1 -1 -1 -1\n",
"1 1 -1 -1\n",
"1 -1 1 -1\n",
"1 1 1 -1\n",
"1 -1 -1 1\n",
"1 1 -1 1\n",
"1 -1 1 1\n",
"1 1 1 1\n",
" \n"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print $c->VERTICES;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"AMBIENT_DIM, DIM, FACETS, VERTICES_IN_FACETS, BOUNDED, N_VERTICES, FEASIBLE, SIMPLE, SIMPLE_POLYHEDRON, AFFINE_HULL, VERTICES\n",
"\n"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print join(\", \", $c->list_properties);"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"The property `VERTICES` was added, but also a few others. These were computed on the way. Which properties show up after some computation depends on the rules applied. What is the set of properties that *can* be computed for a given object? This depends on your set of rule valid for the object in question. Here is a short sequence of commands which lets you find out. The properties listed come in alphabetical ordering.\n",
"\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"$t=$c->type;\n",
"print join(\", \", sorted_uniq(sort { $a cmp $b } map { keys %{$_->properties} } $t, @{$t->super}));"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
"Instead of showing the (lengthy) enumeration have a look at the [documentation](release_docs/latest/polytope.html) for a complete list of properties known for objects of the application `polytope`.\n",
"\n",
"\n",
"### Schedules\n",
"\n",
"[beware: output from branch \"cones\"]\n",
"\n",
"Let us restart with our cube from scratch.\n",
"\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"POLYTOPE_AMBIENT_DIM, POLYTOPE_DIM, FACETS, VERTICES_IN_FACETS, BOUNDED\n",
"\n"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"$c=cube(3);\n",
"print join(\", \", $c->list_properties);"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"Suppose we want to see which sequence of rules leads to the computation of the F_VECTOR.\n",
"\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"HASSE_DIAGRAM : RAYS_IN_FACETS\n",
"F_VECTOR : HASSE_DIAGRAM\n",
"\n"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"$schedule=$c->get_schedule(\"F_VECTOR\");\n",
"print join(\"\\n\", $schedule->list);"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"Applying the schedule to the object yields the same as asking for the property right away.\n",
"\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"POLYTOPE_AMBIENT_DIM, POLYTOPE_DIM, FACETS, VERTICES_IN_FACETS, BOUNDED, HASSE_DIAGRAM, F_VECTOR\n",
"\n"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"$schedule->apply($c);\n",
"print join(\", \", $c->list_properties);"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"It is possible to apply the same schedule to several polytopes. This is useful for a slight speed up in the total time of the computation.\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
}
|