Sponsored links: Algebra eBooks
 

Related

subvar

Run Example
(%i1)P (s1,s2,s3,s4,s5) := block ( [tot: s1+s2+s3+s4+s5] , s1/tot*(if (s1>
1) then P (s1-1,s2,s3,s4,s5) else 1)+(if s2<
=1 then 0 else P (s1,s2-1,s3,s4,s5)*s2/tot)+(if s3<
=1 then 0 else P (s1,s2,s3-1,s4,s5)*s3/tot)+(if s4<
=1 then 0 else P (s1,s2,s3,s4-1,s5)*s4/tot)+(if s5<
=1 then 0 else P (s1,s2,s3,s4,s5-1)*s5/tot) );
(%o1) P(s1, s2, s3, s4, s5) := block([tot : s1 + s2 + s3 + s4 + s5], 
s1
--- (if s1 > 1 then P(s1 - 1, s2, s3, s4, s5) else 1)
tot
                           P(s1, s2 - 1, s3, s4, s5) s2
 + (if s2 <= 1 then 0 else ----------------------------)
                                       tot
                           P(s1, s2, s3 - 1, s4, s5) s3
 + (if s3 <= 1 then 0 else ----------------------------)
                                       tot
                           P(s1, s2, s3, s4 - 1, s5) s4
 + (if s4 <= 1 then 0 else ----------------------------)
                                       tot
                           P(s1, s2, s3, s4, s5 - 1) s5
 + (if s5 <= 1 then 0 else ----------------------------))
                                       tot
(%i2) foo[sort([3,5,1,5,1])]:42;
(%o2)                                 42
(%i3) if foo[sort([3,5,0,5,1])]>
0 then foo[sort([3,5,1,5,1])]+12 else 12;
(%o3) if foo                > 0 then foo                      + 12 else 12
            [0, 1, 3, 5, 5]             sort([3, 5, 1, 5, 1])
(%i4) subvar(foo,sort([3,5,1,5,1]));
(%o4)                                 42
(%i5) arrayinfo(foo);
(%o5)                   [hashed, 1, [[1, 1, 3, 5, 5]]]
(%i6) 
Run Example
P (s1,s2,s3,s4,s5) := block ( [tot: s1+s2+s3+s4+s5] , s1/tot*(if (s1>
1) then P (s1-1,s2,s3,s4,s5) else 1)+(if s2<
=1 then 0 else P (s1,s2-1,s3,s4,s5)*s2/tot)+(if s3<
=1 then 0 else P (s1,s2,s3-1,s4,s5)*s3/tot)+(if s4<
=1 then 0 else P (s1,s2,s3,s4-1,s5)*s4/tot)+(if s5<
=1 then 0 else P (s1,s2,s3,s4,s5-1)*s5/tot) );
(%o1) P(s1, s2, s3, s4, s5) := block([tot : s1 + s2 + s3 + s4 + s5], 
s1
--- (if s1 > 1 then P(s1 - 1, s2, s3, s4, s5) else 1)
tot
                           P(s1, s2 - 1, s3, s4, s5) s2
 + (if s2 <= 1 then 0 else ----------------------------)
                                       tot
                           P(s1, s2, s3 - 1, s4, s5) s3
 + (if s3 <= 1 then 0 else ----------------------------)
                                       tot
                           P(s1, s2, s3, s4 - 1, s5) s4
 + (if s4 <= 1 then 0 else ----------------------------)
                                       tot
                           P(s1, s2, s3, s4, s5 - 1) s5
 + (if s5 <= 1 then 0 else ----------------------------))
                                       tot
(%i2) foo[sort([3,5,1,5,1])]:42;
(%o2)                                 42
(%i3) if foo[sort([3,5,0,5,1])]>
0 then foo[sort([3,5,1,5,1])]+12 else 12;
(%o3) if foo                > 0 then foo                      + 12 else 12
            [0, 1, 3, 5, 5]             sort([3, 5, 1, 5, 1])
(%i4) subvar(foo,sort([3,5,e,5,1]));
(%o4)                         foo
                                 [1, 3, 5, 5, e]
(%i5) arrayinfo(foo);
(%o5)                   [hashed, 1, [[1, 1, 3, 5, 5]]]
(%i6) 
Run Example
? subvar;

 -- Function: subvar (<x>, <i>)
     Evaluates the subscripted expression `<x>[<i>]'.

     `subvar' evaluates its arguments.

     `arraymake (<x>, [<i>]' constructs the expression `<x>[<i>]', but
     does not evaluate it.

     Examples:

          (%i1) x : foo $
          (%i2) i : 3 $
          (%i3) subvar (x, i);
          (%o3)                         foo
                                           3
          (%i4) foo : [aa, bb, cc, dd, ee]$
          (%i5) subvar (x, i);
          (%o5)                          cc
          (%i6) arraymake (x, [i]);
          (%o6)                         foo
                                           3
          (%i7) ''%;
          (%o7)                          cc


  There are also some inexact matches for `subvar'.
  Try `?? subvar' to see them.

(%o1)                                true
(%i2) 

Related Help

Help for Subvar