Average Error: 6.2 → 2.1
Time: 29.0s
Precision: binary64
Cost: 7876
\[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right) \]
\[\begin{array}{l} t_1 := a + b \cdot c\\ t_2 := i \cdot \left(c \cdot t_1\right)\\ \mathbf{if}\;t_2 \leq -2 \cdot 10^{+238}:\\ \;\;\;\;2 \cdot \left(x \cdot y - \mathsf{fma}\left(c, b, a\right) \cdot \left(c \cdot i\right)\right)\\ \mathbf{elif}\;t_2 \leq 10^{+307}:\\ \;\;\;\;2 \cdot \left(\left(x \cdot y + z \cdot t\right) - t_2\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(z \cdot t - c \cdot \left(i \cdot t_1\right)\right)\\ \end{array} \]
(FPCore (x y z t a b c i)
 :precision binary64
 (* 2.0 (- (+ (* x y) (* z t)) (* (* (+ a (* b c)) c) i))))
(FPCore (x y z t a b c i)
 :precision binary64
 (let* ((t_1 (+ a (* b c))) (t_2 (* i (* c t_1))))
   (if (<= t_2 -2e+238)
     (* 2.0 (- (* x y) (* (fma c b a) (* c i))))
     (if (<= t_2 1e+307)
       (* 2.0 (- (+ (* x y) (* z t)) t_2))
       (* 2.0 (- (* z t) (* c (* i t_1))))))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
	return 2.0 * (((x * y) + (z * t)) - (((a + (b * c)) * c) * i));
}
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
	double t_1 = a + (b * c);
	double t_2 = i * (c * t_1);
	double tmp;
	if (t_2 <= -2e+238) {
		tmp = 2.0 * ((x * y) - (fma(c, b, a) * (c * i)));
	} else if (t_2 <= 1e+307) {
		tmp = 2.0 * (((x * y) + (z * t)) - t_2);
	} else {
		tmp = 2.0 * ((z * t) - (c * (i * t_1)));
	}
	return tmp;
}
function code(x, y, z, t, a, b, c, i)
	return Float64(2.0 * Float64(Float64(Float64(x * y) + Float64(z * t)) - Float64(Float64(Float64(a + Float64(b * c)) * c) * i)))
end
function code(x, y, z, t, a, b, c, i)
	t_1 = Float64(a + Float64(b * c))
	t_2 = Float64(i * Float64(c * t_1))
	tmp = 0.0
	if (t_2 <= -2e+238)
		tmp = Float64(2.0 * Float64(Float64(x * y) - Float64(fma(c, b, a) * Float64(c * i))));
	elseif (t_2 <= 1e+307)
		tmp = Float64(2.0 * Float64(Float64(Float64(x * y) + Float64(z * t)) - t_2));
	else
		tmp = Float64(2.0 * Float64(Float64(z * t) - Float64(c * Float64(i * t_1))));
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(2.0 * N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] - N[(N[(N[(a + N[(b * c), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision] * i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_, c_, i_] := Block[{t$95$1 = N[(a + N[(b * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(i * N[(c * t$95$1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -2e+238], N[(2.0 * N[(N[(x * y), $MachinePrecision] - N[(N[(c * b + a), $MachinePrecision] * N[(c * i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 1e+307], N[(2.0 * N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] - t$95$2), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(N[(z * t), $MachinePrecision] - N[(c * N[(i * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right)
\begin{array}{l}
t_1 := a + b \cdot c\\
t_2 := i \cdot \left(c \cdot t_1\right)\\
\mathbf{if}\;t_2 \leq -2 \cdot 10^{+238}:\\
\;\;\;\;2 \cdot \left(x \cdot y - \mathsf{fma}\left(c, b, a\right) \cdot \left(c \cdot i\right)\right)\\

\mathbf{elif}\;t_2 \leq 10^{+307}:\\
\;\;\;\;2 \cdot \left(\left(x \cdot y + z \cdot t\right) - t_2\right)\\

\mathbf{else}:\\
\;\;\;\;2 \cdot \left(z \cdot t - c \cdot \left(i \cdot t_1\right)\right)\\


\end{array}

Error

Target

Original6.2
Target1.7
Herbie2.1
\[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(a + b \cdot c\right) \cdot \left(c \cdot i\right)\right) \]

Derivation

  1. Split input into 3 regimes
  2. if (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i) < -2.0000000000000001e238

    1. Initial program 40.0

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

      \[\leadsto 2 \cdot \color{blue}{\left(y \cdot x - c \cdot \left(i \cdot \left(c \cdot b + a\right)\right)\right)} \]
    3. Simplified14.4

      \[\leadsto 2 \cdot \color{blue}{\left(y \cdot x - \mathsf{fma}\left(c, b, a\right) \cdot \left(c \cdot i\right)\right)} \]
      Proof
      (-.f64 (*.f64 y x) (*.f64 (fma.f64 c b a) (*.f64 c i))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 y x) (*.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 c b) a)) (*.f64 c i))): 1 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 y x) (Rewrite<= *-commutative_binary64 (*.f64 (*.f64 c i) (+.f64 (*.f64 c b) a)))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 y x) (Rewrite<= associate-*r*_binary64 (*.f64 c (*.f64 i (+.f64 (*.f64 c b) a))))): 34 points increase in error, 26 points decrease in error
      (-.f64 (*.f64 y x) (*.f64 c (Rewrite=> distribute-rgt-in_binary64 (+.f64 (*.f64 (*.f64 c b) i) (*.f64 a i))))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 y x) (Rewrite=> distribute-lft-in_binary64 (+.f64 (*.f64 c (*.f64 (*.f64 c b) i)) (*.f64 c (*.f64 a i))))): 0 points increase in error, 1 points decrease in error
      (-.f64 (*.f64 y x) (+.f64 (*.f64 c (Rewrite=> associate-*l*_binary64 (*.f64 c (*.f64 b i)))) (*.f64 c (*.f64 a i)))): 20 points increase in error, 10 points decrease in error
      (-.f64 (*.f64 y x) (+.f64 (*.f64 c (*.f64 c (Rewrite<= *-commutative_binary64 (*.f64 i b)))) (*.f64 c (*.f64 a i)))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 y x) (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 c c) (*.f64 i b))) (*.f64 c (*.f64 a i)))): 32 points increase in error, 6 points decrease in error
      (-.f64 (*.f64 y x) (+.f64 (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 c 2)) (*.f64 i b)) (*.f64 c (*.f64 a i)))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 y x) (Rewrite<= cancel-sign-sub_binary64 (-.f64 (*.f64 (pow.f64 c 2) (*.f64 i b)) (*.f64 (neg.f64 c) (*.f64 a i))))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 y x) (-.f64 (*.f64 (pow.f64 c 2) (*.f64 i b)) (Rewrite=> distribute-lft-neg-out_binary64 (neg.f64 (*.f64 c (*.f64 a i)))))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 y x) (-.f64 (*.f64 (pow.f64 c 2) (*.f64 i b)) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (*.f64 c (*.f64 a i)))))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 y x) (-.f64 (*.f64 (pow.f64 c 2) (*.f64 i b)) (Rewrite=> mul-1-neg_binary64 (neg.f64 (*.f64 c (*.f64 a i)))))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 y x) (-.f64 (*.f64 (pow.f64 c 2) (*.f64 i b)) (Rewrite<= distribute-lft-neg-out_binary64 (*.f64 (neg.f64 c) (*.f64 a i))))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 y x) (Rewrite=> cancel-sign-sub_binary64 (+.f64 (*.f64 (pow.f64 c 2) (*.f64 i b)) (*.f64 c (*.f64 a i))))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 y x) (+.f64 (*.f64 (Rewrite=> unpow2_binary64 (*.f64 c c)) (*.f64 i b)) (*.f64 c (*.f64 a i)))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 y x) (+.f64 (Rewrite=> associate-*l*_binary64 (*.f64 c (*.f64 c (*.f64 i b)))) (*.f64 c (*.f64 a i)))): 6 points increase in error, 32 points decrease in error
      (-.f64 (*.f64 y x) (+.f64 (*.f64 c (*.f64 c (Rewrite=> *-commutative_binary64 (*.f64 b i)))) (*.f64 c (*.f64 a i)))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 y x) (+.f64 (*.f64 c (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 c b) i))) (*.f64 c (*.f64 a i)))): 10 points increase in error, 20 points decrease in error
      (-.f64 (*.f64 y x) (Rewrite<= distribute-lft-in_binary64 (*.f64 c (+.f64 (*.f64 (*.f64 c b) i) (*.f64 a i))))): 1 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 y x) (*.f64 c (Rewrite<= distribute-rgt-in_binary64 (*.f64 i (+.f64 (*.f64 c b) a))))): 0 points increase in error, 0 points decrease in error

    if -2.0000000000000001e238 < (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i) < 9.99999999999999986e306

    1. Initial program 0.3

      \[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right) \]

    if 9.99999999999999986e306 < (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i)

    1. Initial program 63.5

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

      \[\leadsto 2 \cdot \color{blue}{\left(t \cdot z - c \cdot \left(i \cdot \left(c \cdot b + a\right)\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.1

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

Alternatives

Alternative 1
Error1.7
Cost20096
\[2 \cdot \mathsf{fma}\left(z, t, \mathsf{fma}\left(\mathsf{fma}\left(b, c, a\right), c \cdot \left(-i\right), x \cdot y\right)\right) \]
Alternative 2
Error1.9
Cost2504
\[\begin{array}{l} t_1 := a + b \cdot c\\ t_2 := i \cdot \left(c \cdot t_1\right)\\ t_3 := c \cdot \left(i \cdot t_1\right)\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;2 \cdot \left(x \cdot y - t_3\right)\\ \mathbf{elif}\;t_2 \leq 10^{+307}:\\ \;\;\;\;2 \cdot \left(\left(x \cdot y + z \cdot t\right) - t_2\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(z \cdot t - t_3\right)\\ \end{array} \]
Alternative 3
Error22.6
Cost1892
\[\begin{array}{l} t_1 := 2 \cdot \left(x \cdot y + z \cdot t\right)\\ t_2 := 2 \cdot \left(x \cdot y - c \cdot \left(a \cdot i\right)\right)\\ t_3 := \left(c \cdot \left(i \cdot \left(a + b \cdot c\right)\right)\right) \cdot -2\\ \mathbf{if}\;c \leq -1.12 \cdot 10^{+125}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;c \leq -2.4 \cdot 10^{+61}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -1.7 \cdot 10^{+28}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;c \leq -3.872712674595726 \cdot 10^{-128}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -2.52143899907966 \cdot 10^{-182}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq 4.024986954537281 \cdot 10^{-63}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 1.634196644480658 \cdot 10^{-42}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;c \leq 25000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 2.2 \cdot 10^{+74}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 4
Error21.1
Cost1496
\[\begin{array}{l} t_1 := 2 \cdot \left(x \cdot y + z \cdot t\right)\\ t_2 := \left(c \cdot \left(i \cdot \left(a + b \cdot c\right)\right)\right) \cdot -2\\ \mathbf{if}\;c \leq -1.12 \cdot 10^{+125}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq -2.4 \cdot 10^{+61}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -1.7 \cdot 10^{+28}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq 4.024986954537281 \cdot 10^{-63}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 1.634196644480658 \cdot 10^{-42}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq 2.2 \cdot 10^{+74}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error9.2
Cost1488
\[\begin{array}{l} t_1 := 2 \cdot \left(z \cdot t - c \cdot \left(i \cdot \left(a + b \cdot c\right)\right)\right)\\ t_2 := 2 \cdot \left(\left(x \cdot y + z \cdot t\right) - i \cdot \left(c \cdot a\right)\right)\\ \mathbf{if}\;c \leq -1.12 \cdot 10^{+125}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -2.4 \cdot 10^{+61}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq -1.7 \cdot 10^{+28}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 3.6 \cdot 10^{+59}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error40.6
Cost1372
\[\begin{array}{l} t_1 := z \cdot \left(2 \cdot t\right)\\ t_2 := 2 \cdot \left(x \cdot y\right)\\ t_3 := -2 \cdot \left(a \cdot \left(c \cdot i\right)\right)\\ \mathbf{if}\;a \leq -2.02 \cdot 10^{+192}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq -2.2220988540082718 \cdot 10^{+136}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -3.987461604905332 \cdot 10^{+76}:\\ \;\;\;\;c \cdot \left(i \cdot \left(a \cdot -2\right)\right)\\ \mathbf{elif}\;a \leq -34988116198952018000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 4.353064554859461 \cdot 10^{-111}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 6.543879599907343 \cdot 10^{-54}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 6.196930758261767 \cdot 10^{+75}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 7
Error11.1
Cost1224
\[\begin{array}{l} t_1 := \left(c \cdot \left(i \cdot \left(a + b \cdot c\right)\right)\right) \cdot -2\\ \mathbf{if}\;c \leq -1.12 \cdot 10^{+125}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 3.6 \cdot 10^{+59}:\\ \;\;\;\;2 \cdot \left(\left(x \cdot y + z \cdot t\right) - i \cdot \left(c \cdot a\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error8.8
Cost1224
\[\begin{array}{l} t_1 := 2 \cdot \left(x \cdot y - c \cdot \left(i \cdot \left(a + b \cdot c\right)\right)\right)\\ \mathbf{if}\;c \leq -1.3 \cdot 10^{+15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 9.5 \cdot 10^{+20}:\\ \;\;\;\;2 \cdot \left(\left(x \cdot y + z \cdot t\right) - i \cdot \left(c \cdot a\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error22.6
Cost972
\[\begin{array}{l} t_1 := 2 \cdot \left(x \cdot y + z \cdot t\right)\\ \mathbf{if}\;c \leq -1.12 \cdot 10^{+125}:\\ \;\;\;\;-2 \cdot \left(c \cdot \left(i \cdot \left(b \cdot c\right)\right)\right)\\ \mathbf{elif}\;c \leq 2.1 \cdot 10^{+103}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 1.55 \cdot 10^{+217}:\\ \;\;\;\;\left(c \cdot \left(b \cdot i\right)\right) \cdot \left(c \cdot -2\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error38.7
Cost848
\[\begin{array}{l} t_1 := 2 \cdot \left(x \cdot y\right)\\ t_2 := z \cdot \left(2 \cdot t\right)\\ \mathbf{if}\;t \leq -3.273918911369525 \cdot 10^{-167}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 2.8671985525503355 \cdot 10^{+33}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.45 \cdot 10^{+115}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 2.75 \cdot 10^{+214}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 11
Error23.0
Cost708
\[\begin{array}{l} \mathbf{if}\;a \leq -2.02 \cdot 10^{+192}:\\ \;\;\;\;-2 \cdot \left(a \cdot \left(c \cdot i\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(x \cdot y + z \cdot t\right)\\ \end{array} \]
Alternative 12
Error42.5
Cost320
\[z \cdot \left(2 \cdot t\right) \]

Error

Reproduce

herbie shell --seed 2022300 
(FPCore (x y z t a b c i)
  :name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, A"
  :precision binary64

  :herbie-target
  (* 2.0 (- (+ (* x y) (* z t)) (* (+ a (* b c)) (* c i))))

  (* 2.0 (- (+ (* x y) (* z t)) (* (* (+ a (* b c)) c) i))))