Average Error: 33.4 → 8.7
Time: 17.9s
Precision: 64
Internal Precision: 128
\[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
\[\begin{array}{l} \mathbf{if}\;b_2 \le -1.4610610347609648 \cdot 10^{+33}:\\ \;\;\;\;(-2 \cdot \left(\frac{b_2}{a}\right) + \left(\frac{c}{\frac{b_2}{\frac{1}{2}}}\right))_*\\ \mathbf{elif}\;b_2 \le -1.6380403487825836 \cdot 10^{-118}:\\ \;\;\;\;\frac{\frac{{\left(\sqrt{b_2 \cdot b_2 - c \cdot a}\right)}^{3} - {b_2}^{3}}{\sqrt{b_2 \cdot b_2 - c \cdot a} \cdot \sqrt{b_2 \cdot b_2 - c \cdot a} + \left(b_2 \cdot b_2 + b_2 \cdot \sqrt{b_2 \cdot b_2 - c \cdot a}\right)}}{a}\\ \mathbf{elif}\;b_2 \le 1.501809486178084 \cdot 10^{+23}:\\ \;\;\;\;\frac{-c}{\sqrt{b_2 \cdot b_2 - c \cdot a} + b_2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{c}{b_2}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b_2

Bits error versus c

Derivation

  1. Split input into 4 regimes
  2. if b_2 < -1.4610610347609648e+33

    1. Initial program 34.3

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Simplified34.3

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    3. Taylor expanded around -inf 5.8

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}}\]
    4. Simplified5.8

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

    if -1.4610610347609648e+33 < b_2 < -1.6380403487825836e-118

    1. Initial program 5.9

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Simplified5.9

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    3. Using strategy rm
    4. Applied flip3--11.9

      \[\leadsto \frac{\color{blue}{\frac{{\left(\sqrt{b_2 \cdot b_2 - a \cdot c}\right)}^{3} - {b_2}^{3}}{\sqrt{b_2 \cdot b_2 - a \cdot c} \cdot \sqrt{b_2 \cdot b_2 - a \cdot c} + \left(b_2 \cdot b_2 + \sqrt{b_2 \cdot b_2 - a \cdot c} \cdot b_2\right)}}}{a}\]

    if -1.6380403487825836e-118 < b_2 < 1.501809486178084e+23

    1. Initial program 23.0

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Simplified23.0

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    3. Using strategy rm
    4. Applied flip--24.7

      \[\leadsto \frac{\color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} \cdot \sqrt{b_2 \cdot b_2 - a \cdot c} - b_2 \cdot b_2}{\sqrt{b_2 \cdot b_2 - a \cdot c} + b_2}}}{a}\]
    5. Applied associate-/l/30.9

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} \cdot \sqrt{b_2 \cdot b_2 - a \cdot c} - b_2 \cdot b_2}{a \cdot \left(\sqrt{b_2 \cdot b_2 - a \cdot c} + b_2\right)}}\]
    6. Simplified23.6

      \[\leadsto \frac{\color{blue}{-a \cdot c}}{a \cdot \left(\sqrt{b_2 \cdot b_2 - a \cdot c} + b_2\right)}\]
    7. Using strategy rm
    8. Applied distribute-frac-neg23.6

      \[\leadsto \color{blue}{-\frac{a \cdot c}{a \cdot \left(\sqrt{b_2 \cdot b_2 - a \cdot c} + b_2\right)}}\]
    9. Simplified12.9

      \[\leadsto -\color{blue}{\frac{c}{b_2 + \sqrt{b_2 \cdot b_2 - a \cdot c}}}\]

    if 1.501809486178084e+23 < b_2

    1. Initial program 55.5

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

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    3. Taylor expanded around inf 4.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \le -1.4610610347609648 \cdot 10^{+33}:\\ \;\;\;\;(-2 \cdot \left(\frac{b_2}{a}\right) + \left(\frac{c}{\frac{b_2}{\frac{1}{2}}}\right))_*\\ \mathbf{elif}\;b_2 \le -1.6380403487825836 \cdot 10^{-118}:\\ \;\;\;\;\frac{\frac{{\left(\sqrt{b_2 \cdot b_2 - c \cdot a}\right)}^{3} - {b_2}^{3}}{\sqrt{b_2 \cdot b_2 - c \cdot a} \cdot \sqrt{b_2 \cdot b_2 - c \cdot a} + \left(b_2 \cdot b_2 + b_2 \cdot \sqrt{b_2 \cdot b_2 - c \cdot a}\right)}}{a}\\ \mathbf{elif}\;b_2 \le 1.501809486178084 \cdot 10^{+23}:\\ \;\;\;\;\frac{-c}{\sqrt{b_2 \cdot b_2 - c \cdot a} + b_2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{c}{b_2}\\ \end{array}\]

Reproduce

herbie shell --seed 2019022 +o rules:numerics
(FPCore (a b_2 c)
  :name "quad2p (problem 3.2.1, positive)"
  (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))

Details

Time bar (total: 16.7s)Debug log

sample173.0ms

Algorithm
intervals
Results
60.0ms40×body2560valid
15.0ms185×body80valid
10.0ms27×body1280valid
7.0ms97×body80nan
4.0ms15×body640valid
2.0msbody5120valid
2.0msbody320valid
1.0msbody160valid

simplify52.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
51.0ms
(/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a)

prune21.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 32.5b

localize19.0ms

Local error

Found 4 expressions with local error:

21.7b
(sqrt (- (* b_2 b_2) (* a c)))
2.1b
(- (sqrt (- (* b_2 b_2) (* a c))) b_2)
0.4b
(- (* b_2 b_2) (* a c))
0.1b
(/ (- (sqrt (- (* b_2 b_2) (* a c))) b_2) a)

rewrite77.0ms

Algorithm
rewrite-expression-head
Rules
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
fma-neg
add-log-exp
sqrt-prod
flip--
log1p-expm1-u
add-exp-log
add-cbrt-cube
flip3--
pow1
expm1-log1p-u
associate-/l*
associate-/l/
sqrt-div
sub-neg
div-inv
prod-diff
div-sub
diff-log
pow1/2
frac-2neg
clear-num
rem-sqrt-square
Counts
4 → 69
Calls
4 calls:
Slowest
40.0ms
(/ (- (sqrt (- (* b_2 b_2) (* a c))) b_2) a)
24.0ms
(- (sqrt (- (* b_2 b_2) (* a c))) b_2)
7.0ms
(sqrt (- (* b_2 b_2) (* a c)))
4.0ms
(- (* b_2 b_2) (* a c))

series228.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
69.0ms
(/ (- (sqrt (- (* b_2 b_2) (* a c))) b_2) a)
68.0ms
(- (sqrt (- (* b_2 b_2) (* a c))) b_2)
56.0ms
(sqrt (- (* b_2 b_2) (* a c)))
35.0ms
(- (* b_2 b_2) (* a c))

simplify2.1s

Counts
31 → 81
Calls
31 calls:
Slowest
460.0ms
(sqrt (- (* (* b_2 b_2) (* b_2 b_2)) (* (* a c) (* a c))))
395.0ms
(- (* (sqrt (- (* b_2 b_2) (* a c))) (sqrt (- (* b_2 b_2) (* a c)))) (* b_2 b_2))
374.0ms
(sqrt (- (pow (* b_2 b_2) 3) (pow (* a c) 3)))
146.0ms
(- b_2 (* 1/2 (/ (* a c) b_2)))
133.0ms
(- (pow (sqrt (- (* b_2 b_2) (* a c))) 3) (pow b_2 3))

prune848.0ms

Pruning

13 alts after pruning (13 fresh and 0 done)

Merged error: 5.5b

localize10.0ms

Local error

Found 4 expressions with local error:

21.7b
(sqrt (- (* b_2 b_2) (* a c)))
13.5b
(/ (- (* a c)) (* a (+ (sqrt (- (* b_2 b_2) (* a c))) b_2)))
1.4b
(+ (sqrt (- (* b_2 b_2) (* a c))) b_2)
0.4b
(- (* b_2 b_2) (* a c))

rewrite24.0ms

Algorithm
rewrite-expression-head
Rules
10×add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
add-log-exp
associate-/l*
sqrt-prod
add-exp-log
add-cbrt-cube
times-frac
fma-def
log1p-expm1-u
pow1
expm1-log1p-u
flip--
flip-+
associate-/r/
associate-*r/
sqrt-div
flip3--
flip3-+
distribute-rgt-neg-in
neg-mul-1
distribute-lft-neg-in
div-inv
distribute-frac-neg
prod-diff
div-exp
div-sub
diff-log
fma-neg
pow1/2
frac-2neg
sub-neg
associate-/r*
clear-num
rem-sqrt-square
+-commutative
cbrt-undiv
neg-sub0
Counts
4 → 81
Calls
4 calls:
Slowest
9.0ms
(/ (- (* a c)) (* a (+ (sqrt (- (* b_2 b_2) (* a c))) b_2)))
9.0ms
(+ (sqrt (- (* b_2 b_2) (* a c))) b_2)
3.0ms
(sqrt (- (* b_2 b_2) (* a c)))
2.0ms
(- (* b_2 b_2) (* a c))

series247.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
132.0ms
(/ (- (* a c)) (* a (+ (sqrt (- (* b_2 b_2) (* a c))) b_2)))
49.0ms
(+ (sqrt (- (* b_2 b_2) (* a c))) b_2)
45.0ms
(sqrt (- (* b_2 b_2) (* a c)))
20.0ms
(- (* b_2 b_2) (* a c))

simplify2.6s

Counts
48 → 93
Calls
48 calls:
Slowest
417.0ms
(/ (* (* (- (* a c)) (- (* a c))) (- (* a c))) (* (* (* a (+ (sqrt (- (* b_2 b_2) (* a c))) b_2)) (* a (+ (sqrt (- (* b_2 b_2) (* a c))) b_2))) (* a (+ (sqrt (- (* b_2 b_2) (* a c))) b_2))))
391.0ms
(sqrt (- (* (* b_2 b_2) (* b_2 b_2)) (* (* a c) (* a c))))
354.0ms
(+ (* (sqrt (- (* b_2 b_2) (* a c))) (sqrt (- (* b_2 b_2) (* a c)))) (- (* b_2 b_2) (* (sqrt (- (* b_2 b_2) (* a c))) b_2)))
316.0ms
(sqrt (- (pow (* b_2 b_2) 3) (pow (* a c) 3)))
220.0ms
(/ (* a c) (* a (+ (sqrt (- (* b_2 b_2) (* a c))) b_2)))

prune875.0ms

Pruning

12 alts after pruning (11 fresh and 1 done)

Merged error: 5.5b

localize8.0ms

Local error

Found 4 expressions with local error:

21.7b
(sqrt (- (* b_2 b_2) (* a c)))
1.4b
(+ b_2 (sqrt (- (* b_2 b_2) (* a c))))
0.4b
(- (* b_2 b_2) (* a c))
0.1b
(/ c (+ b_2 (sqrt (- (* b_2 b_2) (* a c)))))

rewrite9.0ms

Algorithm
rewrite-expression-head
Rules
add-sqr-sqrt
add-log-exp
add-cube-cbrt
*-un-lft-identity
log1p-expm1-u
add-exp-log
add-cbrt-cube
pow1
expm1-log1p-u
sqrt-prod
associate-/r*
flip--
flip-+
associate-/r/
sqrt-div
flip3--
flip3-+
div-inv
prod-diff
diff-log
fma-neg
pow1/2
frac-2neg
sub-neg
clear-num
rem-sqrt-square
+-commutative
Counts
4 → 61
Calls
4 calls:
Slowest
3.0ms
(sqrt (- (* b_2 b_2) (* a c)))
2.0ms
(- (* b_2 b_2) (* a c))
2.0ms
(/ c (+ b_2 (sqrt (- (* b_2 b_2) (* a c)))))
2.0ms
(+ b_2 (sqrt (- (* b_2 b_2) (* a c))))

series241.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
120.0ms
(/ c (+ b_2 (sqrt (- (* b_2 b_2) (* a c)))))
53.0ms
(+ b_2 (sqrt (- (* b_2 b_2) (* a c))))
41.0ms
(sqrt (- (* b_2 b_2) (* a c)))
28.0ms
(- (* b_2 b_2) (* a c))

simplify1.5s

Counts
26 → 73
Calls
26 calls:
Slowest
440.0ms
(sqrt (- (* (* b_2 b_2) (* b_2 b_2)) (* (* a c) (* a c))))
338.0ms
(sqrt (- (pow (* b_2 b_2) 3) (pow (* a c) 3)))
249.0ms
(+ (* b_2 b_2) (- (* (sqrt (- (* b_2 b_2) (* a c))) (sqrt (- (* b_2 b_2) (* a c)))) (* b_2 (sqrt (- (* b_2 b_2) (* a c))))))
116.0ms
(- b_2 (* 1/2 (/ (* a c) b_2)))
105.0ms
(- (* 2 b_2) (* 1/2 (/ (* a c) b_2)))

prune811.0ms

Pruning

10 alts after pruning (8 fresh and 2 done)

Merged error: 5.5b

localize16.0ms

Local error

Found 4 expressions with local error:

21.7b
(sqrt (- (* b_2 b_2) (* a c)))
1.4b
(+ b_2 (sqrt (- (* b_2 b_2) (* a c))))
0.4b
(- (* b_2 b_2) (* a c))
0.2b
(* c (/ 1 (+ b_2 (sqrt (- (* b_2 b_2) (* a c))))))

rewrite12.0ms

Algorithm
rewrite-expression-head
Rules
add-sqr-sqrt
add-log-exp
add-cube-cbrt
associate-*r*
*-un-lft-identity
log1p-expm1-u
add-exp-log
add-cbrt-cube
pow1
expm1-log1p-u
sqrt-prod
flip--
flip-+
associate-/r/
sqrt-div
flip3--
flip3-+
div-inv
*-commutative
un-div-inv
associate-*r/
prod-diff
diff-log
fma-neg
pow1/2
sub-neg
rem-sqrt-square
+-commutative
Counts
4 → 62
Calls
4 calls:
Slowest
5.0ms
(sqrt (- (* b_2 b_2) (* a c)))
3.0ms
(- (* b_2 b_2) (* a c))
3.0ms
(+ b_2 (sqrt (- (* b_2 b_2) (* a c))))
1.0ms
(* c (/ 1 (+ b_2 (sqrt (- (* b_2 b_2) (* a c))))))

series279.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
135.0ms
(* c (/ 1 (+ b_2 (sqrt (- (* b_2 b_2) (* a c))))))
68.0ms
(+ b_2 (sqrt (- (* b_2 b_2) (* a c))))
44.0ms
(sqrt (- (* b_2 b_2) (* a c)))
32.0ms
(- (* b_2 b_2) (* a c))

simplify1.6s

Counts
29 → 74
Calls
29 calls:
Slowest
428.0ms
(sqrt (- (* (* b_2 b_2) (* b_2 b_2)) (* (* a c) (* a c))))
379.0ms
(sqrt (- (pow (* b_2 b_2) 3) (pow (* a c) 3)))
249.0ms
(+ (* b_2 b_2) (- (* (sqrt (- (* b_2 b_2) (* a c))) (sqrt (- (* b_2 b_2) (* a c)))) (* b_2 (sqrt (- (* b_2 b_2) (* a c))))))
109.0ms
(- (* 2 b_2) (* 1/2 (/ (* a c) b_2)))
103.0ms
(- b_2 (* 1/2 (/ (* a c) b_2)))

prune656.0ms

Pruning

10 alts after pruning (7 fresh and 3 done)

Merged error: 5.5b

regimes379.0ms

Accuracy

86.5% (3.2b remaining)

Error of 8.7b against oracle of 5.5b and baseline of 29.3b

bsearch195.0ms

end0.0ms

sample3.7s

Algorithm
intervals
Results
787.0ms5850×body80valid
742.0ms1064×body2560valid
590.0ms922×body1280valid
513.0ms102×body5120valid
377.0ms2973×body80nan
231.0ms436×body640valid
108.0ms226×body320valid
95.0ms140×body160valid