Carl Love

Carl Love

28100 Reputation

25 Badges

13 years, 106 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@casperyc

Exchange the roles of newdata and data, and then you only need one change in your code at the top. But call it something sensible like data_name:

mysum:= proc(data_name::evaln(list))
local
       data:= eval(data_name)
,
#
# other locals stay the same
#

;
#
# rest of code is exactly the same
#
end proc:

@mahmood180 You see, these comments get lost and forgotten if you don't Post them as separate Questions.

@mahmood180 Please post this as a separate Question. And we can't answer "Is this the right one?" unless you also post a problem with the putative answer.

@Joe Riel You wrote:

Suppose you are creating m lists, each with n elements and collecting them into a set. Assume all lists are different. With Maple's approach the cost of this, I think, is O(m*n)

Sets are stored sorted in Maple, not just hashed, so there are logarithmic factors involved; so, O(m*ln(m)*n), assuming an optimal sorting algorithm. A logarithmic factor is only a small difference though.

@AM So, you see that the question has been answered, right? In modern Maple:

S:= {parse(cat(convert(M^%T, list)[]))};

And for earlier Maple, follow the solution of Kitonum.

Showing explictly what each step does:


M:= < 1,1,1 ; 2,2,2 ; 3,3,3 >;

M := Matrix(3, 3, {(1, 1) = 1, (1, 2) = 1, (1, 3) = 1, (2, 1) = 2, (2, 2) = 2, (2, 3) = 2, (3, 1) = 3, (3, 2) = 3, (3, 3) = 3})

M^%T;

Matrix(3, 3, {(1, 1) = 1, (1, 2) = 2, (1, 3) = 3, (2, 1) = 1, (2, 2) = 2, (2, 3) = 3, (3, 1) = 1, (3, 2) = 2, (3, 3) = 3})

convert(%, list);

[1, 1, 1, 2, 2, 2, 3, 3, 3]

%[];

1, 1, 1, 2, 2, 2, 3, 3, 3

cat(%);

`111222333`

parse(%);

111222333

{%};

{111222333}

 


Download parse_matrix.mw

@JVLB You asked:

So there is no way to speed this up?

You can try the Grid package, which is analogous to Threads, but does not use a shared-memory environment. Since the initial memory state needs to be copied to all processes, Grid is slower and uses more memory than Threads.

Or can I sort of create my own "Map" procedure which creates threads explicitly?

It still wouldn't work if you're using non-thread-safe code.

Why are they not thread safe? Do they internally use the same memory space (or global variable) to store intermediate results?

Yes, exactly.

(in which case manually programming a "Map" procedure would not work either)

Correct.

@Kitonum Thanks for pointing this out. The problem can be overcome more directly by taking the Transpose of M.

Note that map(rhs, convert(op(2,M), list)) only works for this particular Matrix. It will definitely fail for any Matrix with a 0 entry. Zero entries are not represented in op(2,M).

Do you think that many readers here understand "average BER for BPSK"??? Please post your complete code or attach a worksheet.

@nm It is perfectly fine to create a list via

L:= [seq(i, i= 1..N)];

That creates only one list and only one sequence. That's not assigning to a list; it's assigning a list to a name. The following code is bad (O(N^2)), although it is allowed and is very frequently seen:

L:= [];
for i to N do L:= [op(L), i] end do
;

Assuming that a for loop is necessary (i.e., that seq won't work), which is frequently the case, the above should be replaced with either of the following:

V:= Vector();
for i to N do V(i):= i end do;
L:= convert(V, list)
;

or

T:= table();
for i to N do T[i]:= i end do;
L:= convert(T, list);

Table lookup and storage is essentially O(1) in Maple.

When you see code written by Joe or me, pay attention to how lists are created. Note the differences between the two methods presented in both Joe's and my Answers to your earlier Question from today, "How to obtain positions in matrix that meet some condition?"

Mathematica must suffer some performance penalty for allowing lists to be mutable objects. For example, I'd wager that comparing two lists for equality is O(n), whereas it's instantaneous in Maple.

@nm 

{parse(cat(convert(M^%T,list)[]))};

@tomleslie All that's needed to create your sequence is

outp:= convert(M^%T, list)[];

So you want the answer to be a set containing a single integer whose digits come from the Matrix entries? That's what {111222333} is. But that's not a sequence. So I need clarification.

@nm If you want to save typing, as often seems to be your goal, note that the else NULL in Preben's code is superfluous. All if statements without an else clause have else NULL as default. Also, end if can be changed to fi. The 2,3 can be replaced with op(1,A) to increase the generality of the code. Finally, the two statements can be combined. So, it becomes

ind:= convert(Matrix(op(1,A), (i,j)-> if A[i,j] >= 3 then [i,j] fi), list):

That code involves a user arrow procedure iterated over every element, so Pagan's seq solution is faster:

(n,m):= op(1,A):
ind:= [seq(seq(`if`(A[i,j] >= 3, [i,j], NULL), i= 1..n), j= 1..m)]:

I don't yet know how to make rtable_scanblock work.

Update: I figured out rtable_scanblock, and I give two solutions in an Answer below.

@Stephen Forrest Could you explain your Answer, please? Especially the RegSplit and RegSubs?

@k20057 5 Why can't you plot? I gave you the plotting command before:

plot([lhs,rhs]~(T), style= point);

First 530 531 532 533 534 535 536 Last Page 532 of 709