Average Error: 0.0 → 0.0
Time: 8.4s
Precision: binary64
Cost: 6848
\[\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]
\[\mathsf{fma}\left(y, x + -0.5, 0.918938533204673 - x\right) \]
(FPCore (x y)
 :precision binary64
 (+ (- (* x (- y 1.0)) (* y 0.5)) 0.918938533204673))
(FPCore (x y) :precision binary64 (fma y (+ x -0.5) (- 0.918938533204673 x)))
double code(double x, double y) {
	return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
double code(double x, double y) {
	return fma(y, (x + -0.5), (0.918938533204673 - x));
}
function code(x, y)
	return Float64(Float64(Float64(x * Float64(y - 1.0)) - Float64(y * 0.5)) + 0.918938533204673)
end
function code(x, y)
	return fma(y, Float64(x + -0.5), Float64(0.918938533204673 - x))
end
code[x_, y_] := N[(N[(N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision] - N[(y * 0.5), $MachinePrecision]), $MachinePrecision] + 0.918938533204673), $MachinePrecision]
code[x_, y_] := N[(y * N[(x + -0.5), $MachinePrecision] + N[(0.918938533204673 - x), $MachinePrecision]), $MachinePrecision]
\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673
\mathsf{fma}\left(y, x + -0.5, 0.918938533204673 - x\right)

Error

Derivation

  1. Initial program 0.0

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

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

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

Alternatives

Alternative 1
Error27.8
Cost1116
\[\begin{array}{l} \mathbf{if}\;x \leq -7.6 \cdot 10^{+63}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq -1.45 \cdot 10^{+44}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq -0.92:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq -3.7 \cdot 10^{-153}:\\ \;\;\;\;0.918938533204673\\ \mathbf{elif}\;x \leq -1.62 \cdot 10^{-186}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;x \leq 1.15 \cdot 10^{-219}:\\ \;\;\;\;0.918938533204673\\ \mathbf{elif}\;x \leq 0.88:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]
Alternative 2
Error27.7
Cost852
\[\begin{array}{l} \mathbf{if}\;x \leq -0.92:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq -5.9 \cdot 10^{-154}:\\ \;\;\;\;0.918938533204673\\ \mathbf{elif}\;x \leq -1 \cdot 10^{-188}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;x \leq 1.26 \cdot 10^{-219}:\\ \;\;\;\;0.918938533204673\\ \mathbf{elif}\;x \leq 0.9:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]
Alternative 3
Error1.8
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -6.5 \cdot 10^{+41}:\\ \;\;\;\;x \cdot \left(y + -1\right)\\ \mathbf{elif}\;x \leq 1750000:\\ \;\;\;\;\left(0.918938533204673 - x\right) + y \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;y \cdot x - x\\ \end{array} \]
Alternative 4
Error1.6
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -6.5 \cdot 10^{+41}:\\ \;\;\;\;x \cdot \left(y + -1\right)\\ \mathbf{elif}\;x \leq 2.15 \cdot 10^{-6}:\\ \;\;\;\;\left(0.918938533204673 - x\right) + y \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;\left(0.918938533204673 - x\right) + y \cdot x\\ \end{array} \]
Alternative 5
Error1.6
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -6.5 \cdot 10^{+41}:\\ \;\;\;\;x \cdot \left(y + -1\right)\\ \mathbf{elif}\;x \leq 2.15 \cdot 10^{-6}:\\ \;\;\;\;\left(0.918938533204673 + y \cdot -0.5\right) - x\\ \mathbf{else}:\\ \;\;\;\;\left(0.918938533204673 - x\right) + y \cdot x\\ \end{array} \]
Alternative 6
Error1.5
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -1.3 \lor \neg \left(y \leq 1\right):\\ \;\;\;\;y \cdot \left(x + -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;0.918938533204673 - x\\ \end{array} \]
Alternative 7
Error1.5
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -0.72 \lor \neg \left(x \leq 0.85\right):\\ \;\;\;\;x \cdot \left(y + -1\right)\\ \mathbf{else}:\\ \;\;\;\;0.918938533204673 + y \cdot -0.5\\ \end{array} \]
Alternative 8
Error1.5
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -0.68:\\ \;\;\;\;x \cdot \left(y + -1\right)\\ \mathbf{elif}\;x \leq 0.9:\\ \;\;\;\;0.918938533204673 + y \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;y \cdot x - x\\ \end{array} \]
Alternative 9
Error0.0
Cost576
\[\left(0.918938533204673 - x\right) + y \cdot \left(x + -0.5\right) \]
Alternative 10
Error10.8
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -4.6 \cdot 10^{+27}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;y \leq 1.82:\\ \;\;\;\;0.918938533204673 - x\\ \mathbf{else}:\\ \;\;\;\;y \cdot -0.5\\ \end{array} \]
Alternative 11
Error28.4
Cost392
\[\begin{array}{l} \mathbf{if}\;x \leq -0.92:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq 1850000:\\ \;\;\;\;0.918938533204673\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]
Alternative 12
Error45.2
Cost64
\[0.918938533204673 \]

Error

Reproduce

herbie shell --seed 2022343 
(FPCore (x y)
  :name "Numeric.SpecFunctions:logGamma from math-functions-0.1.5.2, A"
  :precision binary64
  (+ (- (* x (- y 1.0)) (* y 0.5)) 0.918938533204673))