Average Error: 19.4 → 9.0
Time: 19.4s
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 -7.01049118321302 \cdot 10^{+117}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\left(-4 \cdot a\right) \cdot c + b \cdot b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(2 \cdot \frac{a \cdot c}{b} - b\right) - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le 1.501809486178084 \cdot 10^{+23}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \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}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\left(-4 \cdot a\right) \cdot c + b \cdot b} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\left(-4 \cdot a\right) \cdot c + b \cdot b} - b}{2 \cdot a}\\ \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 3 regimes
  2. if b < -7.01049118321302e+117

    1. Initial program 49.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. Simplified49.4

      \[\leadsto \color{blue}{\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{\sqrt{b \cdot b + \left(-4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \end{array}}\]
    3. Taylor expanded around -inf 10.2

      \[\leadsto \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(2 \cdot \frac{a \cdot c}{b} - b\right) - b}{2 \cdot a}\\ \end{array}\]

    if -7.01049118321302e+117 < b < 1.501809486178084e+23

    1. Initial program 9.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. Simplified9.4

      \[\leadsto \color{blue}{\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{\sqrt{b \cdot b + \left(-4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \end{array}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt9.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -7.01049118321302 \cdot 10^{+117}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\left(-4 \cdot a\right) \cdot c + b \cdot b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(2 \cdot \frac{a \cdot c}{b} - b\right) - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le 1.501809486178084 \cdot 10^{+23}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \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}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\left(-4 \cdot a\right) \cdot c + b \cdot b} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\left(-4 \cdot a\right) \cdot c + b \cdot b} - b}{2 \cdot a}\\ \end{array}\]

Reproduce

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

sample84.0ms

Algorithm
intervals
Results
49.0ms283×body80valid
15.0ms97×body80nan

simplify154.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
153.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

localize184.0ms

Local error

Found 4 expressions with local error:

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

rewrite45.0ms

Algorithm
rewrite-expression-head
Rules
12×add-sqr-sqrt
*-un-lft-identity
sqrt-prod
add-log-exp
add-cube-cbrt
add-exp-log
sqrt-div
add-cbrt-cube
pow1
difference-of-squares
flip--
flip-+
pow1/2
flip3--
flip3-+
sub-neg
rem-sqrt-square
distribute-lft-out--
diff-log
neg-sub0
associate--l-
Counts
4 → 55
Calls
4 calls:
Slowest
21.0ms
(- (sqrt (+ (* b b) (* (* -4 a) c))) b)
13.0ms
(- (- b) (sqrt (+ (* b b) (* (* -4 a) c))))
6.0ms
(sqrt (+ (* b b) (* (* -4 a) c)))
4.0ms
(sqrt (+ (* b b) (* (* -4 a) c)))

series235.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
75.0ms
(sqrt (+ (* b b) (* (* -4 a) c)))
58.0ms
(sqrt (+ (* b b) (* (* -4 a) c)))
52.0ms
(- (sqrt (+ (* b b) (* (* -4 a) c))) b)
50.0ms
(- (- b) (sqrt (+ (* b b) (* (* -4 a) c))))

simplify1.3s

Counts
30 → 67
Calls
30 calls:
Slowest
159.0ms
(sqrt (+ (pow (* b b) 3) (pow (* (* -4 a) c) 3)))
137.0ms
(sqrt (+ (pow (* b b) 3) (pow (* (* -4 a) c) 3)))
126.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* -4 a) c) (* (* -4 a) c))))
120.0ms
(- b (* 2 (/ (* a c) b)))
105.0ms
(- b (* 2 (/ (* a c) b)))

prune1.1s

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 7.6b

localize111.0ms

Local error

Found 4 expressions with local error:

21.7b
(sqrt (+ (* b b) (* (* -4 a) c)))
21.7b
(sqrt (+ (* b b) (* (* -4 a) c)))
21.7b
(sqrt (+ (* b b) (* (* -4 a) c)))
9.3b
(- (- b) (* (sqrt (sqrt (+ (* b b) (* (* -4 a) c)))) (sqrt (sqrt (+ (* b b) (* (* -4 a) c))))))

rewrite10.0ms

Algorithm
rewrite-expression-head
Rules
11×add-sqr-sqrt
sqrt-prod
add-cube-cbrt
*-un-lft-identity
add-log-exp
sqrt-div
add-exp-log
add-cbrt-cube
pow1
flip-+
pow1/2
flip3-+
rem-sqrt-square
difference-of-squares
flip--
diff-log
flip3--
sub-neg
neg-sub0
associate--l-
Counts
4 → 56
Calls
4 calls:
Slowest
4.0ms
(- (- b) (* (sqrt (sqrt (+ (* b b) (* (* -4 a) c)))) (sqrt (sqrt (+ (* b b) (* (* -4 a) c))))))
2.0ms
(sqrt (+ (* b b) (* (* -4 a) c)))
2.0ms
(sqrt (+ (* b b) (* (* -4 a) c)))
2.0ms
(sqrt (+ (* b b) (* (* -4 a) c)))

series170.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
45.0ms
(sqrt (+ (* b b) (* (* -4 a) c)))
45.0ms
(- (- b) (* (sqrt (sqrt (+ (* b b) (* (* -4 a) c)))) (sqrt (sqrt (+ (* b b) (* (* -4 a) c))))))
41.0ms
(sqrt (+ (* b b) (* (* -4 a) c)))
40.0ms
(sqrt (+ (* b b) (* (* -4 a) c)))

simplify1.8s

Counts
33 → 68
Calls
33 calls:
Slowest
245.0ms
(sqrt (+ (pow (* b b) 3) (pow (* (* -4 a) c) 3)))
224.0ms
(sqrt (+ (pow (* b b) 3) (pow (* (* -4 a) c) 3)))
198.0ms
(sqrt (+ (pow (* b b) 3) (pow (* (* -4 a) c) 3)))
149.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* -4 a) c) (* (* -4 a) c))))
131.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* -4 a) c) (* (* -4 a) c))))

prune1.3s

Pruning

10 alts after pruning (9 fresh and 1 done)

Merged error: 7.6b

localize117.0ms

Local error

Found 4 expressions with local error:

21.7b
(sqrt (+ (* b b) (* (* -4 a) c)))
21.7b
(sqrt (+ (* b b) (* (* -4 a) c)))
21.7b
(sqrt (+ (* b b) (* (* -4 a) c)))
12.1b
(- (* (sqrt (sqrt (+ (* b b) (* (* -4 a) c)))) (sqrt (sqrt (+ (* b b) (* (* -4 a) c))))) b)

rewrite17.0ms

Algorithm
rewrite-expression-head
Rules
10×add-sqr-sqrt
sqrt-prod
add-cube-cbrt
*-un-lft-identity
sqrt-div
add-log-exp
add-exp-log
add-cbrt-cube
pow1
flip-+
pow1/2
flip3-+
rem-sqrt-square
flip--
flip3--
sub-neg
Counts
4 → 53
Calls
4 calls:
Slowest
11.0ms
(- (* (sqrt (sqrt (+ (* b b) (* (* -4 a) c)))) (sqrt (sqrt (+ (* b b) (* (* -4 a) c))))) b)
2.0ms
(sqrt (+ (* b b) (* (* -4 a) c)))
2.0ms
(sqrt (+ (* b b) (* (* -4 a) c)))
2.0ms
(sqrt (+ (* b b) (* (* -4 a) c)))

series243.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
70.0ms
(sqrt (+ (* b b) (* (* -4 a) c)))
65.0ms
(sqrt (+ (* b b) (* (* -4 a) c)))
64.0ms
(sqrt (+ (* b b) (* (* -4 a) c)))
44.0ms
(- (* (sqrt (sqrt (+ (* b b) (* (* -4 a) c)))) (sqrt (sqrt (+ (* b b) (* (* -4 a) c))))) b)

simplify1.7s

Counts
30 → 65
Calls
30 calls:
Slowest
229.0ms
(sqrt (+ (pow (* b b) 3) (pow (* (* -4 a) c) 3)))
204.0ms
(sqrt (+ (pow (* b b) 3) (pow (* (* -4 a) c) 3)))
181.0ms
(sqrt (+ (pow (* b b) 3) (pow (* (* -4 a) c) 3)))
152.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* -4 a) c) (* (* -4 a) c))))
144.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* -4 a) c) (* (* -4 a) c))))

prune1.1s

Pruning

10 alts after pruning (8 fresh and 2 done)

Merged error: 7.6b

localize124.0ms

Local error

Found 4 expressions with local error:

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

rewrite20.0ms

Algorithm
rewrite-expression-head
Rules
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
cbrt-prod
add-log-exp
add-exp-log
add-cbrt-cube
cbrt-div
pow1
flip-+
sqrt-prod
flip3-+
sqrt-div
pow1/3
flip--
pow1/2
flip3--
sub-neg
rem-sqrt-square
Counts
4 → 51
Calls
4 calls:
Slowest
14.0ms
(- (* (fabs (cbrt (+ (* b b) (* a (* -4 c))))) (sqrt (cbrt (+ (* b b) (* (* -4 a) c))))) b)
2.0ms
(sqrt (+ (* b b) (* (* -4 a) c)))
1.0ms
(cbrt (+ (* b b) (* a (* -4 c))))
1.0ms
(cbrt (+ (* b b) (* (* -4 a) c)))

series330.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
111.0ms
(cbrt (+ (* b b) (* (* -4 a) c)))
91.0ms
(cbrt (+ (* b b) (* a (* -4 c))))
77.0ms
(- (* (fabs (cbrt (+ (* b b) (* a (* -4 c))))) (sqrt (cbrt (+ (* b b) (* (* -4 a) c))))) b)
51.0ms
(sqrt (+ (* b b) (* (* -4 a) c)))

simplify2.2s

Counts
28 → 63
Calls
28 calls:
Slowest
312.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))))
264.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))))
202.0ms
(- (* (fabs (pow (- (pow b 2) (* 4 (* a c))) 1/3)) (exp (* 1/6 (+ (log -4) (+ (log a) (log c)))))) (+ b (* 1/24 (* (pow b 2) (* (fabs (pow (- (pow b 2) (* 4 (* a c))) 1/3)) (exp (* 1/6 (- (log -4) (+ (* 5 (log a)) (* 5 (log c)))))))))))
197.0ms
(cbrt (+ (pow (* b b) 3) (pow (* (* -4 a) c) 3)))
194.0ms
(sqrt (+ (pow (* b b) 3) (pow (* (* -4 a) c) 3)))

prune1.4s

Pruning

10 alts after pruning (8 fresh and 2 done)

Merged error: 7.5b

regimes458.0ms

Accuracy

88.1% (1.4b remaining)

Error of 9.0b against oracle of 7.5b and baseline of 19.5b

bsearch305.0ms

end0.0ms

sample3.1s

Algorithm
intervals
Results
2.2s8738×body80valid
683.0ms2979×body80nan