begin global tab_diff, tab_diffv diff_tab = [ [1], [-1/60,3/20,-3/4,0,3/4,-3/20,1/60], [1/90,-3/20,3/2,-49/18,3/2,-3/20,1/90], [-7/240,3/10,-169/120,61/30,0,-61/30,169/120,-3/10,7/240], [7/240,-2/5,169/60,-122/15,91/8,-122/15,169/60,-2/5,7/240], [139/12096,-121/756,3125/3024,-3011/756,33853/4032,-1039/126,0, 1039/126,-33853/4032,3011/756,-3125/3024,121/756,-139/12096], [-139/12096,121/630,-3125/2016,3011/378,-33853/1344,1039/21, -44473/720,1039/21,-33853/1344,3011/378,-3125/2016,121/630, -139/12096], [-2473/518400, 2747/32400, -1363/1920, 4787/1296, -678739/51840, 37517/1200, -12312353/259200, 251539/6480, 0, -251539/6480, 12312353/259200, -37517/1200, 678739/51840, -4787/1296, 1363/1920, -2747/32400, 2473/518400], [2473/518400, -2747/28350, 1363/1440, -4787/810, 678739/25920, -37517/450, 12312353/64800, -251539/810, 4913051/13440, -251539/810, 12312353/64800, -37517/450, 678739/25920, -4787/810, 1363/1440, -2747/28350, 2473/518400], [-2021/268800, 7403/50400, -156031/115200, 65377/8400, -248167/8064, 309691/3600, -1618681/9600, 5586823/25200, -66976673/403200, 0, 66976673/403200, -5586823/25200, 1618681/9600, -309691/3600, 248167/8064, -65377/8400, 156031/115200, -7403/50400, 2021/268800], [-21713/10644480, 32699/665280, -3039931/5322240, 44989/10560, -81091903/3548160, 5165621/55440, -130451323/443520, 39926233/55440, -269158459/197120, 666523661/332640, -78685061/34560, 666523661/332640, -269158459/197120, 39926233/55440, -130451323/443520, 5165621/55440, -81091903/3548160, 44989/10560, -3039931/5322240, 32699/665280, -21713/10644480], [2677/829440, -55057/725760, 109819/129024, -548749/90720, 25219187/829440, -9186451/80640, 628607179/1935360, -10656949/15120, 368867591/322560, -478917077/362880, 916.2723252177028, 0, -916.2723252177028, 478917077/362880, -368867591/322560, 10656949/15120, -628607179/1935360, 9186451/80640, -25219187/829440, 548749/90720, -109819/129024, 55057/725760, -2677/829440], [-2677/760320, 55057/604800, -109819/96768, 548749/60480, -3602741/69120, 9186451/40320, -628607179/806400, 10656949/5040, -368867591/80640, 478917077/60480, -10995.267902612433, 12264.447302188551, -10995.267902612433, 478917077/60480, -368867591/80640, 10656949/5040, -628607179/806400, 9186451/40320, -3602741/69120, 548749/60480, -109819/96768, 55057/604800, -2677/760320], [392251/79833600, -301141/2419200, 803105/532224, -28111729/2419200, 38447137/604800, -90273149/345600, 828.9862464175485, -66270565/32256, 3968.854857390873, -5875.183389274692, 548397449/86400, -4234.884892300986, 0, 4234.884892300986, -548397449/86400, 5875.183389274692, -3968.854857390873, 66270565/32256, -828.9862464175485, 90273149/345600, -38447137/604800, 28111729/2419200, -803105/532224, 301141/2419200, -392251/79833600], [-392251/68428800, 301141/1900800, -160621/76032, 28111729/1555200, -38447137/345600, 90273149/172800, -1934.3012416409465, 13254113/2304, -13890.992000868055, 27417.522483281893, -44430.34887731481, 59288.3884922138, -65260.40946063646, 59288.3884922138, -44430.34887731481, 27417.522483281893, -13890.992000868055, 13254113/2304, -1934.3012416409465, 90273149/172800, -38447137/345600, 28111729/1555200, -160621/76032, 301141/1900800, -392251/68428800], [462397/63866880, -116357/591360, 14891341/5806080, -34012985/1596672, 49759967/394240, -205141127/362880, 819550333/414720, -147381799/26880, 12150.355132034007, -21429.566915371473, 29559.504599144344, -30366.093272256294, 19658.44724708644, 0, -19658.44724708644, 30366.093272256294, -29559.504599144344, 21429.566915371473, -12150.355132034007, 147381799/26880, -819550333/414720, 205141127/362880, -49759967/394240, 34012985/1596672, -14891341/5806080, 116357/591360, -462397/63866880], [-35569/3991680, 116357/443520, -14891341/3991680, 6802597/199584, -49759967/221760, 205141127/181440, -117078619/25920, 147381799/10080, -38881.13642250882, 85718.2676614859, -157650.69119543652, 242928.74617805035, -314535.155953383, 1085856289/3168, -314535.155953383, 242928.74617805035, -157650.69119543652, 85718.2676614859, -38881.13642250882, 147381799/10080, -117078619/25920, 205141127/181440, -49759967/221760, 6802597/199584, -14891341/3991680, 116357/443520, -35569/3991680], [354971/34214400, -18033847/59875200, 3107353/739200, -68025869/1814400, 764658775/3193344, -28638419/24640, 4437.5358114878945, -70496837/5184, 1817870687/53760, -551961925/8064, 112225.73000716491, -146344.3397389069, 144464.45257679725, -91323.99824535033, 0, 91323.99824535033, -144464.45257679725, 146344.3397389069, -112225.73000716491, 551961925/8064, -1817870687/53760, 70496837/5184, -4437.5358114878945, 28638419/24640, -764658775/3193344, 68025869/1814400, -3107353/739200, 18033847/59875200, -354971/34214400], [-354971/26611200, 1387219/3326400, -3107353/492800, 68025869/1108800, -152931755/354816, 28638419/12320, -9984.455575847764, 70496837/2016, -1817870687/17920, 110392385/448, -505015.78503224207, 878066.0384334415, -1300180.0731911752, 1643831.968416306, -1777206.4762581168, 1643831.968416306, -1300180.0731911752, 878066.0384334415, -505015.78503224207, 110392385/448, -1817870687/17920, 70496837/2016, -9984.455575847764, 28638419/12320, -152931755/354816, 68025869/1108800, -3107353/492800, 1387219/3326400, -354971/26611200], [154477/10644480, -26633/59400, 355238273/53222400, -26472629/415800, 703770169/1612800, -63290987/27720, 9454.461361099839, -219560281/6930, 87099.3596216067, -498555697/2520, 371712.25739397324, -574075.5604256854, 715038.4507268557, -683314.7463564214, 423682.9584378946, 0, -423682.9584378946, 683314.7463564214, -715038.4507268557, 574075.5604256854, -371712.25739397324, 498555697/2520, -87099.3596216067, 219560281/6930, -9454.461361099839, 63290987/27720, -703770169/1612800, 26472629/415800, -355238273/53222400, 26633/59400, -154477/10644480], [0.005873343259565978, -0.2072968570414007, 3.5537025472690154, -39.400399164970096, 317.3166509668866, -1976.1420670886469, 9888.825953571892, -40778.74178604712, 140984.0369842934, -413595.54362350475, 1038367.7376354603, -2244654.089502898, 4196536.657000686, -6807167.396956872, 9602050.567143656, -11796342.893053222, 12632811.42748226, -11796342.893053222, 9602050.567143656, -6807167.396956872, 4196536.657000686, -2244654.089502898, 1038367.7376354603, -413595.54362350475, 140984.0369842934, -40778.74178604712, 9888.825953571892, -1976.1420670886469, 317.3166509668866, -39.400399164970096, 3.5537025472690154, -0.2072968570414007, 0.005873343259565978], [-0.006687176916126569, 182035669/778377600, -3.9614914834153114, 43.260384273648164, -341.90064621496043, 2080.7542524373775, -10126.582118695027, 40390.02018330178, -134186.6825709837, 375262.41314945085, -888771.9697958316, 1786407.53815386, -3040050.4498071615, 4341946.758998833, -5097356.637806768, 4673525.878001358, -2827559.224280478, 0, 2827559.224280478, -4673525.878001358, 5097356.637806768, -4341946.758998833, 3040050.4498071615, -1786407.53815386, 888771.9697958316, -375262.41314945085, 134186.6825709837, -40390.02018330178, 10126.582118695027, -2080.7542524373775, 341.90064621496043, -43.260384273648164, 3.9614914834153114, -182035669/778377600, 0.006687176916126569], [9797927/1132185600, -182035669/566092800, 5.810187509009124, -67.98060385858997, 578.6010935945485, -3814.716129468525, 20253.164237390054, -88858.04440326392, 328011.8907290713, -1031971.6361609899, 2793283.3336440423, -6550160.97323082, 13376221.97915151, -23880707.17449358, 37380615.3439163, -51408784.65801494, 62206302.93417052, -66281815.12236388, 62206302.93417052, -51408784.65801494, 37380615.3439163, -23880707.17449358, 13376221.97915151, -6550160.97323082, 2793283.3336440423, -1031971.6361609899, 328011.8907290713, -88858.04440326392, 20253.164237390054, -3814.716129468525, 578.6010935945485, -67.98060385858997, 5.810187509009124, -182035669/566092800, 9797927/1132185600], [-0.009332470275581635, 0.34402346379324306, -6.15213852441283, 71.05165114070279, -595.1122156963487, 3847.767250900206, -19955.02716637555, 85132.52554556729, -303953.20031468215, 918926.1148505581, -2370511.92168014, 5240062.788594784, -9934784.39219035, 16104729.814346485, -22115672.239893954, 25188993.19451772, -22603469.63177157, 13500898.864533069, 0, -13500898.864533069, 22603469.63177157, -25188993.19451772, 22115672.239893954, -16104729.814346485, 9934784.39219035, -5240062.788594784, 2370511.92168014, -918926.1148505581, 303953.20031468215, -85132.52554556729, 19955.02716637555, -3847.767250900206, 595.1122156963487, -71.05165114070279, 6.15213852441283, -0.34402346379324306, 0.009332470275581635], [0.012443293700775513, -0.4856801841786961, 9.228207786619246, -113.68264182512446, 1020.1923697651692, -7103.570309354226, 39910.0543327511, -185743.69209941954, 729487.6807552371, -2450469.639601488, 7111535.76504042, -17965929.560896404, 39739137.5687614, -77302703.10886313, 132694033.43936373, -201511945.55614176, 271241635.58125883, -324021572.7487936, 343777625.044988, -324021572.7487936, 271241635.58125883, -201511945.55614176, 132694033.43936373, -77302703.10886313, 39739137.5687614, -17965929.560896404, 7111535.76504042, -2450469.639601488, 729487.6807552371, -185743.69209941954, 39910.0543327511, -7103.570309354226, 1020.1923697651692, -113.68264182512446, 9.228207786619246, -0.4856801841786961, 0.012443293700775513], ] function tab_diff(h) return fn diff|f,x,n| if n==0 return f(x) else a = diff_tab[n] m = len(a)//2 d = h^(1/n) return (-m..m).sum(|k| a[m+k]*f(x+k*d))/h end end end function tab_diffv(h) return fn diffv|v,f,x,n| if n==0 return f(x) else a = diff_tab[n] m = len(a)//2 dv = h^(1/n)*v return (-m..m).sum(|k| a[m+k]*f(x+k*dv))/h end end end end