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

Percentage Accurate: 69.2% → 95.1%
Time: 10.1s
Alternatives: 13
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 13 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: 95.1% accurate, 0.1× speedup?

\[\begin{array}{l} z = |z|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq -1.35 \cdot 10^{-18} \lor \neg \left(y \leq 3 \cdot 10^{-142}\right):\\ \;\;\;\;0.5 \cdot \left(\frac{x}{\frac{y}{x}} + \frac{y - z}{y} \cdot \left(y + z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, x, \left(y - z\right) \cdot \left(y + z\right)\right)}{y \cdot 2}\\ \end{array} \end{array} \]
NOTE: z should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -1.35e-18) (not (<= y 3e-142)))
   (* 0.5 (+ (/ x (/ y x)) (* (/ (- y z) y) (+ y z))))
   (/ (fma x x (* (- y z) (+ y z))) (* y 2.0))))
z = abs(z);
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -1.35e-18) || !(y <= 3e-142)) {
		tmp = 0.5 * ((x / (y / x)) + (((y - z) / y) * (y + z)));
	} else {
		tmp = fma(x, x, ((y - z) * (y + z))) / (y * 2.0);
	}
	return tmp;
}
z = abs(z)
function code(x, y, z)
	tmp = 0.0
	if ((y <= -1.35e-18) || !(y <= 3e-142))
		tmp = Float64(0.5 * Float64(Float64(x / Float64(y / x)) + Float64(Float64(Float64(y - z) / y) * Float64(y + z))));
	else
		tmp = Float64(fma(x, x, Float64(Float64(y - z) * Float64(y + z))) / Float64(y * 2.0));
	end
	return tmp
end
NOTE: z should be positive before calling this function
code[x_, y_, z_] := If[Or[LessEqual[y, -1.35e-18], N[Not[LessEqual[y, 3e-142]], $MachinePrecision]], N[(0.5 * N[(N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(y - z), $MachinePrecision] / y), $MachinePrecision] * N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x + N[(N[(y - z), $MachinePrecision] * N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{-18} \lor \neg \left(y \leq 3 \cdot 10^{-142}\right):\\
\;\;\;\;0.5 \cdot \left(\frac{x}{\frac{y}{x}} + \frac{y - z}{y} \cdot \left(y + z\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.34999999999999994e-18 or 3.0000000000000001e-142 < y

    1. Initial program 58.8%

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{{y}^{2} - {z}^{2}}{y} + 0.5 \cdot \frac{{x}^{2}}{y}} \]
    3. Step-by-step derivation
      1. distribute-lft-out58.8%

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{y}{x}} + \color{blue}{\frac{y - z}{\frac{y}{y + z}}}\right) \]
      10. associate-/r/99.2%

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

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

    if -1.34999999999999994e-18 < y < 3.0000000000000001e-142

    1. Initial program 94.5%

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

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

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

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

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

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

Alternative 2: 94.7% accurate, 0.0× speedup?

\[\begin{array}{l} z = |z|\\ \\ \begin{array}{l} \mathbf{if}\;x \cdot x \leq 2 \cdot 10^{+237}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\mathsf{hypot}\left(x, y\right)}{y}, \frac{\mathsf{hypot}\left(x, y\right)}{2}, \frac{z}{y} \cdot \frac{-z}{2}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \mathsf{fma}\left(\frac{x}{y}, x, y\right)\\ \end{array} \end{array} \]
NOTE: z should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (<= (* x x) 2e+237)
   (fma (/ (hypot x y) y) (/ (hypot x y) 2.0) (* (/ z y) (/ (- z) 2.0)))
   (* 0.5 (fma (/ x y) x y))))
z = abs(z);
double code(double x, double y, double z) {
	double tmp;
	if ((x * x) <= 2e+237) {
		tmp = fma((hypot(x, y) / y), (hypot(x, y) / 2.0), ((z / y) * (-z / 2.0)));
	} else {
		tmp = 0.5 * fma((x / y), x, y);
	}
	return tmp;
}
z = abs(z)
function code(x, y, z)
	tmp = 0.0
	if (Float64(x * x) <= 2e+237)
		tmp = fma(Float64(hypot(x, y) / y), Float64(hypot(x, y) / 2.0), Float64(Float64(z / y) * Float64(Float64(-z) / 2.0)));
	else
		tmp = Float64(0.5 * fma(Float64(x / y), x, y));
	end
	return tmp
end
NOTE: z should be positive before calling this function
code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 2e+237], N[(N[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] / y), $MachinePrecision] * N[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] / 2.0), $MachinePrecision] + N[(N[(z / y), $MachinePrecision] * N[((-z) / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(x / y), $MachinePrecision] * x + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{+237}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\mathsf{hypot}\left(x, y\right)}{y}, \frac{\mathsf{hypot}\left(x, y\right)}{2}, \frac{z}{y} \cdot \frac{-z}{2}\right)\\

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


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

    1. Initial program 76.9%

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{\mathsf{hypot}\left(x, y\right)}{y}, \frac{\mathsf{hypot}\left(x, y\right)}{2}, -\color{blue}{\frac{z}{y} \cdot \frac{z}{2}}\right) \]
    3. Applied egg-rr99.9%

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

    if 1.99999999999999988e237 < (*.f64 x x)

    1. Initial program 59.5%

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

      \[\leadsto \color{blue}{0.5 \cdot y + 0.5 \cdot \frac{{x}^{2} - {z}^{2}}{y}} \]
    3. Step-by-step derivation
      1. distribute-lft-out60.8%

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(y + \color{blue}{\frac{x}{\frac{y}{x}}}\right) \]
    7. Simplified89.8%

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\mathsf{fma}\left(\frac{x}{y}, x, y\right)} \]
    9. Applied egg-rr89.8%

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

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

Alternative 3: 86.1% accurate, 0.6× speedup?

\[\begin{array}{l} z = |z|\\ \\ \begin{array}{l} \mathbf{if}\;x \cdot x \leq 2 \cdot 10^{+132}:\\ \;\;\;\;0.5 \cdot \left(y - \frac{z}{\frac{y}{z}}\right)\\ \mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+222} \lor \neg \left(x \cdot x \leq 2 \cdot 10^{+295}\right):\\ \;\;\;\;0.5 \cdot \left(y + \frac{x}{\frac{y}{x}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot x - z \cdot z}{y \cdot 2}\\ \end{array} \end{array} \]
NOTE: z should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (<= (* x x) 2e+132)
   (* 0.5 (- y (/ z (/ y z))))
   (if (or (<= (* x x) 5e+222) (not (<= (* x x) 2e+295)))
     (* 0.5 (+ y (/ x (/ y x))))
     (/ (- (* x x) (* z z)) (* y 2.0)))))
z = abs(z);
double code(double x, double y, double z) {
	double tmp;
	if ((x * x) <= 2e+132) {
		tmp = 0.5 * (y - (z / (y / z)));
	} else if (((x * x) <= 5e+222) || !((x * x) <= 2e+295)) {
		tmp = 0.5 * (y + (x / (y / x)));
	} else {
		tmp = ((x * x) - (z * z)) / (y * 2.0);
	}
	return tmp;
}
NOTE: z should be positive before calling this function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((x * x) <= 2d+132) then
        tmp = 0.5d0 * (y - (z / (y / z)))
    else if (((x * x) <= 5d+222) .or. (.not. ((x * x) <= 2d+295))) then
        tmp = 0.5d0 * (y + (x / (y / x)))
    else
        tmp = ((x * x) - (z * z)) / (y * 2.0d0)
    end if
    code = tmp
end function
z = Math.abs(z);
public static double code(double x, double y, double z) {
	double tmp;
	if ((x * x) <= 2e+132) {
		tmp = 0.5 * (y - (z / (y / z)));
	} else if (((x * x) <= 5e+222) || !((x * x) <= 2e+295)) {
		tmp = 0.5 * (y + (x / (y / x)));
	} else {
		tmp = ((x * x) - (z * z)) / (y * 2.0);
	}
	return tmp;
}
z = abs(z)
def code(x, y, z):
	tmp = 0
	if (x * x) <= 2e+132:
		tmp = 0.5 * (y - (z / (y / z)))
	elif ((x * x) <= 5e+222) or not ((x * x) <= 2e+295):
		tmp = 0.5 * (y + (x / (y / x)))
	else:
		tmp = ((x * x) - (z * z)) / (y * 2.0)
	return tmp
z = abs(z)
function code(x, y, z)
	tmp = 0.0
	if (Float64(x * x) <= 2e+132)
		tmp = Float64(0.5 * Float64(y - Float64(z / Float64(y / z))));
	elseif ((Float64(x * x) <= 5e+222) || !(Float64(x * x) <= 2e+295))
		tmp = Float64(0.5 * Float64(y + Float64(x / Float64(y / x))));
	else
		tmp = Float64(Float64(Float64(x * x) - Float64(z * z)) / Float64(y * 2.0));
	end
	return tmp
end
z = abs(z)
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x * x) <= 2e+132)
		tmp = 0.5 * (y - (z / (y / z)));
	elseif (((x * x) <= 5e+222) || ~(((x * x) <= 2e+295)))
		tmp = 0.5 * (y + (x / (y / x)));
	else
		tmp = ((x * x) - (z * z)) / (y * 2.0);
	end
	tmp_2 = tmp;
end
NOTE: z should be positive before calling this function
code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 2e+132], N[(0.5 * N[(y - N[(z / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[N[(x * x), $MachinePrecision], 5e+222], N[Not[LessEqual[N[(x * x), $MachinePrecision], 2e+295]], $MachinePrecision]], N[(0.5 * N[(y + N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * x), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{+132}:\\
\;\;\;\;0.5 \cdot \left(y - \frac{z}{\frac{y}{z}}\right)\\

\mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+222} \lor \neg \left(x \cdot x \leq 2 \cdot 10^{+295}\right):\\
\;\;\;\;0.5 \cdot \left(y + \frac{x}{\frac{y}{x}}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{x \cdot x - z \cdot z}{y \cdot 2}\\


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

    1. Initial program 77.7%

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

        \[\leadsto \color{blue}{\frac{x \cdot x + y \cdot y}{y \cdot 2} - \frac{z \cdot z}{y \cdot 2}} \]
      2. sub-neg75.7%

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{\mathsf{hypot}\left(x, y\right)}{y}, \frac{\mathsf{hypot}\left(x, y\right)}{2}, -\color{blue}{\frac{z}{y} \cdot \frac{z}{2}}\right) \]
    3. Applied egg-rr99.9%

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

      \[\leadsto \color{blue}{0.5 \cdot y - 0.5 \cdot \frac{{z}^{2}}{y}} \]
    5. Step-by-step derivation
      1. distribute-lft-out--85.0%

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

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

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

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

    if 1.99999999999999998e132 < (*.f64 x x) < 5.00000000000000023e222 or 2e295 < (*.f64 x x)

    1. Initial program 56.9%

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

      \[\leadsto \color{blue}{0.5 \cdot y + 0.5 \cdot \frac{{x}^{2} - {z}^{2}}{y}} \]
    3. Step-by-step derivation
      1. distribute-lft-out60.1%

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

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

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

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

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

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

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

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

    if 5.00000000000000023e222 < (*.f64 x x) < 2e295

    1. Initial program 94.5%

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

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

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

        \[\leadsto \frac{x \cdot x - \color{blue}{z \cdot z}}{y \cdot 2} \]
    4. Simplified94.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 2 \cdot 10^{+132}:\\ \;\;\;\;0.5 \cdot \left(y - \frac{z}{\frac{y}{z}}\right)\\ \mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+222} \lor \neg \left(x \cdot x \leq 2 \cdot 10^{+295}\right):\\ \;\;\;\;0.5 \cdot \left(y + \frac{x}{\frac{y}{x}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot x - z \cdot z}{y \cdot 2}\\ \end{array} \]

Alternative 4: 94.5% accurate, 0.7× speedup?

\[\begin{array}{l} z = |z|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{-18} \lor \neg \left(y \leq 1.65 \cdot 10^{-96}\right):\\ \;\;\;\;0.5 \cdot \left(\frac{x}{\frac{y}{x}} + \frac{y - z}{y} \cdot \left(y + z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(y + \frac{x \cdot x - z \cdot z}{y}\right)\\ \end{array} \end{array} \]
NOTE: z should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -1e-18) (not (<= y 1.65e-96)))
   (* 0.5 (+ (/ x (/ y x)) (* (/ (- y z) y) (+ y z))))
   (* 0.5 (+ y (/ (- (* x x) (* z z)) y)))))
z = abs(z);
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -1e-18) || !(y <= 1.65e-96)) {
		tmp = 0.5 * ((x / (y / x)) + (((y - z) / y) * (y + z)));
	} else {
		tmp = 0.5 * (y + (((x * x) - (z * z)) / y));
	}
	return tmp;
}
NOTE: z should be positive before calling this function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((y <= (-1d-18)) .or. (.not. (y <= 1.65d-96))) then
        tmp = 0.5d0 * ((x / (y / x)) + (((y - z) / y) * (y + z)))
    else
        tmp = 0.5d0 * (y + (((x * x) - (z * z)) / y))
    end if
    code = tmp
end function
z = Math.abs(z);
public static double code(double x, double y, double z) {
	double tmp;
	if ((y <= -1e-18) || !(y <= 1.65e-96)) {
		tmp = 0.5 * ((x / (y / x)) + (((y - z) / y) * (y + z)));
	} else {
		tmp = 0.5 * (y + (((x * x) - (z * z)) / y));
	}
	return tmp;
}
z = abs(z)
def code(x, y, z):
	tmp = 0
	if (y <= -1e-18) or not (y <= 1.65e-96):
		tmp = 0.5 * ((x / (y / x)) + (((y - z) / y) * (y + z)))
	else:
		tmp = 0.5 * (y + (((x * x) - (z * z)) / y))
	return tmp
z = abs(z)
function code(x, y, z)
	tmp = 0.0
	if ((y <= -1e-18) || !(y <= 1.65e-96))
		tmp = Float64(0.5 * Float64(Float64(x / Float64(y / x)) + Float64(Float64(Float64(y - z) / y) * Float64(y + z))));
	else
		tmp = Float64(0.5 * Float64(y + Float64(Float64(Float64(x * x) - Float64(z * z)) / y)));
	end
	return tmp
end
z = abs(z)
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y <= -1e-18) || ~((y <= 1.65e-96)))
		tmp = 0.5 * ((x / (y / x)) + (((y - z) / y) * (y + z)));
	else
		tmp = 0.5 * (y + (((x * x) - (z * z)) / y));
	end
	tmp_2 = tmp;
end
NOTE: z should be positive before calling this function
code[x_, y_, z_] := If[Or[LessEqual[y, -1e-18], N[Not[LessEqual[y, 1.65e-96]], $MachinePrecision]], N[(0.5 * N[(N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(y - z), $MachinePrecision] / y), $MachinePrecision] * N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y + N[(N[(N[(x * x), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{-18} \lor \neg \left(y \leq 1.65 \cdot 10^{-96}\right):\\
\;\;\;\;0.5 \cdot \left(\frac{x}{\frac{y}{x}} + \frac{y - z}{y} \cdot \left(y + z\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.0000000000000001e-18 or 1.64999999999999995e-96 < y

    1. Initial program 55.6%

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{{y}^{2} - {z}^{2}}{y} + 0.5 \cdot \frac{{x}^{2}}{y}} \]
    3. Step-by-step derivation
      1. distribute-lft-out55.6%

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(\frac{x}{\frac{y}{x}} + \color{blue}{\frac{y - z}{\frac{y}{y + z}}}\right) \]
      10. associate-/r/99.2%

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

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

    if -1.0000000000000001e-18 < y < 1.64999999999999995e-96

    1. Initial program 95.1%

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

      \[\leadsto \color{blue}{0.5 \cdot y + 0.5 \cdot \frac{{x}^{2} - {z}^{2}}{y}} \]
    3. Step-by-step derivation
      1. distribute-lft-out95.2%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{-18} \lor \neg \left(y \leq 1.65 \cdot 10^{-96}\right):\\ \;\;\;\;0.5 \cdot \left(\frac{x}{\frac{y}{x}} + \frac{y - z}{y} \cdot \left(y + z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(y + \frac{x \cdot x - z \cdot z}{y}\right)\\ \end{array} \]

Alternative 5: 94.8% accurate, 0.7× speedup?

\[\begin{array}{l} z = |z|\\ \\ \begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{-18}:\\ \;\;\;\;0.5 \cdot \left(\frac{x}{\frac{y}{x}} + \left(y - \frac{z \cdot z}{y}\right)\right)\\ \mathbf{elif}\;z \cdot z \leq 4 \cdot 10^{+284}:\\ \;\;\;\;0.5 \cdot \left(y + \frac{x \cdot x - z \cdot z}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 \cdot \frac{\frac{y}{y + z}}{y - z}}\\ \end{array} \end{array} \]
NOTE: z should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (<= (* z z) 1e-18)
   (* 0.5 (+ (/ x (/ y x)) (- y (/ (* z z) y))))
   (if (<= (* z z) 4e+284)
     (* 0.5 (+ y (/ (- (* x x) (* z z)) y)))
     (/ 1.0 (* 2.0 (/ (/ y (+ y z)) (- y z)))))))
z = abs(z);
double code(double x, double y, double z) {
	double tmp;
	if ((z * z) <= 1e-18) {
		tmp = 0.5 * ((x / (y / x)) + (y - ((z * z) / y)));
	} else if ((z * z) <= 4e+284) {
		tmp = 0.5 * (y + (((x * x) - (z * z)) / y));
	} else {
		tmp = 1.0 / (2.0 * ((y / (y + z)) / (y - z)));
	}
	return tmp;
}
NOTE: z should be positive before calling this function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((z * z) <= 1d-18) then
        tmp = 0.5d0 * ((x / (y / x)) + (y - ((z * z) / y)))
    else if ((z * z) <= 4d+284) then
        tmp = 0.5d0 * (y + (((x * x) - (z * z)) / y))
    else
        tmp = 1.0d0 / (2.0d0 * ((y / (y + z)) / (y - z)))
    end if
    code = tmp
end function
z = Math.abs(z);
public static double code(double x, double y, double z) {
	double tmp;
	if ((z * z) <= 1e-18) {
		tmp = 0.5 * ((x / (y / x)) + (y - ((z * z) / y)));
	} else if ((z * z) <= 4e+284) {
		tmp = 0.5 * (y + (((x * x) - (z * z)) / y));
	} else {
		tmp = 1.0 / (2.0 * ((y / (y + z)) / (y - z)));
	}
	return tmp;
}
z = abs(z)
def code(x, y, z):
	tmp = 0
	if (z * z) <= 1e-18:
		tmp = 0.5 * ((x / (y / x)) + (y - ((z * z) / y)))
	elif (z * z) <= 4e+284:
		tmp = 0.5 * (y + (((x * x) - (z * z)) / y))
	else:
		tmp = 1.0 / (2.0 * ((y / (y + z)) / (y - z)))
	return tmp
z = abs(z)
function code(x, y, z)
	tmp = 0.0
	if (Float64(z * z) <= 1e-18)
		tmp = Float64(0.5 * Float64(Float64(x / Float64(y / x)) + Float64(y - Float64(Float64(z * z) / y))));
	elseif (Float64(z * z) <= 4e+284)
		tmp = Float64(0.5 * Float64(y + Float64(Float64(Float64(x * x) - Float64(z * z)) / y)));
	else
		tmp = Float64(1.0 / Float64(2.0 * Float64(Float64(y / Float64(y + z)) / Float64(y - z))));
	end
	return tmp
end
z = abs(z)
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z * z) <= 1e-18)
		tmp = 0.5 * ((x / (y / x)) + (y - ((z * z) / y)));
	elseif ((z * z) <= 4e+284)
		tmp = 0.5 * (y + (((x * x) - (z * z)) / y));
	else
		tmp = 1.0 / (2.0 * ((y / (y + z)) / (y - z)));
	end
	tmp_2 = tmp;
end
NOTE: z should be positive before calling this function
code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e-18], N[(0.5 * N[(N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision] + N[(y - N[(N[(z * z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * z), $MachinePrecision], 4e+284], N[(0.5 * N[(y + N[(N[(N[(x * x), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 * N[(N[(y / N[(y + z), $MachinePrecision]), $MachinePrecision] / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{-18}:\\
\;\;\;\;0.5 \cdot \left(\frac{x}{\frac{y}{x}} + \left(y - \frac{z \cdot z}{y}\right)\right)\\

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{2 \cdot \frac{\frac{y}{y + z}}{y - z}}\\


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

    1. Initial program 73.4%

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

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

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

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

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

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

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

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

    if 1.0000000000000001e-18 < (*.f64 z z) < 4.00000000000000032e284

    1. Initial program 90.1%

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

      \[\leadsto \color{blue}{0.5 \cdot y + 0.5 \cdot \frac{{x}^{2} - {z}^{2}}{y}} \]
    3. Step-by-step derivation
      1. distribute-lft-out96.6%

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

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

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

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

    if 4.00000000000000032e284 < (*.f64 z z)

    1. Initial program 54.7%

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{y \cdot y} - {z}^{2}}{y} \]
      2. unpow257.3%

        \[\leadsto 0.5 \cdot \frac{y \cdot y - \color{blue}{z \cdot z}}{y} \]
      3. difference-of-squares62.5%

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\frac{y - z}{\frac{y}{y + z}}} \]
      6. associate-*r/86.0%

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{0.5} \cdot \frac{\frac{y}{y + z}}{y - z}}} \]
      4. metadata-eval86.0%

        \[\leadsto \frac{1}{\color{blue}{2} \cdot \frac{\frac{y}{y + z}}{y - z}} \]
    8. Simplified86.0%

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

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

Alternative 6: 91.5% accurate, 0.9× speedup?

\[\begin{array}{l} z = |z|\\ \\ \begin{array}{l} \mathbf{if}\;x \cdot x \leq 2 \cdot 10^{+295}:\\ \;\;\;\;0.5 \cdot \left(y + \frac{x \cdot x - z \cdot z}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(y + \frac{x}{\frac{y}{x}}\right)\\ \end{array} \end{array} \]
NOTE: z should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (<= (* x x) 2e+295)
   (* 0.5 (+ y (/ (- (* x x) (* z z)) y)))
   (* 0.5 (+ y (/ x (/ y x))))))
z = abs(z);
double code(double x, double y, double z) {
	double tmp;
	if ((x * x) <= 2e+295) {
		tmp = 0.5 * (y + (((x * x) - (z * z)) / y));
	} else {
		tmp = 0.5 * (y + (x / (y / x)));
	}
	return tmp;
}
NOTE: z should be positive before calling this function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((x * x) <= 2d+295) then
        tmp = 0.5d0 * (y + (((x * x) - (z * z)) / y))
    else
        tmp = 0.5d0 * (y + (x / (y / x)))
    end if
    code = tmp
end function
z = Math.abs(z);
public static double code(double x, double y, double z) {
	double tmp;
	if ((x * x) <= 2e+295) {
		tmp = 0.5 * (y + (((x * x) - (z * z)) / y));
	} else {
		tmp = 0.5 * (y + (x / (y / x)));
	}
	return tmp;
}
z = abs(z)
def code(x, y, z):
	tmp = 0
	if (x * x) <= 2e+295:
		tmp = 0.5 * (y + (((x * x) - (z * z)) / y))
	else:
		tmp = 0.5 * (y + (x / (y / x)))
	return tmp
z = abs(z)
function code(x, y, z)
	tmp = 0.0
	if (Float64(x * x) <= 2e+295)
		tmp = Float64(0.5 * Float64(y + Float64(Float64(Float64(x * x) - Float64(z * z)) / y)));
	else
		tmp = Float64(0.5 * Float64(y + Float64(x / Float64(y / x))));
	end
	return tmp
end
z = abs(z)
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x * x) <= 2e+295)
		tmp = 0.5 * (y + (((x * x) - (z * z)) / y));
	else
		tmp = 0.5 * (y + (x / (y / x)));
	end
	tmp_2 = tmp;
end
NOTE: z should be positive before calling this function
code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 2e+295], N[(0.5 * N[(y + N[(N[(N[(x * x), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y + N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{+295}:\\
\;\;\;\;0.5 \cdot \left(y + \frac{x \cdot x - z \cdot z}{y}\right)\\

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


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

    1. Initial program 78.6%

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

      \[\leadsto \color{blue}{0.5 \cdot y + 0.5 \cdot \frac{{x}^{2} - {z}^{2}}{y}} \]
    3. Step-by-step derivation
      1. distribute-lft-out91.4%

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

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

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

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

    if 2e295 < (*.f64 x x)

    1. Initial program 50.8%

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

      \[\leadsto \color{blue}{0.5 \cdot y + 0.5 \cdot \frac{{x}^{2} - {z}^{2}}{y}} \]
    3. Step-by-step derivation
      1. distribute-lft-out52.4%

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

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

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

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

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

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

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

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

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

Alternative 7: 44.3% accurate, 1.0× speedup?

\[\begin{array}{l} z = |z|\\ \\ \begin{array}{l} t_0 := \left(z \cdot \frac{z}{y}\right) \cdot -0.5\\ \mathbf{if}\;x \leq 3.2 \cdot 10^{-200}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{-35}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 9.6 \cdot 10^{-6}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{+50}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \end{array} \end{array} \]
NOTE: z should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* (* z (/ z y)) -0.5)))
   (if (<= x 3.2e-200)
     (* y 0.5)
     (if (<= x 7.2e-35)
       t_0
       (if (<= x 9.6e-6)
         (* y 0.5)
         (if (<= x 8.5e+50) t_0 (* 0.5 (/ x (/ y x)))))))))
z = abs(z);
double code(double x, double y, double z) {
	double t_0 = (z * (z / y)) * -0.5;
	double tmp;
	if (x <= 3.2e-200) {
		tmp = y * 0.5;
	} else if (x <= 7.2e-35) {
		tmp = t_0;
	} else if (x <= 9.6e-6) {
		tmp = y * 0.5;
	} else if (x <= 8.5e+50) {
		tmp = t_0;
	} else {
		tmp = 0.5 * (x / (y / x));
	}
	return tmp;
}
NOTE: z should be positive before calling this function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (z * (z / y)) * (-0.5d0)
    if (x <= 3.2d-200) then
        tmp = y * 0.5d0
    else if (x <= 7.2d-35) then
        tmp = t_0
    else if (x <= 9.6d-6) then
        tmp = y * 0.5d0
    else if (x <= 8.5d+50) then
        tmp = t_0
    else
        tmp = 0.5d0 * (x / (y / x))
    end if
    code = tmp
end function
z = Math.abs(z);
public static double code(double x, double y, double z) {
	double t_0 = (z * (z / y)) * -0.5;
	double tmp;
	if (x <= 3.2e-200) {
		tmp = y * 0.5;
	} else if (x <= 7.2e-35) {
		tmp = t_0;
	} else if (x <= 9.6e-6) {
		tmp = y * 0.5;
	} else if (x <= 8.5e+50) {
		tmp = t_0;
	} else {
		tmp = 0.5 * (x / (y / x));
	}
	return tmp;
}
z = abs(z)
def code(x, y, z):
	t_0 = (z * (z / y)) * -0.5
	tmp = 0
	if x <= 3.2e-200:
		tmp = y * 0.5
	elif x <= 7.2e-35:
		tmp = t_0
	elif x <= 9.6e-6:
		tmp = y * 0.5
	elif x <= 8.5e+50:
		tmp = t_0
	else:
		tmp = 0.5 * (x / (y / x))
	return tmp
z = abs(z)
function code(x, y, z)
	t_0 = Float64(Float64(z * Float64(z / y)) * -0.5)
	tmp = 0.0
	if (x <= 3.2e-200)
		tmp = Float64(y * 0.5);
	elseif (x <= 7.2e-35)
		tmp = t_0;
	elseif (x <= 9.6e-6)
		tmp = Float64(y * 0.5);
	elseif (x <= 8.5e+50)
		tmp = t_0;
	else
		tmp = Float64(0.5 * Float64(x / Float64(y / x)));
	end
	return tmp
end
z = abs(z)
function tmp_2 = code(x, y, z)
	t_0 = (z * (z / y)) * -0.5;
	tmp = 0.0;
	if (x <= 3.2e-200)
		tmp = y * 0.5;
	elseif (x <= 7.2e-35)
		tmp = t_0;
	elseif (x <= 9.6e-6)
		tmp = y * 0.5;
	elseif (x <= 8.5e+50)
		tmp = t_0;
	else
		tmp = 0.5 * (x / (y / x));
	end
	tmp_2 = tmp;
end
NOTE: z should be positive before calling this function
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z * N[(z / y), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]}, If[LessEqual[x, 3.2e-200], N[(y * 0.5), $MachinePrecision], If[LessEqual[x, 7.2e-35], t$95$0, If[LessEqual[x, 9.6e-6], N[(y * 0.5), $MachinePrecision], If[LessEqual[x, 8.5e+50], t$95$0, N[(0.5 * N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
t_0 := \left(z \cdot \frac{z}{y}\right) \cdot -0.5\\
\mathbf{if}\;x \leq 3.2 \cdot 10^{-200}:\\
\;\;\;\;y \cdot 0.5\\

\mathbf{elif}\;x \leq 7.2 \cdot 10^{-35}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 9.6 \cdot 10^{-6}:\\
\;\;\;\;y \cdot 0.5\\

\mathbf{elif}\;x \leq 8.5 \cdot 10^{+50}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < 3.19999999999999983e-200 or 7.20000000000000038e-35 < x < 9.5999999999999996e-6

    1. Initial program 72.2%

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

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

    if 3.19999999999999983e-200 < x < 7.20000000000000038e-35 or 9.5999999999999996e-6 < x < 8.49999999999999961e50

    1. Initial program 83.5%

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

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

        \[\leadsto \color{blue}{\frac{{z}^{2}}{y} \cdot -0.5} \]
      2. unpow257.5%

        \[\leadsto \frac{\color{blue}{z \cdot z}}{y} \cdot -0.5 \]
    4. Simplified57.5%

      \[\leadsto \color{blue}{\frac{z \cdot z}{y} \cdot -0.5} \]
    5. Taylor expanded in z around 0 57.5%

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

        \[\leadsto \frac{\color{blue}{z \cdot z}}{y} \cdot -0.5 \]
      2. associate-*r/59.8%

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

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

    if 8.49999999999999961e50 < x

    1. Initial program 62.9%

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{x \cdot x}}{y} \]
      2. associate-/l*68.3%

        \[\leadsto 0.5 \cdot \color{blue}{\frac{x}{\frac{y}{x}}} \]
    4. Simplified68.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 3.2 \cdot 10^{-200}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{-35}:\\ \;\;\;\;\left(z \cdot \frac{z}{y}\right) \cdot -0.5\\ \mathbf{elif}\;x \leq 9.6 \cdot 10^{-6}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{+50}:\\ \;\;\;\;\left(z \cdot \frac{z}{y}\right) \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \end{array} \]

Alternative 8: 44.1% accurate, 1.0× speedup?

\[\begin{array}{l} z = |z|\\ \\ \begin{array}{l} t_0 := \frac{z}{\frac{y}{z} \cdot -2}\\ \mathbf{if}\;x \leq 3 \cdot 10^{-208}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{-35}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.8 \cdot 10^{-7}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;x \leq 7 \cdot 10^{+50}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \end{array} \end{array} \]
NOTE: z should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ z (* (/ y z) -2.0))))
   (if (<= x 3e-208)
     (* y 0.5)
     (if (<= x 5.8e-35)
       t_0
       (if (<= x 3.8e-7)
         (* y 0.5)
         (if (<= x 7e+50) t_0 (* 0.5 (/ x (/ y x)))))))))
z = abs(z);
double code(double x, double y, double z) {
	double t_0 = z / ((y / z) * -2.0);
	double tmp;
	if (x <= 3e-208) {
		tmp = y * 0.5;
	} else if (x <= 5.8e-35) {
		tmp = t_0;
	} else if (x <= 3.8e-7) {
		tmp = y * 0.5;
	} else if (x <= 7e+50) {
		tmp = t_0;
	} else {
		tmp = 0.5 * (x / (y / x));
	}
	return tmp;
}
NOTE: z should be positive before calling this function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = z / ((y / z) * (-2.0d0))
    if (x <= 3d-208) then
        tmp = y * 0.5d0
    else if (x <= 5.8d-35) then
        tmp = t_0
    else if (x <= 3.8d-7) then
        tmp = y * 0.5d0
    else if (x <= 7d+50) then
        tmp = t_0
    else
        tmp = 0.5d0 * (x / (y / x))
    end if
    code = tmp
end function
z = Math.abs(z);
public static double code(double x, double y, double z) {
	double t_0 = z / ((y / z) * -2.0);
	double tmp;
	if (x <= 3e-208) {
		tmp = y * 0.5;
	} else if (x <= 5.8e-35) {
		tmp = t_0;
	} else if (x <= 3.8e-7) {
		tmp = y * 0.5;
	} else if (x <= 7e+50) {
		tmp = t_0;
	} else {
		tmp = 0.5 * (x / (y / x));
	}
	return tmp;
}
z = abs(z)
def code(x, y, z):
	t_0 = z / ((y / z) * -2.0)
	tmp = 0
	if x <= 3e-208:
		tmp = y * 0.5
	elif x <= 5.8e-35:
		tmp = t_0
	elif x <= 3.8e-7:
		tmp = y * 0.5
	elif x <= 7e+50:
		tmp = t_0
	else:
		tmp = 0.5 * (x / (y / x))
	return tmp
z = abs(z)
function code(x, y, z)
	t_0 = Float64(z / Float64(Float64(y / z) * -2.0))
	tmp = 0.0
	if (x <= 3e-208)
		tmp = Float64(y * 0.5);
	elseif (x <= 5.8e-35)
		tmp = t_0;
	elseif (x <= 3.8e-7)
		tmp = Float64(y * 0.5);
	elseif (x <= 7e+50)
		tmp = t_0;
	else
		tmp = Float64(0.5 * Float64(x / Float64(y / x)));
	end
	return tmp
end
z = abs(z)
function tmp_2 = code(x, y, z)
	t_0 = z / ((y / z) * -2.0);
	tmp = 0.0;
	if (x <= 3e-208)
		tmp = y * 0.5;
	elseif (x <= 5.8e-35)
		tmp = t_0;
	elseif (x <= 3.8e-7)
		tmp = y * 0.5;
	elseif (x <= 7e+50)
		tmp = t_0;
	else
		tmp = 0.5 * (x / (y / x));
	end
	tmp_2 = tmp;
end
NOTE: z should be positive before calling this function
code[x_, y_, z_] := Block[{t$95$0 = N[(z / N[(N[(y / z), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 3e-208], N[(y * 0.5), $MachinePrecision], If[LessEqual[x, 5.8e-35], t$95$0, If[LessEqual[x, 3.8e-7], N[(y * 0.5), $MachinePrecision], If[LessEqual[x, 7e+50], t$95$0, N[(0.5 * N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
t_0 := \frac{z}{\frac{y}{z} \cdot -2}\\
\mathbf{if}\;x \leq 3 \cdot 10^{-208}:\\
\;\;\;\;y \cdot 0.5\\

\mathbf{elif}\;x \leq 5.8 \cdot 10^{-35}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 3.8 \cdot 10^{-7}:\\
\;\;\;\;y \cdot 0.5\\

\mathbf{elif}\;x \leq 7 \cdot 10^{+50}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < 2.99999999999999986e-208 or 5.8000000000000004e-35 < x < 3.80000000000000015e-7

    1. Initial program 72.2%

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

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

    if 2.99999999999999986e-208 < x < 5.8000000000000004e-35 or 3.80000000000000015e-7 < x < 7.00000000000000012e50

    1. Initial program 83.5%

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

        \[\leadsto \color{blue}{\frac{x \cdot x + y \cdot y}{y \cdot 2} - \frac{z \cdot z}{y \cdot 2}} \]
      2. sub-neg81.0%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{{z}^{2}}{y}} \]
    5. Step-by-step derivation
      1. *-commutative57.5%

        \[\leadsto \color{blue}{\frac{{z}^{2}}{y} \cdot -0.5} \]
      2. unpow257.5%

        \[\leadsto \frac{\color{blue}{z \cdot z}}{y} \cdot -0.5 \]
      3. metadata-eval57.5%

        \[\leadsto \frac{z \cdot z}{y} \cdot \color{blue}{\frac{1}{-2}} \]
      4. associate-/l*59.9%

        \[\leadsto \color{blue}{\frac{z}{\frac{y}{z}}} \cdot \frac{1}{-2} \]
      5. times-frac59.9%

        \[\leadsto \color{blue}{\frac{z \cdot 1}{\frac{y}{z} \cdot -2}} \]
      6. *-rgt-identity59.9%

        \[\leadsto \frac{\color{blue}{z}}{\frac{y}{z} \cdot -2} \]
    6. Simplified59.9%

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

    if 7.00000000000000012e50 < x

    1. Initial program 62.9%

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{x \cdot x}}{y} \]
      2. associate-/l*68.3%

        \[\leadsto 0.5 \cdot \color{blue}{\frac{x}{\frac{y}{x}}} \]
    4. Simplified68.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 3 \cdot 10^{-208}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{-35}:\\ \;\;\;\;\frac{z}{\frac{y}{z} \cdot -2}\\ \mathbf{elif}\;x \leq 3.8 \cdot 10^{-7}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;x \leq 7 \cdot 10^{+50}:\\ \;\;\;\;\frac{z}{\frac{y}{z} \cdot -2}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \end{array} \]

Alternative 9: 44.2% accurate, 1.0× speedup?

\[\begin{array}{l} z = |z|\\ \\ \begin{array}{l} t_0 := \frac{z}{\frac{y}{z} \cdot -2}\\ \mathbf{if}\;x \leq 6.6 \cdot 10^{-205}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;x \leq 4.2 \cdot 10^{-35}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-8}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{+51}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \frac{x}{y}}{2}\\ \end{array} \end{array} \]
NOTE: z should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ z (* (/ y z) -2.0))))
   (if (<= x 6.6e-205)
     (* y 0.5)
     (if (<= x 4.2e-35)
       t_0
       (if (<= x 1.6e-8)
         (* y 0.5)
         (if (<= x 1.1e+51) t_0 (/ (* x (/ x y)) 2.0)))))))
z = abs(z);
double code(double x, double y, double z) {
	double t_0 = z / ((y / z) * -2.0);
	double tmp;
	if (x <= 6.6e-205) {
		tmp = y * 0.5;
	} else if (x <= 4.2e-35) {
		tmp = t_0;
	} else if (x <= 1.6e-8) {
		tmp = y * 0.5;
	} else if (x <= 1.1e+51) {
		tmp = t_0;
	} else {
		tmp = (x * (x / y)) / 2.0;
	}
	return tmp;
}
NOTE: z should be positive before calling this function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = z / ((y / z) * (-2.0d0))
    if (x <= 6.6d-205) then
        tmp = y * 0.5d0
    else if (x <= 4.2d-35) then
        tmp = t_0
    else if (x <= 1.6d-8) then
        tmp = y * 0.5d0
    else if (x <= 1.1d+51) then
        tmp = t_0
    else
        tmp = (x * (x / y)) / 2.0d0
    end if
    code = tmp
end function
z = Math.abs(z);
public static double code(double x, double y, double z) {
	double t_0 = z / ((y / z) * -2.0);
	double tmp;
	if (x <= 6.6e-205) {
		tmp = y * 0.5;
	} else if (x <= 4.2e-35) {
		tmp = t_0;
	} else if (x <= 1.6e-8) {
		tmp = y * 0.5;
	} else if (x <= 1.1e+51) {
		tmp = t_0;
	} else {
		tmp = (x * (x / y)) / 2.0;
	}
	return tmp;
}
z = abs(z)
def code(x, y, z):
	t_0 = z / ((y / z) * -2.0)
	tmp = 0
	if x <= 6.6e-205:
		tmp = y * 0.5
	elif x <= 4.2e-35:
		tmp = t_0
	elif x <= 1.6e-8:
		tmp = y * 0.5
	elif x <= 1.1e+51:
		tmp = t_0
	else:
		tmp = (x * (x / y)) / 2.0
	return tmp
z = abs(z)
function code(x, y, z)
	t_0 = Float64(z / Float64(Float64(y / z) * -2.0))
	tmp = 0.0
	if (x <= 6.6e-205)
		tmp = Float64(y * 0.5);
	elseif (x <= 4.2e-35)
		tmp = t_0;
	elseif (x <= 1.6e-8)
		tmp = Float64(y * 0.5);
	elseif (x <= 1.1e+51)
		tmp = t_0;
	else
		tmp = Float64(Float64(x * Float64(x / y)) / 2.0);
	end
	return tmp
end
z = abs(z)
function tmp_2 = code(x, y, z)
	t_0 = z / ((y / z) * -2.0);
	tmp = 0.0;
	if (x <= 6.6e-205)
		tmp = y * 0.5;
	elseif (x <= 4.2e-35)
		tmp = t_0;
	elseif (x <= 1.6e-8)
		tmp = y * 0.5;
	elseif (x <= 1.1e+51)
		tmp = t_0;
	else
		tmp = (x * (x / y)) / 2.0;
	end
	tmp_2 = tmp;
end
NOTE: z should be positive before calling this function
code[x_, y_, z_] := Block[{t$95$0 = N[(z / N[(N[(y / z), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 6.6e-205], N[(y * 0.5), $MachinePrecision], If[LessEqual[x, 4.2e-35], t$95$0, If[LessEqual[x, 1.6e-8], N[(y * 0.5), $MachinePrecision], If[LessEqual[x, 1.1e+51], t$95$0, N[(N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]]]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
t_0 := \frac{z}{\frac{y}{z} \cdot -2}\\
\mathbf{if}\;x \leq 6.6 \cdot 10^{-205}:\\
\;\;\;\;y \cdot 0.5\\

\mathbf{elif}\;x \leq 4.2 \cdot 10^{-35}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 1.6 \cdot 10^{-8}:\\
\;\;\;\;y \cdot 0.5\\

\mathbf{elif}\;x \leq 1.1 \cdot 10^{+51}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < 6.5999999999999998e-205 or 4.2e-35 < x < 1.6000000000000001e-8

    1. Initial program 72.2%

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

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

    if 6.5999999999999998e-205 < x < 4.2e-35 or 1.6000000000000001e-8 < x < 1.09999999999999996e51

    1. Initial program 83.5%

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

        \[\leadsto \color{blue}{\frac{x \cdot x + y \cdot y}{y \cdot 2} - \frac{z \cdot z}{y \cdot 2}} \]
      2. sub-neg81.0%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{{z}^{2}}{y}} \]
    5. Step-by-step derivation
      1. *-commutative57.5%

        \[\leadsto \color{blue}{\frac{{z}^{2}}{y} \cdot -0.5} \]
      2. unpow257.5%

        \[\leadsto \frac{\color{blue}{z \cdot z}}{y} \cdot -0.5 \]
      3. metadata-eval57.5%

        \[\leadsto \frac{z \cdot z}{y} \cdot \color{blue}{\frac{1}{-2}} \]
      4. associate-/l*59.9%

        \[\leadsto \color{blue}{\frac{z}{\frac{y}{z}}} \cdot \frac{1}{-2} \]
      5. times-frac59.9%

        \[\leadsto \color{blue}{\frac{z \cdot 1}{\frac{y}{z} \cdot -2}} \]
      6. *-rgt-identity59.9%

        \[\leadsto \frac{\color{blue}{z}}{\frac{y}{z} \cdot -2} \]
    6. Simplified59.9%

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

    if 1.09999999999999996e51 < x

    1. Initial program 62.9%

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{x \cdot x}}{y} \]
      2. associate-/l*68.3%

        \[\leadsto 0.5 \cdot \color{blue}{\frac{x}{\frac{y}{x}}} \]
    4. Simplified68.3%

      \[\leadsto \color{blue}{0.5 \cdot \frac{x}{\frac{y}{x}}} \]
    5. Step-by-step derivation
      1. metadata-eval68.3%

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

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

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

        \[\leadsto \color{blue}{\frac{1 \cdot \left(x \cdot x\right)}{2 \cdot y}} \]
      5. *-un-lft-identity61.7%

        \[\leadsto \frac{\color{blue}{x \cdot x}}{2 \cdot y} \]
      6. *-commutative61.7%

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

        \[\leadsto \color{blue}{\frac{\frac{x \cdot x}{y}}{2}} \]
      8. associate-*l/68.4%

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

        \[\leadsto \frac{\color{blue}{\frac{x}{\frac{y}{x}}}}{2} \]
      10. div-inv68.3%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 6.6 \cdot 10^{-205}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;x \leq 4.2 \cdot 10^{-35}:\\ \;\;\;\;\frac{z}{\frac{y}{z} \cdot -2}\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-8}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{+51}:\\ \;\;\;\;\frac{z}{\frac{y}{z} \cdot -2}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \frac{x}{y}}{2}\\ \end{array} \]

Alternative 10: 79.8% accurate, 1.1× speedup?

\[\begin{array}{l} z = |z|\\ \\ \begin{array}{l} \mathbf{if}\;z \cdot z \leq 4 \cdot 10^{+284}:\\ \;\;\;\;0.5 \cdot \left(y + \frac{x}{\frac{y}{x}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(z \cdot \frac{z}{y}\right) \cdot -0.5\\ \end{array} \end{array} \]
NOTE: z should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (<= (* z z) 4e+284) (* 0.5 (+ y (/ x (/ y x)))) (* (* z (/ z y)) -0.5)))
z = abs(z);
double code(double x, double y, double z) {
	double tmp;
	if ((z * z) <= 4e+284) {
		tmp = 0.5 * (y + (x / (y / x)));
	} else {
		tmp = (z * (z / y)) * -0.5;
	}
	return tmp;
}
NOTE: z should be positive before calling this function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((z * z) <= 4d+284) then
        tmp = 0.5d0 * (y + (x / (y / x)))
    else
        tmp = (z * (z / y)) * (-0.5d0)
    end if
    code = tmp
end function
z = Math.abs(z);
public static double code(double x, double y, double z) {
	double tmp;
	if ((z * z) <= 4e+284) {
		tmp = 0.5 * (y + (x / (y / x)));
	} else {
		tmp = (z * (z / y)) * -0.5;
	}
	return tmp;
}
z = abs(z)
def code(x, y, z):
	tmp = 0
	if (z * z) <= 4e+284:
		tmp = 0.5 * (y + (x / (y / x)))
	else:
		tmp = (z * (z / y)) * -0.5
	return tmp
z = abs(z)
function code(x, y, z)
	tmp = 0.0
	if (Float64(z * z) <= 4e+284)
		tmp = Float64(0.5 * Float64(y + Float64(x / Float64(y / x))));
	else
		tmp = Float64(Float64(z * Float64(z / y)) * -0.5);
	end
	return tmp
end
z = abs(z)
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z * z) <= 4e+284)
		tmp = 0.5 * (y + (x / (y / x)));
	else
		tmp = (z * (z / y)) * -0.5;
	end
	tmp_2 = tmp;
end
NOTE: z should be positive before calling this function
code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 4e+284], N[(0.5 * N[(y + N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(z * N[(z / y), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 4 \cdot 10^{+284}:\\
\;\;\;\;0.5 \cdot \left(y + \frac{x}{\frac{y}{x}}\right)\\

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


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

    1. Initial program 78.9%

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

      \[\leadsto \color{blue}{0.5 \cdot y + 0.5 \cdot \frac{{x}^{2} - {z}^{2}}{y}} \]
    3. Step-by-step derivation
      1. distribute-lft-out92.1%

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

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

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

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

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

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

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

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

    if 4.00000000000000032e284 < (*.f64 z z)

    1. Initial program 54.7%

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

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

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

        \[\leadsto \frac{\color{blue}{z \cdot z}}{y} \cdot -0.5 \]
    4. Simplified61.2%

      \[\leadsto \color{blue}{\frac{z \cdot z}{y} \cdot -0.5} \]
    5. Taylor expanded in z around 0 61.2%

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

        \[\leadsto \frac{\color{blue}{z \cdot z}}{y} \cdot -0.5 \]
      2. associate-*r/71.8%

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

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

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

Alternative 11: 85.9% accurate, 1.1× speedup?

\[\begin{array}{l} z = |z|\\ \\ \begin{array}{l} \mathbf{if}\;x \cdot x \leq 2 \cdot 10^{+132}:\\ \;\;\;\;0.5 \cdot \left(y - \frac{z}{\frac{y}{z}}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(y + \frac{x}{\frac{y}{x}}\right)\\ \end{array} \end{array} \]
NOTE: z should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (<= (* x x) 2e+132)
   (* 0.5 (- y (/ z (/ y z))))
   (* 0.5 (+ y (/ x (/ y x))))))
z = abs(z);
double code(double x, double y, double z) {
	double tmp;
	if ((x * x) <= 2e+132) {
		tmp = 0.5 * (y - (z / (y / z)));
	} else {
		tmp = 0.5 * (y + (x / (y / x)));
	}
	return tmp;
}
NOTE: z should be positive before calling this function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((x * x) <= 2d+132) then
        tmp = 0.5d0 * (y - (z / (y / z)))
    else
        tmp = 0.5d0 * (y + (x / (y / x)))
    end if
    code = tmp
end function
z = Math.abs(z);
public static double code(double x, double y, double z) {
	double tmp;
	if ((x * x) <= 2e+132) {
		tmp = 0.5 * (y - (z / (y / z)));
	} else {
		tmp = 0.5 * (y + (x / (y / x)));
	}
	return tmp;
}
z = abs(z)
def code(x, y, z):
	tmp = 0
	if (x * x) <= 2e+132:
		tmp = 0.5 * (y - (z / (y / z)))
	else:
		tmp = 0.5 * (y + (x / (y / x)))
	return tmp
z = abs(z)
function code(x, y, z)
	tmp = 0.0
	if (Float64(x * x) <= 2e+132)
		tmp = Float64(0.5 * Float64(y - Float64(z / Float64(y / z))));
	else
		tmp = Float64(0.5 * Float64(y + Float64(x / Float64(y / x))));
	end
	return tmp
end
z = abs(z)
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x * x) <= 2e+132)
		tmp = 0.5 * (y - (z / (y / z)));
	else
		tmp = 0.5 * (y + (x / (y / x)));
	end
	tmp_2 = tmp;
end
NOTE: z should be positive before calling this function
code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 2e+132], N[(0.5 * N[(y - N[(z / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y + N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{+132}:\\
\;\;\;\;0.5 \cdot \left(y - \frac{z}{\frac{y}{z}}\right)\\

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


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

    1. Initial program 77.7%

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

        \[\leadsto \color{blue}{\frac{x \cdot x + y \cdot y}{y \cdot 2} - \frac{z \cdot z}{y \cdot 2}} \]
      2. sub-neg75.7%

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{\mathsf{hypot}\left(x, y\right)}{y}, \frac{\mathsf{hypot}\left(x, y\right)}{2}, -\color{blue}{\frac{z}{y} \cdot \frac{z}{2}}\right) \]
    3. Applied egg-rr99.9%

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

      \[\leadsto \color{blue}{0.5 \cdot y - 0.5 \cdot \frac{{z}^{2}}{y}} \]
    5. Step-by-step derivation
      1. distribute-lft-out--85.0%

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

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

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

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

    if 1.99999999999999998e132 < (*.f64 x x)

    1. Initial program 62.9%

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

      \[\leadsto \color{blue}{0.5 \cdot y + 0.5 \cdot \frac{{x}^{2} - {z}^{2}}{y}} \]
    3. Step-by-step derivation
      1. distribute-lft-out65.6%

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(y + \color{blue}{\frac{x}{\frac{y}{x}}}\right) \]
    7. Simplified89.6%

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

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

Alternative 12: 44.8% accurate, 1.7× speedup?

\[\begin{array}{l} z = |z|\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 1.65 \cdot 10^{+66}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \end{array} \end{array} \]
NOTE: z should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (<= x 1.65e+66) (* y 0.5) (* 0.5 (/ x (/ y x)))))
z = abs(z);
double code(double x, double y, double z) {
	double tmp;
	if (x <= 1.65e+66) {
		tmp = y * 0.5;
	} else {
		tmp = 0.5 * (x / (y / x));
	}
	return tmp;
}
NOTE: z should be positive before calling this function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= 1.65d+66) then
        tmp = y * 0.5d0
    else
        tmp = 0.5d0 * (x / (y / x))
    end if
    code = tmp
end function
z = Math.abs(z);
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= 1.65e+66) {
		tmp = y * 0.5;
	} else {
		tmp = 0.5 * (x / (y / x));
	}
	return tmp;
}
z = abs(z)
def code(x, y, z):
	tmp = 0
	if x <= 1.65e+66:
		tmp = y * 0.5
	else:
		tmp = 0.5 * (x / (y / x))
	return tmp
z = abs(z)
function code(x, y, z)
	tmp = 0.0
	if (x <= 1.65e+66)
		tmp = Float64(y * 0.5);
	else
		tmp = Float64(0.5 * Float64(x / Float64(y / x)));
	end
	return tmp
end
z = abs(z)
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= 1.65e+66)
		tmp = y * 0.5;
	else
		tmp = 0.5 * (x / (y / x));
	end
	tmp_2 = tmp;
end
NOTE: z should be positive before calling this function
code[x_, y_, z_] := If[LessEqual[x, 1.65e+66], N[(y * 0.5), $MachinePrecision], N[(0.5 * N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.65 \cdot 10^{+66}:\\
\;\;\;\;y \cdot 0.5\\

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


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

    1. Initial program 74.6%

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

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

    if 1.6500000000000001e66 < x

    1. Initial program 62.1%

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{x \cdot x}}{y} \]
      2. associate-/l*70.9%

        \[\leadsto 0.5 \cdot \color{blue}{\frac{x}{\frac{y}{x}}} \]
    4. Simplified70.9%

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

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

Alternative 13: 34.8% accurate, 5.0× speedup?

\[\begin{array}{l} z = |z|\\ \\ y \cdot 0.5 \end{array} \]
NOTE: z should be positive before calling this function
(FPCore (x y z) :precision binary64 (* y 0.5))
z = abs(z);
double code(double x, double y, double z) {
	return y * 0.5;
}
NOTE: z should be positive before calling this function
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
end function
z = Math.abs(z);
public static double code(double x, double y, double z) {
	return y * 0.5;
}
z = abs(z)
def code(x, y, z):
	return y * 0.5
z = abs(z)
function code(x, y, z)
	return Float64(y * 0.5)
end
z = abs(z)
function tmp = code(x, y, z)
	tmp = y * 0.5;
end
NOTE: z should be positive before calling this function
code[x_, y_, z_] := N[(y * 0.5), $MachinePrecision]
\begin{array}{l}
z = |z|\\
\\
y \cdot 0.5
\end{array}
Derivation
  1. Initial program 71.5%

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

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

    \[\leadsto y \cdot 0.5 \]

Developer target: 99.9% accurate, 1.0× speedup?

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

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

Reproduce

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