diff --git a/lib/lierep.gd b/lib/lierep.gd
index cc97469ed0..c92fe687c7 100644
--- a/lib/lierep.gd
+++ b/lib/lierep.gd
@@ -549,7 +549,7 @@ DeclareOperation( "DominantCharacter", [ IsRootSystem, IsList ] );
## with highest weight w_i for i = 1, 2.
## Let W = V_1 \otimes V_2.
## Then in general W is a reducible L-module. Now this function
-## returns a list of two lists. The first of these is the list of highest
+## returns a list of two lists. The first of these is the sorted list of highest
## weights of the irreducible modules occurring in the decomposition of
## W as a direct sum of irreducible modules. The second list contains
## the multiplicities of these weights (i.e., the number of copies of
@@ -587,8 +587,8 @@ DeclareOperation( "DecomposeTensorProduct", [ IsLieAlgebra, IsList, IsList ] );
## [ [ [ 1, 1, 0, 0 ], [ 2, 0, 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 1, 0, 0 ],
## [ 1, 0, 0, 0 ], [ 0, 0, 0, 0 ] ], [ 1, 1, 4, 6, 14, 21 ] ]
## gap> DecomposeTensorProduct( L, [ 1, 0, 0, 0 ], [ 0, 0, 1, 0 ] );
-## [ [ [ 1, 0, 1, 0 ], [ 1, 0, 0, 0 ], [ 0, 0, 0, 1 ], [ 0, 1, 0, 0 ],
-## [ 2, 0, 0, 0 ], [ 0, 0, 1, 0 ], [ 1, 1, 0, 0 ] ],
+## [ [ [ 0, 0, 0, 1 ], [ 0, 0, 1, 0 ], [ 0, 1, 0, 0 ], [ 1, 0, 0, 0 ],
+## [ 1, 0, 1, 0 ], [ 1, 1, 0, 0 ], [ 2, 0, 0, 0 ] ],
## [ 1, 1, 1, 1, 1, 1, 1 ] ]
## gap> DimensionOfHighestWeightModule( L, [ 1, 2, 3, 4 ] );
## 79316832731136
diff --git a/lib/lierep.gi b/lib/lierep.gi
index dfea0bbade..4af3fc71ce 100644
--- a/lib/lierep.gi
+++ b/lib/lierep.gi
@@ -1306,10 +1306,10 @@ InstallMethod( DecomposeTensorProduct,
nu:= mu[1]-rho;
mult:= ch1[2][i]*( (-1)^Length(mu[2]) );
- p:= Position( wts, nu );
- if p = fail then
- Add( wts, nu );
- Add( mlts, mult );
+ p:= PositionSorted( wts, nu );
+ if not IsBound( wts[p] ) or wts[p] <> nu then
+ Add( wts, nu, p );
+ Add( mlts, mult, p );
else
mlts[p]:= mlts[p]+mult;
if mlts[p] = 0 then
diff --git a/tst/testinstall/algsc.tst b/tst/testinstall/algsc.tst
index d0c9cd0c56..d8d06de8f4 100644
--- a/tst/testinstall/algsc.tst
+++ b/tst/testinstall/algsc.tst
@@ -1,6 +1,7 @@
#@local T0,T1,T2,T3,a,b,c,coeff,der,e,fam,g,gens,i,id,j,k,l1,l2,l3,lcs,orb
#@local TestMonomialUseLattice_Orig,permgrp,ps,q,s,s1,s2,s3,sc,t,theta
#@local U,ucs,v,vecs,vectors,w,z,A,V,W
+#@local L,l
gap> START_TEST("algsc.tst");
#############################################################################
@@ -218,6 +219,34 @@ gap> LieCentralizer( l1, ps );
gap> LieNormalizer( l1, ps );
+# Test added for DecomposeTensorProduct
+gap> L := SimpleLieAlgebra( "A", 3, Rationals );;
+gap> v := [1,3,1];;
+gap> w := [4,1,4];;
+gap> l := DecomposeTensorProduct( L, v, w );
+[ [ [ 0, 0, 8 ], [ 0, 1, 6 ], [ 0, 2, 4 ], [ 0, 2, 8 ], [ 0, 3, 2 ],
+ [ 0, 3, 6 ], [ 0, 4, 0 ], [ 0, 4, 4 ], [ 0, 5, 2 ], [ 0, 6, 0 ],
+ [ 1, 0, 5 ], [ 1, 0, 9 ], [ 1, 1, 3 ], [ 1, 1, 7 ], [ 1, 2, 1 ],
+ [ 1, 2, 5 ], [ 1, 3, 3 ], [ 1, 3, 7 ], [ 1, 4, 1 ], [ 1, 4, 5 ],
+ [ 1, 5, 3 ], [ 1, 6, 1 ], [ 2, 0, 6 ], [ 2, 1, 4 ], [ 2, 1, 8 ],
+ [ 2, 2, 2 ], [ 2, 2, 6 ], [ 2, 3, 0 ], [ 2, 3, 4 ], [ 2, 4, 2 ],
+ [ 2, 4, 6 ], [ 2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