Main:bigenough2 from A

Percentage Accurate: 100.0% → 100.0%
Time: 4.5s
Alternatives: 8
Speedup: 1.0×

Specification

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

\\
x + y \cdot \left(z + x\right)
\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: 100.0% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 0.1× speedup?

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

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

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

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

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(y, x + z, x\right)} \]
  4. Final simplification100.0%

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

Alternative 2: 60.5% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -8 \cdot 10^{+151}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq -6.6 \cdot 10^{+128}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -3.3 \cdot 10^{+63}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq -3.45 \cdot 10^{+46}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -1.9 \cdot 10^{-64}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{-23}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 6.4 \cdot 10^{+28}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{+51} \lor \neg \left(y \leq 2.05 \cdot 10^{+151}\right) \land y \leq 1.1 \cdot 10^{+234}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -8e+151)
   (* y z)
   (if (<= y -6.6e+128)
     (* y x)
     (if (<= y -3.3e+63)
       (* y z)
       (if (<= y -3.45e+46)
         (* y x)
         (if (<= y -1.9e-64)
           (* y z)
           (if (<= y 4.2e-23)
             x
             (if (<= y 6.4e+28)
               (* y z)
               (if (or (<= y 1.15e+51)
                       (and (not (<= y 2.05e+151)) (<= y 1.1e+234)))
                 (* y x)
                 (* y z))))))))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -8e+151) {
		tmp = y * z;
	} else if (y <= -6.6e+128) {
		tmp = y * x;
	} else if (y <= -3.3e+63) {
		tmp = y * z;
	} else if (y <= -3.45e+46) {
		tmp = y * x;
	} else if (y <= -1.9e-64) {
		tmp = y * z;
	} else if (y <= 4.2e-23) {
		tmp = x;
	} else if (y <= 6.4e+28) {
		tmp = y * z;
	} else if ((y <= 1.15e+51) || (!(y <= 2.05e+151) && (y <= 1.1e+234))) {
		tmp = y * x;
	} else {
		tmp = y * z;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y <= (-8d+151)) then
        tmp = y * z
    else if (y <= (-6.6d+128)) then
        tmp = y * x
    else if (y <= (-3.3d+63)) then
        tmp = y * z
    else if (y <= (-3.45d+46)) then
        tmp = y * x
    else if (y <= (-1.9d-64)) then
        tmp = y * z
    else if (y <= 4.2d-23) then
        tmp = x
    else if (y <= 6.4d+28) then
        tmp = y * z
    else if ((y <= 1.15d+51) .or. (.not. (y <= 2.05d+151)) .and. (y <= 1.1d+234)) then
        tmp = y * x
    else
        tmp = y * z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -8e+151) {
		tmp = y * z;
	} else if (y <= -6.6e+128) {
		tmp = y * x;
	} else if (y <= -3.3e+63) {
		tmp = y * z;
	} else if (y <= -3.45e+46) {
		tmp = y * x;
	} else if (y <= -1.9e-64) {
		tmp = y * z;
	} else if (y <= 4.2e-23) {
		tmp = x;
	} else if (y <= 6.4e+28) {
		tmp = y * z;
	} else if ((y <= 1.15e+51) || (!(y <= 2.05e+151) && (y <= 1.1e+234))) {
		tmp = y * x;
	} else {
		tmp = y * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -8e+151:
		tmp = y * z
	elif y <= -6.6e+128:
		tmp = y * x
	elif y <= -3.3e+63:
		tmp = y * z
	elif y <= -3.45e+46:
		tmp = y * x
	elif y <= -1.9e-64:
		tmp = y * z
	elif y <= 4.2e-23:
		tmp = x
	elif y <= 6.4e+28:
		tmp = y * z
	elif (y <= 1.15e+51) or (not (y <= 2.05e+151) and (y <= 1.1e+234)):
		tmp = y * x
	else:
		tmp = y * z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -8e+151)
		tmp = Float64(y * z);
	elseif (y <= -6.6e+128)
		tmp = Float64(y * x);
	elseif (y <= -3.3e+63)
		tmp = Float64(y * z);
	elseif (y <= -3.45e+46)
		tmp = Float64(y * x);
	elseif (y <= -1.9e-64)
		tmp = Float64(y * z);
	elseif (y <= 4.2e-23)
		tmp = x;
	elseif (y <= 6.4e+28)
		tmp = Float64(y * z);
	elseif ((y <= 1.15e+51) || (!(y <= 2.05e+151) && (y <= 1.1e+234)))
		tmp = Float64(y * x);
	else
		tmp = Float64(y * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -8e+151)
		tmp = y * z;
	elseif (y <= -6.6e+128)
		tmp = y * x;
	elseif (y <= -3.3e+63)
		tmp = y * z;
	elseif (y <= -3.45e+46)
		tmp = y * x;
	elseif (y <= -1.9e-64)
		tmp = y * z;
	elseif (y <= 4.2e-23)
		tmp = x;
	elseif (y <= 6.4e+28)
		tmp = y * z;
	elseif ((y <= 1.15e+51) || (~((y <= 2.05e+151)) && (y <= 1.1e+234)))
		tmp = y * x;
	else
		tmp = y * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -8e+151], N[(y * z), $MachinePrecision], If[LessEqual[y, -6.6e+128], N[(y * x), $MachinePrecision], If[LessEqual[y, -3.3e+63], N[(y * z), $MachinePrecision], If[LessEqual[y, -3.45e+46], N[(y * x), $MachinePrecision], If[LessEqual[y, -1.9e-64], N[(y * z), $MachinePrecision], If[LessEqual[y, 4.2e-23], x, If[LessEqual[y, 6.4e+28], N[(y * z), $MachinePrecision], If[Or[LessEqual[y, 1.15e+51], And[N[Not[LessEqual[y, 2.05e+151]], $MachinePrecision], LessEqual[y, 1.1e+234]]], N[(y * x), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{+151}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;y \leq -6.6 \cdot 10^{+128}:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;y \leq -3.3 \cdot 10^{+63}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;y \leq -3.45 \cdot 10^{+46}:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;y \leq -1.9 \cdot 10^{-64}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;y \leq 4.2 \cdot 10^{-23}:\\
\;\;\;\;x\\

\mathbf{elif}\;y \leq 6.4 \cdot 10^{+28}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;y \leq 1.15 \cdot 10^{+51} \lor \neg \left(y \leq 2.05 \cdot 10^{+151}\right) \land y \leq 1.1 \cdot 10^{+234}:\\
\;\;\;\;y \cdot x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -8.00000000000000014e151 or -6.6000000000000001e128 < y < -3.3000000000000002e63 or -3.45000000000000009e46 < y < -1.9000000000000001e-64 or 4.2000000000000002e-23 < y < 6.4000000000000001e28 or 1.15000000000000003e51 < y < 2.0499999999999999e151 or 1.10000000000000004e234 < y

    1. Initial program 100.0%

      \[x + y \cdot \left(z + x\right) \]
    2. Taylor expanded in x around -inf 97.2%

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(-1 \cdot y - 1\right)\right) + y \cdot z} \]
    3. Step-by-step derivation
      1. +-commutative97.2%

        \[\leadsto \color{blue}{y \cdot z + -1 \cdot \left(x \cdot \left(-1 \cdot y - 1\right)\right)} \]
      2. mul-1-neg97.2%

        \[\leadsto y \cdot z + \color{blue}{\left(-x \cdot \left(-1 \cdot y - 1\right)\right)} \]
      3. unsub-neg97.2%

        \[\leadsto \color{blue}{y \cdot z - x \cdot \left(-1 \cdot y - 1\right)} \]
      4. sub-neg97.2%

        \[\leadsto y \cdot z - x \cdot \color{blue}{\left(-1 \cdot y + \left(-1\right)\right)} \]
      5. metadata-eval97.2%

        \[\leadsto y \cdot z - x \cdot \left(-1 \cdot y + \color{blue}{-1}\right) \]
      6. +-commutative97.2%

        \[\leadsto y \cdot z - x \cdot \color{blue}{\left(-1 + -1 \cdot y\right)} \]
      7. mul-1-neg97.2%

        \[\leadsto y \cdot z - x \cdot \left(-1 + \color{blue}{\left(-y\right)}\right) \]
      8. unsub-neg97.2%

        \[\leadsto y \cdot z - x \cdot \color{blue}{\left(-1 - y\right)} \]
    4. Simplified97.2%

      \[\leadsto \color{blue}{y \cdot z - x \cdot \left(-1 - y\right)} \]
    5. Taylor expanded in z around inf 69.0%

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

    if -8.00000000000000014e151 < y < -6.6000000000000001e128 or -3.3000000000000002e63 < y < -3.45000000000000009e46 or 6.4000000000000001e28 < y < 1.15000000000000003e51 or 2.0499999999999999e151 < y < 1.10000000000000004e234

    1. Initial program 100.0%

      \[x + y \cdot \left(z + x\right) \]
    2. Taylor expanded in x around inf 92.9%

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

        \[\leadsto x \cdot \color{blue}{\left(y + 1\right)} \]
    4. Simplified92.9%

      \[\leadsto \color{blue}{x \cdot \left(y + 1\right)} \]
    5. Taylor expanded in y around inf 92.9%

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

    if -1.9000000000000001e-64 < y < 4.2000000000000002e-23

    1. Initial program 100.0%

      \[x + y \cdot \left(z + x\right) \]
    2. Taylor expanded in y around 0 77.9%

      \[\leadsto \color{blue}{x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification75.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -8 \cdot 10^{+151}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq -6.6 \cdot 10^{+128}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -3.3 \cdot 10^{+63}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq -3.45 \cdot 10^{+46}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -1.9 \cdot 10^{-64}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{-23}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 6.4 \cdot 10^{+28}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{+51} \lor \neg \left(y \leq 2.05 \cdot 10^{+151}\right) \land y \leq 1.1 \cdot 10^{+234}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]

Alternative 3: 73.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -6.2 \cdot 10^{-84} \lor \neg \left(x \leq 6.5 \cdot 10^{-149}\right) \land \left(x \leq 7.6 \cdot 10^{-68} \lor \neg \left(x \leq 1.18 \cdot 10^{+24}\right)\right):\\ \;\;\;\;x \cdot \left(y + 1\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -6.2e-84)
         (and (not (<= x 6.5e-149)) (or (<= x 7.6e-68) (not (<= x 1.18e+24)))))
   (* x (+ y 1.0))
   (* y z)))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -6.2e-84) || (!(x <= 6.5e-149) && ((x <= 7.6e-68) || !(x <= 1.18e+24)))) {
		tmp = x * (y + 1.0);
	} else {
		tmp = y * z;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((x <= (-6.2d-84)) .or. (.not. (x <= 6.5d-149)) .and. (x <= 7.6d-68) .or. (.not. (x <= 1.18d+24))) then
        tmp = x * (y + 1.0d0)
    else
        tmp = y * z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((x <= -6.2e-84) || (!(x <= 6.5e-149) && ((x <= 7.6e-68) || !(x <= 1.18e+24)))) {
		tmp = x * (y + 1.0);
	} else {
		tmp = y * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x <= -6.2e-84) or (not (x <= 6.5e-149) and ((x <= 7.6e-68) or not (x <= 1.18e+24))):
		tmp = x * (y + 1.0)
	else:
		tmp = y * z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((x <= -6.2e-84) || (!(x <= 6.5e-149) && ((x <= 7.6e-68) || !(x <= 1.18e+24))))
		tmp = Float64(x * Float64(y + 1.0));
	else
		tmp = Float64(y * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x <= -6.2e-84) || (~((x <= 6.5e-149)) && ((x <= 7.6e-68) || ~((x <= 1.18e+24)))))
		tmp = x * (y + 1.0);
	else
		tmp = y * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.2e-84], And[N[Not[LessEqual[x, 6.5e-149]], $MachinePrecision], Or[LessEqual[x, 7.6e-68], N[Not[LessEqual[x, 1.18e+24]], $MachinePrecision]]]], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{-84} \lor \neg \left(x \leq 6.5 \cdot 10^{-149}\right) \land \left(x \leq 7.6 \cdot 10^{-68} \lor \neg \left(x \leq 1.18 \cdot 10^{+24}\right)\right):\\
\;\;\;\;x \cdot \left(y + 1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -6.20000000000000003e-84 or 6.50000000000000019e-149 < x < 7.60000000000000075e-68 or 1.17999999999999997e24 < x

    1. Initial program 100.0%

      \[x + y \cdot \left(z + x\right) \]
    2. Taylor expanded in x around inf 86.8%

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

        \[\leadsto x \cdot \color{blue}{\left(y + 1\right)} \]
    4. Simplified86.8%

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

    if -6.20000000000000003e-84 < x < 6.50000000000000019e-149 or 7.60000000000000075e-68 < x < 1.17999999999999997e24

    1. Initial program 100.0%

      \[x + y \cdot \left(z + x\right) \]
    2. Taylor expanded in x around -inf 99.9%

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

        \[\leadsto \color{blue}{y \cdot z + -1 \cdot \left(x \cdot \left(-1 \cdot y - 1\right)\right)} \]
      2. mul-1-neg99.9%

        \[\leadsto y \cdot z + \color{blue}{\left(-x \cdot \left(-1 \cdot y - 1\right)\right)} \]
      3. unsub-neg99.9%

        \[\leadsto \color{blue}{y \cdot z - x \cdot \left(-1 \cdot y - 1\right)} \]
      4. sub-neg99.9%

        \[\leadsto y \cdot z - x \cdot \color{blue}{\left(-1 \cdot y + \left(-1\right)\right)} \]
      5. metadata-eval99.9%

        \[\leadsto y \cdot z - x \cdot \left(-1 \cdot y + \color{blue}{-1}\right) \]
      6. +-commutative99.9%

        \[\leadsto y \cdot z - x \cdot \color{blue}{\left(-1 + -1 \cdot y\right)} \]
      7. mul-1-neg99.9%

        \[\leadsto y \cdot z - x \cdot \left(-1 + \color{blue}{\left(-y\right)}\right) \]
      8. unsub-neg99.9%

        \[\leadsto y \cdot z - x \cdot \color{blue}{\left(-1 - y\right)} \]
    4. Simplified99.9%

      \[\leadsto \color{blue}{y \cdot z - x \cdot \left(-1 - y\right)} \]
    5. Taylor expanded in z around inf 75.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -6.2 \cdot 10^{-84} \lor \neg \left(x \leq 6.5 \cdot 10^{-149}\right) \land \left(x \leq 7.6 \cdot 10^{-68} \lor \neg \left(x \leq 1.18 \cdot 10^{+24}\right)\right):\\ \;\;\;\;x \cdot \left(y + 1\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]

Alternative 4: 83.3% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -2.35 \cdot 10^{-64} \lor \neg \left(y \leq 7.5 \cdot 10^{-83}\right):\\ \;\;\;\;y \cdot \left(x + z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(y + 1\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -2.35e-64) (not (<= y 7.5e-83))) (* y (+ x z)) (* x (+ y 1.0))))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -2.35e-64) || !(y <= 7.5e-83)) {
		tmp = y * (x + z);
	} else {
		tmp = x * (y + 1.0);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((y <= (-2.35d-64)) .or. (.not. (y <= 7.5d-83))) then
        tmp = y * (x + z)
    else
        tmp = x * (y + 1.0d0)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((y <= -2.35e-64) || !(y <= 7.5e-83)) {
		tmp = y * (x + z);
	} else {
		tmp = x * (y + 1.0);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -2.35e-64) or not (y <= 7.5e-83):
		tmp = y * (x + z)
	else:
		tmp = x * (y + 1.0)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -2.35e-64) || !(y <= 7.5e-83))
		tmp = Float64(y * Float64(x + z));
	else
		tmp = Float64(x * Float64(y + 1.0));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y <= -2.35e-64) || ~((y <= 7.5e-83)))
		tmp = y * (x + z);
	else
		tmp = x * (y + 1.0);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.35e-64], N[Not[LessEqual[y, 7.5e-83]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.35 \cdot 10^{-64} \lor \neg \left(y \leq 7.5 \cdot 10^{-83}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\

\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -2.3499999999999999e-64 or 7.4999999999999997e-83 < y

    1. Initial program 100.0%

      \[x + y \cdot \left(z + x\right) \]
    2. Taylor expanded in x around -inf 97.3%

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

        \[\leadsto \color{blue}{y \cdot z + -1 \cdot \left(x \cdot \left(-1 \cdot y - 1\right)\right)} \]
      2. mul-1-neg97.3%

        \[\leadsto y \cdot z + \color{blue}{\left(-x \cdot \left(-1 \cdot y - 1\right)\right)} \]
      3. unsub-neg97.3%

        \[\leadsto \color{blue}{y \cdot z - x \cdot \left(-1 \cdot y - 1\right)} \]
      4. sub-neg97.3%

        \[\leadsto y \cdot z - x \cdot \color{blue}{\left(-1 \cdot y + \left(-1\right)\right)} \]
      5. metadata-eval97.3%

        \[\leadsto y \cdot z - x \cdot \left(-1 \cdot y + \color{blue}{-1}\right) \]
      6. +-commutative97.3%

        \[\leadsto y \cdot z - x \cdot \color{blue}{\left(-1 + -1 \cdot y\right)} \]
      7. mul-1-neg97.3%

        \[\leadsto y \cdot z - x \cdot \left(-1 + \color{blue}{\left(-y\right)}\right) \]
      8. unsub-neg97.3%

        \[\leadsto y \cdot z - x \cdot \color{blue}{\left(-1 - y\right)} \]
    4. Simplified97.3%

      \[\leadsto \color{blue}{y \cdot z - x \cdot \left(-1 - y\right)} \]
    5. Taylor expanded in y around inf 88.1%

      \[\leadsto \color{blue}{y \cdot \left(z - -1 \cdot x\right)} \]
    6. Step-by-step derivation
      1. cancel-sign-sub-inv88.1%

        \[\leadsto y \cdot \color{blue}{\left(z + \left(--1\right) \cdot x\right)} \]
      2. metadata-eval88.1%

        \[\leadsto y \cdot \left(z + \color{blue}{1} \cdot x\right) \]
      3. *-lft-identity88.1%

        \[\leadsto y \cdot \left(z + \color{blue}{x}\right) \]
      4. +-commutative88.1%

        \[\leadsto y \cdot \color{blue}{\left(x + z\right)} \]
    7. Simplified88.1%

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

    if -2.3499999999999999e-64 < y < 7.4999999999999997e-83

    1. Initial program 100.0%

      \[x + y \cdot \left(z + x\right) \]
    2. Taylor expanded in x around inf 80.8%

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

        \[\leadsto x \cdot \color{blue}{\left(y + 1\right)} \]
    4. Simplified80.8%

      \[\leadsto \color{blue}{x \cdot \left(y + 1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification85.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.35 \cdot 10^{-64} \lor \neg \left(y \leq 7.5 \cdot 10^{-83}\right):\\ \;\;\;\;y \cdot \left(x + z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(y + 1\right)\\ \end{array} \]

Alternative 5: 97.9% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -2.2 \cdot 10^{+29} \lor \neg \left(y \leq 1\right):\\ \;\;\;\;y \cdot \left(x + z\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -2.2e+29) (not (<= y 1.0))) (* y (+ x z)) (+ x (* y z))))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -2.2e+29) || !(y <= 1.0)) {
		tmp = y * (x + z);
	} else {
		tmp = x + (y * z);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((y <= (-2.2d+29)) .or. (.not. (y <= 1.0d0))) then
        tmp = y * (x + z)
    else
        tmp = x + (y * z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((y <= -2.2e+29) || !(y <= 1.0)) {
		tmp = y * (x + z);
	} else {
		tmp = x + (y * z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -2.2e+29) or not (y <= 1.0):
		tmp = y * (x + z)
	else:
		tmp = x + (y * z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -2.2e+29) || !(y <= 1.0))
		tmp = Float64(y * Float64(x + z));
	else
		tmp = Float64(x + Float64(y * z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y <= -2.2e+29) || ~((y <= 1.0)))
		tmp = y * (x + z);
	else
		tmp = x + (y * z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.2e+29], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -2.2000000000000001e29 or 1 < y

    1. Initial program 100.0%

      \[x + y \cdot \left(z + x\right) \]
    2. Taylor expanded in x around -inf 96.3%

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

        \[\leadsto \color{blue}{y \cdot z + -1 \cdot \left(x \cdot \left(-1 \cdot y - 1\right)\right)} \]
      2. mul-1-neg96.3%

        \[\leadsto y \cdot z + \color{blue}{\left(-x \cdot \left(-1 \cdot y - 1\right)\right)} \]
      3. unsub-neg96.3%

        \[\leadsto \color{blue}{y \cdot z - x \cdot \left(-1 \cdot y - 1\right)} \]
      4. sub-neg96.3%

        \[\leadsto y \cdot z - x \cdot \color{blue}{\left(-1 \cdot y + \left(-1\right)\right)} \]
      5. metadata-eval96.3%

        \[\leadsto y \cdot z - x \cdot \left(-1 \cdot y + \color{blue}{-1}\right) \]
      6. +-commutative96.3%

        \[\leadsto y \cdot z - x \cdot \color{blue}{\left(-1 + -1 \cdot y\right)} \]
      7. mul-1-neg96.3%

        \[\leadsto y \cdot z - x \cdot \left(-1 + \color{blue}{\left(-y\right)}\right) \]
      8. unsub-neg96.3%

        \[\leadsto y \cdot z - x \cdot \color{blue}{\left(-1 - y\right)} \]
    4. Simplified96.3%

      \[\leadsto \color{blue}{y \cdot z - x \cdot \left(-1 - y\right)} \]
    5. Taylor expanded in y around inf 98.6%

      \[\leadsto \color{blue}{y \cdot \left(z - -1 \cdot x\right)} \]
    6. Step-by-step derivation
      1. cancel-sign-sub-inv98.6%

        \[\leadsto y \cdot \color{blue}{\left(z + \left(--1\right) \cdot x\right)} \]
      2. metadata-eval98.6%

        \[\leadsto y \cdot \left(z + \color{blue}{1} \cdot x\right) \]
      3. *-lft-identity98.6%

        \[\leadsto y \cdot \left(z + \color{blue}{x}\right) \]
      4. +-commutative98.6%

        \[\leadsto y \cdot \color{blue}{\left(x + z\right)} \]
    7. Simplified98.6%

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

    if -2.2000000000000001e29 < y < 1

    1. Initial program 100.0%

      \[x + y \cdot \left(z + x\right) \]
    2. Taylor expanded in z around inf 98.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.2 \cdot 10^{+29} \lor \neg \left(y \leq 1\right):\\ \;\;\;\;y \cdot \left(x + z\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot z\\ \end{array} \]

Alternative 6: 60.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -1.0) (* y x) (if (<= y 1.0) x (* y x))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.0) {
		tmp = y * x;
	} else if (y <= 1.0) {
		tmp = x;
	} else {
		tmp = y * x;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y <= (-1.0d0)) then
        tmp = y * x
    else if (y <= 1.0d0) then
        tmp = x
    else
        tmp = y * x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.0) {
		tmp = y * x;
	} else if (y <= 1.0) {
		tmp = x;
	} else {
		tmp = y * x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -1.0:
		tmp = y * x
	elif y <= 1.0:
		tmp = x
	else:
		tmp = y * x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -1.0)
		tmp = Float64(y * x);
	elseif (y <= 1.0)
		tmp = x;
	else
		tmp = Float64(y * x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -1.0)
		tmp = y * x;
	elseif (y <= 1.0)
		tmp = x;
	else
		tmp = y * x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -1.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.0], x, N[(y * x), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\

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


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

    1. Initial program 100.0%

      \[x + y \cdot \left(z + x\right) \]
    2. Taylor expanded in x around inf 49.6%

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

        \[\leadsto x \cdot \color{blue}{\left(y + 1\right)} \]
    4. Simplified49.6%

      \[\leadsto \color{blue}{x \cdot \left(y + 1\right)} \]
    5. Taylor expanded in y around inf 48.2%

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

    if -1 < y < 1

    1. Initial program 100.0%

      \[x + y \cdot \left(z + x\right) \]
    2. Taylor expanded in y around 0 69.7%

      \[\leadsto \color{blue}{x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification60.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]

Alternative 7: 100.0% accurate, 1.0× speedup?

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

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

    \[x + y \cdot \left(z + x\right) \]
  2. Final simplification100.0%

    \[\leadsto x + y \cdot \left(x + z\right) \]

Alternative 8: 36.1% accurate, 7.0× speedup?

\[\begin{array}{l} \\ x \end{array} \]
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
	return x;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x
end function
public static double code(double x, double y, double z) {
	return x;
}
def code(x, y, z):
	return x
function code(x, y, z)
	return x
end
function tmp = code(x, y, z)
	tmp = x;
end
code[x_, y_, z_] := x
\begin{array}{l}

\\
x
\end{array}
Derivation
  1. Initial program 100.0%

    \[x + y \cdot \left(z + x\right) \]
  2. Taylor expanded in y around 0 40.7%

    \[\leadsto \color{blue}{x} \]
  3. Final simplification40.7%

    \[\leadsto x \]

Reproduce

?
herbie shell --seed 2023271 
(FPCore (x y z)
  :name "Main:bigenough2 from A"
  :precision binary64
  (+ x (* y (+ z x))))