...
Clausal Language (ver. 5.81.21, by P.J. Voda, J. Komara, J. Kluka)
Module  Ex09b in logic: Peano arithmetic

Included module  Standard

Included module  Mtex

Included module  Mtexln

Included module  Mauxb

Remark 

Literature.

  • [1] Ján Komara. Specification and Verification of Programs. Online.

  • [2] Ján Kľuka. Úvod do deklaratívneho programovania. Online.

  • [3] Ján Komara. Recursive Functions. Online.


Remark 

Chapter. Programs Operating on Lists.


Remark 

Section. Operations on Lists.

###

Theory  Theory_map in logic: ☆Peano arithmetic

Function  F displayed by Tex_f1_f as  f ( #1 )

Remark 

Map. Given the function f (x) , define the function Mapf (x) such that

L Mapf (x) =L (x) i<L (x) Mapf (x) [i] =f (x [i] )

Verify your implementation!


Function  Map displayed by Tex_f1_ln_map_f as  Mapf ( #1 )
Mapf (0) =0 Mapf ( v , w ) =f (v) , Mapf (w)
##

Theorem  Map_l
L Mapf (x) =L (x)
##

Theorem  Map_sub
i<L (x) Mapf (x) [i] =f (x [i] )

End of theory  Theory_map

Remark 

Zip and unzip. Define the functions Zip (x,y) and Unzip (z) such that

L (x) =L (y) LZip (x,y) =L (x) L (x) =L (y) i<L (x) Zip (x,y) [i] =x [i] ,y [i]

and

L (x) =L (y) UnzipZip (x,y) =x,y

Verify your implementations!


Function  Zip  / 2
Zip ( x , y ) =?

Function  Unzip
Unzip ( z ) =?
##

Theorem  Zip_l
L (x) =L (y) LZip (x,y) =L (x)
##

Theorem  Zip_sub
L (x) =L (y) i<L (x) Zip (x,y) [i] =x [i] ,y [i]
##

Theorem  Unzip_zip
L (x) =L (y) UnzipZip (x,y) =x,y

Remark 

Take and drop. Define the functions Take (n,x) and Drop (n,x) such that

nL (x) LTake (n,x) =n nL (x) y x=Take (n,x) y

and

nL (x) LDrop (n,x) =L (x) n nL (x) y x= y Drop (n,x)

Verify your implementations!


Function  Take  / 2
Take ( n , x ) =?

Function  Drop  / 2
Drop ( n , x ) =?
##

Theorem  Take_l
nL (x) LTake (n,x) =n
##

Theorem  Take_prefix
nL (x) y x=Take (n,x) y
##

Theorem  Drop_l
nL (x) LDrop (n,x) =L (x) n
##

Theorem  Drop_suffix
nL (x) y x= y Drop (n,x)

Remark 

Interval. Define the function [m .. n) such that

L ( [m .. n) ) =nm i<nm [m .. n) [i] =m+i

Verify your implementation!


Function  Interval  / 2 displayed by Tex_f2_ln_interval_co as  [ #1 .. #2 )
[ m .. n ) =?
##

Theorem  Interval_l
L ( [m .. n) ) =nm
##

Theorem  Interval_sub
i<nm [m .. n) [i] =m+i

Remark 

Exercise. Prove

kmmn [k .. m) [m .. n) = [k .. n)

Theorem  Interval_conc
kmmn [k .. m) [m .. n) = [k .. n)

Remark 

List minimum. Define the function Minl (x) such that

x0Minl (x) ϵx x0aϵxMinl (x) a

Verify your implementations!


Function  Minl
Minl ( v ,0) =v Minl ( v , w ) =min (v,Minl (w) ) w0
##

Theorem  Minl_in
x0Minl (x) ϵx
##

Theorem  Minl_min
x0aϵxMinl (x) a

Remark 

List maximum. Define the function Maxl (x) such that

x0Maxl (x) ϵx x0aϵxaMaxl (x)

Verify your implementations!


Function  Maxl
Maxl ( x ) =?
##

Theorem  Maxl_in
x0Maxl (x) ϵx
##

Theorem  Maxl_max
x0aϵxaMaxl (x)

Remark 

Deleting elements from lists. Define the function Delall (a,x) such that

bϵDelall (a,x) bϵxba

Verify your implementation!


Function  Delall  / 2
Delall ( a , x ) =?
##

Theorem  Delall_in
bϵDelall (a,x) bϵxba
###

Theory  Theory_filter in logic: ☆Peano arithmetic

Predicate  A

Remark 

Filter. Given the predicate A , define the function FilterA (x) such that

aϵ FilterA (x) aϵxA (a)

Verify your implementation!


Function  Filter displayed by Tex_f1_ln_filter_a as  FilterA ( #1 )
FilterA ( x ) =?
##

Theorem  Filter_in
aϵ FilterA (x) aϵxA (a)

End of theory  Theory_filter

Remark 

Multiplicity. Define the function #a (x) such that

#a (b,0) = (a =* b) #a (xy) = #a (x) + #a (y)

Verify your implementation!

Remark. The x =* y is the characteristic function of the binary equality predicate x=y and it is defined in the module Maux*.


Function  Count  / 2 displayed by Tex_f2_ln_count as  # #1 ( #2 )
# a ( x ) =?
##

Theorem  Count_singleton
#a (b,0) = (a =* b)

Theorem  Count_conc
#a (xy) = #a (x) + #a (y)

Remark 

List union. Define the function x such that

(x,0) =x (xy) = x y

Verify your implementation!


Function  Union displayed by Tex_f1_ln_union as  #1
x =?
##

Theorem  Union_singleton
(x,0) =x

Theorem  Union_conc
(xy) = x y

Query:


Results:

Heap used: 368128 free: 133847572
Time used: 0:0:0:73