PADE

Overview

The PADE function computes a Padé approximant to a polynomial, expressing it as the ratio of two polynomials. Named after French mathematician Henri Padé, who developed the technique around 1890, Padé approximants provide a powerful method for approximating functions that often outperforms truncated Taylor series—particularly near singularities or where the Taylor series converges slowly or diverges.

A Padé approximant of order [m/n] is a rational function:

R(x) = \frac{P(x)}{Q(x)} = \frac{a_0 + a_1 x + a_2 x^2 + \cdots + a_m x^m}{1 + b_1 x + b_2 x^2 + \cdots + b_n x^n}

where the coefficients are chosen so that the Taylor series expansion of R(x) matches the Taylor series of the original function up to order m + n. The numerator polynomial P(x) has degree m, and the denominator polynomial Q(x) has degree n.

This implementation uses the scipy.interpolate.pade function from SciPy. The function accepts Taylor series coefficients in increasing order of powers along with the desired orders m and n for the numerator and denominator polynomials. It returns two rows of coefficients: the numerator polynomial coefficients in the first row and the denominator polynomial coefficients in the second row, both in descending order of powers.

Padé approximants are widely used in numerical analysis, control systems, and scientific computing. They excel at representing functions with poles or branch cuts, approximating transcendental functions (such as exponentials, logarithms, and trigonometric functions), and improving convergence in computational algorithms. For example, the classic [2/2] Padé approximant of e^x provides excellent accuracy over a wide range with just a simple rational expression.

For more details on the mathematical theory, see the Wikipedia article on Padé approximants or the Wolfram MathWorld entry.

This example function is provided as-is without any representation of accuracy.

Excel Usage

=PADE(an, m, n)
  • an (list[list], required): Taylor series coefficients in increasing order of powers
  • m (int, required): Order of the numerator polynomial
  • n (int, required): Order of the denominator polynomial

Returns (list[list]): 2D list with two rows - numerator coefficients (first row) and denominator coefficients (second row), both in descending order of powers. Returns error message (str) if invalid input.

Examples

Example 1: Pade [1/1] approximation for exponential series

Inputs:

an m n
1 1 0.5 0.1667 1 1

Excel formula:

=PADE({1,1,0.5,0.1667}, 1, 1)

Expected output:

Result
0.5 1
-0.5 1

Example 2: Pade [2/2] approximation for exponential series

Inputs:

an m n
1 1 0.5 0.1667 0.04167 2 2

Excel formula:

=PADE({1,1,0.5,0.1667,0.04167}, 2, 2)

Expected output:

Result
0.0831 0.4996 1
0.0835 -0.5004 1

Example 3: Pade [1/0] for simple polynomial coefficients

Inputs:

an m n
1 2 3 1 0

Excel formula:

=PADE({1,2,3}, 1, 0)

Expected output:

Result
1
-2 1

Example 4: Pade [2/0] for polynomial with alternating zeros

Inputs:

an m n
1 0 1 0 1 2 0

Excel formula:

=PADE({1,0,1,0,1}, 2, 0)

Expected output:

Result
1
-1 0 1

Python Code

from scipy.interpolate import pade as scipy_interpolate_pade

def pade(an, m, n):
    """
    Compute Pade rational approximation to a polynomial.

    See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.pade.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        an (list[list]): Taylor series coefficients in increasing order of powers
        m (int): Order of the numerator polynomial
        n (int): Order of the denominator polynomial

    Returns:
        list[list]: 2D list with two rows - numerator coefficients (first row) and denominator coefficients (second row), both in descending order of powers. Returns error message (str) if invalid input.
    """
    def to2d(x):
        return [[x]] if not isinstance(x, list) else x

    try:
        # Normalize input to 2D list
        an_2d = to2d(an)

        # Flatten the input list
        an_flat = []
        for row in an_2d:
            if isinstance(row, list):
                an_flat.extend(row)
            else:
                an_flat.append(row)

        # Validate coefficients
        clean_an = []
        for x in an_flat:
            if isinstance(x, (int, float)):
                clean_an.append(float(x))
            elif isinstance(x, str):
                try:
                    clean_an.append(float(x))
                except ValueError:
                    return f"Invalid input: coefficient '{x}' is not numeric."
            else:
                return f"Invalid input: coefficient must be numeric, got {type(x).__name__}."

        if not clean_an:
            return "Invalid input: an must contain at least one coefficient."

        # Validate m and n
        if not isinstance(m, (int, float)):
            return f"Invalid input: m must be an integer, got {type(m).__name__}."
        if isinstance(m, float) and not m.is_integer():
            return f"Invalid input: m must be an integer, got {m}."
        m = int(m)

        if not isinstance(n, (int, float)):
            return f"Invalid input: n must be an integer, got {type(n).__name__}."
        if isinstance(n, float) and not n.is_integer():
            return f"Invalid input: n must be an integer, got {n}."
        n = int(n)

        if m < 0:
            return "Invalid input: m must be non-negative."
        if n < 0:
            return "Invalid input: n must be non-negative."

        if m + n >= len(clean_an):
            return f"Invalid input: m + n ({m+n}) must be less than the number of coefficients ({len(clean_an)})."

        # Calculate Pade approximation
        p, q = scipy_interpolate_pade(clean_an, m, n)

        # Extract coefficients
        # p and q are numpy.poly1d objects. .coef returns coefficients in decreasing power order.
        p_coeffs = p.coef.tolist()
        q_coeffs = q.coef.tolist()

        # Pad rows to equal length for Excel compatibility
        result = [p_coeffs, q_coeffs]
        max_len = max(len(r) for r in result)
        result = [r + [""] * (max_len - len(r)) for r in result]

        return result

    except Exception as e:
        return f"Invalid input: {str(e)}"

Online Calculator