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

Percentage Accurate: 69.2% → 97.0%
Time: 10.3s
Alternatives: 10
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 10 alternatives:

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

Initial Program: 69.2% accurate, 1.0× speedup?

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

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

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

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


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

    1. Initial program 74.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.9999999999999996e-187 < y

    1. Initial program 69.0%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-sub68.0%

        \[\leadsto \color{blue}{\frac{x \cdot x + y \cdot y}{y \cdot 2} - \frac{z \cdot z}{y \cdot 2}} \]
      2. add-sqr-sqrt68.0%

        \[\leadsto \frac{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}}{y \cdot 2} - \frac{z \cdot z}{y \cdot 2} \]
      3. associate-/l*68.1%

        \[\leadsto \color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \frac{\sqrt{x \cdot x + y \cdot y}}{y \cdot 2}} - \frac{z \cdot z}{y \cdot 2} \]
      4. fma-neg68.1%

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

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

        \[\leadsto \mathsf{fma}\left(\mathsf{hypot}\left(x, y\right), \frac{\color{blue}{\mathsf{hypot}\left(x, y\right)}}{y \cdot 2}, -\frac{z \cdot z}{y \cdot 2}\right) \]
      7. div-inv88.8%

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

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

        \[\leadsto \mathsf{fma}\left(\mathsf{hypot}\left(x, y\right), \frac{\mathsf{hypot}\left(x, y\right)}{y \cdot 2}, -{z}^{2} \cdot \frac{1}{\color{blue}{2 \cdot y}}\right) \]
      10. associate-/r*88.8%

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

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

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

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

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

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

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

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

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

\mathbf{elif}\;y\_m \leq 1.25 \cdot 10^{+18}:\\
\;\;\;\;\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 \left(z \cdot \frac{-1}{y\_m}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < 7.60000000000000026e-195

    1. Initial program 74.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 0 62.8%

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

        \[\leadsto \color{blue}{\frac{0.5 \cdot \left({x}^{2} - {z}^{2}\right)}{y}} \]
      2. *-commutative62.8%

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

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

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

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

        \[\leadsto \left(x \cdot x - \color{blue}{z \cdot z}\right) \cdot \frac{0.5}{y} \]
      3. difference-of-squares69.8%

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

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

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

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

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

    if 7.60000000000000026e-195 < y < 1.25e18

    1. Initial program 93.3%

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

    if 1.25e18 < y

    1. Initial program 49.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 73.1% accurate, 0.6× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \begin{array}{l} \mathbf{if}\;x \leq 7 \cdot 10^{+132}:\\ \;\;\;\;0.5 \cdot \left(y\_m - \frac{z}{\frac{y\_m}{z}}\right)\\ \mathbf{elif}\;x \leq 2.4 \cdot 10^{+171}:\\ \;\;\;\;\frac{x}{y\_m \cdot \frac{2}{x}}\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{+188}:\\ \;\;\;\;0.5 \cdot \left(y\_m - z \cdot \frac{z}{y\_m}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{2}{x} \cdot \frac{y\_m}{x}}\\ \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 7e+132)
    (* 0.5 (- y_m (/ z (/ y_m z))))
    (if (<= x 2.4e+171)
      (/ x (* y_m (/ 2.0 x)))
      (if (<= x 2.7e+188)
        (* 0.5 (- y_m (* z (/ z y_m))))
        (/ 1.0 (* (/ 2.0 x) (/ y_m x))))))))
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 <= 7e+132) {
		tmp = 0.5 * (y_m - (z / (y_m / z)));
	} else if (x <= 2.4e+171) {
		tmp = x / (y_m * (2.0 / x));
	} else if (x <= 2.7e+188) {
		tmp = 0.5 * (y_m - (z * (z / y_m)));
	} else {
		tmp = 1.0 / ((2.0 / x) * (y_m / x));
	}
	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 <= 7d+132) then
        tmp = 0.5d0 * (y_m - (z / (y_m / z)))
    else if (x <= 2.4d+171) then
        tmp = x / (y_m * (2.0d0 / x))
    else if (x <= 2.7d+188) then
        tmp = 0.5d0 * (y_m - (z * (z / y_m)))
    else
        tmp = 1.0d0 / ((2.0d0 / x) * (y_m / x))
    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 <= 7e+132) {
		tmp = 0.5 * (y_m - (z / (y_m / z)));
	} else if (x <= 2.4e+171) {
		tmp = x / (y_m * (2.0 / x));
	} else if (x <= 2.7e+188) {
		tmp = 0.5 * (y_m - (z * (z / y_m)));
	} else {
		tmp = 1.0 / ((2.0 / x) * (y_m / x));
	}
	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 <= 7e+132:
		tmp = 0.5 * (y_m - (z / (y_m / z)))
	elif x <= 2.4e+171:
		tmp = x / (y_m * (2.0 / x))
	elif x <= 2.7e+188:
		tmp = 0.5 * (y_m - (z * (z / y_m)))
	else:
		tmp = 1.0 / ((2.0 / x) * (y_m / x))
	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 <= 7e+132)
		tmp = Float64(0.5 * Float64(y_m - Float64(z / Float64(y_m / z))));
	elseif (x <= 2.4e+171)
		tmp = Float64(x / Float64(y_m * Float64(2.0 / x)));
	elseif (x <= 2.7e+188)
		tmp = Float64(0.5 * Float64(y_m - Float64(z * Float64(z / y_m))));
	else
		tmp = Float64(1.0 / Float64(Float64(2.0 / x) * Float64(y_m / x)));
	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 <= 7e+132)
		tmp = 0.5 * (y_m - (z / (y_m / z)));
	elseif (x <= 2.4e+171)
		tmp = x / (y_m * (2.0 / x));
	elseif (x <= 2.7e+188)
		tmp = 0.5 * (y_m - (z * (z / y_m)));
	else
		tmp = 1.0 / ((2.0 / x) * (y_m / x));
	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, 7e+132], N[(0.5 * N[(y$95$m - N[(z / N[(y$95$m / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.4e+171], N[(x / N[(y$95$m * N[(2.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.7e+188], N[(0.5 * N[(y$95$m - N[(z * N[(z / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(2.0 / x), $MachinePrecision] * N[(y$95$m / x), $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 7 \cdot 10^{+132}:\\
\;\;\;\;0.5 \cdot \left(y\_m - \frac{z}{\frac{y\_m}{z}}\right)\\

\mathbf{elif}\;x \leq 2.4 \cdot 10^{+171}:\\
\;\;\;\;\frac{x}{y\_m \cdot \frac{2}{x}}\\

\mathbf{elif}\;x \leq 2.7 \cdot 10^{+188}:\\
\;\;\;\;0.5 \cdot \left(y\_m - z \cdot \frac{z}{y\_m}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{2}{x} \cdot \frac{y\_m}{x}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < 7.00000000000000041e132

    1. Initial program 75.2%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \left(y - \color{blue}{z \cdot \frac{z}{y}}\right) \]
    8. Step-by-step derivation
      1. clear-num74.5%

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

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

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

    if 7.00000000000000041e132 < x < 2.39999999999999998e171

    1. Initial program 99.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 inf 96.0%

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

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

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

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

        \[\leadsto \color{blue}{\frac{x}{2} \cdot \frac{x}{y}} \]
      2. clear-num96.4%

        \[\leadsto \color{blue}{\frac{1}{\frac{2}{x}}} \cdot \frac{x}{y} \]
      3. frac-times96.6%

        \[\leadsto \color{blue}{\frac{1 \cdot x}{\frac{2}{x} \cdot y}} \]
      4. *-un-lft-identity96.6%

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

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

    if 2.39999999999999998e171 < x < 2.7e188

    1. Initial program 2.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 68.1%

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

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

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

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

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

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

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

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

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

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

    if 2.7e188 < x

    1. Initial program 50.5%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 7 \cdot 10^{+132}:\\ \;\;\;\;0.5 \cdot \left(y - \frac{z}{\frac{y}{z}}\right)\\ \mathbf{elif}\;x \leq 2.4 \cdot 10^{+171}:\\ \;\;\;\;\frac{x}{y \cdot \frac{2}{x}}\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{+188}:\\ \;\;\;\;0.5 \cdot \left(y - z \cdot \frac{z}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{2}{x} \cdot \frac{y}{x}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 73.1% accurate, 0.6× 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 4 \cdot 10^{+133}:\\ \;\;\;\;0.5 \cdot \left(y\_m - \frac{z}{\frac{y\_m}{z}}\right)\\ \mathbf{elif}\;x \leq 4.4 \cdot 10^{+170}:\\ \;\;\;\;\frac{x}{y\_m \cdot \frac{2}{x}}\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{+188}:\\ \;\;\;\;0.5 \cdot \left(y\_m - z \cdot \frac{z}{y\_m}\right)\\ \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 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (*
  y_s
  (if (<= x 4e+133)
    (* 0.5 (- y_m (/ z (/ y_m z))))
    (if (<= x 4.4e+170)
      (/ x (* y_m (/ 2.0 x)))
      (if (<= x 2.8e+188)
        (* 0.5 (- y_m (* z (/ z y_m))))
        (* 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 <= 4e+133) {
		tmp = 0.5 * (y_m - (z / (y_m / z)));
	} else if (x <= 4.4e+170) {
		tmp = x / (y_m * (2.0 / x));
	} else if (x <= 2.8e+188) {
		tmp = 0.5 * (y_m - (z * (z / y_m)));
	} 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 <= 4d+133) then
        tmp = 0.5d0 * (y_m - (z / (y_m / z)))
    else if (x <= 4.4d+170) then
        tmp = x / (y_m * (2.0d0 / x))
    else if (x <= 2.8d+188) then
        tmp = 0.5d0 * (y_m - (z * (z / y_m)))
    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 <= 4e+133) {
		tmp = 0.5 * (y_m - (z / (y_m / z)));
	} else if (x <= 4.4e+170) {
		tmp = x / (y_m * (2.0 / x));
	} else if (x <= 2.8e+188) {
		tmp = 0.5 * (y_m - (z * (z / y_m)));
	} 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 <= 4e+133:
		tmp = 0.5 * (y_m - (z / (y_m / z)))
	elif x <= 4.4e+170:
		tmp = x / (y_m * (2.0 / x))
	elif x <= 2.8e+188:
		tmp = 0.5 * (y_m - (z * (z / y_m)))
	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 <= 4e+133)
		tmp = Float64(0.5 * Float64(y_m - Float64(z / Float64(y_m / z))));
	elseif (x <= 4.4e+170)
		tmp = Float64(x / Float64(y_m * Float64(2.0 / x)));
	elseif (x <= 2.8e+188)
		tmp = Float64(0.5 * Float64(y_m - Float64(z * Float64(z / y_m))));
	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 <= 4e+133)
		tmp = 0.5 * (y_m - (z / (y_m / z)));
	elseif (x <= 4.4e+170)
		tmp = x / (y_m * (2.0 / x));
	elseif (x <= 2.8e+188)
		tmp = 0.5 * (y_m - (z * (z / y_m)));
	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, 4e+133], N[(0.5 * N[(y$95$m - N[(z / N[(y$95$m / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.4e+170], N[(x / N[(y$95$m * N[(2.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.8e+188], N[(0.5 * N[(y$95$m - N[(z * N[(z / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 4 \cdot 10^{+133}:\\
\;\;\;\;0.5 \cdot \left(y\_m - \frac{z}{\frac{y\_m}{z}}\right)\\

\mathbf{elif}\;x \leq 4.4 \cdot 10^{+170}:\\
\;\;\;\;\frac{x}{y\_m \cdot \frac{2}{x}}\\

\mathbf{elif}\;x \leq 2.8 \cdot 10^{+188}:\\
\;\;\;\;0.5 \cdot \left(y\_m - z \cdot \frac{z}{y\_m}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < 4.0000000000000001e133

    1. Initial program 75.2%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \left(y - \color{blue}{z \cdot \frac{z}{y}}\right) \]
    8. Step-by-step derivation
      1. clear-num74.5%

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

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

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

    if 4.0000000000000001e133 < x < 4.39999999999999978e170

    1. Initial program 99.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 inf 96.0%

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

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

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

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

        \[\leadsto \color{blue}{\frac{x}{2} \cdot \frac{x}{y}} \]
      2. clear-num96.4%

        \[\leadsto \color{blue}{\frac{1}{\frac{2}{x}}} \cdot \frac{x}{y} \]
      3. frac-times96.6%

        \[\leadsto \color{blue}{\frac{1 \cdot x}{\frac{2}{x} \cdot y}} \]
      4. *-un-lft-identity96.6%

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

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

    if 4.39999999999999978e170 < x < 2.7999999999999998e188

    1. Initial program 2.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 68.1%

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

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

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

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

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

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

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

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

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

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

    if 2.7999999999999998e188 < x

    1. Initial program 50.5%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 4 \cdot 10^{+133}:\\ \;\;\;\;0.5 \cdot \left(y - \frac{z}{\frac{y}{z}}\right)\\ \mathbf{elif}\;x \leq 4.4 \cdot 10^{+170}:\\ \;\;\;\;\frac{x}{y \cdot \frac{2}{x}}\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{+188}:\\ \;\;\;\;0.5 \cdot \left(y - z \cdot \frac{z}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(x \cdot \frac{0.5}{y}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 73.2% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(y\_m - z \cdot \frac{z}{y\_m}\right)\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;x \leq 3.8 \cdot 10^{+132}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq 7 \cdot 10^{+169}:\\
\;\;\;\;\frac{x}{y\_m \cdot \frac{2}{x}}\\

\mathbf{elif}\;x \leq 4.6 \cdot 10^{+188}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < 3.80000000000000006e132 or 7.00000000000000038e169 < x < 4.60000000000000023e188

    1. Initial program 74.2%

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

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

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

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

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

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

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

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

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

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

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

    if 3.80000000000000006e132 < x < 7.00000000000000038e169

    1. Initial program 99.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 inf 96.0%

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

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

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

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

        \[\leadsto \color{blue}{\frac{x}{2} \cdot \frac{x}{y}} \]
      2. clear-num96.4%

        \[\leadsto \color{blue}{\frac{1}{\frac{2}{x}}} \cdot \frac{x}{y} \]
      3. frac-times96.6%

        \[\leadsto \color{blue}{\frac{1 \cdot x}{\frac{2}{x} \cdot y}} \]
      4. *-un-lft-identity96.6%

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

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

    if 4.60000000000000023e188 < x

    1. Initial program 50.5%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 3.8 \cdot 10^{+132}:\\ \;\;\;\;0.5 \cdot \left(y - z \cdot \frac{z}{y}\right)\\ \mathbf{elif}\;x \leq 7 \cdot 10^{+169}:\\ \;\;\;\;\frac{x}{y \cdot \frac{2}{x}}\\ \mathbf{elif}\;x \leq 4.6 \cdot 10^{+188}:\\ \;\;\;\;0.5 \cdot \left(y - z \cdot \frac{z}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(x \cdot \frac{0.5}{y}\right)\\ \end{array} \]
  5. Add Preprocessing

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

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


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

    1. Initial program 78.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(x - z\right) \cdot \left(\left(x + z\right) \cdot \frac{0.5}{y}\right)} \]
    9. Applied egg-rr76.0%

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

    if 5.7e17 < y

    1. Initial program 49.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

    1. Initial program 78.6%

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

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

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

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

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

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

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

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

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

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

    if 1.14e18 < y

    1. Initial program 49.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 53.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}\;y\_m \leq 320000000:\\ \;\;\;\;\frac{x}{y\_m} \cdot \frac{x}{2}\\ \mathbf{else}:\\ \;\;\;\;y\_m \cdot 0.5\\ \end{array} \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (* y_s (if (<= y_m 320000000.0) (* (/ x y_m) (/ x 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 <= 320000000.0) {
		tmp = (x / y_m) * (x / 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 <= 320000000.0d0) then
        tmp = (x / y_m) * (x / 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 <= 320000000.0) {
		tmp = (x / y_m) * (x / 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 <= 320000000.0:
		tmp = (x / y_m) * (x / 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 <= 320000000.0)
		tmp = Float64(Float64(x / y_m) * Float64(x / 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 <= 320000000.0)
		tmp = (x / y_m) * (x / 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, 320000000.0], N[(N[(x / y$95$m), $MachinePrecision] * N[(x / 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 320000000:\\
\;\;\;\;\frac{x}{y\_m} \cdot \frac{x}{2}\\

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


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

    1. Initial program 78.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 inf 35.9%

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

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

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

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

    if 3.2e8 < y

    1. Initial program 51.9%

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

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

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

Alternative 9: 53.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}\;y\_m \leq 240000000:\\ \;\;\;\;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 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (* y_s (if (<= y_m 240000000.0) (* 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 <= 240000000.0) {
		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 <= 240000000.0d0) 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 <= 240000000.0) {
		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 <= 240000000.0:
		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 <= 240000000.0)
		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 <= 240000000.0)
		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, 240000000.0], 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 240000000:\\
\;\;\;\;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 < 2.4e8

    1. Initial program 78.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 inf 35.9%

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

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

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

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

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

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

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

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

    if 2.4e8 < y

    1. Initial program 51.9%

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

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

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

Alternative 10: 35.0% accurate, 5.0× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \left(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 72.5%

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

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

    \[\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 2024096 
(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)))