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

Percentage Accurate: 69.2% → 93.4%
Time: 8.4s
Alternatives: 9
Speedup: 0.7×

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 9 alternatives:

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

Initial Program: 69.2% 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: 93.4% accurate, 0.1× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ \begin{array}{l} t_0 := \mathsf{hypot}\left(x, y\_m + z\right)\\ y\_s \cdot \begin{array}{l} \mathbf{if}\;\frac{\left(x \cdot x + y\_m \cdot y\_m\right) - z \cdot z}{y\_m \cdot 2} \leq -5 \cdot 10^{-135}:\\ \;\;\;\;\frac{z}{y\_m} \cdot \frac{z}{-2}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(t\_0 \cdot \frac{t\_0}{y\_m}\right)\\ \end{array} \end{array} \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (let* ((t_0 (hypot x (+ y_m z))))
   (*
    y_s
    (if (<= (/ (- (+ (* x x) (* y_m y_m)) (* z z)) (* y_m 2.0)) -5e-135)
      (* (/ z y_m) (/ z -2.0))
      (* 0.5 (* t_0 (/ t_0 y_m)))))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double t_0 = hypot(x, (y_m + z));
	double tmp;
	if (((((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0)) <= -5e-135) {
		tmp = (z / y_m) * (z / -2.0);
	} else {
		tmp = 0.5 * (t_0 * (t_0 / y_m));
	}
	return y_s * tmp;
}
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) {
	double t_0 = Math.hypot(x, (y_m + z));
	double tmp;
	if (((((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0)) <= -5e-135) {
		tmp = (z / y_m) * (z / -2.0);
	} else {
		tmp = 0.5 * (t_0 * (t_0 / y_m));
	}
	return y_s * tmp;
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z):
	t_0 = math.hypot(x, (y_m + z))
	tmp = 0
	if ((((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0)) <= -5e-135:
		tmp = (z / y_m) * (z / -2.0)
	else:
		tmp = 0.5 * (t_0 * (t_0 / y_m))
	return y_s * tmp
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	t_0 = hypot(x, Float64(y_m + z))
	tmp = 0.0
	if (Float64(Float64(Float64(Float64(x * x) + Float64(y_m * y_m)) - Float64(z * z)) / Float64(y_m * 2.0)) <= -5e-135)
		tmp = Float64(Float64(z / y_m) * Float64(z / -2.0));
	else
		tmp = Float64(0.5 * Float64(t_0 * Float64(t_0 / y_m)));
	end
	return Float64(y_s * tmp)
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp_2 = code(y_s, x, y_m, z)
	t_0 = hypot(x, (y_m + z));
	tmp = 0.0;
	if (((((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0)) <= -5e-135)
		tmp = (z / y_m) * (z / -2.0);
	else
		tmp = 0.5 * (t_0 * (t_0 / y_m));
	end
	tmp_2 = y_s * tmp;
end
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_] := Block[{t$95$0 = N[Sqrt[x ^ 2 + N[(y$95$m + z), $MachinePrecision] ^ 2], $MachinePrecision]}, N[(y$95$s * If[LessEqual[N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y$95$m * y$95$m), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y$95$m * 2.0), $MachinePrecision]), $MachinePrecision], -5e-135], N[(N[(z / y$95$m), $MachinePrecision] * N[(z / -2.0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(t$95$0 * N[(t$95$0 / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
\begin{array}{l}
t_0 := \mathsf{hypot}\left(x, y\_m + z\right)\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;\frac{\left(x \cdot x + y\_m \cdot y\_m\right) - z \cdot z}{y\_m \cdot 2} \leq -5 \cdot 10^{-135}:\\
\;\;\;\;\frac{z}{y\_m} \cdot \frac{z}{-2}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(t\_0 \cdot \frac{t\_0}{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))) < -5.0000000000000002e-135

    1. Initial program 69.4%

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{{z}^{2}}{y}} \]
    4. Step-by-step derivation
      1. associate-*r/28.5%

        \[\leadsto \color{blue}{\frac{-0.5 \cdot {z}^{2}}{y}} \]
      2. metadata-eval28.5%

        \[\leadsto \frac{\color{blue}{\left(-0.5\right)} \cdot {z}^{2}}{y} \]
      3. distribute-lft-neg-in28.5%

        \[\leadsto \frac{\color{blue}{-0.5 \cdot {z}^{2}}}{y} \]
      4. *-commutative28.5%

        \[\leadsto \frac{-\color{blue}{{z}^{2} \cdot 0.5}}{y} \]
      5. distribute-neg-frac28.5%

        \[\leadsto \color{blue}{-\frac{{z}^{2} \cdot 0.5}{y}} \]
      6. associate-*r/28.5%

        \[\leadsto -\color{blue}{{z}^{2} \cdot \frac{0.5}{y}} \]
      7. distribute-rgt-neg-in28.5%

        \[\leadsto \color{blue}{{z}^{2} \cdot \left(-\frac{0.5}{y}\right)} \]
      8. distribute-neg-frac28.5%

        \[\leadsto {z}^{2} \cdot \color{blue}{\frac{-0.5}{y}} \]
      9. metadata-eval28.5%

        \[\leadsto {z}^{2} \cdot \frac{\color{blue}{-0.5}}{y} \]
    5. Simplified28.5%

      \[\leadsto \color{blue}{{z}^{2} \cdot \frac{-0.5}{y}} \]
    6. Step-by-step derivation
      1. associate-*r/28.5%

        \[\leadsto \color{blue}{\frac{{z}^{2} \cdot -0.5}{y}} \]
      2. clear-num28.5%

        \[\leadsto \color{blue}{\frac{1}{\frac{y}{{z}^{2} \cdot -0.5}}} \]
    7. Applied egg-rr28.5%

      \[\leadsto \color{blue}{\frac{1}{\frac{y}{{z}^{2} \cdot -0.5}}} \]
    8. Step-by-step derivation
      1. clear-num28.5%

        \[\leadsto \color{blue}{\frac{{z}^{2} \cdot -0.5}{y}} \]
      2. associate-/l*28.5%

        \[\leadsto \color{blue}{{z}^{2} \cdot \frac{-0.5}{y}} \]
      3. metadata-eval28.5%

        \[\leadsto {z}^{2} \cdot \frac{\color{blue}{\frac{1}{-2}}}{y} \]
      4. associate-/r*28.5%

        \[\leadsto {z}^{2} \cdot \color{blue}{\frac{1}{-2 \cdot y}} \]
      5. *-commutative28.5%

        \[\leadsto {z}^{2} \cdot \frac{1}{\color{blue}{y \cdot -2}} \]
      6. div-inv28.5%

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

        \[\leadsto \frac{\color{blue}{z \cdot z}}{y \cdot -2} \]
      8. times-frac30.1%

        \[\leadsto \color{blue}{\frac{z}{y} \cdot \frac{z}{-2}} \]
    9. Applied egg-rr30.1%

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

    if -5.0000000000000002e-135 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64)))

    1. Initial program 61.6%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Step-by-step derivation
      1. remove-double-neg61.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-out61.6%

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

        \[\leadsto \color{blue}{-\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{\left(-y\right) \cdot 2}} \]
      4. distribute-frac-neg61.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-161.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-out61.6%

        \[\leadsto \frac{-1 \cdot \left(\left(x \cdot x + y \cdot y\right) - z \cdot z\right)}{\color{blue}{-y \cdot 2}} \]
      7. *-commutative61.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-in61.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-frac61.6%

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

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

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}}{y} \]
    3. Simplified64.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. Step-by-step derivation
      1. prod-diff52.7%

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

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

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

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

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

      \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\mathsf{fma}\left(y + z, y - z, \mathsf{fma}\left(-z, z, {z}^{2}\right)\right)}\right)}{y} \]
    7. Step-by-step derivation
      1. add-sqr-sqrt42.4%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y + z, y - z, \mathsf{fma}\left(-z, z, {z}^{2}\right)\right)\right)} \cdot \sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y + z, y - z, \mathsf{fma}\left(-z, z, {z}^{2}\right)\right)\right)}}}{y} \]
      2. associate-/l*42.5%

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

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

Alternative 2: 88.3% accurate, 0.1× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \begin{array}{l} \mathbf{if}\;\frac{\left(x \cdot x + y\_m \cdot y\_m\right) - z \cdot z}{y\_m \cdot 2} \leq -5 \cdot 10^{-135}:\\ \;\;\;\;\frac{z}{y\_m} \cdot \frac{z}{-2}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(y\_m + \frac{{x}^{2}}{y\_m}\right)\\ \end{array} \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (*
  y_s
  (if (<= (/ (- (+ (* x x) (* y_m y_m)) (* z z)) (* y_m 2.0)) -5e-135)
    (* (/ z y_m) (/ z -2.0))
    (* 0.5 (+ y_m (/ (pow x 2.0) y_m))))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (((((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0)) <= -5e-135) {
		tmp = (z / y_m) * (z / -2.0);
	} else {
		tmp = 0.5 * (y_m + (pow(x, 2.0) / y_m));
	}
	return y_s * tmp;
}
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z)
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (((((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0d0)) <= (-5d-135)) then
        tmp = (z / y_m) * (z / (-2.0d0))
    else
        tmp = 0.5d0 * (y_m + ((x ** 2.0d0) / y_m))
    end if
    code = y_s * tmp
end function
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) {
	double tmp;
	if (((((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0)) <= -5e-135) {
		tmp = (z / y_m) * (z / -2.0);
	} else {
		tmp = 0.5 * (y_m + (Math.pow(x, 2.0) / y_m));
	}
	return y_s * tmp;
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z):
	tmp = 0
	if ((((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0)) <= -5e-135:
		tmp = (z / y_m) * (z / -2.0)
	else:
		tmp = 0.5 * (y_m + (math.pow(x, 2.0) / y_m))
	return y_s * tmp
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	tmp = 0.0
	if (Float64(Float64(Float64(Float64(x * x) + Float64(y_m * y_m)) - Float64(z * z)) / Float64(y_m * 2.0)) <= -5e-135)
		tmp = Float64(Float64(z / y_m) * Float64(z / -2.0));
	else
		tmp = Float64(0.5 * Float64(y_m + Float64((x ^ 2.0) / y_m)));
	end
	return Float64(y_s * tmp)
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp_2 = code(y_s, x, y_m, z)
	tmp = 0.0;
	if (((((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0)) <= -5e-135)
		tmp = (z / y_m) * (z / -2.0);
	else
		tmp = 0.5 * (y_m + ((x ^ 2.0) / y_m));
	end
	tmp_2 = y_s * tmp;
end
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_] := N[(y$95$s * If[LessEqual[N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y$95$m * y$95$m), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y$95$m * 2.0), $MachinePrecision]), $MachinePrecision], -5e-135], N[(N[(z / y$95$m), $MachinePrecision] * N[(z / -2.0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y$95$m + N[(N[Power[x, 2.0], $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;\frac{\left(x \cdot x + y\_m \cdot y\_m\right) - z \cdot z}{y\_m \cdot 2} \leq -5 \cdot 10^{-135}:\\
\;\;\;\;\frac{z}{y\_m} \cdot \frac{z}{-2}\\

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


\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))) < -5.0000000000000002e-135

    1. Initial program 69.4%

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{{z}^{2}}{y}} \]
    4. Step-by-step derivation
      1. associate-*r/28.5%

        \[\leadsto \color{blue}{\frac{-0.5 \cdot {z}^{2}}{y}} \]
      2. metadata-eval28.5%

        \[\leadsto \frac{\color{blue}{\left(-0.5\right)} \cdot {z}^{2}}{y} \]
      3. distribute-lft-neg-in28.5%

        \[\leadsto \frac{\color{blue}{-0.5 \cdot {z}^{2}}}{y} \]
      4. *-commutative28.5%

        \[\leadsto \frac{-\color{blue}{{z}^{2} \cdot 0.5}}{y} \]
      5. distribute-neg-frac28.5%

        \[\leadsto \color{blue}{-\frac{{z}^{2} \cdot 0.5}{y}} \]
      6. associate-*r/28.5%

        \[\leadsto -\color{blue}{{z}^{2} \cdot \frac{0.5}{y}} \]
      7. distribute-rgt-neg-in28.5%

        \[\leadsto \color{blue}{{z}^{2} \cdot \left(-\frac{0.5}{y}\right)} \]
      8. distribute-neg-frac28.5%

        \[\leadsto {z}^{2} \cdot \color{blue}{\frac{-0.5}{y}} \]
      9. metadata-eval28.5%

        \[\leadsto {z}^{2} \cdot \frac{\color{blue}{-0.5}}{y} \]
    5. Simplified28.5%

      \[\leadsto \color{blue}{{z}^{2} \cdot \frac{-0.5}{y}} \]
    6. Step-by-step derivation
      1. associate-*r/28.5%

        \[\leadsto \color{blue}{\frac{{z}^{2} \cdot -0.5}{y}} \]
      2. clear-num28.5%

        \[\leadsto \color{blue}{\frac{1}{\frac{y}{{z}^{2} \cdot -0.5}}} \]
    7. Applied egg-rr28.5%

      \[\leadsto \color{blue}{\frac{1}{\frac{y}{{z}^{2} \cdot -0.5}}} \]
    8. Step-by-step derivation
      1. clear-num28.5%

        \[\leadsto \color{blue}{\frac{{z}^{2} \cdot -0.5}{y}} \]
      2. associate-/l*28.5%

        \[\leadsto \color{blue}{{z}^{2} \cdot \frac{-0.5}{y}} \]
      3. metadata-eval28.5%

        \[\leadsto {z}^{2} \cdot \frac{\color{blue}{\frac{1}{-2}}}{y} \]
      4. associate-/r*28.5%

        \[\leadsto {z}^{2} \cdot \color{blue}{\frac{1}{-2 \cdot y}} \]
      5. *-commutative28.5%

        \[\leadsto {z}^{2} \cdot \frac{1}{\color{blue}{y \cdot -2}} \]
      6. div-inv28.5%

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

        \[\leadsto \frac{\color{blue}{z \cdot z}}{y \cdot -2} \]
      8. times-frac30.1%

        \[\leadsto \color{blue}{\frac{z}{y} \cdot \frac{z}{-2}} \]
    9. Applied egg-rr30.1%

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

    if -5.0000000000000002e-135 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64)))

    1. Initial program 61.6%

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{{x}^{2} + {y}^{2}}{y}} \]
    4. Step-by-step derivation
      1. associate-*r/42.3%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{0.5 \cdot \color{blue}{{\left(\mathsf{hypot}\left(x, y\right)\right)}^{2}}}{y} \]
      10. associate-*l/42.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 85.5% accurate, 0.7× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \begin{array}{l} \mathbf{if}\;y\_m \leq 1.95 \cdot 10^{+145}:\\ \;\;\;\;\frac{\left(x \cdot x + y\_m \cdot y\_m\right) - z \cdot z}{y\_m \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;y\_m \cdot 0.5\\ \end{array} \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (*
  y_s
  (if (<= y_m 1.95e+145)
    (/ (- (+ (* x x) (* y_m y_m)) (* z z)) (* y_m 2.0))
    (* y_m 0.5))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (y_m <= 1.95e+145) {
		tmp = (((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0);
	} else {
		tmp = y_m * 0.5;
	}
	return y_s * tmp;
}
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z)
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y_m <= 1.95d+145) then
        tmp = (((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0d0)
    else
        tmp = y_m * 0.5d0
    end if
    code = y_s * tmp
end function
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) {
	double tmp;
	if (y_m <= 1.95e+145) {
		tmp = (((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0);
	} else {
		tmp = y_m * 0.5;
	}
	return y_s * tmp;
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z):
	tmp = 0
	if y_m <= 1.95e+145:
		tmp = (((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0)
	else:
		tmp = y_m * 0.5
	return y_s * tmp
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	tmp = 0.0
	if (y_m <= 1.95e+145)
		tmp = Float64(Float64(Float64(Float64(x * x) + Float64(y_m * y_m)) - Float64(z * z)) / Float64(y_m * 2.0));
	else
		tmp = Float64(y_m * 0.5);
	end
	return Float64(y_s * tmp)
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp_2 = code(y_s, x, y_m, z)
	tmp = 0.0;
	if (y_m <= 1.95e+145)
		tmp = (((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0);
	else
		tmp = y_m * 0.5;
	end
	tmp_2 = y_s * tmp;
end
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_] := N[(y$95$s * If[LessEqual[y$95$m, 1.95e+145], N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y$95$m * y$95$m), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y$95$m * 2.0), $MachinePrecision]), $MachinePrecision], N[(y$95$m * 0.5), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;y\_m \leq 1.95 \cdot 10^{+145}:\\
\;\;\;\;\frac{\left(x \cdot x + y\_m \cdot y\_m\right) - z \cdot z}{y\_m \cdot 2}\\

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


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

    1. Initial program 72.7%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Add Preprocessing

    if 1.9499999999999999e145 < y

    1. Initial program 4.4%

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

      \[\leadsto \color{blue}{0.5 \cdot y} \]
    4. Step-by-step derivation
      1. *-commutative66.2%

        \[\leadsto \color{blue}{y \cdot 0.5} \]
    5. Simplified66.2%

      \[\leadsto \color{blue}{y \cdot 0.5} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 51.6% accurate, 1.2× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \begin{array}{l} \mathbf{if}\;y\_m \leq 5 \cdot 10^{-29}:\\ \;\;\;\;\frac{z}{y\_m} \cdot \frac{z}{-2}\\ \mathbf{else}:\\ \;\;\;\;y\_m \cdot 0.5\\ \end{array} \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (* y_s (if (<= y_m 5e-29) (* (/ z y_m) (/ z -2.0)) (* y_m 0.5))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (y_m <= 5e-29) {
		tmp = (z / y_m) * (z / -2.0);
	} else {
		tmp = y_m * 0.5;
	}
	return y_s * tmp;
}
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z)
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y_m <= 5d-29) then
        tmp = (z / y_m) * (z / (-2.0d0))
    else
        tmp = y_m * 0.5d0
    end if
    code = y_s * tmp
end function
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) {
	double tmp;
	if (y_m <= 5e-29) {
		tmp = (z / y_m) * (z / -2.0);
	} else {
		tmp = y_m * 0.5;
	}
	return y_s * tmp;
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z):
	tmp = 0
	if y_m <= 5e-29:
		tmp = (z / y_m) * (z / -2.0)
	else:
		tmp = y_m * 0.5
	return y_s * tmp
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	tmp = 0.0
	if (y_m <= 5e-29)
		tmp = Float64(Float64(z / y_m) * Float64(z / -2.0));
	else
		tmp = Float64(y_m * 0.5);
	end
	return Float64(y_s * tmp)
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp_2 = code(y_s, x, y_m, z)
	tmp = 0.0;
	if (y_m <= 5e-29)
		tmp = (z / y_m) * (z / -2.0);
	else
		tmp = y_m * 0.5;
	end
	tmp_2 = y_s * tmp;
end
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_] := N[(y$95$s * If[LessEqual[y$95$m, 5e-29], N[(N[(z / y$95$m), $MachinePrecision] * N[(z / -2.0), $MachinePrecision]), $MachinePrecision], N[(y$95$m * 0.5), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;y\_m \leq 5 \cdot 10^{-29}:\\
\;\;\;\;\frac{z}{y\_m} \cdot \frac{z}{-2}\\

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


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

    1. Initial program 69.4%

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{{z}^{2}}{y}} \]
    4. Step-by-step derivation
      1. associate-*r/35.6%

        \[\leadsto \color{blue}{\frac{-0.5 \cdot {z}^{2}}{y}} \]
      2. metadata-eval35.6%

        \[\leadsto \frac{\color{blue}{\left(-0.5\right)} \cdot {z}^{2}}{y} \]
      3. distribute-lft-neg-in35.6%

        \[\leadsto \frac{\color{blue}{-0.5 \cdot {z}^{2}}}{y} \]
      4. *-commutative35.6%

        \[\leadsto \frac{-\color{blue}{{z}^{2} \cdot 0.5}}{y} \]
      5. distribute-neg-frac35.6%

        \[\leadsto \color{blue}{-\frac{{z}^{2} \cdot 0.5}{y}} \]
      6. associate-*r/35.6%

        \[\leadsto -\color{blue}{{z}^{2} \cdot \frac{0.5}{y}} \]
      7. distribute-rgt-neg-in35.6%

        \[\leadsto \color{blue}{{z}^{2} \cdot \left(-\frac{0.5}{y}\right)} \]
      8. distribute-neg-frac35.6%

        \[\leadsto {z}^{2} \cdot \color{blue}{\frac{-0.5}{y}} \]
      9. metadata-eval35.6%

        \[\leadsto {z}^{2} \cdot \frac{\color{blue}{-0.5}}{y} \]
    5. Simplified35.6%

      \[\leadsto \color{blue}{{z}^{2} \cdot \frac{-0.5}{y}} \]
    6. Step-by-step derivation
      1. associate-*r/35.6%

        \[\leadsto \color{blue}{\frac{{z}^{2} \cdot -0.5}{y}} \]
      2. clear-num35.6%

        \[\leadsto \color{blue}{\frac{1}{\frac{y}{{z}^{2} \cdot -0.5}}} \]
    7. Applied egg-rr35.6%

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

        \[\leadsto \color{blue}{\frac{{z}^{2} \cdot -0.5}{y}} \]
      2. associate-/l*35.6%

        \[\leadsto \color{blue}{{z}^{2} \cdot \frac{-0.5}{y}} \]
      3. metadata-eval35.6%

        \[\leadsto {z}^{2} \cdot \frac{\color{blue}{\frac{1}{-2}}}{y} \]
      4. associate-/r*35.6%

        \[\leadsto {z}^{2} \cdot \color{blue}{\frac{1}{-2 \cdot y}} \]
      5. *-commutative35.6%

        \[\leadsto {z}^{2} \cdot \frac{1}{\color{blue}{y \cdot -2}} \]
      6. div-inv35.6%

        \[\leadsto \color{blue}{\frac{{z}^{2}}{y \cdot -2}} \]
      7. unpow235.6%

        \[\leadsto \frac{\color{blue}{z \cdot z}}{y \cdot -2} \]
      8. times-frac37.1%

        \[\leadsto \color{blue}{\frac{z}{y} \cdot \frac{z}{-2}} \]
    9. Applied egg-rr37.1%

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

    if 4.99999999999999986e-29 < y

    1. Initial program 52.9%

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

      \[\leadsto \color{blue}{0.5 \cdot y} \]
    4. Step-by-step derivation
      1. *-commutative54.5%

        \[\leadsto \color{blue}{y \cdot 0.5} \]
    5. Simplified54.5%

      \[\leadsto \color{blue}{y \cdot 0.5} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 51.6% accurate, 1.2× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \begin{array}{l} \mathbf{if}\;y\_m \leq 1.2 \cdot 10^{-28}:\\ \;\;\;\;z \cdot \left(z \cdot \frac{-0.5}{y\_m}\right)\\ \mathbf{else}:\\ \;\;\;\;y\_m \cdot 0.5\\ \end{array} \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (* y_s (if (<= y_m 1.2e-28) (* z (* z (/ -0.5 y_m))) (* y_m 0.5))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (y_m <= 1.2e-28) {
		tmp = z * (z * (-0.5 / y_m));
	} else {
		tmp = y_m * 0.5;
	}
	return y_s * tmp;
}
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z)
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y_m <= 1.2d-28) then
        tmp = z * (z * ((-0.5d0) / y_m))
    else
        tmp = y_m * 0.5d0
    end if
    code = y_s * tmp
end function
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) {
	double tmp;
	if (y_m <= 1.2e-28) {
		tmp = z * (z * (-0.5 / y_m));
	} else {
		tmp = y_m * 0.5;
	}
	return y_s * tmp;
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z):
	tmp = 0
	if y_m <= 1.2e-28:
		tmp = z * (z * (-0.5 / y_m))
	else:
		tmp = y_m * 0.5
	return y_s * tmp
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	tmp = 0.0
	if (y_m <= 1.2e-28)
		tmp = Float64(z * Float64(z * Float64(-0.5 / y_m)));
	else
		tmp = Float64(y_m * 0.5);
	end
	return Float64(y_s * tmp)
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp_2 = code(y_s, x, y_m, z)
	tmp = 0.0;
	if (y_m <= 1.2e-28)
		tmp = z * (z * (-0.5 / y_m));
	else
		tmp = y_m * 0.5;
	end
	tmp_2 = y_s * tmp;
end
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_] := N[(y$95$s * If[LessEqual[y$95$m, 1.2e-28], N[(z * N[(z * N[(-0.5 / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y$95$m * 0.5), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

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

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


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

    1. Initial program 69.4%

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{{z}^{2}}{y}} \]
    4. Step-by-step derivation
      1. associate-*r/35.6%

        \[\leadsto \color{blue}{\frac{-0.5 \cdot {z}^{2}}{y}} \]
      2. metadata-eval35.6%

        \[\leadsto \frac{\color{blue}{\left(-0.5\right)} \cdot {z}^{2}}{y} \]
      3. distribute-lft-neg-in35.6%

        \[\leadsto \frac{\color{blue}{-0.5 \cdot {z}^{2}}}{y} \]
      4. *-commutative35.6%

        \[\leadsto \frac{-\color{blue}{{z}^{2} \cdot 0.5}}{y} \]
      5. distribute-neg-frac35.6%

        \[\leadsto \color{blue}{-\frac{{z}^{2} \cdot 0.5}{y}} \]
      6. associate-*r/35.6%

        \[\leadsto -\color{blue}{{z}^{2} \cdot \frac{0.5}{y}} \]
      7. distribute-rgt-neg-in35.6%

        \[\leadsto \color{blue}{{z}^{2} \cdot \left(-\frac{0.5}{y}\right)} \]
      8. distribute-neg-frac35.6%

        \[\leadsto {z}^{2} \cdot \color{blue}{\frac{-0.5}{y}} \]
      9. metadata-eval35.6%

        \[\leadsto {z}^{2} \cdot \frac{\color{blue}{-0.5}}{y} \]
    5. Simplified35.6%

      \[\leadsto \color{blue}{{z}^{2} \cdot \frac{-0.5}{y}} \]
    6. Step-by-step derivation
      1. associate-*r/35.6%

        \[\leadsto \color{blue}{\frac{{z}^{2} \cdot -0.5}{y}} \]
      2. clear-num35.6%

        \[\leadsto \color{blue}{\frac{1}{\frac{y}{{z}^{2} \cdot -0.5}}} \]
    7. Applied egg-rr35.6%

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

        \[\leadsto \color{blue}{\frac{{z}^{2} \cdot -0.5}{y}} \]
      2. associate-/l*35.6%

        \[\leadsto \color{blue}{{z}^{2} \cdot \frac{-0.5}{y}} \]
      3. unpow235.6%

        \[\leadsto \color{blue}{\left(z \cdot z\right)} \cdot \frac{-0.5}{y} \]
      4. metadata-eval35.6%

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

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

        \[\leadsto \left(z \cdot z\right) \cdot \frac{1}{\color{blue}{y \cdot -2}} \]
      7. associate-*l*37.1%

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

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

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

        \[\leadsto z \cdot \left(z \cdot \frac{\color{blue}{-0.5}}{y}\right) \]
    9. Applied egg-rr37.1%

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

    if 1.2000000000000001e-28 < y

    1. Initial program 52.9%

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

      \[\leadsto \color{blue}{0.5 \cdot y} \]
    4. Step-by-step derivation
      1. *-commutative54.5%

        \[\leadsto \color{blue}{y \cdot 0.5} \]
    5. Simplified54.5%

      \[\leadsto \color{blue}{y \cdot 0.5} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 35.6% accurate, 1.2× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \begin{array}{l} \mathbf{if}\;x \leq 7.6 \cdot 10^{+173}:\\ \;\;\;\;y\_m \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{x \cdot z}{y\_m}\\ \end{array} \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (* y_s (if (<= x 7.6e+173) (* y_m 0.5) (* 0.5 (/ (* x z) y_m)))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (x <= 7.6e+173) {
		tmp = y_m * 0.5;
	} else {
		tmp = 0.5 * ((x * z) / y_m);
	}
	return y_s * tmp;
}
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z)
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= 7.6d+173) then
        tmp = y_m * 0.5d0
    else
        tmp = 0.5d0 * ((x * z) / y_m)
    end if
    code = y_s * tmp
end function
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) {
	double tmp;
	if (x <= 7.6e+173) {
		tmp = y_m * 0.5;
	} else {
		tmp = 0.5 * ((x * z) / y_m);
	}
	return y_s * tmp;
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z):
	tmp = 0
	if x <= 7.6e+173:
		tmp = y_m * 0.5
	else:
		tmp = 0.5 * ((x * z) / y_m)
	return y_s * tmp
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	tmp = 0.0
	if (x <= 7.6e+173)
		tmp = Float64(y_m * 0.5);
	else
		tmp = Float64(0.5 * Float64(Float64(x * z) / y_m));
	end
	return Float64(y_s * tmp)
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp_2 = code(y_s, x, y_m, z)
	tmp = 0.0;
	if (x <= 7.6e+173)
		tmp = y_m * 0.5;
	else
		tmp = 0.5 * ((x * z) / y_m);
	end
	tmp_2 = y_s * tmp;
end
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_] := N[(y$95$s * If[LessEqual[x, 7.6e+173], N[(y$95$m * 0.5), $MachinePrecision], N[(0.5 * N[(N[(x * z), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;x \leq 7.6 \cdot 10^{+173}:\\
\;\;\;\;y\_m \cdot 0.5\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{x \cdot z}{y\_m}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 7.60000000000000022e173

    1. Initial program 64.7%

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

      \[\leadsto \color{blue}{0.5 \cdot y} \]
    4. Step-by-step derivation
      1. *-commutative39.3%

        \[\leadsto \color{blue}{y \cdot 0.5} \]
    5. Simplified39.3%

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

    if 7.60000000000000022e173 < x

    1. Initial program 67.1%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Step-by-step derivation
      1. remove-double-neg67.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-out67.1%

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

        \[\leadsto \color{blue}{-\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{\left(-y\right) \cdot 2}} \]
      4. distribute-frac-neg67.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-167.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-out67.1%

        \[\leadsto \frac{-1 \cdot \left(\left(x \cdot x + y \cdot y\right) - z \cdot z\right)}{\color{blue}{-y \cdot 2}} \]
      7. *-commutative67.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-in67.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-frac67.1%

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

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

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}}{y} \]
    3. Simplified75.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. prod-diff67.1%

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

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

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

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

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

      \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\mathsf{fma}\left(y + z, y - z, \mathsf{fma}\left(-z, z, {z}^{2}\right)\right)}\right)}{y} \]
    7. Step-by-step derivation
      1. add-sqr-sqrt67.5%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y + z, y - z, \mathsf{fma}\left(-z, z, {z}^{2}\right)\right)\right)} \cdot \sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y + z, y - z, \mathsf{fma}\left(-z, z, {z}^{2}\right)\right)\right)}}}{y} \]
      2. associate-/l*67.5%

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

      \[\leadsto 0.5 \cdot \color{blue}{\left(\mathsf{hypot}\left(x, y + z\right) \cdot \frac{\mathsf{hypot}\left(x, y + z\right)}{y}\right)} \]
    9. Taylor expanded in x around inf 79.3%

      \[\leadsto 0.5 \cdot \left(\mathsf{hypot}\left(x, y + z\right) \cdot \color{blue}{\frac{x}{y}}\right) \]
    10. Taylor expanded in z around inf 27.6%

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

Alternative 7: 40.1% accurate, 1.2× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \begin{array}{l} \mathbf{if}\;y\_m \leq 4.7 \cdot 10^{-20}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{z}{y\_m}\right)\\ \mathbf{else}:\\ \;\;\;\;y\_m \cdot 0.5\\ \end{array} \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (* y_s (if (<= y_m 4.7e-20) (* 0.5 (* x (/ z y_m))) (* y_m 0.5))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (y_m <= 4.7e-20) {
		tmp = 0.5 * (x * (z / y_m));
	} else {
		tmp = y_m * 0.5;
	}
	return y_s * tmp;
}
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z)
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y_m <= 4.7d-20) then
        tmp = 0.5d0 * (x * (z / y_m))
    else
        tmp = y_m * 0.5d0
    end if
    code = y_s * tmp
end function
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) {
	double tmp;
	if (y_m <= 4.7e-20) {
		tmp = 0.5 * (x * (z / y_m));
	} else {
		tmp = y_m * 0.5;
	}
	return y_s * tmp;
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z):
	tmp = 0
	if y_m <= 4.7e-20:
		tmp = 0.5 * (x * (z / y_m))
	else:
		tmp = y_m * 0.5
	return y_s * tmp
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	tmp = 0.0
	if (y_m <= 4.7e-20)
		tmp = Float64(0.5 * Float64(x * Float64(z / y_m)));
	else
		tmp = Float64(y_m * 0.5);
	end
	return Float64(y_s * tmp)
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp_2 = code(y_s, x, y_m, z)
	tmp = 0.0;
	if (y_m <= 4.7e-20)
		tmp = 0.5 * (x * (z / y_m));
	else
		tmp = y_m * 0.5;
	end
	tmp_2 = y_s * tmp;
end
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_] := N[(y$95$s * If[LessEqual[y$95$m, 4.7e-20], N[(0.5 * N[(x * N[(z / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y$95$m * 0.5), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

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

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


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

    1. Initial program 70.0%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Step-by-step derivation
      1. remove-double-neg70.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-out70.0%

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

        \[\leadsto \color{blue}{-\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{\left(-y\right) \cdot 2}} \]
      4. distribute-frac-neg70.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-170.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-out70.0%

        \[\leadsto \frac{-1 \cdot \left(\left(x \cdot x + y \cdot y\right) - z \cdot z\right)}{\color{blue}{-y \cdot 2}} \]
      7. *-commutative70.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-in70.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-frac70.0%

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

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

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}}{y} \]
    3. Simplified72.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. prod-diff55.9%

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y + z, y - z, \mathsf{fma}\left(-z, z, {z}^{2}\right)\right)\right)} \cdot \sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y + z, y - z, \mathsf{fma}\left(-z, z, {z}^{2}\right)\right)\right)}}}{y} \]
      2. associate-/l*42.2%

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

      \[\leadsto 0.5 \cdot \color{blue}{\left(\mathsf{hypot}\left(x, y + z\right) \cdot \frac{\mathsf{hypot}\left(x, y + z\right)}{y}\right)} \]
    9. Taylor expanded in x around inf 19.7%

      \[\leadsto 0.5 \cdot \left(\mathsf{hypot}\left(x, y + z\right) \cdot \color{blue}{\frac{x}{y}}\right) \]
    10. Taylor expanded in z around inf 15.9%

      \[\leadsto 0.5 \cdot \color{blue}{\frac{x \cdot z}{y}} \]
    11. Step-by-step derivation
      1. associate-/l*16.9%

        \[\leadsto 0.5 \cdot \color{blue}{\left(x \cdot \frac{z}{y}\right)} \]
    12. Simplified16.9%

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

    if 4.70000000000000015e-20 < y

    1. Initial program 50.0%

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

      \[\leadsto \color{blue}{0.5 \cdot y} \]
    4. Step-by-step derivation
      1. *-commutative57.6%

        \[\leadsto \color{blue}{y \cdot 0.5} \]
    5. Simplified57.6%

      \[\leadsto \color{blue}{y \cdot 0.5} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 8: 34.2% accurate, 5.0× speedup?

\[\begin{array}{l} 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} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z) :precision binary64 (* y_s (* y_m 0.5)))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	return y_s * (y_m * 0.5);
}
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z)
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    code = y_s * (y_m * 0.5d0)
end function
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) {
	return y_s * (y_m * 0.5);
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z):
	return y_s * (y_m * 0.5)
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	return Float64(y_s * Float64(y_m * 0.5))
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp = code(y_s, x, y_m, z)
	tmp = y_s * (y_m * 0.5);
end
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_] := N[(y$95$s * N[(y$95$m * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
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 64.9%

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

    \[\leadsto \color{blue}{0.5 \cdot y} \]
  4. Step-by-step derivation
    1. *-commutative37.2%

      \[\leadsto \color{blue}{y \cdot 0.5} \]
  5. Simplified37.2%

    \[\leadsto \color{blue}{y \cdot 0.5} \]
  6. Add Preprocessing

Alternative 9: 3.0% accurate, 5.0× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \left(x \cdot 0.5\right) \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z) :precision binary64 (* y_s (* x 0.5)))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	return y_s * (x * 0.5);
}
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z)
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    code = y_s * (x * 0.5d0)
end function
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) {
	return y_s * (x * 0.5);
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z):
	return y_s * (x * 0.5)
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	return Float64(y_s * Float64(x * 0.5))
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp = code(y_s, x, y_m, z)
	tmp = y_s * (x * 0.5);
end
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_] := N[(y$95$s * N[(x * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

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

    \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
  2. Step-by-step derivation
    1. remove-double-neg64.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-out64.9%

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

      \[\leadsto \color{blue}{-\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{\left(-y\right) \cdot 2}} \]
    4. distribute-frac-neg64.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-164.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-out64.9%

      \[\leadsto \frac{-1 \cdot \left(\left(x \cdot x + y \cdot y\right) - z \cdot z\right)}{\color{blue}{-y \cdot 2}} \]
    7. *-commutative64.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-in64.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-frac64.9%

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

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

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

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

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

    \[\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. prod-diff52.4%

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y + z, y - z, \mathsf{fma}\left(-z, z, {z}^{2}\right)\right)\right)} \cdot \sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y + z, y - z, \mathsf{fma}\left(-z, z, {z}^{2}\right)\right)\right)}}}{y} \]
    2. associate-/l*42.3%

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

    \[\leadsto 0.5 \cdot \color{blue}{\left(\mathsf{hypot}\left(x, y + z\right) \cdot \frac{\mathsf{hypot}\left(x, y + z\right)}{y}\right)} \]
  9. Taylor expanded in x around inf 18.0%

    \[\leadsto 0.5 \cdot \left(\mathsf{hypot}\left(x, y + z\right) \cdot \color{blue}{\frac{x}{y}}\right) \]
  10. Taylor expanded in y around inf 2.9%

    \[\leadsto 0.5 \cdot \color{blue}{x} \]
  11. Final simplification2.9%

    \[\leadsto x \cdot 0.5 \]
  12. Add Preprocessing

Developer target: 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 2024103 
(FPCore (x y z)
  :name "Diagrams.TwoD.Apollonian:initialConfig from diagrams-contrib-1.3.0.5, A"
  :precision binary64

  :alt
  (- (* y 0.5) (* (* (/ 0.5 y) (+ z x)) (- z x)))

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