?

Average Accuracy: 99.8% → 99.9%
Time: 14.0s
Precision: binary64
Cost: 13376

?

\[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
\[\mathsf{fma}\left(\log y, -0.5 - y, y + \left(x - z\right)\right) \]
(FPCore (x y z) :precision binary64 (- (+ (- x (* (+ y 0.5) (log y))) y) z))
(FPCore (x y z) :precision binary64 (fma (log y) (- -0.5 y) (+ y (- x z))))
double code(double x, double y, double z) {
	return ((x - ((y + 0.5) * log(y))) + y) - z;
}
double code(double x, double y, double z) {
	return fma(log(y), (-0.5 - y), (y + (x - z)));
}
function code(x, y, z)
	return Float64(Float64(Float64(x - Float64(Float64(y + 0.5) * log(y))) + y) - z)
end
function code(x, y, z)
	return fma(log(y), Float64(-0.5 - y), Float64(y + Float64(x - z)))
end
code[x_, y_, z_] := N[(N[(N[(x - N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision]
code[x_, y_, z_] := N[(N[Log[y], $MachinePrecision] * N[(-0.5 - y), $MachinePrecision] + N[(y + N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z
\mathsf{fma}\left(\log y, -0.5 - y, y + \left(x - z\right)\right)

Error?

Target

Original99.8%
Target99.8%
Herbie99.9%
\[\left(\left(y + x\right) - z\right) - \left(y + 0.5\right) \cdot \log y \]

Derivation?

  1. Initial program 99.8%

    \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
  2. Simplified99.9%

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

    [Start]99.8

    \[ \left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]

    associate--l+ [=>]99.8

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

    sub-neg [=>]99.8

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

    +-commutative [=>]99.8

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

    associate-+l+ [=>]99.8

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

    *-commutative [=>]99.8

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

    distribute-rgt-neg-in [=>]99.8

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

    fma-def [=>]99.9

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

    neg-sub0 [=>]99.9

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

    +-commutative [=>]99.9

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

    associate--r+ [=>]99.9

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

    metadata-eval [=>]99.9

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

    associate-+r- [=>]99.9

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

    +-commutative [<=]99.9

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

    associate-+r- [<=]99.9

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

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

Alternatives

Alternative 1
Accuracy75.2%
Cost7772
\[\begin{array}{l} t_0 := y - \log y \cdot \left(y + 0.5\right)\\ t_1 := y \cdot \left(1 - \log y\right)\\ t_2 := x + t_1\\ t_3 := t_1 - z\\ \mathbf{if}\;x \leq -100:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{-77}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.65 \cdot 10^{-247}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -1.02 \cdot 10^{-281}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 20500000000000:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{+130}:\\ \;\;\;\;x - z\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{+225}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x - z\\ \end{array} \]
Alternative 2
Accuracy75.1%
Cost7244
\[\begin{array}{l} \mathbf{if}\;y \leq 7.6 \cdot 10^{-255}:\\ \;\;\;\;x - z\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{-163}:\\ \;\;\;\;\log y \cdot -0.5 - z\\ \mathbf{elif}\;y \leq 7.4 \cdot 10^{+19}:\\ \;\;\;\;x - z\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(1 - \log y\right)\\ \end{array} \]
Alternative 3
Accuracy89.4%
Cost7244
\[\begin{array}{l} t_0 := y \cdot \left(1 - \log y\right)\\ \mathbf{if}\;y \leq 7.5 \cdot 10^{+20}:\\ \;\;\;\;\left(x + \log y \cdot -0.5\right) - z\\ \mathbf{elif}\;y \leq 1.75 \cdot 10^{+145}:\\ \;\;\;\;\left(y + x\right) - y \cdot \log y\\ \mathbf{elif}\;y \leq 9.5 \cdot 10^{+193}:\\ \;\;\;\;t_0 - z\\ \mathbf{else}:\\ \;\;\;\;x + t_0\\ \end{array} \]
Alternative 4
Accuracy98.3%
Cost7241
\[\begin{array}{l} \mathbf{if}\;z \leq -3.5 \cdot 10^{+22} \lor \neg \left(z \leq 7 \cdot 10^{-45}\right):\\ \;\;\;\;\left(y - z\right) + \left(x - y \cdot \log y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y + x\right) - \log y \cdot \left(y + 0.5\right)\\ \end{array} \]
Alternative 5
Accuracy70.9%
Cost7116
\[\begin{array}{l} \mathbf{if}\;y \leq 6.2 \cdot 10^{-184}:\\ \;\;\;\;x - z\\ \mathbf{elif}\;y \leq 5.2 \cdot 10^{-163}:\\ \;\;\;\;x - \log y \cdot 0.5\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{+126}:\\ \;\;\;\;x - z\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(1 - \log y\right)\\ \end{array} \]
Alternative 6
Accuracy69.5%
Cost7116
\[\begin{array}{l} \mathbf{if}\;y \leq 4.9 \cdot 10^{-255}:\\ \;\;\;\;x - z\\ \mathbf{elif}\;y \leq 2.65 \cdot 10^{-164}:\\ \;\;\;\;\log y \cdot -0.5 - z\\ \mathbf{elif}\;y \leq 3.4 \cdot 10^{+124}:\\ \;\;\;\;x - z\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(1 - \log y\right)\\ \end{array} \]
Alternative 7
Accuracy99.2%
Cost7108
\[\begin{array}{l} \mathbf{if}\;y \leq 5.5 \cdot 10^{-5}:\\ \;\;\;\;\left(x + \log y \cdot -0.5\right) - z\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) + \left(x - y \cdot \log y\right)\\ \end{array} \]
Alternative 8
Accuracy99.8%
Cost7104
\[\left(x - \log y \cdot \left(y + 0.5\right)\right) + \left(y - z\right) \]
Alternative 9
Accuracy71.0%
Cost6852
\[\begin{array}{l} \mathbf{if}\;y \leq 1.05 \cdot 10^{+125}:\\ \;\;\;\;x - z\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(1 - \log y\right)\\ \end{array} \]
Alternative 10
Accuracy49.1%
Cost392
\[\begin{array}{l} \mathbf{if}\;x \leq -1.35 \cdot 10^{+49}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{+71}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Accuracy58.3%
Cost192
\[x - z \]
Alternative 12
Accuracy30.2%
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023151 
(FPCore (x y z)
  :name "Numeric.SpecFunctions:stirlingError from math-functions-0.1.5.2"
  :precision binary64

  :herbie-target
  (- (- (+ y x) z) (* (+ y 0.5) (log y)))

  (- (+ (- x (* (+ y 0.5) (log y))) y) z))