Average Error: 34.1 → 10.3
Time: 29.5s
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 -4.21731702933355 \cdot 10^{+148}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.2612246360442721 \cdot 10^{-22}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \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

Target

Original34.1
Target21.5
Herbie10.3
\[\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 3 regimes
  2. if b < -4.21731702933355e+148

    1. Initial program 58.9

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. Taylor expanded around -inf 2.3

      \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}}\]

    if -4.21731702933355e+148 < b < 1.2612246360442721e-22

    1. Initial program 14.8

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

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

    if 1.2612246360442721e-22 < b

    1. Initial program 54.5

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. Taylor expanded around inf 6.4

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    4. Simplified6.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.21731702933355 \cdot 10^{+148}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.2612246360442721 \cdot 10^{-22}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019007 
(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: 28.3s)Debug log

sample91.0ms

Algorithm
intervals

simplify91.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune11.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 34.1b

localize23.0ms

Local error

Found 4 expressions with local error:

24.1b
(sqrt (- (* b b) (* (* 4 a) c)))
1.5b
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
1.2b
(- (* b b) (* (* 4 a) c))
0.1b
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))

rewrite69.0ms

Algorithm
rewrite-expression-head
Counts
4 → 59
Calls

4 calls. Slowest were:

40.0ms
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))
21.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
4.0ms
(- (* b b) (* (* 4 a) c))

series253.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

97.0ms
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))
70.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
43.0ms
(- (* b b) (* (* 4 a) c))
43.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

simplify2.2s

Counts
32 → 71
Calls

32 calls. Slowest were:

378.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
352.0ms
(- (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* b b))
250.0ms
(- (pow (sqrt (- (* b b) (* (* 4 a) c))) 3) (pow b 3))

prune762.0ms

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 6.1b

localize11.0ms

Local error

Found 4 expressions with local error:

24.1b
(sqrt (- (* b b) (* (* 4 a) c)))
1.5b
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
1.2b
(- (* b b) (* (* 4 a) c))
0.1b
(/ 1 (/ (* 2 a) (- (sqrt (- (* b b) (* (* 4 a) c))) b)))

rewrite36.0ms

Algorithm
rewrite-expression-head
Counts
4 → 61
Calls

4 calls. Slowest were:

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

series272.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

94.0ms
(/ 1 (/ (* 2 a) (- (sqrt (- (* b b) (* (* 4 a) c))) b)))
76.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
55.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
47.0ms
(- (* b b) (* (* 4 a) c))

simplify1.7s

Counts
30 → 73
Calls

30 calls. Slowest were:

380.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
228.0ms
(+ (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (+ (* b b) (* (sqrt (- (* b b) (* (* 4 a) c))) b)))
162.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune800.0ms

Pruning

10 alts after pruning (8 fresh and 2 done)

Merged error: 6.1b

localize9.0ms

Local error

Found 4 expressions with local error:

24.1b
(sqrt (- (* b b) (* (* 4 a) c)))
24.1b
(sqrt (- (* b b) (* (* 4 a) c)))
1.5b
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
1.5b
(- (sqrt (- (* b b) (* (* 4 a) c))) b)

rewrite27.0ms

Algorithm
rewrite-expression-head
Counts
4 → 50
Calls

4 calls. Slowest were:

11.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
11.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
2.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series205.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

62.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
49.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
48.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
46.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)

simplify1.9s

Counts
24 → 62
Calls

24 calls. Slowest were:

386.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
366.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
169.0ms
(- b (* 2 (/ (* a c) b)))

prune888.0ms

Pruning

10 alts after pruning (7 fresh and 3 done)

Merged error: 6.1b

localize24.0ms

Local error

Found 4 expressions with local error:

24.9b
(cbrt (- (* b b) (* (* 4 a) c)))
24.9b
(cbrt (- (* b b) (* (* 4 a) c)))
24.9b
(cbrt (- (* b b) (* (* 4 a) c)))
24.1b
(sqrt (* (* (cbrt (- (* b b) (* (* 4 a) c))) (cbrt (- (* b b) (* (* 4 a) c)))) (cbrt (- (* b b) (* (* 4 a) c)))))

rewrite14.0ms

Algorithm
rewrite-expression-head
Counts
4 → 74
Calls

4 calls. Slowest were:

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

series383.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

122.0ms
(cbrt (- (* b b) (* (* 4 a) c)))
108.0ms
(cbrt (- (* b b) (* (* 4 a) c)))
103.0ms
(cbrt (- (* b b) (* (* 4 a) c)))
50.0ms
(sqrt (* (* (cbrt (- (* b b) (* (* 4 a) c))) (cbrt (- (* b b) (* (* 4 a) c)))) (cbrt (- (* b b) (* (* 4 a) c)))))

simplify11.1s

Counts
54 → 86
Calls

54 calls. Slowest were:

575.0ms
(sqrt (* (* (cbrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c)))) (cbrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))) (cbrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))))
527.0ms
(sqrt (* (* (cbrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3))) (cbrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))) (cbrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))))
523.0ms
(sqrt (* (* (cbrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c)))) (cbrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))) (cbrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))))

prune1.5s

Pruning

10 alts after pruning (6 fresh and 4 done)

Merged error: 6.1b

regimes338.0ms

Accuracy

83.3% (4.8b remaining)

Error of 10.3b against oracle of 5.5b and baseline of 34.2b

bsearch303.0ms

end0.0ms

sample5.3s

Algorithm
intervals