Average Error: 33.2 → 9.6
Time: 30.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 -4.9529633933266 \cdot 10^{-08}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -1.432147794020809 \cdot 10^{-104}:\\ \;\;\;\;\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 -5.51185453096989 \cdot 10^{-127}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 8.046684077965657 \cdot 10^{+99}:\\ \;\;\;\;\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.2
Target20.4
Herbie9.6
\[\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 < -4.9529633933266e-08 or -1.432147794020809e-104 < b < -5.51185453096989e-127

    1. Initial program 53.5

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

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

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

    if -4.9529633933266e-08 < b < -1.432147794020809e-104

    1. Initial program 34.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--34.9

      \[\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/38.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. Simplified21.5

      \[\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 -5.51185453096989e-127 < b < 8.046684077965657e+99

    1. Initial program 11.0

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

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

      \[\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.046684077965657e+99 < b

    1. Initial program 44.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 *-un-lft-identity44.6

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.9529633933266 \cdot 10^{-08}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -1.432147794020809 \cdot 10^{-104}:\\ \;\;\;\;\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 -5.51185453096989 \cdot 10^{-127}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 8.046684077965657 \cdot 10^{+99}:\\ \;\;\;\;\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 2019004 
(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: 29.8s)Debug log

sample172.0ms

Algorithm
intervals

simplify87.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune6.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 33.9b

localize35.0ms

Local error

Found 4 expressions with local error:

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

rewrite30.0ms

Algorithm
rewrite-expression-head
Counts
4 → 70
Calls

4 calls. Slowest were:

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

series194.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

58.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
54.0ms
(sqrt (- (* b b) (* 4 (* a c))))
54.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
28.0ms
(- (* b b) (* 4 (* a c)))

simplify2.6s

Counts
46 → 82
Calls

46 calls. Slowest were:

273.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
230.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))))
221.0ms
(- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3))

prune1.1s

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 5.1b

localize32.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (- (pow b 2) (* 4 (* a c))))
0.9b
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
0.8b
(- (pow b 2) (* 4 (* a c)))
0.1b
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))

rewrite64.0ms

Algorithm
rewrite-expression-head
Counts
4 → 70
Calls

4 calls. Slowest were:

38.0ms
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))
12.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
6.0ms
(- (pow b 2) (* 4 (* a c)))

series235.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

80.0ms
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))
74.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
46.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
34.0ms
(- (pow b 2) (* 4 (* a c)))

simplify3.4s

Counts
46 → 82
Calls

46 calls. Slowest were:

970.0ms
(- (* (- b) (- b)) (* (sqrt (- (pow b 2) (* 4 (* a c)))) (sqrt (- (pow b 2) (* 4 (* a c))))))
332.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
217.0ms
(- (pow (- b) 3) (pow (sqrt (- (pow b 2) (* 4 (* a c)))) 3))

prune981.0ms

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 5.1b

localize6.0ms

Local error

Found 4 expressions with local error:

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

rewrite16.0ms

Algorithm
rewrite-expression-head
Counts
4 → 69
Calls

4 calls. Slowest were:

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

series256.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

109.0ms
(/ 1 (/ (* 2 a) (- (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
73.0ms
(sqrt (- (* b b) (* 4 (* a c))))
46.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
28.0ms
(- (* b b) (* 4 (* a c)))

simplify2.2s

Counts
39 → 81
Calls

39 calls. Slowest were:

443.0ms
(+ (* (- b) (- b)) (+ (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))) (* (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
265.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
144.0ms
(sqrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))

prune1.1s

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 5.1b

localize18.0ms

Local error

Found 4 expressions with local error:

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

rewrite31.0ms

Algorithm
rewrite-expression-head
Counts
4 → 93
Calls

4 calls. Slowest were:

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

series212.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

78.0ms
(/ (/ 1 (* 2 a)) (/ 1 (- (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
56.0ms
(sqrt (- (* b b) (* 4 (* a c))))
51.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
26.0ms
(- (* b b) (* 4 (* a c)))

simplify9.5s

Counts
87 → 105
Calls

87 calls. Slowest were:

660.0ms
(/ (cbrt (/ 1 (* 2 a))) (+ (* (- b) (- b)) (+ (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))) (* (- b) (sqrt (- (* b b) (* 4 (* a c))))))))
570.0ms
(/ 1 (/ 1 (- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))))))
483.0ms
(/ 1 (/ 1 (- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))))))

prune1.3s

Pruning

10 alts after pruning (8 fresh and 2 done)

Merged error: 5.1b

regimes354.0ms

Accuracy

85.2% (4.1b remaining)

Error of 9.6b against oracle of 5.5b and baseline of 33.2b

bsearch819.0ms

end0.0ms

sample5.0s

Algorithm
intervals