ux01 <- function(x) ifelse(x<35, 0.1, ifelse(x<45, 0.05, ifelse(x<60, 0.02, 0)))
ux02 <- function(x) 0.001
ux03 <- function(x) ifelse(x<60, 0, ifelse(x<65, 0.1, 0))
ux04 <- function(x,A=0.00022,B=2.7e-06,c=1.124) A + B*c^(x)

tpx00 <- function(t,x,A=0.00022,B=2.7e-06,c=1.124,e=0.0000000001, int=function(f,a,b)integrate(f,a,b)$value) { # t > 0
  g <- function(t) ifelse(x<0, 0, ifelse(x<35, ifelse(t<(35-x), exp(-int(function(s) A + B*c^(x+s) + 0.10 + 0.001, 0, t)), ifelse(t<(45-x), exp(-int(function(s) A + B*c^(x+s) + 0.10 + 0.001, 0, 35-x))*exp(-int(function(s) A + B*c^(x+s) + 0.05 + 0.001, 35-x, t)), ifelse(t<(60-x), exp(-int(function(s) A + B*c^(x+s) + 0.10 + 0.001, 0, 35-x))*exp(-int(function(s) A + B*c^(x+s) + 0.05 + 0.001, 35-x, 45-x))*exp(-int(function(s) A + B*c^(x+s) + 0.02 + 0.001, 45-x, t)), ifelse(t<(65-x), 0.7*exp(-int(function(s) A + B*c^(x+s) + 0.10 + 0.001, 0, 35-x))*exp(-int(function(s) A + B*c^(x+s) + 0.05 + 0.001, 35-x, 45-x))*exp(-int(function(s) A + B*c^(x+s) + 0.02 + 0.001, 45-x, 60-x))*exp(-int(function(s) A + B*c^(x+s) + 0.10 + 0.001, 60-x, t)), 0)))), ifelse(x<45, ifelse(t<(45-x), exp(-int(function(s) A + B*c^(x+s) + 0.05 + 0.001, 0, t)), ifelse(t<(60-x), exp(-int(function(s) A + B*c^(x+s) + 0.05 + 0.001, 0, 45-x))*exp(-int(function(s) A + B*c^(x+s) + 0.02 + 0.001, 45-x, t)), ifelse(t<(65-x), 0.7*exp(-int(function(s) A + B*c^(x+s) + 0.05 + 0.001, 0, 45-x))*exp(-int(function(s) A + B*c^(x+s) + 0.02 + 0.001, 45-x, 60-x))*exp(-int(function(s) A + B*c^(x+s) + 0.10 + 0.001, 60-x, t)), 0))), ifelse(x<60, ifelse(t<(60-x), exp(-int(function(s) A + B*c^(x+s) + 0.02 + 0.001, 0, t)), ifelse(t<(65-x), 0.7*exp(-int(function(s) A + B*c^(x+s) + 0.02 + 0.001, 0, 60-x))*exp(-int(function(s) A + B*c^(x+s) + 0.10 + 0.001, 60-x, t)), 0)), ifelse(x<65, ifelse(t<(65-x), exp(-int(function(s) A + B*c^(x+s) + 0.10 + 0.001, 0, t)), 0), 0)))))
  unlist(lapply(t,g))
}

tpx01 <- function(t,x) {
  g <- function(t) integrate(function(t) tpx00(t,x)*ux01(x+t), 0, t)$value
  unlist(lapply(t,g))
}

tpx02 <- function(t,x) {
  g <- function(t) integrate(function(t) tpx00(t,x)*ux02(x+t), 0, t)$value
  unlist(lapply(t,g))  
}

tpx03 <- function(t,x) {
  g <- function(t) integrate(function(t) tpx00(t,x)*ux03(x+t), 0, t)$value
  unlist(lapply(t,g)) 
}

tpx04 <- function(t,x) {
  g <- function(t) integrate(function(t) tpx00(t,x)*ux04(x+t), 0, t)$value
  unlist(lapply(t,g)) 
}

serviceTable <- function(x, radix=1e+06) {
  data.frame(x=x:65, 
             lx=radix*c(tpx00(0:(65-x-1), x),tpx00(65-x-0.0000000001,x)),
             wx=radix*tpx00(0:(65-x),x)*unlist(lapply(x:65, function(x) tpx01(1,x))), 
             ix=radix*tpx00(0:(65-x),x)*unlist(lapply(x:65, function(x) tpx02(1,x))),
             rx=radix*c(tpx00(0:(65-x-1),x)*unlist(lapply(x:64, function(x) tpx03(1,x))), tpx00(65-x-0.000000000001,x)),
             dx=radix*tpx00(0:(65-x),x)*unlist(lapply(x:65, function(x) tpx04(1,x))))
}

print(serviceTable(20))
##     x         lx        wx        ix        rx        dx
## 1  20 1000000.00 95104.164 951.04164     0.000 237.41893
## 2  21  903707.38 85946.182 859.46182     0.000 217.71579
## 3  22  816684.02 77669.758 776.69758     0.000 199.95897
## 4  23  738037.60 70190.027 701.90027     0.000 183.96186
## 5  24  666961.71 63430.295 634.30295     0.000 169.55582
## 6  25  602727.56 57321.250 573.21250     0.000 156.58845
## 7  26  544676.51 51800.251 518.00251     0.000 144.92203
## 8  27  492213.33 46810.690 468.10690     0.000 134.43210
## 9  28  444800.10 42301.406 423.01406     0.000 125.00620
## 10 29  401950.68 38226.165 382.26165     0.000 116.54268
## 11 30  363225.71 34543.182 345.43182     0.000 108.94969
## 12 31  328228.15 31214.695 312.14695     0.000 102.14422
## 13 32  296599.16 28206.579 282.06579     0.000  96.05126
## 14 33  268014.46 25487.990 254.87990     0.000  90.60300
## 15 34  242180.99 23031.058 230.31058     0.000  85.73817
## 16 35  218833.88 10665.313 213.30626     0.000  83.45331
## 17 36  207871.81 10130.950 202.61899     0.000  83.57433
## 18 37  197454.67  9623.143 192.46285     0.000  83.97859
## 19 38  187555.08  9140.558 182.81115     0.000  84.67124
## 20 39  178147.04  8681.926 173.63853     0.000  85.65838
## 21 40  169205.82  8246.044 164.92087     0.000  86.94715
## 22 41  160707.91  7831.763 156.63526     0.000  88.54569
## 23 42  152630.97  7437.995 148.75990     0.000  90.46319
## 24 43  144953.75  7063.705 141.27409     0.000  92.70993
## 25 44  137656.06  6707.906 134.15813     0.000  95.29724
## 26 45  130718.70  2586.134 129.30670     0.000  99.73394
## 27 46  127903.52  2530.354 126.51771     0.000 106.23161
## 28 47  125140.42  2475.598 123.77989     0.000 113.44367
## 29 48  122427.60  2421.829 121.09146     0.000 121.43776
## 30 49  119763.24  2369.011 118.45056     0.000 130.28776
## 31 50  117145.49  2317.107 115.85533     0.000 140.07423
## 32 51  114572.45  2266.077 113.30384     0.000 150.88497
## 33 52  112042.19  2215.883 110.79413     0.000 162.81549
## 34 53  109552.70  2166.483 108.32417     0.000 175.96953
## 35 54  107101.92  2117.837 105.89187     0.000 190.45958
## 36 55  104687.73  2069.901 103.49506     0.000 206.40736
## 37 56  102307.93  2022.630 101.13150     0.000 223.94425
## 38 57   99960.22  1975.977  98.79885     0.000 243.21169
## 39 58   97642.23  1929.894  96.49469     0.000 264.36145
## 40 59   95351.48  1884.330  94.21649     0.000 287.55581
## 41 60   65159.77     0.000  61.87556  6187.556 210.42408
## 42 61   58699.91     0.000  55.73070  5573.070 211.50710
## 43 62   52859.60     0.000  50.17509  5017.509 212.66541
## 44 63   47579.25     0.000  45.15206  4515.206 213.87329
## 45 64   42805.02     0.000  40.61042  4061.042 215.10449
## 46 65   38488.26     0.000   0.00000 38488.265   0.00000