Average Error: 19.5 → 13.1
Time: 21.0s
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 2.6985622642685762 \cdot 10^{+103}:\\ \;\;\;\;\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}{(\left(\sqrt{\sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}}\right) \cdot \left(\sqrt{\sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}}\right) + \left(-b\right))_*}\\ \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 < 2.6985622642685762e+103

    1. Initial program 14.7

      \[\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. Simplified14.7

      \[\leadsto \color{blue}{\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-sqr-sqrt14.7

      \[\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{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*} \cdot \sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}} - b}\\ \end{array}\]
    5. Applied sqrt-prod14.8

      \[\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{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}} \cdot \sqrt{\sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}} - b}\\ \end{array}\]
    6. Applied fma-neg14.7

      \[\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}:\\ \;\;\;\;\color{blue}{\frac{2 \cdot c}{(\left(\sqrt{\sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}}\right) \cdot \left(\sqrt{\sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}}\right) + \left(-b\right))_*}}\\ \end{array}\]

    if 2.6985622642685762e+103 < b

    1. Initial program 45.6

      \[\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. Simplified45.6

      \[\leadsto \color{blue}{\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 4.3

      \[\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.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le 2.6985622642685762 \cdot 10^{+103}:\\ \;\;\;\;\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}{(\left(\sqrt{\sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}}\right) \cdot \left(\sqrt{\sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}}\right) + \left(-b\right))_*}\\ \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 2019008 +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.8s)Debug log

sample142.0ms

Algorithm
intervals

simplify105.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

104.0ms
(if (>= b 0) (/ (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)) (/ (* 2 c) (+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))))

prune26.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 20.0b

localize147.0ms

Local error

Found 4 expressions with local error:

23.7b
(sqrt (fma c (* a -4) (* b b)))
23.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))))

rewrite23.0ms

Algorithm
rewrite-expression-head
Counts
4 → 93
Calls

4 calls. Slowest were:

10.0ms
(- (sqrt (fma c (* a -4) (* b b))) b)
9.0ms
(- (- b) (sqrt (fma c (* a -4) (* b b))))
2.0ms
(sqrt (fma c (* a -4) (* b b)))

series216.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

70.0ms
(sqrt (fma c (* a -4) (* b b)))
55.0ms
(- (- b) (sqrt (fma c (* a -4) (* b b))))
49.0ms
(- (sqrt (fma c (* a -4) (* b b))) b)
42.0ms
(sqrt (fma c (* a -4) (* b b)))

simplify2.2s

Counts
81 → 105
Calls

81 calls. Slowest were:

99.0ms
(- (* 2 (/ (* a c) b)) (* 2 b))
75.0ms
(fma 1 (- b) (- (* (sqrt (cbrt (fma c (* a -4) (* b b)))) (sqrt (* (cbrt (fma c (* a -4) (* b b))) (cbrt (fma c (* a -4) (* b b))))))))
74.0ms
(fma 1 (- b) (- (* (sqrt (fma c (* a -4) (* b b))) (sqrt 1))))

prune1.8s

Pruning

11 alts after pruning (11 fresh and 0 done)

Merged error: 14.5b

localize109.0ms

Local error

Found 4 expressions with local error:

23.7b
(sqrt (fma c (* a -4) (* b b)))
23.7b
(sqrt (fma c (* a -4) (* b b)))
23.7b
(sqrt (fma c (* a -4) (* b b)))
16.2b
(fma (sqrt (sqrt (fma c (* a -4) (* b b)))) (sqrt (sqrt (fma c (* a -4) (* b b)))) (- b))

rewrite3.0ms

Algorithm
rewrite-expression-head
Counts
4 → 52
Calls

4 calls. Slowest were:

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

series502.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

331.0ms
(fma (sqrt (sqrt (fma c (* a -4) (* b b)))) (sqrt (sqrt (fma c (* a -4) (* b b)))) (- b))
68.0ms
(sqrt (fma c (* a -4) (* b b)))
52.0ms
(sqrt (fma c (* a -4) (* b b)))
51.0ms
(sqrt (fma c (* a -4) (* b b)))

simplify614.0ms

Counts
24 → 64
Calls

24 calls. Slowest were:

329.0ms
(- (pow (exp (* 1/4 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c)))))) 2) b)
101.0ms
(- (pow (exp (* 1/4 (- (log -4) (+ (log (/ -1 c)) (log (/ -1 a)))))) 2) b)
21.0ms
(sqrt (* (cbrt (fma c (* a -4) (* b b))) (cbrt (fma c (* a -4) (* b b)))))

prune1.2s

Pruning

12 alts after pruning (11 fresh and 1 done)

Merged error: 14.5b

localize138.0ms

Local error

Found 4 expressions with local error:

24.5b
(cbrt (fma (* a -4) c (* b b)))
24.5b
(cbrt (fma (* a -4) c (* b b)))
23.7b
(sqrt (fma c (* a -4) (* b b)))
23.1b
(fma (sqrt (cbrt (fma (* a -4) c (* b b)))) (fabs (cbrt (fma (* a -4) c (* b b)))) b)

rewrite5.0ms

Algorithm
rewrite-expression-head
Counts
4 → 50
Calls

4 calls. Slowest were:

2.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)))

series741.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

271.0ms
(fma (sqrt (cbrt (fma (* a -4) c (* b b)))) (fabs (cbrt (fma (* a -4) c (* b b)))) b)
211.0ms
(cbrt (fma (* a -4) c (* b b)))
195.0ms
(cbrt (fma (* a -4) c (* b b)))
63.0ms
(sqrt (fma c (* a -4) (* b b)))

simplify1.6s

Counts
22 → 62
Calls

22 calls. Slowest were:

207.0ms
(+ (* (exp (* 1/6 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c)))))) (fabs (pow (fma (* -4 a) c (pow b 2)) 1/3))) b)
200.0ms
(- (+ b (* (fabs (pow (fma (* -4 a) c (pow b 2)) 1/3)) (pow b 1/3))) (* 2/3 (* (* a (* (fabs (pow (fma (* -4 a) c (pow b 2)) 1/3)) c)) (pow (/ 1 (pow b 5)) 1/3))))
198.0ms
(exp (* 1/3 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c))))))

prune1.8s

Pruning

11 alts after pruning (10 fresh and 1 done)

Merged error: 14.5b

localize156.0ms

Local error

Found 4 expressions with local error:

24.5b
(cbrt (fma (* a -4) c (* b b)))
24.5b
(cbrt (fma (* a -4) c (* b b)))
24.5b
(cbrt (fma (* a -4) c (* b b)))
24.5b
(cbrt (fma (* a -4) c (* b b)))

rewrite3.0ms

Algorithm
rewrite-expression-head
Counts
4 → 52
Calls

4 calls. Slowest were:

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

series936.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

254.0ms
(cbrt (fma (* a -4) c (* b b)))
237.0ms
(cbrt (fma (* a -4) c (* b b)))
229.0ms
(cbrt (fma (* a -4) c (* b b)))
215.0ms
(cbrt (fma (* a -4) c (* b b)))

simplify1.9s

Counts
24 → 64
Calls

24 calls. Slowest were:

232.0ms
(exp (* 1/3 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c))))))
225.0ms
(exp (* 1/3 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c))))))
173.0ms
(- (pow b 2/3) (* 4/3 (* (* a c) (pow (/ 1 (pow b 4)) 1/3))))

prune1.5s

Pruning

11 alts after pruning (10 fresh and 1 done)

Merged error: 14.5b

regimes400.0ms

Accuracy

91.4% (0.6b remaining)

Error of 13.1b against oracle of 12.5b and baseline of 19.5b

bsearch328.0ms

end0.0ms

sample3.2s

Algorithm
intervals