I agree completely with what you say here. Would it be accurate to say:
"Supercompilation, when applied to a lazy functional language, can never
produce a superlinear improvement."
> Would it be accurate to say: "Supercompilation, when applied to a lazy
> functional language, can never produce a superlinear improvement."
I think, it's true for classical Turchin's scp.
It's false if Nemytykh extensions are used.
Example:
=====================================
main n = f1 (chk (gen n)) n
f1 True n = n
f1 False n = []
and True True = True
and False True = True
and True False = False
and False False = False
gen [ ] = Leaf
gen (x:xs) = (gen xs):^:(gen xs)
chk Leaf = True
chk (left :^: right) = and (chk right) (chk left)
=====================================
The "main x" will be supercompiled by Scp4 with the following result:
=====================================
main n = n
=====================================
The trick is the following in Scp4: will be discovered output format of (chk
(gen n)) --- for all n ((chk (gen n)) ==True)
Please note:
1. In this example does not matter is language lazy or not;
2. The termination property of "main" is not changed
Best regards
Sergei
PS. Please, check example ;-)
> I actually made the conscious decision when implementing distillation to
> require that full definitions are given for all functions, including
> equality.
> This means that there is no notion of propagating positive or negative
> information: all information propagation is achieved by the substituting of
> patterns for variables.
As far as I understand, if the input language is statically typed (in
the Hindley-Milner style), and we require that all constructors be
present in every case-expression, there is no difference between
"positive" and "negative" information. For example, if lists are
defined as
data List a = Nil | Cons a (List a);
then any case expression "knows" in advance, that it can be given
either Nil or Cons, OR neither Nil nor Cons.
Sergei
Your message below does not appear to be consistent with your previous
message:
There remains a subtle point concerning the propagation of negative
information, though... But, perhaps, the negative information
propagation could be added to distillation?
Or am I missing something?
I now see where you are coming from - my apologies - your previous
messages are
not inconsistent. I thought that you had said that I should add negative
information
propagation to distillation on the one hand, and that there is no
distinction between
positive and negative information for distillation on the other.
However, what you were
actually saying is that there is no distinction between positive and
negative information
for statically typed languages. I guess I need to divorce my
transformation algorithm
from the language ;-) . I was confused because I was not using the fact
that distillation
is defined for a statically typed language to argue that perfect
propagation of
information can be obtained without the need for distinguishing positive
and negative
information propagation. If we try to divorce the distillation algorithm
from the typing
discipline of the language, then my earlier question still stands:
If we require that full definitions are given for all functions,
including equality, is there any
need for a notion of propagating positive or negative information or can
all information propagation
be achieved by the substituting of patterns for variables? Thus, if
there is a test for equality for two
variables v and v', then in a context within which the result of this
test is true, equal patterns will have
been substituted for v and v', and in a context within which the result
of this test is false, non-equal
patterns will have been substituted for v and v'. I believe this gives
the same effect as perfect
propagation of information and a cleaner simpler algorithm, but am open
to the possibility of this
not being the case.
Geoff.
Dear Geoff,
> However, what you were actually saying is that there is no
> distinction between positive and negative information
> for statically typed languages.
In a language like Refal (or Scheme) one can write something like
f(A) = ASpecialCase;
f(x) = x;
In terms of Refal, there are an infinite (but countable) set of
zero-arity constructors (= "symbols"), a single unary constructor (=
"enclosing an expression in parentheses") and a single binary
constructor (= "concatenation"), which is associative.
Note also that the input data for the program may contain arbitrary
zero-arity constructors ("symbols") that don't appear in the program!
Hence, the function f returns ASpecialCase when given A, and behaves
as the identity function when given anything else. There is no way to
express the fact that "x is not A" by means of a substitution!
But, it the language is a statically typed one, the constructor A must
be declared by means of a declaration, like
data ABC = A | B | C;
Hence, upon seeing A in the rule
f(A) = ASpecialCase;
the supercompiler/distiller knows that X in the second rule
f(x) = x;
is either B or C. Hence, this rule can be replaced with 2 rules:
f(B) = B;
f(C) = C;
which is impossible in principle if we deal with a language like Refal
(or Scheme).
That's why my guess was that the (explicit) negative information
propagation is less important for statically typed languages. Just
because there is no difference between the "negative" and "positive"
information! :-)
The "negative" statement "x is not A" can be reformulated as a
"positive" (and finite) statement "x is either B or C".
Sergei
I don't think the two aims are mutually exclusive...
I think the greedy instantiation of variables based on case often
yields less expensive simplifications for characters and naturals then
carrying around disequality/apartness constraints. I say this based
on my attempts to prove conjectures using these two techniques
manually.
I believe the implementation describing the above apartness constraint
(in póitín) would be:...
False. As an aside, I'm curious if this is the type of thing that is
being done with "output-formats" since it sounds like such a
transition could in fact get super-linear speed-up for an algorithm
that decides to, for instance, calculate Ackerman's function and then
destructure it yielding False in all cases. Of course such a
transition can only be semantics preserving if we can ensure
termination.
...
> Example:
> =====================================
> main n = f1 (chk (gen n)) n
...
Thank you very much for the interesting example given by you.
> The trick is the following in Scp4: will be discovered output format of (chk
> (gen n)) --- for all n ((chk (gen n)) ==True)
....
> PS. Please, check example ;-)
-- It seems the postscript concerning myself.
I have tried to supercompile your example by the current version of
the SCP4 supercompiler. SCP4 does not produce the result expected by
you.
I am sorry about. :-)
The reason is as follows:
The configuration (chk (gen n)) was splitted during generalization:
let m = (gen n) in (chk m)
and the first configuration (gen n) was supercompiled separately of
the second (chk m).
Actually, in my opinion, the example given by you is a good problem to
be solved by development of the supercompilation technology.
The main goal is to improve programs. As a consequence, we have to
generate new ideas and have not to create artificial limits for
supercompilation technology. That is to say, for a technology based on
observation of meta-interpretation of programs.
Sincerely.
Andrei Nemytykh.