Average Error: 2.1 → 0.1
Time: 12.5s
Precision: binary64
Cost: 19913
\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
\[\begin{array}{l} \mathbf{if}\;a \leq -5 \cdot 10^{-58} \lor \neg \left(a \leq 3 \cdot 10^{-12}\right):\\ \;\;\;\;\mathsf{fma}\left(a, t + z \cdot b, \mathsf{fma}\left(y, z, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), \mathsf{fma}\left(t, a, x\right)\right)\\ \end{array} \]
(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
 (if (or (<= a -5e-58) (not (<= a 3e-12)))
   (fma a (+ t (* z b)) (fma y z x))
   (fma z (fma a b y) (fma t a 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) {
	double tmp;
	if ((a <= -5e-58) || !(a <= 3e-12)) {
		tmp = fma(a, (t + (z * b)), fma(y, z, x));
	} else {
		tmp = fma(z, fma(a, b, y), fma(t, a, x));
	}
	return tmp;
}
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)
	tmp = 0.0
	if ((a <= -5e-58) || !(a <= 3e-12))
		tmp = fma(a, Float64(t + Float64(z * b)), fma(y, z, x));
	else
		tmp = fma(z, fma(a, b, y), fma(t, a, x));
	end
	return tmp
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_] := If[Or[LessEqual[a, -5e-58], N[Not[LessEqual[a, 3e-12]], $MachinePrecision]], N[(a * N[(t + N[(z * b), $MachinePrecision]), $MachinePrecision] + N[(y * z + x), $MachinePrecision]), $MachinePrecision], N[(z * N[(a * b + y), $MachinePrecision] + N[(t * a + x), $MachinePrecision]), $MachinePrecision]]
\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
\begin{array}{l}
\mathbf{if}\;a \leq -5 \cdot 10^{-58} \lor \neg \left(a \leq 3 \cdot 10^{-12}\right):\\
\;\;\;\;\mathsf{fma}\left(a, t + z \cdot b, \mathsf{fma}\left(y, z, x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), \mathsf{fma}\left(t, a, x\right)\right)\\


\end{array}

Error

Target

Original2.1
Target0.3
Herbie0.1
\[\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. Split input into 2 regimes
  2. if a < -4.99999999999999977e-58 or 3.0000000000000001e-12 < a

    1. Initial program 4.2

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

      \[\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, 9 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)))): 9 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, 9 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)))): 3 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, 3 points decrease in error

    if -4.99999999999999977e-58 < a < 3.0000000000000001e-12

    1. Initial program 0.4

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), \mathsf{fma}\left(t, a, 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, 9 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)))): 9 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, 9 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)))): 3 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, 3 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -5 \cdot 10^{-58} \lor \neg \left(a \leq 3 \cdot 10^{-12}\right):\\ \;\;\;\;\mathsf{fma}\left(a, t + z \cdot b, \mathsf{fma}\left(y, z, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), \mathsf{fma}\left(t, a, x\right)\right)\\ \end{array} \]

Alternatives

Alternative 1
Error2.7
Cost13376
\[\mathsf{fma}\left(a, t + z \cdot b, \mathsf{fma}\left(y, z, x\right)\right) \]
Alternative 2
Error1.8
Cost3017
\[\begin{array}{l} t_1 := x + z \cdot y\\ t_2 := \left(a \cdot t + t_1\right) + b \cdot \left(a \cdot z\right)\\ \mathbf{if}\;t_2 \leq -1 \cdot 10^{-46} \lor \neg \left(t_2 \leq 1.5 \cdot 10^{+296}\right):\\ \;\;\;\;\left(a \cdot \left(z \cdot b\right) + a \cdot t\right) + t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error23.4
Cost1504
\[\begin{array}{l} t_1 := z \cdot \left(y + a \cdot b\right)\\ t_2 := x + z \cdot y\\ t_3 := a \cdot \left(t + z \cdot b\right)\\ \mathbf{if}\;x \leq -8.2 \cdot 10^{+87}:\\ \;\;\;\;x + a \cdot t\\ \mathbf{elif}\;x \leq -3 \cdot 10^{+48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -8 \cdot 10^{-71}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -4.2 \cdot 10^{-203}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -2.2 \cdot 10^{-239}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{-256}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 8 \cdot 10^{-196}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{-128}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error18.0
Cost1500
\[\begin{array}{l} t_1 := a \cdot t + z \cdot y\\ t_2 := a \cdot \left(t + z \cdot b\right)\\ t_3 := x + t_2\\ \mathbf{if}\;x \leq -9.8 \cdot 10^{+70}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -1.4 \cdot 10^{+31}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -0.45:\\ \;\;\;\;x + a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;x \leq -1.05 \cdot 10^{-241}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{-277}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{-156}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.85 \cdot 10^{+66}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot y\\ \end{array} \]
Alternative 5
Error34.3
Cost1380
\[\begin{array}{l} \mathbf{if}\;x \leq -5.2 \cdot 10^{+87}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{+31}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq -350:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -6.5 \cdot 10^{-195}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq -1.26 \cdot 10^{-241}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{-277}:\\ \;\;\;\;a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;x \leq 1.82 \cdot 10^{-75}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{+70}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{+100}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error34.4
Cost1380
\[\begin{array}{l} \mathbf{if}\;x \leq -5.2 \cdot 10^{+87}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.5 \cdot 10^{+31}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq -1.65:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -9.5 \cdot 10^{-196}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq -9.8 \cdot 10^{-241}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{-277}:\\ \;\;\;\;b \cdot \left(a \cdot z\right)\\ \mathbf{elif}\;x \leq 3.9 \cdot 10^{-75}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 2.6 \cdot 10^{+69}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{+100}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error20.1
Cost1240
\[\begin{array}{l} t_1 := a \cdot t + z \cdot y\\ \mathbf{if}\;x \leq -2.45 \cdot 10^{+89}:\\ \;\;\;\;x + a \cdot t\\ \mathbf{elif}\;x \leq -2.2 \cdot 10^{+31}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5.8:\\ \;\;\;\;x + a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;x \leq -1 \cdot 10^{-241}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.8 \cdot 10^{-277}:\\ \;\;\;\;a \cdot \left(t + z \cdot b\right)\\ \mathbf{elif}\;x \leq 1.5 \cdot 10^{-99}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot y\\ \end{array} \]
Alternative 8
Error33.5
Cost1116
\[\begin{array}{l} \mathbf{if}\;x \leq -5.2 \cdot 10^{+87}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.2 \cdot 10^{+31}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq -22:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.7 \cdot 10^{-197}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{-75}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{+70}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.1 \cdot 10^{+100}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error25.3
Cost1113
\[\begin{array}{l} t_1 := x + a \cdot t\\ \mathbf{if}\;y \leq -3 \cdot 10^{+241}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;y \leq 7.6 \cdot 10^{-256}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.2 \cdot 10^{-231}:\\ \;\;\;\;a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;y \leq 4.7 \cdot 10^{+129} \lor \neg \left(y \leq 6.2 \cdot 10^{+168}\right) \land y \leq 8.2 \cdot 10^{+213}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot y\\ \end{array} \]
Alternative 10
Error19.7
Cost1108
\[\begin{array}{l} t_1 := x + z \cdot y\\ \mathbf{if}\;z \leq -3.2 \cdot 10^{+76}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{elif}\;z \leq -1.02 \cdot 10^{-105}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.8 \cdot 10^{-132}:\\ \;\;\;\;x + a \cdot t\\ \mathbf{elif}\;z \leq 2.75 \cdot 10^{-83}:\\ \;\;\;\;x + a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;z \leq 1.05 \cdot 10^{-66}:\\ \;\;\;\;a \cdot \left(t + z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error2.8
Cost960
\[\left(a \cdot \left(z \cdot b\right) + a \cdot t\right) + \left(x + z \cdot y\right) \]
Alternative 12
Error7.6
Cost841
\[\begin{array}{l} \mathbf{if}\;y \leq -2.1 \cdot 10^{-74} \lor \neg \left(y \leq 1.3 \cdot 10^{-26}\right):\\ \;\;\;\;\left(x + a \cdot t\right) + z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x + a \cdot \left(t + z \cdot b\right)\\ \end{array} \]
Alternative 13
Error19.5
Cost717
\[\begin{array}{l} \mathbf{if}\;z \leq -3.5 \cdot 10^{+76}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{elif}\;z \leq -1.02 \cdot 10^{-106} \lor \neg \left(z \leq 2.7 \cdot 10^{-133}\right):\\ \;\;\;\;x + z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x + a \cdot t\\ \end{array} \]
Alternative 14
Error19.5
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -1.5 \cdot 10^{-105} \lor \neg \left(z \leq 10^{-132}\right):\\ \;\;\;\;x + z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x + a \cdot t\\ \end{array} \]
Alternative 15
Error32.7
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -0.64:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 0.095:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 16
Error39.7
Cost64
\[x \]

Error

Reproduce

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