Average Error: 0.1 → 0.1
Time: 10.0s
Precision: binary64
Cost: 13376
\[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
\[x + \mathsf{fma}\left(\log y, -0.5 - y, y - z\right) \]
(FPCore (x y z) :precision binary64 (- (+ (- x (* (+ y 0.5) (log y))) y) z))
(FPCore (x y z) :precision binary64 (+ x (fma (log y) (- -0.5 y) (- y 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 x + fma(log(y), (-0.5 - y), (y - 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 Float64(x + fma(log(y), Float64(-0.5 - y), Float64(y - 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[(x + N[(N[Log[y], $MachinePrecision] * N[(-0.5 - y), $MachinePrecision] + N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z
x + \mathsf{fma}\left(\log y, -0.5 - y, y - z\right)

Error

Target

Original0.1
Target0.1
Herbie0.1
\[\left(\left(y + x\right) - z\right) - \left(y + 0.5\right) \cdot \log y \]

Derivation

  1. Initial program 0.1

    \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
  2. Simplified0.1

    \[\leadsto \color{blue}{x + \mathsf{fma}\left(\log y, -0.5 - y, y - z\right)} \]
    Proof
    (+.f64 x (fma.f64 (log.f64 y) (-.f64 -1/2 y) (-.f64 y z))): 0 points increase in error, 0 points decrease in error
    (+.f64 x (fma.f64 (log.f64 y) (-.f64 (Rewrite<= metadata-eval (neg.f64 1/2)) y) (-.f64 y z))): 0 points increase in error, 0 points decrease in error
    (+.f64 x (fma.f64 (log.f64 y) (Rewrite<= unsub-neg_binary64 (+.f64 (neg.f64 1/2) (neg.f64 y))) (-.f64 y z))): 0 points increase in error, 0 points decrease in error
    (+.f64 x (fma.f64 (log.f64 y) (Rewrite<= distribute-neg-in_binary64 (neg.f64 (+.f64 1/2 y))) (-.f64 y z))): 0 points increase in error, 0 points decrease in error
    (+.f64 x (fma.f64 (log.f64 y) (neg.f64 (Rewrite<= +-commutative_binary64 (+.f64 y 1/2))) (-.f64 y z))): 0 points increase in error, 0 points decrease in error
    (+.f64 x (fma.f64 (log.f64 y) (neg.f64 (+.f64 y 1/2)) (Rewrite<= remove-double-neg_binary64 (neg.f64 (neg.f64 (-.f64 y z)))))): 0 points increase in error, 0 points decrease in error
    (+.f64 x (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (log.f64 y) (neg.f64 (+.f64 y 1/2))) (neg.f64 (neg.f64 (-.f64 y z)))))): 13 points increase in error, 2 points decrease in error
    (+.f64 x (+.f64 (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 (log.f64 y) (+.f64 y 1/2)))) (neg.f64 (neg.f64 (-.f64 y z))))): 0 points increase in error, 0 points decrease in error
    (+.f64 x (+.f64 (neg.f64 (Rewrite<= *-commutative_binary64 (*.f64 (+.f64 y 1/2) (log.f64 y)))) (neg.f64 (neg.f64 (-.f64 y z))))): 0 points increase in error, 0 points decrease in error
    (+.f64 x (Rewrite<= distribute-neg-in_binary64 (neg.f64 (+.f64 (*.f64 (+.f64 y 1/2) (log.f64 y)) (neg.f64 (-.f64 y z)))))): 0 points increase in error, 0 points decrease in error
    (+.f64 x (neg.f64 (Rewrite<= sub-neg_binary64 (-.f64 (*.f64 (+.f64 y 1/2) (log.f64 y)) (-.f64 y z))))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= sub-neg_binary64 (-.f64 x (-.f64 (*.f64 (+.f64 y 1/2) (log.f64 y)) (-.f64 y z)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 x (*.f64 (+.f64 y 1/2) (log.f64 y))) (-.f64 y z))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate--l+_binary64 (-.f64 (+.f64 (-.f64 x (*.f64 (+.f64 y 1/2) (log.f64 y))) y) z)): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.1

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

Alternatives

Alternative 1
Error6.9
Cost7504
\[\begin{array}{l} t_0 := 1 - \log y\\ t_1 := y \cdot t_0 - z\\ \mathbf{if}\;y \leq 5.6 \cdot 10^{+15}:\\ \;\;\;\;\left(x + \log y \cdot -0.5\right) - z\\ \mathbf{elif}\;y \leq 8.2 \cdot 10^{+93}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.9 \cdot 10^{+133}:\\ \;\;\;\;x + \left(y - y \cdot \log y\right)\\ \mathbf{elif}\;y \leq 7.8 \cdot 10^{+184}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{\frac{1}{t_0}}\\ \end{array} \]
Alternative 2
Error14.3
Cost7376
\[\begin{array}{l} t_0 := x + \left(y - y \cdot \log y\right)\\ t_1 := y \cdot \left(1 - \log y\right) - z\\ \mathbf{if}\;y \leq 7.5 \cdot 10^{+15}:\\ \;\;\;\;x - z\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{+94}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.6 \cdot 10^{+132}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 10^{+185}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error6.9
Cost7376
\[\begin{array}{l} t_0 := y \cdot \left(1 - \log y\right) - z\\ t_1 := x + \left(y - y \cdot \log y\right)\\ \mathbf{if}\;y \leq 1.6 \cdot 10^{+16}:\\ \;\;\;\;\left(x + \log y \cdot -0.5\right) - z\\ \mathbf{elif}\;y \leq 1.45 \cdot 10^{+94}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{+133}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 8.5 \cdot 10^{+184}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error18.9
Cost7116
\[\begin{array}{l} t_0 := y - y \cdot \log y\\ \mathbf{if}\;y \leq 3.5 \cdot 10^{+40}:\\ \;\;\;\;x - z\\ \mathbf{elif}\;y \leq 2.4 \cdot 10^{+61}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 5.2 \cdot 10^{+116}:\\ \;\;\;\;x - z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error14.2
Cost7112
\[\begin{array}{l} \mathbf{if}\;z \leq -1.4 \cdot 10^{+89}:\\ \;\;\;\;x - z\\ \mathbf{elif}\;z \leq 2.15 \cdot 10^{+52}:\\ \;\;\;\;x + \left(y - y \cdot \log y\right)\\ \mathbf{else}:\\ \;\;\;\;x - z\\ \end{array} \]
Alternative 6
Error0.4
Cost7108
\[\begin{array}{l} \mathbf{if}\;y \leq 0.082:\\ \;\;\;\;\left(x + \log y \cdot -0.5\right) - z\\ \mathbf{else}:\\ \;\;\;\;\left(\left(x + y\right) - y \cdot \log y\right) - z\\ \end{array} \]
Alternative 7
Error0.1
Cost7104
\[\left(y + \left(x + \log y \cdot \left(-0.5 - y\right)\right)\right) - z \]
Alternative 8
Error26.5
Cost192
\[x - z \]
Alternative 9
Error45.0
Cost64
\[x \]

Error

Reproduce

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