Polynomials

The jetpoly class represents a polynomial in several variables.

Example to generate two monomials p1 = (2 + i)*x0 and p2 = -0.5*x1**2 (where p1 has complex coefficient):

  from njet import jetpoly

  p1 = jetpoly(2 + 1j, index=0, power=1)
  p2 = jetpoly(-0.5, index=1, power=2)
  87*p1**1 + (p1 - p2)*(p1 + p2) + 6
> [(174+87j)*x0**1 +
  6 +
  (3+4j)*x0**2 +
  -0.25*x1**4]

These polynomials can be used as jet entries:

  from njet import jet

  j1p = jet(p1, p1, 0)
  j2p = jet(0.22, p2, 0, 0)
  j1p*j2p
> 3-jet([(0.44+0.22j)*x0**1], [(0.44+0.22j)*x0**1 + (-1-0.5j)*x0**1*x1**2], [(-2-1j)*x0**1*x1**2], [0])

Note that elementary functions can be applied only on those jets containing polynomials in the higher-order components. The next example will work:

  from njet.functions import sin

  j3p = jet(1, p1, 0, 0)
  sin(j2p*j3p)
> 3-jet(0.21822962308086932, [(0.4293948777054664+0.2146974388527332j)*x0**1 + -0.48794872466530276*x1**2], [-0.05455740577021733*x1**4 + (-0.03168694127134222-0.0422492550284563j)*x0**2 + (-1.8557738645056285-0.9278869322528143j)*x0**1*x1**2], [(0.6446451181643271+0.859526824219103j)*x0**2*x1**2 + (-0.9767350275217077-0.48836751376085386j)*x0**1*x1**4 + (-0.020782712080944576-0.11430491644519516j)*x0**3 + 0.12198718116632569*x1**6])

However, an expression of the form sin(j1p) will not work. The reason is that an elementary function applied on a class of type jetpoly is not defined.

class njet.poly.jetpoly(value=0, index: int = 0, power: int = 0, **kwargs)

Implementation of a polynomial with arbitrary number of variables.

The information of the coefficients is stored internally as dictionary in the ‘terms’ field. One can use the ‘terms’ field as keyworded argument in order to construct a custom polynomial.

A polynomial p can be initiated with a value v and (optional) its index (describing the variable) and power n so that overall p = v*x_i**n. A general polynomial in several variables can then be constructed by successive addition and multiplication of different classes with each other.

Example

self.terms = {
frozenset({(0, 1)}): 11,
frozenset({(0, 4), (1, 22), (13, 1)}): 89,
frozenset({(4, 9), (7, 2), (12, 33)}): -0.22
}
The interpretation is:
11*x0**1 +
89*x0**4*x1**22*x13**1 +
-0.22*x4**9*x7**2*x12**33
conjugate()

Conjugate the terms of the current polynomial.

Consider the following example: Let f = u + 1j*v be a complex function in which u and v are real functions from R^2 -> R^2. Denote by Df := partial f/partial z and D’f := partial f/partial bar z the Wirtinger operators and for any g = x + 1j*y the complex conjugation g’ = x - 1j*y. Then we have for the differential of f:

df = Df*dz + D’f*dz’,

(df)’ = D(f’)*dz + D’(f’)*dz’.

Since our polynomials represent differentials, in this example df plays the role of a polynomial of the two independent variables dz and dz’ (the variables z and z’ behave independent when applying the Wirtinger operators to any function g(z, z’), as one can show). This means that in the complex case conjugation should be propagated to the underlying function: f –> f’, without changing the differentials themselves (the keys of self.terms).

However, this requires that the keys (related to the variables) are prepared in advance accordingly: Every variable needs his complex-conjugate partner, and in the original expression complex conjugation needs to be replaced by this partner variable.

Returns

Return type

jetpoly

get_order(return_indices=False)

Return the order of the current polynomial.

Parameters

return_indices (boolean, optional) – If true, also return the indices of the current polynomial.

Returns

  • int – The order.

  • set – A set of indices as described above.

taylor_coefficients(n_args: int = 0, facts=[], mult_prm: bool = True, mult_drv: bool = True)

Obtain the Taylor coefficients of the current polynomial.

Parameters
  • n_args (int, optional) – The total number of involved parameters. If nothing specified, the number of involved variables is determined from the current indices of the polynomial.

  • facts (list, optional) – A list containing the factorial numbers up to the maximal order in the current polynomial. Hereby it must hold facts[k] = k!

  • mult_prm (bool, optional) – Whether or not to include multiplicities into the final result related to the permutation of expressions (e.g. derivatives).

  • mult_drv (bool, optional) – Whether or not to include multiplicities related to the derivatives of powers.

Returns

A dictionary of the form “tuple: value”, where “tuple” consists of series of powers, hereby the entry j denotes the power of the j-th variable.

Return type

dict

truncate(max_power)

Drop all terms beyond a specific power.

Parameters

max_power (int) – The maximal power beyond which we want to drop terms.

Returns

A jetpoly object of power up (and including) max_power.

Return type

jetpoly