Average Error: 28.0 → 2.0
Time: 12.9s
Precision: binary64
Cost: 39940
\[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
\[\begin{array}{l} t_0 := \sqrt[3]{y + y}\\ \mathbf{if}\;z \cdot z \leq 5 \cdot 10^{+289}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\mathsf{hypot}\left(x, y\right)}{{t_0}^{2}}, \frac{\mathsf{hypot}\left(x, y\right)}{t_0}, \left(z \cdot z\right) \cdot \frac{-0.5}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \left(\frac{z}{\frac{y}{z}} - y\right)\\ \end{array} \]
(FPCore (x y z)
 :precision binary64
 (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (cbrt (+ y y))))
   (if (<= (* z z) 5e+289)
     (fma
      (/ (hypot x y) (pow t_0 2.0))
      (/ (hypot x y) t_0)
      (* (* z z) (/ -0.5 y)))
     (* -0.5 (- (/ z (/ y z)) y)))))
double code(double x, double y, double z) {
	return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
double code(double x, double y, double z) {
	double t_0 = cbrt((y + y));
	double tmp;
	if ((z * z) <= 5e+289) {
		tmp = fma((hypot(x, y) / pow(t_0, 2.0)), (hypot(x, y) / t_0), ((z * z) * (-0.5 / y)));
	} else {
		tmp = -0.5 * ((z / (y / z)) - y);
	}
	return tmp;
}
function code(x, y, z)
	return Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) - Float64(z * z)) / Float64(y * 2.0))
end
function code(x, y, z)
	t_0 = cbrt(Float64(y + y))
	tmp = 0.0
	if (Float64(z * z) <= 5e+289)
		tmp = fma(Float64(hypot(x, y) / (t_0 ^ 2.0)), Float64(hypot(x, y) / t_0), Float64(Float64(z * z) * Float64(-0.5 / y)));
	else
		tmp = Float64(-0.5 * Float64(Float64(z / Float64(y / z)) - y));
	end
	return tmp
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]
code[x_, y_, z_] := Block[{t$95$0 = N[Power[N[(y + y), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[N[(z * z), $MachinePrecision], 5e+289], N[(N[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] / N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] / t$95$0), $MachinePrecision] + N[(N[(z * z), $MachinePrecision] * N[(-0.5 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(N[(z / N[(y / z), $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision]), $MachinePrecision]]]
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\begin{array}{l}
t_0 := \sqrt[3]{y + y}\\
\mathbf{if}\;z \cdot z \leq 5 \cdot 10^{+289}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\mathsf{hypot}\left(x, y\right)}{{t_0}^{2}}, \frac{\mathsf{hypot}\left(x, y\right)}{t_0}, \left(z \cdot z\right) \cdot \frac{-0.5}{y}\right)\\

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


\end{array}

Error

Target

Original28.0
Target0.2
Herbie2.0
\[y \cdot 0.5 - \left(\frac{0.5}{y} \cdot \left(z + x\right)\right) \cdot \left(z - x\right) \]

Derivation

  1. Split input into 2 regimes
  2. if (*.f64 z z) < 5.00000000000000031e289

    1. Initial program 23.7

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Applied egg-rr1.8

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

    if 5.00000000000000031e289 < (*.f64 z z)

    1. Initial program 61.2

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

      \[\leadsto \color{blue}{-0.5 \cdot \left(\frac{\mathsf{fma}\left(z, z, x \cdot \left(-x\right)\right)}{y} - y\right)} \]
      Proof
      (*.f64 -1/2 (-.f64 (/.f64 (fma.f64 z z (*.f64 x (neg.f64 x))) y) y)): 0 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= metadata-eval (/.f64 -1 2)) (-.f64 (/.f64 (fma.f64 z z (*.f64 x (neg.f64 x))) y) y)): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 -1 2) (-.f64 (/.f64 (fma.f64 z z (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 x x)))) y) y)): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 -1 2) (-.f64 (/.f64 (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 z z) (*.f64 x x))) y) y)): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 -1 2) (-.f64 (/.f64 (-.f64 (*.f64 z z) (*.f64 x x)) y) (Rewrite<= /-rgt-identity_binary64 (/.f64 y 1)))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 -1 2) (-.f64 (/.f64 (-.f64 (*.f64 z z) (*.f64 x x)) y) (/.f64 y (Rewrite<= *-inverses_binary64 (/.f64 y y))))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 -1 2) (-.f64 (/.f64 (-.f64 (*.f64 z z) (*.f64 x x)) y) (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 y y) y)))): 51 points increase in error, 1 points decrease in error
      (*.f64 (/.f64 -1 2) (Rewrite<= div-sub_binary64 (/.f64 (-.f64 (-.f64 (*.f64 z z) (*.f64 x x)) (*.f64 y y)) y))): 2 points increase in error, 2 points decrease in error
      (*.f64 (/.f64 -1 2) (/.f64 (Rewrite<= associate--r+_binary64 (-.f64 (*.f64 z z) (+.f64 (*.f64 x x) (*.f64 y y)))) y)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= times-frac_binary64 (/.f64 (*.f64 -1 (-.f64 (*.f64 z z) (+.f64 (*.f64 x x) (*.f64 y y)))) (*.f64 2 y))): 0 points increase in error, 1 points decrease in error
      (/.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 (-.f64 (*.f64 z z) (+.f64 (*.f64 x x) (*.f64 y y))))) (*.f64 2 y)): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= sub0-neg_binary64 (-.f64 0 (-.f64 (*.f64 z z) (+.f64 (*.f64 x x) (*.f64 y y))))) (*.f64 2 y)): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 0 (*.f64 z z)) (+.f64 (*.f64 x x) (*.f64 y y)))) (*.f64 2 y)): 0 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 (*.f64 z z))) (+.f64 (*.f64 x x) (*.f64 y y))) (*.f64 2 y)): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= +-commutative_binary64 (+.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (neg.f64 (*.f64 z z)))) (*.f64 2 y)): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= sub-neg_binary64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z))) (*.f64 2 y)): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (Rewrite<= *-commutative_binary64 (*.f64 y 2))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in z around inf 58.2

      \[\leadsto -0.5 \cdot \left(\color{blue}{\frac{{z}^{2}}{y}} - y\right) \]
    4. Simplified3.8

      \[\leadsto -0.5 \cdot \left(\color{blue}{z \cdot \frac{z}{y}} - y\right) \]
      Proof
      (*.f64 z (/.f64 z y)): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 z z) y)): 62 points increase in error, 20 points decrease in error
      (/.f64 (Rewrite<= unpow2_binary64 (pow.f64 z 2)) y): 0 points increase in error, 0 points decrease in error
    5. Applied egg-rr3.8

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

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

Alternatives

Alternative 1
Error13.3
Cost3016
\[\begin{array}{l} t_0 := \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;0.5 \cdot \left(y + x \cdot \frac{x}{y}\right)\\ \mathbf{elif}\;t_0 \leq \infty:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \left(\frac{z}{\frac{y}{z}} - y\right)\\ \end{array} \]
Alternative 2
Error15.0
Cost2008
\[\begin{array}{l} t_0 := \frac{x \cdot x}{y \cdot 2}\\ t_1 := -0.5 \cdot \left(\frac{z}{\frac{y}{z}} - y\right)\\ \mathbf{if}\;x \cdot x \leq 1.5 \cdot 10^{+94}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+123}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \cdot x \leq 10^{+136}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 10^{+158}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{x}{y}\right)\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+262}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 10^{+303}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
Alternative 3
Error15.0
Cost2008
\[\begin{array}{l} t_0 := \frac{x \cdot x}{y \cdot 2}\\ t_1 := -0.5 \cdot \left(\frac{z}{\frac{y}{z}} - y\right)\\ \mathbf{if}\;x \cdot x \leq 1.5 \cdot 10^{+94}:\\ \;\;\;\;-0.5 \cdot \left(z \cdot \frac{z}{y} - y\right)\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+123}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \cdot x \leq 10^{+136}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 10^{+158}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{x}{y}\right)\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+262}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 10^{+303}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
Alternative 4
Error25.6
Cost1108
\[\begin{array}{l} t_0 := \frac{\left(z \cdot z\right) \cdot -0.5}{y}\\ t_1 := 0.5 \cdot \left(x \cdot \frac{x}{y}\right)\\ \mathbf{if}\;y \leq -1.12 \cdot 10^{+58}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;y \leq -2.9 \cdot 10^{-67}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.3 \cdot 10^{-277}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.15 \cdot 10^{-82}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 6.6 \cdot 10^{+38}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
Alternative 5
Error25.3
Cost1108
\[\begin{array}{l} t_0 := z \cdot \frac{z \cdot -0.5}{y}\\ t_1 := 0.5 \cdot \left(x \cdot \frac{x}{y}\right)\\ \mathbf{if}\;y \leq -1.12 \cdot 10^{+58}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;y \leq -2.9 \cdot 10^{-67}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{-228}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.15 \cdot 10^{-82}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 6.6 \cdot 10^{+38}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
Alternative 6
Error25.3
Cost1108
\[\begin{array}{l} t_0 := z \cdot \frac{z \cdot -0.5}{y}\\ \mathbf{if}\;y \leq -1.12 \cdot 10^{+58}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;y \leq -2.9 \cdot 10^{-67}:\\ \;\;\;\;\frac{x \cdot x}{y \cdot 2}\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{-228}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.15 \cdot 10^{-82}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{x}{y}\right)\\ \mathbf{elif}\;y \leq 6.6 \cdot 10^{+38}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
Alternative 7
Error6.6
Cost840
\[\begin{array}{l} t_0 := 0.5 \cdot \left(y + x \cdot \frac{x}{y}\right)\\ \mathbf{if}\;x \leq -1.007238165673285 \cdot 10^{-48}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 8.402344026082175 \cdot 10^{-54}:\\ \;\;\;\;-0.5 \cdot \left(z \cdot \frac{z}{y} - y\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error24.8
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -1.12 \cdot 10^{+58}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{-82}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
Alternative 9
Error27.9
Cost192
\[y \cdot 0.5 \]

Error

Reproduce

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