Average Error: 33.1 → 10.3
Time: 20.9s
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 -2.8671071746705253 \cdot 10^{+127}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.354454736393541 \cdot 10^{-170}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\\ \mathbf{elif}\;b \le 9.22274670563189 \cdot 10^{-75}:\\ \;\;\;\;\frac{a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b} \cdot \frac{-2 \cdot c}{a}\\ \mathbf{elif}\;b \le 1.849572225033813 \cdot 10^{-22}:\\ \;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{a} \cdot \frac{\sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{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

Original33.1
Target20.7
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 5 regimes
  2. if b < -2.8671071746705253e+127

    1. Initial program 51.2

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

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

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

    if -2.8671071746705253e+127 < b < 1.354454736393541e-170

    1. Initial program 11.3

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied clear-num11.5

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

    if 1.354454736393541e-170 < b < 9.22274670563189e-75

    1. Initial program 24.9

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied flip--25.0

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

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

      \[\leadsto \frac{\color{blue}{\left(-4 \cdot c\right) \cdot a}}{\left(2 \cdot a\right) \cdot \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b\right)}\]
    7. Using strategy rm
    8. Applied times-frac18.2

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

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

    if 9.22274670563189e-75 < b < 1.849572225033813e-22

    1. Initial program 37.0

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt37.5

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

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

    if 1.849572225033813e-22 < b

    1. Initial program 54.3

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.8671071746705253 \cdot 10^{+127}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.354454736393541 \cdot 10^{-170}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\\ \mathbf{elif}\;b \le 9.22274670563189 \cdot 10^{-75}:\\ \;\;\;\;\frac{a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b} \cdot \frac{-2 \cdot c}{a}\\ \mathbf{elif}\;b \le 1.849572225033813 \cdot 10^{-22}:\\ \;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{a} \cdot \frac{\sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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

sample174.0ms

Algorithm
intervals

simplify70.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune19.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 32.2b

localize21.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (- (* b b) (* (* 4 a) c)))
1.1b
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
0.4b
(- (* b b) (* (* 4 a) c))
0.1b
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))

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

series257.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

100.0ms
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))
77.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
48.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
33.0ms
(- (* b b) (* (* 4 a) c))

simplify2.2s

Counts
32 → 71
Calls

32 calls. Slowest were:

377.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
301.0ms
(- (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* b b))
165.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune833.0ms

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 6.5b

localize9.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (- (* b b) (* (* 4 a) c)))
1.1b
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
0.4b
(- (* b b) (* (* 4 a) c))
0.2b
(/ 1 (/ (* 2 a) (- (sqrt (- (* b b) (* (* 4 a) c))) b)))

rewrite21.0ms

Algorithm
rewrite-expression-head
Counts
4 → 61
Calls

4 calls. Slowest were:

10.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
6.0ms
(/ 1 (/ (* 2 a) (- (sqrt (- (* b b) (* (* 4 a) c))) b)))
2.0ms
(- (* b b) (* (* 4 a) c))

series245.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

93.0ms
(/ 1 (/ (* 2 a) (- (sqrt (- (* b b) (* (* 4 a) c))) b)))
74.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
54.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
25.0ms
(- (* b b) (* (* 4 a) c))

simplify1.7s

Counts
30 → 73
Calls

30 calls. Slowest were:

371.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
187.0ms
(+ (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (+ (* b b) (* (sqrt (- (* b b) (* (* 4 a) c))) b)))
114.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune727.0ms

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 6.4b

localize16.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (- (* b b) (* (* 4 a) c)))
23.2b
(sqrt (- (* b b) (* (* 4 a) c)))
1.1b
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
1.1b
(- (sqrt (- (* b b) (* (* 4 a) c))) b)

rewrite41.0ms

Algorithm
rewrite-expression-head
Counts
4 → 50
Calls

4 calls. Slowest were:

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

series213.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

67.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
58.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
47.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
41.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

simplify1.7s

Counts
24 → 62
Calls

24 calls. Slowest were:

402.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
334.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
137.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune884.0ms

Pruning

9 alts after pruning (7 fresh and 2 done)

Merged error: 6.4b

localize18.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (- (* b b) (* (* 4 a) c)))
16.3b
(/ (* (* -4 c) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b)))
1.1b
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
0.4b
(- (* b b) (* (* 4 a) c))

rewrite27.0ms

Algorithm
rewrite-expression-head
Counts
4 → 55
Calls

4 calls. Slowest were:

12.0ms
(/ (* (* -4 c) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b)))
8.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
4.0ms
(- (* b b) (* (* 4 a) c))

series351.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

164.0ms
(/ (* (* -4 c) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b)))
73.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
72.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
43.0ms
(- (* b b) (* (* 4 a) c))

simplify3.7s

Counts
29 → 67
Calls

29 calls. Slowest were:

941.0ms
(/ (* (* (* (* -4 c) a) (* (* -4 c) a)) (* (* -4 c) a)) (* (* (* (* 2 a) (* 2 a)) (* 2 a)) (* (* (+ (sqrt (- (* b b) (* (* 4 a) c))) b) (+ (sqrt (- (* b b) (* (* 4 a) c))) b)) (+ (sqrt (- (* b b) (* (* 4 a) c))) b))))
814.0ms
(/ (* (* (* (* -4 c) a) (* (* -4 c) a)) (* (* -4 c) a)) (* (* (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b)) (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b))) (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b))))
442.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))

prune747.0ms

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 6.4b

regimes357.0ms

Accuracy

84.2% (4.3b remaining)

Error of 10.3b against oracle of 6.0b and baseline of 33.2b

bsearch787.0ms

end0.0ms

sample4.9s

Algorithm
intervals