?

Average Accuracy: 68.9% → 99.8%
Time: 11.9s
Precision: binary64
Cost: 7168

?

\[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
\[\mathsf{fma}\left(\frac{z + x}{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 (/ (+ z x) 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(((z + x) / 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(z + x) / 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[(z + x), $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{z + x}{y}, z - x, -y\right) \cdot -0.5

Error?

Target

Original68.9%
Target99.9%
Herbie99.8%
\[y \cdot 0.5 - \left(\frac{0.5}{y} \cdot \left(z + x\right)\right) \cdot \left(z - x\right) \]

Derivation?

  1. Initial program 72.2%

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

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

    [Start]72.2

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

    sub-neg [=>]72.2

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

    +-commutative [=>]72.2

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

    neg-sub0 [=>]72.2

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

    associate-+l- [=>]72.2

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

    sub0-neg [=>]72.2

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

    neg-mul-1 [=>]72.2

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

    *-commutative [=>]72.2

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

    times-frac [=>]72.2

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

    associate--r+ [=>]72.2

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

    div-sub [=>]72.2

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

    difference-of-squares [=>]77.0

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

    +-commutative [<=]77.0

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

    associate-*l/ [<=]80.9

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

    *-commutative [=>]80.9

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

    associate-/l* [=>]99.9

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

    *-inverses [=>]99.9

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

    /-rgt-identity [=>]99.9

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

    metadata-eval [=>]99.9

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

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

    [Start]99.9

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

    *-commutative [=>]99.9

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

    fma-neg [=>]99.9

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

    +-commutative [=>]99.9

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

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

Alternatives

Alternative 1
Accuracy51.3%
Cost1372
\[\begin{array}{l} t_0 := z \cdot \left(z \cdot \frac{-0.5}{y}\right)\\ t_1 := 0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{if}\;z \leq -1.3 \cdot 10^{-36}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.5 \cdot 10^{-128}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -6.5 \cdot 10^{-271}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq 8.2 \cdot 10^{-224}:\\ \;\;\;\;x \cdot \frac{x \cdot 0.5}{y}\\ \mathbf{elif}\;z \leq 1.9 \cdot 10^{-34}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{+15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3 \cdot 10^{+79}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Accuracy51.4%
Cost1372
\[\begin{array}{l} t_0 := z \cdot \frac{-0.5}{\frac{y}{z}}\\ t_1 := 0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{if}\;z \leq -1.3 \cdot 10^{-36}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.85 \cdot 10^{-131}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.2 \cdot 10^{-269}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq 1.5 \cdot 10^{-223}:\\ \;\;\;\;x \cdot \frac{x \cdot 0.5}{y}\\ \mathbf{elif}\;z \leq 1.6 \cdot 10^{-32}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq 5 \cdot 10^{+15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.02 \cdot 10^{+80}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Accuracy51.3%
Cost1372
\[\begin{array}{l} t_0 := -0.5 \cdot \frac{z}{\frac{y}{z}}\\ t_1 := 0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{if}\;z \leq -1.15 \cdot 10^{-36}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.45 \cdot 10^{-130}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.05 \cdot 10^{-268}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq 3.6 \cdot 10^{-223}:\\ \;\;\;\;x \cdot \frac{x \cdot 0.5}{y}\\ \mathbf{elif}\;z \leq 9.5 \cdot 10^{-38}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq 1.5 \cdot 10^{+16}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.1 \cdot 10^{+79}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Accuracy51.3%
Cost1372
\[\begin{array}{l} t_0 := -0.5 \cdot \frac{z}{\frac{y}{z}}\\ \mathbf{if}\;z \leq -1.5 \cdot 10^{-37}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.9 \cdot 10^{-137}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{elif}\;z \leq -1.8 \cdot 10^{-270}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq 7.7 \cdot 10^{-224}:\\ \;\;\;\;x \cdot \frac{x \cdot 0.5}{y}\\ \mathbf{elif}\;z \leq 1.16 \cdot 10^{-32}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{+16}:\\ \;\;\;\;\frac{x \cdot \left(x \cdot 0.5\right)}{y}\\ \mathbf{elif}\;z \leq 1.16 \cdot 10^{+79}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Accuracy87.7%
Cost1364
\[\begin{array}{l} t_0 := -0.5 \cdot \left(z \cdot \frac{z}{y} - y\right)\\ t_1 := -0.5 \cdot \left(\left(z - x\right) \cdot \frac{x}{y} - y\right)\\ \mathbf{if}\;x \leq -2.3 \cdot 10^{-23}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 0.54:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.8 \cdot 10^{+74}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2 \cdot 10^{+101}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5.4 \cdot 10^{+155}:\\ \;\;\;\;\left(z + x\right) \cdot \left(\left(x - z\right) \cdot \frac{0.5}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Accuracy84.8%
Cost905
\[\begin{array}{l} \mathbf{if}\;x \leq -4.1 \cdot 10^{-22} \lor \neg \left(x \leq 1.24 \cdot 10^{+113}\right):\\ \;\;\;\;-0.5 \cdot \left(\left(-y\right) - \frac{x}{\frac{y}{x}}\right)\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \left(z \cdot \frac{z}{y} - y\right)\\ \end{array} \]
Alternative 7
Accuracy84.7%
Cost904
\[\begin{array}{l} \mathbf{if}\;x \leq -1.65 \cdot 10^{-16}:\\ \;\;\;\;\left(z + x\right) \cdot \left(\left(x - z\right) \cdot \frac{0.5}{y}\right)\\ \mathbf{elif}\;x \leq 1.24 \cdot 10^{+113}:\\ \;\;\;\;-0.5 \cdot \left(z \cdot \frac{z}{y} - y\right)\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \left(\left(-y\right) - \frac{x}{\frac{y}{x}}\right)\\ \end{array} \]
Alternative 8
Accuracy80.9%
Cost841
\[\begin{array}{l} \mathbf{if}\;x \leq -5.5 \cdot 10^{+101} \lor \neg \left(x \leq 1.24 \cdot 10^{+113}\right):\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \left(z \cdot \frac{z}{y} - y\right)\\ \end{array} \]
Alternative 9
Accuracy99.8%
Cost832
\[-0.5 \cdot \left(\left(z - x\right) \cdot \frac{z + x}{y} - y\right) \]
Alternative 10
Accuracy52.4%
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -1.65 \cdot 10^{-16} \lor \neg \left(x \leq 1.24 \cdot 10^{+113}\right):\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
Alternative 11
Accuracy52.3%
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -3.2 \cdot 10^{-18}:\\ \;\;\;\;x \cdot \frac{x \cdot 0.5}{y}\\ \mathbf{elif}\;x \leq 1.24 \cdot 10^{+113}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \end{array} \]
Alternative 12
Accuracy34.7%
Cost192
\[y \cdot 0.5 \]

Error

Reproduce?

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