Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

For the test I wrote such code in GAP

GenerateSubgroupListByListOfSubgroupsAndNumber := function (subgroups, number)
  local number_subgroups, subgroups_list, factor, i;

  number_subgroups := Size(subgroups);
  subgroups_list := [];

  for i in Reversed([0..number_subgroups-1]) do
    factor := Int(number / 2^i);
    number := RemInt(number, 2^i);

    if factor = 1 then
      Add(subgroups_list, subgroups[i+1], 1);
    fi;
  od;

  return subgroups_list;
end;

And SAGE equivalent

 def generate_subgroup_list_by_list_of_subgroups_and_number(subgroups, number):
  number_subgroups = len(subgroups);
  subgroups_list = []

  for i in reversed(range(0, number_subgroups)):
    factor, number = int( number / 2^i ), number % 2^i

    if factor == 1:
      subgroups_list = [subgroups[i]] + subgroups_list

  return subgroups_list

I think that code above illustrate good example of working with lists. number and etc.

And I ran following benchmarks:

GAP:

array := [1..10];
for n in [1..10000] do
  for i in [1..100] do
    GenerateSubgroupListByListOfSubgroupsAndNumber(array, i);
  od;
od;

Result:

$ time echo "Read(\"gap_benchmark.g\"); quit;" | gap -b -q -T

real    0m7.651s
user    0m7.520s
sys 0m0.056s

SAGE:

array = [1..10]
for n in [1..10000]:
  for i in [1..100]:
    generate_subgroup_list_by_list_of_subgroups_and_number(array, i)

Result:

$ time sage sage_benchmark.sage 

real    0m50.127s
user    0m49.707s
sys 0m0.268s

So, 7 seconds of GAP work vs 50 second of SAGE.

I will try to use cython with SAGE and will update this answer.

For the test I wrote such code in GAP

GenerateSubgroupListByListOfSubgroupsAndNumber := function (subgroups, number)
  local number_subgroups, subgroups_list, factor, i;

  number_subgroups := Size(subgroups);
  subgroups_list := [];

  for i in Reversed([0..number_subgroups-1]) do
    factor := Int(number / 2^i);
    number := RemInt(number, 2^i);

    if factor = 1 then
      Add(subgroups_list, subgroups[i+1], 1);
    fi;
  od;

  return subgroups_list;
end;

And SAGE equivalent

 def generate_subgroup_list_by_list_of_subgroups_and_number(subgroups, number):
  number_subgroups = len(subgroups);
  subgroups_list = []

  for i in reversed(range(0, number_subgroups)):
    factor, number = int( number / 2^i ), number % 2^i

    if factor == 1:
      subgroups_list = [subgroups[i]] + subgroups_list

  return subgroups_list

I think that code above illustrate is a good example of working with lists. number lists, numbers and etc.

And I ran following benchmarks:

GAP:

array := [1..10];
for n in [1..10000] do
  for i in [1..100] do
    GenerateSubgroupListByListOfSubgroupsAndNumber(array, i);
  od;
od;

Result:

$ time echo "Read(\"gap_benchmark.g\"); quit;" | gap -b -q -T

real    0m7.651s
user    0m7.520s
sys 0m0.056s

SAGE:

array = [1..10]
for n in [1..10000]:
  for i in [1..100]:
    generate_subgroup_list_by_list_of_subgroups_and_number(array, i)

Result:

$ time sage sage_benchmark.sage 

real    0m50.127s
user    0m49.707s
sys 0m0.268s

So, 7 seconds of GAP work vs 50 second of SAGE.

I will try to use cython with SAGE and will update this answer.