Another 'program' generated from the interest sparked in writing the Alternate Languages essay! This one is a very simple Expert System written in Prolog. It has a database of 19 aircraft with the manufactuer, designation, nickname, primary role, year first flown, length, number of screw, and maximum speed in terms of the speed of sound. If you would like to download the program in its entirety, you can do so here. When I created the program, I had the final goal in mind. I created a hypothetical situation - France wants to buy a new aircraft. It has to be a supersonic, multirole fighter. It also has to be relatively modern (flown after 1975), and also be small enough to perhaps work off carriers (under 17m). On to the program: DOMAINS maker, designation, nickname, role, plane = symbol yearFlown, crew = integer length, mach = realDomains are simply aliases for types. A maker is a symbol, as is designation etc. This merely makes the program more readable - and it imposes a few restrictions which can be useful (if not, a little annoying though). a 'maker' does not equal a 'designation' even though the both of them are symbols. You will actually get a compiler error if you substitute the two. This does, though, make sure you are consistent.
PREDICATES
nondeterm Aircraft(maker, designation, nickname,
role, yearFlown, length, crew, mach)
nondeterm Stealth(designation)
nondeterm Multirole(designation)
nondeterm Supersonic(designation)
The 'nondeterm' simply means these predicates are non-deterministic. Predicates are the 'templates' for the rules and fact you will use to build the database.
CLAUSES
...
Aircraft("SEPECAT", "Jaguar", "Jaguar", "Strike", 1968, 16.83, 1, 1.6).
Aircraft("Panavia", "Tornado", "Tornado", "Strike", 1974, 16.72, 2, 2.2).
...
Aircraft("Northrop Grumman", "B-2", "Spirit", "Bomber", 1989, 21.03, 3, 0.9).
Aircraft("Rockwell", "B-1B", "Lancer", "Bomber", 1984, 44.81, 4, 1.25).
Stealth("F-117").
...
Multirole("Mirage 2000").
...
Supersonic(Name):- Aircraft(_,Name,_,_,_,_,_,Mach), Mach >= 1.0.
I've cut out most of the database, because they all look similar. You can see how data is entered into the 'database', then how some aircraft like the F-117 are further modified by being specified as being either stealthy or multirole. The 'supersonic' rule specifies that an aircraft is supersonic if its mach number is greater than or equal to 1 (Mach 1 is the speed of sound).
GOAL Multirole(Designation), Supersonic(Designation), Aircraft(Maker, Designation,_,_,Year,Length,_,_), Year > 1975, Length < 17.00.This is the final goal, in Prolog, as I stated before the code. France wants a multirole, supersonic fighter. The first year flown has to be greater than 1975, and the length less than 17 metres. Run the program now - note that it is only coincidence that both the fighters Prolog finds are French in origin! Please feel free to extent this program and send changes to me. Enjoy.
|