Average Error: 33.2 → 6.6
Time: 23.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 -1.1121654501400248 \cdot 10^{+139}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -6.179298479433663 \cdot 10^{-282}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le 7.734953967976876 \cdot 10^{+108}:\\ \;\;\;\;\frac{1}{a \cdot 2} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\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.7
Herbie6.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 < -1.1121654501400248e+139

    1. Initial program 61.2

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

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

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

    if -1.1121654501400248e+139 < b < -6.179298479433663e-282

    1. Initial program 34.1

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

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

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

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

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

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

    if -6.179298479433663e-282 < b < 7.734953967976876e+108

    1. Initial program 9.5

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

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

    if 7.734953967976876e+108 < b

    1. Initial program 46.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 div-inv46.6

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.1121654501400248 \cdot 10^{+139}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -6.179298479433663 \cdot 10^{-282}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le 7.734953967976876 \cdot 10^{+108}:\\ \;\;\;\;\frac{1}{a \cdot 2} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2019008 
(FPCore (a b c)
  :name "quadm (p42, negative)"

  :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: 22.8s)Debug log

sample168.0ms

Algorithm
intervals

simplify448.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune7.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 34.0b

localize31.0ms

Local error

Found 4 expressions with local error:

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

rewrite38.0ms

Algorithm
rewrite-expression-head
Counts
4 → 70
Calls

4 calls. Slowest were:

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

series236.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

80.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
71.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
53.0ms
(sqrt (- (* b b) (* 4 (* a c))))
32.0ms
(- (* b b) (* 4 (* a c)))

simplify2.6s

Counts
46 → 82
Calls

46 calls. Slowest were:

322.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
276.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))))
234.0ms
(- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3))

prune1.1s

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 6.6b

localize13.0ms

Local error

Found 4 expressions with local error:

23.7b
(sqrt (- (* b b) (* 4 (* a c))))
1.0b
(- (* b b) (* 4 (* a c)))
0.8b
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
0.2b
(* (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (/ 1 (* 2 a)))

rewrite27.0ms

Algorithm
rewrite-expression-head
Counts
4 → 70
Calls

4 calls. Slowest were:

16.0ms
(* (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (/ 1 (* 2 a)))
5.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
3.0ms
(sqrt (- (* b b) (* 4 (* a c))))

series188.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

55.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
53.0ms
(* (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (/ 1 (* 2 a)))
50.0ms
(sqrt (- (* b b) (* 4 (* a c))))
30.0ms
(- (* b b) (* 4 (* a c)))

simplify4.5s

Counts
45 → 82
Calls

45 calls. Slowest were:

548.0ms
(* (- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c)))))) 1)
513.0ms
(* (- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3)) 1)
421.0ms
(* (- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c)))))) (/ 1 (* 2 a)))

prune1.0s

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 6.6b

localize30.0ms

Local error

Found 4 expressions with local error:

23.7b
(sqrt (- (* b b) (* 4 (* a c))))
15.4b
(* (* (* 4 a) c) (/ 1/2 a))
1.0b
(- (* b b) (* 4 (* a c)))
0.9b
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))

rewrite17.0ms

Algorithm
rewrite-expression-head
Counts
4 → 56
Calls

4 calls. Slowest were:

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

series163.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

57.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
52.0ms
(sqrt (- (* b b) (* 4 (* a c))))
43.0ms
(- (* b b) (* 4 (* a c)))
11.0ms
(* (* (* 4 a) c) (/ 1/2 a))

simplify2.1s

Counts
29 → 68
Calls

29 calls. Slowest were:

339.0ms
(+ (log (* (* 4 a) c)) (log (/ 1/2 a)))
314.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
284.0ms
(* (* (* 4 a) c) (/ 1/2 a))

prune832.0ms

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 6.6b

localize7.0ms

Local error

Found 4 expressions with local error:

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

rewrite47.0ms

Algorithm
rewrite-expression-head
Counts
4 → 62
Calls

4 calls. Slowest were:

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

series284.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

151.0ms
(/ (* 2 c) (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))))
57.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
50.0ms
(sqrt (- (* b b) (* 4 (* a c))))
26.0ms
(- (* b b) (* 4 (* a c)))

simplify2.2s

Counts
37 → 74
Calls

37 calls. Slowest were:

359.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
348.0ms
(+ (* (- b) (- b)) (- (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))) (* (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
146.0ms
(sqrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))

prune938.0ms

Pruning

9 alts after pruning (7 fresh and 2 done)

Merged error: 6.6b

regimes365.0ms

Accuracy

95.4% (1.1b remaining)

Error of 6.6b against oracle of 5.5b and baseline of 29.4b

bsearch519.0ms

end0.0ms

sample5.1s

Algorithm
intervals