# Singular

 Page 1 of 1 [ 3 posts ]
 Print view | E-mail friend Previous topic | Next topic
Author Message
 Post subject: coefficients of multivariable polyomialsPosted: Tue Apr 04, 2017 1:52 pm

Joined: Sat Feb 18, 2017 10:08 am
Posts: 4
In maple I can create the following procedure:

Code:
positivify := proc(f,vars)
description "takes a multivariable polynomial and changes its coefficient to positive"
local c:
c:=coeffs(f,vars,'t'):
convert([seq(abs(c[i])*t[i],i=1..nops([t]))],`+`);
end proc:

What this does is take a multivariable polynomial over the real numbers, say e.g. 4x^2-x+2xy-3z^4,
and creates a new polynomial with the same number of monomials and individual degree of variables but with coefficients that are the absolute value of the coefficient of the old monomials, so for the example it creates 4x^2+x+2xy+3z^4.

I would like to do the same in singular. Here, I believe, coeffs in singular works for univariate case (so I need to inquire the coeff of x but then I get values in R[y,z]). Any hints of how I can most efficiently program this in singular? I suppose there is naive way to just walk through all the coefficients of each indeterminate and check for the coefficient, but I fear I will end up writing a very long procedure that way.

Jose

Top

 Post subject: Re: coefficients of multivariable polyomialsPosted: Tue Apr 04, 2017 3:08 pm

Joined: Wed Mar 03, 2010 5:08 pm
Posts: 106
Location: Germany, Münster
Code:
> LIB "general.lib";  // to have the proc absValue at your disposal
> proc positify(poly f) {
poly h;
for (int i=0;i<=size(f);i++) {
}
return(h);
}
> ring r3 = 0,(x,y,z),dp;
> poly F = 4*x^2-x+2xy-3*z^4;
3z4+4x2+2xy+x
> short =0;
_;
> 3*z^4+4*x^2+2*x*y+x

Caveat: When you use the exponentiation sing ^ in the input, then you should also put the * between the variables and the coefficients.
Otherwise everything to the left of an ^ (upto an +,-) is treated as a single token.
Code:
> -2x3y^2;
-4x6y2
> -2*x^3*y^2;
-2x3y2

If the variable names consists of single letters only, then -- for the users convenience -- the ^and * can be ommitted.
The setting of the variable short only affcts the output format.

See 6.4 Miscellaneous oddities 2. monomials and precedence
http://www.singular.uni-kl.de/Manual/latest/sing_410.htm#SEC450
and
http://www.singular.uni-kl.de/Manual/latest/sing_393.htm#SEC433 for short.

Top

 Post subject: Re: coefficients of multivariable polyomialsPosted: Tue Apr 04, 2017 11:47 pm

Joined: Sat Feb 18, 2017 10:08 am
Posts: 4
thanks gorzel. As always, you come up with a very good reply. I now like this singular code better than the maple one.

Jose

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 3 posts ]

 You can post new topics in this forumYou can reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

 It is currently Thu Oct 18, 2018 9:19 am