Average Error: 33.5 → 10.4
Time: 24.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 -2.3604286795685533 \cdot 10^{-29}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 3.328175344273382 \cdot 10^{+63}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \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.5
Target20.6
Herbie10.4
\[\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 3 regimes
  2. if b < -2.3604286795685533e-29

    1. Initial program 54.6

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

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

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

    if -2.3604286795685533e-29 < b < 3.328175344273382e+63

    1. Initial program 15.3

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

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

    if 3.328175344273382e+63 < b

    1. Initial program 37.3

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

      \[\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 5.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.3604286795685533 \cdot 10^{-29}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 3.328175344273382 \cdot 10^{+63}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Reproduce

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

sample188.0ms

Algorithm
intervals
Results
368×(pre true 80)
182×(body real 80)
91×(body nan 80)
35×(body real 1280)
32×(body real 2560)
13×(body real 640)
(body real 320)
(body real 160)
(body real 5120)

simplify96.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
96.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))

prune12.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 35.2b

localize49.0ms

Local error

Found 4 expressions with local error:

24.0b
(sqrt (- (* b b) (* 4 (* a c))))
1.2b
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
1.2b
(- (* b b) (* 4 (* a c)))
0.1b
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))

rewrite60.0ms

Algorithm
rewrite-expression-head
Rules
20×add-sqr-sqrt
13×*-un-lft-identity
add-log-exp
add-cube-cbrt
difference-of-squares
associate-/l*
sqrt-prod
add-exp-log
add-cbrt-cube
times-frac
flip--
flip3--
pow1
distribute-lft-out--
associate-/l/
diff-log
sqrt-div
sub-neg
div-inv
div-exp
div-sub
pow1/2
frac-2neg
associate-/r*
clear-num
rem-sqrt-square
cbrt-undiv
neg-sub0
associate--l-
Counts
4 → 70
Calls
4 calls:
Slowest
37.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
13.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
4.0ms
(sqrt (- (* b b) (* 4 (* a c))))
4.0ms
(- (* b b) (* 4 (* a c)))

series241.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
86.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
64.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
47.0ms
(sqrt (- (* b b) (* 4 (* a c))))
44.0ms
(- (* b b) (* 4 (* a c)))

simplify2.7s

Counts
46 → 82
Calls
46 calls:
Slowest
361.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
283.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))))
215.0ms
(- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3))
162.0ms
(sqrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))
106.0ms
(- b (* 2 (/ (* a c) b)))

prune985.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 4.9b

localize23.0ms

Local error

Found 4 expressions with local error:

24.0b
(sqrt (- (pow b 2) (* 4 (* a c))))
1.2b
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
1.2b
(- (pow b 2) (* 4 (* a c)))
0.1b
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))

rewrite47.0ms

Algorithm
rewrite-expression-head
Rules
20×add-sqr-sqrt
13×*-un-lft-identity
add-log-exp
add-cube-cbrt
difference-of-squares
associate-/l*
sqrt-prod
add-exp-log
add-cbrt-cube
times-frac
flip--
flip3--
pow1
distribute-lft-out--
associate-/l/
diff-log
sqrt-div
sub-neg
div-inv
div-exp
div-sub
pow1/2
frac-2neg
associate-/r*
clear-num
rem-sqrt-square
cbrt-undiv
neg-sub0
associate--l-
Counts
4 → 70
Calls
4 calls:
Slowest
24.0ms
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))
12.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
6.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
4.0ms
(- (pow b 2) (* 4 (* a c)))

series235.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
68.0ms
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))
67.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
60.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
40.0ms
(- (pow b 2) (* 4 (* a c)))

simplify3.5s

Counts
46 → 82
Calls
46 calls:
Slowest
1.0s
(- (* (- b) (- b)) (* (sqrt (- (pow b 2) (* 4 (* a c)))) (sqrt (- (pow b 2) (* 4 (* a c))))))
315.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
236.0ms
(- (pow (- b) 3) (pow (sqrt (- (pow b 2) (* 4 (* a c)))) 3))
156.0ms
(sqrt (- (* (pow b 2) (pow b 2)) (* (* 4 (* a c)) (* 4 (* a c)))))
104.0ms
(/ (* (* (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))) (- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))) (* (* (* 2 a) (* 2 a)) (* 2 a)))

prune912.0ms

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 4.9b

localize13.0ms

Local error

Found 4 expressions with local error:

24.0b
(sqrt (- (pow b 2) (* 4 (* a c))))
1.2b
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
1.2b
(- (pow b 2) (* 4 (* a c)))
0.2b
(/ 1 (/ (* 2 a) (- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))))

rewrite43.0ms

Algorithm
rewrite-expression-head
Rules
16×add-sqr-sqrt
12×associate-/r*
11×*-un-lft-identity
add-log-exp
add-cube-cbrt
add-exp-log
times-frac
sqrt-prod
pow1
difference-of-squares
flip--
add-cbrt-cube
flip3--
associate-/r/
distribute-lft-out--
div-inv
diff-log
sqrt-div
sub-neg
rec-exp
inv-pow
pow-flip
div-exp
pow1/2
frac-2neg
clear-num
rem-sqrt-square
neg-sub0
associate--l-
Counts
4 → 69
Calls
4 calls:
Slowest
14.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
14.0ms
(/ 1 (/ (* 2 a) (- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))))
7.0ms
(- (pow b 2) (* 4 (* a c)))
6.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))

series254.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
92.0ms
(/ 1 (/ (* 2 a) (- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))))
64.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
61.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
38.0ms
(- (pow b 2) (* 4 (* a c)))

simplify2.4s

Counts
39 → 81
Calls
39 calls:
Slowest
396.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
266.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)))))))
166.0ms
(sqrt (- (* (pow b 2) (pow b 2)) (* (* 4 (* a c)) (* 4 (* a c)))))
125.0ms
(- b (* 2 (/ (* a c) b)))
90.0ms
(cbrt (/ (* 2 a) (- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))))

prune1.1s

Pruning

10 alts after pruning (8 fresh and 2 done)

Merged error: 4.9b

localize26.0ms

Local error

Found 4 expressions with local error:

24.0b
(sqrt (- (pow b 2) (* 4 (* a c))))
24.0b
(sqrt (- (pow b 2) (* 4 (* a c))))
24.0b
(sqrt (- (pow b 2) (* 4 (* a c))))
1.2b
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))

rewrite32.0ms

Algorithm
rewrite-expression-head
Rules
14×add-sqr-sqrt
10×sqrt-prod
*-un-lft-identity
add-cube-cbrt
add-log-exp
sqrt-div
flip--
add-exp-log
add-cbrt-cube
flip3--
pow1
pow1/2
rem-sqrt-square
difference-of-squares
distribute-lft-out--
diff-log
sub-neg
neg-sub0
associate--l-
Counts
4 → 58
Calls
4 calls:
Slowest
14.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
6.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
6.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
6.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))

series214.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
59.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
59.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
55.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
40.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))

simplify2.9s

Counts
36 → 70
Calls
36 calls:
Slowest
436.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
371.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
358.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
222.0ms
(sqrt (- (* (pow b 2) (pow b 2)) (* (* 4 (* a c)) (* 4 (* a c)))))
181.0ms
(sqrt (- (* (pow b 2) (pow b 2)) (* (* 4 (* a c)) (* 4 (* a c)))))

prune1.3s

Pruning

10 alts after pruning (7 fresh and 3 done)

Merged error: 4.9b

regimes924.0ms

Accuracy

83.2% (4.7b remaining)

Error of 10.4b against oracle of 5.7b and baseline of 33.5b

bsearch240.0ms

end0.0ms

sample4.9s

Algorithm
intervals
Results
11455×(pre true 80)
5803×(body real 80)
2738×(body nan 80)
1107×(body real 2560)
947×(body real 1280)
433×(body real 640)
217×(body real 320)
109×(body real 5120)
101×(body real 160)