Average Error: 32.8 → 6.5
Time: 42.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 -5.248460788560141 \cdot 10^{+152}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -4.025787927750883 \cdot 10^{-265}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b\right) \cdot \frac{1}{a \cdot 2}\\ \mathbf{elif}\;b \le 6.763064983187116 \cdot 10^{+126}:\\ \;\;\;\;\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

Original32.8
Target20.2
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 < -5.248460788560141e+152

    1. Initial program 60.4

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

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

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

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

    if -5.248460788560141e+152 < b < -4.025787927750883e-265

    1. Initial program 7.7

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

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

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

    if -4.025787927750883e-265 < b < 6.763064983187116e+126

    1. Initial program 31.4

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

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

      \[\leadsto \color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \frac{1}{2 \cdot a}}\]
    5. Using strategy rm
    6. Applied flip--31.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}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}} \cdot \frac{1}{2 \cdot a}\]
    7. Applied associate-*l/31.6

      \[\leadsto \color{blue}{\frac{\left(\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\right) \cdot \frac{1}{2 \cdot a}}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}}\]
    8. Simplified15.0

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

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

    if 6.763064983187116e+126 < b

    1. Initial program 60.0

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

      \[\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-inv60.0

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    6. Simplified1.9

      \[\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 -5.248460788560141 \cdot 10^{+152}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -4.025787927750883 \cdot 10^{-265}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b\right) \cdot \frac{1}{a \cdot 2}\\ \mathbf{elif}\;b \le 6.763064983187116 \cdot 10^{+126}:\\ \;\;\;\;\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 2019018 
(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: 41.3s)Debug log

sample148.0ms

Algorithm
intervals
Results
29.0ms187×body80valid
28.0ms30×body2560valid
25.0ms32×body1280valid
15.0ms104×body80nan
10.0ms16×body640valid
7.0msbody5120valid
4.0msbody320valid

simplify92.0ms

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

prune20.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 31.3b

localize28.0ms

Local error

Found 4 expressions with local error:

19.9b
(sqrt (- (* b b) (* (* 4 a) c)))
0.1b
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))
0.1b
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
0.0b
(- (* b b) (* (* 4 a) c))

rewrite69.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
41.0ms
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))
20.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
4.0ms
(- (* b b) (* (* 4 a) c))
2.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series246.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
76.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
75.0ms
(/ (- (sqrt (- (* b b) (* (* 4 a) c))) b) (* 2 a))
50.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
45.0ms
(- (* b b) (* (* 4 a) c))

simplify2.1s

Counts
32 → 71
Calls
32 calls:
Slowest
414.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
364.0ms
(- (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* b b))
142.0ms
(- (pow (sqrt (- (* b b) (* (* 4 a) c))) 3) (pow b 3))
115.0ms
(- (log (- (sqrt (- (* b b) (* (* 4 a) c))) b)) (log (* 2 a)))
113.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune852.0ms

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 6.2b

localize15.0ms

Local error

Found 4 expressions with local error:

19.9b
(sqrt (- (* b b) (* (* 4 a) c)))
0.1b
(/ (+ (sqrt (- (* b b) (* (* 4 a) c))) (- b)) (* 2 a))
0.1b
(+ (sqrt (- (* b b) (* (* 4 a) c))) (- b))
0.0b
(- (* b b) (* (* 4 a) c))

rewrite79.0ms

Algorithm
rewrite-expression-head
Rules
13×*-un-lft-identity
add-log-exp
add-sqr-sqrt
add-cube-cbrt
add-exp-log
add-cbrt-cube
associate-/l*
times-frac
pow1
distribute-lft-out
sqrt-prod
div-sub
associate-/l/
flip--
flip-+
unsub-neg
sqrt-div
flip3--
flip3-+
associate-+r-
neg-sub0
div-inv
div-exp
diff-log
pow1/2
frac-2neg
sub-neg
sum-log
associate-/r*
clear-num
rem-sqrt-square
+-commutative
cbrt-undiv
Counts
4 → 67
Calls
4 calls:
Slowest
48.0ms
(/ (+ (sqrt (- (* b b) (* (* 4 a) c))) (- b)) (* 2 a))
21.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) (- b))
4.0ms
(- (* b b) (* (* 4 a) c))
4.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series211.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
66.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
64.0ms
(/ (+ (sqrt (- (* b b) (* (* 4 a) c))) (- b)) (* 2 a))
54.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) (- b))
26.0ms
(- (* b b) (* (* 4 a) c))

simplify2.9s

Counts
38 → 79
Calls
38 calls:
Slowest
622.0ms
(- (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* (- b) (- b)))
419.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
298.0ms
(+ (pow (sqrt (- (* b b) (* (* 4 a) c))) 3) (pow (- b) 3))
182.0ms
(/ (* (* (+ (sqrt (- (* b b) (* (* 4 a) c))) (- b)) (+ (sqrt (- (* b b) (* (* 4 a) c))) (- b))) (+ (sqrt (- (* b b) (* (* 4 a) c))) (- b))) (* (* (* 2 a) (* 2 a)) (* 2 a)))
140.0ms
(sqrt (- (* (* b b) (* b b)) (* (* (* 4 a) c) (* (* 4 a) c))))

prune901.0ms

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 6.2b

localize6.0ms

Local error

Found 4 expressions with local error:

19.9b
(sqrt (- (* b b) (* (* 4 a) c)))
0.2b
(* (- (sqrt (- (* b b) (* (* 4 a) c))) b) (/ 1 (* 2 a)))
0.1b
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
0.0b
(- (* b b) (* (* 4 a) c))

rewrite71.0ms

Algorithm
rewrite-expression-head
Rules
add-exp-log
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
add-log-exp
add-cbrt-cube
pow1
flip--
flip3--
associate-*r*
sqrt-prod
associate-*l*
prod-exp
associate-*l/
sqrt-div
sub-neg
frac-times
div-inv
cbrt-unprod
*-commutative
un-div-inv
associate-*r/
pow-prod-down
diff-log
pow1/2
rec-exp
rem-sqrt-square
Counts
4 → 62
Calls
4 calls:
Slowest
41.0ms
(* (- (sqrt (- (* b b) (* (* 4 a) c))) b) (/ 1 (* 2 a)))
24.0ms
(- (sqrt (- (* b b) (* (* 4 a) c))) b)
3.0ms
(- (* b b) (* (* 4 a) c))
2.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series213.0ms

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

simplify3.0s

Counts
37 → 74
Calls
37 calls:
Slowest
496.0ms
(* (- (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* b b)) 1)
420.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* 4 a) c) 3)))
203.0ms
(* (- (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (* b b)) (/ 1 (* 2 a)))
192.0ms
(* (- (sqrt (- (* b b) (* (* 4 a) c))) b) (/ 1 (* 2 a)))
186.0ms
(* (+ (* (sqrt (- (* b b) (* (* 4 a) c))) (sqrt (- (* b b) (* (* 4 a) c)))) (+ (* b b) (* (sqrt (- (* b b) (* (* 4 a) c))) b))) (* 2 a))

prune814.0ms

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 6.2b

localize30.0ms

Local error

Found 4 expressions with local error:

19.9b
(sqrt (- (* b b) (* (* 4 a) c)))
14.6b
(/ (+ (* -4 (* a c)) 0) (/ a 1/2))
1.1b
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
0.1b
(/ (/ (+ (* -4 (* a c)) 0) (/ a 1/2)) (+ (sqrt (- (* b b) (* (* 4 a) c))) b))

rewrite57.0ms

Algorithm
rewrite-expression-head
Rules
111×times-frac
65×add-sqr-sqrt
64×add-cube-cbrt
64×*-un-lft-identity
22×div-inv
20×associate-/l*
11×add-exp-log
11×add-cbrt-cube
associate-/r/
associate-/r*
add-log-exp
div-exp
cbrt-undiv
pow1
associate-/l/
flip-+
sqrt-prod
flip3-+
sqrt-div
frac-2neg
clear-num
flip--
pow1/2
flip3--
rem-sqrt-square
+-commutative
Counts
4 → 146
Calls
4 calls:
Slowest
17.0ms
(/ (/ (+ (* -4 (* a c)) 0) (/ a 1/2)) (+ (sqrt (- (* b b) (* (* 4 a) c))) b))
17.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
13.0ms
(/ (+ (* -4 (* a c)) 0) (/ a 1/2))
7.0ms
(sqrt (- (* b b) (* (* 4 a) c)))

series249.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
127.0ms
(/ (/ (+ (* -4 (* a c)) 0) (/ a 1/2)) (+ (sqrt (- (* b b) (* (* 4 a) c))) b))
66.0ms
(+ (sqrt (- (* b b) (* (* 4 a) c))) b)
49.0ms
(sqrt (- (* b b) (* (* 4 a) c)))
6.0ms
(/ (+ (* -4 (* a c)) 0) (/ a 1/2))

simplify22.5s

Counts
180 → 158
Calls
180 calls:
Slowest
922.0ms
(/ (+ (* -4 (* a c)) 0) (/ a 1/2))
892.0ms
(/ (* (cbrt (/ (+ (* -4 (* a c)) 0) (/ a 1/2))) (cbrt (/ (+ (* -4 (* a c)) 0) (/ a 1/2)))) 1)
800.0ms
(/ (sqrt (/ (+ (* -4 (* a c)) 0) (/ a 1/2))) 1)
754.0ms
(* (cbrt (/ (+ (* -4 (* a c)) 0) (/ a 1/2))) (cbrt (/ (+ (* -4 (* a c)) 0) (/ a 1/2))))
702.0ms
(/ (/ (+ (* -4 (* a c)) 0) (/ a 1/2)) (cbrt (+ (sqrt (- (* b b) (* (* 4 a) c))) b)))

prune1.6s

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 6.2b

regimes265.0ms

Accuracy

96.3% (0.9b remaining)

Error of 6.5b against oracle of 5.6b and baseline of 28.9b

bsearch403.0ms

end0.0ms

sample4.4s

Algorithm
intervals
Results
1.5s5918×body80valid
1.1s1103×body2560valid
721.0ms862×body1280valid
389.0ms2797×body80nan
283.0ms474×body640valid
118.0ms114×body5120valid
90.0ms221×body320valid
30.0ms108×body160valid