Newsgroups: comp.theory,comp.lang.scheme,comp.software-eng
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!fas-news.harvard.edu!newspump.wustl.edu!news.ecn.bgu.edu!vixen.cso.uiuc.edu!howland.reston.ans.net!nntp.coast.net!news.kei.com!world!mv!usenet
From: ENGR@GSSI.MV.COM (Michael Furman)
Subject: Re: Same program, different language (was Style: multiple returns and relatives)
Distribution: inet
Message-ID: <DJ8JG3.460@mv.mv.com>
Mime-Version: 1.0
Organization: GSSI
Date: Thu, 7 Dec 1995 21:24:03 GMT
References: <alberto.534.00162922@moreira.mv.com> <skfVWbO00VohAJimgc@andrew.cmu.edu> <48nni8$klj@ixnews4.ix.netcom.com> <48q9f4$2sj@camelot.ccs.neu.edu> <4950b5$qc9@alpha.pcix.com> <49lcjm$rt2@cloner2.ix.netcom.com> <49vjmp$bbf@alpha.pcix.com> <4a3cr2$3g0@ixnews5.ix.netcom.com>
X-Newsreader: WinVN 0.93.10
X-Nntp-Posting-Host: gssi.mv.com
Lines: 80
Xref: glinda.oz.cs.cmu.edu comp.theory:14890 comp.lang.scheme:14517 comp.software-eng:40014

In article <4a3cr2$3g0@ixnews5.ix.netcom.com>, JEThomas@ix.netcom.com says...
>  ............................
>
>That's what I said.  It wasn't what I was trying for.
>
>Suppose that program "p1" in language "H1" and "p2" in "H2" have the
>same correct outputs.  Suppose further that the assertion is made that

  It is still not defined well what you are saying. What does it 
exactly means "correct output"? I guess you want programs "p1" and "p2"
be equivelent in some sense! But there are a lot of different meanings
of such equivalence, and, from other hand, it is practically impossible
to define exact equivalence between programs in different languages (except
interpeting an abstract machine of one language from another one - see
articles of other authors in this thread).

>p1 will be "less efficient" than p2.  By "less efficient" we mean
>that when we look at the resoures temporarily used by the two
>programs, the total time, total memory, total filespace, etc, and we
>score those resources according to some particular weighting, p1 is
>shown to use more resources than p2 to get the same output.
>
>My question is, how can it be known that p1 will be less efficient
>than p2 when all that is known are the languages?

Of cause it can't. First "p1" and "p2" may be very different program - 
that just printing the same result.
>
>I don't want to claim that a compiler can be made which can perfectly
>optimise any program.  I want to ask:  Given some correct program in
>some language, can it be proven that no compiler can optimise it?

Yes - it can if you fefine parameter for optimisation (for example - 
execution time). There is finite number of "correct" and "equivalent"
(you must define this too) programs - and threfore there is one or number 
of "optimal" programs. But I can not see any practical value of that.

>
>How I came to this question was as follows:  Someone posted a very
>readable program that did a double recursion.  Some single recursions
>can be compiled as loops (or loops can be compiled as recursions, 
>whichever is better).  But the double recursion if compiled literally 
>would be dramatically inefficient, many intermediate results would be 
>done repeatedly when they could instead be done once and saved.  Someone
>else claimed that this was an 'inefficient program'.  I intended to
>claim that they couldn't know that unless they knew that the compiler
>couldn't optimise the double recursion to a single.

I did not see theese posts. But an any case recursion can not dramatically
reduce speed of execution eveon on old computers without hardware stack.
If program calculated the same many times - it can, but it is not related to 
using recursion vs iteration but related to algorithm. Such modifications 
of algorithms (except trvial loop optimisation) usually can not be done by
compiler.

>
>This has no practical significance since I doubt that any existing
>compiler can do that optimisation; it likely would not be cost-efficient 
>to build one that could.  But it means something to me -- we can write
>toward the strengths of particular implementations of compilers, but
>languages as such have no inherent efficiency.
>
>Or do they?

  For some classes of programs and figh level languages - they do. I do not 
think that we can make effective operating system using Lisp or Snobol. Or 
C++ compiler using Basic. E.t.c.
  
   

>

-- 
---------------------------------------------------------------
Michael Furman,                       (603)893-1109
Geophysical Survey Systems, Inc.  fax:(603)889-3984
13 Klein Drive - P.O. Box 97          engr@gssi.mv.com 
North Salem, NH 03073-0097            71543.1334@compuserve.com
---------------------------------------------------------------

