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

Percentage Accurate: 99.9% → 99.9%
Time: 8.0s
Alternatives: 8
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 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} \\ \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: 99.9% accurate, 1.2× speedup?

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

\\
2 \cdot \left(x + y\right) + \left(x + z\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. associate-+l+99.9%

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

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

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

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

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

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

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

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

Alternative 2: 51.4% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.95 \cdot 10^{+131}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;x \leq -1.1 \cdot 10^{-178}:\\ \;\;\;\;2 \cdot y\\ \mathbf{elif}\;x \leq 2.15 \cdot 10^{-241}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{-191}:\\ \;\;\;\;2 \cdot y\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{-129}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 2.9 \cdot 10^{-44}:\\ \;\;\;\;2 \cdot y\\ \mathbf{elif}\;x \leq 0.078:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{+26}:\\ \;\;\;\;2 \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot 3\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -1.95e+131)
   (* x 3.0)
   (if (<= x -1.1e-178)
     (* 2.0 y)
     (if (<= x 2.15e-241)
       z
       (if (<= x 3.2e-191)
         (* 2.0 y)
         (if (<= x 8.2e-129)
           z
           (if (<= x 2.9e-44)
             (* 2.0 y)
             (if (<= x 0.078) z (if (<= x 3.5e+26) (* 2.0 y) (* x 3.0))))))))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -1.95e+131) {
		tmp = x * 3.0;
	} else if (x <= -1.1e-178) {
		tmp = 2.0 * y;
	} else if (x <= 2.15e-241) {
		tmp = z;
	} else if (x <= 3.2e-191) {
		tmp = 2.0 * y;
	} else if (x <= 8.2e-129) {
		tmp = z;
	} else if (x <= 2.9e-44) {
		tmp = 2.0 * y;
	} else if (x <= 0.078) {
		tmp = z;
	} else if (x <= 3.5e+26) {
		tmp = 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.95d+131)) then
        tmp = x * 3.0d0
    else if (x <= (-1.1d-178)) then
        tmp = 2.0d0 * y
    else if (x <= 2.15d-241) then
        tmp = z
    else if (x <= 3.2d-191) then
        tmp = 2.0d0 * y
    else if (x <= 8.2d-129) then
        tmp = z
    else if (x <= 2.9d-44) then
        tmp = 2.0d0 * y
    else if (x <= 0.078d0) then
        tmp = z
    else if (x <= 3.5d+26) then
        tmp = 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.95e+131) {
		tmp = x * 3.0;
	} else if (x <= -1.1e-178) {
		tmp = 2.0 * y;
	} else if (x <= 2.15e-241) {
		tmp = z;
	} else if (x <= 3.2e-191) {
		tmp = 2.0 * y;
	} else if (x <= 8.2e-129) {
		tmp = z;
	} else if (x <= 2.9e-44) {
		tmp = 2.0 * y;
	} else if (x <= 0.078) {
		tmp = z;
	} else if (x <= 3.5e+26) {
		tmp = 2.0 * y;
	} else {
		tmp = x * 3.0;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -1.95e+131:
		tmp = x * 3.0
	elif x <= -1.1e-178:
		tmp = 2.0 * y
	elif x <= 2.15e-241:
		tmp = z
	elif x <= 3.2e-191:
		tmp = 2.0 * y
	elif x <= 8.2e-129:
		tmp = z
	elif x <= 2.9e-44:
		tmp = 2.0 * y
	elif x <= 0.078:
		tmp = z
	elif x <= 3.5e+26:
		tmp = 2.0 * y
	else:
		tmp = x * 3.0
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -1.95e+131)
		tmp = Float64(x * 3.0);
	elseif (x <= -1.1e-178)
		tmp = Float64(2.0 * y);
	elseif (x <= 2.15e-241)
		tmp = z;
	elseif (x <= 3.2e-191)
		tmp = Float64(2.0 * y);
	elseif (x <= 8.2e-129)
		tmp = z;
	elseif (x <= 2.9e-44)
		tmp = Float64(2.0 * y);
	elseif (x <= 0.078)
		tmp = z;
	elseif (x <= 3.5e+26)
		tmp = 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.95e+131)
		tmp = x * 3.0;
	elseif (x <= -1.1e-178)
		tmp = 2.0 * y;
	elseif (x <= 2.15e-241)
		tmp = z;
	elseif (x <= 3.2e-191)
		tmp = 2.0 * y;
	elseif (x <= 8.2e-129)
		tmp = z;
	elseif (x <= 2.9e-44)
		tmp = 2.0 * y;
	elseif (x <= 0.078)
		tmp = z;
	elseif (x <= 3.5e+26)
		tmp = 2.0 * y;
	else
		tmp = x * 3.0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -1.95e+131], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, -1.1e-178], N[(2.0 * y), $MachinePrecision], If[LessEqual[x, 2.15e-241], z, If[LessEqual[x, 3.2e-191], N[(2.0 * y), $MachinePrecision], If[LessEqual[x, 8.2e-129], z, If[LessEqual[x, 2.9e-44], N[(2.0 * y), $MachinePrecision], If[LessEqual[x, 0.078], z, If[LessEqual[x, 3.5e+26], N[(2.0 * y), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;x \leq 2.15 \cdot 10^{-241}:\\
\;\;\;\;z\\

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

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

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

\mathbf{elif}\;x \leq 0.078:\\
\;\;\;\;z\\

\mathbf{elif}\;x \leq 3.5 \cdot 10^{+26}:\\
\;\;\;\;2 \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.95e131 or 3.4999999999999999e26 < 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. associate-+l+99.8%

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

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

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

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

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

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

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

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

    if -1.95e131 < x < -1.1000000000000001e-178 or 2.1499999999999999e-241 < x < 3.2000000000000003e-191 or 8.1999999999999999e-129 < x < 2.9000000000000001e-44 or 0.0779999999999999999 < x < 3.4999999999999999e26

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

    if -1.1000000000000001e-178 < x < 2.1499999999999999e-241 or 3.2000000000000003e-191 < x < 8.1999999999999999e-129 or 2.9000000000000001e-44 < x < 0.0779999999999999999

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.95 \cdot 10^{+131}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;x \leq -1.1 \cdot 10^{-178}:\\ \;\;\;\;2 \cdot y\\ \mathbf{elif}\;x \leq 2.15 \cdot 10^{-241}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{-191}:\\ \;\;\;\;2 \cdot y\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{-129}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 2.9 \cdot 10^{-44}:\\ \;\;\;\;2 \cdot y\\ \mathbf{elif}\;x \leq 0.078:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{+26}:\\ \;\;\;\;2 \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot 3\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 82.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x + \left(z + 2 \cdot x\right)\\ t_1 := z - y \cdot -2\\ \mathbf{if}\;x \leq -3.9 \cdot 10^{+151}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq -3.8 \cdot 10^{+78}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \leq -3.3 \cdot 10^{-54}:\\ \;\;\;\;x + 2 \cdot \left(x + y\right)\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{+17}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ x (+ z (* 2.0 x)))) (t_1 (- z (* y -2.0))))
   (if (<= x -3.9e+151)
     t_0
     (if (<= x -3.8e+78)
       t_1
       (if (<= x -3.3e-54)
         (+ x (* 2.0 (+ x y)))
         (if (<= x 3.5e+17) t_1 t_0))))))
double code(double x, double y, double z) {
	double t_0 = x + (z + (2.0 * x));
	double t_1 = z - (y * -2.0);
	double tmp;
	if (x <= -3.9e+151) {
		tmp = t_0;
	} else if (x <= -3.8e+78) {
		tmp = t_1;
	} else if (x <= -3.3e-54) {
		tmp = x + (2.0 * (x + y));
	} else if (x <= 3.5e+17) {
		tmp = t_1;
	} 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) :: t_1
    real(8) :: tmp
    t_0 = x + (z + (2.0d0 * x))
    t_1 = z - (y * (-2.0d0))
    if (x <= (-3.9d+151)) then
        tmp = t_0
    else if (x <= (-3.8d+78)) then
        tmp = t_1
    else if (x <= (-3.3d-54)) then
        tmp = x + (2.0d0 * (x + y))
    else if (x <= 3.5d+17) then
        tmp = t_1
    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 + (2.0 * x));
	double t_1 = z - (y * -2.0);
	double tmp;
	if (x <= -3.9e+151) {
		tmp = t_0;
	} else if (x <= -3.8e+78) {
		tmp = t_1;
	} else if (x <= -3.3e-54) {
		tmp = x + (2.0 * (x + y));
	} else if (x <= 3.5e+17) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x + (z + (2.0 * x))
	t_1 = z - (y * -2.0)
	tmp = 0
	if x <= -3.9e+151:
		tmp = t_0
	elif x <= -3.8e+78:
		tmp = t_1
	elif x <= -3.3e-54:
		tmp = x + (2.0 * (x + y))
	elif x <= 3.5e+17:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(x + Float64(z + Float64(2.0 * x)))
	t_1 = Float64(z - Float64(y * -2.0))
	tmp = 0.0
	if (x <= -3.9e+151)
		tmp = t_0;
	elseif (x <= -3.8e+78)
		tmp = t_1;
	elseif (x <= -3.3e-54)
		tmp = Float64(x + Float64(2.0 * Float64(x + y)));
	elseif (x <= 3.5e+17)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x + (z + (2.0 * x));
	t_1 = z - (y * -2.0);
	tmp = 0.0;
	if (x <= -3.9e+151)
		tmp = t_0;
	elseif (x <= -3.8e+78)
		tmp = t_1;
	elseif (x <= -3.3e-54)
		tmp = x + (2.0 * (x + y));
	elseif (x <= 3.5e+17)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(z + N[(2.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(z - N[(y * -2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -3.9e+151], t$95$0, If[LessEqual[x, -3.8e+78], t$95$1, If[LessEqual[x, -3.3e-54], N[(x + N[(2.0 * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 3.5e+17], t$95$1, t$95$0]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq -3.8 \cdot 10^{+78}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x \leq -3.3 \cdot 10^{-54}:\\
\;\;\;\;x + 2 \cdot \left(x + y\right)\\

\mathbf{elif}\;x \leq 3.5 \cdot 10^{+17}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -3.89999999999999976e151 or 3.5e17 < 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. associate-+l+99.8%

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

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

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

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

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

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

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

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

    if -3.89999999999999976e151 < x < -3.7999999999999999e78 or -3.29999999999999993e-54 < x < 3.5e17

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{z + 2 \cdot y} \]
    6. Step-by-step derivation
      1. metadata-eval94.1%

        \[\leadsto z + \color{blue}{\left(--2\right)} \cdot y \]
      2. cancel-sign-sub-inv94.1%

        \[\leadsto \color{blue}{z - -2 \cdot y} \]
      3. *-commutative94.1%

        \[\leadsto z - \color{blue}{y \cdot -2} \]
    7. Simplified94.1%

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

    if -3.7999999999999999e78 < x < -3.29999999999999993e-54

    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. associate-+l+99.8%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.9 \cdot 10^{+151}:\\ \;\;\;\;x + \left(z + 2 \cdot x\right)\\ \mathbf{elif}\;x \leq -3.8 \cdot 10^{+78}:\\ \;\;\;\;z - y \cdot -2\\ \mathbf{elif}\;x \leq -3.3 \cdot 10^{-54}:\\ \;\;\;\;x + 2 \cdot \left(x + y\right)\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{+17}:\\ \;\;\;\;z - y \cdot -2\\ \mathbf{else}:\\ \;\;\;\;x + \left(z + 2 \cdot x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 82.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := z - x \cdot -3\\ t_1 := z - y \cdot -2\\ \mathbf{if}\;x \leq -4.2 \cdot 10^{+151}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq -1.6 \cdot 10^{+78}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \leq -1.85 \cdot 10^{-53}:\\ \;\;\;\;x + 2 \cdot \left(x + y\right)\\ \mathbf{elif}\;x \leq 1.95 \cdot 10^{+26}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (- z (* x -3.0))) (t_1 (- z (* y -2.0))))
   (if (<= x -4.2e+151)
     t_0
     (if (<= x -1.6e+78)
       t_1
       (if (<= x -1.85e-53)
         (+ x (* 2.0 (+ x y)))
         (if (<= x 1.95e+26) t_1 t_0))))))
double code(double x, double y, double z) {
	double t_0 = z - (x * -3.0);
	double t_1 = z - (y * -2.0);
	double tmp;
	if (x <= -4.2e+151) {
		tmp = t_0;
	} else if (x <= -1.6e+78) {
		tmp = t_1;
	} else if (x <= -1.85e-53) {
		tmp = x + (2.0 * (x + y));
	} else if (x <= 1.95e+26) {
		tmp = t_1;
	} 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) :: t_1
    real(8) :: tmp
    t_0 = z - (x * (-3.0d0))
    t_1 = z - (y * (-2.0d0))
    if (x <= (-4.2d+151)) then
        tmp = t_0
    else if (x <= (-1.6d+78)) then
        tmp = t_1
    else if (x <= (-1.85d-53)) then
        tmp = x + (2.0d0 * (x + y))
    else if (x <= 1.95d+26) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = z - (x * -3.0);
	double t_1 = z - (y * -2.0);
	double tmp;
	if (x <= -4.2e+151) {
		tmp = t_0;
	} else if (x <= -1.6e+78) {
		tmp = t_1;
	} else if (x <= -1.85e-53) {
		tmp = x + (2.0 * (x + y));
	} else if (x <= 1.95e+26) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = z - (x * -3.0)
	t_1 = z - (y * -2.0)
	tmp = 0
	if x <= -4.2e+151:
		tmp = t_0
	elif x <= -1.6e+78:
		tmp = t_1
	elif x <= -1.85e-53:
		tmp = x + (2.0 * (x + y))
	elif x <= 1.95e+26:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(z - Float64(x * -3.0))
	t_1 = Float64(z - Float64(y * -2.0))
	tmp = 0.0
	if (x <= -4.2e+151)
		tmp = t_0;
	elseif (x <= -1.6e+78)
		tmp = t_1;
	elseif (x <= -1.85e-53)
		tmp = Float64(x + Float64(2.0 * Float64(x + y)));
	elseif (x <= 1.95e+26)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = z - (x * -3.0);
	t_1 = z - (y * -2.0);
	tmp = 0.0;
	if (x <= -4.2e+151)
		tmp = t_0;
	elseif (x <= -1.6e+78)
		tmp = t_1;
	elseif (x <= -1.85e-53)
		tmp = x + (2.0 * (x + y));
	elseif (x <= 1.95e+26)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(z - N[(x * -3.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(z - N[(y * -2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -4.2e+151], t$95$0, If[LessEqual[x, -1.6e+78], t$95$1, If[LessEqual[x, -1.85e-53], N[(x + N[(2.0 * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.95e+26], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := z - x \cdot -3\\
t_1 := z - y \cdot -2\\
\mathbf{if}\;x \leq -4.2 \cdot 10^{+151}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq -1.6 \cdot 10^{+78}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x \leq -1.85 \cdot 10^{-53}:\\
\;\;\;\;x + 2 \cdot \left(x + y\right)\\

\mathbf{elif}\;x \leq 1.95 \cdot 10^{+26}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -4.2000000000000001e151 or 1.95e26 < 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}{\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. unsub-neg99.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto z - \left(\left(-1 \cdot x + \left(-\color{blue}{2 \cdot x}\right)\right) + \left(-\left(y + y\right)\right)\right) \]
      14. distribute-lft-neg-in99.8%

        \[\leadsto z - \left(\left(-1 \cdot x + \color{blue}{\left(-2\right) \cdot x}\right) + \left(-\left(y + y\right)\right)\right) \]
      15. metadata-eval99.8%

        \[\leadsto z - \left(\left(-1 \cdot x + \color{blue}{-2} \cdot x\right) + \left(-\left(y + y\right)\right)\right) \]
      16. metadata-eval99.8%

        \[\leadsto z - \left(\left(-1 \cdot x + \color{blue}{\left(-1 + -1\right)} \cdot x\right) + \left(-\left(y + y\right)\right)\right) \]
      17. distribute-rgt-out99.8%

        \[\leadsto z - \left(\color{blue}{x \cdot \left(-1 + \left(-1 + -1\right)\right)} + \left(-\left(y + y\right)\right)\right) \]
      18. distribute-neg-out99.8%

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

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

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

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

    if -4.2000000000000001e151 < x < -1.59999999999999997e78 or -1.84999999999999991e-53 < x < 1.95e26

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{z + 2 \cdot y} \]
    6. Step-by-step derivation
      1. metadata-eval94.1%

        \[\leadsto z + \color{blue}{\left(--2\right)} \cdot y \]
      2. cancel-sign-sub-inv94.1%

        \[\leadsto \color{blue}{z - -2 \cdot y} \]
      3. *-commutative94.1%

        \[\leadsto z - \color{blue}{y \cdot -2} \]
    7. Simplified94.1%

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

    if -1.59999999999999997e78 < x < -1.84999999999999991e-53

    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. associate-+l+99.8%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.2 \cdot 10^{+151}:\\ \;\;\;\;z - x \cdot -3\\ \mathbf{elif}\;x \leq -1.6 \cdot 10^{+78}:\\ \;\;\;\;z - y \cdot -2\\ \mathbf{elif}\;x \leq -1.85 \cdot 10^{-53}:\\ \;\;\;\;x + 2 \cdot \left(x + y\right)\\ \mathbf{elif}\;x \leq 1.95 \cdot 10^{+26}:\\ \;\;\;\;z - y \cdot -2\\ \mathbf{else}:\\ \;\;\;\;z - x \cdot -3\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 80.2% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{+82} \lor \neg \left(y \leq 1.45 \cdot 10^{+133}\right):\\
\;\;\;\;2 \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.80000000000000007e82 or 1.4500000000000001e133 < y

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

    if -1.80000000000000007e82 < y < 1.4500000000000001e133

    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. unsub-neg99.9%

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

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

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

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

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

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

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

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

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

        \[\leadsto z - \left(\left(-1 \cdot x + \left(-\color{blue}{2 \cdot x}\right)\right) + \left(-\left(y + y\right)\right)\right) \]
      14. distribute-lft-neg-in99.8%

        \[\leadsto z - \left(\left(-1 \cdot x + \color{blue}{\left(-2\right) \cdot x}\right) + \left(-\left(y + y\right)\right)\right) \]
      15. metadata-eval99.8%

        \[\leadsto z - \left(\left(-1 \cdot x + \color{blue}{-2} \cdot x\right) + \left(-\left(y + y\right)\right)\right) \]
      16. metadata-eval99.8%

        \[\leadsto z - \left(\left(-1 \cdot x + \color{blue}{\left(-1 + -1\right)} \cdot x\right) + \left(-\left(y + y\right)\right)\right) \]
      17. distribute-rgt-out99.8%

        \[\leadsto z - \left(\color{blue}{x \cdot \left(-1 + \left(-1 + -1\right)\right)} + \left(-\left(y + y\right)\right)\right) \]
      18. distribute-neg-out99.8%

        \[\leadsto z - \left(x \cdot \left(-1 + \left(-1 + -1\right)\right) + \color{blue}{\left(\left(-y\right) + \left(-y\right)\right)}\right) \]
      19. fma-define99.9%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.8 \cdot 10^{+82} \lor \neg \left(y \leq 1.45 \cdot 10^{+133}\right):\\ \;\;\;\;2 \cdot y\\ \mathbf{else}:\\ \;\;\;\;z - x \cdot -3\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 83.6% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.9 \cdot 10^{+151} \lor \neg \left(x \leq 5.8 \cdot 10^{+19}\right):\\
\;\;\;\;z - x \cdot -3\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -3.89999999999999976e151 or 5.8e19 < 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}{\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. unsub-neg99.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto z - \left(\left(-1 \cdot x + \left(-\color{blue}{2 \cdot x}\right)\right) + \left(-\left(y + y\right)\right)\right) \]
      14. distribute-lft-neg-in99.8%

        \[\leadsto z - \left(\left(-1 \cdot x + \color{blue}{\left(-2\right) \cdot x}\right) + \left(-\left(y + y\right)\right)\right) \]
      15. metadata-eval99.8%

        \[\leadsto z - \left(\left(-1 \cdot x + \color{blue}{-2} \cdot x\right) + \left(-\left(y + y\right)\right)\right) \]
      16. metadata-eval99.8%

        \[\leadsto z - \left(\left(-1 \cdot x + \color{blue}{\left(-1 + -1\right)} \cdot x\right) + \left(-\left(y + y\right)\right)\right) \]
      17. distribute-rgt-out99.8%

        \[\leadsto z - \left(\color{blue}{x \cdot \left(-1 + \left(-1 + -1\right)\right)} + \left(-\left(y + y\right)\right)\right) \]
      18. distribute-neg-out99.8%

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

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

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

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

    if -3.89999999999999976e151 < x < 5.8e19

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{z + 2 \cdot y} \]
    6. Step-by-step derivation
      1. metadata-eval89.5%

        \[\leadsto z + \color{blue}{\left(--2\right)} \cdot y \]
      2. cancel-sign-sub-inv89.5%

        \[\leadsto \color{blue}{z - -2 \cdot y} \]
      3. *-commutative89.5%

        \[\leadsto z - \color{blue}{y \cdot -2} \]
    7. Simplified89.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.9 \cdot 10^{+151} \lor \neg \left(x \leq 5.8 \cdot 10^{+19}\right):\\ \;\;\;\;z - x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;z - y \cdot -2\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 51.4% accurate, 0.8× speedup?

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

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

\mathbf{elif}\;z \leq 3.9 \cdot 10^{+59}:\\
\;\;\;\;2 \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.3200000000000001e167 or 3.90000000000000021e59 < 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. associate-+l+99.9%

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

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

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

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

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

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

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

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

    if -1.3200000000000001e167 < z < 3.90000000000000021e59

    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. associate-+l+99.9%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.32 \cdot 10^{+167}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 3.9 \cdot 10^{+59}:\\ \;\;\;\;2 \cdot y\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 34.3% 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. associate-+l+99.9%

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{z} \]
  6. Final simplification32.4%

    \[\leadsto z \]
  7. Add Preprocessing

Reproduce

?
herbie shell --seed 2024077 
(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))