Items tagged with set set Tagged Items Feed

though swap can do this,

hope to know a simple way to shift a list or set to the left in cycle in maple

for example






  Suppose I have an array





  I would like to check if an element, e.g. "c", belong to this array. I can contrsuct a "for... end do" command to compare each element and/or construct a subroutine. 


  Is there any build-in function in maple can do that? Perferably return true/false


Thank you!

I know how we can add a member to a mathematical set ,for example :

C := NULL;

C := C, V, B, X;


V, B, X

but, my problem is that how we can subtract a member from the defined set ?





assume x,y is a real number and {x>4,y>4}, how can i get the supplementary set ({x<=4,y<=4}) of x,y in the real domain by maple?

eq:=[Vector[row](4, {(1) = 0., (2) = 0., (3) = 0., (4) = 0.}), Vector[row](4, {(1) = -0.3381778526e-2, (2) = -.3381778526, (3) = -.3185010532, (4) = 0.}), Vector[row](4, {(1) = 0., (2) = 0., (3) = 0., (4) = 0.}), Vector[row](4, {(1) = 0., (2) = 0., (3) = 0., (4) = 0.}), Vector[row](4, {(1) = 0., (2) = 0., (3) = 0., (4) = 0.})]

how i can get a unique results:[Vector[row](4, {(1) = 0., (2) = 0., (3) = 0., (4) = 0.}), Vector[row](4, {(1) = -0.3381778526e-2, (2) = -.3381778526, (3) = -.3185010532, (4) = 0.})]


The work contains two procedures called  SetPartition  and  NumbPart .

The first procedure  SetPartition  generates all the partitions of a set  S  into disjoint subsets of specific sizes defined by a list  Q. The third optional parameter is the symbol  `ordered`  or  `nonordered`  (by default) . It determines whether the order of subsets in a partition is significant.

The second procedure  NumbPart  returns the number of all partitions of the sizes indicated by  Q .


Codes of these procedures:

SetPartition:=proc(S::set, Q::list(posint), K::symbol:=nonordered)  # Procedure finds all partitions of the set  S  into subsets of the specific size given Q.

local L, P, T, S1, S2, n, i, j, m, k, M;

uses ListTools,combinat;

if `+`(op(Q))<>nops(S) then error "Should be `+`(op(Q))=nops(S)" fi;


T:=[seq([L[i],Occurrences(L[i],Q)], i=1..nops(L))];


S1:=S;  S2:={`if`(K=ordered,[],{})}; n:=nops(P);

for i to n do

m:=P[i,1]; k:=P[i,2];

for j to k do

S2:={seq(seq(`if`(K=ordered,[op(s),t],{op(s),t}), t=choose(S1 minus `union`(op(s)),m)), s=S2)};

od; od;

if K=ordered then {map(op@permute,S2)[]} else S2 fi;

end proc:


NumbPart:=proc(Q::list(posint), K::symbol:=nonordered)  # Procedure finds the number of all partitions of a set into subsets of the specific size given  Q

local L, T, P, n, S, N;

uses ListTools;


T:=[seq([L[i],Occurrences(L[i],Q)], i=1..nops(L))];


n:=nops(P);  N:=add(P[i,2], i=1..n);


if K=nonordered then return S else  S*N! fi;

end proc:


Examples of use:

SetPartition({a,b,c,d,e}, [1,1,3]);  nops(%);  # Nonordered partitions and their number

SetPartition({a,b,c,d,e}, [1,1,3], ordered);  nops(%);  # Ordered partitions and their number



Here's a more interesting example. 5 fruits  {apple, pear, orange, mango, peach}  must be put on three plates so that  on each of two plates there are 2  fruits, and there is one fruit  on one plate. Two variants to solve: 1) plates are indistinguishable and 2) different plates. In how many ways can this be done?

SetPartition({apple,pear,orange,mango,peach}, [1,2,2]);  nops(%);  # plates are indistinguishable


NumbPart([1,2,2], ordered);  # Number of ways for  different plates



Another example - how many ways can be divided  100 objects into 10 equal parts?





I paste below a simple code illustrating what I want to create: two lists from a set with pairs. I wonder it is a very simple task but I my lists aren't create in the end. 



> restart;
> lista:=[[1,10],[2,20],[3,30]]:
> x:=[]:
> y:=[]:
> for i from 1 to nops(lista) do
>     for j from 1 to 2 do
>         if j = 1 then
>             x[i,j]:=op(1,op(i,lista));
>        fi;
>        if j = 2 then
>             y[i,j]:=op(2,op(i,lista));
>       fi;
>    od;
> od;
> x;
> y;



In resume then after the for loop is terminated I want to be left with two lists:

x:= [1,2,3] and y:=[10,20,30]. I'm sure it has a quick fix but I'm stuck and would appreciate any help/advice.  

Thanks in advance!

I tried

nops({x, y, z,1+x, 2+y, -3+z,-2+x, 3+y, -1+z });

and Maple out 9.

If x = 1, y = 2, z = 3, we have

nops({1, 2, 3, 2, 4, 0, -1, 5, 2});

equal to 7.


I edited my question. The word "list" into "set".

My question means, there is a triple (x, y, z) = (1, 2, 3) so that the number of element of the set {x, y, z,1+x, 2+y, -3+z,-2+x, 3+y, -1+z } is 7, not 9. Why we can confirm the number of elements of the set {x, y, z, 1+x, 2+y, -3+z,-2+x, 3+y, -1+z } is 9? And, how must select the integer numbers x, y, z (0 < x <10, 0< y <10, 0< z < 10) so that the number of elements of the set {x, y, z, 1+x, 2+y, -3+z,-2+x, 3+y, -1+z } is 9?

I tried




for x from -2 to 5  do

for y from -2 to 5  do

for z from -2 to 5  do




if op(1,a)*op(2,a)*op(3,a)*op(1,b)*op(2,b)*op(3,b)*op(1,c)*op(2,c)*op(3,c)<> 0

and op(1,a)<>op(2,a) and  op(1,a)<>op(3,a) and  op(1,a)<>op(2,b) and  op(1,a)<>op(3,b) and  op(1,a)<>op(2,c) and  op(1,a)<>op(3,c) and op(2,a)<>op(3,a) and op(2,a)<>op(1,b) and

op(2,a)<>op(3,b) and

op(2,a)<>op(1,c) and

op(2,a)<>op(3,c) and

op(3,a)<>op(1,b) and

op(3,a)<>op(2,b) and 

op(3,a)<>op(1,c) and

op(3,a)<>op(2,c) and

op(1,b)<>op(2,b) and

op(1,b)<>op(3,b) and

op(1,b)<>op(2,c) and

op(1,b)<>op(3,c) and

op(2,b)<>op(3,b) and

op(2,b)<>op(1,c) and

op(2,b)<>op(3,c) and

op(3,b)<>op(1,c) and

op(3,b)<>op(2,c) and

op(1,c)<>op(2,c) and

op(1,c)<>op(3,c) and op(2,c)<>op(3,c) then L:=[op(L), {a,b,c}] fi; od: od: od:







I experienced strange operation of "union" for sets of vectors.

Mt1:=Matrix(2, 4, [[ 0,1, 0, 0], [ 0,  0,  1, 1]]); Ms := Vector[column](4, [8,4,2,1]); St1 := {}:

St1:= `union`(St1, {Mt1 . Ms});

I am surprised, because each execution of union adds new and the same vector <4 | 3> to set St1:


But after copying any set in the clipboard and pasting the set St1 has only one instance of vector <4 | 3>:


What does it mean?

properties of operations on sets?



is((A minus B) intersect (A minus C) = A minus (B union C)) assuming A::set, B::set, C::set;


So if I have a procedure like 


tneighbors := proc (G::Graph)

local numvertices::integer, i::integer, currentvertex;

numvertices := nops(Vertices(G));

for i to numvertices do

currentvertex := Vertices(G)[i];

if nops(Neighbors(G, currentvertex)) = 2 then print(currentvertex)

end if;

end do;

end proc;

How do I make it so the output gets returned as a set?

For example, if I do  twoneighbors(G); and get



How do I make it so the output is listed as a set like {1,4,7}? Thanks.


I would like to start with the following set of 9 elements,
A = { E11, E12, E21, E22, E11+E12, E11+E21, E12+E22, E21+E22, E11+E12+E21+E22 }.

I need a procedure that takes each of those elements and creates 3 new ones in the following way: Eij becomes Eij1, Eij2, Eij1+Eij2. So for example, E11 will become: E111, E112, and E111+E112. And for example the fifth element in A (i.e. E11+E12) will become the 3 new elements: E111+E121, E112+E122, and E111+E121 + E112+E122.

Since each of the 9 elements gets triplicated, there will be a new set, call it B, with 27 elements.

B = {E111, E112, E111+E112, E121, E122, E121+E122, ... }

Now I want to repeat this process of triplicating again so that, for example, E111 becomes: E1111, E1112, and E1111+E1112. And so on. This new set C will have 81 elements. Now I want to repeat this one last time. The final set, D, will have 243 (3^5) elements. 

Step 2: 

For every pair of elements x and y in D, I want to compute z:=(x+y)mod2. If z already belongs to D, discard it, otherwise, place z in the set D2. Do this until there are no more elements to add together (note that if x+y is computed then I don't want y+x to be computed also--that's inefficient). Maybe the most efficient way is to perform all possibly combinations of x+y mod 2 to create the set D2 and then just go: D2 setminus D.

Step 3: For x in D and y in D2 perform all possible combinations of z:=(x+y)mod2 and place these in D3 then perform set subtraction again: D3 minus D2 minus D.

Repeat this process again: x in D and y in D3 to create new elements in D4. Repeat again until Dm is empty (that is, D(m-1) will be the last set that contains new elements). I'm expecting around 12 sets... 

The issue with this whole algorithm is that I often run out of memory so I need a clever way to do this, since this algorithm is essentially classifying 2^32 elements into disjoint sets. Thank you! 

I have a large system of non-linear equations. Is there any way to get Maple to remove the duplicate equations in the system? For example Maple doesn't recognise that x-y =0 is equal to y-x=0. 

I have a set, R consisting of 9 elements:

R = {A_1, A_2, A_3, A_4, B_1, B_2, B_3, B_4, C_1}

B_1 = A_1 + A_2,
B_2 = A_1 + A_3,
B_3 = A_3 + A_4,
B_4 = A_2 + A_4,
C_1 = A_1 + A_2 + A_3 + A_4.

I want to know how to do 2 things:
1) For each element x in R I want x to become x_1, x_2, and x_3 (where x_3 = x_2 + x_1). So for example:
A_1 will become A_11, A_12, A_13 (where A_13 = A_11 + A_12). This should create a total of 27 elements (since each of the 9 elements splits into 3). I want all 27 elements to go into a new set called S_1.
2) The second thing I want is a procedure that takes x in S_1 and y in S_1 and computes z=(x+y)mod2. If z is not already an element of S_1 then put it into a new set S_2. This procedure should terminate when all the possible additions of x and y have been computed. I know that S_2 will contain 162 elements (all of which are different from the 27 elements in S_1). Then I want the procedure to take x in S_1 and y in S_2 and do the same thing: z=(x+y)mod2, where new elements not in S_1 or S_2 will be placed in S_3. Then again repeat this: x in S_1 and y in S_r until no new sets S_{r+1} can be created (i.e. S_{r+1} is empty because no new possible elements exist).

1 2 3 4 5 Page 1 of 5