acer

32348 Reputation

29 Badges

19 years, 329 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

What exactly is meant, when you write that you cannot simplify the piecewise under assumptions, "...because that value of q[S] is still dependent of another variable"? Why can't that other variable be included in the assumption(s), and the assumption(s) be whatever is need to trigger a given conditional (but no conditional earlier in the piecewise)?

acer

@Alejandro Jakubi That's really helpful, Alejandro. Thanks.

@jakubi 

Without preserved nesting and order of all the comments to a post, a lot or real value is lost.

I'd like to hear that it's going to be corrected, as an automatic sweep throught the new site. It's even more important than the related issue of whether the formatting of earlier posts will be fixed (all crammed into one run-on paragraph).

And the same is true for Questions: Just because more highly up-voted Answers rise to the top should (ideally) not mean that the comments nested underneath them get their order and placement mangled.

Which reminds me: the mechanism for submitting nested comments is erratic. I always click the link for a previous comment or Answer on which I want to reply further. And the system certainly knows something of what I want, because it inserts a @name for the author to which I'm responding further. But only sometimes does my comment get nested (indented, or whatever you want to call it). It's frustrating, and I believe that I'm being careful enough to be attempting it properly. (Also, for comments on Posts -- not Questions or Answers -- why doesn't the "Parent" drop-down choice appear?)

acer

There are effective differences between these,

flat := a->`if`(type(a,list), op(map(procname,a)), a):

flat2 := x -> [subsindets(x,list,t->op(t))]:

In cases of extreme nesting there could be tie-in with stacklimit, for the recursive call. And indeed the recursive method fails after hitting the recursion limit. For very deep nesting the subsindets may succeed, but only so slowly as to be useless.

> Z:=(`[]`@@17229)(7,8):

> st:=time(): ans1:=[flat(Z)]: time()-st; # very fast
                                    0.219

> Z:=(`[]`@@17230)(7,8):

> st:=time(): ans1:=[flat(Z)]: time()-st;
Error, (in flat) too many levels of recursion
                                    0.172

In case you are wondering about ListTools:-Flatten and deeply nested lists,

> st:=time(): ans1:=ListTools:-Flatten((`[]`@@59059)(7)): time()-st;
                                    1.904

> st:=time(): ans1:=ListTools:-Flatten((`[]`@@59060)(7)): time()-st;
Error, (in ListTools:-Flatten) too many levels of recursion
                                    1.528

I'm leaving out half the story, throughout, which is memory allocation increases by different methods.

For a simple list of many lists of lists (ie. shallow nesting with many children, and IMO likely the more common case), the comparative performance situation can look quite different

> Z:=[seq([[7,8]],i=1..100000)]:

> st:=time(): ans1:=[flat(Z)]: time()-st;
                                    2.527

> st:=time(): ans2:=flat2(Z): time()-st;
                                    0.187

> st:=time(): ans3:=ListTools:-Flatten(Z): time()-st;
                                    2.293

This was all in Maple 13.01 on Windows XP.

acer

There are effective differences between these,

flat := a->`if`(type(a,list), op(map(procname,a)), a):

flat2 := x -> [subsindets(x,list,t->op(t))]:

In cases of extreme nesting there could be tie-in with stacklimit, for the recursive call. And indeed the recursive method fails after hitting the recursion limit. For very deep nesting the subsindets may succeed, but only so slowly as to be useless.

> Z:=(`[]`@@17229)(7,8):

> st:=time(): ans1:=[flat(Z)]: time()-st; # very fast
                                    0.219

> Z:=(`[]`@@17230)(7,8):

> st:=time(): ans1:=[flat(Z)]: time()-st;
Error, (in flat) too many levels of recursion
                                    0.172

In case you are wondering about ListTools:-Flatten and deeply nested lists,

> st:=time(): ans1:=ListTools:-Flatten((`[]`@@59059)(7)): time()-st;
                                    1.904

> st:=time(): ans1:=ListTools:-Flatten((`[]`@@59060)(7)): time()-st;
Error, (in ListTools:-Flatten) too many levels of recursion
                                    1.528

I'm leaving out half the story, throughout, which is memory allocation increases by different methods.

For a simple list of many lists of lists (ie. shallow nesting with many children, and IMO likely the more common case), the comparative performance situation can look quite different

> Z:=[seq([[7,8]],i=1..100000)]:

> st:=time(): ans1:=[flat(Z)]: time()-st;
                                    2.527

> st:=time(): ans2:=flat2(Z): time()-st;
                                    0.187

> st:=time(): ans3:=ListTools:-Flatten(Z): time()-st;
                                    2.293

This was all in Maple 13.01 on Windows XP.

acer

By coincidence, now that the Mapleprimes Search facility has improved, I was thinking about sieving this site and collating all the requests for abstract linear algebra. Maybe that would help in the decision making.

The question comes up (with slightly differing functionality aspects, naturally) pretty regularly.

I have made some very modest efforts into this area. But they are very rough (in a backlog of unfinished prototype side-projects). So I doubt they would be of use to anyone, as is.

Part of the problem is knowing where to start. Collating the particular functionality requests seems like one reasonable place to begin. It's tempting to ask, "Ok, how do I lay down a comprehensive set of requirements, up front?" But if the horizon is too vast, that can be an impediment to making any headway. I asked a colleague, expert in programming, what one can do in extreme situations. The answer was that one way is to collect a smaller, manageable set of individual tasks, and see what would be required to solve them individually.

The technical question, of how to represent an abstract Matrix, is interesting. In the past, I've briefly looked at attributes on names, `is` and assumptions, and even modules or records. It's quicker to get going simply with attributes on names, but these days I'm leaning more toward modules or similar (despite their rather heavy nature).

On a forwards thinking note, I saw this the other day. Wouldn't it be nice to be able to do the same in Maple. (This looks like an impressive use of it.)

acer

If you expect to use a `simple' piece of code many times, inside some other procedures, then you might not want to take the performance hit of extra function calls just to get that simple code to run inside some parent procedure.

Maple function calls can be (relatively) expensive, so wrapping just a tiny code fragment inside a proc can have a measurable cost. For such reasons, the `option inline` exists for procedures. Compare the body of computational routine `f` below, when `Centroid` does or does not have option inline.

The idea is that `f` might do a long computation which calls `Centroid`many times. You can ignore the T stuff, and focus on the last part of the body of `f`, where the centroid computation takes place.

Notice in the printed 2D output below how the body of the second version of `f` has the centroid code inlined into it, avoiding the overhead cost of the function call to `Centroid`.

> Centroid:=proc(L) `+`(op(L))/nops(L) end proc:

> f:=proc()
  local T;
  T := [[1,2,3],[4,5,6],[8,9,10]];
  Centroid(T);
end proc;

   f := proc () local T; T := [[1, 2, 3], [4, 5, 6], [8, 9, 10]]; Centroid(T) end proc

> f(); # it works
                          [13  16  19]
                          [--, --, --]
                          [3   3   3 ]

> Centroid:=proc(L) option inline; `+`(op(L))/nops(L) end proc:

> f:=proc()
  local T;
  T := [[1,2,3],[4,5,6],[8,9,10]];
  Centroid(T);
end proc;

   f := proc() local T; T := [[1, 2, 3], [4, 5, 6], [8, 9, 10]]; (`+`(op(T)))/nops(T) end proc

> f(); # it still works
                          [13  16  19]
                          [--, --, --]
                          [3   3   3 ]

BTW, you seem to be suggesting that Maple should have a routine to compute centroids of lists. That notion has, built right into it, the idea that a list represents a point in space. That may be convenient sometimes, but a Vector (usual, or VectorCalculus) might be more useful. I'd agree that the `geometry` package's objects are too unwieldy.

The original versions posted here simply print the result, and return NULL. If that's really what one wants, inside some larger working procedure say, then why not use userinfo?

While I was composing the minor variant, using `+` and `op`, Joe posted the same.

note to admin: I realize now that I should have made this a branch post. Can that be done, after the fact? Thnx.

acer

I buy into the notion that Thread:-Add and friends should be drop-in replacements for their global counterparts, as much as is reasonably possible. As Darin has pointed out, some languages provide the automatic handling of locals that allows examples such as this to work automatically. Why isn't it reasonable to expect that Maple can too?

I'd say that Thread:-Add and friends haven't attained much more than surface usefulness if they are this problematic.

Hence, I call the given example a bug in Threads itself.

acer

@Robert Israel Hi Robert, some time back Doug Meade wanted to be able to distribute a Maplet bundled with image files. He posted about his solution here.

While I'm looking at this thread again, while updating tags on old posts,

1:iolib(34);

acer

@Will On behalf of many of us, Will, let me just say Thanks!

@jakubi Alejandro, thanks for looking. I wonder if yours is the only mapleprimes backup.

Would you be able to say how many responses this thread had, in total, in V.1? In V.2, it currently lists as 13+1 where yours is the 1. (And it'll likely be 13+2 when I submit this.)

Would you be able to show a block quote of a paragraph or a significant, uniquely identifying portion of one of the missing responses?

Thanks,
acer

@Joe Riel Joe, did you mean to format that comment like this?

In html input mode, use &lt; and &gt; to input < and >, respectively. For an ampersand, use &amp;

@Joe Riel Joe, did you mean to format that comment like this?

In html input mode, use &lt; and &gt; to input < and >, respectively. For an ampersand, use &amp;

The Online Help has somehow messed up that example, Alejandro! It's the very last example on ?assuming,details.

In the Online Help page, the result of using assuming is (incorrectly) the same as the result from using assume. They both show as the result a+1.

But the assuming result should be this, instead,

> f := proc(x) sqrt(a^2)+x end proc;
f := proc(x) sqrt(a^2) + x end proc

> f(1) assuming a>0;
2 1/2
(a ) + 1

 

I wonder how it goes wrong. (eg. Examples run out-of-order, or a 2DMath effect, or...) I didn't check in the Standard GUI itself.

Your example with attributes is also interesting; that too should be documented as another exception.

acer

First 455 456 457 458 459 460 461 Last Page 457 of 592