?

Average Error: 0.25% → 0.01%
Time: 14.8s
Precision: binary64
Cost: 19904

?

\[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
\[\mathsf{fma}\left(z, \frac{t}{16}, \mathsf{fma}\left(b, -0.25 \cdot a, \mathsf{fma}\left(x, y, c\right)\right)\right) \]
(FPCore (x y z t a b c)
 :precision binary64
 (+ (- (+ (* x y) (/ (* z t) 16.0)) (/ (* a b) 4.0)) c))
(FPCore (x y z t a b c)
 :precision binary64
 (fma z (/ t 16.0) (fma b (* -0.25 a) (fma x y c))))
double code(double x, double y, double z, double t, double a, double b, double c) {
	return (((x * y) + ((z * t) / 16.0)) - ((a * b) / 4.0)) + c;
}
double code(double x, double y, double z, double t, double a, double b, double c) {
	return fma(z, (t / 16.0), fma(b, (-0.25 * a), fma(x, y, c)));
}
function code(x, y, z, t, a, b, c)
	return Float64(Float64(Float64(Float64(x * y) + Float64(Float64(z * t) / 16.0)) - Float64(Float64(a * b) / 4.0)) + c)
end
function code(x, y, z, t, a, b, c)
	return fma(z, Float64(t / 16.0), fma(b, Float64(-0.25 * a), fma(x, y, c)))
end
code[x_, y_, z_, t_, a_, b_, c_] := N[(N[(N[(N[(x * y), $MachinePrecision] + N[(N[(z * t), $MachinePrecision] / 16.0), $MachinePrecision]), $MachinePrecision] - N[(N[(a * b), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_, c_] := N[(z * N[(t / 16.0), $MachinePrecision] + N[(b * N[(-0.25 * a), $MachinePrecision] + N[(x * y + c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c
\mathsf{fma}\left(z, \frac{t}{16}, \mathsf{fma}\left(b, -0.25 \cdot a, \mathsf{fma}\left(x, y, c\right)\right)\right)

Error?

Derivation?

  1. Initial program 0.25

    \[\left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]
  2. Simplified0.01

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

    [Start]0.25

    \[ \left(\left(x \cdot y + \frac{z \cdot t}{16}\right) - \frac{a \cdot b}{4}\right) + c \]

    associate-+l- [=>]0.25

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

    +-commutative [=>]0.25

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

    associate--l+ [=>]0.25

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

    associate-*r/ [<=]0.12

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

    *-commutative [<=]0.12

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

    *-commutative [=>]0.12

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

    fma-def [=>]0.11

    \[ \color{blue}{\mathsf{fma}\left(z, \frac{t}{16}, x \cdot y - \left(\frac{a \cdot b}{4} - c\right)\right)} \]

    associate--r- [=>]0.11

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

    +-commutative [=>]0.11

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

    associate-+r- [=>]0.11

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

    sub-neg [=>]0.11

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

    +-commutative [<=]0.11

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

    neg-mul-1 [=>]0.11

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

    associate-*l/ [<=]0.02

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

    associate-*r* [=>]0.02

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

    *-commutative [=>]0.02

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

    fma-def [=>]0.01

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

    associate-*r/ [=>]0.01

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

    associate-/l* [=>]0.07

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

    associate-/r/ [=>]0.01

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

    metadata-eval [=>]0.01

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

    +-commutative [=>]0.01

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

    fma-def [=>]0.01

    \[ \mathsf{fma}\left(z, \frac{t}{16}, \mathsf{fma}\left(b, -0.25 \cdot a, \color{blue}{\mathsf{fma}\left(x, y, c\right)}\right)\right) \]
  3. Final simplification0.01

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

Alternatives

Alternative 1
Error0.01%
Cost13632
\[\mathsf{fma}\left(x, y, \mathsf{fma}\left(t, \frac{z}{16}, c - a \cdot \frac{b}{4}\right)\right) \]
Alternative 2
Error37.99%
Cost3308
\[\begin{array}{l} t_1 := c + \left(z \cdot t\right) \cdot 0.0625\\ t_2 := -0.25 \cdot \left(b \cdot a\right)\\ t_3 := c + x \cdot y\\ \mathbf{if}\;b \cdot a \leq -6 \cdot 10^{+107}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \cdot a \leq -5.8 \cdot 10^{+68}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \cdot a \leq -1.3 \cdot 10^{+59}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \cdot a \leq -4.6 \cdot 10^{-14}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;b \cdot a \leq -6 \cdot 10^{-268}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \cdot a \leq 0:\\ \;\;\;\;t_3\\ \mathbf{elif}\;b \cdot a \leq 7 \cdot 10^{-220}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \cdot a \leq 4.2 \cdot 10^{-149}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;b \cdot a \leq 4.5 \cdot 10^{-37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \cdot a \leq 8 \cdot 10^{+69}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;b \cdot a \leq 5.5 \cdot 10^{+171}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error39.97%
Cost2161
\[\begin{array}{l} t_1 := \left(z \cdot t\right) \cdot 0.0625\\ t_2 := c + t_1\\ t_3 := t_1 + x \cdot y\\ t_4 := c + -0.25 \cdot \left(b \cdot a\right)\\ t_5 := c + x \cdot y\\ \mathbf{if}\;a \leq -7.2 \cdot 10^{+59}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;a \leq -2.1 \cdot 10^{+24}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq -3.2 \cdot 10^{-25}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -2.35 \cdot 10^{-31}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq -1.5 \cdot 10^{-47}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;a \leq -3.6 \cdot 10^{-68}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq -1.25 \cdot 10^{-166}:\\ \;\;\;\;t_5\\ \mathbf{elif}\;a \leq -2.45 \cdot 10^{-290}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 4.7 \cdot 10^{-265}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq 2.2 \cdot 10^{-182}:\\ \;\;\;\;t_5\\ \mathbf{elif}\;a \leq 2.1 \cdot 10^{-71} \lor \neg \left(a \leq 1.12 \cdot 10^{-39}\right):\\ \;\;\;\;t_4\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 4
Error32.93%
Cost2008
\[\begin{array}{l} t_1 := c + \left(z \cdot t\right) \cdot 0.0625\\ t_2 := c + -0.25 \cdot \left(b \cdot a\right)\\ t_3 := c + x \cdot y\\ \mathbf{if}\;b \cdot a \leq -6.8 \cdot 10^{-34}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \cdot a \leq -8.5 \cdot 10^{-268}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \cdot a \leq 0:\\ \;\;\;\;t_3\\ \mathbf{elif}\;b \cdot a \leq 8.6 \cdot 10^{-219}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \cdot a \leq 3.55 \cdot 10^{-149}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;b \cdot a \leq 0.000104:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error38.81%
Cost1620
\[\begin{array}{l} t_1 := c + x \cdot y\\ t_2 := -0.25 \cdot \left(b \cdot a\right)\\ \mathbf{if}\;b \cdot a \leq -1.15 \cdot 10^{+59}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \cdot a \leq -1.25 \cdot 10^{-12}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \cdot a \leq -7.2 \cdot 10^{-34}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \cdot a \leq -8.5 \cdot 10^{-78}:\\ \;\;\;\;\left(z \cdot t\right) \cdot 0.0625\\ \mathbf{elif}\;b \cdot a \leq 1.6 \cdot 10^{+177}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error56.19%
Cost1376
\[\begin{array}{l} t_1 := \left(z \cdot t\right) \cdot 0.0625\\ t_2 := -0.25 \cdot \left(b \cdot a\right)\\ \mathbf{if}\;c \leq -3.8 \cdot 10^{+56}:\\ \;\;\;\;c\\ \mathbf{elif}\;c \leq -3.1 \cdot 10^{-75}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;c \leq -1.7 \cdot 10^{-120}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -1.75 \cdot 10^{-182}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq -1.4 \cdot 10^{-229}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 7.5 \cdot 10^{-226}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq 2.6 \cdot 10^{-128}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 1.26 \cdot 10^{+113}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;c\\ \end{array} \]
Alternative 7
Error9.47%
Cost1225
\[\begin{array}{l} \mathbf{if}\;b \cdot a \leq -6.6 \cdot 10^{-34} \lor \neg \left(b \cdot a \leq 7 \cdot 10^{-5}\right):\\ \;\;\;\;\left(c + x \cdot y\right) + -0.25 \cdot \left(b \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;c + \left(\left(z \cdot t\right) \cdot 0.0625 + x \cdot y\right)\\ \end{array} \]
Alternative 8
Error13.44%
Cost1224
\[\begin{array}{l} t_1 := -0.25 \cdot \left(b \cdot a\right)\\ \mathbf{if}\;b \cdot a \leq -3.7 \cdot 10^{+109}:\\ \;\;\;\;x \cdot y + t_1\\ \mathbf{elif}\;b \cdot a \leq 1.45 \cdot 10^{+53}:\\ \;\;\;\;c + \left(\left(z \cdot t\right) \cdot 0.0625 + x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;c + t_1\\ \end{array} \]
Alternative 9
Error14.31%
Cost1224
\[\begin{array}{l} t_1 := -0.25 \cdot \left(b \cdot a\right)\\ t_2 := \left(z \cdot t\right) \cdot 0.0625\\ \mathbf{if}\;b \cdot a \leq -2.6 \cdot 10^{+109}:\\ \;\;\;\;x \cdot y + t_1\\ \mathbf{elif}\;b \cdot a \leq 2.8 \cdot 10^{+177}:\\ \;\;\;\;c + \left(t_2 + x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t_2 + t_1\\ \end{array} \]
Alternative 10
Error8.85%
Cost1224
\[\begin{array}{l} t_1 := \left(z \cdot t\right) \cdot 0.0625\\ t_2 := -0.25 \cdot \left(b \cdot a\right)\\ \mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+27}:\\ \;\;\;\;\left(c + t_1\right) + t_2\\ \mathbf{elif}\;z \cdot t \leq 4 \cdot 10^{+70}:\\ \;\;\;\;\left(c + x \cdot y\right) + t_2\\ \mathbf{else}:\\ \;\;\;\;c + \left(t_1 + x \cdot y\right)\\ \end{array} \]
Alternative 11
Error0.25%
Cost1088
\[c + \left(\left(\frac{z \cdot t}{16} + x \cdot y\right) - \frac{b \cdot a}{4}\right) \]
Alternative 12
Error55.54%
Cost984
\[\begin{array}{l} t_1 := \left(z \cdot t\right) \cdot 0.0625\\ \mathbf{if}\;c \leq -9 \cdot 10^{+55}:\\ \;\;\;\;c\\ \mathbf{elif}\;c \leq -1.15 \cdot 10^{-73}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;c \leq -8.6 \cdot 10^{-106}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 6 \cdot 10^{-216}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;c \leq 2.9 \cdot 10^{-75}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 3800000000000:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;c\\ \end{array} \]
Alternative 13
Error55.82%
Cost456
\[\begin{array}{l} \mathbf{if}\;c \leq -4.7 \cdot 10^{+57}:\\ \;\;\;\;c\\ \mathbf{elif}\;c \leq 27000000000:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;c\\ \end{array} \]
Alternative 14
Error68.06%
Cost64
\[c \]

Error

Reproduce?

herbie shell --seed 2023088 
(FPCore (x y z t a b c)
  :name "Diagrams.Solve.Polynomial:quartForm  from diagrams-solve-0.1, C"
  :precision binary64
  (+ (- (+ (* x y) (/ (* z t) 16.0)) (/ (* a b) 4.0)) c))