Różnice

Różnice między wybraną wersją a wersją aktualną.

Odnośnik do tego porównania

pl:prolog:pllib:analogy [2019/06/27 15:50] (aktualna)
Linia 1: Linia 1:
 +====== Analogy ======
 +{{tag>​comparing geometry}}
 +===== Description =====
 +A program solving geometric analogies
 +
 +**Source**: ​ The Art of Prolog
 +===== Download =====
 +Program source code: {{analogy.pl}}
 +===== Listing =====
 +<code prolog>
 +/*
 +   ​analogy(Pair1,​Pair2,​Answers) :-
 + An analogy holds between the pairs of figures Pair1 and Pair2.
 + The second element of Pair2 is one of the possible Answers.
 +*/
 +:- op(100,​xfx,​[is_to]).
 +
 +analogy(A is_to B,C is_to X,Answers) :-
 +    match(A,​B,​Match),​
 +    match(C,​X,​Match),​
 +    member(X,​Answers).
 +
 +match(inside(Figure1,​Figure2),​inside(Figure2,​Figure1),​invert).
 +match(above(Figure1,​Figure2),​above(Figure2,​Figure1),​invert).
 +
 +   /​* ​ Testing and data */
 +
 +:- op(40,​xfx,​[is_to]).
 +
 +test_analogy(Name,​X) :-
 +    figures(Name,​A,​B,​C),​
 +    answers(Name,​Answers),​
 +    analogy(A is_to B,C is_to X,Answers).
 +
 +figures(test1,​inside(square,​triangle),​inside(triangle,​square),​
 + inside(circle,​square)).
 +answers(test1,​[inside(circle,​triangle),​inside(square,​circle),​
 + inside(triangle,​square)]).
 +
 +% Program 14.13: A program solving geometric analogies
 +% ?- test_analogy(test1,​X).</​code>​
 +===== Comments =====
  
pl/prolog/pllib/analogy.txt · ostatnio zmienione: 2019/06/27 15:50 (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