Average Error: 1.9 → 0.9
Time: 12.8s
Precision: binary64
Cost: 13641
\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
\[\begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{+194} \lor \neg \left(b \leq 10^{+105}\right):\\ \;\;\;\;\left(t \cdot a + \left(x + y \cdot z\right)\right) + b \cdot \left(z \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a, t + b \cdot z, \mathsf{fma}\left(y, z, 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 (<= b -5e+194) (not (<= b 1e+105)))
   (+ (+ (* t a) (+ x (* y z))) (* b (* z a)))
   (fma a (+ t (* b z)) (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) {
	double tmp;
	if ((b <= -5e+194) || !(b <= 1e+105)) {
		tmp = ((t * a) + (x + (y * z))) + (b * (z * a));
	} else {
		tmp = fma(a, (t + (b * z)), fma(y, z, 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 ((b <= -5e+194) || !(b <= 1e+105))
		tmp = Float64(Float64(Float64(t * a) + Float64(x + Float64(y * z))) + Float64(b * Float64(z * a)));
	else
		tmp = fma(a, Float64(t + Float64(b * z)), fma(y, z, 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[b, -5e+194], N[Not[LessEqual[b, 1e+105]], $MachinePrecision]], N[(N[(N[(t * a), $MachinePrecision] + N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b * N[(z * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a * N[(t + N[(b * z), $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
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{+194} \lor \neg \left(b \leq 10^{+105}\right):\\
\;\;\;\;\left(t \cdot a + \left(x + y \cdot z\right)\right) + b \cdot \left(z \cdot a\right)\\

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


\end{array}

Error

Target

Original1.9
Target0.3
Herbie0.9
\[\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 b < -4.99999999999999989e194 or 9.9999999999999994e104 < b

    1. Initial program 1.0

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

    if -4.99999999999999989e194 < b < 9.9999999999999994e104

    1. Initial program 2.1

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

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

      [Start]2.1

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

      associate-+l+ [=>]2.1

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

      +-commutative [=>]2.1

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

      *-commutative [=>]2.1

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

      associate-*l* [=>]0.9

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

      distribute-lft-out [=>]0.9

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

      fma-def [=>]0.9

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

      +-commutative [=>]0.9

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

      fma-def [=>]0.9

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

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

Alternatives

Alternative 1
Error25.0
Cost1376
\[\begin{array}{l} t_1 := z \cdot \left(y + b \cdot a\right)\\ t_2 := a \cdot \left(t + b \cdot z\right)\\ t_3 := x + y \cdot z\\ \mathbf{if}\;x \leq -1.55 \cdot 10^{+118}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -55:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -9.2 \cdot 10^{-40}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -2.3 \cdot 10^{-183}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -4 \cdot 10^{-266}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.35 \cdot 10^{-294}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 5.4 \cdot 10^{-217}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2 \cdot 10^{+43}:\\ \;\;\;\;x + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 2
Error34.3
Cost1248
\[\begin{array}{l} \mathbf{if}\;x \leq -1.55 \cdot 10^{+118}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -145000000000:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq -8 \cdot 10^{-38}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{-183}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq -1.3 \cdot 10^{-264}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 3.4 \cdot 10^{-290}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 3.8 \cdot 10^{-218}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 2.15 \cdot 10^{-10}:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error20.8
Cost1241
\[\begin{array}{l} t_1 := x + t \cdot a\\ t_2 := x + y \cdot z\\ \mathbf{if}\;z \leq -7.5 \cdot 10^{+40}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -3.4 \cdot 10^{-48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.8 \cdot 10^{-105}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{-6}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 8 \cdot 10^{+68} \lor \neg \left(z \leq 4.2 \cdot 10^{+220}\right):\\ \;\;\;\;z \cdot \left(y + b \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error20.8
Cost1241
\[\begin{array}{l} t_1 := x + y \cdot z\\ t_2 := a \cdot \left(t + b \cdot z\right)\\ \mathbf{if}\;a \leq -8300000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -3.8 \cdot 10^{-87}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -3.6 \cdot 10^{-118}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 8.2 \cdot 10^{-124}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 7.1 \cdot 10^{+47} \lor \neg \left(a \leq 7 \cdot 10^{+163}\right):\\ \;\;\;\;x + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x + b \cdot \left(z \cdot a\right)\\ \end{array} \]
Alternative 5
Error21.3
Cost1240
\[\begin{array}{l} t_1 := x + y \cdot z\\ t_2 := a \cdot \left(t + b \cdot z\right)\\ \mathbf{if}\;a \leq -7000000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -3.8 \cdot 10^{-87}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -3.6 \cdot 10^{-118}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 1.4 \cdot 10^{-61}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 2.3 \cdot 10^{+33}:\\ \;\;\;\;y \cdot z + t \cdot a\\ \mathbf{elif}\;a \leq 6.6 \cdot 10^{+163}:\\ \;\;\;\;x + b \cdot \left(z \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;x + t \cdot a\\ \end{array} \]
Alternative 6
Error1.0
Cost1225
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;b \leq -1.3 \cdot 10^{+227} \lor \neg \left(b \leq 2 \cdot 10^{+52}\right):\\ \;\;\;\;\left(t \cdot a + t_1\right) + b \cdot \left(z \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot \left(b \cdot z\right) + t \cdot a\right) + t_1\\ \end{array} \]
Alternative 7
Error10.0
Cost1105
\[\begin{array}{l} t_1 := x + b \cdot \left(z \cdot a\right)\\ \mathbf{if}\;b \leq -3.75 \cdot 10^{+84}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 1.12 \cdot 10^{+58}:\\ \;\;\;\;y \cdot z + \left(x + t \cdot a\right)\\ \mathbf{elif}\;b \leq 2 \cdot 10^{+195} \lor \neg \left(b \leq 4.5 \cdot 10^{+266}\right):\\ \;\;\;\;x + z \cdot \left(y + b \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error2.8
Cost960
\[\left(a \cdot \left(b \cdot z\right) + t \cdot a\right) + \left(x + y \cdot z\right) \]
Alternative 9
Error26.5
Cost850
\[\begin{array}{l} \mathbf{if}\;x \leq -6900000000 \lor \neg \left(x \leq -2.05 \cdot 10^{-39}\right) \land \left(x \leq -2.7 \cdot 10^{-183} \lor \neg \left(x \leq -2.45 \cdot 10^{-265}\right)\right):\\ \;\;\;\;x + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 10
Error20.6
Cost850
\[\begin{array}{l} \mathbf{if}\;z \leq -1.6 \cdot 10^{+41} \lor \neg \left(z \leq -3.9 \cdot 10^{-48} \lor \neg \left(z \leq -1.2 \cdot 10^{-101}\right) \land z \leq 3.4 \cdot 10^{-5}\right):\\ \;\;\;\;x + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + t \cdot a\\ \end{array} \]
Alternative 11
Error10.8
Cost841
\[\begin{array}{l} \mathbf{if}\;b \leq -3.6 \cdot 10^{+87} \lor \neg \left(b \leq 1.15 \cdot 10^{+72}\right):\\ \;\;\;\;x + b \cdot \left(z \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot z + \left(x + t \cdot a\right)\\ \end{array} \]
Alternative 12
Error34.3
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.85 \cdot 10^{+118}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{-10}:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 13
Error40.1
Cost64
\[x \]

Error

Reproduce

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