Average Error: 19.2 → 13.5
Time: 19.3s
Precision: 64
Internal Precision: 128
\[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
\[\begin{array}{l} \mathbf{if}\;b \le 1.501809486178084 \cdot 10^{+23}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}} \cdot \sqrt{\sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*} - b}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*} - b}\\ \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 15.5

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

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

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

    if 1.501809486178084e+23 < b

    1. Initial program 32.7

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

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

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

Reproduce

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

Details

Time bar (total: 18.1s)Debug log

sample135.0ms

Algorithm
intervals
Results
89.0ms281×body80valid
21.0ms96×body80nan

simplify132.0ms

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

prune25.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 18.0b

localize174.0ms

Local error

Found 4 expressions with local error:

22.4b
(sqrt (fma c (* a -4) (* b b)))
22.4b
(sqrt (fma c (* a -4) (* b b)))
2.0b
(- (sqrt (fma c (* a -4) (* b b))) b)
1.1b
(- (- b) (sqrt (fma c (* a -4) (* b b))))

rewrite32.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
9.0ms
(- (sqrt (fma c (* a -4) (* b b))) b)
9.0ms
(- (- b) (sqrt (fma c (* a -4) (* b b))))
4.0ms
(sqrt (fma c (* a -4) (* b b)))
1.0ms
(sqrt (fma c (* a -4) (* b b)))

series220.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
64.0ms
(sqrt (fma c (* a -4) (* b b)))
54.0ms
(- (- b) (sqrt (fma c (* a -4) (* b b))))
52.0ms
(sqrt (fma c (* a -4) (* b b)))
49.0ms
(- (sqrt (fma c (* a -4) (* b b))) b)

simplify2.2s

Counts
81 → 105
Calls
81 calls:
Slowest
74.0ms
(fma 1 (- b) (- (* (sqrt (fma c (* a -4) (* b b))) (sqrt 1))))
72.0ms
(- (* 2 (/ (* a c) b)) (* 2 b))
62.0ms
(fma (sqrt (- b)) (sqrt (- b)) (- (* (sqrt (sqrt (fma c (* a -4) (* b b)))) (sqrt (sqrt (fma c (* a -4) (* b b)))))))
57.0ms
(fma (- (sqrt (fma c (* a -4) (* b b)))) (sqrt 1) (* (sqrt (fma c (* a -4) (* b b))) (sqrt 1)))
54.0ms
(fma -1 b (- (* (sqrt (fma c (* a -4) (* b b))) (sqrt 1))))

prune1.5s

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 10.3b

localize130.0ms

Local error

Found 4 expressions with local error:

22.4b
(sqrt (fma c (* a -4) (* b b)))
22.4b
(sqrt (fma c (* a -4) (* b b)))
22.4b
(sqrt (fma c (* a -4) (* b b)))
12.8b
(- (- b) (* (sqrt (sqrt (fma c (* a -4) (* b b)))) (sqrt (sqrt (fma c (* a -4) (* b b))))))

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

series224.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
61.0ms
(sqrt (fma c (* a -4) (* b b)))
56.0ms
(- (- b) (* (sqrt (sqrt (fma c (* a -4) (* b b)))) (sqrt (sqrt (fma c (* a -4) (* b b))))))
55.0ms
(sqrt (fma c (* a -4) (* b b)))
51.0ms
(sqrt (fma c (* a -4) (* b b)))

simplify638.0ms

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

prune1.2s

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 10.3b

localize128.0ms

Local error

Found 4 expressions with local error:

23.1b
(cbrt (fma c (* a -4) (* b b)))
23.1b
(cbrt (fma (* c -4) a (* b b)))
22.4b
(sqrt (fma c (* a -4) (* b b)))
7.2b
(- (* (fabs (cbrt (fma (* c -4) a (* b b)))) (sqrt (cbrt (fma c (* a -4) (* b b))))) b)

rewrite24.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
20.0ms
(- (* (fabs (cbrt (fma (* c -4) a (* b b)))) (sqrt (cbrt (fma c (* a -4) (* b b))))) b)
1.0ms
(sqrt (fma c (* a -4) (* b b)))
1.0ms
(cbrt (fma c (* a -4) (* b b)))
1.0ms
(cbrt (fma (* c -4) a (* b b)))

series624.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
228.0ms
(- (* (fabs (cbrt (fma (* c -4) a (* b b)))) (sqrt (cbrt (fma c (* a -4) (* b b))))) b)
184.0ms
(cbrt (fma c (* a -4) (* b b)))
163.0ms
(cbrt (fma (* c -4) a (* b b)))
48.0ms
(sqrt (fma c (* a -4) (* b b)))

simplify1.5s

Counts
23 → 66
Calls
23 calls:
Slowest
206.0ms
(- (pow b 2/3) (* 4/3 (* (* a c) (pow (/ 1 (pow b 4)) 1/3))))
182.0ms
(- (* (exp (* 1/6 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c)))))) (fabs (pow (fma (* -4 c) a (pow b 2)) 1/3))) b)
161.0ms
(- (pow b 2/3) (* 4/3 (* (* a c) (pow (/ 1 (pow b 4)) 1/3))))
161.0ms
(exp (* 1/3 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c))))))
146.0ms
(- (* (fabs (pow (fma (* -4 c) a (pow b 2)) 1/3)) (pow b 1/3)) (+ (* 2/3 (* (* a (* (fabs (pow (fma (* -4 c) a (pow b 2)) 1/3)) c)) (pow (/ 1 (pow b 5)) 1/3))) b))

prune1.6s

Pruning

9 alts after pruning (7 fresh and 2 done)

Merged error: 10.3b

localize120.0ms

Local error

Found 4 expressions with local error:

23.1b
(cbrt (fma c (* a -4) (* b b)))
23.1b
(cbrt (fma c (* a -4) (* b b)))
22.4b
(sqrt (fma c (* a -4) (* b b)))
9.1b
(- (- b) (* (sqrt (cbrt (fma c (* a -4) (* b b)))) (fabs (cbrt (fma c (* a -4) (* b b))))))

rewrite13.0ms

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

series557.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
224.0ms
(cbrt (fma c (* a -4) (* b b)))
200.0ms
(cbrt (fma c (* a -4) (* b b)))
84.0ms
(- (- b) (* (sqrt (cbrt (fma c (* a -4) (* b b)))) (fabs (cbrt (fma c (* a -4) (* b b))))))
48.0ms
(sqrt (fma c (* a -4) (* b b)))

simplify1.7s

Counts
33 → 75
Calls
33 calls:
Slowest
233.0ms
(- (pow b 2/3) (* 4/3 (* (* a c) (pow (/ 1 (pow b 4)) 1/3))))
207.0ms
(exp (* 1/3 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c))))))
198.0ms
(exp (* 1/3 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c))))))
189.0ms
(- (* 1/24 (* (fabs (pow (fma c (* -4 a) (pow b 2)) 1/3)) (* (pow b 2) (exp (* 1/6 (- (log -4) (+ (* 5 (log a)) (* 5 (log c))))))))) (+ (* (fabs (pow (fma c (* -4 a) (pow b 2)) 1/3)) (exp (* 1/6 (+ (log -4) (+ (log a) (log c)))))) b))
169.0ms
(- (pow b 2/3) (* 4/3 (* (* a c) (pow (/ 1 (pow b 4)) 1/3))))

prune1.5s

Pruning

9 alts after pruning (6 fresh and 3 done)

Merged error: 10.3b

regimes392.0ms

Accuracy

84.2% (1.1b remaining)

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

bsearch130.0ms

end0.0ms

sample3.2s

Algorithm
intervals
Results
2.0s8730×body80valid
611.0ms2975×body80nan