, , (. 20,2). (.. ), , . -
II. Prolog
, , . 1, , : " , , ?" , , .
S1 !
S2 B2
SwVolt BulbVolt
Mg>-
^"!
S3
?3
1
. 20.2. , ,
, 2, : " , 2 , 3 , , 3 ?" , 3, , . 2, 2 , 2 . 2 , 2 . , 3 . 3. , 2 , 3 ; , 3 .
"pos" (), "zero" () "neq" (). , X , .
X > D, pos X = , X < 0, neg
, . - : -, 0, -, 0. , . X + V = Z , : qsurat X, , ZI
qsum . , , , : asurnt pos, pos pos}.
|
|
20.
:
qsumi , neg, pos). qsumj pos, neg, zero). qsum(pos, neg, neg).
(). - , , , . .
, 20.1, . . ( ) : switch(SwitchPositicn, voltage, Current) bulb(BulbState, Lightness, voitage, Current)
SwitchPosition - , Voltage - , Current -, BulbState , a Lightness .
20.1.
% : neg, zero, pos
%
% switch! SwitchPosition, Voltage, Current)
switch* on, zero, ftnyCurrent}. % - switch! off, Anyvoltage, zero). % -
% :
% bulb[ BulbState, Lightness, Voltage, Current)'
bulb(blown, dark, AnyVoltage, zero). bulb{ ok, light, pos, pos). bulbf ok, light, neg, neg). bulb (ok, dark, zero, zero),
% , I .
circuit1(SuitchPos, BulbState, Lightness):-switch,- SwitchPos, SwVolt, Curr), bulb(BulbState, Lightness, BulbVolt, Curr), qsum(SwVolt, BulbVolt, pos)- % pos
, , %
Circuit2[ Swl, Sw2, Sw3, Bl, 2, , LI, L2, L3):-switcht Swl, vswl, CD, bulb! Bl, LI, VB1, Cl), switch) Sw2, VSw2, C2), bulb(B2, L2, VB2, C2), qsum(VSw2, VE2, V3\, switcht 3w3, V3, CSw3), bulb(E3, L3, V3, CB3), qsum(VEwl, VB1, VI), qsumt VI, V3, pos), qsumf CSw3, CB3, C3), qsumf C2, C3, Cl).
II. Prolog
% qsuml Ql, Q2, Q3):
% 03 = Ql + Q2,
% [pos,zero,neg]
qsumt pos, pos, pos).
qsumt pos, zero, pos).
qsumt pos, neg, pos).
qsumt pos, neg, zero).
qsumt pos, neg, neg).
qsumt zero, pos, pos).
qsumt zero, zero, zero).
qsumt zero, neg, neg).
qsumt neg, pos, pos).
qsumt neg, pos, zero),
qsumt neg, pos, neg).
qsumt neg, zeror neg).
qsumt neg, neg, neg].
Prolog. , (off) (zero), , . switch! off, AnyVoltage, ).
(blown) (dark), , , . bulbt blown, dark, AnyVoltage, zero).
|
|
(intact) , , , . , , . , , . , , : Voltage - Resistance * Current
Resistance , Voltage Current .
, . , , : circuitl(SwPos, Bulbstate, Lightness)
, SwPos, BulbState Lightness, circuitl. , , , circuitl. , , .
1. .
2. .
3. ( ): + = .
, .
2 (circuit2), , .
, , 20.1, .
20.
" " ( ), ( - ). , , (on) , (ok)?
1- circuit2 (on,on,on,ok,ok,ok,Ll,L2,L3).
LI = light L2 = dark L3 = dark
, ( , ?). , 1 , 3 , 3 , ?
?- circuit2(_, _, off, Bl, B2, , light, _, dark). Bl - ok B2 = ok = blown
, ? , , 3, , ?
?- circijit2 (SwPosl, SwPos2, SwPos3, ok, ok, ok, _, _, light).
SwPosl = on
EwPos2 = on
5wPos3 = off;
SwPosl = on
SwPos2 = off
SwFos3 = off
20.1. :
qmultf ft, ,
= *, , pos, zero neg.
20.2. :
resistor(Voltage, Current) diode(Voltage, Current)
. Voltage Current . , ,