Average Error: 33.4 → 6.7
Time: 18.7s
Precision: 64
Internal Precision: 128
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{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{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.408724732699167 \cdot 10^{+98}:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \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 - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{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 - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. 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 - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied div-inv9.0

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

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

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

    1. Initial program 32.5

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

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

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

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

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

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

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

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

    if 2.408724732699167e+98 < b

    1. Initial program 58.7

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    3. 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{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.408724732699167 \cdot 10^{+98}:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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

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

sample158.0ms

Algorithm
intervals

simplify79.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune20.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 34.5b

localize24.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
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
0.1b
(/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a))

rewrite45.0ms

Algorithm
rewrite-expression-head
Counts
4 → 63
Calls

4 calls. Slowest were:

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

series208.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

78.0ms
(/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a))
58.0ms
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
40.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
31.0ms
(- (* b b) (* (* 4 a) c))

simplify2.2s

Counts
36 → 75
Calls

36 calls. Slowest were:

412.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
234.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))))
224.0ms
(+ (pow (- b) 3) (pow (sqrt (- (* b b) (* (* 4 a) c))) 3))

prune754.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 6.9b

localize9.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
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
0.2b
(* (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (/ 1 (* 2 a)))

rewrite47.0ms

Algorithm
rewrite-expression-head
Counts
4 → 65
Calls

4 calls. Slowest were:

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

series249.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

70.0ms
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
68.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
66.0ms
(* (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (/ 1 (* 2 a)))
45.0ms
(- (* b b) (* (* 4 a) c))

simplify3.0s

Counts
39 → 77
Calls

39 calls. Slowest were:

379.0ms
(* (- (* (- b) (- b)) (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c))))) 1)
336.0ms
(* (- (* (- b) (- b)) (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c))))) (/ 1 (* 2 a)))
308.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))

prune723.0ms

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 6.9b

localize16.0ms

Local error

Found 4 expressions with local error:

23.3b
(sqrt (- (* b b) (* (* 4 a) c)))
15.2b
(* (* (* c a) 4) (/ 1/2 a))
1.0b
(- (* b b) (* (* 4 a) c))
0.8b
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))

rewrite19.0ms

Algorithm
rewrite-expression-head
Counts
4 → 59
Calls

4 calls. Slowest were:

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

series135.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

52.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
50.0ms
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
25.0ms
(- (* b b) (* (* 4 a) c))
7.0ms
(* (* (* c a) 4) (/ 1/2 a))

simplify1.7s

Counts
33 → 71
Calls

33 calls. Slowest were:

298.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
290.0ms
(+ (log (* (* c a) 4)) (log (/ 1/2 a)))
197.0ms
(* (* (* c a) 4) (/ 1/2 a))

prune689.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.8b
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
0.1b
(/ (* 2 c) (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))))

rewrite26.0ms

Algorithm
rewrite-expression-head
Counts
4 → 69
Calls

4 calls. Slowest were:

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

series242.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

111.0ms
(/ (* 2 c) (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))))
64.0ms
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
42.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
24.0ms
(- (* b b) (* (* 4 a) c))

simplify2.3s

Counts
47 → 81
Calls

47 calls. Slowest were:

346.0ms
(+ (* (- b) (- b)) (+ (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* (- b) (sqrt (- (* b b) (* (* 4 a) c))))))
324.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
127.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune677.0ms

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 6.9b

regimes422.0ms

Accuracy

95.3% (1.1b remaining)

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

bsearch966.0ms

end0.0ms

sample3.4s

Algorithm
intervals