Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revisionLast revisionBoth sides next revision | ||
tutorial:polynomials_tutorial [2010/03/28 10:01] – joswig | user_guide:tutorials:polynomials_tutorial [2019/01/25 09:38] – ↷ Page moved from user_guide:polynomials_tutorial to user_guide:tutorials:polynomials_tutorial oroehrig | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== Basic Usage of Polynomials | + | A short note on variable naming up front: You can alter the settings for the names that are used for polynomial variables |
+ | < | ||
+ | > reset_custom %polynomial_var_names; | ||
+ | </ | ||
- | A polynomial always carries a reference | + | ===== Usage of Polynomials in Perl ===== |
+ | ===Constructors=== | ||
+ | The easiest way to create | ||
+ | < | ||
+ | > $p = new Polynomial(" | ||
+ | </ | ||
+ | Sometimes it's convenient to use the constructor that takes a vector of coefficients and a matrix of exponents: | ||
+ | < | ||
+ | > $coeff = new Vector([9,-5]); | ||
+ | > $exp = new Matrix< | ||
+ | > $p2 = new Polynomial($coeff, | ||
+ | > print $p2; | ||
+ | -5*x_0^8*x_1^3 + 9*x_1^4 | ||
+ | </ | ||
+ | There is a seperate type for univariate polynomials, | ||
+ | < | ||
+ | > $up = new UniPolynomial(" | ||
+ | </ | ||
+ | Polynomials (and UniPolynomials) are templated by their coefficient and exponent types, defaulting to Rational for coefficients and Int for exponents. You can even have polynomials of polynomials (of polynomials...). | ||
< | < | ||
- | $r=new Ring(qw(x y)); | + | > $pp = new UniPolynomial< |
+ | > print $pp; | ||
+ | (4*x^2 + 5)*y^3/2 + (-5/3*x^4)*y^2/3 | ||
+ | </ | ||
+ | ===Computations=== | ||
+ | The standard arithmetic functions " | ||
+ | < | ||
+ | > print $p + ($p^2); | ||
+ | 9*x_1^2 + 6*x_1*x_2^5 + 27*x_1 + x_2^10 + 9*x_2^5 + 20 | ||
+ | </ | ||
+ | However, note that 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 " | ||
+ | < | ||
+ | > print $p + $p^2; | ||
+ | 36*x_1^2 + 24*x_1*x_2^5 + 96*x_1 + 4*x_2^10 + 32*x_2^5 + 64 | ||
+ | </ | ||
+ | For UniPolynomials, | ||
+ | < | ||
+ | > print (($up^2)/ | ||
+ | (2*x^2 + 3*x + 4)/(1) | ||
</ | </ | ||
- | It may be convenient | + | ===Example: Newton Polynomials=== |
+ | Here is one way to produce polytopes from polynomials (as the convex hull of the exponent vectors of all terms). | ||
< | < | ||
- | polytope> | + | polytope > $np = newton($p*($p+$p)); |
+ | polytope > print $np->VERTICES; | ||
+ | 1 0 0 0 | ||
+ | 1 0 2 0 | ||
+ | 1 0 0 10 | ||
+ | polytope > print equal_polyhedra($np, | ||
+ | 1 | ||
</ | </ | ||
- | Notice that the variable names are chosen | + | The final " |
+ | |||
+ | === Example: Toric Degeneration === | ||
+ | |||
+ | The following describes how to construct | ||
< | < | ||
- | polytope> | + | polytope > $points |
- | polytope> | + | polytope > $height |
- | polytope> | + | polytope > $coefficients = new Vector< |
- | 1 + 2*x + x^2 + 2*y + 3*x*y + y^2 + x^2*y + x*y^2 | + | |
</ | </ | ||
- | Standard arithmetic function " | + | The following |
- | Here is one way to produce polytopes from polynomials (as the convex hull of the exponent vectors of all terms). | + | < |
+ | polytope > $p = new Polynomial($coefficients, | ||
+ | </ | ||
+ | |||
+ | Notice that the points are given in Euclidean coordinates; | ||
< | < | ||
- | polytope> | + | polytope > print $p; |
- | polytope> | + | 1/ |
- | 1 0 0 | + | |
- | 1 2 0 | + | |
- | 1 0 2 | + | |
- | 1 2 1 | + | |
- | 1 1 2 | + | |
- | polytope> | + | |
- | 1 | + | |
</ | </ | ||
- | The final " | ||