Carl Love

Carl Love

28055 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

Do you mean that you want an approximation based on a finite number of terms of the series?

@vs140580 Here is a crude implementation of Heap's permutation algorithm (see Wikipedia article) as an iterator. That is, this procedure returns another procedure such that each call of this latter procedure produces 1 permutation. 

Permute:= proc(L::set)
local n:= nops(L), A:= Array(0..n-1, [L[]]), c:= Array(0..n), i:= 0;    
    proc()     
    local R:= [seq](A);
        while c[i] >= i do c[i++]:= 0 od;
        if i=n then return R fi;
        if i::even then A[[0,i]]:= A[[i,0]] else A[[c[i],i]]:= A[[i,c[i]]] fi; 
        c[i]++; i:= 0;
        R
    end proc  
end proc
: 
#Usage:   
Get:= Permute({a,b,c}):
'Get'()$3!;
[a, b, c], [b, a, c], [c, a, b], [a, c, b], [b, c, a], [c, b, a]

Since the above is written entirely with primitive commands, you can see directly that it uses nearly 0 memory (if you don't save the output in a memory container such as a list, set, or sequence).

A more-sophicated algorithm is needed to efficiently generate the permutations of a multiset (i.e., with repeated elements).

@acer Yes, I understand that the order of L makes no difference programmatically. I thought that the OP would prefer that the numeric order of the coefficients correspond to the order of L, especially given the originally posted code with commented-out corrections. Also, I'd guess that the actual use case is far more complex than the posted example.

Edit: I just now read your edit about the arbitrariness of order. Okay, I guess that you see the same issue that I do.

@Neel Here's a simpler way, using coeff instead of coeffs. I probably would've posted this had I thought of it before I thought of the other.

sol:= W(x) = 
    _C1*(cosh(alpha*x)-sinh(alpha*x))
    + _C2*(cosh(alpha*x)+sinh(alpha*x))
    + _C3*sin(alpha*x) + _C4*cos(alpha*x)
:
V:= [sinh, cosh, sin, cos](alpha*x):
sol:= collect(sol, V):
subs(coeff~(rhs(sol), V) =~ D||(1..nops(V)), sol);

The output is identical to the output in my first Answer.

I totally understand your concern that Maple may run out of memory if you represent the totality of combinations\permutations in a single Maple structure before writing that structure to Excel. But doesn't that concern apply to Excel also? Or does Excel manage a balance between RAM and disk storage for an active worksheet (in a more sophisticated way than Maple does)?

@acer Is it assured that the order of CL corresponds to the order of L? My concern about this was why I made CL (my C) a table. 

@Joe Riel So, are you saying that a variable local to a static module needs to itself be declared static even though a variable local to a static procedure does not need to be declared ​​​​​​static? And does that need continue no matter how deeply nested the modules are? 

Logically, I would think that anything local to anything static couldn't possibly be non-static.

Won't this make the Excel file too large to open in Excel? What do you want to do in Excel that can't be done in Maple?

How will multithreading help you on your single-processor computer?

@acer My interpretation of the OP's request was that they wanted an expression with Nabla expanded to diff or Diff but without the f expanded (to wit: "When f (specific expression) is very complicated, in order to write concisely"). My Answer does not attempt to give a workaround for %Nabla@@4 because even if that did work under value, the final result wouldn't be what the OP wants when f is complicated.

On the other hand, this does seem to me to produce what the OP wants:

restart:
with(Physics:-Vectors):
f:= (x,y,z)-> sin(x)*sin(y)*sin(z)*exp(-x^2-y^2-z^2):
(Nabla@@4)(%f(x,y,z));

diff(%f(x, y, z), x$4)+2*(diff(%f(x, y, z), x$2, y$2))+2*(diff(%f(x, y, z), x$2, z$2))+diff(%f(x, y, z), y$4)+2*(diff(%f(x, y, z), y$2, z$2))+diff(%f(x, y, z), z$4)

In short, my Answer doesn't address the Question's titular issue because doing so doesn't produce the actually desired result.

@Carl Love Here's an example of using Iterator. This uses all 3.6x10^5 permutations of $1..9 (the first 9 natural numbers). Just to have something to do with them, I took the first 9 primes, used the permutation as exponents for the primes, multiplied those, and added that for all the permutations.

restart:
n:= 9:
Pr:= Array(1..n, k-> ithprime(k), datatype= integer[8]):
CodeTools:-Usage(add(mul(Pr^~pm), pm= Iterator:-Permute(n, 'plain')));
memory used=0.56GiB, alloc change=34.00MiB, 
cpu time=2.20s, real time=2.22s, gc time=93.75ms

     17397348309628470393619091828889943584100122136329600

This uses no significant amount of memory. The report of  "memory used" is a misnomer. It should be labeled "memory used & recycled"---it doesn't represent the amount of memory in use at any one time.

The keyword plain makes the Iterator use the same array transposition algorithm that you coded in C++ in another thread. 

@lcz Like I said, you can replace f by %f instead of replacing Nabla by %Nabla. Then the Nablas will be expanded, but not the f, until you use value.

@Thomas385 Man, that's really lame of you. There's at least one more critical point to find.

@acer If I've read correctly (albeit very quickly), that help page says that name conflicts won't be a problem if the global name has last_name_eval. Well:

type(:-process, last_name_eval);
             true

So why the name conflict?

@acer Okay, I deleted my Reply so that the student can do that.

@acer [I deleted this comment to follow your pedagogy.]

First 185 186 187 188 189 190 191 Last Page 187 of 709