Average Error: 33.3 → 6.7
Time: 33.1s
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 -1.0041518941750358 \cdot 10^{+133}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 3.9279776760338723 \cdot 10^{-290}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}\\ \mathbf{elif}\;b \le 2.653900512555386 \cdot 10^{+58}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\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.3
Target20.7
Herbie6.7
\[\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 4 regimes
  2. if b < -1.0041518941750358e+133

    1. Initial program 60.5

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

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

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

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

    if -1.0041518941750358e+133 < b < 3.9279776760338723e-290

    1. Initial program 32.8

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

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

      \[\leadsto \frac{\left(-b\right) - \sqrt{\color{blue}{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
    4. Simplified32.8

      \[\leadsto \frac{\left(-b\right) - \sqrt{\color{blue}{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied div-inv32.9

      \[\leadsto \color{blue}{\left(\left(-b\right) - \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}\right) \cdot \frac{1}{2 \cdot a}}\]
    7. Using strategy rm
    8. Applied flip--33.0

      \[\leadsto \color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} \cdot \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}{\left(-b\right) + \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}} \cdot \frac{1}{2 \cdot a}\]
    9. Applied associate-*l/33.0

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

      \[\leadsto \frac{\color{blue}{\left(0 - \left(c \cdot -4\right) \cdot a\right) \cdot \frac{\frac{1}{2}}{a}}}{\left(-b\right) + \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}\]
    11. Using strategy rm
    12. Applied sub0-neg14.9

      \[\leadsto \frac{\color{blue}{\left(-\left(c \cdot -4\right) \cdot a\right)} \cdot \frac{\frac{1}{2}}{a}}{\left(-b\right) + \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}\]
    13. Applied distribute-lft-neg-out14.9

      \[\leadsto \frac{\color{blue}{-\left(\left(c \cdot -4\right) \cdot a\right) \cdot \frac{\frac{1}{2}}{a}}}{\left(-b\right) + \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}\]
    14. Applied distribute-frac-neg14.9

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

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

    if 3.9279776760338723e-290 < b < 2.653900512555386e+58

    1. Initial program 8.9

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

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

      \[\leadsto \frac{\left(-b\right) - \sqrt{\color{blue}{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
    4. Simplified9.0

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

    if 2.653900512555386e+58 < b

    1. Initial program 37.0

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.0041518941750358 \cdot 10^{+133}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 3.9279776760338723 \cdot 10^{-290}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}\\ \mathbf{elif}\;b \le 2.653900512555386 \cdot 10^{+58}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Reproduce

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

sample174.0ms

Algorithm
intervals

simplify81.0ms

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

prune11.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 34.1b

localize30.0ms

Local error

Found 4 expressions with local error:

23.4b
(sqrt (fma (* -4 a) c (* b b)))
0.3b
(- (- 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))

rewrite36.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
22.0ms
(/ (- (- b) (sqrt (fma (* -4 a) c (* b b)))) (* 2 a))
9.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))

series248.0ms

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

simplify3.3s

Counts
93 → 112
Calls
93 calls:
Slowest
214.0ms
(- (* (- b) (- b)) (* (sqrt (fma (* -4 a) c (* b b))) (sqrt (fma (* -4 a) c (* b b)))))
179.0ms
(- (pow (- b) 3) (pow (sqrt (fma (* -4 a) c (* b b))) 3))
82.0ms
(- (log (- (- b) (sqrt (fma (* -4 a) c (* b b))))) (log (* 2 a)))
74.0ms
(fma 1 (- b) (- (* (sqrt (fma (* -4 a) c (* b b))) (sqrt 1))))
74.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))))))))

prune1.3s

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 6.2b

localize21.0ms

Local error

Found 4 expressions with local error:

23.4b
(sqrt (fma (* a -4) c (* b b)))
0.3b
(- (- b) (sqrt (fma (* a -4) c (* b b))))
0.1b
(/ (- (- b) (sqrt (fma (* a -4) c (* b b)))) (* 2 a))
0.0b
(fma (* a -4) c (* b b))

rewrite18.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
11.0ms
(/ (- (- b) (sqrt (fma (* a -4) c (* b b)))) (* 2 a))
5.0ms
(- (- b) (sqrt (fma (* a -4) c (* b b))))
1.0ms
(sqrt (fma (* a -4) c (* b b)))
0.0ms
(fma (* a -4) c (* b b))

series238.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
72.0ms
(/ (- (- b) (sqrt (fma (* a -4) c (* b b)))) (* 2 a))
63.0ms
(sqrt (fma (* a -4) c (* b b)))
56.0ms
(- (- b) (sqrt (fma (* a -4) c (* b b))))
46.0ms
(fma (* a -4) c (* b b))

simplify3.3s

Counts
93 → 112
Calls
93 calls:
Slowest
247.0ms
(- (* (- b) (- b)) (* (sqrt (fma (* a -4) c (* b b))) (sqrt (fma (* a -4) c (* b b)))))
199.0ms
(- (pow (- b) 3) (pow (sqrt (fma (* a -4) c (* b b))) 3))
81.0ms
(/ (* (* (- (- b) (sqrt (fma (* a -4) c (* b b)))) (- (- b) (sqrt (fma (* a -4) c (* b b))))) (- (- b) (sqrt (fma (* a -4) c (* b b))))) (* (* (* 2 a) (* 2 a)) (* 2 a)))
67.0ms
(fma (sqrt (- b)) (sqrt (- b)) (- (* (sqrt (sqrt (fma (* a -4) c (* b b)))) (sqrt (sqrt (fma (* a -4) c (* b b)))))))
62.0ms
(fma 1 (- b) (- (* (sqrt (cbrt (fma (* a -4) c (* b b)))) (sqrt (* (cbrt (fma (* a -4) c (* b b))) (cbrt (fma (* a -4) c (* b b))))))))

prune1.2s

Pruning

10 alts after pruning (9 fresh and 1 done)

Merged error: 6.2b

localize6.0ms

Local error

Found 4 expressions with local error:

23.4b
(sqrt (fma (* a -4) c (* b b)))
0.3b
(- (- b) (sqrt (fma (* a -4) c (* b b))))
0.2b
(* (- (- b) (sqrt (fma (* a -4) c (* b b)))) (/ 1 (* 2 a)))
0.0b
(fma (* a -4) c (* b b))

rewrite33.0ms

Algorithm
rewrite-expression-head
Rules
31×add-sqr-sqrt
26×*-un-lft-identity
24×prod-diff
22×add-cube-cbrt
17×sqrt-prod
add-exp-log
neg-mul-1
add-log-exp
associate-*l*
add-cbrt-cube
pow1
difference-of-squares
log1p-expm1-u
associate-*r*
fma-neg
expm1-log1p-u
flip--
flip3--
distribute-lft-out--
prod-exp
associate-*l/
frac-times
div-inv
fma-udef
cbrt-unprod
*-commutative
un-div-inv
associate-*r/
pow-prod-down
diff-log
pow1/2
sub-neg
rec-exp
rem-sqrt-square
neg-sub0
associate--l-
Counts
4 → 100
Calls
4 calls:
Slowest
21.0ms
(* (- (- b) (sqrt (fma (* a -4) c (* b b)))) (/ 1 (* 2 a)))
9.0ms
(- (- b) (sqrt (fma (* a -4) c (* b b))))
1.0ms
(sqrt (fma (* a -4) c (* b b)))
0.0ms
(fma (* a -4) c (* b b))

series198.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
63.0ms
(sqrt (fma (* a -4) c (* b b)))
58.0ms
(* (- (- b) (sqrt (fma (* a -4) c (* b b)))) (/ 1 (* 2 a)))
45.0ms
(- (- b) (sqrt (fma (* a -4) c (* b b))))
32.0ms
(fma (* a -4) c (* b b))

simplify5.2s

Counts
92 → 112
Calls
92 calls:
Slowest
749.0ms
(* (- (* (- b) (- b)) (* (sqrt (fma (* a -4) c (* b b))) (sqrt (fma (* a -4) c (* b b))))) 1)
448.0ms
(* (- (pow (- b) 3) (pow (sqrt (fma (* a -4) c (* b b))) 3)) 1)
333.0ms
(* (- (- b) (sqrt (fma (* a -4) c (* b b)))) (/ 1 (* 2 a)))
297.0ms
(* (- (* (- b) (- b)) (* (sqrt (fma (* a -4) c (* b b))) (sqrt (fma (* a -4) c (* b b))))) (/ 1 (* 2 a)))
289.0ms
(* (+ (* (- b) (- b)) (+ (* (sqrt (fma (* a -4) c (* b b))) (sqrt (fma (* a -4) c (* b b)))) (* (- b) (sqrt (fma (* a -4) c (* b b)))))) (* 2 a))

prune1.3s

Pruning

9 alts after pruning (7 fresh and 2 done)

Merged error: 6.2b

localize24.0ms

Local error

Found 4 expressions with local error:

23.4b
(sqrt (fma (* a -4) c (* b b)))
15.3b
(* (- 0 (* (* c -4) a)) (/ 1/2 a))
1.7b
(+ (- b) (sqrt (fma (* a -4) c (* b b))))
0.1b
(/ (* (- 0 (* (* c -4) a)) (/ 1/2 a)) (+ (- b) (sqrt (fma (* a -4) c (* b b)))))

rewrite24.0ms

Algorithm
rewrite-expression-head
Rules
16×*-un-lft-identity
11×add-exp-log
11×add-cbrt-cube
11×add-sqr-sqrt
10×add-cube-cbrt
add-log-exp
pow1
associate-/l/
flip--
log1p-expm1-u
associate-*l/
associate-*r*
flip3--
times-frac
fma-def
associate-/r*
frac-times
expm1-log1p-u
distribute-lft-out
sqrt-prod
associate-*l*
sub0-neg
div-inv
flip-+
cbrt-unprod
associate-/r/
associate-*r/
prod-exp
div-exp
flip3-+
cbrt-undiv
distribute-lft-neg-out
associate-/l*
associate-+l-
*-commutative
distribute-frac-neg
pow-prod-down
pow1/2
frac-2neg
sum-log
neg-mul-1
clear-num
rem-sqrt-square
+-commutative
neg-sub0
Counts
4 → 92
Calls
4 calls:
Slowest
14.0ms
(/ (* (- 0 (* (* c -4) a)) (/ 1/2 a)) (+ (- b) (sqrt (fma (* a -4) c (* b b)))))
4.0ms
(+ (- b) (sqrt (fma (* a -4) c (* b b))))
4.0ms
(* (- 0 (* (* c -4) a)) (/ 1/2 a))
1.0ms
(sqrt (fma (* a -4) c (* b b)))

series261.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
147.0ms
(/ (* (- 0 (* (* c -4) a)) (/ 1/2 a)) (+ (- b) (sqrt (fma (* a -4) c (* b b)))))
56.0ms
(+ (- b) (sqrt (fma (* a -4) c (* b b))))
53.0ms
(sqrt (fma (* a -4) c (* b b)))
5.0ms
(* (- 0 (* (* c -4) a)) (/ 1/2 a))

simplify8.4s

Counts
61 → 104
Calls
61 calls:
Slowest
626.0ms
(* (- 0 (* (* c -4) a)) (/ 1/2 a))
508.0ms
(- (+ (log (- 0 (* (* c -4) a))) (log (/ 1/2 a))) (log (+ (- b) (sqrt (fma (* a -4) c (* b b))))))
507.0ms
(* (- (pow 0 3) (pow (* (* c -4) a) 3)) (/ 1/2 a))
506.0ms
(+ (* (- b) (- b)) (- (* (sqrt (fma (* a -4) c (* b b))) (sqrt (fma (* a -4) c (* b b)))) (* (- b) (sqrt (fma (* a -4) c (* b b))))))
471.0ms
(* (- (pow 0 3) (pow (* (* c -4) a) 3)) 1/2)

prune1.2s

Pruning

9 alts after pruning (7 fresh and 2 done)

Merged error: 6.2b

regimes252.0ms

Accuracy

95.1% (1.2b remaining)

Error of 6.7b against oracle of 5.5b and baseline of 29.7b

bsearch477.0ms

end0.0ms

sample4.7s

Algorithm
intervals