Prev No Next Up Home Keys Figs Search New

I Need Serious Help

Appeared in Volume 10/2, May 1997

[Some amusing reflections on cheating. There were also some serious comments, but I've removed those. Ed.]


ok@goanna.cs.rmit.edu.au
Richard A. O'Keefe
15th January 1997

Recently a poster sent a message to comp.lang.prolog. He was running up against a deadline for an assignment and wanted some Prolog code, any Prolog code.

A possible assignment_work predicate:

assignment_work :-
    study,
    think,
    write.
assignment_work :-
    cheat,
    fail.


ludemann@inxight.com
Peter Ludemann
19th January 1997

Hmmm ... that code makes an unpleasant assumption about even honest students. The following gives the same computation (it's logically equivalent), but avoids trying illicit methods.

assignment_work :-
    study, !,
    think, !,
    write, !.
assignment_work :-
    cheat,
    fail.


fjh@mundook.cs.mu.oz.au
Fergus Henderson
20th January 1997

Richard's solution had the desirable feature that if writing fails, then you backtrack to thinking again, and if that fails, then you backtrack into studying again. Of course, if we can study at all, then we don't want to try cheating.

Now the only problem with that specification is that it is difficult to implement in Prolog, because you need a soft cut - the best Prolog solution I can come up with requires twice as much study ;-)

assignment_work :-
    ( study ->
         study,
         think,
         write
    ;
         cheat,
         fail
    ).

john.fletcher@dial.pipex.com
John Fletcher
21st January 1997

I think the original poster's point was that he has too many commitments already .... what he really wants is:

assignment_work :-
    cheat,
    \+ get_caught.

It's called "don't know, don't care" non-determinism.


odin@cs.uq.oz.au
Dan
21st January 1997

Of course there are those who believe any "original" work is simply an underlining of influences. In which case:

study :-
     cheat.

The credit comes from the work done by think/1:

assignment_work(Credit) :-
    study,
    (
         think(Credit)
    ;
         increment_guilt,
         Credit = 0
    ),
    write. 


bowers@cs.bris.ac.uk
A. Bowers
23rd January 1997

Fergus Henderson's solution illustrates that the soft, (or shallow) cut form of if-then-else is a very useful language feature. Goedel programmers use it all the time.

In Goedel, one might say:

AssignmentWork <-
    IF SOME [x] Study(x)
    THEN
        Think(x, y) &
        Write(y)
    ELSE<
        Cheat &
        Fail.

The variables are added because in a declarative language there is no point resatisfying goals that do not bind variables (no side effects). Think of "x" as the output from studying, developed into "y" by thinking. Note "x" is not in scope in the "else" part of the formula.

This can't be directly implemented in "ordinary" Prolog (except by computing the condition twice, as Fergus does), but some Prolog's have a form of it; SICStus has if/3. Of course, in Prolog, the programmer is responsible for ensuring safeness, it is not enforced.


bjorne@ida.his.se
Bjorn Olsson
23rd January 1997

John Fletcher wrote:
assignment_work :- cheat, \+ get_caught.

This contains very bad advice: if you get caught, try cheat again. In reality he may not be given a chance to try cheating again, so he may want something like:

% Try cheating ...
assignment_work :-
    cheat, !,
    \+ get_caught.<
% .. but dont get caught.
assignment_work :-
    fail.

ok@goanna.cs.rmit.edu.au
Richard A. O'Keefe
27th January 1997

Ok, here's the definitive version of the assignment_work predicate:

assignment_work :-
    life_choice(honesty(H)),
    assignment_activities(H).

assignment_activities(honest) :-
    repeat,
        study,
        think,
        write,
        (  deadline_too_close
        ;  test
        ),
    !,
    hand_in.
assignment_activities(dishonest) :-
    cheat,
    hand_in,
    fail.


clmeier@lili6.lili.uni-bielefeld.de
Clemens Meier
27th January 1997

Richard A. O'Keefe writes:
assignment_activities(dishonest) :- ...

Well, you can get lucky, can't you? In order to simulate that, we'll have to borrow from Intercal:

:- op(911, xfx, percents).
:- use_module(library(random)).

P percents Goal :-
    random(0, 100, R),
    percents(R, P, Goal).

percents(R, P, Goal) :-
    (   R < P ->
        call(Goal)
    ;   true
    ).

And thus:
assignment_activities(dishonest) :-
    cheat,
    hand_in,
    99 percents fail.

ludemann@inxight.com
Peter Ludemann
30th January 1997

Richard A. O'Keefe writes:
Ok, here's the definitive version...

Well, yes ... but it is rather procedural, isn't it? The following simply returns a list of tasks to do which can be used by the student to guide his or her activities. Even for the alternative solutions to this problem, there is no need for "soft-if-then-else" or "soft cuts".

solution_work(Tasks) :-
    life_choice(honesty(H)),
    phrase(assignment_activities(H), Tasks).

assignment_activities(honest) -->
    tasks_study_think_write
    (  {deadline_too_close}
     -> []
    ;  [test]
     ),
    [hand_in].
assignment_activities(dishonest) -->
    [cheat, hand_in, fail].

tasks_study_think_write -->
    (   [study], tasks_think_write
    ;   []
    ).
tasks_think_write -->
    (   [think], tasks_write
    ;   []
    ).
tasks_write -->
    (   [write]
    ;   []
    ).

Even better would be implementing this with coroutining predicates, to get the interactions between the commands and the results nicely interleaving (e.g., there should be time values in the results from study/think/write and the deadline_too_close predicate would use the finish time from the "write").

I leave this as an exercise to the reader (except that the original reader has probably long left this thread, as it didn't get his homework done for him).

Prev No Next Up Home Keys Figs Search New