1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
|
# Littlewood-Richardson Calculator
# Copyright (C) 1999- Anders S. Buch (asbuch at math rutgers edu)
# See the file LICENSE for license information.
tos := proc(expr)
local i, res, term, base, expo;
if _iss(expr) then
i := _partlen(expr);
if i = 0 then
RETURN(1);
else
RETURN(s[op(1..i, expr)]);
fi;
elif type(expr, `+`) then
res := 0;
for term in expr do
res := res + tos(term);
od;
RETURN(res);
elif type(expr, `*`) then
res := tos(op(1, expr));
for i from 2 to nops(expr) do
res := _mults2(res * tos(op(i, expr)));
od;
RETURN(res);
elif type(expr, `^`) then
base := tos(op(1, expr));
expo := expand(op(2, expr));
if type(expo, integer) then
if expo > 1 then
while expo mod 2 = 0 do
base := _mults2(base^2);
expo := expo / 2;
od;
res := base;
expo := expo - 1;
# return res * base ^ expo
while expo > 0 do
base := _mults2(base^2);
expo := expo / 2;
if expo mod 2 = 1 then
res := _mults2(res * base);
expo := expo - 1;
fi;
od;
RETURN(res);
fi;
fi;
RETURN(base^expo);
elif type(expr, list) then
RETURN([seq(tos(expr[i]), i=1..nops(expr))]);
elif type(expr, set) then
RETURN({seq(tos(expr[i]), i=1..nops(expr))});
else
RETURN(expr);
fi;
0$0;
end:
skew := proc(expr, shape)
local ee, sh, res, term, tt, s_part, c_part, fac;
if not (type(shape, list) or _iss(shape)) then
ERROR(`second argument must be a partition`, shape);
fi;
ee := tos(expr);
sh := _partlen(shape);
if sh = 0 then
RETURN(ee);
fi;
sh := s[op(1..sh, shape)];
if not type(ee, `+`) then
ee := [ee];
fi;
res := 0;
for term in ee do
if type(term, `*`) then
tt := term;
else
tt := [term];
fi;
s_part := 1;
c_part := 1;
for fac in tt do
if _iss(fac) then
s_part := s_part * fac;
else
c_part := c_part * fac;
fi;
od;
if _iss(s_part) then
if sh = s_part then
res := res + c_part;
elif _subpart(sh, s_part) then
res := res + expand(c_part * _call_lrskew(s_part, sh));
fi;
fi;
od;
RETURN(res);
end:
lrcoef := proc(outer, inner1, inner2)
local cmd, fd, res, i;
cmd := cat(LRCALC_BIN_PATH, ` coef `,
seq(cat(` `, op(i,outer)), i=1..nops(outer)), ` -`,
seq(cat(` `, op(i,inner1)), i=1..nops(inner1)), ` -`,
seq(cat(` `, op(i,inner2)), i=1..nops(inner2)));
fd := process[popen](cmd, READ);
res := readline(fd);
process[pclose](fd);
RETURN(parse(res));
end:
_iss := proc(expr)
if not type(expr, indexed) then
RETURN(false);
fi;
RETURN(evalb(op(0, expr) = `s`));
end:
_mults2 := proc(expr)
local ee, res, term, tt, s_part, c_part, fac, base, expo;
ee := expand(expr);
if not type(ee, `+`) then
ee := [ee];
fi;
res := 0;
for term in ee do
if type(term, `*`) then
tt := term;
else
tt := [term];
fi;
s_part := 1;
c_part := 1;
for fac in tt do
if _iss(fac) then
if type(s_part, integer) then
s_part := fac;
elif _cmppart(s_part, fac) <= 0 then
s_part := _call_lrmult(s_part, fac);
else
s_part := _call_lrmult(fac, s_part);
fi;
elif type(fac, `^`) then
base := op(1, fac);
expo := op(2, fac);
if _iss(base) and expo = 2 then
s_part := s_part * _call_lrmult(base, base);
else
c_part := c_part * fac;
fi;
else
c_part := c_part * fac;
fi;
od;
res := res + expand(c_part * s_part);
od;
RETURN(res);
end:
# quantum(rows, cols) and QUANTUM_OPTS are for doing calculations in
# the quantum cohomology ring of Gr(d,n) where d=rows and n=rows+cols,
# rather than the ring of symmetric functions.
quantum := proc(rows, cols)
global QUANTUM_OPTS;
if rows <= 0 or cols <= 0 then
QUANTUM_OPTS := ``;
else
QUANTUM_OPTS := cat(` -q`, rows, `,`, cols);
fi;
readlib(forget);
forget(_call_lrmult);
0$0;
end:
fusion := proc(rows, cols)
global QUANTUM_OPTS;
if rows <= 0 or cols <= 0 then
QUANTUM_OPTS := ``;
else
QUANTUM_OPTS := cat(` -f`, rows, `,`, cols);
fi;
readlib(forget);
forget(_call_lrmult);
0$0;
end:
QUANTUM_OPTS := ``:
_call_lrmult := proc(fac1, fac2)
option remember;
local cmd, fd, res, i;
global QUANTUM_OPTS;
cmd := cat(LRCALC_BIN_PATH, ` mult -m`, QUANTUM_OPTS,
seq(cat(` `, op(i,fac1)), i=1..nops(fac1)), ` -`,
seq(cat(` `, op(i,fac2)), i=1..nops(fac2)));
fd := process[popen](cmd, READ);
res := readline(fd);
process[pclose](fd);
RETURN(parse(res));
end:
_call_lrskew := proc(outer, inner)
option remember;
local cmd, fd, res, i;
cmd := cat(LRCALC_BIN_PATH, ` skew -m`,
seq(cat(` `, op(i,outer)), i=1..nops(outer)), ` /`,
seq(cat(` `, op(i,inner)), i=1..nops(inner)));
fd := process[popen](cmd, READ);
res := readline(fd);
process[pclose](fd);
RETURN(parse(res));
end:
_partlen := proc(lambda)
local n;
n := nops(lambda);
while n > 0 and op(n,lambda) = 0 do n := n - 1; od;
RETURN(n);
end:
_cmppart := proc(p1, p2)
local n;
n := nops(p1);
if n <> nops(p2) then
RETURN(n - nops(p2));
fi;
while n > 0 do
if op(n, p1) <> op(n, p2) then
RETURN(op(n, p1) - op(n, p2));
fi;
n := n - 1;
od;
RETURN(0);
end:
_subpart := proc(p1, p2)
local n;
n := _partlen(p1);
if n > nops(p2) then
RETURN(false);
fi;
while n > 0 do
if op(n, p1) > op(n, p2) then
RETURN(false);
fi;
n := n - 1;
od;
RETURN(true);
end:
|