Main:bigenough2 from A

Percentage Accurate: 100.0% → 100.0%
Time: 4.9s
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. Add Preprocessing
  5. Final simplification100.0%

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

Alternative 2: 61.7% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -5.6 \cdot 10^{+250}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -6.8 \cdot 10^{+50}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq -700000:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -1.3 \cdot 10^{-18}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq -1.65 \cdot 10^{-65}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -3 \cdot 10^{-102}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{-53}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.3 \cdot 10^{+87} \lor \neg \left(y \leq 5 \cdot 10^{+168}\right) \land y \leq 1.08 \cdot 10^{+225}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -5.6e+250)
   (* y x)
   (if (<= y -6.8e+50)
     (* y z)
     (if (<= y -700000.0)
       (* y x)
       (if (<= y -1.3e-18)
         (* y z)
         (if (<= y -1.65e-65)
           x
           (if (<= y -3e-102)
             (* y z)
             (if (<= y 1.05e-53)
               x
               (if (or (<= y 1.3e+87)
                       (and (not (<= y 5e+168)) (<= y 1.08e+225)))
                 (* y z)
                 (* y x))))))))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -5.6e+250) {
		tmp = y * x;
	} else if (y <= -6.8e+50) {
		tmp = y * z;
	} else if (y <= -700000.0) {
		tmp = y * x;
	} else if (y <= -1.3e-18) {
		tmp = y * z;
	} else if (y <= -1.65e-65) {
		tmp = x;
	} else if (y <= -3e-102) {
		tmp = y * z;
	} else if (y <= 1.05e-53) {
		tmp = x;
	} else if ((y <= 1.3e+87) || (!(y <= 5e+168) && (y <= 1.08e+225))) {
		tmp = y * z;
	} 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 <= (-5.6d+250)) then
        tmp = y * x
    else if (y <= (-6.8d+50)) then
        tmp = y * z
    else if (y <= (-700000.0d0)) then
        tmp = y * x
    else if (y <= (-1.3d-18)) then
        tmp = y * z
    else if (y <= (-1.65d-65)) then
        tmp = x
    else if (y <= (-3d-102)) then
        tmp = y * z
    else if (y <= 1.05d-53) then
        tmp = x
    else if ((y <= 1.3d+87) .or. (.not. (y <= 5d+168)) .and. (y <= 1.08d+225)) then
        tmp = y * z
    else
        tmp = y * x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -5.6e+250) {
		tmp = y * x;
	} else if (y <= -6.8e+50) {
		tmp = y * z;
	} else if (y <= -700000.0) {
		tmp = y * x;
	} else if (y <= -1.3e-18) {
		tmp = y * z;
	} else if (y <= -1.65e-65) {
		tmp = x;
	} else if (y <= -3e-102) {
		tmp = y * z;
	} else if (y <= 1.05e-53) {
		tmp = x;
	} else if ((y <= 1.3e+87) || (!(y <= 5e+168) && (y <= 1.08e+225))) {
		tmp = y * z;
	} else {
		tmp = y * x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -5.6e+250:
		tmp = y * x
	elif y <= -6.8e+50:
		tmp = y * z
	elif y <= -700000.0:
		tmp = y * x
	elif y <= -1.3e-18:
		tmp = y * z
	elif y <= -1.65e-65:
		tmp = x
	elif y <= -3e-102:
		tmp = y * z
	elif y <= 1.05e-53:
		tmp = x
	elif (y <= 1.3e+87) or (not (y <= 5e+168) and (y <= 1.08e+225)):
		tmp = y * z
	else:
		tmp = y * x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -5.6e+250)
		tmp = Float64(y * x);
	elseif (y <= -6.8e+50)
		tmp = Float64(y * z);
	elseif (y <= -700000.0)
		tmp = Float64(y * x);
	elseif (y <= -1.3e-18)
		tmp = Float64(y * z);
	elseif (y <= -1.65e-65)
		tmp = x;
	elseif (y <= -3e-102)
		tmp = Float64(y * z);
	elseif (y <= 1.05e-53)
		tmp = x;
	elseif ((y <= 1.3e+87) || (!(y <= 5e+168) && (y <= 1.08e+225)))
		tmp = Float64(y * z);
	else
		tmp = Float64(y * x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -5.6e+250)
		tmp = y * x;
	elseif (y <= -6.8e+50)
		tmp = y * z;
	elseif (y <= -700000.0)
		tmp = y * x;
	elseif (y <= -1.3e-18)
		tmp = y * z;
	elseif (y <= -1.65e-65)
		tmp = x;
	elseif (y <= -3e-102)
		tmp = y * z;
	elseif (y <= 1.05e-53)
		tmp = x;
	elseif ((y <= 1.3e+87) || (~((y <= 5e+168)) && (y <= 1.08e+225)))
		tmp = y * z;
	else
		tmp = y * x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -5.6e+250], N[(y * x), $MachinePrecision], If[LessEqual[y, -6.8e+50], N[(y * z), $MachinePrecision], If[LessEqual[y, -700000.0], N[(y * x), $MachinePrecision], If[LessEqual[y, -1.3e-18], N[(y * z), $MachinePrecision], If[LessEqual[y, -1.65e-65], x, If[LessEqual[y, -3e-102], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.05e-53], x, If[Or[LessEqual[y, 1.3e+87], And[N[Not[LessEqual[y, 5e+168]], $MachinePrecision], LessEqual[y, 1.08e+225]]], N[(y * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq -6.8 \cdot 10^{+50}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;y \leq -700000:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;y \leq -1.3 \cdot 10^{-18}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;y \leq -1.65 \cdot 10^{-65}:\\
\;\;\;\;x\\

\mathbf{elif}\;y \leq -3 \cdot 10^{-102}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;y \leq 1.05 \cdot 10^{-53}:\\
\;\;\;\;x\\

\mathbf{elif}\;y \leq 1.3 \cdot 10^{+87} \lor \neg \left(y \leq 5 \cdot 10^{+168}\right) \land y \leq 1.08 \cdot 10^{+225}:\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -5.60000000000000019e250 or -6.7999999999999997e50 < y < -7e5 or 1.29999999999999999e87 < y < 4.99999999999999967e168 or 1.0799999999999999e225 < y

    1. Initial program 100.0%

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

      \[\leadsto x + \color{blue}{x \cdot y} \]
    4. Step-by-step derivation
      1. *-commutative80.6%

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

      \[\leadsto x + \color{blue}{y \cdot x} \]
    6. Taylor expanded in y around inf 78.5%

      \[\leadsto \color{blue}{x \cdot y} \]
    7. Step-by-step derivation
      1. *-commutative78.5%

        \[\leadsto \color{blue}{y \cdot x} \]
    8. Simplified78.5%

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

    if -5.60000000000000019e250 < y < -6.7999999999999997e50 or -7e5 < y < -1.3e-18 or -1.6500000000000001e-65 < y < -3e-102 or 1.04999999999999989e-53 < y < 1.29999999999999999e87 or 4.99999999999999967e168 < y < 1.0799999999999999e225

    1. Initial program 99.9%

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

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

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

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{y + 1}, y \cdot z\right) \]
    5. Simplified98.8%

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

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

    if -1.3e-18 < y < -1.6500000000000001e-65 or -3e-102 < y < 1.04999999999999989e-53

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5.6 \cdot 10^{+250}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -6.8 \cdot 10^{+50}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq -700000:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -1.3 \cdot 10^{-18}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq -1.65 \cdot 10^{-65}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -3 \cdot 10^{-102}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{-53}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.3 \cdot 10^{+87} \lor \neg \left(y \leq 5 \cdot 10^{+168}\right) \land y \leq 1.08 \cdot 10^{+225}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 84.7% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \left(x + z\right)\\ \mathbf{if}\;y \leq -3.5 \cdot 10^{-20}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq -3.2 \cdot 10^{-66}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -6.2 \cdot 10^{-102}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 1.35 \cdot 10^{-53}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* y (+ x z))))
   (if (<= y -3.5e-20)
     t_0
     (if (<= y -3.2e-66)
       x
       (if (<= y -6.2e-102) (* y z) (if (<= y 1.35e-53) x t_0))))))
double code(double x, double y, double z) {
	double t_0 = y * (x + z);
	double tmp;
	if (y <= -3.5e-20) {
		tmp = t_0;
	} else if (y <= -3.2e-66) {
		tmp = x;
	} else if (y <= -6.2e-102) {
		tmp = y * z;
	} else if (y <= 1.35e-53) {
		tmp = x;
	} else {
		tmp = t_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) :: t_0
    real(8) :: tmp
    t_0 = y * (x + z)
    if (y <= (-3.5d-20)) then
        tmp = t_0
    else if (y <= (-3.2d-66)) then
        tmp = x
    else if (y <= (-6.2d-102)) then
        tmp = y * z
    else if (y <= 1.35d-53) then
        tmp = x
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = y * (x + z);
	double tmp;
	if (y <= -3.5e-20) {
		tmp = t_0;
	} else if (y <= -3.2e-66) {
		tmp = x;
	} else if (y <= -6.2e-102) {
		tmp = y * z;
	} else if (y <= 1.35e-53) {
		tmp = x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = y * (x + z)
	tmp = 0
	if y <= -3.5e-20:
		tmp = t_0
	elif y <= -3.2e-66:
		tmp = x
	elif y <= -6.2e-102:
		tmp = y * z
	elif y <= 1.35e-53:
		tmp = x
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(y * Float64(x + z))
	tmp = 0.0
	if (y <= -3.5e-20)
		tmp = t_0;
	elseif (y <= -3.2e-66)
		tmp = x;
	elseif (y <= -6.2e-102)
		tmp = Float64(y * z);
	elseif (y <= 1.35e-53)
		tmp = x;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = y * (x + z);
	tmp = 0.0;
	if (y <= -3.5e-20)
		tmp = t_0;
	elseif (y <= -3.2e-66)
		tmp = x;
	elseif (y <= -6.2e-102)
		tmp = y * z;
	elseif (y <= 1.35e-53)
		tmp = x;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3.5e-20], t$95$0, If[LessEqual[y, -3.2e-66], x, If[LessEqual[y, -6.2e-102], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.35e-53], x, t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -3.5 \cdot 10^{-20}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq -3.2 \cdot 10^{-66}:\\
\;\;\;\;x\\

\mathbf{elif}\;y \leq -6.2 \cdot 10^{-102}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;y \leq 1.35 \cdot 10^{-53}:\\
\;\;\;\;x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -3.50000000000000003e-20 or 1.35e-53 < y

    1. Initial program 100.0%

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

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

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

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{y + 1}, y \cdot z\right) \]
    5. Simplified99.2%

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

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

        \[\leadsto y \cdot \color{blue}{\left(z + x\right)} \]
    8. Simplified94.5%

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

    if -3.50000000000000003e-20 < y < -3.19999999999999982e-66 or -6.20000000000000026e-102 < y < 1.35e-53

    1. Initial program 100.0%

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

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

    if -3.19999999999999982e-66 < y < -6.20000000000000026e-102

    1. Initial program 100.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.5 \cdot 10^{-20}:\\ \;\;\;\;y \cdot \left(x + z\right)\\ \mathbf{elif}\;y \leq -3.2 \cdot 10^{-66}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -6.2 \cdot 10^{-102}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 1.35 \cdot 10^{-53}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x + z\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 84.7% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \left(x + z\right)\\ \mathbf{if}\;y \leq -1.82:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq -1.8 \cdot 10^{-57}:\\ \;\;\;\;x + y \cdot x\\ \mathbf{elif}\;y \leq -5.9 \cdot 10^{-102}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{-53}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* y (+ x z))))
   (if (<= y -1.82)
     t_0
     (if (<= y -1.8e-57)
       (+ x (* y x))
       (if (<= y -5.9e-102) (* y z) (if (<= y 2.8e-53) x t_0))))))
double code(double x, double y, double z) {
	double t_0 = y * (x + z);
	double tmp;
	if (y <= -1.82) {
		tmp = t_0;
	} else if (y <= -1.8e-57) {
		tmp = x + (y * x);
	} else if (y <= -5.9e-102) {
		tmp = y * z;
	} else if (y <= 2.8e-53) {
		tmp = x;
	} else {
		tmp = t_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) :: t_0
    real(8) :: tmp
    t_0 = y * (x + z)
    if (y <= (-1.82d0)) then
        tmp = t_0
    else if (y <= (-1.8d-57)) then
        tmp = x + (y * x)
    else if (y <= (-5.9d-102)) then
        tmp = y * z
    else if (y <= 2.8d-53) then
        tmp = x
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = y * (x + z);
	double tmp;
	if (y <= -1.82) {
		tmp = t_0;
	} else if (y <= -1.8e-57) {
		tmp = x + (y * x);
	} else if (y <= -5.9e-102) {
		tmp = y * z;
	} else if (y <= 2.8e-53) {
		tmp = x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = y * (x + z)
	tmp = 0
	if y <= -1.82:
		tmp = t_0
	elif y <= -1.8e-57:
		tmp = x + (y * x)
	elif y <= -5.9e-102:
		tmp = y * z
	elif y <= 2.8e-53:
		tmp = x
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(y * Float64(x + z))
	tmp = 0.0
	if (y <= -1.82)
		tmp = t_0;
	elseif (y <= -1.8e-57)
		tmp = Float64(x + Float64(y * x));
	elseif (y <= -5.9e-102)
		tmp = Float64(y * z);
	elseif (y <= 2.8e-53)
		tmp = x;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = y * (x + z);
	tmp = 0.0;
	if (y <= -1.82)
		tmp = t_0;
	elseif (y <= -1.8e-57)
		tmp = x + (y * x);
	elseif (y <= -5.9e-102)
		tmp = y * z;
	elseif (y <= 2.8e-53)
		tmp = x;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.82], t$95$0, If[LessEqual[y, -1.8e-57], N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -5.9e-102], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.8e-53], x, t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -1.82:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq -1.8 \cdot 10^{-57}:\\
\;\;\;\;x + y \cdot x\\

\mathbf{elif}\;y \leq -5.9 \cdot 10^{-102}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;y \leq 2.8 \cdot 10^{-53}:\\
\;\;\;\;x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < -1.82000000000000006 or 2.79999999999999985e-53 < y

    1. Initial program 100.0%

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

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

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

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{y + 1}, y \cdot z\right) \]
    5. Simplified99.2%

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

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

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

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

    if -1.82000000000000006 < y < -1.8000000000000001e-57

    1. Initial program 99.9%

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

      \[\leadsto x + \color{blue}{x \cdot y} \]
    4. Step-by-step derivation
      1. *-commutative73.8%

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

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

    if -1.8000000000000001e-57 < y < -5.9000000000000003e-102

    1. Initial program 100.0%

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

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

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

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

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

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

    if -5.9000000000000003e-102 < y < 2.79999999999999985e-53

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.82:\\ \;\;\;\;y \cdot \left(x + z\right)\\ \mathbf{elif}\;y \leq -1.8 \cdot 10^{-57}:\\ \;\;\;\;x + y \cdot x\\ \mathbf{elif}\;y \leq -5.9 \cdot 10^{-102}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{-53}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x + z\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 98.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 0.019\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 -1.0) (not (<= y 0.019))) (* y (+ x z)) (+ x (* y z))))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -1.0) || !(y <= 0.019)) {
		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 <= (-1.0d0)) .or. (.not. (y <= 0.019d0))) 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 <= -1.0) || !(y <= 0.019)) {
		tmp = y * (x + z);
	} else {
		tmp = x + (y * z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -1.0) or not (y <= 0.019):
		tmp = y * (x + z)
	else:
		tmp = x + (y * z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -1.0) || !(y <= 0.019))
		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 <= -1.0) || ~((y <= 0.019)))
		tmp = y * (x + z);
	else
		tmp = x + (y * z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 0.019]], $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 -1 \lor \neg \left(y \leq 0.019\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 < -1 or 0.0189999999999999995 < y

    1. Initial program 100.0%

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

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

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

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{y + 1}, y \cdot z\right) \]
    5. Simplified99.1%

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

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

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

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

    if -1 < y < 0.0189999999999999995

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 0.019\right):\\ \;\;\;\;y \cdot \left(x + z\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 61.2% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -8200 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot x\\

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


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

    1. Initial program 100.0%

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

      \[\leadsto x + \color{blue}{x \cdot y} \]
    4. Step-by-step derivation
      1. *-commutative54.3%

        \[\leadsto x + \color{blue}{y \cdot x} \]
    5. Simplified54.3%

      \[\leadsto x + \color{blue}{y \cdot x} \]
    6. Taylor expanded in y around inf 53.2%

      \[\leadsto \color{blue}{x \cdot y} \]
    7. Step-by-step derivation
      1. *-commutative53.2%

        \[\leadsto \color{blue}{y \cdot x} \]
    8. Simplified53.2%

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

    if -8200 < y < 1

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -8200 \lor \neg \left(y \leq 1\right):\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
  5. Add Preprocessing

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. Add Preprocessing
  3. Final simplification100.0%

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

Alternative 8: 36.4% 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. Add Preprocessing
  3. Taylor expanded in y around 0 40.0%

    \[\leadsto \color{blue}{x} \]
  4. Final simplification40.0%

    \[\leadsto x \]
  5. Add Preprocessing

Reproduce

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