Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow function-call syntax for evaluating univariate polynomials #4296

Merged
merged 1 commit into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions hpcgap/lib/ratfun.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,20 @@ function(f,g)
TryNextMethod();
end);

#############################################################################
##
#M <upol>(<val>)
##
## Method to allow univariate polynomials to be used like functions when
## appropriate
InstallMethod(CallFuncList, [IsUnivariatePolynomial, IsList],
function(poly, lst)
if Length(lst) <> 1 then
TryNextMethod();
fi;
return Value(poly, lst[1]);
end);

#############################################################################
##
#M Value
Expand Down
2 changes: 2 additions & 0 deletions lib/ratfun.gd
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,8 @@ DeclareOperation( "UnivariateRationalFunctionByCoefficients",
## The second version takes an univariate rational function and specializes
## the value of its indeterminate to <A>val</A>.
## Again, an optional argument <A>one</A> may be given.
## <C>Value( <A>upol</A>, <A>val</A> )</C> can also be expressed as <C>upol(
## <A>val</A> )</C>.
## <P/>
## <Example><![CDATA[
## gap> Value(x*y+y+x^7,[x,y],[5,7]);
Expand Down
14 changes: 14 additions & 0 deletions lib/ratfun.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,20 @@ function(f,g)
TryNextMethod();
end);

#############################################################################
wucas marked this conversation as resolved.
Show resolved Hide resolved
##
#M <upol>(<val>)
##
## Method to allow univariate polynomials to be used like functions when
## appropriate
InstallMethod(CallFuncList, [IsUnivariatePolynomial, IsList],
function(poly, lst)
if Length(lst) <> 1 then
TryNextMethod();
fi;
return Value(poly, lst[1]);
end);

#############################################################################
##
#M Value
Expand Down
10 changes: 10 additions & 0 deletions tst/testinstall/ratfun.tst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ gap> Value(t^0,-1);
gap> Value(t,-1);
-1

#
gap> t(0);
0
gap> t(1);
1
gap> (t+1)(3);
4
gap> data[4](3);
4

#
gap> y1:=Indeterminate(Rationals,1);;
gap> y2:=Indeterminate(Rationals,2);;
Expand Down
12 changes: 12 additions & 0 deletions tst/testinstall/ratfun_gf5.tst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ Z(5)^0
gap> Value(t,-1);
Z(5)^2

#
gap> data[1](0);
0
gap> 0*t(1);
0*Z(5)
gap> (0*t)(1);
0
gap> data[4](3);
Z(5)^2
gap> (t+Z(5)^0)(3);
Z(5)^2

#
gap> y1:=Indeterminate(Rationals,1);;
gap> y2:=Indeterminate(Rationals,2);;
Expand Down