I want define new graph in sage. Let G be finite group. The graph's vertices are subgroup and two vertices are adjacent if and only if sum of two subgroup is G.
I have trouble with define this graph in sage. Any suggestion?
I have idea in gap but I don't have idea what can I change in sage?
Summands := function(G)
local n, i, sgl, l, A, B, D;
obtain a list of all subgroups
sgl := List(LatticeSubgroups(G)!.conjugacyClassesSubgroups, Representative);
n is the number of divisors of |G|
n := Size(DivisorsInt(Size(G)));
D := [];
if IsOddInt(n) then l := QuoInt(n + 1, 2);
else l := QuoInt(n, 2);
fi;
for i in [1..l] do
for A in Filtered(sgl, function(g) return Size(g) = DivisorsInt(Size(G))[i]; end) do
for B in Filtered(sgl, function(g) return Size(g) = DivisorsInt(Size(G))[n+1-i]; end) do
Add(D, [A, B]);
od;
od;
od;
return D;
end;
Here are Sage equivalents to some of these commands. Incidentally, we use GAP for the group calculations!
sage: D = DihedralGroup(5)
sage: D.subgroups()
[Permutation Group with generators [()], Permutation Group with generators [(2,5)(3,4)], Permutation Group with generators [(1,2)(3,5)], Permutation Group with generators [(1,3)(4,5)], Permutation Group with generators [(1,4)(2,3)], Permutation Group with generators [(1,5)(2,4)], Permutation Group with generators [(1,2,3,4,5)], Permutation Group with generators [(1,5,4,3,2), (1,5)(2,4)]]
sage: divisors(D.cardinality())
[1, 2, 5, 10]
To make graphs in Sage, you can pass dictionaries of lists or other things; see
sage: Graph?
for more information on that.
Edit - left in to make comments comprehensible:
By the way, it looks like you are trying to make a list of pairs of subgroups A and B such that |A||B|=ord(G). Is that necessarily the same as groups whose sum (whatever you mean by that - direct sum?) is the original group? I'm thinking for instance of even a group of order four; summing any two subgroups of order two may not be isomorphic to the original group - for instance, if the two subgroups are the same one if you mean some sort of ambient sum (does this even make sense?), or if you use direct sum but the group is the cyclic group of order 4, not the Klein four group.
Related
I'm trying to learn how match_vertices works in igraph so that I can use it to join node and attribute information from graphs generated by a few different black box computer programs. I tried looking at the single provided example, but it was too complicated for me to understand. So, I tried to throw together an even simpler toy example which I am trying to understand.
library(igraph)
bow = make_graph(~ A - B - C - A - D - E - A)
tie = make_graph(~ a - e - d - a - c - b - a)
isomorphic(bow, tie)
It looks to me like the code should be:
A = get.adjacency(bow)
B = get.adjacency(tie)
P0 = diag(nrow(A))
corr = match_vertices(A, B,
start = P0,
m = 0,
iteration = 30)
corr$P
The permutation matrix didn't seem to change. The resulting permutation matrix is the same as the
starting permutation matrix. Why is that?
I defined a random permutation matrix and repeated the exercise to
see if that was always the case. It was!
random_permutation = function(n, ...) {
P = diag(n)
i = sample(1:n, ...)
P[i,,drop=FALSE]
}
Can anyone recommend some simple toy examples of using match_vertices that
demonstrate its main features?
show how to approximately match two graphs
show how to approximately match two graphs when some vertices are known
show how to approximately match two graphs when they have different
numbers of vertices
Also, are there any ways of matching graphs if even if the seeds aren't known
a priori, the nodes have maximally consistent attributes?
Assume we have a Venn diagram of two circles. We have to find the union, intersection and the product of them. For example we have sets:
A=[a,b,f,g]
B=[b,e,f,h]
Union
AUB=[a,b,e,f,g,h]
Intersection
A∩B = [f,g]
Product
A*B=[ab, ae, af, ah, bb, be, bf, bh, fb, fe, ff, fh, gb, ge, gf, gh]
My question is, how do we write these operations in Pseudocode? I don't know how to do it.
A union B:
C := empty set
for each a in A:
C.add(a)
for each b in B:
if not C.contains(b) then C.add(b)
This has quadratic runtime if implemented using lists/arrays. It has linear runtime if using a hash table/dictionary.
A intersect B:
C := empty set
for each a in A:
if B.contains(a) then C.add(a)
Same performance as union.
A x B:
C := empty set
for each a in A:
for each b in B:
C.add((a,b))
This has quadratic runtime but that is unavoidable since the returned result contains on the order of n^2 elements.
Let f be a continuous real function defined on the interval [a,b]. I want to aproximate this function by a piecewise quadratic polynomial. I already created a matrix that summarizes these polynomials. Let's say that I'm considering a uniform partition of the interval into N pieces ( therefore N+1 points).
I have a matrix A of size N times 3, where the k row represents the quadratic polynomial associated with the k-interval of this partition in the natural form ( the row [a b c] represents the polynomial a+bx+cx^2). I already created a method to find this matrix (obviously it depends on the choice of my interpolation points inside of each interval but that it doesn't matter for this question).
I'm trying to plot the corresponding function but I'm having some problems. I used the same idea given in Similar question. This is what I wrote
x=zeros(N+1,1);
%this is the set of points defining the uniform partition
for i=1:N+1
x(i)=a+(i-1)*((b-a)/(N));
end
%this is the length of my linspace for plotting the functions
l=100
And now I plot the functions:
figure;
hold on;
%first the original function
u=linspace(a,b,l*N);
v=arrayfun( f , u);
plot(u,v,'b')
% this is for plotting the other functions
for k=1:N
x0=linspace(x(k),x(k+1));
y0=arrayfun(#(t) [1,t,t^2]*A(k,:)',x0);
plot(x0, y0, 'r');
end
The problem is that the for is plotting the same function f and I don't know why. I tried with multiple different functions. I'm pretty sure that my matrix A is correct.
Please write a minimal working example that can be run as standalone code or copy/pasted from people here to check where you might have a bug -- often in the process of reducing your code to its bare principles in this manner, you end up figuring out what is the problem yourself in the first place. But, in any case, I have written one myself and cannot replicate the problem.
figure;
hold on;
# arbitrary values for Minimal Working Example
N = 10;
x = [10:10:110]; # (N+1, 1)
A = randn( N, 3 ); # (3 , N)
a = 100; b = 200; l = 3;
f = #(t) t.^2 .* sin(t);
%first the original function
u = linspace(a,b,l*N);
v = arrayfun( f , u);
plot(u,v,'b')
for k = 1 : N
x0 = linspace( x(k), x(k+1) )
y0 = arrayfun( #(t) ([1, t, t.^2]) * (A(k, :).'), x0 )
x0, y0
plot(x0, y0, 'r');
endfor
hold off;
Output:
Are you doing something different?
Can anyone figure out a function that can perform a mapping from a finite set of N numbers X = {x0, x1, x2, ..., xN} where each x can be valued 0 to 999999999 and N < 999999999, to a set Y = {0, 1, 2, 3, ..., N}.
In my case, i have about 24000000 element in the first set whose values can range as X. This elements have continuous block (for example 53000 to 1234500, then 8000000 to 9000000 and so on) and i have to remap this elements from 0 to 2400000. I don't require to maintain order.
I need a (possibly simple and rapid) math function, or a bitwise transformation, not something like put it ordered into an array and then binary search for their position.
Really thank to whom that can figure out a way to solve this!
Luca
If you don't want to keep some gigabytes of straight map, then augmented segment tree is reasonable approach. Tree should contain intervals and shift of every interval (sum of left intervals). Of course, finding appropriate interval (and shift) in this method is close to the binary search.
For example, you get X=80000015. Find interval for this value - it is 8000000 to 9000000. Rank of this interval is 175501 (1234500-53000 + 1). So X maps to
X => 175501 + 80000015 - 80000000 = 175516
For sparse elements make counting stage - find what is rank R for every number M and put (key=M, value=R) pair in hash table.
X = (3, 19, 20, 101)
table: [(3:0), (19:1), (20:2), (101:3)]
Note that one should keep balance between speed and space - for long filled intervals it is better to store only interval ends.
Suppose each student has x enemies. We need to form groups in a class of 100 students such that no enemies are in the same group. Find the minimum number of groups needed in the worst case for x=1,2,3. How to proceed with this question ?
Consider a graph with vertices representing students and edges representing whether the two students are enemies.
A graph where each vertex has k adjacent vertices is called a k-regular graph.
The necessary and sufficient conditions for a k-regular graph of order n to exist are that k < n and that n*k is even.
Dividing the vertices of a graph into groups such that no two vertices in a group are adjacent is called vertex coloring, and the smallest number of such groups is called the chromatic number of the graph.
So, your problem can be stated as follows: Given two integers n and k < n, find the maximum chromatic number of a k-regular graph with n vertices.
To solve this, the Brooks' theorem can be used:
In a connected graph in which every vertex has at most Δ neighbors,
the vertices can be colored with only Δ colors, except for two cases,
complete graphs and cycle graphs of odd length, which require Δ + 1
colors.