Average Error: 19.1 → 8.5
Time: 29.1s
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 -7.427548864663621 \cdot 10^{+119}:\\ \;\;\;\;\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 7.329806779291632 \cdot 10^{+78}:\\ \;\;\;\;\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}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}\\ \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 < -7.427548864663621e+119

    1. Initial program 51.3

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

      \[\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 -7.427548864663621e+119 < b < 7.329806779291632e+78

    1. Initial program 8.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. Using strategy rm
    3. Applied add-sqr-sqrt8.5

      \[\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}\]

    if 7.329806779291632e+78 < b

    1. Initial program 27.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. Taylor expanded around inf 7.4

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\color{blue}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}\\ \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.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -7.427548864663621 \cdot 10^{+119}:\\ \;\;\;\;\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 7.329806779291632 \cdot 10^{+78}:\\ \;\;\;\;\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}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}\\ \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 2018362 
(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

start179.0ms

Algorithm
intervals

setup187.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 18.7b

localize176.0ms

Local error

Found 4 expressions with local error:

21.8b
(sqrt (- (* b b) (* (* 4 a) c)))
21.8b
(sqrt (- (* b b) (* (* 4 a) c)))
1.8b
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
0.9b
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))

rewrite30.0ms

Algorithm
rewrite-expression-head
Counts
4 → 57
Calls

4 calls. Slowest were:

11.0ms
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
8.0ms
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
6.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series199.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

60.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
47.0ms
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
46.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
45.0ms
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))

simplify2.6s

Counts
32 → 69
Calls

32 calls. Slowest were:

450.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
442.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
220.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune1.5s

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 5.8b

localize156.0ms

Local error

Found 4 expressions with local error:

21.8b
(sqrt (- (* b b) (* (* 4 a) c)))
21.8b
(sqrt (- (* b b) (* (* 4 a) c)))
21.8b
(sqrt (- (* b b) (* (* 4 a) c)))
10.8b
(+ (- b) (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))))

rewrite19.0ms

Algorithm
rewrite-expression-head
Counts
4 → 54
Calls

4 calls. Slowest were:

6.0ms
(+ (- b) (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))))
4.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
4.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series212.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

70.0ms
(+ (- b) (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))))
55.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
46.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
40.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

simplify2.9s

Counts
31 → 66
Calls

31 calls. Slowest were:

487.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
475.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
378.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))

prune1.5s

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 5.8b

localize130.0ms

Local error

Found 4 expressions with local error:

22.6b
(cbrt (- (* b b) (* (* 4 a) c)))
22.6b
(cbrt (- (* b b) (* (* 4 a) c)))
21.8b
(sqrt (- (* b b) (* (* 4 a) c)))
21.8b
(sqrt (- (* b b) (* (* 4 a) c)))

rewrite8.0ms

Algorithm
rewrite-expression-head
Counts
4 → 54
Calls

4 calls. Slowest were:

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

series335.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

105.0ms
(cbrt (- (* b b) (* (* 4 a) c)))
100.0ms
(cbrt (- (* b b) (* (* 4 a) c)))
67.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
63.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

simplify3.8s

Counts
34 → 66
Calls

34 calls. Slowest were:

519.0ms
(cbrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
490.0ms
(cbrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
407.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))

prune1.9s

Pruning

10 alts after pruning (9 fresh and 1 done)

Merged error: 5.8b

localize142.0ms

Local error

Found 4 expressions with local error:

21.8b
(sqrt (- (* b b) (* (* 4 a) c)))
21.8b
(sqrt (- (* b b) (* (* 4 a) c)))
21.8b
(sqrt (- (* b b) (* (* 4 a) c)))
6.5b
(- (- b) (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))))

rewrite17.0ms

Algorithm
rewrite-expression-head
Counts
4 → 56
Calls

4 calls. Slowest were:

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

series210.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

75.0ms
(- (- b) (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))))
49.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
46.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
40.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

simplify3.3s

Counts
33 → 68
Calls

33 calls. Slowest were:

484.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
461.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
457.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))

prune1.8s

Pruning

11 alts after pruning (9 fresh and 2 done)

Merged error: 5.8b

regimes526.0ms

Accuracy

90.8% (1.1b remaining)

Error of 8.5b against oracle of 7.4b and baseline of 19.2b

bsearch355.0ms