Optimisation.CirclePacking:place from circle-packing-0.1.0.4, H

Percentage Accurate: 100.0% → 100.0%
Time: 5.5s
Alternatives: 10
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 10 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 100.0% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 0.8× speedup?

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

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

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

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

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

      \[\leadsto \color{blue}{1 \cdot \left(x + y\right)} + \left(x + y\right) \cdot \left(-z\right) \]
    4. *-un-lft-identity100.0%

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

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

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

Alternative 2: 75.3% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(-z\right)\\ t_1 := y \cdot \left(-z\right)\\ \mathbf{if}\;z \leq -1 \cdot 10^{+222}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq -3.15 \cdot 10^{+155}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;z \leq -3.6 \cdot 10^{+62}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq -200:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 4.8 \cdot 10^{+179} \lor \neg \left(z \leq 2.6 \cdot 10^{+229}\right):\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (- z))) (t_1 (* y (- z))))
   (if (<= z -1e+222)
     t_0
     (if (<= z -3.15e+155)
       t_1
       (if (<= z -3.6e+62)
         t_0
         (if (<= z -200.0)
           t_1
           (if (<= z 1.0)
             (+ x y)
             (if (or (<= z 4.8e+179) (not (<= z 2.6e+229))) t_1 t_0))))))))
double code(double x, double y, double z) {
	double t_0 = x * -z;
	double t_1 = y * -z;
	double tmp;
	if (z <= -1e+222) {
		tmp = t_0;
	} else if (z <= -3.15e+155) {
		tmp = t_1;
	} else if (z <= -3.6e+62) {
		tmp = t_0;
	} else if (z <= -200.0) {
		tmp = t_1;
	} else if (z <= 1.0) {
		tmp = x + y;
	} else if ((z <= 4.8e+179) || !(z <= 2.6e+229)) {
		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
    t_1 = y * -z
    if (z <= (-1d+222)) then
        tmp = t_0
    else if (z <= (-3.15d+155)) then
        tmp = t_1
    else if (z <= (-3.6d+62)) then
        tmp = t_0
    else if (z <= (-200.0d0)) then
        tmp = t_1
    else if (z <= 1.0d0) then
        tmp = x + y
    else if ((z <= 4.8d+179) .or. (.not. (z <= 2.6d+229))) 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;
	double t_1 = y * -z;
	double tmp;
	if (z <= -1e+222) {
		tmp = t_0;
	} else if (z <= -3.15e+155) {
		tmp = t_1;
	} else if (z <= -3.6e+62) {
		tmp = t_0;
	} else if (z <= -200.0) {
		tmp = t_1;
	} else if (z <= 1.0) {
		tmp = x + y;
	} else if ((z <= 4.8e+179) || !(z <= 2.6e+229)) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * -z
	t_1 = y * -z
	tmp = 0
	if z <= -1e+222:
		tmp = t_0
	elif z <= -3.15e+155:
		tmp = t_1
	elif z <= -3.6e+62:
		tmp = t_0
	elif z <= -200.0:
		tmp = t_1
	elif z <= 1.0:
		tmp = x + y
	elif (z <= 4.8e+179) or not (z <= 2.6e+229):
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(x * Float64(-z))
	t_1 = Float64(y * Float64(-z))
	tmp = 0.0
	if (z <= -1e+222)
		tmp = t_0;
	elseif (z <= -3.15e+155)
		tmp = t_1;
	elseif (z <= -3.6e+62)
		tmp = t_0;
	elseif (z <= -200.0)
		tmp = t_1;
	elseif (z <= 1.0)
		tmp = Float64(x + y);
	elseif ((z <= 4.8e+179) || !(z <= 2.6e+229))
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * -z;
	t_1 = y * -z;
	tmp = 0.0;
	if (z <= -1e+222)
		tmp = t_0;
	elseif (z <= -3.15e+155)
		tmp = t_1;
	elseif (z <= -3.6e+62)
		tmp = t_0;
	elseif (z <= -200.0)
		tmp = t_1;
	elseif (z <= 1.0)
		tmp = x + y;
	elseif ((z <= 4.8e+179) || ~((z <= 2.6e+229)))
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, Block[{t$95$1 = N[(y * (-z)), $MachinePrecision]}, If[LessEqual[z, -1e+222], t$95$0, If[LessEqual[z, -3.15e+155], t$95$1, If[LessEqual[z, -3.6e+62], t$95$0, If[LessEqual[z, -200.0], t$95$1, If[LessEqual[z, 1.0], N[(x + y), $MachinePrecision], If[Or[LessEqual[z, 4.8e+179], N[Not[LessEqual[z, 2.6e+229]], $MachinePrecision]], t$95$1, t$95$0]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq -3.15 \cdot 10^{+155}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;z \leq -3.6 \cdot 10^{+62}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;z \leq -200:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;z \leq 1:\\
\;\;\;\;x + y\\

\mathbf{elif}\;z \leq 4.8 \cdot 10^{+179} \lor \neg \left(z \leq 2.6 \cdot 10^{+229}\right):\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1e222 or -3.15e155 < z < -3.6e62 or 4.80000000000000025e179 < z < 2.6e229

    1. Initial program 100.0%

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

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

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

        \[\leadsto \color{blue}{1 \cdot \left(x + y\right)} + \left(x + y\right) \cdot \left(-z\right) \]
      4. *-un-lft-identity100.0%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot z\right)} \]
    7. Step-by-step derivation
      1. associate-*r*67.3%

        \[\leadsto \color{blue}{\left(-1 \cdot x\right) \cdot z} \]
      2. neg-mul-167.3%

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

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

    if -1e222 < z < -3.15e155 or -3.6e62 < z < -200 or 1 < z < 4.80000000000000025e179 or 2.6e229 < z

    1. Initial program 100.0%

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

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

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

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

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

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

        \[\leadsto x \cdot \color{blue}{\left(\left(1 - z\right) + \frac{y \cdot \left(1 - z\right)}{x}\right)} \]
      6. remove-double-neg80.3%

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

        \[\leadsto x \cdot \left(-\color{blue}{-1 \cdot \left(\left(1 - z\right) + \frac{y \cdot \left(1 - z\right)}{x}\right)}\right) \]
      8. distribute-lft-out80.3%

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

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

        \[\leadsto x \cdot \left(-\color{blue}{\left(-1 \cdot \left(1 - z\right) - \frac{y \cdot \left(1 - z\right)}{x}\right)}\right) \]
      11. *-commutative80.3%

        \[\leadsto x \cdot \left(-\left(\color{blue}{\left(1 - z\right) \cdot -1} - \frac{y \cdot \left(1 - z\right)}{x}\right)\right) \]
      12. *-commutative80.3%

        \[\leadsto x \cdot \left(-\left(\left(1 - z\right) \cdot -1 - \frac{\color{blue}{\left(1 - z\right) \cdot y}}{x}\right)\right) \]
      13. associate-/l*81.6%

        \[\leadsto x \cdot \left(-\left(\left(1 - z\right) \cdot -1 - \color{blue}{\left(1 - z\right) \cdot \frac{y}{x}}\right)\right) \]
      14. distribute-lft-out--81.6%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(z \cdot \left(1 + \frac{y}{x}\right)\right)\right)} \]
    7. Step-by-step derivation
      1. mul-1-neg78.8%

        \[\leadsto \color{blue}{-x \cdot \left(z \cdot \left(1 + \frac{y}{x}\right)\right)} \]
      2. associate-*r*88.5%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(z \cdot x\right) \cdot \left(-1 - \frac{y}{x}\right)} \]
    9. Taylor expanded in x around 0 59.2%

      \[\leadsto \color{blue}{-1 \cdot \left(y \cdot z\right)} \]
    10. Step-by-step derivation
      1. mul-1-neg59.2%

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

        \[\leadsto -\color{blue}{z \cdot y} \]
      3. distribute-rgt-neg-in59.2%

        \[\leadsto \color{blue}{z \cdot \left(-y\right)} \]
    11. Simplified59.2%

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

    if -200 < z < 1

    1. Initial program 100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1 \cdot 10^{+222}:\\ \;\;\;\;x \cdot \left(-z\right)\\ \mathbf{elif}\;z \leq -3.15 \cdot 10^{+155}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \mathbf{elif}\;z \leq -3.6 \cdot 10^{+62}:\\ \;\;\;\;x \cdot \left(-z\right)\\ \mathbf{elif}\;z \leq -200:\\ \;\;\;\;y \cdot \left(-z\right)\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 4.8 \cdot 10^{+179} \lor \neg \left(z \leq 2.6 \cdot 10^{+229}\right):\\ \;\;\;\;y \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(-z\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 75.6% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \left(1 - z\right)\\ \mathbf{if}\;1 - z \leq -10:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;1 - z \leq 10:\\ \;\;\;\;x + y\\ \mathbf{elif}\;1 - z \leq 3 \cdot 10^{+62}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;1 - z \leq 2 \cdot 10^{+155} \lor \neg \left(1 - z \leq 5 \cdot 10^{+220}\right):\\ \;\;\;\;x \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* y (- 1.0 z))))
   (if (<= (- 1.0 z) -10.0)
     t_0
     (if (<= (- 1.0 z) 10.0)
       (+ x y)
       (if (<= (- 1.0 z) 3e+62)
         t_0
         (if (or (<= (- 1.0 z) 2e+155) (not (<= (- 1.0 z) 5e+220)))
           (* x (- z))
           (* y (- z))))))))
double code(double x, double y, double z) {
	double t_0 = y * (1.0 - z);
	double tmp;
	if ((1.0 - z) <= -10.0) {
		tmp = t_0;
	} else if ((1.0 - z) <= 10.0) {
		tmp = x + y;
	} else if ((1.0 - z) <= 3e+62) {
		tmp = t_0;
	} else if (((1.0 - z) <= 2e+155) || !((1.0 - z) <= 5e+220)) {
		tmp = x * -z;
	} else {
		tmp = y * -z;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = y * (1.0d0 - z)
    if ((1.0d0 - z) <= (-10.0d0)) then
        tmp = t_0
    else if ((1.0d0 - z) <= 10.0d0) then
        tmp = x + y
    else if ((1.0d0 - z) <= 3d+62) then
        tmp = t_0
    else if (((1.0d0 - z) <= 2d+155) .or. (.not. ((1.0d0 - z) <= 5d+220))) then
        tmp = x * -z
    else
        tmp = y * -z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = y * (1.0 - z);
	double tmp;
	if ((1.0 - z) <= -10.0) {
		tmp = t_0;
	} else if ((1.0 - z) <= 10.0) {
		tmp = x + y;
	} else if ((1.0 - z) <= 3e+62) {
		tmp = t_0;
	} else if (((1.0 - z) <= 2e+155) || !((1.0 - z) <= 5e+220)) {
		tmp = x * -z;
	} else {
		tmp = y * -z;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = y * (1.0 - z)
	tmp = 0
	if (1.0 - z) <= -10.0:
		tmp = t_0
	elif (1.0 - z) <= 10.0:
		tmp = x + y
	elif (1.0 - z) <= 3e+62:
		tmp = t_0
	elif ((1.0 - z) <= 2e+155) or not ((1.0 - z) <= 5e+220):
		tmp = x * -z
	else:
		tmp = y * -z
	return tmp
function code(x, y, z)
	t_0 = Float64(y * Float64(1.0 - z))
	tmp = 0.0
	if (Float64(1.0 - z) <= -10.0)
		tmp = t_0;
	elseif (Float64(1.0 - z) <= 10.0)
		tmp = Float64(x + y);
	elseif (Float64(1.0 - z) <= 3e+62)
		tmp = t_0;
	elseif ((Float64(1.0 - z) <= 2e+155) || !(Float64(1.0 - z) <= 5e+220))
		tmp = Float64(x * Float64(-z));
	else
		tmp = Float64(y * Float64(-z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = y * (1.0 - z);
	tmp = 0.0;
	if ((1.0 - z) <= -10.0)
		tmp = t_0;
	elseif ((1.0 - z) <= 10.0)
		tmp = x + y;
	elseif ((1.0 - z) <= 3e+62)
		tmp = t_0;
	elseif (((1.0 - z) <= 2e+155) || ~(((1.0 - z) <= 5e+220)))
		tmp = x * -z;
	else
		tmp = y * -z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(1.0 - z), $MachinePrecision], -10.0], t$95$0, If[LessEqual[N[(1.0 - z), $MachinePrecision], 10.0], N[(x + y), $MachinePrecision], If[LessEqual[N[(1.0 - z), $MachinePrecision], 3e+62], t$95$0, If[Or[LessEqual[N[(1.0 - z), $MachinePrecision], 2e+155], N[Not[LessEqual[N[(1.0 - z), $MachinePrecision], 5e+220]], $MachinePrecision]], N[(x * (-z)), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;1 - z \leq 10:\\
\;\;\;\;x + y\\

\mathbf{elif}\;1 - z \leq 3 \cdot 10^{+62}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;1 - z \leq 2 \cdot 10^{+155} \lor \neg \left(1 - z \leq 5 \cdot 10^{+220}\right):\\
\;\;\;\;x \cdot \left(-z\right)\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (-.f64 #s(literal 1 binary64) z) < -10 or 10 < (-.f64 #s(literal 1 binary64) z) < 3e62

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{y \cdot \left(1 - z\right)} \]

    if -10 < (-.f64 #s(literal 1 binary64) z) < 10

    1. Initial program 100.0%

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

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

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

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

    if 3e62 < (-.f64 #s(literal 1 binary64) z) < 2.00000000000000001e155 or 5.0000000000000002e220 < (-.f64 #s(literal 1 binary64) z)

    1. Initial program 100.0%

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

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

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

        \[\leadsto \color{blue}{1 \cdot \left(x + y\right)} + \left(x + y\right) \cdot \left(-z\right) \]
      4. *-un-lft-identity100.0%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot z\right)} \]
    7. Step-by-step derivation
      1. associate-*r*65.3%

        \[\leadsto \color{blue}{\left(-1 \cdot x\right) \cdot z} \]
      2. neg-mul-165.3%

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

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

    if 2.00000000000000001e155 < (-.f64 #s(literal 1 binary64) z) < 5.0000000000000002e220

    1. Initial program 99.8%

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

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

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

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

        \[\leadsto x \cdot \color{blue}{\left(\frac{y \cdot \left(1 - z\right)}{x} + \left(1 + \left(-z\right)\right)\right)} \]
      4. sub-neg90.2%

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

        \[\leadsto x \cdot \color{blue}{\left(\left(1 - z\right) + \frac{y \cdot \left(1 - z\right)}{x}\right)} \]
      6. remove-double-neg90.2%

        \[\leadsto x \cdot \color{blue}{\left(-\left(-\left(\left(1 - z\right) + \frac{y \cdot \left(1 - z\right)}{x}\right)\right)\right)} \]
      7. mul-1-neg90.2%

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

        \[\leadsto x \cdot \left(-\color{blue}{\left(-1 \cdot \left(1 - z\right) + -1 \cdot \frac{y \cdot \left(1 - z\right)}{x}\right)}\right) \]
      9. mul-1-neg90.2%

        \[\leadsto x \cdot \left(-\left(-1 \cdot \left(1 - z\right) + \color{blue}{\left(-\frac{y \cdot \left(1 - z\right)}{x}\right)}\right)\right) \]
      10. unsub-neg90.2%

        \[\leadsto x \cdot \left(-\color{blue}{\left(-1 \cdot \left(1 - z\right) - \frac{y \cdot \left(1 - z\right)}{x}\right)}\right) \]
      11. *-commutative90.2%

        \[\leadsto x \cdot \left(-\left(\color{blue}{\left(1 - z\right) \cdot -1} - \frac{y \cdot \left(1 - z\right)}{x}\right)\right) \]
      12. *-commutative90.2%

        \[\leadsto x \cdot \left(-\left(\left(1 - z\right) \cdot -1 - \frac{\color{blue}{\left(1 - z\right) \cdot y}}{x}\right)\right) \]
      13. associate-/l*89.8%

        \[\leadsto x \cdot \left(-\left(\left(1 - z\right) \cdot -1 - \color{blue}{\left(1 - z\right) \cdot \frac{y}{x}}\right)\right) \]
      14. distribute-lft-out--89.8%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(z \cdot \left(1 + \frac{y}{x}\right)\right)\right)} \]
    7. Step-by-step derivation
      1. mul-1-neg89.8%

        \[\leadsto \color{blue}{-x \cdot \left(z \cdot \left(1 + \frac{y}{x}\right)\right)} \]
      2. associate-*r*99.7%

        \[\leadsto -\color{blue}{\left(x \cdot z\right) \cdot \left(1 + \frac{y}{x}\right)} \]
      3. distribute-rgt-neg-in99.7%

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

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

        \[\leadsto \left(z \cdot x\right) \cdot \color{blue}{\left(\left(-1\right) + \left(-\frac{y}{x}\right)\right)} \]
      6. metadata-eval99.7%

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

        \[\leadsto \left(z \cdot x\right) \cdot \color{blue}{\left(-1 - \frac{y}{x}\right)} \]
    8. Simplified99.7%

      \[\leadsto \color{blue}{\left(z \cdot x\right) \cdot \left(-1 - \frac{y}{x}\right)} \]
    9. Taylor expanded in x around 0 50.4%

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

        \[\leadsto \color{blue}{-y \cdot z} \]
      2. *-commutative50.4%

        \[\leadsto -\color{blue}{z \cdot y} \]
      3. distribute-rgt-neg-in50.4%

        \[\leadsto \color{blue}{z \cdot \left(-y\right)} \]
    11. Simplified50.4%

      \[\leadsto \color{blue}{z \cdot \left(-y\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification77.7%

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

Alternative 4: 98.0% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;1 - z \leq -10 \lor \neg \left(1 - z \leq 2\right):\\ \;\;\;\;z \cdot \left(\left(-x\right) - y\right)\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= (- 1.0 z) -10.0) (not (<= (- 1.0 z) 2.0)))
   (* z (- (- x) y))
   (+ x y)))
double code(double x, double y, double z) {
	double tmp;
	if (((1.0 - z) <= -10.0) || !((1.0 - z) <= 2.0)) {
		tmp = z * (-x - y);
	} else {
		tmp = x + y;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (((1.0d0 - z) <= (-10.0d0)) .or. (.not. ((1.0d0 - z) <= 2.0d0))) then
        tmp = z * (-x - y)
    else
        tmp = x + y
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (((1.0 - z) <= -10.0) || !((1.0 - z) <= 2.0)) {
		tmp = z * (-x - y);
	} else {
		tmp = x + y;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if ((1.0 - z) <= -10.0) or not ((1.0 - z) <= 2.0):
		tmp = z * (-x - y)
	else:
		tmp = x + y
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((Float64(1.0 - z) <= -10.0) || !(Float64(1.0 - z) <= 2.0))
		tmp = Float64(z * Float64(Float64(-x) - y));
	else
		tmp = Float64(x + y);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (((1.0 - z) <= -10.0) || ~(((1.0 - z) <= 2.0)))
		tmp = z * (-x - y);
	else
		tmp = x + y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[N[(1.0 - z), $MachinePrecision], -10.0], N[Not[LessEqual[N[(1.0 - z), $MachinePrecision], 2.0]], $MachinePrecision]], N[(z * N[((-x) - y), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 #s(literal 1 binary64) z) < -10 or 2 < (-.f64 #s(literal 1 binary64) z)

    1. Initial program 100.0%

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

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

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

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

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

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

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

    if -10 < (-.f64 #s(literal 1 binary64) z) < 2

    1. Initial program 100.0%

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

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

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

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

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

Alternative 5: 61.7% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{-62}:\\ \;\;\;\;x - x \cdot z\\ \mathbf{elif}\;x \leq -1.65 \cdot 10^{-130}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;x \leq -2.9 \cdot 10^{-148}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(1 - z\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -1e-62)
   (- x (* x z))
   (if (<= x -1.65e-130)
     (+ x y)
     (if (<= x -2.9e-148) (* x (- 1.0 z)) (* y (- 1.0 z))))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -1e-62) {
		tmp = x - (x * z);
	} else if (x <= -1.65e-130) {
		tmp = x + y;
	} else if (x <= -2.9e-148) {
		tmp = x * (1.0 - z);
	} else {
		tmp = y * (1.0 - z);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= (-1d-62)) then
        tmp = x - (x * z)
    else if (x <= (-1.65d-130)) then
        tmp = x + y
    else if (x <= (-2.9d-148)) then
        tmp = x * (1.0d0 - z)
    else
        tmp = y * (1.0d0 - z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -1e-62) {
		tmp = x - (x * z);
	} else if (x <= -1.65e-130) {
		tmp = x + y;
	} else if (x <= -2.9e-148) {
		tmp = x * (1.0 - z);
	} else {
		tmp = y * (1.0 - z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -1e-62:
		tmp = x - (x * z)
	elif x <= -1.65e-130:
		tmp = x + y
	elif x <= -2.9e-148:
		tmp = x * (1.0 - z)
	else:
		tmp = y * (1.0 - z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -1e-62)
		tmp = Float64(x - Float64(x * z));
	elseif (x <= -1.65e-130)
		tmp = Float64(x + y);
	elseif (x <= -2.9e-148)
		tmp = Float64(x * Float64(1.0 - z));
	else
		tmp = Float64(y * Float64(1.0 - z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -1e-62)
		tmp = x - (x * z);
	elseif (x <= -1.65e-130)
		tmp = x + y;
	elseif (x <= -2.9e-148)
		tmp = x * (1.0 - z);
	else
		tmp = y * (1.0 - z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -1e-62], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -1.65e-130], N[(x + y), $MachinePrecision], If[LessEqual[x, -2.9e-148], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{-62}:\\
\;\;\;\;x - x \cdot z\\

\mathbf{elif}\;x \leq -1.65 \cdot 10^{-130}:\\
\;\;\;\;x + y\\

\mathbf{elif}\;x \leq -2.9 \cdot 10^{-148}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - z\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < -1e-62

    1. Initial program 100.0%

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

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

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

        \[\leadsto \color{blue}{1 \cdot \left(x + y\right)} + \left(x + y\right) \cdot \left(-z\right) \]
      4. *-un-lft-identity100.0%

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

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

      \[\leadsto \color{blue}{x + -1 \cdot \left(x \cdot z\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg72.8%

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

        \[\leadsto \color{blue}{x - x \cdot z} \]
    7. Applied egg-rr72.8%

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

    if -1e-62 < x < -1.6499999999999999e-130

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{y + x} \]
    5. Simplified58.2%

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

    if -1.6499999999999999e-130 < x < -2.8999999999999998e-148

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\left(1 - z\right) \cdot x} \]
    5. Simplified44.9%

      \[\leadsto \color{blue}{\left(1 - z\right) \cdot x} \]

    if -2.8999999999999998e-148 < x

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{y \cdot \left(1 - z\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification65.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{-62}:\\ \;\;\;\;x - x \cdot z\\ \mathbf{elif}\;x \leq -1.65 \cdot 10^{-130}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;x \leq -2.9 \cdot 10^{-148}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(1 - z\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 61.7% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
t_0 := x \cdot \left(1 - z\right)\\
\mathbf{if}\;x \leq -5.9 \cdot 10^{-64}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;x \leq -2.9 \cdot 10^{-148}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - z\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -5.89999999999999995e-64 or -2.0000000000000002e-130 < x < -2.8999999999999998e-148

    1. Initial program 100.0%

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

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

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

      \[\leadsto \color{blue}{\left(1 - z\right) \cdot x} \]

    if -5.89999999999999995e-64 < x < -2.0000000000000002e-130

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{y + x} \]
    5. Simplified58.2%

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

    if -2.8999999999999998e-148 < x

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{y \cdot \left(1 - z\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification65.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5.9 \cdot 10^{-64}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{elif}\;x \leq -2 \cdot 10^{-130}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;x \leq -2.9 \cdot 10^{-148}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(1 - z\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 75.3% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -140 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;y \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -140.0) (not (<= z 1.0))) (* y (- z)) (+ x y)))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -140.0) || !(z <= 1.0)) {
		tmp = y * -z;
	} else {
		tmp = x + y;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((z <= (-140.0d0)) .or. (.not. (z <= 1.0d0))) then
        tmp = y * -z
    else
        tmp = x + y
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= -140.0) || !(z <= 1.0)) {
		tmp = y * -z;
	} else {
		tmp = x + y;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -140.0) or not (z <= 1.0):
		tmp = y * -z
	else:
		tmp = x + y
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -140.0) || !(z <= 1.0))
		tmp = Float64(y * Float64(-z));
	else
		tmp = Float64(x + y);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -140.0) || ~((z <= 1.0)))
		tmp = y * -z;
	else
		tmp = x + y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -140.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(y * (-z)), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

        \[\leadsto x \cdot \color{blue}{\left(\left(1 - z\right) + \frac{y \cdot \left(1 - z\right)}{x}\right)} \]
      6. remove-double-neg84.4%

        \[\leadsto x \cdot \color{blue}{\left(-\left(-\left(\left(1 - z\right) + \frac{y \cdot \left(1 - z\right)}{x}\right)\right)\right)} \]
      7. mul-1-neg84.4%

        \[\leadsto x \cdot \left(-\color{blue}{-1 \cdot \left(\left(1 - z\right) + \frac{y \cdot \left(1 - z\right)}{x}\right)}\right) \]
      8. distribute-lft-out84.4%

        \[\leadsto x \cdot \left(-\color{blue}{\left(-1 \cdot \left(1 - z\right) + -1 \cdot \frac{y \cdot \left(1 - z\right)}{x}\right)}\right) \]
      9. mul-1-neg84.4%

        \[\leadsto x \cdot \left(-\left(-1 \cdot \left(1 - z\right) + \color{blue}{\left(-\frac{y \cdot \left(1 - z\right)}{x}\right)}\right)\right) \]
      10. unsub-neg84.4%

        \[\leadsto x \cdot \left(-\color{blue}{\left(-1 \cdot \left(1 - z\right) - \frac{y \cdot \left(1 - z\right)}{x}\right)}\right) \]
      11. *-commutative84.4%

        \[\leadsto x \cdot \left(-\left(\color{blue}{\left(1 - z\right) \cdot -1} - \frac{y \cdot \left(1 - z\right)}{x}\right)\right) \]
      12. *-commutative84.4%

        \[\leadsto x \cdot \left(-\left(\left(1 - z\right) \cdot -1 - \frac{\color{blue}{\left(1 - z\right) \cdot y}}{x}\right)\right) \]
      13. associate-/l*86.6%

        \[\leadsto x \cdot \left(-\left(\left(1 - z\right) \cdot -1 - \color{blue}{\left(1 - z\right) \cdot \frac{y}{x}}\right)\right) \]
      14. distribute-lft-out--86.6%

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

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

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

        \[\leadsto \color{blue}{-x \cdot \left(z \cdot \left(1 + \frac{y}{x}\right)\right)} \]
      2. associate-*r*93.4%

        \[\leadsto -\color{blue}{\left(x \cdot z\right) \cdot \left(1 + \frac{y}{x}\right)} \]
      3. distribute-rgt-neg-in93.4%

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

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

        \[\leadsto \left(z \cdot x\right) \cdot \color{blue}{\left(\left(-1\right) + \left(-\frac{y}{x}\right)\right)} \]
      6. metadata-eval93.4%

        \[\leadsto \left(z \cdot x\right) \cdot \left(\color{blue}{-1} + \left(-\frac{y}{x}\right)\right) \]
      7. sub-neg93.4%

        \[\leadsto \left(z \cdot x\right) \cdot \color{blue}{\left(-1 - \frac{y}{x}\right)} \]
    8. Simplified93.4%

      \[\leadsto \color{blue}{\left(z \cdot x\right) \cdot \left(-1 - \frac{y}{x}\right)} \]
    9. Taylor expanded in x around 0 50.6%

      \[\leadsto \color{blue}{-1 \cdot \left(y \cdot z\right)} \]
    10. Step-by-step derivation
      1. mul-1-neg50.6%

        \[\leadsto \color{blue}{-y \cdot z} \]
      2. *-commutative50.6%

        \[\leadsto -\color{blue}{z \cdot y} \]
      3. distribute-rgt-neg-in50.6%

        \[\leadsto \color{blue}{z \cdot \left(-y\right)} \]
    11. Simplified50.6%

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

    if -140 < z < 1

    1. Initial program 100.0%

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

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

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

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

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

Alternative 8: 100.0% accurate, 1.0× speedup?

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

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

    \[\left(x + y\right) \cdot \left(1 - z\right) \]
  2. Add Preprocessing
  3. Final simplification100.0%

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

Alternative 9: 51.5% accurate, 2.3× speedup?

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

\\
x + y
\end{array}
Derivation
  1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{y + x} \]
  5. Simplified48.9%

    \[\leadsto \color{blue}{y + x} \]
  6. Final simplification48.9%

    \[\leadsto x + y \]
  7. Add Preprocessing

Alternative 10: 26.9% accurate, 7.0× speedup?

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

\\
x
\end{array}
Derivation
  1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{\left(1 - z\right) \cdot x} \]
  5. Simplified48.7%

    \[\leadsto \color{blue}{\left(1 - z\right) \cdot x} \]
  6. Taylor expanded in z around 0 21.6%

    \[\leadsto \color{blue}{x} \]
  7. Add Preprocessing

Reproduce

?
herbie shell --seed 2024086 
(FPCore (x y z)
  :name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, H"
  :precision binary64
  (* (+ x y) (- 1.0 z)))