The question Reads, "Write a Prolog program that finds the maximum of a list of numbers."
I have used the power of the internet to help find a solution that works but, I want to have an understanding of the program itself.
max_num([X],X).
max_num([X|Y],X):- max_num(Y,Z), X >= Z.
max_num([X|Y],A):- max_num(Y,A), A > X.
Line1:
max_num([X],X).
I understand that Line1 is defining the basic template of the question. The [X] defines the list and the other X represents the maximum value within that list.
Line2:
max_num([X|Y],X):- max_num(Y,Z), X >= Z.
This is where I lose track of things. I understand the first part, "max_num([X|Y],X)" and that it split the list into two parts, "A first half" and the "Second half" separated by the vertical line. and the X is just the Max Number? I am unsure at this point.
Line3: Well its just not even worth trying to comprehend now. Please comment below to help me understand the current logic of this program.
Best Regards.