Average Error: 2.2 → 0.2
Time: 13.6s
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 := \mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)\\ \mathbf{if}\;a \leq -10000000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 6.467021878229546 \cdot 10^{-40}:\\ \;\;\;\;\left(a \cdot t + \left(x + y \cdot z\right)\right) + b \cdot \left(a \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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 (fma y z (fma a (fma z b t) x))))
   (if (<= a -10000000000000.0)
     t_1
     (if (<= a 6.467021878229546e-40)
       (+ (+ (* a t) (+ x (* y z))) (* b (* a z)))
       t_1))))
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 = fma(y, z, fma(a, fma(z, b, t), x));
	double tmp;
	if (a <= -10000000000000.0) {
		tmp = t_1;
	} else if (a <= 6.467021878229546e-40) {
		tmp = ((a * t) + (x + (y * z))) + (b * (a * z));
	} else {
		tmp = t_1;
	}
	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 = fma(y, z, fma(a, fma(z, b, t), x))
	tmp = 0.0
	if (a <= -10000000000000.0)
		tmp = t_1;
	elseif (a <= 6.467021878229546e-40)
		tmp = Float64(Float64(Float64(a * t) + Float64(x + Float64(y * z))) + Float64(b * Float64(a * z)));
	else
		tmp = t_1;
	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[(y * z + N[(a * N[(z * b + t), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -10000000000000.0], t$95$1, If[LessEqual[a, 6.467021878229546e-40], N[(N[(N[(a * t), $MachinePrecision] + N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b * N[(a * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
\begin{array}{l}
t_1 := \mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)\\
\mathbf{if}\;a \leq -10000000000000:\\
\;\;\;\;t_1\\

\mathbf{elif}\;a \leq 6.467021878229546 \cdot 10^{-40}:\\
\;\;\;\;\left(a \cdot t + \left(x + y \cdot z\right)\right) + b \cdot \left(a \cdot z\right)\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Target

Original2.2
Target0.4
Herbie0.2
\[\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 < -1e13 or 6.4670218782295463e-40 < a

    1. Initial program 5.0

      \[\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(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)} \]
      Proof
      (fma.f64 y z (fma.f64 a (fma.f64 z b t) x)): 0 points increase in error, 0 points decrease in error
      (fma.f64 y z (fma.f64 a (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z b) t)) x)): 0 points increase in error, 0 points decrease in error
      (fma.f64 y z (fma.f64 a (Rewrite<= +-commutative_binary64 (+.f64 t (*.f64 z b))) x)): 0 points increase in error, 0 points decrease in error
      (fma.f64 y z (Rewrite<= fma-def_binary64 (+.f64 (*.f64 a (+.f64 t (*.f64 z b))) x))): 0 points increase in error, 0 points decrease in error
      (fma.f64 y z (+.f64 (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 a t) (*.f64 a (*.f64 z b)))) x)): 0 points increase in error, 0 points decrease in error
      (fma.f64 y z (+.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 t a)) (*.f64 a (*.f64 z b))) x)): 0 points increase in error, 0 points decrease in error
      (fma.f64 y z (+.f64 (+.f64 (*.f64 t a) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a z) b))) x)): 17 points increase in error, 20 points decrease in error
      (fma.f64 y z (Rewrite<= +-commutative_binary64 (+.f64 x (+.f64 (*.f64 t a) (*.f64 (*.f64 a z) b))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y z) (+.f64 x (+.f64 (*.f64 t a) (*.f64 (*.f64 a z) b))))): 2 points increase in error, 0 points decrease in error
      (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (*.f64 y z) x) (+.f64 (*.f64 t a) (*.f64 (*.f64 a z) b)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 y z))) (+.f64 (*.f64 t a) (*.f64 (*.f64 a z) b))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b))): 0 points increase in error, 0 points decrease in error

    if -1e13 < a < 6.4670218782295463e-40

    1. Initial program 0.3

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -10000000000000:\\ \;\;\;\;\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)\\ \mathbf{elif}\;a \leq 6.467021878229546 \cdot 10^{-40}:\\ \;\;\;\;\left(a \cdot t + \left(x + y \cdot z\right)\right) + b \cdot \left(a \cdot z\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
Error1.8
Cost7112
\[\begin{array}{l} t_1 := x + y \cdot z\\ t_2 := \left(a \cdot t + t_1\right) + b \cdot \left(a \cdot z\right)\\ \mathbf{if}\;b \leq -1.598754333812799 \cdot 10^{-67}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 1.5814842360598363 \cdot 10^{-229}:\\ \;\;\;\;\mathsf{fma}\left(t, a, t_1\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error24.4
Cost1636
\[\begin{array}{l} t_1 := a \cdot t + y \cdot z\\ t_2 := x + a \cdot t\\ t_3 := x + b \cdot \left(a \cdot z\right)\\ t_4 := x + y \cdot z\\ \mathbf{if}\;b \leq -1.18 \cdot 10^{+175}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;b \leq -4.3 \cdot 10^{+111}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq -9.236275042974385 \cdot 10^{-243}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;b \leq 2.2080577885491834 \cdot 10^{-266}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 2.2240412131145797 \cdot 10^{-144}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;b \leq 2.4512454174338468 \cdot 10^{-48}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 5081784959440276:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 5.085013598100387 \cdot 10^{+38}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;b \leq 8.4 \cdot 10^{+132}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 3
Error12.7
Cost1236
\[\begin{array}{l} t_1 := x + a \cdot \left(t + z \cdot b\right)\\ t_2 := z \cdot \left(y + a \cdot b\right)\\ t_3 := \left(x + a \cdot t\right) + y \cdot z\\ \mathbf{if}\;z \leq -1.02 \cdot 10^{+102}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2.5 \cdot 10^{+64}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -9.971070094947713 \cdot 10^{+19}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.8149598722105035 \cdot 10^{-278}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 31080.30376776488:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 4
Error1.8
Cost1224
\[\begin{array}{l} t_1 := \left(a \cdot t + \left(x + y \cdot z\right)\right) + b \cdot \left(a \cdot z\right)\\ \mathbf{if}\;b \leq -1.598754333812799 \cdot 10^{-67}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 1.5814842360598363 \cdot 10^{-229}:\\ \;\;\;\;\left(x + a \cdot t\right) + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error15.5
Cost1104
\[\begin{array}{l} t_1 := x + a \cdot \left(t + z \cdot b\right)\\ t_2 := z \cdot \left(y + a \cdot b\right)\\ \mathbf{if}\;z \leq -1.02 \cdot 10^{+102}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2.5 \cdot 10^{+64}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -136122.17519292585:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 31080.30376776488:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot z\\ \end{array} \]
Alternative 6
Error25.9
Cost980
\[\begin{array}{l} t_1 := x + a \cdot t\\ \mathbf{if}\;z \leq -7 \cdot 10^{+116}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -2.5 \cdot 10^{+64}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -136122.17519292585:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 1.4 \cdot 10^{+47}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{+90}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error20.7
Cost844
\[\begin{array}{l} \mathbf{if}\;z \leq -136122.17519292585:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{elif}\;z \leq 9.884033008853764 \cdot 10^{-114}:\\ \;\;\;\;x + a \cdot t\\ \mathbf{elif}\;z \leq 31080.30376776488:\\ \;\;\;\;x + b \cdot \left(a \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot z\\ \end{array} \]
Alternative 8
Error34.0
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -2.1677078980924566 \cdot 10^{+42}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.3963888539005345 \cdot 10^{-208}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq -1.4613912396342752 \cdot 10^{-300}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 8.678402690772755 \cdot 10^{-116}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error19.0
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -2.1677078980924566 \cdot 10^{+42}:\\ \;\;\;\;x + a \cdot t\\ \mathbf{elif}\;x \leq 8.876939943983883 \cdot 10^{-121}:\\ \;\;\;\;a \cdot t + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot z\\ \end{array} \]
Alternative 10
Error20.0
Cost584
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;z \leq -7.599981451806761 \cdot 10^{-88}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.0369457006605977 \cdot 10^{-104}:\\ \;\;\;\;x + a \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error33.5
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -2.2926148297862894 \cdot 10^{+48}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 8.678402690772755 \cdot 10^{-116}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error40.4
Cost64
\[x \]

Error

Reproduce

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