Joe Riel

9660 Reputation

23 Badges

20 years, 4 days

MaplePrimes Activity


These are replies submitted by Joe Riel

@Carl Love Did you have that saved? I had searched this site for the original (Comparison of CartesianProducts, or something like that) but couldn't locate it.

An alternative, which initially avoids the the garbage collection, is to use convert(., bytes) to convert the string to a list of integers.  Alas, a subsequent operation to subtract 48 from each integer (so they are rendered as digits) does invoke the garbage collector. Wrapping the initial call to convert/bytes in an Array constructor permits the subtraction without creating another large list, however, the rtable construction invokes the garbage collector.  

 

FloatToArray := proc(x::float)
   Array(convert(sprintf("%d",op(1,x)),'bytes')) - 48;
end proc:

 

I find the question unclear.  Could you give more detail?

@brian bovril Look in the Iterator,RevolvingDoorCombination help page.  The example is in the section "Split a list into nearly equal sublists". It's possible I built the package incorrectly and so failed to distribute that updated help page. Let me know if that is the case.

By the way, motivated by this thread, I'm in the process (a slow one) of rewriting the Iterator package to make it feasible to parallelize the search code, i.e. each iterator will be configurable to run over a portion of the total space.  

Followup

I installed the latest package here; apparently none of the help pages were distributed. I know what happened; Maplesoft is switching to a new help database format, which is what I use locally. When I built the package I failed to build the old help database (Iterator.hdb).  Will update it shortly. My apologies.

@YasH A full explanation would require a separate post, which might be interesting in its own right. The short explanation is that  subtracting 32 from the ascii value of # (35) gives 3, which is the dagtag of a rational number:

kernelopts(dagtag=convert("#",bytes)[]-32);
                                                        RATIONAL

I basically created an m-string that encodes a non-reduced rational, then used sscanf to convert it to a Maple expression.

 

@Alejandro Jakubi That is the primary selection. Doesn't work for me pasting into this site with Chromium (ver. 32); it does with iceweasel, but iceweasel is a lot slower. As mentioned in my other response, the clipboard does work.

@Alex Smith Ah, interesting.  I now see that I can paste from Maple, but not from Emacs.  That may give me a clue on how to track down the issue.

Followup

I now have a partial understanding of the problem.  X uses selections.  There are two main selections: primary and clipboard. I've only knowingly used the primary selection, which works by highlighting the text to copy, moving to the target application, moving the cursor to where the text is desired, and clicking the middle mouse button.  That works in most applications.  It works to paste text into the search bar of the chromium browser, but it doesn't work to paste into these text windows. Nothing happens. I can, however, use the primary selection to copy from here to another application.

Fortunately, the clipboard allows copying into this site.  Right-click opens a menu with Paste as an entree, however, selecting it raises an error message, "Currently not supported by your browser, use keyboard-shortcuts."  The keyboard shortcut C-v does the job.

To insert copied text from Emacs into the clipboard I need to set the Emacs variable x-select-enable-clipboard to non-nil.

Still need to figure out why the chromium add-on that is supposed to permit editing this text in Emacs isn't working with this site.

@Carl Love On the other hand, it does, or can, provide a more useful error message.  The subs method isn't necessarily bad, but it is a low-level hack. Using a lexically-scoped variable is a slightly higher-level hack.

 

 

 

 

 

 

 

@Carl Love John's request was to create the declaration Vector(4), which that does not do. I wouldn't be surprised, though, if evaluating the dimension at execution time, rather than creation time, is better.  Really depends on the application.

@Carl Love John's example isn't ideal for demonstrating much of anything other than his problem. Presumably he simplified it just for that purpose, which I appreciate. With that in mind, here is a conversion of it to a Maple object.  This is overkill, but maybe useful. I chose to implement a different method for type checking the Vector dimension.

Using an object doesn't, I believe, eliminate the need to use subs. I avoided it here by moving the dimension check out of the parameter declaration and into the procedure body, where it is handled by a lexically-scoped variable.  The same technique could be used in the original. There are other ways to avoid subs, but that is the oldest (Maple history-wise) and probably the most direct. It is necessary where, say, lexical-scoped variables are not allowed (say with a compiled procedure).

MyObject := module()
option object;

local dim := 3;

export
    ModuleCopy :: static := proc(self :: MyObject
                                 , proto :: MyObject
                                 , { dim :: nonnegint := proto:-dim }
                                 , $
                                )
        self:-dim := dim;
    end proc;

export
    F :: static := proc( self :: MyObject)
    local dim;
        dim := self:-dim;
        proc(x :: Vector)
            if not upperbound(x,1) = dim then
                error "expected a Vector with length %1", dim;
            end if;
        end proc;
     end proc;

end module:

(**) M := Object(MyObject, 'dim'=2):
(**) N := Object(MyObject, 'dim'=3):
(**)
(**) f := F(M):
(**) g := F(N):
(**)
(**) f(<a,b,c>);
Error, (in f) expected a Vector with length 2
(**) f(<a,b>);
(**) g(<a,b,c>);
(**) g(<a,b>);
Error, (in g) expected a Vector with length 3

Note that the technique for calling an object's method, here F(M) is different from a module's, which would be MyObject:-F().

I thought there was an option for selecting the order (chronological or by ranking). I'm sure I used it in the last few weeks, It wasn't easy to find, I cannot find it now.

@Mac Dude To stack them, do, for instance, `&delta;&Delta;x`.

@brian bovril The link isn't working.  Regardless, I wrote a procedure to do this. With compilation, it split the 28 values into a set of 12 and 16 in about 11 minutes.  I attempted to parallelize it, but ran into some conceptual issues that I need to work out.  Concurrently I came up with a clever method to simplify the task such that parallelization should not be needed.  The idea is to use a revolving-door algorithm to generate the partition.  I included one in the Iterator package, however, what I really want are not the partitions but the indices that get exchanged with each transition.  I'll be looking into an efficient way to do that.  With that in place, rather than summing with each new partition, you merely have to use a table-lookup, based on the indices, to find the difference and then add/subtract it to two running sums representing the value of each partition, then add their absolute values.  

Followup

I've added an 'include_indices' option to the RevolvingDoorCombination iterator from the Iterator package so that it returns the indices that change with each iteration.  As alluded to above, that allows computing the 'variance' with just a single addition to a running sum. In rethinking the problem, I realized we only need to keep one running sum, the other one will be its negative. With that, the code can split the 28 element list into 12 and 16 blocks in under 3 minutes, which isn't bad (there are +30e6 iterations). 

I'll be submitting the updated Iterator package to the Application Center shortly, after updating the help page and writing some tests.

Further

The Iterator package has been updated on the Maple Application Center. I renamed the new option of RevolvingDoorCombination to include_change and added an example, a simplification of this problem, showing its use.

@Carl Love Presumably that's why Brian asked about 7x4, it isn't a power of 2.  The total number of set partitions of n distinct items into e sets of length L, with n = e*L, is n!/e!/(L!)^e. For 28 into 7x4 that more than 1.3x1016, so a brute force method is hopeless. A generalization of the splitting technique, when e is odd, is to split into m and m-1 sets of L and minimize the difference of the averages of the logs. 

@brian bovril Once the partitions of indicies are obtained, it is easy to get the partitions of the values and labels. For example

indxs := [[1,3],[2,4]]:
vals := [a,b,c,d]:
map(i->vals[i], indxs);
                      [[a,c],[b,d]]

The same can be done for the labels.

First 46 47 48 49 50 51 52 Last Page 48 of 195