?

Average Error: 1.7 → 0.3
Time: 8.9s
Precision: binary64
Cost: 6980

?

\[\left(\left(\left(\left(0 \leq x \land x \leq 1.79 \cdot 10^{+308}\right) \land \left(0 \leq y \land y \leq 1.79 \cdot 10^{+308}\right)\right) \land \left(-1 \leq a \land a \leq 1\right)\right) \land \left(-1.79 \cdot 10^{+308} \leq b \land b \leq 1.79 \cdot 10^{+308}\right)\right) \land \left(-1.79 \cdot 10^{+308} \leq c \land c \leq 1.79 \cdot 10^{+308}\right)\]
\[ \begin{array}{c}[a, b, c] = \mathsf{sort}([a, b, c])\\ \end{array} \]
\[\left(x + y\right) + \left(a \cdot b\right) \cdot c \]
\[\begin{array}{l} \mathbf{if}\;b \leq 10^{-21}:\\ \;\;\;\;\mathsf{fma}\left(a, b \cdot c, x + y\right)\\ \mathbf{else}:\\ \;\;\;\;y + \mathsf{fma}\left(b, a \cdot c, x\right)\\ \end{array} \]
(FPCore (x y a b c) :precision binary64 (+ (+ x y) (* (* a b) c)))
(FPCore (x y a b c)
 :precision binary64
 (if (<= b 1e-21) (fma a (* b c) (+ x y)) (+ y (fma b (* a c) x))))
double code(double x, double y, double a, double b, double c) {
	return (x + y) + ((a * b) * c);
}
double code(double x, double y, double a, double b, double c) {
	double tmp;
	if (b <= 1e-21) {
		tmp = fma(a, (b * c), (x + y));
	} else {
		tmp = y + fma(b, (a * c), x);
	}
	return tmp;
}
function code(x, y, a, b, c)
	return Float64(Float64(x + y) + Float64(Float64(a * b) * c))
end
function code(x, y, a, b, c)
	tmp = 0.0
	if (b <= 1e-21)
		tmp = fma(a, Float64(b * c), Float64(x + y));
	else
		tmp = Float64(y + fma(b, Float64(a * c), x));
	end
	return tmp
end
code[x_, y_, a_, b_, c_] := N[(N[(x + y), $MachinePrecision] + N[(N[(a * b), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]
code[x_, y_, a_, b_, c_] := If[LessEqual[b, 1e-21], N[(a * N[(b * c), $MachinePrecision] + N[(x + y), $MachinePrecision]), $MachinePrecision], N[(y + N[(b * N[(a * c), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]]
\left(x + y\right) + \left(a \cdot b\right) \cdot c
\begin{array}{l}
\mathbf{if}\;b \leq 10^{-21}:\\
\;\;\;\;\mathsf{fma}\left(a, b \cdot c, x + y\right)\\

\mathbf{else}:\\
\;\;\;\;y + \mathsf{fma}\left(b, a \cdot c, x\right)\\


\end{array}

Error?

Derivation?

  1. Split input into 2 regimes
  2. if b < 9.99999999999999908e-22

    1. Initial program 1.9

      \[\left(x + y\right) + \left(a \cdot b\right) \cdot c \]
    2. Simplified0.3

      \[\leadsto \color{blue}{\mathsf{fma}\left(a, b \cdot c, x + y\right)} \]
      Proof

      [Start]1.9

      \[ \left(x + y\right) + \left(a \cdot b\right) \cdot c \]

      +-commutative [=>]1.9

      \[ \color{blue}{\left(a \cdot b\right) \cdot c + \left(x + y\right)} \]

      associate-*l* [=>]0.3

      \[ \color{blue}{a \cdot \left(b \cdot c\right)} + \left(x + y\right) \]

      fma-def [=>]0.3

      \[ \color{blue}{\mathsf{fma}\left(a, b \cdot c, x + y\right)} \]

    if 9.99999999999999908e-22 < b

    1. Initial program 0.1

      \[\left(x + y\right) + \left(a \cdot b\right) \cdot c \]
    2. Simplified0.3

      \[\leadsto \color{blue}{y + \mathsf{fma}\left(b, a \cdot c, x\right)} \]
      Proof

      [Start]0.1

      \[ \left(x + y\right) + \left(a \cdot b\right) \cdot c \]

      +-commutative [=>]0.1

      \[ \color{blue}{\left(a \cdot b\right) \cdot c + \left(x + y\right)} \]

      associate-+r+ [=>]0.1

      \[ \color{blue}{\left(\left(a \cdot b\right) \cdot c + x\right) + y} \]

      +-commutative [=>]0.1

      \[ \color{blue}{y + \left(\left(a \cdot b\right) \cdot c + x\right)} \]

      *-commutative [=>]0.1

      \[ y + \left(\color{blue}{c \cdot \left(a \cdot b\right)} + x\right) \]

      associate-*r* [=>]0.3

      \[ y + \left(\color{blue}{\left(c \cdot a\right) \cdot b} + x\right) \]

      *-commutative [=>]0.3

      \[ y + \left(\color{blue}{b \cdot \left(c \cdot a\right)} + x\right) \]

      fma-def [=>]0.3

      \[ y + \color{blue}{\mathsf{fma}\left(b, c \cdot a, x\right)} \]

      *-commutative [=>]0.3

      \[ y + \mathsf{fma}\left(b, \color{blue}{a \cdot c}, x\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq 10^{-21}:\\ \;\;\;\;\mathsf{fma}\left(a, b \cdot c, x + y\right)\\ \mathbf{else}:\\ \;\;\;\;y + \mathsf{fma}\left(b, a \cdot c, x\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.3
Cost6980
\[\begin{array}{l} \mathbf{if}\;b \leq 5 \cdot 10^{-21}:\\ \;\;\;\;\left(x + y\right) + a \cdot \left(b \cdot c\right)\\ \mathbf{else}:\\ \;\;\;\;y + \mathsf{fma}\left(b, a \cdot c, x\right)\\ \end{array} \]
Alternative 2
Error0.8
Cost708
\[\begin{array}{l} \mathbf{if}\;b \leq 2.15 \cdot 10^{+48}:\\ \;\;\;\;\left(x + y\right) + a \cdot \left(b \cdot c\right)\\ \mathbf{else}:\\ \;\;\;\;y + c \cdot \left(b \cdot a\right)\\ \end{array} \]
Alternative 3
Error12.1
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 1200000000:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(b \cdot c\right)\\ \end{array} \]
Alternative 4
Error11.3
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 0.14:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(a \cdot c\right)\\ \end{array} \]
Alternative 5
Error26.9
Cost448
\[y + c \cdot \left(b \cdot a\right) \]
Alternative 6
Error11.1
Cost192
\[x + y \]
Alternative 7
Error37.0
Cost64
\[x \]
Alternative 8
Error36.2
Cost64
\[y \]

Error

Reproduce?

herbie shell --seed 1 
(FPCore (x y a b c)
  :name "x + y + a * b * c"
  :precision binary64
  :pre (and (and (and (and (and (<= 0.0 x) (<= x 1.79e+308)) (and (<= 0.0 y) (<= y 1.79e+308))) (and (<= -1.0 a) (<= a 1.0))) (and (<= -1.79e+308 b) (<= b 1.79e+308))) (and (<= -1.79e+308 c) (<= c 1.79e+308)))
  (+ (+ x y) (* (* a b) c)))