?

Average Error: 6.6 → 1.8
Time: 26.3s
Precision: binary64
Cost: 20096

?

\[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 \cdot \mathsf{fma}\left(-\mathsf{fma}\left(b, c, a\right), c \cdot i, \mathsf{fma}\left(x, y, z \cdot t\right)\right) \]
(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
 (* 2.0 (fma (- (fma b c a)) (* c i) (fma x y (* z t)))))
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) {
	return 2.0 * fma(-fma(b, c, a), (c * i), fma(x, y, (z * t)));
}
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)
	return Float64(2.0 * fma(Float64(-fma(b, c, a)), Float64(c * i), fma(x, y, Float64(z * t))))
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_] := N[(2.0 * N[((-N[(b * c + a), $MachinePrecision]) * N[(c * i), $MachinePrecision] + N[(x * y + N[(z * t), $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)
2 \cdot \mathsf{fma}\left(-\mathsf{fma}\left(b, c, a\right), c \cdot i, \mathsf{fma}\left(x, y, z \cdot t\right)\right)

Error?

Target

Original6.6
Target1.8
Herbie1.8
\[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. Initial program 6.6

    \[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. Simplified1.8

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

    [Start]6.6

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

    sub-neg [=>]6.6

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

    +-commutative [=>]6.6

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

    associate-*l* [=>]1.8

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

    distribute-lft-neg-in [=>]1.8

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

    fma-def [=>]1.8

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

    +-commutative [=>]1.8

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

    fma-def [=>]1.8

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

    fma-def [=>]1.8

    \[ 2 \cdot \mathsf{fma}\left(-\mathsf{fma}\left(b, c, a\right), c \cdot i, \color{blue}{\mathsf{fma}\left(x, y, z \cdot t\right)}\right) \]
  3. Final simplification1.8

    \[\leadsto 2 \cdot \mathsf{fma}\left(-\mathsf{fma}\left(b, c, a\right), c \cdot i, \mathsf{fma}\left(x, y, z \cdot t\right)\right) \]

Alternatives

Alternative 1
Error10.3
Cost3536
\[\begin{array}{l} t_1 := a + b \cdot c\\ t_2 := i \cdot \left(c \cdot t_1\right)\\ t_3 := 2 \cdot \left(z \cdot t - t_2\right)\\ \mathbf{if}\;t_2 \leq -1 \cdot 10^{+292}:\\ \;\;\;\;\left(c \cdot \left(a \cdot i + c \cdot \left(b \cdot i\right)\right)\right) \cdot -2\\ \mathbf{elif}\;t_2 \leq -4 \cdot 10^{-32}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_2 \leq 2 \cdot 10^{+37}:\\ \;\;\;\;2 \cdot \left(x \cdot y + z \cdot t\right)\\ \mathbf{elif}\;t_2 \leq 4 \cdot 10^{+303}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(c \cdot \left(i \cdot t_1\right)\right)\\ \end{array} \]
Alternative 2
Error7.3
Cost2504
\[\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^{+105}:\\ \;\;\;\;2 \cdot \left(z \cdot t - \left(c \cdot i\right) \cdot t_1\right)\\ \mathbf{elif}\;t_2 \leq 4 \cdot 10^{+29}:\\ \;\;\;\;2 \cdot \left(\left(x \cdot y + z \cdot t\right) + c \cdot \frac{-1}{\frac{1}{a \cdot i}}\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(x \cdot y + t_1 \cdot \frac{c}{\frac{-1}{i}}\right)\\ \end{array} \]
Alternative 3
Error2.1
Cost2504
\[\begin{array}{l} t_1 := a + b \cdot c\\ t_2 := i \cdot \left(c \cdot t_1\right)\\ \mathbf{if}\;t_2 \leq -1 \cdot 10^{+292}:\\ \;\;\;\;2 \cdot \left(x \cdot y - c \cdot \left(a \cdot i + c \cdot \left(b \cdot i\right)\right)\right)\\ \mathbf{elif}\;t_2 \leq 2 \cdot 10^{+218}:\\ \;\;\;\;2 \cdot \left(\left(x \cdot y + z \cdot t\right) - t_2\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(x \cdot y + t_1 \cdot \frac{c}{\frac{-1}{i}}\right)\\ \end{array} \]
Alternative 4
Error7.1
Cost2376
\[\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^{+105}:\\ \;\;\;\;2 \cdot \left(z \cdot t - \left(c \cdot i\right) \cdot t_1\right)\\ \mathbf{elif}\;t_2 \leq 4 \cdot 10^{+29}:\\ \;\;\;\;2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \frac{c \cdot i}{\frac{1}{a}}\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(x \cdot y + t_1 \cdot \frac{c}{\frac{-1}{i}}\right)\\ \end{array} \]
Alternative 5
Error10.0
Cost2249
\[\begin{array}{l} t_1 := a + b \cdot c\\ t_2 := i \cdot \left(c \cdot t_1\right)\\ \mathbf{if}\;t_2 \leq -4 \cdot 10^{-32} \lor \neg \left(t_2 \leq 2 \cdot 10^{+37}\right):\\ \;\;\;\;2 \cdot \left(z \cdot t - \left(c \cdot i\right) \cdot t_1\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(x \cdot y + z \cdot t\right)\\ \end{array} \]
Alternative 6
Error7.9
Cost2129
\[\begin{array}{l} t_1 := 2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \frac{c \cdot i}{\frac{1}{a}}\right)\\ \mathbf{if}\;x \cdot y \leq -5 \cdot 10^{-90}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{-207}:\\ \;\;\;\;2 \cdot \left(z \cdot t - \left(c \cdot i\right) \cdot \left(a + b \cdot c\right)\right)\\ \mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+20} \lor \neg \left(x \cdot y \leq 5 \cdot 10^{+31}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(x \cdot y - c \cdot \left(a \cdot i + c \cdot \left(b \cdot i\right)\right)\right)\\ \end{array} \]
Alternative 7
Error21.6
Cost1498
\[\begin{array}{l} \mathbf{if}\;c \leq -7.5 \cdot 10^{+117}:\\ \;\;\;\;2 \cdot \left(z \cdot t - a \cdot \left(c \cdot i\right)\right)\\ \mathbf{elif}\;c \leq -1.02 \cdot 10^{+19}:\\ \;\;\;\;2 \cdot \left(x \cdot y - \left(b \cdot i\right) \cdot \left(c \cdot c\right)\right)\\ \mathbf{elif}\;c \leq -1.35 \cdot 10^{-27} \lor \neg \left(c \leq 8.8 \cdot 10^{-24}\right) \land \left(c \leq 76000 \lor \neg \left(c \leq 1.95 \cdot 10^{+37}\right)\right):\\ \;\;\;\;-2 \cdot \left(c \cdot \left(i \cdot \left(a + b \cdot c\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(x \cdot y + z \cdot t\right)\\ \end{array} \]
Alternative 8
Error37.7
Cost1376
\[\begin{array}{l} t_1 := 2 \cdot \left(x \cdot y\right)\\ t_2 := 2 \cdot \left(z \cdot t\right)\\ t_3 := a \cdot \left(c \cdot \left(i \cdot -2\right)\right)\\ \mathbf{if}\;z \leq -6.5 \cdot 10^{+143}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -6.2 \cdot 10^{+78}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -9.5 \cdot 10^{+55}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -8500:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -3.05 \cdot 10^{-12}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.55 \cdot 10^{-127}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -8.2 \cdot 10^{-184}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 1.14 \cdot 10^{-94}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 9
Error23.1
Cost1237
\[\begin{array}{l} t_1 := 2 \cdot \left(x \cdot y + z \cdot t\right)\\ \mathbf{if}\;a \leq -1.85 \cdot 10^{+250}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -2.05 \cdot 10^{+219}:\\ \;\;\;\;\left(a \cdot i\right) \cdot \left(c \cdot -2\right)\\ \mathbf{elif}\;a \leq 6.2 \cdot 10^{+129} \lor \neg \left(a \leq 7.9 \cdot 10^{+186}\right) \land a \leq 1.45 \cdot 10^{+231}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(c \cdot \left(i \cdot -2\right)\right)\\ \end{array} \]
Alternative 10
Error21.1
Cost1234
\[\begin{array}{l} \mathbf{if}\;c \leq -1.55 \cdot 10^{-27} \lor \neg \left(c \leq 5.8 \cdot 10^{-24}\right) \land \left(c \leq 34000 \lor \neg \left(c \leq 5 \cdot 10^{+37}\right)\right):\\ \;\;\;\;-2 \cdot \left(c \cdot \left(i \cdot \left(a + b \cdot c\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(x \cdot y + z \cdot t\right)\\ \end{array} \]
Alternative 11
Error21.0
Cost1232
\[\begin{array}{l} t_1 := 2 \cdot \left(x \cdot y + z \cdot t\right)\\ t_2 := \left(c \cdot \left(a \cdot i + c \cdot \left(b \cdot i\right)\right)\right) \cdot -2\\ \mathbf{if}\;c \leq -1.55 \cdot 10^{-27}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq 8.5 \cdot 10^{-24}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 34000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq 2.1 \cdot 10^{+37}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(c \cdot \left(i \cdot \left(a + b \cdot c\right)\right)\right)\\ \end{array} \]
Alternative 12
Error1.8
Cost1216
\[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(c \cdot i\right) \cdot \left(a + b \cdot c\right)\right) \]
Alternative 13
Error36.7
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -2.2 \cdot 10^{-21} \lor \neg \left(x \leq 1.6 \cdot 10^{-184}\right):\\ \;\;\;\;2 \cdot \left(x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(z \cdot t\right)\\ \end{array} \]
Alternative 14
Error42.1
Cost320
\[2 \cdot \left(z \cdot t\right) \]
Alternative 15
Error62.2
Cost64
\[0 \]

Error

Reproduce?

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