Average Error: 19.1 → 13.1
Time: 24.5s
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 5.001839899625071 \cdot 10^{+77}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}} \cdot \sqrt{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}} - b}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if b < 5.001839899625071e+77

    1. Initial program 14.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. Initial simplification14.7

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

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

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

    if 5.001839899625071e+77 < b

    1. Initial program 40.3

      \[\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. Initial simplification40.3

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\left(-4 \cdot a\right) \cdot c + b \cdot b}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{\left(-4 \cdot a\right) \cdot c + b \cdot b} - b}\\ \end{array}\]
    3. Taylor expanded around 0 5.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{\left(-4 \cdot a\right) \cdot c + b \cdot b} - b}\\ \end{array}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification13.1

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

Reproduce

herbie shell --seed 2018362 
(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.3s)Debug log

start197.0ms

Algorithm
intervals

setup167.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 17.0b

localize220.0ms

Local error

Found 4 expressions with local error:

21.0b
(sqrt (+ (* (* -4 a) c) (* b b)))
21.0b
(sqrt (+ (* (* -4 a) c) (* b b)))
1.8b
(- (sqrt (+ (* (* -4 a) c) (* b b))) b)
0.9b
(- (- b) (sqrt (+ (* (* -4 a) c) (* b b))))

rewrite57.0ms

Algorithm
rewrite-expression-head
Counts
4 → 55
Calls

4 calls. Slowest were:

29.0ms
(- (sqrt (+ (* (* -4 a) c) (* b b))) b)
14.0ms
(- (- b) (sqrt (+ (* (* -4 a) c) (* b b))))
7.0ms
(sqrt (+ (* (* -4 a) c) (* b b)))

series265.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

77.0ms
(sqrt (+ (* (* -4 a) c) (* b b)))
74.0ms
(- (sqrt (+ (* (* -4 a) c) (* b b))) b)
69.0ms
(sqrt (+ (* (* -4 a) c) (* b b)))
46.0ms
(- (- b) (sqrt (+ (* (* -4 a) c) (* b b))))

simplify1.4s

Counts
30 → 67
Calls

30 calls. Slowest were:

287.0ms
(sqrt (- (* (* (* -4 a) c) (* (* -4 a) c)) (* (* b b) (* b b))))
265.0ms
(sqrt (- (* (* (* -4 a) c) (* (* -4 a) c)) (* (* b b) (* b b))))
263.0ms
(sqrt (+ (pow (* (* -4 a) c) 3) (pow (* b b) 3)))

prune1.5s

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 11.8b

localize169.0ms

Local error

Found 4 expressions with local error:

21.0b
(sqrt (+ (* (* -4 a) c) (* b b)))
21.0b
(sqrt (+ (* (* -4 a) c) (* b b)))
21.0b
(sqrt (+ (* (* -4 a) c) (* b b)))
7.6b
(- (* (sqrt (sqrt (+ (* (* -4 a) c) (* b b)))) (sqrt (sqrt (+ (* (* -4 a) c) (* b b))))) b)

rewrite39.0ms

Algorithm
rewrite-expression-head
Counts
4 → 53
Calls

4 calls. Slowest were:

27.0ms
(- (* (sqrt (sqrt (+ (* (* -4 a) c) (* b b)))) (sqrt (sqrt (+ (* (* -4 a) c) (* b b))))) b)
5.0ms
(sqrt (+ (* (* -4 a) c) (* b b)))
3.0ms
(sqrt (+ (* (* -4 a) c) (* b b)))

series242.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

70.0ms
(sqrt (+ (* (* -4 a) c) (* b b)))
67.0ms
(sqrt (+ (* (* -4 a) c) (* b b)))
55.0ms
(- (* (sqrt (sqrt (+ (* (* -4 a) c) (* b b)))) (sqrt (sqrt (+ (* (* -4 a) c) (* b b))))) b)
50.0ms
(sqrt (+ (* (* -4 a) c) (* b b)))

simplify1.7s

Counts
30 → 65
Calls

30 calls. Slowest were:

277.0ms
(sqrt (- (* (* (* -4 a) c) (* (* -4 a) c)) (* (* b b) (* b b))))
275.0ms
(sqrt (- (* (* (* -4 a) c) (* (* -4 a) c)) (* (* b b) (* b b))))
271.0ms
(sqrt (+ (pow (* (* -4 a) c) 3) (pow (* b b) 3)))

prune1.3s

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 11.8b

localize190.0ms

Local error

Found 4 expressions with local error:

21.8b
(cbrt (+ (* (* -4 a) c) (* b b)))
21.8b
(cbrt (+ (* b b) (* (* c a) -4)))
21.0b
(sqrt (+ (* (* -4 a) c) (* b b)))
9.9b
(- (- b) (* (fabs (cbrt (+ (* b b) (* (* c a) -4)))) (sqrt (cbrt (+ (* (* -4 a) c) (* b b))))))

rewrite24.0ms

Algorithm
rewrite-expression-head
Counts
4 → 53
Calls

4 calls. Slowest were:

8.0ms
(cbrt (+ (* (* -4 a) c) (* b b)))
7.0ms
(- (- b) (* (fabs (cbrt (+ (* b b) (* (* c a) -4)))) (sqrt (cbrt (+ (* (* -4 a) c) (* b b))))))
6.0ms
(sqrt (+ (* (* -4 a) c) (* b b)))

series431.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

187.0ms
(cbrt (+ (* (* -4 a) c) (* b b)))
98.0ms
(cbrt (+ (* b b) (* (* c a) -4)))
84.0ms
(- (- b) (* (fabs (cbrt (+ (* b b) (* (* c a) -4)))) (sqrt (cbrt (+ (* (* -4 a) c) (* b b))))))
62.0ms
(sqrt (+ (* (* -4 a) c) (* b b)))

simplify2.8s

Counts
29 → 65
Calls

29 calls. Slowest were:

348.0ms
(exp (* 1/3 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c))))))
322.0ms
(- (exp (* 1/3 (+ (log -4) (+ (log a) (log c))))) (* 1/12 (* (exp (* 1/3 (- (log -4) (+ (* 2 (log a)) (* 2 (log c)))))) (pow b 2))))
265.0ms
(sqrt (- (* (* (* -4 a) c) (* (* -4 a) c)) (* (* b b) (* b b))))

prune1.7s

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 11.8b

localize106.0ms

Local error

Found 4 expressions with local error:

21.8b
(cbrt (+ (* (* -4 a) c) (* b b)))
21.8b
(cbrt (+ (* b b) (* (* c a) -4)))
21.0b
(sqrt (+ (* (* -4 a) c) (* b b)))
6.7b
(- (* (fabs (cbrt (+ (* b b) (* (* c a) -4)))) (sqrt (cbrt (+ (* (* -4 a) c) (* b b))))) b)

rewrite29.0ms

Algorithm
rewrite-expression-head
Counts
4 → 51
Calls

4 calls. Slowest were:

16.0ms
(- (* (fabs (cbrt (+ (* b b) (* (* c a) -4)))) (sqrt (cbrt (+ (* (* -4 a) c) (* b b))))) b)
6.0ms
(sqrt (+ (* (* -4 a) c) (* b b)))
4.0ms
(cbrt (+ (* (* -4 a) c) (* b b)))

series418.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

185.0ms
(cbrt (+ (* (* -4 a) c) (* b b)))
99.0ms
(cbrt (+ (* b b) (* (* c a) -4)))
72.0ms
(- (* (fabs (cbrt (+ (* b b) (* (* c a) -4)))) (sqrt (cbrt (+ (* (* -4 a) c) (* b b))))) b)
61.0ms
(sqrt (+ (* (* -4 a) c) (* b b)))

simplify2.9s

Counts
28 → 63
Calls

28 calls. Slowest were:

489.0ms
(exp (* 1/3 (- (log -4) (+ (log (/ 1 a)) (log (/ 1 c))))))
306.0ms
(sqrt (- (* (* (* -4 a) c) (* (* -4 a) c)) (* (* b b) (* b b))))
262.0ms
(- (exp (* 1/3 (+ (log -4) (+ (log a) (log c))))) (* 1/12 (* (exp (* 1/3 (- (log -4) (+ (* 2 (log a)) (* 2 (log c)))))) (pow b 2))))

prune1.8s

Pruning

9 alts after pruning (7 fresh and 2 done)

Merged error: 11.8b

regimes408.0ms

Accuracy

88.6% (0.8b remaining)

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

bsearch236.0ms