└── Exercises ├── Definability ├── exercise_1.pdf ├── exercise_2.pdf ├── exercise_3.pdf └── exercise_4.pdf ├── Prolog ├── Code │ ├── ex1.pl │ ├── ex2.pl │ ├── ex2.pl~ │ ├── ex3.pl │ ├── ex4.pl │ ├── ex5.pl │ └── ex6.pl └── Notes │ └── ex1_2.pdf ├── Resolution ├── ex13.pdf ├── ex14.pdf └── ex15.pdf └── Satisfiability ├── exercise_5.pdf └── exercise_6.pdf /Exercises/Definability/exercise_1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BoyanVD/LogicProgramming-2022-2023/dd473eae175812e5c2a0615fa107697272840bd5/Exercises/Definability/exercise_1.pdf -------------------------------------------------------------------------------- /Exercises/Definability/exercise_2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BoyanVD/LogicProgramming-2022-2023/dd473eae175812e5c2a0615fa107697272840bd5/Exercises/Definability/exercise_2.pdf -------------------------------------------------------------------------------- /Exercises/Definability/exercise_3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BoyanVD/LogicProgramming-2022-2023/dd473eae175812e5c2a0615fa107697272840bd5/Exercises/Definability/exercise_3.pdf -------------------------------------------------------------------------------- /Exercises/Definability/exercise_4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BoyanVD/LogicProgramming-2022-2023/dd473eae175812e5c2a0615fa107697272840bd5/Exercises/Definability/exercise_4.pdf -------------------------------------------------------------------------------- /Exercises/Prolog/Code/ex1.pl: -------------------------------------------------------------------------------- 1 | :- use_module(library(clpfd)). 2 | 3 | %Exercise 1 4 | %Natural numbers 5 | nat(c). 6 | nat(s(X)):-nat(X). 7 | 8 | %Sum of two natural numbers 9 | sumNat(c,X,X). 10 | sumNat(s(X),Y,s(Z)):-sum(X,Y,Z). 11 | 12 | %Fibonacci: given N, find Fn, where F0 := 0, F1 := 1, Fn := Fn-1 + Fn-2 13 | fib(0,0). 14 | fib(1,1). 15 | fib(N,Fn):-N#>0,N1#=N-1,N2#=N-2,fib(N1,Fn1),fib(N2,Fn2),Fn#=Fn1+Fn2. 16 | 17 | fastfib(0,0,1). 18 | fastfib(N,Fn,Fnext):-N#>0,Fprev#=Fnext-Fn,N1#=N-1,fastfib(N1,Fprev,Fn). 19 | 20 | %Factorial: given N, find N! 21 | factorial(0,1). 22 | factorial(N,Fn):-N#>0,N1#=N-1,factorial(N1,Fn1),Fn#=N*Fn1. 23 | 24 | %Given x, y find d,u,v,where d = gcd(x,y) and ux + vy = d 25 | gcd(0,Y,Y,0,1). 26 | gcd(X,Y,D,U,V):- X #>= Y,X1#=X-Y,V#=V1-U,gcd(X1,Y,D,U,V1). 27 | gcd(X,Y,D,U,V):- Y #> X,gcd(Y,X,D,V,U). 28 | -------------------------------------------------------------------------------- /Exercises/Prolog/Code/ex2.pl: -------------------------------------------------------------------------------- 1 | :- use_module(library(clpfd)). 2 | 3 | 4 | %Exercise 2 5 | %Given X, L find if X in L 6 | member1(X,[H|T]):-X#=H;member1(X,T). 7 | 8 | member2(X,[X|_]). 9 | member2(X,[H|T]):-H#\=X,member2(X,T). 10 | 11 | member3(X,L):-append1(_,[X|_],L). 12 | 13 | % Diven A and B find the concatenation of AoB 14 | append1([],B,B). 15 | append1([H|T],B,[H|T1]):-append1(T,B,T1). 16 | 17 | % Given X and L : check if X is the last element of L 18 | last1(X,[X]). 19 | last1(X,[_|T]):-last1(X,T). 20 | 21 | 22 | remove1(X,[X|T],T). 23 | remove1(X,[H|T],[H|R]):-X#\=H,remove1(X,T,R). 24 | 25 | remove2(X,List,Result):-append1(A,[X|B],List),append1(A,B,Result),not(member1(X,A)). 26 | 27 | removeAll(_,[],[]). 28 | removeAll(X,[X|T],R):-removeAll(X,T,R). 29 | removeAll(X,[H|T],[H|R]):-X#\=H,removeAll(X,T,R). 30 | 31 | permutation1([],[]). 32 | permutation1(L,[H|T]):-permutation1(T,M), remove1(H,L,M). 33 | 34 | reverse1([],[]). 35 | reverse1([H|T],R):-reverse1(T,RT),append1(RT,[H],R). 36 | 37 | isSorted([]). 38 | isSorted([_]). 39 | isSorted([X,Y|T]):-X#= 1, K1 #= K - 1, between1(0, S, Ni), 38 | S1 #= S - Ni, genKS(K1, S1, Rest). 39 | 40 | % generate all finite sequences of natural numbers 41 | genAll2([]). 42 | genAll2(L):- nat(N), between1(1, N, K), 43 | S #= N - K, genKS(K, S, L). 44 | 45 | genAll([]). 46 | genAll(L):- pair(K, S), K > 0, S > 0, genKS(K, S, L). 47 | 48 | 49 | %Generate all finite sets of natural numbers 50 | % Gen all sets, with elements less than N 51 | gen_sets_max_el(0, []). 52 | gen_sets_max_el(N, [N1 | S]) :- N #> 0, N1 #= N - 1, between1(0, N1, N2), gen_sets_max_el(N2, S). 53 | 54 | gen_finite_sets(S) :- nat(N), gen_sets_max_el(N, S). 55 | 56 | 57 | % Fibonacci numbers 58 | % 59 | % Old way 60 | fib1(0,0). 61 | fib1(1,1). 62 | fib1(N,Fn):-N#>0,N1#=N-1,N2#=N-2,fib1(N1,Fn1),fib1(N2,Fn2),Fn#=Fn1+Fn2. 63 | fib1(X):-nat(N),fib1(N,X). 64 | 65 | fib(0, 1). 66 | fib(Y, Z):- fib(X, Y), Z #= X + Y. 67 | fib(X):- fib(X, _). 68 | 69 | % Factoriel 70 | fact1(0, 1). 71 | fact1(N, F) :- N #> 0, N1 #= N - 1, fact1(N1, F1), F #= F1 * N. 72 | fact1(X):-nat(N),fact1(N,X). 73 | 74 | 75 | % Generate all finite arithmetic progressions 76 | is_arithmetic([]). 77 | is_arithmetic([_]). 78 | is_arithmetic([A, B]):- A < B. 79 | is_arithmetic(L):- (L = [X,Y,_|_]),X < Y, 80 | not(( append(_, [A, B, C|_], L), (A + C) =\= (B + B) )). 81 | 82 | gen_arithmetic(L):- genAll(L), is_arithmetic(L). 83 | 84 | -------------------------------------------------------------------------------- /Exercises/Prolog/Code/ex6.pl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BoyanVD/LogicProgramming-2022-2023/dd473eae175812e5c2a0615fa107697272840bd5/Exercises/Prolog/Code/ex6.pl -------------------------------------------------------------------------------- /Exercises/Prolog/Notes/ex1_2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BoyanVD/LogicProgramming-2022-2023/dd473eae175812e5c2a0615fa107697272840bd5/Exercises/Prolog/Notes/ex1_2.pdf -------------------------------------------------------------------------------- /Exercises/Resolution/ex13.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BoyanVD/LogicProgramming-2022-2023/dd473eae175812e5c2a0615fa107697272840bd5/Exercises/Resolution/ex13.pdf -------------------------------------------------------------------------------- /Exercises/Resolution/ex14.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BoyanVD/LogicProgramming-2022-2023/dd473eae175812e5c2a0615fa107697272840bd5/Exercises/Resolution/ex14.pdf -------------------------------------------------------------------------------- /Exercises/Resolution/ex15.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BoyanVD/LogicProgramming-2022-2023/dd473eae175812e5c2a0615fa107697272840bd5/Exercises/Resolution/ex15.pdf -------------------------------------------------------------------------------- /Exercises/Satisfiability/exercise_5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BoyanVD/LogicProgramming-2022-2023/dd473eae175812e5c2a0615fa107697272840bd5/Exercises/Satisfiability/exercise_5.pdf -------------------------------------------------------------------------------- /Exercises/Satisfiability/exercise_6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BoyanVD/LogicProgramming-2022-2023/dd473eae175812e5c2a0615fa107697272840bd5/Exercises/Satisfiability/exercise_6.pdf --------------------------------------------------------------------------------