Bouland and Aaronson, Equation (26)

Percentage Accurate: 99.9% → 99.9%
Time: 3.4s
Alternatives: 10
Speedup: 0.9×

Specification

?
\[\begin{array}{l} \\ \left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \end{array} \]
(FPCore (a b)
 :precision binary64
 (- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))
double code(double a, double b) {
	return (pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(a, b)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = ((((a * a) + (b * b)) ** 2.0d0) + (4.0d0 * (b * b))) - 1.0d0
end function
public static double code(double a, double b) {
	return (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0;
}
def code(a, b):
	return (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0
function code(a, b)
	return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(b * b))) - 1.0)
end
function tmp = code(a, b)
	tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (b * b))) - 1.0;
end
code[a_, b_] := N[(N[(N[Power[N[(N[(a * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}

\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1
\end{array}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 10 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \end{array} \]
(FPCore (a b)
 :precision binary64
 (- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))
double code(double a, double b) {
	return (pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(a, b)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = ((((a * a) + (b * b)) ** 2.0d0) + (4.0d0 * (b * b))) - 1.0d0
end function
public static double code(double a, double b) {
	return (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0;
}
def code(a, b):
	return (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0
function code(a, b)
	return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(b * b))) - 1.0)
end
function tmp = code(a, b)
	tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (b * b))) - 1.0;
end
code[a_, b_] := N[(N[(N[Power[N[(N[(a * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}

\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1
\end{array}

Alternative 1: 99.9% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \left(\mathsf{fma}\left(a, \left(a \cdot a\right) \cdot a, {b}^{4}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \end{array} \]
(FPCore (a b)
 :precision binary64
 (- (+ (fma a (* (* a a) a) (pow b 4.0)) (* 4.0 (* b b))) 1.0))
double code(double a, double b) {
	return (fma(a, ((a * a) * a), pow(b, 4.0)) + (4.0 * (b * b))) - 1.0;
}
function code(a, b)
	return Float64(Float64(fma(a, Float64(Float64(a * a) * a), (b ^ 4.0)) + Float64(4.0 * Float64(b * b))) - 1.0)
end
code[a_, b_] := N[(N[(N[(a * N[(N[(a * a), $MachinePrecision] * a), $MachinePrecision] + N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision] + N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}

\\
\left(\mathsf{fma}\left(a, \left(a \cdot a\right) \cdot a, {b}^{4}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
  2. Step-by-step derivation
    1. lift-pow.f64N/A

      \[\leadsto \left(\color{blue}{{\left(a \cdot a + b \cdot b\right)}^{2}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. lift-*.f64N/A

      \[\leadsto \left({\left(\color{blue}{a \cdot a} + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    3. lift-+.f64N/A

      \[\leadsto \left({\color{blue}{\left(a \cdot a + b \cdot b\right)}}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    4. pow2N/A

      \[\leadsto \left({\left(\color{blue}{{a}^{2}} + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    5. lift-*.f64N/A

      \[\leadsto \left({\left({a}^{2} + \color{blue}{b \cdot b}\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    6. pow2N/A

      \[\leadsto \left({\left({a}^{2} + \color{blue}{{b}^{2}}\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    7. sum-square-powN/A

      \[\leadsto \left(\color{blue}{\left(\left({\left({a}^{2}\right)}^{2} + 2 \cdot \left({a}^{2} \cdot {b}^{2}\right)\right) + {\left({b}^{2}\right)}^{2}\right)} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    8. pow2N/A

      \[\leadsto \left(\left(\left(\color{blue}{{a}^{2} \cdot {a}^{2}} + 2 \cdot \left({a}^{2} \cdot {b}^{2}\right)\right) + {\left({b}^{2}\right)}^{2}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    9. *-commutativeN/A

      \[\leadsto \left(\left(\left({a}^{2} \cdot {a}^{2} + 2 \cdot \color{blue}{\left({b}^{2} \cdot {a}^{2}\right)}\right) + {\left({b}^{2}\right)}^{2}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    10. associate-*l*N/A

      \[\leadsto \left(\left(\left({a}^{2} \cdot {a}^{2} + \color{blue}{\left(2 \cdot {b}^{2}\right) \cdot {a}^{2}}\right) + {\left({b}^{2}\right)}^{2}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    11. distribute-rgt-inN/A

      \[\leadsto \left(\left(\color{blue}{{a}^{2} \cdot \left({a}^{2} + 2 \cdot {b}^{2}\right)} + {\left({b}^{2}\right)}^{2}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    12. +-commutativeN/A

      \[\leadsto \left(\left({a}^{2} \cdot \color{blue}{\left(2 \cdot {b}^{2} + {a}^{2}\right)} + {\left({b}^{2}\right)}^{2}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    13. pow2N/A

      \[\leadsto \left(\left(\color{blue}{\left(a \cdot a\right)} \cdot \left(2 \cdot {b}^{2} + {a}^{2}\right) + {\left({b}^{2}\right)}^{2}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    14. associate-*l*N/A

      \[\leadsto \left(\left(\color{blue}{a \cdot \left(a \cdot \left(2 \cdot {b}^{2} + {a}^{2}\right)\right)} + {\left({b}^{2}\right)}^{2}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    15. pow2N/A

      \[\leadsto \left(\left(a \cdot \left(a \cdot \left(2 \cdot {b}^{2} + {a}^{2}\right)\right) + \color{blue}{{b}^{2} \cdot {b}^{2}}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    16. pow-sqrN/A

      \[\leadsto \left(\left(a \cdot \left(a \cdot \left(2 \cdot {b}^{2} + {a}^{2}\right)\right) + \color{blue}{{b}^{\left(2 \cdot 2\right)}}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    17. metadata-evalN/A

      \[\leadsto \left(\left(a \cdot \left(a \cdot \left(2 \cdot {b}^{2} + {a}^{2}\right)\right) + {b}^{\color{blue}{4}}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    18. lower-fma.f64N/A

      \[\leadsto \left(\color{blue}{\mathsf{fma}\left(a, a \cdot \left(2 \cdot {b}^{2} + {a}^{2}\right), {b}^{4}\right)} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
  3. Applied rewrites99.9%

    \[\leadsto \left(\color{blue}{\mathsf{fma}\left(a, a \cdot \mathsf{fma}\left(b, b + b, a \cdot a\right), \left(b \cdot b\right) \cdot \left(b \cdot b\right)\right)} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
  4. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \left(\mathsf{fma}\left(a, a \cdot \mathsf{fma}\left(b, b + b, a \cdot a\right), \color{blue}{\left(b \cdot b\right) \cdot \left(b \cdot b\right)}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. pow2N/A

      \[\leadsto \left(\mathsf{fma}\left(a, a \cdot \mathsf{fma}\left(b, b + b, a \cdot a\right), \color{blue}{{\left(b \cdot b\right)}^{2}}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    3. lift-*.f64N/A

      \[\leadsto \left(\mathsf{fma}\left(a, a \cdot \mathsf{fma}\left(b, b + b, a \cdot a\right), {\color{blue}{\left(b \cdot b\right)}}^{2}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    4. pow-prod-downN/A

      \[\leadsto \left(\mathsf{fma}\left(a, a \cdot \mathsf{fma}\left(b, b + b, a \cdot a\right), \color{blue}{{b}^{2} \cdot {b}^{2}}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    5. pow-prod-upN/A

      \[\leadsto \left(\mathsf{fma}\left(a, a \cdot \mathsf{fma}\left(b, b + b, a \cdot a\right), \color{blue}{{b}^{\left(2 + 2\right)}}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    6. metadata-evalN/A

      \[\leadsto \left(\mathsf{fma}\left(a, a \cdot \mathsf{fma}\left(b, b + b, a \cdot a\right), {b}^{\color{blue}{4}}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    7. lower-pow.f64100.0

      \[\leadsto \left(\mathsf{fma}\left(a, a \cdot \mathsf{fma}\left(b, b + b, a \cdot a\right), \color{blue}{{b}^{4}}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
  5. Applied rewrites100.0%

    \[\leadsto \left(\mathsf{fma}\left(a, a \cdot \mathsf{fma}\left(b, b + b, a \cdot a\right), \color{blue}{{b}^{4}}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
  6. Taylor expanded in a around 0

    \[\leadsto \left(\mathsf{fma}\left(a, a \cdot \color{blue}{\left(2 \cdot {b}^{2}\right)}, {b}^{4}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
  7. Step-by-step derivation
    1. count-2-revN/A

      \[\leadsto \left(\mathsf{fma}\left(a, a \cdot \left({b}^{2} + \color{blue}{{b}^{2}}\right), {b}^{4}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. pow2N/A

      \[\leadsto \left(\mathsf{fma}\left(a, a \cdot \left(b \cdot b + {\color{blue}{b}}^{2}\right), {b}^{4}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    3. pow2N/A

      \[\leadsto \left(\mathsf{fma}\left(a, a \cdot \left(b \cdot b + b \cdot \color{blue}{b}\right), {b}^{4}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    4. distribute-rgt-inN/A

      \[\leadsto \left(\mathsf{fma}\left(a, a \cdot \left(b \cdot \color{blue}{\left(b + b\right)}\right), {b}^{4}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    5. *-commutativeN/A

      \[\leadsto \left(\mathsf{fma}\left(a, a \cdot \left(\left(b + b\right) \cdot \color{blue}{b}\right), {b}^{4}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    6. lower-*.f64N/A

      \[\leadsto \left(\mathsf{fma}\left(a, a \cdot \left(\left(b + b\right) \cdot \color{blue}{b}\right), {b}^{4}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    7. lift-+.f6476.9

      \[\leadsto \left(\mathsf{fma}\left(a, a \cdot \left(\left(b + b\right) \cdot b\right), {b}^{4}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
  8. Applied rewrites76.9%

    \[\leadsto \left(\mathsf{fma}\left(a, a \cdot \color{blue}{\left(\left(b + b\right) \cdot b\right)}, {b}^{4}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
  9. Taylor expanded in a around inf

    \[\leadsto \left(\mathsf{fma}\left(a, \color{blue}{{a}^{3}}, {b}^{4}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
  10. Step-by-step derivation
    1. unpow3N/A

      \[\leadsto \left(\mathsf{fma}\left(a, \left(a \cdot a\right) \cdot \color{blue}{a}, {b}^{4}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. lower-*.f64N/A

      \[\leadsto \left(\mathsf{fma}\left(a, \left(a \cdot a\right) \cdot \color{blue}{a}, {b}^{4}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    3. lift-*.f6499.8

      \[\leadsto \left(\mathsf{fma}\left(a, \left(a \cdot a\right) \cdot a, {b}^{4}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
  11. Applied rewrites99.8%

    \[\leadsto \left(\mathsf{fma}\left(a, \color{blue}{\left(a \cdot a\right) \cdot a}, {b}^{4}\right) + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
  12. Add Preprocessing

Alternative 2: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \end{array} \]
(FPCore (a b)
 :precision binary64
 (- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))
double code(double a, double b) {
	return (pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(a, b)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = ((((a * a) + (b * b)) ** 2.0d0) + (4.0d0 * (b * b))) - 1.0d0
end function
public static double code(double a, double b) {
	return (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0;
}
def code(a, b):
	return (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0
function code(a, b)
	return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(b * b))) - 1.0)
end
function tmp = code(a, b)
	tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (b * b))) - 1.0;
end
code[a_, b_] := N[(N[(N[Power[N[(N[(a * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}

\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
  2. Add Preprocessing

Alternative 3: 82.2% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq 7.8 \cdot 10^{+19}:\\ \;\;\;\;\mathsf{fma}\left(b \cdot b, 4, \mathsf{fma}\left({b}^{3}, b, -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;{a}^{4}\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= a 7.8e+19) (fma (* b b) 4.0 (fma (pow b 3.0) b -1.0)) (pow a 4.0)))
double code(double a, double b) {
	double tmp;
	if (a <= 7.8e+19) {
		tmp = fma((b * b), 4.0, fma(pow(b, 3.0), b, -1.0));
	} else {
		tmp = pow(a, 4.0);
	}
	return tmp;
}
function code(a, b)
	tmp = 0.0
	if (a <= 7.8e+19)
		tmp = fma(Float64(b * b), 4.0, fma((b ^ 3.0), b, -1.0));
	else
		tmp = a ^ 4.0;
	end
	return tmp
end
code[a_, b_] := If[LessEqual[a, 7.8e+19], N[(N[(b * b), $MachinePrecision] * 4.0 + N[(N[Power[b, 3.0], $MachinePrecision] * b + -1.0), $MachinePrecision]), $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \leq 7.8 \cdot 10^{+19}:\\
\;\;\;\;\mathsf{fma}\left(b \cdot b, 4, \mathsf{fma}\left({b}^{3}, b, -1\right)\right)\\

\mathbf{else}:\\
\;\;\;\;{a}^{4}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < 7.8e19

    1. Initial program 99.9%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\left(4 \cdot {b}^{2} + {b}^{4}\right) - 1} \]
    3. Step-by-step derivation
      1. associate--l+N/A

        \[\leadsto 4 \cdot {b}^{2} + \color{blue}{\left({b}^{4} - 1\right)} \]
      2. pow2N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \left({b}^{\color{blue}{4}} - 1\right) \]
      3. associate-*r*N/A

        \[\leadsto \left(4 \cdot b\right) \cdot b + \left(\color{blue}{{b}^{4}} - 1\right) \]
      4. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, \color{blue}{b}, {b}^{4} - 1\right) \]
      5. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{4} - 1\right) \]
      6. sub-flipN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{4} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      7. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{\left(2 + 2\right)} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      8. pow-prod-upN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{2} \cdot {b}^{2} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{2} \cdot {b}^{2} + -1\right) \]
      10. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left({b}^{2}, {b}^{2}, -1\right)\right) \]
      11. pow2N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, {b}^{2}, -1\right)\right) \]
      12. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, {b}^{2}, -1\right)\right) \]
      13. pow2N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
      14. lift-*.f6469.6

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
    4. Applied rewrites69.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
      2. lift-fma.f64N/A

        \[\leadsto \left(4 \cdot b\right) \cdot b + \color{blue}{\mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)} \]
      3. associate-*l*N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \mathsf{fma}\left(\color{blue}{b \cdot b}, b \cdot b, -1\right) \]
      4. pow2N/A

        \[\leadsto 4 \cdot {b}^{2} + \mathsf{fma}\left(b \cdot \color{blue}{b}, b \cdot b, -1\right) \]
      5. *-commutativeN/A

        \[\leadsto {b}^{2} \cdot 4 + \mathsf{fma}\left(\color{blue}{b \cdot b}, b \cdot b, -1\right) \]
      6. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left({b}^{2}, \color{blue}{4}, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
      7. pow2N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b, 4, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
      8. lift-*.f6469.6

        \[\leadsto \mathsf{fma}\left(b \cdot b, 4, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
      9. lift-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b, 4, \left(b \cdot b\right) \cdot \left(b \cdot b\right) + -1\right) \]
      10. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b, 4, \left(b \cdot b\right) \cdot \left(b \cdot b\right) + -1\right) \]
      11. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b, 4, \left(b \cdot b\right) \cdot \left(b \cdot b\right) + -1\right) \]
      12. pow2N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b, 4, {b}^{2} \cdot \left(b \cdot b\right) + -1\right) \]
      13. associate-*r*N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b, 4, \left({b}^{2} \cdot b\right) \cdot b + -1\right) \]
      14. pow2N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b, 4, \left(\left(b \cdot b\right) \cdot b\right) \cdot b + -1\right) \]
      15. unpow3N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b, 4, {b}^{3} \cdot b + -1\right) \]
      16. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b, 4, \mathsf{fma}\left({b}^{3}, b, -1\right)\right) \]
      17. unpow3N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b, 4, \mathsf{fma}\left(\left(b \cdot b\right) \cdot b, b, -1\right)\right) \]
      18. pow2N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b, 4, \mathsf{fma}\left({b}^{2} \cdot b, b, -1\right)\right) \]
      19. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b, 4, \mathsf{fma}\left({b}^{2} \cdot b, b, -1\right)\right) \]
      20. pow2N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b, 4, \mathsf{fma}\left(\left(b \cdot b\right) \cdot b, b, -1\right)\right) \]
      21. lift-*.f6469.6

        \[\leadsto \mathsf{fma}\left(b \cdot b, 4, \mathsf{fma}\left(\left(b \cdot b\right) \cdot b, b, -1\right)\right) \]
    6. Applied rewrites69.6%

      \[\leadsto \mathsf{fma}\left(b \cdot b, \color{blue}{4}, \mathsf{fma}\left(\left(b \cdot b\right) \cdot b, b, -1\right)\right) \]
    7. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b, 4, \mathsf{fma}\left(\left(b \cdot b\right) \cdot b, b, -1\right)\right) \]
      2. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b, 4, \mathsf{fma}\left(\left(b \cdot b\right) \cdot b, b, -1\right)\right) \]
      3. pow3N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b, 4, \mathsf{fma}\left({b}^{3}, b, -1\right)\right) \]
      4. lower-pow.f6469.6

        \[\leadsto \mathsf{fma}\left(b \cdot b, 4, \mathsf{fma}\left({b}^{3}, b, -1\right)\right) \]
    8. Applied rewrites69.6%

      \[\leadsto \mathsf{fma}\left(b \cdot b, 4, \mathsf{fma}\left({b}^{3}, b, -1\right)\right) \]

    if 7.8e19 < a

    1. Initial program 99.9%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Taylor expanded in a around inf

      \[\leadsto \color{blue}{{a}^{4}} \]
    3. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto {a}^{\left(2 + \color{blue}{2}\right)} \]
      2. pow-prod-upN/A

        \[\leadsto {a}^{2} \cdot \color{blue}{{a}^{2}} \]
      3. lower-*.f64N/A

        \[\leadsto {a}^{2} \cdot \color{blue}{{a}^{2}} \]
      4. pow2N/A

        \[\leadsto \left(a \cdot a\right) \cdot {\color{blue}{a}}^{2} \]
      5. lift-*.f64N/A

        \[\leadsto \left(a \cdot a\right) \cdot {\color{blue}{a}}^{2} \]
      6. pow2N/A

        \[\leadsto \left(a \cdot a\right) \cdot \left(a \cdot \color{blue}{a}\right) \]
      7. lift-*.f6445.7

        \[\leadsto \left(a \cdot a\right) \cdot \left(a \cdot \color{blue}{a}\right) \]
    4. Applied rewrites45.7%

      \[\leadsto \color{blue}{\left(a \cdot a\right) \cdot \left(a \cdot a\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \left(a \cdot a\right) \cdot \left(\color{blue}{a} \cdot a\right) \]
      2. lift-*.f64N/A

        \[\leadsto \left(a \cdot a\right) \cdot \left(a \cdot \color{blue}{a}\right) \]
      3. lift-*.f64N/A

        \[\leadsto \left(a \cdot a\right) \cdot \color{blue}{\left(a \cdot a\right)} \]
      4. pow2N/A

        \[\leadsto {a}^{2} \cdot \left(\color{blue}{a} \cdot a\right) \]
      5. pow2N/A

        \[\leadsto {a}^{2} \cdot {a}^{\color{blue}{2}} \]
      6. pow-prod-upN/A

        \[\leadsto {a}^{\color{blue}{\left(2 + 2\right)}} \]
      7. metadata-evalN/A

        \[\leadsto {a}^{4} \]
      8. lower-pow.f6445.8

        \[\leadsto {a}^{\color{blue}{4}} \]
    6. Applied rewrites45.8%

      \[\leadsto {a}^{\color{blue}{4}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 82.2% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq 7.8 \cdot 10^{+19}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(b, b, 4\right) \cdot b, b, -1\right)\\ \mathbf{else}:\\ \;\;\;\;{a}^{4}\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= a 7.8e+19) (fma (* (fma b b 4.0) b) b -1.0) (pow a 4.0)))
double code(double a, double b) {
	double tmp;
	if (a <= 7.8e+19) {
		tmp = fma((fma(b, b, 4.0) * b), b, -1.0);
	} else {
		tmp = pow(a, 4.0);
	}
	return tmp;
}
function code(a, b)
	tmp = 0.0
	if (a <= 7.8e+19)
		tmp = fma(Float64(fma(b, b, 4.0) * b), b, -1.0);
	else
		tmp = a ^ 4.0;
	end
	return tmp
end
code[a_, b_] := If[LessEqual[a, 7.8e+19], N[(N[(N[(b * b + 4.0), $MachinePrecision] * b), $MachinePrecision] * b + -1.0), $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \leq 7.8 \cdot 10^{+19}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(b, b, 4\right) \cdot b, b, -1\right)\\

\mathbf{else}:\\
\;\;\;\;{a}^{4}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < 7.8e19

    1. Initial program 99.9%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\left(4 \cdot {b}^{2} + {b}^{4}\right) - 1} \]
    3. Step-by-step derivation
      1. associate--l+N/A

        \[\leadsto 4 \cdot {b}^{2} + \color{blue}{\left({b}^{4} - 1\right)} \]
      2. pow2N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \left({b}^{\color{blue}{4}} - 1\right) \]
      3. associate-*r*N/A

        \[\leadsto \left(4 \cdot b\right) \cdot b + \left(\color{blue}{{b}^{4}} - 1\right) \]
      4. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, \color{blue}{b}, {b}^{4} - 1\right) \]
      5. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{4} - 1\right) \]
      6. sub-flipN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{4} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      7. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{\left(2 + 2\right)} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      8. pow-prod-upN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{2} \cdot {b}^{2} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{2} \cdot {b}^{2} + -1\right) \]
      10. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left({b}^{2}, {b}^{2}, -1\right)\right) \]
      11. pow2N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, {b}^{2}, -1\right)\right) \]
      12. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, {b}^{2}, -1\right)\right) \]
      13. pow2N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
      14. lift-*.f6469.6

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
    4. Applied rewrites69.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
      2. lift-fma.f64N/A

        \[\leadsto \left(4 \cdot b\right) \cdot b + \color{blue}{\mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)} \]
      3. associate-*l*N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \mathsf{fma}\left(\color{blue}{b \cdot b}, b \cdot b, -1\right) \]
      4. lift-*.f64N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \mathsf{fma}\left(b \cdot \color{blue}{b}, b \cdot b, -1\right) \]
      5. lift-*.f64N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \mathsf{fma}\left(\color{blue}{b \cdot b}, b \cdot b, -1\right) \]
      6. lift-fma.f64N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \left(\left(b \cdot b\right) \cdot \left(b \cdot b\right) + \color{blue}{-1}\right) \]
      7. lift-*.f64N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \left(\left(b \cdot b\right) \cdot \left(b \cdot b\right) + -1\right) \]
      8. associate-+r+N/A

        \[\leadsto \left(4 \cdot \left(b \cdot b\right) + \left(b \cdot b\right) \cdot \left(b \cdot b\right)\right) + \color{blue}{-1} \]
      9. lift-*.f64N/A

        \[\leadsto \left(4 \cdot \left(b \cdot b\right) + \left(b \cdot b\right) \cdot \left(b \cdot b\right)\right) + -1 \]
      10. lift-*.f64N/A

        \[\leadsto \left(4 \cdot \left(b \cdot b\right) + \left(b \cdot b\right) \cdot \left(b \cdot b\right)\right) + -1 \]
      11. pow2N/A

        \[\leadsto \left(4 \cdot {b}^{2} + \left(b \cdot b\right) \cdot \left(b \cdot b\right)\right) + -1 \]
      12. lift-*.f64N/A

        \[\leadsto \left(4 \cdot {b}^{2} + \left(b \cdot b\right) \cdot \left(b \cdot b\right)\right) + -1 \]
      13. pow2N/A

        \[\leadsto \left(4 \cdot {b}^{2} + {\left(b \cdot b\right)}^{2}\right) + -1 \]
      14. lift-*.f64N/A

        \[\leadsto \left(4 \cdot {b}^{2} + {\left(b \cdot b\right)}^{2}\right) + -1 \]
      15. pow-prod-downN/A

        \[\leadsto \left(4 \cdot {b}^{2} + {b}^{2} \cdot {b}^{2}\right) + -1 \]
      16. distribute-rgt-inN/A

        \[\leadsto {b}^{2} \cdot \left(4 + {b}^{2}\right) + -1 \]
      17. *-commutativeN/A

        \[\leadsto \left(4 + {b}^{2}\right) \cdot {b}^{2} + -1 \]
      18. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(4 + {b}^{2}, \color{blue}{{b}^{2}}, -1\right) \]
      19. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left({b}^{2} + 4, {\color{blue}{b}}^{2}, -1\right) \]
      20. pow2N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b + 4, {b}^{2}, -1\right) \]
      21. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(b, b, 4\right), {\color{blue}{b}}^{2}, -1\right) \]
      22. pow2N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(b, b, 4\right), b \cdot \color{blue}{b}, -1\right) \]
      23. lift-*.f6469.6

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(b, b, 4\right), b \cdot \color{blue}{b}, -1\right) \]
    6. Applied rewrites69.6%

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(b, b, 4\right), \color{blue}{b \cdot b}, -1\right) \]
    7. Step-by-step derivation
      1. lift-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b + 4, \color{blue}{b} \cdot b, -1\right) \]
      2. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b + 4, b \cdot \color{blue}{b}, -1\right) \]
      3. lift-fma.f64N/A

        \[\leadsto \left(b \cdot b + 4\right) \cdot \left(b \cdot b\right) + \color{blue}{-1} \]
      4. associate-*r*N/A

        \[\leadsto \left(\left(b \cdot b + 4\right) \cdot b\right) \cdot b + -1 \]
      5. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(b \cdot b + 4\right) \cdot b, \color{blue}{b}, -1\right) \]
      6. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(b \cdot b + 4\right) \cdot b, b, -1\right) \]
      7. lift-fma.f6469.6

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(b, b, 4\right) \cdot b, b, -1\right) \]
    8. Applied rewrites69.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(b, b, 4\right) \cdot b, b, -1\right)} \]

    if 7.8e19 < a

    1. Initial program 99.9%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Taylor expanded in a around inf

      \[\leadsto \color{blue}{{a}^{4}} \]
    3. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto {a}^{\left(2 + \color{blue}{2}\right)} \]
      2. pow-prod-upN/A

        \[\leadsto {a}^{2} \cdot \color{blue}{{a}^{2}} \]
      3. lower-*.f64N/A

        \[\leadsto {a}^{2} \cdot \color{blue}{{a}^{2}} \]
      4. pow2N/A

        \[\leadsto \left(a \cdot a\right) \cdot {\color{blue}{a}}^{2} \]
      5. lift-*.f64N/A

        \[\leadsto \left(a \cdot a\right) \cdot {\color{blue}{a}}^{2} \]
      6. pow2N/A

        \[\leadsto \left(a \cdot a\right) \cdot \left(a \cdot \color{blue}{a}\right) \]
      7. lift-*.f6445.7

        \[\leadsto \left(a \cdot a\right) \cdot \left(a \cdot \color{blue}{a}\right) \]
    4. Applied rewrites45.7%

      \[\leadsto \color{blue}{\left(a \cdot a\right) \cdot \left(a \cdot a\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \left(a \cdot a\right) \cdot \left(\color{blue}{a} \cdot a\right) \]
      2. lift-*.f64N/A

        \[\leadsto \left(a \cdot a\right) \cdot \left(a \cdot \color{blue}{a}\right) \]
      3. lift-*.f64N/A

        \[\leadsto \left(a \cdot a\right) \cdot \color{blue}{\left(a \cdot a\right)} \]
      4. pow2N/A

        \[\leadsto {a}^{2} \cdot \left(\color{blue}{a} \cdot a\right) \]
      5. pow2N/A

        \[\leadsto {a}^{2} \cdot {a}^{\color{blue}{2}} \]
      6. pow-prod-upN/A

        \[\leadsto {a}^{\color{blue}{\left(2 + 2\right)}} \]
      7. metadata-evalN/A

        \[\leadsto {a}^{4} \]
      8. lower-pow.f6445.8

        \[\leadsto {a}^{\color{blue}{4}} \]
    6. Applied rewrites45.8%

      \[\leadsto {a}^{\color{blue}{4}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 82.2% accurate, 2.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq 7.8 \cdot 10^{+19}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(b, b, 4\right) \cdot b, b, -1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(a \cdot a\right) \cdot a\right) \cdot a\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= a 7.8e+19) (fma (* (fma b b 4.0) b) b -1.0) (* (* (* a a) a) a)))
double code(double a, double b) {
	double tmp;
	if (a <= 7.8e+19) {
		tmp = fma((fma(b, b, 4.0) * b), b, -1.0);
	} else {
		tmp = ((a * a) * a) * a;
	}
	return tmp;
}
function code(a, b)
	tmp = 0.0
	if (a <= 7.8e+19)
		tmp = fma(Float64(fma(b, b, 4.0) * b), b, -1.0);
	else
		tmp = Float64(Float64(Float64(a * a) * a) * a);
	end
	return tmp
end
code[a_, b_] := If[LessEqual[a, 7.8e+19], N[(N[(N[(b * b + 4.0), $MachinePrecision] * b), $MachinePrecision] * b + -1.0), $MachinePrecision], N[(N[(N[(a * a), $MachinePrecision] * a), $MachinePrecision] * a), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \leq 7.8 \cdot 10^{+19}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(b, b, 4\right) \cdot b, b, -1\right)\\

\mathbf{else}:\\
\;\;\;\;\left(\left(a \cdot a\right) \cdot a\right) \cdot a\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < 7.8e19

    1. Initial program 99.9%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\left(4 \cdot {b}^{2} + {b}^{4}\right) - 1} \]
    3. Step-by-step derivation
      1. associate--l+N/A

        \[\leadsto 4 \cdot {b}^{2} + \color{blue}{\left({b}^{4} - 1\right)} \]
      2. pow2N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \left({b}^{\color{blue}{4}} - 1\right) \]
      3. associate-*r*N/A

        \[\leadsto \left(4 \cdot b\right) \cdot b + \left(\color{blue}{{b}^{4}} - 1\right) \]
      4. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, \color{blue}{b}, {b}^{4} - 1\right) \]
      5. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{4} - 1\right) \]
      6. sub-flipN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{4} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      7. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{\left(2 + 2\right)} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      8. pow-prod-upN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{2} \cdot {b}^{2} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{2} \cdot {b}^{2} + -1\right) \]
      10. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left({b}^{2}, {b}^{2}, -1\right)\right) \]
      11. pow2N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, {b}^{2}, -1\right)\right) \]
      12. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, {b}^{2}, -1\right)\right) \]
      13. pow2N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
      14. lift-*.f6469.6

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
    4. Applied rewrites69.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
      2. lift-fma.f64N/A

        \[\leadsto \left(4 \cdot b\right) \cdot b + \color{blue}{\mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)} \]
      3. associate-*l*N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \mathsf{fma}\left(\color{blue}{b \cdot b}, b \cdot b, -1\right) \]
      4. lift-*.f64N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \mathsf{fma}\left(b \cdot \color{blue}{b}, b \cdot b, -1\right) \]
      5. lift-*.f64N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \mathsf{fma}\left(\color{blue}{b \cdot b}, b \cdot b, -1\right) \]
      6. lift-fma.f64N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \left(\left(b \cdot b\right) \cdot \left(b \cdot b\right) + \color{blue}{-1}\right) \]
      7. lift-*.f64N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \left(\left(b \cdot b\right) \cdot \left(b \cdot b\right) + -1\right) \]
      8. associate-+r+N/A

        \[\leadsto \left(4 \cdot \left(b \cdot b\right) + \left(b \cdot b\right) \cdot \left(b \cdot b\right)\right) + \color{blue}{-1} \]
      9. lift-*.f64N/A

        \[\leadsto \left(4 \cdot \left(b \cdot b\right) + \left(b \cdot b\right) \cdot \left(b \cdot b\right)\right) + -1 \]
      10. lift-*.f64N/A

        \[\leadsto \left(4 \cdot \left(b \cdot b\right) + \left(b \cdot b\right) \cdot \left(b \cdot b\right)\right) + -1 \]
      11. pow2N/A

        \[\leadsto \left(4 \cdot {b}^{2} + \left(b \cdot b\right) \cdot \left(b \cdot b\right)\right) + -1 \]
      12. lift-*.f64N/A

        \[\leadsto \left(4 \cdot {b}^{2} + \left(b \cdot b\right) \cdot \left(b \cdot b\right)\right) + -1 \]
      13. pow2N/A

        \[\leadsto \left(4 \cdot {b}^{2} + {\left(b \cdot b\right)}^{2}\right) + -1 \]
      14. lift-*.f64N/A

        \[\leadsto \left(4 \cdot {b}^{2} + {\left(b \cdot b\right)}^{2}\right) + -1 \]
      15. pow-prod-downN/A

        \[\leadsto \left(4 \cdot {b}^{2} + {b}^{2} \cdot {b}^{2}\right) + -1 \]
      16. distribute-rgt-inN/A

        \[\leadsto {b}^{2} \cdot \left(4 + {b}^{2}\right) + -1 \]
      17. *-commutativeN/A

        \[\leadsto \left(4 + {b}^{2}\right) \cdot {b}^{2} + -1 \]
      18. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(4 + {b}^{2}, \color{blue}{{b}^{2}}, -1\right) \]
      19. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left({b}^{2} + 4, {\color{blue}{b}}^{2}, -1\right) \]
      20. pow2N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b + 4, {b}^{2}, -1\right) \]
      21. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(b, b, 4\right), {\color{blue}{b}}^{2}, -1\right) \]
      22. pow2N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(b, b, 4\right), b \cdot \color{blue}{b}, -1\right) \]
      23. lift-*.f6469.6

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(b, b, 4\right), b \cdot \color{blue}{b}, -1\right) \]
    6. Applied rewrites69.6%

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(b, b, 4\right), \color{blue}{b \cdot b}, -1\right) \]
    7. Step-by-step derivation
      1. lift-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b + 4, \color{blue}{b} \cdot b, -1\right) \]
      2. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b + 4, b \cdot \color{blue}{b}, -1\right) \]
      3. lift-fma.f64N/A

        \[\leadsto \left(b \cdot b + 4\right) \cdot \left(b \cdot b\right) + \color{blue}{-1} \]
      4. associate-*r*N/A

        \[\leadsto \left(\left(b \cdot b + 4\right) \cdot b\right) \cdot b + -1 \]
      5. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(b \cdot b + 4\right) \cdot b, \color{blue}{b}, -1\right) \]
      6. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(b \cdot b + 4\right) \cdot b, b, -1\right) \]
      7. lift-fma.f6469.6

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(b, b, 4\right) \cdot b, b, -1\right) \]
    8. Applied rewrites69.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(b, b, 4\right) \cdot b, b, -1\right)} \]

    if 7.8e19 < a

    1. Initial program 99.9%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Taylor expanded in a around inf

      \[\leadsto \color{blue}{{a}^{4}} \]
    3. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto {a}^{\left(2 + \color{blue}{2}\right)} \]
      2. pow-prod-upN/A

        \[\leadsto {a}^{2} \cdot \color{blue}{{a}^{2}} \]
      3. lower-*.f64N/A

        \[\leadsto {a}^{2} \cdot \color{blue}{{a}^{2}} \]
      4. pow2N/A

        \[\leadsto \left(a \cdot a\right) \cdot {\color{blue}{a}}^{2} \]
      5. lift-*.f64N/A

        \[\leadsto \left(a \cdot a\right) \cdot {\color{blue}{a}}^{2} \]
      6. pow2N/A

        \[\leadsto \left(a \cdot a\right) \cdot \left(a \cdot \color{blue}{a}\right) \]
      7. lift-*.f6445.7

        \[\leadsto \left(a \cdot a\right) \cdot \left(a \cdot \color{blue}{a}\right) \]
    4. Applied rewrites45.7%

      \[\leadsto \color{blue}{\left(a \cdot a\right) \cdot \left(a \cdot a\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \left(a \cdot a\right) \cdot \left(\color{blue}{a} \cdot a\right) \]
      2. lift-*.f64N/A

        \[\leadsto \left(a \cdot a\right) \cdot \left(a \cdot \color{blue}{a}\right) \]
      3. lift-*.f64N/A

        \[\leadsto \left(a \cdot a\right) \cdot \color{blue}{\left(a \cdot a\right)} \]
      4. pow2N/A

        \[\leadsto {a}^{2} \cdot \left(\color{blue}{a} \cdot a\right) \]
      5. associate-*r*N/A

        \[\leadsto \left({a}^{2} \cdot a\right) \cdot \color{blue}{a} \]
      6. pow2N/A

        \[\leadsto \left(\left(a \cdot a\right) \cdot a\right) \cdot a \]
      7. unpow3N/A

        \[\leadsto {a}^{3} \cdot a \]
      8. lower-*.f64N/A

        \[\leadsto {a}^{3} \cdot \color{blue}{a} \]
      9. unpow3N/A

        \[\leadsto \left(\left(a \cdot a\right) \cdot a\right) \cdot a \]
      10. pow2N/A

        \[\leadsto \left({a}^{2} \cdot a\right) \cdot a \]
      11. lower-*.f64N/A

        \[\leadsto \left({a}^{2} \cdot a\right) \cdot a \]
      12. pow2N/A

        \[\leadsto \left(\left(a \cdot a\right) \cdot a\right) \cdot a \]
      13. lift-*.f6445.7

        \[\leadsto \left(\left(a \cdot a\right) \cdot a\right) \cdot a \]
    6. Applied rewrites45.7%

      \[\leadsto \color{blue}{\left(\left(a \cdot a\right) \cdot a\right) \cdot a} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 81.7% accurate, 2.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq 7.8 \cdot 10^{+19}:\\ \;\;\;\;\mathsf{fma}\left(\left(b \cdot b\right) \cdot b, b, -1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(a \cdot a\right) \cdot a\right) \cdot a\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= a 7.8e+19) (fma (* (* b b) b) b -1.0) (* (* (* a a) a) a)))
double code(double a, double b) {
	double tmp;
	if (a <= 7.8e+19) {
		tmp = fma(((b * b) * b), b, -1.0);
	} else {
		tmp = ((a * a) * a) * a;
	}
	return tmp;
}
function code(a, b)
	tmp = 0.0
	if (a <= 7.8e+19)
		tmp = fma(Float64(Float64(b * b) * b), b, -1.0);
	else
		tmp = Float64(Float64(Float64(a * a) * a) * a);
	end
	return tmp
end
code[a_, b_] := If[LessEqual[a, 7.8e+19], N[(N[(N[(b * b), $MachinePrecision] * b), $MachinePrecision] * b + -1.0), $MachinePrecision], N[(N[(N[(a * a), $MachinePrecision] * a), $MachinePrecision] * a), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \leq 7.8 \cdot 10^{+19}:\\
\;\;\;\;\mathsf{fma}\left(\left(b \cdot b\right) \cdot b, b, -1\right)\\

\mathbf{else}:\\
\;\;\;\;\left(\left(a \cdot a\right) \cdot a\right) \cdot a\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < 7.8e19

    1. Initial program 99.9%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\left(4 \cdot {b}^{2} + {b}^{4}\right) - 1} \]
    3. Step-by-step derivation
      1. associate--l+N/A

        \[\leadsto 4 \cdot {b}^{2} + \color{blue}{\left({b}^{4} - 1\right)} \]
      2. pow2N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \left({b}^{\color{blue}{4}} - 1\right) \]
      3. associate-*r*N/A

        \[\leadsto \left(4 \cdot b\right) \cdot b + \left(\color{blue}{{b}^{4}} - 1\right) \]
      4. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, \color{blue}{b}, {b}^{4} - 1\right) \]
      5. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{4} - 1\right) \]
      6. sub-flipN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{4} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      7. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{\left(2 + 2\right)} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      8. pow-prod-upN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{2} \cdot {b}^{2} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{2} \cdot {b}^{2} + -1\right) \]
      10. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left({b}^{2}, {b}^{2}, -1\right)\right) \]
      11. pow2N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, {b}^{2}, -1\right)\right) \]
      12. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, {b}^{2}, -1\right)\right) \]
      13. pow2N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
      14. lift-*.f6469.6

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
    4. Applied rewrites69.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
      2. lift-fma.f64N/A

        \[\leadsto \left(4 \cdot b\right) \cdot b + \color{blue}{\mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)} \]
      3. associate-*l*N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \mathsf{fma}\left(\color{blue}{b \cdot b}, b \cdot b, -1\right) \]
      4. lift-*.f64N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \mathsf{fma}\left(b \cdot \color{blue}{b}, b \cdot b, -1\right) \]
      5. lift-*.f64N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \mathsf{fma}\left(\color{blue}{b \cdot b}, b \cdot b, -1\right) \]
      6. lift-fma.f64N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \left(\left(b \cdot b\right) \cdot \left(b \cdot b\right) + \color{blue}{-1}\right) \]
      7. lift-*.f64N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \left(\left(b \cdot b\right) \cdot \left(b \cdot b\right) + -1\right) \]
      8. associate-+r+N/A

        \[\leadsto \left(4 \cdot \left(b \cdot b\right) + \left(b \cdot b\right) \cdot \left(b \cdot b\right)\right) + \color{blue}{-1} \]
      9. lift-*.f64N/A

        \[\leadsto \left(4 \cdot \left(b \cdot b\right) + \left(b \cdot b\right) \cdot \left(b \cdot b\right)\right) + -1 \]
      10. lift-*.f64N/A

        \[\leadsto \left(4 \cdot \left(b \cdot b\right) + \left(b \cdot b\right) \cdot \left(b \cdot b\right)\right) + -1 \]
      11. pow2N/A

        \[\leadsto \left(4 \cdot {b}^{2} + \left(b \cdot b\right) \cdot \left(b \cdot b\right)\right) + -1 \]
      12. lift-*.f64N/A

        \[\leadsto \left(4 \cdot {b}^{2} + \left(b \cdot b\right) \cdot \left(b \cdot b\right)\right) + -1 \]
      13. pow2N/A

        \[\leadsto \left(4 \cdot {b}^{2} + {\left(b \cdot b\right)}^{2}\right) + -1 \]
      14. lift-*.f64N/A

        \[\leadsto \left(4 \cdot {b}^{2} + {\left(b \cdot b\right)}^{2}\right) + -1 \]
      15. pow-prod-downN/A

        \[\leadsto \left(4 \cdot {b}^{2} + {b}^{2} \cdot {b}^{2}\right) + -1 \]
      16. distribute-rgt-inN/A

        \[\leadsto {b}^{2} \cdot \left(4 + {b}^{2}\right) + -1 \]
      17. *-commutativeN/A

        \[\leadsto \left(4 + {b}^{2}\right) \cdot {b}^{2} + -1 \]
      18. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(4 + {b}^{2}, \color{blue}{{b}^{2}}, -1\right) \]
      19. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left({b}^{2} + 4, {\color{blue}{b}}^{2}, -1\right) \]
      20. pow2N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b + 4, {b}^{2}, -1\right) \]
      21. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(b, b, 4\right), {\color{blue}{b}}^{2}, -1\right) \]
      22. pow2N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(b, b, 4\right), b \cdot \color{blue}{b}, -1\right) \]
      23. lift-*.f6469.6

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(b, b, 4\right), b \cdot \color{blue}{b}, -1\right) \]
    6. Applied rewrites69.6%

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(b, b, 4\right), \color{blue}{b \cdot b}, -1\right) \]
    7. Step-by-step derivation
      1. lift-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b + 4, \color{blue}{b} \cdot b, -1\right) \]
      2. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(b \cdot b + 4, b \cdot \color{blue}{b}, -1\right) \]
      3. lift-fma.f64N/A

        \[\leadsto \left(b \cdot b + 4\right) \cdot \left(b \cdot b\right) + \color{blue}{-1} \]
      4. associate-*r*N/A

        \[\leadsto \left(\left(b \cdot b + 4\right) \cdot b\right) \cdot b + -1 \]
      5. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(b \cdot b + 4\right) \cdot b, \color{blue}{b}, -1\right) \]
      6. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(b \cdot b + 4\right) \cdot b, b, -1\right) \]
      7. lift-fma.f6469.6

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(b, b, 4\right) \cdot b, b, -1\right) \]
    8. Applied rewrites69.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(b, b, 4\right) \cdot b, b, -1\right)} \]
    9. Taylor expanded in b around inf

      \[\leadsto \mathsf{fma}\left({b}^{3}, b, -1\right) \]
    10. Step-by-step derivation
      1. unpow3N/A

        \[\leadsto \mathsf{fma}\left(\left(b \cdot b\right) \cdot b, b, -1\right) \]
      2. pow2N/A

        \[\leadsto \mathsf{fma}\left({b}^{2} \cdot b, b, -1\right) \]
      3. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left({b}^{2} \cdot b, b, -1\right) \]
      4. pow2N/A

        \[\leadsto \mathsf{fma}\left(\left(b \cdot b\right) \cdot b, b, -1\right) \]
      5. lift-*.f6469.2

        \[\leadsto \mathsf{fma}\left(\left(b \cdot b\right) \cdot b, b, -1\right) \]
    11. Applied rewrites69.2%

      \[\leadsto \mathsf{fma}\left(\left(b \cdot b\right) \cdot b, b, -1\right) \]

    if 7.8e19 < a

    1. Initial program 99.9%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Taylor expanded in a around inf

      \[\leadsto \color{blue}{{a}^{4}} \]
    3. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto {a}^{\left(2 + \color{blue}{2}\right)} \]
      2. pow-prod-upN/A

        \[\leadsto {a}^{2} \cdot \color{blue}{{a}^{2}} \]
      3. lower-*.f64N/A

        \[\leadsto {a}^{2} \cdot \color{blue}{{a}^{2}} \]
      4. pow2N/A

        \[\leadsto \left(a \cdot a\right) \cdot {\color{blue}{a}}^{2} \]
      5. lift-*.f64N/A

        \[\leadsto \left(a \cdot a\right) \cdot {\color{blue}{a}}^{2} \]
      6. pow2N/A

        \[\leadsto \left(a \cdot a\right) \cdot \left(a \cdot \color{blue}{a}\right) \]
      7. lift-*.f6445.7

        \[\leadsto \left(a \cdot a\right) \cdot \left(a \cdot \color{blue}{a}\right) \]
    4. Applied rewrites45.7%

      \[\leadsto \color{blue}{\left(a \cdot a\right) \cdot \left(a \cdot a\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \left(a \cdot a\right) \cdot \left(\color{blue}{a} \cdot a\right) \]
      2. lift-*.f64N/A

        \[\leadsto \left(a \cdot a\right) \cdot \left(a \cdot \color{blue}{a}\right) \]
      3. lift-*.f64N/A

        \[\leadsto \left(a \cdot a\right) \cdot \color{blue}{\left(a \cdot a\right)} \]
      4. pow2N/A

        \[\leadsto {a}^{2} \cdot \left(\color{blue}{a} \cdot a\right) \]
      5. associate-*r*N/A

        \[\leadsto \left({a}^{2} \cdot a\right) \cdot \color{blue}{a} \]
      6. pow2N/A

        \[\leadsto \left(\left(a \cdot a\right) \cdot a\right) \cdot a \]
      7. unpow3N/A

        \[\leadsto {a}^{3} \cdot a \]
      8. lower-*.f64N/A

        \[\leadsto {a}^{3} \cdot \color{blue}{a} \]
      9. unpow3N/A

        \[\leadsto \left(\left(a \cdot a\right) \cdot a\right) \cdot a \]
      10. pow2N/A

        \[\leadsto \left({a}^{2} \cdot a\right) \cdot a \]
      11. lower-*.f64N/A

        \[\leadsto \left({a}^{2} \cdot a\right) \cdot a \]
      12. pow2N/A

        \[\leadsto \left(\left(a \cdot a\right) \cdot a\right) \cdot a \]
      13. lift-*.f6445.7

        \[\leadsto \left(\left(a \cdot a\right) \cdot a\right) \cdot a \]
    6. Applied rewrites45.7%

      \[\leadsto \color{blue}{\left(\left(a \cdot a\right) \cdot a\right) \cdot a} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 7: 67.0% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq 7.8 \cdot 10^{+19}:\\ \;\;\;\;\mathsf{fma}\left(4 \cdot b, b, -1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(a \cdot a\right) \cdot a\right) \cdot a\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= a 7.8e+19) (fma (* 4.0 b) b -1.0) (* (* (* a a) a) a)))
double code(double a, double b) {
	double tmp;
	if (a <= 7.8e+19) {
		tmp = fma((4.0 * b), b, -1.0);
	} else {
		tmp = ((a * a) * a) * a;
	}
	return tmp;
}
function code(a, b)
	tmp = 0.0
	if (a <= 7.8e+19)
		tmp = fma(Float64(4.0 * b), b, -1.0);
	else
		tmp = Float64(Float64(Float64(a * a) * a) * a);
	end
	return tmp
end
code[a_, b_] := If[LessEqual[a, 7.8e+19], N[(N[(4.0 * b), $MachinePrecision] * b + -1.0), $MachinePrecision], N[(N[(N[(a * a), $MachinePrecision] * a), $MachinePrecision] * a), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \leq 7.8 \cdot 10^{+19}:\\
\;\;\;\;\mathsf{fma}\left(4 \cdot b, b, -1\right)\\

\mathbf{else}:\\
\;\;\;\;\left(\left(a \cdot a\right) \cdot a\right) \cdot a\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < 7.8e19

    1. Initial program 99.9%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\left(4 \cdot {b}^{2} + {b}^{4}\right) - 1} \]
    3. Step-by-step derivation
      1. associate--l+N/A

        \[\leadsto 4 \cdot {b}^{2} + \color{blue}{\left({b}^{4} - 1\right)} \]
      2. pow2N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \left({b}^{\color{blue}{4}} - 1\right) \]
      3. associate-*r*N/A

        \[\leadsto \left(4 \cdot b\right) \cdot b + \left(\color{blue}{{b}^{4}} - 1\right) \]
      4. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, \color{blue}{b}, {b}^{4} - 1\right) \]
      5. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{4} - 1\right) \]
      6. sub-flipN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{4} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      7. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{\left(2 + 2\right)} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      8. pow-prod-upN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{2} \cdot {b}^{2} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{2} \cdot {b}^{2} + -1\right) \]
      10. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left({b}^{2}, {b}^{2}, -1\right)\right) \]
      11. pow2N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, {b}^{2}, -1\right)\right) \]
      12. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, {b}^{2}, -1\right)\right) \]
      13. pow2N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
      14. lift-*.f6469.6

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
    4. Applied rewrites69.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right)} \]
    5. Taylor expanded in b around 0

      \[\leadsto 4 \cdot {b}^{2} - \color{blue}{1} \]
    6. Step-by-step derivation
      1. sub-flipN/A

        \[\leadsto 4 \cdot {b}^{2} + \left(\mathsf{neg}\left(1\right)\right) \]
      2. pow2N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \left(\mathsf{neg}\left(1\right)\right) \]
      3. associate-*l*N/A

        \[\leadsto \left(4 \cdot b\right) \cdot b + \left(\mathsf{neg}\left(1\right)\right) \]
      4. metadata-evalN/A

        \[\leadsto \left(4 \cdot b\right) \cdot b + -1 \]
      5. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, -1\right) \]
      6. lift-*.f6451.4

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, -1\right) \]
    7. Applied rewrites51.4%

      \[\leadsto \mathsf{fma}\left(4 \cdot b, \color{blue}{b}, -1\right) \]

    if 7.8e19 < a

    1. Initial program 99.9%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Taylor expanded in a around inf

      \[\leadsto \color{blue}{{a}^{4}} \]
    3. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto {a}^{\left(2 + \color{blue}{2}\right)} \]
      2. pow-prod-upN/A

        \[\leadsto {a}^{2} \cdot \color{blue}{{a}^{2}} \]
      3. lower-*.f64N/A

        \[\leadsto {a}^{2} \cdot \color{blue}{{a}^{2}} \]
      4. pow2N/A

        \[\leadsto \left(a \cdot a\right) \cdot {\color{blue}{a}}^{2} \]
      5. lift-*.f64N/A

        \[\leadsto \left(a \cdot a\right) \cdot {\color{blue}{a}}^{2} \]
      6. pow2N/A

        \[\leadsto \left(a \cdot a\right) \cdot \left(a \cdot \color{blue}{a}\right) \]
      7. lift-*.f6445.7

        \[\leadsto \left(a \cdot a\right) \cdot \left(a \cdot \color{blue}{a}\right) \]
    4. Applied rewrites45.7%

      \[\leadsto \color{blue}{\left(a \cdot a\right) \cdot \left(a \cdot a\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \left(a \cdot a\right) \cdot \left(\color{blue}{a} \cdot a\right) \]
      2. lift-*.f64N/A

        \[\leadsto \left(a \cdot a\right) \cdot \left(a \cdot \color{blue}{a}\right) \]
      3. lift-*.f64N/A

        \[\leadsto \left(a \cdot a\right) \cdot \color{blue}{\left(a \cdot a\right)} \]
      4. pow2N/A

        \[\leadsto {a}^{2} \cdot \left(\color{blue}{a} \cdot a\right) \]
      5. associate-*r*N/A

        \[\leadsto \left({a}^{2} \cdot a\right) \cdot \color{blue}{a} \]
      6. pow2N/A

        \[\leadsto \left(\left(a \cdot a\right) \cdot a\right) \cdot a \]
      7. unpow3N/A

        \[\leadsto {a}^{3} \cdot a \]
      8. lower-*.f64N/A

        \[\leadsto {a}^{3} \cdot \color{blue}{a} \]
      9. unpow3N/A

        \[\leadsto \left(\left(a \cdot a\right) \cdot a\right) \cdot a \]
      10. pow2N/A

        \[\leadsto \left({a}^{2} \cdot a\right) \cdot a \]
      11. lower-*.f64N/A

        \[\leadsto \left({a}^{2} \cdot a\right) \cdot a \]
      12. pow2N/A

        \[\leadsto \left(\left(a \cdot a\right) \cdot a\right) \cdot a \]
      13. lift-*.f6445.7

        \[\leadsto \left(\left(a \cdot a\right) \cdot a\right) \cdot a \]
    6. Applied rewrites45.7%

      \[\leadsto \color{blue}{\left(\left(a \cdot a\right) \cdot a\right) \cdot a} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 8: 67.0% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq 7.8 \cdot 10^{+19}:\\ \;\;\;\;\mathsf{fma}\left(4 \cdot b, b, -1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot a\right) \cdot \left(a \cdot a\right)\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= a 7.8e+19) (fma (* 4.0 b) b -1.0) (* (* a a) (* a a))))
double code(double a, double b) {
	double tmp;
	if (a <= 7.8e+19) {
		tmp = fma((4.0 * b), b, -1.0);
	} else {
		tmp = (a * a) * (a * a);
	}
	return tmp;
}
function code(a, b)
	tmp = 0.0
	if (a <= 7.8e+19)
		tmp = fma(Float64(4.0 * b), b, -1.0);
	else
		tmp = Float64(Float64(a * a) * Float64(a * a));
	end
	return tmp
end
code[a_, b_] := If[LessEqual[a, 7.8e+19], N[(N[(4.0 * b), $MachinePrecision] * b + -1.0), $MachinePrecision], N[(N[(a * a), $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \leq 7.8 \cdot 10^{+19}:\\
\;\;\;\;\mathsf{fma}\left(4 \cdot b, b, -1\right)\\

\mathbf{else}:\\
\;\;\;\;\left(a \cdot a\right) \cdot \left(a \cdot a\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < 7.8e19

    1. Initial program 99.9%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\left(4 \cdot {b}^{2} + {b}^{4}\right) - 1} \]
    3. Step-by-step derivation
      1. associate--l+N/A

        \[\leadsto 4 \cdot {b}^{2} + \color{blue}{\left({b}^{4} - 1\right)} \]
      2. pow2N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \left({b}^{\color{blue}{4}} - 1\right) \]
      3. associate-*r*N/A

        \[\leadsto \left(4 \cdot b\right) \cdot b + \left(\color{blue}{{b}^{4}} - 1\right) \]
      4. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, \color{blue}{b}, {b}^{4} - 1\right) \]
      5. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{4} - 1\right) \]
      6. sub-flipN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{4} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      7. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{\left(2 + 2\right)} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      8. pow-prod-upN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{2} \cdot {b}^{2} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{2} \cdot {b}^{2} + -1\right) \]
      10. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left({b}^{2}, {b}^{2}, -1\right)\right) \]
      11. pow2N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, {b}^{2}, -1\right)\right) \]
      12. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, {b}^{2}, -1\right)\right) \]
      13. pow2N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
      14. lift-*.f6469.6

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
    4. Applied rewrites69.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right)} \]
    5. Taylor expanded in b around 0

      \[\leadsto 4 \cdot {b}^{2} - \color{blue}{1} \]
    6. Step-by-step derivation
      1. sub-flipN/A

        \[\leadsto 4 \cdot {b}^{2} + \left(\mathsf{neg}\left(1\right)\right) \]
      2. pow2N/A

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \left(\mathsf{neg}\left(1\right)\right) \]
      3. associate-*l*N/A

        \[\leadsto \left(4 \cdot b\right) \cdot b + \left(\mathsf{neg}\left(1\right)\right) \]
      4. metadata-evalN/A

        \[\leadsto \left(4 \cdot b\right) \cdot b + -1 \]
      5. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, -1\right) \]
      6. lift-*.f6451.4

        \[\leadsto \mathsf{fma}\left(4 \cdot b, b, -1\right) \]
    7. Applied rewrites51.4%

      \[\leadsto \mathsf{fma}\left(4 \cdot b, \color{blue}{b}, -1\right) \]

    if 7.8e19 < a

    1. Initial program 99.9%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Taylor expanded in a around inf

      \[\leadsto \color{blue}{{a}^{4}} \]
    3. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto {a}^{\left(2 + \color{blue}{2}\right)} \]
      2. pow-prod-upN/A

        \[\leadsto {a}^{2} \cdot \color{blue}{{a}^{2}} \]
      3. lower-*.f64N/A

        \[\leadsto {a}^{2} \cdot \color{blue}{{a}^{2}} \]
      4. pow2N/A

        \[\leadsto \left(a \cdot a\right) \cdot {\color{blue}{a}}^{2} \]
      5. lift-*.f64N/A

        \[\leadsto \left(a \cdot a\right) \cdot {\color{blue}{a}}^{2} \]
      6. pow2N/A

        \[\leadsto \left(a \cdot a\right) \cdot \left(a \cdot \color{blue}{a}\right) \]
      7. lift-*.f6445.7

        \[\leadsto \left(a \cdot a\right) \cdot \left(a \cdot \color{blue}{a}\right) \]
    4. Applied rewrites45.7%

      \[\leadsto \color{blue}{\left(a \cdot a\right) \cdot \left(a \cdot a\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 9: 51.4% accurate, 4.1× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(4 \cdot b, b, -1\right) \end{array} \]
(FPCore (a b) :precision binary64 (fma (* 4.0 b) b -1.0))
double code(double a, double b) {
	return fma((4.0 * b), b, -1.0);
}
function code(a, b)
	return fma(Float64(4.0 * b), b, -1.0)
end
code[a_, b_] := N[(N[(4.0 * b), $MachinePrecision] * b + -1.0), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(4 \cdot b, b, -1\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
  2. Taylor expanded in a around 0

    \[\leadsto \color{blue}{\left(4 \cdot {b}^{2} + {b}^{4}\right) - 1} \]
  3. Step-by-step derivation
    1. associate--l+N/A

      \[\leadsto 4 \cdot {b}^{2} + \color{blue}{\left({b}^{4} - 1\right)} \]
    2. pow2N/A

      \[\leadsto 4 \cdot \left(b \cdot b\right) + \left({b}^{\color{blue}{4}} - 1\right) \]
    3. associate-*r*N/A

      \[\leadsto \left(4 \cdot b\right) \cdot b + \left(\color{blue}{{b}^{4}} - 1\right) \]
    4. lower-fma.f64N/A

      \[\leadsto \mathsf{fma}\left(4 \cdot b, \color{blue}{b}, {b}^{4} - 1\right) \]
    5. lower-*.f64N/A

      \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{4} - 1\right) \]
    6. sub-flipN/A

      \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{4} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
    7. metadata-evalN/A

      \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{\left(2 + 2\right)} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
    8. pow-prod-upN/A

      \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{2} \cdot {b}^{2} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
    9. metadata-evalN/A

      \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{2} \cdot {b}^{2} + -1\right) \]
    10. lower-fma.f64N/A

      \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left({b}^{2}, {b}^{2}, -1\right)\right) \]
    11. pow2N/A

      \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, {b}^{2}, -1\right)\right) \]
    12. lift-*.f64N/A

      \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, {b}^{2}, -1\right)\right) \]
    13. pow2N/A

      \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
    14. lift-*.f6469.6

      \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
  4. Applied rewrites69.6%

    \[\leadsto \color{blue}{\mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right)} \]
  5. Taylor expanded in b around 0

    \[\leadsto 4 \cdot {b}^{2} - \color{blue}{1} \]
  6. Step-by-step derivation
    1. sub-flipN/A

      \[\leadsto 4 \cdot {b}^{2} + \left(\mathsf{neg}\left(1\right)\right) \]
    2. pow2N/A

      \[\leadsto 4 \cdot \left(b \cdot b\right) + \left(\mathsf{neg}\left(1\right)\right) \]
    3. associate-*l*N/A

      \[\leadsto \left(4 \cdot b\right) \cdot b + \left(\mathsf{neg}\left(1\right)\right) \]
    4. metadata-evalN/A

      \[\leadsto \left(4 \cdot b\right) \cdot b + -1 \]
    5. lower-fma.f64N/A

      \[\leadsto \mathsf{fma}\left(4 \cdot b, b, -1\right) \]
    6. lift-*.f6451.4

      \[\leadsto \mathsf{fma}\left(4 \cdot b, b, -1\right) \]
  7. Applied rewrites51.4%

    \[\leadsto \mathsf{fma}\left(4 \cdot b, \color{blue}{b}, -1\right) \]
  8. Add Preprocessing

Alternative 10: 24.6% accurate, 36.7× speedup?

\[\begin{array}{l} \\ -1 \end{array} \]
(FPCore (a b) :precision binary64 -1.0)
double code(double a, double b) {
	return -1.0;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(a, b)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = -1.0d0
end function
public static double code(double a, double b) {
	return -1.0;
}
def code(a, b):
	return -1.0
function code(a, b)
	return -1.0
end
function tmp = code(a, b)
	tmp = -1.0;
end
code[a_, b_] := -1.0
\begin{array}{l}

\\
-1
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
  2. Taylor expanded in a around 0

    \[\leadsto \color{blue}{\left(4 \cdot {b}^{2} + {b}^{4}\right) - 1} \]
  3. Step-by-step derivation
    1. associate--l+N/A

      \[\leadsto 4 \cdot {b}^{2} + \color{blue}{\left({b}^{4} - 1\right)} \]
    2. pow2N/A

      \[\leadsto 4 \cdot \left(b \cdot b\right) + \left({b}^{\color{blue}{4}} - 1\right) \]
    3. associate-*r*N/A

      \[\leadsto \left(4 \cdot b\right) \cdot b + \left(\color{blue}{{b}^{4}} - 1\right) \]
    4. lower-fma.f64N/A

      \[\leadsto \mathsf{fma}\left(4 \cdot b, \color{blue}{b}, {b}^{4} - 1\right) \]
    5. lower-*.f64N/A

      \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{4} - 1\right) \]
    6. sub-flipN/A

      \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{4} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
    7. metadata-evalN/A

      \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{\left(2 + 2\right)} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
    8. pow-prod-upN/A

      \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{2} \cdot {b}^{2} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
    9. metadata-evalN/A

      \[\leadsto \mathsf{fma}\left(4 \cdot b, b, {b}^{2} \cdot {b}^{2} + -1\right) \]
    10. lower-fma.f64N/A

      \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left({b}^{2}, {b}^{2}, -1\right)\right) \]
    11. pow2N/A

      \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, {b}^{2}, -1\right)\right) \]
    12. lift-*.f64N/A

      \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, {b}^{2}, -1\right)\right) \]
    13. pow2N/A

      \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
    14. lift-*.f6469.6

      \[\leadsto \mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right) \]
  4. Applied rewrites69.6%

    \[\leadsto \color{blue}{\mathsf{fma}\left(4 \cdot b, b, \mathsf{fma}\left(b \cdot b, b \cdot b, -1\right)\right)} \]
  5. Taylor expanded in b around 0

    \[\leadsto -1 \]
  6. Step-by-step derivation
    1. Applied rewrites24.6%

      \[\leadsto -1 \]
    2. Add Preprocessing

    Reproduce

    ?
    herbie shell --seed 2025132 
    (FPCore (a b)
      :name "Bouland and Aaronson, Equation (26)"
      :precision binary64
      (- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))