Exact Polynomial Conversion
Overview
Globtim provides functionality to convert polynomial approximations from orthogonal bases (Chebyshev or Legendre) to exact monomial form. This is useful for:
- Symbolic manipulation of polynomials
- Integration with computer algebra systems
- Understanding polynomial structure
- Exact arithmetic operations
- Finding critical points symbolically
Main Functions
to_exact_monomial_basis
Converts a polynomial from orthogonal basis to monomial basis using exact arithmetic.
to_exact_monomial_basis(pol::ApproxPoly; variables=nothing)Arguments:
pol::ApproxPoly: Polynomial approximation from Globtimvariables: Array of polynomial variables (created automatically if not provided)
Returns:
DynamicPolynomials.Polynomial: Polynomial in monomial basis with exact coefficients
Example:
using Globtim
using DynamicPolynomials
# Create a polynomial approximation
TR = test_input(x -> sin(π*x[1])*cos(π*x[2]), dim=2, center=[0.0, 0.0], sample_range=1.0)
pol = Constructor(TR, 8, basis=:chebyshev, precision=RationalPrecision)
# Convert to monomial basis
@polyvar x y
mono_poly = to_exact_monomial_basis(pol, variables=[x, y])exact_polynomial_coefficients
Convenience function to get exact monomial coefficients directly from a function.
exact_polynomial_coefficients(f::Function, dim::Int, degree::Int; kwargs...)Arguments:
f::Function: Function to approximatedim::Int: Dimension of the inputdegree::Int: Maximum polynomial degreebasis::Symbol = :chebyshev: Basis to use (:chebyshevor:legendre)center::Vector = zeros(dim): Center of approximation domainsample_range::Real = 1.0: Radius of approximation domaintolerance::Real = 0.5: Tolerance for approximationprecision = Float64Precision: Arithmetic precision
Returns:
DynamicPolynomials.Polynomial: Polynomial in monomial basis
Example:
# Direct conversion from function to monomial polynomial
f = x -> x[1]^2 + x[2]^2 - x[1]*x[2]
mono_poly = exact_polynomial_coefficients(f, 2, 4, basis=:chebyshev)Using Rational Arithmetic
The Constructor function supports exact rational arithmetic through the precision parameter:
pol = Constructor(TR, degree,
basis = :chebyshev,
precision = RationalPrecision, # Use exact rational arithmetic
normalized = false, # Use unnormalized basis functions
power_of_two_denom = false # Don't restrict to power-of-2 denominators
)Example: Complete Workflow
using Globtim
using DynamicPolynomials
# Define a test function
f = x -> exp(-x[1]^2 - x[2]^2)
# Create test input
TR = test_input(f, dim=2, center=[0.0, 0.0], sample_range=1.0)
# Construct polynomial with rational coefficients
pol = Constructor(TR, 6, basis=:legendre, precision=RationalPrecision)
# Convert to monomial basis
@polyvar x y
mono_poly = to_exact_monomial_basis(pol, variables=[x, y])
# Now you can:
# 1. Take derivatives symbolically
dx = differentiate(mono_poly, x)
dy = differentiate(mono_poly, y)
# 2. Evaluate at specific points
point_value = substitute(mono_poly, x => 0.5, y => 0.5)
# 3. Extract coefficients
terms_list = terms(mono_poly)
for term in terms_list[1:min(5, length(terms_list))]
coeff = coefficient(term)
mon = monomial(term)
println("$coeff * $mon")
endFinding Critical Points
Once you have the polynomial in either orthogonal or monomial form, you can find critical points:
# Using the orthogonal polynomial directly (more efficient)
@polyvar x_vars[1:2]
real_pts = solve_polynomial_system(
x_vars,
2, # dimension
pol.degree,
pol.coeffs;
basis = pol.basis,
precision = pol.precision,
normalized = pol.normalized
)
# Process the critical points
df_crit = process_crit_pts(real_pts, f, TR)Implementation Details
The exact conversion functionality leverages existing Globtim components:
Constructorwithprecision=RationalPrecisioncomputes exact rational coefficientsconstruct_orthopoly_polynomial(internal) builds the polynomial in monomial formto_exact_monomial_basisprovides a clean API and handles domain scaling
The conversion preserves numerical precision and allows for exact symbolic manipulation of the resulting polynomial.
See Also
- Polynomial Approximation - General polynomial approximation
- Critical Point Analysis - Finding and analyzing critical points
- Examples - More examples of using Globtim