transport( X) :- public( X).
transport( X) :- private( X).
public( bus).
public( train).
public( airplane).
public( ship).
private( bicycle).
private( motorcycle).
private( car).
vehicle( bicycle).
vehicle( motorcycle).
vehicle( car).
vehicle( bus).
motor_vehicle( X) :- has_motor( X).
slow( bicycle).
eco-friendly( bicycle).
fast( car, mittel).
dangerous( car).
has_petrolengine( car).
fast( bus, rather).
has_petrolengine( bus).
fast( train, medium).
has_electricmotor( train).
fast( airplane, very).
has_petrolengine( airplane).
slow( ship).
has_dieselmotor( ship).
eco_hostile( X) :- has_petrolengine( X).
eco_hostile( X) :- has_dieselmotor( X).
eco_friendly( X) :- has_electricmotor( X).
safe( X) :- public( X).
has_motor( X) :- has_petrolengine( X).
has_motor( X) :- has_dieselmotor( X).
has_motor( X) :- has_electricmotor( X).
fast( X) :- fast( X, _).
Back to example 4.1
breakdown( flashover_arc).
breakdown( puncture_arc).
breakdown( surface_leakage).
cause( flashover_arc, high_voltage).
cause( high_voltage, lightning_strike).
cause( puncture_arc, faulty_material).
cause( puncture_arc, cracky_material).
cause( surface_leakage, 'surface is dirty and wet').
cause( surface_leakage, 'material is composite polymer').
consequence( Cause, Consequence) :- cause( Consequence, Cause).
consequence( puncture_arc, damage).
consequence( damage, 'replace insulator').
consequence( surface_leakage, creepage_path).
consequence( creepage_path, 'replace insulator').
Back to example 4.2
res( NW, R) :-
resistor( NW, R).
res( seq( NW1, NW2), R) :-
res( NW1, R1), res( NW2, R2), R is R1 + R2.
res( par( NW1, NW2), R) :-
res( NW1, R1), res( NW2, R2),
S is 1/R1 + 1/R2, R is 1/S.
Back to example 4.3
adder1( I1, I2, C_in, Out, C_out) :-
xor( I1, I2, X), and( I1, I2, A1), and( X, C_in, A2),
xor( X, C_in, Out), or( A1, A2, C_out).
adder_overflow( [], [], [], 0).
adder_overflow( [ I1| I1s], [ I2| I2s], [ O| Os], Overflow) :-
adder_overflow( I1s, I2s, Os, Carry),
adder1( I1, I2, Carry, O, Overflow).
adder( X, Y, [ OF| Z]) :-
adder_overflow( X, Y, Z, OF).
or( 0, 0, 0).
or( 0, 1, 1).
or( 1, 0, 1).
or( 1, 1, 1).
xor( 0, 0, 0).
xor( 0, 1, 1).
xor( 1, 0, 1).
xor( 1, 1, 0).
and( 0, 0, 0).
and( 0, 1, 0).
and( 1, 0, 0).
and( 1, 1, 1).
Back to example 4.4