> f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]
description
Transcript of > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]
![Page 1: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/1.jpg)
> f:= n -> [seq([n-k, n-k], k=0..n)];
f := n -> [seq([n - k, n - k], k = 0 .. n)]
> f(6);
[[6, 6], [5, 5], [4, 4], [3, 3], [2, 2], [1, 1], [0, 0]]
> h:= n -> [seq([n-k, k], k=0..n)];
h := n -> [seq([n - k, k], k = 0 .. n)]
> h(6);
[[6, 0], [5, 1], [4, 2], [3, 3], [2, 4], [1, 5], [0, 6]]
> {$-4..4};
{-4, -3, -2, -1, 0, 1, 2, 3, 4}
> h:= n ->[{$0..k}, k = 0..n];
h := n -> [{`$`(0 .. k)}, k = 0 .. n]
![Page 2: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/2.jpg)
> h(5);
[{$(0 .. k)}, k = 0 .. 5]
> g := x -> {$0..x};> g(5);
g := x -> {`$`(0 .. x)}
{0, 1, 2, 3, 4, 5}
> h:= n ->[g(n)];
h := n -> [g(n)]
> h(6);
[{0, 1, 2, 3, 4, 5, 6}]
> h:= n ->[g(k),k = 0..n ];
h := n -> [g(k), k = 0 .. n]
![Page 3: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/3.jpg)
> h(6);
[{$(0 .. k)}, k = 0 .. 6]
> h:= n ->[{$0..k},k = 0..n];
h := n -> [{`$`(0 .. k)}, k = 0 .. n]
> h(6);
[{$(0 .. k)}, k = 0 .. 6]> [$-4..4];
[-4, -3, -2, -1, 0, 1, 2, 3, 4]
> h := n -> [$ 0..n];
h := n -> [`$`(0 .. n)]
> h(6);
[0, 1, 2, 3, 4, 5, 6]
![Page 4: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/4.jpg)
> {$0..4};
{0, 1, 2, 3, 4}
> {$0..0};
{0}
> {$0..1};
{0, 1}> {$0..k};
{$(0 .. k)}
> A := $1..12;
A := 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
> h := n -> [seq({$0..k}, k=1..n)];
h := n -> [seq({`$`(0 .. k)}, k = 1 .. n)]
![Page 5: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/5.jpg)
> h(6);
[{0, 1}, {0, 1, 2}, {0, 1, 2, 3}, {0, 1, 2, 3, 4},
{0, 1, 2, 3, 4, 5}, {0, 1, 2, 3, 4, 5, 6}]> g:= x ->{$0..x}; g := x -> {`$`(0 .. x)}
> g(5); {0, 1, 2, 3, 4, 5}> s:n ->[seq([g(k)], k = 0..n)]; n -> [seq([g(k)], k = 0 .. n)]
> s(5); s(5)> map(abs, [-1, 3, -32, 4]);
[1, 3, 32, 4]> map(abs, {1, -1, 2, -2});
{1, 2}> map(abs, [1, -1, 2, -2]); [1, 1, 2, 2]>map(f, (1, 2, 3)); 6> map(f, {1, 2, 3}, 0, 0); {1, 4, 9}
![Page 6: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/6.jpg)
•The map2 function is similar to map, except that for each operand of expr, arg1 is passed as the first argument to fcn, the operand of expr is passed as the second argument, and arg3, ..., argn are passed as the third, ..., nth arguments.
> map2(k, m, {a,b,c});
{k(m, a), k(m, b), k(m, c)}
2.3A := [a, a, b, b, b]; B := [b, c];
hd := x -> x[1]; // all in section 1> hd(A);
> map(hd,[a, b], [a, b, c], [b, d]);
[a[1], b[1]]
> map(hd,[a, b]);
[a[1], b[1]]
![Page 7: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/7.jpg)
C:=[a, b]; C := [a, b]> map(hd,C); [a[1], b[1]]
> hd(C);
a> map(hd,C); [a[1], b[1]]
> map(hd,([a, b])); [a[1], b[1]]
> map(hd,{[a, b]}); {a}
> map(hd,[[a, b]]); [a]
>
![Page 8: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/8.jpg)
map(tl2,[[a, b]]); # again in section 1 page 14
[[b]]> map(tl2,[[a, b]]);
[[b]]
> map(tl2,[a, b]);
[a[2 .. 1], b[2 .. 1]]
> map(tl2,[[a, b,c,d]]);
[[b, c, d]]> map(tl2,[[a, b,c,d],B]);
![Page 9: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/9.jpg)
2.3
• > C:=[a, b, c,d];
• C := [a, b, c, d]
• tl2 := x -> x[2..nops(x)];• tl2 := x -> x[2 .. nops(x)]
• catLists := (x, y) -> [op(x), op(y)];• catLists := (x, y) -> [op(x), op(y)]
• > catLists([1,2,3,4],[3,4,5]);
• [1, 2, 3, 4, 3, 4, 5]
![Page 10: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/10.jpg)
•> •> catLists(hd(C), tl2(C));
• [a, b, c, d]•cons := catLists;• cons := catLists
•> g:=x -> (hd(x), tl2(x));
• g := x -> (hd(x), tl2(x))
•> g([1,2,3,4]);
• 1, [2, 3, 4]
•> h := cons@g;
• h := catLists@g
•> h([1,2,3,4]);
• [1, 2, 3, 4] •> evalb(h(C) = C);
• true
![Page 11: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/11.jpg)
2.8
• f:=x->1/(x+1);• 1• f := x -> -----• x + 1• solve(f(x) = f(y), x);• y• > solve(f(x) = y, x);• -1 + y• - ------• y• > f(%);
• 1• ------------• -1 + y• - ------ + 1• y
![Page 12: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/12.jpg)
•> simplify(%);
• y
![Page 13: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/13.jpg)
3.1.2
> tl := x ->x[2..nops(x)]; > last := x -> if nops(x) = 1 then x else last(tl(x)) fi;
![Page 14: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/14.jpg)
3.7
> cons := (x, S) -> [x, op(S)];
cons := (x, S) -> [x, op(S)]
> cons(b,[a, b, c]);
[b, a, b, c]
> cons(d,[a, b, c]);
[d, a, b, c]
![Page 15: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/15.jpg)
> concat := (x, y) -> if x = [ ] then y else cons(hd(x), concat(tl(x), y)) fi;
concat := proc(x, y)option operator, arrow; if x = [] then y else cons(hd(x), concat(tl(x), y)) end ifend proc
> trace(concat); concat
![Page 16: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/16.jpg)
> concat([a, b, c], [d, e]);{--> enter concat, args = [a, b, c], [d, e]{--> enter concat, args = [b, c], [d, e]{--> enter concat, args = [c], [d, e]{--> enter concat, args = [], [d, e]
<-- exit concat (now in concat) = [d, e]}
<-- exit concat (now in concat) = [c, d, e]}
<-- exit concat (now in concat) = [b, c, d, e]}
<-- exit concat (now at top level) = [a, b, c, d, e]}
![Page 17: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/17.jpg)
3.7.1 Recursive way
hd:= x -> x[1]; hd := x -> x[1]
> tl := x ->x[2..nops(x)];
tl := x -> x[2 .. nops(x)]
> subset:=(x,y)->if x = {} then true> else member(hd(x),y) and subset (tl(x),y)> fi;> > A := {a,b,c,d,e}; A := {a, b, c, d, e}> B := {e,z}; B := {e, z}> C:= {a,b}; C := {a, b}
![Page 18: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/18.jpg)
> B := {e,z};
B := {e, z}> C:= {a,b};
C := {a, b}> subset(C,A);
true
> subset(B,A);
false
> subset({},A);
true
> subset(A,C);
false
![Page 19: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/19.jpg)
3.7.1 Non recursive version
subset:=(x,y)->if `intersect`(x,y) =x then print(yes) else print(no)fi;
subset := proc(x, y)option operator, arrow; if x intersect y = x then print(yes) else print(no) end ifend proc
> subset({d,e},{a,b,c});
no
> subset({a,b},{a,b,c});
yes
![Page 20: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/20.jpg)
3.7.2
• subset1:=(x,y)->if x = {} then true else if evalb(hd(x) in y) then subset1(tl(x),y) else false fi fi;
•power:=x->if x = {} then {{}}
• else power(tl(x)) union map(`union`,power(tl(x)),{hd(x)})fi;
![Page 21: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/21.jpg)
5.1.4.b
• > sum(a[n+2]*x^n, n = 0..k);• > sum(a[n]*x^(n-2), n = 2..k+2);• > simplify(sum(a[n+2]*x^n, n = 0..k));• > evalb(simplify(sum(a[n+2]*x^n, n = 0..k))=
simplify(sum(a[n]*x^(n-2), n = 2..k+2)));– False;
• > sum('a[n+2]*x^n','n'=0..4);• > a[2]+a[3]*x+a[4]*x^2+a[5]*x^3+a[6]*x^4• > sum('a[n]*x^(n-2)','n'=2..6);• > a[2]+a[3]*x+a[4]*x^2+a[5]*x^3+a[6]*x^4
• > evalb(sum('a[n+2]*x^n','n'=0..4) = sum('a[n]*x^(n-2)','n'=2..6));• true
![Page 22: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/22.jpg)
> evalb(sum('a[n+2]*x^n','n'=0..k) = sum('a[n]*x^(n-2)','n'=2..(k+2) ));false.
WHY????????????
![Page 23: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/23.jpg)
5.2
permute({a, b, c}); [[a, b, c], [a, c, b], [b, a, c], [b, c, a], [c, a, b], [c, b, a]]> > permute([r, a, d, a, r]);
[[r, a, d, a, r], [r, a, d, r, a], [r, a, a, d, r], [r, a, a, r, d],
[r, a, r, d, a], [r, a, r, a, d], [r, d, a, a, r],
[r, d, a, r, a], [r, d, r, a, a], [r, r, a, d, a],
[r, r, a, a, d], [r, r, d, a, a], [a, r, d, a, r],
![Page 24: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/24.jpg)
[a, r, d, r, a], [a, r, a, d, r], [a, r, a, r, d],
[a, r, r, d, a], [a, r, r, a, d], [a, d, r, a, r],
[a, d, r, r, a], [a, d, a, r, r], [a, a, r, d, r],
[a, a, r, r, d], [a, a, d, r, r], [d, r, a, a, r],
[d, r, a, r, a], [d, r, r, a, a], [d, a, r, a, r],
[d, a, r, r, a], [d, a, a, r, r]]
![Page 25: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/25.jpg)
n:=2;numbcomb(n,n/2); n := 2> n:=3;numbcomb(n,n/2);
n := 3
Error, (in numbcomb) 2nd argument must be an integer> n:=4;numbcomb(n,n/2); n := 4 6n:=6;numbcomb(n,n/2); n := 6 20> numbcomb(8,4); 70
5.2.3
![Page 26: > f:= n -> [seq([n-k, n-k], k=0..n)]; f := n -> [seq([n - k, n - k], k = 0 .. n)]](https://reader036.fdocuments.us/reader036/viewer/2022081418/5681451f550346895db1e077/html5/thumbnails/26.jpg)
binomial(m, k); binomial(m, k)> m:=6; k:=2; m := 6 k := 2evalb(binomial(m, k)=binomial(m-1, k)+binomial(m-1, k-1)); true
5.3.2