Average Error: 33.2 → 13.7
Time: 16.9s
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 -5.4415579011733295 \cdot 10^{-244}:\\ \;\;\;\;\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.0251889522263652 \cdot 10^{+136}:\\ \;\;\;\;\frac{c \cdot -2}{\sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*} + b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(a \cdot \left(c \cdot -4\right)\right) \cdot \frac{\frac{1}{2}}{a}}{b + b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.2
Target20.6
Herbie13.7
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \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 < -5.4415579011733295e-244

    1. Initial program 21.7

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

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

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

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

    if -5.4415579011733295e-244 < b < 2.0251889522263652e+136

    1. Initial program 31.2

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

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

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

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

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

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

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

    if 2.0251889522263652e+136 < b

    1. Initial program 61.0

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

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

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

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

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

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

      \[\leadsto \frac{\left(a \cdot \left(-4 \cdot c\right)\right) \cdot \frac{\frac{1}{2}}{a}}{\color{blue}{b} + b}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -5.4415579011733295 \cdot 10^{-244}:\\ \;\;\;\;\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.0251889522263652 \cdot 10^{+136}:\\ \;\;\;\;\frac{c \cdot -2}{\sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*} + b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(a \cdot \left(c \cdot -4\right)\right) \cdot \frac{\frac{1}{2}}{a}}{b + b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019010 +o rules:numerics
(FPCore (a b c)
  :name "quadp (p42, positive)"

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

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

Details

Time bar (total: 15.7s)Debug log

sample150.0ms

Algorithm
intervals

simplify55.0ms

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

prune10.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 32.9b

localize46.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (fma (* a c) -4 (* b b)))
1.7b
(- (sqrt (fma (* a c) -4 (* b b))) b)
0.2b
(fma (* a c) -4 (* b b))
0.1b
(/ (- (sqrt (fma (* a c) -4 (* b b))) b) (* 2 a))

rewrite33.0ms

Algorithm
rewrite-expression-head
Rules
10×add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
sqrt-prod
add-exp-log
fma-neg
add-cbrt-cube
add-log-exp
log1p-expm1-u
pow1
expm1-log1p-u
associate-/l*
times-frac
associate-/l/
flip--
flip3--
div-inv
fma-udef
div-exp
div-sub
pow1/2
frac-2neg
sub-neg
associate-/r*
clear-num
rem-sqrt-square
cbrt-undiv
Counts
4 → 67
Calls
4 calls:
Slowest
19.0ms
(/ (- (sqrt (fma (* a c) -4 (* b b))) b) (* 2 a))
10.0ms
(- (sqrt (fma (* a c) -4 (* b b))) b)
2.0ms
(sqrt (fma (* a c) -4 (* b b)))
0.0ms
(fma (* a c) -4 (* b b))

series254.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
85.0ms
(sqrt (fma (* a c) -4 (* b b)))
71.0ms
(/ (- (sqrt (fma (* a c) -4 (* b b))) b) (* 2 a))
69.0ms
(- (sqrt (fma (* a c) -4 (* b b))) b)
29.0ms
(fma (* a c) -4 (* b b))

simplify1.4s

Counts
34 → 79
Calls
34 calls:
Slowest
703.0ms
(- (* (sqrt (fma (* a c) -4 (* b b))) (sqrt (fma (* a c) -4 (* b b)))) (* b b))
142.0ms
(- (pow (sqrt (fma (* a c) -4 (* b b))) 3) (pow b 3))
98.0ms
(/ (* (* (- (sqrt (fma (* a c) -4 (* b b))) b) (- (sqrt (fma (* a c) -4 (* b b))) b)) (- (sqrt (fma (* a c) -4 (* b b))) b)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
58.0ms
(- (log (- (sqrt (fma (* a c) -4 (* b b))) b)) (log (* 2 a)))
40.0ms
(/ (* (cbrt (- (sqrt (fma (* a c) -4 (* b b))) b)) (cbrt (- (sqrt (fma (* a c) -4 (* b b))) b))) 2)

prune832.0ms

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 21.0b

localize18.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (fma (* a -4) c (* b b)))
1.7b
(- (sqrt (fma (* a -4) c (* b b))) b)
0.1b
(/ (- (sqrt (fma (* a -4) c (* b b))) b) (* 2 a))
0.0b
(fma (* a -4) c (* b b))

rewrite30.0ms

Algorithm
rewrite-expression-head
Rules
10×add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
sqrt-prod
add-exp-log
fma-neg
add-cbrt-cube
add-log-exp
log1p-expm1-u
pow1
expm1-log1p-u
associate-/l*
times-frac
associate-/l/
flip--
flip3--
div-inv
fma-udef
div-exp
div-sub
pow1/2
frac-2neg
sub-neg
associate-/r*
clear-num
rem-sqrt-square
cbrt-undiv
Counts
4 → 67
Calls
4 calls:
Slowest
17.0ms
(/ (- (sqrt (fma (* a -4) c (* b b))) b) (* 2 a))
10.0ms
(- (sqrt (fma (* a -4) c (* b b))) b)
2.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
69.0ms
(/ (- (sqrt (fma (* a -4) c (* b b))) b) (* 2 a))
56.0ms
(- (sqrt (fma (* a -4) c (* b b))) b)
41.0ms
(sqrt (fma (* a -4) c (* b b)))
31.0ms
(fma (* a -4) c (* b b))

simplify1.3s

Counts
34 → 79
Calls
34 calls:
Slowest
566.0ms
(- (* (sqrt (fma (* a -4) c (* b b))) (sqrt (fma (* a -4) c (* b b)))) (* b b))
105.0ms
(- (pow (sqrt (fma (* a -4) c (* b b))) 3) (pow b 3))
94.0ms
(/ (* (* (- (sqrt (fma (* a -4) c (* b b))) b) (- (sqrt (fma (* a -4) c (* b b))) b)) (- (sqrt (fma (* a -4) c (* b b))) b)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
80.0ms
(- (log (- (sqrt (fma (* a -4) c (* b b))) b)) (log (* 2 a)))
52.0ms
(- (pow b 2) (* 4 (* a c)))

prune922.0ms

Pruning

10 alts after pruning (9 fresh and 1 done)

Merged error: 21.0b

localize6.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (fma (* a c) -4 (* b b)))
1.7b
(- (sqrt (fma (* a c) -4 (* b b))) b)
0.2b
(* (- (sqrt (fma (* a c) -4 (* b b))) b) (/ 1 (* 2 a)))
0.2b
(fma (* a c) -4 (* b b))

rewrite19.0ms

Algorithm
rewrite-expression-head
Rules
10×add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
add-exp-log
sqrt-prod
fma-neg
add-cbrt-cube
pow1
add-log-exp
log1p-expm1-u
associate-*r*
expm1-log1p-u
flip--
associate-*l*
flip3--
prod-exp
associate-*l/
frac-times
div-inv
fma-udef
cbrt-unprod
*-commutative
un-div-inv
associate-*r/
pow-prod-down
pow1/2
sub-neg
rec-exp
rem-sqrt-square
Counts
4 → 70
Calls
4 calls:
Slowest
12.0ms
(* (- (sqrt (fma (* a c) -4 (* b b))) b) (/ 1 (* 2 a)))
5.0ms
(- (sqrt (fma (* a c) -4 (* b b))) b)
1.0ms
(sqrt (fma (* a c) -4 (* b b)))
0.0ms
(fma (* a c) -4 (* b b))

series245.0ms

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

simplify1.9s

Counts
39 → 82
Calls
39 calls:
Slowest
293.0ms
(* (- (* (sqrt (fma (* a c) -4 (* b b))) (sqrt (fma (* a c) -4 (* b b)))) (* b b)) 1)
261.0ms
(* (- (pow (sqrt (fma (* a c) -4 (* b b))) 3) (pow b 3)) 1)
236.0ms
(* (- (sqrt (fma (* a c) -4 (* b b))) b) (/ 1 (* 2 a)))
200.0ms
(* (- (* (sqrt (fma (* a c) -4 (* b b))) (sqrt (fma (* a c) -4 (* b b)))) (* b b)) (/ 1 (* 2 a)))
173.0ms
(* (+ (* (sqrt (fma (* a c) -4 (* b b))) (sqrt (fma (* a c) -4 (* b b)))) (+ (* b b) (* (sqrt (fma (* a c) -4 (* b b))) b))) (* 2 a))

prune827.0ms

Pruning

9 alts after pruning (7 fresh and 2 done)

Merged error: 20.1b

localize20.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (fma (* a c) -4 (* b b)))
14.3b
(* (* a (* -4 c)) (/ 1/2 a))
0.3b
(+ (sqrt (fma (* a c) -4 (* b b))) b)
0.2b
(fma (* a c) -4 (* b b))

rewrite10.0ms

Algorithm
rewrite-expression-head
Rules
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
sqrt-prod
add-exp-log
add-cbrt-cube
fma-def
pow1
add-log-exp
log1p-expm1-u
associate-*r*
expm1-log1p-u
div-inv
fma-udef
flip-+
cbrt-unprod
*-commutative
associate-*r/
prod-exp
pow-prod-down
associate-*l*
pow1/2
flip3-+
rem-sqrt-square
+-commutative
Counts
4 → 61
Calls
4 calls:
Slowest
4.0ms
(* (* a (* -4 c)) (/ 1/2 a))
4.0ms
(+ (sqrt (fma (* a c) -4 (* b b))) b)
1.0ms
(sqrt (fma (* a c) -4 (* b b)))
0.0ms
(fma (* a c) -4 (* b b))

series180.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
80.0ms
(+ (sqrt (fma (* a c) -4 (* b b))) b)
59.0ms
(sqrt (fma (* a c) -4 (* b b)))
32.0ms
(fma (* a c) -4 (* b b))
9.0ms
(* (* a (* -4 c)) (/ 1/2 a))

simplify830.0ms

Counts
28 → 73
Calls
28 calls:
Slowest
247.0ms
(* (* a (* -4 c)) (/ 1/2 a))
150.0ms
(+ (log (* a (* -4 c))) (log (/ 1/2 a)))
149.0ms
(* (* (* (* a (* -4 c)) (* a (* -4 c))) (* a (* -4 c))) (* (* (/ 1/2 a) (/ 1/2 a)) (/ 1/2 a)))
49.0ms
(- (pow b 2) (* 4 (* a c)))
48.0ms
(- (pow b 2) (* 4 (* a c)))

prune894.0ms

Pruning

9 alts after pruning (6 fresh and 3 done)

Merged error: 12.7b

regimes364.0ms

Accuracy

98.4% (0.3b remaining)

Error of 13.7b against oracle of 13.5b and baseline of 29.4b

bsearch399.0ms

end0.0ms

sample4.7s

Algorithm
intervals