Average Error: 33.4 → 6.7
Time: 23.6s
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. Using strategy rm
    3. Applied div-inv45.4

      \[\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. 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 0 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}{\left(-b\right) - \color{blue}{1 \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\]
    11. Applied *-un-lft-identity9.1

      \[\leadsto \frac{2 \cdot c}{\color{blue}{1 \cdot \left(-b\right)} - 1 \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\]
    12. Applied distribute-lft-out--9.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)}}\]
    13. 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. Using strategy rm
    3. Applied div-inv58.7

      \[\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. Taylor expanded around inf 2.9

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    5. 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: 22.7s)Debug log

sample168.0ms

Algorithm
intervals

simplify75.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune18.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))

rewrite49.0ms

Algorithm
rewrite-expression-head
Counts
4 → 63
Calls

4 calls. Slowest were:

37.0ms
(/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a))
6.0ms
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
3.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series290.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

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

simplify2.6s

Counts
36 → 75
Calls

36 calls. Slowest were:

458.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
300.0ms
(+ (pow (- b) 3) (pow (sqrt (- (* b b) (* (* 4 a) c))) 3))
291.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))))

prune895.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 6.9b

localize7.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)))

rewrite43.0ms

Algorithm
rewrite-expression-head
Counts
4 → 65
Calls

4 calls. Slowest were:

22.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))

series230.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

87.0ms
(* (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (/ 1 (* 2 a)))
58.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
50.0ms
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
34.0ms
(- (* b b) (* (* 4 a) c))

simplify3.7s

Counts
39 → 77
Calls

39 calls. Slowest were:

489.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
455.0ms
(* (- (* (- b) (- b)) (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c))))) 1)
347.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 (9 fresh and 0 done)

Merged error: 6.9b

localize37.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))))

rewrite18.0ms

Algorithm
rewrite-expression-head
Counts
4 → 59
Calls

4 calls. Slowest were:

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

series164.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

54.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
54.0ms
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
47.0ms
(- (* b b) (* (* 4 a) c))
8.0ms
(* (* (* c a) 4) (/ 1/2 a))

simplify2.2s

Counts
33 → 71
Calls

33 calls. Slowest were:

394.0ms
(+ (log (* (* c a) 4)) (log (/ 1/2 a)))
382.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
231.0ms
(* (* (* c a) 4) (/ 1/2 a))

prune1.3s

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 6.9b

localize7.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)))))

rewrite25.0ms

Algorithm
rewrite-expression-head
Counts
4 → 69
Calls

4 calls. Slowest were:

11.0ms
(/ (* 2 c) (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))))
7.0ms
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
3.0ms
(- (* b b) (* (* 4 a) c))

series314.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

149.0ms
(/ (* 2 c) (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))))
70.0ms
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
62.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
33.0ms
(- (* b b) (* (* 4 a) c))

simplify2.8s

Counts
47 → 81
Calls

47 calls. Slowest were:

356.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
353.0ms
(+ (* (- b) (- b)) (+ (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* (- b) (sqrt (- (* b b) (* (* 4 a) c))))))
148.0ms
(- b (* 2 (/ (* a c) b)))

prune815.0ms

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 6.9b

regimes377.0ms

Accuracy

95.3% (1.1b remaining)

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

bsearch693.0ms

end0.0ms

sample4.8s

Algorithm
intervals