Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: coefficients of multivariable polyomials
PostPosted: 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.

Thanks for any advise!

Jose


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: coefficients of multivariable polyomials
PostPosted: Tue Apr 04, 2017 3:08 pm 

Joined: Wed Mar 03, 2010 5:08 pm
Posts: 103
Location: Germany,
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++) {
  h = h + absValue(leadcoef(f[i]))*leadmonom(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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: coefficients of multivariable polyomials
PostPosted: 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


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

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

It is currently Tue Dec 12, 2017 10:11 am
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group