Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendInside from plot-0.2.3.4

Percentage Accurate: 99.9% → 100.0%
Time: 8.5s
Alternatives: 9
Speedup: 1.2×

Specification

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

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

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

Alternative 1: 100.0% accurate, 0.1× speedup?

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

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

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

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

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

      \[\leadsto z + \color{blue}{\left(-\left(-\left(\left(\left(\left(x + y\right) + y\right) + x\right) + x\right)\right)\right)} \]
    4. distribute-neg-in99.9%

      \[\leadsto z + \left(-\color{blue}{\left(\left(-\left(\left(\left(x + y\right) + y\right) + x\right)\right) + \left(-x\right)\right)}\right) \]
    5. distribute-neg-in99.9%

      \[\leadsto z + \color{blue}{\left(\left(-\left(-\left(\left(\left(x + y\right) + y\right) + x\right)\right)\right) + \left(-\left(-x\right)\right)\right)} \]
    6. remove-double-neg99.9%

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

      \[\leadsto z + \color{blue}{\left(\left(\left(\left(x + y\right) + y\right) + x\right) - \left(-x\right)\right)} \]
    8. associate-+l+99.9%

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

      \[\leadsto z + \left(\left(\color{blue}{\left(\left(y + y\right) + x\right)} + x\right) - \left(-x\right)\right) \]
    10. associate-+r+99.9%

      \[\leadsto z + \left(\color{blue}{\left(\left(y + y\right) + \left(x + x\right)\right)} - \left(-x\right)\right) \]
    11. associate--l+99.9%

      \[\leadsto z + \color{blue}{\left(\left(y + y\right) + \left(\left(x + x\right) - \left(-x\right)\right)\right)} \]
    12. count-299.9%

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

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

      \[\leadsto z + \color{blue}{\mathsf{fma}\left(y, 2, \left(x + x\right) - \left(-x\right)\right)} \]
    15. count-299.9%

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

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

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

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

    \[\leadsto \color{blue}{z + \mathsf{fma}\left(y, 2, x \cdot 3\right)} \]
  4. Step-by-step derivation
    1. add-log-exp22.0%

      \[\leadsto z + \color{blue}{\log \left(e^{\mathsf{fma}\left(y, 2, x \cdot 3\right)}\right)} \]
    2. *-un-lft-identity22.0%

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

      \[\leadsto z + \color{blue}{\left(\log 1 + \log \left(e^{\mathsf{fma}\left(y, 2, x \cdot 3\right)}\right)\right)} \]
    4. metadata-eval22.0%

      \[\leadsto z + \left(\color{blue}{0} + \log \left(e^{\mathsf{fma}\left(y, 2, x \cdot 3\right)}\right)\right) \]
    5. add-log-exp99.9%

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

      \[\leadsto z + \left(0 + \color{blue}{\left(y \cdot 2 + x \cdot 3\right)}\right) \]
    7. +-commutative99.9%

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

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

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

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

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

Alternative 2: 53.1% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -5 \cdot 10^{+20}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq -8.2 \cdot 10^{-296}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{-84}:\\ \;\;\;\;2 \cdot y\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-68}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;z \leq 1.18 \cdot 10^{+55}:\\ \;\;\;\;2 \cdot y\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -5e+20)
   z
   (if (<= z -8.2e-296)
     (* x 3.0)
     (if (<= z 2.3e-84)
       (* 2.0 y)
       (if (<= z 6e-68) (* x 3.0) (if (<= z 1.18e+55) (* 2.0 y) z))))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -5e+20) {
		tmp = z;
	} else if (z <= -8.2e-296) {
		tmp = x * 3.0;
	} else if (z <= 2.3e-84) {
		tmp = 2.0 * y;
	} else if (z <= 6e-68) {
		tmp = x * 3.0;
	} else if (z <= 1.18e+55) {
		tmp = 2.0 * y;
	} else {
		tmp = 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 (z <= (-5d+20)) then
        tmp = z
    else if (z <= (-8.2d-296)) then
        tmp = x * 3.0d0
    else if (z <= 2.3d-84) then
        tmp = 2.0d0 * y
    else if (z <= 6d-68) then
        tmp = x * 3.0d0
    else if (z <= 1.18d+55) then
        tmp = 2.0d0 * y
    else
        tmp = z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -5e+20) {
		tmp = z;
	} else if (z <= -8.2e-296) {
		tmp = x * 3.0;
	} else if (z <= 2.3e-84) {
		tmp = 2.0 * y;
	} else if (z <= 6e-68) {
		tmp = x * 3.0;
	} else if (z <= 1.18e+55) {
		tmp = 2.0 * y;
	} else {
		tmp = z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -5e+20:
		tmp = z
	elif z <= -8.2e-296:
		tmp = x * 3.0
	elif z <= 2.3e-84:
		tmp = 2.0 * y
	elif z <= 6e-68:
		tmp = x * 3.0
	elif z <= 1.18e+55:
		tmp = 2.0 * y
	else:
		tmp = z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -5e+20)
		tmp = z;
	elseif (z <= -8.2e-296)
		tmp = Float64(x * 3.0);
	elseif (z <= 2.3e-84)
		tmp = Float64(2.0 * y);
	elseif (z <= 6e-68)
		tmp = Float64(x * 3.0);
	elseif (z <= 1.18e+55)
		tmp = Float64(2.0 * y);
	else
		tmp = z;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -5e+20)
		tmp = z;
	elseif (z <= -8.2e-296)
		tmp = x * 3.0;
	elseif (z <= 2.3e-84)
		tmp = 2.0 * y;
	elseif (z <= 6e-68)
		tmp = x * 3.0;
	elseif (z <= 1.18e+55)
		tmp = 2.0 * y;
	else
		tmp = z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -5e+20], z, If[LessEqual[z, -8.2e-296], N[(x * 3.0), $MachinePrecision], If[LessEqual[z, 2.3e-84], N[(2.0 * y), $MachinePrecision], If[LessEqual[z, 6e-68], N[(x * 3.0), $MachinePrecision], If[LessEqual[z, 1.18e+55], N[(2.0 * y), $MachinePrecision], z]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -5 \cdot 10^{+20}:\\
\;\;\;\;z\\

\mathbf{elif}\;z \leq -8.2 \cdot 10^{-296}:\\
\;\;\;\;x \cdot 3\\

\mathbf{elif}\;z \leq 2.3 \cdot 10^{-84}:\\
\;\;\;\;2 \cdot y\\

\mathbf{elif}\;z \leq 6 \cdot 10^{-68}:\\
\;\;\;\;x \cdot 3\\

\mathbf{elif}\;z \leq 1.18 \cdot 10^{+55}:\\
\;\;\;\;2 \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -5e20 or 1.1799999999999999e55 < z

    1. Initial program 99.9%

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

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

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

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

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

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

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

    if -5e20 < z < -8.19999999999999988e-296 or 2.29999999999999981e-84 < z < 6e-68

    1. Initial program 99.8%

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

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

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

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

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

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

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

    if -8.19999999999999988e-296 < z < 2.29999999999999981e-84 or 6e-68 < z < 1.1799999999999999e55

    1. Initial program 99.9%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -5 \cdot 10^{+20}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq -8.2 \cdot 10^{-296}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{-84}:\\ \;\;\;\;2 \cdot y\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-68}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;z \leq 1.18 \cdot 10^{+55}:\\ \;\;\;\;2 \cdot y\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]

Alternative 3: 83.3% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := z + 2 \cdot y\\ \mathbf{if}\;y \leq -2 \cdot 10^{+62}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{+31}:\\ \;\;\;\;z + x \cdot 3\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{+171} \lor \neg \left(y \leq 9.8 \cdot 10^{+203}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{0.3333333333333333}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ z (* 2.0 y))))
   (if (<= y -2e+62)
     t_0
     (if (<= y 4.5e+31)
       (+ z (* x 3.0))
       (if (or (<= y 1.1e+171) (not (<= y 9.8e+203)))
         t_0
         (/ x 0.3333333333333333))))))
double code(double x, double y, double z) {
	double t_0 = z + (2.0 * y);
	double tmp;
	if (y <= -2e+62) {
		tmp = t_0;
	} else if (y <= 4.5e+31) {
		tmp = z + (x * 3.0);
	} else if ((y <= 1.1e+171) || !(y <= 9.8e+203)) {
		tmp = t_0;
	} else {
		tmp = x / 0.3333333333333333;
	}
	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 = z + (2.0d0 * y)
    if (y <= (-2d+62)) then
        tmp = t_0
    else if (y <= 4.5d+31) then
        tmp = z + (x * 3.0d0)
    else if ((y <= 1.1d+171) .or. (.not. (y <= 9.8d+203))) then
        tmp = t_0
    else
        tmp = x / 0.3333333333333333d0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = z + (2.0 * y);
	double tmp;
	if (y <= -2e+62) {
		tmp = t_0;
	} else if (y <= 4.5e+31) {
		tmp = z + (x * 3.0);
	} else if ((y <= 1.1e+171) || !(y <= 9.8e+203)) {
		tmp = t_0;
	} else {
		tmp = x / 0.3333333333333333;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = z + (2.0 * y)
	tmp = 0
	if y <= -2e+62:
		tmp = t_0
	elif y <= 4.5e+31:
		tmp = z + (x * 3.0)
	elif (y <= 1.1e+171) or not (y <= 9.8e+203):
		tmp = t_0
	else:
		tmp = x / 0.3333333333333333
	return tmp
function code(x, y, z)
	t_0 = Float64(z + Float64(2.0 * y))
	tmp = 0.0
	if (y <= -2e+62)
		tmp = t_0;
	elseif (y <= 4.5e+31)
		tmp = Float64(z + Float64(x * 3.0));
	elseif ((y <= 1.1e+171) || !(y <= 9.8e+203))
		tmp = t_0;
	else
		tmp = Float64(x / 0.3333333333333333);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = z + (2.0 * y);
	tmp = 0.0;
	if (y <= -2e+62)
		tmp = t_0;
	elseif (y <= 4.5e+31)
		tmp = z + (x * 3.0);
	elseif ((y <= 1.1e+171) || ~((y <= 9.8e+203)))
		tmp = t_0;
	else
		tmp = x / 0.3333333333333333;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(z + N[(2.0 * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2e+62], t$95$0, If[LessEqual[y, 4.5e+31], N[(z + N[(x * 3.0), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 1.1e+171], N[Not[LessEqual[y, 9.8e+203]], $MachinePrecision]], t$95$0, N[(x / 0.3333333333333333), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := z + 2 \cdot y\\
\mathbf{if}\;y \leq -2 \cdot 10^{+62}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 4.5 \cdot 10^{+31}:\\
\;\;\;\;z + x \cdot 3\\

\mathbf{elif}\;y \leq 1.1 \cdot 10^{+171} \lor \neg \left(y \leq 9.8 \cdot 10^{+203}\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -2.00000000000000007e62 or 4.4999999999999996e31 < y < 1.1e171 or 9.7999999999999995e203 < y

    1. Initial program 99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{x + \left(2 \cdot \left(x + y\right) + z\right)} \]
    4. Taylor expanded in x around 0 86.6%

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

    if -2.00000000000000007e62 < y < 4.4999999999999996e31

    1. Initial program 99.8%

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

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

        \[\leadsto \color{blue}{z + \left(\left(\left(\left(x + y\right) + y\right) + x\right) + x\right)} \]
      3. remove-double-neg99.8%

        \[\leadsto z + \color{blue}{\left(-\left(-\left(\left(\left(\left(x + y\right) + y\right) + x\right) + x\right)\right)\right)} \]
      4. distribute-neg-in99.8%

        \[\leadsto z + \left(-\color{blue}{\left(\left(-\left(\left(\left(x + y\right) + y\right) + x\right)\right) + \left(-x\right)\right)}\right) \]
      5. distribute-neg-in99.8%

        \[\leadsto z + \color{blue}{\left(\left(-\left(-\left(\left(\left(x + y\right) + y\right) + x\right)\right)\right) + \left(-\left(-x\right)\right)\right)} \]
      6. remove-double-neg99.8%

        \[\leadsto z + \left(\color{blue}{\left(\left(\left(x + y\right) + y\right) + x\right)} + \left(-\left(-x\right)\right)\right) \]
      7. sub-neg99.8%

        \[\leadsto z + \color{blue}{\left(\left(\left(\left(x + y\right) + y\right) + x\right) - \left(-x\right)\right)} \]
      8. associate-+l+99.8%

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

        \[\leadsto z + \left(\left(\color{blue}{\left(\left(y + y\right) + x\right)} + x\right) - \left(-x\right)\right) \]
      10. associate-+r+99.8%

        \[\leadsto z + \left(\color{blue}{\left(\left(y + y\right) + \left(x + x\right)\right)} - \left(-x\right)\right) \]
      11. associate--l+99.9%

        \[\leadsto z + \color{blue}{\left(\left(y + y\right) + \left(\left(x + x\right) - \left(-x\right)\right)\right)} \]
      12. count-299.9%

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

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

        \[\leadsto z + \color{blue}{\mathsf{fma}\left(y, 2, \left(x + x\right) - \left(-x\right)\right)} \]
      15. count-299.9%

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

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

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

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

      \[\leadsto \color{blue}{z + \mathsf{fma}\left(y, 2, x \cdot 3\right)} \]
    4. Taylor expanded in y around 0 91.1%

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

    if 1.1e171 < y < 9.7999999999999995e203

    1. Initial program 99.7%

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

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

        \[\leadsto \color{blue}{z + \left(\left(\left(\left(x + y\right) + y\right) + x\right) + x\right)} \]
      3. remove-double-neg99.7%

        \[\leadsto z + \color{blue}{\left(-\left(-\left(\left(\left(\left(x + y\right) + y\right) + x\right) + x\right)\right)\right)} \]
      4. distribute-neg-in99.7%

        \[\leadsto z + \left(-\color{blue}{\left(\left(-\left(\left(\left(x + y\right) + y\right) + x\right)\right) + \left(-x\right)\right)}\right) \]
      5. distribute-neg-in99.7%

        \[\leadsto z + \color{blue}{\left(\left(-\left(-\left(\left(\left(x + y\right) + y\right) + x\right)\right)\right) + \left(-\left(-x\right)\right)\right)} \]
      6. remove-double-neg99.7%

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

        \[\leadsto z + \color{blue}{\left(\left(\left(\left(x + y\right) + y\right) + x\right) - \left(-x\right)\right)} \]
      8. associate-+l+99.7%

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

        \[\leadsto z + \left(\left(\color{blue}{\left(\left(y + y\right) + x\right)} + x\right) - \left(-x\right)\right) \]
      10. associate-+r+99.7%

        \[\leadsto z + \left(\color{blue}{\left(\left(y + y\right) + \left(x + x\right)\right)} - \left(-x\right)\right) \]
      11. associate--l+99.7%

        \[\leadsto z + \color{blue}{\left(\left(y + y\right) + \left(\left(x + x\right) - \left(-x\right)\right)\right)} \]
      12. count-299.7%

        \[\leadsto z + \left(\color{blue}{2 \cdot y} + \left(\left(x + x\right) - \left(-x\right)\right)\right) \]
      13. *-commutative99.7%

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

        \[\leadsto z + \color{blue}{\mathsf{fma}\left(y, 2, \left(x + x\right) - \left(-x\right)\right)} \]
      15. count-299.7%

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

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

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

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

      \[\leadsto \color{blue}{z + \mathsf{fma}\left(y, 2, x \cdot 3\right)} \]
    4. Taylor expanded in y around 0 99.7%

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

        \[\leadsto \color{blue}{\frac{\left(3 \cdot x\right) \cdot \left(3 \cdot x\right) - z \cdot z}{3 \cdot x - z}} \]
      2. div-sub5.8%

        \[\leadsto \color{blue}{\frac{\left(3 \cdot x\right) \cdot \left(3 \cdot x\right)}{3 \cdot x - z} - \frac{z \cdot z}{3 \cdot x - z}} \]
      3. swap-sqr5.8%

        \[\leadsto \frac{\color{blue}{\left(3 \cdot 3\right) \cdot \left(x \cdot x\right)}}{3 \cdot x - z} - \frac{z \cdot z}{3 \cdot x - z} \]
      4. metadata-eval5.8%

        \[\leadsto \frac{\color{blue}{9} \cdot \left(x \cdot x\right)}{3 \cdot x - z} - \frac{z \cdot z}{3 \cdot x - z} \]
    6. Applied egg-rr5.8%

      \[\leadsto \color{blue}{\frac{9 \cdot \left(x \cdot x\right)}{3 \cdot x - z} - \frac{z \cdot z}{3 \cdot x - z}} \]
    7. Step-by-step derivation
      1. div-sub5.8%

        \[\leadsto \color{blue}{\frac{9 \cdot \left(x \cdot x\right) - z \cdot z}{3 \cdot x - z}} \]
      2. *-commutative5.8%

        \[\leadsto \frac{\color{blue}{\left(x \cdot x\right) \cdot 9} - z \cdot z}{3 \cdot x - z} \]
      3. associate-*l*5.8%

        \[\leadsto \frac{\color{blue}{x \cdot \left(x \cdot 9\right)} - z \cdot z}{3 \cdot x - z} \]
    8. Simplified5.8%

      \[\leadsto \color{blue}{\frac{x \cdot \left(x \cdot 9\right) - z \cdot z}{3 \cdot x - z}} \]
    9. Taylor expanded in x around inf 99.7%

      \[\leadsto \color{blue}{3 \cdot x} \]
    10. Step-by-step derivation
      1. *-commutative99.7%

        \[\leadsto \color{blue}{x \cdot 3} \]
      2. /-rgt-identity99.7%

        \[\leadsto \color{blue}{\frac{x \cdot 3}{1}} \]
      3. associate-/l*100.0%

        \[\leadsto \color{blue}{\frac{x}{\frac{1}{3}}} \]
      4. metadata-eval100.0%

        \[\leadsto \frac{x}{\color{blue}{0.3333333333333333}} \]
    11. Simplified100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{+62}:\\ \;\;\;\;z + 2 \cdot y\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{+31}:\\ \;\;\;\;z + x \cdot 3\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{+171} \lor \neg \left(y \leq 9.8 \cdot 10^{+203}\right):\\ \;\;\;\;z + 2 \cdot y\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{0.3333333333333333}\\ \end{array} \]

Alternative 4: 85.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.2 \cdot 10^{+63}:\\ \;\;\;\;z + 2 \cdot y\\ \mathbf{elif}\;y \leq 1.6 \cdot 10^{+21}:\\ \;\;\;\;z + x \cdot 3\\ \mathbf{else}:\\ \;\;\;\;x + 2 \cdot \left(x + y\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -1.2e+63)
   (+ z (* 2.0 y))
   (if (<= y 1.6e+21) (+ z (* x 3.0)) (+ x (* 2.0 (+ x y))))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.2e+63) {
		tmp = z + (2.0 * y);
	} else if (y <= 1.6e+21) {
		tmp = z + (x * 3.0);
	} else {
		tmp = x + (2.0 * (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 <= (-1.2d+63)) then
        tmp = z + (2.0d0 * y)
    else if (y <= 1.6d+21) then
        tmp = z + (x * 3.0d0)
    else
        tmp = x + (2.0d0 * (x + y))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.2e+63) {
		tmp = z + (2.0 * y);
	} else if (y <= 1.6e+21) {
		tmp = z + (x * 3.0);
	} else {
		tmp = x + (2.0 * (x + y));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -1.2e+63:
		tmp = z + (2.0 * y)
	elif y <= 1.6e+21:
		tmp = z + (x * 3.0)
	else:
		tmp = x + (2.0 * (x + y))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -1.2e+63)
		tmp = Float64(z + Float64(2.0 * y));
	elseif (y <= 1.6e+21)
		tmp = Float64(z + Float64(x * 3.0));
	else
		tmp = Float64(x + Float64(2.0 * Float64(x + y)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -1.2e+63)
		tmp = z + (2.0 * y);
	elseif (y <= 1.6e+21)
		tmp = z + (x * 3.0);
	else
		tmp = x + (2.0 * (x + y));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -1.2e+63], N[(z + N[(2.0 * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.6e+21], N[(z + N[(x * 3.0), $MachinePrecision]), $MachinePrecision], N[(x + N[(2.0 * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.2 \cdot 10^{+63}:\\
\;\;\;\;z + 2 \cdot y\\

\mathbf{elif}\;y \leq 1.6 \cdot 10^{+21}:\\
\;\;\;\;z + x \cdot 3\\

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


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

    1. Initial program 99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{x + \left(2 \cdot \left(x + y\right) + z\right)} \]
    4. Taylor expanded in x around 0 85.2%

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

    if -1.2e63 < y < 1.6e21

    1. Initial program 99.8%

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

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

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

        \[\leadsto z + \color{blue}{\left(-\left(-\left(\left(\left(\left(x + y\right) + y\right) + x\right) + x\right)\right)\right)} \]
      4. distribute-neg-in99.9%

        \[\leadsto z + \left(-\color{blue}{\left(\left(-\left(\left(\left(x + y\right) + y\right) + x\right)\right) + \left(-x\right)\right)}\right) \]
      5. distribute-neg-in99.9%

        \[\leadsto z + \color{blue}{\left(\left(-\left(-\left(\left(\left(x + y\right) + y\right) + x\right)\right)\right) + \left(-\left(-x\right)\right)\right)} \]
      6. remove-double-neg99.9%

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

        \[\leadsto z + \color{blue}{\left(\left(\left(\left(x + y\right) + y\right) + x\right) - \left(-x\right)\right)} \]
      8. associate-+l+99.9%

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

        \[\leadsto z + \left(\left(\color{blue}{\left(\left(y + y\right) + x\right)} + x\right) - \left(-x\right)\right) \]
      10. associate-+r+99.9%

        \[\leadsto z + \left(\color{blue}{\left(\left(y + y\right) + \left(x + x\right)\right)} - \left(-x\right)\right) \]
      11. associate--l+99.9%

        \[\leadsto z + \color{blue}{\left(\left(y + y\right) + \left(\left(x + x\right) - \left(-x\right)\right)\right)} \]
      12. count-299.9%

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

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

        \[\leadsto z + \color{blue}{\mathsf{fma}\left(y, 2, \left(x + x\right) - \left(-x\right)\right)} \]
      15. count-299.9%

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

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

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

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

      \[\leadsto \color{blue}{z + \mathsf{fma}\left(y, 2, x \cdot 3\right)} \]
    4. Taylor expanded in y around 0 91.0%

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

    if 1.6e21 < y

    1. Initial program 99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{x + \left(2 \cdot \left(x + y\right) + z\right)} \]
    4. Taylor expanded in z around 0 92.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.2 \cdot 10^{+63}:\\ \;\;\;\;z + 2 \cdot y\\ \mathbf{elif}\;y \leq 1.6 \cdot 10^{+21}:\\ \;\;\;\;z + x \cdot 3\\ \mathbf{else}:\\ \;\;\;\;x + 2 \cdot \left(x + y\right)\\ \end{array} \]

Alternative 5: 80.7% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.8 \cdot 10^{+153}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{+106}:\\ \;\;\;\;z + 2 \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot 3\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -1.8e+153)
   (* x 3.0)
   (if (<= x 3.2e+106) (+ z (* 2.0 y)) (* x 3.0))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -1.8e+153) {
		tmp = x * 3.0;
	} else if (x <= 3.2e+106) {
		tmp = z + (2.0 * y);
	} else {
		tmp = x * 3.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 <= (-1.8d+153)) then
        tmp = x * 3.0d0
    else if (x <= 3.2d+106) then
        tmp = z + (2.0d0 * y)
    else
        tmp = x * 3.0d0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -1.8e+153) {
		tmp = x * 3.0;
	} else if (x <= 3.2e+106) {
		tmp = z + (2.0 * y);
	} else {
		tmp = x * 3.0;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -1.8e+153:
		tmp = x * 3.0
	elif x <= 3.2e+106:
		tmp = z + (2.0 * y)
	else:
		tmp = x * 3.0
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -1.8e+153)
		tmp = Float64(x * 3.0);
	elseif (x <= 3.2e+106)
		tmp = Float64(z + Float64(2.0 * y));
	else
		tmp = Float64(x * 3.0);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -1.8e+153)
		tmp = x * 3.0;
	elseif (x <= 3.2e+106)
		tmp = z + (2.0 * y);
	else
		tmp = x * 3.0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -1.8e+153], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, 3.2e+106], N[(z + N[(2.0 * y), $MachinePrecision]), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{+153}:\\
\;\;\;\;x \cdot 3\\

\mathbf{elif}\;x \leq 3.2 \cdot 10^{+106}:\\
\;\;\;\;z + 2 \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.8e153 or 3.1999999999999998e106 < x

    1. Initial program 99.8%

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

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

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

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

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

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

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

    if -1.8e153 < x < 3.1999999999999998e106

    1. Initial program 99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{x + \left(2 \cdot \left(x + y\right) + z\right)} \]
    4. Taylor expanded in x around 0 81.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.8 \cdot 10^{+153}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{+106}:\\ \;\;\;\;z + 2 \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot 3\\ \end{array} \]

Alternative 6: 99.9% accurate, 1.2× speedup?

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

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

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

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

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

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

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

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

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

Alternative 7: 99.9% accurate, 1.2× speedup?

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{x + \left(2 \cdot \left(x + y\right) + z\right)} \]
  4. Taylor expanded in x around 0 99.9%

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

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

Alternative 8: 52.2% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.7 \cdot 10^{+36}:\\
\;\;\;\;2 \cdot y\\

\mathbf{elif}\;y \leq 2.2 \cdot 10^{+21}:\\
\;\;\;\;z\\

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


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

    1. Initial program 99.9%

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

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

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

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

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

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

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

    if -3.70000000000000029e36 < y < 2.2e21

    1. Initial program 99.8%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.7 \cdot 10^{+36}:\\ \;\;\;\;2 \cdot y\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{+21}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;2 \cdot y\\ \end{array} \]

Alternative 9: 34.7% accurate, 11.0× speedup?

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{z} \]
  5. Final simplification35.9%

    \[\leadsto z \]

Reproduce

?
herbie shell --seed 2023279 
(FPCore (x y z)
  :name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendInside from plot-0.2.3.4"
  :precision binary64
  (+ (+ (+ (+ (+ x y) y) x) z) x))