sursumCorda

922 Reputation

13 Badges

2 years, 207 days

MaplePrimes Activity


These are replies submitted by sursumCorda

@Preben Alsholm & @Carl Love Thanks again. 
Maybe the real time just depends upon the chronological order of codes. When I run the zip version first, `~` is slower instead: (But it seems to me that the first call almost always uses more memories.) 
 

restart;

x := combinat:-randperm(2*10^7):
y := combinat:-randperm(2*10^7):

undefine(f);

t4 := CodeTools[Usage](zip(f, x, y), iterations = 5)

memory used=1.44GiB, alloc change=2.42GiB, cpu time=2.14m, real time=37.94s, gc time=105.51s

 

t2a := CodeTools[Usage](`~`[f](x, y), iterations = 5)

memory used=1.04GiB, alloc change=-4.00MiB, cpu time=2.29m, real time=38.87s, gc time=115.58s

 

t2b := CodeTools[Usage](`~`[f](x, ` $`, y), iterations = 5)

memory used=1.04GiB, alloc change=0 bytes, cpu time=2.20m, real time=38.44s, gc time=109.43s

 

evalb(t2a = t2b and t2b = t4)

true

(1)

NULL


 

Download `_`_and_zip.mw

@Preben Alsholm Thanks for your reply. Surely their respective domains of operation are different, but I am intrigued to know when `~` and map do the same thing, why the latter is less efficient here. (Is this just determined by the computer's performance?)

@Christian Wolinski Many thanks. I think that this doesn't work on the trivial case x = [].

@Carl Love Thanks very much. I shall think it over later.

And what about other two commands? Contrary to my expectations, they do not do the same thing (at least here). 

@Oliveira I find an instance such that _Z1  _Z1

restart;
op([-1, -1], Invfunc[cos](0)):
ToInert(%);

restart;
op([-1, -1], Invfunc[cos](0)):
ToInert(%);

restart;
op([-1, -1], Invfunc[cos](0)):
ToInert(%);

The return value is always _Inert_LOCALNAME("_Z1~", ```different number```), which is surely distinct from the ToInert(_Z1).

@nm Thanks. As regards the series solutions, if an "exact" general solution is available, we can utilize the asympt function later, but if the symbolic solver is stuck… 
An instance that both Maple and Mathematica cannot solve: 

dsolve({t^2*diff(diff(z(t),t),t)+log(t)^2*z(t)=0},z(t),type='series',t=infinity):
AsymptoticDSolveValue[t^2*Derivative[2][z][t]+Log[t]^2*z[t]==0,z[t],t->Infinity];

@nm It's a undocumented internal function, so use of Holonomic`DifferentialAsymptoticSeries is somewhat discouraged. 

In addition, unfortunately, 

dsolve({t^6*diff(diff(z(t),t),t)+2*t^5*diff(z(t),t)-4*z(t)=0},z(t),'series');

returns nothing (in other words, Maple is unable to find symbolic solution), but Mma's AsymptoticDSolveValue is still capable of solving it. (I don't why.)

@nm Actually, one can obtain (almost) the same results in Mma: 

Series solutions from MatLab's ode::series (just for comparison): 

@Carl Love & @mmcdara Thanks. 

In my opinion, Mathematica's Apply is technically not identical with Maple's apply. Compare:

(* Mma *)
Construct[f, a, b, c];
(* Maple *)
apply(f, a, b, c):

 and 

(* Mma *)
Apply[f, {a, b, c}];
(* Maple *)
`?()`(f, [a, b, c]):

@Carl Love Well, maybe the better term is "ordered pair" rather than "rule" (let alone "function"). (A bijection is dispensable.)
Here is the result from Mathematica: 

@Christian Wolinski@mmcdara, and @Carl Love 
Thanks. But if we add a new rule fg (which gives an additional cycle), the results will go wrong.

@lcz 

eval(reduce(uneval(SubstituteAll), [s, seq(uneval(L1[k], L2[k]), k = 1 .. length['shortname'](L1))]));
 = 
  "{ {0, 1}, {1, 2}, {1, 10}, {2, 3}, {3, 4}, {4, 5},

    {4, 9}, {5, 6}, {6, 7}, {7, 8},{8, 9}, {10, 11}, {11, 12},

    {11, 16}, {12, 13}, {13, 14}, {14, 15}, {15, 16}}"



@Carl Love Actually, as I mentioned before, sometimes such a list does perform a permutation, but in my opinion, we do not need to regard it as a permutation. 
Here we convert one cycles into (another) rules

cycles := [[g, d, c], [e, a], [f, d, c], [b]]:
use ListTools in rules := (combinat['randperm']@MakeUnique@curry(`?()`,`=`)~@FlattenOnce)([seq(Transpose([k,Rotate(k,1)]),k  in  cycles),[[a,b](*,[f,g]*)]]) end use: # a = b obfuscates the rules here.

Yet I have no idea how to reconvert rules back into cycles
Comparison: 
 

restart;

RandomTools:-Generate(listlist(variable(alpha), 20, 23))

[[y, K, N, h, c, G, K, m, x, Y, Y, T, x, R, A, P, Y, L, R, k, y, z, m], [i, K, L, E, f, L, m, m, f, F, A, y, d, h, n, l, f, m, M, J, o, Y, Q], [s, F, l, W, d, U, d, E, h, I, G, Q, n, s, A, H, u, T, p, Q, a, C, T], [h, a, u, r, Q, t, A, s, G, h, Z, p, F, Y, s, l, v, t, P, n, W, s, h], [K, R, S, c, A, M, f, i, A, V, l, T, a, Q, v, v, A, J, m, j, A, U, T], [t, o, L, J, W, w, L, Y, I, T, j, G, e, y, u, s, Z, M, O, b, B, I, x], [d, o, c, a, d, C, S, k, g, z, Z, N, Y, N, B, w, o, R, A, A, F, m, d], [e, Y, x, c, c, V, M, u, c, y, O, p, V, M, o, f, O, z, H, M, g, x, C], [R, W, a, q, D, p, R, H, n, s, V, r, B, m, u, Q, h, Y, z, h, v, d, F], [s, h, I, r, O, L, q, S, M, g, h, b, X, l, f, X, B, I, W, n, q, h, C], [i, B, H, F, c, W, g, B, l, q, N, J, H, M, p, L, x, Y, d, R, s, T, f], [a, D, r, k, P, d, m, U, j, R, g, M, D, F, D, r, G, B, V, t, q, B, i], [X, I, w, a, c, W, z, E, g, f, x, f, w, A, k, M, T, o, l, B, C, t, Z], [h, h, R, j, z, g, B, M, n, B, R, J, s, o, u, g, s, M, K, I, c, y, V], [P, D, b, U, X, V, E, O, a, u, M, M, t, o, m, r, k, x, r, W, N, l, N], [d, M, R, P, a, z, G, c, w, p, P, g, A, Y, W, w, b, h, u, i, c, H, Z], [H, z, U, F, M, z, x, n, r, g, E, s, p, P, H, o, y, O, f, N, b, C, n], [D, u, P, R, G, t, Z, p, Y, S, r, O, B, h, K, s, T, C, O, S, d, u, Y], [S, n, K, Q, t, b, k, l, H, X, J, C, K, M, O, y, z, D, A, b, d, n, z], [X, X, H, u, w, i, x, u, u, D, m, i, u, I, f, c, n, g, i, j, f, L, e]]

(1)

CyclestoRules := proc (C::(list(list))) options operator, arrow; map(proc (c) options operator, arrow; `~`[`=`](c, c[[2 .. -1, 1]])[] end proc, C) end proc

RulesfromCycles := proc (cycles::listlist) options operator, arrow; (`@`(`~`[curry(`?()`, `=`)], ListTools:-FlattenOnce))([seq(ListTools:-Transpose([k, ListTools:-Rotate(k, 1)]), `in`(k, cycles))]) end proc

Warning, (in RulesfromCycles) `k` is implicitly declared local

 

pairs1 := CodeTools:-Usage(CyclestoRules([[y, K, N, h, c, G, K, m, x, Y, Y, T, x, R, A, P, Y, L, R, k, y, z, m], [i, K, L, E, f, L, m, m, f, F, A, y, d, h, n, l, f, m, M, J, o, Y, Q], [s, F, l, W, d, U, d, E, h, I, G, Q, n, s, A, H, u, T, p, Q, a, C, T], [h, a, u, r, Q, t, A, s, G, h, Z, p, F, Y, s, l, v, t, P, n, W, s, h], [K, R, S, c, A, M, f, i, A, V, l, T, a, Q, v, v, A, J, m, j, A, U, T], [t, o, L, J, W, w, L, Y, I, T, j, G, e, y, u, s, Z, M, O, b, B, I, x], [d, o, c, a, d, C, S, k, g, z, Z, N, Y, N, B, w, o, R, A, A, F, m, d], [e, Y, x, c, c, V, M, u, c, y, O, p, V, M, o, f, O, z, H, M, g, x, C], [R, W, a, q, D, p, R, H, n, s, V, r, B, m, u, Q, h, Y, z, h, v, d, F], [s, h, I, r, O, L, q, S, M, g, h, b, X, l, f, X, B, I, W, n, q, h, C], [i, B, H, F, c, W, g, B, l, q, N, J, H, M, p, L, x, Y, d, R, s, T, f], [a, D, r, k, P, d, m, U, j, R, g, M, D, F, D, r, G, B, V, t, q, B, i], [X, I, w, a, c, W, z, E, g, f, x, f, w, A, k, M, T, o, l, B, C, t, Z], [h, h, R, j, z, g, B, M, n, B, R, J, s, o, u, g, s, M, K, I, c, y, V], [P, D, b, U, X, V, E, O, a, u, M, M, t, o, m, r, k, x, r, W, N, l, N], [d, M, R, P, a, z, G, c, w, p, P, g, A, Y, W, w, b, h, u, i, c, H, Z], [H, z, U, F, M, z, x, n, r, g, E, s, p, P, H, o, y, O, f, N, b, C, n], [D, u, P, R, G, t, Z, p, Y, S, r, O, B, h, K, s, T, C, O, S, d, u, Y], [S, n, K, Q, t, b, k, l, H, X, J, C, K, M, O, y, z, D, A, b, d, n, z], [X, X, H, u, w, i, x, u, u, D, m, i, u, I, f, c, n, g, i, j, f, L, e]]))

memory used=46.48KiB, alloc change=0 bytes, cpu time=0ns, real time=1000.00us, gc time=0ns

 

pairs2 := CodeTools:-Usage(RulesfromCycles([[y, K, N, h, c, G, K, m, x, Y, Y, T, x, R, A, P, Y, L, R, k, y, z, m], [i, K, L, E, f, L, m, m, f, F, A, y, d, h, n, l, f, m, M, J, o, Y, Q], [s, F, l, W, d, U, d, E, h, I, G, Q, n, s, A, H, u, T, p, Q, a, C, T], [h, a, u, r, Q, t, A, s, G, h, Z, p, F, Y, s, l, v, t, P, n, W, s, h], [K, R, S, c, A, M, f, i, A, V, l, T, a, Q, v, v, A, J, m, j, A, U, T], [t, o, L, J, W, w, L, Y, I, T, j, G, e, y, u, s, Z, M, O, b, B, I, x], [d, o, c, a, d, C, S, k, g, z, Z, N, Y, N, B, w, o, R, A, A, F, m, d], [e, Y, x, c, c, V, M, u, c, y, O, p, V, M, o, f, O, z, H, M, g, x, C], [R, W, a, q, D, p, R, H, n, s, V, r, B, m, u, Q, h, Y, z, h, v, d, F], [s, h, I, r, O, L, q, S, M, g, h, b, X, l, f, X, B, I, W, n, q, h, C], [i, B, H, F, c, W, g, B, l, q, N, J, H, M, p, L, x, Y, d, R, s, T, f], [a, D, r, k, P, d, m, U, j, R, g, M, D, F, D, r, G, B, V, t, q, B, i], [X, I, w, a, c, W, z, E, g, f, x, f, w, A, k, M, T, o, l, B, C, t, Z], [h, h, R, j, z, g, B, M, n, B, R, J, s, o, u, g, s, M, K, I, c, y, V], [P, D, b, U, X, V, E, O, a, u, M, M, t, o, m, r, k, x, r, W, N, l, N], [d, M, R, P, a, z, G, c, w, p, P, g, A, Y, W, w, b, h, u, i, c, H, Z], [H, z, U, F, M, z, x, n, r, g, E, s, p, P, H, o, y, O, f, N, b, C, n], [D, u, P, R, G, t, Z, p, Y, S, r, O, B, h, K, s, T, C, O, S, d, u, Y], [S, n, K, Q, t, b, k, l, H, X, J, C, K, M, O, y, z, D, A, b, d, n, z], [X, X, H, u, w, i, x, u, u, D, m, i, u, I, f, c, n, g, i, j, f, L, e]]))

memory used=171.22KiB, alloc change=0 bytes, cpu time=15.00ms, real time=16.00ms, gc time=0ns

 

is(pairs1 = pairs2) = trueNULL


 

Download trivial.mw

@Carl Love Sorry, I don't know if such algorithms exist. This instance is adapted from the last example of MMA's Apply (which is more or less similar to Maple's `?()`). Unfortunately, the original function that occured in the help page only has limited functionalities. (So it is incorrect in general.)

First 13 14 15 16 17 18 19 Page 15 of 19