Average Error: 2.0 → 1.4
Time: 16.7s
Precision: binary64
Cost: 19780
\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
\[\begin{array}{l} \mathbf{if}\;z \leq 1.590135594514713 \cdot 10^{-79}:\\ \;\;\;\;\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot t + \left(x + z \cdot \left(y + a \cdot b\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 (<= z 1.590135594514713e-79)
   (fma y z (fma a (fma z b t) x))
   (+ (* a t) (+ x (* z (+ y (* a b)))))))
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 (z <= 1.590135594514713e-79) {
		tmp = fma(y, z, fma(a, fma(z, b, t), x));
	} else {
		tmp = (a * t) + (x + (z * (y + (a * b))));
	}
	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 (z <= 1.590135594514713e-79)
		tmp = fma(y, z, fma(a, fma(z, b, t), x));
	else
		tmp = Float64(Float64(a * t) + Float64(x + Float64(z * Float64(y + Float64(a * b)))));
	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[LessEqual[z, 1.590135594514713e-79], N[(y * z + N[(a * N[(z * b + t), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision], N[(N[(a * t), $MachinePrecision] + N[(x + N[(z * N[(y + N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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}\;z \leq 1.590135594514713 \cdot 10^{-79}:\\
\;\;\;\;\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)\\

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


\end{array}

Error

Target

Original2.0
Target0.4
Herbie1.4
\[\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 z < 1.5901355945147129e-79

    1. Initial program 1.5

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

      \[\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)): 1 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)): 1 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)): 11 points increase in error, 13 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))))): 1 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.5901355945147129e-79 < z

    1. Initial program 3.2

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

      \[\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)): 1 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)): 1 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)): 11 points increase in error, 13 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))))): 1 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
    3. Taylor expanded in z around inf 0.5

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

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

Alternatives

Alternative 1
Error20.8
Cost1372
\[\begin{array}{l} t_1 := x + a \cdot t\\ \mathbf{if}\;a \leq -3.7 \cdot 10^{+215}:\\ \;\;\;\;a \cdot \left(t + z \cdot b\right)\\ \mathbf{elif}\;a \leq -2.95 \cdot 10^{+41}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -3.1186309155163883 \cdot 10^{-26}:\\ \;\;\;\;a \cdot t + z \cdot y\\ \mathbf{elif}\;a \leq -8.622372021997244 \cdot 10^{-97}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 9.384367446799105 \cdot 10^{-54}:\\ \;\;\;\;x + z \cdot y\\ \mathbf{elif}\;a \leq 4.2 \cdot 10^{+38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 3 \cdot 10^{+78}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error25.9
Cost1244
\[\begin{array}{l} t_1 := x + z \cdot y\\ t_2 := a \cdot \left(z \cdot b\right)\\ \mathbf{if}\;a \leq -1.85 \cdot 10^{+203}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -9 \cdot 10^{+73}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -962044713.8640698:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;a \leq 4 \cdot 10^{+99}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 4.2 \cdot 10^{+149}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;a \leq 1.55 \cdot 10^{+168}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 4.8 \cdot 10^{+215}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;a \cdot t\\ \end{array} \]
Alternative 3
Error21.1
Cost1240
\[\begin{array}{l} t_1 := x + a \cdot t\\ \mathbf{if}\;a \leq -2.95 \cdot 10^{+41}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -3.1186309155163883 \cdot 10^{-26}:\\ \;\;\;\;a \cdot t + z \cdot y\\ \mathbf{elif}\;a \leq -8.622372021997244 \cdot 10^{-97}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 9.384367446799105 \cdot 10^{-54}:\\ \;\;\;\;x + z \cdot y\\ \mathbf{elif}\;a \leq 4.2 \cdot 10^{+38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 3 \cdot 10^{+78}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error2.0
Cost1224
\[\begin{array}{l} t_1 := \left(a \cdot t + \left(x + z \cdot y\right)\right) + b \cdot \left(z \cdot a\right)\\ \mathbf{if}\;y \leq -2.8082781696137605 \cdot 10^{-252}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.481267235167165 \cdot 10^{+83}:\\ \;\;\;\;a \cdot t + \left(x + z \cdot \left(y + a \cdot b\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error10.2
Cost1100
\[\begin{array}{l} t_1 := a \cdot t + \left(x + z \cdot y\right)\\ t_2 := a \cdot t + \left(x + a \cdot \left(z \cdot b\right)\right)\\ \mathbf{if}\;b \leq -3.3 \cdot 10^{+98}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 1.050488971173852 \cdot 10^{+42}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 2 \cdot 10^{+142}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error7.7
Cost968
\[\begin{array}{l} t_1 := a \cdot t + \left(x + z \cdot y\right)\\ \mathbf{if}\;x \leq -4.5779433922819695 \cdot 10^{-70}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 9.333394028759037 \cdot 10^{-122}:\\ \;\;\;\;a \cdot t + z \cdot \left(y + a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error7.9
Cost968
\[\begin{array}{l} t_1 := a \cdot t + \left(x + z \cdot y\right)\\ \mathbf{if}\;x \leq -4.5779433922819695 \cdot 10^{-70}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.43739127080597 \cdot 10^{-155}:\\ \;\;\;\;z \cdot y + a \cdot \left(t + z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error2.5
Cost964
\[\begin{array}{l} \mathbf{if}\;a \leq 5 \cdot 10^{+117}:\\ \;\;\;\;a \cdot t + \left(x + z \cdot \left(y + a \cdot b\right)\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot t + \left(x + a \cdot \left(z \cdot b\right)\right)\\ \end{array} \]
Alternative 9
Error33.5
Cost852
\[\begin{array}{l} \mathbf{if}\;x \leq -2.2173588269797715 \cdot 10^{-44}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.9343396106457694 \cdot 10^{-106}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq -3.2547396609877853 \cdot 10^{-302}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 6.521891652524814 \cdot 10^{-221}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 2.1836583727236428 \cdot 10^{-71}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error20.1
Cost848
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := x + z \cdot y\\ \mathbf{if}\;z \leq -3.689039332145516 \cdot 10^{-104}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 3.6944028476627727 \cdot 10^{-79}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.6 \cdot 10^{+50}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 6 \cdot 10^{+103}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 11
Error20.3
Cost848
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := x + z \cdot y\\ \mathbf{if}\;y \leq -15436893359104.363:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 0.00023807532134435702:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.622660815538323 \cdot 10^{+30}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{elif}\;y \leq 6.411945780274456 \cdot 10^{+61}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 12
Error11.9
Cost840
\[\begin{array}{l} t_1 := a \cdot t + \left(x + z \cdot y\right)\\ \mathbf{if}\;b \leq -7.4 \cdot 10^{+213}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq -7.8 \cdot 10^{+146}:\\ \;\;\;\;a \cdot t + a \cdot \left(z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 13
Error11.7
Cost840
\[\begin{array}{l} t_1 := a \cdot t + \left(x + z \cdot y\right)\\ \mathbf{if}\;b \leq -7.4 \cdot 10^{+213}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq -7.8 \cdot 10^{+146}:\\ \;\;\;\;a \cdot t + b \cdot \left(z \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 14
Error32.6
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -2.2173588269797715 \cdot 10^{-44}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.3349423261662076 \cdot 10^{-56}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 15
Error39.8
Cost64
\[x \]

Error

Reproduce

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