Average Error: 28.2 → 0.1
Time: 10.6s
Precision: binary64
Cost: 7168
\[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
\[\mathsf{fma}\left(\frac{x + z}{y}, z - x, -y\right) \cdot -0.5 \]
(FPCore (x y z)
 :precision binary64
 (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))
(FPCore (x y z) :precision binary64 (* (fma (/ (+ x z) y) (- z x) (- y)) -0.5))
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) {
	return fma(((x + z) / y), (z - x), -y) * -0.5;
}
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)
	return Float64(fma(Float64(Float64(x + z) / y), Float64(z - x), Float64(-y)) * -0.5)
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_] := N[(N[(N[(N[(x + z), $MachinePrecision] / y), $MachinePrecision] * N[(z - x), $MachinePrecision] + (-y)), $MachinePrecision] * -0.5), $MachinePrecision]
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\mathsf{fma}\left(\frac{x + z}{y}, z - x, -y\right) \cdot -0.5

Error

Target

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

Derivation

  1. Initial program 28.2

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

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

    [Start]28.2

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

    sub-neg [=>]28.2

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

    +-commutative [=>]28.2

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

    neg-sub0 [=>]28.2

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

    associate-+l- [=>]28.2

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

    sub0-neg [=>]28.2

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

    neg-mul-1 [=>]28.2

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

    *-commutative [=>]28.2

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

    times-frac [=>]28.2

    \[ \color{blue}{\frac{z \cdot z - \left(x \cdot x + y \cdot y\right)}{y} \cdot \frac{-1}{2}} \]
  3. Final simplification0.1

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

Alternatives

Alternative 1
Error30.6
Cost2033
\[\begin{array}{l} t_0 := z \cdot \left(z \cdot \frac{-0.5}{y}\right)\\ t_1 := \left(x \cdot \frac{x}{y}\right) \cdot 0.5\\ \mathbf{if}\;z \leq -5.5 \cdot 10^{+34}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.8 \cdot 10^{-7}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq -5 \cdot 10^{-44}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -6.8 \cdot 10^{-214}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq -1.55 \cdot 10^{-223}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{-207}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq 4.9 \cdot 10^{-178}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{elif}\;z \leq 1.55 \cdot 10^{-150}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq 9.4 \cdot 10^{-132}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 0.068 \lor \neg \left(z \leq 1.65 \cdot 10^{+87}\right) \land z \leq 4.4 \cdot 10^{+210}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error30.6
Cost2032
\[\begin{array}{l} t_0 := z \cdot \left(z \cdot \frac{-0.5}{y}\right)\\ t_1 := \left(x \cdot \frac{x}{y}\right) \cdot 0.5\\ \mathbf{if}\;z \leq -8.2 \cdot 10^{+34}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.8 \cdot 10^{-7}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq -5 \cdot 10^{-44}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -5.5 \cdot 10^{-212}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq -1.55 \cdot 10^{-223}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{-207}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq 4.9 \cdot 10^{-178}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{elif}\;z \leq 1.75 \cdot 10^{-150}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq 9.4 \cdot 10^{-132}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 0.068:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq 1.9 \cdot 10^{+89}:\\ \;\;\;\;-0.5 \cdot \frac{z}{\frac{y}{z}}\\ \mathbf{elif}\;z \leq 3.1 \cdot 10^{+209}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error30.7
Cost2032
\[\begin{array}{l} t_0 := z \cdot \left(z \cdot \frac{-0.5}{y}\right)\\ t_1 := \left(x \cdot \frac{x}{y}\right) \cdot 0.5\\ \mathbf{if}\;z \leq -1.3 \cdot 10^{+34}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -0.000175:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq -5 \cdot 10^{-44}:\\ \;\;\;\;-0.5 \cdot \frac{z \cdot z}{y}\\ \mathbf{elif}\;z \leq -1.22 \cdot 10^{-210}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq -1.52 \cdot 10^{-223}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{-207}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq 1.95 \cdot 10^{-177}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{elif}\;z \leq 1.55 \cdot 10^{-150}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq 9.4 \cdot 10^{-132}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 0.068:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{+87}:\\ \;\;\;\;-0.5 \cdot \frac{z}{\frac{y}{z}}\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{+210}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error15.9
Cost1368
\[\begin{array}{l} t_0 := \left(x \cdot \frac{x}{y}\right) \cdot 0.5\\ t_1 := -0.5 \cdot \left(z \cdot \frac{z}{y} - y\right)\\ \mathbf{if}\;z \leq -6.8 \cdot 10^{-214}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.5 \cdot 10^{-223}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{-207}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq 4.9 \cdot 10^{-178}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{elif}\;z \leq 2.35 \cdot 10^{-150}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq 8 \cdot 10^{-131}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error6.8
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -7.5 \cdot 10^{-48} \lor \neg \left(z \leq 1.4 \cdot 10^{-31}\right):\\ \;\;\;\;-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 6
Error0.1
Cost832
\[-0.5 \cdot \left(\frac{z - x}{\frac{y}{x + z}} - y\right) \]
Alternative 7
Error22.9
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{-103}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;y \leq 2.9 \cdot 10^{-53}:\\ \;\;\;\;\left(x \cdot \frac{x}{y}\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
Alternative 8
Error27.6
Cost192
\[y \cdot 0.5 \]

Error

Reproduce

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