From: ··············@web.de
Subject: How to create/fill easily a state transition table?
Date: 
Message-ID: <1176283607.468657.40890@l77g2000hsb.googlegroups.com>
Hallo!

I want to create a state transition table with boolean values like the
following one. The output values depend on specific boolean rules that
I defined.

A-in     B-in     C-in     D-in  ... |    A-out    B-out    C-out
D-out ....
--------------------------------------------------------------------------------------------------
  0       0        0           0         |   0            0
1            0
  0       0        0           1         |   0            0
0            0
  0       0        1           0         |   0            1
1            0
  0       0        1           1         |   0            1
0            0
  0       1        0           0         |   0            0
1            0
  0       1        0           1         |   0            1
0            0
  0       1        1           0         |   0            0
1            0
.... etc.

Does anybody has an idea to fill the input values of the elements (A-
in, B-in,...) of a complete state transition table? Now I use many
nested loops, but I would like to avert the loops. The loops will
always depend on the number of elements, but I have different state
transition tables with different numbers of elements (e.g. one stt
with 3 elements A,B,C; one stt with 10 elements: A-J and so on). I'd
like to use a function (mapping/apply?) to be independent of the
number of elements.

I will be very grateful if anybody has an idea.

Daniela

From: Pascal Bourguignon
Subject: Re: How to create/fill easily a state transition table?
Date: 
Message-ID: <87y7kzkuoq.fsf@voyager.informatimago.com>
··············@web.de writes:

> Hallo!
>
> I want to create a state transition table with boolean values like the
> following one. The output values depend on specific boolean rules that
> I defined.
>
> A-in     B-in     C-in     D-in  ... |    A-out    B-out    C-out
> D-out ....
> --------------------------------------------------------------------------------------------------
>   0       0        0           0         |   0            0
> 1            0
>   0       0        0           1         |   0            0
> 0            0
>   0       0        1           0         |   0            1
> 1            0
>   0       0        1           1         |   0            1
> 0            0
>   0       1        0           0         |   0            0
> 1            0
>   0       1        0           1         |   0            1
> 0            0
>   0       1        1           0         |   0            0
> 1            0
> .... etc.
>
> Does anybody has an idea to fill the input values of the elements (A-
> in, B-in,...) of a complete state transition table? Now I use many
> nested loops, but I would like to avert the loops. The loops will
> always depend on the number of elements, but I have different state
> transition tables with different numbers of elements (e.g. one stt
> with 3 elements A,B,C; one stt with 10 elements: A-J and so on). I'd
> like to use a function (mapping/apply?) to be independent of the
> number of elements.
>
> I will be very grateful if anybody has an idea.

You can merely count with integers from 0 to 2^(number of inputs)-1,
and convert the counter to binary to write out the booleans.  Isn't it
how you write these tables by hand, counting in base 2?


For an example, see the source of this emacs lisp command  karnaugh,
in: http://darcs.informatimago.com/emacs/pjb-sources.el

(insert
 (karnaugh  '(a-in b-in c-in d-in) 
            '((a-out . (lambda (a b c d) (and a b c d)))
              (b-out . (lambda (a b c d) (or a b c d)))
              (c-out . (lambda (a b c d) (xor (and a b) (or c d))))
             d-out) '("1" . "0") '("X" . ".")))

+------+------+------+------+-------+-------+-------+-------+
| a-in | b-in | c-in | d-in | a-out | b-out | c-out | d-out |
+------+------+------+------+-------+-------+-------+-------+
|   0  |   0  |   0  |   0  |   .   |   .   |   X   |       |
|   0  |   0  |   0  |   1  |   X   |   .   |   X   |       |
|   0  |   0  |   1  |   0  |   X   |   .   |   X   |       |
|   0  |   0  |   1  |   1  |   X   |   .   |   .   |       |
|   0  |   1  |   0  |   0  |   X   |   .   |   .   |       |
|   0  |   1  |   0  |   1  |   X   |   .   |   .   |       |
|   0  |   1  |   1  |   0  |   X   |   .   |   .   |       |
|   0  |   1  |   1  |   1  |   X   |   .   |   X   |       |
|   1  |   0  |   0  |   0  |   X   |   .   |   .   |       |
|   1  |   0  |   0  |   1  |   X   |   .   |   .   |       |
|   1  |   0  |   1  |   0  |   X   |   .   |   .   |       |
|   1  |   0  |   1  |   1  |   X   |   .   |   X   |       |
|   1  |   1  |   0  |   0  |   X   |   .   |   .   |       |
|   1  |   1  |   0  |   1  |   X   |   .   |   .   |       |
|   1  |   1  |   1  |   0  |   X   |   .   |   .   |       |
|   1  |   1  |   1  |   1  |   X   |   X   |   X   |       |
+------+------+------+------+-------+-------+-------+-------+
nil



-- 
__Pascal Bourguignon__
http://www.informatimago.com
http://pjb.ogamita.org
From: Rob St. Amant
Subject: Re: How to create/fill easily a state transition table?
Date: 
Message-ID: <evioga$n3n$1@blackhelicopter.databasix.com>
Pascal Bourguignon <···@informatimago.com> writes:

> ··············@web.de writes:
>
>> Hallo!
>>
>> I want to create a state transition table with boolean values like the
>> following one. The output values depend on specific boolean rules that
>> I defined.
>>
>> A-in     B-in     C-in     D-in  ... |    A-out    B-out    C-out
>> D-out ....
>> --------------------------------------------------------------------------------------------------
>>   0       0        0           0         |   0            0
>> 1            0
>>   0       0        0           1         |   0            0
>> 0            0
>>   0       0        1           0         |   0            1
>> 1            0
>>   0       0        1           1         |   0            1
>> 0            0
>>   0       1        0           0         |   0            0
>> 1            0
>>   0       1        0           1         |   0            1
>> 0            0
>>   0       1        1           0         |   0            0
>> 1            0
>> .... etc.
>>
>> Does anybody has an idea to fill the input values of the elements (A-
>> in, B-in,...) of a complete state transition table? Now I use many
>> nested loops, but I would like to avert the loops. The loops will
>> always depend on the number of elements, but I have different state
>> transition tables with different numbers of elements (e.g. one stt
>> with 3 elements A,B,C; one stt with 10 elements: A-J and so on). I'd
>> like to use a function (mapping/apply?) to be independent of the
>> number of elements.
>>
>> I will be very grateful if anybody has an idea.
>
> You can merely count with integers from 0 to 2^(number of inputs)-1,
> and convert the counter to binary to write out the booleans.  Isn't it
> how you write these tables by hand, counting in base 2?

The logic of this little hacked-together fragment may help:

CL-USER> (let* ((states '(a b c))
		(n (length states))
		(zero-vector (make-array n :initial-element 0)))
	   (format t "~{~A~T~}~%" states)
	   (dotimes (row-counter (expt 2 n))
	     (let ((state-vector (copy-seq zero-vector)))
	       (dotimes (j n)
		 (when (logbitp j row-counter)
		   (setf (elt state-vector j) 1)))
	       (map nil #'(lambda (e)
			    (format t "~A~T" e))
		    state-vector)
	       (terpri))))
A B C 
0 0 0 
1 0 0 
0 1 0 
1 1 0 
0 0 1 
1 0 1 
0 1 1 
1 1 1 
NIL