Diagrams.TwoD.Apollonian:initialConfig from diagrams-contrib-1.3.0.5, A

Percentage Accurate: 69.9% → 96.0%
Time: 10.8s
Alternatives: 6
Speedup: 1.1×

Specification

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

\\
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\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 6 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: 69.9% accurate, 1.0× speedup?

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

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

Alternative 1: 96.0% accurate, 0.1× speedup?

\[\begin{array}{l} z_m = \left|z\right| \\ y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ \begin{array}{l} t_0 := \frac{\left(x \cdot x + y\_m \cdot y\_m\right) - z\_m \cdot z\_m}{y\_m \cdot 2}\\ y\_s \cdot \begin{array}{l} \mathbf{if}\;t\_0 \leq 0 \lor \neg \left(t\_0 \leq \infty\right):\\ \;\;\;\;0.5 \cdot \left(\left(y\_m + z\_m\right) \cdot \frac{y\_m - z\_m}{y\_m}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{\mathsf{hypot}\left(x, y\_m\right)}{\frac{y\_m}{\mathsf{hypot}\left(x, y\_m\right)}}\\ \end{array} \end{array} \end{array} \]
z_m = (fabs.f64 z)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z_m)
 :precision binary64
 (let* ((t_0 (/ (- (+ (* x x) (* y_m y_m)) (* z_m z_m)) (* y_m 2.0))))
   (*
    y_s
    (if (or (<= t_0 0.0) (not (<= t_0 INFINITY)))
      (* 0.5 (* (+ y_m z_m) (/ (- y_m z_m) y_m)))
      (* 0.5 (/ (hypot x y_m) (/ y_m (hypot x y_m))))))))
z_m = fabs(z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z_m) {
	double t_0 = (((x * x) + (y_m * y_m)) - (z_m * z_m)) / (y_m * 2.0);
	double tmp;
	if ((t_0 <= 0.0) || !(t_0 <= ((double) INFINITY))) {
		tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m));
	} else {
		tmp = 0.5 * (hypot(x, y_m) / (y_m / hypot(x, y_m)));
	}
	return y_s * tmp;
}
z_m = Math.abs(z);
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z_m) {
	double t_0 = (((x * x) + (y_m * y_m)) - (z_m * z_m)) / (y_m * 2.0);
	double tmp;
	if ((t_0 <= 0.0) || !(t_0 <= Double.POSITIVE_INFINITY)) {
		tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m));
	} else {
		tmp = 0.5 * (Math.hypot(x, y_m) / (y_m / Math.hypot(x, y_m)));
	}
	return y_s * tmp;
}
z_m = math.fabs(z)
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z_m):
	t_0 = (((x * x) + (y_m * y_m)) - (z_m * z_m)) / (y_m * 2.0)
	tmp = 0
	if (t_0 <= 0.0) or not (t_0 <= math.inf):
		tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m))
	else:
		tmp = 0.5 * (math.hypot(x, y_m) / (y_m / math.hypot(x, y_m)))
	return y_s * tmp
z_m = abs(z)
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z_m)
	t_0 = Float64(Float64(Float64(Float64(x * x) + Float64(y_m * y_m)) - Float64(z_m * z_m)) / Float64(y_m * 2.0))
	tmp = 0.0
	if ((t_0 <= 0.0) || !(t_0 <= Inf))
		tmp = Float64(0.5 * Float64(Float64(y_m + z_m) * Float64(Float64(y_m - z_m) / y_m)));
	else
		tmp = Float64(0.5 * Float64(hypot(x, y_m) / Float64(y_m / hypot(x, y_m))));
	end
	return Float64(y_s * tmp)
end
z_m = abs(z);
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp_2 = code(y_s, x, y_m, z_m)
	t_0 = (((x * x) + (y_m * y_m)) - (z_m * z_m)) / (y_m * 2.0);
	tmp = 0.0;
	if ((t_0 <= 0.0) || ~((t_0 <= Inf)))
		tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m));
	else
		tmp = 0.5 * (hypot(x, y_m) / (y_m / hypot(x, y_m)));
	end
	tmp_2 = y_s * tmp;
end
z_m = N[Abs[z], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z$95$m_] := Block[{t$95$0 = N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y$95$m * y$95$m), $MachinePrecision]), $MachinePrecision] - N[(z$95$m * z$95$m), $MachinePrecision]), $MachinePrecision] / N[(y$95$m * 2.0), $MachinePrecision]), $MachinePrecision]}, N[(y$95$s * If[Or[LessEqual[t$95$0, 0.0], N[Not[LessEqual[t$95$0, Infinity]], $MachinePrecision]], N[(0.5 * N[(N[(y$95$m + z$95$m), $MachinePrecision] * N[(N[(y$95$m - z$95$m), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Sqrt[x ^ 2 + y$95$m ^ 2], $MachinePrecision] / N[(y$95$m / N[Sqrt[x ^ 2 + y$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
z_m = \left|z\right|
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
\begin{array}{l}
t_0 := \frac{\left(x \cdot x + y\_m \cdot y\_m\right) - z\_m \cdot z\_m}{y\_m \cdot 2}\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 0 \lor \neg \left(t\_0 \leq \infty\right):\\
\;\;\;\;0.5 \cdot \left(\left(y\_m + z\_m\right) \cdot \frac{y\_m - z\_m}{y\_m}\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{\mathsf{hypot}\left(x, y\_m\right)}{\frac{y\_m}{\mathsf{hypot}\left(x, y\_m\right)}}\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < 0.0 or +inf.0 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64)))

    1. Initial program 61.5%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Step-by-step derivation
      1. remove-double-neg61.5%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{0.5} \cdot \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y} \]
      12. associate--l+61.5%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{x \cdot x + \left(y \cdot y - z \cdot z\right)}}{y} \]
      13. fma-define66.7%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}}{y} \]
    3. Simplified66.7%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}{y}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. difference-of-squares70.2%

        \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y + z\right) \cdot \left(y - z\right)}\right)}{y} \]
      2. *-commutative70.2%

        \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y - z\right) \cdot \left(y + z\right)}\right)}{y} \]
    6. Applied egg-rr70.2%

      \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y - z\right) \cdot \left(y + z\right)}\right)}{y} \]
    7. Taylor expanded in x around 0 48.8%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\left(y + z\right) \cdot \left(y - z\right)}{y}} \]
    8. Step-by-step derivation
      1. associate-/l*71.2%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(y + z\right) \cdot \frac{y - z}{y}\right)} \]
    9. Simplified71.2%

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

    if 0.0 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < +inf.0

    1. Initial program 75.1%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Step-by-step derivation
      1. remove-double-neg75.1%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{0.5} \cdot \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y} \]
      12. associate--l+75.1%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{x \cdot x + \left(y \cdot y - z \cdot z\right)}}{y} \]
      13. fma-define75.1%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}}{y} \]
    3. Simplified75.1%

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{{x}^{2} + {y}^{2}}{y}} \]
    6. Step-by-step derivation
      1. +-commutative46.7%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{{y}^{2} + {x}^{2}}}{y} \]
      2. unpow246.7%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{y \cdot y} + {x}^{2}}{y} \]
      3. fma-undefine46.7%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(y, y, {x}^{2}\right)}}{y} \]
    7. Simplified46.7%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\mathsf{fma}\left(y, y, {x}^{2}\right)}{y}} \]
    8. Step-by-step derivation
      1. fma-undefine46.7%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{y \cdot y + {x}^{2}}}{y} \]
      2. pow246.7%

        \[\leadsto 0.5 \cdot \frac{y \cdot y + \color{blue}{x \cdot x}}{y} \]
      3. +-commutative46.7%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{x \cdot x + y \cdot y}}{y} \]
      4. add-sqr-sqrt46.4%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\sqrt{\frac{x \cdot x + y \cdot y}{y}} \cdot \sqrt{\frac{x \cdot x + y \cdot y}{y}}\right)} \]
      5. sqrt-div46.4%

        \[\leadsto 0.5 \cdot \left(\color{blue}{\frac{\sqrt{x \cdot x + y \cdot y}}{\sqrt{y}}} \cdot \sqrt{\frac{x \cdot x + y \cdot y}{y}}\right) \]
      6. hypot-define46.4%

        \[\leadsto 0.5 \cdot \left(\frac{\color{blue}{\mathsf{hypot}\left(x, y\right)}}{\sqrt{y}} \cdot \sqrt{\frac{x \cdot x + y \cdot y}{y}}\right) \]
      7. sqrt-div46.3%

        \[\leadsto 0.5 \cdot \left(\frac{\mathsf{hypot}\left(x, y\right)}{\sqrt{y}} \cdot \color{blue}{\frac{\sqrt{x \cdot x + y \cdot y}}{\sqrt{y}}}\right) \]
      8. hypot-define69.3%

        \[\leadsto 0.5 \cdot \left(\frac{\mathsf{hypot}\left(x, y\right)}{\sqrt{y}} \cdot \frac{\color{blue}{\mathsf{hypot}\left(x, y\right)}}{\sqrt{y}}\right) \]
    9. Applied egg-rr69.3%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{\mathsf{hypot}\left(x, y\right)}{\sqrt{y}} \cdot \frac{\mathsf{hypot}\left(x, y\right)}{\sqrt{y}}\right)} \]
    10. Step-by-step derivation
      1. unpow269.3%

        \[\leadsto 0.5 \cdot \color{blue}{{\left(\frac{\mathsf{hypot}\left(x, y\right)}{\sqrt{y}}\right)}^{2}} \]
      2. hypot-undefine46.3%

        \[\leadsto 0.5 \cdot {\left(\frac{\color{blue}{\sqrt{x \cdot x + y \cdot y}}}{\sqrt{y}}\right)}^{2} \]
      3. unpow246.3%

        \[\leadsto 0.5 \cdot {\left(\frac{\sqrt{\color{blue}{{x}^{2}} + y \cdot y}}{\sqrt{y}}\right)}^{2} \]
      4. unpow246.3%

        \[\leadsto 0.5 \cdot {\left(\frac{\sqrt{{x}^{2} + \color{blue}{{y}^{2}}}}{\sqrt{y}}\right)}^{2} \]
      5. +-commutative46.3%

        \[\leadsto 0.5 \cdot {\left(\frac{\sqrt{\color{blue}{{y}^{2} + {x}^{2}}}}{\sqrt{y}}\right)}^{2} \]
      6. unpow246.3%

        \[\leadsto 0.5 \cdot {\left(\frac{\sqrt{\color{blue}{y \cdot y} + {x}^{2}}}{\sqrt{y}}\right)}^{2} \]
      7. unpow246.3%

        \[\leadsto 0.5 \cdot {\left(\frac{\sqrt{y \cdot y + \color{blue}{x \cdot x}}}{\sqrt{y}}\right)}^{2} \]
      8. hypot-define69.3%

        \[\leadsto 0.5 \cdot {\left(\frac{\color{blue}{\mathsf{hypot}\left(y, x\right)}}{\sqrt{y}}\right)}^{2} \]
    11. Simplified69.3%

      \[\leadsto 0.5 \cdot \color{blue}{{\left(\frac{\mathsf{hypot}\left(y, x\right)}{\sqrt{y}}\right)}^{2}} \]
    12. Step-by-step derivation
      1. unpow269.3%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{\mathsf{hypot}\left(y, x\right)}{\sqrt{y}} \cdot \frac{\mathsf{hypot}\left(y, x\right)}{\sqrt{y}}\right)} \]
      2. clear-num69.2%

        \[\leadsto 0.5 \cdot \left(\color{blue}{\frac{1}{\frac{\sqrt{y}}{\mathsf{hypot}\left(y, x\right)}}} \cdot \frac{\mathsf{hypot}\left(y, x\right)}{\sqrt{y}}\right) \]
      3. frac-times69.3%

        \[\leadsto 0.5 \cdot \color{blue}{\frac{1 \cdot \mathsf{hypot}\left(y, x\right)}{\frac{\sqrt{y}}{\mathsf{hypot}\left(y, x\right)} \cdot \sqrt{y}}} \]
      4. *-un-lft-identity69.3%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{hypot}\left(y, x\right)}}{\frac{\sqrt{y}}{\mathsf{hypot}\left(y, x\right)} \cdot \sqrt{y}} \]
    13. Applied egg-rr69.3%

      \[\leadsto 0.5 \cdot \color{blue}{\frac{\mathsf{hypot}\left(y, x\right)}{\frac{\sqrt{y}}{\mathsf{hypot}\left(y, x\right)} \cdot \sqrt{y}}} \]
    14. Step-by-step derivation
      1. hypot-undefine46.3%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{y \cdot y + x \cdot x}}}{\frac{\sqrt{y}}{\mathsf{hypot}\left(y, x\right)} \cdot \sqrt{y}} \]
      2. unpow246.3%

        \[\leadsto 0.5 \cdot \frac{\sqrt{\color{blue}{{y}^{2}} + x \cdot x}}{\frac{\sqrt{y}}{\mathsf{hypot}\left(y, x\right)} \cdot \sqrt{y}} \]
      3. unpow246.3%

        \[\leadsto 0.5 \cdot \frac{\sqrt{{y}^{2} + \color{blue}{{x}^{2}}}}{\frac{\sqrt{y}}{\mathsf{hypot}\left(y, x\right)} \cdot \sqrt{y}} \]
      4. +-commutative46.3%

        \[\leadsto 0.5 \cdot \frac{\sqrt{\color{blue}{{x}^{2} + {y}^{2}}}}{\frac{\sqrt{y}}{\mathsf{hypot}\left(y, x\right)} \cdot \sqrt{y}} \]
      5. unpow246.3%

        \[\leadsto 0.5 \cdot \frac{\sqrt{\color{blue}{x \cdot x} + {y}^{2}}}{\frac{\sqrt{y}}{\mathsf{hypot}\left(y, x\right)} \cdot \sqrt{y}} \]
      6. unpow246.3%

        \[\leadsto 0.5 \cdot \frac{\sqrt{x \cdot x + \color{blue}{y \cdot y}}}{\frac{\sqrt{y}}{\mathsf{hypot}\left(y, x\right)} \cdot \sqrt{y}} \]
      7. hypot-undefine69.3%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{hypot}\left(x, y\right)}}{\frac{\sqrt{y}}{\mathsf{hypot}\left(y, x\right)} \cdot \sqrt{y}} \]
      8. associate-*l/69.3%

        \[\leadsto 0.5 \cdot \frac{\mathsf{hypot}\left(x, y\right)}{\color{blue}{\frac{\sqrt{y} \cdot \sqrt{y}}{\mathsf{hypot}\left(y, x\right)}}} \]
      9. rem-square-sqrt69.9%

        \[\leadsto 0.5 \cdot \frac{\mathsf{hypot}\left(x, y\right)}{\frac{\color{blue}{y}}{\mathsf{hypot}\left(y, x\right)}} \]
      10. hypot-undefine46.7%

        \[\leadsto 0.5 \cdot \frac{\mathsf{hypot}\left(x, y\right)}{\frac{y}{\color{blue}{\sqrt{y \cdot y + x \cdot x}}}} \]
      11. unpow246.7%

        \[\leadsto 0.5 \cdot \frac{\mathsf{hypot}\left(x, y\right)}{\frac{y}{\sqrt{\color{blue}{{y}^{2}} + x \cdot x}}} \]
      12. unpow246.7%

        \[\leadsto 0.5 \cdot \frac{\mathsf{hypot}\left(x, y\right)}{\frac{y}{\sqrt{{y}^{2} + \color{blue}{{x}^{2}}}}} \]
      13. +-commutative46.7%

        \[\leadsto 0.5 \cdot \frac{\mathsf{hypot}\left(x, y\right)}{\frac{y}{\sqrt{\color{blue}{{x}^{2} + {y}^{2}}}}} \]
      14. unpow246.7%

        \[\leadsto 0.5 \cdot \frac{\mathsf{hypot}\left(x, y\right)}{\frac{y}{\sqrt{\color{blue}{x \cdot x} + {y}^{2}}}} \]
      15. unpow246.7%

        \[\leadsto 0.5 \cdot \frac{\mathsf{hypot}\left(x, y\right)}{\frac{y}{\sqrt{x \cdot x + \color{blue}{y \cdot y}}}} \]
      16. hypot-undefine69.9%

        \[\leadsto 0.5 \cdot \frac{\mathsf{hypot}\left(x, y\right)}{\frac{y}{\color{blue}{\mathsf{hypot}\left(x, y\right)}}} \]
    15. Simplified69.9%

      \[\leadsto 0.5 \cdot \color{blue}{\frac{\mathsf{hypot}\left(x, y\right)}{\frac{y}{\mathsf{hypot}\left(x, y\right)}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification70.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \leq 0 \lor \neg \left(\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \leq \infty\right):\\ \;\;\;\;0.5 \cdot \left(\left(y + z\right) \cdot \frac{y - z}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{\mathsf{hypot}\left(x, y\right)}{\frac{y}{\mathsf{hypot}\left(x, y\right)}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 90.9% accurate, 0.1× speedup?

\[\begin{array}{l} z_m = \left|z\right| \\ y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \begin{array}{l} \mathbf{if}\;y\_m \leq 3.7 \cdot 10^{+112}:\\ \;\;\;\;0.5 \cdot \frac{\mathsf{fma}\left(x, x, \left(y\_m + z\_m\right) \cdot \left(y\_m - z\_m\right)\right)}{y\_m}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\left(y\_m + z\_m\right) \cdot \frac{y\_m - z\_m}{y\_m}\right)\\ \end{array} \end{array} \]
z_m = (fabs.f64 z)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z_m)
 :precision binary64
 (*
  y_s
  (if (<= y_m 3.7e+112)
    (* 0.5 (/ (fma x x (* (+ y_m z_m) (- y_m z_m))) y_m))
    (* 0.5 (* (+ y_m z_m) (/ (- y_m z_m) y_m))))))
z_m = fabs(z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z_m) {
	double tmp;
	if (y_m <= 3.7e+112) {
		tmp = 0.5 * (fma(x, x, ((y_m + z_m) * (y_m - z_m))) / y_m);
	} else {
		tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m));
	}
	return y_s * tmp;
}
z_m = abs(z)
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z_m)
	tmp = 0.0
	if (y_m <= 3.7e+112)
		tmp = Float64(0.5 * Float64(fma(x, x, Float64(Float64(y_m + z_m) * Float64(y_m - z_m))) / y_m));
	else
		tmp = Float64(0.5 * Float64(Float64(y_m + z_m) * Float64(Float64(y_m - z_m) / y_m)));
	end
	return Float64(y_s * tmp)
end
z_m = N[Abs[z], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z$95$m_] := N[(y$95$s * If[LessEqual[y$95$m, 3.7e+112], N[(0.5 * N[(N[(x * x + N[(N[(y$95$m + z$95$m), $MachinePrecision] * N[(y$95$m - z$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(y$95$m + z$95$m), $MachinePrecision] * N[(N[(y$95$m - z$95$m), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;y\_m \leq 3.7 \cdot 10^{+112}:\\
\;\;\;\;0.5 \cdot \frac{\mathsf{fma}\left(x, x, \left(y\_m + z\_m\right) \cdot \left(y\_m - z\_m\right)\right)}{y\_m}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\left(y\_m + z\_m\right) \cdot \frac{y\_m - z\_m}{y\_m}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 3.70000000000000004e112

    1. Initial program 79.3%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Step-by-step derivation
      1. remove-double-neg79.3%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{0.5} \cdot \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y} \]
      12. associate--l+79.3%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{x \cdot x + \left(y \cdot y - z \cdot z\right)}}{y} \]
      13. fma-define82.8%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}}{y} \]
    3. Simplified82.8%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}{y}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. difference-of-squares83.9%

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

        \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y - z\right) \cdot \left(y + z\right)}\right)}{y} \]
    6. Applied egg-rr83.9%

      \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y - z\right) \cdot \left(y + z\right)}\right)}{y} \]

    if 3.70000000000000004e112 < y

    1. Initial program 26.2%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Step-by-step derivation
      1. remove-double-neg26.2%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{0.5} \cdot \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y} \]
      12. associate--l+26.2%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{x \cdot x + \left(y \cdot y - z \cdot z\right)}}{y} \]
      13. fma-define26.2%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}}{y} \]
    3. Simplified26.2%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}{y}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. difference-of-squares30.7%

        \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y + z\right) \cdot \left(y - z\right)}\right)}{y} \]
      2. *-commutative30.7%

        \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y - z\right) \cdot \left(y + z\right)}\right)}{y} \]
    6. Applied egg-rr30.7%

      \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y - z\right) \cdot \left(y + z\right)}\right)}{y} \]
    7. Taylor expanded in x around 0 29.0%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\left(y + z\right) \cdot \left(y - z\right)}{y}} \]
    8. Step-by-step derivation
      1. associate-/l*87.8%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(y + z\right) \cdot \frac{y - z}{y}\right)} \]
    9. Simplified87.8%

      \[\leadsto \color{blue}{0.5 \cdot \left(\left(y + z\right) \cdot \frac{y - z}{y}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification84.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 3.7 \cdot 10^{+112}:\\ \;\;\;\;0.5 \cdot \frac{\mathsf{fma}\left(x, x, \left(y + z\right) \cdot \left(y - z\right)\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\left(y + z\right) \cdot \frac{y - z}{y}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 91.8% accurate, 0.3× speedup?

\[\begin{array}{l} z_m = \left|z\right| \\ y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ \begin{array}{l} t_0 := \frac{\left(x \cdot x + y\_m \cdot y\_m\right) - z\_m \cdot z\_m}{y\_m \cdot 2}\\ y\_s \cdot \begin{array}{l} \mathbf{if}\;t\_0 \leq 0 \lor \neg \left(t\_0 \leq \infty\right):\\ \;\;\;\;0.5 \cdot \left(\left(y\_m + z\_m\right) \cdot \frac{y\_m - z\_m}{y\_m}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(y\_m + \frac{x \cdot x}{y\_m}\right)\\ \end{array} \end{array} \end{array} \]
z_m = (fabs.f64 z)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z_m)
 :precision binary64
 (let* ((t_0 (/ (- (+ (* x x) (* y_m y_m)) (* z_m z_m)) (* y_m 2.0))))
   (*
    y_s
    (if (or (<= t_0 0.0) (not (<= t_0 INFINITY)))
      (* 0.5 (* (+ y_m z_m) (/ (- y_m z_m) y_m)))
      (* 0.5 (+ y_m (/ (* x x) y_m)))))))
z_m = fabs(z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z_m) {
	double t_0 = (((x * x) + (y_m * y_m)) - (z_m * z_m)) / (y_m * 2.0);
	double tmp;
	if ((t_0 <= 0.0) || !(t_0 <= ((double) INFINITY))) {
		tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m));
	} else {
		tmp = 0.5 * (y_m + ((x * x) / y_m));
	}
	return y_s * tmp;
}
z_m = Math.abs(z);
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z_m) {
	double t_0 = (((x * x) + (y_m * y_m)) - (z_m * z_m)) / (y_m * 2.0);
	double tmp;
	if ((t_0 <= 0.0) || !(t_0 <= Double.POSITIVE_INFINITY)) {
		tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m));
	} else {
		tmp = 0.5 * (y_m + ((x * x) / y_m));
	}
	return y_s * tmp;
}
z_m = math.fabs(z)
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z_m):
	t_0 = (((x * x) + (y_m * y_m)) - (z_m * z_m)) / (y_m * 2.0)
	tmp = 0
	if (t_0 <= 0.0) or not (t_0 <= math.inf):
		tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m))
	else:
		tmp = 0.5 * (y_m + ((x * x) / y_m))
	return y_s * tmp
z_m = abs(z)
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z_m)
	t_0 = Float64(Float64(Float64(Float64(x * x) + Float64(y_m * y_m)) - Float64(z_m * z_m)) / Float64(y_m * 2.0))
	tmp = 0.0
	if ((t_0 <= 0.0) || !(t_0 <= Inf))
		tmp = Float64(0.5 * Float64(Float64(y_m + z_m) * Float64(Float64(y_m - z_m) / y_m)));
	else
		tmp = Float64(0.5 * Float64(y_m + Float64(Float64(x * x) / y_m)));
	end
	return Float64(y_s * tmp)
end
z_m = abs(z);
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp_2 = code(y_s, x, y_m, z_m)
	t_0 = (((x * x) + (y_m * y_m)) - (z_m * z_m)) / (y_m * 2.0);
	tmp = 0.0;
	if ((t_0 <= 0.0) || ~((t_0 <= Inf)))
		tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m));
	else
		tmp = 0.5 * (y_m + ((x * x) / y_m));
	end
	tmp_2 = y_s * tmp;
end
z_m = N[Abs[z], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z$95$m_] := Block[{t$95$0 = N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y$95$m * y$95$m), $MachinePrecision]), $MachinePrecision] - N[(z$95$m * z$95$m), $MachinePrecision]), $MachinePrecision] / N[(y$95$m * 2.0), $MachinePrecision]), $MachinePrecision]}, N[(y$95$s * If[Or[LessEqual[t$95$0, 0.0], N[Not[LessEqual[t$95$0, Infinity]], $MachinePrecision]], N[(0.5 * N[(N[(y$95$m + z$95$m), $MachinePrecision] * N[(N[(y$95$m - z$95$m), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y$95$m + N[(N[(x * x), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
z_m = \left|z\right|
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
\begin{array}{l}
t_0 := \frac{\left(x \cdot x + y\_m \cdot y\_m\right) - z\_m \cdot z\_m}{y\_m \cdot 2}\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 0 \lor \neg \left(t\_0 \leq \infty\right):\\
\;\;\;\;0.5 \cdot \left(\left(y\_m + z\_m\right) \cdot \frac{y\_m - z\_m}{y\_m}\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(y\_m + \frac{x \cdot x}{y\_m}\right)\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < 0.0 or +inf.0 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64)))

    1. Initial program 61.5%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Step-by-step derivation
      1. remove-double-neg61.5%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{0.5} \cdot \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y} \]
      12. associate--l+61.5%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{x \cdot x + \left(y \cdot y - z \cdot z\right)}}{y} \]
      13. fma-define66.7%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}}{y} \]
    3. Simplified66.7%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}{y}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. difference-of-squares70.2%

        \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y + z\right) \cdot \left(y - z\right)}\right)}{y} \]
      2. *-commutative70.2%

        \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y - z\right) \cdot \left(y + z\right)}\right)}{y} \]
    6. Applied egg-rr70.2%

      \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y - z\right) \cdot \left(y + z\right)}\right)}{y} \]
    7. Taylor expanded in x around 0 48.8%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\left(y + z\right) \cdot \left(y - z\right)}{y}} \]
    8. Step-by-step derivation
      1. associate-/l*71.2%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(y + z\right) \cdot \frac{y - z}{y}\right)} \]
    9. Simplified71.2%

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

    if 0.0 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < +inf.0

    1. Initial program 75.1%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Step-by-step derivation
      1. remove-double-neg75.1%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{0.5} \cdot \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y} \]
      12. associate--l+75.1%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{x \cdot x + \left(y \cdot y - z \cdot z\right)}}{y} \]
      13. fma-define75.1%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}}{y} \]
    3. Simplified75.1%

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{{x}^{2} + {y}^{2}}{y}} \]
    6. Step-by-step derivation
      1. +-commutative46.7%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{{y}^{2} + {x}^{2}}}{y} \]
      2. unpow246.7%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{y \cdot y} + {x}^{2}}{y} \]
      3. fma-undefine46.7%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(y, y, {x}^{2}\right)}}{y} \]
    7. Simplified46.7%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\mathsf{fma}\left(y, y, {x}^{2}\right)}{y}} \]
    8. Taylor expanded in x around 0 62.3%

      \[\leadsto \color{blue}{0.5 \cdot y + 0.5 \cdot \frac{{x}^{2}}{y}} \]
    9. Step-by-step derivation
      1. distribute-lft-out62.3%

        \[\leadsto \color{blue}{0.5 \cdot \left(y + \frac{{x}^{2}}{y}\right)} \]
    10. Simplified62.3%

      \[\leadsto \color{blue}{0.5 \cdot \left(y + \frac{{x}^{2}}{y}\right)} \]
    11. Step-by-step derivation
      1. pow262.3%

        \[\leadsto 0.5 \cdot \left(y + \frac{\color{blue}{x \cdot x}}{y}\right) \]
    12. Applied egg-rr62.3%

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

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

Alternative 4: 75.7% accurate, 1.1× speedup?

\[\begin{array}{l} z_m = \left|z\right| \\ y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \begin{array}{l} \mathbf{if}\;z\_m \leq 2.1 \cdot 10^{+141}:\\ \;\;\;\;0.5 \cdot \left(y\_m + \frac{x \cdot x}{y\_m}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(z\_m \cdot \frac{y\_m - z\_m}{y\_m}\right)\\ \end{array} \end{array} \]
z_m = (fabs.f64 z)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z_m)
 :precision binary64
 (*
  y_s
  (if (<= z_m 2.1e+141)
    (* 0.5 (+ y_m (/ (* x x) y_m)))
    (* 0.5 (* z_m (/ (- y_m z_m) y_m))))))
z_m = fabs(z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z_m) {
	double tmp;
	if (z_m <= 2.1e+141) {
		tmp = 0.5 * (y_m + ((x * x) / y_m));
	} else {
		tmp = 0.5 * (z_m * ((y_m - z_m) / y_m));
	}
	return y_s * tmp;
}
z_m = abs(z)
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z_m)
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z_m
    real(8) :: tmp
    if (z_m <= 2.1d+141) then
        tmp = 0.5d0 * (y_m + ((x * x) / y_m))
    else
        tmp = 0.5d0 * (z_m * ((y_m - z_m) / y_m))
    end if
    code = y_s * tmp
end function
z_m = Math.abs(z);
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z_m) {
	double tmp;
	if (z_m <= 2.1e+141) {
		tmp = 0.5 * (y_m + ((x * x) / y_m));
	} else {
		tmp = 0.5 * (z_m * ((y_m - z_m) / y_m));
	}
	return y_s * tmp;
}
z_m = math.fabs(z)
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z_m):
	tmp = 0
	if z_m <= 2.1e+141:
		tmp = 0.5 * (y_m + ((x * x) / y_m))
	else:
		tmp = 0.5 * (z_m * ((y_m - z_m) / y_m))
	return y_s * tmp
z_m = abs(z)
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z_m)
	tmp = 0.0
	if (z_m <= 2.1e+141)
		tmp = Float64(0.5 * Float64(y_m + Float64(Float64(x * x) / y_m)));
	else
		tmp = Float64(0.5 * Float64(z_m * Float64(Float64(y_m - z_m) / y_m)));
	end
	return Float64(y_s * tmp)
end
z_m = abs(z);
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp_2 = code(y_s, x, y_m, z_m)
	tmp = 0.0;
	if (z_m <= 2.1e+141)
		tmp = 0.5 * (y_m + ((x * x) / y_m));
	else
		tmp = 0.5 * (z_m * ((y_m - z_m) / y_m));
	end
	tmp_2 = y_s * tmp;
end
z_m = N[Abs[z], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z$95$m_] := N[(y$95$s * If[LessEqual[z$95$m, 2.1e+141], N[(0.5 * N[(y$95$m + N[(N[(x * x), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(z$95$m * N[(N[(y$95$m - z$95$m), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;z\_m \leq 2.1 \cdot 10^{+141}:\\
\;\;\;\;0.5 \cdot \left(y\_m + \frac{x \cdot x}{y\_m}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < 2.0999999999999998e141

    1. Initial program 74.0%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Step-by-step derivation
      1. remove-double-neg74.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{0.5} \cdot \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y} \]
      12. associate--l+74.0%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{x \cdot x + \left(y \cdot y - z \cdot z\right)}}{y} \]
      13. fma-define75.4%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}}{y} \]
    3. Simplified75.4%

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{{x}^{2} + {y}^{2}}{y}} \]
    6. Step-by-step derivation
      1. +-commutative49.8%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{{y}^{2} + {x}^{2}}}{y} \]
      2. unpow249.8%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{y \cdot y} + {x}^{2}}{y} \]
      3. fma-undefine49.8%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(y, y, {x}^{2}\right)}}{y} \]
    7. Simplified49.8%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\mathsf{fma}\left(y, y, {x}^{2}\right)}{y}} \]
    8. Taylor expanded in x around 0 65.8%

      \[\leadsto \color{blue}{0.5 \cdot y + 0.5 \cdot \frac{{x}^{2}}{y}} \]
    9. Step-by-step derivation
      1. distribute-lft-out65.8%

        \[\leadsto \color{blue}{0.5 \cdot \left(y + \frac{{x}^{2}}{y}\right)} \]
    10. Simplified65.8%

      \[\leadsto \color{blue}{0.5 \cdot \left(y + \frac{{x}^{2}}{y}\right)} \]
    11. Step-by-step derivation
      1. pow265.8%

        \[\leadsto 0.5 \cdot \left(y + \frac{\color{blue}{x \cdot x}}{y}\right) \]
    12. Applied egg-rr65.8%

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

    if 2.0999999999999998e141 < z

    1. Initial program 35.4%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Step-by-step derivation
      1. remove-double-neg35.4%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{0.5} \cdot \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y} \]
      12. associate--l+35.4%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{x \cdot x + \left(y \cdot y - z \cdot z\right)}}{y} \]
      13. fma-define45.3%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}}{y} \]
    3. Simplified45.3%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}{y}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. difference-of-squares56.4%

        \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y + z\right) \cdot \left(y - z\right)}\right)}{y} \]
      2. *-commutative56.4%

        \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y - z\right) \cdot \left(y + z\right)}\right)}{y} \]
    6. Applied egg-rr56.4%

      \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y - z\right) \cdot \left(y + z\right)}\right)}{y} \]
    7. Taylor expanded in x around 0 56.4%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\left(y + z\right) \cdot \left(y - z\right)}{y}} \]
    8. Step-by-step derivation
      1. associate-/l*85.5%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(y + z\right) \cdot \frac{y - z}{y}\right)} \]
    9. Simplified85.5%

      \[\leadsto \color{blue}{0.5 \cdot \left(\left(y + z\right) \cdot \frac{y - z}{y}\right)} \]
    10. Taylor expanded in y around 0 69.3%

      \[\leadsto 0.5 \cdot \left(\color{blue}{z} \cdot \frac{y - z}{y}\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 52.3% accurate, 1.1× speedup?

\[\begin{array}{l} z_m = \left|z\right| \\ y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \begin{array}{l} \mathbf{if}\;y\_m \leq 9.2 \cdot 10^{+113}:\\ \;\;\;\;0.5 \cdot \left(z\_m \cdot \frac{y\_m - z\_m}{y\_m}\right)\\ \mathbf{else}:\\ \;\;\;\;y\_m \cdot 0.5\\ \end{array} \end{array} \]
z_m = (fabs.f64 z)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z_m)
 :precision binary64
 (*
  y_s
  (if (<= y_m 9.2e+113) (* 0.5 (* z_m (/ (- y_m z_m) y_m))) (* y_m 0.5))))
z_m = fabs(z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z_m) {
	double tmp;
	if (y_m <= 9.2e+113) {
		tmp = 0.5 * (z_m * ((y_m - z_m) / y_m));
	} else {
		tmp = y_m * 0.5;
	}
	return y_s * tmp;
}
z_m = abs(z)
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z_m)
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z_m
    real(8) :: tmp
    if (y_m <= 9.2d+113) then
        tmp = 0.5d0 * (z_m * ((y_m - z_m) / y_m))
    else
        tmp = y_m * 0.5d0
    end if
    code = y_s * tmp
end function
z_m = Math.abs(z);
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z_m) {
	double tmp;
	if (y_m <= 9.2e+113) {
		tmp = 0.5 * (z_m * ((y_m - z_m) / y_m));
	} else {
		tmp = y_m * 0.5;
	}
	return y_s * tmp;
}
z_m = math.fabs(z)
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z_m):
	tmp = 0
	if y_m <= 9.2e+113:
		tmp = 0.5 * (z_m * ((y_m - z_m) / y_m))
	else:
		tmp = y_m * 0.5
	return y_s * tmp
z_m = abs(z)
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z_m)
	tmp = 0.0
	if (y_m <= 9.2e+113)
		tmp = Float64(0.5 * Float64(z_m * Float64(Float64(y_m - z_m) / y_m)));
	else
		tmp = Float64(y_m * 0.5);
	end
	return Float64(y_s * tmp)
end
z_m = abs(z);
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp_2 = code(y_s, x, y_m, z_m)
	tmp = 0.0;
	if (y_m <= 9.2e+113)
		tmp = 0.5 * (z_m * ((y_m - z_m) / y_m));
	else
		tmp = y_m * 0.5;
	end
	tmp_2 = y_s * tmp;
end
z_m = N[Abs[z], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z$95$m_] := N[(y$95$s * If[LessEqual[y$95$m, 9.2e+113], N[(0.5 * N[(z$95$m * N[(N[(y$95$m - z$95$m), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y$95$m * 0.5), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;y\_m \leq 9.2 \cdot 10^{+113}:\\
\;\;\;\;0.5 \cdot \left(z\_m \cdot \frac{y\_m - z\_m}{y\_m}\right)\\

\mathbf{else}:\\
\;\;\;\;y\_m \cdot 0.5\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 9.19999999999999987e113

    1. Initial program 78.6%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Step-by-step derivation
      1. remove-double-neg78.6%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{0.5} \cdot \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y} \]
      12. associate--l+78.6%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{x \cdot x + \left(y \cdot y - z \cdot z\right)}}{y} \]
      13. fma-define82.0%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}}{y} \]
    3. Simplified82.0%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}{y}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. difference-of-squares83.2%

        \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y + z\right) \cdot \left(y - z\right)}\right)}{y} \]
      2. *-commutative83.2%

        \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y - z\right) \cdot \left(y + z\right)}\right)}{y} \]
    6. Applied egg-rr83.2%

      \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y - z\right) \cdot \left(y + z\right)}\right)}{y} \]
    7. Taylor expanded in x around 0 55.8%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\left(y + z\right) \cdot \left(y - z\right)}{y}} \]
    8. Step-by-step derivation
      1. associate-/l*67.6%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(y + z\right) \cdot \frac{y - z}{y}\right)} \]
    9. Simplified67.6%

      \[\leadsto \color{blue}{0.5 \cdot \left(\left(y + z\right) \cdot \frac{y - z}{y}\right)} \]
    10. Taylor expanded in y around 0 42.0%

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

    if 9.19999999999999987e113 < y

    1. Initial program 26.8%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Step-by-step derivation
      1. remove-double-neg26.8%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{0.5} \cdot \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y} \]
      12. associate--l+26.8%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{x \cdot x + \left(y \cdot y - z \cdot z\right)}}{y} \]
      13. fma-define26.8%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}}{y} \]
    3. Simplified26.8%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}{y}} \]
    4. Add Preprocessing
    5. Taylor expanded in y around inf 74.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 9.2 \cdot 10^{+113}:\\ \;\;\;\;0.5 \cdot \left(z \cdot \frac{y - z}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 33.4% accurate, 5.0× speedup?

\[\begin{array}{l} z_m = \left|z\right| \\ y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \left(y\_m \cdot 0.5\right) \end{array} \]
z_m = (fabs.f64 z)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z_m) :precision binary64 (* y_s (* y_m 0.5)))
z_m = fabs(z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z_m) {
	return y_s * (y_m * 0.5);
}
z_m = abs(z)
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z_m)
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z_m
    code = y_s * (y_m * 0.5d0)
end function
z_m = Math.abs(z);
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z_m) {
	return y_s * (y_m * 0.5);
}
z_m = math.fabs(z)
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z_m):
	return y_s * (y_m * 0.5)
z_m = abs(z)
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z_m)
	return Float64(y_s * Float64(y_m * 0.5))
end
z_m = abs(z);
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp = code(y_s, x, y_m, z_m)
	tmp = y_s * (y_m * 0.5);
end
z_m = N[Abs[z], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z$95$m_] := N[(y$95$s * N[(y$95$m * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
y\_s \cdot \left(y\_m \cdot 0.5\right)
\end{array}
Derivation
  1. Initial program 67.9%

    \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
  2. Step-by-step derivation
    1. remove-double-neg67.9%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5} \cdot \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y} \]
    12. associate--l+67.9%

      \[\leadsto 0.5 \cdot \frac{\color{blue}{x \cdot x + \left(y \cdot y - z \cdot z\right)}}{y} \]
    13. fma-define70.6%

      \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}}{y} \]
  3. Simplified70.6%

    \[\leadsto \color{blue}{0.5 \cdot \frac{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}{y}} \]
  4. Add Preprocessing
  5. Taylor expanded in y around inf 37.0%

    \[\leadsto \color{blue}{0.5 \cdot y} \]
  6. Final simplification37.0%

    \[\leadsto y \cdot 0.5 \]
  7. Add Preprocessing

Developer Target 1: 99.9% accurate, 1.0× speedup?

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

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

Reproduce

?
herbie shell --seed 2024160 
(FPCore (x y z)
  :name "Diagrams.TwoD.Apollonian:initialConfig from diagrams-contrib-1.3.0.5, A"
  :precision binary64

  :alt
  (! :herbie-platform default (- (* y 1/2) (* (* (/ 1/2 y) (+ z x)) (- z x))))

  (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))