Joe Riel

9660 Reputation

23 Badges

20 years, 4 days

MaplePrimes Activity


These are replies submitted by Joe Riel

@Carl Love Instead of assigning to Args you could use _rest (I don't recall which release it was introduced, but it has been around for a while). I like it because it also works nicely with optional keyword arguments (not an issue here).

I'd probably go with 

[seq(`if`(a[i]>=3,i,NULL), i=1..numelems(a))];

@Kitonum Using @ is never a good idea, if speed is a concern.  It is an interpreted procedure.

@Carl Love A simple way to handle this, suitable for short texts, like the example Markiyan gave, with less than 256 distinct words, is to map each distinct word to a character, create the corresponding string, use StringTools:-LongestCommonSubsequence, then convert back to words.  I wonder how well the same technique, using a hash function that maps words to characters, would work on longer text?

Hmm. The hash function makes the inverse map problematic, but not impossible, given the known domain and original text. Probably not the right approach, but interesting.

@Markiyan Hirnyk There is also a LongestCommonSubsequence command, on the same help page.  Does that work? Presumably not.  Can you better spell out how you define a common subsequence.  Useful examples would help.

@Axel Vogt The type conversion is clever, but potentially wasteful in that it may needlessly duplicate a structure, say if the input was a Vector. Another consideration is to provide an 'inplace' option. That isn't useful with a list, but is with the rtables.  So you might consider

BubbleSort := proc( L :: {list,Array,Vector}, { inplace :: truefalse := false } )
   if L :: list then return convert(thisproc(Array(L), ':-inplace'),'list');
   elif not inplace then return thisproc(copy(L), ':-inplace');
   end if;
   # for loops, but with L(i) and L(j), using parentheses rather than square brackets, so indices start at 1 regardless actual index range of an Array.
   L;
end proc: 
   

A conversion from a list to an rtable (Vector or Array), as Carl did, is crucial. A naive user might attempt to operate an a list directly. It's possible but inefficient, O(n^3).

@Carl Love I could have been more explicit. The seq command is better for generating definite sequences, which are more common than indefinite sequences (the OP's example is of a definite sequence).  Offhand, I cannot recall ever using an indefinite sequence. The special case of an indefinite repetition is occasionally used, e.g., diff(f(x), x$n), wiith n symbolic.  Regardless, the distinction you made is useful; I had not thought of $ as an indefinite operator.

Consider uploading your worksheet.

is_unimodal := proc(L :: list(numeric))
local i,n;
    n := nops(L);
    for i from 2 to n while L[i-1] <= L[i] do end do;
    for i from i+1 to n while L[i] <= L[i-1] do end do;
    evalb(n<i);
end proc:

@acer Hmm. Yes. Wasn't paying enough attention. 

@acer Let A be m x n and B be n x m, with m >= n.   If A.B is a diagonal matrix with the diagonal [0$(m-n),1$n], then B.A is the diagonal matrix with diagonal [1$n].   I don't have a proof of uniqueness, though n=1 is trivial since then trace(B.A) = trace(A.B).

@Carl Love Yes, that's how I chose it.  Note that if c23 <> 0, the eigenvalues remain the same but BA is no longer unique.

@acer The matrix 

Cx := Matrix([[0,c12,c13], [0,1,0], [0,0,1]]);

determines B.A uniquely

simplify(B.A, Equate(A.B,Cx));
                           Matrix(2, 2, {(1, 1) = 1, (1, 2) = 0, (2, 1) = 0, (2, 2) = 1})

@Preben Alsholm Thanks for delving into that. I was wondering whether my procedure only worked here, or on Linux. That doesn't appear to be the case.  The useful result is that, once a corrupted worksheet is opened, it is best not to save it from Maple, that can lose data that could otherwise be recovered.

@Preben Alsholm I'm curious as to why you received a "no errors in file".  I just tried the routine (DeleteBadCharacters) and it reported two errors and fixed the file. 

First 44 45 46 47 48 49 50 Last Page 46 of 195