Average Error: 6.4 → 1.8
Time: 19.1s
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(z, t, \mathsf{fma}\left(\mathsf{fma}\left(b, c, a\right), i \cdot \left(-c\right), x \cdot y\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 z t (fma (fma b c a) (* i (- c)) (* x y)))))
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(z, t, fma(fma(b, c, a), (i * -c), (x * y)));
}
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(z, t, fma(fma(b, c, a), Float64(i * Float64(-c)), Float64(x * y))))
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[(z * t + N[(N[(b * c + a), $MachinePrecision] * N[(i * (-c)), $MachinePrecision] + N[(x * y), $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(z, t, \mathsf{fma}\left(\mathsf{fma}\left(b, c, a\right), i \cdot \left(-c\right), x \cdot y\right)\right)

Error

Target

Original6.4
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.4

    \[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(z, t, \mathsf{fma}\left(\mathsf{fma}\left(b, c, a\right), i \cdot \left(-c\right), x \cdot y\right)\right)} \]
    Proof
    (*.f64 2 (fma.f64 z t (fma.f64 (fma.f64 b c a) (*.f64 i (neg.f64 c)) (*.f64 x y)))): 0 points increase in error, 0 points decrease in error
    (*.f64 2 (fma.f64 z t (fma.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 b c) a)) (*.f64 i (neg.f64 c)) (*.f64 x y)))): 0 points increase in error, 0 points decrease in error
    (*.f64 2 (fma.f64 z t (fma.f64 (Rewrite<= +-commutative_binary64 (+.f64 a (*.f64 b c))) (*.f64 i (neg.f64 c)) (*.f64 x y)))): 0 points increase in error, 0 points decrease in error
    (*.f64 2 (fma.f64 z t (fma.f64 (+.f64 a (*.f64 b c)) (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 i c))) (*.f64 x y)))): 0 points increase in error, 0 points decrease in error
    (*.f64 2 (fma.f64 z t (fma.f64 (+.f64 a (*.f64 b c)) (neg.f64 (Rewrite<= *-commutative_binary64 (*.f64 c i))) (*.f64 x y)))): 0 points increase in error, 0 points decrease in error
    (*.f64 2 (fma.f64 z t (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (+.f64 a (*.f64 b c)) (neg.f64 (*.f64 c i))) (*.f64 x y))))): 0 points increase in error, 1 points decrease in error
    (*.f64 2 (fma.f64 z t (+.f64 (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 (+.f64 a (*.f64 b c)) (*.f64 c i)))) (*.f64 x y)))): 0 points increase in error, 0 points decrease in error
    (*.f64 2 (fma.f64 z t (+.f64 (neg.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i))) (*.f64 x y)))): 32 points increase in error, 6 points decrease in error
    (*.f64 2 (fma.f64 z t (+.f64 (Rewrite=> neg-sub0_binary64 (-.f64 0 (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i))) (*.f64 x y)))): 0 points increase in error, 0 points decrease in error
    (*.f64 2 (fma.f64 z t (Rewrite=> associate-+l-_binary64 (-.f64 0 (-.f64 (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i) (*.f64 x y)))))): 0 points increase in error, 0 points decrease in error
    (*.f64 2 (fma.f64 z t (Rewrite<= neg-sub0_binary64 (neg.f64 (-.f64 (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i) (*.f64 x y)))))): 0 points increase in error, 0 points decrease in error
    (*.f64 2 (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 z t) (-.f64 (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i) (*.f64 x y))))): 2 points increase in error, 0 points decrease in error
    (*.f64 2 (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 (*.f64 z t) (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i)) (*.f64 x y)))): 0 points increase in error, 0 points decrease in error
    (*.f64 2 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 x y) (-.f64 (*.f64 z t) (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i))))): 0 points increase in error, 0 points decrease in error
    (*.f64 2 (Rewrite<= associate--l+_binary64 (-.f64 (+.f64 (*.f64 x y) (*.f64 z t)) (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i)))): 0 points increase in error, 0 points decrease in error
  3. Final simplification1.8

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

Alternatives

Alternative 1
Error2.4
Cost2248
\[\begin{array}{l} t_1 := a + b \cdot c\\ t_2 := c \cdot t_1\\ \mathbf{if}\;t_2 \leq -2 \cdot 10^{+290}:\\ \;\;\;\;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^{+214}:\\ \;\;\;\;2 \cdot \left(\left(x \cdot y + z \cdot t\right) - i \cdot t_2\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(x \cdot y - c \cdot \left(i \cdot t_1\right)\right)\\ \end{array} \]
Alternative 2
Error17.7
Cost1620
\[\begin{array}{l} t_1 := c \cdot \left(i \cdot \left(a + b \cdot c\right)\right)\\ t_2 := 2 \cdot \left(x \cdot y - t_1\right)\\ t_3 := 2 \cdot \left(x \cdot y + z \cdot t\right)\\ \mathbf{if}\;z \leq -3.3 \cdot 10^{+168}:\\ \;\;\;\;2 \cdot \left(z \cdot t - t_1\right)\\ \mathbf{elif}\;z \leq -1.95 \cdot 10^{+45}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -6.2 \cdot 10^{+23}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2 \cdot 10^{-12}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 6.2 \cdot 10^{-65}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 3
Error37.3
Cost1508
\[\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(i \cdot \left(c \cdot -2\right)\right)\\ \mathbf{if}\;z \leq -1.85 \cdot 10^{+110}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -6.1 \cdot 10^{+56}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.45 \cdot 10^{+44}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -104000:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -1.36 \cdot 10^{-8}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.25 \cdot 10^{-38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.9 \cdot 10^{-65}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -8.5 \cdot 10^{-109}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 3.4 \cdot 10^{-38}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error16.6
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(x \cdot y + z \cdot t\right)\\ \mathbf{if}\;c \leq -4.8 \cdot 10^{-73}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 2.2 \cdot 10^{-66}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq 2.2 \cdot 10^{+72}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 6.5 \cdot 10^{+140}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error9.0
Cost1488
\[\begin{array}{l} t_1 := c \cdot \left(i \cdot \left(a + b \cdot c\right)\right)\\ t_2 := 2 \cdot \left(z \cdot t - t_1\right)\\ t_3 := 2 \cdot \left(x \cdot y - t_1\right)\\ \mathbf{if}\;c \leq -1.72 \cdot 10^{+75}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;c \leq 9.8 \cdot 10^{-48}:\\ \;\;\;\;2 \cdot \left(\left(x \cdot y + z \cdot t\right) - i \cdot \left(c \cdot a\right)\right)\\ \mathbf{elif}\;c \leq 2.5 \cdot 10^{+90}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq 2.9 \cdot 10^{+157}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error20.6
Cost1364
\[\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 -2.4 \cdot 10^{+27}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq 162:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 9.5 \cdot 10^{+38}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq 7.3 \cdot 10^{+157}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 6.2 \cdot 10^{+245}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error20.9
Cost1360
\[\begin{array}{l} t_1 := 2 \cdot \left(z \cdot t - c \cdot \left(c \cdot \left(b \cdot i\right)\right)\right)\\ t_2 := 2 \cdot \left(x \cdot y + z \cdot t\right)\\ \mathbf{if}\;c \leq -2.3 \cdot 10^{+27}:\\ \;\;\;\;\left(c \cdot \left(i \cdot \left(a + b \cdot c\right)\right)\right) \cdot -2\\ \mathbf{elif}\;c \leq 1.15 \cdot 10^{-47}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq 6.8 \cdot 10^{+33}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 6.7 \cdot 10^{+140}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error8.5
Cost1352
\[\begin{array}{l} t_1 := x \cdot y + z \cdot t\\ \mathbf{if}\;c \leq -1.1 \cdot 10^{+80}:\\ \;\;\;\;2 \cdot \left(x \cdot y - c \cdot \left(i \cdot \left(a + b \cdot c\right)\right)\right)\\ \mathbf{elif}\;c \leq 2.55 \cdot 10^{-31}:\\ \;\;\;\;2 \cdot \left(t_1 - i \cdot \left(c \cdot a\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(t_1 - c \cdot \left(c \cdot \left(b \cdot i\right)\right)\right)\\ \end{array} \]
Alternative 9
Error1.8
Cost1216
\[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(a + b \cdot c\right) \cdot \left(c \cdot i\right)\right) \]
Alternative 10
Error36.3
Cost848
\[\begin{array}{l} t_1 := 2 \cdot \left(x \cdot y\right)\\ t_2 := 2 \cdot \left(z \cdot t\right)\\ \mathbf{if}\;z \leq -9 \cdot 10^{+110}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.02 \cdot 10^{+57}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.2 \cdot 10^{-8}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-43}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 11
Error23.4
Cost708
\[\begin{array}{l} \mathbf{if}\;a \leq -4 \cdot 10^{+124}:\\ \;\;\;\;a \cdot \left(i \cdot \left(c \cdot -2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(x \cdot y + z \cdot t\right)\\ \end{array} \]
Alternative 12
Error42.3
Cost320
\[2 \cdot \left(z \cdot t\right) \]

Error

Reproduce

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