Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program that defines a relation max(X,Y,Max) where Max is the greater of X and Y

Posted By: Milind Mishra     Category: Artificial Intelligence     Views: 2793

Prolog program that defines a relation max(X,Y,Max) where Max is the greater of X and Y.

Code for Prolog program that defines a relation max(X,Y,Max) where Max is the greater of X and Y in Artificial Intelligence

domains
    x = integer
    
predicates
    max(x,x,x)
    
clauses
    max(X,Y,Max) :-
        X > Y,!,
        Max = X.
        
    max(X,Y,Max) :-
        Max = Y.
        
Output :

Goal: max(2,3,Max)
Max=3
1 Solution

Goal: max(-1,-4,Max)
Max=-1
1 Solution
  
Share: 



Milind Mishra
Milind Mishra author of Prolog program that defines a relation max(X,Y,Max) where Max is the greater of X and Y is from India.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!