1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088 |
- <a name=r38_0050>
- <title>GOTO</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>GOTO</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>command</b><P>
- <P>
-
- Inside a <em>begin</em>...<em>end</em>
- <a href=r38_0001.html#r38_0041>block</a>, <em>goto</em>, or
- preferably, <em>go to</em>, transfers flow of control to a labeled statement.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>go to</em><labeled_statement> or <em>goto</em> <labeled_statement
- >
- <P>
- <P>
- <P>
- <labeled_statement> is of the form <label> <em>:</em><statement
- >
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- procedure dumb(a);
- begin scalar q;
- go to lab;
- q := df(a**2 - sin(a),a);
- write q;
- lab: return a
- end;
-
- DUMB
- dumb(17);
- 17
- </tt></pre><p><em>go to</em>can only be used inside a <em>begin</em>...<em>end
- </em>
- <a href=r38_0001.html#r38_0041>block</a>, and inside
- the block only statements at the top level can be labeled, not ones inside
- <em><<</em>...<em>>></em>,
- <a href=r38_0200.html#r38_0228>while</a>...<em>do</em>, etc.
- <P>
- <P>
- <P>
- <a name=r38_0051>
- <title>GREATERP</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>GREATERP</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- The <em>greaterp</em> logical operator returns true if its first argument is
- strictly greater than its second argument. As an infix operator it is
- identical with <em>></em>.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>greaterp</em>(<expression>,<expression>) or <expression>
- <em>greaterp</em> <expression>
- <P>
- <P>
- <P>
- <expression> can be any valid REDUCE expression that evaluates to a
- number.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- a := 20;
- A := 20
- if greaterp(a,25) then write "big" else write "small";
-
- small
- if a greaterp 20 then write "big" else write "small";
-
- small
- if (a greaterp 18) then write "big" else write "small";
-
- big
- </tt></pre><p>Logical operators can only be used in conditional statements such
- as
- <P>
- <P>
- <a href=r38_0050.html#r38_0052>if</a>...<em>then</em>...<em>else</em>
- or
- <a href=r38_0050.html#r38_0056>repeat</a>...
- <a href=r38_0200.html#r38_0228>while</a>.
- <P>
- <P>
- <P>
- <a name=r38_0052>
- <title>IF</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>IF</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>command</b><P>
- <P>
-
- The <em>if</em> command is a conditional statement that executes a statement
- if a condition is true, and optionally another statement if it is not.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>if</em><condition> <em>then</em> <statement>
- _ _ _ option(<em>else</em> <statement>)
- <P>
- <P>
- <P>
- <condition> must be a logical or comparison operator that evaluates to
- a
- <a href=r38_0100.html#r38_0109>boolean value</a>.
- <statement> must be a single REDUCE statement or a
- <a href=r38_0001.html#r38_0038>group</a> (<em><<</em>...<em>>></em>)
- or
- <a href=r38_0001.html#r38_0041>block</a> (<em>begin</em>...<em>end</em>) stateme
- nt.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- if x = 5 then a := b+c else a := d+f;
-
- D + F
- x := 9;
- X := 9
- if numberp x and x<20 then y := sqrt(x) else write "illegal";
-
- 3
- clear x;
- if numberp x and x<20 then y := sqrt(x) else write "illegal";
-
- illegal
- x := 12;
- X := 12
- a := if x < 5 then 100 else 150;
-
- A := 150
- b := u**(if x < 10 then 2);
-
- B := 1
- bb := u**(if x > 10 then 2);
-
- 2
- BB := U
- </tt></pre><p>An <em>if</em> statement may be used inside an assignment statemen
- t and sets
- its value depending on the conditions, or used anywhere else an
- expression would be valid, as shown in the last example. If there is no
- <em>else</em> clause, the value is 0 if a number is expected, and nothing
- otherwise.
- <P>
- <P>
- The <em>else</em> clause may be left out if no action is to be taken if the
- condition is false.
- <P>
- <P>
- The condition may be a compound conditional statement using
- <a href=r38_0001.html#r38_0039>and</a> or
- <a href=r38_0050.html#r38_0054>or</a>. If a non-conditional statement, such as a
- constant, is used by
- accident, it is assumed to have value true.
- <P>
- <P>
- Be sure to use
- <a href=r38_0001.html#r38_0038>group</a> or
- <a href=r38_0001.html#r38_0041>block</a> statements after
- <em>then</em> or <em>else</em>.
- <P>
- <P>
- The <em>if</em> operator is right associative. The following constructions are
- examples:
- <P>
- <P>
- _ _ _ (1)
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>if</em><condition> <em>then</em> <em>if</em> <condition> <em>the
- n</em>
- <action> <em>else</em> <action>
- <P>
- <P>
- <P>
- which is equivalent to
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>if</em><condition> <em>then</em> (<em>if</em> <condition>
- <em>then</em> <action> <em>else</em> <action>);
- <P>
- <P>
- <P>
- _ _ _ (2)
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>if</em><condition> <em>then</em> <action> <em>else if</em>
- <condition> <em>then</em> <action> <em>else</em> <action>
- <P>
- <P>
- <P>
- which is equivalent to
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>if</em><condition> <em>then</em> <action> <em>else</em>
- <P>
- <P>
- (<em>if</em> <condition> <em>then</em> <action>
- <em>else</em> <action>).
- <P>
- <P>
- <P>
- <P>
- <P>
- <P>
- <a name=r38_0053>
- <title>LIST</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>LIST</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- The <em>list</em> operator constructs a list from its arguments.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>list</em>(<item> {,<item>}*) or
- <em>list</em>() to construct an empty list.
- <P>
- <P>
- <P>
- <item> can be any REDUCE scalar expression, including another list.
- Left and right curly brackets can also be used instead of the operator
- <em>list</em> to construct a list.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- liss := list(c,b,c,{xx,yy},3x**2+7x+3,df(sin(2*x),x));
-
- 2
- LISS := {C,B,C,{XX,YY},3*X + 7*X + 3,2*COS(2*X)}
- length liss;
- 6
- liss := {c,b,c,{xx,yy},3x**2+7x+3,df(sin(2*x),x)};
-
- 2
- LISS := {C,B,C,{XX,YY},3*X + 7*X + 3,2*COS(2*X)}
- emptylis := list();
- EMPTYLIS := {}
- a . emptylis;
- {A}
- </tt></pre><p>Lists are ordered, hierarchical structures. The elements stay wher
- e you
- put them, and only change position in the list if you specifically change
- them. Lists can have nested sublists to any (reasonable) level. The
- <a href=r38_0150.html#r38_0169>part</a> operator can be used to access elements
- anywhere within a list
- hierarchy. The
- <a href=r38_0150.html#r38_0157>length</a> operator counts the
- number of top-level elements
- of its list argument; elements that are themselves lists still only
- count as one element.
- <P>
- <P>
- <P>
- <a name=r38_0054>
- <title>OR</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>OR</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- The <em>or</em> binary logical operator returns true if either one or
- both of its arguments is true.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <logical expression> <em>or</em> <logical expression>
- <P>
- <P>
- <P>
- <logical expression> must evaluate to true or nil.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- a := 10;
- A := 10
- if a<0 or a>140 then write "not a valid human age" else
- write "age = ",a;
-
- age = 10
- a := 200;
- A := 200
- if a < 0 or a > 140 then write "not a valid human age";
-
- not a valid human age
- </tt></pre><p>The <em>or</em> operator is left associative: <em>x or y or z</em>
- is equivalent to
- <em>(x or y)</em> <em>or z</em>.
- <P>
- <P>
- Logical operators can only be used in conditional expressions, such as
- <P>
- <P>
- <a href=r38_0050.html#r38_0052>if</a>...<em>then</em>...<em>else</em>
- and
- <a href=r38_0200.html#r38_0228>while</a>...<em>do</em>.
- <em>or</em> evaluates its arguments in order and quits, returning true,
- on finding the first true statement.
- <P>
- <P>
- <P>
- <a name=r38_0055>
- <title>PROCEDURE</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>PROCEDURE</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>command</b><P>
- <P>
-
- The <em>procedure</em> command allows you to define a mathematical operation as
- a
- function with arguments.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- _ _ _ <option> <em>procedure</em> <identifier>
- (<arg>{,<arg>}+)<em>;</em><body>
- <P>
- <P>
- <P>
- The <option> may be
- <a href=r38_0150.html#r38_0186>algebraic</a> or
- <a href=r38_0200.html#r38_0221>symbolic</a>,
- indicating the
- mode under which the procedure is executed, or
- <a href=r38_0200.html#r38_0216>real</a> or
- <a href=r38_0150.html#r38_0197>integer</a>, indicating the type of answer expect
- ed. The default is
- algebraic. Real or integer procedures are subtypes of algebraic
- procedures; type-checking is done on the results of integer procedures, but
- not on real procedures (in the current REDUCE release). <identifier>
- may be any valid REDUCE identifier that is not already a procedure name,
- operator,
- <a href=r38_0150.html#r38_0188>array</a> or
- <a href=r38_0300.html#r38_0345>matrix</a>.
- <arg> is a formal parameter that may be any
- valid REDUCE identifier. <body> is a single statement (a
- <a href=r38_0001.html#r38_0038>group</a>
- or
- <a href=r38_0001.html#r38_0041>block</a> statement may be used) with the desired
- activities in it.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- procedure fac(n);
- if not (fixp(n) and n>=0)
- then rederr "Choose nonneg. integer only"
- else for i := 0:n-1 product i+1;
-
- FAC
- fac(0);
- 1
- fac(5);
- 120
- fac(-5);
- ***** choose nonneg. integer only
- </tt></pre><p>Procedures are automatically declared as operators upon definition
- . When
- REDUCE has parsed the procedure definition and successfully converted it to
- a form for its own use, it prints the name of the procedure. Procedure
- definitions cannot be nested. Procedures can call other procedures, or can
- recursively call themselves. Procedure identifiers can be cleared as you
- would clear an operator. Unlike
- <a href=r38_0150.html#r38_0199>let</a> statements, new definitions
- under the same procedure name replace the previous definitions completely.
- <P>
- <P>
- Be careful not to use the name of a system operator for your own procedure.
- REDUCE may or may not give you a warning message. If you redefine a system
- operator in your own procedure, the original function of the system operator
- is lost for the remainder of the REDUCE session.
- <P>
- <P>
- Procedures may have none, one, or more than one parameter. A REDUCE
- parameter is a formal parameter only; the use of x as a parameter in
- a <em>procedure</em> definition has no connection with a value of x in
- the REDUCE session, and the results of calling a procedure have no effect
- on the value of x. If a procedure is called with x as a
- parameter, the current value of x is used as specified in the
- computation, but is not changed outside the procedure.
- Making an assignment statement by <em>:=</em> with a
- formal parameter on the left-hand side only changes the value of the
- calling parameter within the procedure.
- <P>
- <P>
- Using a
- <a href=r38_0150.html#r38_0199>let</a> statement inside a procedure always chang
- es the value
- globally: a <em>let</em> with a formal parameter makes the change to the calling
-
- parameter. <em>let</em> statements cannot be made on local variables inside
- <a href=r38_0001.html#r38_0040>begin</a>...<em>end</em>
- <a href=r38_0001.html#r38_0041>block</a><em>s</em>.
- When
- <a href=r38_0150.html#r38_0189>clear</a> statements are used on formal
- parameters, the calling variables associated with them are cleared globally too.
-
- The use of <em>let</em> or <em>clear</em> statements inside procedures
- should be done with extreme caution.
- <P>
- <P>
- Arrays and operators may be used as parameters to procedures. The body of the
- procedure can contain statements that appropriately manipulate these
- arguments. Changes are made to values of the calling arrays or operators.
- Simple expressions can also be used as arguments, in the place of scalar
- variables. Matrices may not be used as arguments to procedures.
- <P>
- <P>
- A procedure that has no parameters is called by the procedure name,
- immediately followed by empty parentheses. The empty parentheses may be left
- out when writing a procedure with no parameters, but must appear in a call of
- the procedure. If this is a nuisance to you, use a
- <a href=r38_0150.html#r38_0199>let</a> statement on
- the name of the procedure (i.e., <em>let noargs = noargs()</em>) after which
- you can call the procedure by just its name.
- <P>
- <P>
- Procedures that have a single argument can leave out the parentheses around
- it both in the definition and procedure call. (You can use the parentheses if
- you wish.) Procedures with more than one argument must use parentheses, with
- the arguments separated by commas.
- <P>
- <P>
- Procedures often have a <em>begin</em>...<em>end</em> block in them. Inside the
- block, local variables are declared using <em>scalar</em>, <em>real</em> or
- <em>integer</em> declarations.
- The declarations must be made immediately after the word
- <em>begin</em>, and if more than one type of declaration is made, they are
- separated by semicolons. REDUCE currently does no type checking on local
- variables; <em>real</em> and <em>integer</em> are treated just like <em>scalar
- </em>.
- Actions take place as specified in the statements inside the block statement.
- Any identifiers that are not formal parameters or local variables are treated
- as global variables, and activities involving these identifiers are global in
- effect.
- <P>
- <P>
- If a return value is desired from a procedure call, a specific
- <a href=r38_0050.html#r38_0058>return</a> command must be the last statement exe
- cuted before exiting
- from the procedure. If no <em>return</em> is used, a procedure returns a
- zero or no value.
- <P>
- <P>
- Procedures are often written in a file using an editor, then the file
- is input using the command
- <a href=r38_0200.html#r38_0231>in</a>. This method allows easy changes in
- development, and also allows you to load the named procedures whenever
- you like, by loading the files that contain them.
- <P>
- <P>
- <P>
- <a name=r38_0056>
- <title>REPEAT</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>REPEAT</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>command</b><P>
- <P>
-
- <P>
- <P>
- The
- <a href=r38_0050.html#r38_0056>repeat</a> command causes repeated execution of a
- statement
- <em>until</em><P>
- <P>
- the given condition is found to be true. The statement is always executed
- at least once.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>repeat</em><statement> <em>until</em> <condition>
- <P>
- <P>
- <P>
- <statement> can be a single statement,
- <a href=r38_0001.html#r38_0038>group</a> statement, or
- a <em>begin</em>...<em>end</em>
- <a href=r38_0001.html#r38_0041>block</a>. <condition> must be
- a logical operator that evaluates to true or nil.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- <<m := 4; repeat <<write 100*x*m;m := m-1>> until m = 0>
- >;
-
- 400*X
- 300*X
- 200*X
- 100*X
- <<m := -1; repeat <<write m; m := m-1>> until m <= 0>
- >;
-
- -1
- </tt></pre><p><em>repeat</em>must always be followed by an <em>until</em> with a
- condition.
- Be careful not to generate an infinite loop with a condition that is never
- true. In the second example, if the condition had been <em>m = 0</em>, it
- would never have been true since <em>m</em> already had value -2 when the
- condition was first evaluated.
- <P>
- <P>
- <P>
- <a name=r38_0057>
- <title>REST</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>REST</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- The <em>rest</em> operator returns a
- <a href=r38_0050.html#r38_0053>list</a> containing all but the first
- element of the list it is given.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>rest</em>(<list>) or <em>rest</em> <list>
- <P>
- <P>
- <P>
- <P>
- <list> must be a non-empty list, but need not have more than one element.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- alist := {a,b,c,d};
- ALIST := {A,B,C,D};
- rest alist;
- {B,C,D}
- blist := {x,y,{aa,bb,cc},z};
- BLIST := {X,Y,{AA,BB,CC},Z}
- second rest blist;
- {AA,BB,CC}
- clist := {c};
- CLIST := C
- rest clist;
- {}
- </tt></pre><p>
- <a name=r38_0058>
- <title>RETURN</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>RETURN</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>command</b><P>
- <P>
-
- The <em>return</em> command causes a value to be returned from inside a
- <em>begin</em>...<em>end</em>
- <a href=r38_0001.html#r38_0041>block</a>.
- <P>
- <P>
- <P> <H3>
- syntax: </H3>
- <em>begin</em><statements> <em>return</em> <(expression)>
- <em>end</em><P>
- <P>
- <P>
- <P>
- <statements> can be any valid REDUCE statements. The value of
- <expression> is returned.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- begin write "yes"; return a end;
- yes
- A
- procedure dumb(a);
- begin if numberp(a) then return a else return 10 end;
-
- DUMB
- dumb(x);
- 10
- dumb(-5);
- -5
- procedure dumb2(a);
- begin c := a**2 + 2*a + 1; d := 17; c*d; return end;
-
- DUMB2
- dumb2(4);
- c;
- 25
- d;
- 17
- </tt></pre><p>Note in <em>dumb2</em> above that the assignments were made as req
- uested, but
- the product <em>c*d</em> cannot be accessed. Changing the procedure to read
- <em>return c*d</em> would remedy this problem.
- <P>
- <P>
- The <em>return</em> statement is always the last statement executed before
- leaving the block. If <em>return</em> has no argument, the block is exited but
- no value is returned. A block statement does not need a <em>return</em> ;
- the statements inside terminate in their normal fashion without one.
- In that case no value is returned, although the specified actions inside the
- block take place.
- <P>
- <P>
- The <em>return</em> command can be used inside <em><<</em>...<em>>>
- </em>
- <a href=r38_0001.html#r38_0038>group</a> statements and
- <a href=r38_0050.html#r38_0052>if</a>...<em>then</em>...<em>else</em> commands t
- hat
- are inside <em>begin</em>...<em>end</em>
- <a href=r38_0001.html#r38_0041>block</a>s.
- It is not valid in these constructions that are not inside
- a <em>begin</em>...<em>end</em>
- block. It is not valid inside
- <a href=r38_0001.html#r38_0047>for</a>,
- <a href=r38_0050.html#r38_0056>repeat</a>...<em>until</em> or
- <a href=r38_0200.html#r38_0228>while</a>...<em>do</em>
- loops in any construction. To force early termination from loops, the
- <em>go to</em>(
- <a href=r38_0050.html#r38_0050>goto</a>) command must be used.
- When you use nested block statements, a
- <em>return</em> from an inner block exits returning a value to the next-outermos
- t
- block, rather than all the way to the outside.
- <P>
- <P>
- <P>
- <a name=r38_0059>
- <title>REVERSE</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>REVERSE</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- The <em>reverse</em> operator returns a
- <a href=r38_0050.html#r38_0053>list</a> that is the reverse of the
- list it is given.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>reverse</em>(<list>) or <em>reverse</em> <list>
- <P>
- <P>
- <P>
- <list> must be a
- <a href=r38_0050.html#r38_0053>list</a>.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- aa := {c,b,a,{x**2,z**3},y};
- 2 3
- AA := {C,B,A,{X ,Z },Y}
- reverse aa;
- 2 3
- {Y,{X ,Z },A,B,C}
- reverse(q . reverse aa);
- 2 3
- {C,B,A,{X ,Z },Y,Q}
- </tt></pre><p><em>reverse</em>and
- <a href=r38_0001.html#r38_0043>cons</a> can be used together to add a new elemen
- t to
- the end of a list (<em>.</em> adds its new element to the beginning). The
- <em>reverse</em> operator uses a noticeable amount of system resources,
- especially if the list is long. If you are doing much heavy-duty list
- manipulation, you should probably design your algorithms to avoid much
- reversing of lists. A moderate amount of list reversing is no problem.
- <P>
- <P>
- <P>
- <a name=r38_0060>
- <title>RULE</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>RULE</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>type</b><P>
- <P>
-
- <P>
- <P>
- A <em>rule</em> is an instruction to replace an algebraic expression
- or a part of an expression by another one.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <lhs> => <rhs> or
- <lhs> => <rhs> <em>when</em> <cond>
- <P>
- <P>
- <P>
- <lhs> is an algebraic expression used as search pattern and
- <rhs> is an algebraic expression which replaces matches of
- <rhs>. <em>=></em> is the operator
- <a href=r38_0001.html#r38_0026>replace</a>.
- <P>
- <P>
- <lhs> can contain
- <a href=r38_0050.html#r38_0061>free variable</a>s which are
- symbols preceded by a tilde <em>~</em> in their leftmost position
- in <lhs>.
- A double tilde marks an
- <a href=r38_0050.html#r38_0062>optional free variable</a>.
- If a rule has a <em>when</em> <cond>
- part it will fire only if the evaluation of <cond> has a
- result
- <a href=r38_0100.html#r38_0122>true</a>. <cond> may contain references to
- free variables of <lhs>.
- <P>
- <P>
- Rules can be collected in a
- <a href=r38_0050.html#r38_0053>list</a> which then forms a
- <em>rule list</em>. <em>Rule lists</em> can be used to collect
- algebraic knowledge for a specific evaluation context.
- <P>
- <P>
- <em>Rules</em>and <em>rule lists</em> are globally activated and
- deactivated by
- <a href=r38_0150.html#r38_0199>let</a>,
- <a href=r38_0150.html#r38_0195>forall</a>,
- <a href=r38_0150.html#r38_0190>clearrules</a>.
- For a single evaluation they can be locally activate by
- <a href=r38_0200.html#r38_0227>where</a>.
- The active rules for an operator can be visualized by
- <a href=r38_0150.html#r38_0178>showrules</a>.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- operator f,g,h;
- let f(x) => x^2;
- f(x);
- 2
- x
- g_rules:={g(~n,~x)=>h(n/2,x) when evenp n,
- g(~n,~x)=>h((1-n)/2,x) when not evenp n}$
- let g_rules;
- g(3,x);
- h(-1,x)
- </tt></pre><p>
- <a name=r38_0061>
- <title>Free_Variable</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>FREE VARIABLE</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>type</b><P>
- <P>
-
- <P>
- <P>
- A variable preceded by a tilde is considered as <em>free variable</em>
- and stands for an arbitrary part in an algebraic form during
- pattern matching. Free variables occur in the left-hand sides
- of
- <a href=r38_0050.html#r38_0060>rule</a>s, in the side relations for
- <a href=r38_0600.html#r38_0642>compact</a>
- and in the first arguments of
- <a href=r38_0150.html#r38_0163>map</a> and
- <a href=r38_0150.html#r38_0177>select</a>
- calls. See
- <a href=r38_0050.html#r38_0060>rule</a> for examples.
- <P>
- <P>
- In rules also
- <a href=r38_0050.html#r38_0062>optional free variable</a>s may occur.
- <P>
- <P>
- <a name=r38_0062>
- <title>Optional_Free_Variable</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>OPTIONAL FREE VARIABLE</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>type</b><P>
- <P>
-
- <P>
- <P>
- A variable preceded by a double tilde is considered as
- <em>optional free variable</em><P>
- <P>
- and stands for an arbitrary part part in an algebraic form during
- pattern matching. In contrast to ordinary
- <a href=r38_0050.html#r38_0061>free variable</a>s
- an operator pattern with an <em>optional free variable</em>
- matches also if the operand for the variable is missing. In such
- a case the variable is bound to a neutral value.
- Optional free variables can be used as
- <P>
- <P>
- term in a sum: set to 0 if missing,
- <P>
- <P>
- factor in a product: set to 1 if missing,
- <P>
- <P>
- exponent: set to 1 if missing
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt></tt></pre><p>Optional free variables are allowed only in the left-h
- and sides
- of
- <a href=r38_0050.html#r38_0060>rule</a>s.
- <P>
- <P>
- <a name=r38_0063>
- <title>SECOND</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>SECOND</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- The <em>second</em> operator returns the second element of a list.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>second</em>(<list>) or <em>second</em> <list>
- <P>
- <P>
- <P>
- <P>
- <list> must be a list with at least two elements, to avoid an error
- message.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- alist := {a,b,c,d};
- ALIST := {A,B,C,D}
- second alist;
- B
- blist := {x,{aa,bb,cc},z};
- BLIST := {X,{AA,BB,CC},Z}
- second second blist;
- BB
- </tt></pre><p>
- <a name=r38_0064>
- <title>SET</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>SET</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- The <em>set</em> operator is used for assignments when you want both sides of
- the assignment statement to be evaluated.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>set</em>(<restricted\_expression>,<expression>)
- <P>
- <P>
- <P>
- <expression> can be any REDUCE expression; <restricted\_expression>
- must be an identifier or an expression that evaluates to an identifier.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- a := y;
- A := Y
- set(a,sin(x^2));
- 2
- SIN(X )
- a;
- 2
- SIN(X )
- y;
- 2
- SIN(X )
- a := b + c;
- A := B + C
- set(a-c,z);
- Z
- b;
- Z
- </tt></pre><p>Using an
- <a href=r38_0150.html#r38_0188>array</a> or
- <a href=r38_0300.html#r38_0345>matrix</a> reference as the first
- argument to <em>set</em> has
- the result of setting the contents of the designated element to
- <em>set</em>'s second argument. You should be careful to avoid unwanted
- side effects when you use this facility.
- <P>
- <P>
- <P>
- <a name=r38_0065>
- <title>SETQ</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>SETQ</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- The <em>setq</em> operator is an infix or prefix binary assignment operator.
- It is identical to <em>:=</em>.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>setq</em>(<restricted\_expression>,<expression>) or
- <P>
- <P>
- <restricted\_expression> <em>setq</em> <expression>
- <P>
- <P>
- <P>
- <restricted expression> is ordinarily a single identifier, though
- simple expressions may be used (see Comments below). <expression> can
- be any valid REDUCE expression. If <expression> is a
- <a href=r38_0300.html#r38_0345>matrix</a>
- identifier, then <restricted\_expression> can be a matrix identifier
- (redimensioned if necessary), which has each element set to the
- corresponding elements of the identifier on the right-hand side.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- setq(b,6);
- B := 6
- c setq sin(x);
- C := SIN(X)
- w + setq(c,x+3) + z;
- W + X + Z + 3
- c;
- X + 3
- setq(a1 + a2,25);
- A1 + A2 := 25
- a1;
- - (A2 - 25)
- </tt></pre><p>Embedding a <em>setq</em> statement in an expression has the side
- effect of making
- the assignment, as shown in the third example above.
- <P>
- <P>
- Assignments are generally done for identifiers, but may be done for simple
- expressions as well, subject to the following remarks:
- <P>
- <P>
- _ _ _ (i)
- If the left-hand side is an identifier, an operator, or a power, the rule
- is added to the rule table.
- <P>
- <P>
- _ _ _ (ii)
- If the operators <em>- + /</em> appear on the left-hand side, all but the first
- term of the expression is moved to the right-hand side.
- <P>
- <P>
- _ _ _ (iii)
- If the operator <em>*</em> appears on the left-hand side, any constant terms are
-
- moved to the right-hand side, but the symbolic factors remain.
- <P>
- <P>
- Be careful not to make a recursive <em>setq</em> assignment that is not
- controlled inside a loop statement. The process of resubstitution
- continues until you get a stack overflow message. <em>setq</em> can be used
- to attach functionality to operators, as the <em>:=</em> does.
- <P>
- <P>
- <P>
- <a name=r38_0066>
- <title>THIRD</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>THIRD</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- The <em>third</em> operator returns the third item of a
- <a href=r38_0050.html#r38_0053>list</a>.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>third</em>(<list>) or <em>third</em> <list>
- <P>
- <P>
- <P>
- <P>
- <list> must be a list containing at least three items to avoid an error
- message.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- alist := {a,b,c,d};
- ALIST := {A,B,C,D}
- third alist;
- C
- blist := {x,{aa,bb,cc},y,z};
- BLIST := {X,{AA,BB,CC},Y,Z};
- third second blist;
- CC
- third blist;
- Y
- </tt></pre><p>
- <a name=r38_0067>
- <title>WHEN</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>WHEN</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- The <em>when</em> operator is used inside a <em>rule</em> to make the
- execution of the rule depend on a boolean condition which is
- evaluated at execution time. For the use see
- <a href=r38_0050.html#r38_0060>rule</a>.
- <P>
- <P>
- <a name=r38_0068>
- <title>Syntax</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>Syntax</b><menu>
- <li><a href=r38_0001.html#r38_0020>semicolon command</a>alias= (;)<P>
- <li><a href=r38_0001.html#r38_0021>dollar command</a>alias= ($)<P>
- <li><a href=r38_0001.html#r38_0022>percent command</a>alias= (%)<P>
- <li><a href=r38_0001.html#r38_0023>dot operator</a>alias= (.)<P>
- <li><a href=r38_0050.html#r38_0065>assign operator</a>alias= (: =)<P>
- <li><a href=r38_0001.html#r38_0025>equalsign operator</a>alias= (=)<P>
- <li><a href=r38_0001.html#r38_0026>replace operator</a>alias= (= >)<P>
- <li><a href=r38_0001.html#r38_0027>plussign operator</a>alias= (+)<P>
- <li><a href=r38_0001.html#r38_0028>minussign operator</a>alias= (-)<P>
- <li><a href=r38_0001.html#r38_0029>asterisk operator</a>alias= (*)<P>
- <li><a href=r38_0001.html#r38_0030>slash operator</a>alias= (/)<P>
- <li><a href=r38_0001.html#r38_0031>power operator</a>alias= (* *)<P>
- <li><a href=r38_0001.html#r38_0032>caret operator</a>alias= (^)<P>
- <li><a href=r38_0001.html#r38_0033>geqsign operator</a>alias= (> =)<P>
- <li><a href=r38_0001.html#r38_0034>greater operator</a>alias= (>)<P>
- <li><a href=r38_0001.html#r38_0035>leqsign operator</a>alias= (< =)<P>
- <li><a href=r38_0001.html#r38_0036>less operator</a>alias= (<)<P>
- <li><a href=r38_0001.html#r38_0037>tilde operator</a>alias= (~)<P>
- <li><a href=r38_0001.html#r38_0038>group command</a>alias= (< <)<P>
- <li><a href=r38_0001.html#r38_0039>AND operator</a><P>
- <li><a href=r38_0001.html#r38_0040>BEGIN command</a><P>
- <li><a href=r38_0001.html#r38_0041>block command</a><P>
- <li><a href=r38_0001.html#r38_0042>COMMENT command</a><P>
- <li><a href=r38_0001.html#r38_0043>CONS operator</a><P>
- <li><a href=r38_0001.html#r38_0044>END command</a><P>
- <li><a href=r38_0001.html#r38_0045>EQUATION type</a><P>
- <li><a href=r38_0001.html#r38_0046>FIRST operator</a><P>
- <li><a href=r38_0001.html#r38_0047>FOR command</a><P>
- <li><a href=r38_0001.html#r38_0048>FOREACH command</a><P>
- <li><a href=r38_0001.html#r38_0049>GEQ operator</a><P>
- <li><a href=r38_0050.html#r38_0050>GOTO command</a><P>
- <li><a href=r38_0050.html#r38_0051>GREATERP operator</a><P>
- <li><a href=r38_0050.html#r38_0052>IF command</a><P>
- <li><a href=r38_0050.html#r38_0053>LIST operator</a><P>
- <li><a href=r38_0050.html#r38_0054>OR operator</a><P>
- <li><a href=r38_0050.html#r38_0055>PROCEDURE command</a><P>
- <li><a href=r38_0050.html#r38_0056>REPEAT command</a><P>
- <li><a href=r38_0050.html#r38_0057>REST operator</a><P>
- <li><a href=r38_0050.html#r38_0058>RETURN command</a><P>
- <li><a href=r38_0050.html#r38_0059>REVERSE operator</a><P>
- <li><a href=r38_0050.html#r38_0060>RULE type</a><P>
- <li><a href=r38_0050.html#r38_0061>Free Variable type</a><P>
- <li><a href=r38_0050.html#r38_0062>Optional Free Variable type</a><P>
- <li><a href=r38_0050.html#r38_0063>SECOND operator</a><P>
- <li><a href=r38_0050.html#r38_0064>SET operator</a><P>
- <li><a href=r38_0050.html#r38_0065>SETQ operator</a><P>
- <li><a href=r38_0050.html#r38_0066>THIRD operator</a><P>
- <li><a href=r38_0050.html#r38_0067>WHEN operator</a><P>
- </menu>
- <a name=r38_0069>
- <title>ARITHMETIC_OPERATIONS</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>ARITHMETIC\_OPERATIONS</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>introduction</b><P>
- <P>
-
- This section considers operations defined in REDUCE that concern numbers,
- or operators that can operate on numbers in addition, in most cases, to
- more general expressions.
- <P>
- <P>
- <a name=r38_0070>
- <title>ABS</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>ABS</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- The <em>abs</em> operator returns the absolute value of its argument.
- <P>
- <P>
- <P> <H3>
- syntax: </H3>
- <em>abs</em>(<expression>)
- <P>
- <P>
- <P>
- <expression> can be any REDUCE scalar expression.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- abs(-a);
- ABS(A)
- abs(-5);
- 5
- a := -10;
- A := -10
- abs(a);
- 10
- abs(-a);
- 10
- </tt></pre><p>If the argument has had no numeric value assigned to it, such as a
- n
- identifier or polynomial, <em>abs</em> returns an expression involving
- <em>abs</em> of its argument, doing as much simplification of the argument
- as it can, such as dropping any preceding minus sign.
- <P>
- <P>
- <P>
- <a name=r38_0071>
- <title>ADJPREC</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>ADJPREC</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>switch</b><P>
- <P>
-
- <P>
- <P>
- When a real number is input, it is normally truncated to the
- <a href=r38_0200.html#r38_0214>precision</a> in
- effect at the time the number is read. If it is desired to keep the full
- precision of all numbers input, the switch <em>adjprec</em>
- (for <adjust precision>) can be turned on. While on, <em>adjprec</em>
- will automatically increase the precision, when necessary, to match that
- of any integer or real input, and a message printed to inform the user of
- the precision increase.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- on rounded;
- 1.23456789012345;
- 1.23456789012
- on adjprec;
- 1.23456789012345;
- *** precision increased to 15
- </tt></pre><p>
- <a name=r38_0072>
- <title>ARG</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>ARG</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- If
- <a href=r38_0250.html#r38_0274>complex</a> and
- <a href=r38_0300.html#r38_0330>rounded</a> are on, and arg
- evaluates to a complex number, <em>arg</em> returns the polar angle of
- arg, measured in radians. Otherwise an expression in arg is
- returned.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- arg(3+4i)
- ARG(3 + 4*I)
- on rounded, complex;
- ws;
- 0.927295218002
- arg a;
- ARG(A)
- </tt></pre><p>
- <a name=r38_0073>
- <title>CEILING</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>CEILING</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- <P> <H3>
- syntax: </H3>
- <em>ceiling</em>(<expression>)
- <P>
- <P>
- <P>
- This operator returns the ceiling (i.e., the least integer greater than or
- equal to its argument) if its argument has a numerical value. For
- negative numbers, this is equivalent to
- <a href=r38_0050.html#r38_0082>fix</a>. For non-numeric
- arguments, the value is an expression in the original operator.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- ceiling 3.4;
- 4
- fix 3.4;
- 3
- ceiling(-5.2);
- -5
- fix(-5.2);
- -5
- ceiling a;
- CEILING(A)
- </tt></pre><p>
- <a name=r38_0074>
- <title>CHOOSE</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>CHOOSE</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <em>choose</em>(<m>,<m>) returns the number of ways of choosing
- <m> objects from a collection of <n> distinct objects --- in other
- words the binomial coefficient. If <m> and <n> are not positive
- integers, or m >n, the expression is returned unchanged.
- than or equal to
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- choose(2,3);
- 3
- choose(3,2);
- CHOOSE(3,2)
- choose(a,b);
- CHOOSE(A,B)
- </tt></pre><p><P>
- <P>
- <a name=r38_0075>
- <title>DEG2DMS</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>DEG2DMS</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- <P> <H3>
- syntax: </H3>
- <em>deg2dms</em>(<expression>)
- <P>
- <P>
- <P>
- In
- <a href=r38_0300.html#r38_0330>rounded</a> mode, if <expression> is a real
- number, the
- operator <em>deg2dms</em> will interpret it as degrees, and convert it to a
- list containing the equivalent degrees, minutes and seconds. In all other
- cases, an expression in terms of the original operator is returned.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- deg2dms 60;
- DEG2DMS(60)
- on rounded;
- ws;
- {60,0,0}
- deg2dms 42.4;
- {42,23,60.0}
- deg2dms a;
- DEG2DMS(A)
- </tt></pre><p>
- <a name=r38_0076>
- <title>DEG2RAD</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>DEG2RAD</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- <P> <H3>
- syntax: </H3>
- <em>deg2rad</em>(<expression>)
- <P>
- <P>
- <P>
- In
- <a href=r38_0300.html#r38_0330>rounded</a> mode, if <expression> is a real
- number, the
- operator <em>deg2rad</em> will interpret it as degrees, and convert it to
- the equivalent radians. In all other cases, an expression in terms of the
- original operator is returned.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- deg2rad 60;
- DEG2RAD(60)
- on rounded;
- ws;
- 1.0471975512
- deg2rad a;
- DEG2RAD(A)
- </tt></pre><p>
- <a name=r38_0077>
- <title>DIFFERENCE</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>DIFFERENCE</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- The <em>difference</em> operator may be used as either an infix or prefix binary
-
- subtraction operator. It is identical to <em>-</em> as a binary operator.
- <P>
- <P>
- <P> <H3>
- syntax: </H3>
- <em>difference</em>(<expression>,<expression>) or
- <P>
- <P>
- <expression> <em>difference</em> <expression>
- {<em>difference</em> <expression>}*
- <P>
- <P>
- <P>
- <expression> can be a number or any other valid REDUCE expression. Matrix
- expressions are allowed if they are of the same dimensions.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- difference(10,4);
- 6
- 15 difference 5 difference 2;
- 8
- a difference b;
- A - B
- </tt></pre><p>The <em>difference</em> operator is left associative, as shown in
- the second
- example above.
- <P>
- <P>
- <P>
- <P>
- <a name=r38_0078>
- <title>DILOG</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>DILOG</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- The <em>dilog</em> operator is known to the differentiation and integration
- operators, but has numeric value attached only at <em>dilog(0)</em>. Dilog is
- defined by
- <P>
- <P>
- dilog(x) = -int(log(x),x)/(x-1)
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- df(dilog(x**2),x);
- 2
- 2*LOG(X )*X
- - ------------
- 2
- X - 1
- int(dilog(x),x);
- DILOG(X)*X - DILOG(X) + LOG(X)*X - X
- dilog(0);
- 2
- PI
- ----
- 6
- </tt></pre><p>
- <a name=r38_0079>
- <title>DMS2DEG</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>DMS2DEG</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- <P> <H3>
- syntax: </H3>
- <em>dms2deg</em>(<list>)
- <P>
- <P>
- <P>
- In
- <a href=r38_0300.html#r38_0330>rounded</a> mode, if <list> is a list of th
- ree real numbers,
- the operator <em>dms2deg</em> will interpret the list as degrees, minutes
- and seconds and convert it to the equivalent degrees. In all other cases,
- an expression in terms of the original operator is returned.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- dms2deg {42,3,7};
- DMS2DEG({42,3,7})
- on rounded;
- ws;
- 42.0519444444
- dms2deg a;
- DMS2DEG(A)
- </tt></pre><p>
- <a name=r38_0080>
- <title>DMS2RAD</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>DMS2RAD</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- <P> <H3>
- syntax: </H3>
- <em>dms2rad</em>(<list>)
- <P>
- <P>
- <P>
- In
- <a href=r38_0300.html#r38_0330>rounded</a> mode, if <list> is a list of th
- ree real numbers,
- the operator <em>dms2rad</em> will interpret the list as degrees, minutes
- and seconds and convert it to the equivalent radians. In all other cases,
- an expression in terms of the original operator is returned.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- dms2rad {42,3,7};
- DMS2RAD({42,3,7})
- on rounded;
- ws;
- 0.733944887421
- dms2rad a;
- DMS2RAD(A)
- </tt></pre><p>
- <a name=r38_0081>
- <title>FACTORIAL</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>FACTORIAL</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- <P> <H3>
- syntax: </H3>
- <em>factorial</em>(<expression>)
- <P>
- <P>
- <P>
- If the argument of <em>factorial</em> is a positive integer or zero, its
- factorial is returned. Otherwise the result is expressed in terms of the
- original operator. For more general operations, the
- <a href=r38_0450.html#r38_0492>gamma</a> operator
- is available in the
- <a href=r38_0400.html#r38_0444>Special Function Package</a>.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- factorial 4;
- 24
- factorial 30 ;
- 265252859812191058636308480000000
- </tt></pre><p>
- <a name=r38_0082>
- <title>FIX</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>FIX</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- <P> <H3>
- syntax: </H3>
- <em>fix</em>(<expression>)
- <P>
- <P>
- <P>
- The operator <em>fix</em> returns the integer part of its argument, if that
- argument has a numerical value. For positive numbers, this is equivalent
- to
- <a href=r38_0050.html#r38_0084>floor</a>, and, for negative numbers,
- <a href=r38_0050.html#r38_0073>ceiling</a>. For
- non-numeric arguments, the value is an expression in the original operator.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- fix 3.4;
- 3
- floor 3.4;
- 3
- ceiling 3.4;
- 4
- fix(-5.2);
- -5
- floor(-5.2);
- -6
- ceiling(-5.2);
- -5
- fix(a);
- FIX(A)
- </tt></pre><p>
- <a name=r38_0083>
- <title>FIXP</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>FIXP</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- The <em>fixp</em> logical operator returns true if its argument is an integer.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>fixp</em>(<expression>) or <em>fixp</em> <simple\_expression>
- <P>
- <P>
- <P>
- <expression> can be any valid REDUCE expression, <simple\_expression
- >
- must be a single identifier or begin with a prefix operator.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- if fixp 1.5 then write "ok" else write "not";
-
- not
- if fixp(a) then write "ok" else write "not";
-
- not
- a := 15;
- A := 15
- if fixp(a) then write "ok" else write "not";
-
- ok
- </tt></pre><p>Logical operators can only be used inside conditional expressions
- such as
- <em>if</em>...<em>then</em> or <em>while</em>...<em>do</em>.
- <P>
- <P>
- <P>
- <a name=r38_0084>
- <title>FLOOR</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>FLOOR</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- <P> <H3>
- syntax: </H3>
- <em>floor</em>(<expression>)
- <P>
- <P>
- <P>
- This operator returns the floor (i.e., the greatest integer less than or
- equal to its argument) if its argument has a numerical value. For
- positive numbers, this is equivalent to
- <a href=r38_0050.html#r38_0082>fix</a>. For non-numeric
- arguments, the value is an expression in the original operator.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- floor 3.4;
- 3
- fix 3.4;
- 3
- floor(-5.2);
- -6
- fix(-5.2);
- -5
- floor a;
- FLOOR(A)
- </tt></pre><p>
- <a name=r38_0085>
- <title>EXPT</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>EXPT</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- The <em>expt</em> operator is both an infix and prefix binary exponentiation
- operator. It is identical to <em>^</em> or <em>**</em>.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>expt</em>(<expression>,<expression>)
- or <expression> <em>expt</em> <expression>
- <P>
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- a expt b;
- B
- A
- expt(a,b);
- B
- A
- (x+y) expt 4;
- 4 3 2 2 3 4
- X + 4*X *Y + 6*X *Y + 4*X*Y + Y
- </tt></pre><p>Scalar expressions may be raised to fractional and floating-point
- powers.
- Square matrix expressions may be raised to positive powers, and also to
- negative powers if non-singular.
- <P>
- <P>
- <em>expt</em>is left associative. In other words, <em>a expt b expt c</em> is
- equivalent to <em>a expt (b*c)</em>, not <em>a expt (b expt c)</em>, which
- would be right associative.
- <P>
- <P>
- <P>
- <a name=r38_0086>
- <title>GCD</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>GCD</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- The <em>gcd</em> operator returns the greatest common divisor of two
- polynomials.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>gcd</em>(<expression>,<expression>)
- <P>
- <P>
- <P>
- <expression> must be a polynomial (or integer), otherwise an error
- occurs.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- gcd(2*x**2 - 2*y**2,4*x + 4*y);
- 2*(X + Y)
- gcd(sin(x),x**2 + 1);
- 1
- gcd(765,68);
- 17
- </tt></pre><p>The operator <em>gcd</em> described here provides an explicit mean
- s to find the
- gcd of two expressions. The switch <em>gcd</em> described below simplifies
- expressions by finding and canceling gcd's at every opportunity. When
- the switch
- <a href=r38_0250.html#r38_0286>ezgcd</a> is also on, gcd's are figured using the
- EZ GCD
- algorithm, which is usually faster.
- <P>
- <P>
- <P>
- <a name=r38_0087>
- <title>LN</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>LN</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- <P> <H3>
- syntax: </H3>
- <em>ln</em>(<expression>)
- <P>
- <P>
- <P>
- <expression> can be any valid scalar REDUCE expression.
- <P>
- <P>
- The <em>ln</em> operator returns the natural logarithm of its argument.
- However, unlike
- <a href=r38_0050.html#r38_0088>log</a>, there are no algebraic rules associated
- with it; it will only evaluate when
- <a href=r38_0300.html#r38_0330>rounded</a> is on, and the
- argument is a real number.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- ln(x);
- LN(X)
- ln 4;
- LN(4)
- ln(e);
- LN(E)
- df(ln(x),x);
- DF(LN(X),X)
- on rounded;
- ln 4;
- 1.38629436112
- ln e;
- 1
- </tt></pre><p>Because of the restricted algebraic properties of <em>ln</em>, use
- rs are
- advised to use
- <a href=r38_0050.html#r38_0088>log</a> whenever possible.
- <P>
- <P>
- <P>
- <a name=r38_0088>
- <title>LOG</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>LOG</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- The <em>log</em> operator returns the natural logarithm of its argument.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>log</em>(<expression>) or <em>log</em> <expression>
- <P>
- <P>
- <P>
- <expression> can be any valid scalar REDUCE expression.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- log(x);
- LOG(X)
- log 4;
- LOG(4)
- log(e);
- 1
- on rounded;
- log 4;
- 1.38629436112
- </tt></pre><p><em>log</em>returns a numeric value only when
- <a href=r38_0300.html#r38_0330>rounded</a> is on. In that
- case, use of a negative argument for <em>log</em> results in an error
- message. No error is given on a negative argument when REDUCE is not in
- that mode.
- <P>
- <P>
- <P>
- <a name=r38_0089>
- <title>LOGB</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>LOGB</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- <P> <H3>
- syntax: </H3>
- <em>logb</em>(<expression>,<integer>)
- <P>
- <P>
- <P>
- <expression> can be any valid scalar REDUCE expression.
- <P>
- <P>
- The <em>logb</em> operator returns the logarithm of its first argument using
- the second argument as base. However, unlike
- <a href=r38_0050.html#r38_0088>log</a>, there are no
- algebraic rules associated with it; it will only evaluate when
- <a href=r38_0300.html#r38_0330>rounded</a> is on, and the first argument is a re
- al number.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- logb(x,2);
- LOGB(X,2)
- logb(4,3);
- LOGB(4,3)
- logb(2,2);
- LOGB(2,2)
- df(logb(x,3),x);
- DF(LOGB(X,3),X)
- on rounded;
- logb(4,3);
- 1.26185950714
- logb(2,2);
- 1
- </tt></pre><p>
- <a name=r38_0090>
- <title>MAX</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>MAX</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- The operator <em>max</em> is an n-ary prefix operator, which returns the largest
-
- value in its arguments.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>max</em>(<expression>{,<expression>}*)
- <P>
- <P>
- <P>
- <P>
- <expression> must evaluate to a number. <em>max</em> of an empty list
- returns 0.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- max(4,6,10,-1);
- 10
- <<a := 23;b := 2*a;c := 4**2;max(a,b,c)>>;
-
- 46
- max(-5,-10,-a);
- -5
- </tt></pre><p>
- <a name=r38_0091>
- <title>MIN</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>MIN</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- The operator <em>min</em> is an n-ary prefix operator, which returns the
- smallest value in its arguments.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>min</em>(<expression>{,<expression>}*)
- <P>
- <P>
- <P>
- <expression> must evaluate to a number. <em>min</em> of an empty list
- returns 0.
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- min(-3,0,17,2);
- -3
- <<a := 23;b := 2*a;c := 4**2;min(a,b,c)>>;
-
- 16
- min(5,10,a);
- 5
- </tt></pre><p><P>
- <P>
- <a name=r38_0092>
- <title>MINUS</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>MINUS</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- The <em>minus</em> operator is a unary minus, returning the negative of its
- argument. It is equivalent to the unary <em>-</em>.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>minus</em>(<expression>)
- <P>
- <P>
- <P>
- <P>
- <expression> may be any scalar REDUCE expression.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- minus(a);
- - A
- minus(-1);
- 1
- minus((x+1)**4);
- 4 3 2
- - (X + 4*X + 6*X + 4*X + 1)
- </tt></pre><p>
- <a name=r38_0093>
- <title>NEXTPRIME</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>NEXTPRIME</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- <P> <H3>
- syntax: </H3>
- <em>nextprime</em>(<expression>)
- <P>
- <P>
- <P>
- If the argument of <em>nextprime</em> is an integer, the least prime greater
- than that argument is returned. Otherwise, a type error results.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- nextprime 5001;
- 5003
- nextprime(10^30);
- 1000000000000000000000000000057
- nextprime a;
- ***** A invalid as integer
- </tt></pre><p>
- <a name=r38_0094>
- <title>NOCONVERT</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>NOCONVERT</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>switch</b><P>
- <P>
-
- Under normal circumstances when <em>rounded</em> is on, REDUCE converts the
- number 1.0 to the integer 1. If this is not desired, the switch
- <em>noconvert</em> can be turned on.
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- on rounded;
- 1.0000000000001;
- 1
- on noconvert;
- 1.0000000000001;
- 1.0
- </tt></pre><p><P>
- <P>
- <a name=r38_0095>
- <title>NORM</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>NORM</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- <P> <H3>
- syntax: </H3>
- <em>norm</em>(<expression>)
- <P>
- <P>
- <P>
- If <em>rounded</em> is on, and the argument is a real number, <norm>
- returns its absolute value. If <em>complex</em> is also on, <norm>
- returns the square root of the sum of squares of the real and imaginary
- parts of the argument. In all other cases, a result is returned in
- terms of the original operator.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- norm (-2);
- NORM(-2)
- on rounded;
- ws;
- 2.0
- norm(3+4i);
- NORM(4*I+3)
- on complex;
- ws;
- 5.0
- </tt></pre><p>
- <a name=r38_0096>
- <title>PERM</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>PERM</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- <P> <H3>
- syntax: </H3>
- perm(<expression1>,<expression2>)
- <P>
- <P>
- <P>
- If <expression1> and <expression2> evaluate to positive integers,
- <em>perm</em> returns the number of permutations possible in selecting
- <expression1> objects from <expression2> objects.
- In other cases, an expression in the original operator is returned.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- perm(1,1);
- 1
- perm(3,5);
- 60
- perm(-3,5);
- PERM(-3,5)
- perm(a,b);
- PERM(A,B)
- </tt></pre><p>
- <a name=r38_0097>
- <title>PLUS</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>PLUS</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- The <em>plus</em> operator is both an infix and prefix n-ary addition
- operator. It exists because of the way in which REDUCE handles such
- operators internally, and is not recommended for use in algebraic mode
- programming.
- <a href=r38_0001.html#r38_0027>plussign</a>, which has the identical effect, sho
- uld be
- used instead.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>plus</em>(<expression>,<expression>{,<expression>}
- *) or
- <P>
- <P>
- <expression> <em>plus</em> <expression> {<em>plus</em> <expressio
- n>}*
- <P>
- <P>
- <P>
- <expression> can be any valid REDUCE expression, including matrix
- expressions of the same dimensions.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- a plus b plus c plus d;
- A + B + C + D
- 4.5 plus 10;
- 29
- --
- 2
- plus(x**2,y**2);
- 2 2
- X + Y
- </tt></pre><p>
- <a name=r38_0098>
- <title>QUOTIENT</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>QUOTIENT</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- The <em>quotient</em> operator is both an infix and prefix binary operator that
- returns the quotient of its first argument divided by its second. It is
- also a unary
- <a href=r38_0100.html#r38_0101>recip</a>rocal operator. It is identical to <em>/
- </em> and
- <a href=r38_0001.html#r38_0030>slash</a>.
- <P> <H3>
- syntax: </H3>
- <P>
- <P>
- <em>quotient</em>(<expression>,<expression>) or
- <expression> <em>quotient</em> <expression> or
- <em>quotient</em>(<expression>) or
- <em>quotient</em> <expression>
- <P>
- <P>
- <P>
- <expression> can be any valid REDUCE scalar expression. Matrix
- expressions can also be used if the second expression is invertible and the
- matrices are of the correct dimensions.
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- quotient(a,x+1);
- A
- -----
- X + 1
- 7 quotient 17;
- 7
- --
- 17
- on rounded;
- 4.5 quotient 2;
- 2.25
- quotient(x**2 + 3*x + 2,x+1);
- X + 2
- matrix m,inverse;
- m := mat((a,b),(c,d));
- M(1,1) := A;
- M(1,2) := B;
- M(2,1) := C
- M(2,2) := D
- inverse := quotient m;
- D
- INVERSE(1,1) := ----------
- A*D - B*C
- B
- INVERSE(1,2) := - ----------
- A*D - B*C
- C
- INVERSE(2,1) := - ----------
- A*D - B*C
- A
- INVERSE(2,2) := ----------
- A*D - B*C
- </tt></pre><p><P>
- <P>
- The <em>quotient</em> operator is left associative: <em>a quotient b quotient c
- </em>
- is equivalent to <em>(a quotient b) quotient c</em>.
- <P>
- <P>
- If a matrix argument to the unary <em>quotient</em> is not invertible, or if the
-
- second matrix argument to the binary quotient is not invertible, an error
- message is given.
- <P>
- <P>
- <P>
- <a name=r38_0099>
- <title>RAD2DEG</title></a>
- <p align="centre"><img src="redlogo.gif" width=621 height=60 border=0 alt="REDUC
- E"></p>
- <b><a href=r38_idx.html>INDEX</a></b><p><p>
- <b>RAD2DEG</b> _ _ _ _ _ _ _ _ _ _ _ _ <b>operator</b><P>
- <P>
-
- <P>
- <P>
- <P> <H3>
- syntax: </H3>
- <em>rad2deg</em>(<expression>)
- <P>
- <P>
- <P>
- In
- <a href=r38_0300.html#r38_0330>rounded</a> mode, if <expression> is a real
- number, the
- operator <em>rad2deg</em> will interpret it as radians, and convert it to
- the equivalent degrees. In all other cases, an expression in terms of the
- original operator is returned.
- <P>
- <P>
- <P> <H3>
- examples: </H3>
- <p><pre><tt>
- rad2deg 1;
- RAD2DEG(1)
- on rounded;
- ws;
- 57.2957795131
- rad2deg a;
- RAD2DEG(A)
- </tt></pre><p>
|