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

Percentage Accurate: 100.0% → 100.0%
Time: 6.0s
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. Step-by-step derivation
    1. distribute-rgt-neg-out100.0%

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

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

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

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

Alternative 2: 74.7% accurate, 0.3× speedup?

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

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

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

\mathbf{elif}\;z \leq 3.85 \cdot 10^{+80}:\\
\;\;\;\;y \cdot \left(1 - z\right)\\

\mathbf{elif}\;z \leq 1.15 \cdot 10^{+179}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if z < -1.3500000000000001 or 3.84999999999999998e80 < z < 1.14999999999999997e179

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-x \cdot z} \]
      2. distribute-lft-neg-out53.3%

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

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

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

    if -1.3500000000000001 < z < 9.99999999999999955e-7

    1. Initial program 100.0%

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

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

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

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

    if 9.99999999999999955e-7 < z < 3.84999999999999998e80

    1. Initial program 100.0%

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

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

    if 1.14999999999999997e179 < z

    1. Initial program 99.9%

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

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

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

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

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

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

      \[\leadsto \color{blue}{y + -1 \cdot \left(y \cdot z\right)} \]
    6. Step-by-step derivation
      1. associate-*r*67.1%

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

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

      \[\leadsto \color{blue}{y + \left(-y\right) \cdot z} \]
    8. Taylor expanded in z around inf 67.1%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.35:\\ \;\;\;\;x \cdot \left(-z\right)\\ \mathbf{elif}\;z \leq 10^{-6}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 3.85 \cdot 10^{+80}:\\ \;\;\;\;y \cdot \left(1 - z\right)\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{+179}:\\ \;\;\;\;x \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 97.9% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;1 - z \leq -400 \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) -400.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) <= -400.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) <= (-400.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) <= -400.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) <= -400.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) <= -400.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) <= -400.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], -400.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 -400 \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) < -400 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 94.7%

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

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

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

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

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

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

    if -400 < (-.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 97.5%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;1 - z \leq -400 \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 4: 74.6% accurate, 0.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.3500000000000001 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 51.7%

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

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

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

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

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

        \[\leadsto z \cdot \left(\frac{x}{z} + \color{blue}{\left(-x\right)}\right) \]
      3. unsub-neg51.7%

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

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

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

        \[\leadsto \color{blue}{-x \cdot z} \]
      2. distribute-lft-neg-out49.1%

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

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

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

    if -1.3500000000000001 < 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 97.5%

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

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

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

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

Alternative 5: 74.1% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.35:\\
\;\;\;\;x \cdot \left(-z\right)\\

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-x \cdot z} \]
      2. distribute-lft-neg-out49.6%

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

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

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

    if -1.3500000000000001 < 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 97.5%

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

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

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

    if 1 < 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 x around 0 55.6%

      \[\leadsto \color{blue}{y + -1 \cdot \left(y \cdot z\right)} \]
    6. Step-by-step derivation
      1. associate-*r*55.6%

        \[\leadsto y + \color{blue}{\left(-1 \cdot y\right) \cdot z} \]
      2. mul-1-neg55.6%

        \[\leadsto y + \color{blue}{\left(-y\right)} \cdot z \]
    7. Simplified55.6%

      \[\leadsto \color{blue}{y + \left(-y\right) \cdot z} \]
    8. Taylor expanded in z around inf 54.1%

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

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

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

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

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

Alternative 6: 62.9% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -4.7 \cdot 10^{-57}:\\ \;\;\;\;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 -4.7e-57) (* x (- 1.0 z)) (* y (- 1.0 z))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -4.7e-57) {
		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 <= (-4.7d-57)) 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 <= -4.7e-57) {
		tmp = x * (1.0 - z);
	} else {
		tmp = y * (1.0 - z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -4.7e-57:
		tmp = x * (1.0 - z)
	else:
		tmp = y * (1.0 - z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -4.7e-57)
		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 <= -4.7e-57)
		tmp = x * (1.0 - z);
	else
		tmp = y * (1.0 - z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -4.7e-57], 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 -4.7 \cdot 10^{-57}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\

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


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

    1. Initial program 100.0%

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

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

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

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

    if -4.6999999999999998e-57 < 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 59.6%

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

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

Alternative 7: 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 8: 31.4% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 6 \cdot 10^{-111}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \end{array} \]
(FPCore (x y z) :precision binary64 (if (<= y 6e-111) x y))
double code(double x, double y, double z) {
	double tmp;
	if (y <= 6e-111) {
		tmp = x;
	} else {
		tmp = y;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y <= 6d-111) then
        tmp = x
    else
        tmp = y
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= 6e-111) {
		tmp = x;
	} else {
		tmp = y;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= 6e-111:
		tmp = x
	else:
		tmp = y
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= 6e-111)
		tmp = x;
	else
		tmp = y;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= 6e-111)
		tmp = x;
	else
		tmp = y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, 6e-111], x, y]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 6.00000000000000016e-111

    1. Initial program 100.0%

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

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

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

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

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

    if 6.00000000000000016e-111 < y

    1. Initial program 100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 6 \cdot 10^{-111}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 50.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 54.4%

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

      \[\leadsto \color{blue}{y + x} \]
  5. Simplified54.4%

    \[\leadsto \color{blue}{y + x} \]
  6. Final simplification54.4%

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

Alternative 10: 25.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 55.6%

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

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

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

    \[\leadsto \color{blue}{x} \]
  7. Final simplification32.6%

    \[\leadsto x \]
  8. Add Preprocessing

Reproduce

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