0% found this document useful (0 votes)
12 views6 pages

Prolog 2

Uploaded by

nawelz0311
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views6 pages

Prolog 2

Uploaded by

nawelz0311
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1 premier/2

p r e m i e r (X, L ) : L=[X| ] .

2 member/2

member (X, [X| ] ) .


member (X, [ | L ] ) :−
member (X, L ) .

2.1 inclus/2

inclus ([] , ).
i n c l u s ( [ X| L1 ] , L2 ) :−
member (X, L2 ) ,
i n c l u s ( L1 , L2 ) .

2.2 intersection/3

intersection ([] , , []).


i n t e r s e c t i o n ( [ X| L1 ] , L2 , [X| L3 ] ) :−
member (X, L2 ) ,
i n t e r s e c t i o n ( L1 , L2 , L3 ) .
i n t e r s e c t i o n ( [ | L1 ] , L2 , L3 ) :−
i n t e r s e c t i o n ( L1 , L2 , L3 ) .

2.3 different/1

differents ( [ ] ) .
d i f f e r e n t s ( [ Head | T a i l ] ) :−
\+ member ( Head , T a i l ) ,
d i f f e r e n t s ( Tail ) .

3 ajoute debut/3

a j o u t e d e b u t (X, L , [X| L ] ) .

1
4 append/3

append ( [ ] , L , L ) .
append ( [ X | Xs ] , Ys , [X| Zs ] ) : −
append ( Xs , Ys , Zs ) .

4.1 dernier/ 2 avec append

d e r n i e r (L ,X) :−
append ( , [X] , L ) .

4.2 sauf dernier/2 avec append

s a u f d e r n i e r (L , L1 ) :−
append ( L1 , [ ] , L ) .

4.3 ajoute fin/3

a j o u t e f i n (X, L , L1 ) :−
append (L , [X] , L1 ) .

4.4 palindrome/1

palindrome ( [ ] ) .
palindrome ( [X ] ) .
p a l i n d r o m e ( [ X| L ] ) :−
append ( L1 , [X] , L ) ,
p a l i n d r o m e ( L1 ) .

5 dernier/2

d e r n i e r ( [ X] , X ) .
d e r n i e r ( [ | L ] ,X) :−
d e r n i e r (L ,X ) .

2
6 sauf dernier/2

s a u f d e r n i e r ( [ X] , [ ] ) .
s a u f d e r n i e r ( [ X| L ] , [X| L1 ] ) :−
s a u f d e r n i e r (L , L1 ) .

6.1 reverse/2

reverse ( [ ] , [ ] ) .
r e v e r s e ( [ X| XS ] , L2 ) :−
d e r n i e r ( L2 , X) ,
s a u f d e r n i e r ( L2 , L3 ) ,
r e v e r s e (XS , L3 ) .

7 ajoute fin/3

a j o u t e f i n (Y, [ ] , [Y ] ) .
a j o u t e f i n (Y, [X| L ] , [X| L1 ] ) :−
a j o u t e f i n (Y, L , L1 ) .

8 pair/1

pair ( [ ] ) .
p a i r ( [ , | L ] ) :−
p a i r (L ) .

9 enleve/3

enleve ( , [ ] , [ ] ) .
e n l e v e (X, [X| Xs ] , Xs ) .
e n l e v e (X, [Y| Ys ] , [Y| Zs ] ) :−
e n l e v e (X, Ys , Zs ) .

9.1 inclus/2

inclus ([] , L).


i n c l u s ( [ X| L1 ] , L2 ) :−
e n l e v e (X, L2 , L3 ) ,
i n c l u s ( L1 , L2 ) .

3
9.2 permute/2

permute ( [ ] , [ ] ) .
permute ( [ X| Xs ] , Y) :−
permute ( Xs , Ys ) ,
e n l e v e (X, Y, Ys ) .

9.3 oter daublons/2

oter doublons ( [ ] , [ ] ) .
o t e r d o u b l o n s ( [ X| L1 ] , [X| L2 ] ) :−
e n l e v e (X, L1 , L3 ) ,
o t e r d o u b l o n s ( L3 , L2 ) .

10 delete/3

delete ( , [ ] , [ ] ) .
d e l e t e ( Element , [ Element | L i s t e ] , L i s t e S a n s E l e m e n t ) :−
d e l e t e ( Element , L i s t e , ListeSansElement ) .
d e l e t e ( Element , [ T| L i s t e ] , [ T | L i s t e S a n s E l e m e n t ] ) :−
Element \= T,
d e l e t e ( Element , L i s t e , ListeSansElement ) .

10.1 delete list/3

d e l e t e l i s t ( [ X| XS ] , L1 , L2 ) :−
d e l e t e (X, L1 , L3 ) ,
d e l e t e l i s t (XS , L3 , L2 ) .
d e l e t e l i s t ( [ ] , L, L).

11 sublist/2

prefix ([] , ).
p r e f i x ( [ X| Xs ] , [X| Ys ] ) :−
p r e f i x ( Xs , Ys ) .

s u f f i x ( Sub , L i s t ) :−
append ( , Sub , L i s t ) .

4
append ( [ ] , L , L ) .
append ( [ X| Xs ] , Ys , [X| Zs ] ) :−
append ( Xs , Ys , Zs ) .

s u b l i s t ( Sub , L i s t ) :−
append ( , Sub , L i s t ) .

s u b l i s t ( Sub , L i s t ) :−
s u f f i x ( Suffix , List ) ,
p r e f i x ( Sub , S u f f i x ) .

s u b l i s t ( Sub , L i s t ) :−
append ( P r e f i x , , List ) ,
p r e f i x ( Sub , P r e f i x ) .

s u b l i s t ( Sub , L i s t ) :−
append ( , S u f f i x , L i s t ) ,
s u f f i x ( Sub , S u f f i x ) .

s u b l i s t ( Sub , L i s t ) :−
append ( P r e f i x , , List ) ,
append ( , Sub , P r e f i x ) .

12 tri insertion/2

tri insertion ([] , []).


t r i i n s e r t i o n ( [ Head | T a i l ] , S o r t e d ) :−
t r i i n s e r t i o n ( Tail , SortedTail ) ,
i n s e r t ( Head , S o r t e d T a i l , S o r t e d ) .

i n s e r t (X, [ ] , [X ] ) .
i n s e r t (X, [Y| T a i l ] , [ X,Y| T a i l ] ) :−
X =< Y.
i n s e r t (X, [Y| T a i l ] , [Y| R e s u l t ] ) :−
X > Y,
i n s e r t (X, T a i l , R e s u l t ) .

13 tri rapide/2

tri rapide ([] , [ ] ) .


t r i r a p i d e ( [ P i v o t | Rest ] , S o r t e d ) :−
p a r t i t i o n ( Rest , Pivot , S m a l l e r , G r e a t e r ) ,

5
t r i r a p i d e ( Smaller , SmallerSorted ) ,
t r i r a p i d e ( Greater , G r e a t e r S o r t e d ) ,
append ( S m a l l e r S o r t e d , [ P i v o t | G r e a t e r S o r t e d ] , S o r t e d ) .

partition ([] , , [] , []).


p a r t i t i o n ( [ X| Rest ] , Pivot , [X| S m a l l e r ] , G r e a t e r ) :−
X =< Pivot ,
p a r t i t i o n ( Rest , Pivot , Smaller , Greater ) .
p a r t i t i o n ( [ X| Rest ] , Pivot , S m a l l e r , [X| G r e a t e r ] ) :−
X > Pivot ,
p a r t i t i o n ( Rest , Pivot , Smaller , Greater ) .

14 fusion/3

fusion ( [ ] , L, L).
f u s i o n (L , [ ] , L ) .
f u s i o n ( [ X| Xs ] , [Y| Ys ] , [X| Zs ] ) :−
X =< Y,
f u s i o n ( Xs , [Y| Ys ] , Zs ) .
f u s i o n ( [ X| Xs ] , [Y| Ys ] , [Y| Zs ] ) :−
X > Y,
f u s i o n ( [ X| Xs ] , Ys , Zs ) .

14.1 tri fusion/2

tri fusion ([] , [ ]) .


t r i f u s i o n ( [ X] , [X ] ) .
t r i f u s i o n ( L i s t , S o r t e d ) :−
length ( L i s t , Len ) ,
Len > 1 ,
LenDiv2 i s Len // 2 ,
length ( L e f t , LenDiv2 ) ,
append ( L e f t , Right , L i s t ) ,
t r i f u s i o n ( Left , LeftSorted ) ,
t r i f u s i o n ( Right , R i g h t S o r t e d ) ,
f u s i o n ( LeftSorted , RightSorted , Sorted ) .

You might also like