Average Error: 19.5 → 8.4
Time: 24.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.337515360840282 \cdot 10^{+154}:\\ \;\;\;\;\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) + \left(-b\right)}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \le 6.182736953988569 \cdot 10^{+53}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \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} + \left(-b\right)}{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{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{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 < -1.337515360840282e+154

    1. Initial program 60.9

      \[\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. Taylor expanded around -inf 11.3

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

    if -1.337515360840282e+154 < b < 6.182736953988569e+53

    1. Initial program 9.0

      \[\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. Using strategy rm
    3. Applied add-sqr-sqrt9.0

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

      \[\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{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]

    if 6.182736953988569e+53 < b

    1. Initial program 26.3

      \[\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. Using strategy rm
    3. Applied add-sqr-sqrt26.3

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

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

      \[\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{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification8.4

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

Reproduce

herbie shell --seed 2019010 
(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: 23.2s)Debug log

sample172.0ms

Algorithm
intervals

simplify113.0ms

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

prune26.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 18.1b

localize134.0ms

Local error

Found 4 expressions with local error:

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

rewrite42.0ms

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

series256.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
72.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
70.0ms
(+ (- b) (sqrt (- (* b b) (* (* 4 a) c))))
59.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
54.0ms
(- (- b) (sqrt (- (* b b) (* (* 4 a) c))))

simplify2.3s

Counts
32 → 69
Calls
32 calls:
Slowest
436.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
404.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
143.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))))
115.0ms
(- b (* 2 (/ (* a c) b)))

prune1.1s

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 6.8b

localize105.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (- (* b b) (* (* 4 a) c)))
22.0b
(sqrt (- (* b b) (* (* 4 a) c)))
22.0b
(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
flip--
add-exp-log
add-cbrt-cube
flip3--
pow1
pow1/2
rem-sqrt-square
difference-of-squares
diff-log
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)))

series251.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
76.0ms
(- (- b) (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))))
63.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
57.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
56.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

simplify2.8s

Counts
33 → 68
Calls
33 calls:
Slowest
454.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
388.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
361.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
179.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))
137.0ms
(- b (* 2 (/ (* a c) b)))

prune1.2s

Pruning

7 alts after pruning (6 fresh and 1 done)

Merged error: 6.8b

localize133.0ms

Local error

Found 4 expressions with local error:

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

rewrite20.0ms

Algorithm
rewrite-expression-head
Rules
10×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
flip-+
associate-+l-
flip3-+
sum-log
+-commutative
neg-sub0
Counts
4 → 54
Calls
4 calls:
Slowest
8.0ms
(+ (- b) (* (sqrt (sqrt (- (* b b) (* (* 4 a) c)))) (sqrt (sqrt (- (* b b) (* (* 4 a) c))))))
4.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
4.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
3.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series238.0ms

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

simplify2.9s

Counts
31 → 66
Calls
31 calls:
Slowest
448.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
401.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
368.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
201.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))
169.0ms
(- b (* 2 (/ (* a c) b)))

prune1.5s

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 6.8b

localize133.0ms

Local error

Found 4 expressions with local error:

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

rewrite13.0ms

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

series326.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
123.0ms
(cbrt (- (* b b) (* (* 4 a) c)))
103.0ms
(cbrt (- (* b b) (* (* 4 a) c)))
51.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
48.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

simplify3.6s

Counts
34 → 66
Calls
34 calls:
Slowest
457.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
452.0ms
(cbrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
379.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
302.0ms
(cbrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
294.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.5s

Pruning

8 alts after pruning (5 fresh and 3 done)

Merged error: 6.8b

regimes409.0ms

Accuracy

90.9% (1.1b remaining)

Error of 8.4b against oracle of 7.3b and baseline of 19.6b

bsearch486.0ms

end0.0ms

sample3.4s

Algorithm
intervals