Average Error: 33.1 → 10.3
Time: 19.4s
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 -2.8671071746705253 \cdot 10^{+127}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.354454736393541 \cdot 10^{-170}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}}\\ \mathbf{elif}\;b \le 9.22274670563189 \cdot 10^{-75}:\\ \;\;\;\;\frac{a}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + b} \cdot \frac{\frac{c}{\frac{-1}{2}}}{a}\\ \mathbf{elif}\;b \le 1.849572225033813 \cdot 10^{-22}:\\ \;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}}{a} \cdot \frac{\sqrt{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}}{2}\\ \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.1
Target20.7
Herbie10.3
\[\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 5 regimes
  2. if b < -2.8671071746705253e+127

    1. Initial program 51.2

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified51.2

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

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

    if -2.8671071746705253e+127 < b < 1.354454736393541e-170

    1. Initial program 11.4

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified11.3

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

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

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

    if 1.354454736393541e-170 < b < 9.22274670563189e-75

    1. Initial program 24.9

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified24.9

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

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

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

      \[\leadsto \frac{\color{blue}{\left(c \cdot -4\right) \cdot a}}{\left(2 \cdot a\right) \cdot \left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b\right)}\]
    7. Using strategy rm
    8. Applied times-frac18.2

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

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

    if 9.22274670563189e-75 < b < 1.849572225033813e-22

    1. Initial program 37.0

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified37.0

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt37.5

      \[\leadsto \frac{\color{blue}{\sqrt{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b} \cdot \sqrt{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}}}{2 \cdot a}\]
    5. Applied times-frac37.5

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

    if 1.849572225033813e-22 < b

    1. Initial program 54.3

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified54.3

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.8671071746705253 \cdot 10^{+127}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.354454736393541 \cdot 10^{-170}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}}\\ \mathbf{elif}\;b \le 9.22274670563189 \cdot 10^{-75}:\\ \;\;\;\;\frac{a}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + b} \cdot \frac{\frac{c}{\frac{-1}{2}}}{a}\\ \mathbf{elif}\;b \le 1.849572225033813 \cdot 10^{-22}:\\ \;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}}{a} \cdot \frac{\sqrt{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}}{2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019005 
(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.8s)Debug log

sample90.0ms

Algorithm
intervals

simplify114.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune20.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 32.2b

localize52.0ms

Local error

Found 4 expressions with local error:

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

rewrite46.0ms

Algorithm
rewrite-expression-head
Counts
4 → 59
Calls

4 calls. Slowest were:

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

series225.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

69.0ms
(/ (- (sqrt (- (* b b) (* (* c a) 4))) b) (* 2 a))
67.0ms
(- (sqrt (- (* b b) (* (* c a) 4))) b)
64.0ms
(sqrt (- (* b b) (* (* c a) 4)))
24.0ms
(- (* b b) (* (* c a) 4))

simplify2.4s

Counts
32 → 71
Calls

32 calls. Slowest were:

377.0ms
(- (* (sqrt (- (* b b) (* (* c a) 4))) (sqrt (- (* b b) (* (* c a) 4)))) (* b b))
366.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))
251.0ms
(- (pow (sqrt (- (* b b) (* (* c a) 4))) 3) (pow b 3))

prune701.0ms

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 6.5b

localize13.0ms

Local error

Found 4 expressions with local error:

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

rewrite36.0ms

Algorithm
rewrite-expression-head
Counts
4 → 61
Calls

4 calls. Slowest were:

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

series234.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

99.0ms
(/ 1 (/ (* 2 a) (- (sqrt (- (* b b) (* (* c a) 4))) b)))
55.0ms
(- (sqrt (- (* b b) (* (* c a) 4))) b)
51.0ms
(sqrt (- (* b b) (* (* c a) 4)))
29.0ms
(- (* b b) (* (* c a) 4))

simplify1.7s

Counts
30 → 73
Calls

30 calls. Slowest were:

394.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))
228.0ms
(+ (* (sqrt (- (* b b) (* (* c a) 4))) (sqrt (- (* b b) (* (* c a) 4)))) (+ (* b b) (* (sqrt (- (* b b) (* (* c a) 4))) b)))
142.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* c a) 4) (* (* c a) 4))))

prune841.0ms

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 6.4b

localize24.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (- (* b b) (* (* c a) 4)))
23.2b
(sqrt (- (* b b) (* (* c a) 4)))
1.1b
(- (sqrt (- (* b b) (* (* c a) 4))) b)
1.1b
(- (sqrt (- (* b b) (* (* c a) 4))) b)

rewrite46.0ms

Algorithm
rewrite-expression-head
Counts
4 → 50
Calls

4 calls. Slowest were:

21.0ms
(- (sqrt (- (* b b) (* (* c a) 4))) b)
16.0ms
(- (sqrt (- (* b b) (* (* c a) 4))) b)
4.0ms
(sqrt (- (* b b) (* (* c a) 4)))

series255.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

76.0ms
(- (sqrt (- (* b b) (* (* c a) 4))) b)
73.0ms
(- (sqrt (- (* b b) (* (* c a) 4))) b)
54.0ms
(sqrt (- (* b b) (* (* c a) 4)))
52.0ms
(sqrt (- (* b b) (* (* c a) 4)))

simplify2.0s

Counts
24 → 62
Calls

24 calls. Slowest were:

404.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))
382.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))
147.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* c a) 4) (* (* c a) 4))))

prune751.0ms

Pruning

9 alts after pruning (7 fresh and 2 done)

Merged error: 6.4b

localize18.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (- (* b b) (* (* c a) 4)))
16.3b
(/ (* (* c -4) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b)))
1.1b
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
0.4b
(- (* b b) (* (* c a) 4))

rewrite30.0ms

Algorithm
rewrite-expression-head
Counts
4 → 55
Calls

4 calls. Slowest were:

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

series318.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

137.0ms
(/ (* (* c -4) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b)))
70.0ms
(sqrt (- (* b b) (* (* c a) 4)))
68.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
43.0ms
(- (* b b) (* (* c a) 4))

simplify3.8s

Counts
29 → 67
Calls

29 calls. Slowest were:

1.1s
(/ (* (* (* (* c -4) a) (* (* c -4) a)) (* (* c -4) a)) (* (* (* (* 2 a) (* 2 a)) (* 2 a)) (* (* (+ (sqrt (- (* b b) (* (* c a) 4))) b) (+ (sqrt (- (* b b) (* (* c a) 4))) b)) (+ (sqrt (- (* b b) (* (* c a) 4))) b))))
783.0ms
(/ (* (* (* (* c -4) a) (* (* c -4) a)) (* (* c -4) a)) (* (* (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b)) (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b))) (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b))))
323.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))

prune676.0ms

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 6.4b

regimes384.0ms

Accuracy

84.2% (4.3b remaining)

Error of 10.3b against oracle of 6.0b and baseline of 33.2b

bsearch682.0ms

end0.0ms

sample3.4s

Algorithm
intervals