C0d1ng4fun

SKOI

2004-2005

Some Kind Of Intelligence (SKOI, pronounced like the Swedish word "skoj" meaning fun) was originally a library I began developing to try out some of my math and AI related ideas. Most of it was created around the winter 2004-2005. Later it also came to span a couple of tools built on the library.

Arbitrary-precision arithmetic

The most useful part of the project are some routines I created for dealing with arbitrary sized integer numbers. I could not resist the temptation to implement rational numbers so they are in there as well. Finally I wrote an expression parsing application using these routines which came out pretty fun to play with. In addition to the traditional arithmetic operations it supports factorials and "n choose k" expressions, making it is easy to use for combinatorics.

Below is an example which calculates the probability to get a hand with a pair (and nothing more) if pulling 5 cards from a 52 card shuffled deck.

Exp: ((13 * (3!)) * ((12 choose 3) * (4 ^ 3))) ((13 * (3!)) * ((12 choose 3) * (4 ^ 3))) = 1098240 Exp: (52 choose 5) (52 choose 5) = 2598960 Exp: ((13 * (3!)) * ((12 choose 3) * (4 ^ 3))) / (52 choose 5) (((13 * (3!)) * ((12 choose 3) * (4 ^ 3))) / (52 choose 5)) = 352 / 833

An example with big numbers.

Exp: (2 ^ 4253) - 1 ((2 ^ 4253) - 1) = 1907970075244390738074680429695291736693569947499401773947418 82673528979787005053706368049835514900244303495954950709725762186311224148828811 92021690454220696074466616936422119528953843684539025016866393283880519205513715 43909126665275330073092926875390922570433625178573666246999754023754629544902932 59233303137330643531556539739921926201438606439020075174723029056838272505051571 96759460835006340449597766065626902082396082556701234418990892795664601199805798 85486301076373809935198265823897818881357054086530452196558017580812511640805546 09057468028203308718724654081055323215860189611391296030471108443146745671967766 30892585854727150731156376517100831824864711009761489031356285654178415488174314 60339096027379473850553559603318556145409000814563786590683703172676969800011877 50995491090350108417050917991562167972281070161305972518044872048331306383715094 85493841573854989460607072258473797817668642213435452698944302835364403718737538 53978382595118331664161343236956603676768977222879187734209689823260890261500315 15424165462111337527431154890666327374921446276833564519776797633875503548665093 91455648203148224888312702377703966770797655985733335701372734207909906440045574 18306543203793508332362458193488240647835856929248810219783329749499061226644213 76034687815350484991 Exp: 1000! (1000!) = 4023872600770937735437024339230039857193748642107146325437999104299385 12398629020592044208486969404800479988610197196058631666872994808558901323829669 94459099742450408707375991882362772718873251977950595099527612087497546249704360 14182780946464962910563938874378864873371191810458257836478499770124766328898359 55735432513185323958463075557409114262417474349347553428646576611667797396668820 29120737914385371958824980812686783837455973174613608537953452422158659320192809 08782973084313928444032812315586110369768013573042161687476096758713483120254785 89320767169132448426236131412508780208000261683151027341827977704784635868170164 36502415369139828126481021309276124489635992870511496497541990934222156683257208 08213331861168115536158365469840467089756029009505376164758477284218896796462449 45160765353408198901385442487984959953319101723355556602139450399736280750137837 61530712776192684903435262520001588853514733161170210396817592151090778801939317 81141945452572238655414610628921879602238389714760885062768629671466746975629112 34082439208160153780889893964518263243671616762179168909779911903754031274622289 98800519544441428201218736174599264295658174662830295557029902432415318161721046 58320367869061172601587835207515162842255402651704833042261439742869330616908979 68482590125458327168226458066526769958652682272807075781391858178889652208164348 34482599326604336766017699961283186078838615027946595513115655203609398818061213 85586003014356945272242063446317974605946825731037900840244324384656572450144028 21885252470935190620929023136493273497565513958720559654228749774011413346962715 42284586237738753823048386568897646192738381490014076731044664025989949022222176 59043399018860185665264850617997023561938970178600408118897299183110211712298459 01641921068884387121855646124960798722908519296819372388642614839657382291123125 02418664935314397013742853192664987533721894069428143411852015801412334482801505 13996942901534830776445690990731524332782882698646027898643211390835062170950025 97389863554277196742822248757586765752344220207573630569498825087968928162753848 86339690995982628095612145099487170124451646126037902930912088908694202851064018 21543994571568059418727489980942547421735824010636774045957417851608292301353580 81840096996372524230560855903700624271243416909004153690105933983835777939410970 02775347200000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000

Poker simulations

SKOI also contain a scripted training environment with simulation of games and tournaments for self learning poker playing agents. I tested it with some neural network based agents and evolutionary learning. The success was limited since the internal models lacked a great deal of detail. However during one test run I had a bug in the game trial routines causing every player who went all-in to win. The agents learned this quite fast and went all-in all the time. I remember finding that an interesting way to discover a bug.

ExpEval.zip (27.6 kB)-The expression parser and rational calculator with a few examples.