And gate

Description

A circuit for a logical and-gate

Source: The Art of Prolog

Download

Program source code: and_gate.pl

Listing

resistor(power,n1).
resistor(power,n2).
 
transistor(n2,ground,n1).
transistor(n3,n4,n2).
transistor(n5,ground,n4).
 
 
/*
inverter(Input,Output) :-
	Output is the inversion of Input.
*/
inverter(Input,Output) :-
	transistor(Input,ground,Output),
	resistor(power,Output).
 
/*
nand_gate(Input1,Input2,Output):-
   Output is the logical nand of Input1 and Input2.
*/
 
nand_gate(Input1,Input2,Output) :-
	transistor(Input1,X,Output),
	transistor(Input2,ground,X),
	resistor(power,Output).
 
/*
and_gate(Input1,Input2,Output):-
  Output is the logical and of Input1 and Input2.		     
*/
 
and_gate(Input1,Input2,Output) :-
	nand_gate(Input1,Input2,X),
	inverter(X,Output).
 
%Program 2.2: A circuit for a logical and-gate

Comments

pl/prolog/pllib/and_gate.txt · ostatnio zmienione: 2017/07/17 08:08 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0