I have a List j={j[1],j[3],j[6]}. But this list is in fact a variable of my code, so i could have j={j[6],j[10]} either.

I need to define a function like this :


So I wanted to do the following:

seqList=Sequence @@ j

But the problem with that is seqList will not have the "_" after the variable. I would have a sequence that will look like j[[1]],j[[2]],... and NOT j[[1]]_, j[[2]]_

So how to define a sequence of parameters with the "_" after.

What is my actual goal :

I need to automatize a polynomial identification at the maximum.

I have a function that creates a polynomial with variable coefficient. This is :

CreerPoly[{j}, {degrees}]

For example if I want to create a polynome depending on x and y with degree 2 in aa and 1 in bb I will call CreerPoly[{aa,bb}, {2,1}]

And it will return me :

A[0, 0] + bb A[0, 1] + aa A[1, 0] + aa bb A[1, 1] + aa^2 A[2, 0] + 
 aa^2 bb A[2, 1]

I have a script that determines on how many variables my polynome will depends and at which degree.

And I need from this information to create the associated polynome.

But as I need to solve equations, I want that this polynome is a function of the variable I have found because I need to change the variables to solve the equations. For example if it depends on x,y,z I want to have a function : myFinalPolynome[x,y,z]. And of course as I said I don't know at the beginning how many variables I will have in my polynome.

  • 2
    $\begingroup$ Can you elaborate what your actual goal is? This looks suspicious like a XY problem and looks like a bad idea. $\endgroup$ – Sascha Jun 20 '17 at 10:09
  • $\begingroup$ I updated my question ! $\endgroup$ – StarBucK Jun 20 '17 at 10:18
  • 1
    $\begingroup$ I see many problems with your syntax. If you have j={j[1],j[3],j[6]}, this definition is recursive (you have j on the left and right sides of the assignment). Next, you have patterns named as list elements. j[[n]]_ is not a valid pattern as j[[n]] cannot be used as a name for a pattern. What exactly did you want to achieve with this? I think, you're looking for BlankSequence and BlankNullSequence which allow for variable number of arguments, but it's not clear, why you don't want to have the function take a (variable-length) list as its single argument. $\endgroup$ – LLlAMnYP Jun 20 '17 at 10:34
  • $\begingroup$ For j={j[1],j[3],j[6]} you are right, I wrote a little too fast my message. For j[[n]]_ I didn't know we could'nt use it as a Pattern. I added a part to my message to explain what I wanted to do. $\endgroup$ – StarBucK Jun 20 '17 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.