Skip to content

Commit a9b46b6

Browse files
felixlotterd-torrance
authored andcommitted
realized suggestions
1 parent a697813 commit a9b46b6

File tree

5 files changed

+68
-53
lines changed

5 files changed

+68
-53
lines changed

M2/Macaulay2/packages/PathSignatures/algebra.m2

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ matrixAction = method();
99
matrixAction (Matrix, NCRing, NCRing) := NCRingElement => (M, A, B) -> (
1010
N :=transpose entries M;
1111
f := ncMap(B, A, apply(N, j->sum(length(j), i->j#i*(gens B)#i)));
12-
return(f);
12+
f
1313
)
1414

1515
matrixAction (Matrix, NCRingElement, NCRing) := NCRingElement => (M, p, B) -> (
1616
f := matrixAction(M,ring p, B);
17-
return(f(p));
17+
f(p)
1818
)
1919

2020
-- Matrix * Tensor also computes the diagonal matrix action on a tensor, but creates the output nc ring automatically
2121
Matrix * NCRingElement := (M, f) -> (
2222
n := length entries M;
2323
m := length entries transpose M;
2424
tf := length gens ring f;
25-
if(m != tf) then (error("A " | toString(n) | "x" | toString(m) | " matrix can not act on a tensor over " | toString(tf) | "-dimensional space.");)
25+
if(m != tf) then (error("a " | toString(n) | "x" | toString(m) | " matrix can not act on a tensor over " | toString(tf) | "-dimensional space.");)
2626
else (
2727
B := wordAlgebra(n, CoefficientRing => (coefficientRing ring f));
28-
return(matrixAction(M, f, B));)
28+
matrixAction(M, f, B))
2929
)
3030

3131
-- tensorParametrization takes a tensor T, constructs a ring R with one variable for each word appearing in T
@@ -37,7 +37,7 @@ tensorParametrization(NCRingElement) := opts -> (f) -> (
3737
lm := t / leadMonomial;
3838
bR := coefficientRing (class f);
3939
bF := baseRing bR;
40-
if (not opts.CoefficientRing === null ) then bF = opts.CoefficientRing;
40+
if (opts.CoefficientRing =!= null ) then bF = opts.CoefficientRing;
4141
if(opts.VarWordTable === null) then (
4242
b := getSymbol("b");
4343
varis := apply(lm, i -> b_(wordString i));
@@ -46,29 +46,29 @@ tensorParametrization(NCRingElement) := opts -> (f) -> (
4646
vwtable := opts.VarWordTable;
4747
words := apply(lm, i-> value(wordString i));
4848
R = ring (product (keys vwtable));
49-
if(instance(R,QuotientRing)) then error("Expected free polynomial ring.");
49+
if(instance(R,QuotientRing)) then error("expected free polynomial ring.");
5050
scan(words, i-> (
5151
if (not isMember(i,values vwtable)) then (
52-
print("Warning: No variable associated to word " | toString(i));
52+
printerr("warning: no variable associated to word " | toString(i));
5353
);
5454
)
5555
);
5656
lc = apply(gens R, i-> inner(f, (vwtable#i)_(ring f)));
5757
);
58-
return(map(bR,R,lc));
58+
map(bR,R,lc)
5959
)
6060

6161
-- create the non commutative algebra over alphabet given by a list.
6262
wordAlgebra = method(Options=>{CoefficientRing => QQ});
6363
wordAlgebra (List) := opts -> (l) -> (
6464
Lt := getSymbol("Lt");
6565
myvars := apply(l,i-> (Lt_i));
66-
return(opts.CoefficientRing myvars);
66+
opts.CoefficientRing myvars
6767
)
6868

6969
-- create the non commutative algebra over alphabet 1..z
7070
wordAlgebra (ZZ) := opts -> (z) -> (
71-
return(wordAlgebra(toList(1..z), CoefficientRing => opts.CoefficientRing));
71+
wordAlgebra(toList(1..z), CoefficientRing => opts.CoefficientRing)
7272
)
7373

7474
-- define shuffle products on words, use linExt to extend to NCRingElements. Define operator ** as shuffle product in NCAlgebra
@@ -87,7 +87,7 @@ shuffleHelper(List,List,NCRing) := (w1,w2,R) -> (
8787
i := w1#-1;
8888
j := w2#-1;
8989

90-
return(shuffleHelper(w1,w2l,R)*[j]_R + shuffleHelper(w1l,w2,R)*[i]_R);
90+
shuffleHelper(w1,w2l,R)*[j]_R + shuffleHelper(w1l,w2,R)*[i]_R
9191
);
9292

9393
shuffleHelper(NCRingElement, List) := (f,w2) -> linExt(i->shuffleHelper(i,w2,ring f),f);
@@ -96,7 +96,7 @@ shuffleHelper(NCRingElement, NCRingElement) := (f,g) -> (
9696
if(ring f === ring g) then (
9797
return(linExt(i->shuffleHelper(f,i),g));)
9898
else (
99-
error "Can not apply shuffle to polynomials from different rings";
99+
error "can not apply shuffle to polynomials from different rings";
100100
)
101101
)
102102

@@ -105,9 +105,9 @@ shuffleHelper(NCRingElement, NCRingElement) := (f,g) -> (
105105
shuffle = method();
106106
shuffle (NCRingElement, NCRingElement) := (a, b) -> shuffleHelper(a,b);
107107

108-
NCRingElement ** NCRingElement := (f,g) -> (
109-
shuffle(f,g)
110-
)
108+
NCRingElement ** NCRingElement := shuffle
109+
110+
NCRingElement ⧢ NCRingElement := shuffle
111111

112112
-- the antipode of the nc polynomial ring as a Hopf algebra
113113
antipode NCRingElement := (f) -> (
@@ -122,16 +122,16 @@ halfshuffleHelper = method();
122122
halfshuffleHelper(NCRingElement, List) := (f,w) -> (
123123
wl := w_(toList(0..length(w)-2));
124124
wr := w_(-1);
125-
return( shuffleHelper(f,wl) * (ring f)_(wr-1) );
125+
shuffleHelper(f,wl) * (ring f)_(wr-1)
126126
)
127127

128128
halfshuffle = method();
129129
halfshuffle (NCRingElement, NCRingElement) := (f,g) -> (
130130
if(ring f === ring g) then (
131-
if(degree f == 0 or degree g == 0) then error("Can not apply halfshuffle to polynomials of degree zero.");
131+
if(degree f == 0 or degree g == 0) then error("can not apply halfshuffle to polynomials of degree zero.");
132132
return(linExt(i->halfshuffleHelper(f,i),g));)
133133
else (
134-
error "Can not apply halfshuffle to polynomials from different rings";
134+
error "can not apply halfshuffle to polynomials from different rings";
135135
)
136136
)
137137

@@ -142,16 +142,16 @@ innerHelper = method();
142142
innerHelper(List, NCRingElement) := (l,f) -> (
143143
H := coefficientHTable f;
144144
mon := (new Array from l)_(ring f);
145-
return(if(H#?mon) then H#mon else 0);
145+
if(H#?mon) then H#mon else 0
146146
)
147147

148148
inner = method();
149149
-- the first argument is to be viewed as an element of the dual space
150150
inner(NCRingElement, NCRingElement) := (fv,f) -> (
151-
return(linExt(w->innerHelper(w,f),fv));
151+
linExt(w->innerHelper(w,f),fv)
152152
)
153153

154-
NCRingElement @ NCRingElement := (f,m) -> inner(f,m);
154+
NCRingElement @ NCRingElement := inner
155155

156156

157157

@@ -199,15 +199,16 @@ adjointWord (NCRingElement, NCPolynomialRing, List) := (f, A, P) -> (
199199

200200
--Check that number of letters in the given NCRing is enough to compute the image of the word
201201
if d>length(gens A) then (
202-
error("Number of generators of the NCRing lower than dimension of the polynomial ring")
202+
error("number of generators of the NCRing lower than dimension of the polynomial ring")
203203
);
204-
if not (length(P) == length(gens ring f)) then error("The polynomial transformation does not map to the space underlying the input word.");
204+
if not (length(P) == length(gens ring f)) then error("the polynomial transformation does not map to the space underlying the input word.");
205205

206206
if not all(apply(P, p->part(0,p)), q->q==0) then (
207-
error("The image of 0 under the polynomial map is not 0");
207+
error("the image of 0 under the polynomial map is not 0");
208208
);
209209
if(f == 0_(ring f)) then return 0_A;
210-
return(linExt(w->adjointWordHelper(w,A,P), f));
210+
211+
linExt(w->adjointWordHelper(w,A,P), f)
211212
)
212213

213214

@@ -223,7 +224,8 @@ nextLyndonWord(Array,ZZ,ZZ) := Array => (ar,d,k) -> (
223224
nl = nl_{0..length(nl)-2};
224225
);
225226
if(nl != {d}) then nl = nl + toList(((length(nl)-1):0) | (1:1));
226-
return(new Array from nl)
227+
228+
new Array from nl
227229
);
228230

229231
-- lyndonWords(d,k) returns a list of all Lyndon words of length at most k in d letters
@@ -236,7 +238,8 @@ lyndonWords (ZZ,ZZ) := (d,k) -> (
236238
while(l_(-1) != [d]) do (
237239
l = l | {nextLyndonWord(l_(-1),d,k)};
238240
);
239-
return(l);
241+
242+
l
240243
)
241244

242245
-- lie(a,b) returns the lie bracket of a and b
@@ -250,7 +253,8 @@ isLyndon Array := (w) -> (
250253
l := toList w;
251254
out := true;
252255
scan(1..length(l)-1, i->( if(out==true) then out = (l < l_{i..(length(l)-1)}) ) );
253-
return(out);
256+
257+
out
254258
);
255259

256260
-- lyndonFact(l) computes the standard decomposition of l
@@ -262,7 +266,8 @@ lyndonDecomposition Array := (w) -> (
262266
cand := select(ls,i-> isLyndon(i_1));
263267
cand = cand_0;
264268
if(isLyndon(cand#0)) then return cand;
265-
return(lyndonDecomposition(cand#0) | {cand#1})
269+
270+
lyndonDecomposition(cand#0) | {cand#1}
266271
)
267272

268273

@@ -273,15 +278,15 @@ lieBasis(Array, NCPolynomialRing) := (w,R) -> (
273278
if(length(w) == 0) then error("lieBasis expected a non-empty list as input.");
274279
if(length(w) == 1) then return R_(w_(-1) - 1);
275280
fact := apply(lyndonDecomposition(w),i-> lieBasis(i,R));
276-
return(lie(fact_0,fact_1))
281+
lie(fact_0,fact_1)
277282
)
278283

279284
lieBasis(List, NCPolynomialRing) := (l, R) -> lieBasis (new Array from l, R);
280285

281286

282287

283288
expTerm = (tl,l) -> (
284-
return(1/(length(l))!)*product(l,i->(tl_i))
289+
1/(length(l))!)*product(l,i->(tl_i)
285290
)
286291

287292
-- Given a tensor p with constant term 0, tensorExp(p,k) returns the k-th level component of exp(p)
@@ -292,11 +297,12 @@ tensorExp (NCRingElement, ZZ) := (p,k) -> (
292297
s := {1} | toList apply(1..k, i-> sum(select(terms p, j->((degree j) == i))));
293298
comp := unique apply(compositions k, i->delete(0,i));
294299
t := sum(apply(comp, i-> expTerm(s,i)));
295-
return(t);
300+
301+
t
296302
)
297303

298304
logTerm = (tl,l) -> (
299-
return(1/(length(l)))*product(l,i->(tl_i))
305+
1/(length(l)))*product(l,i->(tl_i)
300306
)
301307

302308
-- Given a tensor p with constant term 1, tensorLog(p,k) returns the k-th level component of log(p)
@@ -307,7 +313,8 @@ tensorLog (NCRingElement, ZZ) := (p,k) -> (
307313
s := {1} | toList apply(1..k, i-> sum(select(terms lp, j->((degree j) == i))));
308314
comp := unique apply(compositions k, i->delete(0,i));
309315
t := - sum(apply(comp, i-> logTerm(s,i)));
310-
return(t);
316+
317+
t
311318
)
312319

313320
lyndonShuffleHelper = method();
@@ -330,7 +337,7 @@ lyndonShuffleHelper(List,Ring,NCRing) := (l,R,A) -> ( -- R must be a suitable ri
330337
)
331338

332339
lyndonShuffleHelper(NCRingElement,Ring) := (f,R) -> (
333-
return(linExt(i->lyndonShuffleHelper(i, R, ring f),f,CoefficientRing => R))
340+
linExt(i->lyndonShuffleHelper(i, R, ring f),f,CoefficientRing => R)
334341
)
335342

336343
lyndonShuffle = method();
@@ -344,7 +351,7 @@ lyndonShuffle(NCRingElement) := (f) -> ( -- rewrites a tensor as a shuffle polyn
344351
pol := lyndonShuffleHelper(f,R);
345352
polh := standardForm pol;
346353
polh = applyKeys(polh, i-> applyKeys(i,j-> last baseName R_j));
347-
return(polh);
354+
polh
348355
)
349356

350357

M2/Macaulay2/packages/PathSignatures/documentation.m2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ Node
454454
Key
455455
shuffle
456456
(symbol **, NCRingElement, NCRingElement)
457+
(symbol ⧢, NCRingElement, NCRingElement)
457458
(shuffle, NCRingElement, NCRingElement)
458459
Headline
459460
shuffle product of two words

M2/Macaulay2/packages/PathSignatures/interfaceNCAlgebra.m2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ tensorArray(NCRingElement,ZZ) := (f,h) -> (
105105
applyDeep(product(h,k->genv),w->(if(H#?w) then H#w else 0))
106106
)
107107

108-
NCRingElement @ ZZ := (f,h) -> tensorArray(f,h);
108+
NCRingElement @ ZZ := tensorArray
109109

110110
-- installs operator to work with words [i1,...,ik]_R in an NC ring R
111111
Array _ NCPolynomialRing := (a, R) -> (
112-
if(max(toList a)>length(gens R)) then (error(toString(net "Not enough letters in ring " | net R | ".")));
112+
if(max(toList a)>length(gens R)) then (error(toString(net "not enough letters in ring " | net R | ".")));
113113

114114
product(a,i->R_(i-1))
115115
)

M2/Macaulay2/packages/PathSignatures/signatures.m2

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ sig (Path, List) := (X,w) -> (
1717
)
1818

1919
sig(Path,NCRingElement) := (X,f) -> (
20-
return(linExt(w->sig(X,w),f));
20+
linExt(w->sig(X,w),f)
2121
)
2222

2323
--Compute the signature in level h of a path X,
@@ -101,7 +101,7 @@ polyIntegral (RingElement, RingElement) := RingElement => (f, xn) ->(
101101
R := ring f;
102102
indexn := index xn;
103103
termsf := terms f;
104-
return sum(termsf, i->(1_R/(((((exponents(i))#0)#(indexn)+1))) * i * xn))
104+
sum(termsf, i->(1_R/(((((exponents(i))#0)#(indexn)+1))) * i * xn))
105105
);
106106

107107

@@ -136,7 +136,8 @@ polySigGen (List, List, Ring) := RingElement => (l,w, baseR) ->(
136136
resd = sub(polyIntegral(resd, R_(k-1)),R);
137137
--use(baseR);
138138
resd = substitute(resd, {R_(k-1) => 1_baseR}) - substitute(resd, {R_(k-1) =>0_baseR});
139-
return (if class resd === baseR then resd else leadCoefficient resd)
139+
140+
if class resd === baseR then resd else leadCoefficient resd
140141
);
141142

142143

0 commit comments

Comments
 (0)