Average Error: 33.5 → 16.4
Time: 18.0s
Precision: 64
Internal Precision: 128
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le 1.9639198265054672 \cdot 10^{-73}:\\ \;\;\;\;\frac{\sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{-\frac{b}{c}}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.5
Target20.5
Herbie16.4
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if b < 1.9639198265054672e-73

    1. Initial program 21.1

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified21.1

      \[\leadsto \color{blue}{\frac{\sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*} - b}{2 \cdot a}}\]

    if 1.9639198265054672e-73 < b

    1. Initial program 52.9

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified52.9

      \[\leadsto \color{blue}{\frac{\sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity52.9

      \[\leadsto \frac{\color{blue}{1 \cdot \left(\sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*} - b\right)}}{2 \cdot a}\]
    5. Applied associate-/l*52.9

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*} - b}}}\]
    6. Taylor expanded around 0 9.0

      \[\leadsto \frac{1}{\color{blue}{-1 \cdot \frac{b}{c}}}\]
    7. Simplified9.0

      \[\leadsto \frac{1}{\color{blue}{\frac{-b}{c}}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification16.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le 1.9639198265054672 \cdot 10^{-73}:\\ \;\;\;\;\frac{\sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{-\frac{b}{c}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019004 +o rules:numerics
(FPCore (a b c)
  :name "quadp (p42, positive)"

  :herbie-target
  (if (< b 0) (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))

Details

Time bar (total: 16.5s)Debug log

sample143.0ms

Algorithm
intervals

simplify96.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

96.0ms
(/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))

prune20.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 32.6b

localize40.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (fma (* a c) -4 (* b b)))
0.8b
(fma (* a c) -4 (* b b))
0.3b
(/ (- (sqrt (fma (* a c) -4 (* b b))) b) (* 2 a))
0.0b
(- (sqrt (fma (* a c) -4 (* b b))) b)

rewrite39.0ms

Algorithm
rewrite-expression-head
Counts
4 → 67
Calls

4 calls. Slowest were:

26.0ms
(/ (- (sqrt (fma (* a c) -4 (* b b))) b) (* 2 a))
10.0ms
(- (sqrt (fma (* a c) -4 (* b b))) b)
2.0ms
(sqrt (fma (* a c) -4 (* b b)))

series267.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

119.0ms
(/ (- (sqrt (fma (* a c) -4 (* b b))) b) (* 2 a))
70.0ms
(- (sqrt (fma (* a c) -4 (* b b))) b)
47.0ms
(sqrt (fma (* a c) -4 (* b b)))
30.0ms
(fma (* a c) -4 (* b b))

simplify1.4s

Counts
34 → 79
Calls

34 calls. Slowest were:

672.0ms
(- (* (sqrt (fma (* a c) -4 (* b b))) (sqrt (fma (* a c) -4 (* b b)))) (* b b))
127.0ms
(- (pow (sqrt (fma (* a c) -4 (* b b))) 3) (pow b 3))
86.0ms
(/ (* (* (- (sqrt (fma (* a c) -4 (* b b))) b) (- (sqrt (fma (* a c) -4 (* b b))) b)) (- (sqrt (fma (* a c) -4 (* b b))) b)) (* (* (* 2 a) (* 2 a)) (* 2 a)))

prune892.0ms

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 22.7b

localize8.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (fma (* a c) -4 (* b b)))
0.8b
(fma (* a c) -4 (* b b))
0.4b
(/ (* 2 a) (- (sqrt (fma (* a c) -4 (* b b))) b))
0.2b
(/ 1 (/ (* 2 a) (- (sqrt (fma (* a c) -4 (* b b))) b)))

rewrite12.0ms

Algorithm
rewrite-expression-head
Counts
4 → 73
Calls

4 calls. Slowest were:

7.0ms
(/ (* 2 a) (- (sqrt (fma (* a c) -4 (* b b))) b))
4.0ms
(/ 1 (/ (* 2 a) (- (sqrt (fma (* a c) -4 (* b b))) b)))
1.0ms
(sqrt (fma (* a c) -4 (* b b)))

series351.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

161.0ms
(/ (* 2 a) (- (sqrt (fma (* a c) -4 (* b b))) b))
97.0ms
(/ 1 (/ (* 2 a) (- (sqrt (fma (* a c) -4 (* b b))) b)))
49.0ms
(sqrt (fma (* a c) -4 (* b b)))
44.0ms
(fma (* a c) -4 (* b b))

simplify1.6s

Counts
40 → 85
Calls

40 calls. Slowest were:

595.0ms
(/ (* (* (* 2 a) (* 2 a)) (* 2 a)) (* (* (- (sqrt (fma (* a c) -4 (* b b))) b) (- (sqrt (fma (* a c) -4 (* b b))) b)) (- (sqrt (fma (* a c) -4 (* b b))) b)))
138.0ms
(+ (* (sqrt (fma (* a c) -4 (* b b))) (sqrt (fma (* a c) -4 (* b b)))) (+ (* b b) (* (sqrt (fma (* a c) -4 (* b b))) b)))
117.0ms
(+ (* (sqrt (fma (* a c) -4 (* b b))) (sqrt (fma (* a c) -4 (* b b)))) (+ (* b b) (* (sqrt (fma (* a c) -4 (* b b))) b)))

prune1.1s

Pruning

11 alts after pruning (9 fresh and 2 done)

Merged error: 13.1b

localize52.0ms

Local error

Found 4 expressions with local error:

22.7b
(cbrt (fma a (* -4 c) (* b b)))
22.7b
(cbrt (fma (* a c) -4 (* b b)))
6.6b
(- (* (fabs (cbrt (fma a (* -4 c) (* b b)))) (sqrt (cbrt (fma (* a c) -4 (* b b))))) b)
0.8b
(fma (* a c) -4 (* b b))

rewrite17.0ms

Algorithm
rewrite-expression-head
Counts
4 → 50
Calls

4 calls. Slowest were:

13.0ms
(- (* (fabs (cbrt (fma a (* -4 c) (* b b)))) (sqrt (cbrt (fma (* a c) -4 (* b b))))) b)
1.0ms
(cbrt (fma a (* -4 c) (* b b)))
1.0ms
(cbrt (fma (* a c) -4 (* b b)))

series730.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

279.0ms
(- (* (fabs (cbrt (fma a (* -4 c) (* b b)))) (sqrt (cbrt (fma (* a c) -4 (* b b))))) b)
208.0ms
(cbrt (fma (* a c) -4 (* b b)))
197.0ms
(cbrt (fma a (* -4 c) (* b b)))
45.0ms
(fma (* a c) -4 (* b b))

simplify1.4s

Counts
19 → 62
Calls

19 calls. Slowest were:

222.0ms
(- (pow b 2/3) (* 4/3 (* (* a c) (pow (/ 1 (pow b 4)) 1/3))))
197.0ms
(exp (* 1/3 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c))))))
187.0ms
(exp (* 1/3 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c))))))

prune898.0ms

Pruning

11 alts after pruning (8 fresh and 3 done)

Merged error: 13.1b

localize24.0ms

Local error

Found 4 expressions with local error:

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

rewrite5.0ms

Algorithm
rewrite-expression-head
Counts
4 → 48
Calls

4 calls. Slowest were:

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

series485.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

299.0ms
(fma (sqrt (sqrt (fma (* a c) -4 (* b b)))) (sqrt (sqrt (fma (* a c) -4 (* b b)))) (- b))
72.0ms
(sqrt (fma (* a c) -4 (* b b)))
67.0ms
(sqrt (fma (* a c) -4 (* b b)))
47.0ms
(fma (* a c) -4 (* b b))

simplify616.0ms

Counts
20 → 60
Calls

20 calls. Slowest were:

300.0ms
(- (pow (exp (* 1/4 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c)))))) 2) b)
111.0ms
(- (pow (exp (* 1/4 (- (log -4) (+ (log (/ -1 c)) (log (/ -1 a)))))) 2) b)
34.0ms
(- (pow b 2) (* 4 (* a c)))

prune781.0ms

Pruning

11 alts after pruning (7 fresh and 4 done)

Merged error: 13.1b

regimes423.0ms

Accuracy

81.3% (3.9b remaining)

Error of 16.4b against oracle of 12.4b and baseline of 33.5b

bsearch275.0ms

end0.0ms

sample4.9s

Algorithm
intervals