1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681 |
- REDUCE 3.4, 15-Jul-91 ...
- 1:
- (ASSIST)
- % Tests of Assist Package for version 3.4 of REDUCE.
- % DATE : 1 June 1991.
- % Author: H. Caprasse <u214001@bliulg11.bitnet>.
- % <u214001@vm1.ulg.ac.be>
- % 1. TESTS OF THE SWITCH CONTROL FUNCTIONS :
- ;
- switches;
- **** exp:=T ************* div:= NIL ****
- **** gcd:=NIL *********** mcd:= T ****
- **** allfac:=T *********** intstr:= NIL ****
- **** rat:=NIL *********** rational:= NIL ****
- *** factor:= NIL *********** distribute:= NIL ***
- switchoff;
- switches;
- **** exp:=NIL ************* div:= NIL ****
- **** gcd:=NIL *********** mcd:= NIL ****
- **** allfac:=NIL *********** intstr:= NIL ****
- **** rat:=NIL *********** rational:= NIL ****
- *** factor:= NIL *********** distribute:= NIL ***
- switchorg;
- switches;
- **** exp:=T ************* div:= NIL ****
- **** gcd:=NIL *********** mcd:= T ****
- **** allfac:=T *********** intstr:= NIL ****
- **** rat:=NIL *********** rational:= NIL ****
- *** factor:= NIL *********** distribute:= NIL ***
- ;
- if !*mcd then "the switch mcd is on";
- the switch mcd is on
- if !*gcd then "the switch gcd is on";
- ;
- % A new switch :
- !*distribute;
- %
- % 2. THE "LIST" MANIPULATION FACILITIES" :
- ;
- % generation of a new list
- ;
- t1:=mklist(4);
- T1 := {0,0,0,0}
- for i:=1:4 do t1:= (t1.i:=mkid(a,i));
- ;
- % notice that part(t1,i) has become t1.i. as also shown here :
- ;
- t1.1;
- A1
- t1:=(t1.1).t1;
- T1 := {A1,A1,A2,A3,A4}
- % MKLIST does NEVER destroy anything
- ;
- mklist(t1,3);
- {A1,A1,A2,A3,A4}
- mklist(t1,10);
- {A1,A1,A2,A3,A4,0,0,0,0,0}
- % 3. THE DEFINITION OF A BAG
- ;
- % The atom "BAG" is an available (and reserved) name for a BAG envelope
- % it is an OPERATOR. In what follows we mostly use it but we insist that
- % ANY identifier (there are a few exceptions) may be used.
- ;
- aa:=bag(x,1,"A");
- AA := BAG(X,1,A)
- % It is easy to construct NEW bag-like objects
- ;
- putbag bg1,bg2;
- T
- % now one can verify that
- ;
- aa:=bg1(x,y**2);
- 2
- AA := BG1(X,Y )
- % is a bag by BAGP
- ;
- if bagp aa then "this is a bag";
- this is a bag
- ;
- % One can erase the bag property of bg2 by the command
- ;
- clearbag bg2;
- ;
- % baglistp works in the same way for either a LIST OR a BAG
- ;
- if baglistp aa then "this is a bag or list";
- this is a bag or list
- if baglistp list(x) then "this is a bag or list";
- this is a bag or list
- ;
- % Use of the DISPLAYFLAG command that we shall illustrate below is
- % another way.
- % "LIST" MAY NOT be a bag.
- on errcont;
- % The command below gives an error message:
- ;
- putbag list;
- ***** LIST invalid as BAG
- % LISTS may be transformed to BAGS and vice versa
- off errcont;
- ;
- kernlist(aa);
- 2
- {X,Y }
- listbag(list x,bg1);
- BG1(X)
- %
- %
- % 4. BASIC MANIPULATION FUNCTIONS WORKING FOR BOTH STRUCTURES :
- ;
- % define:
- ;
- ab:=bag(x1,x2,x3);
- AB := BAG(X1,X2,X3)
- al:=list(y1,y2,y3);
- AL := {Y1,Y2,Y3}
- % We illustrate how the elementary functions do work DIFFERENTLY
- ;
- first ab;
- BAG(X1)
- third ab;
- BAG(X3)
- first al;
- Y1
- last ab;
- BAG(X3)
- last al;
- Y3
- % The subsequent one do act in the SAME way;
- rest ab;
- BAG(X2,X3)
- rest al;
- {Y2,Y3}
- belast ab;
- BAG(X1,X2)
- belast al;
- {Y1,Y2}
- ;
- % depth determines if the depth of the list is uniform.
- % when it is, it gives its deepness as an integer.
- ;
- depth al;
- 1
- depth bg1(ab);
- 2
- % It is very convenient to define the PICKUP function PART(x,n) by . :
- ;
- ab.1;
- X1
- al.3;
- Y3
- on errcont;
- ab.4;
- ***** Expression BAG(X1,X2,X3) does not have part 4
- off errcont;
- % For bags, it is possible to avoid an error message when one
- % has an index out of range using "first", "second" and "third".
- % For instance:
- ;
- second second ab;
- BAG()
- % This is coherent because the envelope of a bag always remains.
- ;
- size ab;
- 3
- length al;
- 3
- remove(ab,3);
- BAG(X1,X2)
- delete(y2,al);
- {Y1,Y3}
- reverse al;
- {Y3,Y2,Y1}
- member(x3,ab);
- BAG(X3)
- % notice the output.
- ;
- al:=list(x**2,x**2,y1,y2,y3);
- 2
- AL := {X ,
- 2
- X ,
- Y1,
- Y2,
- Y3}
- ;
- elmult(x**2,al);
- 2
- position(y3,al);
- 5
- ;
- repfirst(xx,al);
- 2
- {XX,X ,Y1,Y2,Y3}
- represt(xx,ab);
- BAG(X1,XX)
- insert(x,al,3);
- 2 2
- {X ,X ,X,Y1,Y2,Y3}
- insert( b,ab,2);
- BAG(X1,B,XX)
- insert(ab,ab,1);
- BAG(BAG(X1,XX),X1,XX)
- substitute (new,y1,al);
- 2 2
- {X ,X ,NEW,Y2,Y3}
- ;
- % Function that acts on TWO lists or bags :
- ;
- append(ab,al);
- 2 2
- BAG(X1,XX,X ,X ,Y1,Y2,Y3)
- append(al,ab);
- 2 2
- {X ,X ,Y1,Y2,Y3,X1,XX}
- ;
- % Association list or bag may be constructed and thoroughly used
- ;
- l:=list(a1,a2,a3,a4);
- L := {A1,A2,A3,A4}
- b:=bg1(x1,x2,x3);
- B := BG1(X1,X2,X3)
- % PAIR is the CONSTRUCTOR of the ASSOCIATION LIST or BAG.
- al:=pair(list(1,2,3,4),l);
- AL := {{1,A1},{2,A2},{3,A3},{4,A4}}
- ab:=pair(bg1(1,2,3),b);
- AB := BG1(BG1(1,X1),BG1(2,X2),BG1(3,X3))
- ;
- % A BOOLEAN function abaglistp to test if it is an association
- ;
- if abaglistp bag(bag(1,2)) then "it is an associated bag";
- it is an associated bag
- ;
- % Values associated to the keys can be extracted
- % first occurence ONLY.
- ;
- asfirst(1,al);
- {1,A1}
- asfirst(3,ab);
- BG1(3,X3)
- ;
- assecond(a1,al);
- {1,A1}
- assecond(x3,ab);
- BG1(3,X3)
- ;
- aslast(z,list(list(x1,x2,x3),list(y1,y2,z)));
- {Y1,Y2,Z}
- asrest(list(x2,x3),list(list(x1,x2,x3),list(y1,y2,z)));
- {X1,X2,X3}
- ;
- % All occurences.
- asflist(x,bg1(bg1(x,a1,a2),bg1(x,b1,b2)));
- BG1(BG1(X,A1,A2),BG1(X,B1,B2))
- asslist(a1,list(list(x,a1,a2),list(x,a1,b2),list(x,y,z)));
- {{X,A1,A2},{X,A1,B2}}
- restaslist(bag(a1,x),bg1(bag(x,a1,a2),bag(a1,x,b2),bag(x,y,z)));
- BG1(BG1(X,B2),BG1(A1,A2))
- restaslist(list(a1,x),bag(bag(x,a1,a2),bag(a1,x,b2),bag(x,y,z)));
- BAG(BAG(X,B2),BAG(A1,A2))
- %********
- % Mapping functions can be used with bags through
- ;
- on errcont;
- ;
- for each j in list(list(a),list(c)) join j;
- {A,C}
- for each j in list(bg1(a),bg1(b)) collect first j;
- {BG1(A),BG1(BG1(X1,X2,X3))}
- off errcont;
- ;
- % The FOR EACH .. IN .. statement requires a LIST-LIKE object.;
- ;
- % There are functions available for manipulating bags or lists
- % as sets. (they exist in the symbolic mode).
- ;
- ts:=mkset list(a1,a1,a,2,2);
- TS := {A1,A,2}
- ;
- % Again a boolean function to test the SET property
- ;
- if setp ts then "this is a SET";
- this is a SET
- ;
- union(ts,ts);
- {A1,A,2}
- diffset(ts,list(a1,a));
- {2}
- diffset(list(a1,a),ts);
- {}
- symdiff(ts,ts);
- {}
- intersect(listbag(ts,set1),listbag(ts,set2));
- SET1(A1,A,2)
- % 5. MISCELLANEOUS GENERAL PURPOSE FUNCTIONS :
- ;
- clear a1,a2,a3,a,x,y,z,x1,x2,op$
- minlist(list(1/2,1,3));
- 1
- ---
- 2
- maxlist(list(1/2,1,3));
- 3
- % DETECTION OF A GIVEN VARIABLE IN A GIVEN SET
- ;
- detidnum aa;
- detidnum a10;
- 10
- detidnum a1b2z34;
- 34
- % A list of a finite number of randomly chosen integers can be
- % generated:
- %
- randomlist(3,10);
- {0,0,1,2,2,2,0,0,0,0}
- %
- fact(120);
- 6689502913449127057588118054090372586752746333138029810295671352301633557244962989366874165271984981308157637893214090552534408589408121859898481114389650005964960521256960000000000000000000000000000
- combnum(8,3);
- 56
- permutations(bag(a1,a2,a3));
- BAG(BAG(A1,A2,A3),BAG(A1,A3,A2),BAG(A2,A1,A3),BAG(A2,A3,A1),
- BAG(A3,A1,A2),BAG(A3,A2,A1))
- combinations({a1,a2,a3},2);
- {{A2,A3},{A1,A3},{A1,A2}}
- ;
- % The "depend" command can be traced and made EXPLICIT :
- ;
- depatom a;
- A
- depend a,x,y;
- depatom a;
- {X,Y}
- % The second use of DEPEND
- ;
- depend op,x,y,z;
- implicit op;
- OP
- explicit op;
- OP(X,Y,Z)
- depend y,zz;
- explicit op;
- OP(X,Y(ZZ),Z)
- aa:=implicit op;
- AA := OP
- % The ENTIRE dependence of OP becomes "IMPLICIT"
- ;
- df(aa,y);
- DF(OP,Y)
- % These two last functions work properly ONLY when the command "DEPEND"
- %involves ATOMIC quantities.
- ;
- % Detection of variables a given function depends on is possible
- ;
- funcvar(x+y);
- {X,Y}
- funcvar(sin log(x+y));
- {X,Y}
- ;
- % Variables on which an expression depends :
- %
- funcvar(sin pi);
- funcvar(x+e+i);
- {X}
- %
- % CONSTANT and RESERVED identifiers are recognize and not taken
- % as variables.
- %
- % Now we illustrate functions that give, display or erase
- % a "FLAG" or a "PROPERTY" :
- ;
- % It is possible to give "flags" in the algebraic mode;
- %
- putflag(list(a1,a2),fl1,t);
- T
- putflag(list(a1,a2),fl2,t);
- T
- displayflag a1;
- {FL1,FL2}
- % to clear ALL flags created for a1 :
- ;
- clearflag a1,a2;
- displayflag a2;
- {}
- putprop(x1,propname,value,t);
- X1
- displayprop(x1,prop);
- {}
- displayprop(x1,propname);
- {{PROPNAME,VALUE}}
- % To clear ONE property
- ;
- putprop(x1,propname,value,0);
- displayprop(x1,propname);
- {}
- %
- %
- % 6. FUNCTIONS TO CONTROL THE ENVIRONMENT :
- ;
- % Algebraic ATOMS detection
- ;
- alatomp z;
- T
- z:=s1;
- Z := S1
- alatomp z;
- T
- % Algebraic KERNEL detection
- ;
- alkernp z;
- T
- alkernp log sin r;
- T
- % PRECEDENCE detection
- ;
- precp(difference,plus);
- T
- precp(plus,difference);
- precp(times,.);
- precp(.,times);
- T
- % STRING detection
- ;
- if stringp x then "this is a string";
- if stringp "this is a string" then "this is a string";
- this is a string
- ;
- ;
- % A function which detects the dependence of u with respect
- %to the ATOM or KERNEL v at ANY LEVEL
- ;
- depvarp(log(sin(x+cos(1/acos rr))),rr);
- T
- ;
- operator op;
- *** OP already defined as operator
- symmetric op;
- op(x,y)-op(y,x);
- 0
- remsym op;
- op(x,y)-op(y,x);
- OP(X,Y) - OP(Y,X)
- ;
- clear y,x,u,v;
- korder y,x,u,v;
- korderlist;
- (Y X U V)
- ;
- for all x,y such that nordp(x,y) let op(x,y)=x+y;
- op(a,b);
- BG1(X1,X2,X3) + A
- op(b,a);
- OP(BG1(X1,X2,X3),A)
- clear op;
- % DISPLAY and CLEARING of user's objects of various types entered
- % to the console. Only TOP LEVEL assignments are considered up to now.
- % The following statements must be made INTERACTIVELY. We put them
- % as COMMENTS for the user to experiment with them. We do this because
- % in a fresh environment all outputs are nil.
- ;
- % THIS PART OF THE TEST SHOULD BE REALIZED INTERACTIVELY.
- % SEE THE ** ASSIST LOG ** FILE .
- %v1:=v2:=1;
- %show variables; % For REDUCE 3.3 ONLY.
- %show scalars;
- %aa:=list(a);
- %show lists;
- %array ar(2);
- %show arrays;
- %load matr$
- %matrix mm;
- %show matrices;
- %x**2;
- %saveas res;
- %show saveids;
- %suppress variables; % For REDUCE 3.3 ONLY
- %show variables; % For REDUCE 3.3 ONLY
- %suppress scalars;
- %show scalars;
- %show lists;
- %suppress all;
- %show arrays;
- %show matrices;
- clear op;
- operator op;
- op(x,y,z);
- OP(X,Y,S1)
- clearop op;
- T
- clearfunctions abs,tan;
- *** ABS is unprotected : Cleared ***
- *** TAN is unprotected : Cleared ***
- "Clearing is complete"
- ;
- % THIS FUNCTION MUST BE USED WITH CARE !!"!!!
- ;
- % 7. NEW POLYNOMIAL MANIPUKLATION FACILITIES
- %
- %
- clear x,y,z;
- % To see the internal representation :
- %
- off pri;
- ;
- pol:=(x+2*y+3*z**2)**3;
- 3 2 2 2 2 4 3
- POL := 8*Y + (12*X + 36*Z )*Y + (6*X + 36*Z *X + 54*Z )*Y + X + 9
- 2 2 4 6
- *Z *X + 27*Z *X + 27*Z
- ;
- % Notice the recursive form.
- ;
- pold:=distribute pol;
- 3 2 2 2 4 2 2 3
- POLD := 8*Y + 36*Z *Y + 12*X*Y + 54*Z *Y + 36*Z *X*Y + 6*X *Y + X
- 2 2 4 6
- + 9*Z *X + 27*Z *X + 27*Z
- ;
- % Now it is in a distributive form.
- ;
- % Terms and reductums may be extracted individually :
- on distribute;
- polp:=pol$
- leadterm (pold);
- 3
- 8*Y
- pold:=redexpr pold;
- 2 2 2 4 2 2 3 2
- POLD := 36*Z *Y + 12*X*Y + 54*Z *Y + 36*Z *X*Y + 6*X *Y + X + 9*Z
- 2 4 6
- *X + 27*Z *X + 27*Z
- leadterm pold;
- 2 2
- 36*Z *Y
- ;
- off distribute;
- polp:=pol$
- leadterm polp;
- 3
- 8*Y
- polp:=redexpr polp;
- 2 2 2 2 4 3 2 2
- POLP := (12*X + 36*Z )*Y + (6*X + 36*Z *X + 54*Z )*Y + X + 9*Z *X
- 4 6
- + 27*Z *X + 27*Z
- leadterm polp;
- 2 2
- (12*X + 36*Z )*Y
- ;
- % "leadterm" and "redexpr" extract the leading term and reductum of a
- % polynomial respectively WITHOUT specifying the variable.
- % The default ordering is then assumed.
- % They work both for the distributive and recursive representations.
- %
- % The function "monom" puts in a list all monoms of a multivariate
- % polynomial.
- monom polp;
- 6
- {27*Z ,
- 4
- 27*Z *X,
- 2 2
- 9*Z *X ,
- 3
- X ,
- 2
- 6*X *Y,
- 2
- 36*Z *X*Y,
- 4
- 54*Z *Y,
- 2
- 12*X*Y ,
- 2 2
- 36*Z *Y }
- % "lowestdeg" extracts the smallest power of a given indeterminate
- % in a polynomial:
- lowestdeg(pol,z);
- 0
- ;
- on pri;
- ;
- divpol(pol,x+2*y+3*z**2);
- 2 2 2 2 4
- {X + 4*X*Y + 6*X*Z + 4*Y + 12*Y*Z + 9*Z ,
- 0}
- % This function gives the quotient AND the remainder directly inside a
- % list.
- ;
- % 8. MANIPUKLATIONS OF SOME ELEMENTARY TRANSCENDENTAL FUNCTIONS
- trig:=((sin x)**2+(cos x)**2)**4;
- 8 6 2 4 4
- TRIG := SIN(X) + 4*SIN(X) *COS(X) + 6*SIN(X) *COS(X)
- 2 6 8
- + 4*SIN(X) *COS(X) + COS(X)
- trigreduce trig;
- 1
- trig:=sin (5x);
- TRIG := SIN(5*X)
- trigexpand trig;
- 4 2 2 4
- SIN(X)*(SIN(X) - 10*SIN(X) *COS(X) + 5*COS(X) )
- trigreduce ws;
- SIN(5*X)
- trigexpand sin(x+y+z);
- - SIN(X)*SIN(Y)*SIN(Z) + SIN(X)*COS(Y)*COS(Z) + SIN(Y)*COS(X)*COS(Z)
- + SIN(Z)*COS(X)*COS(Y)
- ;
- % The same functions exist for hyperbolic functions:
- ;
- hypreduce (sinh x **2 -cosh x **2);
- -1
- ;
- % For expressions containing log's. Expansion in terms of sums,
- % differences, .. is given by "logplus" while concatenation is given
- % by the function "concsumlog".
- ;
- clear a,b;
- logplus log(a*log(x**b));
- LOG(LOG(X)) + LOG(A) + LOG(B)
- concsumlog((2*log x + a*b*log(x*y)+1)/(3*x**2*log(y)));
- A*B A*B 2
- LOG(Y *X *X ) + 1
- -----------------------
- 2
- 3*X
- LOG(Y )
- % Though these functions do use substitution rules, these are
- % active only during the time they actually do their work.
- % 9. VECTOR CALCULUS OPERATIONS
- ;
- clear u1,u2,v1,v2,v3,v4,w3,w4;
- u1:=list(v1,v2,v3,v4);
- U1 := {V1,V2,V3,V4}
- u2:=bag(w1,w2,w3,w4);
- U2 := BAG(W1,W2,W3,W4)
- %
- sumvect(u1,u2);
- {V1 + W1,
- V2 + W2,
- V3 + W3,
- V4 + W4}
- minvect(u2,u1);
- BAG( - V1 + W1, - V2 + W2, - V3 + W3, - V4 + W4)
- scalvect(u1,u2);
- V1*W1 + V2*W2 + V3*W3 + V4*W4
- crossvect(rest u1,rest u2);
- {V3*W4 - V4*W3,
- - V2*W4 + V4*W2,
- V2*W3 - V3*W2}
- mpvect(rest u1,rest u2, minvect(rest u1,rest u2));
- 0
- scalvect(crossvect(rest u1,rest u2),minvect(rest u1,rest u2));
- 0
- ;
- % 10. NEW OPERATIONS ON MATRICES
- ;
- clear m,mm,b,b1,bb,cc,a,b,c,d;
- matrix mm(2,2);
- baglmat(bag(bag(a1,a2)),m);
- T
- m;
- [A1 A2]
- on errcont;
- ;
- baglmat(bag(bag(a1),bag(a2)),m);
- ***** (MAT ((*SQ ((((A1 . 1) . 1)) . 1) T) (*SQ ((((A2 . 1) . 1)) . 1) T)))
- should be an identifier
- off errcont;
- % **** i.e. it cannot redefine the matrix! in order
- % to avoid accidental redefinition of an already given matrix;
- clear m;
- baglmat(bag(bag(a1),bag(a2)),m);
- T
- m;
- [A1]
- [ ]
- [A2]
- on errcont;
- baglmat(bag(bag(a1),bag(a2)),bag);
- ***** OPERATOR BAG invalid as matrix
- off errcont;
- % Right since a bag-like object cannot become a matrix.
- coercemat(m,op);
- OP(OP(A1),OP(A2))
- coercemat(m,list);
- {{A1},{A2}}
- ;
- on nero;
- unitmat b1(2);
- matrix b(2,2);
- b:=mat((r1,r2),(s1,s2));
- [R1 R2]
- B := [ ]
- [S1 S2]
- b1;
- [1 0]
- [ ]
- [0 1]
- b;
- [R1 R2]
- [ ]
- [S1 S2]
- mkidm(b,1);
- [1 0]
- [ ]
- [0 1]
- % Allows to relate matrices already defined.
- ;
- % Convenient to replace or get a matrix element inside a procedure :
- %
- seteltmat(b,newelt,2,2);
- [R1 R2 ]
- [ ]
- [S1 NEWELT]
- geteltmat(b,2,1);
- S1
- %
- b:=matsubr(b,bag(1,2),2);
- [R1 R2]
- B := [ ]
- [1 2 ]
- % It gives automatically a new matrix with the second row substituted.
- ;
- submat(b,1,2);
- [1]
- % What is left when row 1 and column 2 are taken off the matrix.
- bb:=mat((1+i,-i),(-1+i,-i));
- [I + 1 - I]
- BB := [ ]
- [I - 1 - I]
- cc:=matsubc(bb,bag(1,2),2);
- [I + 1 1]
- CC := [ ]
- [I - 1 2]
- % Second column substituted.
- cc:=tp matsubc(bb,bag(1,2),2);
- [I + 1 I - 1]
- CC := [ ]
- [ 1 2 ]
- matextr(bb, bag,1);
- BAG(I + 1, - I)
- % First row extracted and placed in a bag.
- matextc(bb,list,2);
- { - I, - I}
- % Second column extracted and placed in a bag.
- ;
- hconcmat(bb,cc);
- [I + 1 - I I + 1 I - 1]
- [ ]
- [I - 1 - I 1 2 ]
- vconcmat(bb,cc);
- [I + 1 - I ]
- [ ]
- [I - 1 - I ]
- [ ]
- [I + 1 I - 1]
- [ ]
- [ 1 2 ]
- % Horizontal an vertical concatenations.
- ;
- tpmat(bb,bb);
- [ 2*I - I + 1 - I + 1 -1]
- [ ]
- [ -2 - I + 1 I + 1 -1]
- [ ]
- [ -2 I + 1 - I + 1 -1]
- [ ]
- [ - 2*I I + 1 I + 1 -1]
- % Tensor product.
- %
- % It is an INFIX operation :
- bb tpmat bb;
- [ 2*I - I + 1 - I + 1 -1]
- [ ]
- [ -2 - I + 1 I + 1 -1]
- [ ]
- [ -2 I + 1 - I + 1 -1]
- [ ]
- [ - 2*I I + 1 I + 1 -1]
- ;
- clear hbb;
- hermat(bb,hbb);
- [ - I + 1 - (I + 1)]
- [ ]
- [ I I ]
- % id hbb changed to a matrix id and assigned to the hermitian matrix
- % of bb.
- ;
- end;
- Quitting
|