?

Average Error: 28.4 → 0.2
Time: 13.2s
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.4
Target0.2
Herbie0.2
\[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.4

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

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

    [Start]28.4

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

    sub-neg [=>]28.4

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

    +-commutative [=>]28.4

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

    neg-sub0 [=>]28.4

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

    associate-+l- [=>]28.4

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

    sub0-neg [=>]28.4

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

    neg-mul-1 [=>]28.4

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

    *-commutative [=>]28.4

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

    times-frac [=>]28.5

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

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

Alternatives

Alternative 1
Error23.6
Cost1372
\[\begin{array}{l} t_0 := z \cdot \left(z \cdot \frac{-0.5}{y}\right)\\ t_1 := x \cdot \left(x \cdot \frac{0.5}{y}\right)\\ \mathbf{if}\;y \leq -2 \cdot 10^{+44}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;y \leq -1.35 \cdot 10^{-37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -3.7 \cdot 10^{-166}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.15 \cdot 10^{-247}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.1 \cdot 10^{-246}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.05 \cdot 10^{-131}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{-66}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
Alternative 2
Error23.7
Cost1372
\[\begin{array}{l} t_0 := -0.5 \cdot \left(z \cdot \frac{z}{y}\right)\\ t_1 := x \cdot \left(x \cdot \frac{0.5}{y}\right)\\ \mathbf{if}\;y \leq -2.7 \cdot 10^{+44}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;y \leq -1.25 \cdot 10^{-37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -8.6 \cdot 10^{-165}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.7 \cdot 10^{-238}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 8 \cdot 10^{-245}:\\ \;\;\;\;z \cdot \left(z \cdot \frac{-0.5}{y}\right)\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{-129}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{-66}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
Alternative 3
Error23.7
Cost1372
\[\begin{array}{l} t_0 := -0.5 \cdot \left(z \cdot \frac{z}{y}\right)\\ t_1 := x \cdot \left(x \cdot \frac{0.5}{y}\right)\\ \mathbf{if}\;y \leq -2 \cdot 10^{+44}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;y \leq -1.55 \cdot 10^{-37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -5 \cdot 10^{-166}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.3 \cdot 10^{-237}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{elif}\;y \leq 4 \cdot 10^{-246}:\\ \;\;\;\;z \cdot \left(z \cdot \frac{-0.5}{y}\right)\\ \mathbf{elif}\;y \leq 8 \cdot 10^{-129}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 10^{-66}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
Alternative 4
Error24.1
Cost1372
\[\begin{array}{l} t_0 := -0.5 \cdot \frac{z \cdot z}{y}\\ t_1 := x \cdot \left(x \cdot \frac{0.5}{y}\right)\\ \mathbf{if}\;y \leq -2 \cdot 10^{+44}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;y \leq -1.8 \cdot 10^{-37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -6.2 \cdot 10^{-168}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.9 \cdot 10^{-237}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{-244}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{-129}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.25 \cdot 10^{-65}:\\ \;\;\;\;-0.5 \cdot \left(z \cdot \frac{z}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
Alternative 5
Error24.1
Cost1372
\[\begin{array}{l} t_0 := -0.5 \cdot \frac{z \cdot z}{y}\\ t_1 := \frac{x \cdot x}{y \cdot 2}\\ \mathbf{if}\;y \leq -2 \cdot 10^{+44}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;y \leq -1.35 \cdot 10^{-37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.5 \cdot 10^{-167}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -4.1 \cdot 10^{-244}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{-245}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.7 \cdot 10^{-129}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7.2 \cdot 10^{-66}:\\ \;\;\;\;-0.5 \cdot \left(z \cdot \frac{z}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
Alternative 6
Error24.3
Cost978
\[\begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{+44} \lor \neg \left(y \leq -9.2 \cdot 10^{-34}\right) \land \left(y \leq -3.2 \cdot 10^{-134} \lor \neg \left(y \leq 4 \cdot 10^{-10}\right)\right):\\ \;\;\;\;y \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(x \cdot \frac{0.5}{y}\right)\\ \end{array} \]
Alternative 7
Error6.7
Cost968
\[\begin{array}{l} \mathbf{if}\;x \leq -1.15 \cdot 10^{-78}:\\ \;\;\;\;-0.5 \cdot \left(\frac{z - x}{y \cdot \frac{1}{x}} - y\right)\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{-94}:\\ \;\;\;\;-0.5 \cdot \left(\frac{1}{\frac{\frac{y}{z}}{z}} - y\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(y + x \cdot \frac{x}{y}\right)\\ \end{array} \]
Alternative 8
Error6.8
Cost964
\[\begin{array}{l} \mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-188}:\\ \;\;\;\;-0.5 \cdot \left(\frac{1}{\frac{\frac{y}{z}}{z}} - y\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(y + x \cdot \frac{x}{y}\right)\\ \end{array} \]
Alternative 9
Error14.6
Cost845
\[\begin{array}{l} \mathbf{if}\;x \leq 2.4 \cdot 10^{+40}:\\ \;\;\;\;-0.5 \cdot \left(\frac{z}{\frac{y}{z}} - y\right)\\ \mathbf{elif}\;x \leq 1.85 \cdot 10^{+84} \lor \neg \left(x \leq 2.2 \cdot 10^{+189}\right):\\ \;\;\;\;x \cdot \left(x \cdot \frac{0.5}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
Alternative 10
Error6.8
Cost836
\[\begin{array}{l} \mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-188}:\\ \;\;\;\;-0.5 \cdot \left(\frac{z}{\frac{y}{z}} - y\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(y + x \cdot \frac{x}{y}\right)\\ \end{array} \]
Alternative 11
Error0.2
Cost832
\[-0.5 \cdot \left(\frac{z - x}{\frac{y}{x + z}} - y\right) \]
Alternative 12
Error27.1
Cost192
\[y \cdot 0.5 \]

Error

Reproduce?

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