Average Error: 19.2 → 13.0
Time: 25.5s
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 5.148536202069843 \cdot 10^{+105}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{-(\left(\left|\sqrt[3]{(\left(c \cdot a\right) \cdot -4 + \left(b \cdot b\right))_*}\right|\right) \cdot \left(\sqrt{\sqrt[3]{(\left(c \cdot a\right) \cdot -4 + \left(b \cdot b\right))_*}}\right) + b)_*}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{(-4 \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*} - b}{a \cdot 2}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{a \cdot 2}}{\frac{1}{\sqrt{(-4 \cdot \left(c \cdot a\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 < 5.148536202069843e+105

    1. Initial program 15.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. Simplified15.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. Using strategy rm
    4. Applied add-cube-cbrt16.0

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

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

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

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

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

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

    if 5.148536202069843e+105 < b

    1. Initial program 30.6

      \[\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. Simplified30.6

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

      \[\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}\]
    4. Using strategy rm
    5. Applied clear-num2.6

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{(-4 \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*} - b}}\\ \end{array}\]
    6. Using strategy rm
    7. Applied div-inv2.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le 5.148536202069843 \cdot 10^{+105}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{-(\left(\left|\sqrt[3]{(\left(c \cdot a\right) \cdot -4 + \left(b \cdot b\right))_*}\right|\right) \cdot \left(\sqrt{\sqrt[3]{(\left(c \cdot a\right) \cdot -4 + \left(b \cdot b\right))_*}}\right) + b)_*}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{(-4 \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*} - b}{a \cdot 2}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{a \cdot 2}}{\frac{1}{\sqrt{(-4 \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*} - b}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019002 +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: 24.6s)Debug log

sample107.0ms

Algorithm
intervals

simplify145.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

144.0ms
(if (>= b 0) (/ (* 2 c) (- (- b) (sqrt (- (* b b) (* (* 4 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))

prune17.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 19.3b

localize131.0ms

Local error

Found 4 expressions with local error:

23.6b
(sqrt (fma -4 (* c a) (* b b)))
23.6b
(sqrt (fma -4 (* c a) (* b b)))
1.7b
(- (- b) (sqrt (fma -4 (* c a) (* b b))))
1.3b
(- (sqrt (fma -4 (* c a) (* b b))) b)

rewrite28.0ms

Algorithm
rewrite-expression-head
Counts
4 → 93
Calls

4 calls. Slowest were:

10.0ms
(- (sqrt (fma -4 (* c a) (* b b))) b)
9.0ms
(- (- b) (sqrt (fma -4 (* c a) (* b b))))
4.0ms
(sqrt (fma -4 (* c a) (* b b)))

series270.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

77.0ms
(- (- b) (sqrt (fma -4 (* c a) (* b b))))
75.0ms
(sqrt (fma -4 (* c a) (* b b)))
74.0ms
(- (sqrt (fma -4 (* c a) (* b b))) b)
45.0ms
(sqrt (fma -4 (* c a) (* b b)))

simplify2.6s

Counts
81 → 105
Calls

81 calls. Slowest were:

106.0ms
(- (* 2 (/ (* a c) b)) (* 2 b))
78.0ms
(fma 1 (- b) (- (* (sqrt (fma -4 (* c a) (* b b))) (sqrt 1))))
77.0ms
(fma 1 (- b) (- (* (sqrt (cbrt (fma -4 (* c a) (* b b)))) (sqrt (* (cbrt (fma -4 (* c a) (* b b))) (cbrt (fma -4 (* c a) (* b b))))))))

prune1.7s

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 11.4b

localize121.0ms

Local error

Found 4 expressions with local error:

23.6b
(sqrt (fma -4 (* c a) (* b b)))
1.3b
(- (sqrt (fma -4 (* c a) (* b b))) b)
0.6b
(fma -4 (* c a) (* b b))
0.1b
(/ (- (sqrt (fma -4 (* c a) (* b b))) b) (* 2 a))

rewrite34.0ms

Algorithm
rewrite-expression-head
Counts
4 → 67
Calls

4 calls. Slowest were:

20.0ms
(/ (- (sqrt (fma -4 (* c a) (* b b))) b) (* 2 a))
10.0ms
(- (sqrt (fma -4 (* c a) (* b b))) b)
2.0ms
(sqrt (fma -4 (* c a) (* b b)))

series238.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

80.0ms
(/ (- (sqrt (fma -4 (* c a) (* b b))) b) (* 2 a))
72.0ms
(sqrt (fma -4 (* c a) (* b b)))
58.0ms
(- (sqrt (fma -4 (* c a) (* b b))) b)
29.0ms
(fma -4 (* c a) (* b b))

simplify1.4s

Counts
34 → 79
Calls

34 calls. Slowest were:

774.0ms
(- (* (sqrt (fma -4 (* c a) (* b b))) (sqrt (fma -4 (* c a) (* b b)))) (* b b))
123.0ms
(- (pow (sqrt (fma -4 (* c a) (* b b))) 3) (pow b 3))
90.0ms
(/ (* (* (- (sqrt (fma -4 (* c a) (* b b))) b) (- (sqrt (fma -4 (* c a) (* b b))) b)) (- (sqrt (fma -4 (* c a) (* b b))) b)) (* (* (* 2 a) (* 2 a)) (* 2 a)))

prune1.3s

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 11.4b

localize106.0ms

Local error

Found 4 expressions with local error:

23.6b
(sqrt (fma -4 (* c a) (* b b)))
1.3b
(- (sqrt (fma -4 (* c a) (* b b))) b)
0.6b
(fma -4 (* c a) (* b b))
0.2b
(/ 1 (/ (* 2 a) (- (sqrt (fma -4 (* c a) (* b b))) b)))

rewrite10.0ms

Algorithm
rewrite-expression-head
Counts
4 → 69
Calls

4 calls. Slowest were:

5.0ms
(- (sqrt (fma -4 (* c a) (* b b))) b)
3.0ms
(/ 1 (/ (* 2 a) (- (sqrt (fma -4 (* c a) (* b b))) b)))
1.0ms
(sqrt (fma -4 (* c a) (* b b)))

series238.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

102.0ms
(/ 1 (/ (* 2 a) (- (sqrt (fma -4 (* c a) (* b b))) b)))
55.0ms
(- (sqrt (fma -4 (* c a) (* b b))) b)
52.0ms
(sqrt (fma -4 (* c a) (* b b)))
30.0ms
(fma -4 (* c a) (* b b))

simplify582.0ms

Counts
32 → 81
Calls

32 calls. Slowest were:

86.0ms
(+ (* (sqrt (fma -4 (* c a) (* b b))) (sqrt (fma -4 (* c a) (* b b)))) (+ (* b b) (* (sqrt (fma -4 (* c a) (* b b))) b)))
59.0ms
(/ (* 2 a) (- (sqrt (fma -4 (* c a) (* b b))) b))
56.0ms
(cbrt (/ (* 2 a) (- (sqrt (fma -4 (* c a) (* b b))) b)))

prune1.2s

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 11.4b

localize142.0ms

Local error

Found 4 expressions with local error:

23.6b
(sqrt (fma -4 (* c a) (* b b)))
1.3b
(- (sqrt (fma -4 (* c a) (* b b))) b)
0.6b
(fma -4 (* c a) (* b b))
0.2b
(/ (/ 1 (* 2 a)) (/ 1 (- (sqrt (fma -4 (* c a) (* b b))) b)))

rewrite12.0ms

Algorithm
rewrite-expression-head
Counts
4 → 96
Calls

4 calls. Slowest were:

5.0ms
(/ (/ 1 (* 2 a)) (/ 1 (- (sqrt (fma -4 (* c a) (* b b))) b)))
5.0ms
(- (sqrt (fma -4 (* c a) (* b b))) b)
1.0ms
(sqrt (fma -4 (* c a) (* b b)))

series258.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

96.0ms
(/ (/ 1 (* 2 a)) (/ 1 (- (sqrt (fma -4 (* c a) (* b b))) b)))
72.0ms
(- (sqrt (fma -4 (* c a) (* b b))) b)
50.0ms
(sqrt (fma -4 (* c a) (* b b)))
39.0ms
(fma -4 (* c a) (* b b))

simplify8.6s

Counts
83 → 108
Calls

83 calls. Slowest were:

1.1s
(/ 1 (/ 1 (- (pow (sqrt (fma -4 (* c a) (* b b))) 3) (pow b 3))))
584.0ms
(/ (sqrt (/ 1 (* 2 a))) (/ 1 (- (* (sqrt (fma -4 (* c a) (* b b))) (sqrt (fma -4 (* c a) (* b b)))) (* b b))))
542.0ms
(/ 1 (/ 1 (- (* (sqrt (fma -4 (* c a) (* b b))) (sqrt (fma -4 (* c a) (* b b)))) (* b b))))

prune1.6s

Pruning

9 alts after pruning (7 fresh and 2 done)

Merged error: 11.4b

regimes451.0ms

Accuracy

92.7% (0.6b remaining)

Error of 13.0b against oracle of 12.4b and baseline of 21.2b

bsearch141.0ms

end0.0ms

sample3.1s

Algorithm
intervals