Average Error: 0.0 → 0.0
Time: 5.9s
Precision: binary64
Cost: 13248
\[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
\[\mathsf{fma}\left(a, b, \mathsf{fma}\left(t, z, y \cdot x\right)\right) \]
(FPCore (x y z t a b) :precision binary64 (+ (+ (* x y) (* z t)) (* a b)))
(FPCore (x y z t a b) :precision binary64 (fma a b (fma t z (* y x))))
double code(double x, double y, double z, double t, double a, double b) {
	return ((x * y) + (z * t)) + (a * b);
}
double code(double x, double y, double z, double t, double a, double b) {
	return fma(a, b, fma(t, z, (y * x)));
}
function code(x, y, z, t, a, b)
	return Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(a * b))
end
function code(x, y, z, t, a, b)
	return fma(a, b, fma(t, z, Float64(y * x)))
end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := N[(a * b + N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(x \cdot y + z \cdot t\right) + a \cdot b
\mathsf{fma}\left(a, b, \mathsf{fma}\left(t, z, y \cdot x\right)\right)

Error

Derivation

  1. Initial program 0.0

    \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
  2. Taylor expanded in x around 0 0.0

    \[\leadsto \color{blue}{a \cdot b + \left(y \cdot x + t \cdot z\right)} \]
  3. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(a, b, \mathsf{fma}\left(t, z, y \cdot x\right)\right)} \]
    Proof
    (fma.f64 a b (fma.f64 t z (*.f64 y x))): 0 points increase in error, 0 points decrease in error
    (fma.f64 a b (fma.f64 t z (Rewrite=> *-commutative_binary64 (*.f64 x y)))): 0 points increase in error, 0 points decrease in error
    (fma.f64 a b (Rewrite=> fma-udef_binary64 (+.f64 (*.f64 t z) (*.f64 x y)))): 0 points increase in error, 0 points decrease in error
    (fma.f64 a b (+.f64 (*.f64 t z) (Rewrite<= *-commutative_binary64 (*.f64 y x)))): 0 points increase in error, 0 points decrease in error
    (fma.f64 a b (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 y x) (*.f64 t z)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 a b) (+.f64 (*.f64 y x) (*.f64 t z)))): 0 points increase in error, 0 points decrease in error
  4. Final simplification0.0

    \[\leadsto \mathsf{fma}\left(a, b, \mathsf{fma}\left(t, z, y \cdot x\right)\right) \]

Alternatives

Alternative 1
Error22.6
Cost1242
\[\begin{array}{l} \mathbf{if}\;y \leq -6.6 \cdot 10^{-69}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 2 \cdot 10^{+58} \lor \neg \left(y \leq 3.5 \cdot 10^{+99}\right) \land \left(y \leq 3.1 \cdot 10^{+172} \lor \neg \left(y \leq 1.45 \cdot 10^{+255}\right) \land y \leq 6.7 \cdot 10^{+292}\right):\\ \;\;\;\;a \cdot b + t \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 2
Error16.5
Cost1241
\[\begin{array}{l} t_1 := a \cdot b + t \cdot z\\ t_2 := y \cdot x + a \cdot b\\ \mathbf{if}\;x \leq -0.25:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -2.1 \cdot 10^{-41}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.05 \cdot 10^{-63}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq -7.8 \cdot 10^{-118} \lor \neg \left(x \leq -1.5 \cdot 10^{-210}\right) \land x \leq 2 \cdot 10^{-134}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error29.9
Cost1232
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -0.00012:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 3.4 \cdot 10^{-271}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;a \cdot b \leq 5.8 \cdot 10^{-183}:\\ \;\;\;\;t \cdot z\\ \mathbf{elif}\;a \cdot b \leq 5.6 \cdot 10^{+43}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
Alternative 4
Error11.6
Cost969
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -1.4 \cdot 10^{-114} \lor \neg \left(a \cdot b \leq 2.25 \cdot 10^{-175}\right):\\ \;\;\;\;y \cdot x + a \cdot b\\ \mathbf{else}:\\ \;\;\;\;y \cdot x + t \cdot z\\ \end{array} \]
Alternative 5
Error32.9
Cost712
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -1.95 \cdot 10^{-114}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 2.25 \cdot 10^{-175}:\\ \;\;\;\;t \cdot z\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
Alternative 6
Error0.0
Cost704
\[a \cdot b + \left(y \cdot x + t \cdot z\right) \]
Alternative 7
Error41.9
Cost192
\[a \cdot b \]

Error

Reproduce

herbie shell --seed 2022343 
(FPCore (x y z t a b)
  :name "Linear.V3:$cdot from linear-1.19.1.3, B"
  :precision binary64
  (+ (+ (* x y) (* z t)) (* a b)))