reduce.tex 287 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947
  1. % The REDUCE User's Manual --- LaTeX version.
  2. % To create this manual, the following steps are recommended:
  3. % latex reduce
  4. % makeindex reduce
  5. % latex reduce
  6. % latex reduce --- this is probably not necessary.
  7. \documentstyle[11pt,makeidx]{book}
  8. \parindent 0pt
  9. \parskip 6pt
  10. \raggedbottom
  11. \newlength{\reduceboxwidth}
  12. \setlength{\reduceboxwidth}{4in}
  13. \newlength{\redboxwidth}
  14. \setlength{\redboxwidth}{3.5in}
  15. \newlength{\rboxwidth}
  16. \setlength{\rboxwidth}{2.6in}
  17. \newcommand{\REDUCE}{REDUCE}
  18. \newcommand{\RLISP}{RLISP}
  19. \newcommand{\ttindex}[1]{\index{#1@{\tt #1}}}
  20. \newcommand{\COMPATNOTE}{{\em Compatibility Note:\ }}
  21. % Close up default vertical spacings:
  22. \setlength{\topsep}{0.5\baselineskip} % above and below environments
  23. \setlength{\itemsep}{\topsep}
  24. \setlength{\abovedisplayskip}{\topsep} % for "long" equations
  25. \setlength{\belowdisplayskip}{\topsep}
  26. \pagestyle{headings}
  27. \makeindex
  28. \begin{document}
  29. \pagestyle{empty}
  30. \begin{titlepage}
  31. \vspace*{\fill}
  32. \begin{center}
  33. {\Huge\bf {\REDUCE}} \\[0.2cm]
  34. {\LARGE\bf User's Manual\vspace{0.4cm} \\
  35. Version 3.4}
  36. \vspace{0.5in}\large\bf
  37. Anthony C.\ Hearn \\
  38. RAND \\
  39. Santa Monica, CA 90407-2138
  40. \vspace{0.1in}
  41. \bf Email: reduce@rand.org
  42. \vspace{0.5in}
  43. \large\bf July 1991
  44. \vspace*{2.5in}
  45. \bf RAND Publication CP78 (Rev. 7/91)
  46. \end{center}
  47. \end{titlepage}
  48. \newpage
  49. \vspace*{3.0in}
  50. \noindent Copyright \copyright 1991 RAND. All rights reserved. \\
  51. \noindent Registered system holders may reproduce all or any part of this
  52. publication for internal purposes, provided that the source of the
  53. material is clearly acknowledged, and the copyright notice is retained.
  54. \pagestyle{headings}
  55. \setcounter{page}{0}
  56. \tableofcontents
  57. \chapter*{Abstract}
  58. \addcontentsline{toc}{chapter}{Abstract}
  59. This document provides the user with a description of the algebraic
  60. programming system {\REDUCE}. The capabilities of this system include:
  61. \begin{enumerate}
  62. \item expansion and ordering of polynomials and rational functions,
  63. \item substitutions and pattern matching in a wide variety of forms,
  64. \item automatic and user controlled simplification of expressions,
  65. \item calculations with symbolic matrices,
  66. \item arbitrary precision integer and real arithmetic,
  67. \item facilities for defining new functions and extending program syntax,
  68. \item analytic differentiation and integration,
  69. \item factorization of polynomials,
  70. \item facilities for the solution of a variety of algebraic equations,
  71. \item facilities for the output of expressions in a variety of formats,
  72. \item facilities for generating numerical programs from symbolic input,
  73. \item Dirac matrix calculations of interest to high energy physicists.
  74. \end{enumerate}
  75. \chapter*{Acknowledgment}
  76. The production of this version of the manual has been the result of the
  77. contributions of a large number of individuals who have taken the time and
  78. effort to suggest improvements to previous versions, and to draft new
  79. sections. Particular thanks are due to Gerry Rayna, who provided a draft
  80. rewrite of most of the first half of the manual. Other people who have
  81. made significant contributions have included John Fitch, Martin Griss,
  82. Stan Kameny, Jed Marti, Herbert Melenk, Don Morrison, Arthur Norman,
  83. Eberhard Schr\"ufer and Larry Seward. Finally, Richard Hitt produced a {\TeX}
  84. version of the {\REDUCE} 3.3 manual, which has been a useful guide for the
  85. production of the {\LaTeX} version of this manual.
  86. \chapter{Introductory Information}
  87. \index{Introduction}{\REDUCE} is a system for carrying out algebraic
  88. operations accurately, no matter how complicated the expressions become.
  89. It can manipulate polynomials in a variety of forms, both expanding and
  90. factoring them, and extract various parts of them as required. {\REDUCE} can
  91. also do differentiation and integration, but we shall only show trivial
  92. examples of this in this introduction. Other topics which are not
  93. considered include the use of arrays, the definition of procedures and
  94. operators, the specific routines for high energy physics calculations, the
  95. use of files to eliminate repetitious typing and for saving results, and
  96. the editing of the input text.
  97. Also not considered in any detail in this introduction are the many options
  98. that are available for varying computational procedures, output forms,
  99. number systems used, and so on.
  100. {\REDUCE} is designed to be an interactive system, so that the user can input
  101. an algebraic expression and see its value before moving on to the next
  102. calculation. For those systems that do not support interactive use, or
  103. for those calculations, especially long ones, for which a standard script
  104. can be defined, {\REDUCE} can also be used in batch mode. In this case,
  105. a sequence of commands can be given to {\REDUCE} and results obtained
  106. without any user interaction during the computation.
  107. In this introduction, we shall limit ourselves to the interactive use of
  108. {\REDUCE}, since this illustrates most completely the capabilities of the
  109. system. When {\REDUCE} is called, it begins by printing a banner message
  110. like:
  111. \begin{verbatim}
  112. REDUCE 3.4, 15-Jul-91 ...
  113. \end{verbatim}
  114. where the version number and the system release date will change from time
  115. to time. It then prompts the user for input by:
  116. \begin{verbatim}
  117. 1:
  118. \end{verbatim}
  119. You can now type a {\REDUCE} statement, terminated by a semicolon to indicate
  120. the end of the expression, for example:
  121. \begin{verbatim}
  122. (x+y+z)^2;
  123. \end{verbatim}
  124. This expression would normally be followed by another character (a RETURN
  125. on an ASCII keyboard) to ``wake up" the system, which would then input the
  126. expression, evaluate it, and return the result:
  127. \begin{verbatim}
  128. 2 2 2
  129. X + 2*X*Y + 2*X*Z + Y + 2*Y*Z + Z
  130. \end{verbatim}
  131. Let us review this simple example to learn a little more about the way that
  132. {\REDUCE} works. First, we note that {\REDUCE} deals with variables, and
  133. constants like other computer languages, but that in evaluating the former,
  134. a variable can stand for itself. Expression evaluation normally follows
  135. the rules of high school algebra, so the only surprise in the above example
  136. might be that the expression was expanded. {\REDUCE} normally expands
  137. expressions where possible, collecting like terms and ordering the
  138. variables in a specific manner. However, expansion, ordering of variables,
  139. format of output and so on is under control of the user, and various
  140. declarations are available to manipulate these.
  141. Another characteristic of the above example is the use of lower case on
  142. input and upper case on output. In fact, input may be in either mode, but
  143. lower case is usually converted to upper case by the system, although some
  144. versions produce output in lower case by default. This distinction is
  145. reflected in this manual in that all expressions intended for input will
  146. be shown in lower case and output in upper case. However, for stylistic
  147. reasons, we represent all single identifiers in the text in upper case.
  148. Finally, the numerical prompt can be used to reference the result in a
  149. later computation.
  150. As a further illustration of the system features, the user should try:
  151. \begin{verbatim}
  152. for i:= 1:40 product i;
  153. \end{verbatim}
  154. The result in this case is the value of 40!,
  155. \begin{verbatim}
  156. 815915283247897734345611269596115894272000000000
  157. \end{verbatim}
  158. You can also get the same result by saying
  159. \begin{verbatim}
  160. factorial 40;
  161. \end{verbatim}
  162. Since we want exact results in algebraic calculations, it is essential that
  163. integer arithmetic be performed to arbitrary precision, as in the above
  164. example. Furthermore, the {\tt FOR} statement in the above is illustrative of a
  165. whole range of combining forms which {\REDUCE} supports for the convenience of
  166. the user.
  167. Among the many options in {\REDUCE} is the use of other number systems, such
  168. as multiple precision floating point with any specified number of digits --
  169. of use if roundoff in, say, the $100^{th}$ digit is all that can be tolerated.
  170. In many cases, it is necessary to use the results of one calculation in
  171. succeeding calculations. One way to do this is via an assignment for a
  172. variable, such as
  173. \begin{verbatim}
  174. u := (x+y+z)^2;
  175. \end{verbatim}
  176. If we now use {\tt U} in later calculations, the value of the right-hand
  177. side of the above will be used.
  178. The results of a given calculation are also saved in the variable
  179. {\tt WS} \ttindex{WS} (for WorkSpace), so this can be used in the next
  180. calculation for further processing.
  181. For example, the expression
  182. \begin{verbatim}
  183. df(ws,x);
  184. \end{verbatim}
  185. following the previous evaluation will calculate the derivative of
  186. {\tt (x+y+z)\^{ }2} with respect to {\tt X}. Alternatively,
  187. \begin{verbatim}
  188. int(ws,y);
  189. \end{verbatim}
  190. would calculate the integral of the same expression with respect to y.
  191. {\REDUCE} is also capable of handling symbolic matrices. For example,
  192. \begin{verbatim}
  193. matrix m(2,2);
  194. \end{verbatim}
  195. declares m to be a two by two matrix, and
  196. \begin{verbatim}
  197. m := mat((a,b),(c,d));
  198. \end{verbatim}
  199. gives its elements values. Expressions which include {\tt M} and make
  200. algebraic sense may now be evaluated, such as {\tt 1/m} to give the
  201. inverse, {\tt 2*m - u*m\^{ }2} to give us another matrix and {\tt det(m)} to
  202. give us the determinant of {\tt M}.
  203. {\REDUCE} has a wide range of substitution capabilities. The system knows
  204. about elementary functions, but does not automatically invoke many of their
  205. well-known properties. For example, products of trigonometrical functions
  206. are not converted automatically into multiple angle expressions, but if the
  207. user wants this, he can say, for example:
  208. \begin{verbatim}
  209. (sin(a+b)+cos(a+b))*(sin(a-b)-cos(a-b))
  210. where cos(~x)*cos(~y) = (cos(x+y)+cos(x-y))/2,
  211. cos(~x)*sin(~y) = (sin(x+y)-sin(x-y))/2,
  212. sin(~x)*sin(~y) = (cos(x-y)-cos(x+y))/2;
  213. \end{verbatim}
  214. where the tilde in front of the variables {\tt X} and {\tt Y} indicates
  215. that the rules apply for all values of those variables.
  216. The result of this calculation is
  217. \begin{verbatim}
  218. -(COS(2*A) + SIN(2*B))
  219. \end{verbatim}
  220. Another very commonly used capability of the system, and an illustration
  221. of one of the many output modes of {\REDUCE}, is the ability to output
  222. results in a FORTRAN compatible form. Such results can then be used in a
  223. FORTRAN based numerical calculation. This is particularly useful as a way
  224. of generating algebraic formulas to be used as the basis of extensive
  225. numerical calculations.
  226. For example, the statements
  227. \begin{verbatim}
  228. on fort;
  229. df(log(x)*(sin(x)+cos(x))/sqrt(x),x,2);
  230. \end{verbatim}
  231. will result in the output
  232. \begin{verbatim}
  233. ANS=(-4.*LOG(X)*COS(X)*X**2-4.*LOG(X)*COS(X)*X+3.*LOG(X)*
  234. . COS(X)-4.*LOG(X)*SIN(X)*X**2+4.*LOG(X)*SIN(X)*X+3.*LOG(X)
  235. . *SIN(X)+8.*COS(X)*X-8.*COS(X)-8.*SIN(X)*X-8.*SIN(X))/(4.*
  236. . SQRT(X)*X**2)
  237. \end{verbatim}
  238. These algebraic manipulations illustrate the algebraic mode of {\REDUCE}.
  239. {\REDUCE} is based on Standard Lisp. A symbolic mode is also available for
  240. executing Lisp statements. These statements follow the syntax of Lisp,
  241. e.g.
  242. \begin{verbatim}
  243. symbolic car '(a);
  244. \end{verbatim}
  245. Communication between the two modes is possible.
  246. With this simple introduction, you are now in a position to study the
  247. material in the full {\REDUCE} manual in order to learn just how extensive
  248. the range of facilities really is. If further tutorial material is
  249. desired, the seven {\REDUCE} Interactive Lessons by David R. Stoutemyer are
  250. recommended. These are normally distributed with the system.
  251. \chapter{Structure of Programs}
  252. A {\REDUCE} program\index{Program structure} consists of a set of
  253. functional commands which are evaluated sequentially by the computer.
  254. These commands are built up from declarations, statements and expressions.
  255. Such entities are composed of sequences of numbers, variables, operators,
  256. strings, reserved words and delimiters (such as commas and parentheses),
  257. which in turn are sequences of basic characters.
  258. \section{The {\REDUCE} Standard Character Set}
  259. \index{Character set}The basic characters which are used to build
  260. {\REDUCE} symbols are the following:
  261. \begin{enumerate}
  262. \item The 26 upper case letters {\tt A} through {\tt Z}
  263. \item The 10 decimal digits {\tt 0} through {\tt 9}
  264. \item The special characters \_\_ ! " \$ \% ' ( ) * + , - . / : ; $<$ $>$
  265. = \{ \} $<$blank$>$
  266. \end{enumerate}
  267. Programs composed from this standard set of characters will run in any
  268. available {\REDUCE} system. Most implementations permit lower case on
  269. input. With the exception of strings and characters preceded by an
  270. exclamation mark\index{Exclamation mark} (q.v.), such lower case
  271. characters will be converted internally into upper case. If you do not
  272. wish this conversion to occur, the command {\tt off raise;} \ttindex{RAISE}
  273. achieves this. However, now case {\em is} distinguished internally, so
  274. that {\tt df} is not the same as {\tt DF} (the derivative operator).
  275. Several implementations also allow some special characters to represent
  276. operators in the system. The operating instructions for a particular
  277. implementation should be consulted on these points. For generality, we
  278. shall limit ourselves to the standard character set in this exposition.
  279. \section{Numbers}
  280. \index{Number}There are several different types of numbers available in
  281. \REDUCE. Integers consist of a signed or unsigned sequence of decimal
  282. digits written without a decimal point, for example:
  283. \begin{verbatim}
  284. -2, 5396, +32
  285. \end{verbatim}
  286. In principle, there is no practical limit on the number of digits
  287. permitted as exact arithmetic is used in most implementations. (You should
  288. however check the specific instructions for your particular system
  289. implementation to make sure that this is true.) For example, if you ask
  290. for the value of $2^{2000}$ you get it
  291. displayed as a number of 603 decimal digits, taking up nine lines of
  292. output on an interactive display. It should be borne in mind of course
  293. that computations with such long numbers can be quite slow.
  294. Numbers that aren't integers are usually represented as the quotient of
  295. two integers, in lowest terms: that is, as rational numbers.
  296. In essentially all versions of {\REDUCE} it is also possible (but not always
  297. desirable!) to ask {\REDUCE} to work with floating point approximations to
  298. numbers again, to any precision. Such numbers are called {\em real}.
  299. \index{Real} They can be input in two ways:
  300. \begin{enumerate}
  301. \item as a signed or unsigned sequence of any number of decimal digits
  302. with an embedded or trailing decimal point.
  303. \item as in 1. followed by a decimal exponent which is written as the
  304. letter {\tt E} followed by a signed or unsigned integer.
  305. \end{enumerate}
  306. e.g. {\tt 32. +32.0 0.32E2} and {\tt 320.E-1} are all representations of
  307. 32.
  308. {\it CAUTION:} The unsigned part of any number\index{Number} may {\em not}
  309. begin with a decimal point, as this causes confusion with the {\tt CONS} (.)
  310. operator in symbolic mode (q.v.), i.e., NOT ALLOWED: {\tt .5 -.23 +.12};
  311. use {\tt 0.5 -0.23 +0.12} instead.
  312. \section{Identifiers}
  313. Identifiers\index{Identifier} in {\REDUCE} consist of one or more
  314. alphanumeric characters (i.e. upper case alphabetic letters or decimal
  315. digits) the first of which must be alphabetic. The maximum number of
  316. characters allowed is implementation dependent, although twenty-four is
  317. permitted in most implementations. In addition, the underscore character
  318. (\_) is considered a letter. For example,
  319. \begin{verbatim}
  320. a az p1 q23p a_very_long_variable
  321. \end{verbatim}
  322. are all identifiers.
  323. A sequence of alphanumeric characters in which the first is a digit is
  324. interpreted as a product. For example, {\tt 2ab3c} is interpreted as
  325. {\tt 2*ab3c}. There is one exception to this: If the first letter after a
  326. digit is {\tt E}, the system will try to interpret that part of the
  327. sequence as a real number\index{Real}, which may fail in some cases. For
  328. example, {\tt 2E12} is the real number $2.0*10^{12}$, {\tt 2e3c} is
  329. 2000.0*C, and {\tt 2ebc} gives an error.
  330. Special characters, such as $-$, *, and blank, may be used in identifiers
  331. too, even as the first character, but each must be preceded by an
  332. exclamation mark in input. For example:
  333. \begin{verbatim}
  334. light!-years d!*!*n good! morning
  335. !$sign !5goldrings
  336. \end{verbatim}
  337. {\it CAUTION:} Many system identifiers have such special characters in their
  338. names (especially * and =). If the user accidentally picks the name of one
  339. of them for his own purposes it may have catastrophic consequences for his
  340. {\REDUCE} run. Users are therefore advised to avoid such names.
  341. Identifiers are used as variables, labels and to name arrays, operators
  342. and procedures.
  343. \subsection*{Restrictions}
  344. The reserved words listed in another section may not be used as
  345. identifiers. No spaces may appear within an identifier, and an identifier
  346. may not extend over a line of text. (Hyphenation of an identifier, by
  347. using a reserved character as a hyphen before an end-of-line character is
  348. possible in some versions of {\REDUCE}).
  349. \section{Variables}
  350. Every variable\index{Variable} is named by an identifier, and is given a
  351. specific type. The type is of no concern to the ordinary user. Most
  352. variables are allowed to have the default type, called {\em scalar}.
  353. These can receive, as values, the representation of any ordinary algebraic
  354. expression. In the absence of such a value, they stand for themselves.
  355. \subsection*{Reserved Variables}
  356. Several variables\index{Reserved variable} in {\REDUCE} have particular
  357. properties which should not be changed by the user. These variables are
  358. as follows: \\
  359. \begin{tabular}{l r}
  360. {\tt E} & \parbox[t]{\reduceboxwidth}{Intended to represent the base of
  361. the natural logarithms. LOG(E), if it occurs in an expression, is
  362. automatically replaced by 1. If {\tt ROUNDED} (q.v.) \ttindex{ROUNDED} is
  363. on, E is replaced by the value of E to the current degree of floating point
  364. precision\index{Numerical precision}.} \\ \\
  365. {\tt I} & \parbox[t]{\reduceboxwidth}{Intended to represent the square
  366. root of $-1$. {\tt i\^{ }2} is replaced by -1, and appropriately for higher
  367. powers of {\tt I}. (This applies only to the symbol {\tt I} used on the top
  368. level, not as a formal parameter in a procedure, a local variable, nor in
  369. the context {\tt for i:= ...} .).} \\ \\
  370. {\tt INFINITY} & \parbox[t]{\reduceboxwidth}{Intended to represent $\infty$
  371. \ttindex{INFINITY}
  372. in limit and power series calculations for example. Note however that the
  373. current system does {\em not} do proper arithmetic on $\infty$. For example,
  374. {\tt infinity + infinity} is {\tt 2*infinity}.} \\ \\
  375. {\tt NIL} & \parbox[t]{\reduceboxwidth}{In {\REDUCE} (algebraic mode only)
  376. taken as a synonym for zero. Therefore NIL cannot be used as a variable.} \\
  377. \\
  378. {\tt PI} & \parbox[t]{\reduceboxwidth}{Intended to represent the circular
  379. constant. With ROUNDED on,
  380. it is replaced by the value of $\pi$ to the current
  381. degree of floating point precision.} \\ \\
  382. {\tt T} & \parbox[t]{\reduceboxwidth}{Should not be used as a formal
  383. parameter or local variable in procedures, since conflict arises with the
  384. symbolic mode meaning of T as {\em true}.} \\ \\
  385. \end{tabular}
  386. Using these reserved variables\index{Reserved variable} inappropriately
  387. will lead to an error.
  388. There are also internal variables used by {\REDUCE} that have similar
  389. restrictions. These usually have an asterisk in their names, so it is
  390. unlikely a casual user would use one. An example of such a variable is
  391. {\tt K!*} used in the asymptotic command package.
  392. Certain words are reserved in {\REDUCE}. They may only be used in the manner
  393. intended. A list of these is given in the section ``Reserved Identifiers".
  394. There are, of course, an impossibly large number of such names to keep in
  395. mind. The reader may therefore want to make himself a copy of the list,
  396. deleting the names he doesn't think he is likely to use by mistake.
  397. \section{Strings}
  398. Strings\index{String} are used in {\tt WRITE} statements (q.v.), in other
  399. output statements (such as error messages), and to name files. A string
  400. consists of any number of characters enclosed in double quotes. For example:
  401. \begin{verbatim}
  402. "A String".
  403. \end{verbatim}
  404. Lower case characters within a string are not converted to upper case.
  405. The string {\tt ""} represents the empty string. A double quote may be
  406. included in a string by preceding it by another double quote. Thus
  407. {\tt "a""b"} is the string {\tt a"b}, and {\tt """"} is the string {\tt "}.
  408. \section{Comments}
  409. Text can be included in program\index{Program} listings for the
  410. convenience of human readers, in such a way that {\REDUCE} pays no
  411. attention to it. There are two ways to do this:
  412. \begin{enumerate}
  413. \item Everything from the word {\tt COMMENT}\ttindex{COMMENT} to the next
  414. statement terminator (q.v.), normally ; or \$, is ignored. Such comments
  415. can be placed anywhere a blank could properly appear. (Note that {\tt END}
  416. and $>>$ are {\em not} treated as {\tt COMMENT} delimiters!)
  417. \item Everything from the symbol {\tt \%}\index{Percent sign} to the end
  418. of the line on which it appears is ignored. Such comments can be placed
  419. as the last part of any line. Statement terminators have no special
  420. meaning in such comments. Remember to put a semicolon before the {\tt \%}
  421. if the earlier part of the line is intended to be so terminated. Remember
  422. also to begin each line of a multi-line {\tt \%} comment with a {\tt \%}
  423. sign.
  424. \end{enumerate}
  425. \section{Operators}
  426. Operators\index{Operator} in {\REDUCE} are specified by name and type.
  427. There are two types, infix\index{Infix operator} and prefix.
  428. \index{Prefix operator} Operators can be purely abstract, just symbols
  429. with no properties; they can have values assigned (using {\tt :=} or
  430. simple {\tt LET} declarations) for specific arguments; they can have
  431. properties declared for some collection of arguments (using more general
  432. {\tt LET} declarations); or they can be fully defined (usually by a
  433. procedure declaration).
  434. Infix operators\index{Infix operator} have a definite precedence with
  435. respect to one another, and normally occur between their arguments.
  436. For example:
  437. \begin{quote}
  438. \begin{tabbing}
  439. {\tt a + b - c} \hspace{1.5in} \= (spaces optional) \\
  440. {\tt x<y and y=z} \> (spaces required where shown)
  441. \end{tabbing}
  442. \end{quote}
  443. Spaces can be freely inserted between operators and variables or operators
  444. and operators. They are required only where operator names are spelled out
  445. with letters (such as the {\tt AND} in the example) and must be unambiguously
  446. separated from another such or from a variable (like {\tt Y}). Wherever one
  447. space can be used, so can any larger number.
  448. Prefix operators occur to the left of their arguments, which are written as
  449. a list enclosed in parentheses and separated by commas, as with normal
  450. mathematical functions, e.g.,
  451. \begin{verbatim}
  452. cos(u)
  453. df(x^2,x)
  454. q(v+w)
  455. \end{verbatim}
  456. Unmatched parentheses, incorrect groupings of infix operators
  457. \index{Infix operator} and the like, naturally lead to syntax errors. The
  458. parentheses can be omitted (replaced by a space following the
  459. operator\index{Operator} name) if the operator is unary and the argument
  460. is a single symbol or begins with a prefix operator name:
  461. \begin{quote}
  462. \begin{tabbing}
  463. {\tt cos y} \hspace{1.75in} \= means cos(y) \\
  464. {\tt cos (-y)} \> -- parentheses necessary \\
  465. {\tt log cos y} \> means log(cos(y)) \\
  466. {\tt log cos (a+b)} \> means log(cos(a+b))
  467. \end{tabbing}
  468. \end{quote}
  469. but
  470. \begin{quote}
  471. \begin{tabbing}
  472. {\tt cos a*b} \hspace{1.6in} \= means (cos a)*b \\
  473. {\tt cos -y} \> is erroneous (treated as a variable \\
  474. \> ``cos" minus the variable y)
  475. \end{tabbing}
  476. \end{quote}
  477. A unary prefix operator\index{Prefix operator} has a precedence
  478. \index{Operator precedence} higher than any infix operator, including
  479. unary infix operators. \index{Infix operator}
  480. In other words, {\REDUCE} will always interpret {\tt cos~y + 3} as
  481. {\tt (cos~y) + 3} rather than as {\tt cos(y + 3)}.
  482. Infix operators may also be used in a prefix format on input, e.g.,
  483. {\tt +(a,b,c)}. On output, however, such expressions will always be
  484. printed in infix form (i.e., {\tt a + b + c} for this example).
  485. A number of prefix operators are built into the system with predefined
  486. properties. Users may also add new operators and define their rules for
  487. simplification. The built in operators are described in another section.
  488. \subsection*{Built-In Infix Operators}
  489. The following infix operators\index{Infix operator} are built into the
  490. system. They are all defined internally as procedures.
  491. \begin{verbatim}
  492. <infix operator>::= where|:=|or|and|not|member|memq|=|neq|eq|
  493. >=|>|<=|<|+|-|*|/|^|**|.
  494. \end{verbatim}
  495. These operators may be further divided into the following subclasses:
  496. \begin{verbatim}
  497. <assignment operator> ::= :=
  498. <logical operator> ::= or|and|not|member|memq
  499. <relational operator> ::= =|neq|eq|>=|>|<=|<
  500. <substitution operator> ::= where
  501. <arithmetic operator> ::= +|-|*|/|^|**
  502. <construction operator> ::= .
  503. \end{verbatim}
  504. {\tt MEMBER}, {\tt MEMQ} and {\tt EQ} are not used in the algebraic mode of
  505. {\REDUCE}. They are explained in the section on symbolic mode (q.v.).
  506. {\tt WHERE} is described in the section on substitutions.
  507. For compatibility with the intermediate language used by {\REDUCE}, each
  508. special character infix operator\index{Infix operator} has an alternative
  509. alphanumeric identifier associated with it. These identifiers may be used
  510. interchangeably with the corresponding special character names on input.
  511. This correspondence is as follows:
  512. \begin{quote}
  513. \begin{tabbing}
  514. {\tt := setq} \hspace{0.5in} \= (the assignment operator) \\
  515. {\tt = equal} \\
  516. {\tt >= geq} \\
  517. {\tt > greaterp} \\
  518. {\tt <= leq} \\
  519. {\tt < lessp} \\
  520. {\tt + plus} \\
  521. {\tt - difference} \> (if unary, {\tt minus}) \\
  522. {\tt * times} \\
  523. {\tt / quotient} \> (if unary, {\tt recip}) \\
  524. {\tt \^{ } or ** expt} \> (raising to a power) \\
  525. {\tt . cons}
  526. \end{tabbing}
  527. \end{quote}
  528. Note: {\tt NEQ} is used to mean {\em not equal}. There is no special
  529. symbol provided for it.
  530. The above operators\index{Operator} are binary, except {\tt NOT} which is
  531. unary and {\tt +} and {\tt *} which are nary (i.e., taking an arbitrary
  532. number of arguments). In addition, {\tt -} and {\tt /} may be used as
  533. unary operators, e.g., /2 means the same as 1/2. Any other operator is
  534. parsed as a binary operator using a left association rule. Thus {\tt
  535. a/b/c} is interpreted as {\tt (a/b)/c}. There are two exceptions to this
  536. rule: {\tt :=} and {\tt .} are right associative. Example: {\tt a:=b:=c}
  537. is interpreted as {\tt a:=(b:=c)}. Unlike ALGOL and PASCAL, {\tt \^{ }} is
  538. left associative.
  539. The operators\index{Operator} {\tt $<$}, {\tt $<$=}, {\tt $>$}, {\tt $>$=}
  540. can only be used for making comparisons between numbers. No meaning is
  541. currently assigned to this kind of comparison between general expressions.
  542. Parentheses may be used to specify the order of combination. If
  543. parentheses are omitted then this order is by the ordering of the
  544. precedence list\index{Operator precedence} defined by the right-hand side
  545. of the BNF definition of {\tt <infix operator>}\index{Infix operator}
  546. above, from lowest to highest. In other words, {\tt :=} has the lowest
  547. precedence, and {\tt .} (the dot operator) the highest.
  548. \chapter{Expressions}
  549. {\REDUCE} expressions\index{Expression} may be of several types and consist
  550. of sequences of numbers, variables, operators, left and right parentheses
  551. and commas. The most common types are as follows:
  552. \section{Scalar Expressions}
  553. \index{Scalar}Using the arithmetic operations {\tt + - * / \^{ }}
  554. (power) and parentheses, scalar expressions are composed from numbers,
  555. ordinary ``scalar" variables (identifiers), array names with subscripts,
  556. operator or procedure names with arguments and statement expressions.
  557. {\it Examples:}
  558. \begin{verbatim}
  559. x
  560. x^3 - 2*y/(2*z^2 - df(x,z))
  561. (p^2 + m^2)^(1/2)*log (y/m)
  562. a(5) + b(i,q)
  563. \end{verbatim}
  564. The symbol ** may be used as an alternative to the caret symbol
  565. (\verb+^+) for forming powers. The particular system instructions should
  566. be consulted to determine if this is not supported.
  567. Statement expressions (q.v.), usually in parentheses, can also form part of
  568. a scalar\index{Scalar} expression, as in the example
  569. \begin{verbatim}
  570. w + (c:=x+y) + z .
  571. \end{verbatim}
  572. When the algebraic value of an expression is needed, {\REDUCE} determines it,
  573. starting with the algebraic values of the parts, roughly as follows:
  574. Variables and operator symbols with an argument list have the algebraic
  575. values they were last assigned, or if never assigned stand for themselves.
  576. However, array elements have the algebraic values they were last assigned,
  577. or, if never assigned, are taken to be 0.
  578. Procedures are evaluated with the values of their actual parameters.
  579. In evaluating expressions, the standard rules of algebra are applied.
  580. Unfortunately, this algebraic evaluation of an expression is not as
  581. unambiguous as is numerical evaluation. This process is generally referred
  582. to as ``simplification"\index{Simplification} in the sense that the
  583. evaluation usually but not always produces a simplified form for the
  584. expression.
  585. There are many options available to the user for carrying out such
  586. simplification\index{Simplification}. If the user doesn't specify any
  587. method, the default method is used. The default evaluation of an
  588. expression involves expansion of the expression and collection of like
  589. terms, ordering of the terms, evaluation of derivatives and other
  590. functions and substitution for any expressions which have values assigned
  591. or declared (see assignments and {\tt LET} statements). In many cases,
  592. this is all that the user needs.
  593. The declarations by which the user can exercise some control over the way
  594. in which the evaluation is performed are explained in other sections. For
  595. example, if a real (floating point) number is encountered during
  596. evaluation, the system will normally convert it into a ratio of two
  597. integers. If the user wants to use real arithmetic, he can effect this by
  598. the command {\tt on rounded;}. \ttindex{ROUNDED} Other modes for
  599. coefficient arithmetic are described elsewhere.
  600. If an illegal action occurs during evaluation (such as division by zero)
  601. or functions are called with the wrong number of arguments, and so on, an
  602. appropriate error message is generated.
  603. % A list of such error messages is given in an appendix.
  604. \section{Integer Expressions}
  605. \index{Integer}These are expressions which, because of the values of the
  606. constants and variables in them, evaluate to whole numbers.
  607. {\it Examples:}
  608. \begin{verbatim}
  609. 2, 37 * 999, (x + 3)^2 - x^2 - 6*x
  610. \end{verbatim}
  611. are obviously integer expressions.
  612. \begin{verbatim}
  613. j + k - 2 * j^2
  614. \end{verbatim}
  615. is an integer expression when {\tt J} and {\tt K} have values that are
  616. integers, or if not integers are such that ``the variables and fractions
  617. cancel out", as in
  618. \begin{verbatim}
  619. k - 7/3 - j + 2/3 + 2*j^2.
  620. \end{verbatim}
  621. \section{Boolean Expressions}
  622. \label{sec-boolean}
  623. A boolean expression\index{Boolean} returns a truth value. In the
  624. algebraic mode of {\REDUCE}, boolean expressions have the syntactical form:
  625. \begin{verbatim}
  626. <expression> <relational operator> <expression>
  627. \end{verbatim}
  628. or
  629. \begin{verbatim}
  630. <boolean operator> (<arguments>)
  631. \end{verbatim}
  632. or
  633. \begin{verbatim}
  634. <boolean expression> <logical operator>
  635. <boolean expression>.
  636. \end{verbatim}
  637. Parentheses can also be used to control the precedence of expressions.
  638. In addition to the logical and relational operators defined earlier as
  639. infix operators, the following boolean operators are also defined: \\ \\
  640. \ttindex{EVENP}\ttindex{FIXP}\ttindex{FREEOF}\ttindex{NUMBERP}
  641. \ttindex{ORDP}\ttindex{PRIMEP}
  642. \begin{tabular}{l r}
  643. {\tt EVENP(U)} & \parbox[t]{\redboxwidth}{determines if the number {\tt U} is
  644. even or not;} \\ \\
  645. {\tt FIXP(U)} & \parbox[t]{\redboxwidth}{determines if the expression {\tt U}
  646. is integer or not;} \\ \\
  647. {\tt FREEOF(U,V)} & \parbox[t]{\redboxwidth}{determines if the expression
  648. {\tt U} does not contain the kernel (q.v.) {\tt V} anywhere in its
  649. structure;} \\ \\
  650. {\tt NUMBERP(U)} & \parbox[t]{\redboxwidth}{determines if {\tt U} is a number
  651. or not;} \\ \\
  652. {\tt ORDP(U,V)} & \parbox[t]{\redboxwidth}{determines if {\tt U} is ordered
  653. ahead of {\tt V} by some canonical ordering (based on the expression structure
  654. and an internal ordering of identifiers);} \\ \\
  655. {\tt PRIMEP(U)} & \parbox[t]{\redboxwidth}{true if {\tt U} is a prime
  656. object.} \\ \\
  657. \end{tabular}
  658. {\it Examples:}
  659. \begin{verbatim}
  660. j<1
  661. x>0 or x=-2
  662. numberp x
  663. fixp x and evenp x
  664. numberp x and x neq 0
  665. \end{verbatim}
  666. Boolean expressions can only appear directly within {\tt IF}, {\tt FOR},
  667. {\tt WHILE}, and {\tt UNTIL} statements, as described in other sections.
  668. Such expression cannot be used in place of ordinary algebraic expressions,
  669. or assigned to a variable.
  670. NB: For those familiar with symbolic mode (q.v.), the meaning of some of
  671. these operators is different in that mode. For example, {\tt NUMBERP} is
  672. true only for integers and reals in symbolic mode.
  673. When two or more boolean expressions are combined with {\tt AND}, they are
  674. evaluated one by one until a {\em false} expression is found. The rest are
  675. not evaluated. Thus
  676. \begin{verbatim}
  677. numberp x and numberp y and x>y
  678. \end{verbatim}
  679. does not attempt to make the {\tt x>y} comparison unless {\tt X} and {\tt Y}
  680. are both verified to be numbers.
  681. Similarly, evaluation of a sequence of boolean expressions connected by
  682. {\tt OR} stops as soon as a {\em true} expression is found.
  683. NB: In a boolean expression, and in a place where a boolean expression is
  684. expected, the algebraic value 0 is interpreted as {\em false}, while all
  685. other algebraic values are converted to {\em true}. So in algebraic mode
  686. a procedure can be written for direct usage in boolean expressions,
  687. returning say 1 or 0 as its value as in
  688. \begin{verbatim}
  689. procedure polynomialp(u,x);
  690. if den(u)=1 and deg(u,x)>=1 then 1 else 0;
  691. \end{verbatim}
  692. One can then use this in a boolean construct, such as
  693. \begin{verbatim}
  694. if polynomialp(q,z) and not polynomialp(q,y) then ...
  695. \end{verbatim}
  696. In addition, any procedure that does not have a defined return value
  697. (for example, a block (q.v.) without a {\tt RETURN} statement in it)
  698. has the boolean value {\em false}.
  699. \section{Equations}
  700. Equations\index{Equation} are a particular type of expression with the syntax
  701. \begin{verbatim}
  702. <expression> = <expression>.
  703. \end{verbatim}
  704. In addition to their role as boolean expressions, they can also be used as
  705. arguments to several operators (e.g., {\tt SOLVE} (q.v.)), and can be
  706. returned as values.
  707. Under normal circumstances, the right-hand-side of the equation is evaluated
  708. but not the left-hand-side. If both sides are to be evaluated, the switch
  709. {\tt EVALLHSEQP} \ttindex{EVALLHSEQP} should be turned on.
  710. To facilitate the handling of equations, two selectors, {\tt LHS}
  711. \ttindex{LHS} and {\tt RHS} \ttindex{RHS}, which return the left- and
  712. right-hand sides of a equation\index{Equation} respectively, are provided.
  713. For example,
  714. \begin{verbatim}
  715. lhs(a+b=c) -> a+b
  716. and
  717. rhs(a+b=c) -> c.
  718. \end{verbatim}
  719. \section{Proper Statements as Expressions}
  720. Several kinds of proper statements\index{Proper statement} (q.v.) deliver
  721. an algebraic or numeric result of some kind, which can in turn be used as
  722. an expression or part of an expression. For example, an assignment
  723. statement itself has a value, namely the value assigned. So
  724. \begin{verbatim}
  725. 2 * (x := a+b)
  726. \end{verbatim}
  727. is equal to {\tt 2*(a+b)}, as well as having the ``side-effect"\index{Side
  728. effect} of assigning the value {\tt a+b} to {\tt X}. In context,
  729. \begin{verbatim}
  730. y := 2 * (x := a+b);
  731. \end{verbatim}
  732. sets {\tt X} to {\tt a+b} and {\tt Y} to {\tt 2*(a+b)}.
  733. The sections on the various proper statement\index{Proper statement} types
  734. indicate which of these statements are also useful as expressions.
  735. \chapter{Lists}
  736. A list\index{List} is an object consisting of a sequence of other objects
  737. (including lists themselves), separated by commas and surrounded by
  738. braces. Examples of lists are:
  739. \begin{verbatim}
  740. {a,b,c}
  741. {1,a-b,c=d}
  742. {{a},{{b,c},d},e}.
  743. \end{verbatim}
  744. \section{Operations on Lists}\index{List operation}
  745. Several operators in the system return their results as lists, and a user
  746. can create new lists using braces and commas. To facilitate the use of
  747. such lists, a number of operators are also available for manipulating
  748. them. {\tt PART(<list>,n)}\ttindex{PART} for example will return the
  749. $n^{th}$ element of a list. {\tt LENGTH}\ttindex{LENGTH} will return the
  750. length of a list. Several operators are also defined uniquely for lists.
  751. For those familiar with them, these operators in fact mirror the
  752. operations defined for Lisp lists. These operators are as follows:
  753. \subsection{FIRST}
  754. This operator\ttindex{FIRST} returns the first member of a list. An error
  755. occurs if the argument is not a list, or the list is empty.
  756. \subsection{SECOND}
  757. {\tt SECOND} \ttindex{SECOND} returns the second member of a list. An error
  758. occurs if the argument is not a list or has no second element.
  759. \subsection{THIRD}
  760. This operator\ttindex{THIRD} returns the third member of a list. An error
  761. occurs if the argument is not a list or has no third element.
  762. \subsection{REST}
  763. {\tt REST} \ttindex{REST} returns its argument with the first element
  764. removed. An error occurs if the argument is not a list, or is empty.
  765. \subsection{ $.$ (Cons) Operator}
  766. This operator\ttindex{. (CONS)} adds (``conses") an expression to the
  767. front of a list. For example:
  768. \begin{verbatim}
  769. a . {b,c} -> {a,b,c}.
  770. \end{verbatim}
  771. \subsection{APPEND}
  772. This operator\ttindex{APPEND} appends its first argument to its second to
  773. form a new list.
  774. {\it Examples:}
  775. \begin{verbatim}
  776. append({a,b},{c,d}) -> {a,b,c,d}
  777. append({{a,b}},{c,d}) -> {{a,b},c,d}.
  778. \end{verbatim}
  779. \subsection{REVERSE}
  780. The operator {\tt REVERSE}\ttindex{REVERSE} returns its argument with the
  781. elements in the reverse order. It only applies to the top level list, not
  782. any lower level lists that may occur. Examples are:\index{List operation}
  783. \begin{verbatim}
  784. reverse({a,b,c}) -> {c,b,a}
  785. reverse({{a,b,c},d}) -> {d,{a,b,c}}.
  786. \end{verbatim}
  787. \subsection{List Arguments of Other Operators}
  788. If an operator other than those specifically defined for lists is given a
  789. single argument that is a list, then the result of this operation will be
  790. a list in which that operator is applied to each element of the list. For
  791. example, the result of evaluating {\tt log\{a,b,c\}} is the expression
  792. {\tt \{LOG(A),LOG(B),LOG(C)\}}.
  793. There are two ways to inhibit this operator distribution. Firstly, the
  794. switch {\tt LISTARGS}, \ttindex{LISTARGS} if on, will globally inhibit
  795. such distribution. Secondly, one can inhibit this distribution for a
  796. specific operator by the declaration {\tt LISTARGP}.\ttindex{LISTARGP} For
  797. example, with the declaration {\tt listargp log}, {\tt log\{a,b,c\}} would
  798. evaluate to {\tt LOG(\{A,B,C\})}.
  799. If an operator has more than one argument, no such distribution occurs.
  800. \chapter{Statements}
  801. A statement\index{Statement} is any combination of reserved words and
  802. expressions, and has the syntax \index{Proper statement}
  803. \begin{verbatim}
  804. <statement> ::= <expression>|<proper statement>
  805. \end{verbatim}
  806. A {\REDUCE} program consists of a series of commands which are statements
  807. followed by a terminator:\index{Terminator}\index{Semicolon}
  808. \index{Dollar sign}
  809. \begin{verbatim}
  810. <terminator> ::= ;|$
  811. \end{verbatim}
  812. The division of the program into lines is arbitrary. Several statements
  813. can be on one line, or one statement can be freely broken onto several
  814. lines. If the program is run interactively, statements ending with ; or \$
  815. are not processed until an end-of-line character is encountered. This
  816. character can vary from system to system, but is normally the RETURN key on
  817. an ASCII terminal. Specific systems may also use additional keys as
  818. statement terminators.
  819. If a statement is a proper statement\index{Proper statement}, the
  820. appropriate action takes place.
  821. Depending on the nature of the proper statement some result or response may
  822. or may not be printed out, and the response may or may not depend on the
  823. terminator used.
  824. If a statement is an expression, it is evaluated. If the terminator is a
  825. semicolon, the result is printed. If the terminator is a dollar sign, the
  826. result is not printed. Because it is not usually possible to know in
  827. advance how large an expression will be, no explicit format statements are
  828. offered to the user. However, a variety of output declarations are
  829. available so that the output can be produced in different forms. These
  830. output declarations are explained in Section~\ref{sec-output}.
  831. The following sub-sections describe the types of proper statements
  832. \index{Proper statement} in {\REDUCE}.
  833. \section{Assignment Statements}
  834. These statements\index{Assignment} have the syntax
  835. \begin{verbatim}
  836. <assignment statement> ::= <expression> := <expression>
  837. \end{verbatim}
  838. The {\tt <expression>} on the left side is normally the name of a variable, an
  839. operator symbol with its list of arguments filled in, or an array name with
  840. the proper number of integer subscript values within the array bounds. For
  841. example:
  842. \begin{quote}
  843. \begin{tabbing}
  844. {\tt a1 := b + c} \\
  845. {\tt h(l,m) := x-2*y} \hspace{1in} \= (where {\tt h} is an operator) \\
  846. {\tt k(3,5) := x-2*y} \> (where {\tt k} is a 2-dim. array)
  847. \end{tabbing}
  848. \end{quote}
  849. More general assignments\index{Assignment} such as {\tt a+b := c} are also
  850. allowed. The effect of these is explained in the section ``Substitutions
  851. for General Expressions".
  852. An assignment statement causes the expression on the right-hand-side to be
  853. evaluated. If the left-hand-side is a variable, the value of the
  854. right-hand-side is assigned to that unevaluated variable. If the
  855. left-hand-side is an operator or array expression, the arguments of that
  856. operator or array are evaluated, but no other simplification done. The
  857. evaluated right-hand-side is then assigned to the resulting expression.
  858. For example, if {\tt A} is a single-dimensional array, {\tt a(1+1) := b}
  859. assigns the value {\tt B} to the array element {\tt a(2)}.
  860. If a semicolon is used as the terminator when an assignment
  861. \index{Assignment} is issued as a command (i.e. not as a part of a group
  862. statement or procedure or other similar construct), the left-hand side
  863. symbol of the assignment statement is printed out, followed by a ``{\tt :=}",
  864. followed by the value of the expression on the right.
  865. It is also possible to write a multiple assignment statement:
  866. \index{Multiple assignment statement}
  867. \begin{verbatim}
  868. <expression> := ... := <expression> := <expression>
  869. \end{verbatim}
  870. In this form, each {\tt <expression>} but the last is set to the value of
  871. the last {\tt <expression>}. If a semicolon is used as a terminator, each
  872. expression except the last is printed followed by a ``{\tt :=}" ending
  873. with the value of the last expression.
  874. \subsection{Set Statement}
  875. In some cases, it is desirable to perform an assignment in which {\em both}
  876. the left- and right-hand sides of an assignment\index{Assignment} are
  877. evaluated. In this case, the {\tt SET}\ttindex{SET} statement can be used
  878. with the syntax:
  879. \begin{verbatim}
  880. SET(<expression>,<expression>);
  881. \end{verbatim}
  882. For example, the statements
  883. \begin{verbatim}
  884. j := 23;
  885. set(mkid(a,j),x);
  886. \end{verbatim}
  887. assigns the value {\tt X} to {\tt A23}.
  888. \section{Group Statements}
  889. The group statement\index{Group statement} is a construct used where
  890. {\REDUCE} expects a single statement, but a series of actions needs to be
  891. performed. It is formed by enclosing one or more statements (of any kind)
  892. between the symbols {\tt $<<$} and {\tt $>>$}, separated by semicolons or
  893. dollar signs -- it doesn't matter which. The statements are executed one
  894. after another.
  895. Examples will be given in the sections on {\tt IF}\ttindex{IF} and other
  896. types of statements in which the {\tt $<<$} \ldots {\tt $>>$} construct is
  897. useful.
  898. If the last statement in the enclosed group has a value, then that is also
  899. the value of the group statement. Care must be taken not to have a
  900. semicolon or dollar sign after the last grouped statement, if the value of
  901. the group is relevant: such an extra terminator causes the group to have
  902. the value NIL or zero.
  903. \section{Conditional Statements}
  904. The conditional statement\index{Conditional statement} has the following
  905. syntax:
  906. \begin{verbatim}
  907. <conditional statement> ::=
  908. IF <boolean expression> THEN <statement> [ELSE <statement>]
  909. \end{verbatim}
  910. The boolean expression is evaluated. If the result is {\em true}, the first
  911. {\tt <statement>} is executed. If it is {\em false}, the second is.
  912. {\it Examples:}
  913. \begin{verbatim}
  914. if x=5 then a:=b+c else d:=e+f
  915. if x=5 and numberp y
  916. then <<ff:=q1; a:=b+c>>
  917. else <<ff:=q2; d:=e+f>>
  918. \end{verbatim}
  919. Note the use of the group statement\index{Group statement}.
  920. \\
  921. Conditional statements associate to the right; i.e.,\ttindex{IF}
  922. \begin{verbatim}
  923. IF <a> THEN <b> ELSE IF <c> THEN <d> ELSE <e>
  924. \end{verbatim}
  925. is equivalent to:
  926. \begin{verbatim}
  927. IF <a> THEN <b> ELSE (IF <c> THEN <d> ELSE <e>)
  928. \end{verbatim}
  929. In addition, the construction
  930. \begin{verbatim}
  931. IF <a> THEN IF <b> THEN <c> ELSE <d>
  932. \end{verbatim}
  933. parses as
  934. \begin{verbatim}
  935. IF <a> THEN (IF <b> THEN <c> ELSE <d>).
  936. \end{verbatim}
  937. If the value of the conditional statement\index{Conditional
  938. statement} is of primary interest, it is often called a conditional
  939. expression instead. Its value is the value of whichever statement was
  940. executed. (If the executed statement has no value, the conditional
  941. expression has no value or the value 0, depending on how it is used.)
  942. {\it Examples:}
  943. \begin{verbatim}
  944. a:=if x<5 then 123 else 456;
  945. b:=u + v^(if numberp z then 10*z else 1) + w;
  946. \end{verbatim}
  947. If the value is of no concern, the {\tt ELSE} clause may be omitted if no
  948. action is required in the {\em false} case.
  949. \begin{verbatim}
  950. if x=5 then a:=b+c;
  951. \end{verbatim}
  952. Note: As explained in Section~\ref{sec-boolean},a
  953. if a scalar or numeric expression is used in place of
  954. the boolean expression -- for example, a variable is written there -- the
  955. {\em true} alternative is followed unless the expression has the value 0.
  956. \section{FOR Statements}
  957. The {\tt FOR} statement is used to define a variety of program
  958. loops\index{Loop}. Its general syntax is as follows:\ttindex{UNTIL}
  959. \ttindex{DO} \ttindex{PRODUCT} \ttindex{SUM} \ttindex{COLLECT} \ttindex{JOIN}
  960. \begin{verbatim}
  961. {STEP <number> UNTIL}
  962. {<var>:=<number>{ }<number>}
  963. FOR { { : } }<action><exprn>
  964. { }
  965. { EACH <var> IN <list> }
  966. \end{verbatim}
  967. where
  968. \begin{verbatim}
  969. <action> ::= do|product|sum|collect|join.
  970. \end{verbatim}
  971. The assignment\index{Assignment} form of the {\tt FOR} statement defines an
  972. iteration over the indicated numerical range. If expressions that do not
  973. evaluate to numbers are used in the designated places, an error will
  974. result.
  975. The {\tt FOR EACH} \ttindex{FOR EACH} form of the {\tt FOR} statement is
  976. designed to iterate down a list. Again, an error will occur if a list is
  977. not used.
  978. The action {\tt DO} \ttindex{DO} means that {\tt <exprn>} is simply
  979. evaluated and no value kept; the statement returning 0 in this case (or no
  980. value at the top level). {\tt COLLECT} means that the results of
  981. evaluating {\tt <exprn>} each time are linked together to make a list,
  982. and {\tt JOIN} means that the values of {\tt <exprn>} are themselves
  983. lists that are joined to make one list (similar to {\tt CONC} in Lisp).
  984. Finally, {\tt PRODUCT} \ttindex{PRODUCT} and {\tt SUM} \ttindex{SUM}
  985. form the respective combined value out of the values of {\tt <exprn>}.
  986. In all cases, {\tt <exprn>} is evaluated algebraically within the
  987. scope of the current value of {\tt <var>}. If {\tt <action>} is
  988. {\tt DO}\ttindex{DO}, then nothing else happens. In other cases, {\tt
  989. <action>} is a binary operator that causes a result to be built up and
  990. returned by {\tt FOR}. In those cases, the loop\index{Loop} is
  991. initialized to a default value ({\tt 0} for {\tt SUM}, \ttindex{SUM} {\tt
  992. 1} for {\tt PRODUCT}, \ttindex{PRODUCT} and an empty list for the other
  993. actions). The test for the end condition is made before any action is
  994. taken. As in Pascal, if the variable is out of range in the assignment
  995. case, or the {\tt <list>} is empty in the {\tt FOR EACH}\ttindex{FOR EACH}
  996. case, {\tt <exprn>} is not evaluated at all.
  997. {\it Examples:}
  998. \begin{enumerate}
  999. \item If {\tt A}, {\tt B} have been declared to be arrays, the following
  1000. stores $5^{2}$ through $10^{2}$ in {\tt A(5)} through {\tt A(10)}, and at
  1001. the same time stores the cubes in the {\tt B} array:
  1002. \begin{verbatim}
  1003. for i := 5 step 1 until 10 do <<a(i):=i^2; b(i):=i^3>>
  1004. \end{verbatim}
  1005. \item As a convenience, the common construction
  1006. \begin{verbatim}
  1007. STEP 1 UNTIL
  1008. \end{verbatim}
  1009. may be abbreviated to a colon. Thus, instead of the above we could write:
  1010. \begin{verbatim}
  1011. for i := 5:10 do <<a(i):=i^2; b(i):=i^3>>
  1012. \end{verbatim}
  1013. \item The following sets {\tt C} to the sum of the squares of 1,3,5,7,9;
  1014. and {\tt D} to the expression {\tt x*(x+1)*(x+2)*(x+3)*(x+4):}
  1015. \begin{verbatim}
  1016. c := for j:=1 step 2 until 9 sum j^2;
  1017. d := for k:=0 step 1 until 4 product (x+k);
  1018. \end{verbatim}
  1019. \item The following forms a list of the squares of the elements of the list
  1020. {\tt \{a,b,c\}:}\ttindex{FOR EACH}
  1021. \begin{verbatim}
  1022. for each x in {a,b,c} collect x^2;
  1023. \end{verbatim}
  1024. \item The following forms a list of the listed squares of the elements of the
  1025. list {\tt \{a,b,c\}} (i.e., {\tt \{\{A\^{ }2\},\{B\^{ }2\},\{C\^{ }2\}\}):}
  1026. \begin{verbatim}
  1027. for each x in {a,b,c} collect {x^2};
  1028. \end{verbatim}
  1029. \item The following also forms a list of the squares of the elements of
  1030. the list {\tt \{a,b,c\},} since the {\tt JOIN} operation joins the
  1031. individual lists into one list:\ttindex{FOR EACH}
  1032. \begin{verbatim}
  1033. for each x in {a,b,c} join {x^2};
  1034. \end{verbatim}
  1035. \end{enumerate}
  1036. The control variable used in the {\tt FOR} statement is actually a new
  1037. variable, not related to the variable of the same name outside the {\tt
  1038. FOR} statement. In other words, executing a statement {\tt for i:=} \ldots
  1039. doesn't change the system's assumption that $i^{2} = -1$.
  1040. Furthermore, in algebraic mode, the value of the control variable is
  1041. substituted in {\tt <exprn>} only if it occurs explicitly in that
  1042. expression. It will not replace a variable of the same name in the value
  1043. of that expression. For example:
  1044. \begin{verbatim}
  1045. b := a; for a := 1:2 do write b;
  1046. \end{verbatim}
  1047. prints {\tt A} twice, not 1 followed by 2.
  1048. \section{WHILE \ldots DO}
  1049. The\ttindex{WHILE} {\tt FOR \ldots DO} \ttindex{DO} feature allows easy
  1050. coding of a repeated operation in which the number of repetitions is known
  1051. in advance. If the criterion for repetition is more complicated, {\tt
  1052. WHILE \ldots DO} can often be used. Its syntax is:
  1053. \begin{verbatim}
  1054. WHILE <boolean expression> DO <statement>
  1055. \end{verbatim}
  1056. The {\tt WHILE \ldots DO} controls the single statement following {\tt DO}.
  1057. If several statements are to be repeated, as is almost always the case,
  1058. they must be grouped using the $<<$ \ldots $>>$ or {\tt BEGIN \ldots END}
  1059. as in the example below.
  1060. The {\tt WHILE} condition is tested each time {\em before} the action
  1061. following the {\tt DO} is attempted. If the condition is false to begin
  1062. with, the action is not performed at all. Make sure that what is to be
  1063. tested has an appropriate value initially.
  1064. {\it Example:}
  1065. Suppose we want to add up a series of terms, generated one by one, until
  1066. we reach a term which is less than 1/1000 in value. For our simple
  1067. example, let us suppose the first term equals 1 and each term is obtained
  1068. from the one before by taking one third of it and adding one third its
  1069. square. We would write:
  1070. \begin{verbatim}
  1071. ex:=0; term:=1;
  1072. while num(term - 1/1000) >= 0 do
  1073. <<ex := ex+term; term:=(term + term^2)/3>>;
  1074. ex;
  1075. \end{verbatim}
  1076. As long as {\tt TERM} is greater than or equal to ({\tt >=}) 1/1000 it will
  1077. be added to {\tt EX} and the next {\tt TERM} calculated. As soo\ as {\tt
  1078. TERM} becomes less than 1/1000 the {\tt WHILE} test fails and the {\tt
  1079. TERM} will not be added.
  1080. \section{REPEAT \ldots UNTIL}
  1081. \ttindex{REPEAT} {\tt REPEAT \ldots UNTIL} is very similar in purpose to
  1082. {\tt WHILE \ldots DO}. Its syntax is:
  1083. \begin{verbatim}
  1084. REPEAT <statement> UNTIL <boolean expression>
  1085. \end{verbatim}
  1086. (PASCAL users note: Only a single statement -- usually a group statement
  1087. -- is allowed between the {\tt REPEAT} and the {\tt UNTIL.)} \\
  1088. There are two essential differences:
  1089. \begin{enumerate}
  1090. \item The test is performed {\em after} the controlled statement (or group of
  1091. statements) is executed, so the controlled statement is always executed at
  1092. least once.
  1093. \item The test is a test for when to stop rather than when to continue, so its
  1094. ``polarity" is the opposite of that in {\tt WHILE \ldots DO.}
  1095. \end{enumerate}
  1096. As an example, we rewrite the example from the {\tt WHILE \ldots DO} section:
  1097. \begin{verbatim}
  1098. ex:=0; term:=1;
  1099. repeat <<ex := ex+term; term := (term + term^2)/3>>
  1100. until num(term - 1/1000) < 0;
  1101. ex;
  1102. \end{verbatim}
  1103. In this case, the answer will be the same as before, because in neither
  1104. case is a term added to {\tt EX} which is less than 1/1000.
  1105. \section{Compound Statements}
  1106. \index{Compound statement}Often the desired process can best (or only) be
  1107. described as a series of steps to be carried out one after the other. In
  1108. many cases, this can be achieved by use of the group statement\index{Group
  1109. statement} (q.v.). However, each step often provides some intermediate
  1110. result, until at the end we have the final result wanted. Alternatively,
  1111. iterations on the steps are needed that are not possible with constructs
  1112. such as {\tt WHILE} \ttindex{WHILE} or {\tt REPEAT} \ttindex{REPEAT}
  1113. statements (q.v.). In such cases the steps of the process must be
  1114. enclosed between the words {\tt BEGIN} and {\tt END}\ttindex{BEGIN \ldots
  1115. END} forming what is technically called a {\em block}\index{Block} or
  1116. {\em compound} statement. Such a compound statement can in fact be used
  1117. wherever a group statement appears. The converse is not true: {\tt BEGIN
  1118. \ldots END} can be used in ways that {\tt $<<$} \ldots {\tt $>>$} cannot.
  1119. If intermediate results must be formed, local variables must be provided
  1120. in which to store them. {\em Local} means that their values are deleted as
  1121. soon as the block's operations are complete, and there is no conflict with
  1122. variables outside the block that happen to have the same name. Local
  1123. variables are created by a {\tt SCALAR}\ttindex{SCALAR} declaration
  1124. immediately after the {\tt BEGIN}:
  1125. \begin{verbatim}
  1126. scalar a,b,c,z;
  1127. \end{verbatim}
  1128. If more convenient, several {\tt SCALAR} declarations can be given one after
  1129. another:
  1130. \begin{verbatim}
  1131. scalar a,b,c;
  1132. scalar z;
  1133. \end{verbatim}
  1134. In place of {\tt SCALAR} one can also use the declarations
  1135. {\tt INTEGER}\ttindex{INTEGER} or {\tt REAL}\ttindex{REAL}. In the present
  1136. version of {\REDUCE} variables declared {\tt INTEGER} are expected to have
  1137. only integer values, and are initialized to 0. {\tt REAL}
  1138. variables on the other hand are currently treated as algebraic mode {\tt
  1139. SCALAR}s.
  1140. {\it CAUTION:} {\tt INTEGER}, {\tt REAL} and {\tt SCALAR} declarations can
  1141. only be given immediately after a {\tt BEGIN}. An error will result if
  1142. they are used after other statements in a block (including {\tt ARRAY} and
  1143. {\tt OPERATOR} declarations, which are global in scope), or outside the
  1144. top-most block (e.g., at the top level). All variables declared {\tt
  1145. SCALAR} are automatically initialized to zero in algebraic mode ({\tt NIL}
  1146. in symbolic mode).
  1147. Any symbols not declared as local variables in a block refer to the
  1148. variables of the same name in the current calling environment. In
  1149. particular, if they are not so declared at a higher level (e.g., in a
  1150. surrounding block or as parameters in a calling procedure), their values can
  1151. be permanently changed.
  1152. Following the {\tt SCALAR}\ttindex{SCALAR} declaration(s), if any, write the
  1153. statements to be executed, one after the other, separated by delimiters
  1154. (e.g., {\tt ;} or {\tt \$}) (it doesn't matter which). However, from a
  1155. stylistic point of view, {\tt ;} is preferred.
  1156. The last statement in the body, just before {\tt END}, need not have a
  1157. terminator (since the {\tt BEGIN \ldots END} are in a sense brackets
  1158. confining the block statements). The last statement must also be the
  1159. command {\tt RETURN} \ttindex{RETURN} followed by the variable or
  1160. expression whose value is to be the value returned by the procedure. If
  1161. the {\tt RETURN} is omitted (or nothing is written after the word
  1162. {\tt RETURN}) the procedure will have no value or the value zero, depending
  1163. on how it is used (and {\tt NIL} in symbolic mode). Remember to put a
  1164. terminator after the {\tt END}.
  1165. {\it Example:}
  1166. Given a previously assigned integer value for {\tt N}, the following block
  1167. will compute the Legendre polynomial of degree {\tt N} in the variable
  1168. {\tt X}:
  1169. \begin{verbatim}
  1170. begin scalar seed,deriv,top,fact;
  1171. seed:=1/(y^2 - 2*x*y +1)^(1/2);
  1172. deriv:=df(seed,y,n);
  1173. top:=sub(y=0,deriv);
  1174. fact:=for i:=1:n product i;
  1175. return top/fact
  1176. end;
  1177. \end{verbatim}
  1178. \subsection{Compound Statements with GO TO}
  1179. It is possible to have more complicated structures inside the {\tt BEGIN
  1180. \ldots END} \ttindex{BEGIN \ldots END} brackets than indicated in the
  1181. previous example. That the individual lines of the program need not be
  1182. assignment \index{Assignment} statements, but could be almost any other
  1183. kind of statement or command, needs no explanation. For example,
  1184. conditional statements, and {\tt WHILE} \ttindex{WHILE} and {\tt REPEAT}
  1185. \ttindex{REPEAT} constructions, have an obvious role in defining more
  1186. intricate blocks.
  1187. If these structured constructs don't suffice, it is possible to use labels
  1188. \index{Label} and {\tt GO} {\tt TO}s\ttindex{GO TO} within a compound
  1189. statement \index{Compound statement}, and also to use
  1190. {\tt RETURN} \ttindex{RETURN} in places within the block other than just before
  1191. the {\tt END}. The following subsections discuss these matters in detail.
  1192. For many readers the following example, presenting one possible definition
  1193. of a process to calculate the factorial of {\tt N} for preassigned {\tt N}
  1194. will suffice:
  1195. {\it Example:}
  1196. \begin{verbatim}
  1197. begin scalar m;
  1198. m:=1;
  1199. l: if n=0 then return m;
  1200. m:=m*n;
  1201. n:=n-1;
  1202. go to l
  1203. end;
  1204. \end{verbatim}
  1205. \subsection{Labels and GO TO Statements}
  1206. \index{Label} \ttindex{GO TO}Within a {\tt BEGIN \ldots END} compound
  1207. statement it is possible to label statements, and transfer to them out of
  1208. sequence using {\tt GO} {\tt TO} statements. Only statements on the top
  1209. level inside compound statements can be labeled, not ones inside
  1210. subsidiary constructions like {\tt $<<$} \ldots {\tt $>>$}, {\tt IF} \ldots
  1211. {\tt THEN} \ldots , {\tt WHILE} \ldots {\tt DO} \ldots , etc.
  1212. Labels and {\tt GO TO} statements have the syntax:
  1213. \begin{verbatim}
  1214. <go to statement> ::= GO TO <label> | GOTO <label>
  1215. <label> ::= <identifier>
  1216. <labeled statement> ::= <label>:<statement>
  1217. \end{verbatim}
  1218. Note that statement names cannot be used as labels.
  1219. While {\tt GO TO} is an unconditional transfer, it is frequently used
  1220. in conditional statements such as
  1221. \begin{verbatim}
  1222. if x>5 then go to abcd;
  1223. \end{verbatim}
  1224. giving the effect of a conditional transfer.
  1225. Transfers using {\tt GO TO}s can only occur within the block in which the
  1226. {\tt GO TO} is used. In other words, you cannot transfer from an inner
  1227. block to an outer block using a {\tt GO TO}. However, if a group statement
  1228. occurs within a compound statement, it is possible to jump out of that group
  1229. statement to a point within the compound statement using a {\tt GO TO}.
  1230. \subsection{RETURN Statements}
  1231. The value corresponding to a {\tt BEGIN \ldots END} compound statement,
  1232. \ttindex{BEGIN \ldots END} such as a procedure body, is normally 0 ({\tt
  1233. NIL} in symbolic mode). By executing a {\tt RETURN}\ttindex{RETURN}
  1234. statement in the compound statement a different value can be returned.
  1235. After a {\tt RETURN} statement is executed no further statements within
  1236. the compound statement are.
  1237. {\tt Examples:}
  1238. \begin{verbatim}
  1239. return x+y;
  1240. return m;
  1241. return;
  1242. \end{verbatim}
  1243. Note that parentheses are not required around the {\tt x+y}, although they
  1244. are permitted. The last example is equivalent to {\tt return 0} or {\tt
  1245. return nil}, depending on whether the block is used as part of an
  1246. expression or not.
  1247. Since {\tt RETURN} \ttindex{RETURN} actually moves up only one
  1248. block\index{Block} level, in a sense the casual user is not expected to
  1249. understand, we tabulate some cautions concerning its use.
  1250. \begin{enumerate}
  1251. \item {\tt RETURN} can be used on the top level inside the compound
  1252. statement, i.e. as one of the statements bracketed together by the {\tt
  1253. BEGIN \ldots END}\ttindex{BEGIN \ldots END}
  1254. \item {\tt RETURN} can be used within a top level {\tt $<<$} \ldots {\tt
  1255. $>>$} construction within the compound statement. In this case, the {\tt
  1256. RETURN} transfers control out of both the group statement and the compound
  1257. statement.
  1258. \item {\tt RETURN} can be used within an {\tt IF} \ldots {\tt THEN} \ldots
  1259. {\tt ELSE} \ldots on the top level within the compound statement.
  1260. \end{enumerate}
  1261. NOTE: At present, there is no construct provided to permit early
  1262. termination of a {\tt FOR} \ttindex{FOR}, {\tt WHILE} \ttindex{WHILE},
  1263. or {\tt REPEAT} \ttindex{REPEAT} statement. In particular, the use of
  1264. {\tt RETURN} in such cases results in a syntax error. For example,
  1265. \begin{verbatim}
  1266. begin scalar y;
  1267. y := for i:=0:99 do if a(i)=x then return b(i);
  1268. ...
  1269. \end{verbatim}
  1270. will lead to an error.
  1271. \chapter{Commands and Declarations}
  1272. A command\index{Command} is an order to the system to do something. Some
  1273. commands cause visible results (such as calling for input or output);
  1274. others, usually called declarations\index{Declaration}, set options,
  1275. define properties of variables, or define procedures. Commands are
  1276. formally defined as a statement followed by a terminator
  1277. \begin{verbatim}
  1278. <command> ::= <statement> <terminator>
  1279. <terminator> ::= ;|$
  1280. \end{verbatim}
  1281. Some {\REDUCE} commands and declarations are described in the following
  1282. sub-sections.
  1283. \section{Array Declarations}
  1284. Array\ttindex{ARRAY} declarations in {\REDUCE} are similar to FORTRAN
  1285. dimension statements. For example:
  1286. \begin{verbatim}
  1287. array a(10),b(2,3,4);
  1288. \end{verbatim}
  1289. Array indices each range from 0 to the value declared. An element of an
  1290. array is referred to in standard FORTRAN notation, e.g. {\tt A(2)}.
  1291. We can also use an expression for defining an array bound, provided the
  1292. value of the expression is a positive integer. For example, if {\tt X} has the
  1293. value 10 and {\tt Y} the value 7 then
  1294. {\tt array c(5*x+y)} is the same as {\tt array c(57)}.
  1295. If an array is referenced by an index outside its range, an error occurs.
  1296. If the array is to be one-dimensional, and the bound a number or a variable
  1297. (not a more general expression) the parentheses may be omitted:
  1298. \begin{verbatim}
  1299. array a 10, c 57;
  1300. \end{verbatim}
  1301. The operator {\tt LENGTH} \ttindex{LENGTH} (q.v.) applied to an array name
  1302. returns a list of its dimensions.
  1303. All array elements are initialized to 0 at declaration time. In other words,
  1304. an array element has an {\em instant evaluation}\index{Instant evaluation}
  1305. property and cannot stand for itself. If this is required, then an
  1306. operator (q.v.) should be used instead.
  1307. Array declarations can appear anywhere in a program. Once a symbol is
  1308. declared to name an array, it can not also be used as a variable, or to
  1309. name an operator or a procedure. It can however be re-declared to be an
  1310. array, and its size may be changed at that time. An array name can also
  1311. continue to be used as a parameter in a procedure, or a local variable in
  1312. a compound statement, although this use is not recommended, since it can
  1313. lead to user confusion over the type of the variable.
  1314. Arrays once declared are global in scope, and so can then be referenced
  1315. anywhere in the program. In other words, unlike arrays in most other
  1316. languages, a declaration within a block (or a procedure) does not limit
  1317. the scope of the array to that block, nor does the array go away on
  1318. exiting the block (use {\tt CLEAR} instead for this purpose).
  1319. \section{Mode Handling Declarations}\index{Mode}
  1320. The {\tt ON} \ttindex{ON} and {\tt OFF} \ttindex{OFF} declarations are
  1321. available to the user for controlling various system options. Each option
  1322. is represented by a ``switch"\index{Switch} name. {\tt ON} and {\tt OFF}
  1323. take a list of switch names as argument and turn them on and off
  1324. respectively, e.g.,
  1325. \begin{verbatim}
  1326. on time;
  1327. \end{verbatim}
  1328. causes the system to print a message after each command giving the elapsed
  1329. CPU time since the last command, or since {\tt TIME} \ttindex{TIME} was
  1330. last turned off, or the session began. Another useful switch with
  1331. interactive use is {\tt DEMO}, which causes the system to pause after each
  1332. command in a file until a RETURN is typed on the terminal. This
  1333. enables a user to set up a demonstration file and step through it command
  1334. by command.
  1335. As with most declarations, arguments to {\tt ON} and {\tt OFF} may be
  1336. strung together separated by commas. For example,
  1337. \begin{verbatim}
  1338. off time,demo;
  1339. \end{verbatim}
  1340. will turn off both the time messages and the demonstration switch.
  1341. We note here that while most {\tt ON} and {\tt OFF} commands are obeyed
  1342. almost instantaneously, some trigger time-consuming actions such as
  1343. reading in necessary modules from secondary storage.
  1344. A diagnostic message is printed if {\tt ON} \ttindex{ON} or {\tt OFF}
  1345. \ttindex{OFF} are used with a switch that is not known to the system. For
  1346. example, if you misspell {\tt DEMO} and type
  1347. \begin{verbatim}
  1348. on demq;
  1349. \end{verbatim}
  1350. you will get the message\index{Switch}
  1351. \begin{verbatim}
  1352. ***** DEMQ not defined as switch.
  1353. \end{verbatim}
  1354. \section{END}
  1355. The identifier {\tt END} \ttindex{END} has three separate uses.
  1356. 1) Its use in a {\tt BEGIN \ldots END} bracket has been discussed in
  1357. connection with compound statements (q.v.).
  1358. 2) Files to be read using {\tt IN} should end with an extra {\tt END};
  1359. command. The reason for this is explained in the section on the {\tt IN}
  1360. command (q.v.). This use of {\tt END} does not allow an immediately
  1361. preceding {\tt END} (such as the {\tt END} of a procedure definition), so
  1362. we advise using {\tt ;END;} there.
  1363. 3) A command {\tt END}; entered at the top level transfers control to the
  1364. Lisp system\index{Lisp} which is the host of the {\REDUCE} system. All
  1365. files opened by {\tt IN} or {\tt OUT} statements are closed in the
  1366. process. {\tt END;} does not stop {\REDUCE}. Those familiar with Lisp can
  1367. experiment with typing identifiers and ({\tt <function name> <argument
  1368. list>}) lists to see the value returned by Lisp. (No terminators, other
  1369. than the RETURN key, should be used.) The data structures created during
  1370. the {\REDUCE} run are accessible.
  1371. You remain in this Lisp mode until you explicitly re-enter {\REDUCE} by
  1372. saying {\tt (BEGIN)} at the Lisp top level. In most systems, a Lisp error
  1373. also returns you to {\REDUCE} (exceptions are noted in the operating
  1374. instructions for your particular {\REDUCE} implementation). In either
  1375. case, you will return to {\REDUCE} in the same mode, algebraic or
  1376. symbolic, that you were in before the {\tt END};. If you are in
  1377. Lisp mode\index{Lisp mode} by mistake -- which is usually the case,
  1378. the result of typing more {\tt END}s\ttindex{END} than {\tt BEGIN}s --
  1379. type {\tt (BEGIN)} in parentheses and hit the RETURN key.
  1380. \section{BYE Command}\ttindex{BYE}
  1381. The command {\tt BYE}; stops the execution of {\REDUCE}, closes all open
  1382. output files, and returns you to the computer system monitor program.
  1383. Where the implementation permits it, your {\REDUCE} session is destroyed.
  1384. If you wish to return later to that session, use {\tt QUIT}; instead.
  1385. \section{QUIT Command}\ttindex{QUIT}
  1386. The command {\tt QUIT}; stops the execution of {\REDUCE} and returns you to
  1387. the computer system monitor program. Where the implementation permits it,
  1388. your {\REDUCE} session is retained so that you can use it again later.
  1389. Please refer to the system-specific user guide to see if this option is
  1390. available in your system. If you do not wish to reenter the {\REDUCE}
  1391. session, use {\tt BYE}; instead.
  1392. \section{SHOWTIME Command}\ttindex{SHOWTIME}
  1393. {\tt SHOWTIME}; prints the elapsed time since the last call of this
  1394. command or, on its first call, since the current {\REDUCE} session began.
  1395. The time is normally given in milliseconds and gives the time as measured
  1396. by a system clock. The operations covered by this measure are system
  1397. dependent.
  1398. \section{DEFINE Command}
  1399. The command {\tt DEFINE} \ttindex{DEFINE} allows a user to supply a new name for
  1400. any identifier or replace it by any well-formed expression. Its argument
  1401. is a list of expressions of the form
  1402. \begin{verbatim}
  1403. <identifier> = <number>|<identifier>|<operator>|
  1404. <reserved word>|<expression>
  1405. \end{verbatim}
  1406. {\it Example:}
  1407. \begin{verbatim}
  1408. define be==,x=y+z;
  1409. \end{verbatim}
  1410. means that {\tt BE} will be interpreted as an equal sign, and {\tt X}
  1411. as the expression {\tt y+z} from then on. This renaming is done at parse
  1412. time, and therefore takes precedence over any other replacement declared
  1413. for the same identifier. It stays in effect until the end of the
  1414. {\REDUCE} run.
  1415. The identifiers {\tt ALGEBRAIC} and {\tt SYMBOLIC} have properties which
  1416. prevent {\tt DEFINE} \ttindex{DEFINE} from being used on them. To define
  1417. {\tt ALG} to be a synonym for {\tt ALGEBRAIC}, the more complicated
  1418. construction
  1419. \begin{verbatim}
  1420. put('alg,'newnam,'algebraic);
  1421. \end{verbatim}
  1422. must be used.
  1423. \chapter{Built-in Prefix Operators}
  1424. In the following subsections are descriptions of the most useful prefix
  1425. \index{Prefix}
  1426. operators built into {\REDUCE} that are not defined in other sections (such
  1427. as substitution operators). Some are fully defined internally as
  1428. procedures; others are more nearly abstract operators, with only some of
  1429. their properties known to the system.
  1430. In many cases, an operator is described by a prototypical header line as
  1431. follows. Each formal parameter is given a name and followed by its allowed
  1432. type. The names of classes referred to in the definition are printed in
  1433. lower case, and parameter names in upper case. If a parameter type is not
  1434. commonly used, it may be a specific set enclosed in brackets {\tt \{} \ldots
  1435. {\tt \}}.
  1436. Operators which accept formal parameter lists of arbitrary length have the
  1437. parameter and type class enclosed in square brackets indicating that zero
  1438. or more occurrences of that argument are permitted. Optional parameters
  1439. and their type classes are enclosed in angle brackets.
  1440. \section{Numerical Operators}\index{Numerical operator}
  1441. {\REDUCE} includes a number of functions that are analogs of those found
  1442. in most numerical systems. With numerical arguments, such functions
  1443. return the expected result. However, they may also be called with
  1444. non-numeric arguments. In such cases, except where noted, the system
  1445. attempts to simplify the expression as far as it can. In such cases, a
  1446. residual expression involving the original operator usually remains.
  1447. These operators are as follows:
  1448. \subsection{ABS}
  1449. {\tt ABS} \ttindex{ABS} returns the absolute value
  1450. of its single argument, if that argument has a numerical value.
  1451. A non-numeric argument is returned as an absolute value, with an overall
  1452. numeric coefficient taken outside the absolute value operator. For example:
  1453. \begin{verbatim}
  1454. abs(-3/4) -> 3/4
  1455. abs(2a) -> 2*ABS(A)
  1456. abs(i) -> 1
  1457. abs(-x) -> ABS(X)
  1458. \end{verbatim}
  1459. \subsection{CEILING} \ttindex{CEILING}
  1460. This operator returns the ceiling (i.e., the least integer greater than
  1461. the given argument) if its single argument has a numerical value. A
  1462. non-numeric argument is returned as an expression in the original
  1463. operator. For example:
  1464. \begin{verbatim}
  1465. ceiling(-5/4) -> -1
  1466. ceiling(-a) -> CEILING(-A)
  1467. \end{verbatim}
  1468. \subsection{CONJ} \ttindex{CONJ}
  1469. This returns the complex conjugate
  1470. of an expression, if that argument has an numerical value. A
  1471. non-numeric argument is returned as an expression in the original
  1472. operator. For example:
  1473. \begin{verbatim}
  1474. conj(1+i) -> 1-I
  1475. conj(a+i*b) -> REPART(A) - REPART(B)*I - IMPART(A)*I
  1476. - IMPART(B)
  1477. \end{verbatim}
  1478. \subsection{FACTORIAL} \ttindex{FACTORIAL}
  1479. If the single argument of {\tt FACTORIAL} evaluates to a non-negative
  1480. integer, its factorial is returned. Otherwise an expression involving
  1481. {\tt FACTORIAL} is returned. For example:
  1482. \begin{verbatim}
  1483. factorial(5) -> 120
  1484. factorial(a) -> FACTORIAL(A)
  1485. \end{verbatim}
  1486. \subsection{FIX} \ttindex{FIX}
  1487. This operator returns the fixed value (i.e., the integer part of
  1488. the given argument) if its single argument has a numerical value. A
  1489. non-numeric argument is returned as an expression in the original
  1490. operator. For example:
  1491. \begin{verbatim}
  1492. fix(-5/4) -> -1
  1493. fix(a) -> FIX(A)
  1494. \end{verbatim}
  1495. \subsection{FLOOR} \ttindex{FLOOR}
  1496. This operator returns the floor (i.e., the greatest integer less than
  1497. the given argument) if its single argument has a numerical value. A
  1498. non-numeric argument is returned as an expression in the original
  1499. operator. For example:
  1500. \begin{verbatim}
  1501. floor(-5/4) -> -2
  1502. floor(a) -> FLOOR(A)
  1503. \end{verbatim}
  1504. \subsection{IMPART} \ttindex{IMPART}
  1505. This operator returns the imaginary part of an expression, if that argument
  1506. has an numerical value. A non-numeric argument is returned as an expression
  1507. in the original operator. For example:
  1508. \begin{verbatim}
  1509. impart(1+i) -> 1
  1510. impart(a+i*b) -> REPART(B) + IMPART(A)
  1511. \end{verbatim}
  1512. \subsection{MAX/MIN}
  1513. {\tt MAX} and {\tt MIN} \ttindex{MAX} \ttindex{MIN} can take an arbitrary
  1514. number of expressions as their arguments. If all arguments evaluate to
  1515. numerical values, the maximum or minimum of the argument list is returned.
  1516. If any argument is non-numeric, an appropriately reduced expression is
  1517. returned. For example:
  1518. \begin{verbatim}
  1519. max(2,-3,4,5) -> 5
  1520. min(2,-2) -> -2.
  1521. max(a,2,3) -> MAX(A,3)
  1522. min(x) -> X
  1523. \end{verbatim}
  1524. {\tt MAX} or {\tt MIN} of an empty list returns 0.
  1525. \subsection{NEXTPRIME} \ttindex{NEXTPRIME}
  1526. {\tt NEXTPRIME} returns the next prime greater than its integer argument.
  1527. A type error occurs in this case if the value of the argument is not an
  1528. integer. For example:
  1529. \begin{verbatim}
  1530. nextprime(5) -> 7
  1531. nextprime(-2) -> 2
  1532. nextprime(-7) -> -5
  1533. \end{verbatim}
  1534. whereas {\tt nextprime(a)} gives a type error.
  1535. \subsection{REPART} \ttindex{REPART}
  1536. This returns the real part of an expression, if that argument has an
  1537. numerical value. A non-numeric argument is returned as an expression in the
  1538. original operator. For example:
  1539. \begin{verbatim}
  1540. repart(1+i) -> 1
  1541. repart(a+i*b) -> REPART(A) - IMPART(B)
  1542. \end{verbatim}
  1543. \subsection{ROUND} \ttindex{ROUND}
  1544. This operator returns the rounded value (i.e, the nearest integer) of its
  1545. single argument if that argument has a numerical value. A non-numeric
  1546. argument is returned as an expression in the original operator. For
  1547. example:
  1548. \begin{verbatim}
  1549. round(-5/4) -> -1
  1550. round(a) -> ROUND(A)
  1551. \end{verbatim}
  1552. \section{Mathematical Functions}
  1553. {\REDUCE} knows that the following represent mathematical functions
  1554. \index{Mathematical function} that can
  1555. take arbitrary scalar expressions as their single argument:
  1556. \begin{verbatim}
  1557. ACOS ACOSD ACOSH ACOT ACOTD ACOTH ACSC ACSCD ACSCH
  1558. ASEC ASECD ASECH ASIN ASIND ASINH ATAN ATAND ATANH
  1559. ATAN2 ATAN2D CBRT COS COSD COSH COT COTD COTH CSC
  1560. CSCD CSCH DILOG EXP EXPINT HYPOT LN LOG LOGB LOG10
  1561. SEC SECD SECH SIN SIND SINH SQRT TAN TAND TANH
  1562. \end{verbatim}
  1563. \ttindex{ACOS} \ttindex{ACOSD} \ttindex{ACOSH} \ttindex{ACOT} \ttindex{ACOTD}
  1564. \ttindex{ACOTH} \ttindex{ACSC} \ttindex{ACSCD} \ttindex{ACSCH} \ttindex{ASEC}
  1565. \ttindex{ASECD} \ttindex{ASECH} \ttindex{ASIN} \ttindex{ASIND}
  1566. \ttindex{ASINH} \ttindex{ATAN} \ttindex{ATAND} \ttindex{ATANH}
  1567. \ttindex{ATAN2} \ttindex{ATAN2D} \ttindex{CBRT} \ttindex{COS} \ttindex{COSD}
  1568. \ttindex{COSH} \ttindex{COT} \ttindex{COTD} \ttindex{COTH} \ttindex{CSC}
  1569. \ttindex{CSCD} \ttindex{CSCH} \ttindex{DILOG} \ttindex{EXP} \ttindex{EXPINT}
  1570. \ttindex{HYPOT} \ttindex{LN} \ttindex{LOG} \ttindex{LOGB} \ttindex{LOG10}
  1571. \ttindex{SEC} \ttindex{SECD} \ttindex{SECH} \ttindex{SIN} \ttindex{SIND}
  1572. \ttindex{SINH} \ttindex{SQRT} \ttindex{TAN} \ttindex{TAND} \ttindex{TANH}
  1573. where {\tt LOG} is the natural logarithm (and equivalent to {\tt LN}),
  1574. and {\tt LOGB} has two arguments of which the second is the logarithmic base.
  1575. However, {\REDUCE} only knows the most elementary identities and properties
  1576. of these functions (except in {\tt on rounded} mode (q.v.)). For example:
  1577. \begin{verbatim}
  1578. cos(-x) = cos(x) sin(-x) = - sin (x)
  1579. cos(n*pi) = (-1)^n sin(n*pi) = 0
  1580. log(e) = 1 e^(i*pi/2) = i
  1581. log(1) = 0 e^(i*pi) = -1
  1582. log(e^x) = x e^(3*i*pi/2) = -i
  1583. \end{verbatim}
  1584. The derivatives of these functions are also known to the system.
  1585. % With the default system switch settings, the argument of a square root is
  1586. % first simplified, and any divisors of the expression that are perfect
  1587. % squares taken outside the square root argument. The remaining expression
  1588. % is left under the square root. However, if the switch {\tt REDUCED}
  1589. % \ttindex{REDUCED} is on,
  1590. % multiplicative factors in the argument of the square root are also
  1591. % separated, becoming individual square roots. Thus with {\tt REDUCED} off,
  1592. % the expression
  1593. % \begin{verbatim}
  1594. % sqrt(-8*a^2*b)
  1595. % \end{verbatim}
  1596. % would become
  1597. % \begin{verbatim}
  1598. % 2*a*sqrt(-2*b) ,
  1599. % \end{verbatim}
  1600. % whereas with {\tt REDUCED} on, it would become
  1601. % \begin{verbatim}
  1602. % 2*a*i*sqrt(2)*sqrt(b) .
  1603. % \end{verbatim}
  1604. % The switch {\tt REDUCED} \ttindex{REDUCED} also applies to other rational
  1605. % powers in addition to square roots.
  1606. % Note that such simplifications can cause trouble if {\tt A} is eventually
  1607. % given a value which is a negative number. If it is important that the
  1608. % positive property of the square root always be preserved, the switch
  1609. % {\tt PRECISE} \ttindex{PRECISE} can be set on. This causes any
  1610. % non-numerical factors taken out of surds to be represented by their
  1611. % absolute value form.
  1612. % With both {\tt REDUCED} and {\tt PRECISE} on then, the above example would
  1613. % become
  1614. % \begin{verbatim}
  1615. % 2*i*abs(a)*sqrt(2)*sqrt(b) .
  1616. % \end{verbatim}
  1617. The user can add further rules for the reduction of expressions involving
  1618. these operators by using the {\tt LET} \ttindex{LET} command (q.v.).
  1619. The square root function can be input using the name {\tt SQRT}, or the
  1620. power operation {\tt \^{ }(1/2)}. On output, unsimplified square roots
  1621. are normally represented by the operator {\tt SQRT} rather than a
  1622. fractional power.
  1623. The statement that {\REDUCE} knows very little about these functions
  1624. applies only in the mathematically exact {\tt off rounded} mode. If
  1625. {\tt ROUNDED} \ttindex{ROUNDED} is on, any of the functions
  1626. \begin{verbatim}
  1627. ACOS ACOSD ACOSH ACOT ACOTD ACOTH ACSC ACSCD ACSCH
  1628. ASEC ASECD ASECH ASIN ASIND ASINH ATAN ATAND ATANH
  1629. ATAN2 ATAN2D CBRT COS COSD COSH COT COTD COTH CSC
  1630. CSCD CSCH EXP HYPOT LN LOG LOGB LOG10 SEC SECD SECH
  1631. SIN SIND SINH SQRT TAN TAND TANH
  1632. \end{verbatim}
  1633. \ttindex{ACOS} \ttindex{ACOSD} \ttindex{ACOSH} \ttindex{ACOT} \ttindex{ACOTD}
  1634. \ttindex{ACOTH} \ttindex{ACSC} \ttindex{ACSCD} \ttindex{ACSCH} \ttindex{ASEC}
  1635. \ttindex{ASECD} \ttindex{ASECH} \ttindex{ASIN} \ttindex{ASIND}
  1636. \ttindex{ASINH} \ttindex{ATAN} \ttindex{ATAND} \ttindex{ATANH}
  1637. \ttindex{ATAN2} \ttindex{ATAN2D} \ttindex{CBRT} \ttindex{COS} \ttindex{COSD}
  1638. \ttindex{COSH} \ttindex{COT} \ttindex{COTD} \ttindex{COTH} \ttindex{CSC}
  1639. \ttindex{CSCD} \ttindex{CSCH} \ttindex{EXP} \ttindex{HYPOT} \ttindex{LN}
  1640. \ttindex{LOG} \ttindex{LOGB} \ttindex{LOG10} \ttindex{SEC} \ttindex{SECD}
  1641. \ttindex{SECH} \ttindex{SIN} \ttindex{SIND} \ttindex{SINH} \ttindex{SQRT}
  1642. \ttindex{TAN} \ttindex{TAND} \ttindex{TANH}
  1643. when given a numeric argument has its value calculated to the current
  1644. degree of floating point precision. In addition, real (non-integer
  1645. valued) powers of numbers will also be evaluated.
  1646. If the {\tt COMPLEX} switch is turned on in addition to {\tt ROUNDED},
  1647. these functions will also calculate a real or complex result, again to
  1648. the current degree of floating point precision,
  1649. if given complex arguments. For example, with {\tt on rounded,complex;}
  1650. \begin{verbatim}
  1651. 2.3^(5.6i) -> -0.0480793490914 - 0.998843519372*I
  1652. cos(2+3i) -> -4.18962569097 - 9.10922789376*I
  1653. \end{verbatim}
  1654. \section{DF Operator}
  1655. The operator {\tt DF} \ttindex{DF} is used to represent partial
  1656. differentiation \index{Differentiation} with respect
  1657. to one or more variables. It is used with the syntax:
  1658. \begin{verbatim}
  1659. DF(EXPRN:algebraic[,VAR:kernel<,NUM:integer>]):algebraic.
  1660. \end{verbatim}
  1661. The first argument is the expression to be differentiated. The remaining
  1662. arguments specify the differentiation variables and the number of times
  1663. they are applied.
  1664. The number {\tt NUM} may be omitted if it is 1. For example,
  1665. \begin{quote}
  1666. \begin{tabbing}
  1667. {\tt df(y,x)} \hspace{1in} \= = $\partial y/\partial x$ \\
  1668. {\tt df(y,x,2)} \> = $\partial^{2}y/\partial x^{2}$ \\
  1669. {\tt df(y,x1,2,x2,x3,2)} \> = $\partial^{5}y/\partial x_{1}^{2} \
  1670. \partial x_{2}\partial x_{3}^{2}.$
  1671. \end{tabbing}
  1672. \end{quote}
  1673. The evaluation of {\tt df(y,x)} proceeds as follows: first, the values of
  1674. {\tt Y} and {\tt X} are found. Let us assume that {\tt X} has no assigned
  1675. value, so its value is {\tt X}. Each term or other part of the value of
  1676. {\tt Y} which contains the variable {\tt X} is differentiated by the
  1677. standard rules. If {\tt Z} is another variable, not {\tt X} itself, then
  1678. its derivative with respect to {\tt X} is taken to be 0, unless {\tt Z}
  1679. has previously been declared to {\tt DEPEND} (q.v.) on {\tt X}, in which
  1680. case the derivative is reported as the symbol {\tt df(z,x)}.
  1681. \subsection{Adding Differentiation Rules}
  1682. The {\tt LET} \ttindex{LET} statement (q.v.) can be used to introduce
  1683. rules for differentiation of user-defined operators. Its general form is
  1684. \begin{verbatim}
  1685. FOR ALL <var1>,...,<varn>
  1686. LET DF(<operator><varlist>,<vari>)=<expression>
  1687. \end{verbatim}
  1688. where {\tt <varlist>} ::= ({\tt <var1>},\dots,{\tt <varn>}), and
  1689. {\tt <var1>},...,{\tt <varn>} are the dummy variable arguments of
  1690. {\tt <operator>}.
  1691. An analogous form applies to infix operators.
  1692. {\it Examples:}
  1693. \begin{verbatim}
  1694. for all x let df(tan x,x)= 1 + tan(x)^2;
  1695. \end{verbatim}
  1696. (This is how the tan differentiation rule appears in the {\REDUCE}
  1697. source.)
  1698. \begin{verbatim}
  1699. for all x,y let df(f(x,y),x)=2*f(x,y),
  1700. df(f(x,y),y)=x*f(x,y);
  1701. \end{verbatim}
  1702. Notice that all dummy arguments of the relevant operator must be declared
  1703. arbitrary by the {\tt FOR ALL} command, and that rules may be supplied for
  1704. operators with any number of arguments. If no differentiation rule
  1705. appears for an argument in an operator, the differentiation routines will
  1706. return as result an expression in terms of {\tt DF} \ttindex{DF}. For
  1707. example, if the rule for the differentiation with respect to the second
  1708. argument of {\tt F} is not supplied, the evaluation of {\tt df(f(x,z),z)}
  1709. would leave this expression unchanged. (No {\tt DEPEND} declaration (q.v.)
  1710. is needed here, since {\tt f(x,z)} obviously ``depends on" {\tt Z}.)
  1711. Once such a rule has been defined for a given operator, any future
  1712. differentiation\index{Differentiation} rules for that operator must be
  1713. defined with the same number of arguments for that operator, otherwise we
  1714. get the error message
  1715. \begin{verbatim}
  1716. Incompatible DF rule argument length for <operator>
  1717. \end{verbatim}
  1718. \section{INT Operator}
  1719. {\tt INT} \ttindex{INT} is an operator in {\REDUCE} for indefinite
  1720. integration \index{Integration} \index{Indefinite integration} using a
  1721. combination of the Risch-Norman algorithm and pattern matching. It is
  1722. used with the syntax:
  1723. \begin{verbatim}
  1724. INT(EXPRN:algebraic,VAR:kernel):algebraic.
  1725. \end{verbatim}
  1726. This will return correctly the indefinite integral for expressions comprising
  1727. polynomials, log functions, exponential functions and tan and atan. The
  1728. arbitrary constant is not represented. If the integral cannot be done in
  1729. closed terms, it returns a formal integral for the answer in one of two ways:
  1730. \begin{enumerate}
  1731. \item It returns the input, {\tt INT(\ldots,\ldots)} unchanged.
  1732. \item It returns an expression involving {\tt INT}s of some
  1733. other functions (sometimes more complicated than
  1734. the original one, unfortunately).
  1735. \end{enumerate}
  1736. Rational functions can be integrated when the denominator is factorizable
  1737. by the program. In addition it will attempt to integrate expressions
  1738. involving error functions, dilogarithms and other trigonometric
  1739. expressions. In these cases it might not always succeed in finding the
  1740. solution, even if one exists.
  1741. {\it Examples:}
  1742. \begin{verbatim}
  1743. int(log(x),x) -> X*(LOG(X) - 1),
  1744. int(e^x,x) -> E**X.
  1745. \end{verbatim}
  1746. The program checks that the variable supplied is a variable and gives an
  1747. error if it is not.
  1748. \subsection{Options}
  1749. The switch {\tt TRINT} when on will trace the operation of the algorithm. It
  1750. produces a great deal of output in a somewhat illegible form, and is not
  1751. of much interest to the general user. It is normally off.
  1752. If the switch {\tt FAILHARD} is on the algorithm will terminate with an
  1753. error if the integral cannot be done in closed terms, rather than return a
  1754. formal integration form. {\tt FAILHARD} is normally off.
  1755. The switch {\tt NOLNR} suppresses the use of the linear properties of
  1756. integration in cases when the integral cannot be found in closed terms.
  1757. It is normally off.
  1758. \subsection{Advanced Use}
  1759. If a function appears in the integrand which is not one of the functions
  1760. {\tt EXP, ERF, TAN, ATAN, LOG, DILOG} then the algorithm will make an attempt to
  1761. integrate the argument if it can, differentiate it and reach a known
  1762. function. However the answer cannot be guaranteed in this case. If a
  1763. function is known to be algebraically independent of this set it can be
  1764. flagged transcendental by
  1765. \begin{verbatim}
  1766. flag('(trilog),'transcendental);
  1767. \end{verbatim}
  1768. in which case this function will be added to the permitted field
  1769. descriptors for a genuine decision procedure. If this is done the user is
  1770. responsible for the mathematical correctness of his actions.
  1771. The standard version does not deal with algebraic extensions. Thus
  1772. integration of expressions involving square roots and other like things
  1773. can lead to trouble. A contributed package that supports integration of
  1774. functions involving square roots is available, however. This is
  1775. distributed with most versions of {\REDUCE}.
  1776. \subsection{References}
  1777. A. C. Norman \& P. M. A. Moore, ``Implementing the New Risch
  1778. Algorithm", Proc. 4th International Symposium on Advanced
  1779. Comp. Methods in Theor. Phys., CNRS, Marseilles, 1977.
  1780. S. J. Harrington, ``A New Symbolic Integration System in Reduce",
  1781. Comp. Journ. 22 (1979) 2.
  1782. A. C. Norman \& J. H. Davenport, ``Symbolic Integration --- The Dust
  1783. Settles?", Proc. EUROSAM 79, Lecture Notes in Computer
  1784. Science 72, Springer-Verlag, Berlin Heidelberg New York
  1785. (1979) 398-407.
  1786. %\subsection{Definite Integration} \index{Definite integration}
  1787. %
  1788. %If {\tt INT} is used with the syntax
  1789. %
  1790. %\begin{verbatim}
  1791. % INT(EXPRN:algebraic,VAR:kernel,LOWER:algebraic,UPPER:algebraic):algebraic.
  1792. %\end{verbatim}
  1793. %
  1794. %The definite integral of {\tt EXPRN} with respect to {\tt VAR} is
  1795. %calculated between the limits {\tt LOWER} and {\tt UPPER}. In the present
  1796. %system, this is calculated either by pattern matching, or by first finding
  1797. %the indefinite integral, and then substituting the limits into this.
  1798. \section{LENGTH Operator}
  1799. {\tt LENGTH} \ttindex{LENGTH} is a generic operator for finding the
  1800. length of various objects in the system. The meaning depends on the type
  1801. of the object. In particular, the length of an algebraic expression is
  1802. the number of additive top-level terms its expanded representation.
  1803. {\it Examples:}
  1804. \begin{verbatim}
  1805. length(a+b) -> 2
  1806. length(2) -> 1.
  1807. \end{verbatim}
  1808. Other objects that support a length operator include arrays, lists and
  1809. matrices. The explicit meaning in these cases is included in the description
  1810. of these objects.
  1811. \section{MKID Operator}\ttindex{MKID}
  1812. In many applications, it is useful to create a set of identifiers for
  1813. naming objects in a consistent manner. In most cases, it is sufficient to
  1814. create such names from two components. The operator {\tt MKID} is provided
  1815. for this purpose. Its syntax is:
  1816. \begin{verbatim}
  1817. MKID(U:id,V:id|non-negative integer):id
  1818. \end{verbatim}
  1819. for example
  1820. \begin{verbatim}
  1821. mkid(a,3) -> A3
  1822. mkid(apple,s) -> APPLES
  1823. \end{verbatim}
  1824. while {\tt mkid(a+b,2)} gives an error.
  1825. \section{PF Operator} \ttindex{PF}
  1826. {\tt PF(<exp>,<var>)} transforms the expression {\tt <exp>} into a list of
  1827. partial fractions with respect to the main variable, {\tt <var>}. {\tt PF}
  1828. does a complete partial fraction decomposition, and as the algorithms used
  1829. are fairly unsophisticated (factorization and the extended Euclidean
  1830. algorithm), the code may be unacceptably slow in complicated cases.
  1831. {\it Example:}
  1832. Given {\tt 2/((x+1)\^{ }2*(x+2))} in the workspace,
  1833. {\tt pf(ws,x);} gives the result
  1834. \begin{verbatim}
  1835. 2 - 2 2
  1836. {-------,-------,--------------} .
  1837. X + 2 X + 1 2
  1838. X + 2*X + 1
  1839. \end{verbatim}
  1840. If you want the denominators in factored form, use {\tt off exp;}.
  1841. Thus, with {\tt 2/((x+1)\^{ }2*(x+2))} in the workspace, the commands
  1842. {\tt off exp; pf(ws,x);} give the result
  1843. \begin{verbatim}
  1844. 2 - 2 2
  1845. {-------,-------,----------} .
  1846. X + 2 X + 1 2
  1847. (X + 1)
  1848. \end{verbatim}
  1849. To recombine the terms, {\tt FOR EACH \ldots SUM} can be used. So with
  1850. the above list in the workspace, {\tt for each j in ws sum j;} returns the
  1851. result
  1852. \begin{verbatim}
  1853. 2
  1854. ------------------
  1855. 2
  1856. (X + 2)*(X + 1)
  1857. \end{verbatim}
  1858. Alternatively, one can use the operations on lists to extract any desired
  1859. term.
  1860. \section{SOLVE Operator}\ttindex{SOLVE}
  1861. SOLVE is an operator for solving one or more simultaneous algebraic
  1862. equations. It is used with the syntax:
  1863. \begin{verbatim}
  1864. SOLVE(EXPRN:algebraic[,VAR:kernel|,VARLIST:list of kernels])
  1865. :integer.
  1866. \end{verbatim}
  1867. {\tt EXPRN} is of the form {\tt <expression>} or
  1868. \{ {\tt <expression1>},{\tt <expression2>}, \dots \}. Each expression is an
  1869. algebraic equation, or is the difference of the two sides of the equation.
  1870. The second argument is either a kernel or a list of kernels representing
  1871. the unknowns in the system. This argument may be omitted if the number of
  1872. distinct top-level kernels equals the number of unknowns, in which case
  1873. these kernels are presumed to be the unknowns.
  1874. Non-linear equations are solved using the Groebner basis package (q.v.).
  1875. \index{Groebner} Users should note that this can be quite a
  1876. time consuming process.
  1877. {\it Examples:}
  1878. \begin{verbatim}
  1879. solve(log(sin(x+3))^5 = 8,x);
  1880. solve(a*log(sin(x+3))^5 - b, sin(x+3));
  1881. solve({a*x+y=3,y=-2},{x,y});
  1882. \end{verbatim}
  1883. {\tt SOLVE} returns a list of solutions. If there is one unknown, each
  1884. solution is an equation for the unknown. If a complete solution was
  1885. found, the unknown will appear by itself on the left-hand side of the
  1886. equation. On the other hand, if the solve package could not find a
  1887. solution, the ``solution" will be an equation for the unknown. If there
  1888. are several unknowns, each solution will be a list of equations for the
  1889. unknowns. For example,
  1890. \begin{verbatim}
  1891. solve(x^2=1,x); -> {X=-1,X=1}
  1892. solve(x^7-x^6+x^2=1,x) -> {X**6+X+1=0,X=1}
  1893. solve({x+3y=7,y-x=1},{x,y}) -> {{X=1,Y=2}}.
  1894. \end{verbatim}
  1895. Solution multiplicities are stored in the global variable {\tt
  1896. MULTIPLICITIES!*} rather than the solution list. The value of this
  1897. variable is a list of the multiplicities of the solutions for the last
  1898. call of {\tt SOLVE}. \ttindex{SOLVE} For example,
  1899. \begin{verbatim}
  1900. solve(x^2=2x-1,x); multiplicities!*;
  1901. \end{verbatim}
  1902. gives the results
  1903. \begin{verbatim}
  1904. {X=1}
  1905. {2}
  1906. \end{verbatim}
  1907. If you want the multiplicities explicitly displayed, the switch
  1908. {\tt MULTIPLICITIES} \ttindex{MULTIPLICITIES} can be turned on. For example
  1909. \begin{verbatim}
  1910. on multiplicities; solve(x^2=2x-1,x);
  1911. \end{verbatim}
  1912. yields the result
  1913. \begin{verbatim}
  1914. {X=1,X=1}
  1915. \end{verbatim}
  1916. For one equation, {\tt SOLVE} \ttindex{SOLVE} recursively uses
  1917. factorization and decomposition, together with the known inverses of
  1918. {\tt LOG}, {\tt SIN}, {\tt COS}, {\tt \^{ }}, {\tt ACOS}, {\tt ASIN}, and
  1919. linear, quadratic, cubic, quartic, or binomial factors. For
  1920. simultaneous linear equations, the built-in matrix equation solvers are
  1921. used, {\tt SOLVE} merely providing a convenient form of input for small
  1922. or sparse systems.
  1923. \subsection{Options}
  1924. If {\tt SOLVESINGULAR} \ttindex{SOLVESINGULAR} is on (the default setting),
  1925. degenerate systems such as {\tt x+y=0,2x+2y=0} will be solved by
  1926. introducing appropriate arbitrary constants.
  1927. The consistent singular equation 0=0 or equations involving functions with
  1928. multiple inverses may introduce unique new indeterminant kernels
  1929. {\tt ARBCOMPLEX(j)}, {\tt ARBREAL(j)}, or {\tt ARBINT(j)}, ($j$=1,2,...),
  1930. representing arbitrary complex, real or integer numbers respectively. To
  1931. automatically select the principal branches, do {\tt off allbranch;} .
  1932. \ttindex{ALLBRANCH}
  1933. To suppress solutions of consistent singular equations do
  1934. {\tt OFF SOLVESINGULAR}.
  1935. To incorporate additional inverse functions do, for example:
  1936. \begin{verbatim}
  1937. put('sinh,'inverse,'asinh);
  1938. put('asinh,'inverse,'sinh);
  1939. \end{verbatim}
  1940. together with any desired simplification rules such as
  1941. \begin{verbatim}
  1942. for all x let sinh(asinh(x))=x, asinh(sinh(x))=x;
  1943. \end{verbatim}
  1944. For completeness, functions with non-unique inverses should be treated as
  1945. {\tt \^{ }}, {\tt SIN}, and {\tt COS} are in the {\tt SOLVE}
  1946. \ttindex{SOLVE} module source.
  1947. Arguments of {\tt ASIN} and {\tt ACOS} are not checked to insure that the
  1948. absolute value of the real part does not exceed 1; and arguments of
  1949. {\tt LOG} are not checked to insure that the absolute value of the imaginary
  1950. part does not exceed $\pi$; but checks (perhaps involving user response
  1951. for non-numerical arguments) could be introduced using
  1952. {\tt LET} \ttindex{LET} statements for these operators.
  1953. Users should also note that even though the solve package can find exact
  1954. solutions for cubics and quartics, the results in most cases are so
  1955. intractable that it is better to look for another method of solution.
  1956. \section{Linear Operators}\index{Linear operator}
  1957. An operator can be declared to be linear in its first argument over powers
  1958. of its second argument. If an operator {\tt F} is so declared, {\tt F} of
  1959. any sum is broken up into sums of {\tt F}s, and any factors which are not
  1960. powers of the variable are taken outside. This means that {\tt F} must
  1961. have (at least) two arguments. In addition, the second argument must be
  1962. an identifier (or more generally a kernel), not an expression.
  1963. {\it Example:}
  1964. If {\tt F} were declared linear, then
  1965. \begin{verbatim}
  1966. 5
  1967. f(a*x^5+b*x+c,x) -> F(X ,X)*A + F(X,X)*B + F(1,X)*C
  1968. \end{verbatim}
  1969. More precisely, not only will the variable and its powers remain within the
  1970. scope of the {\tt F} operator, but so will any variable and its powers which had
  1971. been declared to {\tt DEPEND} (q.v.) on the prescribed variable; and so would
  1972. any expression which contains that variable or a dependent variable on any
  1973. level, e.g. {\tt cos(sin(x))}.
  1974. To declare operators {\tt F} and {\tt G} to be linear operators,
  1975. use:\ttindex{LINEAR}
  1976. \begin{verbatim}
  1977. linear f,g;
  1978. \end{verbatim}
  1979. The analysis is done of the first argument with respect to the second; any
  1980. other arguments are ignored. It uses the following rules of evaluation:
  1981. \begin{quote}
  1982. \begin{tabbing}
  1983. {\tt f(0) -> 0} \\
  1984. {\tt f(-y,x) -> -F(Y,X)} \\
  1985. {\tt f(y+z,x) -> F(Y,X)+F(Z,X)} \\
  1986. {\tt f(y*z,x) -> Z*F(Y,X)} \hspace{0.5in}\= if Z does not depend on X \\
  1987. {\tt f(y/z,x) -> F(Y,X)/Z} \> if Z does not depend on X
  1988. \end{tabbing}
  1989. \end{quote}
  1990. To summarize, {\tt Y} ``depends" on the indeterminate {\tt X} in the above
  1991. if either of the following hold:
  1992. \begin{enumerate}
  1993. \item {\tt Y} is an expression which contains {\tt X} at any level as a
  1994. variable, e.g.: {\tt cos(sin(x))}
  1995. \item Any variable in the expression {\tt Y} has been declared dependent on
  1996. {\tt X} by use of the declaration {\tt DEPEND} (q.v.).
  1997. \end{enumerate}
  1998. The use of such linear operators\index{Linear operator} can be seen in the
  1999. paper Fox, J.A. and A. C. Hearn, ``Analytic Computation of Some Integrals
  2000. in Fourth Order Quantum Electrodynamics" Journ. Comp. Phys. 14 (1974)
  2001. 301-317, which contains a complete listing of a program for definite
  2002. integration\index{Integration} of some expressions which arise in fourth
  2003. order quantum electrodynamics.
  2004. \section{Non-Commuting Operators}\index{Non-commuting operator}
  2005. An operator can be declared to be non-commutative under multiplication by
  2006. the declaration {\tt NONCOM} \ttindex{NONCOM}.
  2007. {\it Example:}
  2008. After the declaration {\tt noncom u,v;}, the expressions {\tt
  2009. u(x)*u(y)-u(y)*u(x)} and {\tt u(x)*v(y)-v(y)*u(x)} will remain unchanged
  2010. on simplification, and in particular will not simplify to zero.
  2011. Note that it is the operator ({\tt U} and {\tt V} in the above example)
  2012. and not the variable that has the non-commutative property.
  2013. The {\tt LET} \ttindex{LET} statement may be used to introduce rules of
  2014. evaluation for such operators. In particular, the boolean operator
  2015. {\tt ORDP}\ttindex{ORDP} is useful for introducing an ordering on such
  2016. expressions.
  2017. {\it Example:}
  2018. The rule
  2019. \begin{verbatim}
  2020. for all x,y such that x neq y and ordp(x,y)
  2021. let u(x)*u(y)= u(y)*u(x)+comm(x,y);
  2022. \end{verbatim}
  2023. would introduce the commutator of {\tt u(x)} and {\tt u(y)} for all
  2024. {\tt X} and {\tt Y}. Note that since {\tt ordp(x,x)} is {\em true}, the
  2025. equality check is necessary in the degenerate case to avoid a circular
  2026. loop in the rule.
  2027. \section{Symmetric and Antisymmetric Operators}
  2028. An operator can be declared to be symmetric with respect to its arguments
  2029. by the declaration {\tt SYMMETRIC}. \ttindex{SYMMETRIC} For example
  2030. \begin{verbatim}
  2031. symmetric u,v;
  2032. \end{verbatim}
  2033. means that any expression involving the top level operators {\tt U} or
  2034. {\tt V} will have its arguments reordered to conform to the internal order
  2035. used by {\REDUCE}. The user can change this order for kernels by the
  2036. command {\tt KORDER} (q.v.).
  2037. For example, {\tt u(x,v(1,2))} would become {\tt u(v(2,1),x)}, since
  2038. numbers are ordered in decreasing order, and expressions are ordered in
  2039. decreasing order of complexity.
  2040. An operator can similarly be declared antisymmetric by the declaration
  2041. {\tt ANTISYMMETRIC}. \ttindex{ANTISYMMETRIC} For example,
  2042. \begin{verbatim}
  2043. antisymmetric l,m;
  2044. \end{verbatim}
  2045. means that any expression involving the top level operators {\tt L} or
  2046. {\tt M} will have its arguments reordered to conform to the internal order
  2047. of the system, and the sign of the expression changed if there are an odd
  2048. number of argument interchanges necessary to bring about the new order.
  2049. For example, {\tt l(x,m(1,2))} would become {\tt -l(-m(2,1),x)} since one
  2050. interchange occurs with each operator. An expression like {\tt l(x,x)}
  2051. would also be replaced by 0.
  2052. \section{Declaring New Prefix Operators}
  2053. The user may add new prefix\index{Prefix} operators to the system by
  2054. using the declaration {\tt OPERATOR}. For example:
  2055. \begin{verbatim}
  2056. operator h,g1,arctan;
  2057. \end{verbatim}
  2058. adds the prefix operators {\tt H}, {\tt G1} and {\tt ARCTAN} to the system.
  2059. This allows symbols like {\tt h(w), h(x,y,z), g1(p+q), arctan(u/v)} to be
  2060. used in expressions, but no meaning or properties of the operator are
  2061. implied. The same operator symbol can be used equally well as a 1-, 2-,
  2062. 3-, etc.-place operator.
  2063. To give a meaning to an operator symbol, or express some of its
  2064. properties, {\tt LET} \ttindex{LET} statements can be used, or the operator
  2065. can be given a definition as a procedure (q.v.).
  2066. If the user forgets to declare an identifier as an operator, the system
  2067. will prompt the user to do so in interactive mode, or do it automatically
  2068. in non-interactive mode. A diagnostic message will also be printed if an
  2069. identifier is declared {\tt OPERATOR} more than once.
  2070. Operators once declared are global in scope, and so can then be referenced
  2071. anywhere in the program. In other words, a declaration within a block (or
  2072. a procedure) does not limit the scope of the operator to that block, nor
  2073. does the operator go away on exiting the block (use {\tt CLEAR} instead
  2074. for this purpose).
  2075. \section{Declaring New Infix Operators}
  2076. Users can add new infix operators by using the declarations
  2077. {\tt INFIX} \ttindex{INFIX} and {\tt PRECEDENCE}. \ttindex{PRECEDENCE}
  2078. For example,
  2079. \begin{verbatim}
  2080. infix mm;
  2081. precedence mm,-;
  2082. \end{verbatim}
  2083. The declaration {\tt infix mm;} would allow one to use the symbol
  2084. {\tt MM} as an infix operator:
  2085. \begin{quote}
  2086. \hspace{0.2in} {\tt a mm b} \hspace{0.3in} instead of \hspace{0.3in}
  2087. {\tt mm(a,b)}.
  2088. \end{quote}
  2089. The declaration {\tt precedence mm,-;} says that {\tt MM} should be
  2090. inserted into the infix operator precedence list (q.v.) just {\em after}
  2091. the - operator. This gives it higher precedence than - and lower
  2092. precedence than * . Thus
  2093. \begin{quote}
  2094. \hspace{0.2in}{\tt a - b mm c - d}\hspace{.3in} means \hspace{.3in}
  2095. {\tt a - (b mm c) - d},
  2096. \end{quote}
  2097. while
  2098. \begin{quote}
  2099. \hspace{0.2in}{\tt a * b mm c * d}\hspace{.3in} means \hspace{.3in}
  2100. {\tt (a * b) mm (c * d)}.
  2101. \end{quote}
  2102. Both infix and prefix\index{Prefix} operators have no transformation
  2103. properties unless {\tt LET} \ttindex{LET} statements or procedure
  2104. declarations are used to assign a meaning.
  2105. We should note here that infix operators so defined are always binary:
  2106. \begin{quote}
  2107. \hspace{0.2in}{\tt a mm b mm c}\hspace{.3in} means \hspace{.3in}
  2108. {\tt (a mm b) mm c}.
  2109. \end{quote}
  2110. \section{Creating or Removing Variable Dependency}
  2111. There are several facilities in {\REDUCE}, such as the differentiation
  2112. \index{Differentiation}
  2113. operator and the linear operator\index{Linear operator} facility, which
  2114. can utilize knowledge of the dependency between various variables, or
  2115. kernels (q.v.). Such dependency may be expressed by the command {\tt
  2116. DEPEND}. \ttindex{DEPEND} This takes an arbitrary number of arguments and
  2117. sets up a dependency of the first argument on the remaining arguments.
  2118. For example,
  2119. \begin{verbatim}
  2120. depend x,y,z;
  2121. \end{verbatim}
  2122. says that {\tt X} is dependent on both {\tt Y} and {\tt Z}.
  2123. \begin{verbatim}
  2124. depend z,cos(x),y;
  2125. \end{verbatim}
  2126. says that {\tt Z} is dependent on {\tt COS(X)} and {\tt Y}.
  2127. Dependencies introduced by {\tt DEPEND} can be removed by {\tt NODEPEND}.
  2128. \ttindex{NODEPEND} The arguments of this are the same as for {\tt DEPEND}.
  2129. For example, given the above dependencies,
  2130. \begin{verbatim}
  2131. nodepend z,cos(x);
  2132. \end{verbatim}
  2133. says that {\tt Z} is no longer dependent on {\tt COS(X)}, although it remains
  2134. dependent on {\tt Y}.
  2135. \chapter{Display and Structuring of Expressions}\index{Display}
  2136. \index{Structuring}
  2137. In this section, we consider a variety of commands and operators which
  2138. permit the user to obtain various parts of algebraic expressions and also
  2139. display their structure in a variety of forms. Also presented are some
  2140. additional concepts in the {\REDUCE} design that help the user gain a better
  2141. understanding of the structure of the system.
  2142. \section{Kernels}\index{Kernel}
  2143. {\REDUCE} is designed so that each operator in the system has an
  2144. evaluation (or simplification)\index{Simplification} function associated
  2145. with it which transforms the expression into an internal canonical form.
  2146. \index{Canonical form} This form, which bears little resemblance to the
  2147. original expression, is described in detail in Hearn, A. C., ``{\REDUCE} 2:
  2148. A System and Language for Algebraic Manipulation," Proc. of the Second
  2149. Symposium on Symbolic and Algebraic Manipulation, ACM, New York (1971)
  2150. 128-133.
  2151. The evaluation function may transform its arguments in one of two
  2152. alternative ways. First, it may convert the expression into other
  2153. operators in the system, leaving no functions of the original operator for
  2154. further manipulation. This is in a sense true of the evaluation functions
  2155. associated with the operators {\tt +}, {\tt *} and {\tt /} , for example,
  2156. because the canonical form\index{Canonical form} does not include these
  2157. operators explicitly. It is also true of an operator such as the
  2158. determinant operator {\tt DET} \ttindex{DET} (q.v.) because the relevant
  2159. evaluation function calculates the appropriate determinant, and the
  2160. operator {\tt DET} no longer appears. On the other hand, the evaluation
  2161. process may leave some residual functions of the relevant operator. For
  2162. example, with the operator {\tt COS}, a residual expression like {\tt
  2163. COS(X)} may remain after evaluation unless a rule for the reduction of
  2164. cosines into exponentials, for example, were introduced. These residual
  2165. functions of an operator are termed {\em kernels}\index{Kernel} and are
  2166. stored uniquely like variables. Subsequently, the kernel is carried
  2167. through the calculation as a variable unless transformations are
  2168. introduced for the operator at a later stage.
  2169. In those cases where the evaluation process leaves an operator expression
  2170. with non-trivial arguments, the form of the argument can vary depending on
  2171. the state of the system at the point of evaluation. Such arguments are
  2172. normally produced in expanded form with no terms factored or grouped in
  2173. any way. For example, the expression {\tt cos(2*x+2*y)} will normally be
  2174. returned in the same form. If the argument {\tt 2*x+2*y} were evaluated
  2175. at the top level, however, it would be printed as {\tt 2*(X+Y)}. If it is
  2176. desirable to have the arguments themselves in a similar form, the switch
  2177. {\tt INTSTR} \ttindex{INTSTR} (for ``internal structure"), if on, will
  2178. cause this to happen.
  2179. In cases where the arguments of the kernel operators may be reordered, the
  2180. system puts them in a canonical order, based on an internal intrinsic
  2181. ordering of the variables. However, some commands allow arguments in the
  2182. form of kernels, and the user has no way of telling what internal order the
  2183. system will assign to these arguments. To resolve this difficulty, we
  2184. introduce the notion of a kernel form as an expression which transforms to
  2185. a kernel on evaluation.
  2186. Examples of kernel forms are:
  2187. \begin{verbatim}
  2188. a
  2189. cos(x*y)
  2190. log(sin(x))
  2191. \end{verbatim}
  2192. whereas
  2193. \begin{verbatim}
  2194. a*b
  2195. (a+b)^4
  2196. \end{verbatim}
  2197. are not.
  2198. We see that kernel forms can usually be used as generalized variables, and
  2199. most algebraic properties associated with variables may also be associated
  2200. with kernels.
  2201. \section{The Expression Workspace}\index{Workspace}
  2202. Several mechanisms are available for saving and retrieving previously
  2203. evaluated expressions. The simplest of these refers to the last algebraic
  2204. expression simplified. When an assignment of an algebraic expression is
  2205. made, or an expression is evaluated at the top level, (i.e., not inside a
  2206. compound statement or procedure) the results of the evaluation are
  2207. automatically saved in a variable {\tt WS} which we shall refer to as the
  2208. workspace. (More precisely, the expression is assigned to the variable
  2209. {\tt WS} which is then available for further manipulation.)
  2210. {\it Example:}
  2211. If we evaluate the expression {\tt (x+y)\^{ }2} at the top level and next
  2212. wish to differentiate it with respect to {\tt Y}, we can simply say
  2213. \begin{verbatim}
  2214. df(ws,y);
  2215. \end{verbatim}
  2216. to get the desired answer.
  2217. If the user wishes to assign the workspace to a variable or expression for
  2218. later use, the {\tt SAVEAS} \ttindex{SAVEAS} statement can be used. It
  2219. has the syntax
  2220. \begin{verbatim}
  2221. SAVEAS <expression>
  2222. \end{verbatim}
  2223. For example, after the differentiation in the last example, the workspace
  2224. holds the expression {\tt 2*x+2*y}. If we wish to assign this to the
  2225. variable {\tt Z} we can now say
  2226. \begin{verbatim}
  2227. saveas z;
  2228. \end{verbatim}
  2229. If the user wishes to save the expression in a form that allows him to use
  2230. some of its variables as arbitrary parameters, the {\tt FOR ALL} (q.v.)
  2231. command can be used.
  2232. {\it Example:}
  2233. \begin{verbatim}
  2234. for all x saveas h(x);
  2235. \end{verbatim}
  2236. with the above expression would mean that {\tt h(z)} evaluates to {\tt
  2237. 2*Y+2*Z}.
  2238. A further method for referencing more than the last expression is described
  2239. in the section on interactive use of {\REDUCE}.
  2240. \section{Output of Expressions}
  2241. A considerable degree of flexibility is available in {\REDUCE} in the
  2242. printing of expressions generated during calculations. No explicit format
  2243. statements are supplied, as these are in most cases of little use in
  2244. algebraic calculations, where the size of output or its composition is not
  2245. generally known in advance. Instead, {\REDUCE} provides a series of mode
  2246. options to the user which should enable him to produce his output in a
  2247. comprehensible and possibly pleasing form.
  2248. The most extreme option offered is to suppress the output entirely from
  2249. any top level evaluation. This is accomplished by turning off the switch
  2250. {\tt OUTPUT} \ttindex{OUTPUT} which is normally on. It is useful for
  2251. limiting output when loading large files or producing ``clean" output from
  2252. the prettyprint programs (q.v.).
  2253. In most circumstances, however, we wish to view the output, so we need to
  2254. know how to format it appropriately. As we mentioned earlier, an
  2255. algebraic expression is normally printed in an expanded form, filling the
  2256. whole output line with terms. Certain output declarations, \index{Output
  2257. declaration} however, can be used to affect this format. To begin with,
  2258. we look at an operator for changing the length of the output line.
  2259. \subsection{LINELENGTH Operator}\ttindex{LINELENGTH}
  2260. This operator is used with the syntax
  2261. \begin{verbatim}
  2262. LINELENGTH(NUM:integer):integer
  2263. \end{verbatim}
  2264. and sets the output line length to the integer {\tt NUM}. It returns the
  2265. previous output line length (so that it can be stored for later resetting
  2266. of the output line if needed).
  2267. \subsection{Output Declarations}
  2268. We now describe a number of switches and declarations which are available
  2269. for controlling output formats. It should be noted, however, that the
  2270. transformation of large expressions to produce these varied output formats
  2271. can take a lot of computing time and space. If a user wishes to speed up
  2272. the printing of the output in such cases, he can turn off the switch {\tt
  2273. PRI}. \ttindex{PRI} If this is done, then output is produced in one fixed
  2274. format, which basically reflects the internal form of the expression, and
  2275. none of the options below apply. {\tt PRI} is normally on.
  2276. With {\tt PRI} on, the output declarations\index{Output declaration}
  2277. and switches available are as follows:
  2278. \subsubsection{ORDER Declaration}
  2279. The declaration {\tt ORDER} \ttindex{ORDER} may be used to order variables
  2280. on output. The syntax is:
  2281. \begin{verbatim}
  2282. order v1,...vn;
  2283. \end{verbatim}
  2284. where the {\tt vi} are kernels (q.v.). Thus,
  2285. \begin{verbatim}
  2286. order x,y,z;
  2287. \end{verbatim}
  2288. orders {\tt X} ahead of {\tt Y}, {\tt Y} ahead of {\tt Z} and all three
  2289. ahead of other variables not given an order. {\tt order nil;} resets the
  2290. output order to the system default. The order of variables may be changed
  2291. by further calls of {\tt ORDER}, but then the reordered variables would
  2292. have an order lower than those in earlier {\tt ORDER} \ttindex{ORDER} calls.
  2293. Thus,
  2294. \begin{verbatim}
  2295. order x,y,z;
  2296. order y,x;
  2297. \end{verbatim}
  2298. would order {\tt Z} ahead of {\tt Y} and {\tt X}. The default ordering is
  2299. implementation dependent, but is usually alphabetic.
  2300. \subsubsection{FACTOR Declaration}
  2301. This declaration takes a list of identifiers or kernels\index{Kernel}
  2302. (q.v.) as argument. {\tt FACTOR} is not a factoring command (use {\tt
  2303. FACTORIZE} or the {\tt FACTOR} switch (q.v.) for this purpose); rather it
  2304. is a separation command. All terms involving fixed powers of the declared
  2305. expressions are printed as a product of the fixed powers and a sum of the
  2306. rest of the terms.
  2307. All expressions involving a given prefix operator may also be factored by
  2308. putting the operator name in the list of factored identifiers. For example:
  2309. \begin{verbatim}
  2310. factor x,cos,sin(x);
  2311. \end{verbatim}
  2312. causes all powers of {\tt X} and {\tt SIN(X)} and all functions of
  2313. {\tt COS} to be factored.
  2314. The declaration {\tt remfac v1,...,vn;} \ttindex{REMFAC} removes the
  2315. factoring flag from the expressions {\tt v1} through {\tt vn}.
  2316. \subsection{Output Control Switches}
  2317. \label{sec-output}
  2318. In addition to these declarations, the form of the output can be modified
  2319. by switching various output control switches using the declarations
  2320. {\tt ON} and {\tt OFF}. We shall illustrate the use of these switches by an
  2321. example, namely the printing of the expression
  2322. \begin{verbatim}
  2323. x^2*(y^2+2*y)+x*(y^2+z)/(2*a) .
  2324. \end{verbatim}
  2325. The relevant switches are as follows:
  2326. \subsubsection{ALLFAC Switch}
  2327. This switch will cause the system to search the whole expression, or any
  2328. sub-expression enclosed in parentheses, for simple multiplicative factors
  2329. and print them outside the parentheses. Thus our expression with {\tt ALLFAC}
  2330. \ttindex{ALLFAC}
  2331. off will print as
  2332. \begin{verbatim}
  2333. 2 2 2 2
  2334. (2*X *Y *A + 4*X *Y*A + X*Y + X*Z)/(2*A)
  2335. \end{verbatim}
  2336. and with {\tt ALLFAC} on as
  2337. \begin{verbatim}
  2338. 2 2
  2339. X*(2*X*Y *A + 4*X*Y*A + Y + Z)/(2*A) .
  2340. \end{verbatim}
  2341. {\tt ALLFAC} is normally on, and is on in the following examples, except
  2342. where otherwise stated.
  2343. \subsubsection{DIV Switch}\ttindex{DIV}
  2344. This switch makes the system search the denominator of an expression for
  2345. simple factors which it divides into the numerator, so that rational
  2346. fractions and negative powers appear in the output. With {\tt DIV} on, our
  2347. expression would print as
  2348. \begin{verbatim}
  2349. 2 2 (-1) (-1)
  2350. X*(X*Y + 2*X*Y + 1/2*Y *A + 1/2*A *Z) .
  2351. \end{verbatim}
  2352. {\tt DIV} is normally off.
  2353. \subsubsection{LIST Switch}\ttindex{LIST}
  2354. This switch causes the system to print each term in any sum on a separate
  2355. line. With {\tt LIST} on, our expression prints as
  2356. \begin{verbatim}
  2357. 2
  2358. X*(2*X*Y *A
  2359. + 4*X*Y*A
  2360. 2
  2361. + Y
  2362. + Z)/(2*A) .
  2363. \end{verbatim}
  2364. {\tt LIST} is normally off.
  2365. \subsubsection{NOSPLIT Switch}\ttindex{NOSPLIT}
  2366. Under normal circumstances, the printing routines try to break an expression
  2367. across lines at a natural point. This is a fairly expensive process. If
  2368. you are not overly concerned about where the end-of-line breaks come, you
  2369. can speed up the printing of expressions by turning off the switch
  2370. {\tt NOSPLIT}. This switch is normally on.
  2371. \subsubsection{RAT Switch}\ttindex{RAT}
  2372. This switch is only useful with expressions in which variables are
  2373. factored with {\tt FACTOR}. With this mode, the overall denominator of the
  2374. expression is printed with each factored sub-expression. We assume a prior
  2375. declaration {\tt factor x;} in the following output. We first print the
  2376. expression with {\tt RAT off}:
  2377. \begin{verbatim}
  2378. 2 2
  2379. (2*X *Y*A*(Y + 2) + X*(Y + Z))/(2*A) .
  2380. \end{verbatim}
  2381. With {\tt RAT} on the output becomes:
  2382. \begin{verbatim}
  2383. 2 2
  2384. X *Y*(Y + 2) + X*(Y + Z)/(2*A) .
  2385. \end{verbatim}
  2386. {\tt RAT} is normally off.
  2387. Next, if we leave {\tt X} factored, and turn on both {\tt DIV} and
  2388. {\tt RAT}, the result becomes
  2389. \begin{verbatim}
  2390. 2 (-1) 2
  2391. X *Y*(Y + 2) + 1/2*X*A *(Y + Z) .
  2392. \end{verbatim}
  2393. Finally, with {\tt X} factored, {\tt RAT} on and {\tt ALLFAC} \ttindex{ALLFAC}
  2394. off we retrieve the original structure
  2395. \begin{verbatim}
  2396. 2 2 2
  2397. X *(Y + 2*Y) + X*(Y + Z)/(2*A) .
  2398. \end{verbatim}
  2399. \subsubsection{RATPRI Switch}\ttindex{RATPRI}
  2400. If the numerator and denominator of an expression can each be printed in
  2401. one line, the output routines will print them in a two dimensional
  2402. notation, with numerator and denominator on separate lines and a line of
  2403. dashes in between. For example, {\tt (a+b)/2} will print as
  2404. \begin{verbatim}
  2405. A + B
  2406. -----
  2407. 2
  2408. \end{verbatim}
  2409. Turning this switch off causes such expressions to be output in a linear
  2410. form.
  2411. \subsubsection{REVPRI Switch}\ttindex{REVPRI}
  2412. The normal ordering of terms in output is from highest to lowest power.
  2413. In some situations (e.g., when a power series is output), the opposite
  2414. ordering is more convenient. The switch {\tt REVPRI} if on causes such a
  2415. reverse ordering of terms. For example, the expression
  2416. {\tt y*(x+1)\^{ }2+(y+3)\^{ }2} will normally print as
  2417. \begin{verbatim}
  2418. 2 2
  2419. X *Y + 2*X*Y + Y + 7*Y + 9
  2420. \end{verbatim}
  2421. whereas with {\tt REVPRI} on, it will print as
  2422. \begin{verbatim}
  2423. 2 2
  2424. 9 + 7*Y + Y + 2*X*Y + X *Y.
  2425. \end{verbatim}
  2426. \subsection{WRITE Command} \ttindex{WRITE}
  2427. In simple cases no explicit output\index{Output} command is necessary in
  2428. {\REDUCE}, since the value of any expression is automatically printed if a
  2429. semicolon is used as a delimiter. There are, however, several situations
  2430. in which such a command is useful.
  2431. In a {\tt FOR}, {\tt WHILE}, or {\tt REPEAT} statement it may be desired
  2432. to output something each time the statement within the loop construct is
  2433. repeated.
  2434. It may be desired for a procedure to output intermediate results or other
  2435. information while it is running. It may be desired to have results labeled
  2436. in special ways, especially if the output is directed to a file or device
  2437. other than the terminal.
  2438. The {\tt WRITE} command consists of the word {\tt WRITE} followed by one
  2439. or more items separated by commas, and followed by a terminator. There
  2440. are three kinds of items which can be used:
  2441. \begin{enumerate}
  2442. \item Expressions (including variables and constants). The expression is
  2443. evaluated, and the result is printed out.
  2444. \item Assignments. The expression on the right side of the {\tt :=}
  2445. operator is evaluated, and is assigned to the variable on the left; then
  2446. the symbol on the left is printed, followed by a ``{\tt :=}", followed by
  2447. the value of the expression on the right -- almost exactly the way an
  2448. assignment followed by a semicolon prints out normally. (The difference is
  2449. that if the {\tt WRITE} is in a {\tt FOR} statement and the left-hand side
  2450. of the assignment is an array position or something similar containing the
  2451. variable of the {\tt FOR} iteration, then the value of that variable is
  2452. inserted in the printout.)
  2453. \item Arbitrary strings of characters, preceded and followed by double-quote
  2454. marks (e.g., {\tt "string"}).
  2455. \end{enumerate}
  2456. The items specified by a single {\tt WRITE} statement print side by side
  2457. on one line. (The line is broken automatically if it is too long.) Strings
  2458. print exactly as quoted. The {\tt WRITE} command itself however does not
  2459. return a value.
  2460. The print line is closed at the end of a {\tt WRITE} command evaluation.
  2461. Therefore the command {\tt WRITE "";} (specifying nothing to be printed
  2462. except the empty string) causes a line to be skipped.
  2463. {\it Examples:}
  2464. \begin{enumerate}
  2465. \item If {\tt A} is {\tt X+5}, {\tt B} is itself, {\tt C} is 123, {\tt M} is
  2466. an array, and {\tt Q}=3, then
  2467. \begin{verbatim}
  2468. write m(q):=a," ",b/c," THANK YOU";
  2469. \end{verbatim}
  2470. will set {\tt M(3)} to {\tt x+5} and print
  2471. \begin{verbatim}
  2472. M(Q) := X + 5 B/123 THANK YOU
  2473. \end{verbatim}
  2474. The blanks between the {\tt 5} and {\tt B}, and the
  2475. {\tt 3} and {\tt T}, come from the blanks in the quoted strings.
  2476. \item To print a table of the squares of the integers from 1 to 20:
  2477. \begin{verbatim}
  2478. for i:=1:20 do write i," ",i^2;
  2479. \end{verbatim}
  2480. \item To print a table of the squares of the integers from 1 to 20, and at
  2481. the same time store them in positions 1 to 20 of an array {\tt A:}
  2482. \begin{verbatim}
  2483. for i:=1:20 do <<a(i):=i^2; write i," ",a(i)>>;
  2484. \end{verbatim}
  2485. This will give us two columns of numbers. If we had used
  2486. \begin{verbatim}
  2487. for i:=1:20 do write i," ",a(i):=i^2;
  2488. \end{verbatim}
  2489. we would also get {\tt A(}i{\tt ) := } repeated on each line.
  2490. \item The following more complete example calculates the famous f and g
  2491. series, first reported in Sconzo, P., LeSchack, A. R., and Tobey, R.,
  2492. ``Symbolic Computation of f and g Series by Computer", Astronomical Journal
  2493. 70 (May 1965).
  2494. \begin{verbatim}
  2495. x1:= -sig*(mu+2*eps)$
  2496. x2:= eps-2*sig^2$
  2497. x3:= -3*mu*sig$
  2498. f:= 1$
  2499. g:= 0$
  2500. for i:= 1 step 1 until 10 do begin
  2501. f1:= -mu*g + x1*df(f,eps) + x2*df(f,sig) + x3*df(f,mu);
  2502. write "f(",i,") := ",f1;
  2503. g1:= f + x1*df(g,eps) + x2*df(g,sig) + x3*df(g,mu);
  2504. write "g(",i,") := ",g1;
  2505. f:=f1$
  2506. g:=g1$
  2507. end;
  2508. \end{verbatim}
  2509. A portion of the output, to illustrate the printout from the {\tt WRITE}
  2510. command, is as follows:
  2511. \begin{verbatim}
  2512. ... <prior output> ...
  2513. 2
  2514. F(4) := MU*(3*EPS - 15*SIG + MU)
  2515. G(4) := 6*SIG*MU
  2516. 2
  2517. F(5) := 15*SIG*MU*( - 3*EPS + 7*SIG - MU)
  2518. 2
  2519. G(5) := MU*(9*EPS - 45*SIG + MU)
  2520. ... <more output> ...
  2521. \end{verbatim}
  2522. \end{enumerate}
  2523. \subsection{Suppression of Zeros}
  2524. It is sometimes annoying to have zero assignments (i.e. assignments of the
  2525. form {\tt <expression> := 0}) printed, especially in printing large arrays
  2526. with many zero elements. The output from such assignments can be
  2527. suppressed by turning on the switch {\tt NERO}. \ttindex{NERO}
  2528. \subsection{{FORTRAN} Style Output Of Expressions}
  2529. It is naturally possible to evaluate expressions numerically in {\REDUCE} by
  2530. giving all variables and sub-expressions numerical values. However, as we
  2531. pointed out elsewhere the user must declare real arithmetical operation by
  2532. turning on the switch {\tt ROUNDED}\ttindex{ROUNDED}. However, it should be
  2533. remembered that arithmetic in {\REDUCE} is not particularly fast, since
  2534. results are interpreted rather than evaluated in a compiled form. The user
  2535. with a large amount of numerical computation after all necessary algebraic
  2536. manipulations have been performed is therefore well advised to perform
  2537. these calculations in a FORTRAN\index{FORTRAN} or similar system. For
  2538. this purpose, {\REDUCE} offers facilities for users to produce FORTRAN
  2539. compatible files for numerical processing.
  2540. First, when the switch {\tt FORT} \ttindex{FORT} is on, the system will
  2541. print expressions in a FORTRAN notation. Expressions begin in column
  2542. seven. If an expression extends over one line, a continuation mark (.)
  2543. followed by a blank appears on subsequent cards. After a certain number
  2544. of lines have been produced (according to the value of the variable {\tt
  2545. *CARDNO} (q.v.)), a new expression is started. If the expression printed
  2546. arises from an assignment to a variable, the variable is printed as the
  2547. name of the expression. Otherwise the expression is given the default
  2548. name {\tt ANS}. An error occurs if identifiers or numbers are outside the
  2549. bounds permitted by FORTRAN.
  2550. A second option is to use the {\tt WRITE} command to produce other programs.
  2551. {\it Example:}
  2552. The following {\REDUCE} statements
  2553. \begin{verbatim}
  2554. on fort;
  2555. out "forfil";
  2556. write "C THIS IS A FORTRAN PROGRAM";
  2557. write " 1 FORMAT(E13.5)";
  2558. write " U=1.23";
  2559. write " V=2.17";
  2560. write " W=5.2";
  2561. x:=(u+v+w)^11;
  2562. write "C IT WAS FOOLISH TO EXPAND THIS EXPRESSION";
  2563. write " PRINT 1,X";
  2564. write " END";
  2565. shut "forfil";
  2566. off fort;
  2567. \end{verbatim}
  2568. will generate a file {\tt forfil} which contains:
  2569. \begin{verbatim}
  2570. C THIS IS A FORTRAN PROGRAM
  2571. 1 FORMAT(E13.5)
  2572. U=1.23
  2573. V=2.17
  2574. W=5.2
  2575. ANS1=1320.*U**3*V*W**7+165.*U**3*W**8+55.*U**2*V**9+495.*U
  2576. . **2*V**8*W+1980.*U**2*V**7*W**2+4620.*U**2*V**6*W**3+
  2577. . 6930.*U**2*V**5*W**4+6930.*U**2*V**4*W**5+4620.*U**2*V**3*
  2578. . W**6+1980.*U**2*V**2*W**7+495.*U**2*V*W**8+55.*U**2*W**9+
  2579. . 11.*U*V**10+110.*U*V**9*W+495.*U*V**8*W**2+1320.*U*V**7*W
  2580. . **3+2310.*U*V**6*W**4+2772.*U*V**5*W**5+2310.*U*V**4*W**6
  2581. . +1320.*U*V**3*W**7+495.*U*V**2*W**8+110.*U*V*W**9+11.*U*W
  2582. . **10+V**11+11.*V**10*W+55.*V**9*W**2+165.*V**8*W**3+330.*
  2583. . V**7*W**4+462.*V**6*W**5+462.*V**5*W**6+330.*V**4*W**7+
  2584. . 165.*V**3*W**8+55.*V**2*W**9+11.*V*W**10+W**11
  2585. X=U**11+11.*U**10*V+11.*U**10*W+55.*U**9*V**2+110.*U**9*V*
  2586. . W+55.*U**9*W**2+165.*U**8*V**3+495.*U**8*V**2*W+495.*U**8
  2587. . *V*W**2+165.*U**8*W**3+330.*U**7*V**4+1320.*U**7*V**3*W+
  2588. . 1980.*U**7*V**2*W**2+1320.*U**7*V*W**3+330.*U**7*W**4+462.
  2589. . *U**6*V**5+2310.*U**6*V**4*W+4620.*U**6*V**3*W**2+4620.*U
  2590. . **6*V**2*W**3+2310.*U**6*V*W**4+462.*U**6*W**5+462.*U**5*
  2591. . V**6+2772.*U**5*V**5*W+6930.*U**5*V**4*W**2+9240.*U**5*V
  2592. . **3*W**3+6930.*U**5*V**2*W**4+2772.*U**5*V*W**5+462.*U**5
  2593. . *W**6+330.*U**4*V**7+2310.*U**4*V**6*W+6930.*U**4*V**5*W
  2594. . **2+11550.*U**4*V**4*W**3+11550.*U**4*V**3*W**4+6930.*U**
  2595. . 4*V**2*W**5+2310.*U**4*V*W**6+330.*U**4*W**7+165.*U**3*V
  2596. . **8+1320.*U**3*V**7*W+4620.*U**3*V**6*W**2+9240.*U**3*V**
  2597. . 5*W**3+11550.*U**3*V**4*W**4+9240.*U**3*V**3*W**5+4620.*U
  2598. . **3*V**2*W**6+ANS1
  2599. C IT WAS FOOLISH TO EXPAND THIS EXPRESSION
  2600. PRINT 1,X
  2601. END
  2602. \end{verbatim}
  2603. If the arguments of a {\tt WRITE} statement include an expression that
  2604. requires continuation records, the output will need editing, since the
  2605. output routine prints the arguments of {\tt WRITE} sequentially, and the
  2606. continuation mechanism therefore generates its auxiliary variables after
  2607. the preceding expression has been printed.
  2608. Finally, since there is no direct analog of {\em list} in FORTRAN,
  2609. a comment line of the form
  2610. \begin{verbatim}
  2611. C ***** INVALID FORTRAN CONSTRUCT (LIST) NOT PRINTED
  2612. \end{verbatim}
  2613. will be printed if you try to print a list with {\tt FORT} on.
  2614. \subsubsection{{FORTRAN} Output Options}\index{Output}\index{FORTRAN}
  2615. There are a number of methods available to change the default format of the
  2616. FORTRAN output.
  2617. The breakup of the expression into subparts is such that the number of
  2618. continuation lines produced is less than a given number. This number can
  2619. be modified by the assignment
  2620. \begin{verbatim}
  2621. cardno!* := <number>;
  2622. \end{verbatim}
  2623. where {\tt <number>} is the {\em total} number of cards allowed in a
  2624. statement. {\tt CARDNO!*} is initially set to 20.
  2625. The width of the output expression is also adjustable by the assignment
  2626. \begin{verbatim}
  2627. fortwidth!* := <integer>;
  2628. \end{verbatim}
  2629. which sets the total width of a given line to {\tt <integer>}. The initial
  2630. FORTRAN output width is 70.
  2631. {\REDUCE} automatically inserts a decimal point after each isolated integer
  2632. coefficient in a FORTRAN expression (so that, for example, 4 becomes
  2633. {\tt 4.} ). To prevent this, set the {\tt PERIOD} \ttindex{PERIOD}
  2634. mode switch to {\tt OFF}.
  2635. Finally, the default name {\tt ANS} assigned to an unnamed expression and
  2636. its subparts can be changed by the operator {\tt VARNAME}.
  2637. \ttindex{VARNAME} This takes a single identifier as argument, which then
  2638. replaces {\tt ANS} as the expression name. The value of {\tt VARNAME} is
  2639. its argument.
  2640. Further facilities for the production of FORTRAN and other language output
  2641. are provided by the SCOPE and GENTRAN packages described in the chapter on
  2642. user contributed packages.
  2643. \subsection{Saving Expressions for Later Use as Input}
  2644. \index{Saving an expression}
  2645. It is often useful to save an expression on an external file for use later
  2646. as input in further calculations. The commands for opening and closing
  2647. output files are explained elsewhere. However, we see in the examples on
  2648. output of expressions that the standard ``natural" method of printing
  2649. expressions is not compatible with the input syntax. So to print the
  2650. expression in an input compatible form we must inhibit this natural style
  2651. by turning off the switch {\tt NAT}. \ttindex{NAT} If this is done, a
  2652. dollar sign will also be printed at the end of the expression.
  2653. {\it Example:}
  2654. The following sequence of commands
  2655. \begin{verbatim}
  2656. off nat; out "out"; x := (y+z)^2; write "end";
  2657. shut "out"; on nat;
  2658. \end{verbatim}
  2659. will generate a file {\tt out} which contains
  2660. \begin{verbatim}
  2661. X := Y**2 + 2*Y*Z + Z**2$
  2662. END$
  2663. \end{verbatim}
  2664. \subsection{Displaying Expression Structure}\index{Displaying structure}
  2665. In those cases where the final result has a complicated form, it is often
  2666. convenient to display the skeletal structure of the answer. The operator
  2667. {\tt STRUCTR},\ttindex{STRUCTR} which takes a single expression as argument,
  2668. will do this for you. Its syntax is:
  2669. \begin{verbatim}
  2670. STRUCTR(EXPRN:algebraic[,ID1:identifier[,ID2:identifier]]);
  2671. \end{verbatim}
  2672. The structure is printed effectively as a tree, in which the subparts are
  2673. laid out with auxiliary names. If the optional {\tt ID1} is absent, the
  2674. auxiliary names are prefixed by the root {\tt ANS}. This root may be
  2675. changed by the operator {\tt VARNAME} \ttindex{VARNAME} (q.v.). If the
  2676. optional {\tt ID1} is present, and is an array name, the subparts are
  2677. named as elements of that array, otherwise {\tt ID1} is used as the root
  2678. prefix. (The second optional argument {\tt ID2} is explained later.)
  2679. The {\tt EXPRN} can be either a scalar or a matrix expression. Use of any
  2680. other will result in an error.
  2681. {\it Example:}
  2682. Let us suppose that the workspace contains {\tt ((A+B)\^{ }2+C)\^{ }3+D}.
  2683. Then the input {\tt STRUCTR WS;} will (with {\tt EXP} off) result in the
  2684. output:
  2685. \begin{verbatim}
  2686. ANS3
  2687. where
  2688. 3
  2689. ANS3 := ANS2 + D
  2690. 2
  2691. ANS2 := ANS1 + C
  2692. ANS1 := A + B
  2693. \end{verbatim}
  2694. The workspace remains unchanged after this operation, since {\tt STRUCTR}
  2695. \ttindex{STRUCTR} in the default situation returns
  2696. no value (if {\tt STRUCTR} is used as a sub-expression, its value is taken
  2697. to be 0). In addition, the sub-expressions are normally only displayed
  2698. and not retained. If you wish to access the sub-expressions with their
  2699. displayed names, the switch {\tt SAVESTRUCTR} \ttindex{SAVESTRUCTR} should be
  2700. turned on. In this case, {\tt STRUCTR} returns a list whose first element
  2701. is a representation for the expression, and subsequent elements are the
  2702. sub-expression relations. Thus, with {\tt SAVESTRUCTR} on, {\tt STRUCTR WS}
  2703. in the above example would return
  2704. \begin{verbatim}
  2705. 3 2
  2706. {ANS3,ANS3=ANS2 + D,ANS2=ANS1 + C,ANS1=A + B}
  2707. \end{verbatim}
  2708. Alternatively the {\tt PART} \ttindex{PART} operator (q.v.) can
  2709. be used to retrieve the required parts of the expression. For example, to
  2710. get the term corresponding to {\tt ANS2} in the above, one could say:
  2711. \begin{verbatim}
  2712. part(ws,1,1);
  2713. \end{verbatim}
  2714. If {\tt FORT} is on, then the results are printed in the reverse order; the
  2715. algorithm in fact guaranteeing that no sub-expression will be referenced
  2716. before it is defined. The second optional argument {\tt ID2} may also be
  2717. used in this case to name the actual expression (or expressions in the
  2718. case of a matrix argument).
  2719. {\it Example:}
  2720. Let us suppose that {\tt M}, a 2 by 1 matrix, contains the elements {\tt
  2721. ((a+b)\^{ }2 + c)\^{ }3 + d} and {\tt (a + b)*(c + d)} respectively, and that
  2722. {\tt V} has been declared to be an array. With {\tt EXP} off and {\tt
  2723. FORT} on, the statement {\tt structr(2*m,v,k);} will result in the output
  2724. \begin{verbatim}
  2725. V(1)=A+B
  2726. V(2)=V(1)**2+C
  2727. V(3)=V(2)**3+D
  2728. V(4)=C+D
  2729. K(1,1)=2.*V(3)
  2730. K(2,1)=2.*V(1)*V(4)
  2731. \end{verbatim}
  2732. \section{Changing the Internal Order of Variables}
  2733. The internal ordering of variables (more specifically kernels) can have
  2734. a significant effect on the space and time associated with a calculation.
  2735. In its default state, {\REDUCE} uses a specific order for this which may
  2736. vary between sessions. However, it is possible for the user to change
  2737. this internal order by means of the declaration
  2738. {\tt KORDER} \ttindex{KORDER}. The syntax for this is:
  2739. \begin{verbatim}
  2740. korder v1,...,vn;
  2741. \end{verbatim}
  2742. where the {\tt Vi} are kernels\index{Kernel}. With this declaration, the
  2743. {\tt Vi} are ordered internally ahead of any other kernels in the system.
  2744. {\tt V1} has the highest order, {\tt V2} the next highest, and so on. A
  2745. further call of {\tt KORDER} replaces a previous one. {\tt KORDER NIL;}
  2746. resets the internal order to the system default.
  2747. Unlike the {\tt ORDER} \ttindex{ORDER} declaration (q.v.), which has a purely
  2748. cosmetic effect on the way results are printed, the use of {\tt KORDER}
  2749. can have a significant effect on computation time. In critical cases
  2750. then, the user can experiment with the ordering of the variables used to
  2751. determine the optimum set for a given problem.
  2752. \section{Obtaining Parts of Algebraic Expressions}
  2753. There are many occasions where it is desirable to obtain a specific part
  2754. of an expression, or even change such a part to another expression. A
  2755. number of operators are available in {\REDUCE} for this purpose, and will be
  2756. described in this section. In addition, operators for obtaining specific
  2757. parts of polynomials and rational functions (such as a denominator) are
  2758. described in another section.
  2759. \subsection{COEFF Operator}\ttindex{COEFF}
  2760. Syntax:
  2761. \begin{verbatim}
  2762. COEFF(EXPRN:polynomial,VAR:kernel)
  2763. \end{verbatim}
  2764. {\tt COEFF} is an operator which partitions {\tt EXPRN} into its various
  2765. coefficients with respect to {\tt VAR} and returns them as a list, with
  2766. the coefficient independent of {\tt VAR} first.
  2767. Under normal circumstances, an error results if {\tt EXPRN} is not a
  2768. polynomial in {\tt VAR}, although the coefficients themselves can be
  2769. rational as long as they do not depend on {\tt VAR}. However, if the
  2770. switch {\tt RATARG} \ttindex{RATARG} is on, denominators are not checked for
  2771. dependence on {\tt VAR}, and are taken to be part of the coefficients.
  2772. {\it Example:}
  2773. \begin{verbatim}
  2774. coeff((y^2+z)^3/z,y);
  2775. \end{verbatim}
  2776. returns the result
  2777. \begin{verbatim}
  2778. 2
  2779. {Z ,0,3*Z,0,3,0,1/Z}.
  2780. \end{verbatim}
  2781. whereas
  2782. \begin{verbatim}
  2783. coeff((y^2+z)**3/z,y);
  2784. \end{verbatim}
  2785. gives an error if {\tt RATARG} is off, and the result
  2786. \begin{verbatim}
  2787. 3 2
  2788. {Z /Y,0,3*Z /Y,0,3*Z/Y,0,1/Y}
  2789. \end{verbatim}
  2790. if {\tt RATARG} is on.
  2791. The length of the result of {\tt COEFF} is the highest power of {\tt VAR}
  2792. encountered plus 1. In the above examples it is 7. In addition, the
  2793. variable {\tt HIPOW!*}\ttindex{HIPOW"!*} is set to the highest non-zero
  2794. power found in {\tt EXPRN} during the evaluation, and {\tt LOWPOW!*}
  2795. \ttindex{LOPOW"!*} to the lowest non-zero power, or zero if there is a
  2796. constant term. If {\tt EXPRN} is a constant, then {\tt HIPOW!*} and {\tt
  2797. LOWPOW!*} are both set to zero.
  2798. \subsection{COEFFN Operator}\ttindex{COEFFN}
  2799. The {\tt COEFFN} operator is designed to give the user a particular
  2800. coefficient of a variable in a polynomial, as opposed to {\tt COEFF} which
  2801. returns all coefficients. {\tt COEFFN} is used with the syntax
  2802. \begin{verbatim}
  2803. COEFFN(EXPRN:polynomial,VAR:kernel,N:integer)
  2804. \end{verbatim}
  2805. It returns the $n^{th}$ coefficient of {\tt VAR} in the polynomial
  2806. {\tt EXPRN}.
  2807. \subsection{PART Operator}\ttindex{PART}
  2808. Syntax:
  2809. \begin{verbatim}
  2810. PART(EXPRN:algebraic[,INTEXP:integer])
  2811. \end{verbatim}
  2812. This operator works on the form of the expression as printed {\em or as it
  2813. would have been printed at that point in the calculation} bearing in mind
  2814. all the relevant switch settings at that point. The reader therefore
  2815. needs some familiarity with the way that expressions are represented in
  2816. prefix form in {\REDUCE} to use these operators effectively. Furthermore,
  2817. it is assumed that {\tt PRI} is {\tt ON} at that point in the calculation.
  2818. The reason for this is that with {\tt PRI} off, an expression is printed
  2819. by walking the tree representing the expression internally. To save
  2820. space, it is never actually transformed into the equivalent prefix
  2821. expression as occurs when {\tt PRI} is on. However, the operations on
  2822. polynomials described elsewhere can be equally well used in this case to
  2823. obtain the relevant parts.
  2824. The evaluation proceeds recursively down the integer expression list. In
  2825. other words,
  2826. \begin{verbatim}
  2827. PART(<expression>,<integer1>,<integer2>)
  2828. -> PART(PART(<expression>,<integer1>),<integer2>)
  2829. \end{verbatim}
  2830. and so on, and
  2831. \begin{verbatim}
  2832. PART(<expression>) -> <expression>.
  2833. \end{verbatim}
  2834. {\tt INTEXP} can be any expression that evaluates to an integer. If the
  2835. integer is positive, then that term of the expression is found. If the
  2836. integer is 0, the operator is returned. Finally, if the integer is
  2837. negative, the counting is from the tail of the expression rather than the
  2838. head.
  2839. For example, if the expression {\tt a+b} is printed as {\tt A+B} (i.e.,
  2840. the ordering of the variables is alphabetical), then
  2841. \begin{verbatim}
  2842. part(a+b,2) -> B
  2843. part(a+b,-1) -> B
  2844. and
  2845. part(a+b,0) -> PLUS
  2846. \end{verbatim}
  2847. An operator {\tt ARGLENGTH} \ttindex{ARGLENGTH} is available to determine
  2848. the number of arguments of the top level operator in an expression. If
  2849. the expression does not contain a top level operator, then -1 is returned.
  2850. For example,
  2851. \begin{verbatim}
  2852. arglength(a+b+c) -> 3
  2853. arglength(f()) -> 0
  2854. arglength(a) -> -1
  2855. \end{verbatim}
  2856. \subsection{Changing Parts of Expressions}
  2857. {\tt PART} may also be used to change a given part of an expression. In
  2858. this case, the {\tt PART} construct appears on the left-hand side of an
  2859. assignment statement, and the expression to replace the given part on the
  2860. right-hand side.
  2861. For example, with the normal settings of {\REDUCE's} switches:
  2862. \begin{verbatim}
  2863. part(a+b,2) := c; -> A+C
  2864. part(a+b,0) := -; -> A-B
  2865. \end{verbatim}
  2866. \chapter{Polynomials and Rationals}
  2867. Many operations in computer algebra are concerned with polynomials
  2868. \index{Polynomial} and rational functions\index{Rational function}. In
  2869. this section, we review some of the switches and operators available for
  2870. this purpose. These are in addition to those that work on general
  2871. expressions (such as {\tt DF} and {\tt INT}) described elsewhere. In the
  2872. case of operators, the arguments are first simplified before the
  2873. operations are applied. In addition, they operate only on arguments of
  2874. prescribed types, and produce a type mismatch error if given arguments
  2875. which cannot be interpreted in the required mode with the current switch
  2876. settings. For example, if an argument is required to be a kernel and
  2877. {\tt a/2} is used (with no other rules for {\tt A}), an error
  2878. \begin{verbatim}
  2879. A/2 invalid as kernel
  2880. \end{verbatim}
  2881. will result.
  2882. With the exception of those that select various parts of a polynomial or
  2883. rational function, these operations have potentially significant effects on
  2884. the space and time associated with a given calculation. The user should
  2885. therefore experiment with their use in a given calculation in order to
  2886. determine the optimum set for a given problem.
  2887. One such operation provided by the system is an operator {\tt LENGTH}
  2888. \ttindex{LENGTH} which returns the number of top level terms in the
  2889. numerator of its argument. For example,
  2890. \begin{verbatim}
  2891. length ((a+b+c)^3/(c+d));
  2892. \end{verbatim}
  2893. has the value 10. To get the number of terms in the denominator, one
  2894. would first select the denominator by the operator {\tt DEN} \ttindex{DEN}
  2895. (q.v.) and then call {\tt LENGTH}, as in
  2896. \begin{verbatim}
  2897. length den ((a+b+c)^3/(c+d));
  2898. \end{verbatim}
  2899. Other operations currently supported, the relevant switches and operators,
  2900. and the required argument and value modes of the latter, follow.
  2901. \section{Controlling the Expansion of Expressions}
  2902. The switch {\tt EXP} \ttindex{EXP} controls the expansion of expressions. If
  2903. it is off, no expansion of powers or products of expressions occurs.
  2904. Users should note however that in this case results come out in a normal
  2905. but not necessarily canonical form. This means that zero expressions
  2906. simplify to zero, but that two equivalent expressions need not necessarily
  2907. simplify to the same form.
  2908. {\it Example:} With {\tt EXP} on, the two expressions
  2909. \begin{verbatim}
  2910. (a+b)*(a+2*b)
  2911. \end{verbatim}
  2912. and
  2913. \begin{verbatim}
  2914. a^2+3*a*b+2*b^2
  2915. \end{verbatim}
  2916. will both simplify to the latter form. With {\tt EXP}
  2917. off, they would remain unchanged, unless the complete factoring {\tt
  2918. (ALLFAC)} option were in force. {\tt EXP} is normally on.
  2919. Several operators that expect a polynomial as an argument behave
  2920. differently when {\tt EXP} is off, since there is often only one term at
  2921. the top level. For example, with {\tt EXP} off
  2922. \begin{verbatim}
  2923. length((a+b+c)^3/(c+d));
  2924. \end{verbatim}
  2925. returns the value 1.
  2926. \section{Factorization of Polynomials}\index{Factorization}
  2927. {\REDUCE} is capable of factorizing univariate and multivariate polynomials
  2928. that have integer coefficients, finding all factors that also have integer
  2929. coefficients. The package for doing this was written by Dr. Arthur C.
  2930. Norman and Ms. P. Mary Ann Moore at The University of Cambridge. It is
  2931. described in P. M. A. Moore and A. C. Norman, ``Implementing a Polynomial
  2932. Factorization and GCD Package", Proc. SYMSAC '81, ACM (New York) (1981),
  2933. 109-116.
  2934. The easiest way to use this facility is to turn on the switch
  2935. {\tt FACTOR}, which causes all expressions to be output in a factored form.
  2936. For example, with {\tt FACTOR} on, the expression {\tt A\^{ }2-B\^{ }2} is
  2937. returned as {\tt (A+B)*(A-B)}.
  2938. It is also possible to factorize a given expression explicitly. The
  2939. operator {\tt FACTORIZE} \ttindex{FACTORIZE} that invokes this facility is
  2940. used with the syntax
  2941. \begin{verbatim}
  2942. FACTORIZE(EXPRN:polynomial[,INTEXP:prime integer]):list,
  2943. \end{verbatim}
  2944. the optional argument of which will be described later. Thus to find and
  2945. display all factors of the cyclotomic polynomial $x^{105}-1$, one could
  2946. write:
  2947. \begin{verbatim}
  2948. factorize(x^105-1);
  2949. \end{verbatim}
  2950. In the above example, there is no overall numerical factor in the result,
  2951. so the results will consist only of polynomials in x. The number of such
  2952. polynomials can be found by using the operator {\tt LENGTH} \ttindex{LENGTH}
  2953. (q.v.). If there is a numerical factor, as in factorizing
  2954. $(12*x^{2}-12)$, that factor will appear as the first member of the
  2955. result. It will however not be factored further. Prime factors of such
  2956. numbers can be found using the switch {\tt IFACTOR} \ttindex{IFACTOR}. For
  2957. example,
  2958. \begin{verbatim}
  2959. on ifactor; factorize(12x^2-12);
  2960. \end{verbatim}
  2961. would result in the output
  2962. \begin{verbatim}
  2963. {2,2,3,X - 1,X + 1}.
  2964. \end{verbatim}
  2965. Note that the {\tt IFACTOR} switch only affects the result of {\tt FACTORIZE}.
  2966. It has no effect if the {\tt FACTOR} \ttindex{FACTOR} switch is also on.
  2967. The order in which the factors occur in the result (with the exception of
  2968. a possible overall numerical coefficient which comes first) is system
  2969. dependent and should not be relied on. Similarly it should be noted that
  2970. any pair of individual factors can be negated without altering their
  2971. product, and that {\REDUCE} may sometimes do that.
  2972. The factorizer works by first reducing multivariate problems to univariate
  2973. ones and then solving the univariate ones modulo small primes. It normally
  2974. selects both evaluation points and primes using a random number generator
  2975. that should lead to different detailed behavior each time any particular
  2976. problem is tackled. If, for some reason, it is known that a certain
  2977. (probably univariate) factorization can be performed effectively with a
  2978. known prime, {\tt P} say, this value of {\tt P} can be handed to
  2979. {\tt FACTORIZE} \ttindex{FACTORIZE} as a second
  2980. argument. An error will occur if a non-prime is provided to {\tt FACTORIZE} in
  2981. this manner. It is also an error to specify a prime that divides the
  2982. discriminant of the polynomial being factored, but users should note that
  2983. this condition is not checked by the program, so this capability should be
  2984. used with care.
  2985. Factorization can be performed over a number of polynomial coefficient
  2986. domains in addition to integers. The particular description of the relevant
  2987. domain should be consulted to see if factorization is supported. For
  2988. example, the following statements will factorize $x^{4}+1$ modulo 7:
  2989. \begin{verbatim}
  2990. setmod 7;
  2991. on modular;
  2992. factorize(x^4+1);
  2993. \end{verbatim}
  2994. The factorization module is provided with a trace facility that may be useful
  2995. as a way of monitoring progress on large problems, and of satisfying
  2996. curiosity about the internal workings of the package. The most simple use
  2997. of this is enabled by issuing the {\REDUCE} command \ttindex{TRFAC}
  2998. {\tt on trfac;} .
  2999. Following this, all calls to the factorizer will generate informative
  3000. messages reporting on such things as the reduction of multivariate to
  3001. univariate cases, the choice of a prime and the reconstruction of full
  3002. factors from their images. Further levels of detail in the trace are
  3003. intended mainly for system tuners and for the investigation of suspected
  3004. bugs. For example, {\tt TRALLFAC} gives tracing information at all levels
  3005. of detail. The switch that can be set by {\tt on timings;} makes it
  3006. possible for one who is familiar with the algorithms used to determine
  3007. what part of the factorization code is consuming the most resources.
  3008. {\tt on overview}; reduces the amount of detail presented in other forms of
  3009. trace. Other forms of trace output are enabled by directives of the form
  3010. \begin{verbatim}
  3011. symbolic set!-trace!-factor(<number>,<filename>);
  3012. \end{verbatim}
  3013. where useful numbers are 1,2,3 and 100,101,... . This facility is
  3014. intended to make it possible to discover in fairly great detail what just
  3015. some small part of the code has been doing - the numbers refer mainly to
  3016. depths of recursion when the factorizer calls itself, and to the split
  3017. between its work forming and factorizing images and reconstructing full
  3018. factors from these. If {\tt NIL} is used in place of a filename the trace
  3019. output requested is directed to the standard output stream. After use of
  3020. this trace facility the generated trace files should be closed by calling
  3021. \begin{verbatim}
  3022. symbolic close!-trace!-files();
  3023. \end{verbatim}
  3024. {\it CAUTION:} The factorization code is very large, and therefore takes
  3025. considerable time to load. As a result, there is some delay when the
  3026. factorizer is first used. In addition, using the factorizer with {\tt
  3027. MCD} \ttindex{MCD} off will result in an error.
  3028. \section{Cancellation of Common Factors}
  3029. Facilities are available in {\REDUCE} for cancelling common factors in the
  3030. numerators and denominators of expressions, at the option of the user. The
  3031. system will perform this greatest common divisor computation if the switch
  3032. {\tt GCD} \ttindex{GCD} is on. ({\tt GCD} is normally off.)
  3033. A check is automatically made, however, for common variable and numerical
  3034. products in the numerators and denominators of expressions, and the
  3035. appropriate cancellations made.
  3036. When {\tt GCD} is on, and {\tt EXP} is off, a check is made for square
  3037. free factors in an expression. This includes separating out and
  3038. independently checking the content of a given polynomial where
  3039. appropriate. (For an explanation of these terms, see Anthony C. Hearn,
  3040. ``Non-Modular Computation of Polynomial GCDs Using Trial Division", Proc.
  3041. EUROSAM 79, published as Lecture Notes on Comp. Science, Springer-Verlag,
  3042. Berlin, No 72 (1979) 227-239.)
  3043. {\it Example:} With {\tt EXP} \ttindex{EXP} off and {\tt GCD} \ttindex{GCD}
  3044. on,
  3045. the polynomial {\tt a*c+a*d+b*c+b*d} would be returned as {\tt (A+B)*(C+D)}.
  3046. Under normal circumstances, GCDs are computed using an algorithm described
  3047. in the above paper. It is also possible in {\REDUCE} to compute gcd's using
  3048. an alternative algorithm, called the EZGCD Algorithm, which uses modular
  3049. arithmetic. The switch {\tt EZGCD} \ttindex{EZGCD}, if on in addition to
  3050. {\tt GCD}, makes this happen.
  3051. In non-trivial cases, the EZGCD algorithm is almost always better
  3052. than the basic algorithm, often by orders of magnitude. We therefore
  3053. {\em strongly} advise users to use the {\tt EZGCD} switch where they have the
  3054. resources available for supporting the package.
  3055. For a description of the EZGCD algorithm, see J. Moses and D.Y.Y. Yun,
  3056. ``The EZ GCD Algorithm", Proc. ACM 1973, ACM, New York (1973) 159-166.
  3057. {\it CAUTION:} The code for the EZGCD package is quite large. Consequently,
  3058. there is usually a delay when it is first used while that module is
  3059. loaded. Note also that this package shares code with the factorizer, so a
  3060. certain amount of trace information can be produced using the factorizer
  3061. trace switches.
  3062. \subsection{Determining the GCD of Two Polynomials}
  3063. This operator, used with the syntax
  3064. \begin{verbatim}
  3065. GCD(EXPRN1:polynomial,EXPRN2:polynomial):polynomial,
  3066. \end{verbatim}
  3067. returns the greatest common divisor of the two polynomials {\tt EXPRN1} and
  3068. {\tt EXPRN2}.
  3069. {\it Examples:}
  3070. \begin{verbatim}
  3071. gcd(x^2+2*x+1,x^2+3*x+2) -> X+1
  3072. gcd(2*x^2-2*y^2,4*x+4*y) -> 2*X+2*Y
  3073. gcd(x^2+y^2,x-y) -> 1.
  3074. \end{verbatim}
  3075. \section{Working with Least Common Multiples}
  3076. Greatest common divisor calculations can often become expensive if
  3077. extensive work with large rational expressions is required. However, in
  3078. many cases, the only significant cancellations arise from the fact that
  3079. there are often common factors in the various denominators which are
  3080. combined when two rationals are added. Since these denominators tend to be
  3081. smaller and more regular in structure than the numerators, considerable
  3082. savings in both time and space can occur if a full GCD check is made when
  3083. the denominators are combined and only a partial check when numerators are
  3084. constructed. In other words, the true least common multiple of the
  3085. denominators is computed at each step. The switch {\tt LCM} \ttindex{LCM}
  3086. is available for this purpose, and is normally on.
  3087. In addition, the operator {\tt LCM}, \ttindex{LCM} used with the syntax
  3088. \begin{verbatim}
  3089. LCM(EXPRN1:polynomial,EXPRN2:polynomial):polynomial,
  3090. \end{verbatim}
  3091. returns the least common multiple of the two polynomials {\tt EXPRN1} and
  3092. {\tt EXPRN2}.
  3093. {\it Examples:}
  3094. \begin{verbatim}
  3095. lcm(x^2+2*x+1,x^2+3*x+2) -> X**3 + 4*X**2 + 5*X + 2
  3096. lcm(2*x^2-2*y^2,4*x+4*y) -> 4*(X**2 - Y**2)
  3097. \end{verbatim}
  3098. \section{Controlling Use of Common Denominators}
  3099. When two rational functions are added, {\REDUCE} normally produces an
  3100. expression over a common denominator. However, if the user does not want
  3101. denominators combined, he or she can turn off the switch {\tt MCD}
  3102. \ttindex{MCD} which controls this process. The latter switch is
  3103. particularly useful if no greatest common divisor calculations are
  3104. desired, or excessive differentiation of rational functions is required.
  3105. {\it CAUTION:} With {\tt MCD} off, results are not guaranteed to come out in
  3106. either normal or canonical form. In other words, an expression equivalent
  3107. to zero may in fact not be simplified to zero. This option is therefore
  3108. most useful for avoiding expression swell during intermediate parts of a
  3109. calculation.
  3110. {\tt MCD}\ttindex{MCD} is normally on.
  3111. \section{REMAINDER Operator}\ttindex{REMAINDER}
  3112. This operator is used with the syntax
  3113. \begin{verbatim}
  3114. REMAINDER(EXPRN1:polynomial,EXPRN2:polynomial):polynomial.
  3115. \end{verbatim}
  3116. It returns the remainder when {\tt EXPRN1} is divided by {\tt EXPRN2}. This
  3117. is the true remainder based on the internal ordering of the variables, and
  3118. not the pseudo-remainder.
  3119. {\it Examples:}
  3120. \begin{verbatim}
  3121. remainder((x+y)*(x+2*y),x+3*y) -> 2*Y**2
  3122. remainder(2*x+y,2) -> Y.
  3123. \end{verbatim}
  3124. \section{RESULTANT Operator}\ttindex{RESULTANT}
  3125. This is used with the syntax
  3126. \begin{verbatim}
  3127. RESULTANT(EXPRN1:polynomial,EXPRN2:polynomial,VAR:kernel):
  3128. polynomial.
  3129. \end{verbatim}
  3130. It computes the resultant of the two given polynomials with respect to the
  3131. given variable. The result can be identified as the determinant of a
  3132. Sylvester matrix, but can often also be thought of informally as the
  3133. result obtained when the given variable is eliminated between the two input
  3134. polynomials. If the two input polynomials have a non-trivial GCD their
  3135. resultant vanishes.
  3136. The sign conventions used by the resultant function follow those in R.
  3137. Loos, ``Computing in Algebraic Extensions" in ``Computer Algebra --- Symbolic
  3138. and Algebraic Computation", Second Ed., Edited by B. Buchberger, G.E.
  3139. Collins and R. Loos, Springer-Verlag, 1983. Namely, with {\tt A} and {\tt B}
  3140. not dependent on {\tt X}:
  3141. \newpage
  3142. \begin{verbatim}
  3143. deg(p)*deg(q)
  3144. resultant(p(x),q(x),x)= (-1) *resultant(q,p,x)
  3145. deg(p)
  3146. resultant(a,p(x),x) = a
  3147. resultant(a,b,x) = 1
  3148. \end{verbatim}
  3149. \section{DECOMPOSE Operator}\ttindex{DECOMPOSE}
  3150. The {\tt DECOMPOSE} operator takes a multivariate polynomial as argument,
  3151. and returns an expression and a list of equations from which the
  3152. original polynomial can be found by composition. Its syntax is:
  3153. \begin{verbatim}
  3154. DECOMPOSE(EXPRN:polynomial):list.
  3155. \end{verbatim}
  3156. For example:
  3157. \begin{verbatim}
  3158. decompose(x^8-88*x^7+2924*x^6-43912*x^5+263431*x^4-
  3159. 218900*x^3+65690*x^2-7700*x+234)
  3160. 2 2 2
  3161. -> {U + 35*U + 234, U=V + 10*V, V=X - 22*X}
  3162. 2
  3163. decompose(u^2+v^2+2u*v+1) -> {W + 1, W=U + V}
  3164. \end{verbatim}
  3165. Users should note however than, unlike factorization, this decomposition
  3166. is not unique.
  3167. \section{INTERPOL operator}\ttindex{INTERPOL}
  3168. Syntax:
  3169. \begin{verbatim}
  3170. INTERPOL(<values>,<variable>,<points>);
  3171. \end{verbatim}
  3172. where {\tt <values>} and {\tt <points>} are lists of equal length and
  3173. {\tt <variable>} is an algebraic expression (preferably a kernel).
  3174. {\tt INTERPOL} generates an interpolation polynomial {\em f} in the given
  3175. variable of degree length({\tt <values>})-1. The unique polynomial {\em f}
  3176. is defined by the property that for corresponding elements {\em v} of
  3177. {\tt <values>} and {\em p} of {\tt <points>} the relation $f(p)=v$ holds.
  3178. The Aitken-Neville interpolation algorithm is used which guarantees a
  3179. stable result even with rounded numbers and an ill-conditioned problem.
  3180. \section{Obtaining Parts of Polynomials And Rationals}
  3181. These operators select various parts of a polynomial or rational function
  3182. structure. Except for the cost of rearrangement of the structure, these
  3183. operations take very little time to perform.
  3184. For those operators in this section that take a kernel {\tt VAR} as their
  3185. second argument, an error results if the first expression is not a
  3186. polynomial in {\tt VAR}, although the coefficients themselves can be
  3187. rational as long as they do not depend on {\tt VAR}. However, if the
  3188. switch {\tt RATARG} \ttindex{RATARG} is on, denominators are not checked
  3189. for dependence on {\tt VAR}, and are taken to be part of the coefficients.
  3190. \subsection{DEG Operator}\ttindex{DEG}
  3191. This operator is used with the syntax
  3192. \begin{verbatim}
  3193. DEG(EXPRN:polynomial,VAR:kernel):integer.
  3194. \end{verbatim}
  3195. It returns the leading degree\index{Degree} of the polynomial {\tt EXPRN}
  3196. in the variable {\tt VAR}. If {\tt VAR} does not occur as a variable in
  3197. {\tt EXPRN}, 0 is returned.
  3198. {\it Examples:}
  3199. \begin{verbatim}
  3200. deg((a+b)*(c+2*d)^2,a) -> 1
  3201. deg((a+b)*(c+2*d)^2,d) -> 2
  3202. deg((a+b)*(c+2*d)^2,e) -> 0.
  3203. \end{verbatim}
  3204. Note also that if {\tt RATARG} is on,
  3205. \begin{verbatim}
  3206. deg((a+b)^3/a,a) -> 3
  3207. \end{verbatim}
  3208. since in this case, the denominator {\tt A} is considered part of the
  3209. coefficients of the numerator in {\tt A}. With {\tt RATARG} off, however,
  3210. an error would result in this case.
  3211. \subsection{DEN Operator}\ttindex{DEN}
  3212. This is used with the syntax:
  3213. \begin{verbatim}
  3214. DEN(EXPRN:rational):polynomial.
  3215. \end{verbatim}
  3216. It returns the denominator of the rational expression {\tt EXPRN}. If
  3217. {\tt EXPRN} is a polynomial, 1 is returned.
  3218. {\it Examples:}
  3219. \begin{verbatim}
  3220. den(x/y^2) -> Y**2
  3221. den(100/6) -> 3
  3222. [since 100/6 is first simplified to 50/3]
  3223. den(a/4+b/6) -> 12
  3224. den(a+b) -> 1
  3225. \end{verbatim}
  3226. \subsection{LCOF Operator}\ttindex{LCOF}
  3227. LCOF is used with the syntax
  3228. \begin{verbatim}
  3229. LCOF(EXPRN:polynomial,VAR:kernel):polynomial.
  3230. \end{verbatim}
  3231. It returns the leading coefficient\index{Leading coefficient} of the
  3232. polynomial {\tt EXPRN} in the variable {\tt VAR}. If {\tt VAR} does not
  3233. occur as a variable in {\tt EXPRN}, {\tt EXPRN} is returned unchanged.
  3234. {\it Examples:}
  3235. \begin{verbatim}
  3236. lcof((a+b)*(c+2*d)^2,a) -> C**2+4*C*D+4*D**2
  3237. lcof((a+b)*(c+2*d)^2,d) -> 4*(A+B)
  3238. lcof((a+b)*(c+2*d),e) -> A*C+2*A*D+B*C+2*B*D
  3239. \end{verbatim}
  3240. \subsection{LTERM Operator}\ttindex{LTERM}
  3241. Syntax:
  3242. \begin{verbatim}
  3243. LTERM(EXPRN:polynomial,VAR:kernel):polynomial.
  3244. \end{verbatim}
  3245. LTERM returns the leading term of {\tt EXPRN} with respect to {\tt VAR}.
  3246. If {\tt EXPRN} does not depend on {\tt VAR}, 0 is returned.
  3247. {\it Examples:}
  3248. \begin{verbatim}
  3249. lterm((a+b)*(c+2*d)^2,a) -> A*(C**2+4*C*D+4*D**2)
  3250. lterm((a+b)*(c+2*d)^2,d) -> 4*D**2*(A+B)
  3251. lterm((a+b)*(c+2*d)^2,e) -> 0
  3252. \end{verbatim}
  3253. \subsection{MAINVAR Operator}\ttindex{MAINVAR}
  3254. Syntax:
  3255. \begin{verbatim}
  3256. MAINVAR(EXPRN:polynomial):expression.
  3257. \end{verbatim}
  3258. Returns the main variable (based on the internal polynomial representation)
  3259. of {\tt EXPRN}. If {\tt EXPRN} is a domain element, 0 is returned.
  3260. {\it Examples:}
  3261. Assuming {\tt A} has higher kernel order than {\tt B}, {\tt C}, or {\tt D}:
  3262. \begin{verbatim}
  3263. mainvar((a+b)*(c+2*d)^2) -> A
  3264. mainvar(2) -> 0
  3265. \end{verbatim}
  3266. \subsection{NUM Operator}\ttindex{NUM}
  3267. Syntax:
  3268. \begin{verbatim}
  3269. NUM(EXPRN:rational):polynomial.
  3270. \end{verbatim}
  3271. Returns the numerator of the rational expression {\tt EXPRN}. If {\tt EXPRN}
  3272. is a polynomial, that polynomial is returned.
  3273. {\it Examples:}
  3274. \begin{verbatim}
  3275. num(x/y^2) -> X
  3276. num(100/6) -> 50
  3277. num(a/4+b/6) -> 3*A+2*B
  3278. num(a+b) -> A+B
  3279. \end{verbatim}
  3280. \subsection{REDUCT Operator}\ttindex{REDUCT}
  3281. Syntax:
  3282. \begin{verbatim}
  3283. REDUCT(EXPRN:polynomial,VAR:kernel):polynomial.
  3284. \end{verbatim}
  3285. Returns the reductum of {\tt EXPRN} with respect to {\tt VAR} (i.e., the
  3286. part of {\tt EXPRN} left after the leading term is removed). If {\tt
  3287. EXPRN} does not depend on the variable {\tt VAR}, {\tt EXPRN} is returned.
  3288. {\it Examples:}
  3289. \begin{verbatim}
  3290. reduct((a+b)*(c+2*d),a) -> B*(C + D)
  3291. reduct((a+b)*(c+2*d),d) -> C*(A + B)
  3292. reduct((a+b)*(c+2*d),e) -> A*C + A*D + B*C + B*D
  3293. \end{verbatim}
  3294. {\COMPATNOTE} In previous versions of REDUCE, {\tt REDUCT} returned zero
  3295. if {\tt EXPRN} did not depend on {\tt VAR}. In the present version, {\tt
  3296. EXPRN} is always equal to {\tt LTERM(EXPRN,VAR)} $+$ {\tt
  3297. REDUCT(EXPRN,VAR)}.
  3298. \section{Polynomial Coefficient Arithmetic}\index{Coefficient}
  3299. {\REDUCE} allows for a variety of numerical domains for the numerical
  3300. coefficients of polynomials used in calculations. The default mode is
  3301. integer arithmetic, although the possibility of using real coefficients
  3302. \index{Real coefficient} has been discussed elsewhere. Rational
  3303. coefficients have also been available by using integer coefficients in
  3304. both the numerator and denominator of an expression, using the {\tt ON
  3305. DIV} \ttindex{DIV} option (q.v.) to print the coefficients as rationals.
  3306. However, {\REDUCE} includes several other coefficient options in its basic
  3307. version which we shall describe in this section. All such coefficient
  3308. modes are supported in a table-driven manner so that it is
  3309. straightforward to extend the range of possibilities. A description of
  3310. how to do this is given in R.J. Bradford, A.C. Hearn, J.A. Padget and
  3311. E. Schr\"ufer, ``Enlarging the {\REDUCE} Domain of Computation," Proc. of
  3312. SYMSAC '86, ACM, New York (1986), 100-106.
  3313. \subsection{Rational Coefficients in Polynomials}\index{Coefficient}
  3314. \index{Rational coefficient}
  3315. Instead of treating rational numbers as the numerator and denominator of a
  3316. rational expression, it is also possible to use them as polynomial
  3317. coefficients directly. This is accomplished by turning on the switch
  3318. {\tt RATIONAL}.\ttindex{RATIONAL}
  3319. {\it Example:} With {\tt RATIONAL} off, the input expression {\tt a/2}
  3320. would be converted into a rational expression, whose numerator was {\tt A}
  3321. and denominator 2. With {\tt RATIONAL} on, the same input would become a
  3322. rational expression with numerator {\tt 1/2*A} and denominator {\tt 1}.
  3323. Thus the latter can be used in operations that require polynomial input
  3324. whereas the former could not.
  3325. \subsection{Real Coefficients in Polynomials}\index{Coefficient}
  3326. \index{Real coefficient}
  3327. The switch {\tt ROUNDED}\ttindex{ROUNDED} permits the use of arbitrary
  3328. sized real coefficients in polynomial expressions. The actual precision
  3329. of these coefficients can be set by the operator {\tt PRECISION}.
  3330. \ttindex{PRECISION} For example, {\tt precision 50;} sets the precision to
  3331. fifty decimal digits. The default precision is system dependent and can
  3332. be found by {\tt precision 0;}. In this mode, denominators are
  3333. automatically made monic, and an appropriate adjustment is made to the
  3334. numerator.
  3335. {\it Example:} With {\tt ROUNDED} on, the input expression {\tt a/2} would
  3336. be converted into a rational expression whose numerator is {\tt 0.5*A} and
  3337. denominator {\tt 1}.
  3338. Internally, {\REDUCE} uses floating point numbers up to the precision
  3339. supported by the underlying machine hardware, and so-called {\em
  3340. bigfloats} for higher precision or whenever necessary to represent numbers
  3341. whose value cannot be represented in floating point. The internal
  3342. precision is two decimal digits greater than the external precision to
  3343. guard against roundoff inaccuracies. Bigfloats represent the fraction and
  3344. exponent parts of a floating-point number by means of (arbitrary
  3345. precision) integers, which is a more precise representation in many cases
  3346. than the machine floating point arithmetic, but not as efficient. If a
  3347. case arises where use of the machine arithmetic leads to problems, a user
  3348. can force {\REDUCE} to use the bigfloat representation at all precisions by
  3349. turning on the switch {\tt ROUNDBF}. \ttindex{ROUNDBF} In rare cases,
  3350. this switch is turned on by the system, and the user informed by the
  3351. message
  3352. \begin{verbatim}
  3353. ROUNDBF turned on to increase accuracy
  3354. \end{verbatim}
  3355. Rounded numbers are normally printed to the specified precision. However,
  3356. if the user wishes to print such numbers with less precision, the printing
  3357. precision can be set by the command {\tt PRINT\_PRECISION}.
  3358. \index{Print precision} For example, {\tt print\_precision 5;} will
  3359. cause such numbers to be printed with five digits maximum.
  3360. Numbers that are stored internally as bigfloats are normally printed with
  3361. a space between every five digits to improve readability. If this
  3362. feature is not required, it can be suppressed by turning off the switch
  3363. {\tt BFSPACE}. \ttindex{BFSPACE}
  3364. Further information on the bigfloat arithmetic may be found in T. Sasaki,
  3365. ``Manual for Arbitrary Precision Real Arithmetic System in {\REDUCE}",
  3366. Department of Computer Science, University of Utah, Technical Note No.
  3367. TR-8 (1979).
  3368. When a real number is input, it is normally truncated to the precision in
  3369. effect at the time the number is read. If it is desired to keep the full
  3370. precision of all numbers input, the switch {\tt ADJPREC} \ttindex{ADJPREC}
  3371. (for {\em adjust precision}) can be turned on. While on, {\tt ADJPREC}
  3372. will automatically increase the precision, when necessary, to match that
  3373. of any integer or real input, and a message printed to inform the user of
  3374. the precision increase.
  3375. When {\tt ROUNDED} is on, rational numbers are normally converted to
  3376. rounded representation. However, if a user wishes to keep such numbers in
  3377. a rational form until used in an operation that returns a real number,
  3378. the switch {\tt ROUNDALL} \ttindex{ROUNDALL} can be turned off. This
  3379. switch is normally on.
  3380. Results from rounded calculations are returned in rounded form with two
  3381. exceptions: if the result is recognized as {\tt 0} or {\tt 1} to the
  3382. current precision, the integer result is returned.
  3383. \COMPATNOTE In previous versions of {\REDUCE}, there were two
  3384. switches to control the use of floating point arithmetic, namely {\tt
  3385. FLOAT} \ttindex{FLOAT} and {\tt BIGFLOAT}. \ttindex{BIGFLOAT} This reflected
  3386. the fact that there was a distinction at the {\em user} level between single
  3387. and multiple precision real arithmetic. This distinction has been removed
  3388. in the present version, as described above, by the introduction of the
  3389. {\tt ROUNDED} switch, with the actual precision controlled by the {\tt
  3390. PRECISION} command. For compatibility, the {\tt FLOAT} and {\tt BIGFLOAT}
  3391. switches are still supported. However, they default to the use of
  3392. {\tt ROUNDED} mode, and so results may be different from previous
  3393. versions, since the algorithms used have changed.
  3394. \subsection{Modular Number Coefficients in Polynomials}\index{Coefficient}
  3395. \index{Modular coefficient}
  3396. {\REDUCE} includes facilities for manipulating polynomials whose
  3397. coefficients are computed modulo a given base. To use this option, two
  3398. commands must be used; {\tt SETMOD} {\tt <integer>},\ttindex{SETMOD} to set
  3399. the prime modulus, and {\tt ON MODULAR}\ttindex{MODULAR} to cause the
  3400. actual modular calculations to occur.
  3401. For example, with {\tt setmod 3;} and {\tt on modular;}, the polynomial
  3402. {\tt (a+2*b)$^{ }$3} would become {\tt A\^{ }3+2*B\^{ }3}.
  3403. The argument of {\tt SETMOD} is evaluated algebraically, except that
  3404. non-modular (integer) arithmetic is used. Thus the sequence
  3405. \begin{verbatim}
  3406. setmod 3; on modular; setmod 7;
  3407. \end{verbatim}
  3408. will correctly set the modulus to 7.
  3409. Users should note that the modular calculations are on the polynomial
  3410. coefficients only. It is not currently possible to reduce the exponents
  3411. since no check for a prime modulus is made (which would allow
  3412. $x^{p-1}$ to be reduced to 1 mod p). Note also that any division by a
  3413. number not co-prime with the modulus will result in the error ``Invalid
  3414. modular division".
  3415. \subsection{Complex Number Coefficients in Polynomials}\index{Coefficient}
  3416. \index{Complex coefficient}
  3417. Although {\REDUCE} routinely treats the square of the variable {\em i} as
  3418. equivalent to $-1$, this is not sufficient to reduce expressions involving
  3419. {\em i} to lowest terms, or to factor such expressions over the complex
  3420. numbers. For example, in the default case,
  3421. \begin{verbatim}
  3422. factorize(a^2+1);
  3423. \end{verbatim}
  3424. gives the result
  3425. \begin{verbatim}
  3426. {A**2+1}
  3427. \end{verbatim}
  3428. and
  3429. \begin{verbatim}
  3430. (a^2+b^2)/(a+i*b)
  3431. \end{verbatim}
  3432. is not reduced further. However, if the switch
  3433. {\tt COMPLEX} \ttindex{COMPLEX} is turned on, full complex arithmetic is then
  3434. carried out. In other words, the above factorization will give the result
  3435. \begin{verbatim}
  3436. {A - I,A + I}
  3437. \end{verbatim}
  3438. and the quotient will be reduced to {\tt A-I*B}.
  3439. The switch {\tt COMPLEX} may be combined with {\tt ROUNDED} to give complex
  3440. real numbers; the appropriate arithmetic is performed in this case.
  3441. Complex conjugation is used to remove complex numbers from denominators of
  3442. expressions. To do this if {\tt COMPLEX} is off, you must turn the switch
  3443. {\tt RATIONALIZE} \ttindex{RATIONALIZE} on.
  3444. \chapter{Substitution Commands} \index{Substitution}
  3445. An important class of commands in {\REDUCE} is that which defines
  3446. substitutions for variables and expressions to be made during the
  3447. evaluation of expressions. Such substitutions use the prefix operator
  3448. {\tt SUB}, various forms of the command {\tt LET}, and rule sets.
  3449. \section{SUB Operator} \ttindex{SUB}
  3450. Syntax:
  3451. \begin{verbatim}
  3452. SUB(<substitution_list>,EXPRN1:algebraic):algebraic
  3453. \end{verbatim}
  3454. where {\tt <substitution\_list>} is a list of one or more equations of the
  3455. form
  3456. \begin{verbatim}
  3457. VAR:kernel=EXPRN:algebraic
  3458. \end{verbatim}
  3459. or a kernel that evaluates to such a list.
  3460. The {\tt SUB} operator gives the algebraic result of replacing every
  3461. occurrence of the variable {\tt VAR} in the expression {\tt EXPRN1} by the
  3462. expression {\tt EXPRN}. Specifically, {\tt EXPRN1} is first evaluated
  3463. using all available rules. Next the substitutions are made, and finally
  3464. the substituted expression is reevaluated. When more than one variable
  3465. occurs in the substitution list, the substitution is performed by
  3466. recursively walking down the tree representing {\tt EXPRN1}, and replacing
  3467. every {\tt VAR} found by the appropriate {\tt EXPRN}. The {\tt EXPRN} are
  3468. not themselves searched for any occurrences of the various {\tt VAR}s.
  3469. The trivial case {\tt SUB(EXPRN1)} returns the algebraic value of
  3470. {\tt EXPRN1}.
  3471. {\it Examples:}
  3472. \begin{verbatim}
  3473. 2 2
  3474. sub({x=a+y,y=y+1},x^2+y^2) -> A + 2*A*Y + 2*Y + 2*Y + 1
  3475. \end{verbatim}
  3476. and with {\tt s := {x=a+y,y=y+1}},
  3477. \begin{verbatim}
  3478. 2 2
  3479. sub(s,x^2+y^2) -> A + 2*A*Y + 2*Y + 2*Y + 1
  3480. \end{verbatim}
  3481. Note that the global assignments {\tt x:=a+y}, etc., do not take place.
  3482. {\tt EXPRN1} can be any valid algebraic expression whose type is such that
  3483. a substitution process is defined for it (e.g., scalar expressions, lists
  3484. and matrices). An error will occur if an expression of an invalid type
  3485. for substitution occurs either in {\tt EXPRN} or {\tt EXPRN1}.
  3486. The braces around the substitution list may also be omitted, as in:
  3487. \begin{verbatim}
  3488. 2 2
  3489. sub(x=a+y,y=y+1,x^2+y^2) -> A + 2*A*Y + 2*Y + 2*Y + 1
  3490. \end{verbatim}
  3491. \section{LET Rules} \ttindex{LET}
  3492. Unlike substitutions introduced via {\tt SUB} {\tt LET}
  3493. rules are global in scope and stay in effect until replaced or {\tt CLEAR}ed.
  3494. The simplest use of the {\tt LET} statement is in the form
  3495. \begin{verbatim}
  3496. LET <substitution list>
  3497. \end{verbatim}
  3498. where {\tt <substitution list>} is a list of rules separated by commas, each
  3499. of the form:
  3500. \begin{verbatim}
  3501. <variable> = <expression>
  3502. \end{verbatim}
  3503. or
  3504. \begin{verbatim}
  3505. <prefix operator>(<argument>,...,<argument>) = <expression>
  3506. \end{verbatim}
  3507. or
  3508. \begin{verbatim}
  3509. <argument> <infix operator>,..., <argument> = <expression>
  3510. \end{verbatim}
  3511. For example,
  3512. \begin{verbatim}
  3513. let {x = y^2,
  3514. h(u,v) = u - v,
  3515. cos(pi/3) = 1/2,
  3516. a*b = c,
  3517. l+m = n,
  3518. w^3 = 2*z - 3,
  3519. z^10 = 0}
  3520. \end{verbatim}
  3521. The list brackets can be left out if preferred. The above rules could
  3522. also have been entered as seven separate {\tt LET} statements.
  3523. After such {\tt LET} rules have been input, {\tt X} will always be
  3524. evaluated as the square of {\tt Y}, and so on. This is so even if at the
  3525. time the {\tt LET} rule was input, the variable {\tt Y} had a value other
  3526. than {\tt Y}. (In contrast, the assignment {\tt x:=y\^{ }2} will set {\tt X}
  3527. equal to the square of the current value of {\tt Y}, which could be quite
  3528. different.)
  3529. The rule {\tt let a*b=c} means that whenever {\tt A} and {\tt B} are both
  3530. factors in an expression their product will be replaced by {\tt C}. For
  3531. example, {\tt a\^{ }5 *} {\tt b\^{ }*w} would be replaced by
  3532. {\tt c\^{ }*b\^{ }2*w}.
  3533. The rule for {\tt l+m} will not only replace all occurrences of {\tt l+m}
  3534. by {\tt N}, but will also normally replace {\tt L} by {\tt n-m}, but not
  3535. {\tt M} by {\tt n-l}. A more complete description of this case is given
  3536. in Section~\ref{sec-gensubs}.
  3537. The rule pertaining to {\tt w\^{ }3} will apply to any power of {\tt W}
  3538. greater than or equal to the third.
  3539. Note especially the last example, {\tt let z\^{ }10=0}. This declaration
  3540. means, in effect: ignore the tenth or any higher power of {\tt Z}. Such
  3541. declarations, when appropriate, often speed up a computation to a
  3542. considerable degree. (See \index{Asymptotic command}
  3543. Asymptotic Commands for more details.)
  3544. Any new operators occurring in such {\tt LET} rules will be automatically
  3545. declared {\tt OPERATOR} by the system, if the rules are being read from a
  3546. file. If they are being entered interactively, the system will ask
  3547. {\tt DECLARE} ... {\tt OPERATOR?} . Answer {\tt Y} or {\tt N} and hit RETURN.
  3548. In each of these examples, substitutions are only made for the explicit
  3549. expressions given; i.e., none of the variables may be considered arbitrary
  3550. in any sense. For example, the command
  3551. \begin{verbatim}
  3552. let h(u,v) = u - v;
  3553. \end{verbatim}
  3554. will cause {\tt h(u,v)} to evaluate to {\tt U - V}, but will not affect
  3555. {\tt h(u,z)} or {\tt H} with any arguments other than precisely the
  3556. symbols {\tt U,V}.
  3557. These simple {\tt LET} rules are on the same logical level as assignments
  3558. made with the := operator. An assignment {\tt x := p+q} cancels a rule
  3559. {\tt let x = y\^{ }2} made earlier, and vice versa.
  3560. {\it CAUTION:} A recursive rule such as
  3561. \begin{verbatim}
  3562. let x = x + 1;
  3563. \end{verbatim}
  3564. is erroneous, since any subsequent evaluation of {\tt X} would lead to a
  3565. non-terminating chain of substitutions:
  3566. \begin{verbatim}
  3567. x -> x + 1 -> (x + 1) + 1 -> ((x + 1) + 1) + 1 -> ...
  3568. \end{verbatim}
  3569. Similarly, coupled substitutions such as
  3570. \begin{verbatim}
  3571. let l = m + n, n = l + r;
  3572. \end{verbatim}
  3573. would lead to the same error. As a result, if you try to evaluate an {\tt X},
  3574. {\tt L} or {\tt N} defined as above, you will get an error such as
  3575. \begin{verbatim}
  3576. X improperly defined in terms of itself
  3577. \end{verbatim}
  3578. Array and matrix elements can appear on the left-hand side of a {\tt LET}
  3579. statement. However, because of their ``instant evaluation'' property, it is
  3580. the value of the element that is substituted for, rather than the element
  3581. itself. E.g.,
  3582. \begin{verbatim}
  3583. array a(5);
  3584. a(2) := b;
  3585. let a(2) = c;
  3586. \end{verbatim}
  3587. results in {\tt B} being substituted by {\tt C}; the assignment for
  3588. {\tt a(2)} does not change.
  3589. Finally, if an error occurs in any equation in a {\tt LET} statement
  3590. (including generalized statements involving {\tt FOR ALL} and {\tt SUCH
  3591. THAT)}, the remaining rules are not evaluated.
  3592. \subsection{FOR ALL \ldots LET} \ttindex{FOR ALL}
  3593. If a substitution for all possible values of a given argument of an
  3594. operator is required, the declaration {\tt FOR ALL} may be used. The
  3595. syntax of such a command is
  3596. \begin{verbatim}
  3597. FOR ALL <variable>,...,<variable>
  3598. <LET statement> <terminator>
  3599. \end{verbatim}
  3600. e.g.,
  3601. \begin{verbatim}
  3602. for all x,y let h(x,y) = x-y;
  3603. for all x let k(x,y) = x^y;
  3604. \end{verbatim}
  3605. The first of these declarations would cause {\tt h(a,b)} to be evaluated
  3606. as {\tt A-B}, {\tt h(u+v,u+w)} to be {\tt V-W}, etc. If the operator
  3607. symbol {\tt H} is used with more or fewer argument places, not two, the
  3608. {\tt LET} would have no effect, and no error would result.
  3609. The second declaration would cause {\tt k(a,y)} to be evaluated as
  3610. {\tt a\^{ }y}, but would have no effect on {\tt k(a,z)} since the rule
  3611. didn't say {\tt FOR ALL Y} ... .
  3612. Where we used {\tt X} and {\tt Y} in the examples, any variables could
  3613. have been used. This use of a variable doesn't affect the value it may
  3614. have outside the {\tt LET} statement. However, you should remember what
  3615. variables you actually used. If you want to delete the rule subsequently,
  3616. you must use the same variables in the {\tt CLEAR} command (q.v.).
  3617. It is possible to use more complicated expressions as a template for a
  3618. {\tt LET} statement, as explained in the section on substitutions for
  3619. general expressions. In nearly all cases, the rule will be accepted, and
  3620. a consistent application made by the system. However, if there is a sole
  3621. constant or a sole free variable on the left-hand side of a rule (e.g.,
  3622. {\tt let 2=3} or {\tt for all x let x=2)}, then the system is unable to
  3623. handle the rule, and the error message
  3624. \begin{verbatim}
  3625. Substitution for ... not allowed
  3626. \end{verbatim}
  3627. will be issued. Any variable listed in the {\tt FOR ALL} part will have
  3628. its symbol preceded by an equal sign: {\tt X} in the above example will
  3629. appear as {\tt =X}. An error will also occur if a variable in the
  3630. {\tt FOR ALL} part is not properly matched on both sides of the {\tt LET}
  3631. equation.
  3632. \subsection{FOR ALL \ldots SUCH THAT \ldots LET}
  3633. \ttindex{FOR ALL} \ttindex{SUCH THAT}
  3634. If a substitution is desired for more than a single value of a variable in
  3635. an operator or other expression, but not all values, a conditional form of
  3636. the {\tt FOR ALL \ldots LET} declaration can be used.
  3637. {\it Example:}
  3638. \begin{verbatim}
  3639. for all x such that numberp x and x<0 let h(x)=0;
  3640. \end{verbatim}
  3641. will cause {\tt h(-5)} to be evaluated as 0, but {\tt H} of a positive
  3642. integer, or of an argument which is not an integer at all, would not be
  3643. affected. Any boolean expression can follow the {\tt SUCH THAT} keywords.
  3644. \subsection{Removing Assignments and Substitution Rules} \ttindex{CLEAR}
  3645. The user may remove all assignments and substitution rules from any
  3646. expression by the command {\tt CLEAR}, in the form
  3647. \begin{verbatim}
  3648. CLEAR <expression>,...,<expression><terminator>
  3649. \end{verbatim}
  3650. e.g.
  3651. \begin{verbatim}
  3652. clear x, h(x,y);
  3653. \end{verbatim}
  3654. Because of their ``instant evaluation" property, array and matrix elements
  3655. cannot be cleared with {\tt CLEAR}. For example, if {\tt A} is an array,
  3656. you must say
  3657. \begin{verbatim}
  3658. a(3) := 0;
  3659. \end{verbatim}
  3660. rather than
  3661. \begin{verbatim}
  3662. clear a(3);
  3663. \end{verbatim}
  3664. to ``clear" element {\tt a(3)}.
  3665. On the other hand, a whole array (or matrix) {\tt A} can be cleared by the
  3666. command {\tt clear a}; This means much more than resetting to 0 all the
  3667. elements of {\tt A}. The fact that {\tt A} is an array, and what its
  3668. dimensions are, are forgotten, so {\tt A} can be redefined as another type
  3669. of object, for example an operator.
  3670. The more general types of {\tt LET} declarations can also be deleted by
  3671. using {\tt CLEAR}. Simply repeat the {\tt LET} rule to be deleted, using
  3672. {\tt CLEAR} in place of {\tt LET}, and omitting the equal sign and
  3673. right-hand part. The same dummy variables must be used in the {\tt FOR
  3674. ALL} part, and the boolean expression in the {\tt SUCH THAT} part must be
  3675. written the same way. (The placing of blanks doesn't have to be
  3676. identical.)
  3677. {\it Example:} The {\tt LET} rule
  3678. \begin{verbatim}
  3679. for all x such that numberp x and x<0 let h(x)=0;
  3680. \end{verbatim}
  3681. can be erased by the command
  3682. \begin{verbatim}
  3683. for all x such that numberp x and x<0 clear h(x);
  3684. \end{verbatim}
  3685. \subsection{Overlapping LET Rules}
  3686. {\tt CLEAR} is not the only way to delete a {\tt LET} rule. A new {\tt
  3687. LET} rule identical to the first, but with a different expression after
  3688. the equal sign, replaces the first. Replacements are also made in other
  3689. cases where the existing rule would be in conflict with the new rule. For
  3690. example, a rule for {\tt x\^{ }4} would replace a rule for {\tt x\^{ }5}.
  3691. The user should however be cautioned against having several {\tt LET}
  3692. rules in effect which relate to the same expression. No guarantee can be
  3693. given as to which rules will be applied by {\REDUCE} or in what order. It
  3694. is best to {\tt CLEAR} an old rule before entering a new related {\tt LET}
  3695. rule.
  3696. \subsection{Substitutions for General Expressions}
  3697. \label{sec-gensubs}
  3698. The examples of substitutions discussed in other sections have involved
  3699. very simple rules. However, the substitution mechanism used in {\REDUCE} is
  3700. very general, and can handle arbitrarily complicated rules without
  3701. difficulty.
  3702. The general substitution mechanism used in {\REDUCE} is discussed in Hearn, A.
  3703. C., ``{\REDUCE}, A User-Oriented Interactive System for Algebraic
  3704. Simplification,'' Interactive Systems for Experimental Applied Mathematics,
  3705. (edited by M. Klerer and J. Reinfelds), Academic Press, New York (1968),
  3706. 79-90, and Hearn. A. C., ``The Problem of Substitution,'' Proc. 1968 Summer
  3707. Institute on Symbolic Mathematical Computation, IBM Programming Laboratory
  3708. Report FSC 69-0312 (1969).
  3709. For the reasons given in these references, {\REDUCE} does not attempt to
  3710. implement a general pattern matching algorithm. However, the present
  3711. system uses far more sophisticated techniques than those discussed in the
  3712. above papers. It is now possible for the rules appearing in arguments of
  3713. {\tt LET} to have the form
  3714. \begin{verbatim}
  3715. <substitution expression> = <expression>
  3716. \end{verbatim}
  3717. where any rule to which a sensible meaning can be assigned is permitted.
  3718. However, this meaning can vary according to the form of {\tt <substitution
  3719. expression>}. The semantic rules associated with the application of the
  3720. substitution are completely consistent, but somewhat complicated by the
  3721. pragmatic need to perform such substitutions as efficiently as possible.
  3722. The following rules explain how the majority of the cases are handled.
  3723. To begin with, the {\tt <substitution expression>} is first partly simplified
  3724. by collecting like terms and putting identifiers (and kernels) in the
  3725. system order. However, no substitutions are performed on any part of the
  3726. expression with the exception of expressions with the ``instant evaluation"
  3727. property, such as array and matrix elements, whose actual values are used.
  3728. It should also be noted that the system order used is not changeable by the
  3729. user, even with the {\tt KORDER} command. Specific cases are then handled as
  3730. follows:
  3731. \begin{enumerate}
  3732. \item If the resulting simplified rule has a left-hand side which is an
  3733. identifier, an expression with a top-level algebraic operator or a power,
  3734. then the rule is added without further change to the appropriate table.
  3735. \item If the operator * appears at the top level of the simplified left-hand
  3736. side, then any constant arguments in that expression are moved to the
  3737. right-hand side of the rule. The remaining left-hand side is then added
  3738. to the appropriate table. For example,
  3739. \begin{verbatim}
  3740. let 2*x*y=3
  3741. \end{verbatim}
  3742. becomes
  3743. \begin{verbatim}
  3744. let x*y=3/2
  3745. \end{verbatim}
  3746. so that {\tt x*y} is added to the product substitution table, and when
  3747. this rule is applied, the expression {\tt x*y} becomes 3/2, but {\tt X} or
  3748. {\tt Y} by themselves are not replaced.
  3749. \item If the operators {\tt +}, {\tt -} or {\tt /} appear at the top level
  3750. of the simplified left-hand side, all but the first term is moved to the
  3751. right-hand side of the rule. Thus the rules
  3752. \begin{verbatim}
  3753. let l+m=n, x/2=y, a-b=c
  3754. \end{verbatim}
  3755. become
  3756. \begin{verbatim}
  3757. let l=n-m, x=2*y, a=c+b.
  3758. \end{verbatim}
  3759. \end{enumerate}
  3760. One problem that can occur in this case is that if a quantified expression
  3761. is moved to the right-hand side, a given free variable might no longer
  3762. appear on the left-hand side, resulting in an error because of the
  3763. unmatched free variable. E.g.,
  3764. \begin{verbatim}
  3765. for all x,y let f(x)+f(y)=x*y
  3766. \end{verbatim}
  3767. would become
  3768. \begin{verbatim}
  3769. for all x,y let f(x)=x*y-f(y)
  3770. \end{verbatim}
  3771. which no longer has {\tt Y} on both sides.
  3772. The fact that array and matrix elements are evaluated in the left-hand side
  3773. of rules can lead to confusion at times. Consider for example the
  3774. statements
  3775. \begin{verbatim}
  3776. array a(5); let x+a(2)=3; let a(3)=4;
  3777. \end{verbatim}
  3778. The left-hand side of the first rule will become {\tt X}, and the second
  3779. 0. Thus the first rule will be instantiated as a substitution for
  3780. {\tt X}, and the second will result in an error.
  3781. The order in which a set of rules is applied is not easily understandable
  3782. without a detailed knowledge of the system simplification protocol. It is
  3783. also possible for this order to change from release to release, as improved
  3784. substitution techniques are implemented. Users should therefore assume
  3785. that the order of application of rules is arbitrary, and program
  3786. accordingly.
  3787. After a substitution has been made, the expression being evaluated is
  3788. reexamined in case a new allowed substitution has been generated. This
  3789. process is continued until no more substitutions can be made.
  3790. As mentioned elsewhere, when a substitution expression appears in a
  3791. product, the substitution is made if that expression divides the product.
  3792. For example, the rule
  3793. \begin{verbatim}
  3794. let a^c = 3*z;
  3795. \end{verbatim}
  3796. would cause {\tt a\^{ }2*c*x} to be replaced by {\tt 3*Z*X} and
  3797. {\tt a\^{ }2*c\^{ }2} by {\tt 3*Z*C}. If the substitution is desired only
  3798. when the substitution expression appears in a product with the explicit
  3799. powers supplied in the rule, the command {\tt MATCH} should be used
  3800. instead. \ttindex{MATCH}
  3801. For example,
  3802. \begin{verbatim}
  3803. match a^2*c = 3*z;
  3804. \end{verbatim}
  3805. would cause {\tt a\^{ }2*c*x} to be replaced by {\tt 3*Z*X}, but
  3806. {\tt a\^{ }2*c\^{ }2} would not be replaced. {\tt MATCH} can also be used
  3807. with the {\tt FOR ALL} constructions described above.
  3808. To remove substitution rules of the type discussed in this section, the
  3809. {\tt CLEAR} \ttindex{CLEAR} command can be used, combined, if necessary,
  3810. with the same {\tt FOR ALL} clause with which the rule was defined, for
  3811. example:
  3812. \begin{verbatim}
  3813. for all x clear log(e^x),e^log(x),cos(w*t+theta(x));
  3814. \end{verbatim}
  3815. Note, however, that the arbitrary variable names in this case {\em must}
  3816. be the same as those used in defining the substitution.
  3817. \section{Rule Lists} \index{Rule Lists}
  3818. Rule lists offer an alternative approach to defining substitutions that is
  3819. different from either {\tt SUB} or {\tt LET}. In fact, they provide the
  3820. best features of both, since they have all the capabilities of {\tt LET},
  3821. but the rules can also be applied locally as is possible with {\tt SUB}.
  3822. In time, they will be used more and more in {\REDUCE}. However, since they
  3823. are relatively new, most {\REDUCE} code you see uses the older constructs.
  3824. A rule list is a list of {\em rules} that have the syntax
  3825. \begin{verbatim}
  3826. <expression> => <expression> (WHEN <boolean expression>)
  3827. \end{verbatim}
  3828. For example,
  3829. \begin{verbatim}
  3830. {cos(~x)*cos(~y) => (cos(x+y)+cos(x-y))/2,
  3831. cos(~n*pi) => (-1)^n when remainder(n,2)=0}
  3832. \end{verbatim}
  3833. The tilde preceding a variable marks that variable as {\em free} for that
  3834. rule, much as a variable in a {\tt FOR ALL} clause in a {\tt LET}
  3835. statement. The first occurrence of that variable in each relevant rule
  3836. must be so marked on input, otherwise inconsistent results can occur.
  3837. For example, the rule list
  3838. \begin{verbatim}
  3839. {cos(~x)*cos(~y) => (cos(x+y)+cos(x-y))/2,
  3840. cos(x)^2 => (1+cos(2x))/2}
  3841. \end{verbatim}
  3842. designed to replace products of cosines, would not be correct, since the
  3843. second rule would only apply to the explicit argument {\tt X}. Later
  3844. occurrences in the same rule may also be marked, but this is optional
  3845. (internally, all such rules are stored with each relevant variable
  3846. explicitly marked). The optional {\tt WHEN} \ttindex{WHEN} clause allows
  3847. constraints to be placed on the application of the rule, much as the {\tt
  3848. SUCH THAT} clause in a {\tt LET} statement.
  3849. A rule set may be named, for example
  3850. \begin{verbatim}
  3851. trig1 := {cos(~x)*cos(~y) => (cos(x+y)+cos(x-y))/2,
  3852. cos(~x)*sin(~y) => (sin(x+y)-sin(x-y))/2,
  3853. sin(~x)*sin(~y) => (cos(x-y)-cos(x+y))/2,
  3854. cos(~x)^2 => (1+cos(2*x))/2,
  3855. sin(~x)^2 => (1-cos(2*x))/2};
  3856. \end{verbatim}
  3857. Such named rule lists may be inspected as needed. E.g., the command
  3858. {\tt trig1;} would cause the above list to be printed.
  3859. Rule lists may be used in two ways. They can be globally instantiated by
  3860. means of the command {\tt LET}.\ttindex{LET} For example,
  3861. \begin{verbatim}
  3862. let trig1;
  3863. \end{verbatim}
  3864. would cause the above set of rules to be globally active from then on until
  3865. cancelled by the command {\tt CLEARRULES}, \ttindex{CLEARRULES} as in
  3866. \begin{verbatim}
  3867. clearrules trig1;
  3868. \end{verbatim}
  3869. {\tt CLEARRULES} has the syntax
  3870. \begin{verbatim}
  3871. CLEARRULES <rule list>|<name of rule list>(,...) .
  3872. \end{verbatim}
  3873. The second way to use rule lists is to invoke them locally by means of a
  3874. {\tt WHERE} \ttindex{WHERE} clause. For example
  3875. \begin{verbatim}
  3876. cos(a)*cos(b+c)
  3877. where {cos(~x)*cos(~y) => (cos(x+y)+cos(x-y))/2};
  3878. \end{verbatim}
  3879. or
  3880. \begin{verbatim}
  3881. cos(a)*sin(b) where trigrules;
  3882. \end{verbatim}
  3883. The syntax of an expression with a {\tt WHERE} clause is:
  3884. \begin{verbatim}
  3885. <expression>
  3886. WHERE <rule>|<rule list>(,<rule>|<rule list> ...)
  3887. \end{verbatim}
  3888. so the first example above could also be written
  3889. \begin{verbatim}
  3890. cos(a)*cos(b+c)
  3891. where cos(~x)*cos(~y) => (cos(x+y)+cos(x-y))/2;
  3892. \end{verbatim}
  3893. The effect of this construct is that the rule set(s) in the {\tt WHERE}
  3894. clause only apply to the expression on the left of {\tt WHERE}. They have
  3895. no effect outside the expression. In particular, they do not affect
  3896. previously defined {\tt WHERE} clauses or {\tt LET} statements. For
  3897. example, the sequence
  3898. \begin{verbatim}
  3899. let a=2;
  3900. a where a=>4;
  3901. a;
  3902. \end{verbatim}
  3903. would result in the output
  3904. \begin{verbatim}
  3905. 4
  3906. 2
  3907. \end{verbatim}
  3908. Although {\tt WHERE} has a precedence less than any other infix operator,
  3909. it still binds higher than keywords such as {\tt ELSE}, {\tt THEN},
  3910. {\tt DO}, {\tt REPEAT} and so on. Thus the expression
  3911. \begin{verbatim}
  3912. if a=2 then 3 else a+2 where a=3
  3913. \end{verbatim}
  3914. will parse as
  3915. \begin{verbatim}
  3916. if a=2 then 3 else (a+2 where a=3)
  3917. \end{verbatim}
  3918. {\tt WHERE} may be used to introduce auxiliary variables in symbolic mode
  3919. expressions, as described in Section~\ref{sec-lambda}. However, the
  3920. symbolic mode use has different semantics, so expressions do not carry
  3921. from one mode to the other.
  3922. \COMPATNOTE In order to provide compatibility with older versions of rule
  3923. sets released through the Network Library, it is currently possible to use
  3924. an equal sign interchangably with the replacement sign {\tt =>} in rules
  3925. and {\tt LET} statements. However, since this may change in future
  3926. versions, the replacement sign is preferable in rules and the equal sign
  3927. in nonrule-based {\tt LET} statements.
  3928. \subsection*{Order of Application of Rules}
  3929. If rules have overlapping domains, their order of application is
  3930. important. In general, it is very difficult to specify this order
  3931. precisely, so that it is best to assume that the order is arbitrary.
  3932. However, if only one operator is involved, the order of application of the
  3933. rules for this operator can be determined from the following:
  3934. \begin{enumerate}
  3935. \item Rules containing at least one free variable apply before all rules
  3936. without free variables.
  3937. \item Rules activated in the most recent {\tt LET}
  3938. command are applied first.
  3939. \item {\tt LET} with several entries generate
  3940. the same order of application as a corresponding sequence of commands with
  3941. one rule or rule set each.
  3942. \item Within a rule set, the rules containing at least
  3943. one free variable are applied in their given order.
  3944. In other words, the first member of the list is applied first.
  3945. \item Consistent with the first item, any rule in a rule list that
  3946. contains no free variables is applied after all rules containing free
  3947. variables.
  3948. \end{enumerate}
  3949. {\it Example:} The following rule set enables the computation of exact
  3950. values of the Gamma function:
  3951. \begin{verbatim}
  3952. operator gamma,gamma_error;
  3953. gamma_rules :=
  3954. {gamma(~x)=>sqrt(pi)/2 when x=1/2,
  3955. gamma(~n)=>factorial(n-1) when fixp n and n>0,
  3956. gamma(~n)=>gamma_error(n) when fixp n,
  3957. gamma(~x)=>(x-1)*gamma(x-1) when fixp(2*x) and x>1,
  3958. gamma(~x)=>gamma(x+1)/x when fixp(2*x)};
  3959. \end{verbatim}
  3960. Here, rule by rule, cases of known or definitely uncomputable values
  3961. are sorted out; e.g. the rule leading to the error expression
  3962. will be applied for negative integers only, since the positive
  3963. integers are caught by the preceding rule, and the
  3964. last rule will apply for negative odd multiples of $1/2$ only.
  3965. Alternatively the first rule could have been written as
  3966. \begin{verbatim}
  3967. gamma(1/2) => sqrt(pi)/2,
  3968. \end{verbatim}
  3969. but then the case $x=1/2$ should be excluded in the {\tt WHEN} part of the
  3970. last rule explicitly because a rule without free variables cannot take
  3971. precedence over the other rules.
  3972. \section{Asymptotic Commands} \index{Asymptotic command}
  3973. In expansions of polynomials involving variables which are known to be
  3974. small, it is often desirable to throw away all powers of these variables
  3975. beyond a certain point to avoid unnecessary computation. The command {\tt
  3976. LET} may be used to do this. For example, if only powers of {\tt X} up to
  3977. {\tt x\^{ }7} are needed, the command
  3978. \begin{verbatim}
  3979. let x^8 = 0;
  3980. \end{verbatim}
  3981. will cause the system to delete all powers of {\tt X} higher than 7.
  3982. {\it CAUTION:} This particular simplification works differently from most
  3983. substitution mechanisms in {\REDUCE} in that it is applied during
  3984. polynomial manipulation rather than to the whole evaluated expression.
  3985. Thus, with the above rule in effect, {\tt x\^{ }10/x\^{ }5} would give the
  3986. result zero, since the numerator would simplify to zero. Similarly
  3987. {\tt x\^{ }20/x\^{ }10} would give a {\tt Zero divisor} error message,
  3988. since both numerator and denominator would first simplify to zero.
  3989. The method just described is not adequate when expressions involve several
  3990. variables having different degrees of smallness. In this case, it is
  3991. necessary to supply an asymptotic weight to each variable and count up the
  3992. total weight of each product in an expanded expression before deciding
  3993. whether to keep the term or not. There are two associated commands in the
  3994. system to permit this type of asymptotic constraint. The command {\tt WEIGHT}
  3995. \ttindex{WEIGHT}
  3996. takes a list of equations of the form
  3997. \begin{verbatim}
  3998. <kernel form> = <number>
  3999. \end{verbatim}
  4000. where {\tt <number>} must be a positive integer (not just evaluate to a
  4001. positive integer). This command assigns the weight {\tt <number>} to the
  4002. relevant kernel form. A check is then made in all algebraic evaluations
  4003. to see if the total weight of the term is greater than the weight level
  4004. assigned to the calculation. If it is, the term is deleted. To compute
  4005. the total weight of a product, the individual weights of each kernel form
  4006. are multiplied by their corresponding powers and then added.
  4007. The weight level of the system is initially set to 2. The user may change
  4008. this setting by the command \ttindex{WTLEVEL}
  4009. \begin{verbatim}
  4010. wtlevel <number>;
  4011. \end{verbatim}
  4012. which sets {\tt <number>} as the new weight level of the system. Again,
  4013. {\tt <number>} must be a positive integer.
  4014. \chapter{File Handling Commands} \index{File handling}
  4015. In many applications, it is desirable to load previously prepared {\REDUCE}
  4016. files into the system, or to write output on other files. {\REDUCE} offers
  4017. four commands for this purpose, namely, {\tt IN}, {\tt OUT}, {\tt SHUT},
  4018. {\tt LOAD}, and {\tt LOAD\_PACKAGE}. The first \ttindex{IN} \ttindex{OUT}
  4019. \ttindex{SHUT} three operators are described here; {\tt LOAD} and {\tt
  4020. LOAD\_PACKAGE} are discussed in Section~\ref{sec-load}.
  4021. \section{IN Command} \ttindex{IN}
  4022. This command takes a list of file names as argument and directs the system
  4023. to input \index{Input} each file (which should contain {\REDUCE} statements
  4024. and commands) into the system. File names can either be an identifier or
  4025. a string. The explicit format of these will be system dependent and, in
  4026. many cases, site dependent. The explicit instructions for the
  4027. implementation being used should therefore be consulted for further
  4028. details. For example:
  4029. \begin{verbatim}
  4030. in f1,"ggg.rr.s";
  4031. \end{verbatim}
  4032. will first load file {\tt F1}, then {\tt ggg.rr.s}. When a semicolon is
  4033. used as the terminator of the IN statement, the statements in the file are
  4034. echoed on the terminal or written on the current output file. If \$
  4035. \index{Command terminator} is used as the terminator, the input is not
  4036. shown. Echoing of all or part of the input file can be prevented, even if
  4037. a semicolon was used, by placing an {\tt off echo;} \ttindex{ECHO} command
  4038. in the input file.
  4039. Files to be read using {\tt IN} should end with {\tt ;END;}. Note the two
  4040. semicolons! First of all, this is protection against obscure difficulties
  4041. the user will have if there are, by mistake, more {\tt BEGIN}s than
  4042. {\tt END}s on the file. Secondly, it triggers some file control book-keeping
  4043. which may improve system efficiency. If {\tt END} is omitted, an error
  4044. message {\tt "End-of-file read"} will occur.
  4045. \section{OUT Command} \ttindex{OUT}
  4046. This command takes a single file name as argument, and directs output to
  4047. that file from then on, until another {\tt OUT} changes the output file,
  4048. or {\tt SHUT} closes it. Output can go to only one file at a time,
  4049. although many can be open. If the file has previously been used for
  4050. output during the current job, and not {\tt SHUT}, \ttindex{SHUT} the new
  4051. output is appended to the end of the file. Any existing file is erased
  4052. before its first use for output in a job, or if it had been {\tt SHUT}
  4053. before the new {\tt OUT}.
  4054. To output on the terminal without closing the output file, the reserved
  4055. file name T (for terminal) may be used. For example,
  4056. {\tt out ofile;} will direct output to the file {\tt OFILE} and
  4057. {\tt out t;} will direct output to the user's terminal.
  4058. The output sent to the file will be in the same form that it would have on
  4059. the terminal. In particular {\tt x\^{ }2} would appear on two lines, an
  4060. {\tt X} on the lower line and a 2 on the line above. If the purpose of the
  4061. output file is to save results to be read in later, this is not an
  4062. appropriate form. We first must turn off the {\tt NAT} switch which
  4063. specifies that output should be in standard mathematical notation.
  4064. {\it Example:} To create a file {\tt ABCD} from which it will be possible
  4065. to read -- using {\tt IN} -- the value of the expression {\tt XYZ}:
  4066. \begin{verbatim}
  4067. off echo$ % needed if your input is from a file.
  4068. off nat$ % output in IN-readable form. Each expression
  4069. % printed will end with a $ .
  4070. out abcd$ % output to new file
  4071. linelength 72$ % for systems with fixed input line length.
  4072. xyz:=xyz; % will output "XYZ := " followed by the value
  4073. % of XYZ
  4074. write ";end"$ % standard for ending files for IN
  4075. shut abcd$ % save ABCD, return to terminal output
  4076. on nat$ % restore usual output form
  4077. \end{verbatim}
  4078. \section{SHUT Command} \ttindex{SHUT}
  4079. This command takes a list of names of files which have been previously
  4080. opened via an {\tt OUT} statement and closes them. Most systems require this
  4081. action by the user before he ends the {\REDUCE} job (if not sooner),
  4082. otherwise the output may be lost. If a file is shut and a further {\tt OUT}
  4083. command issued for the same file, the file is erased before the new output
  4084. is written.
  4085. If it is the current output file which is shut, output will switch to the
  4086. terminal. Attempts to shut files that have not been opened by {\tt OUT},
  4087. or an input file, will lead to errors.
  4088. \chapter{Commands for Interactive Use} \index{Interactive use}
  4089. {\REDUCE} is designed as an interactive system, but naturally it can also
  4090. operate in a batch processing or background mode by taking its input
  4091. command by command from the relevant input stream. There is a basic
  4092. difference, however, between interactive and batch use of the system. In
  4093. the former case, whenever the system discovers an ambiguity at some point
  4094. in a calculation, such as a forgotten type assignment for instance, it asks
  4095. the user for the correct interpretation. In batch operation, it is not
  4096. practical to terminate the calculation at such points and require
  4097. resubmission of the job, so the system makes the most obvious guess of the
  4098. user's intentions and continues the calculation.
  4099. There is also a difference in the handling of errors. In the former case,
  4100. the computation can continue since the user has the opportunity to correct
  4101. the mistake. In batch mode, the error may lead to consequent erroneous
  4102. (and possibly time consuming) computations. So in the default case, no
  4103. further evaluation occurs, although the remainder of the input is checked
  4104. for syntax errors. A message {\tt "Continuing with parsing only"}
  4105. informs the user that this is happening. On the other hand, the switch
  4106. {\tt ERRCONT}, \ttindex{ERRCONT} if on, will cause the system to continue
  4107. evaluating expressions after such errors occur.
  4108. When a syntactical error occurs, the place where the system detected the
  4109. error is marked with three dollar signs (\$\$\$). In interactive mode, the
  4110. user can then use {\tt ED} \ttindex{ED} to correct the error, or retype the
  4111. command. When a non-syntactical error occurs in interactive mode, the
  4112. command being evaluated at the time the last error occurred is saved, and
  4113. may later be reevaluated by the command {\tt RETRY}. \ttindex{RETRY}
  4114. \section{Referencing Previous Results}
  4115. It is often useful to be able to reference results of previous
  4116. computations during a {\REDUCE} session. For this purpose, {\REDUCE}
  4117. maintains a history \index{History} of all interactive inputs and the
  4118. results of all interactive computations during a given session. These
  4119. results are referenced by the command number that {\REDUCE} prints
  4120. automatically in interactive mode. To use an input expression in a new
  4121. computation, one writes {\tt input(}$n${\tt )}, \ttindex{INPUT} where
  4122. $n$ is the command number. To use an output expression, one writes {\tt
  4123. WS(}$n${\tt )}. \ttindex{WS} {\tt WS} references the previous command.
  4124. E.g., if command number 1 was {\tt INT(X-1,X)}; and the result of command
  4125. number 7 was {\tt X-1}, then
  4126. \begin{verbatim}
  4127. 2*input(1)-ws(7)^2;
  4128. \end{verbatim}
  4129. would give the result {\tt -1}, whereas
  4130. \begin{verbatim}
  4131. 2*ws(1)-ws(7)^2;
  4132. \end{verbatim}
  4133. would yield the same result, but {\em without} a recomputation of the
  4134. integral.
  4135. The operator {\tt DISPLAY} \ttindex{DISPLAY} is available to display previous
  4136. inputs. If its argument is a positive integer, {\it n} say, then the
  4137. previous n inputs are displayed. If its argument is {\tt ALL} (or in fact
  4138. any non-numerical expression), then all previous inputs are displayed.
  4139. \section{Interactive Editing}
  4140. It is possible when working interactively to edit any {\REDUCE} input that
  4141. comes from the user's terminal, and also some user-defined procedure
  4142. definitions. At the top level, one can access any previous command string
  4143. by the command {\tt ed(}$n${\tt )}, \ttindex{ED} where n is the desired
  4144. command number as prompted by the system in interactive mode. {\tt ED};
  4145. (i.e. no argument) accesses the previous command.
  4146. After {\tt ED} has been called, you can now edit the displayed string using a
  4147. string editor with the following commands:
  4148. \begin{verbatim}
  4149. B move pointer to beginning
  4150. C<character> replace next character by <character>
  4151. D delete next character
  4152. E end editing and reread text
  4153. F<character> move pointer to next occurrence of
  4154. <character>
  4155. I<string><escape> insert <string> in front of pointer
  4156. K<character> delete all chars until <character>
  4157. P print string from current pointer
  4158. Q give up with error exit
  4159. S<string><escape> search for first occurrence of
  4160. <string> positioning pointer just
  4161. before it
  4162. <space> or X move pointer right one char.
  4163. \end{verbatim}
  4164. The above table can be displayed online by typing a question mark followed
  4165. by a carriage return to the editor. The editor prompts with an angle
  4166. bracket. Commands can be combined on a single line, and all command
  4167. sequences must be followed by a carriage return to become effective.
  4168. Thus, to change the command {\tt x := a+1;} to {\tt x := a+2}; and cause
  4169. it to be executed, the following edit command sequence could be used:
  4170. \begin{verbatim}
  4171. f1c2e<return>.
  4172. \end{verbatim}
  4173. The interactive editor may also be used to edit a user-defined procedure that
  4174. has not been compiled (q.v.). To do this, one says:
  4175. \ttindex{EDITDEF}
  4176. \begin{verbatim}
  4177. editdef <id>;
  4178. \end{verbatim}
  4179. where {\tt <id>} is the name of the procedure. The procedure definition
  4180. will then be displayed in editing mode, and may then be edited and
  4181. redefined on exiting from the editor.
  4182. \section{Interactive File Control}
  4183. If input is coming from an external file, the system treats it as a batch
  4184. processed calculation. If the user desires interactive
  4185. \index{Interactive use} response in this case, he can include the command
  4186. {\tt on int}; \ttindex{INT} in the file. Likewise, he can issue the
  4187. command {\tt off int}; in the main program if he does not desire continual
  4188. questioning from the system. Regardless of the setting of {\tt INT},
  4189. input commands from a file are not kept in the system, and so cannot be
  4190. edited using {\tt ED}. However, many implementations of {\REDUCE} provide
  4191. a link to an external system editor that can be used for such editing.
  4192. The specific instructions for the particular implementation should be
  4193. consulted for information on this.
  4194. Two commands are available in {\REDUCE} for interactive use of files. {\tt
  4195. PAUSE}; \ttindex{PAUSE} may be inserted at any point in an input file. When
  4196. this command is encountered on input, the system prints the message {\tt
  4197. CONT?} on the user's terminal and halts. If the user responds {\tt Y}
  4198. (for yes), the calculation continues from that point in the file. If the
  4199. user responds {\tt N} (for no), control is returned to the terminal, and
  4200. the user can input further statements and commands. Later on he can use
  4201. the command {\tt cont;} \ttindex{CONT} to transfer control back to the
  4202. point in the file following the last {\tt PAUSE} encountered. A top-level
  4203. {\tt pause;} \ttindex{PAUSE} from the user's terminal has no effect.
  4204. \chapter{Matrix Calculations} \index{Matrix calculations}
  4205. A very powerful feature of {\REDUCE} is the ease with which matrix
  4206. calculations can be performed. To extend our syntax to this class of
  4207. calculations we need to add another prefix operator, {\tt MAT},
  4208. \ttindex{MAT} and a further
  4209. variable and expression type as follows:
  4210. \section{MAT Operator} \ttindex{MAT}
  4211. This prefix operator is used to represent {\em n} x {\em m} matrices. {\tt
  4212. MAT} has {\em n} arguments interpreted as rows of the matrix, each of
  4213. which is a list of {\em m} expressions representing elements in that row.
  4214. For example, the matrix
  4215. \[ \left( \begin{array}{lcr} a & b & c \\ d & e & f \end{array} \right) \]
  4216. would be written as {\tt mat((a,b,c),(d,e,f))}.
  4217. Note that the single column matrix
  4218. \[ \left( \begin{array}{c} x \\ y \end{array} \right) \]
  4219. becomes {\tt mat((x),(y))}. The inside parentheses are required to
  4220. distinguish it from the single row matrix
  4221. \[ \left( \begin{array}{lr} x & y \end{array} \right) \]
  4222. which would be written as {\tt mat((x,y))}.
  4223. \section{Matrix Variables}
  4224. An identifier may be declared a matrix variable by the declaration {\tt
  4225. MATRIX}.\ttindex{MATRIX}
  4226. The size of the matrix may be declared explicitly in the matrix
  4227. declaration, or by default in assigning such a variable to a matrix
  4228. expression. For example,
  4229. \begin{verbatim}
  4230. matrix x(2,1),y(3,4),z;
  4231. \end{verbatim}
  4232. declares {\tt X} to be a 2 x 1 (column) matrix, {\tt Y} to be a 3 x 4
  4233. matrix and {\tt Z} a matrix whose size is to be declared later.
  4234. Matrix declarations can appear anywhere in a program. Once a symbol is
  4235. declared to name a matrix, it can not also be used to name an array,
  4236. operator or a procedure, or used as an ordinary variable. It can however
  4237. be re-declared to be a matrix, and its size may be changed at that time.
  4238. Note however that matrices once declared are {\em global} in scope, and so
  4239. can then be referenced anywhere in the program. In other words, a
  4240. declaration within a block (or a procedure) does not limit the scope of
  4241. the matrix to that block, nor does the matrix go away on exiting the block
  4242. (use {\tt CLEAR} instead for this purpose). An element of a matrix is
  4243. referred to in the expected manner; thus {\tt x(1,1)} gives the first
  4244. element of the matrix {\tt X} defined above. References to elements of a
  4245. matrix whose size has not yet been declared leads to an error. All
  4246. elements of a matrix whose size is declared are initialized to 0. As a
  4247. result, a matrix element has an ``instant evaluation" \index{Instant
  4248. evaluation} property and cannot stand for itself. If this is required,
  4249. then an operator (q.v.) should be used to name the matrix elements as in:
  4250. \begin{verbatim}
  4251. matrix m; operator x; m := mat((x(1,1),x(1,2));
  4252. \end{verbatim}
  4253. \section{Matrix Expressions}
  4254. These follow the normal rules of matrix algebra as defined by the
  4255. following syntax: \ttindex{MAT}
  4256. \begin{verbatim}
  4257. <matrix expression> ::=
  4258. MAT<matrix description>|<matrix variable>|
  4259. <scalar expression>*<matrix expression>|
  4260. <matrix expression>*<matrix expression>
  4261. <matrix expression>+<matrix expression>|
  4262. <matrix expression>^<integer>|
  4263. <matrix expression>/<matrix expression>
  4264. \end{verbatim}
  4265. Sums and products of matrix expressions must be of compatible size;
  4266. otherwise an error will result during their evaluation. Similarly, only
  4267. square matrices may be raised to a power. A negative power is computed as
  4268. the inverse of the matrix raised to the corresponding positive power.
  4269. {\tt a/b} is interpreted as {\tt a*b\^{ }(-1)}.
  4270. {\it Examples:}
  4271. Assuming {\tt X} and {\tt Y} have been declared as matrices, the following
  4272. are matrix expressions
  4273. \begin{verbatim}
  4274. y
  4275. y^2*x-3*y^(-2)*x
  4276. y + mat((1,a),(b,c))/2
  4277. \end{verbatim}
  4278. The computation of the quotient of two matrices normally uses a two-step
  4279. elimination method due to Bareiss. An alternative method using Cramer's
  4280. method is also available. This is often more efficient than the Bareiss
  4281. method, although we have no solid statistics on this as yet. To use Cramer's
  4282. method instead, the switch {\tt CRAMER} should be turned on.
  4283. \section{Operators with Matrix Arguments}
  4284. The operator {\tt LENGTH} (q.v.) \ttindex{LENGTH} applied to a matrix
  4285. returns a list of the number of rows and columns in the matrix. Three
  4286. additional operators are useful in matrix calculations, namely {\tt DET},
  4287. {\tt TP} and {\tt TRACE} defined in the following subsections.
  4288. \subsection{DET Operator} \ttindex{DET}
  4289. Syntax:
  4290. \begin{verbatim}
  4291. DET(EXPRN:matrix_expression):algebraic.
  4292. \end{verbatim}
  4293. The operator {\tt DET} is used to represent the determinant of a square
  4294. matrix expression. E.g.,
  4295. \begin{verbatim}
  4296. det(y^2)
  4297. \end{verbatim}
  4298. is a scalar expression whose value is the determinant of the square of the
  4299. matrix {\tt Y}, and
  4300. \begin{verbatim}
  4301. det mat((a,b,c),(d,e,f),(g,h,j));
  4302. \end{verbatim}
  4303. is a scalar expression whose value is the determinant of the matrix
  4304. \[ \left( \begin{array}{lcr} a & b & c \\ d & e & f \\ g & h & j
  4305. \end{array} \right) \]
  4306. Determinant expressions have the ``instant evaluation" property.
  4307. \index{Instant evaluation} In other words, the statement
  4308. \begin{verbatim}
  4309. let det mat((a,b),(c,d)) = 2;
  4310. \end{verbatim}
  4311. sets the {\em value} of the determinant to 2, and does not set up a rule
  4312. for the determinant itself.
  4313. \subsection{MATEIGEN Operator} \ttindex{MATEIGEN}
  4314. Syntax:
  4315. \begin{verbatim}
  4316. MATEIGEN(EXPRN:matrix_expression,ID):list.
  4317. \end{verbatim}
  4318. {\tt MATEIGEN} calculates the eigenvalue equation and the corresponding
  4319. eigenvectors of a matrix, using the variable {\tt ID} to denote the
  4320. eigenvalue. A square free decomposition of the characteristic polynomial
  4321. is carried out. The result is a list of lists of 3 elements, where the
  4322. first element is a square free factor of the characteristic polynomial,
  4323. the second its multiplicity and the third the corresponding eigenvector
  4324. (as an {\em n} by 1 matrix). If the square free decomposition was
  4325. successful, the product of the first elements in the lists is the minimal
  4326. polynomial. In the case of degeneracy, several eigenvectors can exist for
  4327. the same eigenvalue, which manifests itself in the appearance of more than
  4328. one arbitrary variable in the eigenvector. To extract the various parts
  4329. of the result use the operations defined on lists.
  4330. {\it Example:}
  4331. The command
  4332. \begin{verbatim}
  4333. mateigen(mat((2,-1,1),(0,1,1),(-1,1,1)),eta);
  4334. \end{verbatim}
  4335. gives the output
  4336. \begin{verbatim}
  4337. {{ETA - 1,2,
  4338. [ARBCOMPLEX(1)]
  4339. [ ]
  4340. [ARBCOMPLEX(1)]
  4341. [ ]
  4342. [ 0 ]
  4343. },
  4344. {ETA - 2,1,
  4345. [ 0 ]
  4346. [ ]
  4347. [ARBCOMPLEX(2)]
  4348. [ ]
  4349. [ARBCOMPLEX(2)]
  4350. }}
  4351. \end{verbatim}
  4352. \subsection{TP Operator} \ttindex{TP}
  4353. Syntax:
  4354. \begin{verbatim}
  4355. TP(EXPRN:matrix_expression):matrix.
  4356. \end{verbatim}
  4357. This operator takes a single matrix argument and returns its transpose.
  4358. \subsection{Trace Operator} \ttindex{TRACE}
  4359. Syntax:
  4360. \begin{verbatim}
  4361. TRACE(EXPRN:matrix_expression):algebraic.
  4362. \end{verbatim}
  4363. The operator {\tt TRACE} is used to represent the trace of a square matrix.
  4364. \subsection{Matrix Cofactors} \ttindex{COFACTOR}
  4365. Syntax:
  4366. \begin{verbatim}
  4367. COFACTOR(EXPRN:matrix_expression,ROW:integer,COLUMN:integer):
  4368. algebraic
  4369. \end{verbatim}
  4370. The operator {\tt COFACTOR} returns the cofactor of the element in row
  4371. {\tt ROW} and column {\tt COLUMN} of the matrix {\tt MATRIX}. Errors occur
  4372. if {\tt ROW} or {\tt COLUMN} do not simplify to integer expressions or if
  4373. {\tt MATRIX} is not square.
  4374. \subsection{NULLSPACE Operator} \ttindex{NULLSPACE}
  4375. Syntax:
  4376. \begin{verbatim}
  4377. NULLSPACE(EXPRN:matrix_expression):list
  4378. \end{verbatim}
  4379. {\tt NULLSPACE} calculates for a matrix {\tt A} a list of linear
  4380. independent vectors (a basis) whose linear combinations satisfy the
  4381. equation $A x = 0$. The basis is provided in a form such that as many
  4382. upper components as possible are isolated.
  4383. Note that with {\tt b := nullspace a} the expression {\tt length b} is the
  4384. {\em nullity} of A, and that {\tt second length a - length b} calculates the
  4385. {\em rank} of A. The rank of a matrix expression can also be found more
  4386. directly by the {\tt RANK} operator described below.
  4387. {\it Example:} The command
  4388. \begin{verbatim}
  4389. nullspace mat((1,2,3,4),(5,6,7,8));
  4390. \end{verbatim}
  4391. gives the output
  4392. \begin{verbatim}
  4393. {
  4394. [ 1 ]
  4395. [ ]
  4396. [ 0 ]
  4397. [ ]
  4398. [ - 3]
  4399. [ ]
  4400. [ 2 ]
  4401. ,
  4402. [ 0 ]
  4403. [ ]
  4404. [ 1 ]
  4405. [ ]
  4406. [ - 2]
  4407. [ ]
  4408. [ 1 ]
  4409. }
  4410. \end{verbatim}
  4411. In addition to the {\REDUCE} matrix form, {\tt NULLSPACE} accepts as input a
  4412. matrix given as a list of lists, which is interpreted as a row matrix. If
  4413. that form of input is chosen, the vectors in the result will be
  4414. represented by lists as well. This additional input syntax facilitates
  4415. the use of {\tt NULLSPACE} in applications different from classical linear
  4416. algebra.
  4417. \subsection{RANK Operator} \ttindex{RANK}
  4418. Syntax:
  4419. \begin{verbatim}
  4420. RANK(EXPRN:matrix_expression):integer
  4421. \end{verbatim}
  4422. {\tt RANK} calculates the rank of its argument, which, like {\tt NULLSPACE}
  4423. can either be a standard matrix expression, or a list of lists, which can
  4424. be interpreted either as a row matrix or a set of equations.
  4425. {\tt Example:}
  4426. \begin{verbatim}
  4427. rank mat((a,b,c),(d,e,f));
  4428. \end{verbatim}
  4429. returns the value 2.
  4430. \section{Matrix Assignments} \index{Matrix assignment}
  4431. Matrix expressions may appear in the right-hand side of assignment
  4432. statements. If the left-hand side of the assignment, which must be a
  4433. variable, has not already been declared a matrix, it is declared by default
  4434. to the size of the right-hand side. The variable is then set to the value
  4435. of the right-hand side.
  4436. Such an assignment may be used very conveniently to find the solution of a
  4437. set of linear equations. For example, to find the solution of the
  4438. following set of equations
  4439. \begin{verbatim}
  4440. a11*x(1) + a12*x(2) = y1
  4441. a21*x(1) + a22*x(2) = y2
  4442. \end{verbatim}
  4443. we simply write
  4444. \begin{verbatim}
  4445. x := 1/mat((a11,a12),(a21,a22))*mat((y1),(y2));
  4446. \end{verbatim}
  4447. \section{Evaluating Matrix Elements}
  4448. Once an element of a matrix has been assigned, it may be referred to in
  4449. standard array element notation. Thus {\tt y(2,1)} refers to the element
  4450. in the second row and first column of the matrix {\tt Y}.
  4451. \chapter{Procedures} \ttindex{PROCEDURE}
  4452. It is often useful to name a statement for repeated use in calculations
  4453. with varying parameters, or to define a complete evaluation procedure for
  4454. an operator. {\REDUCE} offers a procedural declaration for this purpose. Its
  4455. general syntax is:
  4456. \begin{verbatim}
  4457. [<procedural type>] PROCEDURE <name>[<varlist>];<statement>;
  4458. \end{verbatim}
  4459. where
  4460. \begin{verbatim}
  4461. <varlist> ::= (<variable>,...,<variable>)
  4462. \end{verbatim}
  4463. This will be explained more fully in the following sections.
  4464. In the algebraic mode of {\REDUCE} the {\tt <procedure type>} can be
  4465. omitted, since the default is {\tt ALGEBRAIC}. Procedures of type {\tt
  4466. INTEGER} or {\tt REAL} may also be used. In the former case, the system
  4467. checks that the value of the procedure is an integer. At present, such
  4468. checking is not done for a real procedure, although this will change in
  4469. the future when a more complete type checking mechanism is installed.
  4470. Users should therefore only use these types when appropriate. An empty
  4471. variable list may also be omitted.
  4472. All user-defined procedures are automatically declared to be operators.
  4473. In order to allow users relatively easy access to the whole {\REDUCE} source
  4474. program, system procedures are not protected against user redefinition. If
  4475. a procedure is redefined, a message
  4476. \begin{verbatim}
  4477. *** <procedure name> REDEFINED
  4478. \end{verbatim}
  4479. is printed. If this occurs, and the user is not redefining his own
  4480. procedure, he is well advised to rename it, and possibly start over
  4481. (because he has {\em already} redefined some internal procedure whose correct
  4482. functioning may be required for his job!)
  4483. All required procedures should be defined at the top level, since they
  4484. have global scope throughout a program. In particular, an attempt to
  4485. define a procedure within a procedure will cause an error to occur.
  4486. \section{Procedure Heading} \index{Procedure heading}
  4487. Each procedure has a heading consisting of the word {\tt PROCEDURE}
  4488. (optionally preceded by the word {\tt ALGEBRAIC}), followed by the name of
  4489. the procedure to be defined, and followed by its formal parameters -- the
  4490. symbols which will be used in the body of the definition to illustrate
  4491. what is to be done. There are three cases:
  4492. \begin{enumerate}
  4493. \item No parameters. Simply follow the procedure name with a terminator
  4494. (semicolon or dollar sign).
  4495. \begin{verbatim}
  4496. procedure abc;
  4497. \end{verbatim}
  4498. When such a procedure is used in an expression or command, {\tt abc()}, with
  4499. empty parentheses, must be written.
  4500. \item One parameter. Enclose it in parentheses {\em or} just leave at
  4501. least one space, then follow with a terminator.
  4502. \begin{verbatim}
  4503. procedure abc(x);
  4504. \end{verbatim}
  4505. or
  4506. \begin{verbatim}
  4507. procedure abc x;
  4508. \end{verbatim}
  4509. \item More than one parameter. Enclose them in parentheses, separated by
  4510. commas, then follow with a terminator.
  4511. \begin{verbatim}
  4512. procedure abc(x,y,z);
  4513. \end{verbatim}
  4514. \end{enumerate}
  4515. Referring to the last example, if later in some expression being evaluated
  4516. the symbols {\tt abc(u,p*q,123)} appear, the operations of the procedure
  4517. body will be carried out as if {\tt X} had the same value as {\tt U} does,
  4518. {\tt Y} the same value as {\tt p*q} does, and {\tt Z} the value 123. The
  4519. values of {\tt X}, {\tt Y}, {\tt Z}, after the procedure body operations
  4520. are completed are unchanged. So, normally, are the values of {\tt U},
  4521. {\tt P}, {\tt Q}, and (of course) 123. (This is technically referred to as
  4522. call by value.) \index{Call by value}
  4523. The reader will have noted the word {\em normally} a few lines earlier. The
  4524. call by value protections can be bypassed if necessary, as described
  4525. elsewhere.
  4526. \section{Procedure Body} \index{Procedure body}
  4527. Following the delimiter which ends the procedure heading must be a {\em
  4528. single} statement defining the action to be performed or the value to be
  4529. delivered. A terminator must follow the statement. If it is a semicolon,
  4530. the name of the procedure just defined is printed. It is not printed if a
  4531. dollar sign is used.
  4532. If the result wanted is given by a formula of some kind, the body is just
  4533. that formula, using the variables in the procedure heading.
  4534. {\it Simple Example:}
  4535. If {\tt f(x)} is to mean {\tt (x+5)*(x+6)/(x+7)}, the entire procedure
  4536. definition could read
  4537. \begin{verbatim}
  4538. procedure f x; (x+5)*(x+6)/(x+7);
  4539. \end{verbatim}
  4540. Then {\tt f(10)} would evaluate to 240/17, {\tt f(a-6)} to
  4541. {\tt A*(A-1)/(A+1)}, and so on.
  4542. {\it More Complicated Example:}
  4543. Suppose we need a function {\tt p(n,x)} which, for any positive integer
  4544. {\tt N}, is the Legendre polynomial \index{Legendre polynomial} of order
  4545. {\em n}. We can define this operator using the
  4546. textbook formula defining these functions:
  4547. \begin{displaymath}
  4548. p_n(x) = \displaystyle{1\over{n!}}\
  4549. \displaystyle{d^n\over dy^n}\ \displaystyle{{1\over{(y^2 - 2xy + 1)
  4550. ^{{1\over2}}}}}\Bigg\vert_{y=0}
  4551. \end{displaymath}
  4552. Put into words, the Legendre polynomial $p_n(x)$ is the result of
  4553. substituting $y=0$ in the $n^{th}$ partial derivative with respect to $y$
  4554. of a certain fraction involving $x$ and $y$, then dividing that by $n!$.
  4555. This verbal formula can easily be written in {\REDUCE}:
  4556. \begin{verbatim}
  4557. procedure p(n,x);
  4558. sub(y=0,df(1/(y^2-2*x*y+1)^(1/2),y,n))
  4559. /(for i:=1:n product i);
  4560. \end{verbatim}
  4561. Having input this definition, the expression evaluation
  4562. \begin{verbatim}
  4563. 2p(2,w);
  4564. \end{verbatim}
  4565. would result in the output
  4566. \begin{verbatim}
  4567. 2
  4568. 3*W - 1 .
  4569. \end{verbatim}
  4570. If the desired process is best described as a series of steps, then a group
  4571. or compound statement can be used.
  4572. {\it Example:}
  4573. The above Legendre polynomial example can be rewritten as a series of steps
  4574. instead of a single formula as follows:
  4575. \begin{verbatim}
  4576. procedure p(n,x);
  4577. begin scalar seed,deriv,top,fact;
  4578. seed:=1/(y^2 - 2*x*y +1)^(1/2);
  4579. deriv:=df(seed,y,n);
  4580. top:=sub(y=0,deriv);
  4581. fact:=for i:=1:n product i;
  4582. return top/fact
  4583. end;
  4584. \end{verbatim}
  4585. Procedures may also be defined recursively. In other words, the procedure
  4586. body \index{Procedure body} can include references to the procedure name
  4587. itself, or to other procedures which themselves reference the given
  4588. procedure. As an example, we can define the Legendre polynomial through
  4589. its standard recurrence relation:
  4590. \begin{verbatim}
  4591. procedure p(n,x);
  4592. if n<0 then rederr "Invalid argument to P(N,X)"
  4593. else if n=0 then 1
  4594. else if n=1 then x
  4595. else ((2*n-1)*x*p(n-1,x)-(n-1)*p(n-2,x))/n;
  4596. \end{verbatim}
  4597. The operator {\tt REDERR} \ttindex{REDERR} in the above example provides
  4598. for a simple error exit from an algebraic procedure (and also a block).
  4599. It can take a string as argument.
  4600. It should be noted however that all the above definitions of {\tt p(n,x)} are
  4601. quite inefficient if extensive use is to be made of such polynomials, since
  4602. each call effectively recomputes all lower order polynomials. It would be
  4603. better to store these expressions in an array, and then use say the
  4604. recurrence relation to compute only those polynomials that have not already
  4605. been derived. We leave it as an exercise for the reader to write such a
  4606. definition.
  4607. \section{Using LET Inside Procedures}
  4608. By using {\tt LET} \ttindex{LET} instead of an assignment in the procedure
  4609. body \index{Procedure body} it is possible to bypass the call-by-value
  4610. \index{Call by value} protection. If {\tt X} is a formal parameter or local
  4611. variable of the procedure (i.e. is in the heading or in a local
  4612. declaration), and {\tt LET} is used instead of {\tt :=} to make an
  4613. assignment to {\tt X}, e.g.
  4614. \begin{verbatim}
  4615. let x = 123;
  4616. \end{verbatim}
  4617. then it is the variable which is the value of {\tt X} that is changed.
  4618. This effect also occurs with local variables defined in a block. If the
  4619. value of {\tt X} is not a variable, but a more general expression, then it
  4620. is that expression that is used on the left-hand side of the {\tt LET}
  4621. statement. For example, if {\tt X} had the value {\tt p*q}, it is as if
  4622. {\tt let p*q = 123} had been executed.
  4623. \section{LET Rules as Procedures}
  4624. The {\tt LET} \ttindex{LET} statement offers an alternative syntax and
  4625. semantics for procedure definition.
  4626. In place of
  4627. \begin{verbatim}
  4628. procedure abc(x,y,z); <procedure body>;
  4629. \end{verbatim}
  4630. one can write
  4631. \begin{verbatim}
  4632. for all x,y,z let abc(x,y,z) = <procedure body>;
  4633. \end{verbatim}
  4634. There are several differences to note.
  4635. If the procedure body contains an assignment to one of the formal
  4636. parameters, e.g.
  4637. \begin{verbatim}
  4638. x := 123;
  4639. \end{verbatim}
  4640. in the {\tt PROCEDURE} case it is a variable holding a copy of the first
  4641. actual argument which is changed. The actual argument is not changed.
  4642. In the {\tt LET} case, the actual argument is changed. Thus, if {\tt ABC}
  4643. is defined using {\tt LET}, and {\tt abc(u,v,w)} is evaluated, the value
  4644. of {\tt U} changes to 123. That is, the {\tt LET} form of definition
  4645. allows the user to bypass the protections which are enforced by the call
  4646. by value conventions of standard {\tt PROCEDURE} definitions.
  4647. {\it Example:} We take our earlier {\tt FACTORIAL} \ttindex{FACTORIAL}
  4648. procedure and write it as a {\tt LET} statement.
  4649. \begin{verbatim}
  4650. for all n let factorial n =
  4651. begin scalar m,s;
  4652. m:=1; s:=n;
  4653. l1: if s=0 then return m;
  4654. m:=m*s;
  4655. s:=s-1;
  4656. go to l1
  4657. end;
  4658. \end{verbatim}
  4659. The reader will notice that we introduced a new local variable, {\tt S},
  4660. and set it equal to {\tt N}. The original form of the procedure contained
  4661. the statement {\tt n:=n-1;}. If the user asked for the value of {\tt
  4662. factorial(5)} then {\tt N} would correspond to -- not just have the value
  4663. of -- 5, and {\REDUCE} would object to trying to execute the statement
  4664. 5:=5-1.
  4665. If {\tt PQR} is a procedure with no parameters,
  4666. \begin{verbatim}
  4667. procedure pqr;
  4668. <procedure body>;
  4669. \end{verbatim}
  4670. it can be written as a {\tt LET} statement quite simply:
  4671. \begin{verbatim}
  4672. let pqr = <procedure body>;
  4673. \end{verbatim}
  4674. To call {\em procedure} {\tt PQR}, if defined in the latter form, the empty
  4675. parentheses would not be used: use {\tt PQR} not {\tt PQR()} where a call
  4676. on the procedure is needed.
  4677. The two notations for a procedure with no arguments can be combined. {\tt PQR}
  4678. can be defined in the standard {\tt PROCEDURE} form. Then a {\tt LET}
  4679. statement
  4680. \begin{verbatim}
  4681. let pqr = pqr();
  4682. \end{verbatim}
  4683. would allow a user to use {\tt PQR} instead of {\tt PQR()} in calling the
  4684. procedure.
  4685. A feature available with {\tt LET}-defined procedures and not with procedures
  4686. defined in the standard way is the possibility of defining partial
  4687. functions. \index{Function}
  4688. \begin{verbatim}
  4689. for all x such that numberp x let uvw(x)=<procedure body>;
  4690. \end{verbatim}
  4691. Now {\tt UVW} of an integer would be calculated as prescribed by the procedure
  4692. body, while {\tt UVW} of a general argument, such as {\tt Z} or {\tt p+q}
  4693. (assuming these evaluate to themselves) would simply stay {\tt uvw(z)}
  4694. or {\tt uvw(p+q)} as the case may be.
  4695. \chapter{User Contributed Packages} \index{User packages}
  4696. The complete {\REDUCE} system includes a number of packages that have been
  4697. contributed by users. These packages are unsupported, but are provided with
  4698. the {\REDUCE} distribution as a service to the user community. All questions
  4699. regarding these packages should therefore be directed to their individual
  4700. authors, who are solely responsible for their maintenance and development.
  4701. There are two classes of such packages. The first are those for which
  4702. explicit files exist in the source, test and documentation directories on the
  4703. system tape. The second are those which are bundled into a single library
  4704. directory ``lib" on the system tape, although this organization may
  4705. differ from implementation to implementation.
  4706. All packages in the first class have been precompiled as part of the
  4707. installation process. However, in order to emphasize the unsupported
  4708. nature of these packages, many must be specifically loaded before they can
  4709. be used. (Those that are loaded automatically are noted specifically in
  4710. their description.) You should consult the user notes for your particular
  4711. implementation for further information on whether this is necessary. If
  4712. it is, the relevant command is {\tt LOAD\_PACKAGE}, \index{Load package}
  4713. which takes a list of one or more package names as argument, for example:
  4714. \begin{verbatim}
  4715. load_package algint;
  4716. \end{verbatim}
  4717. although this syntax may vary from implementation to implementation.
  4718. Packages in the second class must be individually compiled and loaded by
  4719. the installer or user.
  4720. Most packages come with separate documentation and test file (except for
  4721. some very simple packages in the ``lib" directory, and those noted here
  4722. that have no additional documentation), which is included, along with the
  4723. source of the package, in the {\REDUCE} system distribution. These items
  4724. should be studied for details on the use of any particular package. We
  4725. also list below the packages in the first class available in the current
  4726. release of {\REDUCE}, together with a brief paragraph describing their
  4727. capabilities. More detailed documentation may be found in the ``doc''
  4728. directory of the REDUCE system distribution. The packages in the second
  4729. class are listed in a header ``README'' file in the ``lib'' directory.
  4730. In some cases, the additional documentation for these packages is in plain
  4731. text. However, an increasing number of documents are now being supplied
  4732. in {\LaTeX} format (and one in troff form). Those documents not in plain
  4733. text are so noted in the descriptions below.
  4734. \section{ALGINT: Integration of Square Roots} \ttindex{ALGINT}
  4735. This package, which is an extension of the basic integration package
  4736. distributed with {\REDUCE}, will analytically integrate a wide range of
  4737. expressions involving square roots where the answer exists in that class
  4738. of functions. It is an implementation of the work described in J.H.
  4739. Davenport, ``On the Integration of Algebraic Functions", LNCS 102,
  4740. Springer Verlag, 1981. Both this and the source code should be consulted
  4741. for a more detailed description of this work.
  4742. Once the {\tt ALGINT} package has been loaded, using {\tt LOAD\_PACKAGE},
  4743. one enters an expression for integration, as with the regular integrator
  4744. (q.v.), for example:
  4745. \begin{verbatim}
  4746. int(sqrt(x+sqrt(x**2+1)/x,x);
  4747. \end{verbatim}
  4748. If one later wishes to integrate expressions without using the facilities of
  4749. this package, the switch {\tt ALGINT} \ttindex{ALGINT} should be turned
  4750. off. This is turned on automatically when the package is loaded.
  4751. The switches supported by the standard integrator (e.g., {\tt TRINT})
  4752. \ttindex{TRINT} are also supported by this package. In addition, the
  4753. switch {\tt TRA}, \ttindex{TRA} if on, will give further tracing
  4754. information about the specific functioning of the algebraic integrator.
  4755. There is no additional documentation for this package.
  4756. \\ \\
  4757. Author: James H. Davenport.
  4758. \section{ARNUM: An Algebraic Number Package} \ttindex{ARNUM}
  4759. This package provides facilities for handling algebraic numbers as
  4760. polynomial coefficients in {\REDUCE} calculations. It includes facilities for
  4761. introducing indeterminates to represent algebraic numbers, for calculating
  4762. splitting fields, and for factoring and finding greatest common divisors
  4763. in such domains.
  4764. \\ \\
  4765. Author: Eberhard Schr\"ufer.
  4766. \section{AVECTOR: A Vector Algebra and Calculus Package} \ttindex{AVECTOR}
  4767. This package provides REDUCE with the ability to perform vector algebra
  4768. using the same notation as scalar algebra. The basic algebraic operations
  4769. are supported, as are differentiation and integration of vectors with
  4770. respect to scalar variables, cross product and dot product, component
  4771. manipulation and application of scalar functions (e.g. cosine) to a vector
  4772. to yield a vector result.
  4773. The documentation for this package is in {\LaTeX} format.
  4774. \\ \\
  4775. Author: David Harper.
  4776. \section{COMPACT: A Package for Compacting Expressions} \ttindex{COMPACT}
  4777. COMPACT is a package of functions for the reduction of a polynomial in the
  4778. presence of side relations. COMPACT applies the side relations to the
  4779. polynomial so that an equivalent expression results with as few terms as
  4780. possible. For example, the evaluation of
  4781. \begin{verbatim}
  4782. compact(s*(1-sin x^2)+c*(1-cos x^2)+sin x^2+cos x^2,
  4783. {cos x^2+sin x^2=1});
  4784. \end{verbatim}
  4785. yields the result
  4786. \begin{verbatim}
  4787. 2 2
  4788. SIN(X) *C + COS(X) *S + 1
  4789. \end{verbatim}
  4790. The documentation for this package is in {\LaTeX} format.
  4791. \\ \\
  4792. Author: Anthony C. Hearn.
  4793. \section{EXCALC: A Differential Geometry Package} \ttindex{EXCALC}
  4794. EXCALC is designed for easy use by all who are familiar with the calculus
  4795. of Modern Differential Geometry. The program is currently able to handle
  4796. scalar-valued exterior forms, vectors and operations between them, as well
  4797. as non-scalar valued forms (indexed forms). It is thus an ideal tool for
  4798. studying differential equations, doing calculations in general relativity
  4799. and field theories, or doing simple things such as calculating the
  4800. Laplacian of a tensor field for an arbitrary given frame.
  4801. \\ \\
  4802. Author: Eberhard Schr\"ufer.
  4803. \section{GENTRAN: A Code Generation Package} \ttindex{GENTRAN}
  4804. GENTRAN is an automatic code GENerator and TRANslator. It constructs
  4805. complete numerical programs based on sets of algorithmic specifications
  4806. and symbolic expressions. Formatted FORTRAN, RATFOR, PASCAL or C code can be
  4807. generated through a series of interactive commands or under the control of
  4808. a template processing routine. Large expressions can be automatically
  4809. segmented into subexpressions of manageable size, and a special
  4810. file-handling mechanism maintains stacks of open I/O channels to allow
  4811. output to be sent to any number of files simultaneously and to facilitate
  4812. recursive invocation of the whole code generation process.
  4813. The documentation for this package is in {\LaTeX} format.
  4814. \\ \\
  4815. Author: Barbara L. Gates.
  4816. \section{GROEBNER: A Gr\"obner Basis Package}
  4817. \index{Gr\"obner basis}
  4818. GROEBNER \ttindex{GROEBNER} is a package for the computation of Gr\"obner
  4819. Bases using the Buchberger algorithm. It can be used over a variety of
  4820. different coefficient domains, and for different variable and term
  4821. orderings.
  4822. The documentation for this package is in {\LaTeX} format.
  4823. \\ \\
  4824. Authors: Herbert Melenk, H.M. M\"oller and Winfried Neun.
  4825. \section{LIMITS: A Package for Finding Limits} \ttindex{LIMITS}
  4826. LIMITS is a fast limit package for REDUCE for functions which are
  4827. continuous except for computable poles and singularities, based on some
  4828. earlier work by Ian Cohen and John P. Fitch. The Truncated Power Series
  4829. package is used for non-critical points, at which the value of the
  4830. function is the constant term in the expansion around that point.
  4831. L'Hopital's rule is used in critical cases, with preprocessing of
  4832. $\infty - \infty$ forms and reformatting of product forms in order to
  4833. be able to apply l'Hopital's rule. A limited amount of bounded arithmetic
  4834. is also employed where applicable.
  4835. This package defines a {\tt LIMIT} operator, called with the syntax:
  4836. \begin{verbatim}
  4837. LIMIT(EXPRN:algebraic,VAR:kernel,LIMPOINT:algebraic):
  4838. algebraic.
  4839. \end{verbatim}
  4840. For example:
  4841. \begin{verbatim}
  4842. limit(x*sin(1/x),x,infinity) -> 1
  4843. limit(sin x/x^2,x,0) -> INFINITY
  4844. \end{verbatim}
  4845. Direction-dependent limit operators {\tt LIMIT!+} and {\tt LIMIT!-} are
  4846. also defined.
  4847. This package loads automatically.
  4848. The documentation for this package is in {\LaTeX} format.
  4849. \\ \\
  4850. Author: Stanley L. Kameny.
  4851. \section{ODESOLVE: A Solver for Ordinary Differential Equations}
  4852. \ttindex{ODESOLVE}
  4853. The ODESOLVE package is a solver for ordinary differential equations. At
  4854. the present time it has very limited capabilities. It can handle only a
  4855. single scalar equation presented as an algebraic expression or equation,
  4856. and it can solve only first-order equations of simple types, linear
  4857. equations with constant coefficients and Euler equations. These solvable
  4858. types are exactly those for which Lie symmetry techniques give no useful
  4859. information. For example, the evaluation of
  4860. \begin{verbatim}
  4861. depend(y,x);
  4862. odesolve(df(y,x)=x**2+e**x,y,x);
  4863. \end{verbatim}
  4864. yields the result
  4865. \begin{verbatim}
  4866. X 3
  4867. 3*E + 3*ARBCONST(1) + X
  4868. {Y=---------------------------}
  4869. 3
  4870. \end{verbatim}
  4871. The documentation for this package is in {\LaTeX} format.
  4872. \\ \\
  4873. Main Author: Malcolm A.H. MacCallum.
  4874. Other contributors: Francis Wright, Alan Barnes.
  4875. \section{ORTHOVEC: A Package for the Manipulation of Scalars and Vectors}
  4876. \ttindex{ORTHOVEC}
  4877. ORTHOVEC is a collection of REDUCE procedures and operations which
  4878. provide a simple-to-use environment for the manipulation of scalars and
  4879. vectors. Operations include addition, subtraction, dot and cross
  4880. products, division, modulus, div, grad, curl, laplacian, differentiation,
  4881. integration, and Taylor expansion.
  4882. The documentation for this package is in {\LaTeX} format.
  4883. \\ \\
  4884. Author: James W. Eastwood.
  4885. \section{ROOTS: A REDUCE Root Finding Package} \ttindex{ROOTS}
  4886. This root finding package can be used to find some or all of the roots of a
  4887. univariate polynomial with real or complex coefficients, to the accuracy
  4888. specified by the user.
  4889. It is designed so that it can be used as an independent package, or it may
  4890. be called from {\tt SOLVE} if {\tt ROUNDED} is on. For example,
  4891. the evaluation of
  4892. \begin{verbatim}
  4893. on rounded,complex;
  4894. solve(x**3+x+5,x);
  4895. \end{verbatim}
  4896. yields the result
  4897. \begin{verbatim}
  4898. {X= - 1.51598,X=0.75799 + 1.65035*I,X=0.75799 - 1.65035*I}
  4899. \end{verbatim}
  4900. This package loads automatically.
  4901. \\ \\
  4902. Author: Stanley L. Kameny.
  4903. \section{SCOPE: A Source Code Optimization Package for REDUCE}
  4904. \ttindex{SCOPE}
  4905. SCOPE is a package for the production of an optimized form of a set of
  4906. expressions. It applies an heuristic search for common (sub)expressions
  4907. to almost any set of proper REDUCE assignment statements. The
  4908. output is obtained as a sequence of assignment statements. GENTRAN is
  4909. used to facilitate expression output.
  4910. The document for this package is in troff format.
  4911. \\ \\
  4912. Author: J.A. van Hulzen.
  4913. \section{SPDE: A Package for finding Symmetry groups of {PDE}'s}
  4914. \ttindex{SPDE}
  4915. The package SPDE provides a set of functions which may be used to
  4916. determine the symmetry group of Lie- or point-symmetries of a given system
  4917. of partial differential equations. In many cases the determining system is
  4918. solved completely automatically. In other cases the user has to provide
  4919. additional input information for the solution algorithm to terminate.
  4920. \\ \\
  4921. Author: Fritz Schwarz.
  4922. \section{SUM: A Package for Series Summation} \ttindex{SUM}
  4923. This package implements the Gosper algorithm for the summation of series.
  4924. It defines operators {\tt SUM} and {\tt PROD}. The operator {\tt SUM}
  4925. returns the indefinite or definite summation of a given expresson, and
  4926. {\tt PROD} returns the product of the given expression.
  4927. This package loads automatically.
  4928. The documentation for this package is in {\LaTeX} format.
  4929. \\ \\
  4930. Author: Fujio Kako.
  4931. \section{TAYLOR: A Package for the Manipulation of Taylor Series}
  4932. \ttindex{TAYLOR}
  4933. This package carries out the Taylor expansion of an expression in one or
  4934. more variables and efficient manipulation of the resulting Taylor series.
  4935. Capabilities include basic operations (addition, subtraction,
  4936. multiplication and division) and also application of certain algebraic and
  4937. transcendental functions.
  4938. The document for this package is in {\LaTeX} format.
  4939. \\ \\
  4940. Author: Rainer Sch\"opf.
  4941. \section{TPS: A Truncated Power Series Package} \ttindex{TPS} \ttindex{PS}
  4942. This package implements formal Laurent series expansions in one variable
  4943. using the domain mechanism of REDUCE. This means that power series
  4944. objects can be added, multiplied, differentiated etc., like other first
  4945. class objects in the system. A lazy evaluation scheme is used and thus
  4946. terms of the series are not evaluated until they are required for printing
  4947. or for use in calculating terms in other power series. The series are
  4948. extendible giving the user the impression that the full infinite series is
  4949. being manipulated. The errors that can sometimes occur using series that
  4950. are truncated at some fixed depth (for example when a term in the required
  4951. series depends on terms of an intermediate series beyond the truncation
  4952. depth) are thus avoided.
  4953. The documentation for this package is in {\LaTeX} format.
  4954. \\ \\
  4955. Authors: Alan Barnes and Julian Padget.
  4956. \chapter{Symbolic Mode} \index{Symbolic mode}
  4957. At the system level, {\REDUCE} is based on a version of the programming
  4958. language Lisp \index{Lisp} known as {\em Standard Lisp} which is described
  4959. in J. Marti, Hearn, A. C., Griss, M. L. and Griss, C., ``Standard LISP
  4960. Report" SIGPLAN Notices, ACM, New York, 14, No 10 (1979) 48-68. We shall
  4961. assume in this section that the reader is familiar with the material in
  4962. that paper. This also assumes implicitly that the reader has a reasonable
  4963. knowledge about Lisp in general, say at the level of the LISP 1.5
  4964. Programmer's Manual (McCarthy, J., Abrahams, P. W., Edwards, D. J., Hart,
  4965. T. P. and Levin, M. I., ``LISP 1.5 Programmer's Manual", M.I.T. Press,
  4966. 1965) or any of the books mentioned at the end of this section. Persons
  4967. unfamiliar with this material will have some difficulty understanding this
  4968. section.
  4969. Although {\REDUCE} is designed primarily for algebraic calculations, its
  4970. source language is general enough to allow for a full range of Lisp-like
  4971. symbolic calculations. To achieve this generality, however, it is
  4972. necessary to provide the user with two modes of evaluation, namely an
  4973. algebraic mode \index{Algebraic mode} and a symbolic mode. \index{Symbolic
  4974. mode} To enter symbolic mode, the user types {\tt symbolic;}
  4975. \ttindex{SYMBOLIC} (or {\tt lisp;}) \ttindex{LISP} and to return to
  4976. algebraic mode he types {\tt algebraic;}. \ttindex{ALGEBRAIC}.
  4977. Evaluations proceed differently in each mode so the user is advised to
  4978. check what mode he is in if a puzzling error arises. He can find his mode
  4979. by typing \ttindex{"!*MODE}
  4980. \begin{verbatim}
  4981. !*mode;
  4982. \end{verbatim}
  4983. The current mode will then be printed as {\tt ALGEBRAIC} or {\tt SYMBOLIC}.
  4984. Expression evaluation may proceed in either mode at any level of a
  4985. calculation, provided the results are passed from mode to mode in a
  4986. compatible manner. One simply prefixes the relevant expression by the
  4987. appropriate mode. If the mode name prefixes an expression at the top
  4988. level, it will then be handled as if the global system mode had been
  4989. changed for the scope of that particular calculation.
  4990. For example, if the current mode is {\tt ALGEBRAIC}, then the commands
  4991. \begin{verbatim}
  4992. symbolic car '(a);
  4993. x+y;
  4994. \end{verbatim}
  4995. will cause the first expression to be evaluated and printed in symbolic
  4996. mode and the second in algebraic mode. Only the second evaluation will
  4997. thus affect the expression workspace. On the other hand, the statement
  4998. \begin{verbatim}
  4999. x + symbolic car '(12);
  5000. \end{verbatim}
  5001. will result in the algebraic value {\tt X+12}.
  5002. The use of {\tt SYMBOLIC} (and equivalently {\tt ALGEBRAIC}) in this
  5003. manner is the same as any operator. That means that parentheses could be
  5004. omitted in the above examples since the meaning is obvious. In other
  5005. cases, parentheses must be used, as in
  5006. \begin{verbatim}
  5007. symbolic(x := 'a);
  5008. \end{verbatim}
  5009. Omitting the parentheses, as in
  5010. \begin{verbatim}
  5011. symbolic x := a;
  5012. \end{verbatim}
  5013. would be wrong, since it would parse as
  5014. \begin{verbatim}
  5015. symbolic(x) := a;
  5016. \end{verbatim}
  5017. For convenience, it is assumed that any operator whose {\em first} argument is
  5018. quoted is being evaluated in symbolic mode, regardless of the mode in
  5019. effect at that time. Thus, the first example above could be equally well
  5020. written:
  5021. \begin{verbatim}
  5022. car '(a);
  5023. \end{verbatim}
  5024. Except where explicit limitations have been made, most {\REDUCE} algebraic
  5025. constructions carry over into symbolic mode. \index{Symbolic mode}
  5026. However, there are some differences. First, expression evaluation now
  5027. becomes Lisp evaluation. Secondly, assignment statements are handled
  5028. differently, as we shall discuss shortly. Thirdly, local variables and array
  5029. elements are initialized to {\tt NIL} rather than {\tt 0}. (In fact, any
  5030. variables not explicitly declared {\tt INTEGER} are also initialized to
  5031. {\tt NIL} in algebraic mode, but the algebraic evaluator recognizes {\tt
  5032. NIL} as {\tt 0}.) Finally, function definitions follow the conventions of
  5033. Standard Lisp.
  5034. To begin with, we mention a few extensions to our basic syntax which are
  5035. designed primarily if not exclusively for symbolic mode.
  5036. \section{Symbolic Infix Operators}
  5037. There are four binary infix operators in {\REDUCE} intended for use in
  5038. symbolic mode, namely . {\tt (CONS), EQ, MEMBER and MEMQ}. The precedence of
  5039. these operators was given in another section.
  5040. \section{Symbolic Expressions}
  5041. These consist of scalar variables and operators and follow the normal
  5042. rules of the Lisp meta language.
  5043. {\it Examples:}
  5044. \begin{verbatim}
  5045. x
  5046. car u . reverse v
  5047. simp (u+v^2)
  5048. \end{verbatim}
  5049. \section{Quoted Expressions} \ttindex{QUOTE}
  5050. Because symbolic evaluation requires that each variable or expression has a
  5051. value, it is necessary to add to {\REDUCE} the concept of a quoted expression
  5052. by analogy with the Lisp {\tt QUOTE} function. This is provided by the single
  5053. quote mark {\tt '}. For example,
  5054. \begin{quote}
  5055. \begin{tabbing}
  5056. {\tt 'a} \hspace{0.5in} \= represents the Lisp S-expression \hspace{0.2 in} \=
  5057. {\tt (quote a)} \\
  5058. {\tt '(a b c)} \> represents the Lisp S-expression \> {\tt (quote (a b c))}
  5059. \end{tabbing}
  5060. \end{quote}
  5061. Note, however, that strings are constants and therefore evaluate to
  5062. themselves in symbolic mode. Thus, to print the string {\tt "A String"}, one
  5063. would write
  5064. \begin{verbatim}
  5065. prin2 "A String";
  5066. \end{verbatim}
  5067. Within a quoted expression, identifier syntax rules are those of {\REDUCE}.
  5068. Thus {\tt ( A !. B)} is the list consisting of the three elements {\tt A},
  5069. {\tt .}, and {\tt B}, whereas {\tt (A . B)} is the dotted pair of {\tt A}
  5070. and {\tt B}.
  5071. \section{Lambda Expressions} \ttindex{LAMBDA}
  5072. \label{sec-lambda}
  5073. {\tt LAMBDA} expressions provide the means for constructing Lisp {\tt LAMBDA}
  5074. expressions in symbolic mode. They may not be used in algebraic mode.
  5075. Syntax:
  5076. \begin{verbatim}
  5077. <LAMBDA expression> ::=
  5078. LAMBDA <varlist><terminator><statement>
  5079. \end{verbatim}
  5080. where
  5081. \begin{verbatim}
  5082. <varlist> ::= (<variable>,...,<variable>)
  5083. \end{verbatim}
  5084. e.g.,
  5085. \begin{verbatim}
  5086. lambda (x,y); car x . cdr y;
  5087. \end{verbatim}
  5088. is equivalent to the Lisp {\tt LAMBDA} expression
  5089. \begin{verbatim}
  5090. (lambda (x y) (cons (car x) (cdr y)))
  5091. \end{verbatim}
  5092. The parentheses may be omitted in specifying the variable list if desired.
  5093. {\tt LAMBDA} expressions may be used in symbolic mode in place of prefix
  5094. operators, or as an argument of the reserved word {\tt FUNCTION}.
  5095. In those cases where a {\tt LAMBDA} expression is used to introduce local
  5096. variables to avoid recomputation, a {\tt WHERE} statement can also be
  5097. used. For example, the expression
  5098. \begin{verbatim}
  5099. (lambda (x,y); list(car x,cdr x,car y,cdr y))
  5100. (reverse u,reverse v)
  5101. \end{verbatim}
  5102. can also be written
  5103. \begin{verbatim}
  5104. {car x,cdr x,car y,cdr y} where x=reverse u,y=reverse v
  5105. \end{verbatim}
  5106. Where possible, {\tt WHERE} syntax is preferred to {\tt LAMBDA} syntax,
  5107. since it is more natural.
  5108. \section{Symbolic Assignment Statements} \index{Assignment}
  5109. In symbolic mode, if the left side of an assignment statement is a
  5110. variable, a {\tt SETQ} of the right-hand side to that variable occurs. If
  5111. the left-hand side is an expression, it must be of the form of an array
  5112. element, otherwise an error will result. For example, {\tt x:=y}
  5113. translates into {\tt (SETQ X Y)} whereas {\tt a(3) := 3} will be valid if
  5114. {\tt A} has been previously declared a single dimensioned array of at
  5115. least four elements.
  5116. \section{FOR EACH Statement} \ttindex{FOR EACH}
  5117. The {\tt FOR EACH} form of the {\tt FOR} statement, designed for iteration
  5118. down a list, is more general in symbolic mode. Its syntax is:
  5119. \begin{verbatim}
  5120. FOR EACH ID:identifier {IN|ON} LST:list
  5121. {DO|COLLECT|JOIN|PRODUCT|SUM} EXPRN:S-expr
  5122. \end{verbatim}
  5123. As in algebraic mode, if the keyword {\tt IN} is used, iteration is on
  5124. each element of the list. With {\tt ON}, iteration is on the whole list
  5125. remaining at each point in the iteration. As a result, we have the
  5126. following equivalence between each form of {\tt FOR EACH} and the various
  5127. mapping functions in Lisp:
  5128. \begin{center}
  5129. {\tt
  5130. \begin{tabular}{|l|lr r|} \hline
  5131. & DO & COLLECT & JOIN \\ \hline
  5132. IN & MAPC & MAPCAR & MAPCAN \\
  5133. ON & MAP & MAPLIST & MAPCON \\ \hline
  5134. \end{tabular}}
  5135. \end{center}
  5136. {\it Example:} To list each element of the list {\tt (a b c)}:
  5137. \begin{verbatim}
  5138. for each x in '(a b c) collect list x;
  5139. \end{verbatim}
  5140. \section{Symbolic Procedures} \index{Symbolic procedure}
  5141. All the functions described in the Standard Lisp Report are available to
  5142. users in symbolic mode. Additional functions may also be defined as
  5143. symbolic procedures. For example, to define the Lisp function {\tt ASSOC},
  5144. the following could be used:
  5145. \begin{verbatim}
  5146. symbolic procedure assoc(u,v);
  5147. if null v then nil
  5148. else if u = caar v then car v
  5149. else assoc(u, cdr v);
  5150. \end{verbatim}
  5151. If the default mode were symbolic, then {\tt SYMBOLIC} could be omitted in
  5152. the above definition. {\tt MACRO}s may be defined by
  5153. prefixing the keyword {\tt PROCEDURE} by the word {\tt MACRO}.
  5154. (In fact, ordinary functions may be defined with the keyword {\tt
  5155. EXPR} prefixing {\tt PROCEDURE} as was used in the Standard Lisp Report.)
  5156. For example, we could define a {\tt MACRO CONSCONS} by
  5157. \begin{verbatim}
  5158. symbolic macro procedure conscons l;
  5159. expand(cdr l,'cons);
  5160. \end{verbatim}
  5161. The Standard Lisp Report also defines a function type {\tt FEXPR}.
  5162. However, its use is discouraged since it is hard to implement efficiently,
  5163. and most uses can be replaced by macros. At the present time, there are
  5164. no {\tt FEXPR}s in the core REDUCE system.
  5165. \section{Standard Lisp Equivalent of Reduce Input}
  5166. A user can obtain the Standard Lisp equivalent of his {\REDUCE} input by
  5167. turning on the switch {\tt DEFN} \ttindex{DEFN} (for definition). The
  5168. system then prints the Lisp translation of his input but does not evaluate
  5169. it. Normal operation is resumed when {\tt DEFN} is turned off.
  5170. \section{Communicating with Algebraic Mode} \index{Mode communication}
  5171. One of the principal motivations for a user of the algebraic facilities of
  5172. {\REDUCE} to learn about symbolic mode \index{Symbolic mode} is that it
  5173. gives one access to a wider range of techniques than is possible in
  5174. algebraic mode \index{Algebraic mode} alone. For example, if a user
  5175. wishes to use parts of the system defined in the basic system source code,
  5176. or refine their algebraic code definitions to make them more efficient,
  5177. then it is necessary to understand the source language in fairly complete
  5178. detail. Moreover, it is also necessary to know a little more about the
  5179. way {\REDUCE} operates internally. Basically, {\REDUCE} considers
  5180. expressions in two forms: prefix form, which follow the normal Lisp rules
  5181. of function composition, and so called canonical form, which uses a
  5182. completely different syntax.
  5183. Once these details are understood, the most critical problem faced by a
  5184. user is how to make expressions and procedures communicate between symbolic
  5185. and algebraic mode. The purpose of this section is to teach a user the
  5186. basic principles for this.
  5187. If one wants to evaluate an expression in algebraic mode, and then use
  5188. that expression in symbolic mode calculations, or vice versa, the easiest
  5189. way to do this is to assign a variable to that expression whose value is
  5190. easily obtainable in both modes. To facilitate this, a declaration {\tt
  5191. SHARE} \ttindex{SHARE} is available. {\tt SHARE} takes a list of
  5192. identifiers as argument, and marks these variables as having recognizable
  5193. values in both modes. The declaration may be used in either mode.
  5194. E.g.,
  5195. \begin{verbatim}
  5196. share x,y;
  5197. \end{verbatim}
  5198. says that {\tt X} and {\tt Y} will receive values to be used in both modes.
  5199. If a {\tt SHARE} declaration is made for a variable with a previously
  5200. assigned algebraic value, that value is also made available in symbolic
  5201. mode.
  5202. \subsection{Passing Algebraic Mode Values to Symbolic Mode}
  5203. If one wishes to work with parts of an algebraic mode
  5204. \index{Algebraic mode} expression in symbolic mode, \index{Symbolic mode}
  5205. one simply makes an assignment \index{Assignment} of a shared variable to
  5206. the relevant expression in algebraic mode. For example, if one wishes to
  5207. work with {\tt (a+b)\^{ }2}, one would say, in algebraic mode:
  5208. \begin{verbatim}
  5209. x := (a+b)^2;
  5210. \end{verbatim}
  5211. assuming that {\tt X} was declared shared as above. If we now change to
  5212. symbolic mode and say
  5213. \begin{verbatim}
  5214. x;
  5215. \end{verbatim}
  5216. its value will be printed as a prefix form with the syntax:
  5217. \begin{verbatim}
  5218. (*SQ <standard quotient> T)
  5219. \end{verbatim}
  5220. This particular format reflects the fact that the algebraic mode processor
  5221. currently likes to transfer prefix forms from command to command, but
  5222. doesn't like to reconvert standard forms \index{Standard form} (which
  5223. represent polynomials) and standard quotients back to a true Lisp prefix
  5224. form for the expression (which would result in excessive computation). So
  5225. {\tt *SQ} is used to tell the algebraic processor that it is dealing with
  5226. a prefix form which is really a standard quotient \index{Standard
  5227. quotient} and the second argument ({\tt T} or {\tt NIL}) tells it whether
  5228. it needs further processing (essentially, an {\em already simplified}
  5229. flag).
  5230. So to get the true standard quotient form in symbolic mode, one needs
  5231. {\tt CADR} of the variable. E.g.,
  5232. \begin{verbatim}
  5233. z := cadr x;
  5234. \end{verbatim}
  5235. would store in {\tt Z} the standard quotient form for {\tt (a+b)\^{ }2}.
  5236. Once you have this expression, you can now manipulate it as you wish. To
  5237. facilitate this, a standard set of selectors \index{Selector} and
  5238. constructors \index{Constructor} are available for getting at parts of the
  5239. form. Those presently defined are as follows:
  5240. \begin{center}
  5241. {\large REDUCE Selectors}
  5242. \end{center}
  5243. \begin{center}
  5244. \begin{tabular}{l r}
  5245. {\tt DENR} & \parbox[t]{\rboxwidth}{denominator of standard quotient} \\ \\
  5246. {\tt LC} & \parbox[t]{\rboxwidth}{leading coefficient of polynomial} \\ \\
  5247. {\tt LDEG} & \parbox[t]{\rboxwidth}{leading degree of polynomial} \\ \\
  5248. {\tt LPOW} & \parbox[t]{\rboxwidth}{leading power of polynomial} \\ \\
  5249. {\tt LT} & \parbox[t]{\rboxwidth}{leading term of polynomial} \\ \\
  5250. {\tt MVAR} & \parbox[t]{\rboxwidth}{main variable of polynomial} \\ \\
  5251. {\tt NUMR} & \parbox[t]{\rboxwidth}{numerator (of standard quotient)} \\ \\
  5252. {\tt PDEG} & \parbox[t]{\rboxwidth}{degree of a power} \\ \\
  5253. {\tt RED} & \parbox[t]{\rboxwidth}{reductum of polynomial} \\ \\
  5254. {\tt TC} & \parbox[t]{\rboxwidth}{coefficient of a term} \\ \\
  5255. {\tt TDEG} & \parbox[t]{\rboxwidth}{degree of a term} \\ \\
  5256. {\tt TPOW} & \parbox[t]{\rboxwidth}{power of a term} \\ \\
  5257. \end{tabular}
  5258. \end{center}
  5259. \begin{center}
  5260. {\large REDUCE Constructors}
  5261. \end{center}
  5262. \begin{center}
  5263. \begin{tabular}{l r}
  5264. {\tt .+} & \parbox[t]{\redboxwidth}{add a term to a polynomial} \\ \\
  5265. {\tt ./} & \parbox[t]{\redboxwidth}{divide (two polynomials to get quotient)}
  5266. \\ \\
  5267. {\tt .*} & \parbox[t]{\redboxwidth}{multiply power by coefficient to produce
  5268. term} \\ \\
  5269. {\tt .\^{ }} & \parbox[t]{\redboxwidth}{raise a variable to a power} \\ \\
  5270. \end{tabular}
  5271. \end{center}
  5272. For example, to find the numerator of the standard quotient above, one
  5273. could say:
  5274. \begin{verbatim}
  5275. numr z;
  5276. \end{verbatim}
  5277. or to find the leading term of the numerator:
  5278. \begin{verbatim}
  5279. lt numr z;
  5280. \end{verbatim}
  5281. Conversion between various data structures is facilitated by the use of a
  5282. set of functions defined for this purpose. Those currently implemented
  5283. include: \\ \\
  5284. \begin{tabular}{l r}
  5285. {\tt !*A2F} & \parbox[t]{\reduceboxwidth}{convert an algebraic expression to
  5286. a standard form. If result is rational, an error results;} \\ \\
  5287. {\tt !*A2K} & \parbox[t]{\reduceboxwidth}{converts an algebraic expression to
  5288. a kernel. If this is not possible, an error results;} \\ \\
  5289. {\tt !*F2A} & \parbox[t]{\reduceboxwidth}{converts a standard form to an
  5290. algebraic expression;} \\ \\
  5291. {\tt !*F2Q} & \parbox[t]{\reduceboxwidth}{convert a standard form to a
  5292. standard quotient;} \\ \\
  5293. {\tt !*K2F} & \parbox[t]{\reduceboxwidth}{convert a kernel to a standard form;}
  5294. \\ \\
  5295. {\tt !*K2Q} & \parbox[t]{\reduceboxwidth}{convert a kernel to a standard
  5296. quotient;} \\ \\
  5297. {\tt !*P2F} & \parbox[t]{\reduceboxwidth}{convert a standard power to a
  5298. standard form;} \\ \\
  5299. {\tt !*P2Q} & \parbox[t]{\reduceboxwidth}{convert a standard power to a standard
  5300. quotient;} \\ \\
  5301. {\tt !*Q2F} & \parbox[t]{\reduceboxwidth}{convert a standard quotient to a
  5302. standard form. If the quotient denominator is not 1, an error results;} \\ \\
  5303. {\tt !*Q2K} & \parbox[t]{\reduceboxwidth}{convert a standard quotient to a
  5304. kernel. If this is not possible, an error results;} \\ \\
  5305. {\tt !*T2F} & \parbox[t]{\reduceboxwidth}{convert a standard term to a
  5306. standard form} \\ \\
  5307. {\tt !*T2Q} & \parbox[t]{\reduceboxwidth}{convert a standard term to a
  5308. standard quotient.}
  5309. \end{tabular}
  5310. \subsection{Passing Symbolic Mode Values to Algebraic Mode}
  5311. In order to pass the value of a shared variable from symbolic mode to
  5312. algebraic mode, the only thing to do is make sure that the value in
  5313. symbolic mode is a prefix expression. E.g., one uses
  5314. {\tt (expt (plus a b) 2)} for {\tt (a+b)\^{ }2}, or the format ({\tt *sq
  5315. <standard quotient> t}) as described above. However, if you have
  5316. been working with parts of a standard form they will probably not be in
  5317. this form. In that case, you can do the following:
  5318. \begin{enumerate}
  5319. \item If it is a standard quotient, call {\tt PREPSQ} on it. This takes a
  5320. standard quotient as argument, and returns a prefix expression.
  5321. Alternatively, you can call {\tt MK!*SQ} on it, which returns a prefix
  5322. form like ({\tt *SQ <standard quotient> T)} and avoids translation of
  5323. the expression into a true prefix form.
  5324. \item If it is a standard form, call {\tt PREPF} on it. This takes a
  5325. standard form as argument, and returns the equivalent prefix expression.
  5326. Alternatively, you can convert it to a standard quotient and then call
  5327. {\tt MK!*SQ}.
  5328. \item If it is a part of a standard form, you must usually first build up a
  5329. standard form out of it, and then go to step 2. The conversion functions
  5330. described earlier may be used for this purpose. For example,
  5331. \begin{enumerate}
  5332. \item If {\tt Z} is an expression which is a term, {\tt !*T2F Z} is a
  5333. standard form.
  5334. \item If {\tt Z} is a standard power, {\tt !*P2F Z} is a standard form.
  5335. \item If {\tt Z} is a variable, you can pass it direct to algebraic mode.
  5336. \end{enumerate}
  5337. \end{enumerate}
  5338. For example, to pass the leading term of {\tt (a+b)\^{ }2} back to
  5339. algebraic mode, one could say:
  5340. \begin{verbatim}
  5341. y:= mk!*sq !*t2q lt numr z;
  5342. \end{verbatim}
  5343. where {\tt Y} has been declared shared as above. If you now go back to
  5344. algebraic mode, you can work with {\tt Y} in the usual way.
  5345. \subsection{Complete Example}
  5346. The following is the complete code for doing the above steps. The end
  5347. result will be that the square of the leading term of $(a+b)^{2}$ is
  5348. calculated.
  5349. \begin{tabular}{l r}
  5350. {\tt share x,y;} & \parbox[t]{\rboxwidth}{{\tt \% declare {\tt X} and
  5351. {\tt Y} as shared}} \\
  5352. {\tt x := (a+b)\^{ }2;} & \parbox[t]{\rboxwidth}{{\tt \% store (a+b)\^{ }2
  5353. in X}} \\
  5354. {\tt symbolic;} & \parbox[t]{\rboxwidth}{{\tt \% transfer to symbolic mode}}
  5355. \\
  5356. {\tt z := cadr x;} & \parbox[t]{\rboxwidth}{\tt {\% store a true standard
  5357. quotient \% in Z}} \\
  5358. {\tt lt numr z;} & \parbox[t]{\rboxwidth}{{\tt \% print the leading term
  5359. of the \% numerator of Z}} \\
  5360. {\tt y := mk!*sq !*t2q numr z;} & \parbox[t]{\rboxwidth}{{\tt \% store the
  5361. prefix form of this \% leading term in Y}} \\
  5362. {\tt algebraic;} & \parbox[t]{\rboxwidth}{{\tt \% return to algebraic mode}}
  5363. \\
  5364. {\tt y\^{ }2;} & \parbox[t]{\rboxwidth}{{\tt \% evaluate square of the leading
  5365. \% term of (a+b)\^{ }2}} \\
  5366. \end{tabular}
  5367. \subsection{Defining Procedures to Communicate Between Modes}
  5368. If one wishes to define a procedure in symbolic mode for use as an
  5369. operator in algebraic mode, it is necessary to declare this fact to the
  5370. system by using the declaration {\tt OPERATOR} \ttindex{OPERATOR} in
  5371. symbolic mode. Thus
  5372. \begin{verbatim}
  5373. symbolic operator leadterm;
  5374. \end{verbatim}
  5375. would declare the procedure {\tt LEADTERM} as an algebraic operator. This
  5376. declaration {\em must} be made in symbolic mode as the effect in algebraic
  5377. mode is different. The value of such a procedure must be a prefix form.
  5378. The algebraic processor will pass arguments to such procedures in prefix
  5379. form. Therefore if you want to work with the arguments as standard
  5380. quotients you must first convert them to that form by using the function
  5381. {\tt SIMP!*}. This function takes a prefix form as argument and returns the
  5382. evaluated standard quotient.
  5383. For example, if you want to define a procedure {\tt LEADTERM} which gives the
  5384. leading term of an algebraic expression, one could do this as follows:
  5385. \begin{verbatim}
  5386. symbolic operator leadterm; % Declare LEADTERM as a symbolic
  5387. % mode procedure to be used in
  5388. % algebraic mode.
  5389. symbolic procedure leadterm u; % Define LEADTERM.
  5390. mk!*sq !*t2q lt numr simp!* u;
  5391. \end{verbatim}
  5392. Note that this operator has a different effect than the operator {\tt LTERM}
  5393. \ttindex{LTERM} (q.v.). In the latter case, the calculation is done
  5394. with respect to the second argument of the operator. In the example here,
  5395. we simply extract the leading term with respect to the system's choice of
  5396. main variable.
  5397. Finally, if you wish to use the algebraic evaluator on an argument in a
  5398. symbolic mode definition, the function {\tt REVAL} can be used. The one
  5399. argument of {\tt REVAL} must be the prefix form of an expression. {\tt
  5400. REVAL} returns the evaluated expression as a true Lisp prefix form.
  5401. \section{References}
  5402. There are a number of useful books which can give you further information
  5403. about LISP. Here is a selection:
  5404. Allen, J.R., ``The Anatomy of LISP", McGraw Hill, New York, 1978.
  5405. McCarthy J., P.W. Abrahams, J. Edwards, T.P. Hart and
  5406. M.I. Levin, ``LISP 1.5 Programmer's Manual", M.I.T. Press, 1965.
  5407. Touretzky, D.S, ``{LISP}: A Gentle Introduction to Symbolic Computation",
  5408. Harper \& Row, New York, 1984.
  5409. Winston, P.H. and Horn, B.K.P., ``LISP", Addison-Wesley, 1981.
  5410. \chapter{Calculations in High Energy Physics}
  5411. A set of {\REDUCE} commands is provided for users interested in symbolic
  5412. calculations in high energy physics. Several extensions to our basic
  5413. syntax are necessary, however, to allow for the different data structures
  5414. encountered.
  5415. \section{High Energy Physics Operators}
  5416. We begin by introducing three new operators required in these calculations.
  5417. \subsection{. (Cons) Operator} \index{Dot product}
  5418. \begin{verbatim}
  5419. Syntax: (EXPRN1:vector_expression)
  5420. . (EXPRN2:vector_expression):algebraic.
  5421. \end{verbatim}
  5422. The binary {\tt .} operator, which is normally used to denote the addition
  5423. of an element to the front of a list, can also be used in algebraic mode
  5424. to denote the scalar product of two Lorentz four-vectors. For this to
  5425. happen, the second argument must be recognizable as a vector expression
  5426. \index{High energy vector expression} (q.v.) at the time of
  5427. evaluation. With this meaning, this operator is often referred to as the
  5428. ``dot" operator. In the present system, the index handling routines all
  5429. assume that Lorentz four-vectors are used, but these routines could be
  5430. rewritten to handle other cases.
  5431. Components of vectors can be represented by including representations of
  5432. unit vectors in the system. Thus if {\tt EO} represents the unit vector
  5433. {\tt (1,0,0,0)}, {\tt (p.eo)} represents the zeroth component of the
  5434. four-vector P. Our metric and notation follows Bjorken and Drell
  5435. ``Relativistic Quantum Mechanics" (McGraw-Hill, New York, 1965).
  5436. Similarly, an arbitrary component {\tt P} may be represented by
  5437. {\tt (p.u)}. If contraction over components of vectors is required, then
  5438. the declaration {\tt INDEX} \ttindex{INDEX} must be used. Thus
  5439. \begin{verbatim}
  5440. index u;
  5441. \end{verbatim}
  5442. declares {\tt U} as an index, and the simplification of
  5443. \begin{verbatim}
  5444. p.u * q.u
  5445. \end{verbatim}
  5446. would result in
  5447. \begin{verbatim}
  5448. P.Q
  5449. \end{verbatim}
  5450. The metric tensor $g^{\mu \nu}$ may be represented by {\tt (u.v)}. If
  5451. contraction over {\tt U} and {\tt V} is required, then they should be
  5452. declared as indices.
  5453. Errors occur if indices are not properly matched in expressions.
  5454. If a user later wishes to remove the index property from specific vectors,
  5455. he can do it with the declaration {\tt REMIND}.\ttindex{REMIND} Thus
  5456. {\tt remind v1...vn;} removes the index flags from the variables {\tt V1}
  5457. through {\tt Vn}. However, these variables remain vectors in the system.
  5458. \subsection{G Operator for Gamma Matrices} \index{Dirac $\gamma$ matrix}
  5459. \ttindex{G}
  5460. Syntax:
  5461. \begin{verbatim}
  5462. G(ID:identifier[,EXPRN:vector_expression])
  5463. :gamma_matrix_expression.
  5464. \end{verbatim}
  5465. {\tt G} is an n-ary operator used to denote a product of $\gamma$ matrices
  5466. contracted with Lorentz four-vectors. Gamma matrices are associated with
  5467. fermion lines in a Feynman diagram. If more than one such line occurs,
  5468. then a different set of $\gamma$ matrices (operating in independent spin
  5469. spaces) is required to represent each line. To facilitate this, the first
  5470. argument of {\tt G} is a line identification identifier (not a number)
  5471. used to distinguish different lines.
  5472. Thus
  5473. \begin{verbatim}
  5474. g(l1,p) * g(l2,q)
  5475. \end{verbatim}
  5476. denotes the product of {\tt P/} associated with a fermion line identified as
  5477. {\tt L1}, and {\tt Q/} associated with another line identified as {\tt L2} and
  5478. where {\tt P} and {\tt Q} are Lorentz four-vectors. A product of $\gamma$
  5479. matrices associated with the same line may be written in a contracted
  5480. form.
  5481. Thus
  5482. \begin{verbatim}
  5483. g(l1,p1,p2,...,p3) = g(l1,p1)*g(l1,p2)*,...,*g(l1,p3) .
  5484. \end{verbatim}
  5485. The vector {\tt A} is reserved in arguments of G to denote the special
  5486. $\gamma$ matrix $\gamma^{5}$. Thus
  5487. \begin{quote}
  5488. \begin{tabbing}
  5489. \ \ \ \ \ {\tt g(l,a)}\hspace{0.2in} \= =\ \ \ $\gamma^{5}$ \hspace{0.5in}
  5490. \= associated with the line {\tt l} \\[0.1in]
  5491. \ \ \ \ \ {\tt g(l,p,a)} \> =\ \ \ $\gamma$.p $\times \gamma^{5}$ \>
  5492. associated with the line {\tt L}.
  5493. \end{tabbing}
  5494. \end{quote}
  5495. $\gamma^{\mu}$ (associated with the line {\tt L}) may be written as
  5496. {\tt g(l,u)}, with {\tt U} flagged as an index if contraction over {\tt U}
  5497. is required.
  5498. The notation of Bjorken and Drell is assumed in all operations involving
  5499. $\gamma$ matrices.
  5500. \subsection{EPS Operator} \ttindex{EPS}
  5501. \begin{verbatim}
  5502. Syntax: EPS(EXPRN1:vector_expression,...,EXPRN4:vector_exp)
  5503. :vector_exp.
  5504. \end{verbatim}
  5505. The operator {\tt EPS} has four arguments, and is used only to denote the
  5506. completely antisymmetric tensor of order 4 and its contraction with Lorentz
  5507. four-vectors. Thus
  5508. \[ \epsilon_{i j k l} = \left\{ \begin{array}{cl}
  5509. +1 & \mbox{if $i,j,k,l$ is an even permutation
  5510. of 0,1,2,3} \\
  5511. -1 & \mbox{if an odd permutation} \\
  5512. 0 & \mbox{otherwise}
  5513. \end{array}
  5514. \right. \]
  5515. A contraction of the form $\epsilon_{i j \mu \nu}p_{\mu}q_{\nu}$ may be
  5516. written as {\tt eps(i,j,p,q)}, with {\tt I} and {\tt J} flagged as indices,
  5517. and so on.
  5518. \section{Vector Variables}
  5519. Apart from the line identification identifier in the {\tt G} operator, all
  5520. other arguments of the operators in this section are vectors. Variables
  5521. used as such must be declared so by the type declaration {\tt VECTOR},
  5522. \ttindex{VECTOR} for example:
  5523. \begin{verbatim}
  5524. vector p1,p2;
  5525. \end{verbatim}
  5526. declares {\tt P1} and {\tt P2} to be vectors. Variables declared as
  5527. indices or given a mass \ttindex{MASS} (q.v.) are automatically declared
  5528. vector by these declarations.
  5529. \section{Additional Expression Types}
  5530. Two additional expression types are necessary for high energy
  5531. calculations, namely
  5532. \subsection{Vector Expressions} \index{High energy vector expression}
  5533. These follow the normal rules of vector combination. Thus the product of a
  5534. scalar or numerical expression and a vector expression is a vector, as are
  5535. the sum and difference of vector expressions. If these rules are not
  5536. followed, error messages are printed. Furthermore, if the system finds an
  5537. undeclared variable where it expects a vector variable, it will ask the
  5538. user in interactive mode whether to make that variable a vector or not. In
  5539. batch mode, the declaration will be made automatically and the user
  5540. informed of this by a message.
  5541. {\tt Examples:}
  5542. Assuming {\tt P} and {\tt Q} have been declared vectors, the following are
  5543. vector expressions
  5544. \begin{verbatim}
  5545. p
  5546. 2*q/3
  5547. 2*x*y*p - p.q*q/(3*q.q)
  5548. \end{verbatim}
  5549. whereas {\tt p*q} and {\tt p/q} are not.
  5550. \subsection{Dirac Expressions}
  5551. These denote those expressions which involve $\gamma$ matrices. A $\gamma$
  5552. matrix is implicitly a 4 $\times$ 4 matrix, and so the product, sum and
  5553. difference of such expressions, or the product of a scalar and Dirac
  5554. expression is again a Dirac expression. There are no Dirac variables in
  5555. the system, so whenever a scalar variable appears in a Dirac expression
  5556. without an associated $\gamma$ matrix expression, an implicit unit 4
  5557. by 4 matrix is assumed. For example, {\tt g(l,p) + m} denotes {\tt
  5558. g(l,p) + m*<unit 4 by 4 matrix>}. Multiplication of Dirac
  5559. expressions, as for matrix expressions, is of course non-commutative.
  5560. \section{Trace Calculations} \index{High energy trace}
  5561. When a Dirac expression is evaluated, the system computes one quarter of
  5562. the trace of each $\gamma$ matrix product in the expansion of the expression.
  5563. One quarter of each trace is taken in order to avoid confusion between the
  5564. trace of the scalar {\tt M}, say, and {\tt M} representing {\tt M * <unit
  5565. 4 by 4 matrix>}. Contraction over indices occurring in such expressions is
  5566. also performed. If an unmatched index is found in such an expression, an
  5567. error occurs.
  5568. The algorithms used for trace calculations are the best available at the
  5569. time this system was produced. For example, in addition to the algorithm
  5570. developed by Chisholm for contracting indices in products of traces,
  5571. {\REDUCE} uses the elegant algorithm of Kahane for contracting indices in
  5572. $\gamma$ matrix products. These algorithms are described in Chisholm, J. S.
  5573. R., Il Nuovo Cimento X, 30, 426 (1963) and Kahane, J., Journal Math.
  5574. Phys. 9, 1732 (1968).
  5575. It is possible to prevent the trace calculation over any line identifier
  5576. by the declaration {\tt NOSPUR}. \ttindex{NOSPUR} For example,
  5577. \begin{verbatim}
  5578. nospur l1,l2;
  5579. \end{verbatim}
  5580. will mean that no traces are taken of $\gamma$ matrix terms involving the line
  5581. numbers {\tt L1} and {\tt L2}. However, in some calculations involving
  5582. more than one line, a catastrophic error
  5583. \begin{verbatim}
  5584. This NOSPUR option not implemented
  5585. \end{verbatim}
  5586. can occur (for the reason stated!) If you encounter this error, please let
  5587. us know!
  5588. A trace of a $\gamma$ matrix expression involving a line identifier which has
  5589. been declared {\tt NOSPUR} may be later taken by making the declaration
  5590. {\tt SPUR}. \ttindex{SPUR}
  5591. \section{Mass Declarations} \ttindex{MASS}
  5592. It is often necessary to put a particle ``on the mass shell" in a
  5593. calculation. This can, of course, be accomplished with a {\tt LET}
  5594. command such as
  5595. \begin{verbatim}
  5596. let p.p= m^2;
  5597. \end{verbatim}
  5598. but an alternative method is provided by two commands {\tt MASS} and
  5599. {\tt MSHELL}. \ttindex{MSHELL}
  5600. {\tt MASS} takes a list of equations of the form:
  5601. \begin{verbatim}
  5602. <vector variable> = <scalar variable>
  5603. \end{verbatim}
  5604. for example,
  5605. \begin{verbatim}
  5606. mass p1=m, q1=mu;
  5607. \end{verbatim}
  5608. The only effect of this command is to associate the relevant scalar
  5609. variable as a mass with the corresponding vector. If we now say
  5610. \begin{verbatim}
  5611. mshell <vector variable>,...,<vector variable>;
  5612. \end{verbatim}
  5613. and a mass has been associated with these arguments, a substitution of the
  5614. form
  5615. \begin{verbatim}
  5616. <vector variable>.<vector variable> = <mass>^2
  5617. \end{verbatim}
  5618. is set up. An error results if the variable has no preassigned mass.
  5619. \section{Example}
  5620. We give here as an example of a simple calculation in high energy physics
  5621. the computation of the Compton scattering cross-section as given in
  5622. Bjorken and Drell Eqs. (7.72) through (7.74). We wish to compute the trace of
  5623. $$\left. \alpha^2\over2 \right. \left({k^\prime\over k}\right)^2
  5624. \left({\gamma.p_f+m\over2m}\right)\left({\gamma.e^\prime \gamma.e
  5625. \gamma.k_i\over2k\cdot \gamma.p_i} + {\gamma.e\gamma.e^\prime
  5626. \gamma.k_f\over2k^\prime\cdot \gamma.p_i}\right)
  5627. \left({\gamma.p_i+m\over2m}\right)$$
  5628. $$
  5629. \left({\gamma.k_i\gamma.e\gamma.e^\prime\over2k\cdot \gamma.p_i} +
  5630. {\gamma.k_f\gamma.e^\prime\gamma.e\over2k^\prime\cdot \gamma.p_i}
  5631. \right)
  5632. $$
  5633. where $k_i$ and $k_f$ are the four-momenta of incoming and outgoing photons
  5634. (with polarization vectors $e$ and $e^\prime$ and laboratory energies
  5635. $k$ and $k^\prime$
  5636. respectively) and $p_i$, $p_f$ are incident and final electron four-momenta.
  5637. Omitting therefore an overall factor
  5638. ${\alpha^2\over2m^2}\left({k^\prime\over k}\right)^2$ we need to find
  5639. one quarter of the trace of
  5640. $${
  5641. \left( \gamma.p_f + m\right)
  5642. \left({\gamma.e^\prime \gamma.e\gamma.k_i\over2k.pi} +
  5643. {\gamma.e\gamma.e^\prime \gamma.k_f\over 2k^\prime .p_i}\right) \left(
  5644. \gamma.p_i + m\right)
  5645. \left({\gamma.k_i\gamma.e\gamma.e^\prime\over 2k.p_i} +
  5646. {\gamma.k_f\gamma.e^\prime \gamma.e\over2k^\prime .p_i}\right) }$$
  5647. A straightforward REDUCE program for this, with appropriate substitutions
  5648. (using {\tt P1} for $p_i$, {\tt PF} for $p_f$, {\tt KI}
  5649. for $k_i$ and {\tt KF} for $k_f$) is
  5650. \begin{verbatim}
  5651. on div; % this gives output in same form as Bjorken and Drell.
  5652. mass ki= 0, kf= 0, p1= m, pf= m; vector e,ep;
  5653. % if e is used as a vector, it loses its scalar identity as
  5654. the base of natural logarithms.
  5655. mshell ki,kf,p1,pf;
  5656. let p1.e= 0, p1.ep= 0, p1.pf= m^2+ki.kf, p1.ki= m*k,p1.kf=
  5657. m*kp, pf.e= -kf.e, pf.ep= ki.ep, pf.ki= m*kp, pf.kf=
  5658. m*k, ki.e= 0, ki.kf= m*(k-kp), kf.ep= 0, e.e= -1,
  5659. ep.ep=-1;
  5660. for all p let gp(p)= g(l,p)+m;
  5661. comment this is just to save us a lot of writing;
  5662. gp(pf)*(g(l,ep,e,ki)/(2*ki.p1) + g(l,e,ep,kf)/(2*kf.p1))
  5663. * gp(p1)*(g(l,ki,e,ep)/(2*ki.p1) + g(l,kf,ep,e)/
  5664. (2*kf.p1))$
  5665. write "The Compton cxn is",ws;
  5666. \end{verbatim}
  5667. (We use {\tt P1} instead of {\tt PI} in the above to avoid confusion with
  5668. the reserved variable {\tt PI}).
  5669. This program will print the following result
  5670. \begin{verbatim}
  5671. (-1) (-1) 2
  5672. The Compton cxn is 1/2*K*KP + 1/2*K *KP + 2*E.EP - 1
  5673. \end{verbatim}
  5674. \section{Extensions to More Than Four Dimensions}
  5675. In our discussion so far, we have assumed that we are working in the
  5676. normal four dimensions of QED calculations. However, in most cases, the
  5677. programs will also work in an arbitrary number of dimensions. The command
  5678. \ttindex{VECDIM}
  5679. \begin{verbatim}
  5680. vecdim <expression>;
  5681. \end{verbatim}
  5682. sets the appropriate dimension. The dimension can be symbolic as well as
  5683. numeric. Users should note however, that the {\tt EPS} operator and the
  5684. $\gamma_{5}$ symbol ({\tt A}) are not properly defined in other than four
  5685. dimensions and will lead to an error if used.
  5686. \chapter{{\REDUCE} and Rlisp Utilities}
  5687. {\REDUCE} and its associated support language system Rlisp \index{Rlisp}
  5688. include a number of utilities which have proved useful for program
  5689. development over the years. The following are supported in most of the
  5690. implementations of {\REDUCE} currently available.
  5691. \section{The Standard Lisp Compiler} \index{Compiler}
  5692. Many versions of {\REDUCE} include a Standard Lisp compiler that is
  5693. automatically loaded on demand. You should check your system specific
  5694. user guide to make sure you have such a compiler. To make the compiler
  5695. active, the switch {\tt COMP} \ttindex{COMP} should be turned on. Any
  5696. further definitions input after this will be compiled automatically. If
  5697. the compiler used is a derivative version of the original Griss-Hearn
  5698. compiler
  5699. (M. L. Griss and A.
  5700. C. Hearn, ``A Portable LISP Compiler", SOFTWARE --- Practice and Experience
  5701. 11 (1981) 541-605),
  5702. there are other switches that might also be
  5703. used in this regard. However, these additional switches are not supported
  5704. in all compilers. They are as follows: \ttindex{PLAP} \ttindex{PGWD}
  5705. \ttindex{PWRDS}
  5706. \begin{tabular}{l r}
  5707. {\tt PLAP} & \parbox[t]{\reduceboxwidth}{If ON, causes the printing of the
  5708. portable macros produced by the compiler;} \\ \\
  5709. {\tt PGWD} & \parbox[t]{\reduceboxwidth}{If ON, causes the printing of the
  5710. actual assembly language instructions generated from the macros;} \\ \\
  5711. {\tt PWRDS} & \parbox[t]{\reduceboxwidth}{If ON, causes a statistic
  5712. message of the form \\
  5713. {\tt <function> COMPILED, <words> WORDS, <words> LEFT} \\
  5714. to be printed. The first number is the number of words of binary
  5715. program space the compiled function took, and the second number
  5716. the number of words left unused in binary program space.} \\ \\
  5717. \end{tabular}
  5718. \section{Fast Loading Code Generation Program} \index{Fast loading of code}
  5719. \label{sec-load}
  5720. In most versions of {\REDUCE}, it is possible to take any set of Lisp, Rlisp
  5721. or {\REDUCE} commands and build a fast loading version of them. In Rlisp or
  5722. {\REDUCE}, one does the following:
  5723. \begin{verbatim}
  5724. faslout <filename>;
  5725. <commands or IN statements>
  5726. faslend;
  5727. \end{verbatim}
  5728. To load such a file, one uses the command {\tt LOAD}, \ttindex{LOAD}
  5729. e.g. {\tt load foo;}
  5730. or {\tt load foo,bah;}
  5731. Fast-loading files produced by this process may have an implementation
  5732. dependent extension added by this process. For example, in PSL-based systems,
  5733. the extension is {\tt b} (for binary). Such extensions are required by
  5734. the {\tt LOAD} program; if they are missing, an error occurs.
  5735. In doing this build, as with the production of a Standard Lisp form of
  5736. such statements, it is important to remember that some of the commands
  5737. must be instantiated during the building process. For example, macros
  5738. must be expanded, and some property list operations must happen.
  5739. The {\REDUCE} sources should be consulted for further details on this.
  5740. % To facilitate this, the {\tt EVAL} and {\tt IGNORE} flags (q.v.) may be
  5741. % used. Note also that there can be no {\tt LOAD} command within the input
  5742. % statements.
  5743. To avoid excessive printout, input statements should be followed by a \$
  5744. instead of the semicolon. With {\tt LOAD} however, the input doesn't
  5745. print out regardless of which terminator is used with the command.
  5746. If you subsequently change the source files used in producing a fast
  5747. loading file, don't forget to repeat the above process in order to update
  5748. the fast loading file correspondingly. Remember also that the text which
  5749. is read in during the creation of the fast load file, in the compiling
  5750. process described above, is {\em not} stored in your {\REDUCE}
  5751. environment, but only translated and output. If you want to use the file
  5752. just created, you must then use {\tt LOAD} to load the output of the
  5753. fast-loading file generation program.
  5754. When the file to be loaded contains a complete package for a given
  5755. application, the use of {\tt LOAD\_PACKAGE} \index{Load package}
  5756. rather than {\tt LOAD} is
  5757. recommended. The syntax is the same. However, {\tt LOAD\_PACKAGE} does some
  5758. additional bookkeeping such as recording that this package has now be loaded,
  5759. which may be used by various utilities in future releases of REDUCE.
  5760. \section{The Standard Lisp Cross Reference Program} \index{Cross reference}
  5761. {\tt CREF} \ttindex{CREF} is a Standard Lisp program for processing a
  5762. set of Standard LISP function definitions to produce:
  5763. \begin{enumerate}
  5764. \item A ``summary" showing:
  5765. \begin{enumerate}
  5766. \item A list of files processed;
  5767. \item A list of ``entry points" (functions which are not called or
  5768. are only called by themselves);
  5769. \item A list of undefined functions (functions called but not
  5770. defined in this set of functions);
  5771. \item A list of variables that were used non-locally but not
  5772. declared {\tt GLOBAL} or {\tt FLUID} before their use;
  5773. \item A list of variables that were declared {\tt GLOBAL} but not used
  5774. as {\tt FLUID}s, i.e., bound in a function;
  5775. \item A list of {\tt FLUID} variables that were not bound in a function
  5776. so that one might consider declaring them {\tt GLOBAL}s;
  5777. \item A list of all {\tt GLOBAL} variables present;
  5778. \item A list of all {\tt FLUID} variables present;
  5779. \item A list of all functions present.
  5780. \end{enumerate}
  5781. \item A ``global variable usage" table, showing for each non-local
  5782. variable:
  5783. \begin{enumerate}
  5784. \item Functions in which it is used as a declared {\tt FLUID} or {\tt GLOBAL};
  5785. \item Functions in which it is used but not declared;
  5786. \item Functions in which it is bound;
  5787. \item Functions in which it is changed by {\tt SETQ}.
  5788. \end{enumerate}
  5789. \item A ``function usage" table showing for each function:
  5790. \begin{enumerate}
  5791. \item Where it is defined;
  5792. \item Functions which call this function;
  5793. \item Functions called by it;
  5794. \item Non-local variables used.
  5795. \end{enumerate}
  5796. \end{enumerate}
  5797. The program will also check that functions are called with the correct
  5798. number of arguments, and print a diagnostic message otherwise.
  5799. The output is alphabetized on the first seven characters of each function
  5800. name.
  5801. \subsection{Restrictions}
  5802. Algebraic procedures in {\REDUCE} are treated as if they were symbolic, so
  5803. that algebraic constructs will actually appear as calls to symbolic
  5804. functions, such as {\tt AEVAL}.
  5805. \subsection{Usage}
  5806. To invoke the cross reference program, the switch {\tt CREF}
  5807. \ttindex{CREF} is used. {\tt on cref} causes the cref program to load
  5808. and the cross-referencing process to begin. After all the required
  5809. definitions are loaded, {\tt off cref} will cause the cross-reference
  5810. listing to be produced. For example, if you wish to cross-reference all
  5811. functions in the file {\tt tst.red}, and produce the cross-reference
  5812. listing in the file {\tt tst.crf}, the following sequence can be used:
  5813. \begin{verbatim}
  5814. out "tst.crf";
  5815. on cref;
  5816. in "tst.red"$
  5817. off cref;
  5818. end;
  5819. \end{verbatim}
  5820. To process more than one file, more {\tt IN} statements may be added
  5821. before the call of {\tt off cref}, or the {\tt IN} statement changed to
  5822. include a list of files.
  5823. \subsection{Options}
  5824. Functions with the flag {\tt NOLIST} will not be examined or output.
  5825. Initially, all Standard Lisp functions are so flagged. (In fact, they are
  5826. kept on a list {\tt NOLIST!*}, so if you wish to see references to {\em
  5827. all} functions, then {\tt CREF} should be first loaded with the command {\tt
  5828. load cref}, and this variable then set to {\tt NIL}).
  5829. It should also be remembered that any macros with the property list flag
  5830. {\tt EXPAND}, or, if the switch {\tt FORCE} is on, without the property
  5831. list flag {\tt NOEXPAND}, will be expanded before the definition is seen
  5832. by the cross-reference program, so this flag can also be used to select
  5833. those macros you require expanded and those you do not.
  5834. \section{Prettyprinting Reduce Expressions} \index{Prettyprinting}
  5835. {\REDUCE} includes a module for printing {\REDUCE} syntax in a standard
  5836. format. This module is activated by the switch {\tt PRET},
  5837. \ttindex{PRET} which is normally off.
  5838. Since the system converts algebraic input into an equivalent symbolic form,
  5839. the printing program tries to interpret this as an algebraic expression
  5840. before printing it. In most cases, this can be done successfully. However,
  5841. there will be occasional instances where results are printed in symbolic
  5842. mode form that bears little resemblance to the original input, even though
  5843. it is formally equivalent.
  5844. If you want to prettyprint a whole file, say {\tt off output,msg;}
  5845. \ttindex{MSG} and (hopefully) only clean output will result. Unlike {\tt
  5846. DEFN} (q.v.), \ttindex{DEFN} input is also evaluated with {\tt PRET}
  5847. \ttindex{PRET} on.
  5848. \section{Prettyprinting Standard Lisp S-Expressions} \index{Prettyprinting}
  5849. REDUCE includes a module for printing
  5850. S-expressions in a standard format. The Standard Lisp function for this
  5851. purpose is {\tt PRETTYPRINT} \ttindex{PRETTYPRINT} which takes a Lisp
  5852. expression and prints the formatted equivalent.
  5853. Users can also have their {\REDUCE} input printed in this form by use of
  5854. the switch {\tt DEFN}. \ttindex{DEFN} This is in fact a convenient way to
  5855. convert {\REDUCE} (or Rlisp) syntax into Lisp. {\tt off msg;} will prevent
  5856. warning messages from being printed.
  5857. NOTE: When {\tt DEFN} is on, input is not evaluated.
  5858. \chapter {Maintaining {\REDUCE}}
  5859. {\REDUCE} continues to evolve both in terms of the number of facilities
  5860. available, and the power of the individual facilities. Corrections are
  5861. made as bugs are discovered, and awkward features simplified. In order to
  5862. provide users with easy access to such enhancements, a {\em {\REDUCE}
  5863. Network Library} has been established from which material can be extracted
  5864. by anyone with electronic mail access to the Internet computer network.
  5865. This includes those with access to BITNET, EARN and UUCP-based networks as
  5866. well as commercial networks such as MCIMail and Compuserve.
  5867. In addition to miscellaneous documents, source and utility files, the library
  5868. includes a bibliography of papers referencing {\REDUCE} which contains over
  5869. 600 entries. Instructions on using this library are sent to all registered
  5870. {\REDUCE} users who provide a network address. If you would like a more
  5871. complete list of the contents of the library, send to
  5872. {\em reduce-netlib@rand.org} the single line message {\em send index} or
  5873. {\em help}. The current {\REDUCE} information package can also be obtained
  5874. in this manner by including on a separate line {\em send info-package} and a
  5875. demonstration file by including the line {\em send demonstration}. If you
  5876. prefer, hard copies of the information package and the bibliography are
  5877. available from the {\REDUCE} secretary at RAND, 1700 Main Street, P.O. Box
  5878. 2138, Santa Monica, CA 90407-2138 ({\em reduce@rand.org}). Copies of the
  5879. network library are also maintained at other addresses. At the time of
  5880. writing, {\em reduce-netlib@can.nl} may also be used instead of
  5881. {\em reduce-netlib@rand.org}. In addition, elib@elib.zib-berlin.de provides
  5882. interactive access to this library. For more information on {\em eLib},
  5883. send the message {\em send index} or {\em help} to that address.
  5884. Finally, there is a {\REDUCE} electronic forum accessible from the same
  5885. networks. This enables {\REDUCE} users to raise questions and discuss ideas
  5886. concerning the use and development of {\REDUCE} with other users. Additions
  5887. and changes to the network library and new releases of {\REDUCE} are also
  5888. announced in this forum. Any user with appropriate electronic mail access is
  5889. encouraged to register for membership in this forum. To do so, send a
  5890. message requesting inclusion to {\em reduce-forum-request@rand.org}.
  5891. \appendix
  5892. \chapter{Reserved Identifiers}
  5893. We list here all identifiers that are normally reserved in REDUCE
  5894. including names of commands, operators and switches initially in the system.
  5895. Excluded are words that are reserved in specific implementations of the
  5896. system. \\ \\
  5897. \begin{tabular}{l r}
  5898. {Commands} & \parbox[t]{\redboxwidth}{{\tt ALGEBRAIC} {\tt ANTISYMMETRIC}
  5899. {\tt ARRAY} {\tt BYE} {\tt CLEAR} {\tt CLEARRULES} {\tt COMMENT} {\tt
  5900. CONT} {\tt DECOMPOSE} {\tt DEFINE} {\tt DEPEND} {\tt DISPLAY} {\tt ED}
  5901. {\tt EDITDEF} {\tt END} {\tt FACTOR} {\tt FOR} {\tt FORALL} {\tt FOREACH}
  5902. {\tt GO} {\tt GOTO} {\tt IF} {\tt IN} {\tt INDEX} {\tt INFIX} {\tt INPUT}
  5903. {\tt INTEGER} {\tt KORDER} {\tt LET} {\tt LINEAR} {\tt LISP} {\tt MASS}
  5904. {\tt MATCH} {\tt MATRIX} {\tt MSHELL} {\tt NODEPEND} {\tt NONCOM} {\tt
  5905. NOSPUR} {\tt OFF} {\tt ON} {\tt OPERATOR} {\tt ORDER} {\tt OUT} {\tt
  5906. PAUSE} {\tt PRECEDENCE} {\tt PRINT\_PRECISION} {\tt PROCEDURE} {\tt QUIT}
  5907. {\tt REAL} {\tt REMFAC} {\tt REMIND} {\tt RETRY} {\tt RETURN} {\tt SAVEAS}
  5908. {\tt SCALAR} {\tt SETMOD} {\tt SHARE} {\tt SHOWTIME} {\tt SHUT} {\tt SPUR}
  5909. {\tt SYMBOLIC} {\tt SYMMETRIC} {\tt VECDIM} {\tt VECTOR} {\tt WEIGHT} {\tt
  5910. WRITE} {\tt WTLEVEL}} \\ \\
  5911. {Boolean Operators} & \parbox[t]{\redboxwidth}{{\tt EVENP} {\tt FIXP}
  5912. {\tt FREEOF} {\tt NUMBERP} {\tt ORDP} {\tt PRIMEP}} \\ \\
  5913. {Infix Operators} & \parbox[t]{\redboxwidth}{
  5914. {\tt \&} {\tt :=} {\tt =} {\tt $>$=} {\tt $>$} {\tt $<$=} {\tt $<$} {\tt
  5915. =$>$} {\tt +} {\tt *} {\tt /} {\tt \^{ }} {\tt **} {\tt .} {\tt WHERE}
  5916. {\tt SETQ} {\tt OR} {\tt AND} {\tt NOT} {\tt MEMBER} {\tt MEMQ} {\tt
  5917. EQUAL} {\tt NEQ} {\tt EQ} {\tt GEQ} {\tt GREATERP} {\tt LEQ} {\tt LESSP}
  5918. {\tt PLUS} {\tt DIFFERENCE} {\tt MINUS} {\tt TIMES} {\tt QUOTIENT} {\tt
  5919. EXPT} {\tt CONS}}
  5920. \end{tabular}
  5921. \newpage
  5922. \begin{tabular}{l r}
  5923. {Numerical Operators} & \parbox[t]{\redboxwidth}{{\tt ABS} {\tt ACOS}
  5924. {\tt ACOSD} {\tt ACOSH} {\tt ACOT} {\tt ACOTD} {\tt ACOTH} {\tt ACSC} {\tt
  5925. ACSCD} {\tt ACSCH} {\tt ASEC} {\tt ASECD} {\tt ASECH} {\tt ASIN} {\tt
  5926. ASIND} {\tt ASINH} {\tt ATAN} {\tt ATAND} {\tt ATANH} {\tt ATAN2} {\tt
  5927. ATAN2D} {\tt CBRT} {\tt COS} {\tt COSD} {\tt COSH} {\tt COT} {\tt COTD}
  5928. {\tt COTH} {\tt CSC} {\tt CSCD} {\tt CSCH} {\tt EXP} {\tt FACTORIAL} {\tt
  5929. FIX} {\tt FLOOR} {\tt HYPOT} {\tt LN} {\tt LOG} {\tt LOGB} {\tt LOG10}
  5930. {\tt NEXTPRIME} {\tt ROUND} {\tt SEC} {\tt SECD} {\tt SECH} {\tt SIN} {\tt
  5931. SIND} {\tt SINH} {\tt SQRT} {\tt TAN} {\tt TAND} {\tt TANH}} \\ \\
  5932. {Prefix Operators} & \parbox[t]{\redboxwidth}{{\tt APPEND} {\tt
  5933. ARGLENGTH} {\tt CEILING} {\tt COEFF} {\tt COEFFN} {\tt COFACTOR} {\tt
  5934. CONJ} {\tt DEG} {\tt DEN} {\tt DET} {\tt DF} {\tt DILOG} {\tt EPS} {\tt
  5935. ERF} {\tt EXPINT} {\tt FACTORIZE} {\tt FIRST} {\tt GCD} {\tt G} {\tt
  5936. IMPART} {\tt INT} {\tt INTERPOL} {\tt LCM} {\tt LCOF} {\tt LENGTH} {\tt
  5937. LHS} {\tt LINELENGTH} {\tt LTERM} {\tt MAINVAR} {\tt MAT} {\tt MATEIGEN}
  5938. {\tt MAX} {\tt MIN} {\tt MKID} {\tt NULLSPACE} {\tt NUM} {\tt PART} {\tt
  5939. PF} {\tt PRECISION} {\tt RANK} {\tt REDERR} {\tt REDUCT} {\tt REMAINDER}
  5940. {\tt REPART} {\tt REST} {\tt RESULTANT} {\tt REVERSE} {\tt RHS} {\tt
  5941. SECOND} {\tt SET} {\tt SOLVE} {\tt STRUCTR} {\tt SUB} {\tt SUM} {\tt
  5942. THIRD} {\tt TP} {\tt TRACE} {\tt VARNAME}} \\ \\
  5943. {Reserved Variables} & \parbox[t]{\redboxwidth}{{\tt E} {\tt I} {\tt
  5944. INFINITY} {\tt K!*} {\tt NIL} {\tt PI} {\tt T}} \\ \\
  5945. {Switches} & \parbox[t]{\redboxwidth}{{\tt ADJPREC} {\tt ALGINT} {\tt
  5946. ALLBRANCH} {\tt ALLFAC} {\tt BFSPACE} {\tt COMP} {\tt COMPLEX} {\tt
  5947. CRAMER} {\tt CREF} {\tt DEFN} {\tt DEMO} {\tt DIV} {\tt ECHO} {\tt
  5948. ERRCONT} {\tt EVALLHSEQP} {\tt EXP} {\tt EZGCD} {\tt FACTOR} {\tt FORT}
  5949. {\tt GCD} {\tt IFACTOR} {\tt INT} {\tt INTSTR} {\tt LCM} {\tt LIST} {\tt
  5950. LISTARGS} {\tt MCD} {\tt MODULAR} {\tt MSG} {\tt MULTIPLICITIES} {\tt NAT}
  5951. {\tt NERO} {\tt NOSPLIT} {\tt OUTPUT} {\tt PERIOD} {\tt PGWD} {\tt PLAP}
  5952. {\tt PRET} {\tt PRI} {\tt PWRDS} {\tt RAISE} {\tt RAT} {\tt RATARG} {\tt
  5953. RATIONAL} {\tt RATIONALIZE} {\tt RATPRI} {\tt REVPRI} {\tt ROUNDALL} {\tt
  5954. ROUNDBF} {\tt ROUNDED} {\tt SAVESTRUCTR} {\tt SOLVESINGULAR} {\tt TIME}
  5955. {\tt TRA} {\tt TRFAC} {\tt TRINT}} \\ \\
  5956. {Other Reserved Ids} & \parbox[t]{\redboxwidth}{{\tt BEGIN} {\tt DO} {\tt
  5957. EXPR} {\tt FASLOUT} {\tt FEXPR} {\tt FLAGOP} {\tt INPUT} {\tt LAMBDA} {\tt
  5958. LISP} {\tt LOAD} {\tt MACRO} {\tt PRODUCT} {\tt REPEAT} {\tt SMACRO} {\tt
  5959. SUM} {\tt WHILE} {\tt WS}}
  5960. \end{tabular}
  5961. \printindex
  5962. \end{document}