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

Percentage Accurate: 68.5% → 99.9%
Time: 6.9s
Alternatives: 8
Speedup: 1.2×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 8 alternatives:

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

Initial Program: 68.5% 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: 99.9% accurate, 1.2× speedup?

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(z \cdot z - x \cdot x\right) - y \cdot y}}{y} \cdot \frac{-1}{2} \]
    10. div-sub70.8%

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

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

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

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

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

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

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

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

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

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

Alternative 2: 78.5% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;z \cdot z \leq 10^{+234}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 z z) < 4.99999999999999978e110 or 9.9999999999999994e174 < (*.f64 z z) < 1.00000000000000002e234

    1. Initial program 74.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\left(z - x\right) \cdot \frac{x + z}{y} - \frac{y}{\color{blue}{1}}\right) \cdot \frac{-1}{2} \]
      17. /-rgt-identity99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.99999999999999978e110 < (*.f64 z z) < 9.9999999999999994e174

    1. Initial program 85.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\left(x + z\right) \cdot \frac{z - x}{y} - \frac{y}{\color{blue}{1}}\right) \cdot \frac{-1}{2} \]
      16. /-rgt-identity99.9%

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

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

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

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

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

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

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

    if 1.00000000000000002e234 < (*.f64 z z)

    1. Initial program 60.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\left(x + z\right) \cdot \frac{z - x}{y} - \frac{y}{\color{blue}{1}}\right) \cdot \frac{-1}{2} \]
      16. /-rgt-identity98.9%

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

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

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

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

        \[\leadsto -0.5 \cdot \frac{\color{blue}{z \cdot z}}{y} \]
    6. Simplified75.3%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{z \cdot z}{y}} \]
    7. Step-by-step derivation
      1. associate-*l/78.7%

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

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

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

        \[\leadsto \color{blue}{\frac{z}{\frac{y}{z}}} \cdot -0.5 \]
      5. associate-*l/79.8%

        \[\leadsto \color{blue}{\frac{z \cdot -0.5}{\frac{y}{z}}} \]
    8. Applied egg-rr79.8%

      \[\leadsto \color{blue}{\frac{z \cdot -0.5}{\frac{y}{z}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification83.0%

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

Alternative 3: 53.6% accurate, 1.0× speedup?

\[\begin{array}{l} z = |z|\\ \\ \begin{array}{l} \mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-274}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{x}{y}\right)\\ \mathbf{elif}\;z \cdot z \leq 10^{+25}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \left(z \cdot \frac{z}{y}\right)\\ \end{array} \end{array} \]
NOTE: z should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (<= (* z z) 5e-274)
   (* 0.5 (* x (/ x y)))
   (if (<= (* z z) 1e+25) (* y 0.5) (* -0.5 (* z (/ z y))))))
z = abs(z);
double code(double x, double y, double z) {
	double tmp;
	if ((z * z) <= 5e-274) {
		tmp = 0.5 * (x * (x / y));
	} else if ((z * z) <= 1e+25) {
		tmp = y * 0.5;
	} else {
		tmp = -0.5 * (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 ((z * z) <= 5d-274) then
        tmp = 0.5d0 * (x * (x / y))
    else if ((z * z) <= 1d+25) then
        tmp = y * 0.5d0
    else
        tmp = (-0.5d0) * (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 ((z * z) <= 5e-274) {
		tmp = 0.5 * (x * (x / y));
	} else if ((z * z) <= 1e+25) {
		tmp = y * 0.5;
	} else {
		tmp = -0.5 * (z * (z / y));
	}
	return tmp;
}
z = abs(z)
def code(x, y, z):
	tmp = 0
	if (z * z) <= 5e-274:
		tmp = 0.5 * (x * (x / y))
	elif (z * z) <= 1e+25:
		tmp = y * 0.5
	else:
		tmp = -0.5 * (z * (z / y))
	return tmp
z = abs(z)
function code(x, y, z)
	tmp = 0.0
	if (Float64(z * z) <= 5e-274)
		tmp = Float64(0.5 * Float64(x * Float64(x / y)));
	elseif (Float64(z * z) <= 1e+25)
		tmp = Float64(y * 0.5);
	else
		tmp = Float64(-0.5 * Float64(z * Float64(z / y)));
	end
	return tmp
end
z = abs(z)
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z * z) <= 5e-274)
		tmp = 0.5 * (x * (x / y));
	elseif ((z * z) <= 1e+25)
		tmp = y * 0.5;
	else
		tmp = -0.5 * (z * (z / y));
	end
	tmp_2 = tmp;
end
NOTE: z should be positive before calling this function
code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 5e-274], N[(0.5 * N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * z), $MachinePrecision], 1e+25], N[(y * 0.5), $MachinePrecision], N[(-0.5 * N[(z * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-274}:\\
\;\;\;\;0.5 \cdot \left(x \cdot \frac{x}{y}\right)\\

\mathbf{elif}\;z \cdot z \leq 10^{+25}:\\
\;\;\;\;y \cdot 0.5\\

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


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

    1. Initial program 75.5%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\frac{z \cdot z - x \cdot x}{y} - \frac{y \cdot y}{y}\right)} \cdot \frac{-1}{2} \]
      11. difference-of-squares75.5%

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

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

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

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

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

        \[\leadsto \left(\left(z - x\right) \cdot \frac{x + z}{y} - \frac{y}{\color{blue}{1}}\right) \cdot \frac{-1}{2} \]
      17. /-rgt-identity99.9%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{x \cdot x}}{y} \cdot 0.5 \]
      3. associate-*r/54.6%

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

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

    if 5e-274 < (*.f64 z z) < 1.00000000000000009e25

    1. Initial program 70.7%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\left(z \cdot z - x \cdot x\right) - y \cdot y}}{y} \cdot \frac{-1}{2} \]
      10. div-sub70.7%

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

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

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

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

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

        \[\leadsto \left(\left(x + z\right) \cdot \frac{z - x}{y} - \frac{y}{\color{blue}{1}}\right) \cdot \frac{-1}{2} \]
      16. /-rgt-identity100.0%

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

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

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

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

        \[\leadsto \color{blue}{y \cdot 0.5} \]
    6. Simplified62.9%

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

    if 1.00000000000000009e25 < (*.f64 z z)

    1. Initial program 67.9%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\left(z \cdot z - x \cdot x\right) - y \cdot y}}{y} \cdot \frac{-1}{2} \]
      10. div-sub67.9%

        \[\leadsto \color{blue}{\left(\frac{z \cdot z - x \cdot x}{y} - \frac{y \cdot y}{y}\right)} \cdot \frac{-1}{2} \]
      11. difference-of-squares78.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 53.6% accurate, 1.0× speedup?

\[\begin{array}{l} z = |z|\\ \\ \begin{array}{l} \mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-274}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{x}{y}\right)\\ \mathbf{elif}\;z \cdot z \leq 10^{+25}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{z \cdot -0.5}{\frac{y}{z}}\\ \end{array} \end{array} \]
NOTE: z should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (<= (* z z) 5e-274)
   (* 0.5 (* x (/ x y)))
   (if (<= (* z z) 1e+25) (* y 0.5) (/ (* z -0.5) (/ y z)))))
z = abs(z);
double code(double x, double y, double z) {
	double tmp;
	if ((z * z) <= 5e-274) {
		tmp = 0.5 * (x * (x / y));
	} else if ((z * z) <= 1e+25) {
		tmp = y * 0.5;
	} else {
		tmp = (z * -0.5) / (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) <= 5d-274) then
        tmp = 0.5d0 * (x * (x / y))
    else if ((z * z) <= 1d+25) then
        tmp = y * 0.5d0
    else
        tmp = (z * (-0.5d0)) / (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) <= 5e-274) {
		tmp = 0.5 * (x * (x / y));
	} else if ((z * z) <= 1e+25) {
		tmp = y * 0.5;
	} else {
		tmp = (z * -0.5) / (y / z);
	}
	return tmp;
}
z = abs(z)
def code(x, y, z):
	tmp = 0
	if (z * z) <= 5e-274:
		tmp = 0.5 * (x * (x / y))
	elif (z * z) <= 1e+25:
		tmp = y * 0.5
	else:
		tmp = (z * -0.5) / (y / z)
	return tmp
z = abs(z)
function code(x, y, z)
	tmp = 0.0
	if (Float64(z * z) <= 5e-274)
		tmp = Float64(0.5 * Float64(x * Float64(x / y)));
	elseif (Float64(z * z) <= 1e+25)
		tmp = Float64(y * 0.5);
	else
		tmp = Float64(Float64(z * -0.5) / Float64(y / z));
	end
	return tmp
end
z = abs(z)
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z * z) <= 5e-274)
		tmp = 0.5 * (x * (x / y));
	elseif ((z * z) <= 1e+25)
		tmp = y * 0.5;
	else
		tmp = (z * -0.5) / (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], 5e-274], N[(0.5 * N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * z), $MachinePrecision], 1e+25], N[(y * 0.5), $MachinePrecision], N[(N[(z * -0.5), $MachinePrecision] / N[(y / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-274}:\\
\;\;\;\;0.5 \cdot \left(x \cdot \frac{x}{y}\right)\\

\mathbf{elif}\;z \cdot z \leq 10^{+25}:\\
\;\;\;\;y \cdot 0.5\\

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


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

    1. Initial program 75.5%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\frac{z \cdot z - x \cdot x}{y} - \frac{y \cdot y}{y}\right)} \cdot \frac{-1}{2} \]
      11. difference-of-squares75.5%

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

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

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

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

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

        \[\leadsto \left(\left(z - x\right) \cdot \frac{x + z}{y} - \frac{y}{\color{blue}{1}}\right) \cdot \frac{-1}{2} \]
      17. /-rgt-identity99.9%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{x \cdot x}}{y} \cdot 0.5 \]
      3. associate-*r/54.6%

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

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

    if 5e-274 < (*.f64 z z) < 1.00000000000000009e25

    1. Initial program 70.7%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\left(z \cdot z - x \cdot x\right) - y \cdot y}}{y} \cdot \frac{-1}{2} \]
      10. div-sub70.7%

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

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

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

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

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

        \[\leadsto \left(\left(x + z\right) \cdot \frac{z - x}{y} - \frac{y}{\color{blue}{1}}\right) \cdot \frac{-1}{2} \]
      16. /-rgt-identity100.0%

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

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

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

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

        \[\leadsto \color{blue}{y \cdot 0.5} \]
    6. Simplified62.9%

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

    if 1.00000000000000009e25 < (*.f64 z z)

    1. Initial program 67.9%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\left(z \cdot z - x \cdot x\right) - y \cdot y}}{y} \cdot \frac{-1}{2} \]
      10. div-sub67.9%

        \[\leadsto \color{blue}{\left(\frac{z \cdot z - x \cdot x}{y} - \frac{y \cdot y}{y}\right)} \cdot \frac{-1}{2} \]
      11. difference-of-squares78.1%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{z \cdot z}{y}} \]
    7. Step-by-step derivation
      1. associate-*l/64.5%

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

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

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

        \[\leadsto \color{blue}{\frac{z}{\frac{y}{z}}} \cdot -0.5 \]
      5. associate-*l/65.1%

        \[\leadsto \color{blue}{\frac{z \cdot -0.5}{\frac{y}{z}}} \]
    8. Applied egg-rr65.1%

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

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

Alternative 5: 88.6% accurate, 1.0× speedup?

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

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


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

    1. Initial program 74.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\left(x + z\right) \cdot \frac{z - x}{y} - \frac{y}{\color{blue}{1}}\right) \cdot \frac{-1}{2} \]
      16. /-rgt-identity99.4%

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

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

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

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

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

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

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

    if 4.9999999999999997e111 < (*.f64 x x)

    1. Initial program 65.7%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\left(z \cdot z - x \cdot x\right) - y \cdot y}}{y} \cdot \frac{-1}{2} \]
      10. div-sub65.7%

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

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

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

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

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

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

        \[\leadsto \left(\left(z - x\right) \cdot \frac{x + z}{y} - \frac{y}{\color{blue}{1}}\right) \cdot \frac{-1}{2} \]
      17. /-rgt-identity99.9%

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

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

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

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

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

Alternative 6: 85.5% accurate, 1.1× speedup?

\[\begin{array}{l} z = |z|\\ \\ \begin{array}{l} \mathbf{if}\;x \cdot x \leq 10^{+184}:\\ \;\;\;\;-0.5 \cdot \left(z \cdot \frac{z}{y} - y\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(y + x \cdot \frac{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) 1e+184)
   (* -0.5 (- (* z (/ z y)) y))
   (* 0.5 (+ y (* x (/ x y))))))
z = abs(z);
double code(double x, double y, double z) {
	double tmp;
	if ((x * x) <= 1e+184) {
		tmp = -0.5 * ((z * (z / y)) - y);
	} else {
		tmp = 0.5 * (y + (x * (x / 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 ((x * x) <= 1d+184) then
        tmp = (-0.5d0) * ((z * (z / y)) - y)
    else
        tmp = 0.5d0 * (y + (x * (x / y)))
    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) <= 1e+184) {
		tmp = -0.5 * ((z * (z / y)) - y);
	} else {
		tmp = 0.5 * (y + (x * (x / y)));
	}
	return tmp;
}
z = abs(z)
def code(x, y, z):
	tmp = 0
	if (x * x) <= 1e+184:
		tmp = -0.5 * ((z * (z / y)) - y)
	else:
		tmp = 0.5 * (y + (x * (x / y)))
	return tmp
z = abs(z)
function code(x, y, z)
	tmp = 0.0
	if (Float64(x * x) <= 1e+184)
		tmp = Float64(-0.5 * Float64(Float64(z * Float64(z / y)) - y));
	else
		tmp = Float64(0.5 * Float64(y + Float64(x * Float64(x / y))));
	end
	return tmp
end
z = abs(z)
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x * x) <= 1e+184)
		tmp = -0.5 * ((z * (z / y)) - y);
	else
		tmp = 0.5 * (y + (x * (x / y)));
	end
	tmp_2 = tmp;
end
NOTE: z should be positive before calling this function
code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 1e+184], N[(-0.5 * N[(N[(z * N[(z / y), $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y + N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 10^{+184}:\\
\;\;\;\;-0.5 \cdot \left(z \cdot \frac{z}{y} - y\right)\\

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


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

    1. Initial program 75.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\left(x + z\right) \cdot \frac{z - x}{y} - \frac{y}{\color{blue}{1}}\right) \cdot \frac{-1}{2} \]
      16. /-rgt-identity99.4%

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

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

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

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

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

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

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

    if 1.00000000000000002e184 < (*.f64 x x)

    1. Initial program 62.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\left(z - x\right) \cdot \frac{x + z}{y} - \frac{y}{\color{blue}{1}}\right) \cdot \frac{-1}{2} \]
      17. /-rgt-identity99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 54.1% accurate, 1.3× speedup?

\[\begin{array}{l} z = |z|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq -8.2 \cdot 10^{+79}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{+44}:\\ \;\;\;\;-0.5 \cdot \left(z \cdot \frac{z}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \end{array} \]
NOTE: z should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (<= y -8.2e+79)
   (* y 0.5)
   (if (<= y 5.8e+44) (* -0.5 (* z (/ z y))) (* y 0.5))))
z = abs(z);
double code(double x, double y, double z) {
	double tmp;
	if (y <= -8.2e+79) {
		tmp = y * 0.5;
	} else if (y <= 5.8e+44) {
		tmp = -0.5 * (z * (z / y));
	} else {
		tmp = 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 (y <= (-8.2d+79)) then
        tmp = y * 0.5d0
    else if (y <= 5.8d+44) then
        tmp = (-0.5d0) * (z * (z / y))
    else
        tmp = 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 (y <= -8.2e+79) {
		tmp = y * 0.5;
	} else if (y <= 5.8e+44) {
		tmp = -0.5 * (z * (z / y));
	} else {
		tmp = y * 0.5;
	}
	return tmp;
}
z = abs(z)
def code(x, y, z):
	tmp = 0
	if y <= -8.2e+79:
		tmp = y * 0.5
	elif y <= 5.8e+44:
		tmp = -0.5 * (z * (z / y))
	else:
		tmp = y * 0.5
	return tmp
z = abs(z)
function code(x, y, z)
	tmp = 0.0
	if (y <= -8.2e+79)
		tmp = Float64(y * 0.5);
	elseif (y <= 5.8e+44)
		tmp = Float64(-0.5 * Float64(z * Float64(z / y)));
	else
		tmp = Float64(y * 0.5);
	end
	return tmp
end
z = abs(z)
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -8.2e+79)
		tmp = y * 0.5;
	elseif (y <= 5.8e+44)
		tmp = -0.5 * (z * (z / y));
	else
		tmp = y * 0.5;
	end
	tmp_2 = tmp;
end
NOTE: z should be positive before calling this function
code[x_, y_, z_] := If[LessEqual[y, -8.2e+79], N[(y * 0.5), $MachinePrecision], If[LessEqual[y, 5.8e+44], N[(-0.5 * N[(z * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.2 \cdot 10^{+79}:\\
\;\;\;\;y \cdot 0.5\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -8.2e79 or 5.8000000000000004e44 < y

    1. Initial program 42.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{y \cdot 0.5} \]
    6. Simplified69.1%

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

    if -8.2e79 < y < 5.8000000000000004e44

    1. Initial program 90.7%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\left(z \cdot z - x \cdot x\right) - y \cdot y}}{y} \cdot \frac{-1}{2} \]
      10. div-sub90.7%

        \[\leadsto \color{blue}{\left(\frac{z \cdot z - x \cdot x}{y} - \frac{y \cdot y}{y}\right)} \cdot \frac{-1}{2} \]
      11. difference-of-squares98.0%

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

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

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

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

        \[\leadsto \left(\left(x + z\right) \cdot \frac{z - x}{y} - \frac{y}{\color{blue}{1}}\right) \cdot \frac{-1}{2} \]
      16. /-rgt-identity99.9%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -8.2 \cdot 10^{+79}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{+44}:\\ \;\;\;\;-0.5 \cdot \left(z \cdot \frac{z}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(z \cdot z - x \cdot x\right) - y \cdot y}}{y} \cdot \frac{-1}{2} \]
    10. div-sub70.8%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{y \cdot 0.5} \]
  6. Simplified33.6%

    \[\leadsto \color{blue}{y \cdot 0.5} \]
  7. Final simplification33.6%

    \[\leadsto y \cdot 0.5 \]

Developer target: 99.8% 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 2023199 
(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)))