Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit ec05386

Browse files
author
Matthias Koeppe
committed
polymake/apps_tropical.rst: Work around polymake interface limitations using getattr, get_member_function, function_call
1 parent 1270269 commit ec05386

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

src/doc/en/thematic_tutorials/polymake/apps_tropical.rst

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ In Sage::
103103
sage: a + b # this won't work!
104104
Traceback (most recent call last):
105105
...
106-
TypeError: C++/perl Interface module compilation failed; most likely due to a type mismatch...
106+
TypeError: C++/perl Interface module compilation failed...
107107

108108
Tropical vector/matrix arithmetics also work - you can even ask for the
109109
tropical determinant!
@@ -490,7 +490,7 @@ Computing the divisor of a tropical polynomial in $ :raw-latex:`\mathbb `R^n$
490490
In Sage::
491491
492492
sage: f = polymake.toTropicalPolynomial("'max(0,x,y,z)'")
493-
sage: div = polymake.divisor(polymake("projective_torus<Max>(3)"), polymake.rational_fct_from_affine_numerator(f))
493+
sage: div = polymake.divisor(getattr(polymake, "projective_torus<Max>")(3), polymake.rational_fct_from_affine_numerator(f))
494494
sage: div.VISUAL() # not tested
495495
496496
Here, ``projective_torus`` creates the tropical projective 3-torus (aka
@@ -513,7 +513,7 @@ Let’s create the standard tropical hyperplane in 3-space:
513513
514514
In Sage::
515515
516-
sage: l = polymake("uniform_linear_space<Min>(3,2)")
516+
sage: l = getattr(polymake, "uniform_linear_space<Min>")(3,2)
517517
518518
Furthermore, we compute a curve as the divisor of a rational function on
519519
``$l``:
@@ -549,8 +549,16 @@ surface”).
549549
550550
In Sage::
551551

552-
sage: l.bounding_box(1) # ERROR - does it get confused by the global function of the same name?
553-
sage: div.bounding_box(1)
552+
sage: l.get_member_function("bounding_box")(1)
553+
-1 -1 -1
554+
1 1 1
555+
sage: div.get_member_function("bounding_box")(1)
556+
-2 -2 -2
557+
4 1 1
558+
559+
(Here we need to go through ``get_member_function`` because of a clash
560+
with a global polymake function of the same name. The sage polymake
561+
interface puts all of these global functions also as methods of all objects.)
554562

555563
The command boundingBox tells us, what a “good” bounding box for a given
556564
polyhedral complex should be. Obviously the bounding box for the curve
@@ -564,6 +572,13 @@ several objects at the same time:
564572
565573
polymake> compose($l->VISUAL(VertexStyle=>"hidden",BoundingMode=>"absolute",BoundingBox=>$div->bounding_box(1)), $div->VISUAL(VertexStyle=>"hidden",EdgeColor=>"red", BoundingMode=>"absolute",BoundingBox=>$div->bounding_box(1)));
566574
575+
.. link
576+
577+
In Sage::
578+
579+
sage: div_bb = div.get_member_function("bounding_box")(1)
580+
sage: polymake.compose(l.VISUAL(VertexStyle=repr("hidden"), BoundingMode=repr("absolute"), BoundingBox=div_bb), div.VISUAL(VertexStyle=repr("hidden"), EdgeColor=repr("red"), BoundingMode=repr("absolute"), BoundingBox=div_bb)) # not tested
581+
567582
Alternatively, we could simply specify an explicit bounding box to make
568583
the surface look more symmetric:
569584

@@ -575,6 +590,13 @@ the surface look more symmetric:
575590
polymake> $m = new Matrix<Rational>([[-5,-5,-5],[5,5,5]]);
576591
polymake> compose($l->VISUAL(VertexStyle=>"hidden",BoundingMode=>"absolute",BoundingBox=>$m), $div->VISUAL(VertexStyle=>"hidden",EdgeColor=>"red",BoundingMode=>"absolute",BoundingBox=>$m));
577592
593+
.. link
594+
595+
In Sage::
596+
597+
sage: m = polymake.new_object("Matrix<Rational>", [[-5,-5,-5],[5,5,5]])
598+
sage: polymake.compose(l.VISUAL(VertexStyle=repr("hidden"), BoundingMode=repr("absolute"), BoundingBox=m), div.VISUAL(VertexStyle=repr("hidden"), EdgeColor=repr("red"), BoundingMode=repr("absolute"), BoundingBox=m)) # not tested
599+
578600
Creation functions for commonly used tropical cycles
579601
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
580602

@@ -654,8 +676,12 @@ be computed via:
654676
655677
In Sage::
656678

657-
sage: p = polymake.cartesian_product(polymake("uniform_linear_space<Max>(3,2)"),
658-
....: polymake("uniform_linear_space<Max>(3,1)"))
679+
sage: p = polymake.function_call("cartesian_product",
680+
....: [getattr(polymake, "uniform_linear_space<Max>")(3,2),
681+
....: getattr(polymake, "uniform_linear_space<Max>")(3,1)])
682+
683+
(Need to use ``function_call`` because an unrelated method ``cartesian_product``
684+
is defined by a Sage superclass; it is not overridden by the polymake interface.)
659685

660686
Computing the skeleton
661687
''''''''''''''''''''''
@@ -776,7 +802,7 @@ Some examples:
776802
777803
In Sage::
778804

779-
sage: x = polymake("uniform_linear_space<Max>(3, 2)")
805+
sage: x = getattr(polymake, "uniform_linear_space<Max>")(3, 2)
780806
sage: x1 = polymake.local_restrict(x, polymake.new_object("IncidenceMatrix", [[0],[2,3]]))
781807

782808
(The tropical hyperplane, locally around the 0-th ray and the maximal cone spanned by rays 2 and 3.

0 commit comments

Comments
 (0)