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

Percentage Accurate: 69.2% → 99.9%
Time: 9.8s
Alternatives: 8
Speedup: 0.9×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 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: 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: 99.9% accurate, 0.1× speedup?

\[\begin{array}{l} \\ 0.5 \cdot \left(\left(\mathsf{hypot}\left(x, y\right) + z\right) \cdot \frac{\mathsf{hypot}\left(x, y\right) - z}{y}\right) \end{array} \]
(FPCore (x y z)
 :precision binary64
 (* 0.5 (* (+ (hypot x y) z) (/ (- (hypot x y) z) y))))
double code(double x, double y, double z) {
	return 0.5 * ((hypot(x, y) + z) * ((hypot(x, y) - z) / y));
}
public static double code(double x, double y, double z) {
	return 0.5 * ((Math.hypot(x, y) + z) * ((Math.hypot(x, y) - z) / y));
}
def code(x, y, z):
	return 0.5 * ((math.hypot(x, y) + z) * ((math.hypot(x, y) - z) / y))
function code(x, y, z)
	return Float64(0.5 * Float64(Float64(hypot(x, y) + z) * Float64(Float64(hypot(x, y) - z) / y)))
end
function tmp = code(x, y, z)
	tmp = 0.5 * ((hypot(x, y) + z) * ((hypot(x, y) - z) / y));
end
code[x_, y_, z_] := N[(0.5 * N[(N[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] + z), $MachinePrecision] * N[(N[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
0.5 \cdot \left(\left(\mathsf{hypot}\left(x, y\right) + z\right) \cdot \frac{\mathsf{hypot}\left(x, y\right) - z}{y}\right)
\end{array}
Derivation
  1. Initial program 71.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}} - z \cdot z}{y} \]
    4. difference-of-squares75.5%

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

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

      \[\leadsto 0.5 \cdot \frac{\left(\mathsf{hypot}\left(x, y\right) + z\right) \cdot \left(\color{blue}{\mathsf{hypot}\left(x, y\right)} - z\right)}{y} \]
  6. Applied egg-rr77.5%

    \[\leadsto 0.5 \cdot \frac{\color{blue}{\left(\mathsf{hypot}\left(x, y\right) + z\right) \cdot \left(\mathsf{hypot}\left(x, y\right) - z\right)}}{y} \]
  7. Step-by-step derivation
    1. associate-/l*99.9%

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

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

    \[\leadsto 0.5 \cdot \left(\left(\mathsf{hypot}\left(x, y\right) + z\right) \cdot \frac{\mathsf{hypot}\left(x, y\right) - z}{y}\right) \]
  10. Add Preprocessing

Alternative 2: 81.5% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 3 \cdot 10^{+132}:\\ \;\;\;\;0.5 \cdot \frac{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\left(y + z\right) \cdot \frac{y - z}{y}\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y 3e+132)
   (* 0.5 (/ (fma x x (- (* y y) (* z z))) y))
   (* 0.5 (* (+ y z) (/ (- y z) y)))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= 3e+132) {
		tmp = 0.5 * (fma(x, x, ((y * y) - (z * z))) / y);
	} else {
		tmp = 0.5 * ((y + z) * ((y - z) / y));
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (y <= 3e+132)
		tmp = Float64(0.5 * Float64(fma(x, x, Float64(Float64(y * y) - Float64(z * z))) / y));
	else
		tmp = Float64(0.5 * Float64(Float64(y + z) * Float64(Float64(y - z) / y)));
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[y, 3e+132], N[(0.5 * N[(N[(x * x + N[(N[(y * y), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(y + z), $MachinePrecision] * N[(N[(y - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 3 \cdot 10^{+132}:\\
\;\;\;\;0.5 \cdot \frac{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}{y}\\

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


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

    1. Initial program 82.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.9999999999999998e132 < y

    1. Initial program 11.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}} - z \cdot z}{y} \]
      4. difference-of-squares13.3%

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

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

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

      \[\leadsto 0.5 \cdot \frac{\color{blue}{\left(\mathsf{hypot}\left(x, y\right) + z\right) \cdot \left(\mathsf{hypot}\left(x, y\right) - z\right)}}{y} \]
    7. Taylor expanded in x around 0 21.6%

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

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

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

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

Alternative 3: 43.7% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \left(\left(y + z\right) \cdot \frac{z}{-y}\right)\\ \mathbf{if}\;y \leq 9 \cdot 10^{-266}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{-240}:\\ \;\;\;\;\frac{x}{y} \cdot \frac{x}{2}\\ \mathbf{elif}\;y \leq 0.46:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 5.6 \cdot 10^{+76}:\\ \;\;\;\;x \cdot \left(x \cdot \frac{1}{y \cdot 2}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* 0.5 (* (+ y z) (/ z (- y))))))
   (if (<= y 9e-266)
     t_0
     (if (<= y 1.8e-240)
       (* (/ x y) (/ x 2.0))
       (if (<= y 0.46)
         t_0
         (if (<= y 5.6e+76) (* x (* x (/ 1.0 (* y 2.0)))) (* 0.5 y)))))))
double code(double x, double y, double z) {
	double t_0 = 0.5 * ((y + z) * (z / -y));
	double tmp;
	if (y <= 9e-266) {
		tmp = t_0;
	} else if (y <= 1.8e-240) {
		tmp = (x / y) * (x / 2.0);
	} else if (y <= 0.46) {
		tmp = t_0;
	} else if (y <= 5.6e+76) {
		tmp = x * (x * (1.0 / (y * 2.0)));
	} else {
		tmp = 0.5 * y;
	}
	return tmp;
}
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 + z) * (z / -y))
    if (y <= 9d-266) then
        tmp = t_0
    else if (y <= 1.8d-240) then
        tmp = (x / y) * (x / 2.0d0)
    else if (y <= 0.46d0) then
        tmp = t_0
    else if (y <= 5.6d+76) then
        tmp = x * (x * (1.0d0 / (y * 2.0d0)))
    else
        tmp = 0.5d0 * y
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = 0.5 * ((y + z) * (z / -y));
	double tmp;
	if (y <= 9e-266) {
		tmp = t_0;
	} else if (y <= 1.8e-240) {
		tmp = (x / y) * (x / 2.0);
	} else if (y <= 0.46) {
		tmp = t_0;
	} else if (y <= 5.6e+76) {
		tmp = x * (x * (1.0 / (y * 2.0)));
	} else {
		tmp = 0.5 * y;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 0.5 * ((y + z) * (z / -y))
	tmp = 0
	if y <= 9e-266:
		tmp = t_0
	elif y <= 1.8e-240:
		tmp = (x / y) * (x / 2.0)
	elif y <= 0.46:
		tmp = t_0
	elif y <= 5.6e+76:
		tmp = x * (x * (1.0 / (y * 2.0)))
	else:
		tmp = 0.5 * y
	return tmp
function code(x, y, z)
	t_0 = Float64(0.5 * Float64(Float64(y + z) * Float64(z / Float64(-y))))
	tmp = 0.0
	if (y <= 9e-266)
		tmp = t_0;
	elseif (y <= 1.8e-240)
		tmp = Float64(Float64(x / y) * Float64(x / 2.0));
	elseif (y <= 0.46)
		tmp = t_0;
	elseif (y <= 5.6e+76)
		tmp = Float64(x * Float64(x * Float64(1.0 / Float64(y * 2.0))));
	else
		tmp = Float64(0.5 * y);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = 0.5 * ((y + z) * (z / -y));
	tmp = 0.0;
	if (y <= 9e-266)
		tmp = t_0;
	elseif (y <= 1.8e-240)
		tmp = (x / y) * (x / 2.0);
	elseif (y <= 0.46)
		tmp = t_0;
	elseif (y <= 5.6e+76)
		tmp = x * (x * (1.0 / (y * 2.0)));
	else
		tmp = 0.5 * y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(0.5 * N[(N[(y + z), $MachinePrecision] * N[(z / (-y)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, 9e-266], t$95$0, If[LessEqual[y, 1.8e-240], N[(N[(x / y), $MachinePrecision] * N[(x / 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 0.46], t$95$0, If[LessEqual[y, 5.6e+76], N[(x * N[(x * N[(1.0 / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * y), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq 1.8 \cdot 10^{-240}:\\
\;\;\;\;\frac{x}{y} \cdot \frac{x}{2}\\

\mathbf{elif}\;y \leq 0.46:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 5.6 \cdot 10^{+76}:\\
\;\;\;\;x \cdot \left(x \cdot \frac{1}{y \cdot 2}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < 9.0000000000000006e-266 or 1.7999999999999999e-240 < y < 0.46000000000000002

    1. Initial program 82.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}} - z \cdot z}{y} \]
      4. difference-of-squares85.7%

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

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

        \[\leadsto 0.5 \cdot \frac{\left(\mathsf{hypot}\left(x, y\right) + z\right) \cdot \left(\color{blue}{\mathsf{hypot}\left(x, y\right)} - z\right)}{y} \]
    6. Applied egg-rr86.8%

      \[\leadsto 0.5 \cdot \frac{\color{blue}{\left(\mathsf{hypot}\left(x, y\right) + z\right) \cdot \left(\mathsf{hypot}\left(x, y\right) - z\right)}}{y} \]
    7. Taylor expanded in x around 0 58.2%

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

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

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

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

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

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

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

    if 9.0000000000000006e-266 < y < 1.7999999999999999e-240

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.46000000000000002 < y < 5.5999999999999997e76

    1. Initial program 78.8%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\frac{y \cdot 2}{\color{blue}{{x}^{2}}}} \]
    8. Step-by-step derivation
      1. associate-/r/46.7%

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

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

        \[\leadsto \color{blue}{\left(\frac{1}{y \cdot 2} \cdot x\right) \cdot x} \]
    9. Applied egg-rr56.8%

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

    if 5.5999999999999997e76 < y

    1. Initial program 23.1%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 9 \cdot 10^{-266}:\\ \;\;\;\;0.5 \cdot \left(\left(y + z\right) \cdot \frac{z}{-y}\right)\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{-240}:\\ \;\;\;\;\frac{x}{y} \cdot \frac{x}{2}\\ \mathbf{elif}\;y \leq 0.46:\\ \;\;\;\;0.5 \cdot \left(\left(y + z\right) \cdot \frac{z}{-y}\right)\\ \mathbf{elif}\;y \leq 5.6 \cdot 10^{+76}:\\ \;\;\;\;x \cdot \left(x \cdot \frac{1}{y \cdot 2}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 78.9% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 3 \cdot 10^{-86}:\\ \;\;\;\;0.5 \cdot \left(\left(x + z\right) \cdot \frac{x - z}{y}\right)\\ \mathbf{elif}\;y \leq 2.65 \cdot 10^{+132}:\\ \;\;\;\;\frac{\left(y \cdot y + x \cdot x\right) - z \cdot z}{y \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\left(y + z\right) \cdot \frac{y - z}{y}\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y 3e-86)
   (* 0.5 (* (+ x z) (/ (- x z) y)))
   (if (<= y 2.65e+132)
     (/ (- (+ (* y y) (* x x)) (* z z)) (* y 2.0))
     (* 0.5 (* (+ y z) (/ (- y z) y))))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= 3e-86) {
		tmp = 0.5 * ((x + z) * ((x - z) / y));
	} else if (y <= 2.65e+132) {
		tmp = (((y * y) + (x * x)) - (z * z)) / (y * 2.0);
	} else {
		tmp = 0.5 * ((y + z) * ((y - z) / y));
	}
	return tmp;
}
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 <= 3d-86) then
        tmp = 0.5d0 * ((x + z) * ((x - z) / y))
    else if (y <= 2.65d+132) then
        tmp = (((y * y) + (x * x)) - (z * z)) / (y * 2.0d0)
    else
        tmp = 0.5d0 * ((y + z) * ((y - z) / y))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= 3e-86) {
		tmp = 0.5 * ((x + z) * ((x - z) / y));
	} else if (y <= 2.65e+132) {
		tmp = (((y * y) + (x * x)) - (z * z)) / (y * 2.0);
	} else {
		tmp = 0.5 * ((y + z) * ((y - z) / y));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= 3e-86:
		tmp = 0.5 * ((x + z) * ((x - z) / y))
	elif y <= 2.65e+132:
		tmp = (((y * y) + (x * x)) - (z * z)) / (y * 2.0)
	else:
		tmp = 0.5 * ((y + z) * ((y - z) / y))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= 3e-86)
		tmp = Float64(0.5 * Float64(Float64(x + z) * Float64(Float64(x - z) / y)));
	elseif (y <= 2.65e+132)
		tmp = Float64(Float64(Float64(Float64(y * y) + Float64(x * x)) - Float64(z * z)) / Float64(y * 2.0));
	else
		tmp = Float64(0.5 * Float64(Float64(y + z) * Float64(Float64(y - z) / y)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= 3e-86)
		tmp = 0.5 * ((x + z) * ((x - z) / y));
	elseif (y <= 2.65e+132)
		tmp = (((y * y) + (x * x)) - (z * z)) / (y * 2.0);
	else
		tmp = 0.5 * ((y + z) * ((y - z) / y));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, 3e-86], N[(0.5 * N[(N[(x + z), $MachinePrecision] * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.65e+132], N[(N[(N[(N[(y * y), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(y + z), $MachinePrecision] * N[(N[(y - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

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

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


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

    1. Initial program 81.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}} - z \cdot z}{y} \]
      4. difference-of-squares84.7%

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

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

        \[\leadsto 0.5 \cdot \frac{\left(\mathsf{hypot}\left(x, y\right) + z\right) \cdot \left(\color{blue}{\mathsf{hypot}\left(x, y\right)} - z\right)}{y} \]
    6. Applied egg-rr85.8%

      \[\leadsto 0.5 \cdot \frac{\color{blue}{\left(\mathsf{hypot}\left(x, y\right) + z\right) \cdot \left(\mathsf{hypot}\left(x, y\right) - z\right)}}{y} \]
    7. Taylor expanded in y around 0 74.0%

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

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

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

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

    if 3.0000000000000001e-86 < y < 2.65e132

    1. Initial program 88.5%

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

    if 2.65e132 < y

    1. Initial program 11.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}} - z \cdot z}{y} \]
      4. difference-of-squares13.3%

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

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

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

      \[\leadsto 0.5 \cdot \frac{\color{blue}{\left(\mathsf{hypot}\left(x, y\right) + z\right) \cdot \left(\mathsf{hypot}\left(x, y\right) - z\right)}}{y} \]
    7. Taylor expanded in x around 0 21.6%

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

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

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

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

Alternative 5: 85.1% accurate, 0.8× speedup?

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

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

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


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

    1. Initial program 75.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}} - z \cdot z}{y} \]
      4. difference-of-squares76.4%

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

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

        \[\leadsto 0.5 \cdot \frac{\left(\mathsf{hypot}\left(x, y\right) + z\right) \cdot \left(\color{blue}{\mathsf{hypot}\left(x, y\right)} - z\right)}{y} \]
    6. Applied egg-rr77.5%

      \[\leadsto 0.5 \cdot \frac{\color{blue}{\left(\mathsf{hypot}\left(x, y\right) + z\right) \cdot \left(\mathsf{hypot}\left(x, y\right) - z\right)}}{y} \]
    7. Taylor expanded in x around 0 66.2%

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

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

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

    if 2.0000000000000002e227 < (*.f64 x x)

    1. Initial program 62.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}} - z \cdot z}{y} \]
      4. difference-of-squares73.4%

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

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

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

      \[\leadsto 0.5 \cdot \frac{\color{blue}{\left(\mathsf{hypot}\left(x, y\right) + z\right) \cdot \left(\mathsf{hypot}\left(x, y\right) - z\right)}}{y} \]
    7. Taylor expanded in y around 0 77.3%

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

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

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

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

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

Alternative 6: 73.9% accurate, 0.9× speedup?

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

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

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


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

    1. Initial program 72.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}} - z \cdot z}{y} \]
      4. difference-of-squares75.0%

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

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

        \[\leadsto 0.5 \cdot \frac{\left(\mathsf{hypot}\left(x, y\right) + z\right) \cdot \left(\color{blue}{\mathsf{hypot}\left(x, y\right)} - z\right)}{y} \]
    6. Applied egg-rr76.4%

      \[\leadsto 0.5 \cdot \frac{\color{blue}{\left(\mathsf{hypot}\left(x, y\right) + z\right) \cdot \left(\mathsf{hypot}\left(x, y\right) - z\right)}}{y} \]
    7. Taylor expanded in x around 0 56.5%

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

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

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

    if 4.5000000000000001e113 < x

    1. Initial program 67.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{{x}^{2}}{y \cdot 2}} \]
      2. unpow270.0%

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

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

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

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

Alternative 7: 52.3% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot x \leq 2 \cdot 10^{+227}:\\ \;\;\;\;0.5 \cdot y\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} \cdot \frac{x}{2}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= (* x x) 2e+227) (* 0.5 y) (* (/ x y) (/ x 2.0))))
double code(double x, double y, double z) {
	double tmp;
	if ((x * x) <= 2e+227) {
		tmp = 0.5 * y;
	} else {
		tmp = (x / y) * (x / 2.0);
	}
	return tmp;
}
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+227) then
        tmp = 0.5d0 * y
    else
        tmp = (x / y) * (x / 2.0d0)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((x * x) <= 2e+227) {
		tmp = 0.5 * y;
	} else {
		tmp = (x / y) * (x / 2.0);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x * x) <= 2e+227:
		tmp = 0.5 * y
	else:
		tmp = (x / y) * (x / 2.0)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (Float64(x * x) <= 2e+227)
		tmp = Float64(0.5 * y);
	else
		tmp = Float64(Float64(x / y) * Float64(x / 2.0));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x * x) <= 2e+227)
		tmp = 0.5 * y;
	else
		tmp = (x / y) * (x / 2.0);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 2e+227], N[(0.5 * y), $MachinePrecision], N[(N[(x / y), $MachinePrecision] * N[(x / 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{+227}:\\
\;\;\;\;0.5 \cdot y\\

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


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

    1. Initial program 75.9%

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

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

        \[\leadsto \color{blue}{y \cdot 0.5} \]
    5. Simplified39.7%

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

    if 2.0000000000000002e227 < (*.f64 x x)

    1. Initial program 62.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 34.7% accurate, 5.0× speedup?

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

\\
0.5 \cdot y
\end{array}
Derivation
  1. Initial program 71.9%

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

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

      \[\leadsto \color{blue}{y \cdot 0.5} \]
  5. Simplified32.3%

    \[\leadsto \color{blue}{y \cdot 0.5} \]
  6. Final simplification32.3%

    \[\leadsto 0.5 \cdot y \]
  7. Add Preprocessing

Developer target: 99.9% accurate, 1.0× speedup?

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

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

Reproduce

?
herbie shell --seed 2024077 
(FPCore (x y z)
  :name "Diagrams.TwoD.Apollonian:initialConfig from diagrams-contrib-1.3.0.5, A"
  :precision binary64

  :alt
  (- (* y 0.5) (* (* (/ 0.5 y) (+ z x)) (- z x)))

  (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))