 |
|
List Archives > 
Maple User Group List Archive > 
Archive by date > 
This Month By Date > 
This Month By Topic
[MUG] Optimize tryhard
| [MUG] Optimize tryhard |
|
Author: Moore, Brian
Posted: Tue, 26 Nov 2002 11:28:57 -0500
|
>> From: "Moore, Brian" "Brian.Moore"
I'm looking for information on the algorithm used in the optimize with
tryhard option in the codegen package.
I would also be very interested in other general packages developed for
converting a Maple expression in efficient code (similar to the optimize
tryhard). Actually, the optimize tryhard seems to generate very efficient
code, but it takes a long time to generate the code.
Does anyone have some information concerning this topic ?
Thanks,
Brian Moore
Canadian Space Agency
6767 route de l'Aeroport, Saint-Hubert
Quebec, Canada J3Y 8Y9
email: "Brian.Moore"
|
| [MUG] Re: Optimize tryhard |
|
Author: Maple User Group
Posted: Fri, 29 Nov 2002 09:10:55 -0500
|
>> From: Maple User Group "maple_gr"
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
From: Gaston Gonnet "gonnet"
Date: Wed, 27 Nov 2002 17:53:49 +0100 (MET)
To: "maple-list"
Subject: Optimize tryhard
Yes, I have some information about tryhard, I have coded it some
time ago. I coded it because I was doing molecular dynamics at
the time, and that requires hundreds of hours of computation, hence
optimization time is not very relevant, but quality of the optimization
is.
optimize/tryhard is unique to that piece of code, all the rest of
codegen or Maple do not utilize it.
I never had the time to write a paper about it.... apologies....
Is there anything in particular you would like to know about it?
Best wishes, Gaston Gonnet.
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Wed, 27 Nov 2002 18:11:28 -0500 (EST)
From: Carl Devore "devore"
To: "maple-list"
Subject: Optimize tryhard
On Tue, 26 Nov 2002, Moore, Brian wrote:
> I'm looking for information on the algorithm used in the optimize with
> tryhard option in the codegen package.
It is all in procedures `codegen/optimize/tryhard/frontend` and its
subsidiaries. Just read the procedures with showstat.
> Actually, the optimize tryhard seems to generate very efficient code,
> but it takes a long time to generate the code.
Yeah, it is pretty good. With a tiny bit of tweaking, it can also be used
as an expression simplifier. For lengthy algebraic number expressions, it
often gives significantly more simplification than the other
simplification commands. Here is the tweaking:
Tryhard:= proc(expr)
local _E;
subs(
pow= `^`
,codegen[optimize](subs(_E= expr, ()-> _E), tryhard)
)()
end proc:
Show that is does something potentially useful:
_EnvExplicit:= true:
p:= randpoly([x,y], degree= 4, dense);
root1:= solve(p, y)[1];
# Root is 11 screens long on my computer
simplify(root1);
# Still 11 screens long
r:= Tryhard(root1);
# 2 1/2 screens long, and it only took twice as long as the simplify.
The actual procedure returned by codegen[optimize] in this case is only
1/3 of a screen long. So, looking at that procedure can give a deeper
understanding of the internal structure of root1 than can be obtained by
looking at the 2 1/2 screens.
Test validity:
simplify(eval(p, y= r));
0
So people who collect such things can file that in their Maple trick bag.
|
| [MUG] Re: Optimize tryhard |
|
Author: Maple User Group
Posted: Wed, 4 Dec 2002 10:25:19 -0500 (
|
>> From: Maple User Group "maple_gr"
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Fri, 29 Nov 2002 12:00:18 -0800 (PST)
From: Robert Israel "israel"
To: "maple-list"
Subject: Optimize tryhard
Carl, your Tryhard looks interesting, but it doesn't quite work: I get
> Tryhard(root1);
Error, (in procmake) unbound lexically scoped identifier in
procedure or module
I think you have to make _E a global rather than a local. I'm
puzzled about this, because the function passed to codegen[optimize]
looks the same in both cases. But appearances are deceiving.
Consider:
> TL:= proc(expr) local _E; subs(_E=expr, () -> _E) end proc;
TG:= proc(expr) global _E; subs(_E=expr, () -> _E) end proc;
> FL:= TL(x+1);
> FG:= TG(x+1);
FL := () -> x + 1
FG := () -> x + 1
> codegen[optimize](FL,tryhard);
Error, (in procmake) unbound lexically scoped identifier in procedure or
module
> codegen[optimize](FG,tryhard);
proc() local result; global x; result := x + 1 end proc
Although FL and FG look the same, FL contains a lexical table while
FG does not.
> op(7,eval(FL));
_E, x + 1
> op(7,eval(FG));
(nothing returned)
Robert Israel "israel"
Department of Mathematics http://www.math.ubc.ca/~israel
University of British Columbia
Vancouver, BC, Canada V6T 1Z2
> Date: Wed, 27 Nov 2002 18:11:28 -0500 (EST)
> From: Carl Devore "devore"
> To: "maple-list"
> Subject: Optimize tryhard
>
>
>
> On Tue, 26 Nov 2002, Moore, Brian wrote:
> > I'm looking for information on the algorithm used in the optimize with
> > tryhard option in the codegen package.
>
> It is all in procedures `codegen/optimize/tryhard/frontend` and its
> subsidiaries. Just read the procedures with showstat.
>
> > Actually, the optimize tryhard seems to generate very efficient code,
> > but it takes a long time to generate the code.
>
> Yeah, it is pretty good. With a tiny bit of tweaking, it can also be used
> as an expression simplifier. For lengthy algebraic number expressions, it
> often gives significantly more simplification than the other
> simplification commands. Here is the tweaking:
>
> Tryhard:= proc(expr)
> local _E;
> subs(
> pow= `^`
> ,codegen[optimize](subs(_E= expr, ()-> _E), tryhard)
> )()
> end proc:
>
> Show that is does something potentially useful:
>
> _EnvExplicit:= true:
> p:= randpoly([x,y], degree= 4, dense);
> root1:= solve(p, y)[1];
> # Root is 11 screens long on my computer
> simplify(root1);
> # Still 11 screens long
> r:= Tryhard(root1);
> # 2 1/2 screens long, and it only took twice as long as the simplify.
>
> The actual procedure returned by codegen[optimize] in this case is only
> 1/3 of a screen long. So, looking at that procedure can give a deeper
> understanding of the internal structure of root1 than can be obtained by
> looking at the 2 1/2 screens.
>
> Test validity:
>
> simplify(eval(p, y= r));
> 0
>
> So people who collect such things can file that in their Maple trick bag.
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Fri, 29 Nov 2002 17:08:31 -0500 (EST)
From: Carl Devore "devore"
To: Robert Israel "israel"
Subject: Optimize tryhard
On Fri, 29 Nov 2002, Robert Israel wrote:
> Carl, your Tryhard looks interesting, but it doesn't quite work: I get
> > Tryhard(root1);
>
> Error, (in procmake) unbound lexically scoped identifier in
> procedure or module
>
> I think you have to make _E a global rather than a local.
Professor Israel is correct. I had switched from a global to a local
without restesting (foolish not to retest). One can substitute for a
string and avoid the dangers of global variables. Here is a correction:
Tryhard:= expr->
subs(pow= `^`, codegen[optimize](subs("E"= expr, ()-> "E", tryhard))()
;
And all of the benefits of this simplification method that I mentioned
before still hold.
There might be some functions other than `^` that get their name
unfortunately changed by the tryhard. If you find any, they can be
back-substituted also, and please let me know.
That explains why there are all those substitutions for strings in the
newer code in `dsolve/numeric` and its subsidiaries. For example, check
out line 168 in the Maple 8 version.
|
Previous by date: [MUG] convolution operator, MTK-Adem Kilicman Dr
Next by date: [MUG] Re: graphing parametric equations in 3d, Maple User Group
Previous thread: [MUG] same function with different arrangement give different plots?, Xiaoyan Li
Next thread: [MUG] graphing parametric equations in 3d, Han Wesseling
|
|
|