% -*- Example Program <ex_10> Diagnosis of 10-cascaded ripple-adder cercuit -*-  
%     Copyright (C) 1997      Shohei Kato  

facts. 
val(Node2,V)	:- conn(Node1,Node2),val(Node1,V).
val(out(D),V) :- dev(D,and),ok(D),val(in(1,D),A),val(in(2,D),B),and(A,B,V).
val(out(D),V) :- dev(D,or),ok(D),val(in(1,D),A),val(in(2,D),B),or(A,B,V).
val(out(D),V) :- dev(D,xor),ok(D),val(in(1,D),A),val(in(2,D),B),xor(A,B,V).
val(out(D),1) :- dev(D,Ano),stuck_on(D).
val(out(D),0) :- dev(D,Ano),stuck_off(D).
and(0,0,0) :- true.
and(0,1,0) :- true.
and(1,0,0) :- true.
and(1,1,1) :- true.
xor(0,0,0) :- true.
xor(0,1,1) :- true.
xor(1,0,1) :- true.
xor(1,1,0) :- true.
or(0,0,0)  :- true.
or(0,1,1)  :- true.
or(1,0,1)  :- true.
or(1,1,1)  :- true.
dev(g10x,xor) :- true.
dev(g10z,xor) :- true.
dev(g101,and) :- true.
dev(g102,and) :- true.
dev(g10c,or)  :- true.
conn(in(1,x10),in(1,g10x)) :- true.
conn(in(1,y10),in(2,g10x)) :- true.
conn(in(1,x10),in(1,g101)) :- true.
conn(in(1,y10),in(2,g101)) :- true.
conn(out(g9c),in(2,g102)) :- true.
conn(out(g9c),in(2,g10z)) :- true.
conn(out(g10x),in(1,g10z)) :- true.
conn(out(g10x),in(1,g102)) :- true.
conn(out(g101),in(2,g10c)) :- true.
conn(out(g102),in(1,g10c)) :- true.
dev(g9x,xor) :- true.
dev(g9z,xor) :- true.
dev(g91,and) :- true.
dev(g92,and) :- true.
dev(g9c,or)  :- true.
conn(in(1,x9),in(1,g9x)) :- true.
conn(in(1,y9),in(2,g9x)) :- true.
conn(in(1,x9),in(1,g91)) :- true.
conn(in(1,y9),in(2,g91)) :- true.
conn(out(g8c),in(2,g92)) :- true.
conn(out(g8c),in(2,g9z)) :- true.
conn(out(g9x),in(1,g9z)) :- true.
conn(out(g9x),in(1,g92)) :- true.
conn(out(g91),in(2,g9c)) :- true.
conn(out(g92),in(1,g9c)) :- true.
dev(g8x,xor) :- true.
dev(g8z,xor) :- true.
dev(g81,and) :- true.
dev(g82,and) :- true.
dev(g8c,or)  :- true.
conn(in(1,x8),in(1,g8x)) :- true.
conn(in(1,y8),in(2,g8x)) :- true.
conn(in(1,x8),in(1,g81)) :- true.
conn(in(1,y8),in(2,g81)) :- true.
conn(out(g7c),in(2,g82)) :- true.
conn(out(g7c),in(2,g8z)) :- true.
conn(out(g8x),in(1,g8z)) :- true.
conn(out(g8x),in(1,g82)) :- true.
conn(out(g81),in(2,g8c)) :- true.
conn(out(g82),in(1,g8c)) :- true.
dev(g7x,xor) :- true.
dev(g7z,xor) :- true.
dev(g71,and) :- true.
dev(g72,and) :- true.
dev(g7c,or)  :- true.
conn(in(1,x7),in(1,g7x)) :- true.
conn(in(1,y7),in(2,g7x)) :- true.
conn(in(1,x7),in(1,g71)) :- true.
conn(in(1,y7),in(2,g71)) :- true.
conn(out(g6c),in(2,g72)) :- true.
conn(out(g6c),in(2,g7z)) :- true.
conn(out(g7x),in(1,g7z)) :- true.
conn(out(g7x),in(1,g72)) :- true.
conn(out(g71),in(2,g7c)) :- true.
conn(out(g72),in(1,g7c)) :- true.
dev(g6x,xor) :- true.
dev(g6z,xor) :- true.
dev(g61,and) :- true.
dev(g62,and) :- true.
dev(g6c,or)  :- true.
conn(in(1,x6),in(1,g6x)) :- true.
conn(in(1,y6),in(2,g6x)) :- true.
conn(in(1,x6),in(1,g61)) :- true.
conn(in(1,y6),in(2,g61)) :- true.
conn(out(g5c),in(2,g62)) :- true.
conn(out(g5c),in(2,g6z)) :- true.
conn(out(g6x),in(1,g6z)) :- true.
conn(out(g6x),in(1,g62)) :- true.
conn(out(g61),in(2,g6c)) :- true.
conn(out(g62),in(1,g6c)) :- true.
dev(g5x,xor) :- true.
dev(g5z,xor) :- true.
dev(g51,and) :- true.
dev(g52,and) :- true.
dev(g5c,or)  :- true.
conn(in(1,x5),in(1,g5x)) :- true.
conn(in(1,y5),in(2,g5x)) :- true.
conn(in(1,x5),in(1,g51)) :- true.
conn(in(1,y5),in(2,g51)) :- true.
conn(out(g4c),in(2,g52)) :- true.
conn(out(g4c),in(2,g5z)) :- true.
conn(out(g5x),in(1,g5z)) :- true.
conn(out(g5x),in(1,g52)) :- true.
conn(out(g51),in(2,g5c)) :- true.
conn(out(g52),in(1,g5c)) :- true.
dev(g4x,xor) :- true.
dev(g4z,xor) :- true.
dev(g41,and) :- true.
dev(g42,and) :- true.
dev(g4c,or)  :- true.
conn(in(1,x4),in(1,g4x)) :- true.
conn(in(1,y4),in(2,g4x)) :- true.
conn(in(1,x4),in(1,g41)) :- true.
conn(in(1,y4),in(2,g41)) :- true.
conn(out(g3c),in(2,g42)) :- true.
conn(out(g3c),in(2,g4z)) :- true.
conn(out(g4x),in(1,g4z)) :- true.
conn(out(g4x),in(1,g42)) :- true.
conn(out(g41),in(2,g4c)) :- true.
conn(out(g42),in(1,g4c)) :- true.
dev(g3x,xor) :- true.
dev(g3z,xor) :- true.
dev(g31,and) :- true.
dev(g32,and) :- true.
dev(g3c,or)  :- true.
conn(in(1,x3),in(1,g3x)) :- true.
conn(in(1,y3),in(2,g3x)) :- true.
conn(in(1,x3),in(1,g31)) :- true.
conn(in(1,y3),in(2,g31)) :- true.
conn(out(g2c),in(2,g32)) :- true.
conn(out(g2c),in(2,g3z)) :- true.
conn(out(g3x),in(1,g3z)) :- true.
conn(out(g3x),in(1,g32)) :- true.
conn(out(g31),in(2,g3c)) :- true.
conn(out(g32),in(1,g3c)) :- true.
dev(g2x,xor) :- true.
dev(g2z,xor) :- true.
dev(g21,and) :- true.
dev(g22,and) :- true.
dev(g2c,or)  :- true.
conn(in(1,x2),in(1,g2x)) :- true.
conn(in(1,y2),in(2,g2x)) :- true.
conn(in(1,x2),in(1,g21)) :- true.
conn(in(1,y2),in(2,g21)) :- true.
conn(out(g1c),in(2,g22)) :- true.
conn(out(g1c),in(2,g2z)) :- true.
conn(out(g2x),in(1,g2z)) :- true.
conn(out(g2x),in(1,g22)) :- true.
conn(out(g21),in(2,g2c)) :- true.
conn(out(g22),in(1,g2c)) :- true.
dev(g1x,xor) :- true.
dev(g1z,xor) :- true.
dev(g11,and) :- true.
dev(g12,and) :- true.
dev(g1c,or)  :- true.
conn(in(1,x1),in(1,g1x)) :- true.
conn(in(1,y1),in(2,g1x)) :- true.
conn(in(1,x1),in(1,g11)) :- true.
conn(in(1,y1),in(2,g11)) :- true.
conn(out(g0c),in(2,g12)) :- true.
conn(out(g0c),in(2,g1z)) :- true.
conn(out(g1x),in(1,g1z)) :- true.
conn(out(g1x),in(1,g12)) :- true.
conn(out(g11),in(2,g1c)) :- true.
conn(out(g12),in(1,g1c)) :- true.
dev(g0c,or)  :- true.
val(in(1,x10),0) :- true.
val(in(1,y10),1) :- true.
val(in(1,x9),0) :- true.
val(in(1,y9),1) :- true.
val(in(1,x8),0) :- true.
val(in(1,y8),1) :- true.
val(in(1,x7),0) :- true.
val(in(1,y7),1) :- true.
val(in(1,x6),0) :- true.
val(in(1,y6),1) :- true.
val(in(1,x5),0) :- true.
val(in(1,y5),1) :- true.
val(in(1,x4),0) :- true.
val(in(1,y4),1) :- true.
val(in(1,x3),0) :- true.
val(in(1,y3),1) :- true.
val(in(1,x2),0) :- true.
val(in(1,y2),1) :- true.
val(in(1,x1),0) :- true.
val(in(1,y1),1) :- true.
val(out(g0c),0) :- true.
facts. 
hypotheses. 
ok(g10x) :- true.   0.500.
ok(g10z) :- true.   0.500.
ok(g101) :- true.   0.500.
ok(g102) :- true.   0.500.
ok(g10c) :- true.   0.500.
stuck_on(g10x) :- true.   0.130.
stuck_on(g10z) :- true.   0.130.
stuck_on(g101) :- true.   0.150.
stuck_on(g102) :- true.   0.150.
stuck_on(g10c) :- true.   0.120.
stuck_off(g10x) :- true.  0.370.
stuck_off(g10z) :- true.  0.370.
stuck_off(g101) :- true.  0.350.
stuck_off(g102) :- true.  0.350.
stuck_off(g10c) :- true.  0.380.
ok(g9x) :- true.   0.500.
ok(g9z) :- true.   0.500.
ok(g91) :- true.   0.500.
ok(g92) :- true.   0.500.
ok(g9c) :- true.   0.500.
stuck_on(g9x) :- true.   0.110.
stuck_on(g9z) :- true.   0.110.
stuck_on(g91) :- true.   0.140.
stuck_on(g92) :- true.   0.140.
stuck_on(g9c) :- true.   0.150.
stuck_off(g9x) :- true.  0.390.
stuck_off(g9z) :- true.  0.390.
stuck_off(g91) :- true.  0.360.
stuck_off(g92) :- true.  0.360.
stuck_off(g9c) :- true.  0.350.
ok(g8x) :- true.   0.500.
ok(g8z) :- true.   0.500.
ok(g81) :- true.   0.500.
ok(g82) :- true.   0.500.
ok(g8c) :- true.   0.500.
stuck_on(g8x) :- true.   0.150.
stuck_on(g8z) :- true.   0.150.
stuck_on(g81) :- true.   0.130.
stuck_on(g82) :- true.   0.130.
stuck_on(g8c) :- true.   0.140.
stuck_off(g8x) :- true.  0.350.
stuck_off(g8z) :- true.  0.350.
stuck_off(g81) :- true.  0.370.
stuck_off(g82) :- true.  0.370.
stuck_off(g8c) :- true.  0.360.
ok(g7x) :- true.   0.500.
ok(g7z) :- true.   0.500.
ok(g71) :- true.   0.500.
ok(g72) :- true.   0.500.
ok(g7c) :- true.   0.500.
stuck_on(g7x) :- true.   0.170.
stuck_on(g7z) :- true.   0.170.
stuck_on(g71) :- true.   0.130.
stuck_on(g72) :- true.   0.130.
stuck_on(g7c) :- true.   0.110.
stuck_off(g7x) :- true.  0.330.
stuck_off(g7z) :- true.  0.330.
stuck_off(g71) :- true.  0.370.
stuck_off(g72) :- true.  0.370.
stuck_off(g7c) :- true.  0.390.
ok(g6x) :- true.   0.500.
ok(g6z) :- true.   0.500.
ok(g61) :- true.   0.500.
ok(g62) :- true.   0.500.
ok(g6c) :- true.   0.500.
stuck_on(g6x) :- true.   0.150.
stuck_on(g6z) :- true.   0.150.
stuck_on(g61) :- true.   0.100.
stuck_on(g62) :- true.   0.100.
stuck_on(g6c) :- true.   0.120.
stuck_off(g6x) :- true.  0.350.
stuck_off(g6z) :- true.  0.350.
stuck_off(g61) :- true.  0.400.
stuck_off(g62) :- true.  0.400.
stuck_off(g6c) :- true.  0.380.
ok(g5x) :- true.   0.500.
ok(g5z) :- true.   0.500.
ok(g51) :- true.   0.500.
ok(g52) :- true.   0.500.
ok(g5c) :- true.   0.500.
stuck_on(g5x) :- true.   0.140.
stuck_on(g5z) :- true.   0.140.
stuck_on(g51) :- true.   0.150.
stuck_on(g52) :- true.   0.150.
stuck_on(g5c) :- true.   0.120.
stuck_off(g5x) :- true.  0.360.
stuck_off(g5z) :- true.  0.360.
stuck_off(g51) :- true.  0.350.
stuck_off(g52) :- true.  0.350.
stuck_off(g5c) :- true.  0.380.
ok(g4x) :- true.   0.500.
ok(g4z) :- true.   0.500.
ok(g41) :- true.   0.500.
ok(g42) :- true.   0.500.
ok(g4c) :- true.   0.500.
stuck_on(g4x) :- true.   0.150.
stuck_on(g4z) :- true.   0.150.
stuck_on(g41) :- true.   0.140.
stuck_on(g42) :- true.   0.140.
stuck_on(g4c) :- true.   0.110.
stuck_off(g4x) :- true.  0.350.
stuck_off(g4z) :- true.  0.350.
stuck_off(g41) :- true.  0.360.
stuck_off(g42) :- true.  0.360.
stuck_off(g4c) :- true.  0.390.
ok(g3x) :- true.   0.500.
ok(g3z) :- true.   0.500.
ok(g31) :- true.   0.500.
ok(g32) :- true.   0.500.
ok(g3c) :- true.   0.500.
stuck_on(g3x) :- true.   0.130.
stuck_on(g3z) :- true.   0.130.
stuck_on(g31) :- true.   0.120.
stuck_on(g32) :- true.   0.120.
stuck_on(g3c) :- true.   0.150.
stuck_off(g3x) :- true.  0.370.
stuck_off(g3z) :- true.  0.370.
stuck_off(g31) :- true.  0.380.
stuck_off(g32) :- true.  0.380.
stuck_off(g3c) :- true.  0.350.
ok(g2x) :- true.   0.500.
ok(g2z) :- true.   0.500.
ok(g21) :- true.   0.500.
ok(g22) :- true.   0.500.
ok(g2c) :- true.   0.500.
stuck_on(g2x) :- true.   0.150.
stuck_on(g2z) :- true.   0.150.
stuck_on(g21) :- true.   0.100.
stuck_on(g22) :- true.   0.100.
stuck_on(g2c) :- true.   0.110.
stuck_off(g2x) :- true.  0.350.
stuck_off(g2z) :- true.  0.350.
stuck_off(g21) :- true.  0.400.
stuck_off(g22) :- true.  0.400.
stuck_off(g2c) :- true.  0.390.
ok(g1x) :- true.   0.500.
ok(g1z) :- true.   0.500.
ok(g11) :- true.   0.500.
ok(g12) :- true.   0.500.
ok(g1c) :- true.   0.500.
stuck_on(g1x) :- true.   0.170.
stuck_on(g1z) :- true.   0.170.
stuck_on(g11) :- true.   0.190.
stuck_on(g12) :- true.   0.190.
stuck_on(g1c) :- true.   0.210.
stuck_off(g1x) :- true.  0.330.
stuck_off(g1z) :- true.  0.330.
stuck_off(g11) :- true.  0.310.
stuck_off(g12) :- true.  0.310.
stuck_off(g1c) :- true.  0.290.
ok(g0c) :- true.   0.500.
stuck_on(g0c) :- true.   0.150.
stuck_off(g0c) :- true.   0.350.
hypotheses. 
consistency_condition. 
false :- ok(D),on(D).
false :- ok(D),off(D).
false :- on(D),off(D).
consistency_condition. 
observations. 
false :- val(out(g10z),1),val(out(g9z),1),val(out(g8z),1),val(out(g7z),1),val(out(g6z),1),val(out(g5z),1),val(out(g4z),1),val(out(g3z),1),val(out(g2z),1),val(out(g1z),1),val(out(g0c),1).
observations. 
