Adelfa Home

Properties of Lists

Specification

[View lists.lf]
nat : type.
z : nat.
s : {x:nat} nat.

list : type.
nil : list.
cons : {n:nat} {l:list} list.

eq_list : {L1:list}{L2:list}type.
refl_list : {L:list} eq_list L L.

append : {L1:list}{L2:list}{L3:list}type.
append_nil : {L:list} append nil L L.
append_cons : {L1:list}{L2:list}{L3:list}{N:nat}{D:append L1 L2 L3}
  append (cons N L1) L2 (cons N L3).

rev_app : {L1:list}{L2:list}type.
rev_app_nil : rev_app nil nil.
rev_app_cons : {N:nat} {A:list} {B:list} {BN:list} {D:rev_app A B}
  {D2:append B (cons N nil) BN} rev_app (cons N A) BN.

rev_acc : {L1:list}{Acc:list}{L2:list}type.
rev_acc_nil : {L:list} rev_acc nil L L.
rev_acc_cons : {L1:list} {L2:list} {L3:list} {N:nat} {D:rev_acc L1 (cons N L2) L3}
  rev_acc (cons N L1) L2 L3.

Reasoning

[View lists.ath]

Click on a command or tactic to see a detailed view of its use.

Specification "lists.lf".

%%% append theorems

Theorem app_assoc : forall L1 L2 L3 L23 L4 D1 D2, {D1 : append L2 L3 L23} =>
  {D2 : append L1 L23 L4} =>
  exists L12 D3 D4, {D3 : append L1 L2 L12} /\ {D4 : append L12 L3 L4}.

Theorem app_identity : forall L1 L2 D, {D : append L1 nil L2} =>
  exists R, {R : eq_list L1 L2}.

%%% rev_app (reverse defined using append) theorems

% proves that the append of two reverses is the reverse of two appends.
Theorem rev_app_swap : forall A B a b AB ba D1 D2 D3 D4,
  {D1 : append A B AB} =>
  {D2 : rev_app A a} =>
  {D3 : rev_app B b} =>
  {D4 : append b a ba} =>
  exists D5, {D5 : rev_app AB ba}.

Theorem rev_app_rev : forall L1 L2 D1, {D1 : rev_app L1 L2} =>
  exists D2, {D2 : rev_app L2 L1}.

%%% rev_acc (reverse defined using an accumulator list) theorems

Theorem rev_acc_func : forall L1 L2 L3 L4 D1 D2, {D1 : rev_acc L1 L2 L3} =>
  {D2 : rev_acc L1 L2 L4} =>
  exists D3, {D3 : eq_list L3 L4}.

Theorem rev_acc_exists : forall L1 L2, {L1 : list} => {L2 : list} =>
  exists L3 D1, {D1 : rev_acc L1 L2 L3}.

Theorem rev_acc_rev_lem : forall a B AB ba ba2 D1 D2 D3, {D1 : rev_acc a B AB} =>
  {D2 : rev_acc AB nil ba} => {D3 : rev_acc B a ba2} =>
  exists D4, {D4 : eq_list ba ba2}.

Theorem rev_acc_rev : forall L1 L2 D1, {D1 : rev_acc L1 nil L2} =>
  exists D2, {D2 : rev_acc L2 nil L1}.