Average Error: 33.5 → 10.5
Time: 27.5s
Precision: 64
Internal Precision: 128
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -2.3604286795685533 \cdot 10^{-29}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 3.328175344273382 \cdot 10^{+63}:\\ \;\;\;\;\frac{(\left(\sqrt[3]{-b} \cdot \sqrt[3]{-b}\right) \cdot \left(\sqrt[3]{-b}\right) + \left(-\sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}\right))_*}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

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

Derivation

  1. Split input into 3 regimes
  2. if b < -2.3604286795685533e-29

    1. Initial program 54.6

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified54.7

      \[\leadsto \color{blue}{\frac{\left(-b\right) - \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}}{2 \cdot a}}\]
    3. Taylor expanded around -inf 6.8

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    4. Simplified6.8

      \[\leadsto \color{blue}{\frac{-c}{b}}\]

    if -2.3604286795685533e-29 < b < 3.328175344273382e+63

    1. Initial program 15.3

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified15.3

      \[\leadsto \color{blue}{\frac{\left(-b\right) - \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied add-cube-cbrt15.5

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{-b} \cdot \sqrt[3]{-b}\right) \cdot \sqrt[3]{-b}} - \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}}{2 \cdot a}\]
    5. Applied fma-neg15.5

      \[\leadsto \frac{\color{blue}{(\left(\sqrt[3]{-b} \cdot \sqrt[3]{-b}\right) \cdot \left(\sqrt[3]{-b}\right) + \left(-\sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}\right))_*}}{2 \cdot a}\]

    if 3.328175344273382e+63 < b

    1. Initial program 37.3

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified37.3

      \[\leadsto \color{blue}{\frac{\left(-b\right) - \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}}{2 \cdot a}}\]
    3. Taylor expanded around inf 5.0

      \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification10.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.3604286795685533 \cdot 10^{-29}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 3.328175344273382 \cdot 10^{+63}:\\ \;\;\;\;\frac{(\left(\sqrt[3]{-b} \cdot \sqrt[3]{-b}\right) \cdot \left(\sqrt[3]{-b}\right) + \left(-\sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}\right))_*}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2019016 +o rules:numerics
(FPCore (a b c)
  :name "quadm (p42, negative)"

  :herbie-target
  (if (< b 0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))

Details

Time bar (total: 26.2s)Debug log

sample158.0ms

Algorithm
intervals
Results
368×(pre true 80)
182×(body real 80)
91×(body nan 80)
35×(body real 1280)
32×(body real 2560)
13×(body real 640)
(body real 320)
(body real 160)
(body real 5120)

simplify78.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
78.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))

prune13.0ms

Pruning

2 alts after pruning (2 fresh and 0 done)

Merged error: 35.2b

localize29.0ms

Local error

Found 4 expressions with local error:

24.0b
(sqrt (fma (* -4 a) c (* b b)))
1.2b
(- (- b) (sqrt (fma (* -4 a) c (* b b))))
0.1b
(/ (- (- b) (sqrt (fma (* -4 a) c (* b b)))) (* 2 a))
0.0b
(fma (* -4 a) c (* b b))

rewrite28.0ms

Algorithm
rewrite-expression-head
Rules
35×add-sqr-sqrt
28×*-un-lft-identity
24×prod-diff
22×add-cube-cbrt
18×sqrt-prod
neg-mul-1
difference-of-squares
add-log-exp
associate-/l*
add-exp-log
add-cbrt-cube
times-frac
log1p-expm1-u
fma-neg
pow1
expm1-log1p-u
distribute-lft-out--
associate-/l/
flip--
flip3--
div-inv
fma-udef
div-exp
div-sub
diff-log
pow1/2
frac-2neg
sub-neg
associate-/r*
clear-num
rem-sqrt-square
cbrt-undiv
neg-sub0
associate--l-
Counts
4 → 100
Calls
4 calls:
Slowest
17.0ms
(/ (- (- b) (sqrt (fma (* -4 a) c (* b b)))) (* 2 a))
8.0ms
(- (- b) (sqrt (fma (* -4 a) c (* b b))))
2.0ms
(sqrt (fma (* -4 a) c (* b b)))
0.0ms
(fma (* -4 a) c (* b b))

series179.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
64.0ms
(/ (- (- b) (sqrt (fma (* -4 a) c (* b b)))) (* 2 a))
42.0ms
(- (- b) (sqrt (fma (* -4 a) c (* b b))))
42.0ms
(sqrt (fma (* -4 a) c (* b b)))
31.0ms
(fma (* -4 a) c (* b b))

simplify3.1s

Counts
93 → 112
Calls
93 calls:
Slowest
247.0ms
(- (* (- b) (- b)) (* (sqrt (fma (* -4 a) c (* b b))) (sqrt (fma (* -4 a) c (* b b)))))
175.0ms
(- (pow (- b) 3) (pow (sqrt (fma (* -4 a) c (* b b))) 3))
76.0ms
(fma 1 (- b) (- (* (sqrt (cbrt (fma (* -4 a) c (* b b)))) (sqrt (* (cbrt (fma (* -4 a) c (* b b))) (cbrt (fma (* -4 a) c (* b b))))))))
66.0ms
(fma (sqrt (- b)) (sqrt (- b)) (- (* (sqrt (sqrt (fma (* -4 a) c (* b b)))) (sqrt (sqrt (fma (* -4 a) c (* b b)))))))
64.0ms
(fma (* (cbrt (- b)) (cbrt (- b))) (cbrt (- b)) (- (* (sqrt (fma (* -4 a) c (* b b))) 1)))

prune1.3s

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 4.9b

localize6.0ms

Local error

Found 4 expressions with local error:

24.0b
(sqrt (fma (* -4 a) c (* b b)))
1.2b
(- (- b) (sqrt (fma (* -4 a) c (* b b))))
0.2b
(/ 1 (/ (* 2 a) (- (- b) (sqrt (fma (* -4 a) c (* b b))))))
0.1b
(/ (* 2 a) (- (- b) (sqrt (fma (* -4 a) c (* b b)))))

rewrite17.0ms

Algorithm
rewrite-expression-head
Rules
41×add-sqr-sqrt
32×*-un-lft-identity
24×add-cube-cbrt
24×prod-diff
19×sqrt-prod
18×associate-/r*
12×times-frac
add-exp-log
difference-of-squares
neg-mul-1
add-log-exp
add-cbrt-cube
associate-/r/
pow1
distribute-lft-out--
log1p-expm1-u
fma-neg
expm1-log1p-u
flip--
div-inv
flip3--
div-exp
frac-2neg
clear-num
rec-exp
inv-pow
associate-/l*
pow-flip
diff-log
pow1/2
sub-neg
rem-sqrt-square
cbrt-undiv
neg-sub0
associate--l-
Counts
4 → 118
Calls
4 calls:
Slowest
7.0ms
(/ (* 2 a) (- (- b) (sqrt (fma (* -4 a) c (* b b)))))
5.0ms
(- (- b) (sqrt (fma (* -4 a) c (* b b))))
4.0ms
(/ 1 (/ (* 2 a) (- (- b) (sqrt (fma (* -4 a) c (* b b))))))
1.0ms
(sqrt (fma (* -4 a) c (* b b)))

series372.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
151.0ms
(/ (* 2 a) (- (- b) (sqrt (fma (* -4 a) c (* b b)))))
89.0ms
(/ 1 (/ (* 2 a) (- (- b) (sqrt (fma (* -4 a) c (* b b))))))
73.0ms
(- (- b) (sqrt (fma (* -4 a) c (* b b))))
59.0ms
(sqrt (fma (* -4 a) c (* b b)))

simplify4.6s

Counts
108 → 130
Calls
108 calls:
Slowest
506.0ms
(+ (* (- b) (- b)) (+ (* (sqrt (fma (* -4 a) c (* b b))) (sqrt (fma (* -4 a) c (* b b)))) (* (- b) (sqrt (fma (* -4 a) c (* b b))))))
487.0ms
(+ (* (- b) (- b)) (+ (* (sqrt (fma (* -4 a) c (* b b))) (sqrt (fma (* -4 a) c (* b b)))) (* (- b) (sqrt (fma (* -4 a) c (* b b))))))
102.0ms
(- (* 2 (/ (* a c) b)) (* 2 b))
81.0ms
(/ (* (* (* 2 a) (* 2 a)) (* 2 a)) (* (* (- (- b) (sqrt (fma (* -4 a) c (* b b)))) (- (- b) (sqrt (fma (* -4 a) c (* b b))))) (- (- b) (sqrt (fma (* -4 a) c (* b b))))))
78.0ms
(fma 1 (- b) (- (* (sqrt (fma (* -4 a) c (* b b))) 1)))

prune1.5s

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 4.9b

localize18.0ms

Local error

Found 4 expressions with local error:

24.0b
(sqrt (fma (* -4 a) c (* b b)))
24.0b
(sqrt (fma (* -4 a) c (* b b)))
24.0b
(sqrt (fma (* -4 a) c (* b b)))
1.2b
(- (- b) (sqrt (fma (* -4 a) c (* b b))))

rewrite17.0ms

Algorithm
rewrite-expression-head
Rules
29×add-sqr-sqrt
24×prod-diff
24×*-un-lft-identity
22×sqrt-prod
22×add-cube-cbrt
neg-mul-1
add-log-exp
log1p-expm1-u
add-exp-log
fma-neg
add-cbrt-cube
pow1
expm1-log1p-u
pow1/2
rem-sqrt-square
difference-of-squares
distribute-lft-out--
flip--
diff-log
flip3--
sub-neg
neg-sub0
associate--l-
Counts
4 → 88
Calls
4 calls:
Slowest
9.0ms
(- (- b) (sqrt (fma (* -4 a) c (* b b))))
2.0ms
(sqrt (fma (* -4 a) c (* b b)))
2.0ms
(sqrt (fma (* -4 a) c (* b b)))
2.0ms
(sqrt (fma (* -4 a) c (* b b)))

series273.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
71.0ms
(sqrt (fma (* -4 a) c (* b b)))
71.0ms
(- (- b) (sqrt (fma (* -4 a) c (* b b))))
66.0ms
(sqrt (fma (* -4 a) c (* b b)))
65.0ms
(sqrt (fma (* -4 a) c (* b b)))

simplify2.3s

Counts
80 → 100
Calls
80 calls:
Slowest
68.0ms
(fma 1 (- b) (- (* (sqrt (fma (* -4 a) c (* b b))) 1)))
64.0ms
(fma 1 (- b) (- (* (sqrt (cbrt (fma (* -4 a) c (* b b)))) (sqrt (* (cbrt (fma (* -4 a) c (* b b))) (cbrt (fma (* -4 a) c (* b b))))))))
61.0ms
(fma -1 b (- (* (sqrt (fma (* -4 a) c (* b b))) (sqrt 1))))
60.0ms
(fma (sqrt (- b)) (sqrt (- b)) (- (* (sqrt (sqrt (fma (* -4 a) c (* b b)))) (sqrt (sqrt (fma (* -4 a) c (* b b)))))))
58.0ms
(fma (* (cbrt (- b)) (cbrt (- b))) (cbrt (- b)) (- (* (sqrt (cbrt (fma (* -4 a) c (* b b)))) (sqrt (* (cbrt (fma (* -4 a) c (* b b))) (cbrt (fma (* -4 a) c (* b b))))))))

prune1.5s

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 4.9b

localize29.0ms

Local error

Found 4 expressions with local error:

24.0b
(sqrt (fma (* -4 a) c (* b b)))
24.0b
(sqrt (fma (* -4 a) c (* b b)))
24.0b
(sqrt (fma -4 (* c a) (* b b)))
1.2b
(- (- b) (sqrt (fma (* -4 a) c (* b b))))

rewrite8.0ms

Algorithm
rewrite-expression-head
Rules
29×add-sqr-sqrt
24×prod-diff
24×*-un-lft-identity
22×sqrt-prod
22×add-cube-cbrt
neg-mul-1
add-log-exp
log1p-expm1-u
add-exp-log
fma-neg
add-cbrt-cube
pow1
expm1-log1p-u
pow1/2
rem-sqrt-square
difference-of-squares
distribute-lft-out--
flip--
diff-log
flip3--
sub-neg
neg-sub0
associate--l-
Counts
4 → 88
Calls
4 calls:
Slowest
5.0ms
(- (- b) (sqrt (fma (* -4 a) c (* b b))))
1.0ms
(sqrt (fma (* -4 a) c (* b b)))
1.0ms
(sqrt (fma (* -4 a) c (* b b)))
1.0ms
(sqrt (fma -4 (* c a) (* b b)))

series235.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
67.0ms
(- (- b) (sqrt (fma (* -4 a) c (* b b))))
62.0ms
(sqrt (fma (* -4 a) c (* b b)))
62.0ms
(sqrt (fma (* -4 a) c (* b b)))
44.0ms
(sqrt (fma -4 (* c a) (* b b)))

simplify2.3s

Counts
80 → 100
Calls
80 calls:
Slowest
87.0ms
(- (* 2 (/ (* a c) b)) (* 2 b))
73.0ms
(fma 1 (- b) (- (* (sqrt (cbrt (fma (* -4 a) c (* b b)))) (sqrt (* (cbrt (fma (* -4 a) c (* b b))) (cbrt (fma (* -4 a) c (* b b))))))))
70.0ms
(fma 1 (- b) (- (* (sqrt (fma (* -4 a) c (* b b))) 1)))
66.0ms
(* -2 (/ (* a c) b))
63.0ms
(fma (* (cbrt (- b)) (cbrt (- b))) (cbrt (- b)) (- (* (sqrt (cbrt (fma (* -4 a) c (* b b)))) (sqrt (* (cbrt (fma (* -4 a) c (* b b))) (cbrt (fma (* -4 a) c (* b b))))))))

prune2.4s

Pruning

9 alts after pruning (7 fresh and 2 done)

Merged error: 4.9b

regimes466.0ms

Accuracy

82.9% (4.8b remaining)

Error of 10.5b against oracle of 5.7b and baseline of 33.6b

bsearch249.0ms

end0.0ms

sample4.9s

Algorithm
intervals
Results
11455×(pre true 80)
5803×(body real 80)
2738×(body nan 80)
1107×(body real 2560)
947×(body real 1280)
433×(body real 640)
217×(body real 320)
109×(body real 5120)
101×(body real 160)