Average Error: 19.0 → 13.0
Time: 26.5s
Precision: 64
Internal Precision: 128
\[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
\[\begin{array}{l} \mathbf{if}\;b \le 7.4121645311061 \cdot 10^{+111}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{\sqrt[3]{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}} \cdot \left|\sqrt[3]{(\left(c \cdot -4\right) \cdot a + \left(b \cdot b\right))_*}\right| - b}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*} - b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if b < 7.4121645311061e+111

    1. Initial program 14.4

      \[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
    2. Initial simplification14.4

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*} - b}\\ \end{array}\]
    3. Using strategy rm
    4. Applied add-cube-cbrt14.6

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\color{blue}{2} \cdot c}{\sqrt{\left(\sqrt[3]{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*} \cdot \sqrt[3]{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}\right) \cdot \sqrt[3]{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}} - b}\\ \end{array}\]
    5. Applied sqrt-prod14.6

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\color{blue}{2 \cdot c}}{\sqrt{\sqrt[3]{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*} \cdot \sqrt[3]{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}} \cdot \sqrt{\sqrt[3]{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}} - b}\\ \end{array}\]
    6. Simplified14.6

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\color{blue}{2} \cdot c}{\left|\sqrt[3]{(\left(c \cdot -4\right) \cdot a + \left(b \cdot b\right))_*}\right| \cdot \sqrt{\sqrt[3]{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}} - b}\\ \end{array}\]

    if 7.4121645311061e+111 < b

    1. Initial program 46.5

      \[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
    2. Initial simplification46.5

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*} - b}\\ \end{array}\]
    3. Taylor expanded around 0 3.0

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \color{blue}{b}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*} - b}\\ \end{array}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification13.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le 7.4121645311061 \cdot 10^{+111}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{\sqrt[3]{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}} \cdot \left|\sqrt[3]{(\left(c \cdot -4\right) \cdot a + \left(b \cdot b\right))_*}\right| - b}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*} - b}\\ \end{array}\]

Reproduce

herbie shell --seed 2018360 +o rules:numerics
(FPCore (a b c)
  :name "jeff quadratic root 1"
  (if (>= b 0) (/ (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)) (/ (* 2 c) (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))))))

Details

Time bar (total: 19.0s)Debug log

start178.0ms

Algorithm
intervals

setup139.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 17.8b

localize144.0ms

Local error

Found 4 expressions with local error:

22.7b
(sqrt (fma c (* a -4) (* b b)))
22.7b
(sqrt (fma c (* a -4) (* b b)))
0.9b
(- (sqrt (fma c (* a -4) (* b b))) b)
0.8b
(- (- b) (sqrt (fma c (* a -4) (* b b))))

rewrite19.0ms

Algorithm
rewrite-expression-head
Counts
4 → 93
Calls

4 calls. Slowest were:

10.0ms
(- (- b) (sqrt (fma c (* a -4) (* b b))))
5.0ms
(- (sqrt (fma c (* a -4) (* b b))) b)
1.0ms
(sqrt (fma c (* a -4) (* b b)))

series260.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

77.0ms
(sqrt (fma c (* a -4) (* b b)))
67.0ms
(sqrt (fma c (* a -4) (* b b)))
64.0ms
(- (sqrt (fma c (* a -4) (* b b))) b)
52.0ms
(- (- b) (sqrt (fma c (* a -4) (* b b))))

simplify2.1s

Counts
81 → 105
Calls

81 calls. Slowest were:

90.0ms
(- (* 2 (/ (* a c) b)) (* 2 b))
58.0ms
(fma 1 (- b) (- (* (sqrt (fma c (* a -4) (* b b))) 1)))
56.0ms
(fma 1 (- b) (- (* (cbrt (sqrt (fma c (* a -4) (* b b)))) (* (cbrt (sqrt (fma c (* a -4) (* b b)))) (cbrt (sqrt (fma c (* a -4) (* b b))))))))

prune2.0s

Pruning

12 alts after pruning (12 fresh and 0 done)

Merged error: 11.9b

localize142.0ms

Local error

Found 4 expressions with local error:

22.7b
(sqrt (fma c (* a -4) (* b b)))
22.7b
(sqrt (fma c (* a -4) (* b b)))
22.7b
(sqrt (fma c (* a -4) (* b b)))
0.9b
(- (sqrt (fma c (* a -4) (* b b))) b)

rewrite8.0ms

Algorithm
rewrite-expression-head
Counts
4 → 61
Calls

4 calls. Slowest were:

5.0ms
(- (sqrt (fma c (* a -4) (* b b))) b)
1.0ms
(sqrt (fma c (* a -4) (* b b)))
1.0ms
(sqrt (fma c (* a -4) (* b b)))

series218.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

61.0ms
(- (sqrt (fma c (* a -4) (* b b))) b)
60.0ms
(sqrt (fma c (* a -4) (* b b)))
55.0ms
(sqrt (fma c (* a -4) (* b b)))
41.0ms
(sqrt (fma c (* a -4) (* b b)))

simplify188.0ms

Counts
29 → 73
Calls

29 calls. Slowest were:

19.0ms
(sqrt (sqrt (fma c (* a -4) (* b b))))
19.0ms
(sqrt (sqrt (fma c (* a -4) (* b b))))
18.0ms
(sqrt (fma c (* a -4) (* b b)))

prune1.8s

Pruning

12 alts after pruning (12 fresh and 0 done)

Merged error: 11.9b

localize185.0ms

Local error

Found 4 expressions with local error:

23.4b
(cbrt (fma c (* a -4) (* b b)))
23.4b
(cbrt (fma (* c -4) a (* b b)))
22.7b
(sqrt (fma c (* a -4) (* b b)))
7.0b
(- (* (fabs (cbrt (fma (* c -4) a (* b b)))) (sqrt (cbrt (fma c (* a -4) (* b b))))) b)

rewrite17.0ms

Algorithm
rewrite-expression-head
Counts
4 → 54
Calls

4 calls. Slowest were:

12.0ms
(- (* (fabs (cbrt (fma (* c -4) a (* b b)))) (sqrt (cbrt (fma c (* a -4) (* b b))))) b)
1.0ms
(sqrt (fma c (* a -4) (* b b)))
1.0ms
(cbrt (fma c (* a -4) (* b b)))

series694.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

249.0ms
(- (* (fabs (cbrt (fma (* c -4) a (* b b)))) (sqrt (cbrt (fma c (* a -4) (* b b))))) b)
193.0ms
(cbrt (fma c (* a -4) (* b b)))
186.0ms
(cbrt (fma (* c -4) a (* b b)))
65.0ms
(sqrt (fma c (* a -4) (* b b)))

simplify2.7s

Counts
23 → 66
Calls

23 calls. Slowest were:

421.0ms
(- (* (exp (* 1/6 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c)))))) (fabs (pow (fma (* -4 c) a (pow b 2)) 1/3))) b)
358.0ms
(exp (* 1/3 (- (log -4) (+ (log (/ -1 c)) (log (/ -1 a))))))
344.0ms
(exp (* 1/3 (- (log -4) (+ (log (/ -1 c)) (log (/ -1 a))))))

prune2.1s

Pruning

13 alts after pruning (12 fresh and 1 done)

Merged error: 11.9b

localize181.0ms

Local error

Found 4 expressions with local error:

23.4b
(cbrt (fma (* a -4) c (* b b)))
23.4b
(cbrt (fma (* a -4) c (* b b)))
23.3b
(fma (fabs (cbrt (fma (* a -4) c (* b b)))) (sqrt (cbrt (fma (* a -4) c (* b b)))) b)
22.7b
(sqrt (fma c (* a -4) (* b b)))

rewrite5.0ms

Algorithm
rewrite-expression-head
Counts
4 → 50
Calls

4 calls. Slowest were:

1.0ms
(sqrt (fma c (* a -4) (* b b)))
1.0ms
(cbrt (fma (* a -4) c (* b b)))
1.0ms
(cbrt (fma (* a -4) c (* b b)))

series847.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

338.0ms
(fma (fabs (cbrt (fma (* a -4) c (* b b)))) (sqrt (cbrt (fma (* a -4) c (* b b)))) b)
235.0ms
(cbrt (fma (* a -4) c (* b b)))
207.0ms
(cbrt (fma (* a -4) c (* b b)))
67.0ms
(sqrt (fma c (* a -4) (* b b)))

simplify2.7s

Counts
22 → 62
Calls

22 calls. Slowest were:

379.0ms
(+ (* (exp (* 1/6 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c)))))) (fabs (pow (fma (* -4 a) c (pow b 2)) 1/3))) b)
358.0ms
(+ (* (fabs (pow (fma (* -4 a) c (pow b 2)) 1/3)) (exp (* 1/6 (- (log -4) (+ (log (/ -1 c)) (log (/ -1 a))))))) b)
350.0ms
(exp (* 1/3 (- (log -4) (+ (log (/ -1 c)) (log (/ -1 a))))))

prune1.5s

Pruning

12 alts after pruning (11 fresh and 1 done)

Merged error: 11.9b

regimes616.0ms

Accuracy

91% (0.6b remaining)

Error of 13.0b against oracle of 12.4b and baseline of 19.1b

bsearch239.0ms