Average Error: 33.4 → 13.5
Time: 18.2s
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 4.891503048541261 \cdot 10^{-173}:\\ \;\;\;\;\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.501809486178084 \cdot 10^{+23}:\\ \;\;\;\;\left(c \cdot \frac{1}{2}\right) \cdot \frac{-4}{\sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*} + b}\\ \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.4
Target20.6
Herbie13.5
\[\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 < 4.891503048541261e-173

    1. Initial program 20.9

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

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

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

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

    if 4.891503048541261e-173 < b < 1.501809486178084e+23

    1. Initial program 32.2

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

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

      \[\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-frac14.7

      \[\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. Simplified5.9

      \[\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}\]

    if 1.501809486178084e+23 < b

    1. Initial program 55.5

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

      \[\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--55.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/56.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. Simplified27.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-frac25.7

      \[\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. Simplified23.9

      \[\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/23.8

      \[\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 4.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.5

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

Reproduce

herbie shell --seed 2019022 +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.0s)Debug log

sample180.0ms

Algorithm
intervals
Results
67.0ms40×body2560valid
32.0ms185×body80valid
23.0ms27×body1280valid
17.0ms97×body80nan
10.0ms15×body640valid
4.0msbody5120valid
3.0msbody320valid
2.0msbody160valid

simplify82.0ms

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

prune28.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 32.5b

localize41.0ms

Local error

Found 4 expressions with local error:

21.7b
(sqrt (fma (* a c) -4 (* b b)))
2.0b
(- (sqrt (fma (* a c) -4 (* b b))) b)
0.4b
(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))

series227.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
76.0ms
(/ (- (sqrt (fma (* a c) -4 (* b b))) b) (* 2 a))
53.0ms
(sqrt (fma (* a c) -4 (* b b)))
53.0ms
(- (sqrt (fma (* a c) -4 (* b b))) b)
44.0ms
(fma (* a c) -4 (* b b))

simplify1.5s

Counts
34 → 79
Calls
34 calls:
Slowest
791.0ms
(- (* (sqrt (fma (* a c) -4 (* b b))) (sqrt (fma (* a c) -4 (* b b)))) (* b b))
116.0ms
(- (pow (sqrt (fma (* a c) -4 (* b b))) 3) (pow b 3))
82.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)))
76.0ms
(- (log (- (sqrt (fma (* a c) -4 (* b b))) b)) (log (* 2 a)))
39.0ms
(- (pow b 2) (* 4 (* a c)))

prune891.0ms

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 17.8b

localize11.0ms

Local error

Found 4 expressions with local error:

21.7b
(sqrt (fma (* a c) -4 (* b b)))
13.5b
(/ (* (* a c) -4) (* (* 2 a) (+ (sqrt (fma (* a c) -4 (* b b))) b)))
1.3b
(+ (sqrt (fma (* a c) -4 (* b b))) b)
0.4b
(fma (* a c) -4 (* b b))

rewrite23.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
14.0ms
(/ (* (* a c) -4) (* (* 2 a) (+ (sqrt (fma (* a c) -4 (* b b))) b)))
7.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))

series320.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
144.0ms
(/ (* (* a c) -4) (* (* 2 a) (+ (sqrt (fma (* a c) -4 (* b b))) b)))
76.0ms
(+ (sqrt (fma (* a c) -4 (* b b))) b)
59.0ms
(sqrt (fma (* a c) -4 (* b b)))
41.0ms
(fma (* a c) -4 (* b b))

simplify2.7s

Counts
31 → 75
Calls
31 calls:
Slowest
644.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))))
577.0ms
(- (log (* (* a c) -4)) (+ (log (* 2 a)) (log (+ (sqrt (fma (* a c) -4 (* b b))) b))))
528.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))))
409.0ms
(- (log (* (* a c) -4)) (log (* (* 2 a) (+ (sqrt (fma (* a c) -4 (* b b))) b))))
234.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: 12.3b

localize12.0ms

Local error

Found 4 expressions with local error:

21.7b
(sqrt (fma (* a c) -4 (* b b)))
1.3b
(+ (sqrt (fma (* a c) -4 (* b b))) b)
0.4b
(fma (* a c) -4 (* b b))
0.2b
(* (* 1/2 c) (/ -4 (+ (sqrt (fma (* a c) -4 (* b b))) b)))

rewrite18.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
8.0ms
(* (* 1/2 c) (/ -4 (+ (sqrt (fma (* a c) -4 (* b b))) b)))
7.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))

series295.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
134.0ms
(* (* 1/2 c) (/ -4 (+ (sqrt (fma (* a c) -4 (* b b))) b)))
73.0ms
(+ (sqrt (fma (* a c) -4 (* b b))) b)
58.0ms
(sqrt (fma (* a c) -4 (* b b)))
30.0ms
(fma (* a c) -4 (* b b))

simplify1.3s

Counts
31 → 75
Calls
31 calls:
Slowest
506.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))))
230.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)))
101.0ms
(+ (log (* 1/2 c)) (log (/ -4 (+ (sqrt (fma (* a c) -4 (* b b))) b))))
85.0ms
(* (* 1/2 c) (/ -4 (+ (sqrt (fma (* a c) -4 (* b b))) b)))
49.0ms
(- (pow b 2) (* 4 (* a c)))

prune878.0ms

Pruning

11 alts after pruning (10 fresh and 1 done)

Merged error: 10.3b

localize14.0ms

Local error

Found 4 expressions with local error:

21.7b
(sqrt (fma (* a c) -4 (* b b)))
1.3b
(+ (sqrt (fma (* a c) -4 (* b b))) b)
0.4b
(fma (* a c) -4 (* b b))
0.1b
(/ (* (* 1/2 c) -4) (+ (sqrt (fma (* a c) -4 (* b b))) b))

rewrite31.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
19.0ms
(/ (* (* 1/2 c) -4) (+ (sqrt (fma (* a c) -4 (* b b))) b))
9.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))

series291.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
117.0ms
(/ (* (* 1/2 c) -4) (+ (sqrt (fma (* a c) -4 (* b b))) b))
66.0ms
(sqrt (fma (* a c) -4 (* b b)))
60.0ms
(+ (sqrt (fma (* a c) -4 (* b b))) b)
47.0ms
(fma (* a c) -4 (* b b))

simplify963.0ms

Counts
35 → 77
Calls
35 calls:
Slowest
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)))
139.0ms
(- (log (* (* 1/2 c) -4)) (log (+ (sqrt (fma (* a c) -4 (* b b))) b)))
97.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)))
68.0ms
(/ (* 1/2 c) (* (cbrt (+ (sqrt (fma (* a c) -4 (* b b))) b)) (cbrt (+ (sqrt (fma (* a c) -4 (* b b))) b))))
45.0ms
(/ (* 1/2 c) (sqrt (+ (sqrt (fma (* a c) -4 (* b b))) b)))

prune907.0ms

Pruning

10 alts after pruning (9 fresh and 1 done)

Merged error: 10.3b

regimes253.0ms

Accuracy

92.9% (1.2b remaining)

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

bsearch255.0ms

end0.0ms

sample4.8s

Algorithm
intervals
Results
1.3s5847×body80valid
1.2s924×body1280valid
1.1s1063×body2560valid
420.0ms2979×body80nan
253.0ms435×body640valid
114.0ms222×body320valid
103.0ms102×body5120valid
39.0ms145×body160valid