in reply to Brute force perl

If you're looking for perl programs of a certain specified length, then genetic algorithms might work well. The building block hypothesis seems particularly applicable.

(Note: even though you'd be evolving code, it's not really genetic programming, since that does functional composition at the semantic level, whereas here we're mucking with characters of raw source code.)

A word spoken in Mind will reach its own level, in the objective world, by its own weight

Replies are listed 'Best First'.
Re^2: Brute force perl
by lima1 (Curate) on Jun 12, 2007 at 16:17 UTC
    Hm, I really don't see the point in using GAs for such an enumeration. In contrast, you would have a lot more expensive fitness evaluations than necessary (Except when you use a cache, but then the GA overhead is still a waste of CPU time).
      you would have a lot more expensive fitness evaluations than necessary

      Why? With the OP's brute force method, you're fully enumerating the search space. With a GA, you're "intelligently" pruning, or picking a path through the search space. That's the whole point, actually. As I said, the building block hypothesis makes sense here. Building blocks such as $_ or print are more likely to survive, for example.

      A word spoken in Mind will reach its own level, in the objective world, by its own weight
        The score for the generated code is just "is this valid", hence, a boolean. Just replacing one character is enough to make invalid code valid, or vice versa. There is no such thing as "almost valid code".

        Hence, there is no way to "prune intelligently".

        "A lot" was probably wrong here, but what I wanted to say is that I don't believe it is possible to generate more "correct strings" in a given time with a GA. And if you want to find ALL (as stated by the OP) correct strings, you can't use GAs at all.
Re^2: Brute force perl
by jagh (Monk) on Jun 12, 2007 at 16:22 UTC

    I thought about GAs for a bit. What I'm missing is a good fitness function..

    I suppose something like the following psuedocode might produce results:

    return ( valid_perl_p($individual) ? length($individual) : 0 );

    It looks like I have some work to do :)

      What I'm missing is a good fitness function.

      eval? Safe?

      A word spoken in Mind will reach its own level, in the objective world, by its own weight
        Right, but from those I'll get ``it works'' or ``it doesn't'', nothing more.

        I'm working on it, though :). AI::Genetic is producing interesting results already..