Difference Engine Number 2 Number 2 has arrived in California.  If we
ignore the considerable intellectual and engineering achievement in
its design, we can model it simply in J.

The state of the machine is given by an array of length n.  (In the
Babbage machine, n=8, and each cell holds an unsigned 31-digit
*decimal* integer, interpreted using 10's complements.)  There is a
single operation.  Each turn of the handle adds the contents of all
but the first array cell to the one immediately to its left.  The
output is given by a (printed) list of the successive values of the
first array element.  The whole process is equivalent to evaluating a
polynomial at equally spaced points.

   op=:+ 0,~ }.

    op^:(i.10) 0 1 2  NB. Debug output
 0  1 2
 1  3 2
 4  5 2
 9  7 2
16  9 2
25 11 2
36 13 2
49 15 2
64 17 2
81 19 2

   {."1 op^:(i.10) 0 1 2 NB. printed output
0 1 4 9 16 25 36 49 64 81

   {."1 op^:(i.10) 10#1
1 2 4 8 16 32 64 128 256 512

You can initialize the engine using the first few expected values as
follows:

   diff=: 2 -~/\ ]
   diffs=:3 : '{."1 diff^:(i.#y) y'
   {."1 op^:(i.20) diffs p: i.20
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71
   {."1 op^:(i.21) diffs p: i.20
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 370876

Perhaps not obviously, op is invertible.

    invop=:-/\.
    (-:[EMAIL PROTECTED]) ?. 10 # 10
1

and J gives

   (-/\.) b. _1
(+ 1&(|.!.0)) :.(-/\.)

which is obviously equivalent to the form above.


I am interested in two questions:

(1) Are there initializations for the Difference Engine that give
"unexpected" results?

(2) Can we modify the operation to give something different and
useful?  For example, a "quotient engine" has operation

   qop=:* 1,~ }.

and can correctly calculate powers.

   {."1 qop^:(i.10) 2 2
2 4 8 16 32 64 128 256 512 1024

Any ideas or suggestions would be welcome.

Best wishes,

John


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to