Right so, I tried writing the same code and it showed an error that essentially meant that I was trying to overwrite the already defined member predicate. The error went away when I changed the name of the predicate to ismember.
Hi, First of all, your videos are great and thank you for these amazing videos. You are doing a great job. I am trying to understand how the search tree looks like while backtracking during recursion and I am kind of lost. Say for Example the below lines of code, removes all the occurrences of an element from a list : remove_all(_, [], []). remove_all(El, [El|Tail], Tail2):- remove_all(El, Tail, Tail2). remove_all(El, [Head|Tail], [Head|Tail2]):- not(El = Head), remove_all(El, Tail, Tail2). Now I query the following ?- remove_all( 2, [1,4,2,3,5,2,7,2], X). I used the online SWISH Prolog to execute it with the trace and I got the following tree Call:remove_all(2, [1, 4, 2, 3, 5, 2, 7, 2], _4896) Call:not(2=1) Exit:not('10758ac0-dc91-4335-a0d8-48b7b11776c0' : (2=1)) Call:remove_all(2, [4, 2, 3, 5, 2, 7, 2], _5128) Call:not(2=4) Exit:not('10758ac0-dc91-4335-a0d8-48b7b11776c0' : (2=4)) Call:remove_all(2, [2, 3, 5, 2, 7, 2], _5146) Call:remove_all(2, [3, 5, 2, 7, 2], _5146) Call:not(2=3) Exit:not('10758ac0-dc91-4335-a0d8-48b7b11776c0' : (2=3)) Call:remove_all(2, [5, 2, 7, 2], _5164) Call:not(2=5) Exit:not('10758ac0-dc91-4335-a0d8-48b7b11776c0' : (2=5)) Call:remove_all(2, [2, 7, 2], _5182) Call:remove_all(2, [7, 2], _5182) Call:not(2=7) Exit:not('10758ac0-dc91-4335-a0d8-48b7b11776c0' : (2=7)) Call:remove_all(2, [2], _5200) Call:remove_all(2, [], _5200) Exit:remove_all(2, [], []) Exit:remove_all(2, [2], []) Exit:remove_all(2, [7, 2], [7]) Exit:remove_all(2, [2, 7, 2], [7]) Exit:remove_all(2, [5, 2, 7, 2], [5, 7]) Exit:remove_all(2, [3, 5, 2, 7, 2], [3, 5, 7]) Exit:remove_all(2, [2, 3, 5, 2, 7, 2], [3, 5, 7]) Exit:remove_all(2, [4, 2, 3, 5, 2, 7, 2], [4, 3, 5, 7]) Exit:remove_all(2, [1, 4, 2, 3, 5, 2, 7, 2], [1, 4, 3, 5, 7]) X = [1, 4, 3, 5, 7] What I am not able to understand is how the backtracking is happening in these lines of code Exit:remove_all(2, [], []) Exit:remove_all(2, [2], []) Exit:remove_all(2, [7, 2], [7]) Exit:remove_all(2, [2, 7, 2], [7]) Exit:remove_all(2, [5, 2, 7, 2], [5, 7]) Exit:remove_all(2, [3, 5, 2, 7, 2], [3, 5, 7]) Exit:remove_all(2, [2, 3, 5, 2, 7, 2], [3, 5, 7]) Exit:remove_all(2, [4, 2, 3, 5, 2, 7, 2], [4, 3, 5, 7]) Exit:remove_all(2, [1, 4, 2, 3, 5, 2, 7, 2], [1, 4, 3, 5, 7]) How does the prolog interpreter perform recursion on this? Can you please explain.
Actually i am not doing prolog from a very long time and so I am not able to help you in this. I wish I could but please take help from community or your friends.
super easy to understand and follow! Thank you!!
Welcome :)
best explain, thank you..
Goated Lectures
Right so, I tried writing the same code and it showed an error that essentially meant that I was trying to overwrite the already defined member predicate. The error went away when I changed the name of the predicate to ismember.
Hmm.... But it ran on my system!!
@@techdose4u Guess our version is different.
This is same as list membership right?
thank you
Welcome 😀
Can you explain how the "member" function works when there are two 'harry' in the list with the stack implementation of function?
Hi,
First of all, your videos are great and thank you for these amazing videos. You are doing a great job. I am trying to understand how the search tree looks like while backtracking during recursion and I am kind of lost.
Say for Example the below lines of code, removes all the occurrences of an element from a list :
remove_all(_, [], []).
remove_all(El, [El|Tail], Tail2):-
remove_all(El, Tail, Tail2).
remove_all(El, [Head|Tail], [Head|Tail2]):-
not(El = Head),
remove_all(El, Tail, Tail2).
Now I query the following ?- remove_all( 2, [1,4,2,3,5,2,7,2], X). I used the online SWISH Prolog to execute it with the trace and I got the following tree
Call:remove_all(2, [1, 4, 2, 3, 5, 2, 7, 2], _4896)
Call:not(2=1)
Exit:not('10758ac0-dc91-4335-a0d8-48b7b11776c0' : (2=1))
Call:remove_all(2, [4, 2, 3, 5, 2, 7, 2], _5128)
Call:not(2=4)
Exit:not('10758ac0-dc91-4335-a0d8-48b7b11776c0' : (2=4))
Call:remove_all(2, [2, 3, 5, 2, 7, 2], _5146)
Call:remove_all(2, [3, 5, 2, 7, 2], _5146)
Call:not(2=3)
Exit:not('10758ac0-dc91-4335-a0d8-48b7b11776c0' : (2=3))
Call:remove_all(2, [5, 2, 7, 2], _5164)
Call:not(2=5)
Exit:not('10758ac0-dc91-4335-a0d8-48b7b11776c0' : (2=5))
Call:remove_all(2, [2, 7, 2], _5182)
Call:remove_all(2, [7, 2], _5182)
Call:not(2=7)
Exit:not('10758ac0-dc91-4335-a0d8-48b7b11776c0' : (2=7))
Call:remove_all(2, [2], _5200)
Call:remove_all(2, [], _5200)
Exit:remove_all(2, [], [])
Exit:remove_all(2, [2], [])
Exit:remove_all(2, [7, 2], [7])
Exit:remove_all(2, [2, 7, 2], [7])
Exit:remove_all(2, [5, 2, 7, 2], [5, 7])
Exit:remove_all(2, [3, 5, 2, 7, 2], [3, 5, 7])
Exit:remove_all(2, [2, 3, 5, 2, 7, 2], [3, 5, 7])
Exit:remove_all(2, [4, 2, 3, 5, 2, 7, 2], [4, 3, 5, 7])
Exit:remove_all(2, [1, 4, 2, 3, 5, 2, 7, 2], [1, 4, 3, 5, 7])
X = [1, 4, 3, 5, 7]
What I am not able to understand is how the backtracking is happening in these lines of code
Exit:remove_all(2, [], [])
Exit:remove_all(2, [2], [])
Exit:remove_all(2, [7, 2], [7])
Exit:remove_all(2, [2, 7, 2], [7])
Exit:remove_all(2, [5, 2, 7, 2], [5, 7])
Exit:remove_all(2, [3, 5, 2, 7, 2], [3, 5, 7])
Exit:remove_all(2, [2, 3, 5, 2, 7, 2], [3, 5, 7])
Exit:remove_all(2, [4, 2, 3, 5, 2, 7, 2], [4, 3, 5, 7])
Exit:remove_all(2, [1, 4, 2, 3, 5, 2, 7, 2], [1, 4, 3, 5, 7])
How does the prolog interpreter perform recursion on this? Can you please explain.
Actually i am not doing prolog from a very long time and so I am not able to help you in this. I wish I could but please take help from community or your friends.
OK !! No Problem. Thank you :)
hello I want a hill climbing code in prolog can you help me even if it is in the form of a pdf or url
It is saying , no permission to define imported_procrdure list:member/2. What does this mean bro
it's the same content as the one in the video of element membership in a list ! ain't it ?
You can say so. For element membership check as well, we did recursive search.
@@techdose4u Nice job anyway (y) keep up the good work , waiting for the next videos
pay attention, dude. your friend has already made a video explaining the same exercise, and it only took him half the time😂😂
if your native is hindi please explain in hindi, it'll bring you more audience