Average Error: 33.2 → 13.4
Time: 18.4s
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.1566096146303247 \cdot 10^{-232}:\\ \;\;\;\;\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 3.1234815487678856 \cdot 10^{+63}:\\ \;\;\;\;\frac{-4 \cdot \left(c \cdot \frac{1}{2}\right)}{b + \sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-4 \cdot \left(c \cdot \frac{1}{2}\right)}{b + b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.2
Target20.7
Herbie13.4
\[\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 < 2.1566096146303247e-232

    1. Initial program 21.1

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

      \[\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 0 21.1

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

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

    if 2.1566096146303247e-232 < b < 3.1234815487678856e+63

    1. Initial program 33.0

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified33.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 flip--33.1

      \[\leadsto \frac{\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}}}{2 \cdot a}\]
    5. Applied associate-/l/37.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}{\left(2 \cdot a\right) \cdot \left(\sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*} + b\right)}}\]
    6. Simplified21.1

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

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

      \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot c\right)} \cdot \frac{-4}{\sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*} + b}\]
    10. Using strategy rm
    11. Applied associate-*r/7.9

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

    if 3.1234815487678856e+63 < b

    1. Initial program 56.6

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

      \[\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 flip--56.6

      \[\leadsto \frac{\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}}}{2 \cdot a}\]
    5. Applied associate-/l/57.2

      \[\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}{\left(2 \cdot a\right) \cdot \left(\sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*} + b\right)}}\]
    6. Simplified29.6

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

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

      \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot c\right)} \cdot \frac{-4}{\sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*} + b}\]
    10. Using strategy rm
    11. Applied associate-*r/26.7

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

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

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

Reproduce

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

sample193.0ms

Algorithm
intervals
Results
378×(pre true 80)
187×(body real 80)
93×(body nan 80)
36×(body real 2560)
30×(body real 1280)
16×(body real 640)
(body real 160)
(body real 320)
(body real 5120)

simplify41.0ms

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

prune24.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 35.0b

localize42.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (fma (* a c) -4 (* b b)))
2.2b
(- (sqrt (fma (* a c) -4 (* b b))) b)
1.2b
(fma (* a c) -4 (* b b))
0.1b
(/ (- (sqrt (fma (* a c) -4 (* b b))) b) (* 2 a))

rewrite34.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
21.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))

series243.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
97.0ms
(/ (- (sqrt (fma (* a c) -4 (* b b))) b) (* 2 a))
57.0ms
(- (sqrt (fma (* a c) -4 (* b b))) b)
50.0ms
(sqrt (fma (* a c) -4 (* b b)))
39.0ms
(fma (* a c) -4 (* b b))

simplify1.4s

Counts
34 → 79
Calls
34 calls:
Slowest
674.0ms
(- (* (sqrt (fma (* a c) -4 (* b b))) (sqrt (fma (* a c) -4 (* b b)))) (* b b))
101.0ms
(- (pow (sqrt (fma (* a c) -4 (* b b))) 3) (pow b 3))
95.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)))
79.0ms
(- (log (- (sqrt (fma (* a c) -4 (* b b))) b)) (log (* 2 a)))
36.0ms
(- (pow b 2) (* 4 (* a c)))

prune929.0ms

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 22.1b

localize23.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (fma (* a c) -4 (* b b)))
16.3b
(/ (* (* a c) -4) (* (* 2 a) (+ (sqrt (fma (* a c) -4 (* b b))) b)))
1.2b
(+ (sqrt (fma (* a c) -4 (* b b))) b)
1.2b
(fma (* a c) -4 (* b b))

rewrite16.0ms

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

series280.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
129.0ms
(/ (* (* a c) -4) (* (* 2 a) (+ (sqrt (fma (* a c) -4 (* b b))) b)))
62.0ms
(sqrt (fma (* a c) -4 (* b b)))
59.0ms
(+ (sqrt (fma (* a c) -4 (* b b))) b)
30.0ms
(fma (* a c) -4 (* b b))

simplify2.6s

Counts
31 → 75
Calls
31 calls:
Slowest
595.0ms
(/ (* (* (* (* a c) -4) (* (* a c) -4)) (* (* a c) -4)) (* (* (* (* 2 a) (* 2 a)) (* 2 a)) (* (* (+ (sqrt (fma (* a c) -4 (* b b))) b) (+ (sqrt (fma (* a c) -4 (* b b))) b)) (+ (sqrt (fma (* a c) -4 (* b b))) b))))
578.0ms
(/ (* (* (* (* a c) -4) (* (* a c) -4)) (* (* a c) -4)) (* (* (* (* 2 a) (+ (sqrt (fma (* a c) -4 (* b b))) b)) (* (* 2 a) (+ (sqrt (fma (* a c) -4 (* b b))) b))) (* (* 2 a) (+ (sqrt (fma (* a c) -4 (* b b))) b))))
549.0ms
(- (log (* (* a c) -4)) (+ (log (* 2 a)) (log (+ (sqrt (fma (* a c) -4 (* b b))) b))))
424.0ms
(- (log (* (* a c) -4)) (log (* (* 2 a) (+ (sqrt (fma (* a c) -4 (* b b))) b))))
179.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)))

prune934.0ms

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 15.5b

localize8.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (fma (* a c) -4 (* b b)))
1.2b
(+ (sqrt (fma (* a c) -4 (* b b))) b)
1.2b
(fma (* a c) -4 (* b b))
0.2b
(* (* 1/2 c) (/ -4 (+ (sqrt (fma (* a c) -4 (* b b))) b)))

rewrite9.0ms

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

series317.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
142.0ms
(* (* 1/2 c) (/ -4 (+ (sqrt (fma (* a c) -4 (* b b))) b)))
82.0ms
(+ (sqrt (fma (* a c) -4 (* b b))) b)
51.0ms
(sqrt (fma (* a c) -4 (* b b)))
42.0ms
(fma (* a c) -4 (* b b))

simplify1.3s

Counts
31 → 75
Calls
31 calls:
Slowest
539.0ms
(* (* (* (* 1/2 c) (* 1/2 c)) (* 1/2 c)) (* (* (/ -4 (+ (sqrt (fma (* a c) -4 (* b b))) b)) (/ -4 (+ (sqrt (fma (* a c) -4 (* b b))) b))) (/ -4 (+ (sqrt (fma (* a c) -4 (* b b))) b))))
220.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)))
125.0ms
(+ (log (* 1/2 c)) (log (/ -4 (+ (sqrt (fma (* a c) -4 (* b b))) b))))
56.0ms
(* (* 1/2 c) (/ -4 (+ (sqrt (fma (* a c) -4 (* b b))) b)))
51.0ms
(- (pow b 2) (* 4 (* a c)))

prune790.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 11.8b

localize6.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (fma (* a c) -4 (* b b)))
1.2b
(+ (sqrt (fma (* a c) -4 (* b b))) b)
1.2b
(fma (* a c) -4 (* b b))
0.1b
(/ (* (* 1/2 c) -4) (+ (sqrt (fma (* a c) -4 (* b b))) b))

rewrite17.0ms

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

series356.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
176.0ms
(/ (* (* 1/2 c) -4) (+ (sqrt (fma (* a c) -4 (* b b))) b))
79.0ms
(+ (sqrt (fma (* a c) -4 (* b b))) b)
52.0ms
(fma (* a c) -4 (* b b))
49.0ms
(sqrt (fma (* a c) -4 (* b b)))

simplify1.1s

Counts
35 → 77
Calls
35 calls:
Slowest
283.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)))
148.0ms
(/ (* (* (* (* 1/2 c) -4) (* (* 1/2 c) -4)) (* (* 1/2 c) -4)) (* (* (+ (sqrt (fma (* a c) -4 (* b b))) b) (+ (sqrt (fma (* a c) -4 (* b b))) b)) (+ (sqrt (fma (* a c) -4 (* b b))) b)))
145.0ms
(- (log (* (* 1/2 c) -4)) (log (+ (sqrt (fma (* a c) -4 (* b b))) b)))
50.0ms
(/ (* 1/2 c) (* (cbrt (+ (sqrt (fma (* a c) -4 (* b b))) b)) (cbrt (+ (sqrt (fma (* a c) -4 (* b b))) b))))
49.0ms
(- (pow b 2) (* 4 (* a c)))

prune1.0s

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 11.8b

regimes360.0ms

Accuracy

95.1% (0.8b remaining)

Error of 13.4b against oracle of 12.6b and baseline of 29.6b

bsearch381.0ms

end0.0ms

sample4.8s

Algorithm
intervals
Results
11500×(pre true 80)
5932×(body real 80)
2746×(body nan 80)
1013×(body real 2560)
888×(body real 1280)
455×(body real 640)
223×(body real 320)
126×(body real 160)
117×(body real 5120)