Average Error: 33.4 → 6.7
Time: 22.8s
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 -6.341219225938887 \cdot 10^{+106}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 3.45159933628946 \cdot 10^{-306}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.408724732699167 \cdot 10^{+98}:\\ \;\;\;\;\frac{c \cdot -2}{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} + b}\\ \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.4
Target20.3
Herbie6.7
\[\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 4 regimes
  2. if b < -6.341219225938887e+106

    1. Initial program 45.4

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

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

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

    if -6.341219225938887e+106 < b < 3.45159933628946e-306

    1. Initial program 8.9

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified8.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 div-inv9.0

      \[\leadsto \color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \frac{1}{2 \cdot a}}\]
    5. Using strategy rm
    6. Applied un-div-inv8.9

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

    if 3.45159933628946e-306 < b < 2.408724732699167e+98

    1. Initial program 32.5

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

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

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

      \[\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}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}} \cdot \frac{1}{2 \cdot a}\]
    7. Applied associate-*l/32.7

      \[\leadsto \color{blue}{\frac{\left(\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\right) \cdot \frac{1}{2 \cdot a}}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}}\]
    8. Simplified16.3

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

      \[\leadsto \frac{\color{blue}{-2 \cdot c}}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}\]
    10. Using strategy rm
    11. Applied *-un-lft-identity9.1

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

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

    if 2.408724732699167e+98 < b

    1. Initial program 58.7

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

      \[\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 div-inv58.7

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    6. Simplified2.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -6.341219225938887 \cdot 10^{+106}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 3.45159933628946 \cdot 10^{-306}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.408724732699167 \cdot 10^{+98}:\\ \;\;\;\;\frac{c \cdot -2}{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} + b}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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

sample162.0ms

Algorithm
intervals

simplify55.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune18.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 34.5b

localize21.0ms

Local error

Found 4 expressions with local error:

23.3b
(sqrt (- (* b b) (* (* 4 a) c)))
1.0b
(- (* b b) (* (* 4 a) c))
0.9b
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
0.1b
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))

rewrite56.0ms

Algorithm
rewrite-expression-head
Counts
4 → 59
Calls

4 calls. Slowest were:

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

series203.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

63.0ms
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))
53.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
49.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
38.0ms
(- (* b b) (* (* 4 a) c))

simplify2.4s

Counts
32 → 71
Calls

32 calls. Slowest were:

479.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
428.0ms
(- (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* b b))
227.0ms
(- (pow (sqrt (- (* b b) (* (* 4 a) c))) 3) (pow b 3))

prune776.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 6.9b

localize6.0ms

Local error

Found 4 expressions with local error:

23.3b
(sqrt (- (* b b) (* (* 4 a) c)))
1.0b
(- (* b b) (* (* 4 a) c))
0.9b
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
0.2b
(* (- (sqrt (- (* b b) (* (* 4 a) c))) b) (/ 1 (* 2 a)))

rewrite45.0ms

Algorithm
rewrite-expression-head
Counts
4 → 62
Calls

4 calls. Slowest were:

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

series230.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

68.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
67.0ms
(* (- (sqrt (- (* b b) (* (* 4 a) c))) b) (/ 1 (* 2 a)))
56.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
39.0ms
(- (* b b) (* (* 4 a) c))

simplify3.3s

Counts
37 → 74
Calls

37 calls. Slowest were:

628.0ms
(* (- (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* b b)) 1)
380.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
254.0ms
(* (- (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* b b)) (/ 1 (* 2 a)))

prune768.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 6.9b

localize18.0ms

Local error

Found 4 expressions with local error:

23.3b
(sqrt (- (* b b) (* (* 4 a) c)))
15.1b
(/ (+ (* -4 (* a c)) 0) (/ a 1/2))
1.0b
(- (* b b) (* (* 4 a) c))
0.8b
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)

rewrite30.0ms

Algorithm
rewrite-expression-head
Counts
4 → 70
Calls

4 calls. Slowest were:

15.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
7.0ms
(/ (+ (* -4 (* a c)) 0) (/ a 1/2))
4.0ms
(- (* b b) (* (* 4 a) c))

series179.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

73.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
65.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
35.0ms
(- (* b b) (* (* 4 a) c))
6.0ms
(/ (+ (* -4 (* a c)) 0) (/ a 1/2))

simplify3.7s

Counts
53 → 82
Calls

53 calls. Slowest were:

757.0ms
(/ (+ (* -4 (* a c)) 0) (/ a 1/2))
461.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
379.0ms
(/ (+ (* -4 (* a c)) 0) (/ 1 1/2))

prune993.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 6.9b

localize12.0ms

Local error

Found 4 expressions with local error:

23.3b
(sqrt (- (* b b) (* (* 4 a) c)))
1.0b
(- (* b b) (* (* 4 a) c))
0.8b
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
0.1b
(/ (* -2 c) (+ (sqrt (- (* b b) (* (* 4 a) c))) b))

rewrite26.0ms

Algorithm
rewrite-expression-head
Counts
4 → 57
Calls

4 calls. Slowest were:

11.0ms
(/ (* -2 c) (+ (sqrt (- (* b b) (* (* 4 a) c))) b))
7.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
4.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series301.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

151.0ms
(/ (* -2 c) (+ (sqrt (- (* b b) (* (* 4 a) c))) b))
72.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
46.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
33.0ms
(- (* b b) (* (* 4 a) c))

simplify2.1s

Counts
32 → 69
Calls

32 calls. Slowest were:

441.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
335.0ms
(+ (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (- (* b b) (* (sqrt (- (* b b) (* (* 4 a) c))) b)))
163.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune690.0ms

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 6.9b

regimes650.0ms

Accuracy

95.3% (1.1b remaining)

Error of 6.7b against oracle of 5.6b and baseline of 28.9b

bsearch694.0ms

end0.0ms

sample4.5s

Algorithm
intervals