Average Error: 2.0 → 0.3
Time: 12.7s
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 -1.339609433722267 \cdot 10^{-28}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 10^{+55}:\\ \;\;\;\;\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 -1.339609433722267e-28)
     t_1
     (if (<= a 1e+55) (+ (+ (* 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 <= -1.339609433722267e-28) {
		tmp = t_1;
	} else if (a <= 1e+55) {
		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 <= -1.339609433722267e-28)
		tmp = t_1;
	elseif (a <= 1e+55)
		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, -1.339609433722267e-28], t$95$1, If[LessEqual[a, 1e+55], 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 -1.339609433722267 \cdot 10^{-28}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;a \leq 10^{+55}:\\
\;\;\;\;\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.0
Target0.4
Herbie0.3
\[\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 < -1.3396094337222671e-28 or 1.00000000000000001e55 < a

    1. Initial program 4.8

      \[\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))): 1 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, 1 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)): 15 points increase in error, 17 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))))): 4 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 -1.3396094337222671e-28 < a < 1.00000000000000001e55

    1. Initial program 0.4

      \[\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.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -1.339609433722267 \cdot 10^{-28}:\\ \;\;\;\;\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)\\ \mathbf{elif}\;a \leq 10^{+55}:\\ \;\;\;\;\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
Error24.4
Cost2164
\[\begin{array}{l} t_1 := z \cdot \left(y + a \cdot b\right)\\ t_2 := x + y \cdot z\\ t_3 := x + a \cdot t\\ t_4 := a \cdot \left(t + z \cdot b\right)\\ \mathbf{if}\;y \leq -1.16 \cdot 10^{+157}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1.4 \cdot 10^{+103}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -2.850096598764501 \cdot 10^{+48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -9.649161352589814 \cdot 10^{+29}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -6.532658349780051 \cdot 10^{-7}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -2.4614057795450198 \cdot 10^{-30}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -3.026579384155218 \cdot 10^{-295}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 1.642258752354168 \cdot 10^{-210}:\\ \;\;\;\;x + b \cdot \left(a \cdot z\right)\\ \mathbf{elif}\;y \leq 2.0914738914617344 \cdot 10^{-154}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq 1.3632084438261095 \cdot 10^{-95}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 3.197448662331151 \cdot 10^{-48}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq 3.4607709077389954 \cdot 10^{+50}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 10^{+177}:\\ \;\;\;\;a \cdot t + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error24.4
Cost2164
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := a \cdot \left(t + z \cdot b\right)\\ t_3 := x + y \cdot z\\ \mathbf{if}\;y \leq -1.16 \cdot 10^{+157}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -1.4 \cdot 10^{+103}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.850096598764501 \cdot 10^{+48}:\\ \;\;\;\;z \cdot \left(a \cdot b\right) + y \cdot z\\ \mathbf{elif}\;y \leq -9.649161352589814 \cdot 10^{+29}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -6.532658349780051 \cdot 10^{-7}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -2.4614057795450198 \cdot 10^{-30}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{elif}\;y \leq -3.026579384155218 \cdot 10^{-295}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.642258752354168 \cdot 10^{-210}:\\ \;\;\;\;x + b \cdot \left(a \cdot z\right)\\ \mathbf{elif}\;y \leq 2.0914738914617344 \cdot 10^{-154}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 1.3632084438261095 \cdot 10^{-95}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 3.197448662331151 \cdot 10^{-48}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 3.4607709077389954 \cdot 10^{+50}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 10^{+177}:\\ \;\;\;\;a \cdot t + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 3
Error1.4
Cost1988
\[\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}\;t_1 \leq -\infty:\\ \;\;\;\;a \cdot \left(t + z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error22.6
Cost1900
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := z \cdot \left(y + a \cdot b\right)\\ t_3 := x + y \cdot z\\ \mathbf{if}\;y \leq -1.16 \cdot 10^{+157}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -1.4 \cdot 10^{+103}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.850096598764501 \cdot 10^{+48}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -9.649161352589814 \cdot 10^{+29}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -6.532658349780051 \cdot 10^{-7}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -2.4614057795450198 \cdot 10^{-30}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 5.34070225723436 \cdot 10^{-199}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.0914738914617344 \cdot 10^{-154}:\\ \;\;\;\;a \cdot \left(t + z \cdot b\right)\\ \mathbf{elif}\;y \leq 3.197448662331151 \cdot 10^{-48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.789254785309711 \cdot 10^{+63}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 10^{+170}:\\ \;\;\;\;a \cdot t + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 5
Error21.9
Cost1636
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := z \cdot \left(y + a \cdot b\right)\\ t_3 := x + y \cdot z\\ \mathbf{if}\;y \leq -1.16 \cdot 10^{+157}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -1.4 \cdot 10^{+103}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.850096598764501 \cdot 10^{+48}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -9.649161352589814 \cdot 10^{+29}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -6.532658349780051 \cdot 10^{-7}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -2.4614057795450198 \cdot 10^{-30}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 3.197448662331151 \cdot 10^{-48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.789254785309711 \cdot 10^{+63}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 10^{+170}:\\ \;\;\;\;a \cdot t + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 6
Error33.7
Cost1116
\[\begin{array}{l} \mathbf{if}\;x \leq -2.382997805081848 \cdot 10^{-88}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.603995361769476 \cdot 10^{-243}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 4.882101094167321 \cdot 10^{-173}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 1.4310916772473616 \cdot 10^{-123}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 2.1315027984822803 \cdot 10^{-48}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 275213.3053473427:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.097639541366319 \cdot 10^{+37}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error27.4
Cost848
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;y \leq -1.398725624691463 \cdot 10^{-261}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.4243734026989194 \cdot 10^{-301}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;y \leq 5.575580087571275 \cdot 10^{-236}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.0914738914617344 \cdot 10^{-154}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error9.9
Cost840
\[\begin{array}{l} t_1 := x + b \cdot \left(a \cdot z\right)\\ \mathbf{if}\;b \leq -7.2 \cdot 10^{+201}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 4.2 \cdot 10^{+139}:\\ \;\;\;\;\left(x + a \cdot t\right) + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error18.9
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -8.415196606629423 \cdot 10^{-60}:\\ \;\;\;\;x + a \cdot t\\ \mathbf{elif}\;x \leq 2.1315027984822803 \cdot 10^{-48}:\\ \;\;\;\;a \cdot t + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot z\\ \end{array} \]
Alternative 10
Error19.9
Cost584
\[\begin{array}{l} t_1 := x + a \cdot t\\ \mathbf{if}\;t \leq -1.2975718225526102 \cdot 10^{-61}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 9.49112444472604 \cdot 10^{+81}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error32.8
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -4.293963523140166 \cdot 10^{+28}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.4992314394990585 \cdot 10^{-47}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error39.2
Cost64
\[x \]

Error

Reproduce

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