Average Error: 19.1 → 7.7
Time: 21.8s
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.3410782657088844 \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(\frac{2}{b}\right) \cdot \left(a \cdot c\right) + \left(b \cdot -2\right))_*}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le 2.0689576101980954 \cdot 10^{+101}:\\ \;\;\;\;\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{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - (\left(a \cdot \frac{c}{b}\right) \cdot -2 + b)_*}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}{2 \cdot a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

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

    1. Initial program 61.0

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

      \[\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{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \end{array}\]
    3. Simplified60.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) + \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}{2 \cdot a}\\ \end{array}\]
    4. Taylor expanded around -inf 11.6

      \[\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{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}{2 \cdot a}\\ \end{array}\]
    5. Simplified11.6

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

    if -1.3410782657088844e+154 < b < 2.0689576101980954e+101

    1. Initial program 8.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 8.7

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

      \[\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{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}{2 \cdot a}\\ \end{array}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt8.8

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

    if 2.0689576101980954e+101 < b

    1. Initial program 29.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 29.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{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \end{array}\]
    3. Simplified29.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{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}{2 \cdot a}\\ \end{array}\]
    4. Taylor expanded around inf 7.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.3410782657088844 \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(\frac{2}{b}\right) \cdot \left(a \cdot c\right) + \left(b \cdot -2\right))_*}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le 2.0689576101980954 \cdot 10^{+101}:\\ \;\;\;\;\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{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - (\left(a \cdot \frac{c}{b}\right) \cdot -2 + b)_*}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}{2 \cdot a}\\ \end{array}\]

Reproduce

herbie shell --seed 2019008 +o rules:numerics
(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: 19.6s)Debug log

sample128.0ms

Algorithm
intervals

simplify94.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune19.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 19.7b

localize178.0ms

Local error

Found 4 expressions with local error:

23.3b
(sqrt (- (* b b) (* (* 4 a) c)))
23.3b
(sqrt (- (* b b) (* (* 4 a) c)))
1.0b
(- (* b b) (* (* 4 a) c))
1.0b
(- (* b b) (* (* 4 a) c))

rewrite32.0ms

Algorithm
rewrite-expression-head
Counts
4 → 64
Calls

4 calls. Slowest were:

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

series208.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

72.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
64.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
39.0ms
(- (* b b) (* (* 4 a) c))
33.0ms
(- (* b b) (* (* 4 a) c))

simplify2.3s

Counts
30 → 76
Calls

30 calls. Slowest were:

440.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
398.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
172.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune1.3s

Pruning

12 alts after pruning (12 fresh and 0 done)

Merged error: 7.9b

localize131.0ms

Local error

Found 4 expressions with local error:

23.3b
(sqrt (fma (* a -4) c (* b b)))
23.3b
(sqrt (- (* b b) (* (* 4 a) c)))
1.0b
(- (* b b) (* (* 4 a) c))
0.9b
(+ (- b) (sqrt (fma (* a -4) c (* b b))))

rewrite21.0ms

Algorithm
rewrite-expression-head
Counts
4 → 65
Calls

4 calls. Slowest were:

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

series226.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

73.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
69.0ms
(sqrt (fma (* a -4) c (* b b)))
42.0ms
(+ (- b) (sqrt (fma (* a -4) c (* b b))))
41.0ms
(- (* b b) (* (* 4 a) c))

simplify1.2s

Counts
29 → 77
Calls

29 calls. Slowest were:

341.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
165.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))
137.0ms
(- b (* 2 (/ (* a c) b)))

prune1.3s

Pruning

12 alts after pruning (12 fresh and 0 done)

Merged error: 7.9b

localize133.0ms

Local error

Found 4 expressions with local error:

23.3b
(sqrt (fma (* a -4) c (* b b)))
23.3b
(sqrt (- (* b b) (* (* 4 a) c)))
23.3b
(sqrt (- (* b b) (* (* 4 a) c)))
7.8b
(- (- b) (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))))

rewrite12.0ms

Algorithm
rewrite-expression-head
Counts
4 → 70
Calls

4 calls. Slowest were:

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

series202.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

65.0ms
(- (- b) (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))))
51.0ms
(sqrt (fma (* a -4) c (* b b)))
44.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
42.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

simplify2.7s

Counts
41 → 82
Calls

41 calls. Slowest were:

439.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
418.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.8s

Pruning

14 alts after pruning (13 fresh and 1 done)

Merged error: 7.9b

localize120.0ms

Local error

Found 4 expressions with local error:

23.3b
(sqrt (fma (* a -4) c (* b b)))
23.3b
(sqrt (fma (* a -4) c (* b b)))
23.3b
(sqrt (- (* b b) (* (* 4 a) c)))
11.4b
(+ (- b) (* (sqrt (sqrt (fma (* a -4) c (* b b)))) (sqrt (sqrt (fma (* a -4) c (* b b))))))

rewrite19.0ms

Algorithm
rewrite-expression-head
Counts
4 → 62
Calls

4 calls. Slowest were:

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

series186.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

51.0ms
(sqrt (fma (* a -4) c (* b b)))
48.0ms
(sqrt (fma (* a -4) c (* b b)))
44.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
44.0ms
(+ (- b) (* (sqrt (sqrt (fma (* a -4) c (* b b)))) (sqrt (sqrt (fma (* a -4) c (* b b))))))

simplify1.5s

Counts
29 → 74
Calls

29 calls. Slowest were:

754.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
162.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))
139.0ms
(- b (* 2 (/ (* a c) b)))

prune1.5s

Pruning

14 alts after pruning (12 fresh and 2 done)

Merged error: 7.9b

regimes613.0ms

Accuracy

91.7% (1.0b remaining)

Error of 7.7b against oracle of 6.7b and baseline of 19.2b

bsearch446.0ms

end0.0ms

sample3.3s

Algorithm
intervals