REDUCE.TEX 328 KB

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