?

Average Error: 2.2 → 0.1
Time: 15.2s
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^{+29} \lor \neg \left(a \leq 5 \cdot 10^{-20}\right):\\ \;\;\;\;\left(a \cdot \left(z \cdot b\right) + a \cdot t\right) + \left(x + y \cdot z\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+29) (not (<= a 5e-20)))
   (+ (+ (* a (* z b)) (* a t)) (+ x (* y z)))
   (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+29) || !(a <= 5e-20)) {
		tmp = ((a * (z * b)) + (a * t)) + (x + (y * z));
	} 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+29) || !(a <= 5e-20))
		tmp = Float64(Float64(Float64(a * Float64(z * b)) + Float64(a * t)) + Float64(x + Float64(y * z)));
	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+29], N[Not[LessEqual[a, 5e-20]], $MachinePrecision]], N[(N[(N[(a * N[(z * b), $MachinePrecision]), $MachinePrecision] + N[(a * t), $MachinePrecision]), $MachinePrecision] + N[(x + N[(y * z), $MachinePrecision]), $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^{+29} \lor \neg \left(a \leq 5 \cdot 10^{-20}\right):\\
\;\;\;\;\left(a \cdot \left(z \cdot b\right) + a \cdot t\right) + \left(x + y \cdot z\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.2
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 < -5.0000000000000001e29 or 4.9999999999999999e-20 < a

    1. Initial program 5.4

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

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

      [Start]5.4

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

      associate-+l+ [=>]5.4

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

      associate-*l* [=>]0.1

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

    if -5.0000000000000001e29 < a < 4.9999999999999999e-20

    1. Initial program 0.3

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

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

      [Start]0.3

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

      +-commutative [=>]0.3

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

      +-commutative [=>]0.3

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

      associate-+l+ [=>]0.3

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

      associate-+r+ [=>]0.3

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

      *-commutative [=>]0.3

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

      associate-*l* [=>]0.1

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

      *-commutative [=>]0.1

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

      distribute-lft-out [=>]0.1

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

      fma-def [=>]0.1

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

      fma-def [=>]0.1

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

      +-commutative [=>]0.1

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

      fma-def [=>]0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -5 \cdot 10^{+29} \lor \neg \left(a \leq 5 \cdot 10^{-20}\right):\\ \;\;\;\;\left(a \cdot \left(z \cdot b\right) + a \cdot t\right) + \left(x + y \cdot z\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
Error28.4
Cost2293
\[\begin{array}{l} t_1 := x + y \cdot z\\ t_2 := a \cdot \left(t + z \cdot b\right)\\ \mathbf{if}\;b \leq -5.8 \cdot 10^{+227}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq -1.26 \cdot 10^{+89}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq -1.02 \cdot 10^{-38}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq -3.6 \cdot 10^{-166}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq -2.2 \cdot 10^{-231}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq -4.15 \cdot 10^{-255}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 1.75 \cdot 10^{-181}:\\ \;\;\;\;x + a \cdot t\\ \mathbf{elif}\;b \leq 4.6 \cdot 10^{-64}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 0.112:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 1.6 \cdot 10^{+91}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 1.7 \cdot 10^{+140}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 2 \cdot 10^{+151} \lor \neg \left(b \leq 8.8 \cdot 10^{+164}\right):\\ \;\;\;\;x + z \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(z \cdot b\right) + y \cdot z\\ \end{array} \]
Alternative 2
Error33.6
Cost1512
\[\begin{array}{l} t_1 := a \cdot \left(z \cdot b\right)\\ \mathbf{if}\;x \leq -36000000000000:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -5.8 \cdot 10^{-51}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq -3.8 \cdot 10^{-101}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.25 \cdot 10^{-147}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;x \leq -2.5 \cdot 10^{-279}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq -5.3 \cdot 10^{-304}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 4.2 \cdot 10^{-242}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5 \cdot 10^{-211}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 9 \cdot 10^{-178}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.15 \cdot 10^{-39}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error29.8
Cost1508
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := a \cdot \left(z \cdot b\right)\\ \mathbf{if}\;a \leq -1.1 \cdot 10^{+123}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -7.8 \cdot 10^{-168}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -8 \cdot 10^{-228}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;a \leq 5.7 \cdot 10^{-272}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 8 \cdot 10^{-248}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;a \leq 2.05 \cdot 10^{-203}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 7.6 \cdot 10^{-180}:\\ \;\;\;\;b \cdot \left(a \cdot z\right)\\ \mathbf{elif}\;a \leq 6.6 \cdot 10^{-168}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;a \leq 8.8 \cdot 10^{+202}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error34.0
Cost1248
\[\begin{array}{l} \mathbf{if}\;x \leq -13000000000000:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.85 \cdot 10^{-50}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq -4 \cdot 10^{-101}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -7.6 \cdot 10^{-150}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;x \leq -1.8 \cdot 10^{-280}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq -1.6 \cdot 10^{-306}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{-163}:\\ \;\;\;\;b \cdot \left(a \cdot z\right)\\ \mathbf{elif}\;x \leq 2.05 \cdot 10^{-38}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error20.4
Cost1240
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := z \cdot \left(y + a \cdot b\right)\\ \mathbf{if}\;z \leq -2.8 \cdot 10^{-35}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -5.7 \cdot 10^{-61}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -7.8 \cdot 10^{-72}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{-43}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 7 \cdot 10^{+18}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{elif}\;z \leq 3.7 \cdot 10^{+46}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error8.9
Cost1232
\[\begin{array}{l} t_1 := \left(x + a \cdot t\right) + y \cdot z\\ t_2 := b \cdot \left(a \cdot z\right) + \left(x + y \cdot z\right)\\ \mathbf{if}\;b \leq -1.8 \cdot 10^{+25}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 4.6 \cdot 10^{-64}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 4.2 \cdot 10^{-19}:\\ \;\;\;\;a \cdot \left(t + z \cdot b\right)\\ \mathbf{elif}\;b \leq 9.5 \cdot 10^{+138}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error1.9
Cost1225
\[\begin{array}{l} \mathbf{if}\;z \leq -1.42 \cdot 10^{+104} \lor \neg \left(z \leq 10^{+87}\right):\\ \;\;\;\;x + z \cdot \left(y + a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot \left(z \cdot b\right) + a \cdot t\right) + \left(x + y \cdot z\right)\\ \end{array} \]
Alternative 8
Error9.0
Cost1104
\[\begin{array}{l} t_1 := \left(x + a \cdot t\right) + y \cdot z\\ t_2 := x + z \cdot \left(y + a \cdot b\right)\\ \mathbf{if}\;z \leq -205000000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 7.2 \cdot 10^{-171}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.9 \cdot 10^{-65}:\\ \;\;\;\;a \cdot \left(z \cdot b\right) + \left(x + y \cdot z\right)\\ \mathbf{elif}\;z \leq 1.02 \cdot 10^{+31}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 9
Error32.9
Cost984
\[\begin{array}{l} \mathbf{if}\;x \leq -2.5 \cdot 10^{+14}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.5 \cdot 10^{-52}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq -2.08 \cdot 10^{-116}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2 \cdot 10^{-292}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 1.7 \cdot 10^{-240}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 2.6 \cdot 10^{-39}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error33.3
Cost984
\[\begin{array}{l} \mathbf{if}\;x \leq -1.5 \cdot 10^{+15}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.9 \cdot 10^{-54}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq -1.35 \cdot 10^{-161}:\\ \;\;\;\;a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;x \leq 1.36 \cdot 10^{-291}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 1.02 \cdot 10^{-240}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 2.45 \cdot 10^{-39}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error19.5
Cost976
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := a \cdot \left(t + z \cdot b\right)\\ \mathbf{if}\;a \leq -2.5 \cdot 10^{+114}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -6.2 \cdot 10^{-145}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 4.4 \cdot 10^{-149}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{elif}\;a \leq 2.6 \cdot 10^{+197}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 12
Error21.1
Cost976
\[\begin{array}{l} t_1 := x + a \cdot t\\ \mathbf{if}\;a \leq -7.4 \cdot 10^{+24}:\\ \;\;\;\;x + a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;a \leq -3.05 \cdot 10^{-146}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 4.5 \cdot 10^{-149}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{elif}\;a \leq 2.7 \cdot 10^{+197}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(t + z \cdot b\right)\\ \end{array} \]
Alternative 13
Error22.9
Cost848
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := a \cdot \left(z \cdot b\right)\\ \mathbf{if}\;a \leq -2.15 \cdot 10^{+120}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -8.2 \cdot 10^{-145}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 4.8 \cdot 10^{-149}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{elif}\;a \leq 1.32 \cdot 10^{+203}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 14
Error8.1
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -340000000 \lor \neg \left(z \leq 1.2 \cdot 10^{+31}\right):\\ \;\;\;\;x + z \cdot \left(y + a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x + a \cdot t\right) + y \cdot z\\ \end{array} \]
Alternative 15
Error13.1
Cost840
\[\begin{array}{l} \mathbf{if}\;a \leq -3.8 \cdot 10^{+28}:\\ \;\;\;\;x + a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;a \leq 7 \cdot 10^{+197}:\\ \;\;\;\;\left(x + a \cdot t\right) + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(t + z \cdot b\right)\\ \end{array} \]
Alternative 16
Error36.9
Cost720
\[\begin{array}{l} \mathbf{if}\;t \leq -6.5 \cdot 10^{-27}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;t \leq 2.85 \cdot 10^{+29}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 1.36 \cdot 10^{+121}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;t \leq 2 \cdot 10^{+157}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;a \cdot t\\ \end{array} \]
Alternative 17
Error39.3
Cost64
\[x \]

Error

Reproduce?

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