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

Percentage Accurate: 99.9% → 99.9%
Time: 7.1s
Alternatives: 8
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 8 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, 0.1× speedup?

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

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

    \[\left(x \cdot y + z\right) \cdot y + t \]
  2. Step-by-step derivation
    1. fma-define99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot y + z, y, t\right)} \]
    2. fma-define99.9%

      \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(x, y, z\right)}, y, t\right) \]
  3. Simplified99.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, t\right)} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. fma-define99.9%

      \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot y + z}, y, t\right) \]
  6. Applied egg-rr99.9%

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

Alternative 2: 62.4% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := y \cdot \left(x \cdot y\right)\\ \mathbf{if}\;y \leq -7.8 \cdot 10^{+58}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq -0.48:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 6.2 \cdot 10^{-51}:\\ \;\;\;\;t\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{+142}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (* y (* x y))))
   (if (<= y -7.8e+58)
     t_1
     (if (<= y -0.48)
       (* y z)
       (if (<= y 6.2e-51) t (if (<= y 1.1e+142) (* y z) t_1))))))
double code(double x, double y, double z, double t) {
	double t_1 = y * (x * y);
	double tmp;
	if (y <= -7.8e+58) {
		tmp = t_1;
	} else if (y <= -0.48) {
		tmp = y * z;
	} else if (y <= 6.2e-51) {
		tmp = t;
	} else if (y <= 1.1e+142) {
		tmp = y * z;
	} else {
		tmp = t_1;
	}
	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 = y * (x * y)
    if (y <= (-7.8d+58)) then
        tmp = t_1
    else if (y <= (-0.48d0)) then
        tmp = y * z
    else if (y <= 6.2d-51) then
        tmp = t
    else if (y <= 1.1d+142) then
        tmp = y * z
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double t_1 = y * (x * y);
	double tmp;
	if (y <= -7.8e+58) {
		tmp = t_1;
	} else if (y <= -0.48) {
		tmp = y * z;
	} else if (y <= 6.2e-51) {
		tmp = t;
	} else if (y <= 1.1e+142) {
		tmp = y * z;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z, t):
	t_1 = y * (x * y)
	tmp = 0
	if y <= -7.8e+58:
		tmp = t_1
	elif y <= -0.48:
		tmp = y * z
	elif y <= 6.2e-51:
		tmp = t
	elif y <= 1.1e+142:
		tmp = y * z
	else:
		tmp = t_1
	return tmp
function code(x, y, z, t)
	t_1 = Float64(y * Float64(x * y))
	tmp = 0.0
	if (y <= -7.8e+58)
		tmp = t_1;
	elseif (y <= -0.48)
		tmp = Float64(y * z);
	elseif (y <= 6.2e-51)
		tmp = t;
	elseif (y <= 1.1e+142)
		tmp = Float64(y * z);
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	t_1 = y * (x * y);
	tmp = 0.0;
	if (y <= -7.8e+58)
		tmp = t_1;
	elseif (y <= -0.48)
		tmp = y * z;
	elseif (y <= 6.2e-51)
		tmp = t;
	elseif (y <= 1.1e+142)
		tmp = y * z;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -7.8e+58], t$95$1, If[LessEqual[y, -0.48], N[(y * z), $MachinePrecision], If[LessEqual[y, 6.2e-51], t, If[LessEqual[y, 1.1e+142], N[(y * z), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq -0.48:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;y \leq 6.2 \cdot 10^{-51}:\\
\;\;\;\;t\\

\mathbf{elif}\;y \leq 1.1 \cdot 10^{+142}:\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -7.8000000000000002e58 or 1.09999999999999993e142 < y

    1. Initial program 99.9%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Step-by-step derivation
      1. fma-define99.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot y + z, y, t\right)} \]
      2. fma-define99.9%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(x, y, z\right)}, y, t\right) \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, t\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. fma-define99.9%

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot y + z}, y, t\right) \]
    6. Applied egg-rr99.9%

      \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot y + z}, y, t\right) \]
    7. Taylor expanded in t around 0 97.8%

      \[\leadsto \color{blue}{y \cdot \left(z + x \cdot y\right)} \]
    8. Taylor expanded in z around 0 81.4%

      \[\leadsto y \cdot \color{blue}{\left(x \cdot y\right)} \]
    9. Step-by-step derivation
      1. *-commutative81.4%

        \[\leadsto y \cdot \color{blue}{\left(y \cdot x\right)} \]
    10. Simplified81.4%

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

    if -7.8000000000000002e58 < y < -0.47999999999999998 or 6.1999999999999995e-51 < y < 1.09999999999999993e142

    1. Initial program 99.9%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Step-by-step derivation
      1. fma-define99.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot y + z, y, t\right)} \]
      2. fma-define99.9%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(x, y, z\right)}, y, t\right) \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, t\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. fma-define99.9%

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot y + z}, y, t\right) \]
    6. Applied egg-rr99.9%

      \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot y + z}, y, t\right) \]
    7. Taylor expanded in z around inf 53.1%

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

    if -0.47999999999999998 < y < 6.1999999999999995e-51

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{t} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification68.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -7.8 \cdot 10^{+58}:\\ \;\;\;\;y \cdot \left(x \cdot y\right)\\ \mathbf{elif}\;y \leq -0.48:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 6.2 \cdot 10^{-51}:\\ \;\;\;\;t\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{+142}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x \cdot y\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 60.9% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := x \cdot \left(y \cdot y\right)\\ \mathbf{if}\;y \leq -3.5 \cdot 10^{+58}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq -23000000:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 2.7 \cdot 10^{-51}:\\ \;\;\;\;t\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{+142}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (* x (* y y))))
   (if (<= y -3.5e+58)
     t_1
     (if (<= y -23000000.0)
       (* y z)
       (if (<= y 2.7e-51) t (if (<= y 1.1e+142) (* y z) t_1))))))
double code(double x, double y, double z, double t) {
	double t_1 = x * (y * y);
	double tmp;
	if (y <= -3.5e+58) {
		tmp = t_1;
	} else if (y <= -23000000.0) {
		tmp = y * z;
	} else if (y <= 2.7e-51) {
		tmp = t;
	} else if (y <= 1.1e+142) {
		tmp = y * z;
	} else {
		tmp = t_1;
	}
	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 = x * (y * y)
    if (y <= (-3.5d+58)) then
        tmp = t_1
    else if (y <= (-23000000.0d0)) then
        tmp = y * z
    else if (y <= 2.7d-51) then
        tmp = t
    else if (y <= 1.1d+142) then
        tmp = y * z
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double t_1 = x * (y * y);
	double tmp;
	if (y <= -3.5e+58) {
		tmp = t_1;
	} else if (y <= -23000000.0) {
		tmp = y * z;
	} else if (y <= 2.7e-51) {
		tmp = t;
	} else if (y <= 1.1e+142) {
		tmp = y * z;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z, t):
	t_1 = x * (y * y)
	tmp = 0
	if y <= -3.5e+58:
		tmp = t_1
	elif y <= -23000000.0:
		tmp = y * z
	elif y <= 2.7e-51:
		tmp = t
	elif y <= 1.1e+142:
		tmp = y * z
	else:
		tmp = t_1
	return tmp
function code(x, y, z, t)
	t_1 = Float64(x * Float64(y * y))
	tmp = 0.0
	if (y <= -3.5e+58)
		tmp = t_1;
	elseif (y <= -23000000.0)
		tmp = Float64(y * z);
	elseif (y <= 2.7e-51)
		tmp = t;
	elseif (y <= 1.1e+142)
		tmp = Float64(y * z);
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	t_1 = x * (y * y);
	tmp = 0.0;
	if (y <= -3.5e+58)
		tmp = t_1;
	elseif (y <= -23000000.0)
		tmp = y * z;
	elseif (y <= 2.7e-51)
		tmp = t;
	elseif (y <= 1.1e+142)
		tmp = y * z;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3.5e+58], t$95$1, If[LessEqual[y, -23000000.0], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.7e-51], t, If[LessEqual[y, 1.1e+142], N[(y * z), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq -23000000:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;y \leq 2.7 \cdot 10^{-51}:\\
\;\;\;\;t\\

\mathbf{elif}\;y \leq 1.1 \cdot 10^{+142}:\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -3.4999999999999997e58 or 1.09999999999999993e142 < y

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{x \cdot \left(\frac{y \cdot z}{x} + {y}^{2}\right)} + t \]
    4. Step-by-step derivation
      1. +-commutative63.8%

        \[\leadsto x \cdot \color{blue}{\left({y}^{2} + \frac{y \cdot z}{x}\right)} + t \]
      2. unpow263.8%

        \[\leadsto x \cdot \left(\color{blue}{y \cdot y} + \frac{y \cdot z}{x}\right) + t \]
      3. associate-/l*72.7%

        \[\leadsto x \cdot \left(y \cdot y + \color{blue}{y \cdot \frac{z}{x}}\right) + t \]
      4. distribute-lft-out90.6%

        \[\leadsto x \cdot \color{blue}{\left(y \cdot \left(y + \frac{z}{x}\right)\right)} + t \]
    5. Simplified90.6%

      \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(y + \frac{z}{x}\right)\right)} + t \]
    6. Taylor expanded in t around 0 88.5%

      \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(y + \frac{z}{x}\right)\right)} \]
    7. Taylor expanded in y around inf 77.3%

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

    if -3.4999999999999997e58 < y < -2.3e7 or 2.6999999999999997e-51 < y < 1.09999999999999993e142

    1. Initial program 99.9%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Step-by-step derivation
      1. fma-define99.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot y + z, y, t\right)} \]
      2. fma-define99.9%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(x, y, z\right)}, y, t\right) \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, t\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. fma-define99.9%

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot y + z}, y, t\right) \]
    6. Applied egg-rr99.9%

      \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot y + z}, y, t\right) \]
    7. Taylor expanded in z around inf 53.1%

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

    if -2.3e7 < y < 2.6999999999999997e-51

    1. Initial program 99.9%

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

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

Alternative 4: 88.8% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -3.8 \cdot 10^{+23} \lor \neg \left(y \leq 3.2 \cdot 10^{-41}\right):\\ \;\;\;\;y \cdot \left(x \cdot y + z\right)\\ \mathbf{else}:\\ \;\;\;\;t + y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (or (<= y -3.8e+23) (not (<= y 3.2e-41)))
   (* y (+ (* x y) z))
   (+ t (* y z))))
double code(double x, double y, double z, double t) {
	double tmp;
	if ((y <= -3.8e+23) || !(y <= 3.2e-41)) {
		tmp = y * ((x * y) + z);
	} else {
		tmp = t + (y * z);
	}
	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) :: tmp
    if ((y <= (-3.8d+23)) .or. (.not. (y <= 3.2d-41))) then
        tmp = y * ((x * y) + z)
    else
        tmp = t + (y * z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if ((y <= -3.8e+23) || !(y <= 3.2e-41)) {
		tmp = y * ((x * y) + z);
	} else {
		tmp = t + (y * z);
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if (y <= -3.8e+23) or not (y <= 3.2e-41):
		tmp = y * ((x * y) + z)
	else:
		tmp = t + (y * z)
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if ((y <= -3.8e+23) || !(y <= 3.2e-41))
		tmp = Float64(y * Float64(Float64(x * y) + z));
	else
		tmp = Float64(t + Float64(y * z));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if ((y <= -3.8e+23) || ~((y <= 3.2e-41)))
		tmp = y * ((x * y) + z);
	else
		tmp = t + (y * z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3.8e+23], N[Not[LessEqual[y, 3.2e-41]], $MachinePrecision]], N[(y * N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{+23} \lor \neg \left(y \leq 3.2 \cdot 10^{-41}\right):\\
\;\;\;\;y \cdot \left(x \cdot y + z\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -3.79999999999999975e23 or 3.20000000000000012e-41 < y

    1. Initial program 99.9%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Step-by-step derivation
      1. fma-define99.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot y + z, y, t\right)} \]
      2. fma-define99.9%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(x, y, z\right)}, y, t\right) \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, t\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. fma-define99.9%

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot y + z}, y, t\right) \]
    6. Applied egg-rr99.9%

      \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot y + z}, y, t\right) \]
    7. Taylor expanded in t around 0 92.9%

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

    if -3.79999999999999975e23 < y < 3.20000000000000012e-41

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{z} \cdot y + t \]
  3. Recombined 2 regimes into one program.
  4. Final simplification91.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.8 \cdot 10^{+23} \lor \neg \left(y \leq 3.2 \cdot 10^{-41}\right):\\ \;\;\;\;y \cdot \left(x \cdot y + z\right)\\ \mathbf{else}:\\ \;\;\;\;t + y \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 78.7% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -3.5 \cdot 10^{+105} \lor \neg \left(y \leq 4.5 \cdot 10^{+149}\right):\\ \;\;\;\;y \cdot \left(x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t + y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (or (<= y -3.5e+105) (not (<= y 4.5e+149))) (* y (* x y)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
	double tmp;
	if ((y <= -3.5e+105) || !(y <= 4.5e+149)) {
		tmp = y * (x * y);
	} else {
		tmp = t + (y * z);
	}
	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) :: tmp
    if ((y <= (-3.5d+105)) .or. (.not. (y <= 4.5d+149))) then
        tmp = y * (x * y)
    else
        tmp = t + (y * z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if ((y <= -3.5e+105) || !(y <= 4.5e+149)) {
		tmp = y * (x * y);
	} else {
		tmp = t + (y * z);
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if (y <= -3.5e+105) or not (y <= 4.5e+149):
		tmp = y * (x * y)
	else:
		tmp = t + (y * z)
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if ((y <= -3.5e+105) || !(y <= 4.5e+149))
		tmp = Float64(y * Float64(x * y));
	else
		tmp = Float64(t + Float64(y * z));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if ((y <= -3.5e+105) || ~((y <= 4.5e+149)))
		tmp = y * (x * y);
	else
		tmp = t + (y * z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3.5e+105], N[Not[LessEqual[y, 4.5e+149]], $MachinePrecision]], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.5 \cdot 10^{+105} \lor \neg \left(y \leq 4.5 \cdot 10^{+149}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -3.49999999999999991e105 or 4.49999999999999982e149 < y

    1. Initial program 100.0%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Step-by-step derivation
      1. fma-define100.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot y + z, y, t\right)} \]
      2. fma-define100.0%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(x, y, z\right)}, y, t\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, t\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. fma-define100.0%

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot y + z}, y, t\right) \]
    6. Applied egg-rr100.0%

      \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot y + z}, y, t\right) \]
    7. Taylor expanded in t around 0 100.0%

      \[\leadsto \color{blue}{y \cdot \left(z + x \cdot y\right)} \]
    8. Taylor expanded in z around 0 87.3%

      \[\leadsto y \cdot \color{blue}{\left(x \cdot y\right)} \]
    9. Step-by-step derivation
      1. *-commutative87.3%

        \[\leadsto y \cdot \color{blue}{\left(y \cdot x\right)} \]
    10. Simplified87.3%

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

    if -3.49999999999999991e105 < y < 4.49999999999999982e149

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{z} \cdot y + t \]
  3. Recombined 2 regimes into one program.
  4. Final simplification84.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.5 \cdot 10^{+105} \lor \neg \left(y \leq 4.5 \cdot 10^{+149}\right):\\ \;\;\;\;y \cdot \left(x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t + y \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 51.0% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.35 \cdot 10^{+29} \lor \neg \left(z \leq 1.1 \cdot 10^{-20}\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (or (<= z -1.35e+29) (not (<= z 1.1e-20))) (* y z) t))
double code(double x, double y, double z, double t) {
	double tmp;
	if ((z <= -1.35e+29) || !(z <= 1.1e-20)) {
		tmp = y * z;
	} else {
		tmp = t;
	}
	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) :: tmp
    if ((z <= (-1.35d+29)) .or. (.not. (z <= 1.1d-20))) then
        tmp = y * z
    else
        tmp = t
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if ((z <= -1.35e+29) || !(z <= 1.1e-20)) {
		tmp = y * z;
	} else {
		tmp = t;
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if (z <= -1.35e+29) or not (z <= 1.1e-20):
		tmp = y * z
	else:
		tmp = t
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if ((z <= -1.35e+29) || !(z <= 1.1e-20))
		tmp = Float64(y * z);
	else
		tmp = t;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if ((z <= -1.35e+29) || ~((z <= 1.1e-20)))
		tmp = y * z;
	else
		tmp = t;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.35e+29], N[Not[LessEqual[z, 1.1e-20]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.35 \cdot 10^{+29} \lor \neg \left(z \leq 1.1 \cdot 10^{-20}\right):\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.35e29 or 1.09999999999999995e-20 < z

    1. Initial program 99.9%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Step-by-step derivation
      1. fma-define100.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot y + z, y, t\right)} \]
      2. fma-define100.0%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(x, y, z\right)}, y, t\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, t\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. fma-define100.0%

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot y + z}, y, t\right) \]
    6. Applied egg-rr100.0%

      \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot y + z}, y, t\right) \]
    7. Taylor expanded in z around inf 53.2%

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

    if -1.35e29 < z < 1.09999999999999995e-20

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{t} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification50.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.35 \cdot 10^{+29} \lor \neg \left(z \leq 1.1 \cdot 10^{-20}\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 99.9% accurate, 1.0× speedup?

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

\\
t + y \cdot \left(x \cdot y + z\right)
\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 + y \cdot \left(x \cdot y + z\right) \]
  4. Add Preprocessing

Alternative 8: 38.4% accurate, 9.0× speedup?

\[\begin{array}{l} \\ t \end{array} \]
(FPCore (x y z t) :precision binary64 t)
double code(double x, double y, double z, double t) {
	return 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 = t
end function
public static double code(double x, double y, double z, double t) {
	return t;
}
def code(x, y, z, t):
	return t
function code(x, y, z, t)
	return t
end
function tmp = code(x, y, z, t)
	tmp = t;
end
code[x_, y_, z_, t_] := t
\begin{array}{l}

\\
t
\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 34.8%

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

Reproduce

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