Average Error: 33.2 → 8.7
Time: 22.5s
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.8021396801207425 \cdot 10^{+125}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.13066952980576 \cdot 10^{-152}:\\ \;\;\;\;\frac{\sqrt{{b}^{2} - \left(c \cdot a\right) \cdot 4} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 3.0304262084228798 \cdot 10^{+63}:\\ \;\;\;\;\frac{\frac{\left(c \cdot -4\right) \cdot a}{a \cdot 2}}{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \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.2
Target20.7
Herbie8.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 4 regimes
  2. if b < -4.8021396801207425e+125

    1. Initial program 50.9

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

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

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

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

    if -4.8021396801207425e+125 < b < 1.13066952980576e-152

    1. Initial program 10.8

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

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

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

    if 1.13066952980576e-152 < b < 3.0304262084228798e+63

    1. Initial program 37.3

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

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

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

      \[\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. Simplified20.1

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

    if 3.0304262084228798e+63 < b

    1. Initial program 56.5

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.8021396801207425 \cdot 10^{+125}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.13066952980576 \cdot 10^{-152}:\\ \;\;\;\;\frac{\sqrt{{b}^{2} - \left(c \cdot a\right) \cdot 4} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 3.0304262084228798 \cdot 10^{+63}:\\ \;\;\;\;\frac{\frac{\left(c \cdot -4\right) \cdot a}{a \cdot 2}}{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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

sample185.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)

simplify106.0ms

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

prune19.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 35.0b

localize43.0ms

Local error

Found 4 expressions with local error:

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

rewrite51.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
20.0ms
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))
19.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
7.0ms
(- (* b b) (* (* 4 a) c))
4.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series214.0ms

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

simplify2.2s

Counts
32 → 71
Calls
32 calls:
Slowest
443.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
318.0ms
(- (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* b b))
185.0ms
(- (pow (sqrt (- (* b b) (* (* 4 a) c))) 3) (pow b 3))
151.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))
133.0ms
(- b (* 2 (/ (* a c) b)))

prune802.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 5.3b

localize25.0ms

Local error

Found 4 expressions with local error:

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

rewrite41.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
23.0ms
(/ (* (* -4 c) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b)))
11.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
4.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
2.0ms
(- (* b b) (* (* 4 a) c))

series290.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
134.0ms
(/ (* (* -4 c) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* 4 a) c))) b)))
71.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
45.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
40.0ms
(- (* b b) (* (* 4 a) c))

simplify3.6s

Counts
29 → 67
Calls
29 calls:
Slowest
939.0ms
(/ (* (* (* (* -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))))
882.0ms
(/ (* (* (* (* -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))))
354.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
292.0ms
(+ (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (- (* b b) (* (sqrt (- (* b b) (* (* 4 a) c))) b)))
177.0ms
(- (log (* (* -4 c) a)) (+ (log (* 2 a)) (log (+ (sqrt (- (* b b) (* (* 4 a) c))) b))))

prune811.0ms

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 5.2b

localize12.0ms

Local error

Found 4 expressions with local error:

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

rewrite26.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
10.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
9.0ms
(/ (* (* -4 c) a) (* 2 a))
4.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
2.0ms
(- (* b b) (* (* 4 a) c))

series134.0ms

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

simplify2.4s

Counts
24 → 63
Calls
24 calls:
Slowest
707.0ms
(- (log (* (* -4 c) a)) (log (* 2 a)))
409.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
360.0ms
(/ (* (* (* (* -4 c) a) (* (* -4 c) a)) (* (* -4 c) a)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
152.0ms
(- (* 2 b) (* 2 (/ (* a c) b)))
140.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune875.0ms

Pruning

7 alts after pruning (6 fresh and 1 done)

Merged error: 5.2b

localize34.0ms

Local error

Found 4 expressions with local error:

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

rewrite102.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
59.0ms
(/ (- (sqrt (- (pow b 2) (* 4 (* a c)))) b) (* 2 a))
29.0ms
(- (sqrt (- (pow b 2) (* 4 (* a c)))) b)
7.0ms
(- (pow b 2) (* 4 (* a c)))
6.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))

series219.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
72.0ms
(- (sqrt (- (pow b 2) (* 4 (* a c)))) b)
64.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
56.0ms
(/ (- (sqrt (- (pow b 2) (* 4 (* a c)))) b) (* 2 a))
27.0ms
(- (pow b 2) (* 4 (* a c)))

simplify2.3s

Counts
32 → 71
Calls
32 calls:
Slowest
394.0ms
(- (* (sqrt (- (pow b 2) (* 4 (* a c)))) (sqrt (- (pow b 2) (* 4 (* a c))))) (* b b))
326.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
199.0ms
(sqrt (- (* (pow b 2) (pow b 2)) (* (* 4 (* a c)) (* 4 (* a c)))))
167.0ms
(- b (* 2 (/ (* a c) b)))
163.0ms
(- (pow (sqrt (- (pow b 2) (* 4 (* a c)))) 3) (pow b 3))

prune719.0ms

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 5.2b

regimes363.0ms

Accuracy

88.5% (3.0b remaining)

Error of 8.7b against oracle of 5.7b and baseline of 31.9b

bsearch602.0ms

end0.0ms

sample5.3s

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)