Average Error: 19.2 → 12.9
Time: 18.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 5.110543529157628 \cdot 10^{+99}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \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))_*}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*} - b}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\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 < 5.110543529157628e+99

    1. Initial program 14.5

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\color{blue}{\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))_*}}}}{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}\]
    5. Applied sqrt-prod14.6

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \color{blue}{\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))_*}}}}{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}\]

    if 5.110543529157628e+99 < b

    1. Initial program 44.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. Simplified44.5

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

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

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

Reproduce

herbie shell --seed 2019004 +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: 17.0s)Debug log

sample124.0ms

Algorithm
intervals

simplify102.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune13.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 18.2b

localize140.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (fma c (* a -4) (* b b)))
22.0b
(sqrt (fma c (* a -4) (* b b)))
0.9b
(- (- b) (sqrt (fma c (* a -4) (* b b))))
0.2b
(fma c (* a -4) (* b b))

rewrite8.0ms

Algorithm
rewrite-expression-head
Counts
4 → 84
Calls

4 calls. Slowest were:

5.0ms
(- (- b) (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)))

series213.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

58.0ms
(- (- b) (sqrt (fma c (* a -4) (* b b))))
56.0ms
(sqrt (fma c (* a -4) (* b b)))
50.0ms
(sqrt (fma c (* a -4) (* b b)))
50.0ms
(fma c (* a -4) (* b b))

simplify2.6s

Counts
76 → 96
Calls

76 calls. Slowest were:

78.0ms
(fma 1 (- b) (- (* (sqrt (fma c (* a -4) (* b b))) 1)))
78.0ms
(- (* 2 (/ (* a c) b)) (* 2 b))
71.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))))))))

prune1.8s

Pruning

6 alts after pruning (6 fresh and 0 done)

Merged error: 12.8b

localize121.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (fma c (* a -4) (* b b)))
22.0b
(sqrt (fma c (* a -4) (* b b)))
22.0b
(sqrt (fma c (* a -4) (* b b)))
13.6b
(- (- b) (* (sqrt (sqrt (fma c (* a -4) (* b b)))) (sqrt (sqrt (fma c (* a -4) (* b b))))))

rewrite14.0ms

Algorithm
rewrite-expression-head
Counts
4 → 66
Calls

4 calls. Slowest were:

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

series231.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

62.0ms
(- (- b) (* (sqrt (sqrt (fma c (* a -4) (* b b)))) (sqrt (sqrt (fma c (* a -4) (* b b))))))
61.0ms
(sqrt (fma c (* a -4) (* b b)))
60.0ms
(sqrt (fma c (* a -4) (* b b)))
49.0ms
(sqrt (fma c (* a -4) (* b b)))

simplify630.0ms

Counts
37 → 78
Calls

37 calls. Slowest were:

91.0ms
(- (* 2 (/ (* a c) b)) (* 2 b))
68.0ms
(fma (sqrt (- b)) (sqrt (- b)) (- (* (sqrt (sqrt (fma c (* a -4) (* b b)))) (sqrt (sqrt (fma c (* a -4) (* b b)))))))
59.0ms
(* -2 (/ (* a c) b))

prune1.3s

Pruning

6 alts after pruning (5 fresh and 1 done)

Merged error: 12.8b

localize128.0ms

Local error

Found 4 expressions with local error:

24.1b
(fma (fabs (cbrt (fma (* a -4) c (* b b)))) (sqrt (cbrt (fma (* a -4) c (* b b)))) b)
22.7b
(cbrt (fma (* a -4) c (* b b)))
22.7b
(cbrt (fma (* a -4) c (* b b)))
22.0b
(sqrt (fma c (* a -4) (* b b)))

rewrite2.0ms

Algorithm
rewrite-expression-head
Counts
4 → 50
Calls

4 calls. Slowest were:

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

series795.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

321.0ms
(fma (fabs (cbrt (fma (* a -4) c (* b b)))) (sqrt (cbrt (fma (* a -4) c (* b b)))) b)
248.0ms
(cbrt (fma (* a -4) c (* b b)))
181.0ms
(cbrt (fma (* a -4) c (* b b)))
45.0ms
(sqrt (fma c (* a -4) (* b b)))

simplify1.6s

Counts
22 → 62
Calls

22 calls. Slowest were:

204.0ms
(- (pow b 2/3) (* 4/3 (* (* a c) (pow (/ 1 (pow b 4)) 1/3))))
198.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
(- (pow b 2/3) (* 4/3 (* (* a c) (pow (/ 1 (pow b 4)) 1/3))))

prune1.4s

Pruning

6 alts after pruning (4 fresh and 2 done)

Merged error: 12.8b

localize108.0ms

Local error

Found 4 expressions with local error:

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

rewrite4.0ms

Algorithm
rewrite-expression-head
Counts
4 → 56
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)))

series227.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

68.0ms
(sqrt (fma c (* a -4) (* b b)))
62.0ms
(sqrt (fma c (* a -4) (* b b)))
52.0ms
(sqrt (fma c (* a -4) (* b b)))
45.0ms
(sqrt (fma c (* a -4) (* b b)))

simplify146.0ms

Counts
28 → 68
Calls

28 calls. Slowest were:

20.0ms
(sqrt (* (cbrt (fma c (* a -4) (* b b))) (cbrt (fma c (* a -4) (* b b)))))
14.0ms
(sqrt (sqrt (fma c (* a -4) (* b b))))
12.0ms
(sqrt (* (cbrt (fma c (* a -4) (* b b))) (cbrt (fma c (* a -4) (* b b)))))

prune1.3s

Pruning

6 alts after pruning (3 fresh and 3 done)

Merged error: 12.8b

regimes193.0ms

Accuracy

91.6% (0.6b remaining)

Error of 12.9b against oracle of 12.3b and baseline of 19.3b

bsearch257.0ms

end0.0ms

sample3.5s

Algorithm
intervals