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

Percentage Accurate: 68.6% → 82.9%
Time: 14.5s
Alternatives: 8
Speedup: 1.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 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: 68.6% 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: 82.9% 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}\\ t_1 := \frac{-z}{t_0}\\ y_s \cdot \begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{+182}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\mathsf{hypot}\left(x, y_m\right), \frac{\mathsf{hypot}\left(x, y_m\right)}{t_0}, z \cdot t_1\right) + \mathsf{fma}\left(t_1, z, z \cdot \frac{z}{t_0}\right)}{t_0}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(y_m - z \cdot \frac{z}{y_m}\right)\\ \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))) (t_1 (/ (- z) t_0)))
   (*
    y_s
    (if (<= (* z z) 1e+182)
      (/
       (+
        (fma (hypot x y_m) (/ (hypot x y_m) t_0) (* z t_1))
        (fma t_1 z (* z (/ z t_0))))
       t_0)
      (* 0.5 (- y_m (* z (/ z y_m))))))))
y_m = fabs(y);
y_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double t_0 = sqrt((y_m * 2.0));
	double t_1 = -z / t_0;
	double tmp;
	if ((z * z) <= 1e+182) {
		tmp = (fma(hypot(x, y_m), (hypot(x, y_m) / t_0), (z * t_1)) + fma(t_1, z, (z * (z / t_0)))) / t_0;
	} else {
		tmp = 0.5 * (y_m - (z * (z / y_m)));
	}
	return y_s * tmp;
}
y_m = abs(y)
y_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	t_0 = sqrt(Float64(y_m * 2.0))
	t_1 = Float64(Float64(-z) / t_0)
	tmp = 0.0
	if (Float64(z * z) <= 1e+182)
		tmp = Float64(Float64(fma(hypot(x, y_m), Float64(hypot(x, y_m) / t_0), Float64(z * t_1)) + fma(t_1, z, Float64(z * Float64(z / t_0)))) / t_0);
	else
		tmp = Float64(0.5 * Float64(y_m - Float64(z * Float64(z / 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_] := Block[{t$95$0 = N[Sqrt[N[(y$95$m * 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[((-z) / t$95$0), $MachinePrecision]}, N[(y$95$s * If[LessEqual[N[(z * z), $MachinePrecision], 1e+182], N[(N[(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[(z * t$95$1), $MachinePrecision]), $MachinePrecision] + N[(t$95$1 * z + N[(z * N[(z / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], N[(0.5 * N[(y$95$m - N[(z * N[(z / 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 := \sqrt{y_m \cdot 2}\\
t_1 := \frac{-z}{t_0}\\
y_s \cdot \begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+182}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{hypot}\left(x, y_m\right), \frac{\mathsf{hypot}\left(x, y_m\right)}{t_0}, z \cdot t_1\right) + \mathsf{fma}\left(t_1, z, z \cdot \frac{z}{t_0}\right)}{t_0}\\

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


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 z z) < 1.0000000000000001e182

    1. Initial program 80.7%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-un-lft-identity80.7%

        \[\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-sqrt48.2%

        \[\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-frac48.1%

        \[\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-sqrt48.1%

        \[\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. pow248.1%

        \[\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-def48.1%

        \[\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. pow248.1%

        \[\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}} \]
    4. Applied egg-rr48.1%

      \[\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}}} \]
    5. Step-by-step derivation
      1. associate-*l/48.1%

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

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

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

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

        \[\leadsto \frac{\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}}}{\sqrt{y \cdot 2}} \]
      3. *-un-lft-identity48.1%

        \[\leadsto \frac{\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}}}{\sqrt{y \cdot 2}} \]
      4. times-frac54.2%

        \[\leadsto \frac{\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}}}{\sqrt{y \cdot 2}} \]
      5. unpow254.2%

        \[\leadsto \frac{\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}}}{\sqrt{y \cdot 2}} \]
      6. *-un-lft-identity54.2%

        \[\leadsto \frac{\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}}}}{\sqrt{y \cdot 2}} \]
      7. times-frac55.1%

        \[\leadsto \frac{\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}}}}{\sqrt{y \cdot 2}} \]
      8. prod-diff55.1%

        \[\leadsto \frac{\color{blue}{\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)}}{\sqrt{y \cdot 2}} \]
    8. Applied egg-rr55.1%

      \[\leadsto \frac{\color{blue}{\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)}}{\sqrt{y \cdot 2}} \]

    if 1.0000000000000001e182 < (*.f64 z z)

    1. Initial program 52.4%

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{{y}^{2}}{y} - \frac{{z}^{2}}{y}\right)} \]
      2. sub-neg58.2%

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

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

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

        \[\leadsto 0.5 \cdot \left(\frac{y}{\color{blue}{1}} + \left(-\frac{{z}^{2}}{y}\right)\right) \]
      6. /-rgt-identity67.1%

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

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

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

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

        \[\leadsto 0.5 \cdot \left(y - \frac{\color{blue}{\left(-z\right) \cdot \left(-z\right)}}{y}\right) \]
      3. div-inv67.1%

        \[\leadsto 0.5 \cdot \left(y - \color{blue}{\left(\left(-z\right) \cdot \left(-z\right)\right) \cdot \frac{1}{y}}\right) \]
      4. sqr-neg67.1%

        \[\leadsto 0.5 \cdot \left(y - \color{blue}{\left(z \cdot z\right)} \cdot \frac{1}{y}\right) \]
      5. associate-*l*81.6%

        \[\leadsto 0.5 \cdot \left(y - \color{blue}{z \cdot \left(z \cdot \frac{1}{y}\right)}\right) \]
      6. div-inv81.6%

        \[\leadsto 0.5 \cdot \left(y - z \cdot \color{blue}{\frac{z}{y}}\right) \]
    7. Applied egg-rr81.6%

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

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

Alternative 2: 90.4% 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 1.75 \cdot 10^{+162}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y_m - z, z + y_m, x \cdot x\right)}{y_m \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(y_m - z \cdot \frac{z}{y_m}\right)\\ \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 1.75e+162)
    (/ (fma (- y_m z) (+ z y_m) (* x x)) (* y_m 2.0))
    (* 0.5 (- y_m (* z (/ z y_m)))))))
y_m = fabs(y);
y_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (y_m <= 1.75e+162) {
		tmp = fma((y_m - z), (z + y_m), (x * x)) / (y_m * 2.0);
	} else {
		tmp = 0.5 * (y_m - (z * (z / y_m)));
	}
	return y_s * tmp;
}
y_m = abs(y)
y_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	tmp = 0.0
	if (y_m <= 1.75e+162)
		tmp = Float64(fma(Float64(y_m - z), Float64(z + y_m), Float64(x * x)) / Float64(y_m * 2.0));
	else
		tmp = Float64(0.5 * Float64(y_m - Float64(z * Float64(z / 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, 1.75e+162], N[(N[(N[(y$95$m - z), $MachinePrecision] * N[(z + y$95$m), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] / N[(y$95$m * 2.0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y$95$m - N[(z * N[(z / 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 1.75 \cdot 10^{+162}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y_m - z, z + y_m, x \cdot x\right)}{y_m \cdot 2}\\

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


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

    1. Initial program 78.5%

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

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

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

        \[\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.1%

        \[\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-def81.3%

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

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

        \[\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-neg81.3%

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

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

    if 1.75000000000000009e162 < y

    1. Initial program 8.9%

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(\color{blue}{\frac{y}{\frac{y}{y}}} + \left(-\frac{{z}^{2}}{y}\right)\right) \]
      5. *-inverses75.2%

        \[\leadsto 0.5 \cdot \left(\frac{y}{\color{blue}{1}} + \left(-\frac{{z}^{2}}{y}\right)\right) \]
      6. /-rgt-identity75.2%

        \[\leadsto 0.5 \cdot \left(\color{blue}{y} + \left(-\frac{{z}^{2}}{y}\right)\right) \]
      7. sub-neg75.2%

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

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

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

        \[\leadsto 0.5 \cdot \left(y - \frac{\color{blue}{\left(-z\right) \cdot \left(-z\right)}}{y}\right) \]
      3. div-inv75.2%

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

        \[\leadsto 0.5 \cdot \left(y - \color{blue}{\left(z \cdot z\right)} \cdot \frac{1}{y}\right) \]
      5. associate-*l*89.8%

        \[\leadsto 0.5 \cdot \left(y - \color{blue}{z \cdot \left(z \cdot \frac{1}{y}\right)}\right) \]
      6. div-inv89.7%

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

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

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

Alternative 3: 88.7% accurate, 0.7× speedup?

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

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


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

    1. Initial program 79.5%

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

    if 1.1999999999999999e143 < y

    1. Initial program 18.7%

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{{y}^{2}}{y} - \frac{{z}^{2}}{y}\right)} \]
      2. sub-neg18.7%

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

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

        \[\leadsto 0.5 \cdot \left(\color{blue}{\frac{y}{\frac{y}{y}}} + \left(-\frac{{z}^{2}}{y}\right)\right) \]
      5. *-inverses72.5%

        \[\leadsto 0.5 \cdot \left(\frac{y}{\color{blue}{1}} + \left(-\frac{{z}^{2}}{y}\right)\right) \]
      6. /-rgt-identity72.5%

        \[\leadsto 0.5 \cdot \left(\color{blue}{y} + \left(-\frac{{z}^{2}}{y}\right)\right) \]
      7. sub-neg72.5%

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

      \[\leadsto \color{blue}{0.5 \cdot \left(y - \frac{{z}^{2}}{y}\right)} \]
    6. Step-by-step derivation
      1. unpow272.5%

        \[\leadsto 0.5 \cdot \left(y - \frac{\color{blue}{z \cdot z}}{y}\right) \]
      2. sqr-neg72.5%

        \[\leadsto 0.5 \cdot \left(y - \frac{\color{blue}{\left(-z\right) \cdot \left(-z\right)}}{y}\right) \]
      3. div-inv72.5%

        \[\leadsto 0.5 \cdot \left(y - \color{blue}{\left(\left(-z\right) \cdot \left(-z\right)\right) \cdot \frac{1}{y}}\right) \]
      4. sqr-neg72.5%

        \[\leadsto 0.5 \cdot \left(y - \color{blue}{\left(z \cdot z\right)} \cdot \frac{1}{y}\right) \]
      5. associate-*l*83.8%

        \[\leadsto 0.5 \cdot \left(y - \color{blue}{z \cdot \left(z \cdot \frac{1}{y}\right)}\right) \]
      6. div-inv83.8%

        \[\leadsto 0.5 \cdot \left(y - z \cdot \color{blue}{\frac{z}{y}}\right) \]
    7. Applied egg-rr83.8%

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

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

Alternative 4: 71.6% accurate, 1.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}\;x \leq 9.2 \cdot 10^{+16}:\\ \;\;\;\;0.5 \cdot \left(y_m - z \cdot \frac{z}{y_m}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y_m} \cdot \frac{x}{2}\\ \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 (<= x 9.2e+16) (* 0.5 (- y_m (* z (/ z y_m)))) (* (/ x y_m) (/ x 2.0)))))
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 <= 9.2e+16) {
		tmp = 0.5 * (y_m - (z * (z / y_m)));
	} else {
		tmp = (x / y_m) * (x / 2.0);
	}
	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 <= 9.2d+16) then
        tmp = 0.5d0 * (y_m - (z * (z / y_m)))
    else
        tmp = (x / y_m) * (x / 2.0d0)
    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 <= 9.2e+16) {
		tmp = 0.5 * (y_m - (z * (z / y_m)));
	} else {
		tmp = (x / y_m) * (x / 2.0);
	}
	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 <= 9.2e+16:
		tmp = 0.5 * (y_m - (z * (z / y_m)))
	else:
		tmp = (x / y_m) * (x / 2.0)
	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 <= 9.2e+16)
		tmp = Float64(0.5 * Float64(y_m - Float64(z * Float64(z / y_m))));
	else
		tmp = Float64(Float64(x / y_m) * Float64(x / 2.0));
	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 <= 9.2e+16)
		tmp = 0.5 * (y_m - (z * (z / y_m)));
	else
		tmp = (x / y_m) * (x / 2.0);
	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, 9.2e+16], N[(0.5 * N[(y$95$m - N[(z * N[(z / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x / y$95$m), $MachinePrecision] * N[(x / 2.0), $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 9.2 \cdot 10^{+16}:\\
\;\;\;\;0.5 \cdot \left(y_m - z \cdot \frac{z}{y_m}\right)\\

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


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

    1. Initial program 73.3%

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(\color{blue}{\frac{y}{\frac{y}{y}}} + \left(-\frac{{z}^{2}}{y}\right)\right) \]
      5. *-inverses64.2%

        \[\leadsto 0.5 \cdot \left(\frac{y}{\color{blue}{1}} + \left(-\frac{{z}^{2}}{y}\right)\right) \]
      6. /-rgt-identity64.2%

        \[\leadsto 0.5 \cdot \left(\color{blue}{y} + \left(-\frac{{z}^{2}}{y}\right)\right) \]
      7. sub-neg64.2%

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

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

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

        \[\leadsto 0.5 \cdot \left(y - \frac{\color{blue}{\left(-z\right) \cdot \left(-z\right)}}{y}\right) \]
      3. div-inv64.2%

        \[\leadsto 0.5 \cdot \left(y - \color{blue}{\left(\left(-z\right) \cdot \left(-z\right)\right) \cdot \frac{1}{y}}\right) \]
      4. sqr-neg64.2%

        \[\leadsto 0.5 \cdot \left(y - \color{blue}{\left(z \cdot z\right)} \cdot \frac{1}{y}\right) \]
      5. associate-*l*70.6%

        \[\leadsto 0.5 \cdot \left(y - \color{blue}{z \cdot \left(z \cdot \frac{1}{y}\right)}\right) \]
      6. div-inv70.7%

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

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

    if 9.2e16 < x

    1. Initial program 62.9%

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

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

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

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

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

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

Alternative 5: 71.6% accurate, 1.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}\;x \leq 3.6 \cdot 10^{+16}:\\ \;\;\;\;0.5 \cdot \left(y_m - z \cdot \frac{z}{y_m}\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{1}{\frac{y_m}{x \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 (<= x 3.6e+16)
    (* 0.5 (- y_m (* z (/ z y_m))))
    (* x (/ 1.0 (/ y_m (* x 0.5)))))))
y_m = fabs(y);
y_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double tmp;
	if (x <= 3.6e+16) {
		tmp = 0.5 * (y_m - (z * (z / y_m)));
	} else {
		tmp = x * (1.0 / (y_m / (x * 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 (x <= 3.6d+16) then
        tmp = 0.5d0 * (y_m - (z * (z / y_m)))
    else
        tmp = x * (1.0d0 / (y_m / (x * 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 (x <= 3.6e+16) {
		tmp = 0.5 * (y_m - (z * (z / y_m)));
	} else {
		tmp = x * (1.0 / (y_m / (x * 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 x <= 3.6e+16:
		tmp = 0.5 * (y_m - (z * (z / y_m)))
	else:
		tmp = x * (1.0 / (y_m / (x * 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 (x <= 3.6e+16)
		tmp = Float64(0.5 * Float64(y_m - Float64(z * Float64(z / y_m))));
	else
		tmp = Float64(x * Float64(1.0 / Float64(y_m / Float64(x * 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 (x <= 3.6e+16)
		tmp = 0.5 * (y_m - (z * (z / y_m)));
	else
		tmp = x * (1.0 / (y_m / (x * 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[x, 3.6e+16], N[(0.5 * N[(y$95$m - N[(z * N[(z / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 / N[(y$95$m / N[(x * 0.5), $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}\;x \leq 3.6 \cdot 10^{+16}:\\
\;\;\;\;0.5 \cdot \left(y_m - z \cdot \frac{z}{y_m}\right)\\

\mathbf{else}:\\
\;\;\;\;x \cdot \frac{1}{\frac{y_m}{x \cdot 0.5}}\\


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

    1. Initial program 73.3%

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(\color{blue}{\frac{y}{\frac{y}{y}}} + \left(-\frac{{z}^{2}}{y}\right)\right) \]
      5. *-inverses64.2%

        \[\leadsto 0.5 \cdot \left(\frac{y}{\color{blue}{1}} + \left(-\frac{{z}^{2}}{y}\right)\right) \]
      6. /-rgt-identity64.2%

        \[\leadsto 0.5 \cdot \left(\color{blue}{y} + \left(-\frac{{z}^{2}}{y}\right)\right) \]
      7. sub-neg64.2%

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

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

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

        \[\leadsto 0.5 \cdot \left(y - \frac{\color{blue}{\left(-z\right) \cdot \left(-z\right)}}{y}\right) \]
      3. div-inv64.2%

        \[\leadsto 0.5 \cdot \left(y - \color{blue}{\left(\left(-z\right) \cdot \left(-z\right)\right) \cdot \frac{1}{y}}\right) \]
      4. sqr-neg64.2%

        \[\leadsto 0.5 \cdot \left(y - \color{blue}{\left(z \cdot z\right)} \cdot \frac{1}{y}\right) \]
      5. associate-*l*70.6%

        \[\leadsto 0.5 \cdot \left(y - \color{blue}{z \cdot \left(z \cdot \frac{1}{y}\right)}\right) \]
      6. div-inv70.7%

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

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

    if 3.6e16 < x

    1. Initial program 62.9%

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

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

        \[\leadsto \color{blue}{{x}^{2} \cdot \frac{1}{y \cdot 2}} \]
      2. metadata-eval61.2%

        \[\leadsto {x}^{2} \cdot \frac{1}{y \cdot \color{blue}{\frac{1}{0.5}}} \]
      3. div-inv61.2%

        \[\leadsto {x}^{2} \cdot \frac{1}{\color{blue}{\frac{y}{0.5}}} \]
      4. clear-num61.2%

        \[\leadsto {x}^{2} \cdot \color{blue}{\frac{0.5}{y}} \]
      5. unpow261.2%

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

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

      \[\leadsto \color{blue}{x \cdot \left(x \cdot \frac{0.5}{y}\right)} \]
    6. Step-by-step derivation
      1. associate-*r/64.7%

        \[\leadsto x \cdot \color{blue}{\frac{x \cdot 0.5}{y}} \]
      2. clear-num64.6%

        \[\leadsto x \cdot \color{blue}{\frac{1}{\frac{y}{x \cdot 0.5}}} \]
    7. Applied egg-rr64.6%

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

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

Alternative 6: 43.5% 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 2400000000000:\\ \;\;\;\;y_m \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(x \cdot \frac{0.5}{y_m}\right)\\ \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 (<= x 2400000000000.0) (* y_m 0.5) (* x (* x (/ 0.5 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 <= 2400000000000.0) {
		tmp = y_m * 0.5;
	} else {
		tmp = x * (x * (0.5 / 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 <= 2400000000000.0d0) then
        tmp = y_m * 0.5d0
    else
        tmp = x * (x * (0.5d0 / 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 <= 2400000000000.0) {
		tmp = y_m * 0.5;
	} else {
		tmp = x * (x * (0.5 / 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 <= 2400000000000.0:
		tmp = y_m * 0.5
	else:
		tmp = x * (x * (0.5 / 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 <= 2400000000000.0)
		tmp = Float64(y_m * 0.5);
	else
		tmp = Float64(x * Float64(x * Float64(0.5 / 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 <= 2400000000000.0)
		tmp = y_m * 0.5;
	else
		tmp = x * (x * (0.5 / 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, 2400000000000.0], N[(y$95$m * 0.5), $MachinePrecision], N[(x * N[(x * N[(0.5 / 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 2400000000000:\\
\;\;\;\;y_m \cdot 0.5\\

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


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

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

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

    if 2.4e12 < x

    1. Initial program 62.9%

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

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

        \[\leadsto \color{blue}{{x}^{2} \cdot \frac{1}{y \cdot 2}} \]
      2. metadata-eval61.2%

        \[\leadsto {x}^{2} \cdot \frac{1}{y \cdot \color{blue}{\frac{1}{0.5}}} \]
      3. div-inv61.2%

        \[\leadsto {x}^{2} \cdot \frac{1}{\color{blue}{\frac{y}{0.5}}} \]
      4. clear-num61.2%

        \[\leadsto {x}^{2} \cdot \color{blue}{\frac{0.5}{y}} \]
      5. unpow261.2%

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

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

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

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

Alternative 7: 43.5% 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 92000000000:\\ \;\;\;\;y_m \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y_m} \cdot \frac{x}{2}\\ \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 (<= x 92000000000.0) (* y_m 0.5) (* (/ x y_m) (/ x 2.0)))))
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 <= 92000000000.0) {
		tmp = y_m * 0.5;
	} else {
		tmp = (x / y_m) * (x / 2.0);
	}
	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 <= 92000000000.0d0) then
        tmp = y_m * 0.5d0
    else
        tmp = (x / y_m) * (x / 2.0d0)
    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 <= 92000000000.0) {
		tmp = y_m * 0.5;
	} else {
		tmp = (x / y_m) * (x / 2.0);
	}
	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 <= 92000000000.0:
		tmp = y_m * 0.5
	else:
		tmp = (x / y_m) * (x / 2.0)
	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 <= 92000000000.0)
		tmp = Float64(y_m * 0.5);
	else
		tmp = Float64(Float64(x / y_m) * Float64(x / 2.0));
	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 <= 92000000000.0)
		tmp = y_m * 0.5;
	else
		tmp = (x / y_m) * (x / 2.0);
	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, 92000000000.0], N[(y$95$m * 0.5), $MachinePrecision], N[(N[(x / y$95$m), $MachinePrecision] * N[(x / 2.0), $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 92000000000:\\
\;\;\;\;y_m \cdot 0.5\\

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


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

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

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

    if 9.2e10 < x

    1. Initial program 62.9%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 92000000000:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} \cdot \frac{x}{2}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 34.9% 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 71.2%

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

    \[\leadsto \color{blue}{0.5 \cdot y} \]
  4. Final simplification35.1%

    \[\leadsto y \cdot 0.5 \]
  5. 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 2024021 
(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)))