Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23

Percentage Accurate: 99.9% → 99.9%
Time: 6.8s
Alternatives: 6
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \left(x \cdot y + z\right) \cdot y + t \end{array} \]
(FPCore (x y z t) :precision binary64 (+ (* (+ (* x y) z) y) t))
double code(double x, double y, double z, double t) {
	return (((x * y) + z) * y) + t;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = (((x * y) + z) * y) + t
end function
public static double code(double x, double y, double z, double t) {
	return (((x * y) + z) * y) + t;
}
def code(x, y, z, t):
	return (((x * y) + z) * y) + t
function code(x, y, z, t)
	return Float64(Float64(Float64(Float64(x * y) + z) * y) + t)
end
function tmp = code(x, y, z, t)
	tmp = (((x * y) + z) * y) + t;
end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}

\\
\left(x \cdot y + z\right) \cdot y + t
\end{array}

Sampling outcomes in binary64 precision:

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 6 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(x \cdot y + z\right) \cdot y + t \end{array} \]
(FPCore (x y z t) :precision binary64 (+ (* (+ (* x y) z) y) t))
double code(double x, double y, double z, double t) {
	return (((x * y) + z) * y) + t;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = (((x * y) + z) * y) + t
end function
public static double code(double x, double y, double z, double t) {
	return (((x * y) + z) * y) + t;
}
def code(x, y, z, t):
	return (((x * y) + z) * y) + t
function code(x, y, z, t)
	return Float64(Float64(Float64(Float64(x * y) + z) * y) + t)
end
function tmp = code(x, y, z, t)
	tmp = (((x * y) + z) * y) + t;
end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}

\\
\left(x \cdot y + z\right) \cdot y + t
\end{array}

Alternative 1: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ t + \left(z + y \cdot x\right) \cdot y \end{array} \]
(FPCore (x y z t) :precision binary64 (+ t (* (+ z (* y x)) y)))
double code(double x, double y, double z, double t) {
	return t + ((z + (y * x)) * y);
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = t + ((z + (y * x)) * y)
end function
public static double code(double x, double y, double z, double t) {
	return t + ((z + (y * x)) * y);
}
def code(x, y, z, t):
	return t + ((z + (y * x)) * y)
function code(x, y, z, t)
	return Float64(t + Float64(Float64(z + Float64(y * x)) * y))
end
function tmp = code(x, y, z, t)
	tmp = t + ((z + (y * x)) * y);
end
code[x_, y_, z_, t_] := N[(t + N[(N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
t + \left(z + y \cdot x\right) \cdot y
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(x \cdot y + z\right) \cdot y + t \]
  2. Add Preprocessing
  3. Final simplification99.9%

    \[\leadsto t + \left(z + y \cdot x\right) \cdot y \]
  4. Add Preprocessing

Alternative 2: 90.4% accurate, 0.3× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (+.f64 (*.f64 x y) z) y) < -1.00000000000000003e170 or 1.0000000000000001e97 < (*.f64 (+.f64 (*.f64 x y) z) y)

    1. Initial program 99.9%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Add Preprocessing
    3. Taylor expanded in t around 0

      \[\leadsto \color{blue}{y \cdot \left(z + x \cdot y\right)} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\left(z + x \cdot y\right) \cdot y} \]
      2. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(z + x \cdot y\right) \cdot y} \]
      3. +-commutativeN/A

        \[\leadsto \color{blue}{\left(x \cdot y + z\right)} \cdot y \]
      4. lower-fma.f6494.9

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, z\right)} \cdot y \]
    5. Applied rewrites94.9%

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

    if -1.00000000000000003e170 < (*.f64 (+.f64 (*.f64 x y) z) y) < 1.0000000000000001e97

    1. Initial program 99.9%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \color{blue}{t + y \cdot z} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{y \cdot z + t} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{z \cdot y} + t \]
      3. lower-fma.f6490.1

        \[\leadsto \color{blue}{\mathsf{fma}\left(z, y, t\right)} \]
    5. Applied rewrites90.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, y, t\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification92.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(z + y \cdot x\right) \cdot y \leq -1 \cdot 10^{+170}:\\ \;\;\;\;\mathsf{fma}\left(x, y, z\right) \cdot y\\ \mathbf{elif}\;\left(z + y \cdot x\right) \cdot y \leq 10^{+97}:\\ \;\;\;\;\mathsf{fma}\left(z, y, t\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, y, z\right) \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 51.3% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left(z + y \cdot x\right) \cdot y\\ \mathbf{if}\;t\_1 \leq -0.2:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-9}:\\ \;\;\;\;1 \cdot t\\ \mathbf{else}:\\ \;\;\;\;z \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (* (+ z (* y x)) y)))
   (if (<= t_1 -0.2) (* z y) (if (<= t_1 5e-9) (* 1.0 t) (* z y)))))
double code(double x, double y, double z, double t) {
	double t_1 = (z + (y * x)) * y;
	double tmp;
	if (t_1 <= -0.2) {
		tmp = z * y;
	} else if (t_1 <= 5e-9) {
		tmp = 1.0 * t;
	} else {
		tmp = z * y;
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: t_1
    real(8) :: tmp
    t_1 = (z + (y * x)) * y
    if (t_1 <= (-0.2d0)) then
        tmp = z * y
    else if (t_1 <= 5d-9) then
        tmp = 1.0d0 * t
    else
        tmp = z * y
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double t_1 = (z + (y * x)) * y;
	double tmp;
	if (t_1 <= -0.2) {
		tmp = z * y;
	} else if (t_1 <= 5e-9) {
		tmp = 1.0 * t;
	} else {
		tmp = z * y;
	}
	return tmp;
}
def code(x, y, z, t):
	t_1 = (z + (y * x)) * y
	tmp = 0
	if t_1 <= -0.2:
		tmp = z * y
	elif t_1 <= 5e-9:
		tmp = 1.0 * t
	else:
		tmp = z * y
	return tmp
function code(x, y, z, t)
	t_1 = Float64(Float64(z + Float64(y * x)) * y)
	tmp = 0.0
	if (t_1 <= -0.2)
		tmp = Float64(z * y);
	elseif (t_1 <= 5e-9)
		tmp = Float64(1.0 * t);
	else
		tmp = Float64(z * y);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	t_1 = (z + (y * x)) * y;
	tmp = 0.0;
	if (t_1 <= -0.2)
		tmp = z * y;
	elseif (t_1 <= 5e-9)
		tmp = 1.0 * t;
	else
		tmp = z * y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$1, -0.2], N[(z * y), $MachinePrecision], If[LessEqual[t$95$1, 5e-9], N[(1.0 * t), $MachinePrecision], N[(z * y), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left(z + y \cdot x\right) \cdot y\\
\mathbf{if}\;t\_1 \leq -0.2:\\
\;\;\;\;z \cdot y\\

\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-9}:\\
\;\;\;\;1 \cdot t\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (+.f64 (*.f64 x y) z) y) < -0.20000000000000001 or 5.0000000000000001e-9 < (*.f64 (+.f64 (*.f64 x y) z) y)

    1. Initial program 99.9%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf

      \[\leadsto \color{blue}{y \cdot z} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{z \cdot y} \]
      2. lower-*.f6443.4

        \[\leadsto \color{blue}{z \cdot y} \]
    5. Applied rewrites43.4%

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

    if -0.20000000000000001 < (*.f64 (+.f64 (*.f64 x y) z) y) < 5.0000000000000001e-9

    1. Initial program 99.9%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(x \cdot y + z\right) \cdot y} + t \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot \left(x \cdot y + z\right)} + t \]
      3. lift-+.f64N/A

        \[\leadsto y \cdot \color{blue}{\left(x \cdot y + z\right)} + t \]
      4. flip-+N/A

        \[\leadsto y \cdot \color{blue}{\frac{\left(x \cdot y\right) \cdot \left(x \cdot y\right) - z \cdot z}{x \cdot y - z}} + t \]
      5. clear-numN/A

        \[\leadsto y \cdot \color{blue}{\frac{1}{\frac{x \cdot y - z}{\left(x \cdot y\right) \cdot \left(x \cdot y\right) - z \cdot z}}} + t \]
      6. un-div-invN/A

        \[\leadsto \color{blue}{\frac{y}{\frac{x \cdot y - z}{\left(x \cdot y\right) \cdot \left(x \cdot y\right) - z \cdot z}}} + t \]
      7. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{y}{\frac{x \cdot y - z}{\left(x \cdot y\right) \cdot \left(x \cdot y\right) - z \cdot z}}} + t \]
      8. clear-numN/A

        \[\leadsto \frac{y}{\color{blue}{\frac{1}{\frac{\left(x \cdot y\right) \cdot \left(x \cdot y\right) - z \cdot z}{x \cdot y - z}}}} + t \]
      9. flip-+N/A

        \[\leadsto \frac{y}{\frac{1}{\color{blue}{x \cdot y + z}}} + t \]
      10. lift-+.f64N/A

        \[\leadsto \frac{y}{\frac{1}{\color{blue}{x \cdot y + z}}} + t \]
      11. inv-powN/A

        \[\leadsto \frac{y}{\color{blue}{{\left(x \cdot y + z\right)}^{-1}}} + t \]
      12. lower-pow.f6499.8

        \[\leadsto \frac{y}{\color{blue}{{\left(x \cdot y + z\right)}^{-1}}} + t \]
      13. lift-+.f64N/A

        \[\leadsto \frac{y}{{\color{blue}{\left(x \cdot y + z\right)}}^{-1}} + t \]
      14. lift-*.f64N/A

        \[\leadsto \frac{y}{{\left(\color{blue}{x \cdot y} + z\right)}^{-1}} + t \]
      15. *-commutativeN/A

        \[\leadsto \frac{y}{{\left(\color{blue}{y \cdot x} + z\right)}^{-1}} + t \]
      16. lower-fma.f6499.8

        \[\leadsto \frac{y}{{\color{blue}{\left(\mathsf{fma}\left(y, x, z\right)\right)}}^{-1}} + t \]
    4. Applied rewrites99.8%

      \[\leadsto \color{blue}{\frac{y}{{\left(\mathsf{fma}\left(y, x, z\right)\right)}^{-1}}} + t \]
    5. Taylor expanded in t around inf

      \[\leadsto \color{blue}{t \cdot \left(1 + \frac{y \cdot \left(z + x \cdot y\right)}{t}\right)} \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\left(1 + \frac{y \cdot \left(z + x \cdot y\right)}{t}\right) \cdot t} \]
      2. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(1 + \frac{y \cdot \left(z + x \cdot y\right)}{t}\right) \cdot t} \]
      3. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\frac{y \cdot \left(z + x \cdot y\right)}{t} + 1\right)} \cdot t \]
      4. associate-/l*N/A

        \[\leadsto \left(\color{blue}{y \cdot \frac{z + x \cdot y}{t}} + 1\right) \cdot t \]
      5. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{z + x \cdot y}{t}, 1\right)} \cdot t \]
      6. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(y, \color{blue}{\frac{z + x \cdot y}{t}}, 1\right) \cdot t \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(y, \frac{\color{blue}{x \cdot y + z}}{t}, 1\right) \cdot t \]
      8. lower-fma.f6498.8

        \[\leadsto \mathsf{fma}\left(y, \frac{\color{blue}{\mathsf{fma}\left(x, y, z\right)}}{t}, 1\right) \cdot t \]
    7. Applied rewrites98.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{\mathsf{fma}\left(x, y, z\right)}{t}, 1\right) \cdot t} \]
    8. Taylor expanded in t around inf

      \[\leadsto 1 \cdot t \]
    9. Step-by-step derivation
      1. Applied rewrites86.2%

        \[\leadsto 1 \cdot t \]
    10. Recombined 2 regimes into one program.
    11. Final simplification57.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left(z + y \cdot x\right) \cdot y \leq -0.2:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;\left(z + y \cdot x\right) \cdot y \leq 5 \cdot 10^{-9}:\\ \;\;\;\;1 \cdot t\\ \mathbf{else}:\\ \;\;\;\;z \cdot y\\ \end{array} \]
    12. Add Preprocessing

    Alternative 4: 80.3% accurate, 0.7× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_1 := \left(y \cdot x\right) \cdot y\\ \mathbf{if}\;y \leq -2.7 \cdot 10^{+36}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{+87}:\\ \;\;\;\;\mathsf{fma}\left(z, y, t\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
    (FPCore (x y z t)
     :precision binary64
     (let* ((t_1 (* (* y x) y)))
       (if (<= y -2.7e+36) t_1 (if (<= y 5.5e+87) (fma z y t) t_1))))
    double code(double x, double y, double z, double t) {
    	double t_1 = (y * x) * y;
    	double tmp;
    	if (y <= -2.7e+36) {
    		tmp = t_1;
    	} else if (y <= 5.5e+87) {
    		tmp = fma(z, y, t);
    	} else {
    		tmp = t_1;
    	}
    	return tmp;
    }
    
    function code(x, y, z, t)
    	t_1 = Float64(Float64(y * x) * y)
    	tmp = 0.0
    	if (y <= -2.7e+36)
    		tmp = t_1;
    	elseif (y <= 5.5e+87)
    		tmp = fma(z, y, t);
    	else
    		tmp = t_1;
    	end
    	return tmp
    end
    
    code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(y * x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -2.7e+36], t$95$1, If[LessEqual[y, 5.5e+87], N[(z * y + t), $MachinePrecision], t$95$1]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_1 := \left(y \cdot x\right) \cdot y\\
    \mathbf{if}\;y \leq -2.7 \cdot 10^{+36}:\\
    \;\;\;\;t\_1\\
    
    \mathbf{elif}\;y \leq 5.5 \cdot 10^{+87}:\\
    \;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_1\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if y < -2.7000000000000001e36 or 5.50000000000000022e87 < y

      1. Initial program 100.0%

        \[\left(x \cdot y + z\right) \cdot y + t \]
      2. Add Preprocessing
      3. Taylor expanded in y around inf

        \[\leadsto \color{blue}{x \cdot {y}^{2}} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

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

          \[\leadsto \color{blue}{{y}^{2} \cdot x} \]
        3. unpow2N/A

          \[\leadsto \color{blue}{\left(y \cdot y\right)} \cdot x \]
        4. lower-*.f6471.3

          \[\leadsto \color{blue}{\left(y \cdot y\right)} \cdot x \]
      5. Applied rewrites71.3%

        \[\leadsto \color{blue}{\left(y \cdot y\right) \cdot x} \]
      6. Step-by-step derivation
        1. Applied rewrites77.2%

          \[\leadsto \left(x \cdot y\right) \cdot \color{blue}{y} \]

        if -2.7000000000000001e36 < y < 5.50000000000000022e87

        1. Initial program 99.9%

          \[\left(x \cdot y + z\right) \cdot y + t \]
        2. Add Preprocessing
        3. Taylor expanded in y around 0

          \[\leadsto \color{blue}{t + y \cdot z} \]
        4. Step-by-step derivation
          1. +-commutativeN/A

            \[\leadsto \color{blue}{y \cdot z + t} \]
          2. *-commutativeN/A

            \[\leadsto \color{blue}{z \cdot y} + t \]
          3. lower-fma.f6488.8

            \[\leadsto \color{blue}{\mathsf{fma}\left(z, y, t\right)} \]
        5. Applied rewrites88.8%

          \[\leadsto \color{blue}{\mathsf{fma}\left(z, y, t\right)} \]
      7. Recombined 2 regimes into one program.
      8. Final simplification83.7%

        \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.7 \cdot 10^{+36}:\\ \;\;\;\;\left(y \cdot x\right) \cdot y\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{+87}:\\ \;\;\;\;\mathsf{fma}\left(z, y, t\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot x\right) \cdot y\\ \end{array} \]
      9. Add Preprocessing

      Alternative 5: 65.4% accurate, 2.4× speedup?

      \[\begin{array}{l} \\ \mathsf{fma}\left(z, y, t\right) \end{array} \]
      (FPCore (x y z t) :precision binary64 (fma z y t))
      double code(double x, double y, double z, double t) {
      	return fma(z, y, t);
      }
      
      function code(x, y, z, t)
      	return fma(z, y, t)
      end
      
      code[x_, y_, z_, t_] := N[(z * y + t), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \mathsf{fma}\left(z, y, t\right)
      \end{array}
      
      Derivation
      1. Initial program 99.9%

        \[\left(x \cdot y + z\right) \cdot y + t \]
      2. Add Preprocessing
      3. Taylor expanded in y around 0

        \[\leadsto \color{blue}{t + y \cdot z} \]
      4. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \color{blue}{y \cdot z + t} \]
        2. *-commutativeN/A

          \[\leadsto \color{blue}{z \cdot y} + t \]
        3. lower-fma.f6466.7

          \[\leadsto \color{blue}{\mathsf{fma}\left(z, y, t\right)} \]
      5. Applied rewrites66.7%

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

      Alternative 6: 29.2% accurate, 2.8× speedup?

      \[\begin{array}{l} \\ z \cdot y \end{array} \]
      (FPCore (x y z t) :precision binary64 (* z y))
      double code(double x, double y, double z, double t) {
      	return z * y;
      }
      
      real(8) function code(x, y, z, t)
          real(8), intent (in) :: x
          real(8), intent (in) :: y
          real(8), intent (in) :: z
          real(8), intent (in) :: t
          code = z * y
      end function
      
      public static double code(double x, double y, double z, double t) {
      	return z * y;
      }
      
      def code(x, y, z, t):
      	return z * y
      
      function code(x, y, z, t)
      	return Float64(z * y)
      end
      
      function tmp = code(x, y, z, t)
      	tmp = z * y;
      end
      
      code[x_, y_, z_, t_] := N[(z * y), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      z \cdot y
      \end{array}
      
      Derivation
      1. Initial program 99.9%

        \[\left(x \cdot y + z\right) \cdot y + t \]
      2. Add Preprocessing
      3. Taylor expanded in z around inf

        \[\leadsto \color{blue}{y \cdot z} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{z \cdot y} \]
        2. lower-*.f6432.0

          \[\leadsto \color{blue}{z \cdot y} \]
      5. Applied rewrites32.0%

        \[\leadsto \color{blue}{z \cdot y} \]
      6. Add Preprocessing

      Reproduce

      ?
      herbie shell --seed 2024255 
      (FPCore (x y z t)
        :name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
        :precision binary64
        (+ (* (+ (* x y) z) y) t))