Sponsored links: Algebra eBooks
 

Related

xreduce

Run Example
(%i1)modulus:2;
(%o1)                                  2
(%i2)  N:2;
(%o2)                                  2
(%i3)   block( P:0, Vars:[], Sol:zeromatrix(N,N), for i: 1 thru N do ( for j: 1 thru N do ( S:zeromatrix(N+2,N+2), S[i ][j ]:1, S[i ][j+1]:1,  S[i ][j+2]:1, S[i+1][j ]:1, S[i+1][j+2]:1, S[i+2][j ]:1, S[i+2][j+1]:1, S[i+2][j+2]:1, S:submatrix (1,N+2,S,1,N+2), P:P+V[i*N+j]*S, Vars: append(Vars, [V[i*N+j]]), Sol[i][j]:V[i*N+j]) ) );
(%o3)                                done
(%i4)  P;
                        [ V  + V  + V   V  + V  + V  ]
                        [  6    5    4   6    5    3 ]
(%o4)                   [                            ]
                        [ V  + V  + V   V  + V  + V  ]
                        [  6    4    3   5    4    3 ]
(%i5)  Vars;
(%o5)                          [V , V , V , V ]
                                 3   4   5   6
(%i6)  R:zeromatrix(N,N)+1;
                                   [ 1  1 ]
(%o6)                              [      ]
                                   [ 1  1 ]
(%i7)  LGS:xreduce('append ,args(P-R));
(%o7) [V  + V  + V  - 1, V  + V  + V  - 1, V  + V  + V  - 1, V  + V  + V  - 1]
        6    5    4       6    5    3       6    4    3       5    4    3
(%i8)  Res:algsys(LGS, Vars);
(%o8)                 [[V  = 1, V  = 1, V  = 1, V  = 1]]
                         3       4       5       6
(%i9)  append([l=Sol],Res[1]);
                    [ V   V  ]
                    [  3   4 ]
(%o9)          [l = [        ], V  = 1, V  = 1, V  = 1, V  = 1]
                    [ V   V  ]   3       4       5       6
                    [  5   6 ]
(%i10) 
Run Example
srt[s1,s2,s3,s4,s5] := cons(s1, sort([s2,s3,s4,s5]));
(%o1)      srt                   := cons(s1, sort([s2, s3, s4, s5]))
              s1, s2, s3, s4, s5
(%i2) P [s1,s2,s3,s4,s5] := block ( [tot: s1+s2+s3+s4+s5, sfd :xreduce('gcd,[s1,s2,s3,s4,s5])] , if (sfd>
1) then P[s1/sfd,s2/sfd,s3/sfd,s4/sfd,s5/sfd] else s1/tot*(if (s1>
1) then arrayapply(P, srt[s1-1,s2,s3,s4,s5]) else 1)+(if s2<
=1 then 0 else arrayapply(P, srt[s1,s2-1,s3,s4,s5])*s2/tot)+(if s3<
=1 then 0 else arrayapply(P, srt[s1,s2,s3-1,s4,s5])*s3/tot)+(if s4<
=1 then 0 else arrayapply(P, srt[s1,s2,s3,s4-1,s5])*s4/tot)+(if s5<
=1 then 0 else arrayapply(P, srt[s1,s2,s3,s4,s5-1])*s5/tot) );
(%o2) P                   := block([tot : s1 + s2 + s3 + s4 + s5, 
       s1, s2, s3, s4, s5
sfd : xreduce('gcd, [s1, s2, s3, s4, s5])], 
if sfd > 1 then P
                 s1/sfd, s2/sfd, s3/sfd, s4/sfd, s5/sfd
      s1
 else --- (if s1 > 1 then arrayapply(P, srt                      ) else 1)
      tot                                  s1 - 1, s2, s3, s4, s5
                           arrayapply(P, srt                      ) s2
                                            s1, s2 - 1, s3, s4, s5
 + (if s2 <= 1 then 0 else -------------------------------------------)
                                               tot
                           arrayapply(P, srt                      ) s3
                                            s1, s2, s3 - 1, s4, s5
 + (if s3 <= 1 then 0 else -------------------------------------------)
                                               tot
                           arrayapply(P, srt                      ) s4
                                            s1, s2, s3, s4 - 1, s5
 + (if s4 <= 1 then 0 else -------------------------------------------)
                                               tot
                           arrayapply(P, srt                      ) s5
                                            s1, s2, s3, s4, s5 - 1
 + (if s5 <= 1 then 0 else -------------------------------------------))
                                               tot
(%i3)  f ([u]) := u;
(%o3)                             f([u]) := u
(%i4) arrgcd(arr):= xreduce('gcd, arr)  ;
(%o4)                  arrgcd(arr) := xreduce('gcd, arr)
(%i5)                        arrgcd ([12,9,3]);
(%o5)                                  3
(%i6)            f (a, b, [u]) := [a, b, u];
(%o6)                      f(a, b, [u]) := [a, b, u]
(%i7)  f (1, 2, 3, 4, 5, 6);
(%o7)                        [1, 2, [3, 4, 5, 6]]
(%i8)  f (1, 2, 3, 4);
(%o8)                           [1, 2, [3, 4]]
(%i9) udskriv (n) := [n,n*100.0];
(%o9)                     udskriv(n) := [n, n 100.0]
(%i10) udskriv(P[12,8,12,12,12]);
                            527
(%o10)                     [----, 17.11038961038961]
                            3080
(%i11) 
Run Example
modulus:2;
(%o1)                                  2
(%i2)  N:4;
(%o2)                                  4
(%i3)   block( P:0, Vars:[], Sol:zeromatrix(N,N), for i: 1 thru N do ( for j: 1 thru N do ( S:zeromatrix(N+2,N+2), S[i ][j ]:1, S[i ][j+1]:1,  S[i ][j+2]:1, S[i+1][j ]:1, S[i+1][j+2]:1, S[i+2][j ]:1, S[i+2][j+1]:1, S[i+2][j+2]:1, S:submatrix (1,N+2,S,1,N+2), P:P+V[i*N+j]*S, Vars: append(Vars, [V[i*N+j]]), Sol[i][j]:V[i*N+j]) ) ,  R:zeromatrix(N,N)+1, LGS:xreduce('append ,args(P-R)), globalsolve:%true, solve(LGS, Vars),   Sol:zeromatrix(N,N), for i: 1 thru N do ( for j: 1 thru N do (Sol[i][j]:V[i*N+j]) ) );

solve: dependent equations eliminated: (16 13 10 14)
(%o3)                                done
(%i4)   Sol;
               [ %r4 + %r3 - %r2 + %r1 + 1 ]         [   - %r4 - %r1   ]
               [                           ]         [                 ]
               [      - %r2 + %r1 + 1      ]         [    %r4 + %r2    ]
(%o4)  Col 1 = [                           ] Col 2 = [                 ]
               [            %r4            ]         [       %r3       ]
               [                           ]         [                 ]
               [          %r1 - 1          ]         [ - %r4 - %r3 + 1 ]
                      [ - %r3 - %r2 + %r1 + 1 ]         [       1 - %r3       ]
                      [                       ]         [                     ]
                      [          %r1          ]         [      %r3 + %r2      ]
              Col 3 = [                       ] Col 4 = [                     ]
                      [ %r4 + %r3 + %r2 - %r1 ]         [ %r4 + %r3 - %r1 - 1 ]
                      [                       ]         [                     ]
                      [          %r2          ]         [   - %r4 - %r2 + 1   ]
(%i5) 

Related Help

Help for Xreduce