Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, C

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

Specification

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

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

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

Alternative 1: 100.0% accurate, 0.1× speedup?

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

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

    \[x \cdot \left(y + z\right) + z \cdot 5 \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. +-commutative99.9%

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

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

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

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

Alternative 2: 60.1% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2.8 \cdot 10^{+218}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq -1.05 \cdot 10^{+179}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -1.2 \cdot 10^{+136}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq -6.6 \cdot 10^{+44}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -5:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq -1.55 \cdot 10^{-42}:\\ \;\;\;\;z \cdot 5\\ \mathbf{elif}\;x \leq -2 \cdot 10^{-64}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-97}:\\ \;\;\;\;z \cdot 5\\ \mathbf{elif}\;x \leq 6.8 \cdot 10^{+53} \lor \neg \left(x \leq 2.5 \cdot 10^{+135}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -2.8e+218)
   (* z x)
   (if (<= x -1.05e+179)
     (* x y)
     (if (<= x -1.2e+136)
       (* z x)
       (if (<= x -6.6e+44)
         (* x y)
         (if (<= x -5.0)
           (* z x)
           (if (<= x -1.55e-42)
             (* z 5.0)
             (if (<= x -2e-64)
               (* x y)
               (if (<= x 1.6e-97)
                 (* z 5.0)
                 (if (or (<= x 6.8e+53) (not (<= x 2.5e+135)))
                   (* x y)
                   (* z x)))))))))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -2.8e+218) {
		tmp = z * x;
	} else if (x <= -1.05e+179) {
		tmp = x * y;
	} else if (x <= -1.2e+136) {
		tmp = z * x;
	} else if (x <= -6.6e+44) {
		tmp = x * y;
	} else if (x <= -5.0) {
		tmp = z * x;
	} else if (x <= -1.55e-42) {
		tmp = z * 5.0;
	} else if (x <= -2e-64) {
		tmp = x * y;
	} else if (x <= 1.6e-97) {
		tmp = z * 5.0;
	} else if ((x <= 6.8e+53) || !(x <= 2.5e+135)) {
		tmp = x * y;
	} else {
		tmp = z * 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 (x <= (-2.8d+218)) then
        tmp = z * x
    else if (x <= (-1.05d+179)) then
        tmp = x * y
    else if (x <= (-1.2d+136)) then
        tmp = z * x
    else if (x <= (-6.6d+44)) then
        tmp = x * y
    else if (x <= (-5.0d0)) then
        tmp = z * x
    else if (x <= (-1.55d-42)) then
        tmp = z * 5.0d0
    else if (x <= (-2d-64)) then
        tmp = x * y
    else if (x <= 1.6d-97) then
        tmp = z * 5.0d0
    else if ((x <= 6.8d+53) .or. (.not. (x <= 2.5d+135))) then
        tmp = x * y
    else
        tmp = z * x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -2.8e+218) {
		tmp = z * x;
	} else if (x <= -1.05e+179) {
		tmp = x * y;
	} else if (x <= -1.2e+136) {
		tmp = z * x;
	} else if (x <= -6.6e+44) {
		tmp = x * y;
	} else if (x <= -5.0) {
		tmp = z * x;
	} else if (x <= -1.55e-42) {
		tmp = z * 5.0;
	} else if (x <= -2e-64) {
		tmp = x * y;
	} else if (x <= 1.6e-97) {
		tmp = z * 5.0;
	} else if ((x <= 6.8e+53) || !(x <= 2.5e+135)) {
		tmp = x * y;
	} else {
		tmp = z * x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -2.8e+218:
		tmp = z * x
	elif x <= -1.05e+179:
		tmp = x * y
	elif x <= -1.2e+136:
		tmp = z * x
	elif x <= -6.6e+44:
		tmp = x * y
	elif x <= -5.0:
		tmp = z * x
	elif x <= -1.55e-42:
		tmp = z * 5.0
	elif x <= -2e-64:
		tmp = x * y
	elif x <= 1.6e-97:
		tmp = z * 5.0
	elif (x <= 6.8e+53) or not (x <= 2.5e+135):
		tmp = x * y
	else:
		tmp = z * x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -2.8e+218)
		tmp = Float64(z * x);
	elseif (x <= -1.05e+179)
		tmp = Float64(x * y);
	elseif (x <= -1.2e+136)
		tmp = Float64(z * x);
	elseif (x <= -6.6e+44)
		tmp = Float64(x * y);
	elseif (x <= -5.0)
		tmp = Float64(z * x);
	elseif (x <= -1.55e-42)
		tmp = Float64(z * 5.0);
	elseif (x <= -2e-64)
		tmp = Float64(x * y);
	elseif (x <= 1.6e-97)
		tmp = Float64(z * 5.0);
	elseif ((x <= 6.8e+53) || !(x <= 2.5e+135))
		tmp = Float64(x * y);
	else
		tmp = Float64(z * x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -2.8e+218)
		tmp = z * x;
	elseif (x <= -1.05e+179)
		tmp = x * y;
	elseif (x <= -1.2e+136)
		tmp = z * x;
	elseif (x <= -6.6e+44)
		tmp = x * y;
	elseif (x <= -5.0)
		tmp = z * x;
	elseif (x <= -1.55e-42)
		tmp = z * 5.0;
	elseif (x <= -2e-64)
		tmp = x * y;
	elseif (x <= 1.6e-97)
		tmp = z * 5.0;
	elseif ((x <= 6.8e+53) || ~((x <= 2.5e+135)))
		tmp = x * y;
	else
		tmp = z * x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -2.8e+218], N[(z * x), $MachinePrecision], If[LessEqual[x, -1.05e+179], N[(x * y), $MachinePrecision], If[LessEqual[x, -1.2e+136], N[(z * x), $MachinePrecision], If[LessEqual[x, -6.6e+44], N[(x * y), $MachinePrecision], If[LessEqual[x, -5.0], N[(z * x), $MachinePrecision], If[LessEqual[x, -1.55e-42], N[(z * 5.0), $MachinePrecision], If[LessEqual[x, -2e-64], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.6e-97], N[(z * 5.0), $MachinePrecision], If[Or[LessEqual[x, 6.8e+53], N[Not[LessEqual[x, 2.5e+135]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(z * x), $MachinePrecision]]]]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;x \leq -1.2 \cdot 10^{+136}:\\
\;\;\;\;z \cdot x\\

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

\mathbf{elif}\;x \leq -5:\\
\;\;\;\;z \cdot x\\

\mathbf{elif}\;x \leq -1.55 \cdot 10^{-42}:\\
\;\;\;\;z \cdot 5\\

\mathbf{elif}\;x \leq -2 \cdot 10^{-64}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;x \leq 1.6 \cdot 10^{-97}:\\
\;\;\;\;z \cdot 5\\

\mathbf{elif}\;x \leq 6.8 \cdot 10^{+53} \lor \neg \left(x \leq 2.5 \cdot 10^{+135}\right):\\
\;\;\;\;x \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -2.7999999999999998e218 or -1.0499999999999999e179 < x < -1.2e136 or -6.60000000000000027e44 < x < -5 or 6.79999999999999995e53 < x < 2.50000000000000015e135

    1. Initial program 99.9%

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

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

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

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

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

    if -2.7999999999999998e218 < x < -1.0499999999999999e179 or -1.2e136 < x < -6.60000000000000027e44 or -1.5500000000000001e-42 < x < -1.99999999999999993e-64 or 1.5999999999999999e-97 < x < 6.79999999999999995e53 or 2.50000000000000015e135 < x

    1. Initial program 99.9%

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

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

    if -5 < x < -1.5500000000000001e-42 or -1.99999999999999993e-64 < x < 1.5999999999999999e-97

    1. Initial program 99.8%

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

      \[\leadsto \color{blue}{5 \cdot z} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification73.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.8 \cdot 10^{+218}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq -1.05 \cdot 10^{+179}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -1.2 \cdot 10^{+136}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq -6.6 \cdot 10^{+44}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -5:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq -1.55 \cdot 10^{-42}:\\ \;\;\;\;z \cdot 5\\ \mathbf{elif}\;x \leq -2 \cdot 10^{-64}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-97}:\\ \;\;\;\;z \cdot 5\\ \mathbf{elif}\;x \leq 6.8 \cdot 10^{+53} \lor \neg \left(x \leq 2.5 \cdot 10^{+135}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 83.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(z + y\right)\\ \mathbf{if}\;x \leq -0.112:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq -1.5 \cdot 10^{-40}:\\ \;\;\;\;z \cdot 5\\ \mathbf{elif}\;x \leq -1.4 \cdot 10^{-64}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-97}:\\ \;\;\;\;z \cdot 5\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (+ z y))))
   (if (<= x -0.112)
     t_0
     (if (<= x -1.5e-40)
       (* z 5.0)
       (if (<= x -1.4e-64) (* x y) (if (<= x 1.6e-97) (* z 5.0) t_0))))))
double code(double x, double y, double z) {
	double t_0 = x * (z + y);
	double tmp;
	if (x <= -0.112) {
		tmp = t_0;
	} else if (x <= -1.5e-40) {
		tmp = z * 5.0;
	} else if (x <= -1.4e-64) {
		tmp = x * y;
	} else if (x <= 1.6e-97) {
		tmp = z * 5.0;
	} 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 = x * (z + y)
    if (x <= (-0.112d0)) then
        tmp = t_0
    else if (x <= (-1.5d-40)) then
        tmp = z * 5.0d0
    else if (x <= (-1.4d-64)) then
        tmp = x * y
    else if (x <= 1.6d-97) then
        tmp = z * 5.0d0
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = x * (z + y);
	double tmp;
	if (x <= -0.112) {
		tmp = t_0;
	} else if (x <= -1.5e-40) {
		tmp = z * 5.0;
	} else if (x <= -1.4e-64) {
		tmp = x * y;
	} else if (x <= 1.6e-97) {
		tmp = z * 5.0;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * (z + y)
	tmp = 0
	if x <= -0.112:
		tmp = t_0
	elif x <= -1.5e-40:
		tmp = z * 5.0
	elif x <= -1.4e-64:
		tmp = x * y
	elif x <= 1.6e-97:
		tmp = z * 5.0
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(x * Float64(z + y))
	tmp = 0.0
	if (x <= -0.112)
		tmp = t_0;
	elseif (x <= -1.5e-40)
		tmp = Float64(z * 5.0);
	elseif (x <= -1.4e-64)
		tmp = Float64(x * y);
	elseif (x <= 1.6e-97)
		tmp = Float64(z * 5.0);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * (z + y);
	tmp = 0.0;
	if (x <= -0.112)
		tmp = t_0;
	elseif (x <= -1.5e-40)
		tmp = z * 5.0;
	elseif (x <= -1.4e-64)
		tmp = x * y;
	elseif (x <= 1.6e-97)
		tmp = z * 5.0;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.112], t$95$0, If[LessEqual[x, -1.5e-40], N[(z * 5.0), $MachinePrecision], If[LessEqual[x, -1.4e-64], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.6e-97], N[(z * 5.0), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq -1.5 \cdot 10^{-40}:\\
\;\;\;\;z \cdot 5\\

\mathbf{elif}\;x \leq -1.4 \cdot 10^{-64}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;x \leq 1.6 \cdot 10^{-97}:\\
\;\;\;\;z \cdot 5\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -0.112000000000000002 or 1.5999999999999999e-97 < x

    1. Initial program 99.9%

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

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

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

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

    if -0.112000000000000002 < x < -1.5000000000000001e-40 or -1.40000000000000002e-64 < x < 1.5999999999999999e-97

    1. Initial program 99.8%

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

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

    if -1.5000000000000001e-40 < x < -1.40000000000000002e-64

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.112:\\ \;\;\;\;x \cdot \left(z + y\right)\\ \mathbf{elif}\;x \leq -1.5 \cdot 10^{-40}:\\ \;\;\;\;z \cdot 5\\ \mathbf{elif}\;x \leq -1.4 \cdot 10^{-64}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-97}:\\ \;\;\;\;z \cdot 5\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(z + y\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 84.0% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(z + y\right)\\ \mathbf{if}\;x \leq -33000000000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq -4.8 \cdot 10^{-44}:\\ \;\;\;\;z \cdot \left(5 + x\right)\\ \mathbf{elif}\;x \leq -1.55 \cdot 10^{-64}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 1.42 \cdot 10^{-97}:\\ \;\;\;\;z \cdot 5\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (+ z y))))
   (if (<= x -33000000000.0)
     t_0
     (if (<= x -4.8e-44)
       (* z (+ 5.0 x))
       (if (<= x -1.55e-64) (* x y) (if (<= x 1.42e-97) (* z 5.0) t_0))))))
double code(double x, double y, double z) {
	double t_0 = x * (z + y);
	double tmp;
	if (x <= -33000000000.0) {
		tmp = t_0;
	} else if (x <= -4.8e-44) {
		tmp = z * (5.0 + x);
	} else if (x <= -1.55e-64) {
		tmp = x * y;
	} else if (x <= 1.42e-97) {
		tmp = z * 5.0;
	} 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 = x * (z + y)
    if (x <= (-33000000000.0d0)) then
        tmp = t_0
    else if (x <= (-4.8d-44)) then
        tmp = z * (5.0d0 + x)
    else if (x <= (-1.55d-64)) then
        tmp = x * y
    else if (x <= 1.42d-97) then
        tmp = z * 5.0d0
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = x * (z + y);
	double tmp;
	if (x <= -33000000000.0) {
		tmp = t_0;
	} else if (x <= -4.8e-44) {
		tmp = z * (5.0 + x);
	} else if (x <= -1.55e-64) {
		tmp = x * y;
	} else if (x <= 1.42e-97) {
		tmp = z * 5.0;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * (z + y)
	tmp = 0
	if x <= -33000000000.0:
		tmp = t_0
	elif x <= -4.8e-44:
		tmp = z * (5.0 + x)
	elif x <= -1.55e-64:
		tmp = x * y
	elif x <= 1.42e-97:
		tmp = z * 5.0
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(x * Float64(z + y))
	tmp = 0.0
	if (x <= -33000000000.0)
		tmp = t_0;
	elseif (x <= -4.8e-44)
		tmp = Float64(z * Float64(5.0 + x));
	elseif (x <= -1.55e-64)
		tmp = Float64(x * y);
	elseif (x <= 1.42e-97)
		tmp = Float64(z * 5.0);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * (z + y);
	tmp = 0.0;
	if (x <= -33000000000.0)
		tmp = t_0;
	elseif (x <= -4.8e-44)
		tmp = z * (5.0 + x);
	elseif (x <= -1.55e-64)
		tmp = x * y;
	elseif (x <= 1.42e-97)
		tmp = z * 5.0;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -33000000000.0], t$95$0, If[LessEqual[x, -4.8e-44], N[(z * N[(5.0 + x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -1.55e-64], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.42e-97], N[(z * 5.0), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq -4.8 \cdot 10^{-44}:\\
\;\;\;\;z \cdot \left(5 + x\right)\\

\mathbf{elif}\;x \leq -1.55 \cdot 10^{-64}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;x \leq 1.42 \cdot 10^{-97}:\\
\;\;\;\;z \cdot 5\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < -3.3e10 or 1.42000000000000009e-97 < x

    1. Initial program 99.9%

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

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

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

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

    if -3.3e10 < x < -4.80000000000000017e-44

    1. Initial program 99.6%

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

      \[\leadsto \color{blue}{5 \cdot z + x \cdot z} \]
    4. Step-by-step derivation
      1. distribute-rgt-in87.1%

        \[\leadsto \color{blue}{z \cdot \left(5 + x\right)} \]
    5. Simplified87.1%

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

    if -4.80000000000000017e-44 < x < -1.55000000000000012e-64

    1. Initial program 100.0%

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

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

    if -1.55000000000000012e-64 < x < 1.42000000000000009e-97

    1. Initial program 99.8%

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

      \[\leadsto \color{blue}{5 \cdot z} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification90.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -33000000000:\\ \;\;\;\;x \cdot \left(z + y\right)\\ \mathbf{elif}\;x \leq -4.8 \cdot 10^{-44}:\\ \;\;\;\;z \cdot \left(5 + x\right)\\ \mathbf{elif}\;x \leq -1.55 \cdot 10^{-64}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 1.42 \cdot 10^{-97}:\\ \;\;\;\;z \cdot 5\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(z + y\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 60.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -0.0075 \lor \neg \left(x \leq -1.7 \cdot 10^{-42} \lor \neg \left(x \leq -1.8 \cdot 10^{-64}\right) \land x \leq 1.5 \cdot 10^{-97}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot 5\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -0.0075)
         (not (or (<= x -1.7e-42) (and (not (<= x -1.8e-64)) (<= x 1.5e-97)))))
   (* x y)
   (* z 5.0)))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -0.0075) || !((x <= -1.7e-42) || (!(x <= -1.8e-64) && (x <= 1.5e-97)))) {
		tmp = x * y;
	} else {
		tmp = z * 5.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 ((x <= (-0.0075d0)) .or. (.not. (x <= (-1.7d-42)) .or. (.not. (x <= (-1.8d-64))) .and. (x <= 1.5d-97))) then
        tmp = x * y
    else
        tmp = z * 5.0d0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((x <= -0.0075) || !((x <= -1.7e-42) || (!(x <= -1.8e-64) && (x <= 1.5e-97)))) {
		tmp = x * y;
	} else {
		tmp = z * 5.0;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x <= -0.0075) or not ((x <= -1.7e-42) or (not (x <= -1.8e-64) and (x <= 1.5e-97))):
		tmp = x * y
	else:
		tmp = z * 5.0
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((x <= -0.0075) || !((x <= -1.7e-42) || (!(x <= -1.8e-64) && (x <= 1.5e-97))))
		tmp = Float64(x * y);
	else
		tmp = Float64(z * 5.0);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x <= -0.0075) || ~(((x <= -1.7e-42) || (~((x <= -1.8e-64)) && (x <= 1.5e-97)))))
		tmp = x * y;
	else
		tmp = z * 5.0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.0075], N[Not[Or[LessEqual[x, -1.7e-42], And[N[Not[LessEqual[x, -1.8e-64]], $MachinePrecision], LessEqual[x, 1.5e-97]]]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(z * 5.0), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0075 \lor \neg \left(x \leq -1.7 \cdot 10^{-42} \lor \neg \left(x \leq -1.8 \cdot 10^{-64}\right) \land x \leq 1.5 \cdot 10^{-97}\right):\\
\;\;\;\;x \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -0.0074999999999999997 or -1.70000000000000011e-42 < x < -1.7999999999999999e-64 or 1.50000000000000012e-97 < x

    1. Initial program 99.9%

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

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

    if -0.0074999999999999997 < x < -1.70000000000000011e-42 or -1.7999999999999999e-64 < x < 1.50000000000000012e-97

    1. Initial program 99.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.0075 \lor \neg \left(x \leq -1.7 \cdot 10^{-42} \lor \neg \left(x \leq -1.8 \cdot 10^{-64}\right) \land x \leq 1.5 \cdot 10^{-97}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot 5\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 93.1% accurate, 0.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 5 \cdot \frac{z}{y}\right)\\


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

    1. Initial program 99.9%

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

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

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

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

    if -5 < x < 5

    1. Initial program 99.8%

      \[x \cdot \left(y + z\right) + z \cdot 5 \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. +-commutative99.8%

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

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

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

      \[\leadsto \color{blue}{y \cdot \left(x + \left(5 \cdot \frac{z}{y} + \frac{x \cdot z}{y}\right)\right)} \]
    6. Step-by-step derivation
      1. associate-/l*91.7%

        \[\leadsto y \cdot \left(x + \left(5 \cdot \frac{z}{y} + \color{blue}{x \cdot \frac{z}{y}}\right)\right) \]
      2. distribute-rgt-out92.1%

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

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

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

      \[\leadsto y \cdot \left(x + \color{blue}{5 \cdot \frac{z}{y}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification93.8%

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

Alternative 7: 99.9% accurate, 1.0× speedup?

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

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

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

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

Alternative 8: 36.6% accurate, 3.0× speedup?

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

\\
z \cdot 5
\end{array}
Derivation
  1. Initial program 99.9%

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

    \[\leadsto \color{blue}{5 \cdot z} \]
  4. Final simplification34.9%

    \[\leadsto z \cdot 5 \]
  5. Add Preprocessing

Developer target: 97.8% accurate, 1.0× speedup?

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

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

Reproduce

?
herbie shell --seed 2024115 
(FPCore (x y z)
  :name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, C"
  :precision binary64

  :alt
  (+ (* (+ x 5.0) z) (* x y))

  (+ (* x (+ y z)) (* z 5.0)))