Horner Functions

Home • Gallery • Tutorials • Download • Purchase • Site Map
 

Horner Functions Support

The Fractal Science Kit fractal generator Horner functions apply Horner's scheme to evaluate a polynomial expression defined by 1 or more coefficient arrays.

Complex Horner.EvaluatePolynomial( \
  Complex coef[], z \
)
Complex Horner.EvaluatePolynomialDerivative( \
  Complex coef[], z \
)
void Horner.EvaluatePolynomialAndDerivative( \
  Complex coef[], z, Complex result[] \
)

Horner.EvaluatePolynomial applies Horner's scheme to evaluate a polynomial expression defined by the coefficients in the coef[] array at the value z. Horner.EvaluatePolynomialDerivative returns the value of the derivative of the function. Horner.EvaluatePolynomialAndDerivative returns both the polynomial expression value and its derivative. The values are returned in the array result[] which must be dimensioned 2. result[0] is the value of the polynomial and result[1] is the value of the derivative both evaluated at the point z.

The number of elements in the coef[] array defines the degree of the polynomial (e.g., a 4th degree polynomial would have 5 values) and any terms missing in the equation must have a 0 coefficient. The coefficients are ordered from high to low in the array; i.e., the coefficient associated with the term with the highest degree is in the array at index 0.

Example:

comment:
 
  4th degree polynomial fractal equation.
 
   f(z) = z^4 - 4/3*(K+L+M)*z^3 + 2*(K*L+K*M+L*M)*z^2 - 4*K*L*M*z + c
  f'(z) = 4*(z-K)*(z-L)*(z-M)
  Critical points: K, L, M
 
global:
 
  Complex coef[] = 1, -4/3*(K+L+M), 2*(K*L+K*M+L*M), -4*K*L*M, c
 
initialize:
 
  if (~IsJulia) {
    coef[4] = c

    switch (criticalPoint) {
      case CriticalPoints.K: z = K
      case CriticalPoints.L: z = L
      case CriticalPoints.M: z = M
    }
  }
 
iterate:
 
  z = Horner.EvaluatePolynomial(coef[], z)
 
properties:
 
  option K {
    type = Complex
    caption = "K"
    default = -0.5
  }
  option L {
    type = Complex
    caption = "L"
    default = 0.5i
  }
  option M {
    type = Complex
    caption = "M"
    default = -0.5i
  }
  enum CriticalPoints {
    K, "K"
    L, "L"
    M, "M"
  }
  option criticalPoint {
    type = criticalPoints
    caption = "Critical Point"
    default = CriticalPoints.K
  }

This fractal equation defines the coefficients of the equation in an array called coef[] and simply calls Horner.EvaluatePolynomial to apply Horner's method to evaluate the polynomial at the value z. The degree of the polynomial is 4 since the number of elements in the array is 5.

Notice how we set coef[4]=c if we are processing a Mandelbrot fractal. This is required for Mandelbrot fractals since c is initialized to the pixel location just prior to calling the initialize section so the assignment in the global section is not correct with respect to coef[4]. This is not required for Julia fractals since c is set to the Julia Constant before the program runs and is never changed. We could move the initialization of the coef[] array out of the global section and into the initialize section to avoid this complexity and thereby simplify the code but this would be less efficient since the inititialize section is executed at the beginning of every iteration while the global section is executed once during program compilation. In fact, since IsJulia is a constant, the compiler will evaluate the if statement during Program Optimization and remove the entire if block for Julia fractals, and at runtime, the initialize section is not even executed!

Complex Horner.EvaluatePolynomialQuotient( \
  Complex coef0[], Complex coef1[], z \
)
Complex Horner.EvaluatePolynomialQuotientDerivative( \
  Complex coef0[], Complex coef1[], z \
)
void Horner.EvaluatePolynomialQuotientAndDerivative( \
  Complex coef0[], Complex coef1[], z, Complex result[] \
)

Horner.EvaluatePolynomialQuotient returns the quotient of 2 polynomials. Horner's scheme is applied to the coefficient arrays coef0[] and coef1[] to evaluate the associated polynomials at the point z and the quotient of the resulting values is returned. Horner.EvaluatePolynomialQuotientDerivative returns the value of the derivative of the function. Horner.EvaluatePolynomialQuotientAndDerivative returns both the polynomial quotient and its derivative. The values are returned in the array result[] which must be dimensioned 2. result[0] is the value of the polynomial quotient and result[1] is the value of the derivative both evaluated at the point z.

For details see:

"Horner scheme."

From Wikipedia, the free encyclopedia.

 

Copyright © 2004-2019 Ross Hilbert
All rights reserved