Why does this not work?

Robin Munn rmunn at pobox.com
Thu Jan 9 17:58:00 EST 2003


Tetsuo <member16943 at dbforums.com> wrote:
> 
> Thanks.
> 
> Can you also help me figure out how to make it a real simulation of a
> circuit, so it would calculate the answers, not just use what I tell it?

I can't spend the time right now to do this in detail, but here are a
few ideas I had:

When you say "a circuit", how far down (conceptually) do you want to go?
All the way down to the level of transistors? That would make for a
really *hairy* simulation. :-) No, what you probably want is to go down
to the simulation of lgoc gates like "AND", "OR", "NAND", etc. In that
case, here's what I suggest.

Write a set of functions "gate_and(a,b)", "gate_or(a,b)", etc. Use some
prefix like gate_ to avoid a conflict with "and" and "or" which are
reserved words. Like so:

    def gate_and(a,b):
        return a and b

    def gate_or(a,b):
        return a or b

    def gate_nand(a,b):
        return not (a and b)

and so on. Then, to simulate the following circuit:

    A ---+--\
         |AND>--+--\
    B ---+--/   |   \
                |NAND>--- out
                |   /
    C ----------+--/

You would write something like this:

    out = gate_nand(c, gate_and(a,b))

Hope this gives you some ideas.

-- 
Robin Munn <rmunn at pobox.com>
http://www.rmunn.com/
PGP key ID: 0x6AFB6838    50FF 2478 CFFB 081A 8338  54F7 845D ACFD 6AFB 6838




More information about the Python-list mailing list