Average Error: 2.1 → 0.6
Time: 13.2s
Precision: binary64
Cost: 21704
\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
\[\begin{array}{l} t_1 := \left(t \cdot a + \left(x + y \cdot z\right)\right) + \left(z \cdot a\right) \cdot b\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right) + t \cdot a\\ \mathbf{elif}\;t_1 \leq 10^{+284}:\\ \;\;\;\;t_1\\ \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
 (let* ((t_1 (+ (+ (* t a) (+ x (* y z))) (* (* z a) b))))
   (if (<= t_1 (- INFINITY))
     (+ (* z (+ y (* a b))) (* t a))
     (if (<= t_1 1e+284) t_1 (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 t_1 = ((t * a) + (x + (y * z))) + ((z * a) * b);
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = (z * (y + (a * b))) + (t * a);
	} else if (t_1 <= 1e+284) {
		tmp = t_1;
	} 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)
	t_1 = Float64(Float64(Float64(t * a) + Float64(x + Float64(y * z))) + Float64(Float64(z * a) * b))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(Float64(z * Float64(y + Float64(a * b))) + Float64(t * a));
	elseif (t_1 <= 1e+284)
		tmp = t_1;
	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_] := Block[{t$95$1 = N[(N[(N[(t * a), $MachinePrecision] + N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(z * a), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(z * N[(y + N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1e+284], t$95$1, 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}
t_1 := \left(t \cdot a + \left(x + y \cdot z\right)\right) + \left(z \cdot a\right) \cdot b\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;z \cdot \left(y + a \cdot b\right) + t \cdot a\\

\mathbf{elif}\;t_1 \leq 10^{+284}:\\
\;\;\;\;t_1\\

\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.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. Split input into 3 regimes
  2. if (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b)) < -inf.0

    1. Initial program 64.0

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

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

      [Start]64.0

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

      +-commutative [=>]64.0

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

      +-commutative [=>]64.0

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

      associate-+l+ [=>]64.0

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

      associate-+r+ [=>]64.0

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

      *-commutative [=>]64.0

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

      associate-*l* [=>]0.2

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

      *-commutative [=>]0.2

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

      distribute-lft-out [=>]0.2

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

      fma-def [=>]0.2

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

      fma-def [=>]0.2

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

      +-commutative [=>]0.2

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

      fma-def [=>]0.2

      \[ \mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), \color{blue}{\mathsf{fma}\left(t, a, x\right)}\right) \]
    3. Taylor expanded in x around 0 7.4

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

    if -inf.0 < (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b)) < 1.00000000000000008e284

    1. Initial program 0.3

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

    if 1.00000000000000008e284 < (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b))

    1. Initial program 15.6

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

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

      [Start]15.6

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

      +-commutative [=>]15.6

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

      +-commutative [=>]15.6

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

      associate-+l+ [=>]15.6

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

      associate-+r+ [=>]15.6

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

      *-commutative [=>]15.6

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

      associate-*l* [=>]3.8

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

      *-commutative [=>]3.8

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

      distribute-lft-out [=>]3.9

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

      fma-def [=>]3.8

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

      fma-def [=>]3.8

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

      +-commutative [=>]3.8

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

      fma-def [=>]3.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(t \cdot a + \left(x + y \cdot z\right)\right) + \left(z \cdot a\right) \cdot b \leq -\infty:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right) + t \cdot a\\ \mathbf{elif}\;\left(t \cdot a + \left(x + y \cdot z\right)\right) + \left(z \cdot a\right) \cdot b \leq 10^{+284}:\\ \;\;\;\;\left(t \cdot a + \left(x + y \cdot z\right)\right) + \left(z \cdot a\right) \cdot b\\ \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
Error0.8
Cost3016
\[\begin{array}{l} t_1 := x + y \cdot z\\ t_2 := \left(t \cdot a + t_1\right) + \left(z \cdot a\right) \cdot b\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right) + t \cdot a\\ \mathbf{elif}\;t_2 \leq 2.7 \cdot 10^{+272}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\left(t \cdot a + a \cdot \left(z \cdot b\right)\right) + t_1\\ \end{array} \]
Alternative 2
Error22.2
Cost1640
\[\begin{array}{l} t_1 := a \cdot \left(t + z \cdot b\right)\\ t_2 := x + y \cdot z\\ t_3 := x + t \cdot a\\ \mathbf{if}\;y \leq -7.4 \cdot 10^{+43}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -7.8 \cdot 10^{+29}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.6 \cdot 10^{-74}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -2.1 \cdot 10^{-302}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{-283}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;y \leq 3.3 \cdot 10^{-192}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{-106}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{-101}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{-90}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{elif}\;y \leq 8.2 \cdot 10^{-29}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error21.4
Cost1636
\[\begin{array}{l} t_1 := x + a \cdot \left(z \cdot b\right)\\ t_2 := a \cdot \left(t + z \cdot b\right)\\ t_3 := x + t \cdot a\\ t_4 := x + y \cdot z\\ \mathbf{if}\;t \leq -9 \cdot 10^{+19}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq -1.9 \cdot 10^{-21}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -2.3 \cdot 10^{-52}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 6.9 \cdot 10^{-302}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;t \leq 2 \cdot 10^{-250}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 4 \cdot 10^{-43}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;t \leq 28500000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.6 \cdot 10^{+82}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;t \leq 5.4 \cdot 10^{+91}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 4
Error21.7
Cost1508
\[\begin{array}{l} t_1 := x + t \cdot a\\ t_2 := x + y \cdot z\\ \mathbf{if}\;y \leq -2.3 \cdot 10^{+207}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -5 \cdot 10^{+76}:\\ \;\;\;\;t \cdot a + y \cdot z\\ \mathbf{elif}\;y \leq -7.4 \cdot 10^{+43}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -7.2 \cdot 10^{+29}:\\ \;\;\;\;a \cdot \left(t + z \cdot b\right)\\ \mathbf{elif}\;y \leq -8.8 \cdot 10^{-72}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -2.35 \cdot 10^{-302}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{-101}:\\ \;\;\;\;x + a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{-90}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{elif}\;y \leq 1.75 \cdot 10^{-25}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error21.6
Cost1508
\[\begin{array}{l} t_1 := x + t \cdot a\\ t_2 := x + y \cdot z\\ \mathbf{if}\;y \leq -4 \cdot 10^{+207}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -4.5 \cdot 10^{+76}:\\ \;\;\;\;t \cdot a + y \cdot z\\ \mathbf{elif}\;y \leq -7.4 \cdot 10^{+43}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -7.8 \cdot 10^{+29}:\\ \;\;\;\;a \cdot \left(t + z \cdot b\right)\\ \mathbf{elif}\;y \leq -3.1 \cdot 10^{-72}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1.5 \cdot 10^{-243}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{-101}:\\ \;\;\;\;x + z \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{-90}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{elif}\;y \leq 3 \cdot 10^{-28}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error20.7
Cost1113
\[\begin{array}{l} t_1 := x + t \cdot a\\ t_2 := x + y \cdot z\\ \mathbf{if}\;y \leq -5.4 \cdot 10^{-73}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -2.1 \cdot 10^{-302}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{-283}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{-98} \lor \neg \left(y \leq 3.2 \cdot 10^{-90}\right) \land y \leq 2.9 \cdot 10^{-25}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error21.7
Cost1108
\[\begin{array}{l} t_1 := z \cdot \left(y + a \cdot b\right)\\ t_2 := x + t \cdot a\\ \mathbf{if}\;a \leq -5 \cdot 10^{-31}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -2.4 \cdot 10^{-56}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -7.8 \cdot 10^{-146}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 2.4 \cdot 10^{-68}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{elif}\;a \leq 1.16 \cdot 10^{+134}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error8.2
Cost969
\[\begin{array}{l} \mathbf{if}\;x \leq -7 \cdot 10^{-78} \lor \neg \left(x \leq 950000000\right):\\ \;\;\;\;\left(x + t \cdot a\right) + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right) + t \cdot a\\ \end{array} \]
Alternative 9
Error2.7
Cost960
\[\left(t \cdot a + a \cdot \left(z \cdot b\right)\right) + \left(x + y \cdot z\right) \]
Alternative 10
Error26.2
Cost850
\[\begin{array}{l} \mathbf{if}\;x \leq -9.5 \cdot 10^{-193} \lor \neg \left(x \leq 2.5 \cdot 10^{-173} \lor \neg \left(x \leq 3.3 \cdot 10^{+78}\right) \land x \leq 1.4 \cdot 10^{+101}\right):\\ \;\;\;\;x + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 11
Error12.2
Cost841
\[\begin{array}{l} \mathbf{if}\;y \leq -2.05 \cdot 10^{-243} \lor \neg \left(y \leq 1.7 \cdot 10^{-114}\right):\\ \;\;\;\;\left(x + t \cdot a\right) + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(a \cdot b\right)\\ \end{array} \]
Alternative 12
Error8.1
Cost841
\[\begin{array}{l} \mathbf{if}\;t \leq -7 \cdot 10^{+21} \lor \neg \left(t \leq 9.2 \cdot 10^{-79}\right):\\ \;\;\;\;\left(x + t \cdot a\right) + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(y + a \cdot b\right)\\ \end{array} \]
Alternative 13
Error33.3
Cost588
\[\begin{array}{l} \mathbf{if}\;x \leq -2.2 \cdot 10^{+18}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -7.5 \cdot 10^{-194}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{+101}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 14
Error33.2
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.18 \cdot 10^{+14}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.8 \cdot 10^{-97}:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 15
Error39.4
Cost64
\[x \]

Error

Reproduce

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