?

Average Accuracy: 55.5% → 99.8%
Time: 9.4s
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

Original55.5%
Target99.7%
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 55.5%

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

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

    [Start]55.5

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

    sub-neg [=>]55.5

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

    +-commutative [=>]55.5

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

    neg-sub0 [=>]55.5

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

    associate-+l- [=>]55.5

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

    sub0-neg [=>]55.5

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

    neg-mul-1 [=>]55.5

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

    *-commutative [=>]55.5

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

    times-frac [=>]55.5

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

    associate--r+ [=>]55.5

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

    div-sub [=>]55.5

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

    difference-of-squares [=>]55.5

    \[ \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 [<=]55.5

    \[ \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/ [<=]61.2

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

    *-commutative [=>]61.2

    \[ \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.8

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

    *-inverses [=>]99.8

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

    /-rgt-identity [=>]99.8

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

    metadata-eval [=>]99.8

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

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

    [Start]99.8

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

    *-commutative [=>]99.8

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

    fma-neg [=>]99.8

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

    +-commutative [=>]99.8

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

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

Alternatives

Alternative 1
Accuracy74.8%
Cost1105
\[\begin{array}{l} t_0 := -0.5 \cdot \left(\frac{z}{\frac{y}{z}} - y\right)\\ \mathbf{if}\;y \leq -4 \cdot 10^{-171}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.05 \cdot 10^{-246}:\\ \;\;\;\;x \cdot \frac{x \cdot 0.5}{y}\\ \mathbf{elif}\;y \leq 1.6 \cdot 10^{-72} \lor \neg \left(y \leq 1.7 \cdot 10^{+58}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(x \cdot 0.5\right)}{y}\\ \end{array} \]
Alternative 2
Accuracy74.8%
Cost1105
\[\begin{array}{l} t_0 := -0.5 \cdot \left(\frac{z}{\frac{y}{z}} - y\right)\\ \mathbf{if}\;y \leq -3.9 \cdot 10^{-171}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -7 \cdot 10^{-237}:\\ \;\;\;\;x \cdot \frac{x \cdot 0.5}{y}\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{-70} \lor \neg \left(y \leq 1.7 \cdot 10^{+58}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{x \cdot \left(z - x\right)}{y}\\ \end{array} \]
Alternative 3
Accuracy88.7%
Cost905
\[\begin{array}{l} \mathbf{if}\;x \leq -4.3 \cdot 10^{-24} \lor \neg \left(x \leq 1.15 \cdot 10^{+34}\right):\\ \;\;\;\;-0.5 \cdot \left(\left(-y\right) - \frac{x}{\frac{y}{x}}\right)\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \left(\frac{z}{\frac{y}{z}} - y\right)\\ \end{array} \]
Alternative 4
Accuracy88.7%
Cost904
\[\begin{array}{l} \mathbf{if}\;x \leq -1.02 \cdot 10^{-30}:\\ \;\;\;\;-0.5 \cdot \left(\left(z - x\right) \cdot \frac{x}{y} - y\right)\\ \mathbf{elif}\;x \leq 2.2 \cdot 10^{+34}:\\ \;\;\;\;-0.5 \cdot \left(\frac{z}{\frac{y}{z}} - y\right)\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \left(\left(-y\right) - \frac{x}{\frac{y}{x}}\right)\\ \end{array} \]
Alternative 5
Accuracy63.2%
Cost844
\[\begin{array}{l} \mathbf{if}\;y \leq -2.15 \cdot 10^{-101}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{-72}:\\ \;\;\;\;z \cdot \frac{z}{\frac{y}{-0.5}}\\ \mathbf{elif}\;y \leq 1.7 \cdot 10^{+58}:\\ \;\;\;\;\frac{x}{\frac{y}{x}} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
Alternative 6
Accuracy63.0%
Cost844
\[\begin{array}{l} \mathbf{if}\;y \leq -2.15 \cdot 10^{-101}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{-74}:\\ \;\;\;\;z \cdot \frac{z}{\frac{y}{-0.5}}\\ \mathbf{elif}\;y \leq 1.7 \cdot 10^{+58}:\\ \;\;\;\;\frac{x \cdot \left(x \cdot 0.5\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
Alternative 7
Accuracy99.8%
Cost832
\[-0.5 \cdot \left(\left(z - x\right) \cdot \frac{z + x}{y} - y\right) \]
Alternative 8
Accuracy62.7%
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -4.6 \cdot 10^{-168}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{+58}:\\ \;\;\;\;\frac{x}{\frac{y}{x}} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
Alternative 9
Accuracy58.0%
Cost192
\[y \cdot 0.5 \]

Error

Reproduce?

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