Average Error: 19.5 → 13.1
Time: 18.5s
Precision: 64
Internal Precision: 128
\[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
\[\begin{array}{l} \mathbf{if}\;b \le 2.375428060879404 \cdot 10^{+58}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\sqrt{(-4 \cdot \left(a \cdot c\right) + \left(b \cdot b\right))_*}} \cdot \sqrt{\sqrt{(-4 \cdot \left(a \cdot c\right) + \left(b \cdot b\right))_*}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{(-4 \cdot \left(a \cdot c\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{(-4 \cdot \left(a \cdot c\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if b < 2.375428060879404e+58

    1. Initial program 16.7

      \[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    2. Simplified16.7

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{(-4 \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{(-4 \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}\\ \end{array}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt16.8

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{\sqrt{\sqrt{(-4 \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*}} \cdot \sqrt{\sqrt{(-4 \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*}}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{(-4 \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}\\ \end{array}\]

    if 2.375428060879404e+58 < b

    1. Initial program 26.6

      \[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    2. Simplified26.6

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{(-4 \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{(-4 \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}\\ \end{array}}\]
    3. Taylor expanded around 0 3.6

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{(-4 \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}\\ \end{array}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification13.1

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

Reproduce

herbie shell --seed 2019010 +o rules:numerics
(FPCore (a b c)
  :name "jeff quadratic root 2"
  (if (>= b 0) (/ (* 2 c) (- (- b) (sqrt (- (* b b) (* (* 4 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a))))

Details

Time bar (total: 17.2s)Debug log

sample197.0ms

Algorithm
intervals

simplify115.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
114.0ms
(if (>= b 0) (/ (* 2 c) (- (- b) (sqrt (- (* b b) (* (* 4 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))

prune15.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 18.1b

localize178.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (fma -4 (* c a) (* b b)))
22.0b
(sqrt (fma -4 (* c a) (* b b)))
1.7b
(- (sqrt (fma -4 (* c a) (* b b))) b)
0.3b
(- (- b) (sqrt (fma -4 (* c a) (* b b))))

rewrite38.0ms

Algorithm
rewrite-expression-head
Rules
29×add-sqr-sqrt
25×*-un-lft-identity
24×prod-diff
23×add-cube-cbrt
22×sqrt-prod
10×fma-neg
neg-mul-1
add-log-exp
log1p-expm1-u
add-exp-log
add-cbrt-cube
pow1
expm1-log1p-u
difference-of-squares
flip--
pow1/2
flip3--
sub-neg
rem-sqrt-square
distribute-lft-out--
diff-log
neg-sub0
associate--l-
Counts
4 → 93
Calls
4 calls:
Slowest
18.0ms
(- (- b) (sqrt (fma -4 (* c a) (* b b))))
11.0ms
(- (sqrt (fma -4 (* c a) (* b b))) b)
4.0ms
(sqrt (fma -4 (* c a) (* b b)))
2.0ms
(sqrt (fma -4 (* c a) (* b b)))

series288.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
79.0ms
(- (sqrt (fma -4 (* c a) (* b b))) b)
74.0ms
(- (- b) (sqrt (fma -4 (* c a) (* b b))))
68.0ms
(sqrt (fma -4 (* c a) (* b b)))
67.0ms
(sqrt (fma -4 (* c a) (* b b)))

simplify2.4s

Counts
81 → 105
Calls
81 calls:
Slowest
100.0ms
(- (* 2 (/ (* a c) b)) (* 2 b))
76.0ms
(fma 1 (- b) (- (* (sqrt (fma -4 (* c a) (* b b))) (sqrt 1))))
58.0ms
(fma (- (sqrt (fma -4 (* c a) (* b b)))) 1 (* (sqrt (fma -4 (* c a) (* b b))) 1))
55.0ms
(fma 1 (- b) (- (* (sqrt (cbrt (fma -4 (* c a) (* b b)))) (sqrt (* (cbrt (fma -4 (* c a) (* b b))) (cbrt (fma -4 (* c a) (* b b))))))))
53.0ms
(fma 1 (- b) (- (* (sqrt (fma -4 (* c a) (* b b))) 1)))

prune1.7s

Pruning

6 alts after pruning (6 fresh and 0 done)

Merged error: 11.2b

localize91.0ms

Local error

Found 4 expressions with local error:

24.5b
(fma (sqrt (sqrt (fma -4 (* c a) (* b b)))) (sqrt (sqrt (fma -4 (* c a) (* b b)))) (- b))
22.0b
(sqrt (fma -4 (* c a) (* b b)))
22.0b
(sqrt (fma -4 (* c a) (* b b)))
22.0b
(sqrt (fma -4 (* c a) (* b b)))

rewrite3.0ms

Algorithm
rewrite-expression-head
Rules
10×add-sqr-sqrt
sqrt-prod
add-cube-cbrt
*-un-lft-identity
add-log-exp
log1p-expm1-u
add-exp-log
add-cbrt-cube
pow1
expm1-log1p-u
pow1/2
rem-sqrt-square
fma-udef
Counts
4 → 52
Calls
4 calls:
Slowest
1.0ms
(sqrt (fma -4 (* c a) (* b b)))
1.0ms
(sqrt (fma -4 (* c a) (* b b)))
1.0ms
(sqrt (fma -4 (* c a) (* b b)))
0.0ms
(fma (sqrt (sqrt (fma -4 (* c a) (* b b)))) (sqrt (sqrt (fma -4 (* c a) (* b b)))) (- b))

series490.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
324.0ms
(fma (sqrt (sqrt (fma -4 (* c a) (* b b)))) (sqrt (sqrt (fma -4 (* c a) (* b b)))) (- b))
69.0ms
(sqrt (fma -4 (* c a) (* b b)))
51.0ms
(sqrt (fma -4 (* c a) (* b b)))
46.0ms
(sqrt (fma -4 (* c a) (* b b)))

simplify598.0ms

Counts
24 → 64
Calls
24 calls:
Slowest
331.0ms
(- (pow (exp (* 1/4 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c)))))) 2) b)
128.0ms
(- (pow (exp (* 1/4 (- (log -4) (+ (log (/ -1 c)) (log (/ -1 a)))))) 2) b)
21.0ms
(sqrt (* (cbrt (fma -4 (* c a) (* b b))) (cbrt (fma -4 (* c a) (* b b)))))
20.0ms
(sqrt (sqrt (fma -4 (* c a) (* b b))))
18.0ms
(sqrt (fma -4 (* c a) (* b b)))

prune1.4s

Pruning

6 alts after pruning (5 fresh and 1 done)

Merged error: 11.2b

localize112.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (fma -4 (* c a) (* b b)))
22.0b
(sqrt (fma -4 (* c a) (* b b)))
22.0b
(sqrt (fma -4 (* c a) (* b b)))
9.3b
(- (- b) (* (sqrt (sqrt (fma -4 (* c a) (* b b)))) (sqrt (sqrt (fma -4 (* c a) (* b b))))))

rewrite10.0ms

Algorithm
rewrite-expression-head
Rules
13×add-sqr-sqrt
sqrt-prod
add-cube-cbrt
*-un-lft-identity
add-log-exp
log1p-expm1-u
add-exp-log
prod-diff
fma-neg
add-cbrt-cube
pow1
expm1-log1p-u
pow1/2
rem-sqrt-square
neg-mul-1
difference-of-squares
flip--
diff-log
flip3--
sub-neg
neg-sub0
associate--l-
Counts
4 → 66
Calls
4 calls:
Slowest
5.0ms
(- (- b) (* (sqrt (sqrt (fma -4 (* c a) (* b b)))) (sqrt (sqrt (fma -4 (* c a) (* b b))))))
1.0ms
(sqrt (fma -4 (* c a) (* b b)))
1.0ms
(sqrt (fma -4 (* c a) (* b b)))
1.0ms
(sqrt (fma -4 (* c a) (* b b)))

series221.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
68.0ms
(sqrt (fma -4 (* c a) (* b b)))
54.0ms
(sqrt (fma -4 (* c a) (* b b)))
53.0ms
(- (- b) (* (sqrt (sqrt (fma -4 (* c a) (* b b)))) (sqrt (sqrt (fma -4 (* c a) (* b b))))))
46.0ms
(sqrt (fma -4 (* c a) (* b b)))

simplify718.0ms

Counts
37 → 78
Calls
37 calls:
Slowest
71.0ms
(- (* 2 (/ (* a c) b)) (* 2 b))
70.0ms
(* -2 (/ (* a c) b))
61.0ms
(fma (sqrt (- b)) (sqrt (- b)) (- (* (sqrt (sqrt (fma -4 (* c a) (* b b)))) (sqrt (sqrt (fma -4 (* c a) (* b b)))))))
49.0ms
(/ (exp (- b)) (exp (* (sqrt (sqrt (fma -4 (* c a) (* b b)))) (sqrt (sqrt (fma -4 (* c a) (* b b)))))))
47.0ms
(fma 1 (- b) (- (* (sqrt (sqrt (fma -4 (* c a) (* b b)))) (sqrt (sqrt (fma -4 (* c a) (* b b)))))))

prune1.4s

Pruning

6 alts after pruning (4 fresh and 2 done)

Merged error: 11.2b

localize186.0ms

Local error

Found 4 expressions with local error:

22.8b
(cbrt (fma -4 (* c a) (* b b)))
22.8b
(cbrt (fma (* -4 a) c (* b b)))
22.0b
(sqrt (fma -4 (* c a) (* b b)))
22.0b
(sqrt (fma -4 (* c a) (* b b)))

rewrite4.0ms

Algorithm
rewrite-expression-head
Rules
10×add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
sqrt-prod
cbrt-prod
add-log-exp
log1p-expm1-u
add-exp-log
add-cbrt-cube
pow1
expm1-log1p-u
pow1/3
pow1/2
rem-sqrt-square
Counts
4 → 54
Calls
4 calls:
Slowest
1.0ms
(sqrt (fma -4 (* c a) (* b b)))
1.0ms
(sqrt (fma -4 (* c a) (* b b)))
1.0ms
(cbrt (fma -4 (* c a) (* b b)))
1.0ms
(cbrt (fma (* -4 a) c (* b b)))

series561.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
248.0ms
(cbrt (fma -4 (* c a) (* b b)))
207.0ms
(cbrt (fma (* -4 a) c (* b b)))
65.0ms
(sqrt (fma -4 (* c a) (* b b)))
40.0ms
(sqrt (fma -4 (* c a) (* b b)))

simplify1.0s

Counts
26 → 66
Calls
26 calls:
Slowest
212.0ms
(- (pow b 2/3) (* 4/3 (* (* a c) (pow (/ 1 (pow b 4)) 1/3))))
157.0ms
(exp (* 1/3 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c))))))
154.0ms
(exp (* 1/3 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c))))))
145.0ms
(- (pow b 2/3) (* 4/3 (* (* a c) (pow (/ 1 (pow b 4)) 1/3))))
77.0ms
(exp (* 1/3 (- (log -4) (+ (log (/ -1 c)) (log (/ -1 a))))))

prune1.6s

Pruning

7 alts after pruning (4 fresh and 3 done)

Merged error: 11.2b

regimes397.0ms

Accuracy

89.5% (0.8b remaining)

Error of 13.1b against oracle of 12.3b and baseline of 19.5b

bsearch198.0ms

end0.0ms

sample3.3s

Algorithm
intervals