Average Error: 33.5 → 10.4
Time: 22.6s
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.3604286795685533 \cdot 10^{-29}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 3.328175344273382 \cdot 10^{+63}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \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.5
Target20.6
Herbie10.4
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\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 < -2.3604286795685533e-29

    1. Initial program 54.6

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around -inf 54.6

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

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

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

    if -2.3604286795685533e-29 < b < 3.328175344273382e+63

    1. Initial program 15.3

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around -inf 15.3

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

    if 3.328175344273382e+63 < b

    1. Initial program 37.3

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around inf 5.0

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

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

Reproduce

herbie shell --seed 2019016 
(FPCore (a b c)
  :name "quadm (p42, negative)"

  :herbie-target
  (if (< b 0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))

Details

Time bar (total: 21.4s)Debug log

sample174.0ms

Algorithm
intervals
Results
368×(pre true 80)
182×(body real 80)
91×(body nan 80)
35×(body real 1280)
32×(body real 2560)
13×(body real 640)
(body real 320)
(body real 160)
(body real 5120)

simplify113.0ms

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

prune7.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 35.2b

localize24.0ms

Local error

Found 4 expressions with local error:

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

rewrite32.0ms

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

series236.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
76.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
69.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
65.0ms
(sqrt (- (* b b) (* 4 (* a c))))
27.0ms
(- (* b b) (* 4 (* a c)))

simplify2.6s

Counts
46 → 82
Calls
46 calls:
Slowest
319.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
274.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))))
199.0ms
(- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3))
172.0ms
(sqrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))
129.0ms
(- b (* 2 (/ (* a c) b)))

prune901.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 4.9b

localize14.0ms

Local error

Found 4 expressions with local error:

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

rewrite69.0ms

Algorithm
rewrite-expression-head
Rules
20×add-sqr-sqrt
13×*-un-lft-identity
add-log-exp
add-cube-cbrt
difference-of-squares
associate-/l*
sqrt-prod
add-exp-log
add-cbrt-cube
times-frac
flip--
flip3--
pow1
distribute-lft-out--
associate-/l/
diff-log
sqrt-div
sub-neg
div-inv
div-exp
div-sub
pow1/2
frac-2neg
associate-/r*
clear-num
rem-sqrt-square
cbrt-undiv
neg-sub0
associate--l-
Counts
4 → 70
Calls
4 calls:
Slowest
39.0ms
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))
18.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
7.0ms
(- (pow b 2) (* 4 (* a c)))
4.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))

series190.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
58.0ms
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))
54.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
46.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
31.0ms
(- (pow b 2) (* 4 (* a c)))

simplify3.1s

Counts
46 → 82
Calls
46 calls:
Slowest
973.0ms
(- (* (- b) (- b)) (* (sqrt (- (pow b 2) (* 4 (* a c)))) (sqrt (- (pow b 2) (* 4 (* a c))))))
294.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
280.0ms
(- (pow (- b) 3) (pow (sqrt (- (pow b 2) (* 4 (* a c)))) 3))
165.0ms
(sqrt (- (* (pow b 2) (pow b 2)) (* (* 4 (* a c)) (* 4 (* a c)))))
98.0ms
(/ (* (* (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))) (- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))) (* (* (* 2 a) (* 2 a)) (* 2 a)))

prune696.0ms

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 4.9b

localize6.0ms

Local error

Found 4 expressions with local error:

24.0b
(sqrt (- (pow b 2) (* 4 (* a c))))
1.2b
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
1.2b
(- (pow b 2) (* 4 (* a c)))
0.2b
(/ 1 (/ (* 2 a) (- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))))

rewrite22.0ms

Algorithm
rewrite-expression-head
Rules
16×add-sqr-sqrt
12×associate-/r*
11×*-un-lft-identity
add-log-exp
add-cube-cbrt
add-exp-log
times-frac
sqrt-prod
pow1
difference-of-squares
flip--
add-cbrt-cube
flip3--
associate-/r/
distribute-lft-out--
div-inv
diff-log
sqrt-div
sub-neg
rec-exp
inv-pow
pow-flip
div-exp
pow1/2
frac-2neg
clear-num
rem-sqrt-square
neg-sub0
associate--l-
Counts
4 → 69
Calls
4 calls:
Slowest
7.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
7.0ms
(/ 1 (/ (* 2 a) (- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))))
3.0ms
(- (pow b 2) (* 4 (* a c)))
3.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))

series182.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
64.0ms
(/ 1 (/ (* 2 a) (- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))))
52.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
40.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
25.0ms
(- (pow b 2) (* 4 (* a c)))

simplify2.0s

Counts
39 → 81
Calls
39 calls:
Slowest
281.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
223.0ms
(+ (* (- b) (- b)) (+ (* (sqrt (- (pow b 2) (* 4 (* a c)))) (sqrt (- (pow b 2) (* 4 (* a c))))) (* (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))))
151.0ms
(sqrt (- (* (pow b 2) (pow b 2)) (* (* 4 (* a c)) (* 4 (* a c)))))
95.0ms
(/ (* 2 a) (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))))
93.0ms
(- b (* 2 (/ (* a c) b)))

prune1.0s

Pruning

10 alts after pruning (8 fresh and 2 done)

Merged error: 4.9b

localize21.0ms

Local error

Found 4 expressions with local error:

24.0b
(sqrt (- (pow b 2) (* 4 (* a c))))
24.0b
(sqrt (- (pow b 2) (* 4 (* a c))))
24.0b
(sqrt (- (pow b 2) (* 4 (* a c))))
1.2b
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))

rewrite17.0ms

Algorithm
rewrite-expression-head
Rules
14×add-sqr-sqrt
10×sqrt-prod
*-un-lft-identity
add-cube-cbrt
add-log-exp
sqrt-div
flip--
add-exp-log
add-cbrt-cube
flip3--
pow1
pow1/2
rem-sqrt-square
difference-of-squares
distribute-lft-out--
diff-log
sub-neg
neg-sub0
associate--l-
Counts
4 → 58
Calls
4 calls:
Slowest
7.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
3.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
3.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
3.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))

series224.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
72.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
54.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
53.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
45.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))

simplify2.8s

Counts
36 → 70
Calls
36 calls:
Slowest
367.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
342.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
341.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
168.0ms
(sqrt (- (* (pow b 2) (pow b 2)) (* (* 4 (* a c)) (* 4 (* a c)))))
168.0ms
(sqrt (- (* (pow b 2) (pow b 2)) (* (* 4 (* a c)) (* 4 (* a c)))))

prune1.2s

Pruning

10 alts after pruning (7 fresh and 3 done)

Merged error: 4.9b

regimes443.0ms

Accuracy

83.2% (4.7b remaining)

Error of 10.4b against oracle of 5.7b and baseline of 33.5b

bsearch216.0ms

end0.0ms

sample5.0s

Algorithm
intervals
Results
11455×(pre true 80)
5803×(body real 80)
2738×(body nan 80)
1107×(body real 2560)
947×(body real 1280)
433×(body real 640)
217×(body real 320)
109×(body real 5120)
101×(body real 160)