Average Error: 0.0 → 0.2
Time: 2.7s
Precision: binary64
\[\left(5 \leq a \land a \leq 10\right) \land \left(0 \leq b \land b \leq 0.001\right)\]
\[[a, b] = \mathsf{sort}([a, b]) \\]
\[\left(a + b\right) \cdot \left(a + b\right) \]
\[\mathsf{fma}\left(2, a \cdot b, b \cdot b\right) \]
(FPCore (a b) :precision binary64 (* (+ a b) (+ a b)))
(FPCore (a b) :precision binary64 (fma 2.0 (* a b) (* b b)))
double code(double a, double b) {
	return (a + b) * (a + b);
}
double code(double a, double b) {
	return fma(2.0, (a * b), (b * b));
}
function code(a, b)
	return Float64(Float64(a + b) * Float64(a + b))
end
function code(a, b)
	return fma(2.0, Float64(a * b), Float64(b * b))
end
code[a_, b_] := N[(N[(a + b), $MachinePrecision] * N[(a + b), $MachinePrecision]), $MachinePrecision]
code[a_, b_] := N[(2.0 * N[(a * b), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]
\left(a + b\right) \cdot \left(a + b\right)
\mathsf{fma}\left(2, a \cdot b, b \cdot b\right)

Error

Bits error versus a

Bits error versus b

Target

Original0.0
Target0.0
Herbie0.2
\[\left(\left(b \cdot a + b \cdot b\right) + b \cdot a\right) + a \cdot a \]

Derivation

  1. Initial program 0.0

    \[\left(a + b\right) \cdot \left(a + b\right) \]
  2. Taylor expanded in a around 0 0.2

    \[\leadsto \color{blue}{2 \cdot \left(a \cdot b\right) + {b}^{2}} \]
  3. Applied add-log-exp_binary640.2

    \[\leadsto 2 \cdot \left(a \cdot b\right) + \color{blue}{\log \left(e^{{b}^{2}}\right)} \]
  4. Applied add-log-exp_binary640.2

    \[\leadsto \color{blue}{\log \left(e^{2 \cdot \left(a \cdot b\right)}\right)} + \log \left(e^{{b}^{2}}\right) \]
  5. Applied sum-log_binary640.2

    \[\leadsto \color{blue}{\log \left(e^{2 \cdot \left(a \cdot b\right)} \cdot e^{{b}^{2}}\right)} \]
  6. Simplified0.2

    \[\leadsto \log \color{blue}{\left({\left(e^{b}\right)}^{\left(\mathsf{fma}\left(2, a, b\right)\right)}\right)} \]
  7. Taylor expanded in b around inf 0.2

    \[\leadsto \color{blue}{b \cdot \mathsf{fma}\left(2, a, b\right)} \]
  8. Simplified0.2

    \[\leadsto \color{blue}{\mathsf{fma}\left(2, a \cdot b, b \cdot b\right)} \]
  9. Final simplification0.2

    \[\leadsto \mathsf{fma}\left(2, a \cdot b, b \cdot b\right) \]

Reproduce

herbie shell --seed 2022129 
(FPCore (a b)
  :name "Expression 4, p15"
  :precision binary64
  :pre (and (and (<= 5.0 a) (<= a 10.0)) (and (<= 0.0 b) (<= b 0.001)))

  :herbie-target
  (+ (+ (+ (* b a) (* b b)) (* b a)) (* a a))

  (* (+ a b) (+ a b)))