Average Error: 33.2 → 13.4
Time: 17.0s
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.1566096146303247 \cdot 10^{-232}:\\ \;\;\;\;\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 3.1234815487678856 \cdot 10^{+63}:\\ \;\;\;\;-2 \cdot \frac{c}{b + \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \frac{c}{b + b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.2
Target20.7
Herbie13.4
\[\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 3 regimes
  2. if b < 2.1566096146303247e-232

    1. Initial program 21.1

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

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

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

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

    if 2.1566096146303247e-232 < b < 3.1234815487678856e+63

    1. Initial program 33.0

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

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

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

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

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

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

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

    if 3.1234815487678856e+63 < b

    1. Initial program 56.6

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

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

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

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

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

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

      \[\leadsto \color{blue}{-2} \cdot \frac{c}{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} + b}\]
    10. Taylor expanded around 0 3.5

      \[\leadsto -2 \cdot \frac{c}{\color{blue}{b} + b}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.4

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

Reproduce

herbie shell --seed 2019016 +o rules:numerics
(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: 16.3s)Debug log

sample190.0ms

Algorithm
intervals
Results
378×(pre true 80)
187×(body real 80)
93×(body nan 80)
36×(body real 2560)
30×(body real 1280)
16×(body real 640)
(body real 160)
(body real 320)
(body real 5120)

simplify86.0ms

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

prune16.0ms

Pruning

2 alts after pruning (2 fresh and 0 done)

Merged error: 35.0b

localize29.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (fma (* a -4) c (* b b)))
2.2b
(- (sqrt (fma (* a -4) c (* b b))) b)
0.1b
(/ (- (sqrt (fma (* a -4) c (* b b))) b) (* 2 a))
0.0b
(fma (* a -4) c (* b b))

rewrite26.0ms

Algorithm
rewrite-expression-head
Rules
10×add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
sqrt-prod
add-exp-log
fma-neg
add-cbrt-cube
add-log-exp
log1p-expm1-u
pow1
expm1-log1p-u
associate-/l*
times-frac
associate-/l/
flip--
flip3--
div-inv
fma-udef
div-exp
div-sub
pow1/2
frac-2neg
sub-neg
associate-/r*
clear-num
rem-sqrt-square
cbrt-undiv
Counts
4 → 67
Calls
4 calls:
Slowest
18.0ms
(/ (- (sqrt (fma (* a -4) c (* b b))) b) (* 2 a))
5.0ms
(- (sqrt (fma (* a -4) c (* b b))) b)
1.0ms
(sqrt (fma (* a -4) c (* b b)))
0.0ms
(fma (* a -4) c (* b b))

series298.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
109.0ms
(/ (- (sqrt (fma (* a -4) c (* b b))) b) (* 2 a))
82.0ms
(- (sqrt (fma (* a -4) c (* b b))) b)
74.0ms
(sqrt (fma (* a -4) c (* b b)))
34.0ms
(fma (* a -4) c (* b b))

simplify1.4s

Counts
34 → 79
Calls
34 calls:
Slowest
690.0ms
(- (* (sqrt (fma (* a -4) c (* b b))) (sqrt (fma (* a -4) c (* b b)))) (* b b))
121.0ms
(/ (* (* (- (sqrt (fma (* a -4) c (* b b))) b) (- (sqrt (fma (* a -4) c (* b b))) b)) (- (sqrt (fma (* a -4) c (* b b))) b)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
84.0ms
(- (pow (sqrt (fma (* a -4) c (* b b))) 3) (pow b 3))
78.0ms
(- (log (- (sqrt (fma (* a -4) c (* b b))) b)) (log (* 2 a)))
52.0ms
(- (pow b 2) (* 4 (* a c)))

prune914.0ms

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 22.1b

localize12.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (fma (* a -4) c (* b b)))
16.3b
(/ (* (* a -4) c) (* (* 2 a) (+ (sqrt (fma (* a -4) c (* b b))) b)))
1.2b
(+ (sqrt (fma (* a -4) c (* b b))) b)
0.1b
(* (* 2 a) (+ (sqrt (fma (* a -4) c (* b b))) b))

rewrite24.0ms

Algorithm
rewrite-expression-head
Rules
11×add-exp-log
11×add-cbrt-cube
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
sqrt-prod
fma-def
pow1
add-log-exp
log1p-expm1-u
associate-*r/
expm1-log1p-u
flip-+
associate-*r*
flip3-+
cbrt-unprod
associate-/r/
prod-exp
div-exp
cbrt-undiv
associate-/l*
div-inv
*-commutative
pow-prod-down
associate-*l*
pow1/2
times-frac
distribute-lft-in
frac-2neg
associate-/r*
clear-num
rem-sqrt-square
+-commutative
distribute-rgt-in
Counts
4 → 74
Calls
4 calls:
Slowest
10.0ms
(/ (* (* a -4) c) (* (* 2 a) (+ (sqrt (fma (* a -4) c (* b b))) b)))
8.0ms
(* (* 2 a) (+ (sqrt (fma (* a -4) c (* b b))) b))
4.0ms
(+ (sqrt (fma (* a -4) c (* b b))) b)
1.0ms
(sqrt (fma (* a -4) c (* b b)))

series314.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
121.0ms
(/ (* (* a -4) c) (* (* 2 a) (+ (sqrt (fma (* a -4) c (* b b))) b)))
92.0ms
(* (* 2 a) (+ (sqrt (fma (* a -4) c (* b b))) b))
52.0ms
(sqrt (fma (* a -4) c (* b b)))
49.0ms
(+ (sqrt (fma (* a -4) c (* b b))) b)

simplify3.0s

Counts
41 → 86
Calls
41 calls:
Slowest
613.0ms
(/ (* (* (* (* a -4) c) (* (* a -4) c)) (* (* a -4) c)) (* (* (* (* 2 a) (+ (sqrt (fma (* a -4) c (* b b))) b)) (* (* 2 a) (+ (sqrt (fma (* a -4) c (* b b))) b))) (* (* 2 a) (+ (sqrt (fma (* a -4) c (* b b))) b))))
566.0ms
(- (log (* (* a -4) c)) (+ (log (* 2 a)) (log (+ (sqrt (fma (* a -4) c (* b b))) b))))
548.0ms
(/ (* (* (* (* a -4) c) (* (* a -4) c)) (* (* a -4) c)) (* (* (* (* 2 a) (* 2 a)) (* 2 a)) (* (* (+ (sqrt (fma (* a -4) c (* b b))) b) (+ (sqrt (fma (* a -4) c (* b b))) b)) (+ (sqrt (fma (* a -4) c (* b b))) b))))
346.0ms
(- (log (* (* a -4) c)) (log (* (* 2 a) (+ (sqrt (fma (* a -4) c (* b b))) b))))
191.0ms
(+ (* (sqrt (fma (* a -4) c (* b b))) (sqrt (fma (* a -4) c (* b b)))) (- (* b b) (* (sqrt (fma (* a -4) c (* b b))) b)))

prune939.0ms

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 15.5b

localize9.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (fma (* a -4) c (* b b)))
1.2b
(+ (sqrt (fma (* a -4) c (* b b))) b)
0.1b
(/ c (+ (sqrt (fma (* a -4) c (* b b))) b))
0.0b
(fma (* a -4) c (* b b))

rewrite16.0ms

Algorithm
rewrite-expression-head
Rules
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
sqrt-prod
fma-def
add-log-exp
log1p-expm1-u
add-exp-log
add-cbrt-cube
pow1
expm1-log1p-u
associate-/r*
flip-+
associate-/r/
flip3-+
div-inv
fma-udef
pow1/2
frac-2neg
clear-num
rem-sqrt-square
+-commutative
Counts
4 → 59
Calls
4 calls:
Slowest
8.0ms
(+ (sqrt (fma (* a -4) c (* b b))) b)
5.0ms
(/ c (+ (sqrt (fma (* a -4) c (* b b))) b))
2.0ms
(sqrt (fma (* a -4) c (* b b)))
0.0ms
(fma (* a -4) c (* b b))

series395.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
184.0ms
(/ c (+ (sqrt (fma (* a -4) c (* b b))) b))
82.0ms
(+ (sqrt (fma (* a -4) c (* b b))) b)
69.0ms
(sqrt (fma (* a -4) c (* b b)))
60.0ms
(fma (* a -4) c (* b b))

simplify487.0ms

Counts
26 → 71
Calls
26 calls:
Slowest
189.0ms
(+ (* (sqrt (fma (* a -4) c (* b b))) (sqrt (fma (* a -4) c (* b b)))) (- (* b b) (* (sqrt (fma (* a -4) c (* b b))) b)))
36.0ms
(- (pow b 2) (* 4 (* a c)))
29.0ms
(- (pow b 2) (* 4 (* a c)))
29.0ms
(sqrt (* (cbrt (fma (* a -4) c (* b b))) (cbrt (fma (* a -4) c (* b b)))))
27.0ms
(- (pow b 2) (* 4 (* a c)))

prune779.0ms

Pruning

7 alts after pruning (6 fresh and 1 done)

Merged error: 11.8b

localize2.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (fma (* a -4) c (* b b)))
2.2b
(- (sqrt (fma (* a -4) c (* b b))) b)
0.1b
(/ (- (sqrt (fma (* a -4) c (* b b))) b) (* 2 a))
0.0b
(fma (* a -4) c (* b b))

rewrite36.0ms

Algorithm
rewrite-expression-head
Rules
10×add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
sqrt-prod
add-exp-log
fma-neg
add-cbrt-cube
add-log-exp
log1p-expm1-u
pow1
expm1-log1p-u
associate-/l*
times-frac
associate-/l/
flip--
flip3--
div-inv
fma-udef
div-exp
div-sub
pow1/2
frac-2neg
sub-neg
associate-/r*
clear-num
rem-sqrt-square
cbrt-undiv
Counts
4 → 67
Calls
4 calls:
Slowest
22.0ms
(/ (- (sqrt (fma (* a -4) c (* b b))) b) (* 2 a))
11.0ms
(- (sqrt (fma (* a -4) c (* b b))) b)
2.0ms
(sqrt (fma (* a -4) c (* b b)))
0.0ms
(fma (* a -4) c (* b b))

series257.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
85.0ms
(/ (- (sqrt (fma (* a -4) c (* b b))) b) (* 2 a))
78.0ms
(- (sqrt (fma (* a -4) c (* b b))) b)
56.0ms
(sqrt (fma (* a -4) c (* b b)))
38.0ms
(fma (* a -4) c (* b b))

simplify1.8s

Counts
34 → 79
Calls
34 calls:
Slowest
1.1s
(- (* (sqrt (fma (* a -4) c (* b b))) (sqrt (fma (* a -4) c (* b b)))) (* b b))
112.0ms
(- (pow (sqrt (fma (* a -4) c (* b b))) 3) (pow b 3))
111.0ms
(/ (* (* (- (sqrt (fma (* a -4) c (* b b))) b) (- (sqrt (fma (* a -4) c (* b b))) b)) (- (sqrt (fma (* a -4) c (* b b))) b)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
45.0ms
(- (log (- (sqrt (fma (* a -4) c (* b b))) b)) (log (* 2 a)))
38.0ms
(/ (* (cbrt (- (sqrt (fma (* a -4) c (* b b))) b)) (cbrt (- (sqrt (fma (* a -4) c (* b b))) b))) 2)

prune695.0ms

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 11.8b

regimes254.0ms

Accuracy

95.3% (0.8b remaining)

Error of 13.4b against oracle of 12.6b and baseline of 29.6b

bsearch453.0ms

end0.0ms

sample3.8s

Algorithm
intervals
Results
11500×(pre true 80)
5932×(body real 80)
2746×(body nan 80)
1013×(body real 2560)
888×(body real 1280)
455×(body real 640)
223×(body real 320)
126×(body real 160)
117×(body real 5120)