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

Error

Target

Original2.0
Target0.3
Herbie2.6
\[\begin{array}{l} \mathbf{if}\;z < -11820553527347888000:\\ \;\;\;\;z \cdot \left(b \cdot a + y\right) + \left(x + t \cdot a\right)\\ \mathbf{elif}\;z < 4.7589743188364287 \cdot 10^{-122}:\\ \;\;\;\;\left(b \cdot z + t\right) \cdot a + \left(z \cdot y + x\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(b \cdot a + y\right) + \left(x + t \cdot a\right)\\ \end{array} \]

Derivation

  1. Initial program 2.0

    \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
  2. Simplified2.6

    \[\leadsto \color{blue}{\mathsf{fma}\left(a, t + z \cdot b, \mathsf{fma}\left(y, z, x\right)\right)} \]
    Proof
    (fma.f64 a (+.f64 t (*.f64 z b)) (fma.f64 y z x)): 0 points increase in error, 0 points decrease in error
    (fma.f64 a (+.f64 t (*.f64 z b)) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y z) x))): 0 points increase in error, 0 points decrease in error
    (fma.f64 a (+.f64 t (*.f64 z b)) (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 y z)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 a (+.f64 t (*.f64 z b))) (+.f64 x (*.f64 y z)))): 5 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 a t) (*.f64 a (*.f64 z b)))) (+.f64 x (*.f64 y z))): 0 points increase in error, 5 points decrease in error
    (+.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 t a)) (*.f64 a (*.f64 z b))) (+.f64 x (*.f64 y z))): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 t a) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a z) b))) (+.f64 x (*.f64 y z))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 (+.f64 x (*.f64 y z)) (+.f64 (*.f64 t a) (*.f64 (*.f64 a z) b)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b))): 0 points increase in error, 0 points decrease in error
  3. Final simplification2.6

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

Alternatives

Alternative 1
Error21.2
Cost1505
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := x + z \cdot y\\ t_3 := a \cdot \left(t + z \cdot b\right)\\ \mathbf{if}\;a \leq -7 \cdot 10^{+96}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq -4.5 \cdot 10^{+31}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -6.1 \cdot 10^{-58}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq 1.18 \cdot 10^{-142}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 2.8 \cdot 10^{-88}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 3.1 \cdot 10^{-6}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 5.4 \cdot 10^{+26} \lor \neg \left(a \leq 7.4 \cdot 10^{+50}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \end{array} \]
Alternative 2
Error21.6
Cost1504
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := x + z \cdot y\\ t_3 := a \cdot \left(t + z \cdot b\right)\\ \mathbf{if}\;a \leq -4.5 \cdot 10^{+97}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq -1.7 \cdot 10^{+31}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -6 \cdot 10^{-58}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq 1.18 \cdot 10^{-142}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 2.4 \cdot 10^{-88}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 3600000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 5.6 \cdot 10^{+20}:\\ \;\;\;\;z \cdot y + a \cdot t\\ \mathbf{elif}\;a \leq 1.3 \cdot 10^{+50}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error21.2
Cost1373
\[\begin{array}{l} t_1 := z \cdot \left(y + a \cdot b\right)\\ t_2 := x + a \cdot t\\ t_3 := x + z \cdot y\\ \mathbf{if}\;a \leq -7.6 \cdot 10^{+34}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -5.2 \cdot 10^{-6}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 5.4 \cdot 10^{-143}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq 2.5 \cdot 10^{-88}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 1.7 \cdot 10^{-6}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq 3.4 \cdot 10^{+29} \lor \neg \left(a \leq 1.35 \cdot 10^{+50}\right):\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error8.1
Cost969
\[\begin{array}{l} \mathbf{if}\;x \leq -4.8 \cdot 10^{-72} \lor \neg \left(x \leq 4.2 \cdot 10^{-76}\right):\\ \;\;\;\;z \cdot y + \left(x + a \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot t + z \cdot \left(y + a \cdot b\right)\\ \end{array} \]
Alternative 5
Error2.6
Cost960
\[\left(a \cdot \left(z \cdot b\right) + a \cdot t\right) + \left(x + z \cdot y\right) \]
Alternative 6
Error13.5
Cost841
\[\begin{array}{l} \mathbf{if}\;y \leq -1.26 \cdot 10^{+101} \lor \neg \left(y \leq 4 \cdot 10^{+18}\right):\\ \;\;\;\;x + z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x + a \cdot \left(t + z \cdot b\right)\\ \end{array} \]
Alternative 7
Error8.7
Cost841
\[\begin{array}{l} \mathbf{if}\;y \leq -6.2 \cdot 10^{+66} \lor \neg \left(y \leq 5 \cdot 10^{-24}\right):\\ \;\;\;\;z \cdot y + \left(x + a \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;x + a \cdot \left(t + z \cdot b\right)\\ \end{array} \]
Alternative 8
Error33.8
Cost588
\[\begin{array}{l} \mathbf{if}\;x \leq -1.9 \cdot 10^{-36}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 9 \cdot 10^{-308}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{+71}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error19.9
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -6.2 \cdot 10^{+20} \lor \neg \left(y \leq 5.5 \cdot 10^{-20}\right):\\ \;\;\;\;x + z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x + a \cdot t\\ \end{array} \]
Alternative 10
Error25.9
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -7 \cdot 10^{+143}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;y \leq 1.3 \cdot 10^{+33}:\\ \;\;\;\;x + a \cdot t\\ \mathbf{else}:\\ \;\;\;\;z \cdot y\\ \end{array} \]
Alternative 11
Error33.3
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.45 \cdot 10^{-36}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.6 \cdot 10^{-68}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error39.7
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022340 
(FPCore (x y z t a b)
  :name "Graphics.Rasterific.CubicBezier:cachedBezierAt from Rasterific-0.6.1"
  :precision binary64

  :herbie-target
  (if (< z -11820553527347888000.0) (+ (* z (+ (* b a) y)) (+ x (* t a))) (if (< z 4.7589743188364287e-122) (+ (* (+ (* b z) t) a) (+ (* z y) x)) (+ (* z (+ (* b a) y)) (+ x (* t a)))))

  (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)))