Home  |   Notes  |   Languages  |   Programs  |   Homework

Re: program 4 question

New Message Reply About this list Date view Thread view Subject view Author view

Stephen Edwards (edwards@CS.VT.EDU)
Thu, 6 Dec 2001 08:52:58 -0500


Message-ID:  <3C0F783A.81A4E924@cs.vt.edu>
Date:         Thu, 6 Dec 2001 08:52:58 -0500
From: Stephen Edwards <edwards@CS.VT.EDU>
Subject:      Re: program 4 question

Scott Preddy wrote:
>
> The test file you have says the result of -8 rem 71 is -8. However,
> my version of prolog and my calculator is saying that it is 63. It seems
> that both answers could be correct. How should I implement this in this
> project?

Implement it as described in the program assignment itself (see the
section on "Implementing irem"). If you use the built-in "mod" operator,
you'll find that "Answer is -8 mod 71" binds Answer to -8.

To get 63 out of your Prolog implementation, you must have tried your
hand at implementing your own version of mod. I admire the effort,
but that is more than is expected for this assignment (use the built
in command instead). This also means that the Prolog version will
get slightly different results than the Sceme implementation your wrote
for Program 2 (Prolog's % does not work like Scheme's remainder, and
rounding in the two languages works differently as well).

Also, note that there are several different strategies for implementing
modulus and remainder functions; many implementers fail to consider
how to deal with negative numbers in a number-theoretic way. Scheme does
a better job than most (providing both of the commonly used definitions). C,
C++, Java, dn Perl provide one of the commonly used definitions.
SWI-Prolog's implementation is a bit "broken" from a mathematical point
of view, but that's OK for this assignment as long as you follow the
instructions.

Incidentally, for those of you who were in class yesterday, a mismatch
between the Perl implementation of % and the Prolog implementation of
mod was causing difficulties with getting my solution to agree with
the Curator :-).

                                -- Steve

--
Stephen Edwards            604 McBryde Hall          Dept. of Computer Science
e-mail      : edwards@cs.vt.edu           U.S. mail: Virginia Tech (VPI&SU)
office phone: (540)-231-5723                         Blacksburg, VA  24061-0106
-------------------------------------------------------------------------------


New Message Reply About this list Date view Thread view Subject view Author view

Home  |   Notes  |   Languages  |   Programs  |   Homework
copyright © 2001 Virginia Tech, ALL RIGHTS RESERVED
Class site maintained by Stephen H. Edwards <edwards@cs.vt.edu>