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

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. Taylor expanded in x around 0 0.1

    \[\leadsto \left(\color{blue}{\left(-1 \cdot \left(\left(0.5 + y\right) \cdot \log y\right) + x\right)} + y\right) - z \]
  3. Simplified0.1

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

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

Alternatives

Alternative 1
Error16.2
Cost7640
\[\begin{array}{l} t_0 := \log y \cdot -0.5\\ t_1 := y \cdot \left(1 - \log y\right) - z\\ \mathbf{if}\;y \leq 4.2463194822090056 \cdot 10^{-272}:\\ \;\;\;\;t_0 - z\\ \mathbf{elif}\;y \leq 3.8945163040762965 \cdot 10^{-225}:\\ \;\;\;\;x - z\\ \mathbf{elif}\;y \leq 1.2094996420823797 \cdot 10^{-182}:\\ \;\;\;\;x + t_0\\ \mathbf{elif}\;y \leq 2.2301578668171844 \cdot 10^{+47}:\\ \;\;\;\;x - z\\ \mathbf{elif}\;y \leq 9.535955973700263 \cdot 10^{+92}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 6.794568280821671 \cdot 10^{+121}:\\ \;\;\;\;x - z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error19.5
Cost7248
\[\begin{array}{l} t_0 := \log y \cdot -0.5\\ \mathbf{if}\;y \leq 4.2463194822090056 \cdot 10^{-272}:\\ \;\;\;\;t_0 - z\\ \mathbf{elif}\;y \leq 3.8945163040762965 \cdot 10^{-225}:\\ \;\;\;\;x - z\\ \mathbf{elif}\;y \leq 1.2094996420823797 \cdot 10^{-182}:\\ \;\;\;\;x + t_0\\ \mathbf{elif}\;y \leq 3.135040589641332 \cdot 10^{+143}:\\ \;\;\;\;x - z\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(1 - \log y\right)\\ \end{array} \]
Alternative 3
Error7.0
Cost7244
\[\begin{array}{l} t_0 := y \cdot \left(1 - \log y\right) - z\\ t_1 := \left(x + \log y \cdot -0.5\right) - z\\ \mathbf{if}\;y \leq 2.2301578668171844 \cdot 10^{+47}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 9.535955973700263 \cdot 10^{+92}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 6.794568280821671 \cdot 10^{+121}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error7.1
Cost7244
\[\begin{array}{l} t_0 := x + \left(y - y \cdot \log y\right)\\ t_1 := \left(x + \log y \cdot -0.5\right) - z\\ \mathbf{if}\;y \leq 2.1821376748430874 \cdot 10^{+48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7.079442789313001 \cdot 10^{+106}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.270005418956597 \cdot 10^{+137}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error0.7
Cost7240
\[\begin{array}{l} t_0 := \left(x + \left(y - z\right)\right) - y \cdot \log y\\ \mathbf{if}\;x \leq -1.286930576034816 \cdot 10^{+28}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.30948188756416667:\\ \;\;\;\;\left(y - \log y \cdot \left(y + 0.5\right)\right) - z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error0.5
Cost7108
\[\begin{array}{l} \mathbf{if}\;y \leq 0.00044878939966875306:\\ \;\;\;\;\left(x + \log y \cdot -0.5\right) - z\\ \mathbf{else}:\\ \;\;\;\;\left(x + \left(y - z\right)\right) - y \cdot \log y\\ \end{array} \]
Alternative 7
Error0.1
Cost7104
\[\left(x + \left(y - z\right)\right) + \log y \cdot \left(-0.5 - y\right) \]
Alternative 8
Error19.1
Cost6984
\[\begin{array}{l} \mathbf{if}\;y \leq 4.2463194822090056 \cdot 10^{-272}:\\ \;\;\;\;\log y \cdot -0.5 - z\\ \mathbf{elif}\;y \leq 3.135040589641332 \cdot 10^{+143}:\\ \;\;\;\;x - z\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(1 - \log y\right)\\ \end{array} \]
Alternative 9
Error18.5
Cost6852
\[\begin{array}{l} \mathbf{if}\;y \leq 3.135040589641332 \cdot 10^{+143}:\\ \;\;\;\;x - z\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(1 - \log y\right)\\ \end{array} \]
Alternative 10
Error33.1
Cost392
\[\begin{array}{l} \mathbf{if}\;z \leq -1.682250078111826 \cdot 10^{+69}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 3.6559387275368564 \cdot 10^{+82}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 11
Error33.1
Cost392
\[\begin{array}{l} \mathbf{if}\;z \leq -1.682250078111826 \cdot 10^{+69}:\\ \;\;\;\;y - z\\ \mathbf{elif}\;z \leq 3.6559387275368564 \cdot 10^{+82}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 12
Error26.6
Cost192
\[x - z \]
Alternative 13
Error44.8
Cost64
\[x \]

Error

Reproduce

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