Sponsored links: Algebra eBooks
 

Related

rest

merge(A, B) := if len...

merge([1,2,3,4,4,8], ...

Calculate

rest

_subsets_(L, n, i) :=...

_subsets_([1,2,3,4,5]...

Calculate

rest

_subsets_(L, n, i) :=...

_subsets_([1,2,3,4,5]...

Calculate

rest

rest([3,4,5,6,2,3,2]);

Calculate

rest

rest([1,2,3,4,5], -5);

Calculate

rest

rest([1, 0, 1, 0, 0, ...

Calculate

rest

_subsets_(L, n, i) :=...

_subsets_([1,2,3,4,5]...

Calculate

rest

merge(A, B) := if len...

merge([2,4], [1,10]);

Calculate

rest

_subsets_(L, n, i) :=...

_subsets_([1,2,3,4,5]...

Calculate

rest

rest([1, 1, 0, 0, 0, ...

Calculate

rest

Run Example
(%i1)intervals(items):=block([result],  result: if (emptyp(items)) then [] else           if(listp(items)) then          if(emptyp(rest(items))) then [] else          cons(cons(first(items),  [second(items)]),          intervals(rest(items))));
(%o1) intervals(items) := block([result], 
result : if emptyp(items) then [] else (if listp(items)
 then (if emptyp(rest(items)) then [] else cons(cons(first(items), 
[second(items)]), intervals(rest(items))))))
(%i2) intervals(makelist(n, n, 1, 10));
(%o2) [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]
(%i3) intervals(makelist(n, n, 1, 11));
(%o3) [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], 
                                                             [9, 10], [10, 11]]
(%i4) ans:errcatch(find_root(sin(x), x, 2, 3));

find_root: function has same sign at endpoints: f(2.0) = 0.90929742682568, 
                                                      f(3.0) = 0.14112000805987
(%o4)                                 []
(%i5) ans;
(%o5)                                 []
(%i6) seq(start,stop,stepping,[shift]) := block([                                            n, y:[],                                             shift: (if (not(emptyp(shift)))                                                         then float(first(shift))                                                            else (0.0))                                            ],            (n:floor((float(stop-start)/float(stepping)))),            (if (start <
 stop)            then            (y:flatten(append([y],                                         makelist(float(start+shift+(stepping*(i-start))),                                         i, start, n+start))))            else            (y:flatten(append([y],                                         makelist(-(float(stop-shift-(stepping*(i-stop)))),                                         i, -(n+stop), stop)))))            (if (n>
1.0)                then return(y)                else return([])));
(%o6) seq(start, stop, stepping, [shift]) := 
block([n, y : [], shift : if not emptyp(shift) then float(first(shift))
                      float(stop - start)
 else 0.0], n : floor(-------------------), 
                        float(stepping)
if start < stop then y : flatten(append([y], 
makelist(float(start + shift + stepping (i - start)), i, start, n + start)))
 else y : flatten(append([y], makelist(- float(stop - shift
 - stepping (i - stop)), i, - (n + stop), stop)))(if n > 1.0 then return(y)
 else return([])))
(%i7) intervals(seq(0,7,1));
(%o7) [[0.0, 1.0], [1.0, 2.0], [2.0, 3.0], [3.0, 4.0], [4.0, 5.0], [5.0, 6.0], 
                                                                    [6.0, 7.0]]
(%i8) ans:[];
(%o8)                                 []
(%i9) %pi;
(%o9)                                 %pi
(%i10) %pi, numer;
(%o10)                         3.141592653589793
(%i11) 2*3.14159/%pi;
                                    6.28318
(%o11)                              -------
                                      %pi
(%i12) block([ans:[]], errormsg:false, for i in intervals(seq(0, 7, 1)) do ans:(append(ans, errcatch(find_root(sin(x), x, first(i), second(i))))), errormsg:true, return(ans));
(%o12)            [0.0, 3.141592653589793, 6.283185307179586]
(%i13) 
Run Example
seq(start,stop,stepping,[shift]) := block([                                            n, y:[],                                             shift: (if (not(emptyp(shift)))                                                         then float(first(shift))                                                            else (0.0))                                            ],            (n:floor((float(stop-start)/float(stepping)))),            (if (start <
 stop)            then            (y:flatten(append([y],                                         makelist(float(start+shift+(stepping*(i-start))),                                         i, start, n+start))))            else            (y:flatten(append([y],                                         makelist(-(float(stop-shift-(stepping*(i-stop)))),                                         i, -(n+stop), stop)))))            (if (n>
1.0)                then return(y)                else return([])));
(%o1) seq(start, stop, stepping, [shift]) := 
block([n, y : [], shift : if not emptyp(shift) then float(first(shift))
                      float(stop - start)
 else 0.0], n : floor(-------------------), 
                        float(stepping)
if start < stop then y : flatten(append([y], 
makelist(float(start + shift + stepping (i - start)), i, start, n + start)))
 else y : flatten(append([y], makelist(- float(stop - shift
 - stepping (i - stop)), i, - (n + stop), stop)))(if n > 1.0 then return(y)
 else return([])))
(%i2) kill(pairs);
(%o2)                                done
(%i3) pairs(items):=block([result],result:if (emptyp(items)) then [] elseif (listp(items)) then     if(emptyp(rest(items))) then cons(last(items), []) else    cons(cons(first(items),  [second(items)]),                     [pairs(rest(rest(items)))]));
(%o3) pairs(items) := block([result], result : 
if emptyp(items) then [] elseif listp(items)
 then (if emptyp(rest(items)) then cons(last(items), [])
 else cons(cons(first(items), [second(items)]), [pairs(rest(rest(items)))])))
(%i4) pairs([1, 2, 3, 4, 5]);
(%o4)                       [[1, 2], [[3, 4], [5]]]
(%i5) kill(pairs);
(%o5)                                done
(%i6) pairs(items):=block([result],result:if (emptyp(items)) then [] elseif (listp(items)) then     if(emptyp(rest(items))) then [last(items), []] else    cons(cons(first(items),  [second(items)]),                     [pairs(rest(rest(items)))]));
(%o6) pairs(items) := block([result], result : 
if emptyp(items) then [] elseif listp(items)
 then (if emptyp(rest(items)) then [last(items), []]
 else cons(cons(first(items), [second(items)]), [pairs(rest(rest(items)))])))
(%i7) pairs([1, 2, 3, 4, 5]);
(%o7)                     [[1, 2], [[3, 4], [5, []]]]
(%i8) first(pairs(seq(1, 10, 1)));
(%o8)                             [1.0, 2.0]
(%i9) test([list]):=map(lambda([x], [first(x), second(x)]),list);
(%o9)    test([list]) := map(lambda([x], [first(x), second(x)]), list)
(%i10) find_root(sin(x), x, 0, %pi);
(%o10)                                0.0
(%i11) 
Run Example
kill(lastdigits,pidigits, a, b);
(%o1)                                done
(%i2) ratprint:false;
(%o2)                                false
(%i3) pidigits(prec):=block([fpprec:prec+1], ratprint:false, bftorat:false, ratepsilon:2.0e-16, float2bf:false, ans:float((%pi-mod(%pi, 10^(-prec)))), return(ans));
(%o3) pidigits(prec) := block([fpprec : prec + 1], ratprint : false, 
bftorat : false, ratepsilon : 2.0E-16, float2bf : false, 
                             - prec
ans : float(%pi - mod(%pi, 10      )), return(ans))
(%i4) lastdigits(fnum, lastn):=block([m:rat(fnum), n:lastn, ans], /* it doesn't help when lastn is bigger than the total digits in fnum it returns the whole digits in fnum anyway without erroring! and fnum=%pi stuff works only upto 8 digits cause num(rat(fnum)) has somuch only! */ratprint:false, ratio(num):=block([k, a], ratprint:false, for k:1 thru fpprec do (a:10^k/ratdenom(num), if(integerp(a)) then return(a))), ratepsilon:2.0e-16, bftorat:false,  ans:mod(ratio(fnum)*num(m), (10^n))/(ratio(fnum)*denom(m)), return(float(ans)));
(%o4) lastdigits(fnum, lastn) := block([m : rat(fnum), n : lastn, ans], 
ratprint : false, ratio(num) := block([k, a], ratprint : false, 
                                 k
                               10
for k thru fpprec do (a : -------------, if integerp(a) then return(a))), 
                          ratdenom(num)
                                                                       n
                                             mod(ratio(fnum) num(m), 10 )
ratepsilon : 2.0E-16, bftorat : false, ans : ----------------------------, 
                                                 ratio(fnum) denom(m)
return(float(ans)))
(%i5) lastdigits(4.1459, 5);
(%o5)                          4.14590001103631
(%i6) lastdigits(3.1459, 3);
(%o6)                               0.0459
(%i7) b:pidigits(5);
(%o7)                               3.14159
(%i8) lastdigits(3.14159, 3);
(%o8)                               0.00159
(%i9) lastdigits(pidigits(5), 3);
(%o9)                               0.00159
(%i10) pidigits(6);
(%o10)                             3.141592
(%i11) lastdigits(pidigits(6), 3);
(%o11)                       5.9199999999999997E-4
(%i12) lastdigits(4.14592, 3);
(%o12)                              0.00592
(%i13) lastdigits(b, 3);
(%o13)                              0.00159
(%i14) a:[0, float(%pi)];
(%o14)                      [0, 3.141592653589793]
(%i15) a;
(%o15)                      [0, 3.141592653589793]
(%i16) delete(pidigits(16), a);
(%o16)                                [0]
(%i17) delete(pidigits(fpprec), a);
(%o17)                                [0]
(%i18) delete(pidigits(fpprec), [0, float(%pi)]);
(%o18)                                [0]
(%i19) intervals(items, [granul]):=block([ start:first(items), stop:last(items), ans:[], granul:(if not(emptyp(granul)) then first(granul) else 1) ], ratprint:false, if (emptyp(items)) then [] elseif(listp(items)) then    if(emptyp(rest(items))) then []     else     while(float(rat(start))<
float(rat(stop))) do    (ans:delete([],             delete([float(rat(stop)), float(rat(stop+granul))],             if(float(rat(start+granul))>
float(rat(stop)))            then return() else            append(ans, [cons(float(rat(start)),  [float(rat(start+granul))])]))),      start:float(rat(start+granul))),     return(ans));
(%o19) intervals(items, [granul]) := block([start : first(items), 
stop : last(items), ans : [], granul : 
if not emptyp(granul) then first(granul) else 1], ratprint : false, 
if emptyp(items) then [] elseif listp(items)
 then (if emptyp(rest(items)) then [] else (while float(rat(start)) < 
float(rat(stop)) do (ans : delete([], delete([float(rat(stop)), 
float(rat(stop + granul))], if float(rat(start + granul)) > float(rat(stop))
 then return() else append(ans, [cons(float(rat(start)), 
[float(rat(start + granul))])]))), start : float(rat(start + granul))))), 
return(ans))
(%i20) intervals([0, 2*%pi], %pi);
(%o20) [[0.0, 3.141592653589793], [3.141592653589793, 6.283185307179585]]
(%i21) delete(pidigits(fpprec), intervals([0, 2*%pi], %pi));
(%o21) [[0.0, 3.141592653589793], [3.141592653589793, 6.283185307179585]]
(%i22) 
[abs,append,block,emptyp,errcatch,errormsg,find_root,first,flatten,floor,if,listp,makelist,not,numer,rest,second,sin] [append,block,buildq,emptyp,ev,find_root,first,flatten,floor,kill,last,listp,makelist,not,rest,second,sin] [append,block,buildq,emptyp,find_root,first,flatten,floor,kill,last,listp,makelist,not,rest,second,sin] [append,block,cons,delete,do,emptyp,first,float,lambda,last,listp,load,makelist,numberp,ratprint,rest,return,reverse] [append,block,cons,delete,do,emptyp,first,float,last,listp,ratprint,rest,return] [append,block,cons,delete,do,emptyp,first,float,last,listp,ratprint,rest] [append,block,cons,emptyp,find_root,first,flatten,floor,if,kill,last,listp,makelist,not,rest,second,sin] [append,block,do,emptyp,errcatch,errormsg,false,find_root,first,flatten,floor,if,listp,makelist,not,rest,second,sin] [append,block,do,emptyp,errcatch,find_root,first,flatten,floor,if,last,listp,makelist,not,rest,second,sin] [append,block,emptyp,errcatch,errormsg,false,find_root,first,flatten,floor,if,listp,makelist,not,rest,second,sin] [append,block,emptyp,errcatch,errormsg,find_root,first,flatten,floor,if,listp,makelist,not,numer,rest,second,sin] [append,block,emptyp,errcatch,errormsg,find_root,first,flatten,floor,if,listp,makelist,not,rest,second,sin] [append,block,emptyp,errcatch,errormsg,first,flatten,floor,if,listp,makelist,not,rest,second,sin] [append,block,emptyp,errcatch,find_root,first,flatten,floor,if,last,listp,makelist,not,rest,second,sin] [append,block,emptyp,errcatch,find_root,first,flatten,floor,kill,last,listp,makelist,not,rest,second,sin] [append,block,emptyp,find_root,first,flatten,floor,kill,last,length,listp,makelist,not,rest,second,sin] [append,block,emptyp,find_root,first,flatten,floor,kill,last,listp,makelist,not,print,rest,second,sin] [append,block,emptyp,find_root,first,flatten,floor,kill,last,listp,makelist,not,rest,second,sin] [append,block,emptyp,first,flatten,floor,kill,lambda,last,listp,makelist,map,not,rest,second] [append,block,lambda,listify,makelist,map,primep,rest,return,setify] [append,block,listify,makelist,map,primep,rest,return,setify] [append,block,listify,makelist,primep,rest,return,setify] [append,eval,false,if,labels,lambda,quotient,rest,reverse,sum,true] [append,length,rest] [append,makelist,random,rest] [append,rest] [bftorat,block,cons,delete,do,emptyp,first,float2bf,fpprec,lambda,last,listp,map,maplist,mod,ratepsilon,ratprint,rest,return,second] [bftorat,block,cons,delete,do,emptyp,first,float2bf,fpprec,lambda,last,listp,map,maplist,mod,ratepsilon,ratprint,rest,return] [bftorat,block,cons,delete,do,emptyp,first,float2bf,fpprec,lambda,last,listp,map,mod,ratepsilon,ratprint,rest,return] [bftorat,block,cons,delete,emptyp,false,first,float2bf,fpprec,if,integerp,kill,lambda,listp,map,mod,ratdenom,ratepsilon,ratprint,rest,return] [block,compile,emptyp,first,if,kill,last,let,listp,rest,second] [block,emptyp,errcatch,find_root,first,if,last,listp,makelist,rest,second,sin] [block,emptyp,first,if,last,listp,makelist,rest,second] [block,emptyp,first,if,listp,makelist,rest,second] [block,equal,mod,print,rest] [block,first,ifactors,lambda,length,map,phi,product,rest] [col,length,matrix,matrixp,rest,row,transpose] [col,length,matrix,rest] [cons,first,length,rest] [cons,first,rest] [cons,if,lambda,length,rest,reverse] [diff,divisors,factor,listify,lreduce,map,rat,rest,resultant] [do,first,genmatrix,kill,makelist,min,ordergreatp,permanent,permutations,print,random,rest,row,sort,sum] [do,mod,print,rest] [eval,if,labels,lambda,rest,reverse,sum] [first,ifactors,lambda,map,phi,product,rest] [first,rest] [if,labels,lambda,rest,reverse,sum] [makelist,random_permutation,rest,sort] [rest]

Related Help

Help for Rest