SESSION 01
> 2+3; 244*7; 3^4; 2/7; 2/3 + 5/7;
> sqrt(5); exp(x); exp(ln(x)); e^(ln(x)); i^2; I^2; (1+i)*(1-i);
(1+I)*(1-I);
5 ex x eln( )x
i2 -1 1 + i ( ) 1 - i( )
2
> a:=5; b:=2; c:=3; x:=sqrt(a); y:=sqrt(b);
a := 5 b := 2 c := 3 x := 5 y := 2
> a; a+b; b*c; x^2+y;
7 9 10 7 + 2
> restart; b; x;
b x
> A:=(2*x+2)*(5*x-3); B:=subs(x=(y+2)/(y-1),A); x; expand(A); simplify(B);
A := 2 x + 2( ) 5 x - 3( ) B := 2 (y + 2)
y - 1 + 2
!"
#
$%
&
5 (y + 2) y - 1 - 3
!"
#
$%
&
x 10 x2 + 4 x - 6 2 2 y + 1( ) 2 y + 13( )
y - 1 ( )2
> 5/3;
5 3
> evalf(5/3);
1.666666667
> Digits:=20;
Digits := 20
> evalf(5/3);
1.6666666666666666667
> evalf(5/3,20);
1.6666666666666666667
> evalf(5/7);
0.71428571428571428571
> evalf(sqrt(5));
2.2360679774997896964
> evalf(Pi); evalf(pi); evalf(exp(1)); evalf(ln(2)); evalf(sin(Pi/2));
evalf(cos(pi/3));
3.1415926535897932385
!
2.7182818284590452354 0.69314718055994530942
1.
cos 0.33333333333333333333 !( )
> evalf(1/1+sqrt(3),50);
2.7320508075688772935274463415058723669428052538104
> 1+(1/(1+(1/2))); evalf(%); ((1+2/3)/(1-2/3))*((3+5/4)/(3+7/3));
evalf(%);
5 3
1.6666666666666666667 255
64 3.9843750000000000000
> x:=7+sqrt(3); y:= 1- 5*sqrt(3); expand(x^2*y^3);
expand(rationalize((x+y)/(x^2-y)));
x := 7 + 3 y := 1 - 5 3 -4628 - 17116 3
106 253 - 178
759 3
> a:=cos(Pi/4); b:=sin(Pi/4); expand(rationalize((a+b^2)/(a^3 - b^4)));
a := 1 2 2 b := 1
2 2 6 + 4 2
> evalc((1+I)/(2+3*I)); evalc((1+I)^3);
5 13 - 1
13 I -2 + 2 I
> x:=2+3*I*sqrt(5); y:=2-I*sqrt(3); evalf(Re(x^2/(x+y)),30);
x := 2 + 3 I 5 y := 2 - I 3
-.747650396133685080663798185792
> z:=1+I*sqrt(3); abs(z)*e^(argument(z)*I);
z := 1 + I 3
2 e 1 3 I !
!# $
&
> restart; f:=x->x^2; g:=y->if y>=0 then (y^5-ln(y))/2 else 0 fi;
simplify(combine((g@f)(y),ln)); g(f(4)); g(f(-2));
f := x - x2 g := y - if 0 . y then 1
2 y5 - 1
2 ln( ) elsey 0 end if;
Error, (in g) cannot determine if this expression is true or false: -y^2
<= 0
524288 - 2 ln 2( ) 512 - ln 2( )
> diff(f(x),x); diff(g(y),y);
2 x 5 2 y4 - 1
2 y
> diff(g(y),y$6);
60 y6
> A:=2*x+t*(y+4); whattype(A); nops(A); op(2,A); whattype(op(1,A));
whattype(op(2,A));
A := 2 x + t (y + 4)
+ 2 t (y + 4)
*
*
> L:=[(x+y-1)^3, (3*x+1)/(x+3), sin(a*x+b)];
for l in L do print(l); whattype(l); op(l); od;
L := (x + y - 1)3, 3 x + 1
x + 3, sin(a x + b) '(
)
*+ , x + y - 1
( )3
^ x + y - 1, 3
3 x + 1 x + 3
* 3 x + 1, 1
x + 3 sin(a x + b)
function a x + b
> L:=[1,2,a,x+y,1/x]; whattype(L); nops(L);
L := 1, 2, a, x + y, 1 x '(
)
*+ , list
5
> S:=seq(k^2,k=1..10); [S];
S := 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 1, 4, 9, 16, 25, 36, 49, 64, 81, 100
[ ]
> L:=[seq(x-k,k=1..5)]; whattype(L); nops(L);
L := [x - 1, x - 2, x - 3, x - 4, x - 5] list
5
> for j from 1 to nops(L) do op(j,L) od;
x - 1 x - 2 x - 3 x - 4 x - 5
> l:=[seq(binomial(15,p),p=0..15)];
l := 1, 15, 105, 455, 1365, 3003, 5005, 6435, 6435, 5005, 3003, 1365, 455, 105, 15, 1[ ]
> A:=5*x^2-6*x+2; convert(A,list); convert(A,`*`);
L:=[seq(x-k,k=1..10)]; convert(L,`*`); expand(%);
A := 5 x2 - 6 x + 2 5 x2, -6 x, 2
[ ]
-60 x3
L := [x - 1, x - 2, x - 3, x - 4, x - 5, x - 6, x - 7, x - 8, x - 9, x - 10] x - 1
( ) (x - 2) (x - 3) (x - 4) (x - 5) (x - 6) (x - 7) (x - 8) (x - 9) (x - 10)
x10 - 55 x9 + 1320 x8 - 18150 x7 + 157773 x6 - 902055 x5 + 3416930 x4 - 8409500 x3 + 12753576 x2 - 10628640 x + 3628800
> restart: L:=[seq(convert([seq((15-k+1)/k,k=1..p)],`*`),p=0..15)];
s:=0: for i from 1 to nops(L) do s:=s+L[i] od; convert(L,`+`);
L := 1, 15, 105, 455, 1365, 3003, 5005, 6435, 6435, 5005, 3003, 1365, 455, 105, 15, 1[ ] s := 1
s := 16 s := 121 s := 576 s := 1941 s := 4944 s := 9949 s := 16384 s := 22819 s := 27824 s := 30827 s := 32192 s := 32647 s := 32752 s := 32767 s := 32768 32768
> f:=x->1/x; A:=x+y+z; map(f,A);
f := x - 1 x A := x + y + z
1 x + 1
y + 1 z
> f:=x->x^2; map(f,1+1); map(f,x+1); A:=(x+1)/(x-1)+(2*x+1);
map(f,A);
f := x - x2 4 x2 + 1 A := x + 1
x - 1 + 2 x + 1 x + 1
( )2 x - 1 ( )2
+ 4 x2 + 1
> f:=x->ln(1+x); X:=[0.1,0.5,1/2,1,4,10]; Y1:=map(f,X);
Y:=map(evalf@f,X);
f := x - ln 1 + x( ) X := 0.1, 0.5, 1
2, 1, 4, 10 '(
)
*+ , Y1 := 0.09531017980, 0.4054651081, ln 3
2
!"
#
$%
&, ln 2( ), ln 5( ), ln 11( ) '(
)
*+ ,
Y := 0.09531017980, 0.4054651081, 0.4054651081, 0.6931471806, 1.609437912, 2.397895273[ ]
> L:=[seq((2*k+1)^3,k=0..19)]; convert(L,`+`);
f:=x->(2*x+1)^3: K:=[seq(k,k=0..19)]; map(f,K); convert(%,`+`);
L := [1, 27, 125, 343, 729, 1331, 2197, 3375, 4913, 6859, 9261, 12167, 15625, 19683, 24389, 29791, 35937, 42875, 50653, 59319]
319600
K := 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19[ ]
[1, 27, 125, 343, 729, 1331, 2197, 3375, 4913, 6859, 9261, 12167, 15625, 19683, 24389, 29791, 35937, 42875, 50653, 59319]
319600
> factor(a^2-b^2);
for k from 1 to 8 do factor(a^k-b^k) od;
factor(x^3-x^2-3*x+3);
factor(x^3-x^2-3*x+3,sqrt(3));
a - b ( ) (a + b)
a - b a - b ( ) (a + b) a - b
( ) (a2 + a b + b2) a - b
( ) (a + b) (a2 + b2) a - b
( ) (a4 + a3 b + a2 b2 + a b3 + b4) a - b
( ) (a + b) (a2 + a b + b2) (a2 - a b + b2) a - b
( ) (a6 + a5 b + a4 b2 + a3 b3 + a2 b4 + a b5 + b6) a - b
( ) (a + b) (a2 + b2) (a4 + b4)
x - 1 ( ) (x2 - 3) x + 3
( ) (x - 3) (x - 1)
> restart: expand((x-2)^20); expand((5*x+(1/3))^7);
1048576 + x20 - 40 x19 + 760 x18 - 9120 x17 + 77520 x16 - 496128 x15 + 2480640 x14 - 9922560 x13 + 32248320 x12 - 85995520 x11 + 189190144 x10 - 343982080 x9 + 515973120 x8 - 635043840 x7 + 635043840 x6 - 508035072 x5 + 317521920 x4 - 149422080 x3 + 49807360 x2 - 10485760 x
78125 x7 + 109375
3 x6 + 21875
3 x5 + 21875 27 x4 + 4375
81 x3 + 175 81 x2 + 35
729 x + 1 2187
> factor(expand(exp(a+b)+exp(a))); factor(x^14+1);
ea! eb + 1
# $
&
x2 + 1
( ) (x12 - x10 + x8 - x6 + x4 - x2 + 1)
> for i from 1 to 15 do A:=expand((x+1)^i):
subs(x=1,[seq(op(j,A),j=1..nops(A))]): print(%); od:
1, 1
[ ]
1, 2, 1
[ ]
1, 3, 3, 1
[ ]
1, 4, 6, 4, 1
[ ]
1, 5, 10, 10, 5, 1
[ ]
1, 6, 15, 20, 15, 6, 1
[ ]
1, 7, 21, 35, 35, 21, 7, 1
[ ]
1, 8, 28, 56, 70, 56, 28, 8, 1
[ ]
1, 9, 36, 84, 126, 126, 84, 36, 9, 1
[ ]
1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1
[ ]
1, 1, 11, 55, 165, 330, 462, 462, 330, 165, 55, 11
[ ]
1, 1, 12, 66, 220, 495, 792, 924, 792, 495, 220, 66, 12
[ ]
1, 1, 13, 78, 286, 715, 1287, 1716, 1716, 1287, 715, 286, 78, 13
[ ]
1, 1, 14, 91, 364, 1001, 2002, 3003, 3432, 3003, 2002, 1001, 364, 91, 14
[ ]
1, 1, 15, 105, 455, 1365, 3003, 5005, 6435, 6435, 5005, 3003, 1365, 455, 105, 15
[ ]
> restart; expand(tan(2*x)); expand(sin(5*x)); combine(sin(x)^4,trig);
2 tan( )x 1 - tan( )x2
16 sin( ) cosx ( )x4 - 12 sin( ) cosx ( )x2 + sin( )x 3
8 + 1
8 cos 4 x( ) - 1 2 cos 2 x( )
> convert(arcsinh(x),ln); convert(cos(x),tan);
ln(x + x2 + 1)
1 - tan 1 2 x
!"
#
$%
&
2
1 + tan 1 2 x
!"
#
$%
&
2
> assume(x>-1): assume(y>0): combine(3*ln(x+1)+2*ln(y),ln); restart:
combine(exp(a^2)*exp(b)^3,exp);
ln((x~ + 1)3 y~2) e(a2 + 3 b)
> convert(exp(I*x),trig); convert(sin(x),exp);
cos( ) + I sinx ( )x -1
2 I e( )I x - 1
e( )I x
!"
"
"
#
$%
%%
&
> convert(sin(x),tan); convert(cos(x),tan);
convert(sin(x),tan)/convert(cos(x),tan);
2 tan 1 2 x
!"
#
$%
&
1 + tan 1 2 x
!"
#
$%
&
2
1 - tan 1 2 x
!"
#
$%
&
2
1 + tan 1 2 x
!"
#
$%
&
2
2 tan 1 2 x
!"
#
$%
&
1 - tan 1 2 x
!"
#
$%
&
2
> simplify(convert(convert((1-exp(I*x))/(1+exp(I*x)),trig),tan));
- tan 1
2 x
!"
#
$%
& -tan 1
2 x
!"
#
$%
& + I
!"
#
$%
&
1 + I tan 1 2 x
!"
#
$%
&
> combine(sin(x)^6*cos(x)^5,trig);
- 5
1024 cos 5 x( ) - 5
512 cos 3 x( ) + 5
512 cos( ) - x 1
1024 cos 11 x( ) + 1
1024 cos 9 x( ) + 5 1024 cos 7 x( )
> expand(sin(x)+sin(2*x)+sin(3*x)+sin(4*x)+sin(5*x)); factor(%);
sin( ) - 2 sinx ( ) cosx ( ) - 8 sinx ( ) cosx ( )x2 + 8 sin( ) cosx ( )x3 + 16 sin( ) cosx ( )x4 sin( ) 2 cosx ( ( ) + 1x ) 2 cos( ( ) - 1x ) 4 cos( ( )x2 + 2 cos( ) - 1x )
> z:=(1+I*sqrt(3))/(1-I); convert(z,polar);
z := 1 2 + 1
2 I
!"
#
$%
& 1 + I 3( )
polar 2, arctan 1 2 3 + 1
2 1 2 - 1
2 3
!"
"
"
"
"
#
$%
%%
%%
&
+ !
!"
"
"
"
"
#
$%
%%
%%
&
> a:=(1/2*3^(1/2)+1/2)/(1/2-1/2*3^(1/2)); expand(rationalize(a));
arctan(%);
a :=
1 2 3 + 1
2 1 2 - 1
2 3 -2 - 3
- 5 12 !
> somme:=proc(n) local i,resultat;
if n<0 then
print(`Le calcul est impossible`) else
resultat:=0;
for i from 1 to n do resultat:=resultat+i; od;
fi;
end;
somme := proc( )n local i, resultat;
if n < 0 then
print `Le calcul est impossible`( )
else resultat := 0; for i to n do resultat := resultat + i end do;
end if;
end proc;
> somme(5); somme(4.5); somme(-3); somme(bonjour);
15 10
Le calcul est impossible
Error, (in somme) cannot determine if this expression is true or false:
bonjour < 0
> somme:=proc(n::integer) local i,resultat;
if n<0 then
print(`Le calcul est impossible`) else
resultat:=0;
for i from 1 to n do resultat:=resultat+i; od;
fi;
end;
somme := proc(n::integer) local i, resultat;
if n < 0 then
print `Le calcul est impossible`( )
else resultat := 0; for i to n do resultat := resultat + i end do;
end if;
end proc;
> somme(5); somme(4.5); somme(-3); somme(bonjour);
15
Error, invalid input: somme expects its 1st argument, n, to be of type integer, but received 4.5
Le calcul est impossible
Error, invalid input: somme expects its 1st argument, n, to be of type integer, but received bonjour
> factorielle:=proc(n::integer) if n=0 then 1 else
n*factorielle(n-1) fi end: for i from 1 to 10 do factorielle(i) od;
1 2 6 24 120 720 5040 40320 362880 3628800
> st := time(): fib:=proc(n::integer)if n=0 then 1 elif n
= 1 then 1 else fib(n-1)+fib(n-2) fi end: seq(fib(n),n=1..20); time() - st;
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946 0.350
> st := time(): fib:=proc(n::integer) option remember; if n=0 then 1 elif n
= 1 then 1 else fib(n-1)+fib(n-2) fi end: seq(fib(n),n=1..20); time() - st;
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946 0.
> st := time(): fib1:=proc(n::integer)
expand((1+sqrt(5))^(n+1)-(1-sqrt(5))^(n+1))/(sqrt(5)*2^(n+1)) end:
seq(fib1(n),n=1..20); time() - st;
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946 0.
> rap:=proc(x,n::integer) local a,c,p:
a:=x: c:=n: p:=1:
while c > 0 do
if (c mod 2)=1 then p := p*a fi:
c:=iquo(c,2):
a:=a*a od:
end:
> rap(3,5);
6561
>