Prolog error

Hi experts ,

Please advise what is wrong with this code.

Write a recursive Prolog procedure triangle(M,N) that determines the number of balls N in a triangle with M balls in the bottom level. Each level has one ball fewer than the previous level. The top level (base case) contains only 1 ball.

Base case

assert(triangle(1, 1)).

assert(triangle(M, N) :-

M > 1,

M1 is M – 1,

assert(triangle(M1 , N1),

N is N1 + M,

The brackets are mis-matched.

Also, M cannot be deprecated - use e.g. M0 is M - 1 instead.

Example:

?- assert((faster(X,Y) :- fast(X), slow(Y))).
true.

?- listing(faster).
:- dynamic faster/2.

faster(A, B) :-
    fast(A),
    slow(B).

Why use assert/1 at all? Would normally write the code in a program.

executed all this commands, all of them do return true.Can you kindly please guide me using M and N, I can see that M=X and N=Y but I want to be relevant to the question.

Using assert/1 for this makes no sense. Noboby would tell a beginner to assert predicates unless they were a sadist :grinning_face:

Stop using assert and write a normal program.