4
$\begingroup$

Question: How do I substitute a value into a polynomial in GAP?

So, if I start off with the following:

x:=Indeterminate(Integers,"x");
f:=x^2+3;

I have $f$ as the polynomial $x^2+3$ over the integers. How can I find, say, $f(100)$?

There should be a simple one line answer, but I can't seem to find it in the help files.

$\endgroup$
  • $\begingroup$ Dear Douglas S.: Sorry if I make this comment here, but there is not a way I could ask a help. I hope you forgive me. Recently, I saw this page. Have you ever seen the codes listed in it? It looks strange to me and it is so interesting to me as well. I will be very thankful if you give me your suggestions or ideas about it. :-) $\endgroup$ – mrs Jun 28 '13 at 10:54
9
$\begingroup$

Please see '?Value':

gap> x:=Indeterminate(Integers,"x");;
gap> f:=x^2+3;;
gap> Value(f,100);
10003

Similarly, for multivariate polynomials do:

gap> x:=Indeterminate(Integers,"x");;
gap> y:=Indeterminate(Integers,"y");;
gap> f:=x*y+y+x^7;
x^7+x*y+y
gap> Value(f,[x,y],[5,7]);
78167

Remark (added later): furthermore, substitution is not limited to the elements of the ring of coefficients. One could, for example, substitute indeterminates like here

gap> x:=Indeterminate(Integers,"x");;
gap> y:=Indeterminate(Integers,"y");;
gap> z:=Indeterminate(Integers,"`");;
gap> f:=x*y+y+x^7+z;
x^7+x*y+y+z
gap> g:=Value(f,[x,y],[z^2,2]);
z^14+2*z^2+z+2
gap> Value(g,2);
16396

or matrices like here:

gap> m:=[ [ 0, -1, -1, 0, 0 ],
>         [ 0,  0,  0, 1, 0 ],
>         [ 0,  0,  0, 0, 1 ],
>         [ 1,  0,  0, 0, 0 ],
>         [ 0,  0,  1, 0, 0 ] ];;
gap> charpol:=CharacteristicPolynomial(m);
x^5-x^3+x^2-1
gap> Value(charpol,m);
[ [ 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0 ], 
  [ 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0 ] ]
$\endgroup$
  • 2
    $\begingroup$ Great! Thanks for that! $\endgroup$ – Douglas S. Stones Mar 31 '13 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.