user_guide:tutorials:polynomials_tutorial

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
tutorial:polynomials_tutorial [2017/02/20 13:43] – [Basic Usage of Polynomials in Perl] wagneruser_guide:tutorials:polynomials_tutorial [2019/02/04 22:55] (current) – external edit 127.0.0.1
Line 1: Line 1:
-===== Basic Usage of Polynomials in Perl ===== +{{page>.:latest:@FILEID@}}
- +
-A polynomial always carries a reference to a polynomial ring.  Polynomial in different rings cannot be added, multiplied, or whatever.  The names of the indeterminates are relevant for the output functions only. +
- +
-<code> +
-polytope> $r=new Ring(qw(x y)); +
-</code> +
- +
-It may be convenient to use special variable names for the indeterminates. +
- +
-<code> +
-polytope> ($x,$y)=$r->variables; +
-</code> +
- +
-Notice that the variable names are chosen to match the print names; but this is "coincidental"+
- +
-<code> +
-polytope > $p=1+($x^2)+$y; +
-polytope > $q=1+$x+2*($y^3)+$x*$y; +
-polytope > print($p*$q); +
-x^3*y + x^3 + 2*x^2*y^3 + x^2 + x*y^2 + 2*x*y + x + 2*y^4 + 2*y^3 + y + 1 +
-</code> +
- +
-Standard arithmetic function "+", "-", "*", "^" are defined.  However, note due to the fact that their precedence is given in perl it may be necessary to write more parentheses than expected at first sight. For example, as above, you always have to write "($x^2)" because of the lower precedence of the "^" operator. +
- +
-Here is one way to produce polytopes from polynomials (as the convex hull of the exponent vectors of all terms). +
- +
-<code> +
-polytope> $npq=newton($p*$q); +
-polytope> print $npq->VERTICES; +
-1 0 0 +
-1 2 3 +
-1 0 4 +
-1 3 0 +
-1 3 1 +
-polytope> print equal_polyhedra($npq, minkowski_sum(newton($p),newton($q))); +
-+
-</code> +
- +
-The final "1" means "true"The Newton polytope of the product of two polynomials always equals the Minkowski sum of the Newton polytopes of the factors. +
- +
-===== ExampleToric Degeneration ===== +
- +
-The following describes how to construct the polynomial which describes the toric deformation with respect to a point configuration and a height function.  This is the input data: +
- +
-<code> +
-polytope > $points = new Matrix<Int>([1,0],[0,1]); +
-polytope > $height = new Vector<Int>([2,3]); +
-polytope > $coefficients = new Vector<Rational>([-1/2,1/3]); +
-</code> +
- +
-The following is generic (assuming that the dimensions of the objects above match). +
- +
-<code> +
-polytope > @vars = ( "s", map { "x$_" (1..$points->rows()) ); +
-polytope > $R = new Ring(@vars); +
-polytope > $p = new Polynomial($height|$points,$coefficients,$R); +
-</code> +
- +
-Notice that the points are given in Euclidean coordinates; that is, if applied, e.g., to the VERTICES of a polytope do not forget to strip the homogenizing coordinate. The output in our example looks like this: +
- +
-<code> +
-polytope > print $p; +
--1/2*s^2*x1 + 1/3*s^3*x2 +
-</code> +
  
  • user_guide/tutorials/polynomials_tutorial.1487598182.txt.gz
  • Last modified: 2017/02/20 13:43
  • by wagner