Average Error: 33.0 → 6.5
Time: 32.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.878856436009372 \cdot 10^{+97}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -3.033451162286551 \cdot 10^{-263}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b\right) \cdot \frac{1}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.1951800716070265 \cdot 10^{+111}:\\ \;\;\;\;\frac{-2 \cdot c}{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} + b}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original33.0
Target20.4
Herbie6.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 4 regimes
  2. if b < -2.878856436009372e+97

    1. Initial program 43.5

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

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

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

    if -2.878856436009372e+97 < b < -3.033451162286551e-263

    1. Initial program 8.5

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

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

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

    if -3.033451162286551e-263 < b < 1.1951800716070265e+111

    1. Initial program 30.2

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied flip--30.3

      \[\leadsto \frac{\color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b \cdot b}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}}}{2 \cdot a}\]
    5. Applied associate-/l/34.9

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b \cdot b}{\left(2 \cdot a\right) \cdot \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b\right)}}\]
    6. Simplified19.5

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

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

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

    if 1.1951800716070265e+111 < b

    1. Initial program 59.5

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.878856436009372 \cdot 10^{+97}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -3.033451162286551 \cdot 10^{-263}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b\right) \cdot \frac{1}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.1951800716070265 \cdot 10^{+111}:\\ \;\;\;\;\frac{-2 \cdot c}{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} + b}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 1042149663 
(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: 31.1s)Debug log

sample252.0ms

Algorithm
intervals
Results
369×(pre true 80)
181×(body real 80)
88×(body nan 80)
31×(body real 1280)
28×(body real 2560)
22×(body real 640)
13×(body real 320)
(body real 160)
(body real 5120)

simplify116.0ms

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

prune24.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 34.2b

localize60.0ms

Local error

Found 4 expressions with local error:

21.8b
(sqrt (- (* b b) (* (* 4 a) c)))
0.8b
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
0.8b
(- (* b b) (* (* 4 a) c))
0.1b
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))

rewrite88.0ms

Algorithm
rewrite-expression-head
Rules
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
add-log-exp
add-exp-log
add-cbrt-cube
flip--
flip3--
pow1
associate-/l*
sqrt-prod
times-frac
associate-/l/
sqrt-div
sub-neg
div-inv
div-exp
div-sub
diff-log
pow1/2
frac-2neg
associate-/r*
clear-num
rem-sqrt-square
cbrt-undiv
Counts
4 → 59
Calls
4 calls:
Slowest
53.0ms
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))
24.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
5.0ms
(- (* b b) (* (* 4 a) c))
5.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series336.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
115.0ms
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))
90.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
80.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
51.0ms
(- (* b b) (* (* 4 a) c))

simplify3.4s

Counts
32 → 71
Calls
32 calls:
Slowest
572.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
508.0ms
(- (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* b b))
288.0ms
(- (pow (sqrt (- (* b b) (* (* 4 a) c))) 3) (pow b 3))
225.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))
189.0ms
(- b (* 2 (/ (* a c) b)))

prune1.3s

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 5.5b

localize37.0ms

Local error

Found 4 expressions with local error:

21.8b
(sqrt (- (* b b) (* (* 4 a) c)))
18.1b
(/ (* (* -4 c) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b)))
0.8b
(- (* b b) (* (* 4 a) c))
0.4b
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)

rewrite60.0ms

Algorithm
rewrite-expression-head
Rules
add-exp-log
add-cbrt-cube
add-log-exp
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
pow1
sqrt-prod
flip--
flip-+
associate-/r/
associate-*r/
div-exp
sqrt-div
flip3--
flip3-+
cbrt-undiv
associate-/l*
div-inv
cbrt-unprod
prod-exp
diff-log
pow1/2
times-frac
frac-2neg
sub-neg
associate-/r*
clear-num
rem-sqrt-square
+-commutative
Counts
4 → 55
Calls
4 calls:
Slowest
27.0ms
(/ (* (* -4 c) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b)))
21.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
5.0ms
(- (* b b) (* (* 4 a) c))
5.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series443.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
222.0ms
(/ (* (* -4 c) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b)))
88.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
81.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
51.0ms
(- (* b b) (* (* 4 a) c))

simplify5.5s

Counts
29 → 67
Calls
29 calls:
Slowest
1.3s
(/ (* (* (* (* -4 c) a) (* (* -4 c) a)) (* (* -4 c) a)) (* (* (* (* 2 a) (* 2 a)) (* 2 a)) (* (* (+ (sqrt (- (* b b) (* (* 4 a) c))) b) (+ (sqrt (- (* b b) (* (* 4 a) c))) b)) (+ (sqrt (- (* b b) (* (* 4 a) c))) b))))
1.3s
(/ (* (* (* (* -4 c) a) (* (* -4 c) a)) (* (* -4 c) a)) (* (* (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b)) (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b))) (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b))))
569.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
451.0ms
(+ (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (- (* b b) (* (sqrt (- (* b b) (* (* 4 a) c))) b)))
225.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune1.3s

Pruning

6 alts after pruning (6 fresh and 0 done)

Merged error: 5.4b

localize20.0ms

Local error

Found 4 expressions with local error:

21.8b
(sqrt (- (* b b) (* (* 4 a) c)))
13.0b
(/ (* (* -4 c) a) (* 2 a))
0.8b
(- (* b b) (* (* 4 a) c))
0.4b
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)

rewrite58.0ms

Algorithm
rewrite-expression-head
Rules
add-log-exp
add-exp-log
add-cbrt-cube
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
pow1
sqrt-prod
flip--
sqrt-div
flip3--
associate-/l*
div-inv
flip-+
div-exp
diff-log
pow1/2
times-frac
flip3-+
frac-2neg
sub-neg
associate-/r*
clear-num
rem-sqrt-square
+-commutative
cbrt-undiv
Counts
4 → 51
Calls
4 calls:
Slowest
22.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
14.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
13.0ms
(/ (* (* -4 c) a) (* 2 a))
6.0ms
(- (* b b) (* (* 4 a) c))

series239.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
92.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
86.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
51.0ms
(- (* b b) (* (* 4 a) c))
10.0ms
(/ (* (* -4 c) a) (* 2 a))

simplify3.4s

Counts
24 → 63
Calls
24 calls:
Slowest
938.0ms
(- (log (* (* -4 c) a)) (log (* 2 a)))
595.0ms
(/ (* (* (* (* -4 c) a) (* (* -4 c) a)) (* (* -4 c) a)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
570.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
225.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))
200.0ms
(- (* 2 b) (* 2 (/ (* a c) b)))

prune1.2s

Pruning

6 alts after pruning (5 fresh and 1 done)

Merged error: 5.4b

localize19.0ms

Local error

Found 4 expressions with local error:

21.8b
(sqrt (- (* b b) (* (* 4 a) c)))
0.8b
(- (* b b) (* (* 4 a) c))
0.4b
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
0.1b
(/ (* -2 c) (+ (sqrt (- (* b b) (* (* 4 a) c))) b))

rewrite54.0ms

Algorithm
rewrite-expression-head
Rules
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
add-log-exp
add-exp-log
add-cbrt-cube
pow1
sqrt-prod
times-frac
associate-/r*
flip--
flip-+
associate-/r/
sqrt-div
flip3--
flip3-+
associate-/l*
div-inv
div-exp
diff-log
pow1/2
frac-2neg
sub-neg
clear-num
rem-sqrt-square
+-commutative
cbrt-undiv
Counts
4 → 57
Calls
4 calls:
Slowest
26.0ms
(/ (* -2 c) (+ (sqrt (- (* b b) (* (* 4 a) c))) b))
18.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
5.0ms
(- (* b b) (* (* 4 a) c))
5.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series430.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
209.0ms
(/ (* -2 c) (+ (sqrt (- (* b b) (* (* 4 a) c))) b))
87.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
80.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
53.0ms
(- (* b b) (* (* 4 a) c))

simplify3.1s

Counts
32 → 69
Calls
32 calls:
Slowest
572.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
442.0ms
(+ (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (- (* b b) (* (sqrt (- (* b b) (* (* 4 a) c))) b)))
222.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))
197.0ms
(- (* 2 b) (* 2 (/ (* a c) b)))
192.0ms
(- b (* 2 (/ (* a c) b)))

prune1.1s

Pruning

6 alts after pruning (4 fresh and 2 done)

Merged error: 5.4b

regimes351.0ms

Accuracy

95.6% (1.0b remaining)

Error of 6.5b against oracle of 5.5b and baseline of 29.2b

bsearch771.0ms

end0.0ms

sample7.5s

Algorithm
intervals
Results
11586×(pre true 80)
5844×(body real 80)
2900×(body nan 80)
1077×(body real 2560)
858×(body real 1280)
449×(body real 640)
227×(body real 320)
135×(body real 160)
96×(body real 5120)