Carl Love

Carl Love

28055 Reputation

25 Badges

12 years, 362 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@brian bovril This is an ideal application for the new data structure DataFrame, which is somewhat between a Matrix and a table.

Regarding the specific uneven length list problem: You need to use add~ rather than  add.

If you don't want to bother me, then display your worksheets in your posts rather than simply attaching a worksheet.
 

restart:

N:= 9:

Dist:= Matrix(
   N$2, shape= symmetric, scan= triangular,
   [0, op]~([[26,15,20,7 ,25,16,24,29],
                [15,23,26,33,40,38,54],
                   [24,13,20,27,35,43],
                      [26,42,34,15,39],
                         [18,14,31,32],
                            [25,49,45],
                               [32,20],
                                  [30]]
)):

d:=<0, 18, 26, 11, 30, 21, 16, 29, 37>:

Procedure "tour_length" calculates the length of a given tour.

tour_length:= proc(tour::list(posint))
   option remember;  
   add(Dist[tour[i],tour[i+1]], i= 1..nops(tour)-1) + Dist[tour[-1],tour[1]]
end proc:

demand:= proc(tour::list(posint))
   option remember;  
   add(d[tour[2..]])
end proc:

P:= [$2..5]:

Tour2:= ([1,op]~)~(combinat:-setpartition(P));

[[[1, 5], [1, 2, 3, 4]], [[1, 2], [1, 5], [1, 3, 4]], [[1, 3], [1, 5], [1, 2, 4]], [[1, 4], [1, 5], [1, 2, 3]], [[1, 2], [1, 3], [1, 4], [1, 5]], [[1, 2, 3, 4, 5]], [[1, 2, 5], [1, 3, 4]], [[1, 2], [1, 3, 4, 5]], [[1, 2, 4], [1, 3, 5]], [[1, 3], [1, 2, 4, 5]], [[1, 2, 3], [1, 4, 5]], [[1, 4], [1, 2, 3, 5]], [[1, 3], [1, 4], [1, 2, 5]], [[1, 2], [1, 4], [1, 3, 5]], [[1, 2], [1, 3], [1, 4, 5]]]

Tours_Distances:= (tour_length~)~(Tour2);

[[14, 85], [52, 14, 59], [30, 14, 69], [40, 14, 56], [52, 30, 40, 14], [98], [59, 59], [52, 72], [69, 35], [30, 82], [56, 53], [40, 61], [30, 40, 59], [52, 40, 35], [52, 30, 53]]

Demand_Reqd:= (demand~)~(Tour2);

[[30, 55], [18, 30, 37], [26, 30, 29], [11, 30, 44], [18, 26, 11, 30], [85], [48, 37], [18, 67], [29, 56], [26, 59], [44, 41], [11, 74], [26, 11, 48], [18, 11, 56], [18, 26, 41]]

SumT_D:= add~(Tours_Distances);

[99, 125, 113, 110, 136, 98, 118, 124, 104, 112, 109, 101, 129, 127, 135]

SumD_D:= add~(Demand_Reqd);

[85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85]

MM:= Matrix((6,L), [[$1..L], Tour2, Tours_Distances, SumT_D,Demand_Reqd, SumD_D])^%T;

MM := Matrix(15, 6, {(1, 1) = 1, (1, 2) = [[1, 5], [1, 2, 3, 4]], (1, 3) = [14, 85], (1, 4) = 99, (1, 5) = [30, 55], (1, 6) = 85, (2, 1) = 2, (2, 2) = [[1, 2], [1, 5], [1, 3, 4]], (2, 3) = [52, 14, 59], (2, 4) = 125, (2, 5) = [18, 30, 37], (2, 6) = 85, (3, 1) = 3, (3, 2) = [[1, 3], [1, 5], [1, 2, 4]], (3, 3) = [30, 14, 69], (3, 4) = 113, (3, 5) = [26, 30, 29], (3, 6) = 85, (4, 1) = 4, (4, 2) = [[1, 4], [1, 5], [1, 2, 3]], (4, 3) = [40, 14, 56], (4, 4) = 110, (4, 5) = [11, 30, 44], (4, 6) = 85, (5, 1) = 5, (5, 2) = [[1, 2], [1, 3], [1, 4], [1, 5]], (5, 3) = [52, 30, 40, 14], (5, 4) = 136, (5, 5) = [18, 26, 11, 30], (5, 6) = 85, (6, 1) = 6, (6, 2) = [[1, 2, 3, 4, 5]], (6, 3) = [98], (6, 4) = 98, (6, 5) = [85], (6, 6) = 85, (7, 1) = 7, (7, 2) = [[1, 2, 5], [1, 3, 4]], (7, 3) = [59, 59], (7, 4) = 118, (7, 5) = [48, 37], (7, 6) = 85, (8, 1) = 8, (8, 2) = [[1, 2], [1, 3, 4, 5]], (8, 3) = [52, 72], (8, 4) = 124, (8, 5) = [18, 67], (8, 6) = 85, (9, 1) = 9, (9, 2) = [[1, 2, 4], [1, 3, 5]], (9, 3) = [69, 35], (9, 4) = 104, (9, 5) = [29, 56], (9, 6) = 85, (10, 1) = 10, (10, 2) = [[1, 3], [1, 2, 4, 5]], (10, 3) = [30, 82], (10, 4) = 112, (10, 5) = [26, 59], (10, 6) = 85, (11, 1) = 11, (11, 2) = [[1, 2, 3], [1, 4, 5]], (11, 3) = [56, 53], (11, 4) = 109, (11, 5) = [44, 41], (11, 6) = 85, (12, 1) = 12, (12, 2) = [[1, 4], [1, 2, 3, 5]], (12, 3) = [40, 61], (12, 4) = 101, (12, 5) = [11, 74], (12, 6) = 85, (13, 1) = 13, (13, 2) = [[1, 3], [1, 4], [1, 2, 5]], (13, 3) = [30, 40, 59], (13, 4) = 129, (13, 5) = [26, 11, 48], (13, 6) = 85, (14, 1) = 14, (14, 2) = [[1, 2], [1, 4], [1, 3, 5]], (14, 3) = [52, 40, 35], (14, 4) = 127, (14, 5) = [18, 11, 56], (14, 6) = 85, (15, 1) = 15, (15, 2) = [[1, 2], [1, 3], [1, 4, 5]], (15, 3) = [52, 30, 53], (15, 4) = 135, (15, 5) = [18, 26, 41], (15, 6) = 85})

MM:= DataFrame(
   <<Tour2> | <Tours_Distances> | <SumT_D> | <Demand_Reqd> | <SumD_D>>,  
   columns= [tour, `tour dists`, `+tour dists`, `dmnd rqd`, `+dmnd rqd`],
   datatypes= [list(list(posint)), list(positive), positive, list(nonnegative), nonnegative]
);

MM := Matrix(16, 6, {(1, 1) = ``, (1, 2) = tour, (1, 3) = `tour dists`, (1, 4) = `+tour dists`, (1, 5) = `dmnd rqd`, (1, 6) = `+dmnd rqd`, (2, 1) = 1, (2, 2) = [[1, 5], [1, 2, 3, 4]], (2, 3) = [14, 85], (2, 4) = 99, (2, 5) = [30, 55], (2, 6) = 85, (3, 1) = 2, (3, 2) = [[1, 2], [1, 5], [1, 3, 4]], (3, 3) = [52, 14, 59], (3, 4) = 125, (3, 5) = [18, 30, 37], (3, 6) = 85, (4, 1) = 3, (4, 2) = [[1, 3], [1, 5], [1, 2, 4]], (4, 3) = [30, 14, 69], (4, 4) = 113, (4, 5) = [26, 30, 29], (4, 6) = 85, (5, 1) = 4, (5, 2) = [[1, 4], [1, 5], [1, 2, 3]], (5, 3) = [40, 14, 56], (5, 4) = 110, (5, 5) = [11, 30, 44], (5, 6) = 85, (6, 1) = 5, (6, 2) = [[1, 2], [1, 3], [1, 4], [1, 5]], (6, 3) = [52, 30, 40, 14], (6, 4) = 136, (6, 5) = [18, 26, 11, 30], (6, 6) = 85, (7, 1) = 6, (7, 2) = [[1, 2, 3, 4, 5]], (7, 3) = [98], (7, 4) = 98, (7, 5) = [85], (7, 6) = 85, (8, 1) = 7, (8, 2) = [[1, 2, 5], [1, 3, 4]], (8, 3) = [59, 59], (8, 4) = 118, (8, 5) = [48, 37], (8, 6) = 85, (9, 1) = 8, (9, 2) = [[1, 2], [1, 3, 4, 5]], (9, 3) = [52, 72], (9, 4) = 124, (9, 5) = [18, 67], (9, 6) = 85, (10, 1) = 9, (10, 2) = [[1, 2, 4], [1, 3, 5]], (10, 3) = [69, 35], (10, 4) = 104, (10, 5) = [29, 56], (10, 6) = 85, (11, 1) = 10, (11, 2) = [[1, 3], [1, 2, 4, 5]], (11, 3) = [30, 82], (11, 4) = 112, (11, 5) = [26, 59], (11, 6) = 85, (12, 1) = 11, (12, 2) = [[1, 2, 3], [1, 4, 5]], (12, 3) = [56, 53], (12, 4) = 109, (12, 5) = [44, 41], (12, 6) = 85, (13, 1) = 12, (13, 2) = [[1, 4], [1, 2, 3, 5]], (13, 3) = [40, 61], (13, 4) = 101, (13, 5) = [11, 74], (13, 6) = 85, (14, 1) = 13, (14, 2) = [[1, 3], [1, 4], [1, 2, 5]], (14, 3) = [30, 40, 59], (14, 4) = 129, (14, 5) = [26, 11, 48], (14, 6) = 85, (15, 1) = 14, (15, 2) = [[1, 2], [1, 4], [1, 3, 5]], (15, 3) = [52, 40, 35], (15, 4) = 127, (15, 5) = [18, 11, 56], (15, 6) = 85, (16, 1) = 15, (16, 2) = [[1, 2], [1, 3], [1, 4, 5]], (16, 3) = [52, 30, 53], (16, 4) = 135, (16, 5) = [18, 26, 41], (16, 6) = 85})

MM[MM[`+tour dists`] >=~ 98 and MM[`+tour dists`] <=~ 99];
 

Matrix([[``, tour, `tour dists`, `+tour dists`, `dmnd rqd`, `+dmnd rqd`], [1, [[1, 5], [1, 2, 3, 4]], [14, 85], 99, [30, 55], 85], [6, [[1, 2, 3, 4, 5]], [98], 98, [85], 85]])

``


 

Download Tours_CL_between.mw

@tomleslie A vector space is built on top of an underlying number system called a field. Usually the field is the real or complex numbers. But all that's required for a field are closure of the operations addition, multiplication, and subtraction; closure of division on the set minus zero; commutivity and associativity of both addition and multiplication; and distributivity of multiplication over addition. The smallest possible field has just two elements, 0 and 1. (Here, 0 and 1 are symbols related to, but not identical to, the usual 0 and 1. You could just as well use false for 0 and true for 1.) The multiplication is the same as usual. The addition is the same as usual except that 1+1 = 0. (If you recognize this as Boolean algebra with + = xor, * = and, 0 = false, 1 = true, then you've recognized correctly.) This field is often called GF(2), GF standing for (Evariste) Galois field, and 2 because it has 2 elements. It turns out that (upto isomorphism) this is the only possible field with 2 elements. This is the field over which the OP is considering matrix operations.

@Joe Riel When used with datatype= float[8], Modular uses the extremely well-optimized Basic Linear Algebra Subprograms (BLAS). There's no theoretic reason why float[8] is faster than integer[8]; it's simply that far more work has been to optimize it, down to the hardware level.

@Joe Riel Using datatype= float[8] with LinearAlgebra:-Modular is much faster than datatype= integer. The package is also slightly faster using order= C_order.

@Joe Riel LinearAlgebra:-Generic is a great (and highly abstract) package for working over arbitrary fields, and I appreciate your example showing how to use it. When the field is GF(p) for word-sized primes p, then the package LinearAlgebra:-Modular is an extremely fast (really astoundingly fast) alternative.

@tomleslie Tom, the OP doesn't want all the 4x4 binary matrices. They want the 4x4 binary matrices of rank 3 and 4 over GF(2). In this context, "rank" means the number of vector space dimensions spanned by the columns (or rows---it's the same number) of the matrix.

@gtbastos See below for my complete Answer to the rank problem over GF(2).

@Joe Riel Joe, your code may be an efficient way to count the matrices, but it doesn't save them (or any representation of them) because Iterator reuses the output rtable. Your line
found[cnt] := eval(p);
needs to be changed to something like
found[cnt]:= copy(M)

@Joe Riel Joe, I assume that the output that you used in the code above is a method implemented in Iterator. How is that done? Can you show the code or example code of something similar?

Your request seems a bit unusual at face value, although it's certainly easily done, as the other Answers show. Those Answers are computing the rank over the complex numbers. Did you want that, or did you want the rank over GF(2), which seems like a more-normal request?

@Jackk I think that you are trying to use the comma (,) in place of the decimal point (.). Certainly that's the way that it's done in many written human languages, but as far I know, in Maple you must use the decimal point. For example, 13/10 = 1.3 not 1,3.

@brian bovril Like this:
 

restart:

N:= 9:

Dist:= Matrix(
   N$2, shape= symmetric, scan= triangular,
   [0, op]~([[26,15,20,7 ,25,16,24,29],
                [15,23,26,33,40,38,54],
                   [24,13,20,27,35,43],
                      [26,42,34,15,39],
                         [18,14,31,32],
                            [25,49,45],
                               [32,20],
                                  [30]]
)):

d:=<0, 18, 26, 11, 30, 21, 16, 29, 37>:

Procedure "tour_length" calculates the length of a given tour.

tour_length:= proc(tour::list(posint))
   option remember;  
   add(Dist[tour[i],tour[i+1]], i= 1..nops(tour)-1) + Dist[tour[-1],tour[1]]
end proc:

P:= [$2..5]:

Tour2:= ([1,op]~)~(combinat:-setpartition(P));

[[[1, 5], [1, 2, 3, 4]], [[1, 2], [1, 5], [1, 3, 4]], [[1, 3], [1, 5], [1, 2, 4]], [[1, 4], [1, 5], [1, 2, 3]], [[1, 2], [1, 3], [1, 4], [1, 5]], [[1, 2, 3, 4, 5]], [[1, 2, 5], [1, 3, 4]], [[1, 2], [1, 3, 4, 5]], [[1, 2, 4], [1, 3, 5]], [[1, 3], [1, 2, 4, 5]], [[1, 2, 3], [1, 4, 5]], [[1, 4], [1, 2, 3, 5]], [[1, 3], [1, 4], [1, 2, 5]], [[1, 2], [1, 4], [1, 3, 5]], [[1, 2], [1, 3], [1, 4, 5]]]

M:= nops(Tour2):

Tours_Distances:= (tour_length~)~(Tour2);

[[14, 85], [52, 14, 59], [30, 14, 69], [40, 14, 56], [52, 30, 40, 14], [98], [59, 59], [52, 72], [69, 35], [30, 82], [56, 53], [40, 61], [30, 40, 59], [52, 40, 35], [52, 30, 53]]

MM:= Matrix((3,M), [[$1..M], Tour2, Tours_Distances])^%T;

MM := Matrix(15, 3, {(1, 1) = 1, (1, 2) = [[1, 5], [1, 2, 3, 4]], (1, 3) = [14, 85], (2, 1) = 2, (2, 2) = [[1, 2], [1, 5], [1, 3, 4]], (2, 3) = [52, 14, 59], (3, 1) = 3, (3, 2) = [[1, 3], [1, 5], [1, 2, 4]], (3, 3) = [30, 14, 69], (4, 1) = 4, (4, 2) = [[1, 4], [1, 5], [1, 2, 3]], (4, 3) = [40, 14, 56], (5, 1) = 5, (5, 2) = [[1, 2], [1, 3], [1, 4], [1, 5]], (5, 3) = [52, 30, 40, 14], (6, 1) = 6, (6, 2) = [[1, 2, 3, 4, 5]], (6, 3) = [98], (7, 1) = 7, (7, 2) = [[1, 2, 5], [1, 3, 4]], (7, 3) = [59, 59], (8, 1) = 8, (8, 2) = [[1, 2], [1, 3, 4, 5]], (8, 3) = [52, 72], (9, 1) = 9, (9, 2) = [[1, 2, 4], [1, 3, 5]], (9, 3) = [69, 35], (10, 1) = 10, (10, 2) = [[1, 3], [1, 2, 4, 5]], (10, 3) = [30, 82], (11, 1) = 11, (11, 2) = [[1, 2, 3], [1, 4, 5]], (11, 3) = [56, 53], (12, 1) = 12, (12, 2) = [[1, 4], [1, 2, 3, 5]], (12, 3) = [40, 61], (13, 1) = 13, (13, 2) = [[1, 3], [1, 4], [1, 2, 5]], (13, 3) = [30, 40, 59], (14, 1) = 14, (14, 2) = [[1, 2], [1, 4], [1, 3, 5]], (14, 3) = [52, 40, 35], (15, 1) = 15, (15, 2) = [[1, 2], [1, 3], [1, 4, 5]], (15, 3) = [52, 30, 53]})

LimitDist:= (L::positive)-> select(T-> max(tour_length~(T)) <= L, Tour2):

Ind:= proc(T::list(list(posint)))
   local p;
   member(T, Tour2, p);
   p
end proc:

MM[Ind~(LimitDist(56)), ..];

Matrix([[4, [[1, 4], [1, 5], [1, 2, 3]], [40, 14, 56]], [5, [[1, 2], [1, 3], [1, 4], [1, 5]], [52, 30, 40, 14]], [11, [[1, 2, 3], [1, 4, 5]], [56, 53]], [14, [[1, 2], [1, 4], [1, 3, 5]], [52, 40, 35]], [15, [[1, 2], [1, 3], [1, 4, 5]], [52, 30, 53]]])

``

``


 

Download Tours.mw

@BK The relevant DOS/Windows commands are CD and SET PATH=..., but I can't provide any more help than that. As I said, this error has nothing to do with Maple. Perhaps Acer can give a better example. Or, you could get better help on a Windows/DOS forum. A place to start might be a Google search on "how to set dos path".

@BK Since awk is not a standard Windows command but your batch file does run in a command window, I guess that you have some third-party version of awk installed. My guess is that you need to change the batch file so that its first command is to change the working directory (aka folder) so that it is the same as the one from which the batch did work. If I give Maple the command ssystem("dir"), it shows me that the working directory is C:\Program Files\Maple 2016. This is probably not the working directory that you were using when you successfully ran the batch file.

@BK That is an error due to the commands in the batch file. The error has absolutely nothing to do with Maple. It looks like you may be trying to run the Linux command awk on a Windows system. If that is what you're trying to do, it may help if you install a free program named Cygwin.

First 363 364 365 366 367 368 369 Last Page 365 of 709