Re: C to Forth converter?
- From: Jean-François Michaud <cometaj@xxxxxxxxxxx>
- Date: 23 Apr 2007 09:37:41 -0700
On Apr 22, 11:29 am, J Thomas <jethom...@xxxxxxxxx> wrote:
On Apr 21, 6:40 pm, Jean-François Michaud <come...@xxxxxxxxxxx> wrote:
On Apr 21, 2:28 pm, Frank Buss <f...@xxxxxxxxxxxxx> wrote:
BTW: this reminds me of another question some time ago in this newsgroup:
how to find the minimum number of instructions for solving a stack juggling
problem? I've written a small Flash animation for it, with a very limited
set of Forth words:
http://www.frank-buss.de/forth/reverse.html
The solution for 5 cells could be extended to arbitrary number of cells.
But is this the shortest solution? Is it provable, that a given solution is
the shortest solution?
This seems to be a variant of the shortest path problem (or traveling
salesman problem without the constraint of having to visit every
"city" once; or more generally, of combinatorial optimization), you
would have to lay down a planar graph of possible operations and a
goal which would be and order of parameters in which you want the
algorithm to converge towards.
And to answer your question, yes it's provable, but if I remember
correctly this problem is NP Hard, which means there's no polynomial
time solution, which means that your algorithm will only run
relatively fast for relatively small problem sets but will become
impractical for larger sets. It will take as much time for you to find
the optimal solution as it will to actually prove that it is the
optimal solution because the only way to find that it is optimal is to
run the algorithm until it finds the solution. It's NP difficult to
prove and provably difficult to prove ;-P.
It doesn't matter whether it's NP-Hard if you never need to solve the
hard problems.
Hehe, thats what I was saying though, It will work for relatively
small problem sets, but will be impractical for larger ones. Frank
Buss's question question was whether the solution could be extended to
work for more than 5 stack elements (it can) and whether it was
provable that a solution was the shortest solution (it also can, but
the consequence of the problem being NP-hard is that it will take as
much time proving that a solution is optimal as it does actually
finding the optimal solution so it's not, in general, useful to prove
that we have an optimal solution because you'll have to run the
algorithm until it reaches a conclusion anyways; you might as well
just run the algorithm in all cases to find the optimal solution and
prove at the same time that it is optimal instead of finding solutions
and then trying to prove that they are optimal. This will work for
small problem sets but will become largely impractical because of
combinatorial explosion for larger problem sets.).
Do it in Forth and what's the chance you'll need ten
stack operations to get a lot of stack parameters just right. Though
translating from C you might....
If you follow good coding practices (particular to Forth), then odds
are you won't encounter larger problem sets, but I'm not at all
certain what kind of results a conversion from C to Forth would yield
as far as stack arguments goes.
[SNIP]
Regards
Jean-Francois Michaud
.
- Follow-Ups:
- Re: C to Forth converter?
- From: J Thomas
- Re: C to Forth converter?
- References:
- C to Forth converter?
- From: Frank Buss
- Re: C to Forth converter?
- From: Stephen Pelc
- Re: C to Forth converter?
- From: Frank Buss
- Re: C to Forth converter?
- From: Andrew Haley
- Re: C to Forth converter?
- From: Frank Buss
- Re: C to Forth converter?
- From: Jean-François Michaud
- Re: C to Forth converter?
- From: J Thomas
- C to Forth converter?
- Prev by Date: Re: I do not worship Java
- Next by Date: Re: C to Forth converter?
- Previous by thread: Re: C to Forth converter?
- Next by thread: Re: C to Forth converter?
- Index(es):
Relevant Pages
|