Carl Love

Carl Love

28035 Reputation

25 Badges

12 years, 318 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@vs140580 Here is a worksheet with your requested modifications. I've included your 25 basic metrics and the 4 metrics based on edge weights.
 

29 Graph Metrics

Author: Carl Love <carl.j.love@gmail.com> 2023-Mar-07

restart
:

All are intended for undirected graphs without self loops and work for both weighted and unweighted graphs.

VS25:= proc(G::Graph)
local
   `C+`, `C*`, Csqrt, Cmax, A1, A2, A3, u, N, e:= 0,
    V:= op(4, G), C:= nops~(V), n:= numelems(C), CN, m:= add(C)/2, E:= rtable(1..m),
    Eput:= (_,v)-> (E[++e]:= (u,v))[1],
    Add:= f-> add(f(e), e= E),
    VSprod:= proc(P)
    local T:= table('sparse');
        for e in E do T[P(e)]++ od;
        (mul@op~@[indices])(T, 'pairs')
    end proc
;
    for u,N in V do CN(u):= add(C[[u, N[]]]); select[fold= (Eput, 0)](`<`, N, u) od;
    C:= (max(C)+1) -~ C;
    ((r-> `if`(r::integer[8], r, evalf(r)))~@table)([
        A__0||(1..3)=~ ((A1,A2,A3):= Add~([
            ((u,v)-> (`C+`(u,v):= C[u]+C[v])),
            ((u,v)-> (`C*`(u,v):= C[u]*C[v])),
            `C+`^2
        ])[]),
        A__0||(4..6)=~ Add~([
            `C*`^2, (`C+`-2)^(1/2)/(Csqrt:= `C*`^(1/2)), 2*Csqrt/`C+`
        ])[],
        A__0||(7..9)=~ (2*m*(n-1) - A1, 2*m^2 - A1/2 - A2, A3 - 2*A2),
        'A__10'= Add(m/(m-n+2)/Csqrt),
        A__||(11,12)=~ VSprod~([`C+`,`C*`])[],
        A__||(13..15)=~ Add~([`C+`/`C*`, `C*`/`C+`, `C+`*`C*`])[],
        (N__0||(1..9), N__10)=~ Add~([
            ((u,v)-> (`C+`(u,v):= CN(u)+CN(v))/2),
            ((u,v)-> (`C*`(u,v):= CN(u)*CN(v))/2),
            `C+`^2/4,
            ((u,v)-> 1/(Cmax(u,v):= max(CN(u), CN(v)))),
            `C*`/`C+`, 2/`C+`, 2/`C*`, 4/`C*`^2, Cmax, `C+`/`C*`
        ])[]
    ])
end proc
:

G:= GraphTheory:-SpecialGraphs:-HypercubeGraph(7);

GRAPHLN(undirected, unweighted, ["0000000", "0000001", "0000010", "0000011", "0000100", "0000101", "0000110", "0000111", "0001000", "0001001", "0001010", "0001011", "0001100", "0001101", "0001110", "0001111", "0010000", "0010001", "0010010", "0010011", "0010100", "0010101", "0010110", "0010111", "0011000", "0011001", "0011010", "0011011", "0011100", "0011101", "0011110", "0011111", "0100000", "0100001", "0100010", "0100011", "0100100", "0100101", "0100110", "0100111", "0101000", "0101001", "0101010", "0101011", "0101100", "0101101", "0101110", "0101111", "0110000", "0110001", "0110010", "0110011", "0110100", "0110101", "0110110", "0110111", "0111000", "0111001", "0111010", "0111011", "0111100", "0111101", "0111110", "0111111", "1000000", "1000001", "1000010", "1000011", "1000100", "1000101", "1000110", "1000111", "1001000", "1001001", "1001010", "1001011", "1001100", "1001101", "1001110", "1001111", "1010000", "1010001", "1010010", "1010011", "1010100", "1010101", "1010110", "1010111", "1011000", "1011001", "1011010", "1011011", "1011100", "1011101", "1011110", "1011111", "1100000", "1100001", "1100010", "1100011", "1100100", "1100101", "1100110", "1100111", "1101000", "1101001", "1101010", "1101011", "1101100", "1101101", "1101110", "1101111", "1110000", "1110001", "1110010", "1110011", "1110100", "1110101", "1110110", "1110111", "1111000", "1111001", "1111010", "1111011", "1111100", "1111101", "1111110", "1111111"], Array(1..128, {(1) = {2, 3, 5, 9, 17, 33, 65}, (2) = {1, 4, 6, 10, 18, 34, 66}, (3) = {1, 4, 7, 11, 19, 35, 67}, (4) = {2, 3, 8, 12, 20, 36, 68}, (5) = {1, 6, 7, 13, 21, 37, 69}, (6) = {2, 5, 8, 14, 22, 38, 70}, (7) = {3, 5, 8, 15, 23, 39, 71}, (8) = {4, 6, 7, 16, 24, 40, 72}, (9) = {1, 10, 11, 13, 25, 41, 73}, (10) = {2, 9, 12, 14, 26, 42, 74}, (11) = {3, 9, 12, 15, 27, 43, 75}, (12) = {4, 10, 11, 16, 28, 44, 76}, (13) = {5, 9, 14, 15, 29, 45, 77}, (14) = {6, 10, 13, 16, 30, 46, 78}, (15) = {7, 11, 13, 16, 31, 47, 79}, (16) = {8, 12, 14, 15, 32, 48, 80}, (17) = {1, 18, 19, 21, 25, 49, 81}, (18) = {2, 17, 20, 22, 26, 50, 82}, (19) = {3, 17, 20, 23, 27, 51, 83}, (20) = {4, 18, 19, 24, 28, 52, 84}, (21) = {5, 17, 22, 23, 29, 53, 85}, (22) = {6, 18, 21, 24, 30, 54, 86}, (23) = {7, 19, 21, 24, 31, 55, 87}, (24) = {8, 20, 22, 23, 32, 56, 88}, (25) = {9, 17, 26, 27, 29, 57, 89}, (26) = {10, 18, 25, 28, 30, 58, 90}, (27) = {11, 19, 25, 28, 31, 59, 91}, (28) = {12, 20, 26, 27, 32, 60, 92}, (29) = {13, 21, 25, 30, 31, 61, 93}, (30) = {14, 22, 26, 29, 32, 62, 94}, (31) = {15, 23, 27, 29, 32, 63, 95}, (32) = {16, 24, 28, 30, 31, 64, 96}, (33) = {1, 34, 35, 37, 41, 49, 97}, (34) = {2, 33, 36, 38, 42, 50, 98}, (35) = {3, 33, 36, 39, 43, 51, 99}, (36) = {4, 34, 35, 40, 44, 52, 100}, (37) = {5, 33, 38, 39, 45, 53, 101}, (38) = {6, 34, 37, 40, 46, 54, 102}, (39) = {7, 35, 37, 40, 47, 55, 103}, (40) = {8, 36, 38, 39, 48, 56, 104}, (41) = {9, 33, 42, 43, 45, 57, 105}, (42) = {10, 34, 41, 44, 46, 58, 106}, (43) = {11, 35, 41, 44, 47, 59, 107}, (44) = {12, 36, 42, 43, 48, 60, 108}, (45) = {13, 37, 41, 46, 47, 61, 109}, (46) = {14, 38, 42, 45, 48, 62, 110}, (47) = {15, 39, 43, 45, 48, 63, 111}, (48) = {16, 40, 44, 46, 47, 64, 112}, (49) = {17, 33, 50, 51, 53, 57, 113}, (50) = {18, 34, 49, 52, 54, 58, 114}, (51) = {19, 35, 49, 52, 55, 59, 115}, (52) = {20, 36, 50, 51, 56, 60, 116}, (53) = {21, 37, 49, 54, 55, 61, 117}, (54) = {22, 38, 50, 53, 56, 62, 118}, (55) = {23, 39, 51, 53, 56, 63, 119}, (56) = {24, 40, 52, 54, 55, 64, 120}, (57) = {25, 41, 49, 58, 59, 61, 121}, (58) = {26, 42, 50, 57, 60, 62, 122}, (59) = {27, 43, 51, 57, 60, 63, 123}, (60) = {28, 44, 52, 58, 59, 64, 124}, (61) = {29, 45, 53, 57, 62, 63, 125}, (62) = {30, 46, 54, 58, 61, 64, 126}, (63) = {31, 47, 55, 59, 61, 64, 127}, (64) = {32, 48, 56, 60, 62, 63, 128}, (65) = {1, 66, 67, 69, 73, 81, 97}, (66) = {2, 65, 68, 70, 74, 82, 98}, (67) = {3, 65, 68, 71, 75, 83, 99}, (68) = {4, 66, 67, 72, 76, 84, 100}, (69) = {5, 65, 70, 71, 77, 85, 101}, (70) = {6, 66, 69, 72, 78, 86, 102}, (71) = {7, 67, 69, 72, 79, 87, 103}, (72) = {8, 68, 70, 71, 80, 88, 104}, (73) = {9, 65, 74, 75, 77, 89, 105}, (74) = {10, 66, 73, 76, 78, 90, 106}, (75) = {11, 67, 73, 76, 79, 91, 107}, (76) = {12, 68, 74, 75, 80, 92, 108}, (77) = {13, 69, 73, 78, 79, 93, 109}, (78) = {14, 70, 74, 77, 80, 94, 110}, (79) = {15, 71, 75, 77, 80, 95, 111}, (80) = {16, 72, 76, 78, 79, 96, 112}, (81) = {17, 65, 82, 83, 85, 89, 113}, (82) = {18, 66, 81, 84, 86, 90, 114}, (83) = {19, 67, 81, 84, 87, 91, 115}, (84) = {20, 68, 82, 83, 88, 92, 116}, (85) = {21, 69, 81, 86, 87, 93, 117}, (86) = {22, 70, 82, 85, 88, 94, 118}, (87) = {23, 71, 83, 85, 88, 95, 119}, (88) = {24, 72, 84, 86, 87, 96, 120}, (89) = {25, 73, 81, 90, 91, 93, 121}, (90) = {26, 74, 82, 89, 92, 94, 122}, (91) = {27, 75, 83, 89, 92, 95, 123}, (92) = {28, 76, 84, 90, 91, 96, 124}, (93) = {29, 77, 85, 89, 94, 95, 125}, (94) = {30, 78, 86, 90, 93, 96, 126}, (95) = {31, 79, 87, 91, 93, 96, 127}, (96) = {32, 80, 88, 92, 94, 95, 128}, (97) = {33, 65, 98, 99, 101, 105, 113}, (98) = {34, 66, 97, 100, 102, 106, 114}, (99) = {35, 67, 97, 100, 103, 107, 115}, (100) = {36, 68, 98, 99, 104, 108, 116}, (101) = {37, 69, 97, 102, 103, 109, 117}, (102) = {38, 70, 98, 101, 104, 110, 118}, (103) = {39, 71, 99, 101, 104, 111, 119}, (104) = {40, 72, 100, 102, 103, 112, 120}, (105) = {41, 73, 97, 106, 107, 109, 121}, (106) = {42, 74, 98, 105, 108, 110, 122}, (107) = {43, 75, 99, 105, 108, 111, 123}, (108) = {44, 76, 100, 106, 107, 112, 124}, (109) = {45, 77, 101, 105, 110, 111, 125}, (110) = {46, 78, 102, 106, 109, 112, 126}, (111) = {47, 79, 103, 107, 109, 112, 127}, (112) = {48, 80, 104, 108, 110, 111, 128}, (113) = {49, 81, 97, 114, 115, 117, 121}, (114) = {50, 82, 98, 113, 116, 118, 122}, (115) = {51, 83, 99, 113, 116, 119, 123}, (116) = {52, 84, 100, 114, 115, 120, 124}, (117) = {53, 85, 101, 113, 118, 119, 125}, (118) = {54, 86, 102, 114, 117, 120, 126}, (119) = {55, 87, 103, 115, 117, 120, 127}, (120) = {56, 88, 104, 116, 118, 119, 128}, (121) = {57, 89, 105, 113, 122, 123, 125}, (122) = {58, 90, 106, 114, 121, 124, 126}, (123) = {59, 91, 107, 115, 121, 124, 127}, (124) = {60, 92, 108, 116, 122, 123, 128}, (125) = {61, 93, 109, 117, 121, 126, 127}, (126) = {62, 94, 110, 118, 122, 125, 128}, (127) = {63, 95, 111, 119, 123, 125, 128}, (128) = {64, 96, 112, 120, 124, 126, 127}}), `GRAPHLN/table/11`, 0)

interface(rtablesize= 25):

sort(<entries(CodeTools:-Usage(VS25(G)), pairs)>, key= lhs);

memory used=2.13MiB, alloc change=0 bytes, cpu time=15.00ms, real time=23.00ms, gc time=0ns

Vector(25, {(1) = `#msub(mi("A"),mi("01"))` = 896, (2) = `#msub(mi("A"),mi("02"))` = 448, (3) = `#msub(mi("A"),mi("03"))` = 1792, (4) = `#msub(mi("A"),mi("04"))` = 448, (5) = `#msub(mi("A"),mi("05"))` = 0, (6) = `#msub(mi("A"),mi("06"))` = 448, (7) = `#msub(mi("A"),mi("07"))` = 112896, (8) = `#msub(mi("A"),mi("08"))` = 400512, (9) = `#msub(mi("A"),mi("09"))` = 896, (10) = `#msub(mi("A"),mi("10"))` = 623.3043478, (11) = `#msub(mi("A"),mi("11"))` = 896, (12) = `#msub(mi("A"),mi("12"))` = 448, (13) = `#msub(mi("A"),mi("13"))` = 896, (14) = `#msub(mi("A"),mi("14"))` = 224, (15) = `#msub(mi("A"),mi("15"))` = 896, (16) = `#msub(mi("N"),mi("01"))` = 25088, (17) = `#msub(mi("N"),mi("02"))` = 702464, (18) = `#msub(mi("N"),mi("03"))` = 1404928, (19) = `#msub(mi("N"),mi("04"))` = 8, (20) = `#msub(mi("N"),mi("05"))` = 12544, (21) = `#msub(mi("N"),mi("06"))` = 8, (22) = `#msub(mi("N"),mi("07"))` = .2857142857, (23) = `#msub(mi("N"),mi("08"))` = 0.1822157434e-3, (24) = `#msub(mi("N"),mi("09"))` = 25088, (25) = `#msub(mi("N"),mi("10"))` = 16})

VSdist:= proc(G::Graph)
uses GT= GraphTheory;
local
    d:= GT:-AllPairsDistance(G), n:= op([1,1], d),
    (D,D__min):= (op@[max,min]@rhs~@op)(2, d), B, A:= GT:-AdjacencyMatrix(G)
;
    table(
        [B__||(1..4)]=~
            if D=infinity then [D, undefined$2, 0]
            else [
                -(B:= -add(d)/2), (B+= D*(n*= (n-1)/2)), B+D__min*n,
                map['reduce'= `+`](x-> `if`(x=0, 0, 1/x), (D-~d)*~A)/2
            ]
            fi
    )
end proc
:        

B:= sort(<entries(CodeTools:-Usage(VSdist(G)), pairs)>, key= lhs);

memory used=5.42MiB, alloc change=0 bytes, cpu time=47.00ms, real time=37.00ms, gc time=0ns

Vector(4, {(1) = `#msub(mi("B"),mi("1"))` = 28672, (2) = `#msub(mi("B"),mi("2"))` = 28224, (3) = `#msub(mi("B"),mi("3"))` = 36352, (4) = `#msub(mi("B"),mi("4"))` = 224/3})

 


 

Download 29GraphMetrics.mw

@vv I vote up also. I know you're aware of this; I only point it out for other readers: Your analysis only applies to real solutions. There are numerous nonreal solutions for which not all the variables are equal.

I combined my Answer for this with my Answer regarding your 15 "A" values and posted it as an Answer to that Question.

Not a single one of your 15 functions make use of the weights. What am I missing? 

@dharr I vote up. You've provided an impressive tour-de-force of Maple's facilities for working with exact polynomials with algebraic-number coefficients. 

@Christian Wolinski Yes, that appears so. As I said above, the "rules" in the OP's leading example do not even represent a function. That's a bit counter-intuitive because "rule" and "function" mean pretty much the same thing in common usage.

@Axel Vogt MaplePrimes Search searches Posts and Questions. As far as I can tell, there's no option for searching Answers, Comments, or Replies. This is very, very bad because the vast majority of useful content on this site is in the Answers. (Posts also contain much useful information, but there are far fewer of them.) The amount of useful-for-searching content in Questions is negligible. Thus, the vast majority of this site cannot be searched in any meaningful way. Thus it has very little potential to be a valuable information resource for the future.

@sursumCorda Many users are probably not aware of the difference between a list(list) and a listlist. The former is a list whose elements are lists; the latter is a list whose elements are lists that all have the same number of elements.

@sursumCorda Going from cycles to rules is trivial, even for cases that aren't permutations:

CyclesToRules:= (C::list(list))-> (c-> (c =~ c[[2..-1, 1]])[])~(C)
:
CyclesToRules([[g, d, c], [e, a], [f, d, c], [b]]);
[g = d, d = c, c = g, e = a, a = e, f = d, d = c, c = f, b = b]

As you say, the a=b obfuscates. The big stumbling block in going from rules to cycles is deciding that a=b can be ignored.

I deleted your recently posted follow-up Question because it's too similar to this one. Indeed, the only difference from this Question is that in the new Question you want D in italics. As noted below, D is a special case.

@sursumCorda The last example shown on that Mathematica help page is a permutation. Indeed, it is the example that you used in your first version of this Question, and it was what I coded my Answer for.

Maple has a command apply, which handles the vast majority of cases. It is quite rare that one one needs to resort to `?()` in top-level code, although one may need to overload it in an object module. The same applies to index (used twice in my Answer), which is an easier-to-use version of `?[]`

@sursumCorda If you could specify an algorithm for this (rather than just an example), I'd be happy to encode it in Maple as efficiently as possible. 

@sursumCorda Your example rules contain a=b. How is that rule represented in the output 

[[g, d, c], [e, a], [f, d, c], [b]]

I could do it with a two-line procedure if your rules were a permutation (or bijection), but they aren't in your example. And given that they aren't, I don't understand what you mean by "cycles". Your rules don't even represent a function, let alone a bijection.

@mmcdara K is the SI unit of temperature; kg is the SI unit of mass.

First 59 60 61 62 63 64 65 Last Page 61 of 708