?

Average Error: 0.02% → 0.01%
Time: 6.2s
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.02

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

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

    [Start]0.02

    \[ \left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673 \]

    sub-neg [=>]0.02

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

    +-commutative [=>]0.02

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

    sub-neg [=>]0.02

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

    distribute-lft-in [=>]0.02

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

    *-commutative [<=]0.02

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

    associate-+r+ [=>]0.02

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

    associate-+l+ [=>]0.02

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

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

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

    distribute-lft-out [=>]0.02

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

    fma-def [=>]0.01

    \[ \color{blue}{\mathsf{fma}\left(y, \left(-0.5\right) + x, x \cdot \left(-1\right) + 0.918938533204673\right)} \]

    +-commutative [=>]0.01

    \[ \mathsf{fma}\left(y, \color{blue}{x + \left(-0.5\right)}, x \cdot \left(-1\right) + 0.918938533204673\right) \]

    metadata-eval [=>]0.01

    \[ \mathsf{fma}\left(y, x + \color{blue}{-0.5}, x \cdot \left(-1\right) + 0.918938533204673\right) \]

    +-commutative [<=]0.01

    \[ \mathsf{fma}\left(y, x + -0.5, \color{blue}{0.918938533204673 + x \cdot \left(-1\right)}\right) \]

    *-commutative [=>]0.01

    \[ \mathsf{fma}\left(y, x + -0.5, 0.918938533204673 + \color{blue}{\left(-1\right) \cdot x}\right) \]

    metadata-eval [=>]0.01

    \[ \mathsf{fma}\left(y, x + -0.5, 0.918938533204673 + \color{blue}{-1} \cdot x\right) \]

    mul-1-neg [=>]0.01

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

    unsub-neg [=>]0.01

    \[ \mathsf{fma}\left(y, x + -0.5, \color{blue}{0.918938533204673 - x}\right) \]
  3. Final simplification0.01

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

Alternatives

Alternative 1
Error46.75%
Cost1512
\[\begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{+75}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;y \leq -4.1 \cdot 10^{+52}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -1.8 \cdot 10^{+40}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;y \leq -1:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -1.25 \cdot 10^{-107}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq -1.8 \cdot 10^{-190}:\\ \;\;\;\;0.918938533204673\\ \mathbf{elif}\;y \leq 2.35 \cdot 10^{-215}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq 2.4 \cdot 10^{-108}:\\ \;\;\;\;0.918938533204673\\ \mathbf{elif}\;y \leq 1.6 \cdot 10^{-20}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{+147}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot -0.5\\ \end{array} \]
Alternative 2
Error43.35%
Cost1052
\[\begin{array}{l} \mathbf{if}\;x \leq -0.0205:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq -1.85 \cdot 10^{-215}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;x \leq -5.1 \cdot 10^{-253}:\\ \;\;\;\;0.918938533204673\\ \mathbf{elif}\;x \leq 4.7 \cdot 10^{-262}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{-165}:\\ \;\;\;\;0.918938533204673\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{-58}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;x \leq 270:\\ \;\;\;\;0.918938533204673\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]
Alternative 3
Error18.61%
Cost984
\[\begin{array}{l} \mathbf{if}\;y \leq -4.6 \cdot 10^{+75}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;y \leq -3.3 \cdot 10^{+52}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -1.9 \cdot 10^{+40}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;y \leq -60:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 1.05:\\ \;\;\;\;0.918938533204673 - x\\ \mathbf{elif}\;y \leq 1.75 \cdot 10^{+148}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot -0.5\\ \end{array} \]
Alternative 4
Error2.42%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -1.4 \lor \neg \left(y \leq 1\right):\\ \;\;\;\;y \cdot \left(x + -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;0.918938533204673 - x\\ \end{array} \]
Alternative 5
Error2.55%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -0.72 \lor \neg \left(x \leq 0.62\right):\\ \;\;\;\;x \cdot \left(y + -1\right)\\ \mathbf{else}:\\ \;\;\;\;0.918938533204673 + y \cdot -0.5\\ \end{array} \]
Alternative 6
Error2.55%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -0.72:\\ \;\;\;\;y \cdot x - x\\ \mathbf{elif}\;x \leq 0.88:\\ \;\;\;\;0.918938533204673 + y \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(y + -1\right)\\ \end{array} \]
Alternative 7
Error0.01%
Cost576
\[\left(0.918938533204673 + y \cdot \left(x + -0.5\right)\right) - x \]
Alternative 8
Error43.52%
Cost392
\[\begin{array}{l} \mathbf{if}\;x \leq -7.8 \cdot 10^{-13}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq 270:\\ \;\;\;\;0.918938533204673\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]
Alternative 9
Error69.94%
Cost64
\[0.918938533204673 \]

Error

Reproduce?

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