Average Error: 19.6 → 8.7
Time: 24.2s
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.1673153527967745 \cdot 10^{+117}:\\ \;\;\;\;\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 3.328175344273382 \cdot 10^{+63}:\\ \;\;\;\;\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{\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}}}{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.1673153527967745e+117

    1. Initial program 48.7

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

      \[\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.1673153527967745e+117 < b < 3.328175344273382e+63

    1. Initial program 9.2

      \[\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-sqrt9.3

      \[\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) + \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}}}{2 \cdot a}\\ \end{array}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt9.4

      \[\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{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \end{array}\]

    if 3.328175344273382e+63 < b

    1. Initial program 26.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.1673153527967745 \cdot 10^{+117}:\\ \;\;\;\;\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 3.328175344273382 \cdot 10^{+63}:\\ \;\;\;\;\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{\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}}}{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 2019016 
(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: 23.0s)Debug log

sample179.0ms

Algorithm
intervals
Results
378×(pre true 80)
285×(body real 80)
93×(body nan 80)

simplify92.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
92.0ms
(if (>= b 0) (/ (* 2 c) (- (- b) (sqrt (- (* b b) (* (* 4 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))

prune33.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 19.9b

localize151.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (- (* b b) (* (* 4 a) c)))
23.2b
(sqrt (- (* b b) (* (* 4 a) c)))
2.2b
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
1.2b
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))

rewrite25.0ms

Algorithm
rewrite-expression-head
Rules
12×add-sqr-sqrt
10×*-un-lft-identity
add-log-exp
sqrt-prod
add-cube-cbrt
add-exp-log
sqrt-div
add-cbrt-cube
pow1
flip--
flip3--
difference-of-squares
pow1/2
rem-sqrt-square
neg-sub0
distribute-lft-out--
distribute-lft-out
flip-+
associate-+l-
diff-log
flip3-+
sub-neg
sum-log
+-commutative
associate--l-
Counts
4 → 57
Calls
4 calls:
Slowest
8.0ms
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
6.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
5.0ms
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
4.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series252.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
69.0ms
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
68.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
61.0ms
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
54.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

simplify2.2s

Counts
32 → 69
Calls
32 calls:
Slowest
407.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
395.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
130.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))
121.0ms
(- b (* 2 (/ (* a c) b)))
118.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune1.0s

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 8.4b

localize124.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (- (* b b) (* (* 4 a) c)))
23.2b
(sqrt (- (* b b) (* (* 4 a) c)))
23.2b
(sqrt (- (* b b) (* (* 4 a) c)))
14.4b
(+ (- b) (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))))

rewrite10.0ms

Algorithm
rewrite-expression-head
Rules
10×add-sqr-sqrt
sqrt-prod
add-cube-cbrt
*-un-lft-identity
add-log-exp
sqrt-div
add-exp-log
add-cbrt-cube
pow1
flip--
pow1/2
flip3--
rem-sqrt-square
flip-+
associate-+l-
flip3-+
sum-log
+-commutative
neg-sub0
Counts
4 → 54
Calls
4 calls:
Slowest
4.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)))
2.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series215.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
60.0ms
(+ (- b) (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))))
57.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
49.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
49.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

simplify2.8s

Counts
31 → 66
Calls
31 calls:
Slowest
421.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
387.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
365.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
168.0ms
(- b (* 2 (/ (* a c) b)))
150.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune1.2s

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 8.4b

localize111.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (- (* b b) (* (* 4 a) c)))
23.2b
(sqrt (- (* b b) (* (* 4 a) c)))
23.2b
(sqrt (- (* b b) (* (* 4 a) c)))
23.2b
(sqrt (- (* b b) (* (* 4 a) c)))

rewrite8.0ms

Algorithm
rewrite-expression-head
Rules
12×sqrt-prod
12×add-sqr-sqrt
add-cube-cbrt
sqrt-div
*-un-lft-identity
add-log-exp
flip--
add-exp-log
pow1/2
add-cbrt-cube
flip3--
rem-sqrt-square
pow1
Counts
4 → 56
Calls
4 calls:
Slowest
2.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
2.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
2.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
2.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series200.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
57.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
50.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
47.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
46.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

simplify3.4s

Counts
36 → 68
Calls
36 calls:
Slowest
441.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
437.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
407.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
352.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
192.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune1.3s

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 8.4b

localize118.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (- (* b b) (* (* 4 a) c)))
23.2b
(sqrt (- (* b b) (* (* 4 a) c)))
23.2b
(sqrt (- (* b b) (* (* 4 a) c)))
23.2b
(sqrt (- (* b b) (* (* 4 a) c)))

rewrite8.0ms

Algorithm
rewrite-expression-head
Rules
12×sqrt-prod
12×add-sqr-sqrt
add-cube-cbrt
sqrt-div
*-un-lft-identity
add-log-exp
flip--
add-exp-log
pow1/2
add-cbrt-cube
flip3--
rem-sqrt-square
pow1
Counts
4 → 56
Calls
4 calls:
Slowest
2.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
2.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
2.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
2.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series256.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
68.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
67.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
66.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
55.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

simplify3.2s

Counts
36 → 68
Calls
36 calls:
Slowest
455.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
376.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
346.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
324.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
166.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune1.7s

Pruning

9 alts after pruning (7 fresh and 2 done)

Merged error: 8.4b

regimes469.0ms

Accuracy

90.5% (1.2b remaining)

Error of 8.7b against oracle of 7.6b and baseline of 19.7b

bsearch517.0ms

end0.0ms

sample3.3s

Algorithm
intervals
Results
11500×(pre true 80)
8754×(body real 80)
2746×(body nan 80)