Average Error: 1.9 → 2.3
Time: 15.6s
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.5703291912154536 \cdot 10^{-249}:\\ \;\;\;\;\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)\\ \mathbf{elif}\;z \leq 5 \cdot 10^{+256}:\\ \;\;\;\;\left(a \cdot t + \left(x + z \cdot y\right)\right) + b \cdot \left(z \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot t + z \cdot y\\ \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.5703291912154536e-249)
   (fma y z (fma a (fma z b t) x))
   (if (<= z 5e+256)
     (+ (+ (* a t) (+ x (* z y))) (* b (* z a)))
     (+ (* a t) (* z y)))))
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.5703291912154536e-249) {
		tmp = fma(y, z, fma(a, fma(z, b, t), x));
	} else if (z <= 5e+256) {
		tmp = ((a * t) + (x + (z * y))) + (b * (z * a));
	} else {
		tmp = (a * t) + (z * y);
	}
	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.5703291912154536e-249)
		tmp = fma(y, z, fma(a, fma(z, b, t), x));
	elseif (z <= 5e+256)
		tmp = Float64(Float64(Float64(a * t) + Float64(x + Float64(z * y))) + Float64(b * Float64(z * a)));
	else
		tmp = Float64(Float64(a * t) + Float64(z * y));
	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.5703291912154536e-249], N[(y * z + N[(a * N[(z * b + t), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 5e+256], N[(N[(N[(a * t), $MachinePrecision] + N[(x + N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b * N[(z * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a * t), $MachinePrecision] + N[(z * y), $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.5703291912154536 \cdot 10^{-249}:\\
\;\;\;\;\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)\\

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

\mathbf{else}:\\
\;\;\;\;a \cdot t + z \cdot y\\


\end{array}

Error

Target

Original1.9
Target0.3
Herbie2.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 3 regimes
  2. if z < 1.57032919121545364e-249

    1. Initial program 1.9

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
    2. Simplified2.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)): 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))): 2 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)): 18 points increase in error, 11 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.57032919121545364e-249 < z < 5.00000000000000015e256

    1. Initial program 1.6

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

    if 5.00000000000000015e256 < z

    1. Initial program 8.6

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
    2. Simplified16.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)): 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))): 2 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)): 18 points increase in error, 11 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 x around 0 23.2

      \[\leadsto \color{blue}{y \cdot z + a \cdot \left(z \cdot b + t\right)} \]
    4. Taylor expanded in z around 0 26.6

      \[\leadsto y \cdot z + \color{blue}{a \cdot t} \]
    5. Simplified26.6

      \[\leadsto y \cdot z + \color{blue}{t \cdot a} \]
      Proof
      (*.f64 t a): 0 points increase in error, 0 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 a t)): 0 points increase in error, 0 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification2.3

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

Alternatives

Alternative 1
Error1.3
Cost1988
\[\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}\;t_1 \leq -\infty:\\ \;\;\;\;x + a \cdot \left(t + z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error33.4
Cost1380
\[\begin{array}{l} \mathbf{if}\;x \leq -1.102288111590218 \cdot 10^{+37}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -0.0001738094526306546:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq -1.5349665955092422 \cdot 10^{-83}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.975158977951405 \cdot 10^{-131}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 3.803906526333651 \cdot 10^{-187}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 8.430999092213408 \cdot 10^{-151}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 7.909972935330018 \cdot 10^{-86}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 6.663579596843868 \cdot 10^{-48}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 5.6763599314358845 \cdot 10^{+41}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error26.1
Cost1376
\[\begin{array}{l} t_1 := x + a \cdot t\\ \mathbf{if}\;y \leq -2.9 \cdot 10^{+172}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;y \leq -8.71718206744736 \cdot 10^{+114}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.3156571901672518 \cdot 10^{+100}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;y \leq -2.900504814083603 \cdot 10^{-120}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -9.856332271791031 \cdot 10^{-147}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;y \leq 4.005359366954478 \cdot 10^{+83}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 8.5 \cdot 10^{+171}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;y \leq 6.2 \cdot 10^{+253}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot y\\ \end{array} \]
Alternative 4
Error19.0
Cost1240
\[\begin{array}{l} t_1 := x + z \cdot y\\ t_2 := a \cdot t + z \cdot y\\ \mathbf{if}\;x \leq -2.6253938453907235 \cdot 10^{+107}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.4555404919756758 \cdot 10^{+53}:\\ \;\;\;\;x + a \cdot t\\ \mathbf{elif}\;x \leq -6.2495148087402634 \cdot 10^{-83}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.0246143971709643 \cdot 10^{-307}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.0780123679677304 \cdot 10^{-255}:\\ \;\;\;\;a \cdot \left(t + z \cdot b\right)\\ \mathbf{elif}\;x \leq 6.957507898832278 \cdot 10^{-33}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error10.0
Cost1236
\[\begin{array}{l} t_1 := \left(x + a \cdot t\right) + z \cdot y\\ t_2 := a \cdot \left(t + z \cdot b\right)\\ t_3 := x + t_2\\ \mathbf{if}\;a \leq -4.1 \cdot 10^{+101}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq -1.15 \cdot 10^{+31}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -2.5449072808821636 \cdot 10^{-60}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq -2.0307319620061763 \cdot 10^{-120}:\\ \;\;\;\;t_2 + z \cdot y\\ \mathbf{elif}\;a \leq 8.807898931961538 \cdot 10^{-58}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 6
Error25.6
Cost1112
\[\begin{array}{l} t_1 := x + a \cdot t\\ \mathbf{if}\;y \leq -2.9 \cdot 10^{+172}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;y \leq -8.71718206744736 \cdot 10^{+114}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.3156571901672518 \cdot 10^{+100}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;y \leq 4.005359366954478 \cdot 10^{+83}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 8.5 \cdot 10^{+171}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;y \leq 6.2 \cdot 10^{+253}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot y\\ \end{array} \]
Alternative 7
Error20.9
Cost1112
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := x + z \cdot y\\ \mathbf{if}\;y \leq -3.755469762699624 \cdot 10^{-34}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -2.900504814083603 \cdot 10^{-120}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -9.856332271791031 \cdot 10^{-147}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;y \leq 1.9401533206040207 \cdot 10^{-295}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.1416334490377924 \cdot 10^{-165}:\\ \;\;\;\;x + a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;y \leq 3.668089285901979 \cdot 10^{+79}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 8
Error12.4
Cost840
\[\begin{array}{l} t_1 := x + a \cdot \left(t + z \cdot b\right)\\ \mathbf{if}\;a \leq -2.0980731287900596 \cdot 10^{-73}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 8.807898931961538 \cdot 10^{-58}:\\ \;\;\;\;x + z \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error8.6
Cost840
\[\begin{array}{l} t_1 := x + a \cdot \left(t + z \cdot b\right)\\ \mathbf{if}\;a \leq -4.1 \cdot 10^{+101}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 8.807898931961538 \cdot 10^{-58}:\\ \;\;\;\;\left(x + a \cdot t\right) + z \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error19.3
Cost584
\[\begin{array}{l} t_1 := x + a \cdot t\\ \mathbf{if}\;a \leq -1.1893715896078757 \cdot 10^{-60}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 8.807898931961538 \cdot 10^{-58}:\\ \;\;\;\;x + z \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error33.6
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.5349665955092422 \cdot 10^{-83}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.957507898832278 \cdot 10^{-33}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error40.0
Cost64
\[x \]

Error

Reproduce

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