Average Error: 2.1 → 1.4
Time: 13.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 3.473623755486017 \cdot 10^{-31}:\\ \;\;\;\;\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right) + \left(x + a \cdot t\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 3.473623755486017e-31)
   (fma y z (fma a (fma z b t) x))
   (+ (* z (+ y (* a b))) (+ x (* a t)))))
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 <= 3.473623755486017e-31) {
		tmp = fma(y, z, fma(a, fma(z, b, t), x));
	} else {
		tmp = (z * (y + (a * b))) + (x + (a * t));
	}
	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 <= 3.473623755486017e-31)
		tmp = fma(y, z, fma(a, fma(z, b, t), x));
	else
		tmp = Float64(Float64(z * Float64(y + Float64(a * b))) + Float64(x + Float64(a * t)));
	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, 3.473623755486017e-31], N[(y * z + N[(a * N[(z * b + t), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision], N[(N[(z * N[(y + N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x + N[(a * t), $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 3.473623755486017 \cdot 10^{-31}:\\
\;\;\;\;\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)\\

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


\end{array}

Error

Target

Original2.1
Target0.3
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 < 3.47362375548601718e-31

    1. Initial program 1.4

      \[\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)): 0 points increase in error, 1 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, 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)): 11 points increase in error, 15 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))))): 0 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, 1 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 3.47362375548601718e-31 < z

    1. Initial program 4.5

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
    2. Taylor expanded in z around 0 0.1

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

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

Alternatives

Alternative 1
Error21.4
Cost1504
\[\begin{array}{l} t_1 := x + z \cdot y\\ t_2 := x + a \cdot t\\ \mathbf{if}\;z \leq -1.45 \cdot 10^{+131}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -7.239546845304488 \cdot 10^{-71}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.942647576076151 \cdot 10^{-107}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.2590271146218264 \cdot 10^{-120}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -4.717315248981911 \cdot 10^{-141}:\\ \;\;\;\;a \cdot \left(t + z \cdot b\right)\\ \mathbf{elif}\;z \leq 1.32187231483921 \cdot 10^{-44}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2.45 \cdot 10^{+144}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.75 \cdot 10^{+205}:\\ \;\;\;\;x + z \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error28.7
Cost1112
\[\begin{array}{l} t_1 := x + z \cdot y\\ \mathbf{if}\;x \leq -3.1704450340028015 \cdot 10^{+80}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -3.768896894937384 \cdot 10^{+33}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq -3.499090926588405 \cdot 10^{-103}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5.920938271068413 \cdot 10^{-306}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 1.2979692672147235 \cdot 10^{-197}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.32668678602126 \cdot 10^{-8}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error21.0
Cost1108
\[\begin{array}{l} t_1 := x + z \cdot y\\ t_2 := x + a \cdot t\\ \mathbf{if}\;z \leq -1.45 \cdot 10^{+131}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -7.239546845304488 \cdot 10^{-71}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.32187231483921 \cdot 10^{-44}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2.45 \cdot 10^{+144}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.75 \cdot 10^{+205}:\\ \;\;\;\;x + z \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error3.3
Cost1096
\[\begin{array}{l} t_1 := z \cdot \left(y + a \cdot b\right) + \left(x + a \cdot t\right)\\ \mathbf{if}\;z \leq 5.821822449967051 \cdot 10^{-247}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 8.671058037896558 \cdot 10^{-97}:\\ \;\;\;\;x + a \cdot \left(t + z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error1.2
Cost1092
\[\begin{array}{l} \mathbf{if}\;z \leq 3.473623755486017 \cdot 10^{-31}:\\ \;\;\;\;\left(a \cdot t + \left(x + z \cdot y\right)\right) + b \cdot \left(z \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right) + \left(x + a \cdot t\right)\\ \end{array} \]
Alternative 6
Error20.8
Cost848
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := x + z \cdot y\\ \mathbf{if}\;y \leq -1.28 \cdot 10^{+165}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -8.3 \cdot 10^{+108}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -9.418283703654742 \cdot 10^{-27}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 3.6 \cdot 10^{+105}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error33.4
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -3.1704450340028015 \cdot 10^{+80}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -5.920938271068413 \cdot 10^{-306}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 1.2979692672147235 \cdot 10^{-197}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 2.9192927375325733 \cdot 10^{+50}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error10.3
Cost708
\[\begin{array}{l} \mathbf{if}\;b \leq 10^{+205}:\\ \;\;\;\;\left(x + a \cdot t\right) + z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x + b \cdot \left(z \cdot a\right)\\ \end{array} \]
Alternative 9
Error32.5
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -116022.46416955547:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.4930788577325444 \cdot 10^{-54}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error39.8
Cost64
\[x \]

Error

Reproduce

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