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

Percentage Accurate: 69.2% → 93.5%
Time: 11.3s
Alternatives: 11
Speedup: 0.8×

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

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

Initial Program: 69.2% accurate, 1.0× speedup?

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

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

Alternative 1: 93.5% accurate, 0.1× speedup?

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

\\
y_s \cdot \begin{array}{l}
\mathbf{if}\;z_m \cdot z_m \leq 5 \cdot 10^{+169}:\\
\;\;\;\;{\left(\frac{x}{\sqrt{2 \cdot y_m}}\right)}^{2} + \left(0.5 \cdot \left(z_m + y_m\right)\right) \cdot \left(1 - \frac{z_m}{y_m}\right)\\

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


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

    1. Initial program 76.5%

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

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

        \[\leadsto \frac{\color{blue}{\left(y \cdot y - z \cdot z\right) + x \cdot x}}{y \cdot 2} \]
      3. sqr-neg76.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-squares76.5%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto {\left(\frac{x}{\sqrt{2 \cdot y}}\right)}^{2} + 0.5 \cdot \color{blue}{\frac{\left(y + z\right) \cdot \left(y - z\right)}{y}} \]
      6. associate-*r/50.5%

        \[\leadsto {\left(\frac{x}{\sqrt{2 \cdot y}}\right)}^{2} + 0.5 \cdot \color{blue}{\left(\left(y + z\right) \cdot \frac{y - z}{y}\right)} \]
      7. associate-*r*50.5%

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

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

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

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

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

    if 5.00000000000000017e169 < (*.f64 z z)

    1. Initial program 68.4%

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

        \[\leadsto \frac{\color{blue}{\frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right) - \left(y \cdot y\right) \cdot \left(y \cdot y\right)}{x \cdot x - y \cdot y}} - z \cdot z}{y \cdot 2} \]
      2. clear-num43.6%

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

        \[\leadsto \frac{\frac{1}{\frac{\color{blue}{{x}^{2}} - y \cdot y}{\left(x \cdot x\right) \cdot \left(x \cdot x\right) - \left(y \cdot y\right) \cdot \left(y \cdot y\right)}} - z \cdot z}{y \cdot 2} \]
      4. pow243.6%

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

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

        \[\leadsto \frac{\frac{1}{\frac{{x}^{2} - {y}^{2}}{{x}^{2} \cdot \color{blue}{{x}^{2}} - \left(y \cdot y\right) \cdot \left(y \cdot y\right)}} - z \cdot z}{y \cdot 2} \]
      7. pow-prod-up43.6%

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

        \[\leadsto \frac{\frac{1}{\frac{{x}^{2} - {y}^{2}}{{x}^{\color{blue}{4}} - \left(y \cdot y\right) \cdot \left(y \cdot y\right)}} - z \cdot z}{y \cdot 2} \]
      9. pow243.6%

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

        \[\leadsto \frac{\frac{1}{\frac{{x}^{2} - {y}^{2}}{{x}^{4} - {y}^{2} \cdot \color{blue}{{y}^{2}}}} - z \cdot z}{y \cdot 2} \]
      11. pow-prod-up43.6%

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{{x}^{2} - {y}^{2}}{{x}^{4} - {y}^{4}}}} - z \cdot z}{y \cdot 2} \]
    5. Taylor expanded in x around inf 71.8%

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{1}{{x}^{2}}}} - z \cdot z}{y \cdot 2} \]
    6. Step-by-step derivation
      1. remove-double-div71.8%

        \[\leadsto \frac{\color{blue}{{x}^{2}} - z \cdot z}{y \cdot 2} \]
      2. unpow271.8%

        \[\leadsto \frac{\color{blue}{x \cdot x} - z \cdot z}{y \cdot 2} \]
    7. Applied egg-rr71.8%

      \[\leadsto \frac{\color{blue}{x \cdot x} - z \cdot z}{y \cdot 2} \]
    8. Step-by-step derivation
      1. difference-of-squares85.0%

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

        \[\leadsto \color{blue}{\frac{x + z}{y} \cdot \frac{x - z}{2}} \]
    9. Applied egg-rr94.7%

      \[\leadsto \color{blue}{\frac{x + z}{y} \cdot \frac{x - z}{2}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification66.7%

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

Alternative 2: 87.4% accurate, 0.1× speedup?

\[\begin{array}{l} z_m = \left|z\right| \\ y_m = \left|y\right| \\ y_s = \mathsf{copysign}\left(1, y\right) \\ y_s \cdot \begin{array}{l} \mathbf{if}\;x \cdot x \leq 10^{-102}:\\ \;\;\;\;\frac{z_m + y_m}{y_m} \cdot \left(0.5 \cdot \left(y_m - z_m\right)\right)\\ \mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+279}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y_m - z_m, z_m + y_m, x \cdot x\right)}{2 \cdot y_m}\\ \mathbf{else}:\\ \;\;\;\;\frac{z_m + x}{y_m} \cdot \frac{x - z_m}{2}\\ \end{array} \end{array} \]
z_m = (fabs.f64 z)
y_m = (fabs.f64 y)
y_s = (copysign.f64 1 y)
(FPCore (y_s x y_m z_m)
 :precision binary64
 (*
  y_s
  (if (<= (* x x) 1e-102)
    (* (/ (+ z_m y_m) y_m) (* 0.5 (- y_m z_m)))
    (if (<= (* x x) 4e+279)
      (/ (fma (- y_m z_m) (+ z_m y_m) (* x x)) (* 2.0 y_m))
      (* (/ (+ z_m x) y_m) (/ (- x z_m) 2.0))))))
z_m = fabs(z);
y_m = fabs(y);
y_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z_m) {
	double tmp;
	if ((x * x) <= 1e-102) {
		tmp = ((z_m + y_m) / y_m) * (0.5 * (y_m - z_m));
	} else if ((x * x) <= 4e+279) {
		tmp = fma((y_m - z_m), (z_m + y_m), (x * x)) / (2.0 * y_m);
	} else {
		tmp = ((z_m + x) / y_m) * ((x - z_m) / 2.0);
	}
	return y_s * tmp;
}
z_m = abs(z)
y_m = abs(y)
y_s = copysign(1.0, y)
function code(y_s, x, y_m, z_m)
	tmp = 0.0
	if (Float64(x * x) <= 1e-102)
		tmp = Float64(Float64(Float64(z_m + y_m) / y_m) * Float64(0.5 * Float64(y_m - z_m)));
	elseif (Float64(x * x) <= 4e+279)
		tmp = Float64(fma(Float64(y_m - z_m), Float64(z_m + y_m), Float64(x * x)) / Float64(2.0 * y_m));
	else
		tmp = Float64(Float64(Float64(z_m + x) / y_m) * Float64(Float64(x - z_m) / 2.0));
	end
	return Float64(y_s * tmp)
end
z_m = N[Abs[z], $MachinePrecision]
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$95$m_] := N[(y$95$s * If[LessEqual[N[(x * x), $MachinePrecision], 1e-102], N[(N[(N[(z$95$m + y$95$m), $MachinePrecision] / y$95$m), $MachinePrecision] * N[(0.5 * N[(y$95$m - z$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 4e+279], N[(N[(N[(y$95$m - z$95$m), $MachinePrecision] * N[(z$95$m + y$95$m), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] / N[(2.0 * y$95$m), $MachinePrecision]), $MachinePrecision], N[(N[(N[(z$95$m + x), $MachinePrecision] / y$95$m), $MachinePrecision] * N[(N[(x - z$95$m), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
y_m = \left|y\right|
\\
y_s = \mathsf{copysign}\left(1, y\right)

\\
y_s \cdot \begin{array}{l}
\mathbf{if}\;x \cdot x \leq 10^{-102}:\\
\;\;\;\;\frac{z_m + y_m}{y_m} \cdot \left(0.5 \cdot \left(y_m - z_m\right)\right)\\

\mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+279}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y_m - z_m, z_m + y_m, x \cdot x\right)}{2 \cdot y_m}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 x x) < 9.99999999999999933e-103

    1. Initial program 73.5%

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

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

        \[\leadsto \frac{\color{blue}{\left(y \cdot y - z \cdot z\right) + x \cdot x}}{y \cdot 2} \]
      3. sqr-neg73.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-squares74.6%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{y + z}{y} \cdot \frac{y - z}{2}} \]
      2. div-inv95.5%

        \[\leadsto \frac{y + z}{y} \cdot \color{blue}{\left(\left(y - z\right) \cdot \frac{1}{2}\right)} \]
      3. metadata-eval95.5%

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

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

    if 9.99999999999999933e-103 < (*.f64 x x) < 4.00000000000000023e279

    1. Initial program 86.1%

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

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

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

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

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

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

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

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

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

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

    if 4.00000000000000023e279 < (*.f64 x x)

    1. Initial program 59.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. flip-+4.3%

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

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

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

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

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

        \[\leadsto \frac{\frac{1}{\frac{{x}^{2} - {y}^{2}}{{x}^{2} \cdot \color{blue}{{x}^{2}} - \left(y \cdot y\right) \cdot \left(y \cdot y\right)}} - z \cdot z}{y \cdot 2} \]
      7. pow-prod-up4.3%

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

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

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

        \[\leadsto \frac{\frac{1}{\frac{{x}^{2} - {y}^{2}}{{x}^{4} - {y}^{2} \cdot \color{blue}{{y}^{2}}}} - z \cdot z}{y \cdot 2} \]
      11. pow-prod-up4.3%

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{{x}^{2} - {y}^{2}}{{x}^{4} - {y}^{4}}}} - z \cdot z}{y \cdot 2} \]
    5. Taylor expanded in x around inf 61.1%

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{1}{{x}^{2}}}} - z \cdot z}{y \cdot 2} \]
    6. Step-by-step derivation
      1. remove-double-div61.1%

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

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

      \[\leadsto \frac{\color{blue}{x \cdot x} - z \cdot z}{y \cdot 2} \]
    8. Step-by-step derivation
      1. difference-of-squares78.8%

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

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

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

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

Alternative 3: 94.3% accurate, 0.1× speedup?

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

\\
y_s \cdot \begin{array}{l}
\mathbf{if}\;x \cdot x \leq 4 \cdot 10^{+279}:\\
\;\;\;\;0.5 \cdot \left(\frac{z_m + y_m}{\frac{y_m}{y_m - z_m}} + \frac{{x}^{2}}{y_m}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x x) < 4.00000000000000023e279

    1. Initial program 78.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.00000000000000023e279 < (*.f64 x x)

    1. Initial program 59.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. flip-+4.3%

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

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

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

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

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

        \[\leadsto \frac{\frac{1}{\frac{{x}^{2} - {y}^{2}}{{x}^{2} \cdot \color{blue}{{x}^{2}} - \left(y \cdot y\right) \cdot \left(y \cdot y\right)}} - z \cdot z}{y \cdot 2} \]
      7. pow-prod-up4.3%

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

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

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

        \[\leadsto \frac{\frac{1}{\frac{{x}^{2} - {y}^{2}}{{x}^{4} - {y}^{2} \cdot \color{blue}{{y}^{2}}}} - z \cdot z}{y \cdot 2} \]
      11. pow-prod-up4.3%

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{{x}^{2} - {y}^{2}}{{x}^{4} - {y}^{4}}}} - z \cdot z}{y \cdot 2} \]
    5. Taylor expanded in x around inf 61.1%

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{1}{{x}^{2}}}} - z \cdot z}{y \cdot 2} \]
    6. Step-by-step derivation
      1. remove-double-div61.1%

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

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

      \[\leadsto \frac{\color{blue}{x \cdot x} - z \cdot z}{y \cdot 2} \]
    8. Step-by-step derivation
      1. difference-of-squares78.8%

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

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

      \[\leadsto \color{blue}{\frac{x + z}{y} \cdot \frac{x - z}{2}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification94.5%

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

Alternative 4: 86.7% accurate, 0.5× speedup?

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

\\
y_s \cdot \begin{array}{l}
\mathbf{if}\;x \cdot x \leq 10^{-102}:\\
\;\;\;\;\frac{z_m + y_m}{y_m} \cdot \left(0.5 \cdot \left(y_m - z_m\right)\right)\\

\mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+279}:\\
\;\;\;\;\frac{\left(x \cdot x + y_m \cdot y_m\right) - z_m \cdot z_m}{2 \cdot y_m}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 x x) < 9.99999999999999933e-103

    1. Initial program 73.5%

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

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

        \[\leadsto \frac{\color{blue}{\left(y \cdot y - z \cdot z\right) + x \cdot x}}{y \cdot 2} \]
      3. sqr-neg73.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-squares74.6%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{y + z}{y} \cdot \frac{y - z}{2}} \]
      2. div-inv95.5%

        \[\leadsto \frac{y + z}{y} \cdot \color{blue}{\left(\left(y - z\right) \cdot \frac{1}{2}\right)} \]
      3. metadata-eval95.5%

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

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

    if 9.99999999999999933e-103 < (*.f64 x x) < 4.00000000000000023e279

    1. Initial program 86.1%

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

    if 4.00000000000000023e279 < (*.f64 x x)

    1. Initial program 59.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. flip-+4.3%

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

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

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

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

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

        \[\leadsto \frac{\frac{1}{\frac{{x}^{2} - {y}^{2}}{{x}^{2} \cdot \color{blue}{{x}^{2}} - \left(y \cdot y\right) \cdot \left(y \cdot y\right)}} - z \cdot z}{y \cdot 2} \]
      7. pow-prod-up4.3%

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

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

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

        \[\leadsto \frac{\frac{1}{\frac{{x}^{2} - {y}^{2}}{{x}^{4} - {y}^{2} \cdot \color{blue}{{y}^{2}}}} - z \cdot z}{y \cdot 2} \]
      11. pow-prod-up4.3%

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{{x}^{2} - {y}^{2}}{{x}^{4} - {y}^{4}}}} - z \cdot z}{y \cdot 2} \]
    5. Taylor expanded in x around inf 61.1%

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{1}{{x}^{2}}}} - z \cdot z}{y \cdot 2} \]
    6. Step-by-step derivation
      1. remove-double-div61.1%

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

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

      \[\leadsto \frac{\color{blue}{x \cdot x} - z \cdot z}{y \cdot 2} \]
    8. Step-by-step derivation
      1. difference-of-squares78.8%

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

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

      \[\leadsto \color{blue}{\frac{x + z}{y} \cdot \frac{x - z}{2}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification91.8%

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

Alternative 5: 80.1% accurate, 0.7× speedup?

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

\\
y_s \cdot \begin{array}{l}
\mathbf{if}\;y_m \leq 3.6 \cdot 10^{-22}:\\
\;\;\;\;\frac{z_m + x}{y_m} \cdot \frac{x - z_m}{2}\\

\mathbf{elif}\;y_m \leq 1.52 \cdot 10^{+172}:\\
\;\;\;\;\left(\left(z_m + y_m\right) \cdot \left(y_m - z_m\right)\right) \cdot \frac{0.5}{y_m}\\

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


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

    1. Initial program 77.9%

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

        \[\leadsto \frac{\color{blue}{\frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right) - \left(y \cdot y\right) \cdot \left(y \cdot y\right)}{x \cdot x - y \cdot y}} - z \cdot z}{y \cdot 2} \]
      2. clear-num46.1%

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

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

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

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

        \[\leadsto \frac{\frac{1}{\frac{{x}^{2} - {y}^{2}}{{x}^{2} \cdot \color{blue}{{x}^{2}} - \left(y \cdot y\right) \cdot \left(y \cdot y\right)}} - z \cdot z}{y \cdot 2} \]
      7. pow-prod-up46.1%

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

        \[\leadsto \frac{\frac{1}{\frac{{x}^{2} - {y}^{2}}{{x}^{\color{blue}{4}} - \left(y \cdot y\right) \cdot \left(y \cdot y\right)}} - z \cdot z}{y \cdot 2} \]
      9. pow246.1%

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

        \[\leadsto \frac{\frac{1}{\frac{{x}^{2} - {y}^{2}}{{x}^{4} - {y}^{2} \cdot \color{blue}{{y}^{2}}}} - z \cdot z}{y \cdot 2} \]
      11. pow-prod-up46.0%

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{{x}^{2} - {y}^{2}}{{x}^{4} - {y}^{4}}}} - z \cdot z}{y \cdot 2} \]
    5. Taylor expanded in x around inf 67.8%

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{1}{{x}^{2}}}} - z \cdot z}{y \cdot 2} \]
    6. Step-by-step derivation
      1. remove-double-div68.2%

        \[\leadsto \frac{\color{blue}{{x}^{2}} - z \cdot z}{y \cdot 2} \]
      2. unpow268.2%

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

      \[\leadsto \frac{\color{blue}{x \cdot x} - z \cdot z}{y \cdot 2} \]
    8. Step-by-step derivation
      1. difference-of-squares73.2%

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

        \[\leadsto \color{blue}{\frac{x + z}{y} \cdot \frac{x - z}{2}} \]
    9. Applied egg-rr79.7%

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

    if 3.5999999999999998e-22 < y < 1.5200000000000001e172

    1. Initial program 85.6%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(y + z\right) \cdot \left(y - z\right)}}{y \cdot 2} \]
    6. Step-by-step derivation
      1. div-inv53.8%

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

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

        \[\leadsto \left(\left(y + z\right) \cdot \left(y - z\right)\right) \cdot \frac{1}{\color{blue}{\frac{y}{0.5}}} \]
      4. clear-num53.8%

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

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

    if 1.5200000000000001e172 < y

    1. Initial program 4.8%

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

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

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

Alternative 6: 84.7% accurate, 0.8× speedup?

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

\\
y_s \cdot \begin{array}{l}
\mathbf{if}\;x \cdot x \leq 10^{-90}:\\
\;\;\;\;\frac{z_m + y_m}{y_m} \cdot \left(0.5 \cdot \left(y_m - z_m\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x x) < 9.99999999999999995e-91

    1. Initial program 73.4%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(y + z\right) \cdot \left(y - z\right)}}{y \cdot 2} \]
    6. Step-by-step derivation
      1. times-frac94.8%

        \[\leadsto \color{blue}{\frac{y + z}{y} \cdot \frac{y - z}{2}} \]
      2. div-inv94.8%

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

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

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

    if 9.99999999999999995e-91 < (*.f64 x x)

    1. Initial program 73.6%

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

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

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

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

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

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

        \[\leadsto \frac{\frac{1}{\frac{{x}^{2} - {y}^{2}}{{x}^{2} \cdot \color{blue}{{x}^{2}} - \left(y \cdot y\right) \cdot \left(y \cdot y\right)}} - z \cdot z}{y \cdot 2} \]
      7. pow-prod-up32.2%

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

        \[\leadsto \frac{\frac{1}{\frac{{x}^{2} - {y}^{2}}{{x}^{\color{blue}{4}} - \left(y \cdot y\right) \cdot \left(y \cdot y\right)}} - z \cdot z}{y \cdot 2} \]
      9. pow232.2%

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

        \[\leadsto \frac{\frac{1}{\frac{{x}^{2} - {y}^{2}}{{x}^{4} - {y}^{2} \cdot \color{blue}{{y}^{2}}}} - z \cdot z}{y \cdot 2} \]
      11. pow-prod-up32.2%

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{{x}^{2} - {y}^{2}}{{x}^{4} - {y}^{4}}}} - z \cdot z}{y \cdot 2} \]
    5. Taylor expanded in x around inf 68.8%

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{1}{{x}^{2}}}} - z \cdot z}{y \cdot 2} \]
    6. Step-by-step derivation
      1. remove-double-div68.8%

        \[\leadsto \frac{\color{blue}{{x}^{2}} - z \cdot z}{y \cdot 2} \]
      2. unpow268.8%

        \[\leadsto \frac{\color{blue}{x \cdot x} - z \cdot z}{y \cdot 2} \]
    7. Applied egg-rr68.8%

      \[\leadsto \frac{\color{blue}{x \cdot x} - z \cdot z}{y \cdot 2} \]
    8. Step-by-step derivation
      1. difference-of-squares77.4%

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

        \[\leadsto \color{blue}{\frac{x + z}{y} \cdot \frac{x - z}{2}} \]
    9. Applied egg-rr85.7%

      \[\leadsto \color{blue}{\frac{x + z}{y} \cdot \frac{x - z}{2}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification89.7%

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

Alternative 7: 56.9% accurate, 0.9× speedup?

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

\\
y_s \cdot \begin{array}{l}
\mathbf{if}\;x \leq 1.95 \cdot 10^{+89}:\\
\;\;\;\;\left(\left(z_m + y_m\right) \cdot \left(y_m - z_m\right)\right) \cdot \frac{0.5}{y_m}\\

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


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

    1. Initial program 75.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(y + z\right) \cdot \left(y - z\right)}}{y \cdot 2} \]
    6. Step-by-step derivation
      1. div-inv56.0%

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

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

        \[\leadsto \left(\left(y + z\right) \cdot \left(y - z\right)\right) \cdot \frac{1}{\color{blue}{\frac{y}{0.5}}} \]
      4. clear-num56.0%

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

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

    if 1.95000000000000005e89 < x

    1. Initial program 65.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 inf 73.5%

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

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

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

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

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

        \[\leadsto \frac{x}{2} \cdot \color{blue}{\frac{1}{\frac{y}{x}}} \]
      3. un-div-inv85.9%

        \[\leadsto \color{blue}{\frac{\frac{x}{2}}{\frac{y}{x}}} \]
      4. div-inv85.9%

        \[\leadsto \frac{\color{blue}{x \cdot \frac{1}{2}}}{\frac{y}{x}} \]
      5. metadata-eval85.9%

        \[\leadsto \frac{x \cdot \color{blue}{0.5}}{\frac{y}{x}} \]
    7. Applied egg-rr85.9%

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

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

Alternative 8: 43.9% accurate, 1.2× speedup?

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

\\
y_s \cdot \begin{array}{l}
\mathbf{if}\;x \leq 7.6 \cdot 10^{-44}:\\
\;\;\;\;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 < 7.6000000000000002e-44

    1. Initial program 73.8%

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

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

    if 7.6000000000000002e-44 < x

    1. Initial program 72.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 inf 54.0%

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

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

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

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

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

Alternative 9: 43.9% accurate, 1.2× speedup?

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

\\
y_s \cdot \begin{array}{l}
\mathbf{if}\;x \leq 5.5 \cdot 10^{-44}:\\
\;\;\;\;y_m \cdot 0.5\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 5.49999999999999993e-44

    1. Initial program 73.8%

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

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

    if 5.49999999999999993e-44 < x

    1. Initial program 72.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 inf 54.0%

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

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

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

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

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

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

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

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

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

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

Alternative 10: 43.9% accurate, 1.2× speedup?

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

\\
y_s \cdot \begin{array}{l}
\mathbf{if}\;x \leq 5.2 \cdot 10^{-44}:\\
\;\;\;\;y_m \cdot 0.5\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 5.1999999999999996e-44

    1. Initial program 73.8%

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

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

    if 5.1999999999999996e-44 < x

    1. Initial program 72.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 inf 54.0%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\frac{x}{2}}{\frac{y}{x}}} \]
      4. div-inv61.1%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 5.2 \cdot 10^{-44}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 0.5}{\frac{y}{x}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 35.0% accurate, 5.0× speedup?

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

    \[\leadsto \color{blue}{0.5 \cdot y} \]
  4. Final simplification28.0%

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