Average Error: 33.6 → 10.6
Time: 29.6s
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.854031372780893 \cdot 10^{+121}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -9.565134490438525 \cdot 10^{-14}:\\ \;\;\;\;\frac{\left(4 \cdot c\right) \cdot a}{\left(2 \cdot a\right) \cdot \left(\sqrt{b \cdot b + a \cdot \left(-4 \cdot c\right)} - b\right)}\\ \mathbf{elif}\;b \le -1.4327714371069 \cdot 10^{-133}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 1.6367105644834092 \cdot 10^{+113}:\\ \;\;\;\;\left(\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}\\ \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.6
Target20.3
Herbie10.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.854031372780893e+121 or -9.565134490438525e-14 < b < -1.4327714371069e-133

    1. Initial program 51.7

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

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

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

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

    if -4.854031372780893e+121 < b < -9.565134490438525e-14

    1. Initial program 46.3

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}}}\]
    6. Using strategy rm
    7. Applied associate-/r/46.3

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

      \[\leadsto \frac{1}{2 \cdot a} \cdot \color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)} \cdot \sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}{\left(-b\right) + \sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}}\]
    10. Applied frac-times48.0

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

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

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

    if -1.4327714371069e-133 < b < 1.6367105644834092e+113

    1. Initial program 11.5

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}}}\]
    6. Using strategy rm
    7. Applied associate-/r/11.6

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

    if 1.6367105644834092e+113 < b

    1. Initial program 46.8

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}}}\]
    6. Using strategy rm
    7. Applied associate-/r/46.8

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.854031372780893 \cdot 10^{+121}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -9.565134490438525 \cdot 10^{-14}:\\ \;\;\;\;\frac{\left(4 \cdot c\right) \cdot a}{\left(2 \cdot a\right) \cdot \left(\sqrt{b \cdot b + a \cdot \left(-4 \cdot c\right)} - b\right)}\\ \mathbf{elif}\;b \le -1.4327714371069 \cdot 10^{-133}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 1.6367105644834092 \cdot 10^{+113}:\\ \;\;\;\;\left(\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2018360 
(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: 21.6s)Debug log

start234.0ms

Algorithm
intervals

setup91.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 32.8b

localize28.0ms

Local error

Found 4 expressions with local error:

22.7b
(sqrt (- (* b b) (* 4 (* a c))))
0.8b
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
0.4b
(- (* b b) (* 4 (* a c)))
0.1b
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))

rewrite25.0ms

Algorithm
rewrite-expression-head
Counts
4 → 70
Calls

4 calls. Slowest were:

15.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
5.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
2.0ms
(- (* b b) (* 4 (* a c)))

series260.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

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

simplify2.7s

Counts
46 → 82
Calls

46 calls. Slowest were:

376.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
287.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))))
227.0ms
(- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3))

prune1.0s

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 4.7b

localize14.0ms

Local error

Found 4 expressions with local error:

22.7b
(sqrt (- (pow b 2) (* 4 (* a c))))
0.8b
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
0.4b
(- (pow b 2) (* 4 (* a c)))
0.1b
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))

rewrite51.0ms

Algorithm
rewrite-expression-head
Counts
4 → 70
Calls

4 calls. Slowest were:

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

series246.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

82.0ms
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))
68.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
68.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
28.0ms
(- (pow b 2) (* 4 (* a c)))

simplify3.1s

Counts
46 → 82
Calls

46 calls. Slowest were:

687.0ms
(- (* (- b) (- b)) (* (sqrt (- (pow b 2) (* 4 (* a c)))) (sqrt (- (pow b 2) (* 4 (* a c))))))
391.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
250.0ms
(- (pow (- b) 3) (pow (sqrt (- (pow b 2) (* 4 (* a c)))) 3))

prune1.1s

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 4.7b

localize12.0ms

Local error

Found 4 expressions with local error:

22.7b
(sqrt (- (pow b 2) (* 4 (* a c))))
0.8b
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
0.4b
(- (pow b 2) (* 4 (* a c)))
0.1b
(/ 1 (/ (* 2 a) (- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))))

rewrite37.0ms

Algorithm
rewrite-expression-head
Counts
4 → 69
Calls

4 calls. Slowest were:

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

series295.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

107.0ms
(/ 1 (/ (* 2 a) (- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))))
75.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
65.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
48.0ms
(- (pow b 2) (* 4 (* a c)))

simplify2.6s

Counts
39 → 81
Calls

39 calls. Slowest were:

499.0ms
(+ (* (- b) (- b)) (+ (* (sqrt (- (pow b 2) (* 4 (* a c)))) (sqrt (- (pow b 2) (* 4 (* a c))))) (* (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))))
424.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
170.0ms
(sqrt (- (* (pow b 2) (pow b 2)) (* (* 4 (* a c)) (* 4 (* a c)))))

prune1.2s

Pruning

7 alts after pruning (6 fresh and 1 done)

Merged error: 4.7b

localize6.0ms

Local error

Found 4 expressions with local error:

22.7b
(sqrt (- (pow b 2) (* 4 (* a c))))
0.8b
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
0.4b
(- (pow b 2) (* 4 (* a c)))
0.2b
(* (/ 1 (* 2 a)) (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))))

rewrite53.0ms

Algorithm
rewrite-expression-head
Counts
4 → 73
Calls

4 calls. Slowest were:

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

series262.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

80.0ms
(* (/ 1 (* 2 a)) (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))))
76.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
63.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
43.0ms
(- (pow b 2) (* 4 (* a c)))

simplify5.2s

Counts
48 → 85
Calls

48 calls. Slowest were:

462.0ms
(* 1 (- (pow (- b) 3) (pow (sqrt (- (pow b 2) (* 4 (* a c)))) 3)))
449.0ms
(+ (* (- b) (- b)) (+ (* (sqrt (- (pow b 2) (* 4 (* a c)))) (sqrt (- (pow b 2) (* 4 (* a c))))) (* (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))))
430.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))

prune1.8s

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 4.7b

regimes382.0ms

Accuracy

81.8% (5.1b remaining)

Error of 10.6b against oracle of 5.5b and baseline of 33.7b

bsearch897.0ms