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

Percentage Accurate: 68.3% → 95.7%
Time: 10.1s
Alternatives: 7
Speedup: 1.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 7 alternatives:

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

Initial Program: 68.3% 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: 95.7% accurate, 0.1× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ \begin{array}{l} t_0 := \frac{\left(x \cdot x + y\_m \cdot y\_m\right) - z \cdot z}{y\_m \cdot 2}\\ y\_s \cdot \begin{array}{l} \mathbf{if}\;t\_0 \leq -5 \cdot 10^{-61}:\\ \;\;\;\;0.5 \cdot \left(\left(x - z\right) \cdot \frac{z}{y\_m}\right)\\ \mathbf{elif}\;t\_0 \leq \infty:\\ \;\;\;\;0.5 \cdot \left(y\_m + \mathsf{fma}\left(x, \frac{x}{y\_m}, z \cdot \frac{0}{y\_m}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(y\_m - z \cdot \frac{z}{y\_m}\right)\\ \end{array} \end{array} \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
 :precision binary64
 (let* ((t_0 (/ (- (+ (* x x) (* y_m y_m)) (* z z)) (* y_m 2.0))))
   (*
    y_s
    (if (<= t_0 -5e-61)
      (* 0.5 (* (- x z) (/ z y_m)))
      (if (<= t_0 INFINITY)
        (* 0.5 (+ y_m (fma x (/ x y_m) (* z (/ 0.0 y_m)))))
        (* 0.5 (- y_m (* z (/ z y_m)))))))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
	double t_0 = (((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0);
	double tmp;
	if (t_0 <= -5e-61) {
		tmp = 0.5 * ((x - z) * (z / y_m));
	} else if (t_0 <= ((double) INFINITY)) {
		tmp = 0.5 * (y_m + fma(x, (x / y_m), (z * (0.0 / y_m))));
	} else {
		tmp = 0.5 * (y_m - (z * (z / y_m)));
	}
	return y_s * tmp;
}
y\_m = abs(y)
y\_s = copysign(1.0, y)
function code(y_s, x, y_m, z)
	t_0 = Float64(Float64(Float64(Float64(x * x) + Float64(y_m * y_m)) - Float64(z * z)) / Float64(y_m * 2.0))
	tmp = 0.0
	if (t_0 <= -5e-61)
		tmp = Float64(0.5 * Float64(Float64(x - z) * Float64(z / y_m)));
	elseif (t_0 <= Inf)
		tmp = Float64(0.5 * Float64(y_m + fma(x, Float64(x / y_m), Float64(z * Float64(0.0 / y_m)))));
	else
		tmp = Float64(0.5 * Float64(y_m - Float64(z * Float64(z / y_m))));
	end
	return Float64(y_s * tmp)
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z_] := Block[{t$95$0 = N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y$95$m * y$95$m), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y$95$m * 2.0), $MachinePrecision]), $MachinePrecision]}, N[(y$95$s * If[LessEqual[t$95$0, -5e-61], N[(0.5 * N[(N[(x - z), $MachinePrecision] * N[(z / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, Infinity], N[(0.5 * N[(y$95$m + N[(x * N[(x / y$95$m), $MachinePrecision] + N[(z * N[(0.0 / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y$95$m - N[(z * N[(z / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)

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

\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;0.5 \cdot \left(y\_m + \mathsf{fma}\left(x, \frac{x}{y\_m}, z \cdot \frac{0}{y\_m}\right)\right)\\

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


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < -4.9999999999999999e-61

    1. Initial program 79.2%

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

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

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

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

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

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

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

      \[\leadsto y \cdot \left(0.5 + \frac{\color{blue}{\left(x + z\right) \cdot \left(x - z\right)}}{{y}^{2}} \cdot 0.5\right) \]
    8. Taylor expanded in y around 0 66.8%

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \left(\left(x - z\right) \cdot \frac{z + x}{y}\right)} \]
    11. Taylor expanded in z around inf 40.6%

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

    if -4.9999999999999999e-61 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < +inf.0

    1. Initial program 80.4%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Step-by-step derivation
      1. remove-double-neg80.4%

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

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

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

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

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(\left(x \cdot x + y \cdot y\right) - z \cdot z\right)}}{\left(-y\right) \cdot 2} \]
      6. distribute-lft-neg-out80.4%

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

        \[\leadsto \frac{-1 \cdot \left(\left(x \cdot x + y \cdot y\right) - z \cdot z\right)}{-\color{blue}{2 \cdot y}} \]
      8. distribute-lft-neg-in80.4%

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}{y}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. prod-diff66.7%

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

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

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

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

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

      \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\mathsf{fma}\left(y + z, y - z, \mathsf{fma}\left(-z, z, {z}^{2}\right)\right)}\right)}{y} \]
    7. Taylor expanded in z around -inf 54.2%

      \[\leadsto 0.5 \cdot \frac{\color{blue}{{z}^{2} \cdot \left(-1 \cdot \frac{y + \left(-1 \cdot y + -1 \cdot \frac{{x}^{2} + {y}^{2}}{z}\right)}{z} - 1\right)}}{y} \]
    8. Taylor expanded in z around 0 64.2%

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

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

    if +inf.0 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64)))

    1. Initial program 0.0%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Step-by-step derivation
      1. remove-double-neg0.0%

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

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

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

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

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(\left(x \cdot x + y \cdot y\right) - z \cdot z\right)}}{\left(-y\right) \cdot 2} \]
      6. distribute-lft-neg-out0.0%

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

        \[\leadsto \frac{-1 \cdot \left(\left(x \cdot x + y \cdot y\right) - z \cdot z\right)}{-\color{blue}{2 \cdot y}} \]
      8. distribute-lft-neg-in0.0%

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}{y}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. prod-diff0.6%

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

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

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

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

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

      \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\mathsf{fma}\left(y + z, y - z, \mathsf{fma}\left(-z, z, {z}^{2}\right)\right)}\right)}{y} \]
    7. Taylor expanded in z around -inf 22.5%

      \[\leadsto 0.5 \cdot \frac{\color{blue}{{z}^{2} \cdot \left(-1 \cdot \frac{y + \left(-1 \cdot y + -1 \cdot \frac{{x}^{2} + {y}^{2}}{z}\right)}{z} - 1\right)}}{y} \]
    8. Taylor expanded in z around 0 62.0%

      \[\leadsto 0.5 \cdot \color{blue}{\left(y + \left(z \cdot \left(-1 \cdot \frac{z}{y} + -1 \cdot \frac{y + -1 \cdot y}{y}\right) + \frac{{x}^{2}}{y}\right)\right)} \]
    9. Taylor expanded in x around 0 79.3%

      \[\leadsto 0.5 \cdot \left(y + \color{blue}{z \cdot \left(-1 \cdot \frac{z}{y} + -1 \cdot \frac{y + -1 \cdot y}{y}\right)}\right) \]
    10. Step-by-step derivation
      1. neg-mul-179.3%

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

        \[\leadsto 0.5 \cdot \left(y + z \cdot \color{blue}{\left(-1 \cdot \frac{y + -1 \cdot y}{y} + \left(-\frac{z}{y}\right)\right)}\right) \]
      3. distribute-rgt1-in79.3%

        \[\leadsto 0.5 \cdot \left(y + z \cdot \left(-1 \cdot \frac{\color{blue}{\left(-1 + 1\right) \cdot y}}{y} + \left(-\frac{z}{y}\right)\right)\right) \]
      4. metadata-eval79.3%

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

        \[\leadsto 0.5 \cdot \left(y + z \cdot \left(-1 \cdot \frac{\color{blue}{0}}{y} + \left(-\frac{z}{y}\right)\right)\right) \]
      6. associate-*r/79.3%

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

        \[\leadsto 0.5 \cdot \left(y + z \cdot \left(\frac{\color{blue}{0}}{y} + \left(-\frac{z}{y}\right)\right)\right) \]
      8. unsub-neg79.3%

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

        \[\leadsto 0.5 \cdot \left(y + z \cdot \left(\color{blue}{0} - \frac{z}{y}\right)\right) \]
      10. neg-sub079.3%

        \[\leadsto 0.5 \cdot \left(y + z \cdot \color{blue}{\left(-\frac{z}{y}\right)}\right) \]
      11. *-commutative79.3%

        \[\leadsto 0.5 \cdot \left(y + \color{blue}{\left(-\frac{z}{y}\right) \cdot z}\right) \]
      12. distribute-lft-neg-out79.3%

        \[\leadsto 0.5 \cdot \left(y + \color{blue}{\left(-\frac{z}{y} \cdot z\right)}\right) \]
      13. distribute-rgt-neg-in79.3%

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

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

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

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

\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;y\_m \leq 10^{-150}:\\
\;\;\;\;0.5 \cdot \left(\left(x - z\right) \cdot \frac{x + z}{y\_m}\right)\\

\mathbf{elif}\;y\_m \leq 1.42 \cdot 10^{+141}:\\
\;\;\;\;\frac{\left(x \cdot x + y\_m \cdot y\_m\right) - z \cdot z}{y\_m \cdot 2}\\

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


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

    1. Initial program 75.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 76.4%

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

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

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

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

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

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

      \[\leadsto y \cdot \left(0.5 + \frac{\color{blue}{\left(x + z\right) \cdot \left(x - z\right)}}{{y}^{2}} \cdot 0.5\right) \]
    8. Taylor expanded in y around 0 73.9%

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

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

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

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

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

    if 1.00000000000000001e-150 < y < 1.42000000000000005e141

    1. Initial program 94.2%

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

    if 1.42000000000000005e141 < y

    1. Initial program 12.9%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Step-by-step derivation
      1. remove-double-neg12.9%

        \[\leadsto \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{\color{blue}{-\left(-y \cdot 2\right)}} \]
      2. distribute-lft-neg-out12.9%

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

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

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

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(\left(x \cdot x + y \cdot y\right) - z \cdot z\right)}}{\left(-y\right) \cdot 2} \]
      6. distribute-lft-neg-out12.9%

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

        \[\leadsto \frac{-1 \cdot \left(\left(x \cdot x + y \cdot y\right) - z \cdot z\right)}{-\color{blue}{2 \cdot y}} \]
      8. distribute-lft-neg-in12.9%

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}{y}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. prod-diff13.4%

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

        \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y \cdot y - z \cdot z\right)} + \mathsf{fma}\left(-z, z, z \cdot z\right)\right)}{y} \]
      3. difference-of-squares14.1%

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

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

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

      \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\mathsf{fma}\left(y + z, y - z, \mathsf{fma}\left(-z, z, {z}^{2}\right)\right)}\right)}{y} \]
    7. Taylor expanded in z around -inf 9.8%

      \[\leadsto 0.5 \cdot \frac{\color{blue}{{z}^{2} \cdot \left(-1 \cdot \frac{y + \left(-1 \cdot y + -1 \cdot \frac{{x}^{2} + {y}^{2}}{z}\right)}{z} - 1\right)}}{y} \]
    8. Taylor expanded in z around 0 86.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(y + \left(z \cdot \left(-1 \cdot \frac{z}{y} + -1 \cdot \frac{y + -1 \cdot y}{y}\right) + \frac{{x}^{2}}{y}\right)\right)} \]
    9. Taylor expanded in x around 0 87.7%

      \[\leadsto 0.5 \cdot \left(y + \color{blue}{z \cdot \left(-1 \cdot \frac{z}{y} + -1 \cdot \frac{y + -1 \cdot y}{y}\right)}\right) \]
    10. Step-by-step derivation
      1. neg-mul-187.7%

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

        \[\leadsto 0.5 \cdot \left(y + z \cdot \color{blue}{\left(-1 \cdot \frac{y + -1 \cdot y}{y} + \left(-\frac{z}{y}\right)\right)}\right) \]
      3. distribute-rgt1-in87.7%

        \[\leadsto 0.5 \cdot \left(y + z \cdot \left(-1 \cdot \frac{\color{blue}{\left(-1 + 1\right) \cdot y}}{y} + \left(-\frac{z}{y}\right)\right)\right) \]
      4. metadata-eval87.7%

        \[\leadsto 0.5 \cdot \left(y + z \cdot \left(-1 \cdot \frac{\color{blue}{0} \cdot y}{y} + \left(-\frac{z}{y}\right)\right)\right) \]
      5. mul0-lft87.7%

        \[\leadsto 0.5 \cdot \left(y + z \cdot \left(-1 \cdot \frac{\color{blue}{0}}{y} + \left(-\frac{z}{y}\right)\right)\right) \]
      6. associate-*r/87.7%

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

        \[\leadsto 0.5 \cdot \left(y + z \cdot \left(\frac{\color{blue}{0}}{y} + \left(-\frac{z}{y}\right)\right)\right) \]
      8. unsub-neg87.7%

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

        \[\leadsto 0.5 \cdot \left(y + z \cdot \left(\color{blue}{0} - \frac{z}{y}\right)\right) \]
      10. neg-sub087.7%

        \[\leadsto 0.5 \cdot \left(y + z \cdot \color{blue}{\left(-\frac{z}{y}\right)}\right) \]
      11. *-commutative87.7%

        \[\leadsto 0.5 \cdot \left(y + \color{blue}{\left(-\frac{z}{y}\right) \cdot z}\right) \]
      12. distribute-lft-neg-out87.7%

        \[\leadsto 0.5 \cdot \left(y + \color{blue}{\left(-\frac{z}{y} \cdot z\right)}\right) \]
      13. distribute-rgt-neg-in87.7%

        \[\leadsto 0.5 \cdot \left(y + \color{blue}{\frac{z}{y} \cdot \left(-z\right)}\right) \]
    11. Simplified87.7%

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

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

Alternative 3: 56.9% accurate, 0.8× 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.5 \cdot 10^{-19}:\\ \;\;\;\;0.5 \cdot \left(\left(x - z\right) \cdot \frac{z}{y\_m}\right)\\ \mathbf{elif}\;y\_m \leq 1.55 \cdot 10^{+102}:\\ \;\;\;\;0.5 \cdot \left(\left(x - z\right) \cdot \frac{x}{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 1.5e-19)
    (* 0.5 (* (- x z) (/ z y_m)))
    (if (<= y_m 1.55e+102) (* 0.5 (* (- x z) (/ x 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 <= 1.5e-19) {
		tmp = 0.5 * ((x - z) * (z / y_m));
	} else if (y_m <= 1.55e+102) {
		tmp = 0.5 * ((x - z) * (x / 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 <= 1.5d-19) then
        tmp = 0.5d0 * ((x - z) * (z / y_m))
    else if (y_m <= 1.55d+102) then
        tmp = 0.5d0 * ((x - z) * (x / 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 <= 1.5e-19) {
		tmp = 0.5 * ((x - z) * (z / y_m));
	} else if (y_m <= 1.55e+102) {
		tmp = 0.5 * ((x - z) * (x / 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 <= 1.5e-19:
		tmp = 0.5 * ((x - z) * (z / y_m))
	elif y_m <= 1.55e+102:
		tmp = 0.5 * ((x - z) * (x / 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 <= 1.5e-19)
		tmp = Float64(0.5 * Float64(Float64(x - z) * Float64(z / y_m)));
	elseif (y_m <= 1.55e+102)
		tmp = Float64(0.5 * Float64(Float64(x - z) * Float64(x / 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 <= 1.5e-19)
		tmp = 0.5 * ((x - z) * (z / y_m));
	elseif (y_m <= 1.55e+102)
		tmp = 0.5 * ((x - z) * (x / 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, 1.5e-19], N[(0.5 * N[(N[(x - z), $MachinePrecision] * N[(z / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$95$m, 1.55e+102], N[(0.5 * N[(N[(x - z), $MachinePrecision] * N[(x / 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 1.5 \cdot 10^{-19}:\\
\;\;\;\;0.5 \cdot \left(\left(x - z\right) \cdot \frac{z}{y\_m}\right)\\

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

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


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

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

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

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

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

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

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

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

      \[\leadsto y \cdot \left(0.5 + \frac{\color{blue}{\left(x + z\right) \cdot \left(x - z\right)}}{{y}^{2}} \cdot 0.5\right) \]
    8. Taylor expanded in y around 0 75.6%

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \left(\left(x - z\right) \cdot \frac{z + x}{y}\right)} \]
    11. Taylor expanded in z around inf 49.8%

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

    if 1.49999999999999996e-19 < y < 1.54999999999999993e102

    1. Initial program 87.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 inf 87.7%

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

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

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

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

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

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

      \[\leadsto y \cdot \left(0.5 + \frac{\color{blue}{\left(x + z\right) \cdot \left(x - z\right)}}{{y}^{2}} \cdot 0.5\right) \]
    8. Taylor expanded in y around 0 81.7%

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \left(\left(x - z\right) \cdot \frac{z + x}{y}\right)} \]
    11. Taylor expanded in z around 0 63.6%

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

    if 1.54999999999999993e102 < y

    1. Initial program 30.0%

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

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

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

      \[\leadsto \color{blue}{y \cdot 0.5} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

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

\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;y\_m \leq 3.35 \cdot 10^{+93}:\\
\;\;\;\;0.5 \cdot \left(\left(x - z\right) \cdot \frac{x + z}{y\_m}\right)\\

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


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

    1. Initial program 79.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 79.3%

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

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

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

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

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

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

      \[\leadsto y \cdot \left(0.5 + \frac{\color{blue}{\left(x + z\right) \cdot \left(x - z\right)}}{{y}^{2}} \cdot 0.5\right) \]
    8. Taylor expanded in y around 0 76.1%

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

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

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

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

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

    if 3.34999999999999983e93 < y

    1. Initial program 30.0%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Step-by-step derivation
      1. remove-double-neg30.0%

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

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

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

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

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(\left(x \cdot x + y \cdot y\right) - z \cdot z\right)}}{\left(-y\right) \cdot 2} \]
      6. distribute-lft-neg-out30.0%

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

        \[\leadsto \frac{-1 \cdot \left(\left(x \cdot x + y \cdot y\right) - z \cdot z\right)}{-\color{blue}{2 \cdot y}} \]
      8. distribute-lft-neg-in30.0%

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}{y}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. prod-diff30.4%

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

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

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

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

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

      \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\mathsf{fma}\left(y + z, y - z, \mathsf{fma}\left(-z, z, {z}^{2}\right)\right)}\right)}{y} \]
    7. Taylor expanded in z around -inf 14.6%

      \[\leadsto 0.5 \cdot \frac{\color{blue}{{z}^{2} \cdot \left(-1 \cdot \frac{y + \left(-1 \cdot y + -1 \cdot \frac{{x}^{2} + {y}^{2}}{z}\right)}{z} - 1\right)}}{y} \]
    8. Taylor expanded in z around 0 89.7%

      \[\leadsto 0.5 \cdot \color{blue}{\left(y + \left(z \cdot \left(-1 \cdot \frac{z}{y} + -1 \cdot \frac{y + -1 \cdot y}{y}\right) + \frac{{x}^{2}}{y}\right)\right)} \]
    9. Taylor expanded in x around 0 81.9%

      \[\leadsto 0.5 \cdot \left(y + \color{blue}{z \cdot \left(-1 \cdot \frac{z}{y} + -1 \cdot \frac{y + -1 \cdot y}{y}\right)}\right) \]
    10. Step-by-step derivation
      1. neg-mul-181.9%

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

        \[\leadsto 0.5 \cdot \left(y + z \cdot \color{blue}{\left(-1 \cdot \frac{y + -1 \cdot y}{y} + \left(-\frac{z}{y}\right)\right)}\right) \]
      3. distribute-rgt1-in81.9%

        \[\leadsto 0.5 \cdot \left(y + z \cdot \left(-1 \cdot \frac{\color{blue}{\left(-1 + 1\right) \cdot y}}{y} + \left(-\frac{z}{y}\right)\right)\right) \]
      4. metadata-eval81.9%

        \[\leadsto 0.5 \cdot \left(y + z \cdot \left(-1 \cdot \frac{\color{blue}{0} \cdot y}{y} + \left(-\frac{z}{y}\right)\right)\right) \]
      5. mul0-lft81.9%

        \[\leadsto 0.5 \cdot \left(y + z \cdot \left(-1 \cdot \frac{\color{blue}{0}}{y} + \left(-\frac{z}{y}\right)\right)\right) \]
      6. associate-*r/81.9%

        \[\leadsto 0.5 \cdot \left(y + z \cdot \left(\color{blue}{\frac{-1 \cdot 0}{y}} + \left(-\frac{z}{y}\right)\right)\right) \]
      7. metadata-eval81.9%

        \[\leadsto 0.5 \cdot \left(y + z \cdot \left(\frac{\color{blue}{0}}{y} + \left(-\frac{z}{y}\right)\right)\right) \]
      8. unsub-neg81.9%

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

        \[\leadsto 0.5 \cdot \left(y + z \cdot \left(\color{blue}{0} - \frac{z}{y}\right)\right) \]
      10. neg-sub081.9%

        \[\leadsto 0.5 \cdot \left(y + z \cdot \color{blue}{\left(-\frac{z}{y}\right)}\right) \]
      11. *-commutative81.9%

        \[\leadsto 0.5 \cdot \left(y + \color{blue}{\left(-\frac{z}{y}\right) \cdot z}\right) \]
      12. distribute-lft-neg-out81.9%

        \[\leadsto 0.5 \cdot \left(y + \color{blue}{\left(-\frac{z}{y} \cdot z\right)}\right) \]
      13. distribute-rgt-neg-in81.9%

        \[\leadsto 0.5 \cdot \left(y + \color{blue}{\frac{z}{y} \cdot \left(-z\right)}\right) \]
    11. Simplified81.9%

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

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

Alternative 5: 74.8% accurate, 1.1× speedup?

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

\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;x \leq 4.25 \cdot 10^{+89}:\\
\;\;\;\;0.5 \cdot \left(y\_m - z \cdot \frac{z}{y\_m}\right)\\

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


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

    1. Initial program 71.2%

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

        \[\leadsto \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{\color{blue}{-\left(-y \cdot 2\right)}} \]
      2. distribute-lft-neg-out71.2%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}{y}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. prod-diff54.6%

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

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

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

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

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

      \[\leadsto 0.5 \cdot \frac{\mathsf{fma}\left(x, x, \color{blue}{\mathsf{fma}\left(y + z, y - z, \mathsf{fma}\left(-z, z, {z}^{2}\right)\right)}\right)}{y} \]
    7. Taylor expanded in z around -inf 53.3%

      \[\leadsto 0.5 \cdot \frac{\color{blue}{{z}^{2} \cdot \left(-1 \cdot \frac{y + \left(-1 \cdot y + -1 \cdot \frac{{x}^{2} + {y}^{2}}{z}\right)}{z} - 1\right)}}{y} \]
    8. Taylor expanded in z around 0 90.7%

      \[\leadsto 0.5 \cdot \color{blue}{\left(y + \left(z \cdot \left(-1 \cdot \frac{z}{y} + -1 \cdot \frac{y + -1 \cdot y}{y}\right) + \frac{{x}^{2}}{y}\right)\right)} \]
    9. Taylor expanded in x around 0 74.4%

      \[\leadsto 0.5 \cdot \left(y + \color{blue}{z \cdot \left(-1 \cdot \frac{z}{y} + -1 \cdot \frac{y + -1 \cdot y}{y}\right)}\right) \]
    10. Step-by-step derivation
      1. neg-mul-174.4%

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

        \[\leadsto 0.5 \cdot \left(y + z \cdot \color{blue}{\left(-1 \cdot \frac{y + -1 \cdot y}{y} + \left(-\frac{z}{y}\right)\right)}\right) \]
      3. distribute-rgt1-in74.4%

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

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

        \[\leadsto 0.5 \cdot \left(y + z \cdot \left(-1 \cdot \frac{\color{blue}{0}}{y} + \left(-\frac{z}{y}\right)\right)\right) \]
      6. associate-*r/74.4%

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

        \[\leadsto 0.5 \cdot \left(y + z \cdot \left(\frac{\color{blue}{0}}{y} + \left(-\frac{z}{y}\right)\right)\right) \]
      8. unsub-neg74.4%

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

        \[\leadsto 0.5 \cdot \left(y + z \cdot \left(\color{blue}{0} - \frac{z}{y}\right)\right) \]
      10. neg-sub074.4%

        \[\leadsto 0.5 \cdot \left(y + z \cdot \color{blue}{\left(-\frac{z}{y}\right)}\right) \]
      11. *-commutative74.4%

        \[\leadsto 0.5 \cdot \left(y + \color{blue}{\left(-\frac{z}{y}\right) \cdot z}\right) \]
      12. distribute-lft-neg-out74.4%

        \[\leadsto 0.5 \cdot \left(y + \color{blue}{\left(-\frac{z}{y} \cdot z\right)}\right) \]
      13. distribute-rgt-neg-in74.4%

        \[\leadsto 0.5 \cdot \left(y + \color{blue}{\frac{z}{y} \cdot \left(-z\right)}\right) \]
    11. Simplified74.4%

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

    if 4.25000000000000023e89 < x

    1. Initial program 68.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 inf 69.8%

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

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

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

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

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

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

      \[\leadsto y \cdot \left(0.5 + \frac{\color{blue}{\left(x + z\right) \cdot \left(x - z\right)}}{{y}^{2}} \cdot 0.5\right) \]
    8. Taylor expanded in y around 0 79.2%

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \left(\left(x - z\right) \cdot \frac{z + x}{y}\right)} \]
    11. Taylor expanded in z around 0 80.2%

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

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

Alternative 6: 57.5% accurate, 1.1× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \begin{array}{l} \mathbf{if}\;y\_m \leq 2.05 \cdot 10^{+94}:\\ \;\;\;\;0.5 \cdot \left(\left(x - z\right) \cdot \frac{x}{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 2.05e+94) (* 0.5 (* (- x z) (/ x 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 <= 2.05e+94) {
		tmp = 0.5 * ((x - z) * (x / 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 <= 2.05d+94) then
        tmp = 0.5d0 * ((x - z) * (x / 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 <= 2.05e+94) {
		tmp = 0.5 * ((x - z) * (x / 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 <= 2.05e+94:
		tmp = 0.5 * ((x - z) * (x / 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 <= 2.05e+94)
		tmp = Float64(0.5 * Float64(Float64(x - z) * Float64(x / 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 <= 2.05e+94)
		tmp = 0.5 * ((x - z) * (x / 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, 2.05e+94], N[(0.5 * N[(N[(x - z), $MachinePrecision] * N[(x / 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 2.05 \cdot 10^{+94}:\\
\;\;\;\;0.5 \cdot \left(\left(x - z\right) \cdot \frac{x}{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.05000000000000015e94

    1. Initial program 79.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 79.3%

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

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

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

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

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

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

      \[\leadsto y \cdot \left(0.5 + \frac{\color{blue}{\left(x + z\right) \cdot \left(x - z\right)}}{{y}^{2}} \cdot 0.5\right) \]
    8. Taylor expanded in y around 0 76.1%

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \left(\left(x - z\right) \cdot \frac{z + x}{y}\right)} \]
    11. Taylor expanded in z around 0 44.8%

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

    if 2.05000000000000015e94 < y

    1. Initial program 30.0%

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

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

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

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

Alternative 7: 34.2% accurate, 5.0× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ y\_s \cdot \left(y\_m \cdot 0.5\right) \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #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 70.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 30.9%

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

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

    \[\leadsto \color{blue}{y \cdot 0.5} \]
  6. Add Preprocessing

Developer target: 99.9% accurate, 1.0× speedup?

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

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

Reproduce

?
herbie shell --seed 2024091 
(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)))