├── .vscode └── settings.json ├── README.md ├── commit.sh ├── desmos.py ├── dump ├── FPoly.txt ├── FRedInterval.txt ├── FRndInterval.txt ├── FSoplexRational.lp ├── FSoplexReal.lp ├── HPoly.txt ├── HRedInterval.txt ├── HRndInterval.txt ├── HSoplexRational.lp ├── HSoplexReal.lp ├── poly.txt └── tmp.lp ├── float32 ├── Makefile ├── fexpm1.cpp ├── fexpm1poly │ ├── fexmp1_0.500000_0.525010.txt │ ├── fexmp1_1.500000_1.550010.txt │ ├── fexmp1_1.500000_1.600010.txt │ ├── fexmp1_2.000000_2.100010.txt │ ├── fexmp1_2.000000_2.100100.txt │ ├── fexmp1_2.100000_2.200010.txt │ ├── fexmp1_2.100000_2.200100.txt │ ├── fexmp1_2.200000_2.300010.txt │ ├── fexmp1_2.200000_2.300100.txt │ └── fexmp1_2.300000_2.400100.txt ├── fhelper.cpp ├── fhelper.hpp ├── flog2 ├── flog2.cpp ├── flog2poly │ ├── 2-2.txt │ ├── 2-4.txt │ ├── 2-6.txt │ ├── 2-8.txt │ ├── 2.txt │ ├── flog2_2.000000_2.100100.txt │ └── flog2_2.100000_2.200100.txt └── luts.h ├── half16 ├── Makefile ├── half.hpp ├── hexpm1 ├── hexpm1.cpp ├── hhelper.cpp ├── hhelper.hpp ├── hlog2 ├── hlog2.cpp └── luts.h ├── lib └── flog2 │ ├── Makefile │ ├── flog2lib │ ├── flog2lib.cpp │ ├── flog2lib.hpp │ └── flog2poly │ ├── 2.txt │ ├── 22.txt │ ├── 24.txt │ ├── 26.txt │ └── 28.txt └── old ├── 1.cpp ├── 2.cpp ├── Interval_Data.h ├── Makefile ├── Sample_Data.h ├── Utilities.cpp ├── Utilities.h ├── commands.txt ├── common.cpp ├── common.h ├── constants.hpp ├── exp1.cpp ├── expm1.cpp ├── file_io.cpp ├── float.cpp ├── helper.hpp ├── helper_test.cpp ├── progressive.cpp ├── rlibm-fast.h └── runAll.sh /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "*.ir": "c", 4 | "algorithm": "cpp", 5 | "any": "cpp", 6 | "array": "cpp", 7 | "*.tcc": "cpp", 8 | "deque": "cpp", 9 | "forward_list": "cpp", 10 | "functional": "cpp", 11 | "iterator": "cpp", 12 | "list": "cpp", 13 | "map": "cpp", 14 | "memory": "cpp", 15 | "memory_resource": "cpp", 16 | "numeric": "cpp", 17 | "optional": "cpp", 18 | "random": "cpp", 19 | "ratio": "cpp", 20 | "regex": "cpp", 21 | "set": "cpp", 22 | "string": "cpp", 23 | "string_view": "cpp", 24 | "system_error": "cpp", 25 | "tuple": "cpp", 26 | "type_traits": "cpp", 27 | "unordered_map": "cpp", 28 | "unordered_set": "cpp", 29 | "utility": "cpp", 30 | "vector": "cpp", 31 | "iostream": "cpp", 32 | "ostream": "cpp" 33 | } 34 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ALibm 2 | 3 | Sebastian (Alex) Schott 4 | 5 | Advised by Professor Jay Lim 6 | 7 | 8 | Full Report: https://docs.google.com/document/d/18aQoqCwM4V8EnPv3WZaG5QA2jsTiSpEXtvwtrYlNPJk/edit?usp=sharing 9 | 10 | 11 | ## Abstract 12 | 13 | The accuracy of mathematical computation in scientific and technological fields depends on the ability of math libraries to evaluate elementary functions (such as ln(x) or ex). Unfortunately, standard math libraries like math.h which are widely used fail to produce the correctly rounded results for all inputs. This rounding issue, while seemingly minor at each calculation, can accumulate to yield significant errors, especially in domains that rely heavily on precise floating point computations. Typically, standard math libraries use polynomial approximations to estimate the real value of each elementary function by minimizing the absolute error across all inputs. However, this technique struggles when the exact real number solution falls on the border of two floating-point values. In such cases, to achieve the correctly rounded result would require extreme precision, which the polynomial cannot handle. RLibm [1] is a math library which solves this problem to produce correctly rounded results for every input. Their method also uses polynomial approximation, but instead of approximating the real number value of the function, they approximate the rounded result. This allows for more flexibility in creating the polynomial, and allows the final polynomial to produce correctly rounded results across various floating point representations. However, there are some elementary functions which RLibm does not implement, such as ex-1 due to difficulty in range reduction. This project extends RLibm to more elementary functions. First I implemented the algorithm described in the original RLibm paper and used it to generate a polynomial approximation of log2(x) and expm1(x) which was correctly rounded on all float inputs over small domains. Using multiple polynomials, I was able to implement log2 in a correctly rounded 32 bit floating point library. 14 | 15 | 16 | [1] An Approach to Generate Correctly Rounded Math Libraries for New Floating Point Variants.Jay P. Lim, Mridul Aanjaneya, John Gustafson, and Santosh Nagarakatte. 2021.48th ACM SIGPLAN Symposium on Principles of Programming Languages (POPL 2021). 17 | -------------------------------------------------------------------------------- /commit.sh: -------------------------------------------------------------------------------- 1 | git add . 2 | git commit -m "update" 3 | git push origin main -------------------------------------------------------------------------------- /desmos.py: -------------------------------------------------------------------------------- 1 | # read in file poly.txt and print the polynomial where each line a coefficient 2 | # output of the form a0 + a1x + a2x^2 + ... + anx^n 3 | 4 | infile = open("/home/rlibm-32/IntervalGen/ALibm/dump/FPoly.txt", "r") 5 | lines = infile.readlines() 6 | combined = "" 7 | for line in lines: 8 | combined += line.strip() 9 | combined += "x^" + str(lines.index(line)) + " + " 10 | 11 | print(combined.strip()) 12 | -------------------------------------------------------------------------------- /dump/FPoly.txt: -------------------------------------------------------------------------------- 1 | -0.625639376708967853701892636308912187814712524414062500000000 2 | 2.754939243685276206718981484300456941127777099609375000000000 3 | -1.519795924075517001838875330577138811349868774414062500000000 4 | 1.373861921492707027780966200225520879030227661132812500000000 5 | -0.343024277657922260775791301057324744760990142822265625000000 6 | 0.065046679847372598781696240166638744994997978210449218750000 7 | -------------------------------------------------------------------------------- /dump/FRedInterval.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschott20/ALibm/7de59ad0278d1fce37f69818244712c2704d16d5/dump/FRedInterval.txt -------------------------------------------------------------------------------- /dump/FRndInterval.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschott20/ALibm/7de59ad0278d1fce37f69818244712c2704d16d5/dump/FRndInterval.txt -------------------------------------------------------------------------------- /dump/FSoplexRational.lp: -------------------------------------------------------------------------------- 1 | Minimize 2 | obj: 1 x0 + 1 x1 + 1 x2 + 1 x3 + 1 x4 3 | Subject To 4 | C0_1 : 1 x0 + 4404019/2097152 x1 + 19395383352361/4398046511104 x2 + 85417636796081538859/9223372036854775808 x3 + 376180895385042222684274321/19342813113834066795298816 x4 >= 3939643031553/549755813888 5 | C0_2 : 1 x0 + 4404019/2097152 x1 + 19395383352361/4398046511104 x2 + 85417636796081538859/9223372036854775808 x3 + 376180895385042222684274321/19342813113834066795298816 x4 <= 8068389465487359/1125899906842624 6 | C1_1 : 1 x0 + 8808039/4194304 x1 + 77581551025521/17592186044416 x2 + 683341327113278963319/73786976294838206464 x3 + 6018897059525518526793321441/309485009821345068724781056 x4 >= 3939644080129/549755813888 7 | C1_2 : 1 x0 + 8808039/4194304 x1 + 77581551025521/17592186044416 x2 + 683341327113278963319/73786976294838206464 x3 + 6018897059525518526793321441/309485009821345068724781056 x4 <= 8068391612971007/1125899906842624 8 | C2_1 : 1 x0 + 2207253/1048576 x1 + 4871965806009/1099511627776 x2 + 10753661141210783277/1152921504606846976 x3 + 23736050814920925020508081/1208925819614629174706176 x4 >= 8114480907028481/1125899906842624 9 | C2_2 : 1 x0 + 2207253/1048576 x1 + 4871965806009/1099511627776 x2 + 10753661141210783277/1152921504606846976 x3 + 23736050814920925020508081/1208925819614629174706176 x4 <= 4057240721947647/562949953421312 10 | C3_1 : 1 x0 + 4424993/2097152 x1 + 19580563050049/4398046511104 x2 + 86643854432525474657/9223372036854775808 x3 + 383398449356944197678902401/19342813113834066795298816 x4 >= 8160804276799489/1125899906842624 11 | C3_2 : 1 x0 + 4424993/2097152 x1 + 19580563050049/4398046511104 x2 + 86643854432525474657/9223372036854775808 x3 + 383398449356944197678902401/19342813113834066795298816 x4 <= 4080402406833151/562949953421312 12 | C4_1 : 1 x0 + 8870959/4194304 x1 + 78693913579681/17592186044416 x2 + 698090480914893384079/73786976294838206464 x3 + 6192732034486301699536061761/309485009821345068724781056 x4 >= 4007498481665/549755813888 13 | C4_2 : 1 x0 + 8870959/4194304 x1 + 78693913579681/17592186044416 x2 + 698090480914893384079/73786976294838206464 x3 + 6192732034486301699536061761/309485009821345068724781056 x4 <= 8207357427316735/1125899906842624 14 | C5_1 : 1 x0 + 8891933/4194304 x1 + 79066472476489/17592186044416 x2 + 703053775807284263237/73786976294838206464 x3 + 6251507069875392580657767121/309485009821345068724781056 x4 >= 8254145727301633/1125899906842624 15 | C5_2 : 1 x0 + 8891933/4194304 x1 + 79066472476489/17592186044416 x2 + 703053775807284263237/73786976294838206464 x3 + 6251507069875392580657767121/309485009821345068724781056 x4 <= 4127073132084223/562949953421312 16 | C6_1 : 1 x0 + 4456453/2097152 x1 + 19859973341209/4398046511104 x2 + 88505037776350871677/9223372036854775808 x3 + 394418541113532171137581681/19342813113834066795298816 x4 >= 8301167029258241/1125899906842624 17 | C6_2 : 1 x0 + 4456453/2097152 x1 + 19859973341209/4398046511104 x2 + 88505037776350871677/9223372036854775808 x3 + 394418541113532171137581681/19342813113834066795298816 x4 <= 4150583783062527/562949953421312 18 | C7_1 : 1 x0 + 1116735/524288 x1 + 1247097060225/274877906944 x2 + 1392676935550365375/144115188075855872 x3 + 1555251077621837277050625/75557863725914323419136 x4 >= 8348425628157953/1125899906842624 19 | C7_2 : 1 x0 + 1116735/524288 x1 + 1247097060225/274877906944 x2 + 1392676935550365375/144115188075855872 x3 + 1555251077621837277050625/75557863725914323419136 x4 <= 4174213082512383/562949953421312 20 | C8_1 : 1 x0 + 8954853/4194304 x1 + 80189392251609/17592186044416 x2 + 718084219772497608477/73786976294838206464 x3 + 6430338629682409526763088881/309485009821345068724781056 x4 >= 8395919376517121/1125899906842624 21 | C8_2 : 1 x0 + 8954853/4194304 x1 + 80189392251609/17592186044416 x2 + 718084219772497608477/73786976294838206464 x3 + 6430338629682409526763088881/309485009821345068724781056 x4 <= 4197959956691967/562949953421312 22 | C9_1 : 1 x0 + 8975827/4194304 x1 + 80565470333929/17592186044416 x2 + 723141723890978934283/73786976294838206464 x3 + 6490795010127193774768577041/309485009821345068724781056 x4 >= 4122877493249/549755813888 23 | C9_2 : 1 x0 + 8975827/4194304 x1 + 80565470333929/17592186044416 x2 + 723141723890978934283/73786976294838206464 x3 + 6490795010127193774768577041/309485009821345068724781056 x4 <= 8443653643040767/1125899906842624 24 | C10_1 : 1 x0 + 140575/65536 x1 + 19761330625/4294967296 x2 + 2777949052609375/281474976710656 x3 + 390510188070562890625/18446744073709551616 x4 >= 8491624132773889/1125899906842624 25 | C10_2 : 1 x0 + 140575/65536 x1 + 19761330625/4294967296 x2 + 2777949052609375/281474976710656 x3 + 390510188070562890625/18446744073709551616 x4 <= 4245812334820351/562949953421312 26 | C11_1 : 1 x0 + 4508887/2097152 x1 + 20330061978769/4398046511104 x2 + 91665952165265820103/9223372036854775808 x3 + 413311420060588907806755361/19342813113834066795298816 x4 >= 8539838361896961/1125899906842624 27 | C11_2 : 1 x0 + 4508887/2097152 x1 + 20330061978769/4398046511104 x2 + 91665952165265820103/9223372036854775808 x3 + 413311420060588907806755361/19342813113834066795298816 x4 <= 4269919449381887/562949953421312 28 | C12_1 : 1 x0 + 2259687/1048576 x1 + 5106185337969/1099511627776 x2 + 11538380627799155703/1152921504606846976 x3 + 26073128705689590753044961/1208925819614629174706176 x4 >= 4193502756865/549755813888 29 | C12_2 : 1 x0 + 2259687/1048576 x1 + 5106185337969/1099511627776 x2 + 11538380627799155703/1152921504606846976 x3 + 26073128705689590753044961/1208925819614629174706176 x4 <= 8588294182926335/1125899906842624 30 | C13_1 : 1 x0 + 9059721/4194304 x1 + 82078544597841/17592186044416 x2 + 743608714142496662361/73786976294838206464 x3 + 6736887483299774004421861281/309485009821345068724781056 x4 >= 8636989448390657/1125899906842624 31 | C13_2 : 1 x0 + 9059721/4194304 x1 + 82078544597841/17592186044416 x2 + 743608714142496662361/73786976294838206464 x3 + 6736887483299774004421861281/309485009821345068724781056 x4 <= 4318494992628735/562949953421312 32 | C14_1 : 1 x0 + 9080695/4194304 x1 + 82459021683025/17592186044416 x2 + 748785225901936702375/73786976294838206464 x3 + 6799490256921587103573150625/309485009821345068724781056 x4 >= 4241177837569/549755813888 33 | C14_2 : 1 x0 + 9080695/4194304 x1 + 82459021683025/17592186044416 x2 + 748785225901936702375/73786976294838206464 x3 + 6799490256921587103573150625/309485009821345068724781056 x4 <= 8685932748208127/1125899906842624 34 | C15_1 : 1 x0 + 2275417/1048576 x1 + 5177522523889/1099511627776 x2 + 11781022768739936713/1152921504606846976 x3 + 26806739485377920575684321/1208925819614629174706176 x4 >= 8735117639944193/1125899906842624 35 | C15_2 : 1 x0 + 2275417/1048576 x1 + 5177522523889/1099511627776 x2 + 11781022768739936713/1152921504606846976 x3 + 26806739485377920575684321/1208925819614629174706176 x4 <= 4367559088405503/562949953421312 36 | C16_1 : 1 x0 + 4561321/2097152 x1 + 20805649265041/4398046511104 x2 + 94901244911266079161/9223372036854775808 x3 + 432875041339901103464731681/19342813113834066795298816 x4 >= 4289332117505/549755813888 37 | C16_2 : 1 x0 + 4561321/2097152 x1 + 20805649265041/4398046511104 x2 + 94901244911266079161/9223372036854775808 x3 + 432875041339901103464731681/19342813113834066795298816 x4 <= 8784552713517055/1125899906842624 38 | C17_1 : 1 x0 + 9143615/4194304 x1 + 83605695268225/17592186044416 x2 + 764458289339971133375/73786976294838206464 x3 + 6989912281283300154694650625/309485009821345068724781056 x4 >= 4313589874689/549755813888 39 | C17_2 : 1 x0 + 9143615/4194304 x1 + 83605695268225/17592186044416 x2 + 764458289339971133375/73786976294838206464 x3 + 6989912281283300154694650625/309485009821345068724781056 x4 <= 8834232600229887/1125899906842624 40 | C18_1 : 1 x0 + 9164589/4194304 x1 + 83989691538921/17592186044416 x2 + 769731003190988468469/73786976294838206464 x3 + 7054268284803097817257844241/309485009821345068724781056 x4 >= 4337970315265/549755813888 41 | C18_2 : 1 x0 + 9164589/4194304 x1 + 83989691538921/17592186044416 x2 + 769731003190988468469/73786976294838206464 x3 + 7054268284803097817257844241/309485009821345068724781056 x4 <= 8884163742529535/1125899906842624 42 | C19_1 : 1 x0 + 4592781/2097152 x1 + 21093637313961/4398046511104 x2 + 96878456676451115541/9223372036854775808 x3 + 444941535132927830885509521/19342813113834066795298816 x4 >= 4362471866369/549755813888 43 | C19_2 : 1 x0 + 4592781/2097152 x1 + 21093637313961/4398046511104 x2 + 96878456676451115541/9223372036854775808 x3 + 444941535132927830885509521/19342813113834066795298816 x4 <= 8934342919190527/1125899906842624 44 | C20_1 : 1 x0 + 1150817/524288 x1 + 1324379767489/274877906944 x2 + 1524118750882388513/144115188075855872 x3 + 1753981768534217701365121/75557863725914323419136 x4 >= 8984775498926081/1125899906842624 45 | C20_2 : 1 x0 + 1150817/524288 x1 + 1324379767489/274877906944 x2 + 1524118750882388513/144115188075855872 x3 + 1753981768534217701365121/75557863725914323419136 x4 <= 4492388017896447/562949953421312 46 | Bounds 47 | x0 free 48 | x1 free 49 | x2 free 50 | x3 free 51 | x4 free 52 | End 53 | -------------------------------------------------------------------------------- /dump/FSoplexReal.lp: -------------------------------------------------------------------------------- 1 | Minimize 2 | obj: 1.0000000000000000e+00 x0 + 1.0000000000000000e+00 x1 + 1.0000000000000000e+00 x2 + 1.0000000000000000e+00 x3 + 1.0000000000000000e+00 x4 3 | Subject To 4 | C0_1 : 1.0000000000000000e+00 x0 + 2.0999999046325684e+00 x1 + 4.4099995994567962e+00 x2 + 9.2609987382889365e+00 x3 + 1.9448096467209101e+01 x4 >= 7.1661689281481813e+00 5 | C0_2 : 1.0000000000000000e+00 x0 + 2.0999999046325684e+00 x1 + 4.4099995994567962e+00 x2 + 9.2609987382889365e+00 x3 + 1.9448096467209101e+01 x4 <= 7.1661694049817006e+00 6 | C1_1 : 1.0000000000000000e+00 x0 + 2.1000001430511475e+00 x1 + 4.4100006008148398e+00 x2 + 9.2610018925668083e+00 x3 + 1.9448105299187247e+01 x4 >= 7.1661708354968141e+00 7 | C1_2 : 1.0000000000000000e+00 x0 + 2.1000001430511475e+00 x1 + 4.4100006008148398e+00 x2 + 9.2610018925668083e+00 x3 + 1.9448105299187247e+01 x4 <= 7.1661713123303334e+00 8 | C2_1 : 1.0000000000000000e+00 x0 + 2.1050004959106445e+00 x1 + 4.4310270877840594e+00 x2 + 9.3273142171789427e+00 x3 + 1.9634001052676080e+01 x4 >= 7.2071068286913951e+00 9 | C2_2 : 1.0000000000000000e+00 x0 + 2.1050004959106445e+00 x1 + 4.4310270877840594e+00 x2 + 9.3273142171789427e+00 x3 + 1.9634001052676080e+01 x4 <= 7.2071073055249126e+00 10 | C3_1 : 1.0000000000000000e+00 x0 + 2.1100010871887207e+00 x1 + 4.4521045879375833e+00 x2 + 9.3939455208261915e+00 x3 + 1.9821235261934877e+01 x4 >= 7.2482502460497935e+00 11 | C3_2 : 1.0000000000000000e+00 x0 + 2.1100010871887207e+00 x1 + 4.4521045879375833e+00 x2 + 9.3939455208261915e+00 x3 + 1.9821235261934877e+01 x4 <= 7.2482507228833111e+00 12 | C4_1 : 1.0000000000000000e+00 x0 + 2.1150014400482178e+00 x1 + 4.4732310914060349e+00 x2 + 9.4608901999922246e+00 x3 + 2.0009796397121626e+01 x4 >= 7.2895972728747438e+00 13 | C4_2 : 1.0000000000000000e+00 x0 + 2.1150014400482178e+00 x1 + 4.4732310914060349e+00 x2 + 9.4608901999922246e+00 x3 + 2.0009796397121626e+01 x4 <= 7.2895977497082631e+00 14 | C5_1 : 1.0000000000000000e+00 x0 + 2.1200020313262939e+00 x1 + 4.4944086128276126e+00 x2 + 9.5281553888049295e+00 x3 + 2.0199708779059023e+01 x4 >= 7.3311541080493052e+00 15 | C5_2 : 1.0000000000000000e+00 x0 + 2.1200020313262939e+00 x1 + 4.4944086128276126e+00 x2 + 9.5281553888049295e+00 x3 + 2.0199708779059023e+01 x4 <= 7.3311545848828228e+00 16 | C6_1 : 1.0000000000000000e+00 x0 + 2.1250023841857910e+00 x1 + 4.5156351327952962e+00 x2 + 9.5957354233031253e+00 x3 + 2.0390960652535192e+01 x4 >= 7.3729174137133677e+00 17 | C6_2 : 1.0000000000000000e+00 x0 + 2.1250023841857910e+00 x1 + 4.5156351327952962e+00 x2 + 9.5957354233031253e+00 x3 + 2.0390960652535192e+01 x4 <= 7.3729178905468853e+00 18 | C7_1 : 1.0000000000000000e+00 x0 + 2.1300029754638672e+00 x1 + 4.5369126754849276e+00 x2 + 9.6636374982026290e+00 x3 + 2.0583576624975802e+01 x4 >= 7.4148914814013560e+00 19 | C7_2 : 1.0000000000000000e+00 x0 + 2.1300029754638672e+00 x1 + 4.5369126754849276e+00 x2 + 9.6636374982026290e+00 x3 + 2.0583576624975802e+01 x4 <= 7.4148919582348736e+00 20 | C8_1 : 1.0000000000000000e+00 x0 + 2.1350033283233643e+00 x1 + 4.5582392119518431e+00 x2 + 9.7318558888112534e+00 x3 + 2.0777544713375359e+01 x4 >= 7.4570744037646373e+00 21 | C8_2 : 1.0000000000000000e+00 x0 + 2.1350033283233643e+00 x1 + 4.5582392119518431e+00 x2 + 9.7318558888112534e+00 x3 + 2.0777544713375359e+01 x4 <= 7.4570748805981548e+00 22 | C9_1 : 1.0000000000000000e+00 x0 + 2.1400039196014404e+00 x1 + 4.5796167759095283e+00 x2 + 9.8003978507189018e+00 x3 + 2.0972889814191980e+01 x4 >= 7.4994704723376344e+00 23 | C9_2 : 1.0000000000000000e+00 x0 + 2.1400039196014404e+00 x1 + 4.5796167759095283e+00 x2 + 9.8003978507189018e+00 x3 + 2.0972889814191980e+01 x4 <= 7.4994709491711538e+00 24 | C10_1 : 1.0000000000000000e+00 x0 + 2.1450042724609375e+00 x1 + 4.6010433288756758e+00 x2 + 9.8692575982162190e+00 x3 + 2.1169599714191360e+01 x4 >= 7.5420773029345591e+00 25 | C10_2 : 1.0000000000000000e+00 x0 + 2.1450042724609375e+00 x1 + 4.6010433288756758e+00 x2 + 9.8692575982162190e+00 x3 + 2.1169599714191360e+01 x4 <= 7.5420777797680767e+00 26 | C11_1 : 1.0000000000000000e+00 x0 + 2.1500048637390137e+00 x1 + 4.6225209141014147e+00 x2 + 9.9384424480533529e+00 x3 + 2.1367699601304977e+01 x4 >= 7.5849001407641490e+00 27 | C11_2 : 1.0000000000000000e+00 x0 + 2.1500048637390137e+00 x1 + 4.6225209141014147e+00 x2 + 9.9384424480533529e+00 x3 + 2.1367699601304977e+01 x4 <= 7.5849006175976665e+00 28 | C12_1 : 1.0000000000000000e+00 x0 + 2.1550054550170898e+00 x1 + 4.6440485111534144e+00 x2 + 1.0007949874899602e+01 x3 + 2.1567186573946245e+01 x4 >= 7.6279370784777711e+00 29 | C12_2 : 1.0000000000000000e+00 x0 + 2.1550054550170898e+00 x1 + 4.6440485111534144e+00 x2 + 1.0007949874899602e+01 x3 + 2.1567186573946245e+01 x4 <= 7.6279375553112905e+00 30 | C13_1 : 1.0000000000000000e+00 x0 + 2.1600058078765869e+00 x1 + 4.6656250900605869e+00 x2 + 1.0077777291905591e+01 x3 + 2.1768057481002860e+01 x4 >= 7.6711876392382701e+00 31 | C13_2 : 1.0000000000000000e+00 x0 + 2.1600058078765869e+00 x1 + 4.6656250900605869e+00 x2 + 1.0077777291905591e+01 x3 + 2.1768057481002860e+01 x4 <= 7.6711881160717876e+00 32 | C14_1 : 1.0000000000000000e+00 x0 + 2.1650063991546631e+00 x1 + 4.6872527083806403e+00 x2 + 1.0147932108099111e+01 x3 + 2.1970337952221648e+01 x4 >= 7.7146575450915407e+00 33 | C14_2 : 1.0000000000000000e+00 x0 + 2.1650063991546631e+00 x1 + 4.6872527083806403e+00 x2 + 1.0147932108099111e+01 x3 + 2.1970337952221648e+01 x4 <= 7.7146580219250600e+00 34 | C15_1 : 1.0000000000000000e+00 x0 + 2.1700067520141602e+00 x1 + 4.7089293037870448e+00 x2 + 1.0218408383975225e+01 x3 + 2.2174015188064342e+01 x4 >= 7.7583429813403209e+00 35 | C15_2 : 1.0000000000000000e+00 x0 + 2.1700067520141602e+00 x1 + 4.7089293037870448e+00 x2 + 1.0218408383975225e+01 x3 + 2.2174015188064342e+01 x4 <= 7.7583434581738384e+00 36 | C16_1 : 1.0000000000000000e+00 x0 + 2.1750073432922363e+00 x1 + 4.7306569433751520e+00 x2 + 1.0289213590437360e+01 x3 + 2.2379115115903534e+01 x4 >= 7.8022496700305055e+00 37 | C16_2 : 1.0000000000000000e+00 x0 + 2.1750073432922363e+00 x1 + 4.7306569433751520e+00 x2 + 1.0289213590437360e+01 x3 + 2.2379115115903534e+01 x4 <= 7.8022501468640248e+00 38 | C17_1 : 1.0000000000000000e+00 x0 + 2.1800076961517334e+00 x1 + 4.7524335552807884e+00 x2 + 1.0360341725961861e+01 x3 + 2.2585624697358792e+01 x4 >= 7.8463742733019899e+00 39 | C17_2 : 1.0000000000000000e+00 x0 + 2.1800076961517334e+00 x1 + 4.7524335552807884e+00 x2 + 1.0360341725961861e+01 x3 + 2.2585624697358792e+01 x4 <= 7.8463747501355092e+00 40 | C18_1 : 1.0000000000000000e+00 x0 + 2.1850082874298096e+00 x1 + 4.7742612161369493e+00 x2 + 1.0431800323613954e+01 x3 + 2.2793570159909461e+01 x4 >= 7.8907220363635133e+00 41 | C18_2 : 1.0000000000000000e+00 x0 + 2.1850082874298096e+00 x1 + 4.7742612161369493e+00 x2 + 1.0431800323613954e+01 x3 + 2.2793570159909461e+01 x4 <= 7.8907225131970327e+00 42 | C19_1 : 1.0000000000000000e+00 x0 + 2.1900086402893066e+00 x1 + 4.7961378445418177e+00 x2 + 1.0503583319565111e+01 x3 + 2.3002938223846233e+01 x4 >= 7.9352900981921266e+00 43 | C19_2 : 1.0000000000000000e+00 x0 + 2.1900086402893066e+00 x1 + 4.7961378445418177e+00 x2 + 1.0503583319565111e+01 x3 + 2.3002938223846233e+01 x4 <= 7.9352905750256459e+00 44 | C20_1 : 1.0000000000000000e+00 x0 + 2.1950092315673828e+00 x1 + 4.8180655266660324e+00 x2 + 1.0575698309328505e+01 x3 + 2.3213755419247629e+01 x4 >= 7.9800837039965709e+00 45 | C20_2 : 1.0000000000000000e+00 x0 + 2.1950092315673828e+00 x1 + 4.8180655266660324e+00 x2 + 1.0575698309328505e+01 x3 + 2.3213755419247629e+01 x4 <= 7.9800841808300884e+00 46 | Bounds 47 | x0 free 48 | x1 free 49 | x2 free 50 | x3 free 51 | x4 free 52 | End 53 | -------------------------------------------------------------------------------- /dump/HPoly.txt: -------------------------------------------------------------------------------- 1 | -4.252186957269221245780954632209613919258117675781250000000000 2 | 14.324144485433413009900505130644887685775756835937500000000000 3 | -30.170931371586849678578801103867590427398681640625000000000000 4 | 46.602547745490745967344992095604538917541503906250000000000000 5 | -48.106537686671551057315809885039925575256347656250000000000000 6 | 31.471257441023958278947247890755534172058105468750000000000000 7 | -11.800706990221982550792745314538478851318359375000000000000000 8 | 1.932412950067042833879327190516050904989242553710937500000000 9 | -------------------------------------------------------------------------------- /dump/HRedInterval.txt: -------------------------------------------------------------------------------- 1 | 0.000000059604645 0.5000000000000000000000000000000000000000 -1.0078125000000000000000000000000000000000 -0.9921875000000000000000000000000000000000 2 | 0.000039160251617 0.6416015625000000000000000000000000000000 -0.6445312500000000000000000000000000000000 -0.6367187500000000000000000000000000000000 3 | 0.000078260898590 0.6411132812500000000000000000000000000000 -0.6445312500000000000000000000000000000000 -0.6367187500000000000000000000000000000000 4 | 0.000117361545563 0.9614257812500000000000000000000000000000 -0.0585927963256835937500000000000000000000 -0.0507822036743164062500000000000000000000 5 | 0.000190854072571 0.7817382812500000000000000000000000000000 -0.3554677963256835937500000000000000000000 -0.3476572036743164062500000000000000000000 6 | 0.000293970108032 0.6020507812500000000000000000000000000000 -0.7382812500000000000000000000000000000000 -0.7304687500000000000000000000000000000000 7 | 0.000450372695923 0.9223632812500000000000000000000000000000 -0.1210927963256835937500000000000000000000 -0.1132822036743164062500000000000000000000 8 | 0.000725269317627 0.7426757812500000000000000000000000000000 -0.4335927963256835937500000000000000000000 -0.4257822036743164062500000000000000000000 9 | 0.001099586486816 0.5629882812500000000000000000000000000000 -0.8320312500000000000000000000000000000000 -0.8242187500000000000000000000000000000000 10 | 0.001725196838379 0.8833007812500000000000000000000000000000 -0.1835927963256835937500000000000000000000 -0.1757822036743164062500000000000000000000 11 | 0.002748489379883 0.7036132812500000000000000000000000000000 -0.5117177963256835937500000000000000000000 -0.5039072036743164062500000000000000000000 12 | 0.004093170166016 0.5239257812500000000000000000000000000000 -0.9355463981628417968750000000000000000000 -0.9316411018371582031250000000000000000000 13 | 0.006595611572266 0.8442382812500000000000000000000000000000 -0.2480463981628417968750000000000000000000 -0.2441411018371582031250000000000000000000 14 | 0.010383605957031 0.6645507812500000000000000000000000000000 -0.5917963981628417968750000000000000000000 -0.5878911018371582031250000000000000000000 15 | 0.015388488769531 0.9848632812500000000000000000000000000000 -0.0253906250000000000000000000000000000000 -0.0214843750000000000000000000000000000000 16 | 0.025161743164062 0.8051757812500000000000000000000000000000 -0.3144531250000000000000000000000000000000 -0.3105468750000000000000000000000000000000 17 | 0.039093017578125 0.6254882812500000000000000000000000000000 -0.6777338981628417968750000000000000000000 -0.6738286018371582031250000000000000000000 18 | 0.059112548828125 0.9458007812500000000000000000000000000000 -0.0839838981628417968750000000000000000000 -0.0800786018371582031250000000000000000000 19 | 0.095764160156250 0.7661132812500000000000000000000000000000 -0.3857419490814208984375000000000000000000 -0.3837893009185791015625000000000000000000 20 | 0.146606445312500 0.5864257812500000000000000000000000000000 -0.7705078125000000000000000000000000000000 -0.7685546875000000000000000000000000000000 21 | 0.226684570312500 0.9067382812500000000000000000000000000000 -0.1416015625000000000000000000000000000000 -0.1396484375000000000000000000000000000000 22 | 0.363525390625000 0.7270507812500000000000000000000000000000 -0.4604490995407104492187500000000000000000 -0.4594727754592895507812500000000000000000 23 | 0.547363281250000 0.5473632812500000000000000000000000000000 -0.8698729872703552246093750000000000000000 -0.8693848252296447753906250000000000000000 24 | 0.867675781250000 0.8676757812500000000000000000000000000000 -0.2047729343175888061523437500000000000000 -0.2046508938074111938476562500000000000000 25 | 1.375976562500000 0.6879882812500000000000000000000000000000 -0.5396728515625000000000000000000000000000 -0.5394287109375000000000000000000000000000 26 | 2.033203125000000 0.5083007812500000000000000000000000000000 -0.9770507812500000000000000000000000000000 -0.9760742187500000000000000000000000000000 27 | 3.314453125000000 0.8286132812500000000000000000000000000000 -0.2719726562500000000000000000000000000000 -0.2709960937500000000000000000000000000000 28 | 5.191406250000000 0.6489257812500000000000000000000000000000 -0.6240231990814208984375000000000000000000 -0.6220705509185791015625000000000000000000 29 | 7.753906250000000 0.9692382812500000000000000000000000000000 -0.0458981990814208984375000000000000000000 -0.0439455509185791015625000000000000000000 30 | 12.632812500000000 0.7895507812500000000000000000000000000000 -0.3427731990814208984375000000000000000000 -0.3408205509185791015625000000000000000000 31 | 19.515625000000000 0.6098632812500000000000000000000000000000 -0.7167963981628417968750000000000000000000 -0.7128911018371582031250000000000000000000 32 | 29.765625000000000 0.9301757812500000000000000000000000000000 -0.1074213981628417968750000000000000000000 -0.1035161018371582031250000000000000000000 33 | 48.031250000000000 0.7504882812500000000000000000000000000000 -0.4160156250000000000000000000000000000000 -0.4121093750000000000000000000000000000000 34 | 73.062500000000000 0.5708007812500000000000000000000000000000 -0.8105463981628417968750000000000000000000 -0.8066411018371582031250000000000000000000 35 | 114.062500000000000 0.8911132812500000000000000000000000000000 -0.1699213981628417968750000000000000000000 -0.1660161018371582031250000000000000000000 36 | 182.125000000000000 0.7114257812500000000000000000000000000000 -0.4941406250000000000000000000000000000000 -0.4902343750000000000000000000000000000000 37 | 272.250000000000000 0.5317382812500000000000000000000000000000 -0.9179677963256835937500000000000000000000 -0.9101572036743164062500000000000000000000 38 | 436.250000000000000 0.8520507812500000000000000000000000000000 -0.2382812500000000000000000000000000000000 -0.2304687500000000000000000000000000000000 39 | 688.500000000000000 0.6723632812500000000000000000000000000000 -0.5742177963256835937500000000000000000000 -0.5664072036743164062500000000000000000000 40 | 1016.500000000000000 0.9926757812500000000000000000000000000000 -0.0117177963256835937500000000000000000000 -0.0039072036743164062500000000000000000000 41 | 1665.000000000000000 0.8129882812500000000000000000000000000000 -0.3007812500000000000000000000000000000000 -0.2929687500000000000000000000000000000000 42 | 2594.000000000000000 0.6333007812500000000000000000000000000000 -0.6601562500000000000000000000000000000000 -0.6523437500000000000000000000000000000000 43 | 3906.000000000000000 0.9536132812500000000000000000000000000000 -0.0742177963256835937500000000000000000000 -0.0664072036743164062500000000000000000000 44 | 6340.000000000000000 0.7739257812500000000000000000000000000000 -0.3710927963256835937500000000000000000000 -0.3632822036743164062500000000000000000000 45 | 9736.000000000000000 0.5942382812500000000000000000000000000000 -0.7539062500000000000000000000000000000000 -0.7460937500000000000000000000000000000000 46 | 0.000003516674042 0.9218750000000000000000000000000000000000 -0.1328125000000000000000000000000000000000 -0.1171875000000000000000000000000000000000 47 | 0.007888793945312 0.5048828125000000000000000000000000000000 -0.9863281250000000000000000000000000000000 -0.9824218750000000000000000000000000000000 48 | 0.122619628906250 0.9809570312500000000000000000000000000000 -0.0283203125000000000000000000000000000000 -0.0263671875000000000000000000000000000000 49 | 0.432128906250000 0.8642578125000000000000000000000000000000 -0.2114257812500000000000000000000000000000 -0.2104492187500000000000000000000000000000 50 | 0.690429687500000 0.6904296875000000000000000000000000000000 -0.5349120497703552246093750000000000000000 -0.5344238877296447753906250000000000000000 51 | 0.946777343750000 0.9467773437500000000000000000000000000000 -0.0789489671587944030761718750000000000000 -0.0788879469037055969238281250000000000000 52 | 1.264648437500000 0.6323242187500000000000000000000000000000 -0.6614989936351776123046875000000000000000 -0.6612549126148223876953125000000000000000 53 | 2.054687500000000 0.5136718750000000000000000000000000000000 -0.9614257812500000000000000000000000000000 -0.9604492187500000000000000000000000000000 54 | 7.019531250000000 0.8774414062500000000000000000000000000000 -0.1904294490814208984375000000000000000000 -0.1884768009185791015625000000000000000000 55 | 65.687500000000000 0.5131835937500000000000000000000000000000 -0.9628906250000000000000000000000000000000 -0.9589843750000000000000000000000000000000 56 | 0.000001370906830 0.7187500000000000000000000000000000000000 -0.4765625000000000000000000000000000000000 -0.4609375000000000000000000000000000000000 57 | 0.007804870605469 0.9990234375000000000000000000000000000000 -0.0019531250000000000000000000000000000000 0.0019531250000000000000000000000000000000 58 | 0.123107910156250 0.9848632812500000000000000000000000000000 -0.0224606990814208984375000000000000000000 -0.0205080509185791015625000000000000000000 59 | 0.490966796875000 0.9819335937500000000000000000000000000000 -0.0268553495407104492187500000000000000000 -0.0258790254592895507812500000000000000000 60 | 0.772949218750000 0.7729492187500000000000000000000000000000 -0.3717041015625000000000000000000000000000 -0.3714599609375000000000000000000000000000 61 | 0.954101562500000 0.9541015625000000000000000000000000000000 -0.0678405687212944030761718750000000000000 -0.0677795484662055969238281250000000000000 62 | 1.208984375000000 0.6044921875000000000000000000000000000000 -0.7264403998851776123046875000000000000000 -0.7261963188648223876953125000000000000000 63 | 1.980468750000000 0.9902343750000000000000000000000000000000 -0.0144042372703552246093750000000000000000 -0.0139160752296447753906250000000000000000 64 | 7.039062500000000 0.8798828125000000000000000000000000000000 -0.1865231990814208984375000000000000000000 -0.1845705509185791015625000000000000000000 65 | 63.781250000000000 0.9965820312500000000000000000000000000000 -0.0058588981628417968750000000000000000000 -0.0019536018371582031250000000000000000000 66 | 0.000008642673492 0.5664062500000000000000000000000000000000 -0.8203125000000000000000000000000000000000 -0.8046875000000000000000000000000000000000 67 | 0.015312194824219 0.9799804687500000000000000000000000000000 -0.0292963981628417968750000000000000000000 -0.0253911018371582031250000000000000000000 68 | 0.206420898437500 0.8256835937500000000000000000000000000000 -0.2763669490814208984375000000000000000000 -0.2744143009185791015625000000000000000000 69 | 0.517578125000000 0.5175781250000000000000000000000000000000 -0.9504394531250000000000000000000000000000 -0.9499511718750000000000000000000000000000 70 | 0.796386718750000 0.7963867187500000000000000000000000000000 -0.3284911811351776123046875000000000000000 -0.3282471001148223876953125000000000000000 71 | 0.983886718750000 0.9838867187500000000000000000000000000000 -0.0234451293945312500000000000000000000000 -0.0234298706054687500000000000000000000000 72 | 1.105468750000000 0.5527343750000000000000000000000000000000 -0.8554076999425888061523437500000000000000 -0.8552856594324111938476562500000000000000 73 | 1.611328125000000 0.8056640625000000000000000000000000000000 -0.3117675781250000000000000000000000000000 -0.3112792968750000000000000000000000000000 74 | 3.960937500000000 0.9902343750000000000000000000000000000000 -0.0141601562500000000000000000000000000000 -0.0131835937500000000000000000000000000000 75 | 33.375000000000000 0.5214843750000000000000000000000000000000 -0.9394531250000000000000000000000000000000 -0.9355468750000000000000000000000000000000 76 | 0.000019311904907 0.6328125000000000000000000000000000000000 -0.6601562500000000000000000000000000000000 -0.6523437500000000000000000000000000000000 77 | 0.063049316406250 0.5043945312500000000000000000000000000000 -0.9892578125000000000000000000000000000000 -0.9873046875000000000000000000000000000000 78 | 0.321044921875000 0.6420898437500000000000000000000000000000 -0.6391601562500000000000000000000000000000 -0.6381835937500000000000000000000000000000 79 | 0.707519531250000 0.7075195312500000000000000000000000000000 -0.4993896186351776123046875000000000000000 -0.4991455376148223876953125000000000000000 80 | 0.999511718750000 0.9995117187500000000000000000000000000000 -0.0007050037384033203125000000000000000000 -0.0007045269012451171875000000000000000000 81 | 1.040039062500000 0.5200195312500000000000000000000000000000 -0.9433746337890625000000000000000000000000 -0.9433441162109375000000000000000000000000 82 | 1.124023437500000 0.5620117187500000000000000000000000000000 -0.8313598632812500000000000000000000000000 -0.8312377929687500000000000000000000000000 83 | 1.180664062500000 0.5903320312500000000000000000000000000000 -0.7604369968175888061523437500000000000000 -0.7603149563074111938476562500000000000000 84 | 2.001953125000000 0.5004882812500000000000000000000000000000 -0.9995115995407104492187500000000000000000 -0.9985352754592895507812500000000000000000 85 | 9.468750000000000 0.5917968750000000000000000000000000000000 -0.7568356990814208984375000000000000000000 -0.7548830509185791015625000000000000000000 86 | 0.000046432018280 0.7607421875000000000000000000000000000000 -0.3945312500000000000000000000000000000000 -0.3867187500000000000000000000000000000000 87 | 0.020126342773438 0.6440429687500000000000000000000000000000 -0.6386713981628417968750000000000000000000 -0.6347661018371582031250000000000000000000 88 | 0.393066406250000 0.7861328125000000000000000000000000000000 -0.3471678495407104492187500000000000000000 -0.3461915254592895507812500000000000000000 89 | 0.808593750000000 0.8085937500000000000000000000000000000000 -0.3065185248851776123046875000000000000000 -0.3062744438648223876953125000000000000000 90 | 1.001953125000000 0.5009765625000000000000000000000000000000 -0.9971857070922851562500000000000000000000 -0.9971837997436523437500000000000000000000 91 | 1.025390625000000 0.5126953125000000000000000000000000000000 -0.9638519249856472015380859375000000000000 -0.9638214148581027984619140625000000000000 92 | 1.086914062500000 0.5434570312500000000000000000000000000000 -0.8797912597656250000000000000000000000000 -0.8797302246093750000000000000000000000000 93 | 1.185546875000000 0.5927734375000000000000000000000000000000 -0.7544555664062500000000000000000000000000 -0.7543334960937500000000000000000000000000 94 | 2.015625000000000 0.5039062500000000000000000000000000000000 -0.9897459745407104492187500000000000000000 -0.9887696504592895507812500000000000000000 95 | 20.609375000000000 0.6440429687500000000000000000000000000000 -0.6386713981628417968750000000000000000000 -0.6347661018371582031250000000000000000000 96 | 0.000076830387115 0.6293945312500000000000000000000000000000 -0.6679677963256835937500000000000000000000 -0.6601572036743164062500000000000000000000 97 | 0.045715332031250 0.7314453125000000000000000000000000000000 -0.4550781250000000000000000000000000000000 -0.4511718750000000000000000000000000000000 98 | 0.395996093750000 0.7919921875000000000000000000000000000000 -0.3374022245407104492187500000000000000000 -0.3364259004592895507812500000000000000000 99 | 0.759765625000000 0.7597656250000000000000000000000000000000 -0.3966064453125000000000000000000000000000 -0.3963623046875000000000000000000000000000 100 | 0.896484375000000 0.8964843750000000000000000000000000000000 -0.1576537936925888061523437500000000000000 -0.1575317531824111938476562500000000000000 101 | 0.981933593750000 0.9819335937500000000000000000000000000000 -0.0263137817382812500000000000000000000000 -0.0262985229492187500000000000000000000000 102 | 1.000976562500000 0.5004882812500000000000000000000000000000 -0.9985918997554108500480651855468750000000 -0.9985909463139250874519348144531250000000 103 | 1.136718750000000 0.5683593750000000000000000000000000000000 -0.8152465820312500000000000000000000000000 -0.8151245117187500000000000000000000000000 104 | 2.267578125000000 0.5668945312500000000000000000000000000000 -0.8198240995407104492187500000000000000000 -0.8188477754592895507812500000000000000000 105 | 16.640625000000000 0.5200195312500000000000000000000000000000 -0.9472656250000000000000000000000000000000 -0.9433593750000000000000000000000000000000 106 | 0.097900390625000 0.7832031250000000000000000000000000000000 -0.3544919490814208984375000000000000000000 -0.3525393009185791015625000000000000000000 107 | 0.605468750000000 0.6054687500000000000000000000000000000000 -0.7238769531250000000000000000000000000000 -0.7233886718750000000000000000000000000000 108 | 0.724609375000000 0.7246093750000000000000000000000000000000 -0.4649658203125000000000000000000000000000 -0.4647216796875000000000000000000000000000 109 | 0.805175781250000 0.8051757812500000000000000000000000000000 -0.3128661811351776123046875000000000000000 -0.3126221001148223876953125000000000000000 110 | 0.899902343750000 0.8999023437500000000000000000000000000000 -0.1521606445312500000000000000000000000000 -0.1520385742187500000000000000000000000000 111 | 0.967773437500000 0.9677734375000000000000000000000000000000 -0.0472869835793972015380859375000000000000 -0.0472564734518527984619140625000000000000 112 | 0.986328125000000 0.9863281250000000000000000000000000000000 -0.0198745727539062500000000000000000000000 -0.0198593139648437500000000000000000000000 113 | 0.995605468750000 0.9956054687500000000000000000000000000000 -0.0063571929931640625000000000000000000000 -0.0063533782958984375000000000000000000000 114 | 1.163085937500000 0.5815429687500000000000000000000000000000 -0.7820434570312500000000000000000000000000 -0.7819213867187500000000000000000000000000 115 | 1.816406250000000 0.9082031250000000000000000000000000000000 -0.1389160156250000000000000000000000000000 -0.1384277343750000000000000000000000000000 116 | 0.330078125000000 0.6601562500000000000000000000000000000000 -0.5991209745407104492187500000000000000000 -0.5981446504592895507812500000000000000000 117 | 0.643066406250000 0.6430664062500000000000000000000000000000 -0.6369628906250000000000000000000000000000 -0.6364746093750000000000000000000000000000 118 | 0.718750000000000 0.7187500000000000000000000000000000000000 -0.4764403998851776123046875000000000000000 -0.4761963188648223876953125000000000000000 119 | 0.836425781250000 0.8364257812500000000000000000000000000000 -0.2579345703125000000000000000000000000000 -0.2576904296875000000000000000000000000000 120 | 0.930664062500000 0.9306640625000000000000000000000000000000 -0.1036682128906250000000000000000000000000 -0.1036071777343750000000000000000000000000 121 | 0.988281250000000 0.9882812500000000000000000000000000000000 -0.0170211773365736007690429687500000000000 -0.0170059222728013992309570312500000000000 122 | 1.000000000000000 0.5000000000000000000000000000000000000000 -1.0000000298023223876953125000000000000000 -0.9999999701976776123046875000000000000000 123 | 1.017578125000000 0.5087890625000000000000000000000000000000 -0.9748611450195312500000000000000000000000 -0.9748458862304687500000000000000000000000 124 | 1.060546875000000 0.5302734375000000000000000000000000000000 -0.9151916503906250000000000000000000000000 -0.9151306152343750000000000000000000000000 125 | 1.352539062500000 0.6762695312500000000000000000000000000000 -0.5643310248851776123046875000000000000000 -0.5640869438648223876953125000000000000000 126 | 0.377929687500000 0.7558593750000000000000000000000000000000 -0.4047851562500000000000000000000000000000 -0.4038085937500000000000000000000000000000 127 | 0.718261718750000 0.7182617187500000000000000000000000000000 -0.4776611328125000000000000000000000000000 -0.4774169921875000000000000000000000000000 128 | 0.884277343750000 0.8842773437500000000000000000000000000000 -0.1774291843175888061523437500000000000000 -0.1773071438074111938476562500000000000000 129 | 0.974121093750000 0.9741210937500000000000000000000000000000 -0.0378570556640625000000000000000000000000 -0.0378265380859375000000000000000000000000 130 | 0.990722656250000 0.9907226562500000000000000000000000000000 -0.0134544363245368003845214843750000000000 -0.0134468087926506996154785156250000000000 131 | 1.581054687500000 0.7905273437500000000000000000000000000000 -0.3395995497703552246093750000000000000000 -0.3391113877296447753906250000000000000000 132 | 3.023437500000000 0.7558593750000000000000000000000000000000 -0.4047851562500000000000000000000000000000 -0.4038085937500000000000000000000000000000 133 | 0.937500000000000 0.9375000000000000000000000000000000000000 -0.0931701660156250000000000000000000000000 -0.0931091308593750000000000000000000000000 134 | -------------------------------------------------------------------------------- /dump/HRndInterval.txt: -------------------------------------------------------------------------------- 1 | 0.000000059604645 -24.000000000000000 -24.0078125000000000000000000000000000000000 -23.9921875000000000000000000000000000000000 2 | 0.000039160251617 -14.640625000000000 -14.6445312500000000000000000000000000000000 -14.6367187500000000000000000000000000000000 3 | 0.000078260898590 -13.640625000000000 -13.6445312500000000000000000000000000000000 -13.6367187500000000000000000000000000000000 4 | 0.000117361545563 -13.054687500000000 -13.0585927963256835937500000000000000000000 -13.0507822036743164062500000000000000000000 5 | 0.000190854072571 -12.351562500000000 -12.3554677963256835937500000000000000000000 -12.3476572036743164062500000000000000000000 6 | 0.000293970108032 -11.734375000000000 -11.7382812500000000000000000000000000000000 -11.7304687500000000000000000000000000000000 7 | 0.000450372695923 -11.117187500000000 -11.1210927963256835937500000000000000000000 -11.1132822036743164062500000000000000000000 8 | 0.000725269317627 -10.429687500000000 -10.4335927963256835937500000000000000000000 -10.4257822036743164062500000000000000000000 9 | 0.001099586486816 -9.828125000000000 -9.8320312500000000000000000000000000000000 -9.8242187500000000000000000000000000000000 10 | 0.001725196838379 -9.179687500000000 -9.1835927963256835937500000000000000000000 -9.1757822036743164062500000000000000000000 11 | 0.002748489379883 -8.507812500000000 -8.5117177963256835937500000000000000000000 -8.5039072036743164062500000000000000000000 12 | 0.004093170166016 -7.933593750000000 -7.9355463981628417968750000000000000000000 -7.9316411018371582031250000000000000000000 13 | 0.006595611572266 -7.246093750000000 -7.2480463981628417968750000000000000000000 -7.2441411018371582031250000000000000000000 14 | 0.010383605957031 -6.589843750000000 -6.5917963981628417968750000000000000000000 -6.5878911018371582031250000000000000000000 15 | 0.015388488769531 -6.023437500000000 -6.0253906250000000000000000000000000000000 -6.0214843750000000000000000000000000000000 16 | 0.025161743164062 -5.312500000000000 -5.3144531250000000000000000000000000000000 -5.3105468750000000000000000000000000000000 17 | 0.039093017578125 -4.675781250000000 -4.6777338981628417968750000000000000000000 -4.6738286018371582031250000000000000000000 18 | 0.059112548828125 -4.082031250000000 -4.0839838981628417968750000000000000000000 -4.0800786018371582031250000000000000000000 19 | 0.095764160156250 -3.384765625000000 -3.3857419490814208984375000000000000000000 -3.3837893009185791015625000000000000000000 20 | 0.146606445312500 -2.769531250000000 -2.7705078125000000000000000000000000000000 -2.7685546875000000000000000000000000000000 21 | 0.226684570312500 -2.140625000000000 -2.1416015625000000000000000000000000000000 -2.1396484375000000000000000000000000000000 22 | 0.363525390625000 -1.459960937500000 -1.4604490995407104492187500000000000000000 -1.4594727754592895507812500000000000000000 23 | 0.547363281250000 -0.869628906250000 -0.8698729872703552246093750000000000000000 -0.8693848252296447753906250000000000000000 24 | 0.867675781250000 -0.204711914062500 -0.2047729343175888061523437500000000000000 -0.2046508938074111938476562500000000000000 25 | 1.375976562500000 0.460449218750000 0.4603271484375000000000000000000000000000 0.4605712890625000000000000000000000000000 26 | 2.033203125000000 1.023437500000000 1.0229492187500000000000000000000000000000 1.0239257812500000000000000000000000000000 27 | 3.314453125000000 1.728515625000000 1.7280273437500000000000000000000000000000 1.7290039062500000000000000000000000000000 28 | 5.191406250000000 2.376953125000000 2.3759768009185791015625000000000000000000 2.3779294490814208984375000000000000000000 29 | 7.753906250000000 2.955078125000000 2.9541018009185791015625000000000000000000 2.9560544490814208984375000000000000000000 30 | 12.632812500000000 3.658203125000000 3.6572268009185791015625000000000000000000 3.6591794490814208984375000000000000000000 31 | 19.515625000000000 4.285156250000000 4.2832036018371582031250000000000000000000 4.2871088981628417968750000000000000000000 32 | 29.765625000000000 4.894531250000000 4.8925786018371582031250000000000000000000 4.8964838981628417968750000000000000000000 33 | 48.031250000000000 5.585937500000000 5.5839843750000000000000000000000000000000 5.5878906250000000000000000000000000000000 34 | 73.062500000000000 6.191406250000000 6.1894536018371582031250000000000000000000 6.1933588981628417968750000000000000000000 35 | 114.062500000000000 6.832031250000000 6.8300786018371582031250000000000000000000 6.8339838981628417968750000000000000000000 36 | 182.125000000000000 7.507812500000000 7.5058593750000000000000000000000000000000 7.5097656250000000000000000000000000000000 37 | 272.250000000000000 8.085937500000000 8.0820322036743164062500000000000000000000 8.0898427963256835937500000000000000000000 38 | 436.250000000000000 8.765625000000000 8.7617187500000000000000000000000000000000 8.7695312500000000000000000000000000000000 39 | 688.500000000000000 9.429687500000000 9.4257822036743164062500000000000000000000 9.4335927963256835937500000000000000000000 40 | 1016.500000000000000 9.992187500000000 9.9882822036743164062500000000000000000000 9.9960927963256835937500000000000000000000 41 | 1665.000000000000000 10.703125000000000 10.6992187500000000000000000000000000000000 10.7070312500000000000000000000000000000000 42 | 2594.000000000000000 11.343750000000000 11.3398437500000000000000000000000000000000 11.3476562500000000000000000000000000000000 43 | 3906.000000000000000 11.929687500000000 11.9257822036743164062500000000000000000000 11.9335927963256835937500000000000000000000 44 | 6340.000000000000000 12.632812500000000 12.6289072036743164062500000000000000000000 12.6367177963256835937500000000000000000000 45 | 9736.000000000000000 13.250000000000000 13.2460937500000000000000000000000000000000 13.2539062500000000000000000000000000000000 46 | 0.000003516674042 -18.125000000000000 -18.1328125000000000000000000000000000000000 -18.1171875000000000000000000000000000000000 47 | 0.007888793945312 -6.984375000000000 -6.9863281250000000000000000000000000000000 -6.9824218750000000000000000000000000000000 48 | 0.122619628906250 -3.027343750000000 -3.0283203125000000000000000000000000000000 -3.0263671875000000000000000000000000000000 49 | 0.432128906250000 -1.210937500000000 -1.2114257812500000000000000000000000000000 -1.2104492187500000000000000000000000000000 50 | 0.690429687500000 -0.534667968750000 -0.5349120497703552246093750000000000000000 -0.5344238877296447753906250000000000000000 51 | 0.946777343750000 -0.078918457031250 -0.0789489671587944030761718750000000000000 -0.0788879469037055969238281250000000000000 52 | 1.264648437500000 0.338623046875000 0.3385010063648223876953125000000000000000 0.3387450873851776123046875000000000000000 53 | 2.054687500000000 1.039062500000000 1.0385742187500000000000000000000000000000 1.0395507812500000000000000000000000000000 54 | 7.019531250000000 2.810546875000000 2.8095705509185791015625000000000000000000 2.8115231990814208984375000000000000000000 55 | 65.687500000000000 6.039062500000000 6.0371093750000000000000000000000000000000 6.0410156250000000000000000000000000000000 56 | 0.000001370906830 -19.468750000000000 -19.4765625000000000000000000000000000000000 -19.4609375000000000000000000000000000000000 57 | 0.007804870605469 -7.000000000000000 -7.0019531250000000000000000000000000000000 -6.9980468750000000000000000000000000000000 58 | 0.123107910156250 -3.021484375000000 -3.0224606990814208984375000000000000000000 -3.0205080509185791015625000000000000000000 59 | 0.490966796875000 -1.026367187500000 -1.0268553495407104492187500000000000000000 -1.0258790254592895507812500000000000000000 60 | 0.772949218750000 -0.371582031250000 -0.3717041015625000000000000000000000000000 -0.3714599609375000000000000000000000000000 61 | 0.954101562500000 -0.067810058593750 -0.0678405687212944030761718750000000000000 -0.0677795484662055969238281250000000000000 62 | 1.208984375000000 0.273681640625000 0.2735596001148223876953125000000000000000 0.2738036811351776123046875000000000000000 63 | 1.980468750000000 0.985839843750000 0.9855957627296447753906250000000000000000 0.9860839247703552246093750000000000000000 64 | 7.039062500000000 2.814453125000000 2.8134768009185791015625000000000000000000 2.8154294490814208984375000000000000000000 65 | 63.781250000000000 5.996093750000000 5.9941411018371582031250000000000000000000 5.9980463981628417968750000000000000000000 66 | 0.000008642673492 -16.812500000000000 -16.8203125000000000000000000000000000000000 -16.8046875000000000000000000000000000000000 67 | 0.015312194824219 -6.027343750000000 -6.0292963981628417968750000000000000000000 -6.0253911018371582031250000000000000000000 68 | 0.206420898437500 -2.275390625000000 -2.2763669490814208984375000000000000000000 -2.2744143009185791015625000000000000000000 69 | 0.517578125000000 -0.950195312500000 -0.9504394531250000000000000000000000000000 -0.9499511718750000000000000000000000000000 70 | 0.796386718750000 -0.328369140625000 -0.3284911811351776123046875000000000000000 -0.3282471001148223876953125000000000000000 71 | 0.983886718750000 -0.023437500000000 -0.0234451293945312500000000000000000000000 -0.0234298706054687500000000000000000000000 72 | 1.105468750000000 0.144653320312500 0.1445923000574111938476562500000000000000 0.1447143405675888061523437500000000000000 73 | 1.611328125000000 0.688476562500000 0.6882324218750000000000000000000000000000 0.6887207031250000000000000000000000000000 74 | 3.960937500000000 1.986328125000000 1.9858398437500000000000000000000000000000 1.9868164062500000000000000000000000000000 75 | 33.375000000000000 5.062500000000000 5.0605468750000000000000000000000000000000 5.0644531250000000000000000000000000000000 76 | 0.000019311904907 -15.656250000000000 -15.6601562500000000000000000000000000000000 -15.6523437500000000000000000000000000000000 77 | 0.063049316406250 -3.988281250000000 -3.9892578125000000000000000000000000000000 -3.9873046875000000000000000000000000000000 78 | 0.321044921875000 -1.638671875000000 -1.6391601562500000000000000000000000000000 -1.6381835937500000000000000000000000000000 79 | 0.707519531250000 -0.499267578125000 -0.4993896186351776123046875000000000000000 -0.4991455376148223876953125000000000000000 80 | 0.999511718750000 -0.000704765319824 -0.0007050037384033203125000000000000000000 -0.0007045269012451171875000000000000000000 81 | 1.040039062500000 0.056640625000000 0.0566253662109375000000000000000000000000 0.0566558837890625000000000000000000000000 82 | 1.124023437500000 0.168701171875000 0.1686401367187500000000000000000000000000 0.1687622070312500000000000000000000000000 83 | 1.180664062500000 0.239624023437500 0.2395630031824111938476562500000000000000 0.2396850436925888061523437500000000000000 84 | 2.001953125000000 1.000976562500000 1.0004884004592895507812500000000000000000 1.0014647245407104492187500000000000000000 85 | 9.468750000000000 3.244140625000000 3.2431643009185791015625000000000000000000 3.2451169490814208984375000000000000000000 86 | 0.000046432018280 -14.390625000000000 -14.3945312500000000000000000000000000000000 -14.3867187500000000000000000000000000000000 87 | 0.020126342773438 -5.636718750000000 -5.6386713981628417968750000000000000000000 -5.6347661018371582031250000000000000000000 88 | 0.393066406250000 -1.346679687500000 -1.3471678495407104492187500000000000000000 -1.3461915254592895507812500000000000000000 89 | 0.808593750000000 -0.306396484375000 -0.3065185248851776123046875000000000000000 -0.3062744438648223876953125000000000000000 90 | 1.001953125000000 0.002815246582031 0.0028142929077148437500000000000000000000 0.0028162002563476562500000000000000000000 91 | 1.025390625000000 0.036163330078125 0.0361480750143527984619140625000000000000 0.0361785851418972015380859375000000000000 92 | 1.086914062500000 0.120239257812500 0.1202087402343750000000000000000000000000 0.1202697753906250000000000000000000000000 93 | 1.185546875000000 0.245605468750000 0.2455444335937500000000000000000000000000 0.2456665039062500000000000000000000000000 94 | 2.015625000000000 1.010742187500000 1.0102540254592895507812500000000000000000 1.0112303495407104492187500000000000000000 95 | 20.609375000000000 4.363281250000000 4.3613286018371582031250000000000000000000 4.3652338981628417968750000000000000000000 96 | 0.000076830387115 -13.664062500000000 -13.6679677963256835937500000000000000000000 -13.6601572036743164062500000000000000000000 97 | 0.045715332031250 -4.453125000000000 -4.4550781250000000000000000000000000000000 -4.4511718750000000000000000000000000000000 98 | 0.395996093750000 -1.336914062500000 -1.3374022245407104492187500000000000000000 -1.3364259004592895507812500000000000000000 99 | 0.759765625000000 -0.396484375000000 -0.3966064453125000000000000000000000000000 -0.3963623046875000000000000000000000000000 100 | 0.896484375000000 -0.157592773437500 -0.1576537936925888061523437500000000000000 -0.1575317531824111938476562500000000000000 101 | 0.981933593750000 -0.026306152343750 -0.0263137817382812500000000000000000000000 -0.0262985229492187500000000000000000000000 102 | 1.000976562500000 0.001408576965332 0.0014081002445891499519348144531250000000 0.0014090536860749125480651855468750000000 103 | 1.136718750000000 0.184814453125000 0.1847534179687500000000000000000000000000 0.1848754882812500000000000000000000000000 104 | 2.267578125000000 1.180664062500000 1.1801759004592895507812500000000000000000 1.1811522245407104492187500000000000000000 105 | 16.640625000000000 4.054687500000000 4.0527343750000000000000000000000000000000 4.0566406250000000000000000000000000000000 106 | 0.097900390625000 -3.353515625000000 -3.3544919490814208984375000000000000000000 -3.3525393009185791015625000000000000000000 107 | 0.605468750000000 -0.723632812500000 -0.7238769531250000000000000000000000000000 -0.7233886718750000000000000000000000000000 108 | 0.724609375000000 -0.464843750000000 -0.4649658203125000000000000000000000000000 -0.4647216796875000000000000000000000000000 109 | 0.805175781250000 -0.312744140625000 -0.3128661811351776123046875000000000000000 -0.3126221001148223876953125000000000000000 110 | 0.899902343750000 -0.152099609375000 -0.1521606445312500000000000000000000000000 -0.1520385742187500000000000000000000000000 111 | 0.967773437500000 -0.047271728515625 -0.0472869835793972015380859375000000000000 -0.0472564734518527984619140625000000000000 112 | 0.986328125000000 -0.019866943359375 -0.0198745727539062500000000000000000000000 -0.0198593139648437500000000000000000000000 113 | 0.995605468750000 -0.006355285644531 -0.0063571929931640625000000000000000000000 -0.0063533782958984375000000000000000000000 114 | 1.163085937500000 0.218017578125000 0.2179565429687500000000000000000000000000 0.2180786132812500000000000000000000000000 115 | 1.816406250000000 0.861328125000000 0.8610839843750000000000000000000000000000 0.8615722656250000000000000000000000000000 116 | 0.330078125000000 -1.598632812500000 -1.5991209745407104492187500000000000000000 -1.5981446504592895507812500000000000000000 117 | 0.643066406250000 -0.636718750000000 -0.6369628906250000000000000000000000000000 -0.6364746093750000000000000000000000000000 118 | 0.718750000000000 -0.476318359375000 -0.4764403998851776123046875000000000000000 -0.4761963188648223876953125000000000000000 119 | 0.836425781250000 -0.257812500000000 -0.2579345703125000000000000000000000000000 -0.2576904296875000000000000000000000000000 120 | 0.930664062500000 -0.103637695312500 -0.1036682128906250000000000000000000000000 -0.1036071777343750000000000000000000000000 121 | 0.988281250000000 -0.017013549804688 -0.0170211773365736007690429687500000000000 -0.0170059222728013992309570312500000000000 122 | 1.000000000000000 0.000000000000000 -0.0000000298023223876953125000000000000000 0.0000000298023223876953125000000000000000 123 | 1.017578125000000 0.025146484375000 0.0251388549804687500000000000000000000000 0.0251541137695312500000000000000000000000 124 | 1.060546875000000 0.084838867187500 0.0848083496093750000000000000000000000000 0.0848693847656250000000000000000000000000 125 | 1.352539062500000 0.435791015625000 0.4356689751148223876953125000000000000000 0.4359130561351776123046875000000000000000 126 | 0.377929687500000 -1.404296875000000 -1.4047851562500000000000000000000000000000 -1.4038085937500000000000000000000000000000 127 | 0.718261718750000 -0.477539062500000 -0.4776611328125000000000000000000000000000 -0.4774169921875000000000000000000000000000 128 | 0.884277343750000 -0.177368164062500 -0.1774291843175888061523437500000000000000 -0.1773071438074111938476562500000000000000 129 | 0.974121093750000 -0.037841796875000 -0.0378570556640625000000000000000000000000 -0.0378265380859375000000000000000000000000 130 | 0.990722656250000 -0.013450622558594 -0.0134544363245368003845214843750000000000 -0.0134468087926506996154785156250000000000 131 | 1.581054687500000 0.660644531250000 0.6604004502296447753906250000000000000000 0.6608886122703552246093750000000000000000 132 | 3.023437500000000 1.595703125000000 1.5952148437500000000000000000000000000000 1.5961914062500000000000000000000000000000 133 | 0.937500000000000 -0.093139648437500 -0.0931701660156250000000000000000000000000 -0.0931091308593750000000000000000000000000 134 | -------------------------------------------------------------------------------- /dump/poly.txt: -------------------------------------------------------------------------------- 1 | -3.637283046442948641896464323508553206920623779296875000000000 2 | 8.610308486984976639178057666867971420288085937500000000000000 3 | -8.564617249525849018709777737967669963836669921875000000000000 4 | 3.786264922819144285170978037058375775814056396484375000000000 -------------------------------------------------------------------------------- /float32/Makefile: -------------------------------------------------------------------------------- 1 | CXX=g++ 2 | CXXFLAGS=-O2 -I/home/soplex-4.0.1//src/ -std=c++11 3 | LIBS= /home/soplex-4.0.1//build/lib/libsoplex.a -lgmp -lz -lm -lmpfr 4 | TARGET1=hlog2 5 | TARGET2=hexpm1 6 | TARGET3=flog2 7 | TARGET4=fexpm1 8 | 9 | 10 | 11 | all: $(TARGET1) $(TARGET2) $(TARGET3) 12 | 13 | .PHONY: $(TARGET1) $(TARGET2) $(TARGET3) 14 | 15 | $(TARGET3): flog2.cpp fhelper.cpp 16 | $(CXX) $(CXXFLAGS) $< fhelper.cpp $(LIBS) -o $@ 17 | ./$(TARGET3) 18 | 19 | $(TARGET4): fexpm1.cpp fhelper.cpp 20 | $(CXX) $(CXXFLAGS) $< fhelper.cpp $(LIBS) -o $@ 21 | ./$(TARGET4) 22 | 23 | clean: 24 | rm -f $(TARGET1) $(TARGET2) $(TARGET3) 25 | 26 | -------------------------------------------------------------------------------- /float32/fexpm1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "luts.h" 15 | #include "fhelper.hpp" 16 | 17 | using namespace std; 18 | using namespace soplex; 19 | 20 | int ComputeSpecialCase(float x) 21 | { 22 | floatX fx; 23 | fx.f = x; 24 | if (x <= 0.0) 25 | { 26 | return -1; 27 | } 28 | else if (fx.x >= 0x7F800000) 29 | { 30 | return -1; 31 | } 32 | else if (fx.f == 2.0037834644317626953125000000000000000000) 33 | { 34 | return -1; 35 | } 36 | 37 | return 0; 38 | } 39 | double RangeReduction(float x) 40 | { 41 | // return (double)x; 42 | double xp = x * 92.332482616893656768297660164535045623779296875; 43 | int N = (int)xp; 44 | 45 | return x - N * 46 | 0.01083042469624914509729318723429969395510852336883544921875; 47 | } 48 | 49 | double OutputCompensation(float x, double yp) 50 | { 51 | // return yp; 52 | double xp = x * 92.332482616893656768297660164535045623779296875; 53 | int N = (int)xp; 54 | int N2 = N % 64; 55 | if (N2 < 0) 56 | N2 += 64; 57 | int N1 = N - N2; 58 | int M = N1 / 64; 59 | 60 | return yp * ldexp(exp2JBy64[N2], M); 61 | } 62 | 63 | double GuessInitial(float x, double &lb, double &ub) 64 | { 65 | 66 | double xrr = RangeReduction(x); 67 | double yp = expm1(xrr); 68 | lb = yp; 69 | ub = yp; 70 | return 0; 71 | } 72 | 73 | float EvaluateFunction(mpfr_t y, float x) 74 | { 75 | mpfr_set_flt(y, x, MPFR_RNDN); 76 | mpfr_expm1(y, y, MPFR_RNDN); 77 | float h = mpfr_get_flt(y, MPFR_RNDN); 78 | return h; 79 | } 80 | 81 | #define GROW 20 82 | #define SPACING 0.1 83 | #define OVERLAP 0.00001 84 | int main() 85 | { 86 | for (float low = 2; low < 3; low += SPACING) 87 | { 88 | float high = low + SPACING + OVERLAP; 89 | // printf("Generating FloatSample...\n"); 90 | vector X = GenerateFloatSample(1, low, high); 91 | 92 | // printf("Generating all float values...\n"); 93 | 94 | vector Test = GenerateFloatSample(-1, low, high); 95 | vector Incorrect; 96 | Polynomial P; 97 | 98 | do 99 | { 100 | printf("Low: %f, High: %f\n", low, high); 101 | if (Incorrect.size() < GROW) 102 | { 103 | for (int i = 0; i < Incorrect.size(); i++) 104 | { 105 | RndInterval I = Incorrect.at(i); 106 | X.push_back(I); 107 | } 108 | } 109 | else 110 | { 111 | for (int i = 0; i < GROW; i++) 112 | { 113 | RndInterval I = Incorrect.at(floor(i * Incorrect.size() / GROW)); 114 | for (size_t j = 0; j < X.size(); j++) 115 | { 116 | if (X.at(j).x_orig == I.x_orig || X.at(j).x_rr == I.x_rr) 117 | { 118 | printf("Duplicate\n"); 119 | break; 120 | } 121 | } 122 | X.push_back(I); 123 | } 124 | } 125 | printf("Sample size: %ld\n", X.size()); 126 | // printf("Generating RndIntervals...\n"); 127 | vector L = CalcRndIntervals(X); 128 | 129 | // printf("Generating RedIntervals...\n"); 130 | vector L2 = CalcRedIntervals(L); 131 | 132 | // printf("Generating Polynomial...\n"); 133 | P = GeneratePolynomial(L2); 134 | 135 | Incorrect = Verify(L2, P, 1); 136 | if (Incorrect.size() > 0) 137 | { 138 | printf("FAILED IN SAMPLE: %ld\n", Incorrect.size()); 139 | // return -1; 140 | } 141 | Incorrect = Verify(Test, P, 0); 142 | // print_poly(P); 143 | printf("----------------------------------------\n"); 144 | 145 | } while (Incorrect.size() > 0); 146 | 147 | FullTest(P, low, high); 148 | std::string filename = "fexpm1poly/fexmp1_" + std::to_string(low) + "_" + std::to_string(high) + ".txt"; 149 | writePolynomialToFile(P, filename); 150 | printf("Successfully written to file: %s\n", filename.c_str()); 151 | print_poly(P); 152 | } 153 | printf("Finished!\n"); 154 | } -------------------------------------------------------------------------------- /float32/fexpm1poly/fexmp1_0.500000_0.525010.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 4556524236219550525 4607145031908278121 4602822795623313202 4594081698521442658 4589650947202769492 3 | -------------------------------------------------------------------------------- /float32/fexpm1poly/fexmp1_1.500000_1.550010.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 13817174769264982400 4609239627350046808 13818434082846332650 4604175117595760326 13818260009918566391 4586780094964506627 3 | -------------------------------------------------------------------------------- /float32/fexpm1poly/fexmp1_1.500000_1.600010.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 13813419807332463847 4608442431059304780 4589622125531242093 4602801108211158389 13815868832406021266 4585832951424436531 3 | -------------------------------------------------------------------------------- /float32/fexpm1poly/fexmp1_2.000000_2.100010.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 13827182514927681858 4613385990475662091 13832895408384768417 4608866143210339981 13823223032808838737 4589351527913121971 3 | -------------------------------------------------------------------------------- /float32/fexpm1poly/fexmp1_2.000000_2.100100.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 13827182514927681858 4613385990475662091 13832895408384768417 4608866143210339981 13823223032808838737 4589351527913121971 3 | -------------------------------------------------------------------------------- /float32/fexpm1poly/fexmp1_2.100000_2.200010.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 13829610474527045534 4614827929701209281 13835347058189639149 4610168567830859871 13824461067062924332 4589822314545333613 3 | -------------------------------------------------------------------------------- /float32/fexpm1poly/fexmp1_2.100000_2.200100.txt: -------------------------------------------------------------------------------- 1 | 7 2 | 13827807774059451101 4613567603970165767 13832699109725159519 4608343599277997475 13821909702923679708 4586672139202450952 4566873692454337370 3 | -------------------------------------------------------------------------------- /float32/fexpm1poly/fexmp1_2.200000_2.300010.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 13831991577493971090 4616590631570313381 13837309156522782870 4611817054687908701 13826063045902153720 4590408070633707247 3 | -------------------------------------------------------------------------------- /float32/fexpm1poly/fexmp1_2.200000_2.300100.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 13831991577493971090 4616590631570313381 13837309156522782870 4611817054687908701 13826063045902153720 4590408070633707247 3 | -------------------------------------------------------------------------------- /float32/fexpm1poly/fexmp1_2.300000_2.400100.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 13834365747648669083 4617876432070616381 13839537717248149894 4612782781916892792 13826900100021722275 4590988543049052110 3 | -------------------------------------------------------------------------------- /float32/fhelper.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "fhelper.hpp" 15 | #include 16 | 17 | using namespace std; 18 | using namespace soplex; 19 | 20 | vector GenerateFloatSample(int sample_size, float min, float max) 21 | { 22 | vector X; 23 | size_t n = 0; 24 | float h; 25 | 26 | if (sample_size == -1) 27 | { 28 | for (h = min; h < max; h = nextafterf(h, max)) 29 | { 30 | if (h == INFINITY || h == -INFINITY) 31 | { 32 | break; 33 | } 34 | if (ComputeSpecialCase(h) == -1) 35 | { 36 | continue; 37 | } 38 | n++; 39 | RndInterval I; 40 | I.x_orig = h; 41 | I.x_rr = RangeReduction(h); 42 | X.push_back(I); 43 | // printf("Sample size: %ld\n", n); 44 | 45 | // for (int i = 0; i < 6; i++) 46 | // { 47 | // h = nextafterf(h, max); 48 | // } 49 | } 50 | } 51 | else 52 | { 53 | // long skip = (1 << 16) / sample_size; 54 | // unsigned long long skip = (1 << 31) / sample_size; 55 | h = min; 56 | 57 | for (int i = 0; i < sample_size; i++) 58 | { 59 | 60 | if (h == INFINITY || h == -INFINITY) 61 | { 62 | break; 63 | } 64 | if (ComputeSpecialCase(h) == -1) 65 | { 66 | continue; 67 | } 68 | 69 | n++; 70 | RndInterval I; 71 | I.x_orig = h; 72 | I.x_rr = RangeReduction(h); 73 | X.push_back(I); 74 | for (int j = 0; j < 30000; j++) 75 | { 76 | h = nextafterf(h, max); 77 | } 78 | } 79 | } 80 | printf("Sample size: %ld\n", X.size()); 81 | return X; 82 | } 83 | 84 | vector CalcRndIntervals(vector X) 85 | { 86 | FILE *fptr; 87 | fptr = fopen("../dump/FRndInterval.txt", "w"); 88 | 89 | float y; 90 | double l, u; 91 | 92 | mpfr_t y_mpfr, x_mpfr; 93 | mpfr_inits2(200, y_mpfr, x_mpfr, NULL); 94 | 95 | vector L; 96 | 97 | for (size_t i = 0; i < X.size(); i++) 98 | { 99 | 100 | RndInterval I; 101 | 102 | I.x_orig = X.at(i).x_orig; 103 | I.x_rr = X.at(i).x_rr; 104 | y = EvaluateFunction(y_mpfr, X.at(i).x_orig); 105 | 106 | float lhalf(nextafterf((float)y, -INFINITY)); 107 | float uhalf(nextafterf((float)y, INFINITY)); 108 | 109 | l = ((double)y + (double)lhalf) / 2; 110 | u = ((double)y + (double)uhalf) / 2; 111 | 112 | // printf("x: %4.40f y: %4.40f l: %4.40f u: %4.40f\n", (double)X.at(i).x_orig, (double)y, l, u); 113 | while ((float)l != (float)y) 114 | { 115 | l = nextafter(l, INFINITY); 116 | } 117 | // l = nextafter(l, INFINITY); 118 | 119 | assert((float)l == y); 120 | 121 | while ((float)u != y) 122 | { 123 | u = nextafter(u, -INFINITY); 124 | } 125 | // u = nextafter(u, -INFINITY); 126 | 127 | assert((float)u == (float)y); 128 | assert(l < u); 129 | 130 | // fprintf(fptr, "%4.40f %4.40f %4.40f %4.40f \n", (double)X.at(i).x_orig, (double)y, l, u); 131 | I.y = y; 132 | I.l = l; 133 | I.u = u; 134 | 135 | L.push_back(I); 136 | } 137 | std::sort(L.begin(), L.end()); 138 | L.erase(std::unique(L.begin(), L.end()), L.end()); 139 | return L; 140 | } 141 | 142 | vector CalcRedIntervals(vector X) 143 | { 144 | FILE *fptr; 145 | fptr = fopen("../dump/FRedInterval.txt", "w"); 146 | float yp; 147 | double lp, up; 148 | 149 | mpfr_t yp_mpfr, xrr_mpfr; 150 | mpfr_inits2(200, yp_mpfr, xrr_mpfr, NULL); 151 | 152 | vector L; 153 | 154 | for (size_t i = 0; i < X.size(); i++) 155 | { 156 | RndInterval I; 157 | 158 | I.x_orig = X.at(i).x_orig; 159 | I.x_rr = X.at(i).x_rr; 160 | 161 | I.y = X.at(i).y; 162 | 163 | I.l = X.at(i).l; 164 | I.u = X.at(i).u; 165 | 166 | // lp = InverseOutputCompensation(X.at(i).x_orig, X.at(i).l); 167 | // up = InverseOutputCompensation(X.at(i).x_orig, X.at(i).u); 168 | // while (OutputCompensation(X.at(i).x_orig, lp) < X.at(i).l) 169 | // { 170 | // lp = nextafter(lp, INFINITY); 171 | // } 172 | 173 | // while (OutputCompensation(X.at(i).x_orig, up) > X.at(i).u) 174 | // { 175 | // up = nextafter(up, -INFINITY); 176 | // } 177 | 178 | GuessInitial(X.at(i).x_orig, lp, up); 179 | unsigned long long step = 0x8000000000000llu; 180 | double oc; 181 | while (step > 0) 182 | // while (step >= 0x0000000000800llu) 183 | { 184 | 185 | doubleX dx; 186 | dx.d = lp; 187 | if (dx.d >= 0) 188 | { 189 | dx.x -= step; 190 | } 191 | else 192 | { 193 | dx.x += step; 194 | } 195 | 196 | oc = OutputCompensation(I.x_orig, dx.d); 197 | 198 | if (oc >= I.l && oc <= I.u) 199 | { 200 | lp = dx.d; 201 | } 202 | else 203 | { 204 | step /= 2; 205 | } 206 | } 207 | 208 | step = 0x8000000000000llu; 209 | while (step > 0) 210 | // while (step >= 0x0000000000800llu) 211 | { 212 | doubleX dx; 213 | dx.d = up; 214 | if (dx.d >= 0) 215 | { 216 | dx.x += step; 217 | } 218 | else 219 | { 220 | dx.x -= step; 221 | } 222 | 223 | oc = OutputCompensation(I.x_orig, dx.d); 224 | if (oc > I.l && oc < I.u) 225 | { 226 | up = dx.d; 227 | } 228 | else 229 | { 230 | step /= 2; 231 | } 232 | } 233 | 234 | step = 0x0000000000800llu; 235 | doubleX dx; 236 | dx.d = up; 237 | if (dx.d >= 0) 238 | { 239 | dx.x -= step; 240 | } 241 | else 242 | { 243 | dx.x += step; 244 | } 245 | up = dx.d; 246 | 247 | dx.d = lp; 248 | if (dx.d >= 0) 249 | { 250 | dx.x += step; 251 | } 252 | else 253 | { 254 | dx.x -= step; 255 | } 256 | lp = dx.d; 257 | 258 | oc = OutputCompensation(I.x_orig, lp); 259 | // printf("lp: %4.40f\n", lp); 260 | // printf("up: %4.40f\n", up); 261 | // printf("oc: %4.40f\n", oc); 262 | // printf("I.y: %4.40f\n", I.y); 263 | assert((float)oc == I.y); 264 | 265 | oc = OutputCompensation(I.x_orig, up); 266 | assert((float)oc == I.y); 267 | assert(lp <= up); 268 | 269 | // fprintf(fptr, "%4.40f %4.40f %4.40f %4.40f %4.40f \n", (double)X.at(i).x_orig, X.at(i).x_rr, X.at(i).y, X.at(i).l, X.at(i).u); 270 | // fprintf(fptr, "%4.40f %4.40f %4.40f \n", (double)X.at(i).yp, X.at(i).lp, X.at(i).up); 271 | I.lp = lp; 272 | I.up = up; 273 | 274 | L.push_back(I); 275 | } 276 | return L; 277 | } 278 | 279 | Polynomial GeneratePolynomial(vector L) 280 | { 281 | 282 | cout << "Solving... [1, 50] \n"; 283 | for (int termsize = 1; termsize < 50; termsize++) 284 | { 285 | // printf("Termsize: %d\n", termsize); 286 | SoPlex mysoplex; 287 | mysoplex.setBoolParam(SoPlex::RATFACJUMP, true); 288 | mysoplex.setIntParam(SoPlex::SOLVEMODE, 2); 289 | mysoplex.setIntParam(SoPlex::CHECKMODE, 2); 290 | mysoplex.setIntParam(SoPlex::SYNCMODE, 1); 291 | mysoplex.setIntParam(SoPlex::READMODE, 1); 292 | mysoplex.setRealParam(SoPlex::FEASTOL, 0.0); 293 | mysoplex.setRealParam(SoPlex::OPTTOL, 0.0); 294 | mysoplex.setRealParam(SoPlex::EPSILON_ZERO, 0.0); 295 | mysoplex.setRealParam(SoPlex::EPSILON_FACTORIZATION, 0.0); 296 | mysoplex.setRealParam(SoPlex::EPSILON_UPDATE, 0.0); 297 | mysoplex.setRealParam(SoPlex::EPSILON_PIVOT, 0.0); 298 | mysoplex.setIntParam(SoPlex::VERBOSITY, 0); 299 | mysoplex.setRealParam(SoPlex::TIMELIMIT, 10 * 60); 300 | mysoplex.setIntParam(SoPlex::OBJSENSE, SoPlex::OBJSENSE_MINIMIZE); 301 | DSVectorRational dummycol(0); 302 | 303 | for (int i = 0; i < termsize; i++) 304 | { 305 | auto column = LPColRational(1.0, dummycol, infinity, -infinity); 306 | mysoplex.addColRational(column); 307 | } 308 | 309 | for (int i = 0; i < L.size(); i++) 310 | { 311 | DSVectorRational row1(termsize); 312 | Rational acc(1.0); 313 | Rational xval(L.at(i).x_rr); 314 | row1.add(0, 1.0); 315 | 316 | for (int j = 1; j < termsize; j++) 317 | { 318 | acc = acc * xval; 319 | row1.add(j, acc); 320 | } 321 | double lbnd = (L.at(i).lp); 322 | double ubnd = (L.at(i).up); 323 | 324 | mysoplex.addRowRational(LPRowRational(lbnd, row1, ubnd)); 325 | } 326 | 327 | mysoplex.writeFileRational("../dump/FSoplexRational.lp", NULL, NULL, NULL); 328 | mysoplex.writeFileReal("../dump/FSoplexReal.lp", NULL, NULL, NULL); 329 | 330 | SPxSolver::Status stat; 331 | 332 | stat = mysoplex.optimize(); 333 | Polynomial P; 334 | 335 | if (stat == SPxSolver::OPTIMAL) 336 | { 337 | DVectorRational prim(termsize); 338 | mysoplex.getPrimalRational(prim); 339 | 340 | P.termsize = termsize; 341 | for (int i = 0; i < termsize; i++) 342 | { 343 | P.coefficients.push_back(prim[i]); 344 | // P.coefficients.push_back(prim[i].doubleValue()) 345 | // P.coefficients.push_back(mpq_get_d(*(prim[i].getMpqPtr()))); 346 | } 347 | std::cout << "Status: " << stat << " with " << termsize << " terms" << std::endl; 348 | 349 | return P; 350 | } 351 | else if (stat == SPxSolver::UNBOUNDED) 352 | { 353 | DVectorRational prim(termsize); 354 | mysoplex.getPrimalRational(prim); 355 | 356 | P.termsize = termsize; 357 | std::cout << "Unbounded solution\n"; 358 | for (int i = 0; i < termsize; i++) 359 | { 360 | P.coefficients.push_back(0.0); 361 | } 362 | } 363 | 364 | // std::cout << "Status: " << stat << std::endl; 365 | } 366 | 367 | Polynomial N; 368 | return N; 369 | } 370 | 371 | long double EvaulutePoly(Polynomial P, double xval) 372 | { 373 | long double acc = 0.0; 374 | long double power = 1.0; 375 | 376 | for (int i = 0; i < P.termsize; i++) 377 | { 378 | 379 | acc += P.coefficients.at(i) * power; 380 | power *= xval; 381 | } 382 | 383 | return acc; 384 | } 385 | 386 | vector Verify(vector L2, Polynomial P, int debug = 0) 387 | { 388 | size_t n = 0; 389 | size_t correct = 0; 390 | 391 | vector Incorrect; 392 | for (size_t i = 0; i < L2.size(); i++) 393 | { 394 | n++; 395 | float h = L2.at(i).x_orig; 396 | 397 | double x = (double)h; 398 | double range_reduced = RangeReduction(h); 399 | long double eval = EvaulutePoly(P, range_reduced); 400 | double oc = OutputCompensation(h, eval); 401 | float y = (float)oc; 402 | 403 | mpfr_t y_mpfr; 404 | mpfr_inits2(200, y_mpfr, NULL); 405 | float oracle = EvaluateFunction(y_mpfr, h); 406 | if (y != oracle) 407 | { 408 | RndInterval I; 409 | I.x_orig = h; 410 | I.x_rr = range_reduced; 411 | // printf("I.x_orig: %4.40f\n", I.x_orig); 412 | Incorrect.push_back(I); 413 | if (debug) 414 | { 415 | printf("x: %4.40f y: %4.40f oracle: %4.40f\n", h, y, oracle); 416 | // printf("xrr: %4.40f eval: %4.40f\n", range_reduced, eval); 417 | // printf("lp: %4.40f up: %4.40f\n", L2.at(i).lp, L2.at(i).up); 418 | } 419 | } 420 | else 421 | { 422 | correct += 1; 423 | } 424 | } 425 | 426 | printf("In sample, Correct: %ld Incorrect: %ld\n", correct, n - correct); 427 | return Incorrect; 428 | } 429 | 430 | void print_poly(Polynomial P) 431 | { 432 | FILE *fptr = fopen("../dump/FPoly.txt", "w"); 433 | for (int i = 0; i < P.termsize; i++) 434 | { 435 | printf("%5.60f\n", P.coefficients.at(i)); 436 | fprintf(fptr, "%5.60f\n", P.coefficients.at(i)); 437 | } 438 | fclose(fptr); 439 | } 440 | 441 | void FullTest(Polynomial P, float min, float max) 442 | { 443 | size_t n = 0; 444 | size_t correct = 0; 445 | 446 | vector Incorrect; 447 | 448 | for (float h = min; h < max; h = nextafterf(h, max)) 449 | { 450 | // printf("x: %4.70f\n", h); 451 | if (h == INFINITY || h == -INFINITY) 452 | { 453 | break; 454 | } 455 | if (ComputeSpecialCase(h) == -1) 456 | { 457 | continue; 458 | } 459 | n++; 460 | 461 | double x = (double)h; 462 | double range_reduced = RangeReduction(h); 463 | long double eval = EvaulutePoly(P, range_reduced); 464 | double oc = OutputCompensation(h, eval); 465 | float y = (float)oc; 466 | 467 | mpfr_t y_mpfr; 468 | mpfr_inits2(200, y_mpfr, NULL); 469 | float oracle = EvaluateFunction(y_mpfr, h); 470 | if (y != oracle) 471 | { 472 | RndInterval I; 473 | I.x_orig = h; 474 | I.x_rr = range_reduced; 475 | Incorrect.push_back(I); 476 | } 477 | else 478 | { 479 | correct += 1; 480 | } 481 | for (int i = 0; i < 5; i++) 482 | { 483 | h = nextafterf(h, max); 484 | } 485 | } 486 | 487 | printf("Full Test Results, Correct: %ld Incorrect: %ld\n", correct, n - correct); 488 | } 489 | 490 | vector VerifyAdd(Polynomial P, long last_size, float min, float max) 491 | { 492 | vector Incorrect; 493 | size_t n = 0; 494 | size_t incorrect_count = 0; 495 | 496 | for (float h = min; h < max; h = nextafterf(h, max)) 497 | { 498 | 499 | n++; 500 | 501 | double x = (double)h; 502 | double range_reduced = RangeReduction(h); 503 | long double eval = EvaulutePoly(P, range_reduced); 504 | double oc = OutputCompensation(h, eval); 505 | float y = (float)oc; 506 | 507 | mpfr_t y_mpfr; 508 | mpfr_inits2(200, y_mpfr, NULL); 509 | float oracle = EvaluateFunction(y_mpfr, h); 510 | if (y != oracle) 511 | { 512 | incorrect_count++; 513 | RndInterval I; 514 | I.x_orig = h; 515 | I.x_rr = range_reduced; 516 | Incorrect.push_back(I); 517 | 518 | // printf("I.x_orig: %4.40f\n", I.x_orig); 519 | // int p = std::max(1, (int)last_size / 40); 520 | // if (rand() % p == 0) 521 | // { 522 | // Incorrect.push_back(I); 523 | // } 524 | } 525 | } 526 | printf("Out of sample, Correct: %ld Incorrect: %ld\n", n - incorrect_count, incorrect_count); 527 | printf("Size of Incorrect: %ld\n", Incorrect.size()); 528 | return Incorrect; 529 | } 530 | 531 | void writePolynomialToFile(const Polynomial &poly, const std::string &filename) 532 | { 533 | std::ofstream outFile(filename); 534 | if (!outFile) 535 | { 536 | std::cerr << "Error opening file for writing." << std::endl; 537 | return; 538 | } 539 | 540 | outFile << poly.termsize << std::endl; 541 | for (double coeff : poly.coefficients) 542 | { 543 | doubleX dx; 544 | dx.d = coeff; 545 | outFile << dx.x << " "; 546 | } 547 | outFile << std::endl; 548 | 549 | outFile.close(); 550 | std::cout << "Polynomial written successfully." << std::endl; 551 | } 552 | 553 | Polynomial readPolynomialFromFile(const std::string &filename) 554 | { 555 | Polynomial poly; 556 | std::ifstream inFile(filename); 557 | if (!inFile) 558 | { 559 | std::cerr << "Error opening file for reading." << std::endl; 560 | return poly; // Returns an empty polynomial if file opening fails 561 | } 562 | 563 | inFile >> poly.termsize; 564 | poly.coefficients.resize(poly.termsize); 565 | 566 | for (int i = 0; i < poly.termsize; ++i) 567 | { 568 | doubleX dx; 569 | inFile >> dx.x; 570 | poly.coefficients[i] = dx.d; 571 | } 572 | 573 | inFile.close(); 574 | std::cout << "Polynomial read successfully." << std::endl; 575 | return poly; 576 | } -------------------------------------------------------------------------------- /float32/fhelper.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | using namespace std; 16 | using namespace soplex; 17 | struct RndInterval 18 | { 19 | float x_orig; 20 | float y; 21 | double l; 22 | double u; 23 | 24 | double x_rr; 25 | double yp; 26 | double lp; 27 | double up; 28 | 29 | bool operator<(RndInterval &other) const 30 | { 31 | // return std::make_tuple(fromX, fromY, toX, toY) < std::make_tuple(other.fromX, other.fromY, other.toX, other.toY); 32 | return x_orig < other.x_orig; 33 | } 34 | 35 | bool operator==(RndInterval &other) const 36 | { 37 | // declare how 2 variable of type posToMove should be compared with == 38 | // return std::make_tuple(fromX, fromY, toX, toY) == std::make_tuple(other.fromX, other.fromY, other.toX, other.toY); 39 | return x_orig == other.x_orig; 40 | } 41 | }; 42 | 43 | struct Polynomial 44 | { 45 | int termsize; 46 | vector coefficients; 47 | }; 48 | typedef union 49 | { 50 | float f; 51 | unsigned x; 52 | } floatX; 53 | 54 | typedef union 55 | { 56 | double d; 57 | unsigned long long int x; 58 | } doubleX; 59 | void FullTest(Polynomial P, float min = 0.0, float max = INFINITY); 60 | double RangeReduction(float x); 61 | double OutputCompensation(float x, double yp); 62 | double InverseOutputCompensation(float x, double yp); 63 | float EvaluateFunction(mpfr_t y, float x); 64 | vector GenerateFloatSample(int sample_size, float min, float max); 65 | vector CalcRndIntervals(vector X); 66 | vector CalcRedIntervals(vector X); 67 | Polynomial GeneratePolynomial(vector L); 68 | long double EvaulutePoly(Polynomial P, double xval); 69 | vector Verify(vector L2, Polynomial P, int debug); 70 | vector VerifyAdd(Polynomial P, long last_size, float min, float max); 71 | int ComputeSpecialCase(float x); 72 | void print_poly(Polynomial P); 73 | float generateRandomFloat(float a, float b); 74 | double GuessInitial(float x, double &lb, double &ub); 75 | bool CompareX(RndInterval a, RndInterval b); 76 | void writePolynomialToFile(const Polynomial &poly, const std::string &filename); 77 | Polynomial readPolynomialFromFile(const std::string &filename); 78 | -------------------------------------------------------------------------------- /float32/flog2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschott20/ALibm/7de59ad0278d1fce37f69818244712c2704d16d5/float32/flog2 -------------------------------------------------------------------------------- /float32/flog2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "luts.h" 15 | #include "fhelper.hpp" 16 | 17 | using namespace std; 18 | using namespace soplex; 19 | 20 | int ComputeSpecialCase(float x) 21 | { 22 | floatX fx; 23 | fx.f = x; 24 | if (x <= 0.0) 25 | { 26 | return -1; 27 | } 28 | else if (fx.x >= 0x7F800000) 29 | { 30 | return -1; 31 | } 32 | else if (fx.f == 2.0037834644317626953125000000000000000000) 33 | { 34 | return -1; 35 | } 36 | 37 | return 0; 38 | } 39 | double RangeReduction(float x) 40 | { 41 | // return x; 42 | 43 | int exp; 44 | double sig = (double)frexp(x, &exp); 45 | return sig; 46 | 47 | // floatX fix, fit; 48 | // int m = 0; 49 | // fix.f = x; 50 | // if (fix.x < 0x800000) 51 | // { 52 | // fix.f *= pow(2, 23); 53 | // m -= 23; 54 | // } 55 | // m += fix.x >> 23; 56 | // m -= 127; 57 | // fix.x &= 0x007FFFFF; 58 | // fix.x |= 0x3F800000; 59 | 60 | // fit.x = fix.x & 0x007F0000; 61 | // int FIndex = fit.x >> 16; 62 | // fit.x |= 0x3F800000; 63 | // double F = fit.f; 64 | 65 | // double f = fix.f - F; 66 | // return f * log2OneByF[FIndex]; 67 | } 68 | 69 | double OutputCompensation(float x, double yp) 70 | { 71 | // return yp; 72 | 73 | int exp; 74 | double sig = (double)frexp(x, &exp); 75 | return yp + exp; 76 | 77 | // floatX fix, fit; 78 | 79 | // int m = 0; 80 | // fix.f = x; 81 | // if (fix.x < 0x800000) 82 | // { 83 | // fix.f *= pow(2, 23); 84 | // m -= 23; 85 | // } 86 | // m += fix.x >> 23; 87 | // m -= 127; 88 | // fix.x &= 0x007FFFFF; 89 | // fix.x |= 0x3F800000; 90 | 91 | // fit.x = fix.x & 0x007F0000; 92 | // int FIndex = fit.x >> 16; 93 | 94 | // return yp + log2Lut[FIndex] + m; 95 | } 96 | 97 | double GuessInitial(float x, double &lb, double &ub) 98 | { 99 | // int exp; 100 | // double sig = (double)frexp(x, &exp); 101 | // return yp - exp; 102 | // lb = log1p(xp) / log(2); 103 | // ub = log1p(xp) / log(2); 104 | double xrr = RangeReduction(x); 105 | double yp = log2(xrr); 106 | lb = yp; 107 | ub = yp; 108 | return 0; 109 | } 110 | 111 | float EvaluateFunction(mpfr_t y, float x) 112 | { 113 | mpfr_set_flt(y, x, MPFR_RNDN); 114 | mpfr_log2(y, y, MPFR_RNDN); 115 | float h = mpfr_get_flt(y, MPFR_RNDN); 116 | return h; 117 | } 118 | 119 | #define GROW 100 120 | #define SPACING 0.1 121 | #define OVERLAP 0.0001 122 | int main() 123 | { 124 | for (float low = 2; low < 2.1; low += SPACING) 125 | { 126 | float high = low + SPACING + OVERLAP; 127 | // printf("Generating FloatSample...\n"); 128 | vector X = GenerateFloatSample(1, low, high); 129 | 130 | // printf("Generating all float values...\n"); 131 | 132 | vector Test = GenerateFloatSample(-1, low, high); 133 | vector Incorrect; 134 | Polynomial P; 135 | 136 | do 137 | { 138 | printf("Low: %f, High: %f\n", low, high); 139 | if (Incorrect.size() < GROW) 140 | { 141 | for (int i = 0; i < Incorrect.size(); i++) 142 | { 143 | RndInterval I = Incorrect.at(i); 144 | X.push_back(I); 145 | } 146 | } 147 | else 148 | { 149 | for (int i = 0; i < GROW; i++) 150 | { 151 | RndInterval I = Incorrect.at(floor(i * Incorrect.size() / GROW)); 152 | for (size_t j = 0; j < X.size(); j++) 153 | { 154 | if (X.at(j).x_orig == I.x_orig || X.at(j).x_rr == I.x_rr) 155 | { 156 | printf("Duplicate\n"); 157 | break; 158 | } 159 | } 160 | X.push_back(I); 161 | } 162 | } 163 | printf("Sample size: %ld\n", X.size()); 164 | // printf("Generating RndIntervals...\n"); 165 | vector L = CalcRndIntervals(X); 166 | 167 | // printf("Generating RedIntervals...\n"); 168 | vector L2 = CalcRedIntervals(L); 169 | 170 | // printf("Generating Polynomial...\n"); 171 | P = GeneratePolynomial(L2); 172 | 173 | Incorrect = Verify(L2, P, 1); 174 | if (Incorrect.size() > 0) 175 | { 176 | printf("FAILED IN SAMPLE: %ld\n", Incorrect.size()); 177 | // return -1; 178 | } 179 | Incorrect = Verify(Test, P, 0); 180 | // print_poly(P); 181 | printf("----------------------------------------\n"); 182 | 183 | } while (Incorrect.size() > 0); 184 | 185 | FullTest(P, low, high); 186 | std::string filename = "flog2poly/flog2_" + std::to_string(low) + "_" + std::to_string(high) + ".txt"; 187 | writePolynomialToFile(P, filename); 188 | printf("Successfully written to file: %s\n", filename.c_str()); 189 | print_poly(P); 190 | } 191 | printf("Finished!\n"); 192 | } -------------------------------------------------------------------------------- /float32/flog2poly/2-2.txt: -------------------------------------------------------------------------------- 1 | 7 2 | 13839950078055808653 4624734434826564558 13853250229213416370 4632490643537813669 13855758816733519427 4628755719687040412 13842904545747925551 3 | -------------------------------------------------------------------------------- /float32/flog2poly/2-4.txt: -------------------------------------------------------------------------------- 1 | 7 2 | 13839813994467456793 4624047845104605039 13851984055115512867 4630870402802447671 13853712686755463775 4625998390763997241 13839806877980237190 3 | -------------------------------------------------------------------------------- /float32/flog2poly/2-6.txt: -------------------------------------------------------------------------------- 1 | 7 2 | 13839685728680924647 4623451467538231135 13850828237194977420 4629650078793719008 13851571232100972718 4623345689582687453 13836476175883689232 3 | -------------------------------------------------------------------------------- /float32/flog2poly/2-8.txt: -------------------------------------------------------------------------------- 1 | 7 2 | 13839589662576611435 4623033249594088492 13850069656578378951 4628182459009314188 13849974111505167414 4621491791609445057 13834307695743617449 3 | -------------------------------------------------------------------------------- /float32/flog2poly/2.txt: -------------------------------------------------------------------------------- 1 | 7 2 | 13840088983442381949 4625347124714385442 13854123740975661436 4634414482658525937 13858134739117318847 4631380976507741609 13846118394287531079 3 | -------------------------------------------------------------------------------- /float32/flog2poly/flog2_2.000000_2.100100.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 13839847489240776815 4624087393816797017 13851744849129611817 4630174802359937793 13851325051802814855 4620706692430642005 3 | -------------------------------------------------------------------------------- /float32/flog2poly/flog2_2.100000_2.200100.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 13839771951092791870 4623728510101761890 13851062742627073950 4629352600831582747 13850092593872581128 4618845546082878214 3 | -------------------------------------------------------------------------------- /half16/Makefile: -------------------------------------------------------------------------------- 1 | CXX=g++ 2 | CXXFLAGS=-O2 -I/home/soplex-4.0.1//src/ -std=c++11 3 | LIBS= /home/soplex-4.0.1//build/lib/libsoplex.a -lgmp -lz -lm -lmpfr 4 | TARGET1=hlog2 5 | TARGET2=hexpm1 6 | TARGET3=flog2 7 | 8 | 9 | 10 | all: $(TARGET1) $(TARGET2) 11 | 12 | .PHONY: $(TARGET1) $(TARGET2) $(TARGET3) 13 | 14 | 15 | $(TARGET1): hlog2.cpp hhelper.cpp 16 | $(CXX) $(CXXFLAGS) $< hhelper.cpp $(LIBS) -o $@ 17 | ./$(TARGET1) 18 | 19 | $(TARGET2): hexpm1.cpp hhelper.cpp 20 | $(CXX) $(CXXFLAGS) $< hhelper.cpp $(LIBS) -o $@ 21 | ./$(TARGET2) 22 | 23 | $(TARGET3): flog2.cpp fhelper.cpp 24 | $(CXX) $(CXXFLAGS) $< fhelper.cpp $(LIBS) -o $@ 25 | ./$(TARGET3) 26 | 27 | 28 | clean: 29 | rm -f $(TARGET1) $(TARGET2) $(TARGET3) 30 | 31 | -------------------------------------------------------------------------------- /half16/hexpm1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschott20/ALibm/7de59ad0278d1fce37f69818244712c2704d16d5/half16/hexpm1 -------------------------------------------------------------------------------- /half16/hexpm1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "half.hpp" 12 | #include 13 | #include 14 | #include 15 | #include "luts.h" 16 | #include "hhelper.hpp" 17 | 18 | using namespace std; 19 | using namespace soplex; 20 | using half_float::half; 21 | 22 | int ComputeSpecialCase(half x) 23 | { 24 | mpfr_t y_mpfr; 25 | mpfr_init2(y_mpfr, 200); 26 | half y = EvaluateFunction(y_mpfr, x); 27 | // check if y is infinity 28 | if (y == INFINITY) 29 | { 30 | return -1; 31 | } 32 | if (y == -1) 33 | { 34 | return -1; 35 | } 36 | return 0; 37 | } 38 | 39 | double RangeReduction(half x) 40 | { 41 | // double xp = x * 92.332482616893656768297660164535045623779296875; 42 | // int N = (int)xp; 43 | // return x - N * 0.01083042469624914509729318723429969395510852336883544921875; 44 | return (double)x; 45 | } 46 | 47 | double OutputCompensation(half x, double yp) 48 | { 49 | // double xp = x * 92.332482616893656768297660164535045623779296875; 50 | // int N = (int)xp; 51 | // int N2 = N % 64; 52 | // if (N2 < 0) 53 | // N2 += 64; 54 | // int N1 = N - N2; 55 | // int M = N1 / 64; 56 | 57 | // return yp * ldexp(exp2JBy64[N2], M); 58 | return yp; 59 | } 60 | 61 | double InverseOutputCompensation(half x, double yp) 62 | { 63 | // double xp = x * 92.332482616893656768297660164535045623779296875; 64 | // int N = (int)xp; 65 | // int N2 = N % 64; 66 | // if (N2 < 0) 67 | // N2 += 64; 68 | // int N1 = N - N2; 69 | // int M = N1 / 64; 70 | // int J = N2; 71 | // return (2 << M) * ((2 << (J / 64)) + (2 << J / 64) * yp) - 1; 72 | return yp; 73 | } 74 | 75 | half EvaluateFunction(mpfr_t y, double x) 76 | { 77 | mpfr_set_d(y, x, MPFR_RNDN); 78 | mpfr_expm1(y, y, MPFR_RNDN); 79 | half h = (half)mpfr_get_d(y, MPFR_RNDN); 80 | return h; 81 | } 82 | 83 | int main() 84 | { 85 | printf("Generating FloatSample...\n"); 86 | vector X = GenerateFloatSample(10, -1, 1); 87 | 88 | printf("Generating all float values...\n"); 89 | vector Test = GenerateFloatSample(-1, -1, 1); 90 | vector Incorrect; 91 | Polynomial P; 92 | 93 | do 94 | { 95 | if (Incorrect.size() < 10) 96 | { 97 | for (int i = 0; i < Incorrect.size(); i++) 98 | { 99 | RndInterval I = Incorrect.at(i); 100 | X.push_back(I); 101 | } 102 | } 103 | else 104 | { 105 | for (int i = 0; i < 10; i++) 106 | { 107 | RndInterval I = Incorrect.at(floor(i * Incorrect.size() / 11)); 108 | X.push_back(I); 109 | } 110 | } 111 | printf("Sample size: %ld\n", X.size()); 112 | printf("Generating RndIntervals...\n"); 113 | vector L = CalcRndIntervals(X); 114 | 115 | printf("Generating RedIntervals...\n"); 116 | vector L2 = CalcRedIntervals(L); 117 | 118 | printf("Generating Polynomial...\n"); 119 | P = GeneratePolynomial(L2); 120 | 121 | Incorrect = Verify(L2, P); 122 | if (Incorrect.size() > 0) 123 | { 124 | printf("FAILED IN SAMPLE: %ld\n", Incorrect.size()); 125 | return 0; 126 | } 127 | Incorrect = Verify(Test, P); 128 | } while (Incorrect.size() > 0); 129 | 130 | for (int i = 0; i < P.termsize; i++) 131 | { 132 | printf("%5.60f\n", P.coefficients.at(i)); 133 | } 134 | 135 | FILE *fptr = fopen("../dump/poly.txt", "w"); 136 | for (int i = 0; i < P.termsize; i++) 137 | { 138 | fprintf(fptr, "%5.60f\n", P.coefficients.at(i)); 139 | } 140 | fclose(fptr); 141 | 142 | printf("Finished!\n"); 143 | } -------------------------------------------------------------------------------- /half16/hhelper.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "half.hpp" 12 | #include 13 | #include 14 | #include 15 | #include "hhelper.hpp" 16 | 17 | using namespace std; 18 | using namespace soplex; 19 | using half_float::half; 20 | 21 | void print_binary_half(half h) 22 | { 23 | short n = *(short *)&h; 24 | 25 | unsigned i; 26 | for (i = 1 << 15; i > 0; i = i / 2) 27 | (n & i) ? printf("1") : printf("0"); 28 | printf("\n"); 29 | } 30 | 31 | vector GenerateFloatSample(int sample_size, float min, float max) 32 | { 33 | vector X; 34 | size_t n = 0; 35 | half h; 36 | half start(min); 37 | half end(max); 38 | half inf((0x7BFF)); 39 | 40 | if (max == -1) 41 | { 42 | end = inf; 43 | } 44 | 45 | if (sample_size == -1) 46 | { 47 | size_t removed_special = 0; 48 | for (h = half_float::nextafter(start, end); h < end; h = half_float::nextafter(h, end)) 49 | { 50 | if (h == inf) 51 | { 52 | break; 53 | } 54 | if (ComputeSpecialCase(h) == -1) 55 | { 56 | removed_special++; 57 | continue; 58 | } 59 | n++; 60 | RndInterval I; 61 | I.x_orig = h; 62 | I.x_rr = RangeReduction(h); 63 | X.push_back(I); 64 | } 65 | printf("Removed Special: %ld\n", removed_special); 66 | } 67 | else 68 | { 69 | int skip = (1 << 16) / sample_size; 70 | 71 | for (h = half_float::nextafter(start, end); h < end; h = half_float::nextafter(h, end)) 72 | { 73 | // printf("h: %4.15f\n", (double)h); 74 | 75 | if (h == inf) 76 | { 77 | break; 78 | } 79 | if (ComputeSpecialCase(h) == -1) 80 | { 81 | continue; 82 | } 83 | 84 | n++; 85 | RndInterval I; 86 | I.x_orig = h; 87 | I.x_rr = RangeReduction(h); 88 | X.push_back(I); 89 | for (int i = 0; i < skip; i++) 90 | { 91 | h = half_float::nextafter(h, inf); 92 | } 93 | } 94 | } 95 | return X; 96 | } 97 | 98 | vector CalcRndIntervals(vector X) 99 | { 100 | FILE *fptr; 101 | fptr = fopen("../dump/HRndInterval.txt", "w"); 102 | 103 | half y; 104 | double l, u; 105 | 106 | mpfr_t y_mpfr, x_mpfr; 107 | mpfr_inits2(200, y_mpfr, x_mpfr, NULL); 108 | 109 | vector L; 110 | 111 | for (size_t i = 0; i < X.size(); i++) 112 | { 113 | 114 | RndInterval I; 115 | 116 | I.x_orig = X.at(i).x_orig; 117 | I.x_rr = X.at(i).x_rr; 118 | y = EvaluateFunction(y_mpfr, (double)X.at(i).x_orig); 119 | 120 | half inf(half_float::half(0x7BFF)); 121 | 122 | half lhalf(half_float::nextafter((half)y, -inf)); 123 | half uhalf(half_float::nextafter((half)y, inf)); 124 | 125 | l = (y + (double)lhalf) / 2; 126 | u = (y + (double)uhalf) / 2; 127 | 128 | // printf("x: %4.15f y: %4.15f l: %4.15f u: %4.15f\n", (double)X.at(i).x_orig, (double)y, l, u); 129 | while ((half)l != (half)y) 130 | { 131 | l = nextafterf(l, INFINITY); 132 | } 133 | assert((half)l == (half)y); 134 | 135 | while ((half)u != (half)y) 136 | { 137 | u = nextafterf(u, -INFINITY); 138 | } 139 | assert((half)u == (half)y); 140 | assert(l < u); 141 | 142 | fprintf(fptr, "%4.15f %4.15f %4.40f %4.40f \n", (double)X.at(i).x_orig, (double)y, l, u); 143 | I.y = y; 144 | I.l = l; 145 | I.u = u; 146 | 147 | L.push_back(I); 148 | } 149 | return L; 150 | } 151 | 152 | vector CalcRedIntervals(vector X) 153 | { 154 | FILE *fptr; 155 | fptr = fopen("../dump/HRedInterval.txt", "w"); 156 | half yp; 157 | double lp, up; 158 | 159 | mpfr_t yp_mpfr, xrr_mpfr; 160 | mpfr_inits2(200, yp_mpfr, xrr_mpfr, NULL); 161 | 162 | vector L; 163 | 164 | for (size_t i = 0; i < X.size(); i++) 165 | { 166 | RndInterval I; 167 | 168 | I.x_orig = X.at(i).x_orig; 169 | I.x_rr = X.at(i).x_rr; 170 | 171 | I.y = X.at(i).y; 172 | 173 | I.l = X.at(i).l; 174 | I.u = X.at(i).u; 175 | 176 | lp = InverseOutputCompensation(X.at(i).x_orig, X.at(i).l); 177 | up = InverseOutputCompensation(X.at(i).x_orig, X.at(i).u); 178 | 179 | while (OutputCompensation(X.at(i).x_orig, lp) < X.at(i).l) 180 | { 181 | lp = nextafterf(lp, INFINITY); 182 | } 183 | 184 | while (OutputCompensation(X.at(i).x_orig, up) > X.at(i).u) 185 | { 186 | up = nextafterf(up, -INFINITY); 187 | } 188 | 189 | assert(lp <= up); 190 | fprintf(fptr, "%4.15f %4.40f %4.40f %4.40f \n", (double)X.at(i).x_orig, X.at(i).x_rr, lp, up); 191 | I.lp = lp; 192 | I.up = up; 193 | 194 | L.push_back(I); 195 | } 196 | return L; 197 | } 198 | 199 | Polynomial GeneratePolynomial(vector L) 200 | { 201 | 202 | cout << "Solving... [1, 30] \n"; 203 | for (int termsize = 1; termsize < 30; termsize++) 204 | { 205 | SoPlex mysoplex; 206 | mysoplex.setBoolParam(SoPlex::RATFACJUMP, true); 207 | mysoplex.setIntParam(SoPlex::SOLVEMODE, 2); 208 | mysoplex.setIntParam(SoPlex::CHECKMODE, 2); 209 | mysoplex.setIntParam(SoPlex::SYNCMODE, 1); 210 | mysoplex.setIntParam(SoPlex::READMODE, 1); 211 | mysoplex.setRealParam(SoPlex::FEASTOL, 0.0); 212 | mysoplex.setRealParam(SoPlex::OPTTOL, 0.0); 213 | mysoplex.setRealParam(SoPlex::EPSILON_ZERO, 0.0); 214 | mysoplex.setRealParam(SoPlex::EPSILON_FACTORIZATION, 0.0); 215 | mysoplex.setRealParam(SoPlex::EPSILON_UPDATE, 0.0); 216 | mysoplex.setRealParam(SoPlex::EPSILON_PIVOT, 0.0); 217 | mysoplex.setIntParam(SoPlex::VERBOSITY, 0); 218 | mysoplex.setRealParam(SoPlex::TIMELIMIT, 5 * 60); 219 | mysoplex.setIntParam(SoPlex::OBJSENSE, SoPlex::OBJSENSE_MINIMIZE); 220 | DSVectorRational dummycol(0); 221 | 222 | for (int i = 0; i < termsize; i++) 223 | { 224 | auto column = LPColRational(1.0, dummycol, infinity, -infinity); 225 | mysoplex.addColRational(column); 226 | } 227 | 228 | for (int i = 0; i < L.size(); i++) 229 | { 230 | DSVectorRational row1(termsize); 231 | Rational acc(1.0); 232 | Rational xval(L.at(i).x_rr); 233 | row1.add(0, 1.0); 234 | 235 | for (int j = 1; j < termsize; j++) 236 | { 237 | acc = acc * xval; 238 | row1.add(j, acc); 239 | } 240 | double lbnd = (L.at(i).lp); 241 | double ubnd = (L.at(i).up); 242 | 243 | mysoplex.addRowRational(LPRowRational(lbnd, row1, ubnd)); 244 | } 245 | 246 | mysoplex.writeFileRational("dump/HSoplexRational.lp", NULL, NULL, NULL); 247 | mysoplex.writeFileReal("dump/HSoplexReal.lp", NULL, NULL, NULL); 248 | 249 | SPxSolver::Status stat; 250 | 251 | stat = mysoplex.optimize(); 252 | Polynomial P; 253 | 254 | if (stat == SPxSolver::OPTIMAL) 255 | { 256 | DVectorRational prim(termsize); 257 | mysoplex.getPrimalRational(prim); 258 | 259 | P.termsize = termsize; 260 | for (int i = 0; i < termsize; i++) 261 | { 262 | P.coefficients.push_back(prim[i]); 263 | } 264 | std::cout << "Status: " << stat << " with " << termsize << "terms" << std::endl; 265 | 266 | return P; 267 | } 268 | else if (stat == SPxSolver::UNBOUNDED) 269 | { 270 | DVectorRational prim(termsize); 271 | mysoplex.getPrimalRational(prim); 272 | 273 | P.termsize = termsize; 274 | std::cout << "Unbounded solution\n"; 275 | for (int i = 0; i < termsize; i++) 276 | { 277 | P.coefficients.push_back(0.0); 278 | } 279 | } 280 | // std::cout << "Status: " << stat << std::endl; 281 | } 282 | 283 | Polynomial N; 284 | return N; 285 | } 286 | 287 | double EvaulutePoly(Polynomial P, double xval) 288 | { 289 | double acc = 0.0; 290 | double power = 1.0; 291 | 292 | for (int i = 0; i < P.termsize; i++) 293 | { 294 | 295 | acc += P.coefficients.at(i) * power; 296 | power *= xval; 297 | } 298 | 299 | return acc; 300 | } 301 | 302 | vector Verify(vector L2, Polynomial P) 303 | { 304 | size_t n = 0; 305 | size_t correct = 0; 306 | half inf(half_float::half(0x7BFF)); 307 | vector Incorrect; 308 | for (size_t i = 0; i < L2.size(); i++) 309 | { 310 | n++; 311 | half h(L2.at(i).x_orig); 312 | 313 | double x = (double)h; 314 | double range_reduced = RangeReduction(h); 315 | double eval = EvaulutePoly(P, range_reduced); 316 | 317 | half y(OutputCompensation(h, eval)); 318 | 319 | mpfr_t y_mpfr; 320 | mpfr_inits2(200, y_mpfr, NULL); 321 | half oracle = EvaluateFunction(y_mpfr, x); 322 | 323 | if (y != oracle) 324 | { 325 | RndInterval I; 326 | I.x_orig = h; 327 | I.x_rr = range_reduced; 328 | Incorrect.push_back(I); 329 | } 330 | else 331 | { 332 | correct += 1; 333 | } 334 | } 335 | 336 | printf("In sample, Correct: %ld Incorrect: %ld\n", correct, n - correct); 337 | return Incorrect; 338 | } 339 | 340 | void print_poly(Polynomial P) 341 | { 342 | FILE *fptr = fopen("../dump/HPoly.txt", "w"); 343 | for (int i = 0; i < P.termsize; i++) 344 | { 345 | printf("%5.60f\n", P.coefficients.at(i)); 346 | fprintf(fptr, "%5.60f\n", P.coefficients.at(i)); 347 | } 348 | fclose(fptr); 349 | } 350 | -------------------------------------------------------------------------------- /half16/hhelper.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "half.hpp" 12 | #include 13 | #include 14 | #include 15 | 16 | using namespace std; 17 | using namespace soplex; 18 | using half_float::half; 19 | struct RndInterval 20 | { 21 | half x_orig; 22 | half y; 23 | double l; 24 | double u; 25 | 26 | double x_rr; 27 | double yp; 28 | double lp; 29 | double up; 30 | }; 31 | 32 | struct Polynomial 33 | { 34 | int termsize; 35 | vector coefficients; 36 | }; 37 | 38 | double RangeReduction(half x); 39 | double OutputCompensation(half x, double yp); 40 | double InverseOutputCompensation(half x, double yp); 41 | half EvaluateFunction(mpfr_t y, double x); 42 | 43 | void print_binary_half(half h); 44 | 45 | vector GenerateFloatSample(int sample_size, float min, float max); 46 | 47 | vector CalcRndIntervals(vector X); 48 | 49 | vector CalcRedIntervals(vector X); 50 | 51 | Polynomial GeneratePolynomial(vector L); 52 | 53 | double EvaulutePoly(Polynomial P, double xval); 54 | 55 | vector Verify(vector L2, Polynomial P); 56 | 57 | int ComputeSpecialCase(half x); 58 | 59 | void print_poly(Polynomial P); 60 | void print_binary_half(half h); 61 | -------------------------------------------------------------------------------- /half16/hlog2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschott20/ALibm/7de59ad0278d1fce37f69818244712c2704d16d5/half16/hlog2 -------------------------------------------------------------------------------- /half16/hlog2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "half.hpp" 12 | #include 13 | #include 14 | #include 15 | #include "hhelper.hpp" 16 | 17 | using namespace std; 18 | using namespace soplex; 19 | using half_float::half; 20 | 21 | int ComputeSpecialCase(half x) 22 | { 23 | mpfr_t y_mpfr; 24 | mpfr_init2(y_mpfr, 200); 25 | half y = EvaluateFunction(y_mpfr, x); 26 | 27 | if (x <= 0) 28 | { 29 | return -1; 30 | } 31 | 32 | return 0; 33 | } 34 | double RangeReduction(half x) 35 | { 36 | // reduces x to [0.5, 1) 37 | int exp; 38 | double sig = half_float::frexp(x, &exp); 39 | return sig; 40 | } 41 | 42 | double OutputCompensation(half x, double yp) 43 | { 44 | int exp; 45 | double sig = half_float::frexp(x, &exp); 46 | return yp + exp; 47 | } 48 | 49 | double InverseOutputCompensation(half x, double yp) 50 | { 51 | int exp; 52 | double sig = (double)half_float::frexp(x, &exp); 53 | return yp - exp; 54 | } 55 | 56 | half EvaluateFunction(mpfr_t y, double x) 57 | { 58 | mpfr_set_d(y, x, MPFR_RNDN); 59 | mpfr_log2(y, y, MPFR_RNDN); 60 | half h = (half)mpfr_get_d(y, MPFR_RNDN); 61 | return h; 62 | } 63 | 64 | #define GROW 10 65 | int main() 66 | { 67 | printf("Generating FloatSample...\n"); 68 | vector X = GenerateFloatSample(100, -9999, 9999); 69 | 70 | printf("Generating all float values...\n"); 71 | vector Test = GenerateFloatSample(-1, -9999, 9999); 72 | vector Incorrect; 73 | Polynomial P; 74 | 75 | do 76 | { 77 | if (Incorrect.size() < GROW) 78 | { 79 | for (int i = 0; i < Incorrect.size(); i++) 80 | { 81 | RndInterval I = Incorrect.at(i); 82 | X.push_back(I); 83 | } 84 | } 85 | else 86 | { 87 | for (int i = 0; i < GROW; i++) 88 | { 89 | RndInterval I = Incorrect.at(floor(i * Incorrect.size() / GROW)); 90 | X.push_back(I); 91 | } 92 | } 93 | printf("Sample size: %ld\n", X.size()); 94 | printf("Generating RndIntervals...\n"); 95 | vector L = CalcRndIntervals(X); 96 | 97 | printf("Generating RedIntervals...\n"); 98 | vector L2 = CalcRedIntervals(L); 99 | 100 | printf("Generating Polynomial...\n"); 101 | P = GeneratePolynomial(L2); 102 | 103 | Incorrect = Verify(L2, P); 104 | if (Incorrect.size() > 0) 105 | { 106 | printf("FAILED IN SAMPLE: %ld\n", Incorrect.size()); 107 | return 0; 108 | } 109 | Incorrect = Verify(Test, P); 110 | printf("----------------------------------------\n"); 111 | } while (Incorrect.size() > 0); 112 | 113 | print_poly(P); 114 | printf("Finished!\n"); 115 | } -------------------------------------------------------------------------------- /lib/flog2/Makefile: -------------------------------------------------------------------------------- 1 | CXX=g++ 2 | CXXFLAGS=-O2 -std=c++11 3 | LIBS= -lmpfr 4 | TARGET1=flog2lib 5 | 6 | 7 | 8 | 9 | all: $(TARGET1) 10 | 11 | .PHONY: $(TARGET1) 12 | 13 | $(TARGET1): flog2lib.cpp 14 | $(CXX) $(CXXFLAGS) $< $(LIBS) -o $@ 15 | ./$(TARGET1) 16 | 17 | 18 | 19 | clean: 20 | rm -f $(TARGET1) 21 | 22 | -------------------------------------------------------------------------------- /lib/flog2/flog2lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschott20/ALibm/7de59ad0278d1fce37f69818244712c2704d16d5/lib/flog2/flog2lib -------------------------------------------------------------------------------- /lib/flog2/flog2lib.cpp: -------------------------------------------------------------------------------- 1 | #include "flog2lib.hpp" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | 11 | double EvaulutePoly(int index, double xval) 12 | { 13 | double acc = 0.0; 14 | double power = 1.0; 15 | doubleX dx; 16 | for (int i = 0; i < 7; i++) 17 | { 18 | dx.x = flog2_coef[index][i]; 19 | acc += dx.d * power; 20 | power *= xval; 21 | } 22 | 23 | return acc; 24 | } 25 | double RangeReduction(float x) 26 | { 27 | // return x; 28 | 29 | int exp; 30 | double sig = (double)frexp(x, &exp); 31 | return sig; 32 | } 33 | 34 | double OutputCompensation(float x, double yp) 35 | { 36 | int exp; 37 | double sig = (double)frexp(x, &exp); 38 | return yp + exp; 39 | } 40 | float EvaluateFunction(mpfr_t y, float x) 41 | { 42 | mpfr_set_d(y, x, MPFR_RNDN); 43 | mpfr_log2(y, y, MPFR_RNDN); 44 | float h = mpfr_get_flt(y, MPFR_RNDN); 45 | return h; 46 | } 47 | 48 | int SelectPoly(float x) 49 | { 50 | if (x < 2.0) 51 | { 52 | return -1; 53 | } 54 | else if (x < 2.2) 55 | { 56 | return 0; 57 | } 58 | else if (x < 2.4) 59 | { 60 | return 1; 61 | } 62 | else if (x < 2.6) 63 | { 64 | return 2; 65 | } 66 | else if (x < 2.8) 67 | { 68 | return 3; 69 | } 70 | else if (x < 3.0) 71 | { 72 | return 4; 73 | } 74 | else 75 | { 76 | return -1; 77 | } 78 | } 79 | float flog2(float x) 80 | { 81 | int poly_ind = SelectPoly(x); 82 | double range_reduced = RangeReduction(x); 83 | double eval = EvaulutePoly(poly_ind, range_reduced); 84 | double oc = OutputCompensation(x, eval); 85 | float y = (float)oc; 86 | return y; 87 | } 88 | 89 | #define LOW 2.0 90 | #define HIGH 3.0 91 | 92 | int main() 93 | { 94 | 95 | size_t n = 0; 96 | size_t incorrect = 0; 97 | 98 | struct timespec start, end; 99 | clock_gettime(CLOCK_MONOTONIC_RAW, &start); 100 | for (float x = LOW; x < HIGH; x = nextafterf(x, numeric_limits::infinity())) 101 | { 102 | n++; 103 | float y = flog2(x); 104 | 105 | mpfr_t y_mpfr; 106 | mpfr_init2(y_mpfr, 500); 107 | float y2 = EvaluateFunction(y_mpfr, x); 108 | if (y != y2) 109 | { 110 | incorrect++; 111 | cout << "Mismatch detected for x = " << x << endl; 112 | cout << "Expected: " << y << endl; 113 | cout << "Actual: " << y2 << endl; 114 | 115 | exit(0); 116 | } 117 | } 118 | 119 | clock_gettime(CLOCK_MONOTONIC_RAW, &end); 120 | n = 0; 121 | double delta_ms = (((end.tv_sec - start.tv_sec) * 1000000 + (end.tv_nsec - start.tv_nsec) / 1000) / 1000); 122 | cout << "ALibm" << endl; 123 | cout << "Total number of tests: " << n << endl; 124 | cout << "Total time taken: " << delta_ms << " ms" << endl; 125 | cout << "Number of incorrect results: " << incorrect << endl; 126 | cout << "Test complete." << endl; 127 | 128 | clock_gettime(CLOCK_MONOTONIC_RAW, &start); 129 | for (float x = LOW; x < HIGH; x = nextafterf(x, numeric_limits::infinity())) 130 | { 131 | n++; 132 | float y = log2(x); 133 | mpfr_t y_mpfr; 134 | mpfr_init2(y_mpfr, 500); 135 | float y2 = EvaluateFunction(y_mpfr, x); 136 | if (y != y2) 137 | { 138 | incorrect++; 139 | // cout << "Mismatch detected for x = " << x << endl; 140 | // cout << "Expected: " << y << endl; 141 | // cout << "Actual: " << y2 << endl; 142 | } 143 | } 144 | clock_gettime(CLOCK_MONOTONIC_RAW, &end); 145 | 146 | delta_ms = (((end.tv_sec - start.tv_sec) * 1000000 + (end.tv_nsec - start.tv_nsec) / 1000) / 1000); 147 | cout << "C Std lib" << endl; 148 | cout << "Total number of tests: " << n << endl; 149 | cout << "Total time taken: " << delta_ms << " ms" << endl; 150 | cout << "Number of incorrect results: " << incorrect << endl; 151 | cout << endl 152 | << endl; 153 | 154 | clock_gettime(CLOCK_MONOTONIC_RAW, &start); 155 | for (int i = 0; i < 10; i++) 156 | { 157 | for (float x = LOW; x < HIGH; x = nextafterf(x, numeric_limits::infinity())) 158 | { 159 | float y = log2(x); 160 | } 161 | } 162 | clock_gettime(CLOCK_MONOTONIC_RAW, &end); 163 | 164 | delta_ms = (((end.tv_sec - start.tv_sec) * 1000000 + (end.tv_nsec - start.tv_nsec) / 1000) / 1000); 165 | cout << "ALibm" << endl; 166 | cout << "Total time taken: " << delta_ms << " ms" << endl; 167 | clock_gettime(CLOCK_MONOTONIC_RAW, &start); 168 | 169 | for (int i = 0; i < 10; i++) 170 | { 171 | for (float x = LOW; x < HIGH; x = nextafterf(x, numeric_limits::infinity())) 172 | { 173 | float y = flog2(x); 174 | } 175 | } 176 | clock_gettime(CLOCK_MONOTONIC_RAW, &end); 177 | 178 | delta_ms = (((end.tv_sec - start.tv_sec) * 1000000 + (end.tv_nsec - start.tv_nsec) / 1000) / 1000); 179 | cout << "C Std Lib" << endl; 180 | cout << "Total time taken: " << delta_ms << " ms" << endl; 181 | 182 | return 0; 183 | } -------------------------------------------------------------------------------- /lib/flog2/flog2lib.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | struct Polynomial 9 | { 10 | int termsize; 11 | vector coefficients; 12 | }; 13 | typedef union 14 | { 15 | float f; 16 | unsigned x; 17 | } floatX; 18 | 19 | typedef union 20 | { 21 | double d; 22 | unsigned long x; 23 | } doubleX; 24 | 25 | unsigned long flog2_coef[5][7] = { 26 | 27 | { 28 | 13840088983442381949U, 29 | 4625347124714385442U, 30 | 13854123740975661436U, 31 | 4634414482658525937U, 32 | 13858134739117318847U, 33 | 4631380976507741609U, 34 | 13846118394287531079U, 35 | 36 | }, 37 | { 38 | 13839950078055808653U, 39 | 4624734434826564558U, 40 | 13853250229213416370U, 41 | 4632490643537813669U, 42 | 13855758816733519427U, 43 | 4628755719687040412U, 44 | 13842904545747925551U, 45 | 46 | }, 47 | { 48 | 13839813994467456793U, 49 | 4624047845104605039U, 50 | 13851984055115512867U, 51 | 4630870402802447671U, 52 | 13853712686755463775U, 53 | 4625998390763997241U, 54 | 13839806877980237190U, 55 | 56 | }, 57 | { 58 | 13839685728680924647U, 59 | 4623451467538231135U, 60 | 13850828237194977420U, 61 | 4629650078793719008U, 62 | 13851571232100972718U, 63 | 4623345689582687453U, 64 | 13836476175883689232U, 65 | 66 | }, 67 | { 68 | 13839589662576611435U, 69 | 4623033249594088492U, 70 | 13850069656578378951U, 71 | 4628182459009314188U, 72 | 13849974111505167414U, 73 | 4621491791609445057U, 74 | 13834307695743617449U, 75 | 76 | }}; 77 | Polynomial readPolynomialFromFile(const std::string &filename); 78 | double EvaulutePoly(int index, double xval); 79 | Polynomial InitPoly(int index); -------------------------------------------------------------------------------- /lib/flog2/flog2poly/2.txt: -------------------------------------------------------------------------------- 1 | 7 2 | 13840088983442381949 4625347124714385442 13854123740975661436 4634414482658525937 13858134739117318847 4631380976507741609 13846118394287531079 3 | -------------------------------------------------------------------------------- /lib/flog2/flog2poly/22.txt: -------------------------------------------------------------------------------- 1 | 7 2 | 13839950078055808653,4624734434826564558,13853250229213416370,4632490643537813669,13855758816733519427,4628755719687040412,13842904545747925551, 3 | -------------------------------------------------------------------------------- /lib/flog2/flog2poly/24.txt: -------------------------------------------------------------------------------- 1 | 7 2 | 13839813994467456793,4624047845104605039,13851984055115512867,4630870402802447671,13853712686755463775,4625998390763997241,13839806877980237190, 3 | -------------------------------------------------------------------------------- /lib/flog2/flog2poly/26.txt: -------------------------------------------------------------------------------- 1 | 7 2 | 13839685728680924647,4623451467538231135,13850828237194977420,4629650078793719008,13851571232100972718,4623345689582687453,13836476175883689232, 3 | -------------------------------------------------------------------------------- /lib/flog2/flog2poly/28.txt: -------------------------------------------------------------------------------- 1 | 7 2 | 13839589662576611435,4623033249594088492,13850069656578378951,4628182459009314188,13849974111505167414,4621491791609445057,13834307695743617449, 3 | -------------------------------------------------------------------------------- /old/1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschott20/ALibm/7de59ad0278d1fce37f69818244712c2704d16d5/old/1.cpp -------------------------------------------------------------------------------- /old/2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sschott20/ALibm/7de59ad0278d1fce37f69818244712c2704d16d5/old/2.cpp -------------------------------------------------------------------------------- /old/Interval_Data.h: -------------------------------------------------------------------------------- 1 | //!##################################################################### 2 | //! \file Interval_Data.h 3 | //!##################################################################### 4 | // Class Interval_Data 5 | //###################################################################### 6 | #ifndef __Interval_Data__ 7 | #define __Interval_Data__ 8 | 9 | class interval_data 10 | { 11 | public: 12 | double x; /* original input */ 13 | double lb; /* lower bound */ 14 | double ub; /* upper bound */ 15 | double w; /* weight */ 16 | double u; /* uniform random value */ 17 | int i; /* index in the powers table */ 18 | 19 | interval_data() {} 20 | 21 | interval_data(const double& x_input,const double& lb_input,const double& ub_input, 22 | const double& w_input,const double& u_input,const int i_input) 23 | :x(x_input),lb(lb_input),ub(ub_input),w(w_input),u(u_input),i(i_input) 24 | {} 25 | 26 | ~interval_data() {} 27 | 28 | interval_data& operator=(const interval_data& rhs) 29 | { 30 | if(this==&rhs) return *this; 31 | 32 | x = rhs.x; 33 | lb = rhs.lb; 34 | ub = rhs.ub; 35 | w = rhs.w; 36 | u = rhs.u; 37 | i = rhs.i; 38 | return *this; 39 | } 40 | }; 41 | #endif 42 | -------------------------------------------------------------------------------- /old/Makefile: -------------------------------------------------------------------------------- 1 | SOPLEX_INCLUDE=$(SOPLEXPATH)/src/ 2 | SOPLEX_LIB=$(SOPLEXPATH)/build/lib/libsoplex.a 3 | 4 | all: progressive 5 | 6 | progressive: rlibm-fast.h progressive.cpp 7 | g++ -O2 -I$(SOPLEX_INCLUDE) -std=c++11 progressive.cpp $(SOPLEX_LIB) -o polygen -lgmp -lz -lm 8 | 9 | clean: 10 | rm -f *~ polygen filter *.txt 11 | 12 | -------------------------------------------------------------------------------- /old/Sample_Data.h: -------------------------------------------------------------------------------- 1 | //!##################################################################### 2 | //! \file Sample_Data.h 3 | //!##################################################################### 4 | // Class Sample_Data 5 | //###################################################################### 6 | #ifndef __Sample_Data__ 7 | #define __Sample_Data__ 8 | 9 | class sample_data 10 | { 11 | public: 12 | double x; 13 | double lb; 14 | double ub; 15 | double orig_lb; /* remember lb before narrowing */ 16 | double orig_ub; /* remember ub before narrowing */ 17 | double w; 18 | double u; 19 | double k; /* key computed as 1/u^w */ 20 | int i; 21 | 22 | sample_data() {} 23 | ~sample_data() {} 24 | }; 25 | #endif 26 | -------------------------------------------------------------------------------- /old/Utilities.cpp: -------------------------------------------------------------------------------- 1 | //!##################################################################### 2 | //! \file Utilities.cpp 3 | //!##################################################################### 4 | #include "Utilities.h" 5 | #include 6 | #include 7 | #include 8 | //###################################################################### 9 | // Number_Of_Intervals 10 | //###################################################################### 11 | unsigned long Utilities:: 12 | Number_Of_Intervals(int argc, char** argv) 13 | { 14 | unsigned long nentries = 0; 15 | 16 | for(int i=1;i distribution(0.0, 1.0); 38 | 39 | unsigned long j=0; 40 | for(int i=1;i 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #define SAMPLE_START 1.0 13 | #define SAMPLE_END 2.0 14 | #define L 32 15 | #define INV_L = (double) 32 / log(2) 16 | 17 | using namespace std; 18 | using namespace soplex; 19 | 20 | struct RndInterval 21 | { 22 | float x_orig; 23 | float y; 24 | 25 | double l; 26 | double u; 27 | 28 | double x_rr; 29 | double yp; 30 | double lp; 31 | double up; 32 | }; 33 | 34 | typedef union 35 | { 36 | float f; 37 | int i; 38 | } floatX; 39 | 40 | struct Polynomial 41 | { 42 | int termsize; 43 | vector coefficients; 44 | }; 45 | 46 | int write_rnd_interval_to_file(vector X, const char *filename) 47 | { 48 | FILE *fptr; 49 | fptr = fopen(filename, "wb"); 50 | 51 | for (size_t i = 0; i < X.size(); i++) 52 | { 53 | 54 | fwrite(&X.at(i), sizeof(RndInterval), 1, fptr); 55 | } 56 | fclose(fptr); 57 | 58 | return 0; 59 | } 60 | vector read_rnd_interval_from_file(const char *filename) 61 | { 62 | vector X; 63 | FILE *fptr; 64 | fptr = fopen(filename, "rb"); 65 | RndInterval x1; 66 | 67 | while (fread(&x1, sizeof(RndInterval), 1, fptr) == 1) 68 | { 69 | X.push_back(x1); 70 | } 71 | fclose(fptr); 72 | 73 | return X; 74 | } 75 | 76 | double RangeReduction(float x) 77 | { 78 | long N = round(x * INV_L); 79 | long N2 = N % LL; 80 | long N1 = N - N2; 81 | } 82 | 83 | double OutputCompensation(float x, double yp) 84 | { 85 | int exp; 86 | double sig = frexp(x, &exp); 87 | return yp + exp; 88 | } 89 | 90 | double InverseOutputCompensation(float x, double yp) 91 | { 92 | int exp; 93 | double sig = frexp(x, &exp); 94 | return yp - exp; 95 | } 96 | 97 | vector GenerateFloatSample(float start, float end, size_t cap, size_t step) 98 | { 99 | FILE *fptr; 100 | fptr = fopen("dump/GenFloatSample.txt", "w"); 101 | 102 | vector X; 103 | size_t n = 0; 104 | 105 | for (float f = start; f < end; 106 | f = nextafterf(f, INFINITY)) 107 | { 108 | if (n > cap) 109 | { 110 | break; 111 | } 112 | 113 | n++; 114 | 115 | RndInterval I; 116 | I.x_orig = f; 117 | I.x_rr = RangeReduction(f); 118 | X.push_back(I); 119 | 120 | fprintf(fptr, "%4.30f %4.30f\n", f, I.x_rr); 121 | 122 | for (int i = 0; i < step; i++) 123 | { 124 | f = nextafterf(f, INFINITY); 125 | } 126 | } 127 | printf("sample size = %ld\n", n); 128 | return X; 129 | } 130 | 131 | vector CalcRndIntervals(vector X) 132 | { 133 | FILE *fptr; 134 | fptr = fopen("dump/CalcRndIntervals.txt", "w"); 135 | 136 | float y; 137 | double l, u; 138 | 139 | mpfr_t y_mpfr, x_mpfr; 140 | 141 | mpfr_inits2(200, y_mpfr, x_mpfr, NULL); 142 | 143 | vector L; 144 | 145 | for (size_t i = 0; i < X.size(); i++) 146 | { 147 | RndInterval I; 148 | I.x_orig = X.at(i).x_orig; 149 | I.x_rr = X.at(i).x_rr; 150 | 151 | mpfr_set_flt(x_mpfr, X.at(i).x_orig, MPFR_RNDN); 152 | mpfr_log2(y_mpfr, x_mpfr, MPFR_RNDN); 153 | 154 | y = mpfr_get_flt(y_mpfr, MPFR_RNDN); 155 | 156 | float lfloat = nextafterf(y, -INFINITY); 157 | float ufloat = nextafterf(y, +INFINITY); 158 | 159 | l = ((double)y + (double)lfloat) / 2; 160 | u = ((double)y + (double)ufloat) / 2; 161 | 162 | while ((float)l != (float)y) 163 | { 164 | l = nextafter(l, y); 165 | } 166 | assert((float)l == (float)y); 167 | 168 | while ((float)u != (float)y) 169 | { 170 | u = nextafter(u, y); 171 | } 172 | assert((float)u == (float)y); 173 | 174 | if (l > u) 175 | { 176 | printf("x = %4.15f y = %4.15f l = %4.15f u = %4.15f\n", X.at(i).x_orig, y, l, u); 177 | double temp = l; 178 | l = u; 179 | u = temp; 180 | } 181 | assert(l < u); 182 | 183 | // fprintf(fptr, "%.24e %.24e %.24e %.24e \n", x, y, l, h); 184 | fprintf(fptr, "%4.15f %4.15f %4.40f %4.40f \n", (double)X.at(i).x_orig, (double)y, l, u); 185 | I.y = y; 186 | I.l = l; 187 | I.u = u; 188 | 189 | L.push_back(I); 190 | } 191 | return L; 192 | } 193 | 194 | vector CalcRedIntervals(vector L) 195 | { 196 | FILE *fptr; 197 | fptr = fopen("dump/CalcRedIntervals.txt", "w"); 198 | float yp; 199 | double lp, up; 200 | 201 | mpfr_t yp_mpfr, xrr_mpfr; 202 | mpfr_inits2(200, yp_mpfr, xrr_mpfr, NULL); 203 | 204 | vector L2; 205 | 206 | for (size_t i = 0; i < L.size(); i++) 207 | { 208 | RndInterval I; 209 | I.x_orig = L.at(i).x_orig; 210 | I.x_rr = L.at(i).x_rr; 211 | 212 | I.y = L.at(i).y; 213 | I.l = L.at(i).l; 214 | I.u = L.at(i).u; 215 | 216 | lp = InverseOutputCompensation(L.at(i).x_orig, L.at(i).l); 217 | up = InverseOutputCompensation(L.at(i).x_orig, L.at(i).u); 218 | 219 | // printf("lp = %4.15f up = %4.15f\n", lp, up); 220 | // printf("lp = %4.15f up = %4.15f\n", lp, up); 221 | // printf("yp = %4.15f\n", yp); 222 | while (OutputCompensation(L.at(i).x_orig, lp) <= L.at(i).l) 223 | { 224 | for (int j = 0; j < 100; j++) 225 | { 226 | lp = nextafter(lp, up); 227 | } 228 | // lp = nextafter(lp, up); 229 | // lp += 0.0000001; 230 | } 231 | while (OutputCompensation(L.at(i).x_orig, up) >= L.at(i).u) 232 | { 233 | for (int j = 0; j < 100; j++) 234 | { 235 | up = nextafter(up, lp); 236 | } 237 | up = nextafter(up, lp); 238 | // up -= 0.0000001; 239 | } 240 | // printf("lp = %4.15f up = %4.15f\n", lp, up); 241 | // printf("lp = %4.15f up = %4.15f\n", lp, up); 242 | // if (lp >= up) 243 | // { 244 | // printf("x = %4.15f lp = %4.15f up = %4.15f\n", L.at(i).x_orig, lp, up); 245 | // double temp = lp; 246 | // lp = up; 247 | // up = temp; 248 | // } 249 | assert(lp < up); 250 | 251 | fprintf(fptr, "%4.15f %4.40f %4.40f %4.40f \n", (double)L.at(i).x_orig, L.at(i).x_rr, lp, up); 252 | I.lp = lp; 253 | I.up = up; 254 | 255 | L2.push_back(I); 256 | } 257 | return L2; 258 | } 259 | 260 | Polynomial GeneratePolynomial(vector L2) 261 | { 262 | 263 | // int termsize = 3; 264 | // for (int termsize = 29; termsize < 30; termsize++) 265 | for (int termsize = 1; termsize < 30; termsize++) 266 | { 267 | 268 | SoPlex mysoplex; 269 | mysoplex.setBoolParam(SoPlex::RATFACJUMP, true); 270 | mysoplex.setIntParam(SoPlex::SOLVEMODE, 2); 271 | mysoplex.setIntParam(SoPlex::CHECKMODE, 2); 272 | mysoplex.setIntParam(SoPlex::SYNCMODE, 1); 273 | mysoplex.setIntParam(SoPlex::READMODE, 1); 274 | mysoplex.setRealParam(SoPlex::FEASTOL, 0.0); 275 | mysoplex.setRealParam(SoPlex::OPTTOL, 0.0); 276 | mysoplex.setRealParam(SoPlex::EPSILON_ZERO, 0.0); 277 | mysoplex.setRealParam(SoPlex::EPSILON_FACTORIZATION, 0.0); 278 | mysoplex.setRealParam(SoPlex::EPSILON_UPDATE, 0.0); 279 | mysoplex.setRealParam(SoPlex::EPSILON_PIVOT, 0.0); 280 | mysoplex.setIntParam(SoPlex::VERBOSITY, 0); 281 | mysoplex.setRealParam(SoPlex::TIMELIMIT, 5 * 60); 282 | mysoplex.setIntParam(SoPlex::OBJSENSE, SoPlex::OBJSENSE_MINIMIZE); 283 | DSVectorRational dummycol(0); 284 | for (int i = 0; i < termsize; i++) 285 | { 286 | auto column = LPColRational(1.0, dummycol, infinity, -infinity); 287 | mysoplex.addColRational(column); 288 | } 289 | 290 | /* then constraints one by one */ 291 | for (int i = 0; i < L2.size(); i++) 292 | // for (int i = 1; i < 50; i++) 293 | { 294 | DSVectorRational row1(termsize); 295 | Rational acc(1.0); 296 | Rational xval(L2.at(i).x_rr); 297 | row1.add(0, 1.0); 298 | 299 | for (int j = 1; j < termsize; j++) 300 | { 301 | acc = acc * xval; 302 | row1.add(j, acc); 303 | } 304 | double lbnd = (L2.at(i).lp); 305 | double ubnd = (L2.at(i).up); 306 | // print x 307 | // mpfr_out_str(stdout, 10, 0, L.at(i).x, MPFR_RNDN); 308 | mysoplex.addRowRational(LPRowRational(lbnd, row1, ubnd)); 309 | } 310 | 311 | mysoplex.writeFileRational("dump/f32_dump_rational.lp", NULL, NULL, NULL); 312 | mysoplex.writeFileReal("dump/f32_dump_real.lp", NULL, NULL, NULL); 313 | 314 | SPxSolver::Status stat; 315 | cout << "Solving... " << termsize << "\n"; 316 | 317 | stat = mysoplex.optimize(); 318 | Polynomial P; 319 | 320 | if (stat == SPxSolver::OPTIMAL) 321 | { 322 | DVectorRational prim(termsize); 323 | mysoplex.getPrimalRational(prim); 324 | 325 | P.termsize = termsize; 326 | for (int i = 0; i < termsize; i++) 327 | { 328 | P.coefficients.push_back(prim[i]); 329 | } 330 | 331 | return P; 332 | } 333 | else if (stat == SPxSolver::UNBOUNDED) 334 | { 335 | DVectorRational prim(termsize); 336 | mysoplex.getPrimalRational(prim); 337 | 338 | P.termsize = termsize; 339 | std::cout << "Unbounded solution\n"; 340 | for (int i = 0; i < termsize; i++) 341 | { 342 | P.coefficients.push_back(0.0); 343 | } 344 | } 345 | // output stat 346 | std::cout << "Status: " << stat << std::endl; 347 | } 348 | Polynomial N; 349 | 350 | return N; 351 | } 352 | double EvaulutePoly(Polynomial P, double xval) 353 | { 354 | double acc = 0.0; 355 | double power = 1.0; 356 | 357 | for (int i = 0; i < P.termsize; i++) 358 | { 359 | 360 | acc += P.coefficients.at(i) * power; 361 | power *= xval; 362 | } 363 | 364 | return acc; 365 | } 366 | 367 | void VerifyConsistant(vector L2, Polynomial P) 368 | { 369 | size_t n = 0; 370 | size_t correct = 0; 371 | 372 | for (size_t i = 0; i < L2.size(); i++) 373 | { 374 | n++; 375 | float f = L2.at(i).x_orig; 376 | 377 | double x = (double)f; 378 | double x_rr = RangeReduction(f); 379 | double eval = EvaulutePoly(P, x_rr); 380 | 381 | float y = OutputCompensation(f, eval); 382 | 383 | mpfr_t y_mpfr; 384 | mpfr_init2(y_mpfr, 200); 385 | mpfr_set_d(y_mpfr, x, MPFR_RNDN); 386 | mpfr_log2(y_mpfr, y_mpfr, MPFR_RNDN); 387 | 388 | float oracle = (float)mpfr_get_d(y_mpfr, MPFR_RNDN); 389 | 390 | if (y == oracle) 391 | { 392 | correct++; 393 | } 394 | else 395 | { 396 | printf("failed: x = %4.30f y = %4.30f oracle = %4.30f\n", x, y, oracle); 397 | printf("x_rr = %4.30f eval = %4.30f\n\n", x_rr, eval); 398 | } 399 | } 400 | 401 | printf("correct = %ld incorrect = %ld\n", correct, n - correct); 402 | return; 403 | } 404 | vector VerifyContinuous(vector L2, Polynomial P, float start, float end, size_t cap) 405 | { 406 | size_t n = 0; 407 | size_t correct = 0; 408 | 409 | for (float f = start; f < end; 410 | f = nextafterf(f, INFINITY)) 411 | { 412 | if (n > cap) 413 | { 414 | break; 415 | } 416 | 417 | n++; 418 | 419 | double x = (double)f; 420 | double x_rr = RangeReduction(f); 421 | double eval = EvaulutePoly(P, x_rr); 422 | 423 | float y = OutputCompensation(f, eval); 424 | 425 | mpfr_t y_mpfr; 426 | mpfr_init2(y_mpfr, 200); 427 | mpfr_set_d(y_mpfr, x, MPFR_RNDN); 428 | mpfr_log2(y_mpfr, y_mpfr, MPFR_RNDN); 429 | 430 | float oracle = (float)mpfr_get_d(y_mpfr, MPFR_RNDN); 431 | 432 | if (y == oracle) 433 | { 434 | correct++; 435 | } 436 | else 437 | { 438 | // printf("continuous Failed: x = %4.30f y = %4.30f oracle = %4.30f x_rr = %4.30f eval = %4.30f\n", x, y, oracle, x_rr, eval); 439 | RndInterval I; 440 | I.x_orig = f; 441 | I.x_rr = x_rr; 442 | L2.push_back(I); 443 | } 444 | } 445 | printf("correct = %ld incorrect = %ld\n", correct, n - correct); 446 | return L2; 447 | } 448 | 449 | int main(int argc, char *argv[]) 450 | { 451 | // 0 : dont use files at all 452 | // 1 : send results to files 453 | // 2 : read results from files if available 454 | 455 | int save_to_file = 0; 456 | // check if first command line arg is -y 457 | if (argc == 2) 458 | { 459 | if (strcmp(argv[1], "1") == 0) 460 | { 461 | save_to_file = 1; 462 | } 463 | } 464 | 465 | printf("Generating FloatSample...\n"); 466 | vector X = GenerateFloatSample(1.01, 1.2, 1000000, 2000); 467 | size_t last = X.size(); 468 | 469 | for (;;) 470 | { 471 | 472 | printf("Generating RndIntervals...\n"); 473 | vector L = CalcRndIntervals(X); 474 | 475 | printf("Generating RedIntervals...\n"); 476 | vector L2 = CalcRedIntervals(L); 477 | 478 | printf("Generating Polynomial...\n"); 479 | Polynomial P = GeneratePolynomial(L2); 480 | 481 | FILE *fptr; 482 | fptr = fopen("dump/poly.txt", "w"); 483 | for (int i = 0; i < P.termsize; i++) 484 | { 485 | fprintf(fptr, "%5.60f\n", P.coefficients.at(i)); 486 | // printf("%5.60f\n", P.coefficients.at(i)); 487 | } 488 | 489 | VerifyConsistant(L2, P); 490 | X = VerifyContinuous(L2, P, 1.01, 1.2, 100000); 491 | if (X.size() == last) 492 | { 493 | break; 494 | } 495 | printf("X size = %ld\n", X.size()); 496 | last = X.size(); 497 | } 498 | 499 | printf("Finished!\n"); 500 | } -------------------------------------------------------------------------------- /old/expm1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "helper.hpp" 12 | 13 | using namespace std; 14 | using namespace soplex; 15 | 16 | #define ROUND_2_INT(f) ((int)(f >= 0.0 ? (f + 0.5) : (f - 0.5))) 17 | #define HEX_TO_DOUBLE(h) ((doubleX){i : h}).d 18 | #define HEX_TO_FLOAT(h) ((floatX){i : h}).f 19 | 20 | struct ReducedFloat 21 | { 22 | int m; 23 | int j; 24 | double r1; 25 | double r2; 26 | }; 27 | 28 | double Inv_L = HEX_TO_DOUBLE(0x40471547652B82FE); 29 | double L1 = HEX_TO_DOUBLE(0x3F962E42FEF00000); 30 | double L2 = HEX_TO_DOUBLE(0x3D8473DE6AF278ED); 31 | 32 | float ttiny = HEX_TO_FLOAT(0x33000000) float tpos = HEX_TO_FLOAT(0x436C5CFA) float tneg = HEX_TO_FLOAT(0xC18AA122) 33 | 34 | // reduce x to the range [-ln2 / 64, ln2 / 64], X = (32M + J)ln2 / 64 + (R1 + R2) 35 | // M, J : int 36 | // R1, R2 : double 37 | ReducedFloat 38 | RangeReduction(float x) 39 | { 40 | ReducedFloat rf; 41 | double r1, r2; 42 | int n, n1, n2; 43 | 44 | n = ROUND_2_INT(x * Inv_L); 45 | n2 = n % 32; 46 | 47 | printf("%d\n", n2); 48 | printf("%d\n", n); 49 | 50 | n1 = n - n2; 51 | 52 | if (abs(n) > 2 ^ 9) 53 | { 54 | r1 = (x - n1 * L1) - n2 * L1; 55 | } 56 | else 57 | { 58 | r1 = x - n * (double)L1; 59 | } 60 | 61 | r2 = -n * (double)L2; 62 | 63 | rf.j = n2; 64 | rf.m = n1 / 32; 65 | 66 | rf.r1 = r1; 67 | rf.r2 = r2; 68 | 69 | cout << rf.j << " " << rf.m << " " << rf.r1 << " " << rf.r2 << endl; 70 | cout << (double)(32 * rf.m + rf.j) * ((double)L1 + (double)L2) + (double)(rf.r1 + rf.r2) << endl; 71 | return rf; 72 | } 73 | 74 | float expm1(float x) 75 | { 76 | // filter speical cases 77 | 78 | if (isinf(x) && x < 0) 79 | { 80 | return -1; 81 | } 82 | 83 | if (isinf(x) && x > 0) 84 | { 85 | return x; 86 | } 87 | 88 | // 0 < x < Te -> expm1 ~ x 89 | if (abs(x) > 0 && abs(x) < ttiny) 90 | { 91 | return x; 92 | } 93 | } 94 | 95 | int main(int argc, char *argv[]) 96 | { 97 | ReducedFloat rf = RangeReduction(1.125); 98 | 99 | return 0; 100 | } -------------------------------------------------------------------------------- /old/file_io.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | struct RndInterval 12 | { 13 | float x_orig; 14 | float y; 15 | 16 | double l; 17 | double u; 18 | 19 | double x_rr; 20 | double yp; 21 | double lp; 22 | double up; 23 | }; 24 | 25 | 26 | int main() 27 | { 28 | vector X; 29 | for (int i = 0; i < 123; i++) 30 | { 31 | RndInterval x1 = {x_orig : i, x_rr : 2}; 32 | X.push_back(x1); 33 | } 34 | 35 | write_rnd_interval_to_file(X, "iotest.bin"); 36 | vector X2 = read_rnd_interval_from_file("iotest.bin"); 37 | 38 | for (int i = 0; i < X2.size(); i++) 39 | { 40 | printf("All fields of X: %f %f %f %f %f %f %f %f\n", X.at(i).x_orig, X.at(i).y, X.at(i).l, X.at(i).u, X.at(i).x_rr, X.at(i).yp, X.at(i).lp, X.at(i).up); 41 | } 42 | return 0; 43 | } -------------------------------------------------------------------------------- /old/float.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "helper.hpp" 12 | 13 | #define SAMPLE_START 1.01 14 | #define SAMPLE_END 1.04 15 | 16 | using namespace std; 17 | using namespace soplex; 18 | 19 | 20 | double RangeReduction(float x) 21 | { 22 | int exp; 23 | double sig = frexp(x, &exp); 24 | return sig; 25 | } 26 | 27 | double OutputCompensation(float x, double yp) 28 | { 29 | int exp; 30 | double sig = frexp(x, &exp); 31 | return yp + exp; 32 | } 33 | 34 | double InverseOutputCompensation(float x, double yp) 35 | { 36 | int exp; 37 | double sig = frexp(x, &exp); 38 | return yp - exp; 39 | } 40 | 41 | vector GenerateFloatSample(float start, float end, size_t cap, size_t step) 42 | { 43 | FILE *fptr; 44 | fptr = fopen("dump/GenFloatSample.txt", "w"); 45 | 46 | vector X; 47 | size_t n = 0; 48 | 49 | for (float f = start; f < end; 50 | f = nextafterf(f, INFINITY)) 51 | { 52 | if (n > cap) 53 | { 54 | break; 55 | } 56 | 57 | n++; 58 | 59 | RndInterval I; 60 | I.x_orig = f; 61 | I.x_rr = RangeReduction(f); 62 | X.push_back(I); 63 | 64 | fprintf(fptr, "%4.30f %4.30f\n", f, I.x_rr); 65 | 66 | for (int i = 0; i < step; i++) 67 | { 68 | f = nextafterf(f, INFINITY); 69 | } 70 | } 71 | printf("sample size = %ld\n", n); 72 | return X; 73 | } 74 | 75 | vector CalcRndIntervals(vector X) 76 | { 77 | FILE *fptr; 78 | fptr = fopen("dump/CalcRndIntervals.txt", "w"); 79 | 80 | float y; 81 | double l, u; 82 | 83 | mpfr_t y_mpfr, x_mpfr; 84 | 85 | mpfr_inits2(200, y_mpfr, x_mpfr, NULL); 86 | 87 | vector L; 88 | 89 | for (size_t i = 0; i < X.size(); i++) 90 | { 91 | RndInterval I; 92 | I.x_orig = X.at(i).x_orig; 93 | I.x_rr = X.at(i).x_rr; 94 | 95 | mpfr_set_flt(x_mpfr, X.at(i).x_orig, MPFR_RNDN); 96 | mpfr_log2(y_mpfr, x_mpfr, MPFR_RNDN); 97 | 98 | y = mpfr_get_flt(y_mpfr, MPFR_RNDN); 99 | 100 | float lfloat = nextafterf(y, -INFINITY); 101 | float ufloat = nextafterf(y, +INFINITY); 102 | 103 | l = ((double)y + (double)lfloat) / 2.0; 104 | u = ((double)y + (double)ufloat) / 2.0; 105 | 106 | while ((float)l != (float)y) 107 | { 108 | l = nextafter(l, u); 109 | } 110 | l = nextafter(l, u); 111 | 112 | assert((float)l == (float)y); 113 | 114 | while ((float)u != (float)y) 115 | { 116 | u = nextafter(u, l); 117 | } 118 | u = nextafter(u, l); 119 | 120 | assert((float)u == (float)y); 121 | 122 | if (l > u) 123 | { 124 | printf("x = %4.15f y = %4.15f l = %4.15f u = %4.15f\n", X.at(i).x_orig, y, l, u); 125 | double temp = l; 126 | l = u; 127 | u = temp; 128 | } 129 | assert(l < u); 130 | 131 | // fprintf(fptr, "%.24e %.24e %.24e %.24e \n", x, y, l, h); 132 | fprintf(fptr, "%4.15f %4.15f %4.40f %4.40f \n", (double)X.at(i).x_orig, (double)y, l, u); 133 | I.y = y; 134 | I.l = l; 135 | I.u = u; 136 | 137 | L.push_back(I); 138 | } 139 | return L; 140 | } 141 | 142 | vector CalcRedIntervals(vector L) 143 | { 144 | FILE *fptr; 145 | fptr = fopen("dump/CalcRedIntervals.txt", "w"); 146 | float yp; 147 | double lp, up; 148 | 149 | mpfr_t yp_mpfr, xrr_mpfr; 150 | mpfr_inits2(200, yp_mpfr, xrr_mpfr, NULL); 151 | 152 | vector L2; 153 | 154 | for (size_t i = 0; i < L.size(); i++) 155 | { 156 | RndInterval I; 157 | I.x_orig = L.at(i).x_orig; 158 | I.x_rr = L.at(i).x_rr; 159 | 160 | I.y = L.at(i).y; 161 | I.l = L.at(i).l; 162 | I.u = L.at(i).u; 163 | 164 | lp = InverseOutputCompensation(L.at(i).x_orig, L.at(i).l); 165 | up = InverseOutputCompensation(L.at(i).x_orig, L.at(i).u); 166 | 167 | // printf("lp = %4.15f up = %4.15f\n", lp, up); 168 | // printf("lp = %4.15f up = %4.15f\n", lp, up); 169 | // printf("yp = %4.15f\n", yp); 170 | while ((float)OutputCompensation(L.at(i).x_orig, lp) != L.at(i).y) 171 | 172 | // while ((float)OutputCompensation(L.at(i).x_orig, lp) != L.at(i).y) 173 | { 174 | for (int j = 0; j < 3; j++) 175 | { 176 | lp = nextafter(lp, up); 177 | } 178 | // lp = nextafter(lp, up); 179 | // lp += 0.0000001; 180 | } 181 | // while (OutputCompensation(L.at(i).x_orig, up) > L.at(i).u || OutputCompensation(L.at(i).x_orig, up) < L.at(i).l) 182 | while ((float)OutputCompensation(L.at(i).x_orig, up) != L.at(i).y) 183 | { 184 | for (int j = 0; j < 3; j++) 185 | { 186 | up = nextafter(up, lp); 187 | } 188 | // up = nextafter(up, lp); 189 | // up -= 0.0000001; 190 | } 191 | // printf("lp = %4.15f up = %4.15f\n", lp, up); 192 | // printf("lp = %4.15f up = %4.15f\n", lp, up); 193 | // if (lp >= up) 194 | // { 195 | // printf("x = %4.15f lp = %4.15f up = %4.15f\n", L.at(i).x_orig, lp, up); 196 | // double temp = lp; 197 | // lp = up; 198 | // up = temp; 199 | // } 200 | assert(lp < up); 201 | 202 | fprintf(fptr, "%4.15f %4.40f %4.40f %4.40f \n", (double)L.at(i).x_orig, L.at(i).x_rr, lp, up); 203 | I.lp = lp; 204 | I.up = up; 205 | 206 | L2.push_back(I); 207 | } 208 | return L2; 209 | } 210 | 211 | Polynomial GeneratePolynomial(vector L2) 212 | { 213 | 214 | // int termsize = 3; 215 | // for (int termsize = 29; termsize < 30; termsize++) 216 | for (int termsize = 1; termsize < 30; termsize++) 217 | { 218 | 219 | SoPlex mysoplex; 220 | mysoplex.setBoolParam(SoPlex::RATFACJUMP, true); 221 | mysoplex.setIntParam(SoPlex::SOLVEMODE, 2); 222 | mysoplex.setIntParam(SoPlex::CHECKMODE, 2); 223 | mysoplex.setIntParam(SoPlex::SYNCMODE, 1); 224 | mysoplex.setIntParam(SoPlex::READMODE, 1); 225 | mysoplex.setRealParam(SoPlex::FEASTOL, 0.0); 226 | mysoplex.setRealParam(SoPlex::OPTTOL, 0.0); 227 | mysoplex.setRealParam(SoPlex::EPSILON_ZERO, 0.0); 228 | mysoplex.setRealParam(SoPlex::EPSILON_FACTORIZATION, 0.0); 229 | mysoplex.setRealParam(SoPlex::EPSILON_UPDATE, 0.0); 230 | mysoplex.setRealParam(SoPlex::EPSILON_PIVOT, 0.0); 231 | mysoplex.setIntParam(SoPlex::VERBOSITY, 0); 232 | mysoplex.setRealParam(SoPlex::TIMELIMIT, 5 * 60); 233 | mysoplex.setIntParam(SoPlex::OBJSENSE, SoPlex::OBJSENSE_MINIMIZE); 234 | DSVectorRational dummycol(0); 235 | for (int i = 0; i < termsize; i++) 236 | { 237 | auto column = LPColRational(1.0, dummycol, infinity, -infinity); 238 | mysoplex.addColRational(column); 239 | } 240 | 241 | /* then constraints one by one */ 242 | for (int i = 0; i < L2.size(); i++) 243 | // for (int i = 1; i < 50; i++) 244 | { 245 | DSVectorRational row1(termsize); 246 | Rational acc(1.0); 247 | Rational xval(L2.at(i).x_rr); 248 | row1.add(0, 1.0); 249 | 250 | for (int j = 1; j < termsize; j++) 251 | { 252 | acc = acc * xval; 253 | row1.add(j, acc); 254 | } 255 | double lbnd = (L2.at(i).lp); 256 | double ubnd = (L2.at(i).up); 257 | // print x 258 | // mpfr_out_str(stdout, 10, 0, L.at(i).x, MPFR_RNDN); 259 | mysoplex.addRowRational(LPRowRational(lbnd, row1, ubnd)); 260 | } 261 | 262 | mysoplex.writeFileRational("dump/f32_dump_rational.lp", NULL, NULL, NULL); 263 | mysoplex.writeFileReal("dump/f32_dump_real.lp", NULL, NULL, NULL); 264 | 265 | SPxSolver::Status stat; 266 | // cout << "Solving... " << termsize << "\n"; 267 | 268 | stat = mysoplex.optimize(); 269 | Polynomial P; 270 | 271 | if (stat == SPxSolver::OPTIMAL) 272 | { 273 | DVectorRational prim(termsize); 274 | mysoplex.getPrimalRational(prim); 275 | 276 | P.termsize = termsize; 277 | for (int i = 0; i < termsize; i++) 278 | { 279 | P.coefficients.push_back(prim[i]); 280 | } 281 | 282 | return P; 283 | } 284 | else if (stat == SPxSolver::UNBOUNDED) 285 | { 286 | DVectorRational prim(termsize); 287 | mysoplex.getPrimalRational(prim); 288 | 289 | P.termsize = termsize; 290 | std::cout << "Unbounded solution\n"; 291 | for (int i = 0; i < termsize; i++) 292 | { 293 | P.coefficients.push_back(0.0); 294 | } 295 | } 296 | // output stat 297 | // std::cout << "Status: " << stat << std::endl; 298 | } 299 | Polynomial N; 300 | 301 | return N; 302 | } 303 | double EvaulutePoly(Polynomial P, double xval) 304 | { 305 | double acc = 0.0; 306 | double power = 1.0; 307 | 308 | for (int i = 0; i < P.termsize; i++) 309 | { 310 | 311 | acc += P.coefficients.at(i) * power; 312 | power *= xval; 313 | } 314 | 315 | return acc; 316 | } 317 | 318 | vector VerifyConsistant(vector L2, Polynomial P) 319 | { 320 | size_t n = 0; 321 | size_t correct = 0; 322 | 323 | for (size_t i = 0; i < L2.size(); i++) 324 | { 325 | n++; 326 | float f = L2.at(i).x_orig; 327 | 328 | // double x = (double)f; 329 | double x_rr = RangeReduction(f); 330 | double eval = EvaulutePoly(P, x_rr); 331 | 332 | float y = OutputCompensation(f, eval); 333 | 334 | mpfr_t y_mpfr; 335 | mpfr_init2(y_mpfr, 200); 336 | mpfr_set_flt(y_mpfr, f, MPFR_RNDN); 337 | mpfr_log2(y_mpfr, y_mpfr, MPFR_RNDN); 338 | 339 | float oracle = (float)mpfr_get_d(y_mpfr, MPFR_RNDN); 340 | 341 | if (y == oracle) 342 | { 343 | correct++; 344 | } 345 | else 346 | { 347 | // L2.at(i).l 348 | // print x y oracle xrr eval y l u lp up 349 | // printf("failed: x = %4.30f y = %4.30f oracle = %4.30f\n", f, y, oracle); 350 | // printf("l = %4.30f u = %4.30f lp = %4.30f up = %4.30f\n", L2.at(i).l, L2.at(i).u, L2.at(i).lp, L2.at(i).up); 351 | // printf("x_rr = %4.30f eval = %4.30f\n\n", x_rr, eval); 352 | // print("") 353 | } 354 | } 355 | 356 | printf("In sample: correct = %ld incorrect = %ld\n", correct, n - correct); 357 | return L2; 358 | } 359 | vector VerifyContinuous(vector L2, Polynomial P, float start, float end, size_t cap) 360 | { 361 | size_t n = 0; 362 | size_t correct = 0; 363 | 364 | for (float f = start; f < end; 365 | f = nextafterf(f, INFINITY)) 366 | { 367 | if (cap > 0 & n > cap) 368 | { 369 | break; 370 | } 371 | 372 | n++; 373 | 374 | double x = (double)f; 375 | double x_rr = RangeReduction(f); 376 | double eval = EvaulutePoly(P, x_rr); 377 | 378 | float y = OutputCompensation(f, eval); 379 | 380 | mpfr_t y_mpfr; 381 | mpfr_init2(y_mpfr, 200); 382 | mpfr_set_d(y_mpfr, x, MPFR_RNDN); 383 | mpfr_log2(y_mpfr, y_mpfr, MPFR_RNDN); 384 | 385 | float oracle = mpfr_get_flt(y_mpfr, MPFR_RNDN); 386 | 387 | if (y == oracle) 388 | { 389 | correct++; 390 | } 391 | else 392 | { 393 | // printf("continuous Failed: x = %4.30f y = %4.30f oracle = %4.30f x_rr = %4.30f eval = %4.30f\n", x, y, oracle, x_rr, eval); 394 | RndInterval I; 395 | I.x_orig = f; 396 | I.x_rr = x_rr; 397 | 398 | L2.push_back(I); 399 | return L2; 400 | } 401 | } 402 | printf("Full range: correct = %ld incorrect = %ld\n", correct, n - correct); 403 | return L2; 404 | } 405 | 406 | int main(int argc, char *argv[]) 407 | { 408 | // 0 : dont use files at all 409 | // 1 : send results to files 410 | // 2 : read results from files if available 411 | 412 | // int save_to_file = 0; 413 | // if (argc == 2) 414 | // { 415 | // if (strcmp(argv[1], "1") == 0) 416 | // { 417 | // save_to_file = 1; 418 | // } 419 | // } 420 | 421 | printf("Generating FloatSample...\n"); 422 | vector X = GenerateFloatSample(SAMPLE_START, SAMPLE_END, 1000000, 1234); 423 | size_t last = X.size(); 424 | 425 | Polynomial P; 426 | for (;;) 427 | { 428 | printf("Generating RndIntervals...\n"); 429 | vector L = CalcRndIntervals(X); 430 | 431 | printf("Generating RedIntervals...\n"); 432 | vector L2 = CalcRedIntervals(L); 433 | 434 | printf("Generating Polynomial...\n"); 435 | P = GeneratePolynomial(L2); 436 | 437 | FILE *fptr; 438 | fptr = fopen("dump/poly.txt", "w"); 439 | for (int i = 0; i < P.termsize; i++) 440 | { 441 | fprintf(fptr, "%5.60f\n", P.coefficients.at(i)); 442 | printf("%5.60f\n", P.coefficients.at(i)); 443 | } 444 | 445 | X = VerifyConsistant(L2, P); 446 | X = VerifyContinuous(X, P, SAMPLE_START, SAMPLE_END, -1); 447 | if (X.size() == last) 448 | { 449 | break; 450 | } 451 | printf("X size = %ld\n", X.size()); 452 | last = X.size(); 453 | } 454 | X = VerifyContinuous(X, P, SAMPLE_START, SAMPLE_END, -1); 455 | 456 | printf("Finished!\n"); 457 | } -------------------------------------------------------------------------------- /old/helper.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | using namespace soplex; 14 | 15 | struct RndInterval 16 | { 17 | float x_orig; 18 | float y; 19 | 20 | double l; 21 | double u; 22 | 23 | double x_rr; 24 | double yp; 25 | double lp; 26 | double up; 27 | }; 28 | 29 | typedef union 30 | { 31 | float f; 32 | int i; 33 | } floatX; 34 | 35 | typedef union 36 | { 37 | double d; 38 | long long i; 39 | } doubleX; 40 | 41 | struct Polynomial 42 | { 43 | int termsize; 44 | vector coefficients; 45 | }; 46 | 47 | int write_rnd_interval_to_file(vector X, const char *filename) 48 | { 49 | FILE *fptr; 50 | fptr = fopen(filename, "wb"); 51 | 52 | for (size_t i = 0; i < X.size(); i++) 53 | { 54 | 55 | fwrite(&X.at(i), sizeof(RndInterval), 1, fptr); 56 | } 57 | fclose(fptr); 58 | 59 | return 0; 60 | } 61 | vector read_rnd_interval_from_file(const char *filename) 62 | { 63 | vector X; 64 | FILE *fptr; 65 | fptr = fopen(filename, "rb"); 66 | RndInterval x1; 67 | 68 | while (fread(&x1, sizeof(RndInterval), 1, fptr) == 1) 69 | { 70 | X.push_back(x1); 71 | } 72 | fclose(fptr); 73 | 74 | return X; 75 | } 76 | vector GenerateFloatSample(int sample_size) 77 | { 78 | vector X; 79 | size_t n = 0; 80 | half h; 81 | half zero(0.0); 82 | half inf((0x7BFF)); 83 | if (sample_size == -1) 84 | { 85 | for (h = half_float::nextafter(zero, inf); h != inf; h = half_float::nextafter(h, inf)) 86 | { 87 | n++; 88 | RndInterval I; 89 | I.x_orig = h; 90 | I.x_rr = RangeReduction(h); 91 | X.push_back(I); 92 | } 93 | } 94 | else 95 | { 96 | int skip = (1 << 16) / sample_size; 97 | for (h = half_float::nextafter(zero, inf); h != inf; h = half_float::nextafter(h, inf)) 98 | { 99 | n++; 100 | RndInterval I; 101 | I.x_orig = h; 102 | I.x_rr = RangeReduction(h); 103 | X.push_back(I); 104 | for (int i = 0; i < skip; i++) 105 | { 106 | h = half_float::nextafter(h, inf); 107 | } 108 | } 109 | } 110 | // printf("sample size = %ld\n", n); 111 | return X; 112 | } 113 | 114 | vector CalcRndIntervals(vector X) 115 | { 116 | FILE *fptr; 117 | fptr = fopen("dump/RndIntervalHalf.txt", "w"); 118 | 119 | half y; 120 | double l, u; 121 | 122 | mpfr_t y_mpfr, x_mpfr; 123 | mpfr_inits2(200, y_mpfr, x_mpfr, NULL); 124 | 125 | vector L; 126 | 127 | for (size_t i = 0; i < X.size(); i++) 128 | { 129 | 130 | RndInterval I; 131 | 132 | I.x_orig = X.at(i).x_orig; 133 | I.x_rr = X.at(i).x_rr; 134 | y = EvaluateFunction(y_mpfr, (double)X.at(i).x_orig); 135 | 136 | half inf(half_float::half(0x7BFF)); 137 | 138 | half lhalf(half_float::nextafter((half)y, -inf)); 139 | half uhalf(half_float::nextafter((half)y, inf)); 140 | 141 | l = (y + (double)lhalf) / 2; 142 | u = (y + (double)uhalf) / 2; 143 | 144 | while ((half)l != (half)y) 145 | { 146 | 147 | l = nextafterf(l, INFINITY); 148 | } 149 | assert((half)l == (half)y); 150 | 151 | while ((half)u != (half)y) 152 | { 153 | 154 | u = nextafterf(u, -INFINITY); 155 | } 156 | assert((half)u == (half)y); 157 | assert(l < u); 158 | 159 | fprintf(fptr, "%4.15f %4.15f %4.40f %4.40f \n", (double)X.at(i).x_orig, (double)y, l, u); 160 | I.y = y; 161 | I.l = l; 162 | I.u = u; 163 | 164 | L.push_back(I); 165 | } 166 | return L; 167 | } 168 | 169 | vector CalcRedIntervals(vector X) 170 | { 171 | FILE *fptr; 172 | fptr = fopen("dump/RedIntervalHalf.txt", "w"); 173 | half yp; 174 | double lp, up; 175 | 176 | mpfr_t yp_mpfr, xrr_mpfr; 177 | mpfr_inits2(200, yp_mpfr, xrr_mpfr, NULL); 178 | 179 | vector L; 180 | 181 | for (size_t i = 0; i < X.size(); i++) 182 | { 183 | RndInterval I; 184 | 185 | I.x_orig = X.at(i).x_orig; 186 | I.x_rr = X.at(i).x_rr; 187 | 188 | I.y = X.at(i).y; 189 | 190 | I.l = X.at(i).l; 191 | I.u = X.at(i).u; 192 | 193 | lp = InverseOutputCompensation(X.at(i).x_orig, X.at(i).l); 194 | up = InverseOutputCompensation(X.at(i).x_orig, X.at(i).u); 195 | 196 | while (OutputCompensation(X.at(i).x_orig, lp) < X.at(i).l) 197 | { 198 | lp = nextafterf(lp, INFINITY); 199 | } 200 | 201 | while (OutputCompensation(X.at(i).x_orig, up) > X.at(i).u) 202 | { 203 | up = nextafterf(up, -INFINITY); 204 | } 205 | 206 | assert(lp <= up); 207 | fprintf(fptr, "%4.15f %4.40f %4.40f %4.40f \n", (double)X.at(i).x_orig, X.at(i).x_rr, lp, up); 208 | I.lp = lp; 209 | I.up = up; 210 | 211 | L.push_back(I); 212 | } 213 | return L; 214 | } 215 | 216 | Polynomial GeneratePolynomial(vector L) 217 | { 218 | 219 | for (int termsize = 1; termsize < 30; termsize++) 220 | { 221 | SoPlex mysoplex; 222 | mysoplex.setBoolParam(SoPlex::RATFACJUMP, true); 223 | mysoplex.setIntParam(SoPlex::SOLVEMODE, 2); 224 | mysoplex.setIntParam(SoPlex::CHECKMODE, 2); 225 | mysoplex.setIntParam(SoPlex::SYNCMODE, 1); 226 | mysoplex.setIntParam(SoPlex::READMODE, 1); 227 | mysoplex.setRealParam(SoPlex::FEASTOL, 0.0); 228 | mysoplex.setRealParam(SoPlex::OPTTOL, 0.0); 229 | mysoplex.setRealParam(SoPlex::EPSILON_ZERO, 0.0); 230 | mysoplex.setRealParam(SoPlex::EPSILON_FACTORIZATION, 0.0); 231 | mysoplex.setRealParam(SoPlex::EPSILON_UPDATE, 0.0); 232 | mysoplex.setRealParam(SoPlex::EPSILON_PIVOT, 0.0); 233 | mysoplex.setIntParam(SoPlex::VERBOSITY, 0); 234 | mysoplex.setRealParam(SoPlex::TIMELIMIT, 5 * 60); 235 | mysoplex.setIntParam(SoPlex::OBJSENSE, SoPlex::OBJSENSE_MINIMIZE); 236 | DSVectorRational dummycol(0); 237 | 238 | for (int i = 0; i < termsize; i++) 239 | { 240 | auto column = LPColRational(1.0, dummycol, infinity, -infinity); 241 | mysoplex.addColRational(column); 242 | } 243 | 244 | for (int i = 0; i < L.size(); i++) 245 | { 246 | DSVectorRational row1(termsize); 247 | Rational acc(1.0); 248 | Rational xval(L.at(i).x_rr); 249 | row1.add(0, 1.0); 250 | 251 | for (int j = 1; j < termsize; j++) 252 | { 253 | acc = acc * xval; 254 | row1.add(j, acc); 255 | } 256 | double lbnd = (L.at(i).lp); 257 | double ubnd = (L.at(i).up); 258 | 259 | mysoplex.addRowRational(LPRowRational(lbnd, row1, ubnd)); 260 | } 261 | 262 | mysoplex.writeFileRational("dump/dump_rational.lp", NULL, NULL, NULL); 263 | mysoplex.writeFileReal("dump/dump_real.lp", NULL, NULL, NULL); 264 | 265 | SPxSolver::Status stat; 266 | cout << "Solving... " << termsize << "\n"; 267 | 268 | stat = mysoplex.optimize(); 269 | Polynomial P; 270 | 271 | if (stat == SPxSolver::OPTIMAL) 272 | { 273 | DVectorRational prim(termsize); 274 | mysoplex.getPrimalRational(prim); 275 | 276 | P.termsize = termsize; 277 | for (int i = 0; i < termsize; i++) 278 | { 279 | P.coefficients.push_back(prim[i]); 280 | } 281 | 282 | return P; 283 | } 284 | else if (stat == SPxSolver::UNBOUNDED) 285 | { 286 | DVectorRational prim(termsize); 287 | mysoplex.getPrimalRational(prim); 288 | 289 | P.termsize = termsize; 290 | std::cout << "Unbounded solution\n"; 291 | for (int i = 0; i < termsize; i++) 292 | { 293 | P.coefficients.push_back(0.0); 294 | } 295 | } 296 | std::cout << "Status: " << stat << std::endl; 297 | } 298 | 299 | Polynomial N; 300 | return N; 301 | } 302 | 303 | double EvaulutePoly(Polynomial P, double xval) 304 | { 305 | double acc = 0.0; 306 | double power = 1.0; 307 | 308 | for (int i = 0; i < P.termsize; i++) 309 | { 310 | 311 | acc += P.coefficients.at(i) * power; 312 | power *= xval; 313 | } 314 | 315 | return acc; 316 | } 317 | 318 | vector Verify(vector L2, Polynomial P) 319 | { 320 | size_t n = 0; 321 | size_t correct = 0; 322 | half inf(half_float::half(0x7BFF)); 323 | vector Incorrect; 324 | for (size_t i = 0; i < L2.size(); i++) 325 | { 326 | n++; 327 | half h(L2.at(i).x_orig); 328 | 329 | double x = (double)h; 330 | double range_reduced = RangeReduction(h); 331 | double eval = EvaulutePoly(P, range_reduced); 332 | 333 | half y(OutputCompensation(h, eval)); 334 | 335 | mpfr_t y_mpfr; 336 | mpfr_inits2(200, y_mpfr, NULL); 337 | half oracle = EvaluateFunction(y_mpfr, x); 338 | 339 | if (y != oracle) 340 | { 341 | RndInterval I; 342 | I.x_orig = h; 343 | I.x_rr = range_reduced; 344 | Incorrect.push_back(I); 345 | } 346 | else 347 | { 348 | correct += 1; 349 | } 350 | } 351 | 352 | printf("In sample, Correct: %ld Incorrect: %ld\n", correct, n - correct); 353 | return Incorrect; 354 | } -------------------------------------------------------------------------------- /old/helper_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "half.hpp" 12 | #include 13 | #include 14 | #include 15 | 16 | using namespace std; 17 | using namespace soplex; 18 | using half_float::half; 19 | 20 | struct RndInterval 21 | { 22 | half x_orig; 23 | half y; 24 | double l; 25 | double u; 26 | 27 | double x_rr; 28 | double yp; 29 | double lp; 30 | double up; 31 | }; 32 | 33 | struct Polynomial 34 | { 35 | int termsize; 36 | vector coefficients; 37 | }; 38 | 39 | void RangeReduction(half x) 40 | { 41 | int exp; 42 | double sig = half_float::frexp(x, &exp); 43 | // exp -= 1 44 | // sig * 2; 45 | // print_binary_half(x); 46 | // std::cout << x << " makes " << sig << " * 2^" << exp - 1 << '\n'; 47 | 48 | // return sig * 2; 49 | printf("x = %4.15f sig = %4.15f exp = %d\n", (double)x, sig, exp); 50 | } 51 | 52 | double OutputCompensation(half x, double yp) 53 | { 54 | int exp; 55 | double sig = half_float::frexp(x, &exp); 56 | // sig *= 2 57 | 58 | // return yp + exp - 1; 59 | // printf("x = %4.15f yp = %4.15f, exp = %d\n", (double)x, yp, exp); 60 | 61 | return yp + exp; 62 | } 63 | 64 | double InverseOutputCompensation(half x, double yp) 65 | { 66 | int exp; 67 | double sig = half_float::frexp(x, &exp); 68 | 69 | // return yp - (exp + 1); 70 | // printf("x = %4.15f yp = %4.15f, exp = %d ret = %4.15f\n", (double)x, yp, exp, yp - exp + 1); 71 | return yp - exp; 72 | } 73 | 74 | int main(int argc, char *argv[]) 75 | { 76 | if (argc == 2) 77 | { 78 | half input((double)atof(argv[1])); 79 | RangeReduction(input); 80 | } 81 | else if (argc == 3) 82 | { 83 | double in = atof(argv[1]); 84 | double yp = atof(argv[2]); 85 | half x(in); 86 | printf("OC = %4.30f Oc-1 = %4.30f\n", OutputCompensation(x, yp), InverseOutputCompensation(x, yp)); 87 | 88 | ; 89 | } 90 | 91 | return 0; 92 | } 93 | -------------------------------------------------------------------------------- /old/progressive.cpp: -------------------------------------------------------------------------------- 1 | #include "rlibm-fast.h" 2 | 3 | 4 | polynomial* rlibm_solve_with_soplex(psample_data* sintervals, 5 | size_t ssize, int** power, int* power_size, int termsize){ 6 | 7 | SoPlex mysoplex; 8 | mysoplex.setBoolParam(SoPlex::RATFACJUMP,true); 9 | mysoplex.setIntParam(SoPlex::SOLVEMODE,2); 10 | mysoplex.setIntParam(SoPlex::CHECKMODE,2); 11 | mysoplex.setIntParam(SoPlex::SYNCMODE,1); 12 | mysoplex.setIntParam(SoPlex::READMODE,1); 13 | mysoplex.setRealParam(SoPlex::FEASTOL,0.0); 14 | mysoplex.setRealParam(SoPlex::OPTTOL,0.0); 15 | mysoplex.setRealParam(SoPlex::EPSILON_ZERO,0.0); 16 | mysoplex.setRealParam(SoPlex::EPSILON_FACTORIZATION,0.0); 17 | mysoplex.setRealParam(SoPlex::EPSILON_UPDATE,0.0); 18 | mysoplex.setRealParam(SoPlex::EPSILON_PIVOT,0.0); 19 | mysoplex.setIntParam(SoPlex::VERBOSITY,0); 20 | mysoplex.setRealParam(SoPlex::TIMELIMIT,5*60); 21 | 22 | /* we first add objective variables */ 23 | DSVectorRational dummycol(0); 24 | for(int i=0;itermsize = termsize; 62 | p->power = power[2]; 63 | p->coeffs = (double *) calloc(termsize, sizeof(double)); 64 | 65 | for(int i=0;icoeffs[i] = mpq_get_d(*(prim[i].getMpqPtr_w())); 67 | 68 | return p; 69 | } 70 | else if(stat==SPxSolver::UNBOUNDED){ 71 | 72 | polynomial* p = (polynomial *) calloc(1, sizeof(polynomial)); 73 | p->termsize = termsize; 74 | p->power = power[2]; 75 | p->coeffs = (double *) calloc(termsize, sizeof(double)); 76 | 77 | for(int i=0;icoeffs[i] = 0.0; 79 | 80 | return p; 81 | } 82 | 83 | return nullptr; 84 | } 85 | 86 | void check_sorted(sample_info* sampled_indices, size_t ssize){ 87 | double min= sampled_indices[0].key; 88 | 89 | for(size_t i = 0; i< ssize; i++){ 90 | assert ( min <= sampled_indices[i].key); 91 | min = sampled_indices[i].key; 92 | } 93 | 94 | } 95 | 96 | 97 | double rlibm_poly_evaluation(double x, polynomial* poly){ 98 | 99 | double ret_val = 0.0; 100 | 101 | // simulated Horner's method 102 | for(int i = poly->termsize-1; i> 0; i--){ 103 | ret_val = ret_val + poly->coeffs[i]; 104 | double xmul = 1.0; 105 | for(int j = 0; j < (poly->power[i] - poly->power[i-1]); j++){ 106 | xmul = xmul * x; 107 | } 108 | ret_val = ret_val * xmul; 109 | } 110 | ret_val = ret_val + poly->coeffs[0]; 111 | 112 | for(int j = 0; j < poly->power[0]; j++){ 113 | ret_val = ret_val * x; 114 | } 115 | return ret_val; 116 | } 117 | 118 | bool rlibm_validate_and_fix_intervals(psample_data* sintervals, 119 | size_t ssize, polynomial* poly){ 120 | 121 | bool return_val = true; 122 | for(size_t i = 0; i < ssize; i++){ 123 | double y = rlibm_poly_evaluation(sintervals[i].x, poly); 124 | 125 | if(y < sintervals[i].orig_lb){ 126 | return_val = false; 127 | double_x lbx; 128 | lbx.d = sintervals[i].lb; 129 | if(lbx.d >= 0) { 130 | lbx.x = lbx.x + 1; 131 | } 132 | else{ 133 | lbx.x = lbx.x - 1 ; 134 | } 135 | sintervals[i].lb = lbx.d; 136 | } 137 | else if(y > sintervals[i].orig_ub){ 138 | return_val = false; 139 | double_x ubx; 140 | ubx.d = sintervals[i].ub; 141 | if(ubx.d >= 0){ 142 | ubx.x = ubx.x - 1; 143 | } 144 | else { 145 | ubx.x = ubx.x + 1; 146 | } 147 | sintervals[i].ub = ubx.d; 148 | } 149 | } 150 | return return_val; 151 | } 152 | 153 | polynomial* 154 | rlibm_generate_polynomial(psample_data* sintervals, size_t ssize, 155 | int** power, int* power_size, int max_tries, int *prev_successful_degree){ 156 | 157 | /* power_size[2] is float's termsize */ 158 | for(int i = *prev_successful_degree; i < power_size[2]; i++){ 159 | printf("\r"); 160 | printf("Trying polynomial with %3d terms, ", i+1); 161 | fflush(stdout); 162 | int count = 0; 163 | while(count < max_tries){ 164 | polynomial* p = rlibm_solve_with_soplex(sintervals, ssize, power, power_size, i+1); 165 | if(p && rlibm_validate_and_fix_intervals(sintervals, ssize, p)){ 166 | *prev_successful_degree = i; 167 | return p; 168 | } 169 | if(p != nullptr){ 170 | free(p); 171 | } 172 | count++; 173 | } 174 | printf("\33[2K\r"); 175 | } 176 | return nullptr; 177 | 178 | } 179 | 180 | int sample_compare(const void* s1, const void* s2){ 181 | 182 | sample_info* e1 = (sample_info*) s1; 183 | sample_info* e2 = (sample_info*) s2; 184 | return e1->key > e2->key; 185 | } 186 | 187 | void rlibm_print_sample(sample_info* sampled_indices, size_t size){ 188 | 189 | double prev = 0.0; 190 | for(size_t i = 0; i < size; i++){ 191 | assert(sampled_indices[i].key >= prev); 192 | prev = sampled_indices[i].key; 193 | printf("counter=%lu, key=%e, sample_index=%lu\n", i, sampled_indices[i].key, 194 | sampled_indices[i].index); 195 | } 196 | } 197 | 198 | void rlibm_weighted_random_sample(sample_info* sampled_indices, size_t ssize, 199 | pinterval_data* intervals, size_t nentries){ 200 | 201 | for(size_t i = 0; i < ssize; i++){ 202 | sampled_indices[i].key = pow(intervals[i].u, 1./(intervals[i].w)); 203 | sampled_indices[i].index = i; 204 | } 205 | 206 | qsort(sampled_indices, ssize, sizeof(sample_info), sample_compare); 207 | // check_sorted (sampled_indices, ssize); 208 | 209 | /* select the top ssize indices from the entire interval data */ 210 | 211 | for(size_t i = ssize; i < nentries; i++){ 212 | 213 | /* if the ith element is smaller than the least element in the 214 | sample, then nothing to do */ 215 | size_t j= 0; 216 | 217 | double interval_key = pow(intervals[i].u, 1./(intervals[i].w)); 218 | 219 | if(interval_key > sampled_indices[0].key){ 220 | /* do insertion sort of the data */ 221 | while(interval_key > sampled_indices[j].key && j < ssize) j++; 222 | 223 | for(size_t t=1; t < j; t++) { 224 | sampled_indices[t-1] = sampled_indices[t]; 225 | } 226 | sampled_indices[j-1].key = interval_key; 227 | sampled_indices[j-1].index = i; 228 | } 229 | } 230 | // check_sorted(sampled_indices, ssize); 231 | } 232 | 233 | 234 | size_t rlibm_compute_violated_indices(size_t* violated_indices, pinterval_data* intervals, size_t nentries, polynomial* poly){ 235 | 236 | size_t num_violated_indices = 0; 237 | for(size_t i = 0; i < nentries; i++){ 238 | double y = rlibm_poly_evaluation(intervals[i].x, poly); 239 | if( y < intervals[i].lb || y > intervals[i].ub){ 240 | violated_indices[num_violated_indices] = i; 241 | num_violated_indices++; 242 | } 243 | } 244 | return num_violated_indices; 245 | } 246 | 247 | void rlibm_evaluate_and_update_weights(size_t* violated_indices, size_t num_violated_indices, 248 | pinterval_data* intervals, size_t nentries, size_t d){ 249 | double w_v = 0.0; 250 | double w_s = 0.0; 251 | // this can be optimized to only change the updated weights. For now 252 | // using an inefficient one 253 | for (size_t i = 0; i < nentries; i++){ 254 | w_s = w_s + intervals[i].w; 255 | } 256 | 257 | for(size_t i = 0; i < num_violated_indices; i++){ 258 | w_v = w_v + intervals[violated_indices[i]].w; 259 | } 260 | 261 | //doubling the weights for a lucky iteration 262 | if(w_v <= 2 * w_s / (9*d -1)){ 263 | for(size_t i = 0; i < num_violated_indices; i++){ 264 | size_t vindex = violated_indices[i]; 265 | intervals[vindex].w = intervals[vindex].w * 2; 266 | } 267 | } 268 | } 269 | 270 | void 271 | rlibm_regenerate_random_values_and_reset_weights(pinterval_data* intervals, 272 | size_t nentries){ 273 | 274 | std::random_device rd; 275 | std::mt19937 generator(rd()); 276 | std::uniform_real_distribution distribution(0.0, 1.0); 277 | 278 | for(size_t i = 0; i < nentries; i++){ 279 | intervals[i].u = distribution(generator); 280 | intervals[i].w = 1.0; 281 | } 282 | } 283 | 284 | bool check_sampled_indices(sample_info* sample, sample_info* prev_sample, size_t size){ 285 | 286 | for(size_t i =0; i < size; i++){ 287 | if (sample[i].index != prev_sample[i].index){ 288 | return false; 289 | } 290 | } 291 | return true; 292 | } 293 | 294 | void rlibm_print_polyinfo(polynomial* p, int** powers, int* powers_sizes){ 295 | 296 | if(p->termsize == 0){ 297 | printf("Polynomial has no terms!\n"); 298 | exit(0); 299 | } 300 | 301 | printf("\n"); 302 | printf("BF16 Polynomial: y=%.70e x^(%d)\n",p->coeffs[0],p->power[0]); 303 | int bfloat16_term = powers_sizes[0]; 304 | if (p->termsize < bfloat16_term) bfloat16_term = p->termsize; 305 | for(int j=1;jcoeffs[j],p->power[j]); 307 | } 308 | 309 | printf("TF32 Polynomial: y=%.70e x^(%d)\n",p->coeffs[0],p->power[0]); 310 | int tf32_terms = powers_sizes[1]; 311 | if (p->termsize < tf32_terms) tf32_terms = p->termsize; 312 | for(int j=1;jcoeffs[j],p->power[j]); 314 | } 315 | 316 | printf("Full Polynomial: y=%.70e x^(%d)\n",p->coeffs[0],p->power[0]); 317 | for(int j=1;jtermsize;j++){ 318 | printf(" + %.70e x^(%d)\n",p->coeffs[j],p->power[j]); 319 | } 320 | 321 | } 322 | 323 | size_t rlibm_count_entries(FILE *fp){ 324 | 325 | /* count the number of entries */ 326 | 327 | fseek(fp, 0, SEEK_END); 328 | size_t nentries_total = ftell(fp); 329 | nentries_total = nentries_total/(3*sizeof(double)); 330 | printf("number of intervals = %lu\n", nentries_total); 331 | fseek(fp, 0, SEEK_SET); 332 | 333 | return nentries_total; 334 | } 335 | 336 | 337 | 338 | pinterval_data* rlibm_read_interval_file(char** argv, size_t* nentries){ 339 | 340 | /* argv[1] is bfloat16, argv[2] is tensforfloat32, argv[3] is float32 */ 341 | 342 | FILE* float_file = fopen(argv[3], "r"); 343 | assert(float_file != nullptr); 344 | 345 | FILE* bfloat_file = fopen(argv[1], "r"); 346 | assert(bfloat_file != nullptr); 347 | 348 | FILE* tfloat_file = fopen(argv[2], "r"); 349 | assert(tfloat_file != nullptr); 350 | 351 | size_t float_nentries = rlibm_count_entries(float_file); 352 | size_t bfloat_nentries = rlibm_count_entries(bfloat_file); 353 | size_t tfloat_nentries = rlibm_count_entries(tfloat_file); 354 | 355 | size_t nentries_total = float_nentries + bfloat_nentries + tfloat_nentries; 356 | 357 | pinterval_data* intervals = (pinterval_data*) calloc(nentries_total, sizeof(pinterval_data)); 358 | 359 | std::random_device rd; 360 | std::mt19937 generator(rd()); 361 | std::uniform_real_distribution distribution(0.0, 1.0); 362 | 363 | /* i is overall entries index */ 364 | 365 | /* j --> float, k --> tensorfloat, l--> bfloat */ 366 | 367 | double fdata_entry[3]; 368 | double tdata_entry[3]; 369 | double bdata_entry[3]; 370 | size_t i = 0; 371 | size_t j= 0, k = 0, l = 0; 372 | int b_read = 0, t_read = 0, f_read = 0; 373 | while( i < nentries_total){ 374 | 375 | if(f_read == 0 && j < float_nentries){ 376 | size_t fbytes = fread(fdata_entry, sizeof(double), 3, float_file); 377 | f_read = 1; 378 | j++; 379 | } 380 | if(t_read == 0 && k < tfloat_nentries){ 381 | size_t tbytes = fread(tdata_entry, sizeof(double), 3, tfloat_file); 382 | t_read = 1; 383 | k++; 384 | } 385 | 386 | if(b_read == 0 && l < bfloat_nentries){ 387 | size_t bbytes = fread(bdata_entry, sizeof(double), 3, bfloat_file); 388 | b_read = 1; 389 | l++; 390 | } 391 | 392 | double float_value = fdata_entry[0]; 393 | double bfloat_value = bdata_entry[0]; 394 | double tfloat_value = tdata_entry[0]; 395 | 396 | if(f_read == 0){ 397 | assert(j == float_nentries); 398 | float_value = 1.0/0.0; 399 | } 400 | 401 | 402 | if(b_read == 0){ 403 | assert(l == bfloat_nentries); 404 | bfloat_value = 1.0/0.0; 405 | } 406 | 407 | if(t_read == 0){ 408 | assert(k == tfloat_nentries); 409 | tfloat_value = 1.0/0.0; 410 | } 411 | 412 | 413 | /* find the minimum and add it based on them */ 414 | 415 | if((bfloat_value <= float_value) && (bfloat_value <= tfloat_value)){ 416 | intervals[i].w = 1.0; 417 | intervals[i].u = distribution(generator); 418 | intervals[i].x = bdata_entry[0]; 419 | intervals[i].lb = bdata_entry[1]; 420 | intervals[i].ub = bdata_entry[2]; 421 | intervals[i].rep = 0; 422 | i++; 423 | b_read = 0; 424 | } 425 | 426 | if((tfloat_value <= bfloat_value) && (tfloat_value <= float_value)){ 427 | intervals[i].w = 1.0; 428 | intervals[i].u = distribution(generator); 429 | intervals[i].x = tdata_entry[0]; 430 | intervals[i].lb = tdata_entry[1]; 431 | intervals[i].ub = tdata_entry[2]; 432 | intervals[i].rep = 1; 433 | i++; 434 | t_read = 0; 435 | } 436 | 437 | if((float_value <= bfloat_value ) && (float_value <= tfloat_value)){ 438 | intervals[i].w = 1.0; 439 | intervals[i].u = distribution(generator); 440 | intervals[i].x = fdata_entry[0]; 441 | intervals[i].lb = fdata_entry[1]; 442 | intervals[i].ub = fdata_entry[2]; 443 | intervals[i].rep = 2; 444 | i++; 445 | f_read = 0; 446 | } 447 | } 448 | 449 | assert(i == nentries_total); 450 | assert(j == float_nentries); 451 | assert(k == tfloat_nentries); 452 | assert(l == bfloat_nentries); 453 | 454 | fclose(float_file); 455 | fclose(bfloat_file); 456 | fclose(tfloat_file); 457 | 458 | *nentries = nentries_total; 459 | return intervals; 460 | } 461 | 462 | 463 | int main(int argc, char** argv){ 464 | 465 | if(argc < 5 || argc > 6){ 466 | printf("Usage: %s <# of subdomains>\n", argv[0]); 467 | exit(0); 468 | } 469 | 470 | if (argc == 6) { 471 | N_RLIBM_PIECES = atoi(argv[5]); 472 | } 473 | 474 | printf("EXIT_ON_THRESHOLD is %d\n", RLIBM_EXIT_ON_THRESHOLD); 475 | 476 | size_t nentries_total = 0; 477 | pinterval_data* intervals_full = rlibm_read_interval_file(argv, &nentries_total); 478 | 479 | /* powers array for each target represntation*/ 480 | 481 | int* powers[3]; 482 | int powers_size[3]; 483 | 484 | FILE* powers_file = fopen(argv[4], "r"); 485 | 486 | int temp_power; 487 | int pvalue; 488 | 489 | 490 | for(int confs = 0; confs < 3; confs++){ 491 | fscanf(powers_file, "%d", &powers_size[confs]); 492 | powers[confs] = (int*) calloc(powers_size[confs], sizeof(int)); 493 | for(int i = 0; i < powers_size[confs]; i++){ 494 | fscanf(powers_file, "%d", &powers[confs][i]); 495 | } 496 | fscanf(powers_file, "\n"); 497 | } 498 | fclose(powers_file); 499 | 500 | for(int confs = 0; confs < 3; confs++){ 501 | printf("Configuration %d\n", confs); 502 | for(int i = 0; i< powers_size[confs]; i++){ 503 | printf(" %d ", powers[confs][i]); 504 | } 505 | printf("\n"); 506 | } 507 | 508 | 509 | //log2, log10 510 | // int powers[]={0, 1,2,3,4,5,6, 7, 8, 9}; //coshx, exp2, exp10, exp 511 | // int powers[] = {1,3,5,7}; //sinhx 512 | // int powers[] = {0,2 ,4,6}; // coshx 513 | //int powers[] = {1,3 ,5,7}; // sinpi 514 | // int powers[] = {0,2,4,6}; // cospi 515 | size_t nentries_pieces = nentries_total/N_RLIBM_PIECES; 516 | 517 | int prev_successful_degree = 0; 518 | size_t prev_end_index = 0; 519 | for(int i = 0; i < N_RLIBM_PIECES; i++){ 520 | 521 | prev_successful_degree = 0; 522 | size_t start_index = prev_end_index; 523 | 524 | size_t even_split = (i+1) * nentries_pieces; 525 | 526 | /* Check the splits so that we don't split bfloat16, tfloat32, and float intervals for the same input */ 527 | 528 | size_t new_end = even_split; 529 | if(even_split < nentries_total){ 530 | if(even_split+1 < nentries_total){ 531 | if(intervals_full[even_split+1].x == intervals_full[even_split].x) 532 | new_end++; 533 | 534 | if(even_split+2 < nentries_total){ 535 | if(intervals_full[even_split+2].x == intervals_full[even_split].x) 536 | new_end++; 537 | } 538 | } 539 | } 540 | 541 | size_t end_index = new_end > nentries_total? nentries_total: new_end; 542 | 543 | prev_end_index = end_index; 544 | 545 | size_t nentries = end_index - start_index; 546 | pinterval_data* intervals = &intervals_full[start_index]; 547 | 548 | printf("Subdomain = %d\n", i); 549 | printf("start_index = %lu\n", start_index); 550 | printf("end_index = %lu\n", end_index); 551 | printf("nentries=%lu\n", nentries); 552 | 553 | /* sample size */ 554 | 555 | size_t cd = 9 * powers_size[2] * powers_size[2]; 556 | size_t samplesize = cd; 557 | 558 | printf("sample size is %lu\n", samplesize); 559 | 560 | size_t n_violated_indices = 0; 561 | size_t *violated_indices = (size_t *) calloc(nentries, sizeof(size_t)); 562 | 563 | sample_info* sampled_indices = (sample_info*) calloc(cd, sizeof(sample_info)); 564 | 565 | size_t prev_violated_indices = 0; 566 | size_t matched_violated_indices = 0; 567 | 568 | psample_data* sampled_intervals = (psample_data *) calloc(cd, sizeof(psample_data)); 569 | 570 | polynomial* p = nullptr; 571 | size_t total_iterations = 0; 572 | 573 | do{ 574 | if(p != nullptr) free(p); 575 | 576 | n_violated_indices = 0; 577 | 578 | rlibm_weighted_random_sample(sampled_indices, cd, intervals, nentries); 579 | total_iterations++; 580 | 581 | for (size_t i = 0; i < cd; i++){ 582 | size_t iindex = sampled_indices[i].index; 583 | 584 | sampled_intervals[i].x = intervals[iindex].x; 585 | sampled_intervals[i].lb = intervals[iindex].lb; 586 | sampled_intervals[i].ub = intervals[iindex].ub; 587 | sampled_intervals[i].orig_lb = sampled_intervals[i].lb; 588 | sampled_intervals[i].orig_ub = sampled_intervals[i].ub; 589 | sampled_intervals[i].w = intervals[iindex].w; 590 | sampled_intervals[i].u = intervals[iindex].u; 591 | sampled_intervals[i].k = sampled_indices[i].key; 592 | sampled_intervals[i].rep = intervals[iindex].rep; 593 | } 594 | 595 | /* need to implement these functions */ 596 | p = rlibm_generate_polynomial(sampled_intervals, samplesize, powers, powers_size, MAX_TRIES, &prev_successful_degree); 597 | 598 | if(p){ 599 | n_violated_indices = rlibm_compute_violated_indices(violated_indices, intervals, nentries, p); 600 | printf("# violated intervals: %10lu, total iterations=%5lu", n_violated_indices, total_iterations); 601 | fflush(stdout); 602 | 603 | if(n_violated_indices <= VIOLATE_THRESHOLD){ 604 | printf("\33[2K\rCANDIDATE POLYNOMIAL WITH %lu VIOLATED INPUTS:\n", n_violated_indices); 605 | printf("starting input: %.70e\n", intervals[0].x); 606 | 607 | for(size_t m = 0; m < n_violated_indices; m++){ 608 | printf("violated input: %.70e\n\t lb: %.70e\n\t ub: %.70e\n", intervals[violated_indices[m]].x, intervals[violated_indices[m]].lb, intervals[violated_indices[m]].ub); 609 | } 610 | rlibm_print_polyinfo(p, powers, powers_size); 611 | if(RLIBM_EXIT_ON_THRESHOLD){ 612 | break; 613 | } 614 | } 615 | 616 | rlibm_evaluate_and_update_weights(violated_indices, n_violated_indices, intervals, nentries, powers_size[2]); 617 | 618 | } 619 | else { 620 | if(total_iterations > MAX_ITERATIONS){ 621 | printf("\ftotal iterations exceeded %d, terminating the polynomial geenerator\n", MAX_ITERATIONS); 622 | if(p!= nullptr){ 623 | free(p); 624 | p = nullptr; 625 | } 626 | break; 627 | } 628 | printf("\rfailed to generate polynomial, resetting weights, total_iterations=%lu\n", total_iterations); 629 | prev_successful_degree = 0; 630 | rlibm_regenerate_random_values_and_reset_weights(intervals, nentries); 631 | } 632 | 633 | /* debugging feature to reset weights for the sample if not making progress*/ 634 | if(n_violated_indices != 0 && (prev_violated_indices == n_violated_indices)){ 635 | matched_violated_indices++; 636 | if(matched_violated_indices > SAMPLE_MATCH_THRESHOLD){ 637 | matched_violated_indices = 0; 638 | n_violated_indices = 0; 639 | 640 | printf("\rnot making progress, same number of violated indices, resetting weights, total_iterations=%lu\n", total_iterations); 641 | prev_successful_degree = 0; 642 | rlibm_regenerate_random_values_and_reset_weights(intervals, nentries); 643 | if(p!= nullptr) { 644 | free(p); 645 | p = nullptr; 646 | } 647 | continue; 648 | } 649 | } 650 | else{ 651 | matched_violated_indices = 0; 652 | prev_violated_indices = n_violated_indices; 653 | } 654 | } while(n_violated_indices > 0 || !p); 655 | 656 | if(p){ 657 | printf("\nFINAL POLYNOMIAL THAT SATISFIES ALL INTERVALS:\n"); 658 | rlibm_print_polyinfo(p, powers, powers_size); 659 | } 660 | else { 661 | printf("\nCould not generate the polynomial that satisifies all intervals, check for partial results with a few violated intervals\n"); 662 | } 663 | free(p); 664 | free(sampled_intervals); 665 | free(sampled_indices); 666 | free(violated_indices); 667 | 668 | } // ends the outer piecewise loop 669 | 670 | free(intervals_full); 671 | return 0; 672 | 673 | } 674 | -------------------------------------------------------------------------------- /old/rlibm-fast.h: -------------------------------------------------------------------------------- 1 | #ifndef __RLIBM_FAST_POLY_GENERATOR__ 2 | #define __RLIBM_FAST_POLY_GENERATOR__ 3 | 4 | #define SOPLEX_WITH_GMP 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #define MAX_TRIES 100 14 | #define VIOLATE_THRESHOLD 10 15 | #define SAMPLE_MATCH_THRESHOLD 20 16 | #define MAX_ITERATIONS 600 17 | int N_RLIBM_PIECES = 1; 18 | 19 | 20 | #ifdef EXIT_ON_THRESHOLD 21 | const int RLIBM_EXIT_ON_THRESHOLD = 1; 22 | #else 23 | const int RLIBM_EXIT_ON_THRESHOLD = 0; 24 | #endif 25 | 26 | using namespace soplex; 27 | using namespace std; 28 | 29 | 30 | typedef struct { 31 | double x; /* original input */ 32 | double lb; /* lower bound */ 33 | double ub; /* upper bound */ 34 | double w; /* weight */ 35 | double u; /* uniform random value */ 36 | } interval_data; 37 | 38 | 39 | /* progressive interval data */ 40 | typedef struct { 41 | double x; /* original input */ 42 | double lb; /* lower bound */ 43 | double ub; /* upper bound */ 44 | double w; /* weight */ 45 | double u; /* uniform random value */ 46 | int rep; /* representation bfloat16 (0) , tensorfloat32 (1), float32 (2) */ 47 | } pinterval_data; 48 | 49 | 50 | typedef struct{ 51 | double x; 52 | double lb; 53 | double ub; 54 | double orig_lb; /* remember lb before narrowing */ 55 | double orig_ub; /* remember ub before narrowing */ 56 | double w; 57 | double u; 58 | double k; /* key computed as 1/u^w */ 59 | 60 | } sample_data; 61 | 62 | 63 | typedef struct{ 64 | double x; 65 | double lb; 66 | double ub; 67 | double orig_lb; /* remember lb before narrowing */ 68 | double orig_ub; /* remember ub before narrowing */ 69 | double w; 70 | double u; 71 | double k; /* key computed as 1/u^w */ 72 | int rep; /* representation bfloat16 (0) , tensorfloat32 (1), float32 (2) */ 73 | } psample_data; 74 | 75 | 76 | typedef struct{ 77 | double key; 78 | size_t index; 79 | } sample_info; 80 | 81 | typedef struct { 82 | int termsize; 83 | int* power; 84 | double* coeffs; 85 | } polynomial; 86 | 87 | typedef union { 88 | double d; 89 | uint64_t x; 90 | } double_x; 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /old/runAll.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./polygen ${BF16INTERVALPATH}/bf16LogIntervals ${TF32INTERVALPATH}/tf32LogIntervals ${FLOAT34INTERVALPATH}/Float34ROLogIntervals configs/log.config 4 4 | ./polygen ${BF16INTERVALPATH}/bf16Log2Intervals ${TF32INTERVALPATH}/tf32Log2Intervals ${FLOAT34INTERVALPATH}/Float34ROLog2Intervals configs/log2.config 1 5 | ./polygen ${BF16INTERVALPATH}/bf16Log10Intervals ${TF32INTERVALPATH}/tf32Log10Intervals ${FLOAT34INTERVALPATH}/Float34ROLog10Intervals configs/log10.config 4 6 | ./polygen ${BF16INTERVALPATH}/bf16ExpIntervals ${TF32INTERVALPATH}/tf32ExpIntervals ${FLOAT34INTERVALPATH}/Float34ROExpIntervals configs/exp.config 4 7 | ./polygen ${BF16INTERVALPATH}/bf16Exp2Intervals ${TF32INTERVALPATH}/tf32Exp2Intervals ${FLOAT34INTERVALPATH}/Float34ROExp2Intervals configs/exp2.config 1 8 | ./polygen ${BF16INTERVALPATH}/bf16Exp10Intervals ${TF32INTERVALPATH}/tf32Exp10Intervals ${FLOAT34INTERVALPATH}/Float34ROExp10Intervals configs/exp10.config 4 9 | ./polygen ${BF16INTERVALPATH}/bf16SinhForSinhIntervals ${TF32INTERVALPATH}/tf32SinhForSinhIntervals ${FLOAT34INTERVALPATH}/Float34ROSinhForSinhIntervals configs/sinhforsinh.config 1 10 | ./polygen ${BF16INTERVALPATH}/bf16CoshForSinhIntervals ${TF32INTERVALPATH}/tf32CoshForSinhIntervals ${FLOAT34INTERVALPATH}/Float34ROCoshForSinhIntervals configs/coshforsinh.config 1 11 | ./polygen ${BF16INTERVALPATH}/bf16SinhForCoshIntervals ${TF32INTERVALPATH}/tf32SinhForCoshIntervals ${FLOAT34INTERVALPATH}/Float34ROSinhForCoshIntervals configs/sinhforcosh.config 1 12 | ./polygen ${BF16INTERVALPATH}/bf16CoshForCoshIntervals ${TF32INTERVALPATH}/tf32CoshForCoshIntervals ${FLOAT34INTERVALPATH}/Float34ROCoshForCoshIntervals configs/coshforcosh.config 1 13 | ./polygen ${BF16INTERVALPATH}/bf16SinpiForSinpiIntervals ${TF32INTERVALPATH}/tf32SinpiForSinpiIntervals ${FLOAT34INTERVALPATH}/Float34ROSinpiForSinpiIntervals configs/sinpiforsinpi.config 1 14 | ./polygen ${BF16INTERVALPATH}/bf16CospiForSinpiIntervals ${TF32INTERVALPATH}/tf32CospiForSinpiIntervals ${FLOAT34INTERVALPATH}/Float34ROCospiForSinpiIntervals configs/cospiforsinpi.config 1 15 | ./polygen ${BF16INTERVALPATH}/bf16SinpiForCospiIntervals ${TF32INTERVALPATH}/tf32SinpiForCospiIntervals ${FLOAT34INTERVALPATH}/Float34ROSinpiForCospiIntervals configs/sinpiforcospi.config 1 16 | ./polygen ${BF16INTERVALPATH}/bf16CospiForCospiIntervals ${TF32INTERVALPATH}/tf32CospiForCospiIntervals ${FLOAT34INTERVALPATH}/Float34ROCospiForCospiIntervals configs/cospiforcospi.config 1 17 | --------------------------------------------------------------------------------