Average Error: 19.2 → 8.4
Time: 23.6s
Precision: 64
Internal Precision: 128
\[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
\[\begin{array}{l} \mathbf{if}\;b \le -1.3474867709131763 \cdot 10^{+154}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(2 \cdot \frac{a \cdot c}{b} - b\right) + \left(-b\right)}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le 4.2908085587759755 \cdot 10^{+99}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(b - 2 \cdot \frac{a \cdot c}{b}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{2 \cdot a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if b < -1.3474867709131763e+154

    1. Initial program 60.9

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

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

    if -1.3474867709131763e+154 < b < 4.2908085587759755e+99

    1. Initial program 8.6

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

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

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

    if 4.2908085587759755e+99 < b

    1. Initial program 29.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.3474867709131763 \cdot 10^{+154}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(2 \cdot \frac{a \cdot c}{b} - b\right) + \left(-b\right)}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le 4.2908085587759755 \cdot 10^{+99}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(b - 2 \cdot \frac{a \cdot c}{b}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{2 \cdot a}\\ \end{array}\]

Reproduce

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

Details

Time bar (total: 22.2s)Debug log

sample144.0ms

Algorithm
intervals

simplify113.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune30.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 19.7b

localize167.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (- (* b b) (* (* 4 a) c)))
22.0b
(sqrt (- (* b b) (* (* 4 a) c)))
0.9b
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
0.8b
(- (* b b) (* (* 4 a) c))

rewrite37.0ms

Algorithm
rewrite-expression-head
Counts
4 → 56
Calls

4 calls. Slowest were:

13.0ms
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
6.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
5.0ms
(- (* b b) (* (* 4 a) c))

series199.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

76.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
51.0ms
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
42.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
30.0ms
(- (* b b) (* (* 4 a) c))

simplify2.3s

Counts
31 → 68
Calls

31 calls. Slowest were:

398.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
356.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
199.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune1.1s

Pruning

11 alts after pruning (11 fresh and 0 done)

Merged error: 7.9b

localize94.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (- (* b b) (* (* 4 a) c)))
22.0b
(sqrt (- (* b b) (* (* 4 a) c)))
22.0b
(sqrt (- (* b b) (* (* 4 a) c)))
10.6b
(- (- b) (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))))

rewrite18.0ms

Algorithm
rewrite-expression-head
Counts
4 → 56
Calls

4 calls. Slowest were:

7.0ms
(- (- b) (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))))
4.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
3.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series265.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

76.0ms
(- (- b) (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))))
72.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
67.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
49.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

simplify2.7s

Counts
33 → 68
Calls

33 calls. Slowest were:

383.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
381.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
320.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))

prune1.3s

Pruning

11 alts after pruning (10 fresh and 1 done)

Merged error: 7.9b

localize132.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (- (* b b) (* (* 4 a) c)))
22.0b
(sqrt (- (* b b) (* (* 4 a) c)))
22.0b
(sqrt (- (* b b) (* (* 4 a) c)))
10.5b
(+ (- b) (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))))

rewrite12.0ms

Algorithm
rewrite-expression-head
Counts
4 → 54
Calls

4 calls. Slowest were:

5.0ms
(+ (- b) (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))))
2.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
2.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series225.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

74.0ms
(+ (- b) (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))))
52.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
51.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
48.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

simplify2.8s

Counts
31 → 66
Calls

31 calls. Slowest were:

398.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
395.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
393.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))

prune1.3s

Pruning

11 alts after pruning (9 fresh and 2 done)

Merged error: 7.9b

localize143.0ms

Local error

Found 4 expressions with local error:

22.7b
(cbrt (- (* b b) (* (* 4 a) c)))
22.7b
(cbrt (- (* b b) (* (* 4 a) c)))
22.0b
(sqrt (- (* b b) (* (* 4 a) c)))
6.6b
(+ (- b) (* (fabs (cbrt (- (* b b) (* (* 4 a) c)))) (sqrt (cbrt (- (* b b) (* (* 4 a) c))))))

rewrite11.0ms

Algorithm
rewrite-expression-head
Counts
4 → 52
Calls

4 calls. Slowest were:

5.0ms
(+ (- b) (* (fabs (cbrt (- (* b b) (* (* 4 a) c)))) (sqrt (cbrt (- (* b b) (* (* 4 a) c))))))
2.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
2.0ms
(cbrt (- (* b b) (* (* 4 a) c)))

series401.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

132.0ms
(cbrt (- (* b b) (* (* 4 a) c)))
118.0ms
(cbrt (- (* b b) (* (* 4 a) c)))
93.0ms
(+ (- b) (* (fabs (cbrt (- (* b b) (* (* 4 a) c)))) (sqrt (cbrt (- (* b b) (* (* 4 a) c))))))
59.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

simplify3.3s

Counts
29 → 64
Calls

29 calls. Slowest were:

768.0ms
(cbrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
428.0ms
(cbrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
377.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))

prune1.2s

Pruning

10 alts after pruning (7 fresh and 3 done)

Merged error: 7.9b

regimes393.0ms

Accuracy

92.2% (0.9b remaining)

Error of 8.4b against oracle of 7.4b and baseline of 19.3b

bsearch495.0ms

end0.0ms

sample3.3s

Algorithm
intervals