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

Percentage Accurate: 99.9% → 100.0%
Time: 5.2s
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.5%

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

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

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

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

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

Alternative 2: 98.8% accurate, 0.1× speedup?

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

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

    \[x \cdot \left(y + z\right) + z \cdot 5 \]
  2. Step-by-step derivation
    1. distribute-lft-in98.7%

      \[\leadsto \color{blue}{\left(x \cdot y + x \cdot z\right)} + z \cdot 5 \]
    2. associate-+l+98.7%

      \[\leadsto \color{blue}{x \cdot y + \left(x \cdot z + z \cdot 5\right)} \]
    3. *-commutative98.7%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, z \cdot x + z \cdot 5\right)} \]
    5. distribute-lft-out99.5%

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

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

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

Alternative 3: 61.2% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -3.1 \cdot 10^{+148}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -8.2 \cdot 10^{+99}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq -4.6 \cdot 10^{-8}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 3 \cdot 10^{-67}:\\ \;\;\;\;z \cdot 5\\ \mathbf{elif}\;x \leq 1600000000000:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 6.6 \cdot 10^{+169}:\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -3.1e+148)
   (* x y)
   (if (<= x -8.2e+99)
     (* z x)
     (if (<= x -4.6e-8)
       (* x y)
       (if (<= x 3e-67)
         (* z 5.0)
         (if (<= x 1600000000000.0)
           (* x y)
           (if (<= x 6.6e+169) (* z x) (* x y))))))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -3.1e+148) {
		tmp = x * y;
	} else if (x <= -8.2e+99) {
		tmp = z * x;
	} else if (x <= -4.6e-8) {
		tmp = x * y;
	} else if (x <= 3e-67) {
		tmp = z * 5.0;
	} else if (x <= 1600000000000.0) {
		tmp = x * y;
	} else if (x <= 6.6e+169) {
		tmp = z * x;
	} else {
		tmp = x * 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 <= (-3.1d+148)) then
        tmp = x * y
    else if (x <= (-8.2d+99)) then
        tmp = z * x
    else if (x <= (-4.6d-8)) then
        tmp = x * y
    else if (x <= 3d-67) then
        tmp = z * 5.0d0
    else if (x <= 1600000000000.0d0) then
        tmp = x * y
    else if (x <= 6.6d+169) then
        tmp = z * x
    else
        tmp = x * y
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -3.1e+148) {
		tmp = x * y;
	} else if (x <= -8.2e+99) {
		tmp = z * x;
	} else if (x <= -4.6e-8) {
		tmp = x * y;
	} else if (x <= 3e-67) {
		tmp = z * 5.0;
	} else if (x <= 1600000000000.0) {
		tmp = x * y;
	} else if (x <= 6.6e+169) {
		tmp = z * x;
	} else {
		tmp = x * y;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -3.1e+148:
		tmp = x * y
	elif x <= -8.2e+99:
		tmp = z * x
	elif x <= -4.6e-8:
		tmp = x * y
	elif x <= 3e-67:
		tmp = z * 5.0
	elif x <= 1600000000000.0:
		tmp = x * y
	elif x <= 6.6e+169:
		tmp = z * x
	else:
		tmp = x * y
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -3.1e+148)
		tmp = Float64(x * y);
	elseif (x <= -8.2e+99)
		tmp = Float64(z * x);
	elseif (x <= -4.6e-8)
		tmp = Float64(x * y);
	elseif (x <= 3e-67)
		tmp = Float64(z * 5.0);
	elseif (x <= 1600000000000.0)
		tmp = Float64(x * y);
	elseif (x <= 6.6e+169)
		tmp = Float64(z * x);
	else
		tmp = Float64(x * y);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -3.1e+148)
		tmp = x * y;
	elseif (x <= -8.2e+99)
		tmp = z * x;
	elseif (x <= -4.6e-8)
		tmp = x * y;
	elseif (x <= 3e-67)
		tmp = z * 5.0;
	elseif (x <= 1600000000000.0)
		tmp = x * y;
	elseif (x <= 6.6e+169)
		tmp = z * x;
	else
		tmp = x * y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -3.1e+148], N[(x * y), $MachinePrecision], If[LessEqual[x, -8.2e+99], N[(z * x), $MachinePrecision], If[LessEqual[x, -4.6e-8], N[(x * y), $MachinePrecision], If[LessEqual[x, 3e-67], N[(z * 5.0), $MachinePrecision], If[LessEqual[x, 1600000000000.0], N[(x * y), $MachinePrecision], If[LessEqual[x, 6.6e+169], N[(z * x), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq -8.2 \cdot 10^{+99}:\\
\;\;\;\;z \cdot x\\

\mathbf{elif}\;x \leq -4.6 \cdot 10^{-8}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;x \leq 3 \cdot 10^{-67}:\\
\;\;\;\;z \cdot 5\\

\mathbf{elif}\;x \leq 1600000000000:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;x \leq 6.6 \cdot 10^{+169}:\\
\;\;\;\;z \cdot x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -3.09999999999999975e148 or -8.19999999999999959e99 < x < -4.6000000000000002e-8 or 3.00000000000000032e-67 < x < 1.6e12 or 6.5999999999999994e169 < x

    1. Initial program 98.8%

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

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

    if -3.09999999999999975e148 < x < -8.19999999999999959e99 or 1.6e12 < x < 6.5999999999999994e169

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{z \cdot x + 5 \cdot z} \]
    3. Step-by-step derivation
      1. +-commutative68.5%

        \[\leadsto \color{blue}{5 \cdot z + z \cdot x} \]
      2. *-commutative68.5%

        \[\leadsto 5 \cdot z + \color{blue}{x \cdot z} \]
      3. distribute-rgt-in68.6%

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

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

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

    if -4.6000000000000002e-8 < x < 3.00000000000000032e-67

    1. Initial program 99.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.1 \cdot 10^{+148}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -8.2 \cdot 10^{+99}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq -4.6 \cdot 10^{-8}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 3 \cdot 10^{-67}:\\ \;\;\;\;z \cdot 5\\ \mathbf{elif}\;x \leq 1600000000000:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 6.6 \cdot 10^{+169}:\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]

Alternative 4: 72.9% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;y \leq 3.9 \cdot 10^{+115} \lor \neg \left(y \leq 5 \cdot 10^{+189}\right) \land y \leq 5.7 \cdot 10^{+226}:\\
\;\;\;\;z \cdot \left(5 + x\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.1e6 or 3.90000000000000006e115 < y < 5.0000000000000004e189 or 5.69999999999999948e226 < y

    1. Initial program 100.0%

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

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

    if -1.1e6 < y < 3.90000000000000006e115 or 5.0000000000000004e189 < y < 5.69999999999999948e226

    1. Initial program 99.2%

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

      \[\leadsto \color{blue}{z \cdot x + 5 \cdot z} \]
    3. Step-by-step derivation
      1. +-commutative82.0%

        \[\leadsto \color{blue}{5 \cdot z + z \cdot x} \]
      2. *-commutative82.0%

        \[\leadsto 5 \cdot z + \color{blue}{x \cdot z} \]
      3. distribute-rgt-in82.7%

        \[\leadsto \color{blue}{z \cdot \left(5 + x\right)} \]
    4. Simplified82.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1100000:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 3.9 \cdot 10^{+115} \lor \neg \left(y \leq 5 \cdot 10^{+189}\right) \land y \leq 5.7 \cdot 10^{+226}:\\ \;\;\;\;z \cdot \left(5 + x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]

Alternative 5: 84.0% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -28 or 1.75000000000000002e-65 < x

    1. Initial program 99.2%

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

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

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

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

    if -28 < x < 1.75000000000000002e-65

    1. Initial program 99.9%

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

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

        \[\leadsto \color{blue}{5 \cdot z + z \cdot x} \]
      2. *-commutative76.4%

        \[\leadsto 5 \cdot z + \color{blue}{x \cdot z} \]
      3. distribute-rgt-in76.4%

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

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

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

Alternative 6: 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.5%

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

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

Alternative 7: 60.9% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -4.6 \cdot 10^{-8}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{-66}:\\ \;\;\;\;z \cdot 5\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -4.6e-8) (* x y) (if (<= x 7.2e-66) (* z 5.0) (* x y))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -4.6e-8) {
		tmp = x * y;
	} else if (x <= 7.2e-66) {
		tmp = z * 5.0;
	} else {
		tmp = x * 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 <= (-4.6d-8)) then
        tmp = x * y
    else if (x <= 7.2d-66) then
        tmp = z * 5.0d0
    else
        tmp = x * y
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -4.6e-8) {
		tmp = x * y;
	} else if (x <= 7.2e-66) {
		tmp = z * 5.0;
	} else {
		tmp = x * y;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -4.6e-8:
		tmp = x * y
	elif x <= 7.2e-66:
		tmp = z * 5.0
	else:
		tmp = x * y
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -4.6e-8)
		tmp = Float64(x * y);
	elseif (x <= 7.2e-66)
		tmp = Float64(z * 5.0);
	else
		tmp = Float64(x * y);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -4.6e-8)
		tmp = x * y;
	elseif (x <= 7.2e-66)
		tmp = z * 5.0;
	else
		tmp = x * y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -4.6e-8], N[(x * y), $MachinePrecision], If[LessEqual[x, 7.2e-66], N[(z * 5.0), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.6 \cdot 10^{-8}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;x \leq 7.2 \cdot 10^{-66}:\\
\;\;\;\;z \cdot 5\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -4.6000000000000002e-8 or 7.20000000000000025e-66 < x

    1. Initial program 99.2%

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

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

    if -4.6000000000000002e-8 < x < 7.20000000000000025e-66

    1. Initial program 99.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.6 \cdot 10^{-8}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{-66}:\\ \;\;\;\;z \cdot 5\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]

Alternative 8: 36.5% 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.5%

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

    \[\leadsto \color{blue}{5 \cdot z} \]
  3. Final simplification39.0%

    \[\leadsto z \cdot 5 \]

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 2023229 
(FPCore (x y z)
  :name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, C"
  :precision binary64

  :herbie-target
  (+ (* (+ x 5.0) z) (* x y))

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