Skip to content

Commit 7c05daa

Browse files
author
Anton Leykin
committed
tropicalCayceyMenger introduced; all other CM subroutines unexported
1 parent 6265ac3 commit 7c05daa

File tree

3 files changed

+79
-55
lines changed

3 files changed

+79
-55
lines changed

Rigidity/CayleyMenger-docs.m2

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,40 @@
11
doc ///
22
Node
33
Key
4-
getAllTrees
5-
(getAllTrees,ZZ)
6-
(getAllTrees,List)
4+
tropicalCayleyMenger
5+
(tropicalCayleyMenger,ZZ)
6+
(tropicalCayleyMenger,List)
77
Headline
8-
Get all Cayley-Menger trees on n vertices
8+
Get maximal cones of the tropicalization of Cayley-Menger variety
99
Usage
10-
L = getAllTrees n
11-
L = getAllTrees variableNames
10+
L = tropicalCayleyMenger n
11+
L = tropicalCayleyMenger G
1212
Inputs
1313
n : ZZ
1414
a positive integer
15-
variableNames : List
16-
the list of variables to use
15+
G : List
16+
the list of pairs of integers representing the edges of a graph on vertices 1 to n
1717
Outputs
1818
L :
19-
a list of polynomials, each representing a rooted tree leaves given by the argument list
19+
a list of @TO Cone@s
2020
Description
2121
Text
22-
This function generates all rooted trees on n leaves,
23-
represented as polynomials in which each monomial corresponds
24-
to a clade (a subset of leaves descending from a common internal node).
25-
The leaves are labeled by variables x_1 to x_n (or the ones provided explicitly).
22+
This function generates all maximal cones of the tropicalization of the Cayley-Menger variety on n vertices.
2623
Example
27-
getAllTrees 3
28-
QQ[a,b,c]
29-
getAllTrees {a,b,c}
24+
T = tropicalCayleyMenger 4;
25+
#T
26+
C = first T;
27+
rays C
28+
linSpace C
29+
Text
30+
If a graph G is provided, it generates the maximal cones of the tropicalization of the Cayley-Menger variety restricted to the edges of G.
31+
Example
32+
G = {{1,2},{2,3},{3,4},{1,4}};
33+
T = tropicalCayleyMenger G;
34+
#T
35+
C = last T;
36+
rays C
37+
linSpace C
3038
SeeAlso
31-
maximalTreePairs
39+
"Working with cones"
3240
///

Rigidity/CayleyMenger-tests.m2

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,47 @@
11
TEST ///
2+
restart
3+
needsPackage "Rigidity"
24
n=4;
5+
T = tropicalCayleyMenger n;
6+
assert(#T == 75);
37
G={{1,2},{2,3},{3,4},{1,4}};
4-
5-
GIndices=edgeListToIndices(G,n);
6-
maximalPairs = maximalTreePairs(n);
7-
assert (#maximalPairs == 75)
8-
maximalCones = apply(maximalPairs,
9-
p->apply(raysOfTreePairCone(p_0,p_1),v->v_GIndices));
10-
assert(toString max maximalPairs == "{x_1*x_2*x_3*x_4+x_1*x_2*x_3+x_1*x_2, x_1*x_2*x_3*x_4+x_1*x_3+x_2*x_4}")
8+
T = tropicalCayleyMenger G;
9+
assert(#T == 75 and numrows rays first T == 4);
10+
assert(
11+
(
12+
rays last T - matrix {{0, 0}, {-1, 0}, {0, 0}, {0, -1}}
13+
)% linSpace first T == 0
14+
)
15+
assert(#(T/dim//uniique)==1)
1116
///
1217

18+
1319
TEST ///
1420
permutationOfDoubleIndices = (p,G) -> apply(G, l->position(G,l' -> sort p_l' == l))
1521
checkInvariance = perm -> (
1622
n := #perm;
17-
G := subsets(1..n,2);
18-
GIndices := edgeListToIndices(G,n);
19-
maximalPairs := maximalTreePairs(n);
20-
maximalCones = apply(maximalPairs,
21-
p->apply(raysOfTreePairCone(p_0,p_1),v->v_GIndices));
22-
lookupSet = maximalCones/toCompare//set;
23-
p := permutationOfDoubleIndices(perm,apply(G,p->p-{1,1})); -- need to decrease indices by 1
24-
wrong := select(#maximalCones, i->(
25-
c := maximalCones#i;
26-
c' := c/(r->r_p);
27-
not member(toCompare c', lookupSet)
28-
));
23+
G := subsets(n,2);
24+
-- maxPairs := maximalTreePairs n;
25+
maximalCones := tropicalCayleyMenger n;
26+
p := permutationOfDoubleIndices(perm,G);
27+
pSet = maximalCones/(c->coneFromVData((rays c)^p,(linSpace c)^p));
28+
wrong := select(
29+
apply(5, i->random(#maximalCones)), --take a few random cones to check
30+
i->(
31+
c := maximalCones#i;
32+
c' := coneFromVData((rays c)^p,(linSpace c)^p);
33+
position(maximalCones, c -> c' == c) === null
34+
));
2935
wrong
3036
)
31-
3237
perm = {3,0,1,2}
33-
toCompare = set; -- comparison as sets holds for n=4
38+
setRandomSeed 1234;
3439
wrong = checkInvariance perm
3540
assert isEmpty wrong
3641

37-
-* FAILS!!!
42+
43+
-* this takes longer to run
3844
perm = {4,0,1,2,3}
39-
toCompare = c -> mingens image transpose matrix(QQ,c);
4045
wrong = checkInvariance perm
4146
assert isEmpty wrong
4247
*-

Rigidity/CayleyMenger.m2

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
export {
2-
"getAllTrees",
3-
"raysOfTreePairCone",
4-
"raysOfUltrametricCone",
5-
"maximalTreePairs",
6-
"edgeListToIndices"
2+
"tropicalCayleyMenger"
73
}
84

95
getAllTrees = method();
@@ -139,12 +135,12 @@ raysOfUltrametricCone=method();
139135
--which is spanned by the all-ones vector
140136
raysOfUltrametricCone(RingElement):=List=>T->(
141137
coordinates := subsets(gens ring T, 2);
142-
toReturn := for m in terms T list(
143-
for c in coordinates list(
144-
if m%c_0==0 and m%c_1==0 then -1 else 0
145-
)
138+
raysMatrix := matrix for m in terms T list(
139+
for c in coordinates list
140+
if m%c_0==0 and m%c_1==0 then -1 else 0
146141
);
147-
return toReturn;
142+
linealityMatrix := matrix {toList(#coordinates:1)};
143+
return coneFromVData(transpose raysMatrix, transpose linealityMatrix);
148144
)
149145

150146
raysOfTreePairCone=method();
@@ -154,7 +150,7 @@ raysOfTreePairCone=method();
154150
--Does this modulo the lineality space, which is spanned
155151
--by the all-ones vector
156152
raysOfTreePairCone(RingElement,RingElement):=List=>(T1,T2)->(
157-
T := T1+T2-product(gens ring T1);
153+
T := T1 + T2;
158154
return raysOfUltrametricCone(T);
159155
)
160156

@@ -163,9 +159,24 @@ edgeListToIndices=method();
163159
--and returns the positions where they appear in the lexicographic order.
164160
--Assumes each edge is in increasing order
165161
edgeListToIndices(List,ZZ):=List=>(G,n)->(
166-
allEdges := flatten for i from 1 to n-1 list for j from i+1 to n list {i,j};
167-
for e in G list(
168-
position(allEdges,f->f==e)
169-
)
162+
allEdges := subsets(1..n,2);
163+
for e in G list position(allEdges,f->f==e)
164+
)
165+
166+
--Takes either an integer n or a graph G (as a list of edges)
167+
tropicalCayleyMenger = method()
168+
--If an integer n is given, returns the list of maximal Cones
169+
tropicalCayleyMenger ZZ := List => n ->
170+
apply(maximalTreePairs n, p->raysOfTreePairCone(p_0,p_1))
171+
tropicalCayleyMenger List := List => G -> (
172+
n := max flatten G;
173+
T := tropicalCayleyMenger n;
174+
GIndices := edgeListToIndices(G,n);
175+
T' := apply(T, p->coneFromVData(
176+
(rays p)^GIndices,
177+
(linealitySpace p)^GIndices
178+
));
179+
maxDim := T'/dim//max;
180+
select(T', p->dim p == maxDim)
170181
)
171182

0 commit comments

Comments
 (0)