Average Error: 33.2 → 9.6
Time: 32.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 -4.1146996886759634 \cdot 10^{+123}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 8.585369465311041 \cdot 10^{-54}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - (\left(\frac{c}{b} \cdot a\right) \cdot -2 + b)_*}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b < -4.1146996886759634e+123

    1. Initial program 49.1

      \[\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-inv49.1

      \[\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 -4.1146996886759634e+123 < b < 8.585369465311041e-54

    1. Initial program 13.0

      \[\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-inv13.1

      \[\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-inv13.0

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

    if 8.585369465311041e-54 < b

    1. Initial program 53.1

      \[\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-inv53.1

      \[\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-+53.2

      \[\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/53.2

      \[\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. Simplified24.6

      \[\leadsto \frac{\color{blue}{\left(4 \cdot \left(c \cdot a\right)\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 inf 21.0

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

      \[\leadsto \frac{2 \cdot c}{\left(-b\right) - \color{blue}{\left(b - 2 \cdot \frac{a \cdot c}{b}\right)}}\]
    10. Simplified7.7

      \[\leadsto \frac{2 \cdot c}{\left(-b\right) - \color{blue}{(\left(\frac{c}{b} \cdot a\right) \cdot -2 + b)_*}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification9.6

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

Reproduce

herbie shell --seed 2019010 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, full range"
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))

Details

Time bar (total: 31.2s)Debug log

sample136.0ms

Algorithm
intervals

simplify87.0ms

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

prune11.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 32.9b

localize50.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (- (* b b) (* (* 4 a) c)))
1.7b
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
0.2b
(- (* b b) (* (* 4 a) c))
0.1b
(/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a))

rewrite70.0ms

Algorithm
rewrite-expression-head
Rules
14×*-un-lft-identity
add-sqr-sqrt
add-log-exp
add-cube-cbrt
add-exp-log
add-cbrt-cube
associate-/l*
log1p-expm1-u
times-frac
fma-def
pow1
expm1-log1p-u
distribute-lft-out
sqrt-prod
associate-/l/
flip--
flip-+
associate-+l-
sqrt-div
flip3--
flip3-+
neg-sub0
div-inv
prod-diff
div-exp
div-sub
diff-log
fma-neg
pow1/2
frac-2neg
sub-neg
sum-log
neg-mul-1
associate-/r*
clear-num
rem-sqrt-square
+-commutative
cbrt-undiv
Counts
4 → 77
Calls
4 calls:
Slowest
44.0ms
(/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a))
12.0ms
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
7.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
5.0ms
(- (* b b) (* (* 4 a) c))

series256.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
100.0ms
(/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a))
65.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
55.0ms
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
35.0ms
(- (* b b) (* (* 4 a) c))

simplify2.5s

Counts
40 → 89
Calls
40 calls:
Slowest
387.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))))
377.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
186.0ms
(+ (pow (- b) 3) (pow (sqrt (- (* b b) (* (* 4 a) c))) 3))
167.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))
145.0ms
(- b (* 2 (/ (* a c) b)))

prune1.1s

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 6.3b

localize7.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (- (* b b) (* (* 4 a) c)))
1.7b
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
0.2b
(* (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (/ 1 (* 2 a)))
0.2b
(- (* b b) (* (* 4 a) c))

rewrite46.0ms

Algorithm
rewrite-expression-head
Rules
12×*-un-lft-identity
add-sqr-sqrt
add-log-exp
add-cube-cbrt
add-exp-log
add-cbrt-cube
pow1
log1p-expm1-u
associate-*l*
associate-*r*
fma-def
expm1-log1p-u
flip-+
sqrt-prod
flip3-+
distribute-lft-out
flip--
prod-exp
associate-*l/
sqrt-div
flip3--
frac-times
div-inv
cbrt-unprod
associate-+l-
*-commutative
un-div-inv
associate-*r/
pow-prod-down
prod-diff
diff-log
fma-neg
pow1/2
sub-neg
sum-log
neg-mul-1
rec-exp
rem-sqrt-square
+-commutative
neg-sub0
Counts
4 → 79
Calls
4 calls:
Slowest
29.0ms
(* (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (/ 1 (* 2 a)))
7.0ms
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
5.0ms
(- (* b b) (* (* 4 a) c))
3.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series232.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
85.0ms
(* (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (/ 1 (* 2 a)))
59.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
51.0ms
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
37.0ms
(- (* b b) (* (* 4 a) c))

simplify4.6s

Counts
43 → 91
Calls
43 calls:
Slowest
885.0ms
(* (- (* (- b) (- b)) (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c))))) 1)
473.0ms
(* (+ (pow (- b) 3) (pow (sqrt (- (* b b) (* (* 4 a) c))) 3)) 1)
452.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
430.0ms
(* (- (* (- b) (- b)) (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c))))) (/ 1 (* 2 a)))
281.0ms
(* (+ (* (- b) (- b)) (- (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* (- b) (sqrt (- (* b b) (* (* 4 a) c)))))) (* 2 a))

prune1.3s

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 6.2b

localize39.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (- (* b b) (* (* 4 a) c)))
14.3b
(* (* 4 (* c a)) (/ 1/2 a))
0.3b
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
0.2b
(- (* b b) (* (* 4 a) c))

rewrite24.0ms

Algorithm
rewrite-expression-head
Rules
26×add-sqr-sqrt
25×prod-diff
23×*-un-lft-identity
21×add-cube-cbrt
16×sqrt-prod
add-log-exp
neg-mul-1
add-exp-log
add-cbrt-cube
pow1
fma-neg
log1p-expm1-u
associate-*r*
expm1-log1p-u
flip--
flip3--
difference-of-squares
diff-log
sqrt-div
sub-neg
distribute-lft-out--
div-inv
cbrt-unprod
*-commutative
associate-*r/
prod-exp
pow-prod-down
associate-*l*
pow1/2
rem-sqrt-square
neg-sub0
associate--l-
Counts
4 → 97
Calls
4 calls:
Slowest
8.0ms
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
6.0ms
(* (* 4 (* c a)) (/ 1/2 a))
6.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
3.0ms
(- (* b b) (* (* 4 a) c))

series171.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
76.0ms
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
46.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
41.0ms
(- (* b b) (* (* 4 a) c))
7.0ms
(* (* 4 (* c a)) (/ 1/2 a))

simplify4.9s

Counts
84 → 109
Calls
84 calls:
Slowest
393.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
294.0ms
(+ (log (* 4 (* c a))) (log (/ 1/2 a)))
170.0ms
(* (* 4 (* c a)) (/ 1/2 a))
168.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))
113.0ms
(- b (* 2 (/ (* a c) b)))

prune1.6s

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 6.2b

localize9.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (- (* b b) (* (* 4 a) c)))
0.3b
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
0.2b
(- (* b b) (* (* 4 a) c))
0.1b
(/ (* 2 c) (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))))

rewrite27.0ms

Algorithm
rewrite-expression-head
Rules
35×add-sqr-sqrt
28×*-un-lft-identity
25×prod-diff
22×add-cube-cbrt
18×sqrt-prod
add-log-exp
neg-mul-1
difference-of-squares
add-exp-log
add-cbrt-cube
times-frac
associate-/r*
fma-neg
flip--
log1p-expm1-u
flip3--
pow1
expm1-log1p-u
distribute-lft-out--
associate-/r/
diff-log
sqrt-div
sub-neg
associate-/l*
div-inv
div-exp
pow1/2
frac-2neg
clear-num
rem-sqrt-square
cbrt-undiv
neg-sub0
associate--l-
Counts
4 → 107
Calls
4 calls:
Slowest
12.0ms
(/ (* 2 c) (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))))
8.0ms
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
3.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
2.0ms
(- (* b b) (* (* 4 a) c))

series259.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
108.0ms
(/ (* 2 c) (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))))
79.0ms
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))
45.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
28.0ms
(- (* b b) (* (* 4 a) c))

simplify6.0s

Counts
99 → 119
Calls
99 calls:
Slowest
433.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
398.0ms
(+ (* (- b) (- b)) (+ (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* (- b) (sqrt (- (* b b) (* (* 4 a) c))))))
202.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))
125.0ms
(- b (* 2 (/ (* a c) b)))
97.0ms
(- (log (* 2 c)) (log (- (- b) (sqrt (- (* b b) (* (* 4 a) c))))))

prune1.4s

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 6.2b

regimes486.0ms

Accuracy

84.2% (4.2b remaining)

Error of 9.6b against oracle of 5.5b and baseline of 31.8b

bsearch435.0ms

end0.0ms

sample5.3s

Algorithm
intervals