?

Average Error: 3.09% → 1.13%
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}\;z \leq -1.35 \cdot 10^{+86} \lor \neg \left(z \leq 5 \cdot 10^{+141}\right):\\ \;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), \mathsf{fma}\left(t, a, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), 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 (<= z -1.35e+86) (not (<= z 5e+141)))
   (fma z (fma a b y) (fma t a x))
   (fma y z (fma a (fma z b t) 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 ((z <= -1.35e+86) || !(z <= 5e+141)) {
		tmp = fma(z, fma(a, b, y), fma(t, a, x));
	} else {
		tmp = fma(y, z, fma(a, fma(z, b, t), 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 ((z <= -1.35e+86) || !(z <= 5e+141))
		tmp = fma(z, fma(a, b, y), fma(t, a, x));
	else
		tmp = fma(y, z, fma(a, fma(z, b, t), 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[z, -1.35e+86], N[Not[LessEqual[z, 5e+141]], $MachinePrecision]], N[(z * N[(a * b + y), $MachinePrecision] + N[(t * a + x), $MachinePrecision]), $MachinePrecision], N[(y * z + N[(a * N[(z * b + t), $MachinePrecision] + 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}\;z \leq -1.35 \cdot 10^{+86} \lor \neg \left(z \leq 5 \cdot 10^{+141}\right):\\
\;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), \mathsf{fma}\left(t, a, x\right)\right)\\

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


\end{array}

Error?

Target

Original3.09%
Target0.61%
Herbie1.13%
\[\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 z < -1.35000000000000009e86 or 5.00000000000000025e141 < z

    1. Initial program 12.06

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

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

      [Start]12.06

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

      +-commutative [=>]12.06

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

      +-commutative [=>]12.06

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

      associate-+l+ [=>]12.06

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

      associate-+r+ [=>]12.06

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

      *-commutative [=>]12.06

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

      associate-*l* [=>]0.14

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

      *-commutative [=>]0.14

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

      distribute-lft-out [=>]0.14

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

      fma-def [=>]0.14

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

      fma-def [=>]0.13

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

      +-commutative [=>]0.13

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

      fma-def [=>]0.13

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

    if -1.35000000000000009e86 < z < 5.00000000000000025e141

    1. Initial program 1.03

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

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

      [Start]1.03

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

      associate-+l+ [=>]1.03

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

      +-commutative [=>]1.03

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

      associate-+l+ [=>]1.03

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

      fma-def [=>]1.02

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

      +-commutative [=>]1.02

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

      *-commutative [=>]1.02

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

      associate-*l* [=>]1.36

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

      distribute-lft-out [=>]1.36

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

      fma-def [=>]1.35

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

      +-commutative [=>]1.35

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

      fma-def [=>]1.35

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

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

Alternatives

Alternative 1
Error2.14%
Cost19780
\[\begin{array}{l} \mathbf{if}\;a \leq -1 \cdot 10^{-131}:\\ \;\;\;\;\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot t + \left(x + z \cdot y\right)\right) + b \cdot \left(z \cdot a\right)\\ \end{array} \]
Alternative 2
Error2.12%
Cost13508
\[\begin{array}{l} \mathbf{if}\;a \leq -1 \cdot 10^{-128}:\\ \;\;\;\;\mathsf{fma}\left(a, t + z \cdot b, \mathsf{fma}\left(y, z, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot t + \left(x + z \cdot y\right)\right) + b \cdot \left(z \cdot a\right)\\ \end{array} \]
Alternative 3
Error65.51%
Cost1644
\[\begin{array}{l} \mathbf{if}\;z \leq -1.15 \cdot 10^{+126}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;z \leq -1.8 \cdot 10^{+72}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1 \cdot 10^{+19}:\\ \;\;\;\;a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;z \leq -6.2 \cdot 10^{-53}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;z \leq -5.3 \cdot 10^{-68}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -6.4 \cdot 10^{-111}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;z \leq -1.05 \cdot 10^{-186}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 8.2 \cdot 10^{-289}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{-186}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.35 \cdot 10^{-122}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;z \leq 9 \cdot 10^{+40}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot y\\ \end{array} \]
Alternative 4
Error34.03%
Cost1376
\[\begin{array}{l} t_1 := x + b \cdot \left(z \cdot a\right)\\ t_2 := x + a \cdot t\\ t_3 := z \cdot y + a \cdot t\\ t_4 := x + z \cdot y\\ \mathbf{if}\;x \leq -4.4 \cdot 10^{+148}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq -3.8 \cdot 10^{+123}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -310000000:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -1.75 \cdot 10^{-12}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5.8 \cdot 10^{-85}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 4.2 \cdot 10^{-141}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 10^{-127}:\\ \;\;\;\;x + a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{-53}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_4\\ \end{array} \]
Alternative 5
Error34.2%
Cost1245
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := a \cdot \left(t + z \cdot b\right)\\ t_3 := x + z \cdot y\\ \mathbf{if}\;z \leq -1.15 \cdot 10^{+48}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -1.4 \cdot 10^{-52}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.16 \cdot 10^{-66}:\\ \;\;\;\;x + b \cdot \left(z \cdot a\right)\\ \mathbf{elif}\;z \leq -1.75 \cdot 10^{-93}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.5 \cdot 10^{-113}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.22 \cdot 10^{-141} \lor \neg \left(z \leq 1350000\right):\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error35.26%
Cost1240
\[\begin{array}{l} t_1 := a \cdot \left(t + z \cdot b\right)\\ t_2 := x + z \cdot y\\ \mathbf{if}\;x \leq -2300000000000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.6 \cdot 10^{-11}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -6.2 \cdot 10^{-69}:\\ \;\;\;\;x + a \cdot t\\ \mathbf{elif}\;x \leq -8 \cdot 10^{-144}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -6.3 \cdot 10^{-245}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{-54}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error2.12%
Cost1092
\[\begin{array}{l} t_1 := x + z \cdot y\\ \mathbf{if}\;a \leq -1 \cdot 10^{-128}:\\ \;\;\;\;\left(a \cdot \left(z \cdot b\right) + a \cdot t\right) + t_1\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot t + t_1\right) + b \cdot \left(z \cdot a\right)\\ \end{array} \]
Alternative 8
Error41.75%
Cost981
\[\begin{array}{l} t_1 := x + a \cdot t\\ \mathbf{if}\;z \leq -1.1 \cdot 10^{+161}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;z \leq -1.55 \cdot 10^{+67}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.6 \cdot 10^{+19}:\\ \;\;\;\;a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{+37} \lor \neg \left(z \leq 1.4 \cdot 10^{+95}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot y\\ \end{array} \]
Alternative 9
Error3.96%
Cost960
\[\left(a \cdot \left(z \cdot b\right) + a \cdot t\right) + \left(x + z \cdot y\right) \]
Alternative 10
Error15.39%
Cost841
\[\begin{array}{l} \mathbf{if}\;b \leq -3.4 \cdot 10^{+180} \lor \neg \left(b \leq 6.5 \cdot 10^{+170}\right):\\ \;\;\;\;x + b \cdot \left(z \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot y + \left(x + a \cdot t\right)\\ \end{array} \]
Alternative 11
Error12.62%
Cost841
\[\begin{array}{l} \mathbf{if}\;t \leq -2 \cdot 10^{+32} \lor \neg \left(t \leq 8.6 \cdot 10^{-93}\right):\\ \;\;\;\;z \cdot y + \left(x + a \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(y + a \cdot b\right)\\ \end{array} \]
Alternative 12
Error32.79%
Cost716
\[\begin{array}{l} t_1 := x + z \cdot y\\ \mathbf{if}\;z \leq -1.15 \cdot 10^{+48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.6 \cdot 10^{+19}:\\ \;\;\;\;a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;z \leq 85000:\\ \;\;\;\;x + a \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 13
Error31.4%
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -1.75 \cdot 10^{+19}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{elif}\;z \leq 6500:\\ \;\;\;\;x + a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot y\\ \end{array} \]
Alternative 14
Error51.95%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -3000000000000:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.3 \cdot 10^{-42}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 15
Error62.61%
Cost64
\[x \]

Error

Reproduce?

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