0

I have some problems dealing with polynomials in Pari and finding the right commands in the documentation.

  1. is it possible to define Polynomials with multiple variables, e.g. f(x,y)=x^2+y^2-1
  2. How can I evaluate a previously defined polynomial (by using Pol() ) at a specific value?
Andrew
  • 873
  • 4
  • 10
klirk
  • 127
  • 4

2 Answers2

3

Yes it is possible to use polynomials with multiple variables. For example x^2 + y^2 - 1 is a polynomial in the variables x and y. Use subst to evaluate a polynomial at a specific value. For example, subst(x^2 + y^2 - 1, y, 3) gives x^2 + 8.

PARI assumes any undefined variables are polynomials. The above works because x and y have not been given another definition. For this reason it is best to avoid using x and y for other things. For example if you enter x=5, then x is defined to be 5 and will no longer be interpreted as a polynomial.

Now f(x,y)=x^2+y^2-1 is not a polynomial, but rather a function definition with two formal arguments x and y. You can call f with the polynomial arguments x and y to get a polynomial and can also call f with other arguments. For example, f(x,y) returns the polynomial x^2 + y^2 - 1 and f(x, 3) returns x^2 + 8.

The purpose of Pol() is rather to convert something else such as a vector into a polynomial. For example, Pol([3,1,5]) gives 3*x^2 + x + 5.

Andrew
  • 873
  • 4
  • 10
  • Thx for your answer. So if I want f to be a polynomial, i simply need to define it by f=x^2+y^2+1? – klirk Jan 12 '18 at 12:49
  • 1
    How can I evaluate a power series? I know that I can convert them to polynomials, but this gives only correct values for x close to 0 – klirk Jan 12 '18 at 13:00
2

PARI also does power series. For example 1/(1-x-x^2) + O(x^20) is the power series expansion up to 20 terms. You need to specify the number of terms required (PARI does not expand infinitely). Use Vec() to convert into a vector. For example, Vec(1/(1-x-x^2) + O(x^20)) gives the first 20 terms of the Fibonacci series.

Multivariate power series are also possible, but you need to be careful with variable priority. If you use x as the primary power series variable (indeterminate) and y as the secondary variable it will work. On the other hand if you want to use z as the primary variable and t as the secondary variable you may run into issues depending on which order z and t are first used. Priority of variables is a messy issue and is best avoided by knowing that x and y are predefined with x having higher priority than y.

(If you have more questions, please submit a new question - I don't really want this to become a blog on all PARI features!)

Andrew
  • 873
  • 4
  • 10