Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Example 11.1 % family database p392. father(jim,edward). father(jim,maggy). fath

ID: 3659737 • Letter: E

Question

Example 11.1 % family database p392. father(jim,edward). father(jim,maggy). father(edward,peter). father(edward,helen). father(edward,kitty). father(bill,fi). mother(maggy,fi). mother(fi,lillian). % parent view (or rules) p392. parent(X,Y) :- father(X,Y). parent(X,Y) :- mother(X,Y). Using the genealogical database and rules defining parent from example 11.1 and the additional rules: sibling(X,Y) :-parent(Z,X), parent(Z,Y), X does not equal Y cousin(X,Y) :-parent(Z,X) , sibling(Z,T), parent(T,Y) Show the bottom-up evaluation of the query cousin(peter,X).

Explanation / Answer

% f am i l y d a t a b a s e p 3 9 2 . f a t h e r ( j i m , e d w a r d ) . f a t h e r ( j i m , ma g g y ) . f a t h e r ( e d w a r d , p e t e r ) . f a t h e r ( e d w a r d , h e l e n ) . f a t h e r ( e d w a r d , k i t t y ) . f a t h e r ( b i l l , f i ) . mo t h e r ( ma g g y , f i ) . mo t h e r ( f i , l i l l i a n ) . % p a r e n t v i e w ( o r r u l e s ) p 3 9 2 . p a r e n t ( X , Y ) : - f a t h e r ( X , Y ) . p a r e n t ( X , Y ) : - mo t h e r ( X , Y ) . % d e f i n i t i o n o f o r e r e g i o n a p 3 9 2 . o r e ( N , X , Y ) : - N = a , X + Y > = 2 , X > = Y , X < = 2 . % d e f i n i i o n o f s h a f t s 2 p 3 9 3 . s h a f t ( N , X , Y ) : - N = s 2 , X = 9 , Y = 5 . % p r o g r am t o f i n d o r e w i t h i n d i s t a n c e o f s h a f t p 3 9 3 . % r e q u i r e s n o n - l i n e a r s o l v e r ? w i t h i n ( S , D , O ) : - ( X 0 - X S ) * ( X 0 - X S ) + ( Y O - Y S ) * ( Y 0 - Y S ) < = D * D , s h a f t ( S , X S , Y S ) , o r e ( O , X O , Y O ) . % p r o g r am f o r ma n a g e r r e l a t i o n i n t emp o r a l d a t a b a s e p 3 9 4 . ma n a g e r _ o f ( T , s a l e s , b a r t ) : - 1 9 8 0 < = T , T < = 1 9 9 2 . ma n a g e r _ o f ( T , ma r k e t i n g , b a r t ) : - 1 9 9 3 < = T , T < = 1 9 9 6 . ma n a g e r _ o f ( T , s a l e s , ma r i a ) : - T = 1 9 9 6 . % p r o g r am f o r j o b r e l a t i o n i n t emp o r a l d a t a b a s e p 3 9 4 . j o b ( T , p e t e r , s a l e s p e r s o n , s a l e s ) : - 1 9 8 5 < = T , T < = 1 9 8 7 . j o b ( T , p e t e r , c o n s u l t a n t , s a l e s ) : - T = 1 9 8 8 . j o b ( T , p e t e r , a n a l y s t , s u p p o r t ) : - 1 9 8 9 < = T , T < = 1 9 9 6 . j o b ( T , k i m , s a l e s p e r s o n , s a l e s ) : - 1 9 9 4 < = T , T < = 1 9 9 5 . j o b ( T , ma r i a , s a l e s p e r s o n , s a l e s ) : - 1 9 8 8 < = T , T < = 1 9 9 1 . j o b ( T , ma r i a , c o n s u l t a n t , s u p p o r t ) : - 1 9 9 2 < = T , T < = 1 9 9 5 . j o b ( T , ma r i a , ma n a g e r , ma n a g eme n t ) : - T = 1 9 9 6 . j o b ( T , b a r t , ma n a g e r , ma n a g eme n t ) : - 1 9 8 0 < = T , T < = 1 9 9 6 . % e v e r ma n a g e d r u l e p 3 9 4 . e v e r _ ma n a g e d ( M , P ) : - ma n a g e r _ o f ( T , D , M ) , j o b ( T , P , _ , D ) . % g o a l f o r d e t e r m i n i n g ma n a g e r s p 3 9 4 . g p 3 9 4 a ( M , P ) : - e v e r _ ma n a g e d ( M , P ) . % l o n g t e r m emp l o y e e r u l e p 3 9 4 . l o n g _ t e r m ( P ) : - j o b ( T 0 , P , _ , _ ) , j o b ( T 1 , P , _ , _ ) , T 1 - T 0 > = 1 0 . % g o a l f o r d e t e r m i n i n g l o n g t e r m emp l o y e e s p 3 9 4 . g p 3 9 4 b ( M , P ) : - l o n g _ t e r m ( P ) . %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 1 1 . 2 B o t t om U p E v a l u a t i o n % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % f l i g h t d a t a b a s e p 3 9 5 . f l i g h t ( 3 0 0 , me l b o u r n e , s y d n e y ) . f l i g h t ( 3 0 1 , s y d n e y , me l b o u r n e ) . f l i g h t ( 5 0 0 , s y d n e y , b r i s b a n e ) . f l i g h t ( 5 0 1 , b r i s b a n e , s y d n e y ) . % p r o g r am f o r c i t y c o n n e c t i o n s p 3 9 5 . d i r e c t _ f l i g h t ( F r om , T o ) : - f l i g h t ( _ , F r om , T o ) . c o n n e c t s ( F r om , T o ) : - d i r e c t _ f l i g h t ( F r om , T o ) . c o n n e c t s ( F r om , T o ) : - d i r e c t _ f l i g h t ( F r om , V i a ) , c o n n e c t s ( V i a , T o ) . % g o a l f o r c o n n e c t i o n s p 3 9 5 . g p 3 9 5 ( T ) : - c o n n e c t s ( me l b o u r n e , T ) . % g o a l g e n e r a t i n g f a c t s S 1 p 3 9 6 . g p 3 9 6 a ( N , F , T ) : - f l i g h t ( N , F , T ) . % s e t o f f a c t s S 1 p 3 9 6 . f l i g h t _ S 1 ( 3 0 0 , me l b o u r n e , s y d n e y ) . f l i g h t _ S 1 ( 3 0 1 , s y d n e y , me l b o u r n e ) . f l i g h t _ S 1 ( 5 0 0 , s y d n e y , b r i s b a n e ) . f l i g h t _ S 1 ( 5 0 1 , b r i s b a n e , s y d n e y ) . % p r o g r am t o g e n e r a t e S 2 ( n o t i n t e x t ) d i r e c t _ f l i g h t _ R 2 ( F r om , T o ) : - f l i g h t _ S 1 ( _ , F r om , T o ) . % g o a l g e n e r a t i n g f a c t s S 2 p 3 9 6 . g p 3 9 6 b ( F , T ) : - d i r e c t _ f l i g h t _ R 2 ( F , T ) . % s e t o f f a c t s S 2 p 3 9 6 . d i r e c t _ f l i g h t _ S 2 ( me l b o u r n e , s y d n e y ) . d i r e c t _ f l i g h t _ S 2 ( s y d n e y , me l b o u r n e ) . d i r e c t _ f l i g h t _ S 2 ( s y d n e y , b r i s b a n e ) . d i r e c t _ f l i g h t _ S 2 ( b r i s b a n e , s y d n e y ) . % p r o g r am t o g e n e r a t e S 3 ( n o t i n t e x t ) c o n n e c t s _ S 2 ( _ , _ ) : - f a i l . % j u s t t o a v o i d e r r o r me s s a g e c o n n e c t s _ R 3 ( F r om , T o ) : - d i r e c t _ f l i g h t _ S 2 ( F r om , T o ) . c o n n e c t s _ R 3 ( F r om , T o ) : - d i r e c t _ f l i g h t _ S 2 ( F r om , V i a ) , c o n n e c t s _ S 2 ( V i a , T o ) . % g o a l g e n e r a t i n g f a c t s S 3 ( n o t i n t e x t ) . g p 3 9 6 c ( F , T ) : - c o n n e c t s _ R 3 ( F , T ) . % s e t o f f a c t s S 3 p 3 9 7 . c o n n e c t s _ S 3 ( me l b o u r n e , s y d n e y ) . c o n n e c t s _ S 3 ( s y d n e y , me l b o u r n e ) . c o n n e c t s _ S 3 ( s y d n e y , b r i s b a n e ) . c o n n e c t s _ S 3 ( b r i s b a n e , s y d n e y ) . % p r o g r am t o g e n e r a t e S 4 ( n o t i n t e x t ) c o n n e c t s _ R 4 ( F r om , T o ) : - d i r e c t _ f l i g h t _ S 2 ( F r om , V i a ) , c o n n e c t s _ S 3 ( V i a , T o ) . % g o a l g e n e r a t i n g f a c t s S 4 ( n o t i n t e x t ) . g p 3 9 7 a ( F , T ) : - c o n n e c t s _ R 4 ( F , T ) . % s e t o f f a c t s S 4 p 3 9 7 . c o n n e c t s _ S 4 ( me l b o u r n e , me l b o u r n e ) . c o n n e c t s _ S 4 ( b r i s b a n e , b r i s b a n e ) . c o n n e c t s _ S 4 ( me l b o u r n e , b r i s b a n e ) . c o n n e c t s _ S 4 ( s y d n e y , s y d n e y ) . c o n n e c t s _ S 4 ( b r i s b a n e , me l b o u r n e ) . % p r o g r am t o g e n e r a t e f i n a l f a c t s ( n o t i n t e x t ) % c o n n e c t s _ S 3 4 i s t h e u n i o n o f f a c t s S 3 a n d S 4 c o n n e c t s _ S 3 4 ( F , T ) : - c o n n e c t s _ S 3 ( F , T ) . c o n n e c t s _ S 3 4 ( F , T ) : - c o n n e c t s _ S 4 ( F , T ) . c o n n e c t s _ R 5 ( F r om , T o ) : - d i r e c t _ f l i g h t _ S 2 ( F r om , V i a ) , c o n n e c t s _ S 3 4 ( V i a , T o ) . % g o a l g e n e r a t i n g f i n a l f a c t s ( n o t i n t e x t ) g p 3 9 7 b ( F , T ) : - c o n n e c t s _ R 5 ( F , T ) . % s e t o f f a c t s S 5 p 3 9 7 . c o n n e c t s _ S 5 ( me l b o u r n e , s y d n e y ) . c o n n e c t s _ S 5 ( s y d n e y , me l b o u r n e ) . c o n n e c t s _ S 5 ( s y d n e y , b r i s b a n e ) . c o n n e c t s _ S 5 ( b r i s b a n e , s y d n e y ) . c o n n e c t s _ S 5 ( me l b o u r n e , me l b o u r n e ) . c o n n e c t s _ S 5 ( b r i s b a n e , b r i s b a n e ) . c o n n e c t s _ S 5 ( me l b o u r n e , b r i s b a n e ) . c o n n e c t s _ S 5 ( s y d n e y , s y d n e y ) . c o n n e c t s _ S 5 ( b r i s b a n e , me l b o u r n e ) . % g e n e r a t i n g a n s w e r t o o r i g i n a l q u e r y p 3 9 7 . g p 3 9 7 c ( T ) : - c o n n e c t s _ S 5 ( me l b o u r n e , T ) . % g o a l g e n e r a t i n g t h e a n s w e r s t o t h e s e c o n d r u l e o f c o n n e c t s p 4 0 1 . g p 4 0 1 ( F r om , V i a , T o ) : - d i r e c t _ f l i g h t _ S 2 ( F r om , V i a ) , c o n n e c t s _ S 3 ( V i a , T o ) . % v o l t a g e d i v i d e r p r o g r am p 4 0 1 - - 4 0 2 . v o l t a g e _ d i v i d e r ( V , I , R 1 , R 2 , V D , I D ) : - V 1 = I * R 1 , V D = I 2 * R 2 , V = V 1 + V D , I = I 2 + I D . c e l l ( 9 ) . r e s i s t o r ( 5 ) . r e s i s t o r ( 9 ) . b u i l d a b l e _ v d ( V , I , R 1 , R 2 , V D , I D ) : - v o l t a g e _ d i v i d e r ( V , I , R 1 , R 2 , V D , I D ) , c e l l ( V ) , r e s i s t o r ( R 1 ) , r e s i s t o r ( R 2 ) . g o a l _ v d ( V , R 1 , R 2 ) : - b u i l d a b l e _ v d ( V , I , R 1 , R 2 , V D , I D ) , I D = 0 . 1 , 5 . 4 < = V D , V D < = 5 . 5 . % i n i t i a l s e t o f f a c t s u s i n g b o t t om u p p 4 0 3 . v o l t a g e _ d i v i d e r _ I 1 ( I * R 1 + V D , I 2 + I D , R 1 , R 2 , I 2 * R 2 , I D ) . c e l l _ I 1 ( 9 ) . r e s i s t o r _ I 1 ( 5 ) . r e s i s t o r _ I 1 ( 9 ) . % g o a l t o g e n e r a t e b u i l d a b l e _ v d f a c t s i n i t e r a t i o n 2 p 4 0 3 . g p 4 0 3 ( V , I , R 1 , R 2 , V D , I D ) : - v o l t a g e _ d i v i d e r _ I 1 ( V , I , R 1 , R 2 , V D , I D ) , c e l l _ I 1 ( V ) , r e s i s t o r _ I 1 ( R 1 ) , r e s i s t o r _ I 1 ( R 2 ) . % s e t o f f a c t s i n s e c o n d i t e r a t i o n u s i n g b o t t om u p p 4 0 4 . v o l t a g e _ d i v i d e r _ I 2 ( I * R 1 + V D , I 2 + I D , R 1 , R 2 , I 2 * R 2 , I D ) . c e l l _ I 2 ( 9 ) . r e s i s t o r _ I 2 ( 5 ) . r e s i s t o r _ I 2 ( 9 ) . b u i l d a b l e _ v d _ I 2 ( 9 , I , 5 , 5 , - 5 * I + 9 , 2 * I - 1 . 8 ) . b u i l d a b l e _ v d _ I 2 ( 9 , I , 5 , 9 , - 5 * I + 9 , 1 4 / 9 * I - 1 ) . b u i l d a b l e _ v d _ I 2 ( 9 , I , 9 , 5 , - 9 * I + 9 , 2 . 8 * I - 1 . 8 ) . b u i l d a b l e _ v d _ I 2 ( 9 , I , 9 , 9 , - 9 * I + 9 , 2 * I - 1 ) . % g o a l t o g e n e r a t e g o a l _ v d f a c t s i n i t e r a t i o n 3 p 4 0 4 . g p 4 0 4 ( V , R 1 , R 2 ) : - b u i l d a b l e _ v d _ I 2 ( V , I , R 1 , R 2 , V D , I D ) , I D = 0 . 1 , 5 . 4 < = V D , V D < = 5 . 5 . % s e t o f f a c t s i n t h i r d i t e r a t i o n u s i n g b o t t om u p p 4 0 4 . v o l t a g e _ d i v i d e r _ I 3 ( I * R 1 + V D , I 2 + I D , R 1 , R 2 , I 2 * R 2 , I D ) . c e l l _ I 3 ( 9 ) . r e s i s t o r _ I 3 ( 5 ) . r e s i s t o r _ I 3 ( 9 ) . b u i l d a b l e _ v d _ I 3 ( 9 , I , 5 , 5 , - 5 * I + 9 , 2 * I - 1 . 8 ) . b u i l d a b l e _ v d _ I 3 ( 9 , I , 5 , 9 , - 5 * I + 9 , 1 4 / 9 * I - 1 ) . b u i l d a b l e _ v d _ I 3 ( 9 , I , 9 , 5 , - 9 * I + 9 , 2 . 8 * I - 1 . 8 ) . b u i l d a b l e _ v d _ I 3 ( 9 , I , 9 , 9 , - 9 * I + 9 , 2 * I - 1 ) . g o a l _ v d _ I 3 ( 9 , 5 , 9 )
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote