?

Average Error: 3.09% → 0.29%
Time: 12.9s
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} \mathbf{if}\;a \leq -2 \cdot 10^{+21}:\\ \;\;\;\;\left(a \cdot \left(z \cdot b\right) + a \cdot t\right) + \left(x + y \cdot z\right)\\ \mathbf{elif}\;a \leq 10^{+68}:\\ \;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), \mathsf{fma}\left(t, a, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a, t + z \cdot b, \mathsf{fma}\left(y, z, x\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 (<= a -2e+21)
   (+ (+ (* a (* z b)) (* a t)) (+ x (* y z)))
   (if (<= a 1e+68)
     (fma z (fma a b y) (fma t a x))
     (fma a (+ t (* z b)) (fma y z x)))))
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 <= -2e+21) {
		tmp = ((a * (z * b)) + (a * t)) + (x + (y * z));
	} else if (a <= 1e+68) {
		tmp = fma(z, fma(a, b, y), fma(t, a, x));
	} else {
		tmp = fma(a, (t + (z * b)), fma(y, z, x));
	}
	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 <= -2e+21)
		tmp = Float64(Float64(Float64(a * Float64(z * b)) + Float64(a * t)) + Float64(x + Float64(y * z)));
	elseif (a <= 1e+68)
		tmp = fma(z, fma(a, b, y), fma(t, a, x));
	else
		tmp = fma(a, Float64(t + Float64(z * b)), fma(y, z, x));
	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, -2e+21], N[(N[(N[(a * N[(z * b), $MachinePrecision]), $MachinePrecision] + N[(a * t), $MachinePrecision]), $MachinePrecision] + N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 1e+68], N[(z * N[(a * b + y), $MachinePrecision] + N[(t * a + x), $MachinePrecision]), $MachinePrecision], N[(a * N[(t + N[(z * b), $MachinePrecision]), $MachinePrecision] + N[(y * z + x), $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 -2 \cdot 10^{+21}:\\
\;\;\;\;\left(a \cdot \left(z \cdot b\right) + a \cdot t\right) + \left(x + y \cdot z\right)\\

\mathbf{elif}\;a \leq 10^{+68}:\\
\;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), \mathsf{fma}\left(t, a, x\right)\right)\\

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


\end{array}

Error?

Target

Original3.09%
Target0.49%
Herbie0.29%
\[\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 a < -2e21

    1. Initial program 7.98

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

      \[\leadsto \color{blue}{\left(x + y \cdot z\right) + \left(t \cdot a + a \cdot \left(z \cdot b\right)\right)} \]
      Proof

      [Start]7.98

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

      associate-+l+ [=>]7.98

      \[ \color{blue}{\left(x + y \cdot z\right) + \left(t \cdot a + \left(a \cdot z\right) \cdot b\right)} \]

      associate-*l* [=>]0.15

      \[ \left(x + y \cdot z\right) + \left(t \cdot a + \color{blue}{a \cdot \left(z \cdot b\right)}\right) \]

    if -2e21 < a < 9.99999999999999953e67

    1. Initial program 0.6

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), \mathsf{fma}\left(t, a, x\right)\right)} \]
      Proof

      [Start]0.6

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

      +-commutative [=>]0.6

      \[ \color{blue}{\left(a \cdot z\right) \cdot b + \left(\left(x + y \cdot z\right) + t \cdot a\right)} \]

      +-commutative [=>]0.6

      \[ \left(a \cdot z\right) \cdot b + \left(\color{blue}{\left(y \cdot z + x\right)} + t \cdot a\right) \]

      associate-+l+ [=>]0.6

      \[ \left(a \cdot z\right) \cdot b + \color{blue}{\left(y \cdot z + \left(x + t \cdot a\right)\right)} \]

      associate-+r+ [=>]0.6

      \[ \color{blue}{\left(\left(a \cdot z\right) \cdot b + y \cdot z\right) + \left(x + t \cdot a\right)} \]

      *-commutative [=>]0.6

      \[ \left(\color{blue}{\left(z \cdot a\right)} \cdot b + y \cdot z\right) + \left(x + t \cdot a\right) \]

      associate-*l* [=>]0.36

      \[ \left(\color{blue}{z \cdot \left(a \cdot b\right)} + y \cdot z\right) + \left(x + t \cdot a\right) \]

      *-commutative [=>]0.36

      \[ \left(z \cdot \left(a \cdot b\right) + \color{blue}{z \cdot y}\right) + \left(x + t \cdot a\right) \]

      distribute-lft-out [=>]0.36

      \[ \color{blue}{z \cdot \left(a \cdot b + y\right)} + \left(x + t \cdot a\right) \]

      fma-def [=>]0.36

      \[ \color{blue}{\mathsf{fma}\left(z, a \cdot b + y, x + t \cdot a\right)} \]

      fma-def [=>]0.35

      \[ \mathsf{fma}\left(z, \color{blue}{\mathsf{fma}\left(a, b, y\right)}, x + t \cdot a\right) \]

      +-commutative [=>]0.35

      \[ \mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), \color{blue}{t \cdot a + x}\right) \]

      fma-def [=>]0.35

      \[ \mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), \color{blue}{\mathsf{fma}\left(t, a, x\right)}\right) \]

    if 9.99999999999999953e67 < a

    1. Initial program 10.85

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(a, t + z \cdot b, \mathsf{fma}\left(y, z, x\right)\right)} \]
      Proof

      [Start]10.85

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

      associate-+l+ [=>]10.85

      \[ \color{blue}{\left(x + y \cdot z\right) + \left(t \cdot a + \left(a \cdot z\right) \cdot b\right)} \]

      +-commutative [=>]10.85

      \[ \color{blue}{\left(t \cdot a + \left(a \cdot z\right) \cdot b\right) + \left(x + y \cdot z\right)} \]

      *-commutative [=>]10.85

      \[ \left(\color{blue}{a \cdot t} + \left(a \cdot z\right) \cdot b\right) + \left(x + y \cdot z\right) \]

      associate-*l* [=>]0.14

      \[ \left(a \cdot t + \color{blue}{a \cdot \left(z \cdot b\right)}\right) + \left(x + y \cdot z\right) \]

      distribute-lft-out [=>]0.14

      \[ \color{blue}{a \cdot \left(t + z \cdot b\right)} + \left(x + y \cdot z\right) \]

      fma-def [=>]0.13

      \[ \color{blue}{\mathsf{fma}\left(a, t + z \cdot b, x + y \cdot z\right)} \]

      +-commutative [=>]0.13

      \[ \mathsf{fma}\left(a, t + z \cdot b, \color{blue}{y \cdot z + x}\right) \]

      fma-def [=>]0.13

      \[ \mathsf{fma}\left(a, t + z \cdot b, \color{blue}{\mathsf{fma}\left(y, z, x\right)}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.29

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

Alternatives

Alternative 1
Error4.13%
Cost13376
\[\mathsf{fma}\left(a, t + z \cdot b, \mathsf{fma}\left(y, z, x\right)\right) \]
Alternative 2
Error36.97%
Cost1377
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := x + y \cdot z\\ t_3 := x + b \cdot \left(a \cdot z\right)\\ \mathbf{if}\;t \leq -9.2 \cdot 10^{+237}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -5.2 \cdot 10^{+32}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.1 \cdot 10^{-191}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.08 \cdot 10^{-253}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 2.6 \cdot 10^{-191}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{elif}\;t \leq 0.0016:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 3.4 \cdot 10^{+76} \lor \neg \left(t \leq 4.2 \cdot 10^{+189}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error36.73%
Cost1377
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := x + y \cdot z\\ t_3 := x + a \cdot \left(z \cdot b\right)\\ \mathbf{if}\;t \leq -9.2 \cdot 10^{+237}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -1.25 \cdot 10^{+32}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.25 \cdot 10^{-198}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.08 \cdot 10^{-253}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 6.2 \cdot 10^{-206}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{elif}\;t \leq 4 \cdot 10^{-90}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 6 \cdot 10^{+79} \lor \neg \left(t \leq 6.2 \cdot 10^{+188}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error34.74%
Cost1245
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := x + y \cdot z\\ \mathbf{if}\;t \leq -9.2 \cdot 10^{+237}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -2.2 \cdot 10^{+32}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.08 \cdot 10^{-253}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.4 \cdot 10^{-215}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{elif}\;t \leq 3.3 \cdot 10^{+16} \lor \neg \left(t \leq 2.7 \cdot 10^{+70}\right) \land t \leq 7.2 \cdot 10^{+188}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error52.03%
Cost1116
\[\begin{array}{l} \mathbf{if}\;x \leq -9500:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.4 \cdot 10^{-285}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 1.2 \cdot 10^{-196}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{-179}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-158}:\\ \;\;\;\;a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-47}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 2.55 \cdot 10^{+66}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error41.29%
Cost1113
\[\begin{array}{l} t_1 := x + a \cdot t\\ \mathbf{if}\;x \leq -2.3 \cdot 10^{-285}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{-197}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 4 \cdot 10^{-179}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{-163}:\\ \;\;\;\;a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;x \leq 88 \lor \neg \left(x \leq 1.6 \cdot 10^{+62}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 7
Error22.65%
Cost1104
\[\begin{array}{l} t_1 := y \cdot z + a \cdot t\\ t_2 := x + y \cdot z\\ \mathbf{if}\;y \leq -1.12 \cdot 10^{+173}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -4 \cdot 10^{+105}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.2 \cdot 10^{+25}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 6.8 \cdot 10^{+192}:\\ \;\;\;\;x + a \cdot \left(t + z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error33.93%
Cost982
\[\begin{array}{l} \mathbf{if}\;t \leq -9.2 \cdot 10^{+237} \lor \neg \left(t \leq -7.6 \cdot 10^{+31}\right) \land \left(t \leq 1.2 \cdot 10^{+16} \lor \neg \left(t \leq 1.05 \cdot 10^{+79}\right) \land t \leq 6.2 \cdot 10^{+188}\right):\\ \;\;\;\;x + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + a \cdot t\\ \end{array} \]
Alternative 9
Error13.63%
Cost972
\[\begin{array}{l} t_1 := x + z \cdot \left(y + a \cdot b\right)\\ \mathbf{if}\;z \leq -3 \cdot 10^{-14}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.1 \cdot 10^{-208}:\\ \;\;\;\;y \cdot z + \left(x + a \cdot t\right)\\ \mathbf{elif}\;z \leq 0.46:\\ \;\;\;\;x + a \cdot \left(t + z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error13.34%
Cost969
\[\begin{array}{l} \mathbf{if}\;x \leq -1.85 \cdot 10^{-48} \lor \neg \left(x \leq 4 \cdot 10^{+44}\right):\\ \;\;\;\;y \cdot z + \left(x + a \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot z + a \cdot \left(t + z \cdot b\right)\\ \end{array} \]
Alternative 11
Error4.14%
Cost960
\[\left(a \cdot \left(z \cdot b\right) + a \cdot t\right) + \left(x + y \cdot z\right) \]
Alternative 12
Error51.82%
Cost852
\[\begin{array}{l} \mathbf{if}\;x \leq -25000:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.3 \cdot 10^{-285}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 2.65 \cdot 10^{-197}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{-45}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 2.3 \cdot 10^{+66}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 13
Error12.21%
Cost841
\[\begin{array}{l} \mathbf{if}\;y \leq -2.45 \cdot 10^{-76} \lor \neg \left(y \leq 0.0062\right):\\ \;\;\;\;y \cdot z + \left(x + a \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;x + a \cdot \left(t + z \cdot b\right)\\ \end{array} \]
Alternative 14
Error51.22%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -29500:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{-50}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 15
Error61.92%
Cost64
\[x \]

Error

Reproduce?

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