changeset 23617:4ce622b7b930 stable

Fix possible infinite loop in normest1.m (bug #51241) * normest1.m: fix the computation of available unparallel columns in S.
author Marco Caliari <marco.caliari@univr.it>
date Fri, 16 Jun 2017 13:05:50 +0200
parents fecca33388f7
children 5e0acf41a9e1 22ff14feb26e
files scripts/linear-algebra/normest1.m
diffstat 1 files changed, 7 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/linear-algebra/normest1.m	Thu Jun 15 19:37:04 2017 -0400
+++ b/scripts/linear-algebra/normest1.m	Fri Jun 16 13:05:50 2017 +0200
@@ -194,17 +194,14 @@
         if (t > 1)
           ## at least two columns of S are not parallel
           i = 1;
-          imax = min (t, 2 ^ (n - 1));
+          ## The maximum number of unparallel columns of length n with
+          ## entries {-1,1} is 2^(n-1).  n of them are already in Sold.
+          imax = min (t, 2 ^ (n - 1) - n);
           while (i <= imax)
-            ## The maximum number of parallel columns of length n with entries
-            ## {-1,1} is 2^(n-1). Therefore, if the number of columns of S is
-            ## greater than 2^(n-1), for sure some of them are parallel to some
-            ## columns of Sold. Don't even try to change them (i <= 2^(n-1)).
-            ## Now, check if S(:,i) is parallel to any previous column of S
-            p = (any (abs (S(:,i)' * S(:,1:i-1)) == n));
-            if (p || (any (abs (S(:,i)' * Sold) == n)))
-              ## i-th column of S parallel to a previous or to a
-              ## column of Sold: change it.
+            if (any (abs (S(:,i)' * S(:,1:i-1)) == n)
+                || any (abs (S(:,i)' * Sold) == n))
+              ## i-th column of S is parallel to a previous column
+              ## or to a column of Sold.  Change it.
               S(:,i) = sign (2*rand (n, 1)-1);
             else
               i++;