Average Error: 19.4 → 13.5
Time: 18.3s
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 1.501809486178084 \cdot 10^{+23}:\\ \;\;\;\;\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 < 1.501809486178084e+23

    1. Initial program 17.4

      \[\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. Simplified17.4

      \[\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-sqrt17.4

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\color{blue}{\sqrt{(-4 \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*} \cdot \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}\]
    5. Applied sqrt-prod17.5

      \[\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 1.501809486178084e+23 < b

    1. Initial program 23.8

      \[\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. Simplified23.8

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

      \[\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.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le 1.501809486178084 \cdot 10^{+23}:\\ \;\;\;\;\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 2019022 +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: 16.8s)Debug log

sample88.0ms

Algorithm
intervals
Results
52.0ms283×body80valid
16.0ms97×body80nan

simplify137.0ms

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

prune28.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 16.0b

localize176.0ms

Local error

Found 4 expressions with local error:

21.7b
(sqrt (fma -4 (* c a) (* b b)))
21.7b
(sqrt (fma -4 (* c a) (* b b)))
2.0b
(- (sqrt (fma -4 (* c a) (* b b))) b)
1.3b
(- (- b) (sqrt (fma -4 (* c a) (* b b))))

rewrite19.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
6.0ms
(- (sqrt (fma -4 (* c a) (* b b))) b)
5.0ms
(- (- b) (sqrt (fma -4 (* c a) (* b b))))
4.0ms
(sqrt (fma -4 (* c a) (* b b)))
2.0ms
(sqrt (fma -4 (* c a) (* b b)))

series267.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
70.0ms
(- (sqrt (fma -4 (* c a) (* b b))) b)
70.0ms
(- (- b) (sqrt (fma -4 (* c a) (* b b))))
68.0ms
(sqrt (fma -4 (* c a) (* b b)))
59.0ms
(sqrt (fma -4 (* c a) (* b b)))

simplify2.2s

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

prune1.6s

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 10.3b

localize124.0ms

Local error

Found 4 expressions with local error:

21.7b
(sqrt (fma -4 (* c a) (* b b)))
21.7b
(sqrt (fma -4 (* c a) (* b b)))
21.7b
(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))))))

rewrite13.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
7.0ms
(- (- b) (* (sqrt (sqrt (fma -4 (* c a) (* b b)))) (sqrt (sqrt (fma -4 (* c a) (* b b))))))
2.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)))

series231.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
70.0ms
(- (- b) (* (sqrt (sqrt (fma -4 (* c a) (* b b)))) (sqrt (sqrt (fma -4 (* c a) (* b b))))))
61.0ms
(sqrt (fma -4 (* c a) (* b b)))
52.0ms
(sqrt (fma -4 (* c a) (* b b)))
48.0ms
(sqrt (fma -4 (* c a) (* b b)))

simplify651.0ms

Counts
37 → 78
Calls
37 calls:
Slowest
69.0ms
(- (* 2 (/ (* a c) b)) (* 2 b))
68.0ms
(/ (exp (- b)) (exp (* (sqrt (sqrt (fma -4 (* c a) (* b b)))) (sqrt (sqrt (fma -4 (* c a) (* b b)))))))
43.0ms
(* -2 (/ (* a c) b))
42.0ms
(fma -1 b (- (* (sqrt (sqrt (fma -4 (* c a) (* b b)))) (sqrt (sqrt (fma -4 (* c a) (* b b)))))))
36.0ms
(fma (sqrt (- b)) (sqrt (- b)) (- (* (sqrt (sqrt (fma -4 (* c a) (* b b)))) (sqrt (sqrt (fma -4 (* c a) (* b b)))))))

prune1.3s

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 10.3b

localize107.0ms

Local error

Found 4 expressions with local error:

23.7b
(fma (sqrt (sqrt (fma -4 (* c a) (* b b)))) (sqrt (sqrt (fma -4 (* c a) (* b b)))) (- b))
21.7b
(sqrt (fma -4 (* c a) (* b b)))
21.7b
(sqrt (fma -4 (* c a) (* b b)))
21.7b
(sqrt (fma -4 (* c a) (* b b)))

rewrite6.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
2.0ms
(sqrt (fma -4 (* c a) (* b b)))
2.0ms
(sqrt (fma -4 (* c a) (* b b)))
2.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))

series472.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
284.0ms
(fma (sqrt (sqrt (fma -4 (* c a) (* b b)))) (sqrt (sqrt (fma -4 (* c a) (* b b)))) (- b))
64.0ms
(sqrt (fma -4 (* c a) (* b b)))
62.0ms
(sqrt (fma -4 (* c a) (* b b)))
62.0ms
(sqrt (fma -4 (* c a) (* b b)))

simplify576.0ms

Counts
24 → 64
Calls
24 calls:
Slowest
297.0ms
(- (pow (exp (* 1/4 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c)))))) 2) b)
136.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)))))
18.0ms
(sqrt (sqrt (fma -4 (* c a) (* b b))))
18.0ms
(sqrt (sqrt (fma -4 (* c a) (* b b))))

prune1.1s

Pruning

9 alts after pruning (7 fresh and 2 done)

Merged error: 10.3b

localize132.0ms

Local error

Found 4 expressions with local error:

22.4b
(cbrt (fma -4 (* c a) (* b b)))
22.4b
(cbrt (fma (* -4 a) c (* b b)))
21.7b
(sqrt (fma -4 (* c a) (* b b)))
9.4b
(- (* (fabs (cbrt (fma (* -4 a) c (* b b)))) (sqrt (cbrt (fma -4 (* c a) (* b b))))) b)

rewrite8.0ms

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

series644.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
251.0ms
(- (* (fabs (cbrt (fma (* -4 a) c (* b b)))) (sqrt (cbrt (fma -4 (* c a) (* b b))))) b)
177.0ms
(cbrt (fma -4 (* c a) (* b b)))
157.0ms
(cbrt (fma (* -4 a) c (* b b)))
59.0ms
(sqrt (fma -4 (* c a) (* b b)))

simplify1.5s

Counts
23 → 66
Calls
23 calls:
Slowest
217.0ms
(- (pow b 2/3) (* 4/3 (* (* a c) (pow (/ 1 (pow b 4)) 1/3))))
199.0ms
(exp (* 1/3 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c))))))
168.0ms
(exp (* 1/3 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c))))))
167.0ms
(- (* (exp (* 1/6 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c)))))) (fabs (pow (fma (* -4 a) c (pow b 2)) 1/3))) b)
156.0ms
(- (pow b 2/3) (* 4/3 (* (* a c) (pow (/ 1 (pow b 4)) 1/3))))

prune1.5s

Pruning

10 alts after pruning (7 fresh and 3 done)

Merged error: 10.3b

regimes396.0ms

Accuracy

84.6% (1.1b remaining)

Error of 13.5b against oracle of 12.4b and baseline of 19.5b

bsearch147.0ms

end0.0ms

sample3.4s

Algorithm
intervals
Results
2.5s8738×body80valid
678.0ms2979×body80nan