# Revision history [back]

Polynomials over the symbolic ring can help here.

There is also a way to get a large sequence of indexed variables.

Below we use monomials a_i*x^i rather than a_i*x^j with i + j = degree(p).

Define a polynomial ring in x over the symbolic ring:

sage: R.<x> = SR[]


Define a bunch of indexed symbolic variables:

sage: a = var('a', 100)


Define a polynomial of degree 7, look at it, check the coefficient of x^5 and of x^0:

sage: p = sum(a[k]*x^k for k in range(8))

sage: p
a_7*x^7 + a_6*x^6 + a_5*x^5 + a_4*x^4 + a_3*x^3 + a_2*x^2 + a_1*x + a_0

sage: p[5]
a_5

sage: p[0]
a_0


Define two more symbolic variables:

sage: x0 = SR.var('x0')
sage: z = SR.var('z')


Define the equations specifying values of p and its derivatives at 0, 1 and x0:

sage: eq = [p(0) == 0,
....:       p.diff(1)(0) == 0,
....:       p.diff(2)(0) == 0,
....:       p(1) == 1 + z,
....:       p.diff(1)(1) == 0,
....:       p.diff(2)(1) == 0,
....:       p(x0) == 1,
....:       p.diff(1)(x0) == 1,
....:      ]


Solve the equation, getting the answers as a list of dictionaries:

sage: s = solve(eq, a[:8], solution_dict=True)

sage: s
[{a_0: 0,
a_1: 0,
a_2: 0,
a_3: (10*x0^7 - 28*x0^6 + 21*x0^5 + x0^2 + (10*x0^7 - 28*x0^6 + 21*x0^5)*z
- 8*x0 + 4)/(x0^7 - 4*x0^6 + 6*x0^5 - 4*x0^4 + x0^3),
a_4: -(15*x0^8 - 24*x0^7 - 21*x0^6 + 42*x0^5 + 3*x0^3 - 23*x0^2
+ 3*(5*x0^8 - 8*x0^7 - 7*x0^6 + 14*x0^5)*z + 5*x0
+ 3)/(x0^8 - 4*x0^7 + 6*x0^6 - 4*x0^5 + x0^4),
a_5: 3*(2*x0^8 + 4*x0^7 - 21*x0^6 + 14*x0^5 + 7*x0^4 + x0^3 - 7*x0^2
+ (2*x0^8 + 4*x0^7 - 21*x0^6 + 14*x0^5 + 7*x0^4)*z - 3*x0
+ 3)/(x0^8 - 4*x0^7 + 6*x0^6 - 4*x0^5 + x0^4),
a_6: -(12*x0^7 - 21*x0^6 - 14*x0^5 + 35*x0^4 + x0^3 - 5*x0^2
+ (12*x0^7 - 21*x0^6 - 14*x0^5 + 35*x0^4)*z - 17*x0
+ 9)/(x0^8 - 4*x0^7 + 6*x0^6 - 4*x0^5 + x0^4),
a_7: (6*x0^6 - 18*x0^5 + 15*x0^4 + x0^2
+ 3*(2*x0^6 - 6*x0^5 + 5*x0^4)*z - 7*x0
+ 3)/(x0^8 - 4*x0^7 + 6*x0^6 - 4*x0^5 + x0^4)}]


Polynomials over the symbolic ring can help here.

There is also a way to get a large sequence of indexed variables.

Below we use monomials a_i*x^i rather than a_i*x^j with i + j = degree(p).

Define a polynomial ring in x over the symbolic ring:

sage: R.<x> = SR[]


Define a bunch of indexed symbolic variables:

sage: a = var('a', SR.var('a', 100)


Define a polynomial of degree 7, look at it, check the coefficient of x^5 and of x^0:

sage: p = sum(a[k]*x^k for k in range(8))

sage: p
a_7*x^7 + a_6*x^6 + a_5*x^5 + a_4*x^4 + a_3*x^3 + a_2*x^2 + a_1*x + a_0

sage: p[5]
a_5

sage: p[0]
a_0


Define two more symbolic variables:

sage: x0 = SR.var('x0')
sage: z = SR.var('z')


Define the equations specifying values of p and its derivatives at 0, 1 and x0:

sage: eq = [p(0) == 0,
....:       p.diff(1)(0) == 0,
....:       p.diff(2)(0) == 0,
....:       p(1) == 1 + z,
....:       p.diff(1)(1) == 0,
....:       p.diff(2)(1) == 0,
....:       p(x0) == 1,
....:       p.diff(1)(x0) == 1,
....:      ]


Solve the equation, getting the answers as a list of dictionaries:

sage: s = solve(eq, a[:8], solution_dict=True)

sage: s
[{a_0: 0,
a_1: 0,
a_2: 0,
a_3: (10*x0^7 - 28*x0^6 + 21*x0^5 + x0^2 + (10*x0^7 - 28*x0^6 + 21*x0^5)*z
- 8*x0 + 4)/(x0^7 - 4*x0^6 + 6*x0^5 - 4*x0^4 + x0^3),
a_4: -(15*x0^8 - 24*x0^7 - 21*x0^6 + 42*x0^5 + 3*x0^3 - 23*x0^2
+ 3*(5*x0^8 - 8*x0^7 - 7*x0^6 + 14*x0^5)*z + 5*x0
+ 3)/(x0^8 - 4*x0^7 + 6*x0^6 - 4*x0^5 + x0^4),
a_5: 3*(2*x0^8 + 4*x0^7 - 21*x0^6 + 14*x0^5 + 7*x0^4 + x0^3 - 7*x0^2
+ (2*x0^8 + 4*x0^7 - 21*x0^6 + 14*x0^5 + 7*x0^4)*z - 3*x0
+ 3)/(x0^8 - 4*x0^7 + 6*x0^6 - 4*x0^5 + x0^4),
a_6: -(12*x0^7 - 21*x0^6 - 14*x0^5 + 35*x0^4 + x0^3 - 5*x0^2
+ (12*x0^7 - 21*x0^6 - 14*x0^5 + 35*x0^4)*z - 17*x0
+ 9)/(x0^8 - 4*x0^7 + 6*x0^6 - 4*x0^5 + x0^4),
a_7: (6*x0^6 - 18*x0^5 + 15*x0^4 + x0^2
+ 3*(2*x0^6 - 6*x0^5 + 5*x0^4)*z - 7*x0
+ 3)/(x0^8 - 4*x0^7 + 6*x0^6 - 4*x0^5 + x0^4)}]


Polynomials over the symbolic ring can help here.

There is also a way to get a large sequence of indexed variables.

Below we use monomials a_i*x^i rather than a_i*x^j with i + j = degree(p).

Define a polynomial ring in x over the symbolic ring:

sage: R.<x> = SR[]


Define a bunch of indexed symbolic variables:

sage: a = SR.var('a', 100)


Define a polynomial of degree 7, look at it, check the coefficient of x^5 and of x^0:

sage: p = sum(a[k]*x^k for k in range(8))

sage: p
a_7*x^7 + a_6*x^6 + a_5*x^5 + a_4*x^4 + a_3*x^3 + a_2*x^2 + a_1*x + a_0

sage: p[5]
a_5

sage: p[0]
a_0


Another way to create the same polynomial:

sage: p = R(a[:8])


Define two more symbolic variables:

sage: x0 = SR.var('x0')
sage: z = SR.var('z')


Define the equations specifying values of p and its derivatives at 0, 1 and x0:

sage: eq = [p(0) == 0,
....:       p.diff(1)(0) == 0,
....:       p.diff(2)(0) == 0,
....:       p(1) == 1 + z,
....:       p.diff(1)(1) == 0,
....:       p.diff(2)(1) == 0,
....:       p(x0) == 1,
....:       p.diff(1)(x0) == 1,
....:      ]


Solve the equation, getting the answers as a list of dictionaries:

sage: s = solve(eq, a[:8], solution_dict=True)

sage: s
[{a_0: 0,
a_1: 0,
a_2: 0,
a_3: (10*x0^7 - 28*x0^6 + 21*x0^5 + x0^2 + (10*x0^7 - 28*x0^6 + 21*x0^5)*z
- 8*x0 + 4)/(x0^7 - 4*x0^6 + 6*x0^5 - 4*x0^4 + x0^3),
a_4: -(15*x0^8 - 24*x0^7 - 21*x0^6 + 42*x0^5 + 3*x0^3 - 23*x0^2
+ 3*(5*x0^8 - 8*x0^7 - 7*x0^6 + 14*x0^5)*z + 5*x0
+ 3)/(x0^8 - 4*x0^7 + 6*x0^6 - 4*x0^5 + x0^4),
a_5: 3*(2*x0^8 + 4*x0^7 - 21*x0^6 + 14*x0^5 + 7*x0^4 + x0^3 - 7*x0^2
+ (2*x0^8 + 4*x0^7 - 21*x0^6 + 14*x0^5 + 7*x0^4)*z - 3*x0
+ 3)/(x0^8 - 4*x0^7 + 6*x0^6 - 4*x0^5 + x0^4),
a_6: -(12*x0^7 - 21*x0^6 - 14*x0^5 + 35*x0^4 + x0^3 - 5*x0^2
+ (12*x0^7 - 21*x0^6 - 14*x0^5 + 35*x0^4)*z - 17*x0
+ 9)/(x0^8 - 4*x0^7 + 6*x0^6 - 4*x0^5 + x0^4),
a_7: (6*x0^6 - 18*x0^5 + 15*x0^4 + x0^2
+ 3*(2*x0^6 - 6*x0^5 + 5*x0^4)*z - 7*x0
+ 3)/(x0^8 - 4*x0^7 + 6*x0^6 - 4*x0^5 + x0^4)}]