Average Error: 33.6 → 10.0
Time: 32.1s
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.584464648766991 \cdot 10^{+89}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -1.6242069554645545 \cdot 10^{-96}:\\ \;\;\;\;\frac{\left(4 \cdot c\right) \cdot a}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}\\ \mathbf{elif}\;b \le 8.095749828230367 \cdot 10^{+95}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{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.6
Target20.6
Herbie10.0
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\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 < -1.584464648766991e+89

    1. Initial program 58.8

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around -inf 3.0

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

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

    if -1.584464648766991e+89 < b < -1.6242069554645545e-96

    1. Initial program 41.9

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

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

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

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

    if -1.6242069554645545e-96 < b < 8.095749828230367e+95

    1. Initial program 12.6

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied clear-num12.7

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

    if 8.095749828230367e+95 < b

    1. Initial program 42.9

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied clear-num43.0

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    5. Simplified3.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.584464648766991 \cdot 10^{+89}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -1.6242069554645545 \cdot 10^{-96}:\\ \;\;\;\;\frac{\left(4 \cdot c\right) \cdot a}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}\\ \mathbf{elif}\;b \le 8.095749828230367 \cdot 10^{+95}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2019005 
(FPCore (a b c)
  :name "The quadratic formula (r2)"

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

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

Details

Time bar (total: 31.0s)Debug log

sample159.0ms

Algorithm
intervals

simplify100.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune14.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 34.4b

localize36.0ms

Local error

Found 4 expressions with local error:

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

rewrite29.0ms

Algorithm
rewrite-expression-head
Counts
4 → 70
Calls

4 calls. Slowest were:

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

series256.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

73.0ms
(sqrt (- (* b b) (* 4 (* a c))))
71.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
71.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
41.0ms
(- (* b b) (* 4 (* a c)))

simplify2.6s

Counts
46 → 82
Calls

46 calls. Slowest were:

268.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
244.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))))
226.0ms
(- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3))

prune938.0ms

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 6.4b

localize18.0ms

Local error

Found 4 expressions with local error:

24.3b
(sqrt (- (* b b) (* 4 (* a c))))
16.9b
(/ (* (* c 4) a) (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
1.1b
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
0.4b
(- (* b b) (* 4 (* a c)))

rewrite32.0ms

Algorithm
rewrite-expression-head
Counts
4 → 58
Calls

4 calls. Slowest were:

13.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
11.0ms
(/ (* (* c 4) a) (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
5.0ms
(- (* b b) (* 4 (* a c)))

series311.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

148.0ms
(/ (* (* c 4) a) (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
67.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
58.0ms
(sqrt (- (* b b) (* 4 (* a c))))
38.0ms
(- (* b b) (* 4 (* a c)))

simplify3.4s

Counts
31 → 70
Calls

31 calls. Slowest were:

801.0ms
(/ (* (* (* (* c 4) a) (* (* c 4) a)) (* (* c 4) a)) (* (* (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))) (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))))) (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))))))
734.0ms
(/ (* (* (* (* c 4) a) (* (* c 4) a)) (* (* c 4) a)) (* (* (* (* 2 a) (* 2 a)) (* 2 a)) (* (* (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))) (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))))))
388.0ms
(+ (* (- b) (- b)) (- (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))) (* (- b) (sqrt (- (* b b) (* 4 (* a c)))))))

prune860.0ms

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 6.4b

localize27.0ms

Local error

Found 4 expressions with local error:

25.1b
(cbrt (- (* b b) (* 4 (* a c))))
25.1b
(cbrt (- (* b b) (* 4 (* a c))))
25.1b
(cbrt (- (* b b) (* 4 (* a c))))
24.3b
(sqrt (* (* (cbrt (- (* b b) (* 4 (* a c)))) (cbrt (- (* b b) (* 4 (* a c))))) (cbrt (- (* b b) (* 4 (* a c))))))

rewrite15.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))))))
1.0ms
(cbrt (- (* b b) (* 4 (* a c))))
1.0ms
(cbrt (- (* b b) (* 4 (* a c))))

series342.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

115.0ms
(cbrt (- (* b b) (* 4 (* a c))))
99.0ms
(cbrt (- (* b b) (* 4 (* a c))))
88.0ms
(cbrt (- (* b b) (* 4 (* a c))))
40.0ms
(sqrt (* (* (cbrt (- (* b b) (* 4 (* a c)))) (cbrt (- (* b b) (* 4 (* a c))))) (cbrt (- (* b b) (* 4 (* a c))))))

simplify10.7s

Counts
54 → 86
Calls

54 calls. Slowest were:

643.0ms
(sqrt (* (* (cbrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3))) (cbrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))) (cbrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))))
585.0ms
(sqrt (* (* (cbrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3))) (cbrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))) (cbrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))))
572.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)))))))

prune2.1s

Pruning

8 alts after pruning (6 fresh and 2 done)

Merged error: 6.4b

localize13.0ms

Local error

Found 4 expressions with local error:

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

rewrite35.0ms

Algorithm
rewrite-expression-head
Counts
4 → 69
Calls

4 calls. Slowest were:

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

series258.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

110.0ms
(/ 1 (/ (* 2 a) (- (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
62.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
45.0ms
(sqrt (- (* b b) (* 4 (* a c))))
41.0ms
(- (* b b) (* 4 (* a c)))

simplify2.3s

Counts
39 → 81
Calls

39 calls. Slowest were:

424.0ms
(+ (* (- b) (- b)) (+ (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))) (* (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
308.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
165.0ms
(sqrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))

prune873.0ms

Pruning

8 alts after pruning (5 fresh and 3 done)

Merged error: 6.4b

regimes321.0ms

Accuracy

86% (4.1b remaining)

Error of 10.0b against oracle of 6.0b and baseline of 35.0b

bsearch466.0ms

end0.0ms

sample4.8s

Algorithm
intervals