I want to write a function to give the Groebner basis respect to lex order of two input polynomials, but the numbers of variables are given by the input, not known a priori. To be precise, I start with:
GBoftwo:=proc(f,g,Var)
where Var is a list of variables, for example the the input can be GBoftwo(x^2+y,x+z^2,[x,y,z]). Then the entire code could be:
GBoftwo:=proc(f,g,Var)
with(Groebner);
local F, n;
F:=[f,g];
n:=nops(Var);
retern Basis(F,plex(Var[1],...,Var[n]))
end proc;
Then the error massage says: Error, unable to parse.
How can I overcome this problem?
Thanks!
I didn't figure it out by any method, I don't know if it's the defect of the Basis command.
You got the error message because you misspelled return
as retern
. So you have a syntax error.
You cannot properly utilize with
inside a procedure.
You should uneval-quote the global name plex
, since it's not a protected name and could be assigned some value at the top-level.
You don't need n
, since op(Var)
provides the expression sequence of the elements of the list Var
.
restart;
GBoftwo:=proc(f,g,Var::list(name))
uses Groebner;
local F:=[f,g];
return Basis(F,':-plex'(op(Var)))
end proc:
GBoftwo(x^2+y,x+z^2,[x,y,z])
[ 4 2 ]
[z + y, z + x]
GBoftwo(x^2+y,x+z^2,[y,x,z])
[ 2 4 ]
[z + x, z + y]
note: Yout example procedure is quite simple, and can be further simplified to just a single line (at which point it's hardly a time-saver; you could as easily just call Basis
directly). Hence I suppose that you are practicing/learning, and that this is just a programming experiment.
restart;
GBoftwo:=proc(f,g,Var::list(name))
Groebner:-Basis([f,g],':-plex'(op(Var)))
end proc:
GBoftwo(x^2+y,x+z^2,[x,y,z])
[ 4 2 ]
[z + y, z + x]
with(Groebner):
# and now, just a few characters longer...
Basis([x^2+y,x+z^2],plex(x,y,z))
[ 4 2 ]
[z + y, z + x]