Average Error: 33.5 → 9.4
Time: 26.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 -2.835340391058544 \cdot 10^{+148}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 3.587545867948427 \cdot 10^{-80}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 8.686813508697628 \cdot 10^{-23} \lor \neg \left(b \le 6.168799619006917 \cdot 10^{+62}\right):\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{2}}{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} + b} \cdot \frac{c \cdot \left(-4 \cdot a\right)}{a}\\ \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.5
Target20.5
Herbie9.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 4 regimes
  2. if b < -2.835340391058544e+148

    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. Taylor expanded around -inf 2.1

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

    if -2.835340391058544e+148 < b < 3.587545867948427e-80

    1. Initial program 12.5

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

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

    if 3.587545867948427e-80 < b < 8.686813508697628e-23 or 6.168799619006917e+62 < b

    1. Initial program 54.1

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

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

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

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

    if 8.686813508697628e-23 < b < 6.168799619006917e+62

    1. Initial program 46.2

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

      \[\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-num46.2

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

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

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

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

      \[\leadsto \frac{\frac{1}{\frac{2}{1}}}{\frac{a}{\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}}}}\]
    11. Applied associate-/r/46.2

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

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

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

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

      \[\leadsto \frac{\left(-4 \cdot a\right) \cdot c + 0}{a} \cdot \color{blue}{\frac{\frac{1}{2}}{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} + b}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification9.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.835340391058544 \cdot 10^{+148}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 3.587545867948427 \cdot 10^{-80}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 8.686813508697628 \cdot 10^{-23} \lor \neg \left(b \le 6.168799619006917 \cdot 10^{+62}\right):\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{2}}{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} + b} \cdot \frac{c \cdot \left(-4 \cdot a\right)}{a}\\ \end{array}\]

Reproduce

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

sample159.0ms

Algorithm
intervals

simplify312.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune10.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 32.6b

localize20.0ms

Local error

Found 4 expressions with local error:

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

rewrite40.0ms

Algorithm
rewrite-expression-head
Counts
4 → 59
Calls

4 calls. Slowest were:

21.0ms
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))
15.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
2.0ms
(- (* b b) (* (* 4 a) c))

series167.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

57.0ms
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))
43.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
41.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
25.0ms
(- (* b b) (* (* 4 a) c))

simplify1.8s

Counts
32 → 71
Calls

32 calls. Slowest were:

379.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
265.0ms
(- (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* b b))
185.0ms
(- (pow (sqrt (- (* b b) (* (* 4 a) c))) 3) (pow b 3))

prune569.0ms

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 4.8b

localize6.0ms

Local error

Found 4 expressions with local error:

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

rewrite23.0ms

Algorithm
rewrite-expression-head
Counts
4 → 71
Calls

4 calls. Slowest were:

12.0ms
(/ (* 2 a) (- (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))

series302.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

130.0ms
(/ (* 2 a) (- (sqrt (- (* b b) (* (* 4 a) c))) b))
89.0ms
(/ 1 (/ (* 2 a) (- (sqrt (- (* b b) (* (* 4 a) c))) b)))
54.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
28.0ms
(- (* b b) (* (* 4 a) c))

simplify2.3s

Counts
43 → 83
Calls

43 calls. Slowest were:

415.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
177.0ms
(+ (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (+ (* b b) (* (sqrt (- (* b b) (* (* 4 a) c))) b)))
136.0ms
(- b (* 2 (/ (* a c) b)))

prune1.0s

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 4.8b

localize21.0ms

Local error

Found 4 expressions with local error:

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

rewrite33.0ms

Algorithm
rewrite-expression-head
Counts
4 → 97
Calls

4 calls. Slowest were:

12.0ms
(/ (/ 1 (/ 2 1)) (/ a (- (sqrt (- (* b b) (* (* 4 a) c))) b)))
11.0ms
(/ a (- (sqrt (- (* b b) (* (* 4 a) c))) b))
4.0ms
(- (* b b) (* (* 4 a) c))

series408.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

166.0ms
(/ a (- (sqrt (- (* b b) (* (* 4 a) c))) b))
128.0ms
(/ (/ 1 (/ 2 1)) (/ a (- (sqrt (- (* b b) (* (* 4 a) c))) b)))
71.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
43.0ms
(- (* b b) (* (* 4 a) c))

simplify8.1s

Counts
97 → 109
Calls

97 calls. Slowest were:

511.0ms
(/ (/ 1 2) (/ a (- (pow (sqrt (- (* b b) (* (* 4 a) c))) 3) (pow b 3))))
407.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
344.0ms
(/ 1 (/ a (- (pow (sqrt (- (* b b) (* (* 4 a) c))) 3) (pow b 3))))

prune1.4s

Pruning

7 alts after pruning (6 fresh and 1 done)

Merged error: 4.8b

localize13.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (- (* b b) (* (* 4 a) c)))
22.0b
(sqrt (- (* b b) (* (* 4 a) c)))
10.5b
(- (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))) b)
0.8b
(- (* b b) (* (* 4 a) c))

rewrite30.0ms

Algorithm
rewrite-expression-head
Counts
4 → 51
Calls

4 calls. Slowest were:

17.0ms
(- (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))) b)
7.0ms
(- (* b b) (* (* 4 a) c))
2.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series223.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

68.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
66.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
53.0ms
(- (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))) b)
35.0ms
(- (* b b) (* (* 4 a) c))

simplify2.0s

Counts
25 → 63
Calls

25 calls. Slowest were:

364.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
343.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
200.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune754.0ms

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 4.8b

regimes384.0ms

Accuracy

85.9% (4.0b remaining)

Error of 9.4b against oracle of 5.5b and baseline of 33.5b

bsearch836.0ms

end0.0ms

sample4.8s

Algorithm
intervals