Diagrams.Solve.Polynomial:quartForm from diagrams-solve-0.1, C

Percentage Accurate: 97.7% → 98.2%
Time: 9.9s
Alternatives: 12
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \end{array} \]
(FPCore (x y z t a b c)
 :precision binary64
 (+ (- (+ (* x y) (/ (* z t) 16.0)) (/ (* a b) 4.0)) c))
double code(double x, double y, double z, double t, double a, double b, double c) {
	return (((x * y) + ((z * t) / 16.0)) - ((a * b) / 4.0)) + c;
}
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(x, y, z, t, a, b, c)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    code = (((x * y) + ((z * t) / 16.0d0)) - ((a * b) / 4.0d0)) + c
end function
public static double code(double x, double y, double z, double t, double a, double b, double c) {
	return (((x * y) + ((z * t) / 16.0)) - ((a * b) / 4.0)) + c;
}
def code(x, y, z, t, a, b, c):
	return (((x * y) + ((z * t) / 16.0)) - ((a * b) / 4.0)) + c
function code(x, y, z, t, a, b, c)
	return Float64(Float64(Float64(Float64(x * y) + Float64(Float64(z * t) / 16.0)) - Float64(Float64(a * b) / 4.0)) + c)
end
function tmp = code(x, y, z, t, a, b, c)
	tmp = (((x * y) + ((z * t) / 16.0)) - ((a * b) / 4.0)) + c;
end
code[x_, y_, z_, t_, a_, b_, c_] := N[(N[(N[(N[(x * y), $MachinePrecision] + N[(N[(z * t), $MachinePrecision] / 16.0), $MachinePrecision]), $MachinePrecision] - N[(N[(a * b), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision]
\begin{array}{l}

\\
\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c
\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 12 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: 97.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \end{array} \]
(FPCore (x y z t a b c)
 :precision binary64
 (+ (- (+ (* x y) (/ (* z t) 16.0)) (/ (* a b) 4.0)) c))
double code(double x, double y, double z, double t, double a, double b, double c) {
	return (((x * y) + ((z * t) / 16.0)) - ((a * b) / 4.0)) + c;
}
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(x, y, z, t, a, b, c)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    code = (((x * y) + ((z * t) / 16.0d0)) - ((a * b) / 4.0d0)) + c
end function
public static double code(double x, double y, double z, double t, double a, double b, double c) {
	return (((x * y) + ((z * t) / 16.0)) - ((a * b) / 4.0)) + c;
}
def code(x, y, z, t, a, b, c):
	return (((x * y) + ((z * t) / 16.0)) - ((a * b) / 4.0)) + c
function code(x, y, z, t, a, b, c)
	return Float64(Float64(Float64(Float64(x * y) + Float64(Float64(z * t) / 16.0)) - Float64(Float64(a * b) / 4.0)) + c)
end
function tmp = code(x, y, z, t, a, b, c)
	tmp = (((x * y) + ((z * t) / 16.0)) - ((a * b) / 4.0)) + c;
end
code[x_, y_, z_, t_, a_, b_, c_] := N[(N[(N[(N[(x * y), $MachinePrecision] + N[(N[(z * t), $MachinePrecision] / 16.0), $MachinePrecision]), $MachinePrecision] - N[(N[(a * b), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision]
\begin{array}{l}

\\
\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c
\end{array}

Alternative 1: 98.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(z, \frac{t}{16}, x \cdot y\right) - \left(\frac{a \cdot b}{4} - c\right) \end{array} \]
(FPCore (x y z t a b c)
 :precision binary64
 (- (fma z (/ t 16.0) (* x y)) (- (/ (* a b) 4.0) c)))
double code(double x, double y, double z, double t, double a, double b, double c) {
	return fma(z, (t / 16.0), (x * y)) - (((a * b) / 4.0) - c);
}
function code(x, y, z, t, a, b, c)
	return Float64(fma(z, Float64(t / 16.0), Float64(x * y)) - Float64(Float64(Float64(a * b) / 4.0) - c))
end
code[x_, y_, z_, t_, a_, b_, c_] := N[(N[(z * N[(t / 16.0), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision] - N[(N[(N[(a * b), $MachinePrecision] / 4.0), $MachinePrecision] - c), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(z, \frac{t}{16}, x \cdot y\right) - \left(\frac{a \cdot b}{4} - c\right)
\end{array}
Derivation
  1. Initial program 97.7%

    \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
  2. Applied rewrites98.2%

    \[\leadsto \color{blue}{\mathsf{fma}\left(z, \frac{t}{16}, x \cdot y\right) - \left(\frac{a \cdot b}{4} - c\right)} \]
  3. Add Preprocessing

Alternative 2: 89.2% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := 0.25 \cdot \left(a \cdot b\right)\\ t_2 := \frac{a \cdot b}{4}\\ \mathbf{if}\;t\_2 \leq -5 \cdot 10^{+48}:\\ \;\;\;\;\mathsf{fma}\left(0.0625, z \cdot t, c\right) - t\_1\\ \mathbf{elif}\;t\_2 \leq 50000000000:\\ \;\;\;\;\mathsf{fma}\left(z, 0.0625 \cdot t, x \cdot y\right) - \left(-c\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, y, c\right) - t\_1\\ \end{array} \end{array} \]
(FPCore (x y z t a b c)
 :precision binary64
 (let* ((t_1 (* 0.25 (* a b))) (t_2 (/ (* a b) 4.0)))
   (if (<= t_2 -5e+48)
     (- (fma 0.0625 (* z t) c) t_1)
     (if (<= t_2 50000000000.0)
       (- (fma z (* 0.0625 t) (* x y)) (- c))
       (- (fma x y c) t_1)))))
double code(double x, double y, double z, double t, double a, double b, double c) {
	double t_1 = 0.25 * (a * b);
	double t_2 = (a * b) / 4.0;
	double tmp;
	if (t_2 <= -5e+48) {
		tmp = fma(0.0625, (z * t), c) - t_1;
	} else if (t_2 <= 50000000000.0) {
		tmp = fma(z, (0.0625 * t), (x * y)) - -c;
	} else {
		tmp = fma(x, y, c) - t_1;
	}
	return tmp;
}
function code(x, y, z, t, a, b, c)
	t_1 = Float64(0.25 * Float64(a * b))
	t_2 = Float64(Float64(a * b) / 4.0)
	tmp = 0.0
	if (t_2 <= -5e+48)
		tmp = Float64(fma(0.0625, Float64(z * t), c) - t_1);
	elseif (t_2 <= 50000000000.0)
		tmp = Float64(fma(z, Float64(0.0625 * t), Float64(x * y)) - Float64(-c));
	else
		tmp = Float64(fma(x, y, c) - t_1);
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_, c_] := Block[{t$95$1 = N[(0.25 * N[(a * b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(a * b), $MachinePrecision] / 4.0), $MachinePrecision]}, If[LessEqual[t$95$2, -5e+48], N[(N[(0.0625 * N[(z * t), $MachinePrecision] + c), $MachinePrecision] - t$95$1), $MachinePrecision], If[LessEqual[t$95$2, 50000000000.0], N[(N[(z * N[(0.0625 * t), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision] - (-c)), $MachinePrecision], N[(N[(x * y + c), $MachinePrecision] - t$95$1), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := 0.25 \cdot \left(a \cdot b\right)\\
t_2 := \frac{a \cdot b}{4}\\
\mathbf{if}\;t\_2 \leq -5 \cdot 10^{+48}:\\
\;\;\;\;\mathsf{fma}\left(0.0625, z \cdot t, c\right) - t\_1\\

\mathbf{elif}\;t\_2 \leq 50000000000:\\
\;\;\;\;\mathsf{fma}\left(z, 0.0625 \cdot t, x \cdot y\right) - \left(-c\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, c\right) - t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 a b) #s(literal 4 binary64)) < -4.99999999999999973e48

    1. Initial program 95.8%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\left(c + \frac{1}{16} \cdot \left(t \cdot z\right)\right) - \frac{1}{4} \cdot \left(a \cdot b\right)} \]
    3. Applied rewrites82.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.0625, z \cdot t, c\right) - 0.25 \cdot \left(a \cdot b\right)} \]

    if -4.99999999999999973e48 < (/.f64 (*.f64 a b) #s(literal 4 binary64)) < 5e10

    1. Initial program 99.1%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Applied rewrites99.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, \frac{t}{16}, x \cdot y\right) - \left(\frac{a \cdot b}{4} - c\right)} \]
    3. Taylor expanded in a around 0

      \[\leadsto \mathsf{fma}\left(z, \frac{t}{16}, x \cdot y\right) - \color{blue}{-1 \cdot c} \]
    4. Applied rewrites95.8%

      \[\leadsto \mathsf{fma}\left(z, \frac{t}{16}, x \cdot y\right) - \color{blue}{\left(-c\right)} \]
    5. Taylor expanded in t around 0

      \[\leadsto \mathsf{fma}\left(z, \color{blue}{\frac{1}{16} \cdot t}, x \cdot y\right) - \left(-c\right) \]
    6. Applied rewrites95.8%

      \[\leadsto \mathsf{fma}\left(z, \color{blue}{0.0625 \cdot t}, x \cdot y\right) - \left(-c\right) \]

    if 5e10 < (/.f64 (*.f64 a b) #s(literal 4 binary64))

    1. Initial program 96.0%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Taylor expanded in z around 0

      \[\leadsto \color{blue}{\left(c + x \cdot y\right) - \frac{1}{4} \cdot \left(a \cdot b\right)} \]
    3. Applied rewrites80.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, c\right) - 0.25 \cdot \left(a \cdot b\right)} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 3: 88.8% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{z \cdot t}{16}\\ \mathbf{if}\;t\_1 \leq -1 \cdot 10^{+21}:\\ \;\;\;\;\mathsf{fma}\left(z, 0.0625 \cdot t, x \cdot y\right) - \left(-c\right)\\ \mathbf{elif}\;t\_1 \leq 4 \cdot 10^{+195}:\\ \;\;\;\;\mathsf{fma}\left(x, y, c\right) - 0.25 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, y, 0.0625 \cdot \left(z \cdot t\right)\right) + c\\ \end{array} \end{array} \]
(FPCore (x y z t a b c)
 :precision binary64
 (let* ((t_1 (/ (* z t) 16.0)))
   (if (<= t_1 -1e+21)
     (- (fma z (* 0.0625 t) (* x y)) (- c))
     (if (<= t_1 4e+195)
       (- (fma x y c) (* 0.25 (* a b)))
       (+ (fma x y (* 0.0625 (* z t))) c)))))
double code(double x, double y, double z, double t, double a, double b, double c) {
	double t_1 = (z * t) / 16.0;
	double tmp;
	if (t_1 <= -1e+21) {
		tmp = fma(z, (0.0625 * t), (x * y)) - -c;
	} else if (t_1 <= 4e+195) {
		tmp = fma(x, y, c) - (0.25 * (a * b));
	} else {
		tmp = fma(x, y, (0.0625 * (z * t))) + c;
	}
	return tmp;
}
function code(x, y, z, t, a, b, c)
	t_1 = Float64(Float64(z * t) / 16.0)
	tmp = 0.0
	if (t_1 <= -1e+21)
		tmp = Float64(fma(z, Float64(0.0625 * t), Float64(x * y)) - Float64(-c));
	elseif (t_1 <= 4e+195)
		tmp = Float64(fma(x, y, c) - Float64(0.25 * Float64(a * b)));
	else
		tmp = Float64(fma(x, y, Float64(0.0625 * Float64(z * t))) + c);
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_, c_] := Block[{t$95$1 = N[(N[(z * t), $MachinePrecision] / 16.0), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+21], N[(N[(z * N[(0.0625 * t), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision] - (-c)), $MachinePrecision], If[LessEqual[t$95$1, 4e+195], N[(N[(x * y + c), $MachinePrecision] - N[(0.25 * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * y + N[(0.0625 * N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{z \cdot t}{16}\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{+21}:\\
\;\;\;\;\mathsf{fma}\left(z, 0.0625 \cdot t, x \cdot y\right) - \left(-c\right)\\

\mathbf{elif}\;t\_1 \leq 4 \cdot 10^{+195}:\\
\;\;\;\;\mathsf{fma}\left(x, y, c\right) - 0.25 \cdot \left(a \cdot b\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, 0.0625 \cdot \left(z \cdot t\right)\right) + c\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 z t) #s(literal 16 binary64)) < -1e21

    1. Initial program 96.6%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Applied rewrites97.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, \frac{t}{16}, x \cdot y\right) - \left(\frac{a \cdot b}{4} - c\right)} \]
    3. Taylor expanded in a around 0

      \[\leadsto \mathsf{fma}\left(z, \frac{t}{16}, x \cdot y\right) - \color{blue}{-1 \cdot c} \]
    4. Applied rewrites82.9%

      \[\leadsto \mathsf{fma}\left(z, \frac{t}{16}, x \cdot y\right) - \color{blue}{\left(-c\right)} \]
    5. Taylor expanded in t around 0

      \[\leadsto \mathsf{fma}\left(z, \color{blue}{\frac{1}{16} \cdot t}, x \cdot y\right) - \left(-c\right) \]
    6. Applied rewrites82.9%

      \[\leadsto \mathsf{fma}\left(z, \color{blue}{0.0625 \cdot t}, x \cdot y\right) - \left(-c\right) \]

    if -1e21 < (/.f64 (*.f64 z t) #s(literal 16 binary64)) < 3.99999999999999991e195

    1. Initial program 98.9%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Taylor expanded in z around 0

      \[\leadsto \color{blue}{\left(c + x \cdot y\right) - \frac{1}{4} \cdot \left(a \cdot b\right)} \]
    3. Applied rewrites90.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, c\right) - 0.25 \cdot \left(a \cdot b\right)} \]

    if 3.99999999999999991e195 < (/.f64 (*.f64 z t) #s(literal 16 binary64))

    1. Initial program 93.0%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\left(\frac{1}{16} \cdot \left(t \cdot z\right) + x \cdot y\right)} + c \]
    3. Applied rewrites88.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, 0.0625 \cdot \left(z \cdot t\right)\right)} + c \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 4: 88.6% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{z \cdot t}{16}\\ t_2 := \mathsf{fma}\left(x, y, 0.0625 \cdot \left(z \cdot t\right)\right) + c\\ \mathbf{if}\;t\_1 \leq -1 \cdot 10^{+21}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_1 \leq 4 \cdot 10^{+195}:\\ \;\;\;\;\mathsf{fma}\left(x, y, c\right) - 0.25 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (x y z t a b c)
 :precision binary64
 (let* ((t_1 (/ (* z t) 16.0)) (t_2 (+ (fma x y (* 0.0625 (* z t))) c)))
   (if (<= t_1 -1e+21)
     t_2
     (if (<= t_1 4e+195) (- (fma x y c) (* 0.25 (* a b))) t_2))))
double code(double x, double y, double z, double t, double a, double b, double c) {
	double t_1 = (z * t) / 16.0;
	double t_2 = fma(x, y, (0.0625 * (z * t))) + c;
	double tmp;
	if (t_1 <= -1e+21) {
		tmp = t_2;
	} else if (t_1 <= 4e+195) {
		tmp = fma(x, y, c) - (0.25 * (a * b));
	} else {
		tmp = t_2;
	}
	return tmp;
}
function code(x, y, z, t, a, b, c)
	t_1 = Float64(Float64(z * t) / 16.0)
	t_2 = Float64(fma(x, y, Float64(0.0625 * Float64(z * t))) + c)
	tmp = 0.0
	if (t_1 <= -1e+21)
		tmp = t_2;
	elseif (t_1 <= 4e+195)
		tmp = Float64(fma(x, y, c) - Float64(0.25 * Float64(a * b)));
	else
		tmp = t_2;
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_, c_] := Block[{t$95$1 = N[(N[(z * t), $MachinePrecision] / 16.0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * y + N[(0.0625 * N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+21], t$95$2, If[LessEqual[t$95$1, 4e+195], N[(N[(x * y + c), $MachinePrecision] - N[(0.25 * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$2]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{z \cdot t}{16}\\
t_2 := \mathsf{fma}\left(x, y, 0.0625 \cdot \left(z \cdot t\right)\right) + c\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{+21}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_1 \leq 4 \cdot 10^{+195}:\\
\;\;\;\;\mathsf{fma}\left(x, y, c\right) - 0.25 \cdot \left(a \cdot b\right)\\

\mathbf{else}:\\
\;\;\;\;t\_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 z t) #s(literal 16 binary64)) < -1e21 or 3.99999999999999991e195 < (/.f64 (*.f64 z t) #s(literal 16 binary64))

    1. Initial program 95.4%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\left(\frac{1}{16} \cdot \left(t \cdot z\right) + x \cdot y\right)} + c \]
    3. Applied rewrites84.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, 0.0625 \cdot \left(z \cdot t\right)\right)} + c \]

    if -1e21 < (/.f64 (*.f64 z t) #s(literal 16 binary64)) < 3.99999999999999991e195

    1. Initial program 98.9%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Taylor expanded in z around 0

      \[\leadsto \color{blue}{\left(c + x \cdot y\right) - \frac{1}{4} \cdot \left(a \cdot b\right)} \]
    3. Applied rewrites90.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, c\right) - 0.25 \cdot \left(a \cdot b\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 86.5% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{z \cdot t}{16}\\ t_2 := \mathsf{fma}\left(0.0625, z \cdot t, c\right)\\ \mathbf{if}\;t\_1 \leq -2 \cdot 10^{+170}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+208}:\\ \;\;\;\;\mathsf{fma}\left(x, y, c\right) - 0.25 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (x y z t a b c)
 :precision binary64
 (let* ((t_1 (/ (* z t) 16.0)) (t_2 (fma 0.0625 (* z t) c)))
   (if (<= t_1 -2e+170)
     t_2
     (if (<= t_1 2e+208) (- (fma x y c) (* 0.25 (* a b))) t_2))))
double code(double x, double y, double z, double t, double a, double b, double c) {
	double t_1 = (z * t) / 16.0;
	double t_2 = fma(0.0625, (z * t), c);
	double tmp;
	if (t_1 <= -2e+170) {
		tmp = t_2;
	} else if (t_1 <= 2e+208) {
		tmp = fma(x, y, c) - (0.25 * (a * b));
	} else {
		tmp = t_2;
	}
	return tmp;
}
function code(x, y, z, t, a, b, c)
	t_1 = Float64(Float64(z * t) / 16.0)
	t_2 = fma(0.0625, Float64(z * t), c)
	tmp = 0.0
	if (t_1 <= -2e+170)
		tmp = t_2;
	elseif (t_1 <= 2e+208)
		tmp = Float64(fma(x, y, c) - Float64(0.25 * Float64(a * b)));
	else
		tmp = t_2;
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_, c_] := Block[{t$95$1 = N[(N[(z * t), $MachinePrecision] / 16.0), $MachinePrecision]}, Block[{t$95$2 = N[(0.0625 * N[(z * t), $MachinePrecision] + c), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+170], t$95$2, If[LessEqual[t$95$1, 2e+208], N[(N[(x * y + c), $MachinePrecision] - N[(0.25 * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$2]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{z \cdot t}{16}\\
t_2 := \mathsf{fma}\left(0.0625, z \cdot t, c\right)\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{+170}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+208}:\\
\;\;\;\;\mathsf{fma}\left(x, y, c\right) - 0.25 \cdot \left(a \cdot b\right)\\

\mathbf{else}:\\
\;\;\;\;t\_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 z t) #s(literal 16 binary64)) < -2.00000000000000007e170 or 2e208 < (/.f64 (*.f64 z t) #s(literal 16 binary64))

    1. Initial program 93.6%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\left(c + \frac{1}{16} \cdot \left(t \cdot z\right)\right) - \frac{1}{4} \cdot \left(a \cdot b\right)} \]
    3. Applied rewrites87.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.0625, z \cdot t, c\right) - 0.25 \cdot \left(a \cdot b\right)} \]
    4. Taylor expanded in a around 0

      \[\leadsto c + \color{blue}{\frac{1}{16} \cdot \left(t \cdot z\right)} \]
    5. Applied rewrites81.2%

      \[\leadsto \mathsf{fma}\left(0.0625, \color{blue}{z \cdot t}, c\right) \]

    if -2.00000000000000007e170 < (/.f64 (*.f64 z t) #s(literal 16 binary64)) < 2e208

    1. Initial program 99.0%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Taylor expanded in z around 0

      \[\leadsto \color{blue}{\left(c + x \cdot y\right) - \frac{1}{4} \cdot \left(a \cdot b\right)} \]
    3. Applied rewrites88.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, c\right) - 0.25 \cdot \left(a \cdot b\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 65.4% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{a \cdot b}{4}\\ \mathbf{if}\;t\_1 \leq -2 \cdot 10^{+95}:\\ \;\;\;\;\mathsf{fma}\left(-0.25 \cdot a, b, c\right)\\ \mathbf{elif}\;t\_1 \leq 4 \cdot 10^{-209}:\\ \;\;\;\;\mathsf{fma}\left(0.0625, z \cdot t, c\right)\\ \mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+137}:\\ \;\;\;\;\mathsf{fma}\left(x, y, c\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, y, -0.25 \cdot \left(a \cdot b\right)\right)\\ \end{array} \end{array} \]
(FPCore (x y z t a b c)
 :precision binary64
 (let* ((t_1 (/ (* a b) 4.0)))
   (if (<= t_1 -2e+95)
     (fma (* -0.25 a) b c)
     (if (<= t_1 4e-209)
       (fma 0.0625 (* z t) c)
       (if (<= t_1 5e+137) (fma x y c) (fma x y (* -0.25 (* a b))))))))
double code(double x, double y, double z, double t, double a, double b, double c) {
	double t_1 = (a * b) / 4.0;
	double tmp;
	if (t_1 <= -2e+95) {
		tmp = fma((-0.25 * a), b, c);
	} else if (t_1 <= 4e-209) {
		tmp = fma(0.0625, (z * t), c);
	} else if (t_1 <= 5e+137) {
		tmp = fma(x, y, c);
	} else {
		tmp = fma(x, y, (-0.25 * (a * b)));
	}
	return tmp;
}
function code(x, y, z, t, a, b, c)
	t_1 = Float64(Float64(a * b) / 4.0)
	tmp = 0.0
	if (t_1 <= -2e+95)
		tmp = fma(Float64(-0.25 * a), b, c);
	elseif (t_1 <= 4e-209)
		tmp = fma(0.0625, Float64(z * t), c);
	elseif (t_1 <= 5e+137)
		tmp = fma(x, y, c);
	else
		tmp = fma(x, y, Float64(-0.25 * Float64(a * b)));
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_, c_] := Block[{t$95$1 = N[(N[(a * b), $MachinePrecision] / 4.0), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+95], N[(N[(-0.25 * a), $MachinePrecision] * b + c), $MachinePrecision], If[LessEqual[t$95$1, 4e-209], N[(0.0625 * N[(z * t), $MachinePrecision] + c), $MachinePrecision], If[LessEqual[t$95$1, 5e+137], N[(x * y + c), $MachinePrecision], N[(x * y + N[(-0.25 * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{a \cdot b}{4}\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{+95}:\\
\;\;\;\;\mathsf{fma}\left(-0.25 \cdot a, b, c\right)\\

\mathbf{elif}\;t\_1 \leq 4 \cdot 10^{-209}:\\
\;\;\;\;\mathsf{fma}\left(0.0625, z \cdot t, c\right)\\

\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+137}:\\
\;\;\;\;\mathsf{fma}\left(x, y, c\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, -0.25 \cdot \left(a \cdot b\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (/.f64 (*.f64 a b) #s(literal 4 binary64)) < -2.00000000000000004e95

    1. Initial program 95.1%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\left(c + \frac{1}{16} \cdot \left(t \cdot z\right)\right) - \frac{1}{4} \cdot \left(a \cdot b\right)} \]
    3. Applied rewrites84.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.0625, z \cdot t, c\right) - 0.25 \cdot \left(a \cdot b\right)} \]
    4. Taylor expanded in a around 0

      \[\leadsto c + \color{blue}{\frac{1}{16} \cdot \left(t \cdot z\right)} \]
    5. Applied rewrites27.4%

      \[\leadsto \mathsf{fma}\left(0.0625, \color{blue}{z \cdot t}, c\right) \]
    6. Taylor expanded in z around 0

      \[\leadsto c + \color{blue}{\frac{-1}{4} \cdot \left(a \cdot b\right)} \]
    7. Applied rewrites70.7%

      \[\leadsto \mathsf{fma}\left(-0.25 \cdot a, \color{blue}{b}, c\right) \]

    if -2.00000000000000004e95 < (/.f64 (*.f64 a b) #s(literal 4 binary64)) < 4.0000000000000002e-209

    1. Initial program 99.2%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\left(c + \frac{1}{16} \cdot \left(t \cdot z\right)\right) - \frac{1}{4} \cdot \left(a \cdot b\right)} \]
    3. Applied rewrites66.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.0625, z \cdot t, c\right) - 0.25 \cdot \left(a \cdot b\right)} \]
    4. Taylor expanded in a around 0

      \[\leadsto c + \color{blue}{\frac{1}{16} \cdot \left(t \cdot z\right)} \]
    5. Applied rewrites62.1%

      \[\leadsto \mathsf{fma}\left(0.0625, \color{blue}{z \cdot t}, c\right) \]

    if 4.0000000000000002e-209 < (/.f64 (*.f64 a b) #s(literal 4 binary64)) < 5.0000000000000002e137

    1. Initial program 99.1%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Taylor expanded in z around 0

      \[\leadsto \color{blue}{\left(c + x \cdot y\right) - \frac{1}{4} \cdot \left(a \cdot b\right)} \]
    3. Applied rewrites69.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, c\right) - 0.25 \cdot \left(a \cdot b\right)} \]
    4. Taylor expanded in a around 0

      \[\leadsto c + \color{blue}{x \cdot y} \]
    5. Applied rewrites57.8%

      \[\leadsto \mathsf{fma}\left(x, \color{blue}{y}, c\right) \]

    if 5.0000000000000002e137 < (/.f64 (*.f64 a b) #s(literal 4 binary64))

    1. Initial program 94.1%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Taylor expanded in z around 0

      \[\leadsto \color{blue}{\left(c + x \cdot y\right) - \frac{1}{4} \cdot \left(a \cdot b\right)} \]
    3. Applied rewrites84.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, c\right) - 0.25 \cdot \left(a \cdot b\right)} \]
    4. Taylor expanded in c around 0

      \[\leadsto x \cdot y - \color{blue}{\frac{1}{4} \cdot \left(a \cdot b\right)} \]
    5. Applied rewrites80.5%

      \[\leadsto \mathsf{fma}\left(x, \color{blue}{y}, -0.25 \cdot \left(a \cdot b\right)\right) \]
  3. Recombined 4 regimes into one program.
  4. Add Preprocessing

Alternative 7: 64.8% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{a \cdot b}{4}\\ t_2 := \mathsf{fma}\left(-0.25 \cdot a, b, c\right)\\ \mathbf{if}\;t\_1 \leq -2 \cdot 10^{+95}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_1 \leq 4 \cdot 10^{-209}:\\ \;\;\;\;\mathsf{fma}\left(0.0625, z \cdot t, c\right)\\ \mathbf{elif}\;t\_1 \leq 10^{+42}:\\ \;\;\;\;\mathsf{fma}\left(x, y, c\right)\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (x y z t a b c)
 :precision binary64
 (let* ((t_1 (/ (* a b) 4.0)) (t_2 (fma (* -0.25 a) b c)))
   (if (<= t_1 -2e+95)
     t_2
     (if (<= t_1 4e-209)
       (fma 0.0625 (* z t) c)
       (if (<= t_1 1e+42) (fma x y c) t_2)))))
double code(double x, double y, double z, double t, double a, double b, double c) {
	double t_1 = (a * b) / 4.0;
	double t_2 = fma((-0.25 * a), b, c);
	double tmp;
	if (t_1 <= -2e+95) {
		tmp = t_2;
	} else if (t_1 <= 4e-209) {
		tmp = fma(0.0625, (z * t), c);
	} else if (t_1 <= 1e+42) {
		tmp = fma(x, y, c);
	} else {
		tmp = t_2;
	}
	return tmp;
}
function code(x, y, z, t, a, b, c)
	t_1 = Float64(Float64(a * b) / 4.0)
	t_2 = fma(Float64(-0.25 * a), b, c)
	tmp = 0.0
	if (t_1 <= -2e+95)
		tmp = t_2;
	elseif (t_1 <= 4e-209)
		tmp = fma(0.0625, Float64(z * t), c);
	elseif (t_1 <= 1e+42)
		tmp = fma(x, y, c);
	else
		tmp = t_2;
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_, c_] := Block[{t$95$1 = N[(N[(a * b), $MachinePrecision] / 4.0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(-0.25 * a), $MachinePrecision] * b + c), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+95], t$95$2, If[LessEqual[t$95$1, 4e-209], N[(0.0625 * N[(z * t), $MachinePrecision] + c), $MachinePrecision], If[LessEqual[t$95$1, 1e+42], N[(x * y + c), $MachinePrecision], t$95$2]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{a \cdot b}{4}\\
t_2 := \mathsf{fma}\left(-0.25 \cdot a, b, c\right)\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{+95}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_1 \leq 4 \cdot 10^{-209}:\\
\;\;\;\;\mathsf{fma}\left(0.0625, z \cdot t, c\right)\\

\mathbf{elif}\;t\_1 \leq 10^{+42}:\\
\;\;\;\;\mathsf{fma}\left(x, y, c\right)\\

\mathbf{else}:\\
\;\;\;\;t\_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 a b) #s(literal 4 binary64)) < -2.00000000000000004e95 or 1.00000000000000004e42 < (/.f64 (*.f64 a b) #s(literal 4 binary64))

    1. Initial program 95.5%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\left(c + \frac{1}{16} \cdot \left(t \cdot z\right)\right) - \frac{1}{4} \cdot \left(a \cdot b\right)} \]
    3. Applied rewrites83.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.0625, z \cdot t, c\right) - 0.25 \cdot \left(a \cdot b\right)} \]
    4. Taylor expanded in a around 0

      \[\leadsto c + \color{blue}{\frac{1}{16} \cdot \left(t \cdot z\right)} \]
    5. Applied rewrites29.4%

      \[\leadsto \mathsf{fma}\left(0.0625, \color{blue}{z \cdot t}, c\right) \]
    6. Taylor expanded in z around 0

      \[\leadsto c + \color{blue}{\frac{-1}{4} \cdot \left(a \cdot b\right)} \]
    7. Applied rewrites68.8%

      \[\leadsto \mathsf{fma}\left(-0.25 \cdot a, \color{blue}{b}, c\right) \]

    if -2.00000000000000004e95 < (/.f64 (*.f64 a b) #s(literal 4 binary64)) < 4.0000000000000002e-209

    1. Initial program 99.2%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\left(c + \frac{1}{16} \cdot \left(t \cdot z\right)\right) - \frac{1}{4} \cdot \left(a \cdot b\right)} \]
    3. Applied rewrites66.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.0625, z \cdot t, c\right) - 0.25 \cdot \left(a \cdot b\right)} \]
    4. Taylor expanded in a around 0

      \[\leadsto c + \color{blue}{\frac{1}{16} \cdot \left(t \cdot z\right)} \]
    5. Applied rewrites62.1%

      \[\leadsto \mathsf{fma}\left(0.0625, \color{blue}{z \cdot t}, c\right) \]

    if 4.0000000000000002e-209 < (/.f64 (*.f64 a b) #s(literal 4 binary64)) < 1.00000000000000004e42

    1. Initial program 99.1%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Taylor expanded in z around 0

      \[\leadsto \color{blue}{\left(c + x \cdot y\right) - \frac{1}{4} \cdot \left(a \cdot b\right)} \]
    3. Applied rewrites68.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, c\right) - 0.25 \cdot \left(a \cdot b\right)} \]
    4. Taylor expanded in a around 0

      \[\leadsto c + \color{blue}{x \cdot y} \]
    5. Applied rewrites61.9%

      \[\leadsto \mathsf{fma}\left(x, \color{blue}{y}, c\right) \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 8: 62.4% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{a \cdot b}{4}\\ t_2 := -0.25 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;t\_1 \leq -2 \cdot 10^{+95}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_1 \leq 4 \cdot 10^{-209}:\\ \;\;\;\;\mathsf{fma}\left(0.0625, z \cdot t, c\right)\\ \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+235}:\\ \;\;\;\;\mathsf{fma}\left(x, y, c\right)\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (x y z t a b c)
 :precision binary64
 (let* ((t_1 (/ (* a b) 4.0)) (t_2 (* -0.25 (* a b))))
   (if (<= t_1 -2e+95)
     t_2
     (if (<= t_1 4e-209)
       (fma 0.0625 (* z t) c)
       (if (<= t_1 2e+235) (fma x y c) t_2)))))
double code(double x, double y, double z, double t, double a, double b, double c) {
	double t_1 = (a * b) / 4.0;
	double t_2 = -0.25 * (a * b);
	double tmp;
	if (t_1 <= -2e+95) {
		tmp = t_2;
	} else if (t_1 <= 4e-209) {
		tmp = fma(0.0625, (z * t), c);
	} else if (t_1 <= 2e+235) {
		tmp = fma(x, y, c);
	} else {
		tmp = t_2;
	}
	return tmp;
}
function code(x, y, z, t, a, b, c)
	t_1 = Float64(Float64(a * b) / 4.0)
	t_2 = Float64(-0.25 * Float64(a * b))
	tmp = 0.0
	if (t_1 <= -2e+95)
		tmp = t_2;
	elseif (t_1 <= 4e-209)
		tmp = fma(0.0625, Float64(z * t), c);
	elseif (t_1 <= 2e+235)
		tmp = fma(x, y, c);
	else
		tmp = t_2;
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_, c_] := Block[{t$95$1 = N[(N[(a * b), $MachinePrecision] / 4.0), $MachinePrecision]}, Block[{t$95$2 = N[(-0.25 * N[(a * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+95], t$95$2, If[LessEqual[t$95$1, 4e-209], N[(0.0625 * N[(z * t), $MachinePrecision] + c), $MachinePrecision], If[LessEqual[t$95$1, 2e+235], N[(x * y + c), $MachinePrecision], t$95$2]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{a \cdot b}{4}\\
t_2 := -0.25 \cdot \left(a \cdot b\right)\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{+95}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_1 \leq 4 \cdot 10^{-209}:\\
\;\;\;\;\mathsf{fma}\left(0.0625, z \cdot t, c\right)\\

\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+235}:\\
\;\;\;\;\mathsf{fma}\left(x, y, c\right)\\

\mathbf{else}:\\
\;\;\;\;t\_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 a b) #s(literal 4 binary64)) < -2.00000000000000004e95 or 2.0000000000000001e235 < (/.f64 (*.f64 a b) #s(literal 4 binary64))

    1. Initial program 93.9%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Taylor expanded in a around inf

      \[\leadsto \color{blue}{\frac{-1}{4} \cdot \left(a \cdot b\right)} \]
    3. Applied rewrites70.2%

      \[\leadsto \color{blue}{-0.25 \cdot \left(a \cdot b\right)} \]

    if -2.00000000000000004e95 < (/.f64 (*.f64 a b) #s(literal 4 binary64)) < 4.0000000000000002e-209

    1. Initial program 99.2%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\left(c + \frac{1}{16} \cdot \left(t \cdot z\right)\right) - \frac{1}{4} \cdot \left(a \cdot b\right)} \]
    3. Applied rewrites66.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.0625, z \cdot t, c\right) - 0.25 \cdot \left(a \cdot b\right)} \]
    4. Taylor expanded in a around 0

      \[\leadsto c + \color{blue}{\frac{1}{16} \cdot \left(t \cdot z\right)} \]
    5. Applied rewrites62.1%

      \[\leadsto \mathsf{fma}\left(0.0625, \color{blue}{z \cdot t}, c\right) \]

    if 4.0000000000000002e-209 < (/.f64 (*.f64 a b) #s(literal 4 binary64)) < 2.0000000000000001e235

    1. Initial program 99.1%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Taylor expanded in z around 0

      \[\leadsto \color{blue}{\left(c + x \cdot y\right) - \frac{1}{4} \cdot \left(a \cdot b\right)} \]
    3. Applied rewrites71.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, c\right) - 0.25 \cdot \left(a \cdot b\right)} \]
    4. Taylor expanded in a around 0

      \[\leadsto c + \color{blue}{x \cdot y} \]
    5. Applied rewrites53.6%

      \[\leadsto \mathsf{fma}\left(x, \color{blue}{y}, c\right) \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 9: 61.9% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{a \cdot b}{4}\\ t_2 := -0.25 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;t\_1 \leq -5 \cdot 10^{+80}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+235}:\\ \;\;\;\;\mathsf{fma}\left(x, y, c\right)\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (x y z t a b c)
 :precision binary64
 (let* ((t_1 (/ (* a b) 4.0)) (t_2 (* -0.25 (* a b))))
   (if (<= t_1 -5e+80) t_2 (if (<= t_1 2e+235) (fma x y c) t_2))))
double code(double x, double y, double z, double t, double a, double b, double c) {
	double t_1 = (a * b) / 4.0;
	double t_2 = -0.25 * (a * b);
	double tmp;
	if (t_1 <= -5e+80) {
		tmp = t_2;
	} else if (t_1 <= 2e+235) {
		tmp = fma(x, y, c);
	} else {
		tmp = t_2;
	}
	return tmp;
}
function code(x, y, z, t, a, b, c)
	t_1 = Float64(Float64(a * b) / 4.0)
	t_2 = Float64(-0.25 * Float64(a * b))
	tmp = 0.0
	if (t_1 <= -5e+80)
		tmp = t_2;
	elseif (t_1 <= 2e+235)
		tmp = fma(x, y, c);
	else
		tmp = t_2;
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_, c_] := Block[{t$95$1 = N[(N[(a * b), $MachinePrecision] / 4.0), $MachinePrecision]}, Block[{t$95$2 = N[(-0.25 * N[(a * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+80], t$95$2, If[LessEqual[t$95$1, 2e+235], N[(x * y + c), $MachinePrecision], t$95$2]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{a \cdot b}{4}\\
t_2 := -0.25 \cdot \left(a \cdot b\right)\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+80}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+235}:\\
\;\;\;\;\mathsf{fma}\left(x, y, c\right)\\

\mathbf{else}:\\
\;\;\;\;t\_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 a b) #s(literal 4 binary64)) < -4.99999999999999961e80 or 2.0000000000000001e235 < (/.f64 (*.f64 a b) #s(literal 4 binary64))

    1. Initial program 94.1%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Taylor expanded in a around inf

      \[\leadsto \color{blue}{\frac{-1}{4} \cdot \left(a \cdot b\right)} \]
    3. Applied rewrites68.6%

      \[\leadsto \color{blue}{-0.25 \cdot \left(a \cdot b\right)} \]

    if -4.99999999999999961e80 < (/.f64 (*.f64 a b) #s(literal 4 binary64)) < 2.0000000000000001e235

    1. Initial program 99.2%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Taylor expanded in z around 0

      \[\leadsto \color{blue}{\left(c + x \cdot y\right) - \frac{1}{4} \cdot \left(a \cdot b\right)} \]
    3. Applied rewrites69.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, c\right) - 0.25 \cdot \left(a \cdot b\right)} \]
    4. Taylor expanded in a around 0

      \[\leadsto c + \color{blue}{x \cdot y} \]
    5. Applied rewrites59.8%

      \[\leadsto \mathsf{fma}\left(x, \color{blue}{y}, c\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 10: 48.8% accurate, 4.1× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(x, y, c\right) \end{array} \]
(FPCore (x y z t a b c) :precision binary64 (fma x y c))
double code(double x, double y, double z, double t, double a, double b, double c) {
	return fma(x, y, c);
}
function code(x, y, z, t, a, b, c)
	return fma(x, y, c)
end
code[x_, y_, z_, t_, a_, b_, c_] := N[(x * y + c), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(x, y, c\right)
\end{array}
Derivation
  1. Initial program 97.7%

    \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
  2. Taylor expanded in z around 0

    \[\leadsto \color{blue}{\left(c + x \cdot y\right) - \frac{1}{4} \cdot \left(a \cdot b\right)} \]
  3. Applied rewrites73.6%

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, c\right) - 0.25 \cdot \left(a \cdot b\right)} \]
  4. Taylor expanded in a around 0

    \[\leadsto c + \color{blue}{x \cdot y} \]
  5. Applied rewrites48.8%

    \[\leadsto \mathsf{fma}\left(x, \color{blue}{y}, c\right) \]
  6. Add Preprocessing

Alternative 11: 42.1% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -1.5 \cdot 10^{+102}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \cdot y \leq 4.7 \cdot 10^{+49}:\\ \;\;\;\;c\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z t a b c)
 :precision binary64
 (if (<= (* x y) -1.5e+102) (* x y) (if (<= (* x y) 4.7e+49) c (* x y))))
double code(double x, double y, double z, double t, double a, double b, double c) {
	double tmp;
	if ((x * y) <= -1.5e+102) {
		tmp = x * y;
	} else if ((x * y) <= 4.7e+49) {
		tmp = c;
	} else {
		tmp = x * y;
	}
	return tmp;
}
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(x, y, z, t, a, b, c)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: tmp
    if ((x * y) <= (-1.5d+102)) then
        tmp = x * y
    else if ((x * y) <= 4.7d+49) then
        tmp = c
    else
        tmp = x * y
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b, double c) {
	double tmp;
	if ((x * y) <= -1.5e+102) {
		tmp = x * y;
	} else if ((x * y) <= 4.7e+49) {
		tmp = c;
	} else {
		tmp = x * y;
	}
	return tmp;
}
def code(x, y, z, t, a, b, c):
	tmp = 0
	if (x * y) <= -1.5e+102:
		tmp = x * y
	elif (x * y) <= 4.7e+49:
		tmp = c
	else:
		tmp = x * y
	return tmp
function code(x, y, z, t, a, b, c)
	tmp = 0.0
	if (Float64(x * y) <= -1.5e+102)
		tmp = Float64(x * y);
	elseif (Float64(x * y) <= 4.7e+49)
		tmp = c;
	else
		tmp = Float64(x * y);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b, c)
	tmp = 0.0;
	if ((x * y) <= -1.5e+102)
		tmp = x * y;
	elseif ((x * y) <= 4.7e+49)
		tmp = c;
	else
		tmp = x * y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_, c_] := If[LessEqual[N[(x * y), $MachinePrecision], -1.5e+102], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 4.7e+49], c, N[(x * y), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1.5 \cdot 10^{+102}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;x \cdot y \leq 4.7 \cdot 10^{+49}:\\
\;\;\;\;c\\

\mathbf{else}:\\
\;\;\;\;x \cdot y\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -1.4999999999999999e102 or 4.6999999999999997e49 < (*.f64 x y)

    1. Initial program 95.4%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{x \cdot y} \]
    3. Applied rewrites62.4%

      \[\leadsto \color{blue}{x \cdot y} \]

    if -1.4999999999999999e102 < (*.f64 x y) < 4.6999999999999997e49

    1. Initial program 99.0%

      \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
    2. Taylor expanded in c around inf

      \[\leadsto \color{blue}{c} \]
    3. Applied rewrites29.8%

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

Alternative 12: 22.5% accurate, 24.7× speedup?

\[\begin{array}{l} \\ c \end{array} \]
(FPCore (x y z t a b c) :precision binary64 c)
double code(double x, double y, double z, double t, double a, double b, double c) {
	return c;
}
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(x, y, z, t, a, b, c)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    code = c
end function
public static double code(double x, double y, double z, double t, double a, double b, double c) {
	return c;
}
def code(x, y, z, t, a, b, c):
	return c
function code(x, y, z, t, a, b, c)
	return c
end
function tmp = code(x, y, z, t, a, b, c)
	tmp = c;
end
code[x_, y_, z_, t_, a_, b_, c_] := c
\begin{array}{l}

\\
c
\end{array}
Derivation
  1. Initial program 97.7%

    \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
  2. Taylor expanded in c around inf

    \[\leadsto \color{blue}{c} \]
  3. Applied rewrites22.5%

    \[\leadsto \color{blue}{c} \]
  4. Add Preprocessing

Reproduce

?
herbie shell --seed 2025128 
(FPCore (x y z t a b c)
  :name "Diagrams.Solve.Polynomial:quartForm  from diagrams-solve-0.1, C"
  :precision binary64
  (+ (- (+ (* x y) (/ (* z t) 16.0)) (/ (* a b) 4.0)) c))