0
$\begingroup$

From a list of integers of length $2^d$ where $d\in \mathbb{N}$ I would like to generate a homogeneous bivariate polynomial of degree $d$. To fix ideas, let $$ l=\{a,b,c,d,e,f,g,h\}$$ ( length $2^3$) where $a,...,h \in \mathbb{R}$. I would like to define a function MultiPolGenerator such that $$\text{MultiPolGenerator[l,d]}= ax^3 + \frac{b+c+d}{3} x^2y + \frac{e+f+g}{3} xy^2 + h y^3 $$

Equivalently if it suits you best, let $$ l=\{a,b,b,b,c,c,c,d\},$$ I would like to define a function MultiPolGenerator such that $$\text{MultiPolGenerator[l,d]}= ax^3 + b x^2y + c xy^2 + d y^3 $$

An answer to either the first or the second question will be accepted. I have tried to use Internal`FromCoefficientList but the output isn't what I would expect.

Side note : it would be great if, instead of a definite number of variables (2 in this case), the function would work for an indefinite number of variables $N$

$\endgroup$
2
  • 3
    $\begingroup$ $2^x$ grows pretty fast, what names would you use for coefficients since there is only 26 letters in alphabet? For $2^5=32$ there is already too few letters. $\endgroup$ Sep 21, 2022 at 15:49
  • $\begingroup$ I acknowledge that the notation I used was unclear. I have edited the "let l=..." part to make it clear, thanks for your comment :) $\endgroup$
    – Baloo
    Sep 22, 2022 at 7:55

1 Answer 1

1
$\begingroup$

We may generate names for the different constants using "Array" The number of constants belonging to a monomial can be generated by "Binomial". The constants can then be partitioned using "TakeList". Then we need to divide the constants by the corresponding divisor. The different monomials can be generated using "Table". Then having the constants and the monomials, we only need to assemble the homogeneous function using "MapThread":

d = 3;
bin = Table[Binomial[d, i], {i, 0, d}];
const = TakeList[Array[Subscript[a, #] &, 2^d], bin];
const = #/Length[#] & /@ const;
monomials = Table[x^i y^(d - i), {i, 0, d}];
Plus @@ MapThread[Total[Times[#1, #2]] &, {monomials, const}] 

enter image description here

$\endgroup$
3
  • $\begingroup$ Thanks for your answer :) Here is a list of problems I encounter running your code : TakeList::splist: bin is not a list of sequence specifications. Power::infy: Infinite expression 1/0 encountered. TakeList::splist: ComplexInfinity is not a list of sequence specifications. MapThread::mptd: Object TakeList[{1/8,1/8,1/4,1/2,0,3/4,5/8,1},ComplexInfinity] at position {2, 2} in MapThread[Total[#1 #2]&,{{y^3,x y^2,x^2 y,x^3},TakeList[{1/8,1/8,1/4,1/2,0,3/4,5/8,1},ComplexInfinity]}] has only 0 of required 1 dimensions. Do you see where these problems come from ? $\endgroup$
    – Baloo
    Sep 22, 2022 at 7:48
  • $\begingroup$ I apologize. I forget to copy the line: bin = Table[Binomial[d, i], {i, 0, d}]. I fixed it, no it should run. $\endgroup$ Sep 22, 2022 at 10:14
  • $\begingroup$ This is what I looked for, thanks a lot :) $\endgroup$
    – Baloo
    Sep 22, 2022 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.