Implement SKI combinator calculus

Wolfram Language, 63 bytes

#//.{{I,x_}->x,{{K,x_},y_}->x,{{{S,x_},y_},z_}->{{x,z},{y,z}}}&

Try it online!

God, I love pattern matching in Wolfram Language. Represents (xy) as {x,y} (a list of two elements).

Alternatively, if we represent (xy) with x>y, we can do it in 55 bytes.

#//.{I>x_->x,(K>x_)>y_->x,((S>x_)>y_)>z_->(x>z)>(y>z)}&

Try it online!


C (gcc), 666 616 518 483 476 bytes

Who doesn't love classy, Arthur Whitney-styled code? No regular expressions involved, only clever parsing and evaluation.

PS: Yes, obviously, a few bytes can be shaved off, but for the artistic style of the obfuscated code, I'll keep them. Also for the byte count :p. Also, this code utilizes undefined behaviour in hope that nothing will break (hopefully).

@ceilingcat insisted on golfing it down from 666 bytes, so here is the golfed version:

#define J putchar
#define H O->a
#define G H->a
#define K O->b
typedef struct x{struct x*a,*b;int q;}Y;Y*O;z=1;A(q){O=calloc(6,4);O->q=q;}h(Y*O){Y*u;O=H&&H->q==2?z=K:H&&G&&G->q==1?z=H->b:H&&G&&G->a&&!G->a->q?u=A(3),(u->a=A(3))->a=G->b,(u->b=A(3))->a=H->b,u->a->b=u->b->b=K,z=u:(O->q==3?H=h(H),K=h(K):0,O);}r(x){Y*O;x=getchar()-73;x=x+33?A(x?x!=10:2):!getchar(K=r(H=r(O=A(3))))+O;}q(Y*O){O&&J(O->q["SKI "],O->q-3||J(41,q(K),q(H),J(40)));}main(){Y*O=r();for(;z;O=h(O))z=0;q(O);}

Try it online!


Seed, 5929 bytes

112 175125024223393299881369706592157488082283804837156017082756856722325166075847950519564167943592808044487267125684500982824738938584413238117265054671445250022137111904987587791131598738185842319020624126430560579515810971576802163527058118646582943324853653999796199542632369416812708749354271741284317250732302328469054803780685477112868334169188856891018023950629378354835273865796757848417669339743382687586174242049454006216851453131134134428463214508793007905337717681133070315471985466427100672192916804351073536100199151762678865541883550052825438862318095200869655875731652644634472553469888478260736141767853906985917128397179426344777487428739589304580323977471164056953882868931380187251967295189408935381614152839152468408840807171349205208276511658744087413652220503302955188388087583226995841538739456644156395560101139819080763360108169780696511114509396125879618194112780933942134035254728657072976361066332228340654952509672470840052751572199952021618538690349385194431929570259295172332958675304853822050032067813782113212943272529171456287770138197431098808476110290296577599039368877537277172555711673263561773864066075324783111552835262411348250926780803347024261611809692356916439087081793705783943728444892895558617726628393799313526344064490248163994546665465033121726293943128808392409220341002079308025402470367376461297787625662090099017340738201274321995960402753799967310100462501817817439404275902236057744198631521982764713517413513492684759682012220358406639453995585097955622518778781635419788927290556424455043104682650850686789548149465510293169369379811410904755344349591169607933240703945487947799620604401842865254399761173120083391863219273707611104375669374834369731924854352980124809575365449102170328729642171080510372133529400335312869161519538242304395605558222669311137024809629422723158127443929965838851434699673241240780740072325299462772193235381070232417931560544370939368587958791970921009919559758980341136448095898140458411304959642390383892634088742457126413199933505834196259551420908796046176263734599654559766270863646315400574309860891105728972779677573869578291151120140986279273354677951859111852198941455676298194162756958212707315621672855168288694803432905244857972636887814553839361360174898392170500411644255800940697816048896461357844937693610505556814340911077617351090920162756901312057574414008827516005454714271470690314016665249119719037270458723972480407715085014725886435349590124926133574618559641211317594225882956122955106738302265568742771293218977446373665098356464490453560656915204902093133574843334957687914950608106786368997052551529215799170043760668159232290215333658686027574681960754052520473508912250488944610972170981106927270994854882358912892806477448683790469418949315007255302019475391953101748911423906572694093610475157294362876893840013039693667512080529582859514794229825966885453665290272903860040888704630678067594424587582134593104911974969177435573137040692039406413342977450835280781502907163369806625411630346631509467255786030649826948756620270937888167082431152978971147961264570302870460167739563632375110965788244327919944904703453384159174835228418109055042667077007429996136731893263624714655509686352079828297127185051734958907328852775480804855520575067864592038588886014587503641421978047451034313132217417192506863044012950606206394775775162310722210243007513401179934165492777130420227846790118743796158899117457763003034091981665147886551990488672957385462699664311848044216618582539442298317833985937376274335807528634096843663112689041681957138734587114980130973202497359892742434241690499668925480120954552675905863096297006484736750062374927336095215006447954435932195246489672109538676706677714266383457801098365321448205215703993187526383029517705108441312142397713020042936472211732270463510163267899932473179973096964887794305173770248541127194061263442536903180692304236864380200265805861792661578771781664608524588218708898376135338355037559429232245266256073422332557855448147834359595547211367611050396334077066065965225811376587274142878051416171862923593914757369386835921772959534934884659509262491509552029596424489029703807841180571511616852791181073720741528730612210314029279670671552128911278063622754352031681499911730714705693167130542509663189854747924736515269868021533436770525016239700248711560663813577527974551203767289719186160666797835958488728313279575683714577092257923486603619686124760901563045814172072022345857443703998401213303985876429725045250852165548603523039788907509054900258634036153406664778483267365407566278165978897218673230547959935055279438171642068793022459942989101657721196052027504113928647422327098510211507006547303387906487492271358052906856962305062851475982750351911114439963023137319468119021068144193039996057417386848323360007424654300359096943509038337709449501642651768997768391341935051993312053833821929022397579024250229200812125865044678988619343260037236517052762645072200309034165197471061250411035183170255257173663398956704471884331514271844690939595913439438401433578271086765564900455207752439277476779780638528561623100414305188891320140503278767840868536606179103212880867525673579105498842409736849370007918907185372206291643693691612237047739540853654783205951206107219076655677337079308112985158162684721282577834132642346812933401448291078452205032999158114786503794356049271788640786065377367688268413484100858857261119710000438626295618339655531102295591902049315178193214504567329420335725282040138700722638834425095806406518718355440532748042585706544885352942453506524161578363688009985070926288728520504343077077550532425299939607626824796614189692624429707587201579387770868869237502195395657619210612884845494673507555914825209673490567961085000292509447322976186784833443074337576462781831435241873744759945468546902905356136364901548136644852173428070314999990087598266546661471720360218504989486980495839512901313823608

Try it online!

Made possible thanks to Abigail's perl answer. Inspired by HighlyRadioactive's comment.

Golfed with the standard algorithm, I'll run BXn and modify the answer later.