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

Percentage Accurate: 69.5% → 92.7%
Time: 9.2s
Alternatives: 7
Speedup: 0.4×

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 7 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.5% 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: 92.7% accurate, 0.0× 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 -2 \cdot 10^{-56}:\\ \;\;\;\;{\left(\frac{z}{\sqrt[3]{y\_m}}\right)}^{2} \cdot \frac{-0.5}{\sqrt[3]{y\_m}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(y\_m + x \cdot \frac{x}{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)) -2e-56)
    (* (pow (/ z (cbrt y_m)) 2.0) (/ -0.5 (cbrt y_m)))
    (* 0.5 (+ y_m (* x (/ x 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)) <= -2e-56) {
		tmp = pow((z / cbrt(y_m)), 2.0) * (-0.5 / cbrt(y_m));
	} else {
		tmp = 0.5 * (y_m + (x * (x / 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 tmp;
	if (((((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0)) <= -2e-56) {
		tmp = Math.pow((z / Math.cbrt(y_m)), 2.0) * (-0.5 / Math.cbrt(y_m));
	} else {
		tmp = 0.5 * (y_m + (x * (x / 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)) <= -2e-56)
		tmp = Float64((Float64(z / cbrt(y_m)) ^ 2.0) * Float64(-0.5 / cbrt(y_m)));
	else
		tmp = Float64(0.5 * Float64(y_m + Float64(x * Float64(x / y_m))));
	end
	return Float64(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], -2e-56], N[(N[Power[N[(z / N[Power[y$95$m, 1/3], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(-0.5 / N[Power[y$95$m, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y$95$m + N[(x * N[(x / y$95$m), $MachinePrecision]), $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 -2 \cdot 10^{-56}:\\
\;\;\;\;{\left(\frac{z}{\sqrt[3]{y\_m}}\right)}^{2} \cdot \frac{-0.5}{\sqrt[3]{y\_m}}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(y\_m + x \cdot \frac{x}{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))) < -2.0000000000000001e-56

    1. Initial program 73.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 inf 26.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{{z}^{2} \cdot -0.5}{y}} \]
      2. add-cube-cbrt26.3%

        \[\leadsto \frac{{z}^{2} \cdot -0.5}{\color{blue}{\left(\sqrt[3]{y} \cdot \sqrt[3]{y}\right) \cdot \sqrt[3]{y}}} \]
      3. times-frac26.3%

        \[\leadsto \color{blue}{\frac{{z}^{2}}{\sqrt[3]{y} \cdot \sqrt[3]{y}} \cdot \frac{-0.5}{\sqrt[3]{y}}} \]
      4. pow226.3%

        \[\leadsto \frac{{z}^{2}}{\color{blue}{{\left(\sqrt[3]{y}\right)}^{2}}} \cdot \frac{-0.5}{\sqrt[3]{y}} \]
    9. Applied egg-rr26.3%

      \[\leadsto \color{blue}{\frac{{z}^{2}}{{\left(\sqrt[3]{y}\right)}^{2}} \cdot \frac{-0.5}{\sqrt[3]{y}}} \]
    10. Step-by-step derivation
      1. *-un-lft-identity26.3%

        \[\leadsto \color{blue}{\left(1 \cdot \frac{{z}^{2}}{{\left(\sqrt[3]{y}\right)}^{2}}\right)} \cdot \frac{-0.5}{\sqrt[3]{y}} \]
      2. add-sqr-sqrt26.3%

        \[\leadsto \left(1 \cdot \color{blue}{\left(\sqrt{\frac{{z}^{2}}{{\left(\sqrt[3]{y}\right)}^{2}}} \cdot \sqrt{\frac{{z}^{2}}{{\left(\sqrt[3]{y}\right)}^{2}}}\right)}\right) \cdot \frac{-0.5}{\sqrt[3]{y}} \]
      3. pow226.3%

        \[\leadsto \left(1 \cdot \color{blue}{{\left(\sqrt{\frac{{z}^{2}}{{\left(\sqrt[3]{y}\right)}^{2}}}\right)}^{2}}\right) \cdot \frac{-0.5}{\sqrt[3]{y}} \]
      4. sqrt-div26.3%

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

        \[\leadsto \left(1 \cdot {\left(\frac{\color{blue}{{z}^{\left(\frac{2}{2}\right)}}}{\sqrt{{\left(\sqrt[3]{y}\right)}^{2}}}\right)}^{2}\right) \cdot \frac{-0.5}{\sqrt[3]{y}} \]
      6. metadata-eval27.2%

        \[\leadsto \left(1 \cdot {\left(\frac{{z}^{\color{blue}{1}}}{\sqrt{{\left(\sqrt[3]{y}\right)}^{2}}}\right)}^{2}\right) \cdot \frac{-0.5}{\sqrt[3]{y}} \]
      7. pow127.2%

        \[\leadsto \left(1 \cdot {\left(\frac{\color{blue}{z}}{\sqrt{{\left(\sqrt[3]{y}\right)}^{2}}}\right)}^{2}\right) \cdot \frac{-0.5}{\sqrt[3]{y}} \]
      8. sqrt-pow127.2%

        \[\leadsto \left(1 \cdot {\left(\frac{z}{\color{blue}{{\left(\sqrt[3]{y}\right)}^{\left(\frac{2}{2}\right)}}}\right)}^{2}\right) \cdot \frac{-0.5}{\sqrt[3]{y}} \]
      9. metadata-eval27.2%

        \[\leadsto \left(1 \cdot {\left(\frac{z}{{\left(\sqrt[3]{y}\right)}^{\color{blue}{1}}}\right)}^{2}\right) \cdot \frac{-0.5}{\sqrt[3]{y}} \]
      10. pow127.2%

        \[\leadsto \left(1 \cdot {\left(\frac{z}{\color{blue}{\sqrt[3]{y}}}\right)}^{2}\right) \cdot \frac{-0.5}{\sqrt[3]{y}} \]
    11. Applied egg-rr27.2%

      \[\leadsto \color{blue}{\left(1 \cdot {\left(\frac{z}{\sqrt[3]{y}}\right)}^{2}\right)} \cdot \frac{-0.5}{\sqrt[3]{y}} \]
    12. Step-by-step derivation
      1. *-lft-identity27.2%

        \[\leadsto \color{blue}{{\left(\frac{z}{\sqrt[3]{y}}\right)}^{2}} \cdot \frac{-0.5}{\sqrt[3]{y}} \]
    13. Simplified27.2%

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

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

    1. Initial program 59.8%

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

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

        \[\leadsto \color{blue}{-\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{\left(-y\right) \cdot 2}} \]
      4. distribute-frac-neg59.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-159.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-out59.8%

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

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

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

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}}{y} \]
    3. Simplified65.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. Taylor expanded in z around 0 46.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(y + \frac{\color{blue}{x \cdot x}}{y}\right) \]
      2. associate-/l*70.1%

        \[\leadsto 0.5 \cdot \left(y + \color{blue}{x \cdot \frac{x}{y}}\right) \]
    10. Applied egg-rr70.1%

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

Alternative 2: 92.0% 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 -2 \cdot 10^{-56}:\\ \;\;\;\;{z}^{2} \cdot \frac{-0.5}{y\_m}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(y\_m + x \cdot \frac{x}{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)) -2e-56)
    (* (pow z 2.0) (/ -0.5 y_m))
    (* 0.5 (+ y_m (* x (/ x 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)) <= -2e-56) {
		tmp = pow(z, 2.0) * (-0.5 / y_m);
	} else {
		tmp = 0.5 * (y_m + (x * (x / 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)) <= (-2d-56)) then
        tmp = (z ** 2.0d0) * ((-0.5d0) / y_m)
    else
        tmp = 0.5d0 * (y_m + (x * (x / 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)) <= -2e-56) {
		tmp = Math.pow(z, 2.0) * (-0.5 / y_m);
	} else {
		tmp = 0.5 * (y_m + (x * (x / 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)) <= -2e-56:
		tmp = math.pow(z, 2.0) * (-0.5 / y_m)
	else:
		tmp = 0.5 * (y_m + (x * (x / 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)) <= -2e-56)
		tmp = Float64((z ^ 2.0) * Float64(-0.5 / y_m));
	else
		tmp = Float64(0.5 * Float64(y_m + Float64(x * Float64(x / 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)) <= -2e-56)
		tmp = (z ^ 2.0) * (-0.5 / y_m);
	else
		tmp = 0.5 * (y_m + (x * (x / 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], -2e-56], N[(N[Power[z, 2.0], $MachinePrecision] * N[(-0.5 / y$95$m), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y$95$m + N[(x * N[(x / y$95$m), $MachinePrecision]), $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 -2 \cdot 10^{-56}:\\
\;\;\;\;{z}^{2} \cdot \frac{-0.5}{y\_m}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(y\_m + x \cdot \frac{x}{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))) < -2.0000000000000001e-56

    1. Initial program 73.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 inf 26.4%

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 59.8%

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

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

        \[\leadsto \color{blue}{-\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{\left(-y\right) \cdot 2}} \]
      4. distribute-frac-neg59.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-159.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-out59.8%

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

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

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

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}}{y} \]
    3. Simplified65.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. Taylor expanded in z around 0 46.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(y + \frac{\color{blue}{x \cdot x}}{y}\right) \]
      2. associate-/l*70.1%

        \[\leadsto 0.5 \cdot \left(y + \color{blue}{x \cdot \frac{x}{y}}\right) \]
    10. Applied egg-rr70.1%

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

Alternative 3: 90.8% 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}\;y\_m \leq 5.8 \cdot 10^{+143}:\\ \;\;\;\;0.5 \cdot \frac{\mathsf{fma}\left(x, x, y\_m \cdot y\_m - z \cdot z\right)}{y\_m}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(y\_m + x \cdot \frac{x}{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 (<= y_m 5.8e+143)
    (* 0.5 (/ (fma x x (- (* y_m y_m) (* z z))) y_m))
    (* 0.5 (+ y_m (* x (/ x 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 (y_m <= 5.8e+143) {
		tmp = 0.5 * (fma(x, x, ((y_m * y_m) - (z * z))) / y_m);
	} else {
		tmp = 0.5 * (y_m + (x * (x / 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 (y_m <= 5.8e+143)
		tmp = Float64(0.5 * Float64(fma(x, x, Float64(Float64(y_m * y_m) - Float64(z * z))) / y_m));
	else
		tmp = Float64(0.5 * Float64(y_m + Float64(x * Float64(x / y_m))));
	end
	return Float64(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, 5.8e+143], N[(0.5 * N[(N[(x * x + N[(N[(y$95$m * y$95$m), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y$95$m + N[(x * N[(x / y$95$m), $MachinePrecision]), $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}\;y\_m \leq 5.8 \cdot 10^{+143}:\\
\;\;\;\;0.5 \cdot \frac{\mathsf{fma}\left(x, x, y\_m \cdot y\_m - z \cdot z\right)}{y\_m}\\

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


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

    1. Initial program 75.8%

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

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

        \[\leadsto \color{blue}{-\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{\left(-y\right) \cdot 2}} \]
      4. distribute-frac-neg75.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-175.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-out75.8%

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

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

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

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

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

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

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

    if 5.7999999999999996e143 < y

    1. Initial program 9.0%

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}}{y} \]
    3. Simplified9.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. Taylor expanded in z around 0 12.7%

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

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

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

        \[\leadsto 0.5 \cdot \frac{\sqrt{x \cdot x + \color{blue}{y \cdot y}} \cdot \sqrt{{x}^{2} + {y}^{2}}}{y} \]
      4. hypot-undefine12.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(y + \frac{\color{blue}{x \cdot x}}{y}\right) \]
      2. associate-/l*87.5%

        \[\leadsto 0.5 \cdot \left(y + \color{blue}{x \cdot \frac{x}{y}}\right) \]
    10. Applied egg-rr87.5%

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

Alternative 4: 92.2% accurate, 0.4× speedup?

\[\begin{array}{l} 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 \cdot z}{y\_m \cdot 2}\\ y\_s \cdot \begin{array}{l} \mathbf{if}\;t\_0 \leq -2 \cdot 10^{-56}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(y\_m + x \cdot \frac{x}{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 (/ (- (+ (* x x) (* y_m y_m)) (* z z)) (* y_m 2.0))))
   (* y_s (if (<= t_0 -2e-56) t_0 (* 0.5 (+ y_m (* x (/ x 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 = (((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0);
	double tmp;
	if (t_0 <= -2e-56) {
		tmp = t_0;
	} else {
		tmp = 0.5 * (y_m + (x * (x / 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) :: t_0
    real(8) :: tmp
    t_0 = (((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0d0)
    if (t_0 <= (-2d-56)) then
        tmp = t_0
    else
        tmp = 0.5d0 * (y_m + (x * (x / 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 t_0 = (((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0);
	double tmp;
	if (t_0 <= -2e-56) {
		tmp = t_0;
	} else {
		tmp = 0.5 * (y_m + (x * (x / 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 = (((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0)
	tmp = 0
	if t_0 <= -2e-56:
		tmp = t_0
	else:
		tmp = 0.5 * (y_m + (x * (x / 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 = Float64(Float64(Float64(Float64(x * x) + Float64(y_m * y_m)) - Float64(z * z)) / Float64(y_m * 2.0))
	tmp = 0.0
	if (t_0 <= -2e-56)
		tmp = t_0;
	else
		tmp = Float64(0.5 * Float64(y_m + Float64(x * Float64(x / 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 = (((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0);
	tmp = 0.0;
	if (t_0 <= -2e-56)
		tmp = t_0;
	else
		tmp = 0.5 * (y_m + (x * (x / 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[(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$s * If[LessEqual[t$95$0, -2e-56], t$95$0, N[(0.5 * N[(y$95$m + N[(x * N[(x / y$95$m), $MachinePrecision]), $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 := \frac{\left(x \cdot x + y\_m \cdot y\_m\right) - z \cdot z}{y\_m \cdot 2}\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{-56}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(y\_m + x \cdot \frac{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))) < -2.0000000000000001e-56

    1. Initial program 73.6%

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

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

    1. Initial program 59.8%

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

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

        \[\leadsto \color{blue}{-\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{\left(-y\right) \cdot 2}} \]
      4. distribute-frac-neg59.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-159.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-out59.8%

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

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

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

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}}{y} \]
    3. Simplified65.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. Taylor expanded in z around 0 46.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(y + \frac{\color{blue}{x \cdot x}}{y}\right) \]
      2. associate-/l*70.1%

        \[\leadsto 0.5 \cdot \left(y + \color{blue}{x \cdot \frac{x}{y}}\right) \]
    10. Applied egg-rr70.1%

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

Alternative 5: 43.4% 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 550000:\\ \;\;\;\;y\_m \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{x}{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 550000.0) (* y_m 0.5) (* 0.5 (* x (/ x 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 <= 550000.0) {
		tmp = y_m * 0.5;
	} else {
		tmp = 0.5 * (x * (x / 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 <= 550000.0d0) then
        tmp = y_m * 0.5d0
    else
        tmp = 0.5d0 * (x * (x / 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 <= 550000.0) {
		tmp = y_m * 0.5;
	} else {
		tmp = 0.5 * (x * (x / 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 <= 550000.0:
		tmp = y_m * 0.5
	else:
		tmp = 0.5 * (x * (x / 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 <= 550000.0)
		tmp = Float64(y_m * 0.5);
	else
		tmp = Float64(0.5 * Float64(x * Float64(x / 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 <= 550000.0)
		tmp = y_m * 0.5;
	else
		tmp = 0.5 * (x * (x / 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, 550000.0], N[(y$95$m * 0.5), $MachinePrecision], N[(0.5 * N[(x * N[(x / 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}\;x \leq 550000:\\
\;\;\;\;y\_m \cdot 0.5\\

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


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

    1. Initial program 65.3%

      \[\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 45.5%

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

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

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

    if 5.5e5 < x

    1. Initial program 65.6%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{{x}^{2} + {y}^{2}} \cdot \sqrt{{x}^{2} + {y}^{2}}}}{y} \]
      2. unpow259.6%

        \[\leadsto 0.5 \cdot \frac{\sqrt{\color{blue}{x \cdot x} + {y}^{2}} \cdot \sqrt{{x}^{2} + {y}^{2}}}{y} \]
      3. unpow259.6%

        \[\leadsto 0.5 \cdot \frac{\sqrt{x \cdot x + \color{blue}{y \cdot y}} \cdot \sqrt{{x}^{2} + {y}^{2}}}{y} \]
      4. hypot-undefine59.6%

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

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

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

        \[\leadsto 0.5 \cdot \frac{\mathsf{hypot}\left(x, y\right) \cdot \color{blue}{\mathsf{hypot}\left(x, y\right)}}{y} \]
      8. unpow259.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{hypot}\left(y, x\right) \cdot \mathsf{hypot}\left(y, x\right)}}{y} \]
      2. add-sqr-sqrt33.6%

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

        \[\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)} \]
    9. Applied egg-rr42.0%

      \[\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)} \]
    10. Step-by-step derivation
      1. unpow242.0%

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

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

      \[\leadsto 0.5 \cdot {\left(\frac{\color{blue}{x}}{\sqrt{y}}\right)}^{2} \]
    13. Step-by-step derivation
      1. unpow234.6%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{y}} \cdot \frac{x}{\sqrt{y}}\right)} \]
      2. frac-times32.0%

        \[\leadsto 0.5 \cdot \color{blue}{\frac{x \cdot x}{\sqrt{y} \cdot \sqrt{y}}} \]
      3. add-sqr-sqrt57.0%

        \[\leadsto 0.5 \cdot \frac{x \cdot x}{\color{blue}{y}} \]
      4. associate-*l/62.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 550000:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{x}{y}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 65.8% accurate, 1.7× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \left(0.5 \cdot \left(y\_m + x \cdot \frac{x}{y\_m}\right)\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 (* 0.5 (+ y_m (* x (/ x y_m))))))
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 * (0.5 * (y_m + (x * (x / y_m))));
}
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 * (0.5d0 * (y_m + (x * (x / y_m))))
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 * (0.5 * (y_m + (x * (x / y_m))));
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
def code(y_s, x, y_m, z):
	return y_s * (0.5 * (y_m + (x * (x / y_m))))
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	return Float64(y_s * Float64(0.5 * Float64(y_m + Float64(x * Float64(x / y_m)))))
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
function tmp = code(y_s, x, y_m, z)
	tmp = y_s * (0.5 * (y_m + (x * (x / y_m))));
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[(0.5 * N[(y$95$m + N[(x * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

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

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

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

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}}{y} \]
  3. Simplified68.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. Taylor expanded in z around 0 47.2%

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

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

      \[\leadsto 0.5 \cdot \frac{\sqrt{\color{blue}{x \cdot x} + {y}^{2}} \cdot \sqrt{{x}^{2} + {y}^{2}}}{y} \]
    3. unpow247.2%

      \[\leadsto 0.5 \cdot \frac{\sqrt{x \cdot x + \color{blue}{y \cdot y}} \cdot \sqrt{{x}^{2} + {y}^{2}}}{y} \]
    4. hypot-undefine47.2%

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

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

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

      \[\leadsto 0.5 \cdot \frac{\mathsf{hypot}\left(x, y\right) \cdot \color{blue}{\mathsf{hypot}\left(x, y\right)}}{y} \]
    8. unpow247.2%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \left(y + \frac{\color{blue}{x \cdot x}}{y}\right) \]
    2. associate-/l*71.6%

      \[\leadsto 0.5 \cdot \left(y + \color{blue}{x \cdot \frac{x}{y}}\right) \]
  10. Applied egg-rr71.6%

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

Alternative 7: 34.3% 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 65.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 39.1%

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

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

    \[\leadsto \color{blue}{y \cdot 0.5} \]
  6. 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 2024089 
(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)))