123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726 |
- REDUCE 3.6, 15-Jul-95, patched to 6 Mar 96 ...
- % Test of Complex Number mode in REDUCE.
- on complex;
- (31+i)/74;
- 31 + i
- --------
- 74
- ws/(b+1);
- 31 + i
- ------------
- 74*(b + 1)
- % this now comes out right!
- w:=(x+3*i)**2;
- 2
- w := x + 6*i*x - 9
- on gcd;
- (x**3-7*x**2+x-7)/(x**2+(3+i)*x+3*i);
- 2
- x - (7 + i)*x + 7*i
- ----------------------
- x + 3
- off gcd;
- sqrt(x**4+14*i*x**3-51*x**2-14*i*x+1);
- 2
- abs(x + 7*i*x - 1)
- % All rounded tests are done twice: first, they are done at the default
- % precision, in which all rounded operations use standard floating point
- % logic. Then precision is increased, causing all rounded operations to
- % use extended precision bigfloat arithmetic. This is necessary to
- % exercise and test the bigfloat-based arithmetic functions.
- prec0 := precision 0;
- prec0 := 12
- % to determine the nominal default precision.
- % Tests using default precision:
- on rounded;
- *** Domain mode complex changed to complex-rounded
- (3.25 + 8.5i) + (6.75 - 8.5i);
- 10.0
- (3.25 + 8.5i) - (6.0 - 9.5i);
- - 2.75 + 18.0*i
- (1.0 + 10.0*i)*(-6.5 + 2.5*i);
- - 31.5 - 62.5*i
- (1.2 - 3.4*i)*(-5.6 + 7.8*i);
- 19.8 + 28.4*i
- (19.8 + 28.4*i)/(-5.6 + 7.8*i);
- 1.2 - 3.4*i
- e;
- 2.71828182846
- pi;
- 3.14159265359
- 17*i**2;
- -17
- (-7.0 + 24.0*i)**(1/2);
- 3.0 + 4.0*i
- sqrt(-7.0 + 24.0*i);
- 3.0 + 4.0*i
- sqrt(-10.12 - 8.16*i);
- 1.2 - 3.4*i
- sin(0.0 + 0.0*i);
- 0
- sin(1.0 + 0.0*i);
- 0.841470984808
- sin(1.0 + 1.0*i);
- 1.29845758142 + 0.634963914785*i
- cos(0.0 + 0.0*i);
- 1
- cos(1.0 - 0.0*i);
- 0.540302305868
- cos(1.0 + 1.0*i);
- 0.833730025131 - 0.988897705763*i
- tan(0.0 + 0.0*i);
- 0
- tan(1.0 + 0.0*i);
- 1.55740772465
- tan(1.0 + 1.0*i);
- 0.27175258532 + 1.08392332734*i
- asin(1.0 + 1.0*i);
- 0.666239432493 + 1.06127506191*i
- acos(1.0 + 1.0*i);
- 0.904556894302 - 1.06127506191*i
- atan(1.0 + 1.0*i);
- 1.0172219679 + 0.402359478109*i
- log(1.0 + 1.0*i);
- 0.34657359028 + 0.785398163397*i
- asin 2;
- 1.57079632679 - 1.31695789692*i
- sin ws;
- 2.0 - 1.25983163303e-15*i
- acos 2;
- 1.31695789692*i
- cos ws;
- 2.0
- atan(1+i);
- 1.0172219679 + 0.402359478109*i
- tan ws;
- 1 + i
- log(2+i);
- 0.804718956217 + 0.463647609001*i
- exp ws;
- 2.0 + i
- e**(i*pi);
- - 1 + 1.22460635382e-16*i
- e**i;
- 0.540302305868 + 0.841470984808*i
- z := sqrt i;
- z := 0.707106781187 + 0.707106781187*i
- z**2;
- i
- off rounded;
- *** Domain mode complex-rounded changed to complex
- %-----------------end of normal floating point tests--------------------
- precision(prec0+6);
- 12
- % arbitrary precision increase -> bigfloat functions
- %----------------------start of bigfloat tests--------------------------
- on rounded;
- *** Domain mode complex changed to complex-rounded
- (3.25 + 8.5i) + (6.75 - 8.5i);
- 10.0
- (3.25 + 8.5i) - (6.0 - 9.5i);
- - 2.75 + 18.0*i
- (1.0 + 10.0*i)*(-6.5 + 2.5*i);
- - 31.5 - 62.5*i
- (1.2 - 3.4*i)*(-5.6 + 7.8*i);
- 19.8 + 28.4*i
- (19.8 + 28.4*i)/(-5.6 + 7.8*i);
- 1.2 - 3.4*i
- e;
- 2.71828182845904524
- pi;
- 3.14159265358979324
- 17*i**2;
- -17
- (-7.0 + 24.0*i)**(1/2);
- 3.0 + 4.0*i
- sqrt(-7.0 + 24.0*i);
- 3.0 + 4.0*i
- sqrt(-10.12 - 8.16*i);
- 1.2 - 3.4*i
- sin(0.0 + 0.0*i);
- 0
- sin(1.0 + 0.0*i);
- 0.841470984807896507
- sin(1.0 + 1.0*i);
- 1.29845758141597729 + 0.634963914784736108*i
- cos(0.0 + 0.0*i);
- 1
- cos(1.0 - 0.0*i);
- 0.540302305868139717
- cos(1.0 + 1.0*i);
- 0.833730025131149049 - 0.988897705762865096*i
- tan(0.0 + 0.0*i);
- 0
- tan(1.0 + 0.0*i);
- 1.55740772465490223
- tan(1.0 + 1.0*i);
- 0.271752585319511717 + 1.08392332733869454*i
- asin(1.0 + 1.0*i);
- 0.666239432492515255 + 1.06127506190503565*i
- acos(1.0 + 1.0*i);
- 0.904556894302381364 - 1.06127506190503565*i
- atan(1.0 + 1.0*i);
- 1.01722196789785137 + 0.402359478108525094*i
- log(1.0 + 1.0*i);
- 0.346573590279972655 + 0.78539816339744831*i
- asin 2;
- 1.57079632679489662 - 1.31695789692481671*i
- sin ws;
- 2.0
- acos 2;
- 1.31695789692481671*i
- cos ws;
- 2.0
- atan(1+i);
- 1.01722196789785137 + 0.402359478108525094*i
- tan ws;
- 1 + i
- log(2+i);
- 0.804718956217050187 + 0.463647609000806116*i
- exp ws;
- 2.0 + i
- e**(i*pi);
- - 1
- e**i;
- 0.540302305868139717 + 0.841470984807896507*i
- z := sqrt i;
- z := 0.707106781186547524 + 0.707106781186547524*i
- z**2;
- i
- off rounded;
- *** Domain mode complex-rounded changed to complex
- % ---------------------------------------------------------------------
- % The following examples are independent of precision.
- precision prec0;
- 18
- % restores default precision.
- % on rationalize; % no longer needed, since it doesn't affect complex.
- s:= 1.1+2.3i;
- 11 + 23*i
- s := -----------
- 10
- s/4;
- 11 + 23*i
- -----------
- 40
- % this would have had a common factor of 4.
- x:= a+1.1+2.3i;
- 10*a + 11 + 23*i
- x := ------------------
- 10
- y:= b+1.2+1.3i;
- 10*b + 12 + 13*i
- y := ------------------
- 10
- z:= x/y;
- 100*a*b + (120 - 130*i)*a + (110 + 230*i)*b + 431 + 133*i
- z := -----------------------------------------------------------
- 2
- 100*b + 240*b + 313
- z/4;
- 100*a*b + (120 - 130*i)*a + (110 + 230*i)*b + 431 + 133*i
- -----------------------------------------------------------
- 2
- 4*(100*b + 240*b + 313)
- % this would have had a common polynomial factor b^2 + ...
- z*7/4;
- 7*(100*a*b + (120 - 130*i)*a + (110 + 230*i)*b + 431 + 133*i)
- ---------------------------------------------------------------
- 2
- 4*(100*b + 240*b + 313)
- s/(c^2+c+1);
- 11 + 23*i
- -----------------
- 2
- 10*(c + c + 1)
- % this would have had a common factor of c^2+c+1
- clear x;
- zz:= x^2+(1.1+2.3i)*x+1.2+1.3i;
- 2
- 10*x + (11 + 23*i)*x + 12 + 13*i
- zz := -----------------------------------
- 10
- ss:=1.23456789x^2+1.3579i*x+5.6789;
- 2
- 123456789*x + 135790000*i*x + 567890000
- ss := ------------------------------------------
- 100000000
- % off rationalize; % not needed now.
- z:= x+1.1+2.3i;
- 10*x + 11 + 23*i
- z := ------------------
- 10
- on rationalize;
- z;
- 10*x + 11 + 23*i
- ------------------
- 10
- % same as previous answer.
- off rationalize;
- 1.23456789x^2+2.3456i*x+7.89;
- 2
- 123456789*x + 234560000*i*x + 789000000
- ------------------------------------------
- 100000000
- on factor;
- x**2+1;
- (x + i)*(x - i)
- x**4-1;
- (x + i)*(x - i)*(x + 1)*(x - 1)
- x**4+(i+2)*x**3+(2*i+5)*x**2+(2*i+6)*x+6;
- 2
- (x + i*x + 3)*(x + 1 + i)*(x + 1 - i)
- (2*i+3)*x**4+(3*i-2)*x**3-2*(i+1)*x**2+i*x-1;
- 2 2
- i*((2 - 3*i)*x - i)*(x + i*x - 1)
- % Multivariate examples:
- x**2+y**2;
- (10*b + 10*i*x + 12 + 13*i)*(10*b - 10*i*x + 12 + 13*i)
- ---------------------------------------------------------
- 100
- off factor;
- factorize(x**2+1);
- {x - i,x + i}
- end;
- (TIME: complex 810 850)
|