Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
tutorial:polynomials_tutorial [2017/02/20 13:44] – [Example: Toric Degeneration] wagner | tutorial:polynomials_tutorial [2017/07/06 16:06] – [Basic Usage of Polynomials in Perl] formatting oroehrig | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== Basic Usage of Polynomials in Perl ===== | + | A short note on variable naming up front: You can alter the settings for the names that are used for polynomial |
- | + | ||
- | A polynomial | + | |
< | < | ||
- | polytope> $r=new Ring(qw(x y)); | + | > reset_custom %polynomial_var_names; |
</ | </ | ||
- | It may be convenient | + | ===== Usage of Polynomials in Perl ===== |
+ | ===Constructors=== | ||
+ | The easiest way to create a simple [[https:// | ||
< | < | ||
- | polytope> ($x,$y)=$r->variables; | + | > $p = new Polynomial("4 + 3x_1 + x_2^5" |
+ | </ | ||
+ | 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, $exp); | ||
+ | > print $p2; | ||
+ | -5*x_0^8*x_1^3 + 9*x_1^4 | ||
+ | </code> | ||
+ | There is a seperate type for univariate polynomials, | ||
+ | < | ||
+ | > $up = new UniPolynomial(" | ||
</ | </ | ||
- | Notice that the variable names are chosen | + | Polynomials (and UniPolynomials) |
< | < | ||
- | polytope | + | > $pp = new UniPolynomial< |
- | polytope | + | > print $pp; |
- | polytope | + | (4*x^2 + 5)*y^3/2 + (-5/3*x^4)*y^2/3 |
- | 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 | + | </ |
+ | ===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 "($p^2)" because of the lower precedence of the " | ||
+ | < | ||
+ | > print $p + $p^2; | ||
+ | 36*x_1^2 + 24*x_1*x_2^5 + 96*x_1 | ||
+ | </ | ||
+ | For UniPolynomials, | ||
+ | < | ||
+ | > print (($up^2)/ | ||
+ | (2*x^2 + 3*x + 4)/(1) | ||
</ | </ | ||
- | Standard arithmetic function " | + | ===Example: Newton Polynomials=== |
Here is one way to produce polytopes from polynomials (as the convex hull of the exponent vectors of all terms). | 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> | + | polytope > print $np-> |
- | 1 0 0 | + | 1 0 0 0 |
- | 1 2 3 | + | 1 0 2 0 |
- | 1 0 4 | + | 1 0 0 10 |
- | 1 3 0 | + | polytope > print equal_polyhedra($np, |
- | 1 3 1 | + | |
- | polytope> | + | |
1 | 1 | ||
</ | </ | ||
Line 40: | Line 60: | ||
The final " | The final " | ||
- | ===== Example: Toric Degeneration | + | === Example: Toric Degeneration === |
The following describes how to construct the polynomial which describes the toric deformation with respect to a point configuration and a height function. | The following describes how to construct the polynomial which describes the toric deformation with respect to a point configuration and a height function. | ||
Line 53: | Line 73: | ||
< | < | ||
- | polytope > @vars = ( " | + | polytope > $p = new Polynomial($height|$points, |
- | polytope > $R = new Ring(@vars); | + | |
- | polytope > $p = new Polynomial($height|$points, | + | |
</ | </ | ||