Loading [MathJax]/jax/output/HTML-CSS/jax.js

First time here? Check out the FAQ!

Ask Your Question
1

Defining family of multivariable polynomials

asked 6 years ago

DCL gravatar image

updated 6 years ago

Brand new to Sage here and trying to define a family of polynomials indexed by natural numbers. In particular, I'd like to be able to generate then perform symbolic calculations with the family of polynomials defined for all nN and all k=0,,2n by pn,k={0if k=0kj=1xjif kn2nk+1j=1xjif k>n

So far the attempts that I've had are of the form:

sage: h = lambda k:sum([var('d_%d' %(i+1)) for i in range(k)])

but I don't seem to easily perform calculations with these. Another method I was trying is defining Q[x0,,xn] then trying to define these polynomials using conditional statements. I seem to keep getting errors stating my variables don't exist.

Would love some help or a hint.

Preview: (hide)

Comments

Your pk silently depends on n. So you want to fix n and study the pk?

vdelecroix gravatar imagevdelecroix ( 6 years ago )

As you write them, your pk are first-degrees polynomials of n variables at most. Is that really what you want ?

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 6 years ago )

That is correct, I'd like to fix any n then study the pk.

Yes, these will be degree 1 polynomials in at most n variables.

DCL gravatar imageDCL ( 6 years ago )

Comments:

  • it might make sense to call the polynomials pn,k.
  • in the case 0<kn, the formula should have xj, not xk
  • indenting the code line h = lambda k: ... by 4 spaces will make it display as code
slelievre gravatar imageslelievre ( 6 years ago )

Thanks for taking all the comments into account and editing your question!

slelievre gravatar imageslelievre ( 6 years ago )

1 Answer

Sort by » oldest newest most voted
2

answered 6 years ago

slelievre gravatar image

updated 6 years ago

Sage has a constructor for polynomial rings in countably many variables.

Using this constructor, the polynomials pn,k in the question can be defined as follows.

Define the polynomial ring Q[x0,x1,x2,...]:

sage: R.<x> = InfinitePolynomialRing(QQ)

Now x[j] gives xj.

sage: x[2]
x_2
sage: x[9876]
x_9876

Define a function p such that p(n, k) gives pn,k:

def p(n, k):
    if n not in NN or k not in NN or k > 2*n:
        raise ValueError("Unsupported values: n = {}, k = {}".format(n, k))
    if k == 0:
        return R.zero()
    if 1 <= k <= n:
        return sum(x[j] for j in (1 .. k))
    # case n < k <= 2* n:
    return sum(x[j] for j in (1 .. 2*n-k+1))

Now p(n, k) returns pn,k:

sage: p(4, 3)
x_3 + x_2 + x_1
sage: p(4, 7)
x_2 + x_1
sage: p(4, 3) + p(4, 7)
x_3 + 2*x_2 + 2*x_1
Preview: (hide)
link

Comments

Thanks, this works perfectly!

DCL gravatar imageDCL ( 6 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 6 years ago

Seen: 329 times

Last updated: May 07 '19