Back to Forum | View unanswered posts | View active topics
Topic review - coefficients of multivariable polyomials |
Author |
Message |
|
|
Post subject: |
Re: coefficients of multivariable polyomials |
|
|
thanks gorzel. As always, you come up with a very good reply. I now like this singular code better than the maple one.
Jose
thanks gorzel. As always, you come up with a very good reply. I now like this singular code better than the maple one.
Jose
|
|
|
|
Posted: Tue Apr 04, 2017 11:47 pm |
|
|
|
|
|
Post subject: |
Re: coefficients of multivariable polyomials |
|
|
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.
[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 [/code] [b]Caveat[/b]: 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 [/code] If the variable names consists of single letters only, then -- for the users convenience -- the ^and * can be ommitted. The setting of the variable [i]short[/i] only affcts the output format.
See 6.4 Miscellaneous oddities 2. monomials and precedence [url]http://www.singular.uni-kl.de/Manual/latest/sing_410.htm#SEC450[/url] and [url]http://www.singular.uni-kl.de/Manual/latest/sing_393.htm#SEC433[/url] for [i]short.[/i]
|
|
|
|
Posted: Tue Apr 04, 2017 3:08 pm |
|
|
|
|
|
Post subject: |
coefficients of multivariable polyomials |
|
|
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
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: [/code]
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
|
|
|
|
Posted: Tue Apr 04, 2017 1:52 pm |
|
|
|
|
|
It is currently Fri May 13, 2022 11:01 am
|
|