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

Percentage Accurate: 69.0% → 90.5%
Time: 16.9s
Alternatives: 7
Speedup: 0.9×

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.0% 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: 90.5% accurate, 0.0× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ y_s = \mathsf{copysign}\left(1, y\right) \\ \begin{array}{l} t_0 := \sqrt{y_m \cdot 2}\\ y_s \cdot \begin{array}{l} \mathbf{if}\;y_m \leq 7.5 \cdot 10^{+190}:\\ \;\;\;\;\frac{1}{t_0} \cdot \mathsf{fma}\left(\mathsf{hypot}\left(x, y_m\right), \frac{\mathsf{hypot}\left(x, y_m\right)}{t_0}, \frac{z}{t_0} \cdot \left(-z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;y_m \cdot 0.5\\ \end{array} \end{array} \end{array} \]
y_m = (fabs.f64 y)
y_s = (copysign.f64 1 y)
(FPCore (y_s x y_m z)
 :precision binary64
 (let* ((t_0 (sqrt (* y_m 2.0))))
   (*
    y_s
    (if (<= y_m 7.5e+190)
      (*
       (/ 1.0 t_0)
       (fma (hypot x y_m) (/ (hypot x y_m) t_0) (* (/ z t_0) (- z))))
      (* 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 t_0 = sqrt((y_m * 2.0));
	double tmp;
	if (y_m <= 7.5e+190) {
		tmp = (1.0 / t_0) * fma(hypot(x, y_m), (hypot(x, y_m) / t_0), ((z / t_0) * -z));
	} 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)
	t_0 = sqrt(Float64(y_m * 2.0))
	tmp = 0.0
	if (y_m <= 7.5e+190)
		tmp = Float64(Float64(1.0 / t_0) * fma(hypot(x, y_m), Float64(hypot(x, y_m) / t_0), Float64(Float64(z / t_0) * Float64(-z))));
	else
		tmp = Float64(y_m * 0.5);
	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_] := Block[{t$95$0 = N[Sqrt[N[(y$95$m * 2.0), $MachinePrecision]], $MachinePrecision]}, N[(y$95$s * If[LessEqual[y$95$m, 7.5e+190], N[(N[(1.0 / t$95$0), $MachinePrecision] * N[(N[Sqrt[x ^ 2 + y$95$m ^ 2], $MachinePrecision] * N[(N[Sqrt[x ^ 2 + y$95$m ^ 2], $MachinePrecision] / t$95$0), $MachinePrecision] + N[(N[(z / t$95$0), $MachinePrecision] * (-z)), $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)

\\
\begin{array}{l}
t_0 := \sqrt{y_m \cdot 2}\\
y_s \cdot \begin{array}{l}
\mathbf{if}\;y_m \leq 7.5 \cdot 10^{+190}:\\
\;\;\;\;\frac{1}{t_0} \cdot \mathsf{fma}\left(\mathsf{hypot}\left(x, y_m\right), \frac{\mathsf{hypot}\left(x, y_m\right)}{t_0}, \frac{z}{t_0} \cdot \left(-z\right)\right)\\

\mathbf{else}:\\
\;\;\;\;y_m \cdot 0.5\\


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

    1. Initial program 74.6%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Step-by-step derivation
      1. *-un-lft-identity74.6%

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

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

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

        \[\leadsto \frac{1}{\sqrt{y \cdot 2}} \cdot \frac{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}} - z \cdot z}{\sqrt{y \cdot 2}} \]
      5. pow237.8%

        \[\leadsto \frac{1}{\sqrt{y \cdot 2}} \cdot \frac{\color{blue}{{\left(\sqrt{x \cdot x + y \cdot y}\right)}^{2}} - z \cdot z}{\sqrt{y \cdot 2}} \]
      6. hypot-def37.8%

        \[\leadsto \frac{1}{\sqrt{y \cdot 2}} \cdot \frac{{\color{blue}{\left(\mathsf{hypot}\left(x, y\right)\right)}}^{2} - z \cdot z}{\sqrt{y \cdot 2}} \]
      7. pow237.8%

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

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y \cdot 2}} \cdot \frac{{\left(\mathsf{hypot}\left(x, y\right)\right)}^{2} - {z}^{2}}{\sqrt{y \cdot 2}}} \]
    4. Step-by-step derivation
      1. div-sub36.5%

        \[\leadsto \frac{1}{\sqrt{y \cdot 2}} \cdot \color{blue}{\left(\frac{{\left(\mathsf{hypot}\left(x, y\right)\right)}^{2}}{\sqrt{y \cdot 2}} - \frac{{z}^{2}}{\sqrt{y \cdot 2}}\right)} \]
      2. unpow236.5%

        \[\leadsto \frac{1}{\sqrt{y \cdot 2}} \cdot \left(\frac{\color{blue}{\mathsf{hypot}\left(x, y\right) \cdot \mathsf{hypot}\left(x, y\right)}}{\sqrt{y \cdot 2}} - \frac{{z}^{2}}{\sqrt{y \cdot 2}}\right) \]
      3. *-un-lft-identity36.5%

        \[\leadsto \frac{1}{\sqrt{y \cdot 2}} \cdot \left(\frac{\mathsf{hypot}\left(x, y\right) \cdot \mathsf{hypot}\left(x, y\right)}{\color{blue}{1 \cdot \sqrt{y \cdot 2}}} - \frac{{z}^{2}}{\sqrt{y \cdot 2}}\right) \]
      4. times-frac40.9%

        \[\leadsto \frac{1}{\sqrt{y \cdot 2}} \cdot \left(\color{blue}{\frac{\mathsf{hypot}\left(x, y\right)}{1} \cdot \frac{\mathsf{hypot}\left(x, y\right)}{\sqrt{y \cdot 2}}} - \frac{{z}^{2}}{\sqrt{y \cdot 2}}\right) \]
      5. unpow240.9%

        \[\leadsto \frac{1}{\sqrt{y \cdot 2}} \cdot \left(\frac{\mathsf{hypot}\left(x, y\right)}{1} \cdot \frac{\mathsf{hypot}\left(x, y\right)}{\sqrt{y \cdot 2}} - \frac{\color{blue}{z \cdot z}}{\sqrt{y \cdot 2}}\right) \]
      6. *-un-lft-identity40.9%

        \[\leadsto \frac{1}{\sqrt{y \cdot 2}} \cdot \left(\frac{\mathsf{hypot}\left(x, y\right)}{1} \cdot \frac{\mathsf{hypot}\left(x, y\right)}{\sqrt{y \cdot 2}} - \frac{z \cdot z}{\color{blue}{1 \cdot \sqrt{y \cdot 2}}}\right) \]
      7. times-frac42.4%

        \[\leadsto \frac{1}{\sqrt{y \cdot 2}} \cdot \left(\frac{\mathsf{hypot}\left(x, y\right)}{1} \cdot \frac{\mathsf{hypot}\left(x, y\right)}{\sqrt{y \cdot 2}} - \color{blue}{\frac{z}{1} \cdot \frac{z}{\sqrt{y \cdot 2}}}\right) \]
      8. prod-diff35.7%

        \[\leadsto \frac{1}{\sqrt{y \cdot 2}} \cdot \color{blue}{\left(\mathsf{fma}\left(\frac{\mathsf{hypot}\left(x, y\right)}{1}, \frac{\mathsf{hypot}\left(x, y\right)}{\sqrt{y \cdot 2}}, -\frac{z}{\sqrt{y \cdot 2}} \cdot \frac{z}{1}\right) + \mathsf{fma}\left(-\frac{z}{\sqrt{y \cdot 2}}, \frac{z}{1}, \frac{z}{\sqrt{y \cdot 2}} \cdot \frac{z}{1}\right)\right)} \]
    5. Applied egg-rr35.7%

      \[\leadsto \frac{1}{\sqrt{y \cdot 2}} \cdot \color{blue}{\left(\mathsf{fma}\left(\frac{\mathsf{hypot}\left(x, y\right)}{1}, \frac{\mathsf{hypot}\left(x, y\right)}{\sqrt{y \cdot 2}}, -\frac{z}{\sqrt{y \cdot 2}} \cdot \frac{z}{1}\right) + \mathsf{fma}\left(-\frac{z}{\sqrt{y \cdot 2}}, \frac{z}{1}, \frac{z}{\sqrt{y \cdot 2}} \cdot \frac{z}{1}\right)\right)} \]
    6. Taylor expanded in z around 0 36.1%

      \[\leadsto \frac{1}{\sqrt{y \cdot 2}} \cdot \left(\mathsf{fma}\left(\frac{\mathsf{hypot}\left(x, y\right)}{1}, \frac{\mathsf{hypot}\left(x, y\right)}{\sqrt{y \cdot 2}}, -\frac{z}{\sqrt{y \cdot 2}} \cdot \frac{z}{1}\right) + \color{blue}{{z}^{2} \cdot \left(-1 \cdot \left(\sqrt{\frac{1}{y}} \cdot \frac{1}{\sqrt{2}}\right) + \sqrt{\frac{1}{y}} \cdot \frac{1}{\sqrt{2}}\right)}\right) \]
    7. Step-by-step derivation
      1. distribute-lft1-in36.1%

        \[\leadsto \frac{1}{\sqrt{y \cdot 2}} \cdot \left(\mathsf{fma}\left(\frac{\mathsf{hypot}\left(x, y\right)}{1}, \frac{\mathsf{hypot}\left(x, y\right)}{\sqrt{y \cdot 2}}, -\frac{z}{\sqrt{y \cdot 2}} \cdot \frac{z}{1}\right) + {z}^{2} \cdot \color{blue}{\left(\left(-1 + 1\right) \cdot \left(\sqrt{\frac{1}{y}} \cdot \frac{1}{\sqrt{2}}\right)\right)}\right) \]
      2. metadata-eval36.1%

        \[\leadsto \frac{1}{\sqrt{y \cdot 2}} \cdot \left(\mathsf{fma}\left(\frac{\mathsf{hypot}\left(x, y\right)}{1}, \frac{\mathsf{hypot}\left(x, y\right)}{\sqrt{y \cdot 2}}, -\frac{z}{\sqrt{y \cdot 2}} \cdot \frac{z}{1}\right) + {z}^{2} \cdot \left(\color{blue}{0} \cdot \left(\sqrt{\frac{1}{y}} \cdot \frac{1}{\sqrt{2}}\right)\right)\right) \]
      3. mul0-lft36.1%

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

      \[\leadsto \frac{1}{\sqrt{y \cdot 2}} \cdot \left(\mathsf{fma}\left(\frac{\mathsf{hypot}\left(x, y\right)}{1}, \frac{\mathsf{hypot}\left(x, y\right)}{\sqrt{y \cdot 2}}, -\frac{z}{\sqrt{y \cdot 2}} \cdot \frac{z}{1}\right) + \color{blue}{{z}^{2} \cdot 0}\right) \]
    9. Taylor expanded in z around 0 44.1%

      \[\leadsto \frac{1}{\sqrt{y \cdot 2}} \cdot \left(\mathsf{fma}\left(\frac{\mathsf{hypot}\left(x, y\right)}{1}, \frac{\mathsf{hypot}\left(x, y\right)}{\sqrt{y \cdot 2}}, -\frac{z}{\sqrt{y \cdot 2}} \cdot \frac{z}{1}\right) + \color{blue}{0}\right) \]

    if 7.4999999999999994e190 < y

    1. Initial program 4.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 7.5 \cdot 10^{+190}:\\ \;\;\;\;\frac{1}{\sqrt{y \cdot 2}} \cdot \mathsf{fma}\left(\mathsf{hypot}\left(x, y\right), \frac{\mathsf{hypot}\left(x, y\right)}{\sqrt{y \cdot 2}}, \frac{z}{\sqrt{y \cdot 2}} \cdot \left(-z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]

Alternative 2: 88.2% 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 2.8 \cdot 10^{+149}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y_m - z, y_m + z, x \cdot x\right)}{y_m \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;y_m \cdot 0.5\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
y_s = (copysign.f64 1 y)
(FPCore (y_s x y_m z)
 :precision binary64
 (*
  y_s
  (if (<= y_m 2.8e+149)
    (/ (fma (- y_m z) (+ y_m z) (* x x)) (* 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 <= 2.8e+149) {
		tmp = fma((y_m - z), (y_m + z), (x * x)) / (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 <= 2.8e+149)
		tmp = Float64(fma(Float64(y_m - z), Float64(y_m + z), Float64(x * x)) / Float64(y_m * 2.0));
	else
		tmp = Float64(y_m * 0.5);
	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, 2.8e+149], N[(N[(N[(y$95$m - z), $MachinePrecision] * N[(y$95$m + z), $MachinePrecision] + N[(x * x), $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 2.8 \cdot 10^{+149}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y_m - z, y_m + z, x \cdot x\right)}{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 < 2.7999999999999999e149

    1. Initial program 77.8%

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

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

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

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

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

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

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

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

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

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

    if 2.7999999999999999e149 < y

    1. Initial program 10.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 2.8 \cdot 10^{+149}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y - z, y + z, x \cdot x\right)}{y \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]

Alternative 3: 54.9% accurate, 0.9× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ y_s = \mathsf{copysign}\left(1, y\right) \\ \begin{array}{l} t_0 := \frac{\left(y_m - z\right) \cdot \left(y_m + z\right)}{y_m \cdot 2}\\ y_s \cdot \begin{array}{l} \mathbf{if}\;x \leq 5.7 \cdot 10^{+31}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5 \cdot 10^{+75}:\\ \;\;\;\;\frac{x \cdot \frac{x}{2}}{y_m}\\ \mathbf{elif}\;x \leq 1.25 \cdot 10^{+107}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{2} \cdot \frac{x}{y_m}\\ \end{array} \end{array} \end{array} \]
y_m = (fabs.f64 y)
y_s = (copysign.f64 1 y)
(FPCore (y_s x y_m z)
 :precision binary64
 (let* ((t_0 (/ (* (- y_m z) (+ y_m z)) (* y_m 2.0))))
   (*
    y_s
    (if (<= x 5.7e+31)
      t_0
      (if (<= x 5e+75)
        (/ (* x (/ x 2.0)) y_m)
        (if (<= x 1.25e+107) t_0 (* (/ x 2.0) (/ 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 = ((y_m - z) * (y_m + z)) / (y_m * 2.0);
	double tmp;
	if (x <= 5.7e+31) {
		tmp = t_0;
	} else if (x <= 5e+75) {
		tmp = (x * (x / 2.0)) / y_m;
	} else if (x <= 1.25e+107) {
		tmp = t_0;
	} else {
		tmp = (x / 2.0) * (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 = ((y_m - z) * (y_m + z)) / (y_m * 2.0d0)
    if (x <= 5.7d+31) then
        tmp = t_0
    else if (x <= 5d+75) then
        tmp = (x * (x / 2.0d0)) / y_m
    else if (x <= 1.25d+107) then
        tmp = t_0
    else
        tmp = (x / 2.0d0) * (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 = ((y_m - z) * (y_m + z)) / (y_m * 2.0);
	double tmp;
	if (x <= 5.7e+31) {
		tmp = t_0;
	} else if (x <= 5e+75) {
		tmp = (x * (x / 2.0)) / y_m;
	} else if (x <= 1.25e+107) {
		tmp = t_0;
	} else {
		tmp = (x / 2.0) * (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 = ((y_m - z) * (y_m + z)) / (y_m * 2.0)
	tmp = 0
	if x <= 5.7e+31:
		tmp = t_0
	elif x <= 5e+75:
		tmp = (x * (x / 2.0)) / y_m
	elif x <= 1.25e+107:
		tmp = t_0
	else:
		tmp = (x / 2.0) * (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(y_m - z) * Float64(y_m + z)) / Float64(y_m * 2.0))
	tmp = 0.0
	if (x <= 5.7e+31)
		tmp = t_0;
	elseif (x <= 5e+75)
		tmp = Float64(Float64(x * Float64(x / 2.0)) / y_m);
	elseif (x <= 1.25e+107)
		tmp = t_0;
	else
		tmp = Float64(Float64(x / 2.0) * 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 = ((y_m - z) * (y_m + z)) / (y_m * 2.0);
	tmp = 0.0;
	if (x <= 5.7e+31)
		tmp = t_0;
	elseif (x <= 5e+75)
		tmp = (x * (x / 2.0)) / y_m;
	elseif (x <= 1.25e+107)
		tmp = t_0;
	else
		tmp = (x / 2.0) * (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[(y$95$m - z), $MachinePrecision] * N[(y$95$m + z), $MachinePrecision]), $MachinePrecision] / N[(y$95$m * 2.0), $MachinePrecision]), $MachinePrecision]}, N[(y$95$s * If[LessEqual[x, 5.7e+31], t$95$0, If[LessEqual[x, 5e+75], N[(N[(x * N[(x / 2.0), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision], If[LessEqual[x, 1.25e+107], t$95$0, N[(N[(x / 2.0), $MachinePrecision] * N[(x / y$95$m), $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(y_m - z\right) \cdot \left(y_m + z\right)}{y_m \cdot 2}\\
y_s \cdot \begin{array}{l}
\mathbf{if}\;x \leq 5.7 \cdot 10^{+31}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 5 \cdot 10^{+75}:\\
\;\;\;\;\frac{x \cdot \frac{x}{2}}{y_m}\\

\mathbf{elif}\;x \leq 1.25 \cdot 10^{+107}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{2} \cdot \frac{x}{y_m}\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < 5.7e31 or 5.0000000000000002e75 < x < 1.25e107

    1. Initial program 73.3%

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(y + \left(-z\right), y - \left(-z\right), x \cdot x\right)}}{y \cdot 2} \]
      6. sub-neg77.0%

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

        \[\leadsto \frac{\mathsf{fma}\left(y - z, \color{blue}{y + \left(-\left(-z\right)\right)}, x \cdot x\right)}{y \cdot 2} \]
      8. remove-double-neg77.0%

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

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

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

    if 5.7e31 < x < 5.0000000000000002e75

    1. Initial program 76.4%

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

      \[\leadsto \frac{\color{blue}{{x}^{2}}}{y \cdot 2} \]
    3. Step-by-step derivation
      1. unpow263.5%

        \[\leadsto \frac{\color{blue}{x \cdot x}}{y \cdot 2} \]
      2. times-frac63.3%

        \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{2}} \]
    4. Applied egg-rr63.3%

      \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{2}} \]
    5. Step-by-step derivation
      1. *-commutative63.3%

        \[\leadsto \color{blue}{\frac{x}{2} \cdot \frac{x}{y}} \]
      2. associate-*r/63.5%

        \[\leadsto \color{blue}{\frac{\frac{x}{2} \cdot x}{y}} \]
    6. Simplified63.5%

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

    if 1.25e107 < x

    1. Initial program 54.2%

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

      \[\leadsto \frac{\color{blue}{{x}^{2}}}{y \cdot 2} \]
    3. Step-by-step derivation
      1. unpow264.3%

        \[\leadsto \frac{\color{blue}{x \cdot x}}{y \cdot 2} \]
      2. times-frac73.1%

        \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{2}} \]
    4. Applied egg-rr73.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 5.7 \cdot 10^{+31}:\\ \;\;\;\;\frac{\left(y - z\right) \cdot \left(y + z\right)}{y \cdot 2}\\ \mathbf{elif}\;x \leq 5 \cdot 10^{+75}:\\ \;\;\;\;\frac{x \cdot \frac{x}{2}}{y}\\ \mathbf{elif}\;x \leq 1.25 \cdot 10^{+107}:\\ \;\;\;\;\frac{\left(y - z\right) \cdot \left(y + z\right)}{y \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{2} \cdot \frac{x}{y}\\ \end{array} \]

Alternative 4: 85.9% accurate, 0.9× 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 2.8 \cdot 10^{+149}:\\ \;\;\;\;\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 1 y)
(FPCore (y_s x y_m z)
 :precision binary64
 (*
  y_s
  (if (<= y_m 2.8e+149)
    (/ (- (+ (* 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 <= 2.8e+149) {
		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 <= 2.8d+149) 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 <= 2.8e+149) {
		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 <= 2.8e+149:
		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 <= 2.8e+149)
		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 <= 2.8e+149)
		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, 2.8e+149], 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 2.8 \cdot 10^{+149}:\\
\;\;\;\;\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 < 2.7999999999999999e149

    1. Initial program 77.8%

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

    if 2.7999999999999999e149 < y

    1. Initial program 10.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 2.8 \cdot 10^{+149}:\\ \;\;\;\;\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]

Alternative 5: 54.0% accurate, 1.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 3.45 \cdot 10^{+50}:\\ \;\;\;\;x \cdot \left(x \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 1 y)
(FPCore (y_s x y_m z)
 :precision binary64
 (* y_s (if (<= y_m 3.45e+50) (* x (* x (/ 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 <= 3.45e+50) {
		tmp = x * (x * (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 <= 3.45d+50) then
        tmp = x * (x * (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 <= 3.45e+50) {
		tmp = x * (x * (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 <= 3.45e+50:
		tmp = x * (x * (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 <= 3.45e+50)
		tmp = Float64(x * Float64(x * 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 <= 3.45e+50)
		tmp = x * (x * (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, 3.45e+50], N[(x * N[(x * 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 3.45 \cdot 10^{+50}:\\
\;\;\;\;x \cdot \left(x \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 < 3.45000000000000016e50

    1. Initial program 78.8%

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

      \[\leadsto \frac{\color{blue}{{x}^{2}}}{y \cdot 2} \]
    3. Step-by-step derivation
      1. div-inv38.9%

        \[\leadsto \color{blue}{{x}^{2} \cdot \frac{1}{y \cdot 2}} \]
      2. unpow238.9%

        \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \frac{1}{y \cdot 2} \]
      3. *-commutative38.9%

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

        \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\frac{\frac{1}{2}}{y}} \]
      5. metadata-eval38.9%

        \[\leadsto \left(x \cdot x\right) \cdot \frac{\color{blue}{0.5}}{y} \]
      6. associate-*l*40.7%

        \[\leadsto \color{blue}{x \cdot \left(x \cdot \frac{0.5}{y}\right)} \]
    4. Applied egg-rr40.7%

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

    if 3.45000000000000016e50 < y

    1. Initial program 38.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 3.45 \cdot 10^{+50}:\\ \;\;\;\;x \cdot \left(x \cdot \frac{0.5}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]

Alternative 6: 54.0% accurate, 1.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 3.8 \cdot 10^{+50}:\\ \;\;\;\;\frac{x}{2 \cdot \frac{y_m}{x}}\\ \mathbf{else}:\\ \;\;\;\;y_m \cdot 0.5\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
y_s = (copysign.f64 1 y)
(FPCore (y_s x y_m z)
 :precision binary64
 (* y_s (if (<= y_m 3.8e+50) (/ x (* 2.0 (/ y_m x))) (* 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 <= 3.8e+50) {
		tmp = x / (2.0 * (y_m / x));
	} 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 <= 3.8d+50) then
        tmp = x / (2.0d0 * (y_m / x))
    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 <= 3.8e+50) {
		tmp = x / (2.0 * (y_m / x));
	} 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 <= 3.8e+50:
		tmp = x / (2.0 * (y_m / x))
	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 <= 3.8e+50)
		tmp = Float64(x / Float64(2.0 * Float64(y_m / x)));
	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 <= 3.8e+50)
		tmp = x / (2.0 * (y_m / x));
	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, 3.8e+50], N[(x / N[(2.0 * N[(y$95$m / x), $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 3.8 \cdot 10^{+50}:\\
\;\;\;\;\frac{x}{2 \cdot \frac{y_m}{x}}\\

\mathbf{else}:\\
\;\;\;\;y_m \cdot 0.5\\


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

    1. Initial program 78.8%

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

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

        \[\leadsto \frac{\color{blue}{x \cdot x}}{y \cdot 2} \]
      2. times-frac40.7%

        \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{2}} \]
    4. Applied egg-rr40.7%

      \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{2}} \]
    5. Step-by-step derivation
      1. clear-num40.6%

        \[\leadsto \color{blue}{\frac{1}{\frac{y}{x}}} \cdot \frac{x}{2} \]
      2. frac-times40.7%

        \[\leadsto \color{blue}{\frac{1 \cdot x}{\frac{y}{x} \cdot 2}} \]
      3. *-un-lft-identity40.7%

        \[\leadsto \frac{\color{blue}{x}}{\frac{y}{x} \cdot 2} \]
    6. Applied egg-rr40.7%

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

    if 3.79999999999999987e50 < y

    1. Initial program 38.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 3.8 \cdot 10^{+50}:\\ \;\;\;\;\frac{x}{2 \cdot \frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]

Alternative 7: 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 1 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 70.2%

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

    \[\leadsto \color{blue}{0.5 \cdot y} \]
  3. Final simplification31.9%

    \[\leadsto y \cdot 0.5 \]

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

  :herbie-target
  (- (* y 0.5) (* (* (/ 0.5 y) (+ z x)) (- z x)))

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