?

Average Accuracy: 97.0% → 96.0%
Time: 18.9s
Precision: binary64
Cost: 19912

?

\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;y \leq -1 \cdot 10^{-109}:\\ \;\;\;\;\left(t \cdot a + t_1\right) + b \cdot \left(z \cdot a\right)\\ \mathbf{elif}\;y \leq 10^{-55}:\\ \;\;\;\;\left(a \cdot \left(z \cdot b\right) + t \cdot a\right) + 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 (+ x (* y z))))
   (if (<= y -1e-109)
     (+ (+ (* t a) t_1) (* b (* z a)))
     (if (<= y 1e-55)
       (+ (+ (* a (* z b)) (* t a)) 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 = x + (y * z);
	double tmp;
	if (y <= -1e-109) {
		tmp = ((t * a) + t_1) + (b * (z * a));
	} else if (y <= 1e-55) {
		tmp = ((a * (z * b)) + (t * a)) + 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(x + Float64(y * z))
	tmp = 0.0
	if (y <= -1e-109)
		tmp = Float64(Float64(Float64(t * a) + t_1) + Float64(b * Float64(z * a)));
	elseif (y <= 1e-55)
		tmp = Float64(Float64(Float64(a * Float64(z * b)) + Float64(t * a)) + 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[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1e-109], N[(N[(N[(t * a), $MachinePrecision] + t$95$1), $MachinePrecision] + N[(b * N[(z * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1e-55], N[(N[(N[(a * N[(z * b), $MachinePrecision]), $MachinePrecision] + N[(t * a), $MachinePrecision]), $MachinePrecision] + t$95$1), $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}
t_1 := x + y \cdot z\\
\mathbf{if}\;y \leq -1 \cdot 10^{-109}:\\
\;\;\;\;\left(t \cdot a + t_1\right) + b \cdot \left(z \cdot a\right)\\

\mathbf{elif}\;y \leq 10^{-55}:\\
\;\;\;\;\left(a \cdot \left(z \cdot b\right) + t \cdot a\right) + 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

Original97.0%
Target99.5%
Herbie96.0%
\[\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 y < -9.9999999999999999e-110

    1. Initial program 97.7%

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

    if -9.9999999999999999e-110 < y < 9.99999999999999995e-56

    1. Initial program 96.2%

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

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

      [Start]96.2

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

      associate-+l+ [=>]96.2

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

      associate-*l* [=>]94.8

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

    if 9.99999999999999995e-56 < y

    1. Initial program 97.5%

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

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

      [Start]97.5

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

      +-commutative [=>]97.5

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

      +-commutative [=>]97.5

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

      associate-+l+ [=>]97.5

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

      associate-+r+ [=>]97.5

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

      *-commutative [=>]97.5

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

      associate-*l* [=>]95.7

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

      *-commutative [=>]95.7

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

      distribute-lft-out [=>]95.7

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

      fma-def [=>]95.7

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

      fma-def [=>]95.7

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

      +-commutative [<=]95.7

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

      fma-def [=>]95.7

      \[ \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 simplification96.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{-109}:\\ \;\;\;\;\left(t \cdot a + \left(x + y \cdot z\right)\right) + b \cdot \left(z \cdot a\right)\\ \mathbf{elif}\;y \leq 10^{-55}:\\ \;\;\;\;\left(a \cdot \left(z \cdot b\right) + t \cdot a\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
Accuracy49.1%
Cost1640
\[\begin{array}{l} t_1 := b \cdot \left(z \cdot a\right)\\ \mathbf{if}\;x \leq -5.2 \cdot 10^{+25}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -8.4 \cdot 10^{-109}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq -1.3 \cdot 10^{-237}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq -1.45 \cdot 10^{-283}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{-285}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{-281}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 3.9 \cdot 10^{-240}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{-34}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{+16}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{+38}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Accuracy49.0%
Cost1640
\[\begin{array}{l} \mathbf{if}\;x \leq -2.75 \cdot 10^{+26}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -3.15 \cdot 10^{-109}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq -4.2 \cdot 10^{-238}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq -1.45 \cdot 10^{-283}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{-285}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;x \leq 1.25 \cdot 10^{-280}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 1.12 \cdot 10^{-234}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 6 \cdot 10^{-35}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 2.6 \cdot 10^{+16}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{+38}:\\ \;\;\;\;b \cdot \left(z \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Accuracy70.0%
Cost1504
\[\begin{array}{l} t_1 := t \cdot a + y \cdot z\\ t_2 := x + y \cdot z\\ \mathbf{if}\;x \leq -3.3 \cdot 10^{+55}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.55 \cdot 10^{-283}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{-287}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{elif}\;x \leq 4.1 \cdot 10^{-222}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{-140}:\\ \;\;\;\;a \cdot \left(t + z \cdot b\right)\\ \mathbf{elif}\;x \leq 5.1 \cdot 10^{-51}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.2 \cdot 10^{-32}:\\ \;\;\;\;x + t \cdot a\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{+38}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Accuracy49.5%
Cost1376
\[\begin{array}{l} \mathbf{if}\;x \leq -2.7 \cdot 10^{+23}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.16 \cdot 10^{-109}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq -6.5 \cdot 10^{-239}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 5.2 \cdot 10^{-282}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 1.85 \cdot 10^{-238}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 2.3 \cdot 10^{-34}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 8.6 \cdot 10^{+15}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{+38}:\\ \;\;\;\;a \cdot \left(z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Accuracy49.6%
Cost1248
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{+22}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -9.5 \cdot 10^{-109}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq -1.8 \cdot 10^{-236}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{-280}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{-238}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{-36}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{+15}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 4.2 \cdot 10^{+38}:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Accuracy95.9%
Cost1225
\[\begin{array}{l} \mathbf{if}\;a \leq -9.2 \cdot 10^{-149} \lor \neg \left(a \leq 5 \cdot 10^{-261}\right):\\ \;\;\;\;\left(a \cdot \left(z \cdot b\right) + t \cdot a\right) + \left(x + y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(y + a \cdot b\right)\\ \end{array} \]
Alternative 7
Accuracy69.3%
Cost1108
\[\begin{array}{l} t_1 := a \cdot \left(t + z \cdot b\right)\\ \mathbf{if}\;a \leq -1.7 \cdot 10^{+80}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -6.6 \cdot 10^{-60}:\\ \;\;\;\;x + t \cdot a\\ \mathbf{elif}\;a \leq -6.8 \cdot 10^{-77}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{elif}\;a \leq -2.75 \cdot 10^{-101}:\\ \;\;\;\;x + z \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;a \leq 9 \cdot 10^{+28}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Accuracy82.0%
Cost1105
\[\begin{array}{l} t_1 := \left(x + t \cdot a\right) + y \cdot z\\ \mathbf{if}\;x \leq -1.45 \cdot 10^{-283}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{-287}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{-219} \lor \neg \left(x \leq 1.12 \cdot 10^{-141}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(t + z \cdot b\right)\\ \end{array} \]
Alternative 9
Accuracy97.9%
Cost1092
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;a \leq -1 \cdot 10^{-132}:\\ \;\;\;\;\left(a \cdot \left(z \cdot b\right) + t \cdot a\right) + t_1\\ \mathbf{else}:\\ \;\;\;\;\left(t \cdot a + t_1\right) + b \cdot \left(z \cdot a\right)\\ \end{array} \]
Alternative 10
Accuracy83.4%
Cost972
\[\begin{array}{l} t_1 := z \cdot \left(y + a \cdot b\right)\\ t_2 := x + t_1\\ \mathbf{if}\;b \leq -2.75 \cdot 10^{+116}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq -1.25 \cdot 10^{-9}:\\ \;\;\;\;t_1 + t \cdot a\\ \mathbf{elif}\;b \leq 3.6 \cdot 10^{+171}:\\ \;\;\;\;\left(x + t \cdot a\right) + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 11
Accuracy66.0%
Cost849
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;z \leq -1.4 \cdot 10^{-33}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 7.2 \cdot 10^{-56}:\\ \;\;\;\;x + t \cdot a\\ \mathbf{elif}\;z \leq 9.8 \cdot 10^{+27} \lor \neg \left(z \leq 1.2 \cdot 10^{+185}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \end{array} \]
Alternative 12
Accuracy68.4%
Cost844
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;z \leq -9.5 \cdot 10^{-33}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{-50}:\\ \;\;\;\;x + t \cdot a\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{+185}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 13
Accuracy87.6%
Cost841
\[\begin{array}{l} \mathbf{if}\;t \leq -1.45 \cdot 10^{+31} \lor \neg \left(t \leq 1.38 \cdot 10^{-70}\right):\\ \;\;\;\;\left(x + t \cdot a\right) + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(y + a \cdot b\right)\\ \end{array} \]
Alternative 14
Accuracy57.7%
Cost716
\[\begin{array}{l} t_1 := x + t \cdot a\\ \mathbf{if}\;z \leq 4 \cdot 10^{-48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.5 \cdot 10^{+20}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{+185}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 15
Accuracy68.4%
Cost713
\[\begin{array}{l} \mathbf{if}\;a \leq -1.6 \cdot 10^{-44} \lor \neg \left(a \leq 1.9 \cdot 10^{+25}\right):\\ \;\;\;\;a \cdot \left(t + z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot z\\ \end{array} \]
Alternative 16
Accuracy49.4%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -3.8 \cdot 10^{+23}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.6 \cdot 10^{+38}:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 17
Accuracy39.0%
Cost64
\[x \]

Error

Reproduce?

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