Main:bigenough2 from A

Percentage Accurate: 100.0% → 100.0%
Time: 3.9s
Alternatives: 7
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 7 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.0% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -2.8 \cdot 10^{+128}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -3.3 \cdot 10^{-7}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq -5 \cdot 10^{-103}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -3.1 \cdot 10^{-121}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 2.3 \cdot 10^{-145}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{-128}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{-20}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.4 \cdot 10^{+81} \lor \neg \left(y \leq 3.2 \cdot 10^{+126}\right) \land y \leq 1.2 \cdot 10^{+156}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -2.8e+128)
   (* y x)
   (if (<= y -3.3e-7)
     (* y z)
     (if (<= y -5e-103)
       x
       (if (<= y -3.1e-121)
         (* y z)
         (if (<= y 2.3e-145)
           x
           (if (<= y 4.3e-128)
             (* y z)
             (if (<= y 1.8e-20)
               x
               (if (or (<= y 3.4e+81)
                       (and (not (<= y 3.2e+126)) (<= y 1.2e+156)))
                 (* y z)
                 (* y x))))))))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -2.8e+128) {
		tmp = y * x;
	} else if (y <= -3.3e-7) {
		tmp = y * z;
	} else if (y <= -5e-103) {
		tmp = x;
	} else if (y <= -3.1e-121) {
		tmp = y * z;
	} else if (y <= 2.3e-145) {
		tmp = x;
	} else if (y <= 4.3e-128) {
		tmp = y * z;
	} else if (y <= 1.8e-20) {
		tmp = x;
	} else if ((y <= 3.4e+81) || (!(y <= 3.2e+126) && (y <= 1.2e+156))) {
		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 <= (-2.8d+128)) then
        tmp = y * x
    else if (y <= (-3.3d-7)) then
        tmp = y * z
    else if (y <= (-5d-103)) then
        tmp = x
    else if (y <= (-3.1d-121)) then
        tmp = y * z
    else if (y <= 2.3d-145) then
        tmp = x
    else if (y <= 4.3d-128) then
        tmp = y * z
    else if (y <= 1.8d-20) then
        tmp = x
    else if ((y <= 3.4d+81) .or. (.not. (y <= 3.2d+126)) .and. (y <= 1.2d+156)) 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 <= -2.8e+128) {
		tmp = y * x;
	} else if (y <= -3.3e-7) {
		tmp = y * z;
	} else if (y <= -5e-103) {
		tmp = x;
	} else if (y <= -3.1e-121) {
		tmp = y * z;
	} else if (y <= 2.3e-145) {
		tmp = x;
	} else if (y <= 4.3e-128) {
		tmp = y * z;
	} else if (y <= 1.8e-20) {
		tmp = x;
	} else if ((y <= 3.4e+81) || (!(y <= 3.2e+126) && (y <= 1.2e+156))) {
		tmp = y * z;
	} else {
		tmp = y * x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -2.8e+128:
		tmp = y * x
	elif y <= -3.3e-7:
		tmp = y * z
	elif y <= -5e-103:
		tmp = x
	elif y <= -3.1e-121:
		tmp = y * z
	elif y <= 2.3e-145:
		tmp = x
	elif y <= 4.3e-128:
		tmp = y * z
	elif y <= 1.8e-20:
		tmp = x
	elif (y <= 3.4e+81) or (not (y <= 3.2e+126) and (y <= 1.2e+156)):
		tmp = y * z
	else:
		tmp = y * x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -2.8e+128)
		tmp = Float64(y * x);
	elseif (y <= -3.3e-7)
		tmp = Float64(y * z);
	elseif (y <= -5e-103)
		tmp = x;
	elseif (y <= -3.1e-121)
		tmp = Float64(y * z);
	elseif (y <= 2.3e-145)
		tmp = x;
	elseif (y <= 4.3e-128)
		tmp = Float64(y * z);
	elseif (y <= 1.8e-20)
		tmp = x;
	elseif ((y <= 3.4e+81) || (!(y <= 3.2e+126) && (y <= 1.2e+156)))
		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 <= -2.8e+128)
		tmp = y * x;
	elseif (y <= -3.3e-7)
		tmp = y * z;
	elseif (y <= -5e-103)
		tmp = x;
	elseif (y <= -3.1e-121)
		tmp = y * z;
	elseif (y <= 2.3e-145)
		tmp = x;
	elseif (y <= 4.3e-128)
		tmp = y * z;
	elseif (y <= 1.8e-20)
		tmp = x;
	elseif ((y <= 3.4e+81) || (~((y <= 3.2e+126)) && (y <= 1.2e+156)))
		tmp = y * z;
	else
		tmp = y * x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -2.8e+128], N[(y * x), $MachinePrecision], If[LessEqual[y, -3.3e-7], N[(y * z), $MachinePrecision], If[LessEqual[y, -5e-103], x, If[LessEqual[y, -3.1e-121], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.3e-145], x, If[LessEqual[y, 4.3e-128], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.8e-20], x, If[Or[LessEqual[y, 3.4e+81], And[N[Not[LessEqual[y, 3.2e+126]], $MachinePrecision], LessEqual[y, 1.2e+156]]], N[(y * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;y \leq -5 \cdot 10^{-103}:\\
\;\;\;\;x\\

\mathbf{elif}\;y \leq -3.1 \cdot 10^{-121}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;y \leq 2.3 \cdot 10^{-145}:\\
\;\;\;\;x\\

\mathbf{elif}\;y \leq 4.3 \cdot 10^{-128}:\\
\;\;\;\;y \cdot z\\

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

\mathbf{elif}\;y \leq 3.4 \cdot 10^{+81} \lor \neg \left(y \leq 3.2 \cdot 10^{+126}\right) \land y \leq 1.2 \cdot 10^{+156}:\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -2.79999999999999983e128 or 3.40000000000000003e81 < y < 3.1999999999999998e126 or 1.2000000000000001e156 < y

    1. Initial program 100.0%

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

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

        \[\leadsto x + \color{blue}{y \cdot x} \]
    5. Simplified67.7%

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

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

    if -2.79999999999999983e128 < y < -3.3000000000000002e-7 or -4.99999999999999966e-103 < y < -3.0999999999999998e-121 or 2.30000000000000007e-145 < y < 4.29999999999999994e-128 or 1.79999999999999987e-20 < y < 3.40000000000000003e81 or 3.1999999999999998e126 < y < 1.2000000000000001e156

    1. Initial program 100.0%

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

      \[\leadsto x + \color{blue}{y \cdot z} \]
    4. Taylor expanded in x around 0 75.5%

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

    if -3.3000000000000002e-7 < y < -4.99999999999999966e-103 or -3.0999999999999998e-121 < y < 2.30000000000000007e-145 or 4.29999999999999994e-128 < y < 1.79999999999999987e-20

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.8 \cdot 10^{+128}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -3.3 \cdot 10^{-7}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq -5 \cdot 10^{-103}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -3.1 \cdot 10^{-121}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 2.3 \cdot 10^{-145}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{-128}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{-20}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.4 \cdot 10^{+81} \lor \neg \left(y \leq 3.2 \cdot 10^{+126}\right) \land y \leq 1.2 \cdot 10^{+156}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 76.6% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{-63} \lor \neg \left(x \leq 8 \cdot 10^{-70}\right):\\
\;\;\;\;x + y \cdot x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -7.20000000000000016e-63 or 7.99999999999999997e-70 < x

    1. Initial program 100.0%

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

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

        \[\leadsto x + \color{blue}{y \cdot x} \]
    5. Simplified86.1%

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

    if -7.20000000000000016e-63 < x < 7.99999999999999997e-70

    1. Initial program 100.0%

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

      \[\leadsto x + \color{blue}{y \cdot z} \]
    4. Taylor expanded in x around 0 77.6%

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

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

Alternative 4: 86.7% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.6 \cdot 10^{-45} \lor \neg \left(z \leq 1.2 \cdot 10^{-37}\right):\\
\;\;\;\;x + y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -2.59999999999999987e-45 or 1.19999999999999995e-37 < z

    1. Initial program 100.0%

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

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

    if -2.59999999999999987e-45 < z < 1.19999999999999995e-37

    1. Initial program 100.0%

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

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

        \[\leadsto x + \color{blue}{y \cdot x} \]
    5. Simplified92.0%

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

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

Alternative 5: 61.9% accurate, 0.5× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

        \[\leadsto x + \color{blue}{y \cdot x} \]
    5. Simplified56.1%

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

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

    if -1 < y < 5

    1. Initial program 100.0%

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

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

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

Alternative 6: 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 7: 37.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. Add Preprocessing
  3. Taylor expanded in y around 0 36.1%

    \[\leadsto \color{blue}{x} \]
  4. Final simplification36.1%

    \[\leadsto x \]
  5. Add Preprocessing

Reproduce

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