lcz

1039 Reputation

12 Badges

6 years, 62 days
changsha, China

MaplePrimes Activity


These are replies submitted by lcz

@Kitonum For the specific case where each division has same size: this is most concise code. But considering the versatility, the solutions provided by Carl Love and dharr are more attractive.

@Carl Love Thank you so much. Unfortunately, your code did not work on my computer. I suspect it may be due to P:=[3,3]. We expect to get 10 solutions, not 20, taking into account symmetrical solutions as one.

F := SetPartitionFixedSize([3, 3],compile = true);
Print(F, 'showrank')

1: 1 2 3 4 5 6 
 2: 1 2 4 3 5 6 
 3: 1 2 5 3 4 6 
 4: 1 2 6 3 4 5 
 5: 1 3 4 2 5 6 
 6: 1 3 5 2 4 6 
 7: 1 3 6 2 4 5 
 8: 1 4 5 2 3 6 
 9: 1 4 6 2 3 5 
10: 1 5 6 2 3 4 

 

@epostma After a continuous dialogue with it, it gave the following improved code.

primes := Array([2]);
for i from 3 to 100 do
   primestest := true:
   for j in primes do
      if i mod j = 0 then
         primestest := false;
         break;
      elif j^2 > i then
         break;
      end if;
   end do:
   if primestest then
      ArrayTools:-Append(primes, i);
   end if;
end do:
print(primes)

@Carl Love  Yes, the codes about prime numbers on its first attempt surprised me as it has a simple syntax error. In addition, It often creates functions that maple does not contain at all. As a digression, I want it to list some articles on graph theory topics that I care about, and many of articles from chatgpt are cut out of whole cloth.

@acer I tried a non-programming method. First we convert this work document into pdf, then import it into inkscape, and then convert it into svg. See the attached file. The pdf format is a vector format, so I feel that pdf and svg have some kind of close connection.

table.zip

@Carl Love Thank you very much. folding is what I need.

@mmcdara I've never been very happy with the sketchiness of Maple's help documentation. More than one place, for example: How to use TSPLIB (.tsp) Format .

@Kitonum Your approach for the problem is nice, but I would love to consider of a more general replacement. For example, the number of elements in each bracket is not necessarily the same.

L:="[ (0, 1, 3), (1, 2), (1, 10), (2), (3, 4), (4, 5), (4, 9), (5, 6), (6,9, 7), (7, 8),(8, 9),
(10, 11), (11, 12), (11, 16), (12), (13,9,10 14), (14, 15), (15, 16)]": 

Still after the above substitution, we have

L1:=["(",")","[","]"]:
L2:=["{","}","{","}"]:
X:=L:
for i from 1 to nops(L1) do
X:=SubstituteAll(X,L1[i],L2[i]);
end do:
parse(X)

{{2}, {12}, {1, 2}, {1, 10}, {3, 4}, {4, 5}, {4, 9}, {5, 6}, {7, 8}, {8, 9}, {10, 11}, {11, 12}, {11, 16}, {14, 15}, {15, 16}, {0, 1, 3}, {6, 7, 9}, {9, 10, 13, 14}}

It is easy to see that SubstituteAll is used four times in the for-loop, and I wonder if there is a more concise way to write it. 

This is the key to my question, how a function with arguments can be repeatedly applied to an object. Note that these arguments are still changing each time. For example, SubstituteAll(X,L1[i],L2[i])

@tomleslie I sometimes encounter this situation too. Usually it's an output from another program (may be Java, C... ) that  maple may not recognize it.

[ (0, 1), (1, 2), (1, 10), (2, 3), (3, 4), (4, 5), (4, 9), (5, 6), (6, 7), (7, 8),
          (8, 9), (10, 11), (11, 12), (11, 16), (12, 13), (13, 14), (14, 15), (15, 16)
        ]

I usually use some text tools (like vs code) for replacement and sometimes even regular replacement. Maple seems to be able to do the same thing.

with(StringTools):
with(GraphTheory):
s:="[ (0, 1), (1, 2), (1, 10), (2, 3), (3, 4), (4, 5), (4, 9), (5, 6), (6, 7), (7, 8),(8, 9), (10, 11), (11, 12), (11, 16), (12, 13), (13, 14), (14, 15), (15, 16)]";    
l:=parse(SubstituteAll(SubstituteAll(s,"(","{"),")","}"));
DrawGraph(Graph({op(l)}))

 

@sursumCorda Thanks! It is well. What have you changed about the original text to make it readable? It retains at least the information of positions of vertices of the graph.

GraphTheory:-GetVertexPositions(g)

[[1080, 1440], [480, 320], [660, 560], [420, 160], [1380, 880], [1020, 720], [720, 880], [660, 800], [2160, 0], [0, 0], 
[1500, 480], [1320, 800], [1800, 240], [900, 1120], [1080, 1360]]

 

@mmcdara It still doesn't seem to work.

We note that Import function is valid for the file with gml format created by maple itself.

HerschelG := GraphTheory:-SpecialGraphs:-HerschelGraph()
GraphTheory:-ExportGraph(HerschelG,"G:/test/herschel.gml",graphlet)
g:=Import ("G:/test/herschel.gml")
GraphTheory:-DrawGraph(g)

Creator "Maple : maplesoft.com"
graph [
    directed 0
    node [
        id 1
        graphics [
            x -1
            y 0
        ]
    ]
    node [
        id 2
        graphics [
            x 0
            y .75
        ]
    ]
    node [
        id 3
        graphics [
            x 1
            y 0
        ]
    ]
    node [
        id 4
        graphics [
            x 0
            y -.75
        ]
    ]
    node [
        id 5
        graphics [
            x -.5
            y 0
        ]
    ]
    node [
        id 6
        graphics [
            x -.25
            y .25
        ]
    ]
    node [
        id 7
        graphics [
            x .25
            y .25
        ]
    ]
    node [
        id 8
        graphics [
            x .5
            y 0
        ]
    ]
    node [
        id 9
        graphics [
            x .25
            y -.25
        ]
    ]
    node [
        id 10
        graphics [
            x -.25
            y -.25
        ]
    ]
    node [
        id 11
        graphics [
            x 0
            y 0
        ]
    ]
    edge [
        source 1
        target 2
    ]
    edge [
        source 1
        target 4
    ]
    edge [
        source 1
        target 5
    ]
    edge [
        source 2
        target 3
    ]
    edge [
        source 2
        target 6
    ]
    edge [
        source 2
        target 7
    ]
    edge [
        source 3
        target 4
    ]
    edge [
        source 3
        target 8
    ]
    edge [
        source 4
        target 9
    ]
    edge [
        source 4
        target 10
    ]
    edge [
        source 5
        target 6
    ]
    edge [
        source 5
        target 10
    ]
    edge [
        source 6
        target 11
    ]
    edge [
        source 7
        target 8
    ]
    edge [
        source 7
        target 11
    ]
    edge [
        source 8
        target 9
    ]
    edge [
        source 9
        target 11
    ]
    edge [
        source 10
        target 11
    ]
]

From the above exported gml file, it stores information about vertices, edges and the coordinates of the vertices of  the Herschel graph. But it's not clear to me  what kind of gml format maple accepts. I don't know what information can be included in the standard gml format and I don't know where I can view it.

@sursumCorda  I was wondering what graph format would store the vertex positions. This will make it easier to import or export. I opened graphml and didn't see what I wanted to see. This might be another interesting question.

@dharr sursumCorda 100 I don't know much about  algorithms of Layered graph drawing.I would be happy to know if bending some edges is necessary for some graphs.

We know that Maple's graph theory package does not support drawing curves (used to represent  edges). We hope that does not to be a reason that some edges overlap. 

Here's what I did with Gephi. It can load Graphviz (The "dot" tool in Graphviz produces layered drawings.). Each edge is straight, but they do not overlap.

 

gr_graphml.txt

@dharr From the discussion below, it appears that there is no polynomial algorithm for finding all minimal cuts. I feel that I have misread Literature [1], or the result of Literature [1] itself is wrong.

@dharr Yes. The purpose of my calculation of all the minimum cuts is to observe some characteristics of edge cuts of some  graphs. The applied meaning is weak. As for the problem with the function  Iterator:-Combination  you mentioned, thanks very much for the reminder.

2 3 4 5 6 7 8 Last Page 4 of 17