Ask Your Question
1

How to draw a graph in Sage and read GAP file added to the same project

asked 2020-10-12 21:46:24 +0100

Buddhiang gravatar image

updated 2020-10-13 07:25:11 +0100

I have created a project in CoCalc with the kernel SageMath. There I have opened a new file (New1) and did some computations using the GAP commands, and "gap.eval" before each command enabled me to obtain the results successfully.

Question 1: Next by using some values obtained as a result of the GAP commands, if I need to plot a graph what is the command I will have to use, which will read GAP data successfully? (The output is in the form [[1,2],[1,3],[2,5],...], as an array)

Question 2: I have written another function(Program1) in GAP file and have uploaded it to the same Project. I would like to call this function to the file New1, where I have been working and use it. How can I call it succesfully?

I tried %run Program1.gap , but it didn't work.

The section of the program relevant to Question 2:

When I try to run the .gap file I get the below error, %run UndirectedGeneratingSets.gap

File "/home/user/UndirectedGeneratingSets.gap", line 9
IsIrredundant := function(G,S)
               ^
 SyntaxError: invalid syntax

I added gap.eval command to places where there are commands and updated the .gap file but still I am getting errors as below.

%run UndirectedGeneratingSetsedited.gap  

File "/home/user/UndirectedGeneratingSetsedited.gap", line 12
gap.eval("return ForAll(S, s -> not(s in Subgroup(G, Filtered(S, t -> (t <> s)))));
                                                                                   ^
SyntaxError: EOL while scanning string literal

I don't know why it says as syntax error. I have closed all the brackets in the code as below:

gap.eval("return ForAll(S, s -> not(s in Subgroup(G, Filtered(S, t -> (t <> s)))));
end;")

 gap.eval("IrredGenSetsFromAvailable := function(G, GensRequired, GensAvailable)")
# return a list of the irredundant generating sets of G that contain the set GensRequired
# and are contained in the union of GensRequired and GensAvailable
# (It is assumed that GensRequired is irredundant)
local GenSets, i, S;
gap.eval("GenSets := [];") # GenSets is a list of the generating sets that have been constructed so far
gap.eval("if Subgroup(G, GensRequired) = G then
    # do not add any additional generators
    return [AsSortedList(GensRequired)];
else
    # for each available generator, recursively find all irredundant generating sets
    # that can be obtained by adding it (and perhaps later elements of GensAvailable)
    # to GensRequired
    for i in [1..Length(GensAvailable)] do
        S := Concatenation(GensRequired, [GensAvailable[i]]);
        if IsIrredundant(G,S) then
            Append(GenSets, IrredGenSetsFromAvailable(G, S,
                    GensAvailable{[i+1 .. Length(GensAvailable)]}));
        fi;
    od;
fi;
return GenSets;
 end;")

and similarly for the rest of the codes in that program as well.

Many many thanks in advance.

edit retag flag offensive close merge delete

Comments

Can you reduce your problem to the simplest possible setup and post actual commands?

slelievre gravatar imageslelievre ( 2020-10-12 23:07:52 +0100 )edit

Thanks a lot, @slelievre , I edited the question by adding the relevant section of the codes.

Buddhiang gravatar imageBuddhiang ( 2020-10-13 07:24:43 +0100 )edit
1

For the plot, something like this

sage: G = gap('[[1,2],[1,3],[2,5]]')                                            
sage: scatter_plot(G.sage())
FrédéricC gravatar imageFrédéricC ( 2020-10-14 08:36:49 +0100 )edit

Thank you very much @FrédéricC can I create the plot such that there will be an edge between 1 and 2 points, 1 and 3 points, 2 and 5 points, and so on?

Buddhiang gravatar imageBuddhiang ( 2020-10-15 09:00:02 +0100 )edit
1

Well, like this maybe

sage: G = gap('[[1,2],[1,3],[2,5]]')                                            
sage: Graph(G.sage(),format='list_of_edges').plot()
FrédéricC gravatar imageFrédéricC ( 2020-10-15 13:34:01 +0100 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2020-10-14 01:08:38 +0100

slelievre gravatar image

updated 2020-10-15 11:45:30 +0100

Regarding this:

%run UndirectedGeneratingSetsedited.gap  

File "/home/user/UndirectedGeneratingSetsedited.gap", line 12
gap.eval("return ForAll(S, s -> not(s in Subgroup(G, Filtered(S, t -> (t <> s)))));
                                                                                   ^
SyntaxError: EOL while scanning string literal

This error means that while parsing your code, there was an opening quote signalling the beginning of a string, but by the end of the line no closing quote was found.

The thing is, you put a newline inside a string delimited by " ... ".

Instead, either remove the newline, or use triple quotes: ''' ... ''' or """ ... """.

Also, consider using libgap.eval instead of gap.eval.

edit flag offensive delete link more

Comments

Thank you very much @slelievre I am now receiving the error:

%run UndirectedGeneratingSetsedited.gap 

 ---------------------------------------------------------------------------

  NameError                                 Traceback (most recent call last)

  /home/user/UndirectedGeneratingSetsedited.gap in <module>()

  7 #        http://hdl.handle.net/10133/4996

  8 

 ----> 9 gap.eval("""IsIrredundant := function(G,S)

 10         # return true if S is irredundant, which means that no element of S is in

 11         # the subgroup generated by the others

 NameError: name 'gap' is not defined

saying that name gap is not defined. What remedy can be done for it? Thanks a lot in advance.

Buddhiang gravatar imageBuddhiang ( 2020-10-15 08:55:51 +0100 )edit

Use libgap instead of gap?

slelievre gravatar imageslelievre ( 2020-10-15 11:45:47 +0100 )edit

Thanks a lot @slelievre I tried with that and checked. Then I receive the following error..

%run UndirectedGeneratingSetsedited.gap 

---------------------------------------------------------------------------

NameError                                 Traceback (most recent call last)

   /home/user/UndirectedGeneratingSetsedited.gap in <module>()

  7 #        http://hdl.handle.net/10133/4996

  8 

 ----> 9 libgap.eval("""IsIrredundant := function(G,S)

 10         # return true if S is irredundant, which means that no element of S is in

 11         # the subgroup generated by the others

 NameError: name 'libgap' is not define
Buddhiang gravatar imageBuddhiang ( 2020-10-15 14:29:14 +0100 )edit

which is similar to the previous one. Will I have to call some package for GAP in Cocalc or in the GAP program I am using?

Buddhiang gravatar imageBuddhiang ( 2020-10-15 14:30:52 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-10-12 21:46:24 +0100

Seen: 404 times

Last updated: Oct 15 '20