Question: Please answer in one document of code Thank you. 1 Basic Prolog 1.1 Elements of a List Let's begin by acquainting ourselves with Prolog. We



Please answer in one document of code Thank you.
1 Basic Prolog 1.1 Elements of a List Let's begin by acquainting ourselves with Prolog. We shall start by writing a predicate elem (X, Xs) that determines if X is an element of this list Xs. elem (X,Xs) false. Your code goes here! Make sure to write at least 5 tests of elem (X,Xs). This can be easily done by writing a headless clause, like so. elem (1,[1,2,3]). 1.2 Picking Elements from a List Write a predicate pick (X,Xs, Ys) that is true when Xs contains X and Ys is equal to Xs with a single instance of X removed. We have included a handful of test cases to clarify the specification, but we also expect you to write an additional 5 test cases. pick (X,Xs, Ys) false. Your code goes here! pick (1,[1,2,3].[2,3]). +pick (1,[2,3] [2,3]). pick (1,12,1,2,1,3].[2,2,1,3]). pick (1,12,1,2,1,3],[2,1,2,3]). + pick (1,12,1,2,1,3].[2,2,3]). 1.3 Permutations of a List [2,3] is [1,2,3] with 1 removed 1 is not in [2,3]. so this is false. We only remove 1 from [2,1,2,1,3] one time. Furthermore, we can remove either 1. However, we should only remove a single 1. Write a predicate permute (Xs, Ys) that determines if Xs is a permutation of Ys. As before, write 5 test cases. If you don't remember what a permutation is, look it up! permute (Xs, Ys) false. Your code goes here! 1 1.4 Sorted Lists Write a predicate sorted (Xs) that determines if a list of numbers Xs is sorted in ascending order, and write 5 test cases for it. sorted (Xs) false. %% Your code goes here!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
