Average Error: 2.0 → 1.2
Time: 14.9s
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}\;a \leq -1 \cdot 10^{+59}:\\ \;\;\;\;\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot t + \left(x + y \cdot z\right)\right) + b \cdot \left(a \cdot z\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 (<= a -1e+59)
   (fma y z (fma a (fma z b t) x))
   (+ (+ (* a t) (+ x (* y z))) (* b (* a z)))))
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 (a <= -1e+59) {
		tmp = fma(y, z, fma(a, fma(z, b, t), x));
	} else {
		tmp = ((a * t) + (x + (y * z))) + (b * (a * z));
	}
	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 (a <= -1e+59)
		tmp = fma(y, z, fma(a, fma(z, b, t), x));
	else
		tmp = Float64(Float64(Float64(a * t) + Float64(x + Float64(y * z))) + Float64(b * Float64(a * z)));
	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[a, -1e+59], N[(y * z + N[(a * N[(z * b + t), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(a * t), $MachinePrecision] + N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b * N[(a * z), $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}\;a \leq -1 \cdot 10^{+59}:\\
\;\;\;\;\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)\\

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


\end{array}

Error

Target

Original2.0
Target0.4
Herbie1.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 < -9.99999999999999972e58

    1. Initial program 6.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)): 9 points increase in error, 12 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 -9.99999999999999972e58 < a

    1. Initial program 1.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 simplification1.2

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

Alternatives

Alternative 1
Error13.8
Cost1888
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := y \cdot z + \left(x + a \cdot \left(z \cdot b\right)\right)\\ t_3 := b \cdot \left(a \cdot z\right)\\ t_4 := t_3 + \left(y \cdot z + a \cdot t\right)\\ t_5 := t_3 + t_1\\ \mathbf{if}\;y \leq -8.391528994475008 \cdot 10^{-17}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq -1.7988953426884438 \cdot 10^{-95}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 1.71163143502842 \cdot 10^{-33}:\\ \;\;\;\;t_5\\ \mathbf{elif}\;y \leq 6.5423086453291045 \cdot 10^{+28}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{elif}\;y \leq 3.978036843758623 \cdot 10^{+49}:\\ \;\;\;\;t_5\\ \mathbf{elif}\;y \leq 2.40601789527207 \cdot 10^{+72}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq 5.028134110147535 \cdot 10^{+89}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 10^{+120}:\\ \;\;\;\;t_4\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error19.8
Cost1372
\[\begin{array}{l} t_1 := y \cdot z + a \cdot t\\ t_2 := x + a \cdot \left(z \cdot b\right)\\ t_3 := x + y \cdot z\\ \mathbf{if}\;x \leq -1.6995150115608045 \cdot 10^{-44}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -3.853912888855949 \cdot 10^{-166}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -4.522030740222479 \cdot 10^{-203}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 7.639766488332613 \cdot 10^{-38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.6387694730173487 \cdot 10^{+60}:\\ \;\;\;\;x + a \cdot t\\ \mathbf{elif}\;x \leq 3.903365503761319 \cdot 10^{+78}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.046233254558986 \cdot 10^{+109}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 3
Error19.2
Cost1372
\[\begin{array}{l} t_1 := y \cdot z + a \cdot t\\ t_2 := x + y \cdot z\\ \mathbf{if}\;x \leq -1.6995150115608045 \cdot 10^{-44}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.8518734359802627 \cdot 10^{-165}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -4.522030740222479 \cdot 10^{-203}:\\ \;\;\;\;b \cdot \left(a \cdot z\right) + a \cdot t\\ \mathbf{elif}\;x \leq 7.639766488332613 \cdot 10^{-38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.6387694730173487 \cdot 10^{+60}:\\ \;\;\;\;x + a \cdot t\\ \mathbf{elif}\;x \leq 3.903365503761319 \cdot 10^{+78}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.046233254558986 \cdot 10^{+109}:\\ \;\;\;\;x + a \cdot \left(z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error17.7
Cost1232
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := y \cdot z + \left(x + a \cdot \left(z \cdot b\right)\right)\\ \mathbf{if}\;y \leq -3.7766664849515306 \cdot 10^{+62}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -79392.93470804516:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -3.196392361513894 \cdot 10^{-115}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 6.4010978689926995 \cdot 10^{-86}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error11.9
Cost1232
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot z\right) + \left(x + a \cdot t\right)\\ t_2 := y \cdot z + \left(x + a \cdot \left(z \cdot b\right)\right)\\ \mathbf{if}\;y \leq -3.7766664849515306 \cdot 10^{+62}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -79392.93470804516:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.7988953426884438 \cdot 10^{-95}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 6.473992267564717 \cdot 10^{-46}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error27.0
Cost1112
\[\begin{array}{l} t_1 := x + a \cdot t\\ \mathbf{if}\;z \leq -5.2 \cdot 10^{+25}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -3.2065664554200036 \cdot 10^{-162}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.56244688292451 \cdot 10^{-179}:\\ \;\;\;\;a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;z \leq 4.3479666149411404 \cdot 10^{-44}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 7.049346738355649 \cdot 10^{-23}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 7.2 \cdot 10^{+70}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 7
Error33.6
Cost984
\[\begin{array}{l} \mathbf{if}\;x \leq -7.0827906260497185 \cdot 10^{-25}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 7.014648478819684 \cdot 10^{-218}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 7.639766488332613 \cdot 10^{-38}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 7.771371624603878 \cdot 10^{+38}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.83018330942356 \cdot 10^{+70}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 3.8802728315676603 \cdot 10^{+84}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error2.0
Cost960
\[\left(a \cdot t + \left(x + y \cdot z\right)\right) + b \cdot \left(a \cdot z\right) \]
Alternative 9
Error26.7
Cost848
\[\begin{array}{l} t_1 := x + a \cdot t\\ \mathbf{if}\;x \leq -6.917502193357058 \cdot 10^{-111}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -4.9462780219398514 \cdot 10^{-157}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 7.014648478819684 \cdot 10^{-218}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.639766488332613 \cdot 10^{-38}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error21.2
Cost848
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;z \leq -3.2065664554200036 \cdot 10^{-162}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.56244688292451 \cdot 10^{-179}:\\ \;\;\;\;a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;z \leq -3.5032997354167794 \cdot 10^{-183}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 2.868798289832802 \cdot 10^{-104}:\\ \;\;\;\;x + a \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error20.9
Cost848
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;z \leq -1.2141923891532768 \cdot 10^{-85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.56244688292451 \cdot 10^{-179}:\\ \;\;\;\;x + a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;z \leq -3.5032997354167794 \cdot 10^{-183}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 2.868798289832802 \cdot 10^{-104}:\\ \;\;\;\;x + a \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error33.2
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.8434710073620327 \cdot 10^{-54}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 7.639766488332613 \cdot 10^{-38}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 13
Error40.2
Cost64
\[x \]

Error

Reproduce

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