?

Average Accuracy: 54.9% → 99.8%
Time: 9.9s
Precision: binary64
Cost: 7168.00

?

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

Original54.9%
Target99.8%
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 54.9%

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

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

    [Start]54.9

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

    sub-neg [=>]54.9

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

    +-commutative [=>]54.9

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

    neg-sub0 [=>]54.9

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

    associate-+l- [=>]54.9

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

    sub0-neg [=>]54.9

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

    neg-mul-1 [=>]54.9

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

    *-commutative [=>]54.9

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

    times-frac [=>]54.9

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

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

Alternatives

Alternative 1
Accuracy75.8%
Cost2137.00
\[\begin{array}{l} t_0 := \frac{x \cdot x}{y \cdot 2}\\ t_1 := -0.5 \cdot \left(z \cdot \frac{z}{y} - y\right)\\ \mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-81}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{-56}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \cdot x \leq 50000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{+59}:\\ \;\;\;\;\frac{x}{\frac{y}{x}} \cdot 0.5\\ \mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+239} \lor \neg \left(x \cdot x \leq 5 \cdot 10^{+300}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Accuracy64.1%
Cost1108.00
\[\begin{array}{l} t_0 := x \cdot \left(x \cdot \frac{0.5}{y}\right)\\ t_1 := z \cdot \left(z \cdot \frac{-0.5}{y}\right)\\ \mathbf{if}\;y \leq -2.8 \cdot 10^{-42}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;y \leq -1.02 \cdot 10^{-181}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -7 \cdot 10^{-251}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.45 \cdot 10^{-283}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 26000000000000:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
Alternative 3
Accuracy64.0%
Cost1108.00
\[\begin{array}{l} t_0 := x \cdot \left(x \cdot \frac{0.5}{y}\right)\\ \mathbf{if}\;y \leq -5.8 \cdot 10^{-41}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;y \leq -1.1 \cdot 10^{-181}:\\ \;\;\;\;z \cdot \left(z \cdot \frac{-0.5}{y}\right)\\ \mathbf{elif}\;y \leq -1.45 \cdot 10^{-249}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 6 \cdot 10^{-284}:\\ \;\;\;\;-0.5 \cdot \left(z \cdot \frac{z}{y}\right)\\ \mathbf{elif}\;y \leq 30000000000000:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
Alternative 4
Accuracy64.1%
Cost1108.00
\[\begin{array}{l} \mathbf{if}\;y \leq -2.8 \cdot 10^{-42}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;y \leq -1.25 \cdot 10^{-181}:\\ \;\;\;\;z \cdot \left(z \cdot \frac{-0.5}{y}\right)\\ \mathbf{elif}\;y \leq -2.2 \cdot 10^{-251}:\\ \;\;\;\;\frac{x}{\frac{y}{x}} \cdot 0.5\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{-283}:\\ \;\;\;\;-0.5 \cdot \left(z \cdot \frac{z}{y}\right)\\ \mathbf{elif}\;y \leq 33000000000000:\\ \;\;\;\;x \cdot \left(x \cdot \frac{0.5}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
Alternative 5
Accuracy64.0%
Cost1108.00
\[\begin{array}{l} \mathbf{if}\;y \leq -9 \cdot 10^{-42}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;y \leq -1.2 \cdot 10^{-181}:\\ \;\;\;\;-0.5 \cdot \frac{z}{\frac{y}{z}}\\ \mathbf{elif}\;y \leq -9.5 \cdot 10^{-245}:\\ \;\;\;\;\frac{x}{\frac{y}{x}} \cdot 0.5\\ \mathbf{elif}\;y \leq 3.4 \cdot 10^{-284}:\\ \;\;\;\;-0.5 \cdot \left(z \cdot \frac{z}{y}\right)\\ \mathbf{elif}\;y \leq 28000000000000:\\ \;\;\;\;x \cdot \left(x \cdot \frac{0.5}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
Alternative 6
Accuracy64.1%
Cost1108.00
\[\begin{array}{l} \mathbf{if}\;y \leq -2.8 \cdot 10^{-42}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;y \leq -1.25 \cdot 10^{-181}:\\ \;\;\;\;\frac{z \cdot \left(z \cdot -0.5\right)}{y}\\ \mathbf{elif}\;y \leq -2.55 \cdot 10^{-247}:\\ \;\;\;\;\frac{x}{\frac{y}{x}} \cdot 0.5\\ \mathbf{elif}\;y \leq 4.9 \cdot 10^{-284}:\\ \;\;\;\;-0.5 \cdot \left(z \cdot \frac{z}{y}\right)\\ \mathbf{elif}\;y \leq 26000000000000:\\ \;\;\;\;x \cdot \left(x \cdot \frac{0.5}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
Alternative 7
Accuracy87.1%
Cost1105.00
\[\begin{array}{l} t_0 := -0.5 \cdot \left(z \cdot \frac{z}{y} - y\right)\\ \mathbf{if}\;z \leq -5.2 \cdot 10^{+34}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -9.2 \cdot 10^{-34}:\\ \;\;\;\;-0.5 \cdot \left(\left(z - x\right) \cdot \frac{x + z}{y}\right)\\ \mathbf{elif}\;z \leq -3 \cdot 10^{-112} \lor \neg \left(z \leq 1.8 \cdot 10^{-86}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(y + x \cdot \frac{x}{y}\right)\\ \end{array} \]
Alternative 8
Accuracy88.1%
Cost1105.00
\[\begin{array}{l} t_0 := -0.5 \cdot \left(z \cdot \frac{z}{y} - y\right)\\ \mathbf{if}\;z \leq -0.37:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -9.2 \cdot 10^{-34}:\\ \;\;\;\;-0.5 \cdot \frac{\left(z - x\right) \cdot \left(x + z\right)}{y}\\ \mathbf{elif}\;z \leq -1.7 \cdot 10^{-113} \lor \neg \left(z \leq 1.12 \cdot 10^{-91}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(y + x \cdot \frac{x}{y}\right)\\ \end{array} \]
Alternative 9
Accuracy89.5%
Cost841.00
\[\begin{array}{l} \mathbf{if}\;z \leq -2.75 \cdot 10^{-112} \lor \neg \left(z \leq 3.4 \cdot 10^{-88}\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 10
Accuracy99.8%
Cost832.00
\[-0.5 \cdot \left(\left(z - x\right) \cdot \frac{x + z}{y} - y\right) \]
Alternative 11
Accuracy63.7%
Cost713.00
\[\begin{array}{l} \mathbf{if}\;y \leq -2.7 \cdot 10^{-12} \lor \neg \left(y \leq 1.95 \cdot 10^{+17}\right):\\ \;\;\;\;y \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(x \cdot \frac{0.5}{y}\right)\\ \end{array} \]
Alternative 12
Accuracy57.9%
Cost192.00
\[y \cdot 0.5 \]

Error

Reproduce?

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