:: On the Decomposition of Finite Sequences
:: by Andrzej Trybulec
::
:: Received May 24, 1995
:: Copyright (c) 1995 Association of Mizar Users


begin

registration
let x, y, z be set ;
cluster <*x,y,z*> -> non trivial ;
coherence
not <*x,y,z*> is trivial
proof end;
end;

registration
let f be non empty FinSequence;
cluster Rev f -> non empty ;
coherence
not Rev f is empty
proof end;
end;

Lm1: for x, y being set holds rng <*x,y*> = {x,y}
proof end;

Lm2: for x, y, z being set holds rng <*x,y,z*> = {x,y,z}
proof end;

begin

theorem :: FINSEQ_6:1
canceled;

theorem :: FINSEQ_6:2
canceled;

theorem Th3: :: FINSEQ_6:3
for X being set
for i being Nat st X c= Seg i & 1 in X holds
(Sgm X) . 1 = 1
proof end;

theorem Th4: :: FINSEQ_6:4
for k being Nat
for f being FinSequence st k in dom f & ( for i being Nat st 1 <= i & i < k holds
f . i <> f . k ) holds
(f . k) .. f = k
proof end;

theorem Th5: :: FINSEQ_6:5
for p1, p2 being set holds <*p1,p2*> | (Seg 1) = <*p1*>
proof end;

theorem Th6: :: FINSEQ_6:6
for p1, p2, p3 being set holds <*p1,p2,p3*> | (Seg 1) = <*p1*>
proof end;

theorem Th7: :: FINSEQ_6:7
for p1, p2, p3 being set holds <*p1,p2,p3*> | (Seg 2) = <*p1,p2*>
proof end;

theorem Th8: :: FINSEQ_6:8
for f1, f2 being FinSequence
for p being set st p in rng f1 holds
p .. (f1 ^ f2) = p .. f1
proof end;

theorem Th9: :: FINSEQ_6:9
for f2, f1 being FinSequence
for p being set st p in (rng f2) \ (rng f1) holds
p .. (f1 ^ f2) = (len f1) + (p .. f2)
proof end;

theorem Th10: :: FINSEQ_6:10
for f1, f2 being FinSequence
for p being set st p in rng f1 holds
(f1 ^ f2) |-- p = (f1 |-- p) ^ f2
proof end;

theorem Th11: :: FINSEQ_6:11
for f2, f1 being FinSequence
for p being set st p in (rng f2) \ (rng f1) holds
(f1 ^ f2) |-- p = f2 |-- p
proof end;

theorem Th12: :: FINSEQ_6:12
for f1, f2 being FinSequence holds f1 c= f1 ^ f2
proof end;

theorem :: FINSEQ_6:13
for f1, f2 being FinSequence
for A being set st A c= dom f1 holds
(f1 ^ f2) | A = f1 | A by Th12, GRFUNC_1:88;

theorem Th14: :: FINSEQ_6:14
for f1, f2 being FinSequence
for p being set st p in rng f1 holds
(f1 ^ f2) -| p = f1 -| p
proof end;

registration
let f1 be FinSequence;
let i be natural number ;
cluster f1 | (Seg i) -> FinSequence-like ;
coherence
f1 | (Seg i) is FinSequence-like
by FINSEQ_1:19;
end;

theorem Th15: :: FINSEQ_6:15
for f1, f2, f3 being FinSequence st f1 c= f2 holds
f3 ^ f1 c= f3 ^ f2
proof end;

theorem Th16: :: FINSEQ_6:16
for f1, f2 being FinSequence
for i being Nat holds (f1 ^ f2) | (Seg ((len f1) + i)) = f1 ^ (f2 | (Seg i))
proof end;

theorem Th17: :: FINSEQ_6:17
for f2, f1 being FinSequence
for p being set st p in (rng f2) \ (rng f1) holds
(f1 ^ f2) -| p = f1 ^ (f2 -| p)
proof end;

theorem :: FINSEQ_6:18
canceled;

theorem Th19: :: FINSEQ_6:19
for f1, f2 being FinSequence
for p being set st f1 ^ f2 just_once_values p holds
p in (rng f1) \+\ (rng f2)
proof end;

theorem :: FINSEQ_6:20
for f1, f2 being FinSequence
for p being set st f1 ^ f2 just_once_values p & p in rng f1 holds
f1 just_once_values p
proof end;

theorem :: FINSEQ_6:21
canceled;

theorem Th22: :: FINSEQ_6:22
for p being set holds p .. <*p*> = 1
proof end;

theorem Th23: :: FINSEQ_6:23
for p1, p2 being set holds p1 .. <*p1,p2*> = 1
proof end;

theorem Th24: :: FINSEQ_6:24
for p1, p2 being set st p1 <> p2 holds
p2 .. <*p1,p2*> = 2
proof end;

theorem Th25: :: FINSEQ_6:25
for p1, p2, p3 being set holds p1 .. <*p1,p2,p3*> = 1
proof end;

theorem Th26: :: FINSEQ_6:26
for p1, p2, p3 being set st p1 <> p2 holds
p2 .. <*p1,p2,p3*> = 2
proof end;

theorem Th27: :: FINSEQ_6:27
for p1, p3, p2 being set st p1 <> p3 & p2 <> p3 holds
p3 .. <*p1,p2,p3*> = 3
proof end;

theorem Th28: :: FINSEQ_6:28
for p being set
for f being FinSequence holds Rev (<*p*> ^ f) = (Rev f) ^ <*p*>
proof end;

theorem Th29: :: FINSEQ_6:29
for f being FinSequence holds Rev (Rev f) = f
proof end;

theorem Th30: :: FINSEQ_6:30
for x, y being set st x <> y holds
<*x,y*> -| y = <*x*>
proof end;

theorem Th31: :: FINSEQ_6:31
for x, y, z being set st x <> y holds
<*x,y,z*> -| y = <*x*>
proof end;

theorem Th32: :: FINSEQ_6:32
for x, z, y being set st x <> z & y <> z holds
<*x,y,z*> -| z = <*x,y*>
proof end;

theorem :: FINSEQ_6:33
for x, y being set holds <*x,y*> |-- x = <*y*>
proof end;

theorem Th34: :: FINSEQ_6:34
for x, y, z being set st x <> y holds
<*x,y,z*> |-- y = <*z*>
proof end;

theorem :: FINSEQ_6:35
for x, y, z being set holds <*x,y,z*> |-- x = <*y,z*>
proof end;

theorem Th36: :: FINSEQ_6:36
for z being set holds
( <*z*> |-- z = {} & <*z*> -| z = {} )
proof end;

theorem Th37: :: FINSEQ_6:37
for x, y being set st x <> y holds
<*x,y*> |-- y = {}
proof end;

theorem Th38: :: FINSEQ_6:38
for x, z, y being set st x <> z & y <> z holds
<*x,y,z*> |-- z = {}
proof end;

theorem Th39: :: FINSEQ_6:39
for x, y being set
for f being FinSequence st x in rng f & y in rng (f -| x) holds
(f -| x) -| y = f -| y
proof end;

theorem Th40: :: FINSEQ_6:40
for x being set
for f1, f2 being FinSequence st not x in rng f1 holds
x .. ((f1 ^ <*x*>) ^ f2) = (len f1) + 1
proof end;

theorem Th41: :: FINSEQ_6:41
for x being set
for f being FinSequence st f just_once_values x holds
(x .. f) + (x .. (Rev f)) = (len f) + 1
proof end;

theorem Th42: :: FINSEQ_6:42
for x being set
for f being FinSequence st f just_once_values x holds
Rev (f -| x) = (Rev f) |-- x
proof end;

theorem :: FINSEQ_6:43
for x being set
for f being FinSequence st f just_once_values x holds
Rev f just_once_values x
proof end;

begin

theorem Th44: :: FINSEQ_6:44
for D being non empty set
for p being Element of D
for f being FinSequence of D st p in rng f holds
f -: p = (f -| p) ^ <*p*>
proof end;

theorem Th45: :: FINSEQ_6:45
for D being non empty set
for p being Element of D
for f being FinSequence of D st p in rng f holds
f :- p = <*p*> ^ (f |-- p)
proof end;

theorem Th46: :: FINSEQ_6:46
for D being non empty set
for f being FinSequence of D st f <> {} holds
f /. 1 in rng f
proof end;

theorem Th47: :: FINSEQ_6:47
for D being non empty set
for f being FinSequence of D st f <> {} holds
(f /. 1) .. f = 1
proof end;

theorem Th48: :: FINSEQ_6:48
for D being non empty set
for p being Element of D
for f being FinSequence of D st f <> {} & f /. 1 = p holds
( f -: p = <*p*> & f :- p = f )
proof end;

theorem Th49: :: FINSEQ_6:49
for D being non empty set
for p1 being Element of D
for f being FinSequence of D holds (<*p1*> ^ f) /^ 1 = f
proof end;

theorem Th50: :: FINSEQ_6:50
for D being non empty set
for p1, p2 being Element of D holds <*p1,p2*> /^ 1 = <*p2*>
proof end;

theorem Th51: :: FINSEQ_6:51
for D being non empty set
for p1, p2, p3 being Element of D holds <*p1,p2,p3*> /^ 1 = <*p2,p3*>
proof end;

theorem Th52: :: FINSEQ_6:52
for k being Nat
for D being non empty set
for f being FinSequence of D st k in dom f & ( for i being Nat st 1 <= i & i < k holds
f /. i <> f /. k ) holds
(f /. k) .. f = k
proof end;

theorem Th53: :: FINSEQ_6:53
for D being non empty set
for p1, p2 being Element of D st p1 <> p2 holds
<*p1,p2*> -: p2 = <*p1,p2*>
proof end;

theorem Th54: :: FINSEQ_6:54
for D being non empty set
for p1, p2, p3 being Element of D st p1 <> p2 holds
<*p1,p2,p3*> -: p2 = <*p1,p2*>
proof end;

theorem Th55: :: FINSEQ_6:55
for D being non empty set
for p1, p3, p2 being Element of D st p1 <> p3 & p2 <> p3 holds
<*p1,p2,p3*> -: p3 = <*p1,p2,p3*>
proof end;

theorem :: FINSEQ_6:56
for D being non empty set
for p being Element of D holds
( <*p*> :- p = <*p*> & <*p*> -: p = <*p*> )
proof end;

theorem Th57: :: FINSEQ_6:57
for D being non empty set
for p1, p2 being Element of D st p1 <> p2 holds
<*p1,p2*> :- p2 = <*p2*>
proof end;

theorem Th58: :: FINSEQ_6:58
for D being non empty set
for p1, p2, p3 being Element of D st p1 <> p2 holds
<*p1,p2,p3*> :- p2 = <*p2,p3*>
proof end;

theorem Th59: :: FINSEQ_6:59
for D being non empty set
for p1, p3, p2 being Element of D st p1 <> p3 & p2 <> p3 holds
<*p1,p2,p3*> :- p3 = <*p3*>
proof end;

theorem :: FINSEQ_6:60
canceled;

theorem Th61: :: FINSEQ_6:61
for k being Nat
for D being non empty set
for p being Element of D
for f being FinSequence of D st p in rng f & p .. f > k holds
p .. f = k + (p .. (f /^ k))
proof end;

theorem Th62: :: FINSEQ_6:62
for k being Nat
for D being non empty set
for p being Element of D
for f being FinSequence of D st p in rng f & p .. f > k holds
p in rng (f /^ k)
proof end;

theorem Th63: :: FINSEQ_6:63
for k, i being Nat
for D being non empty set
for f being FinSequence of D st k < i & i in dom f holds
f /. i in rng (f /^ k)
proof end;

theorem Th64: :: FINSEQ_6:64
for k being Nat
for D being non empty set
for p being Element of D
for f being FinSequence of D st p in rng f & p .. f > k holds
(f /^ k) -: p = (f -: p) /^ k
proof end;

theorem Th65: :: FINSEQ_6:65
for D being non empty set
for p being Element of D
for f being FinSequence of D st p in rng f & p .. f <> 1 holds
(f /^ 1) -: p = (f -: p) /^ 1
proof end;

theorem Th66: :: FINSEQ_6:66
for D being non empty set
for p being Element of D
for f being FinSequence of D holds p in rng (f :- p)
proof end;

theorem Th67: :: FINSEQ_6:67
for x being set
for D being non empty set
for p being Element of D
for f being FinSequence of D st x in rng f & p in rng f & x .. f >= p .. f holds
x in rng (f :- p)
proof end;

theorem Th68: :: FINSEQ_6:68
for k being Nat
for D being non empty set
for p being Element of D
for f being FinSequence of D st p in rng f & k <= len f & k >= p .. f holds
f /. k in rng (f :- p)
proof end;

theorem Th69: :: FINSEQ_6:69
for D being non empty set
for p being Element of D
for f1, f2 being FinSequence of D st p in rng f1 holds
(f1 ^ f2) :- p = (f1 :- p) ^ f2
proof end;

theorem Th70: :: FINSEQ_6:70
for D being non empty set
for p being Element of D
for f2, f1 being FinSequence of D st p in (rng f2) \ (rng f1) holds
(f1 ^ f2) :- p = f2 :- p
proof end;

theorem Th71: :: FINSEQ_6:71
for D being non empty set
for p being Element of D
for f1, f2 being FinSequence of D st p in rng f1 holds
(f1 ^ f2) -: p = f1 -: p
proof end;

theorem Th72: :: FINSEQ_6:72
for D being non empty set
for p being Element of D
for f2, f1 being FinSequence of D st p in (rng f2) \ (rng f1) holds
(f1 ^ f2) -: p = f1 ^ (f2 -: p)
proof end;

theorem :: FINSEQ_6:73
for D being non empty set
for p being Element of D
for f being FinSequence of D holds (f :- p) :- p = f :- p
proof end;

theorem Th74: :: FINSEQ_6:74
for D being non empty set
for p1, p2 being Element of D
for f being FinSequence of D st p1 in rng f & p2 in (rng f) \ (rng (f -: p1)) holds
f |-- p2 = (f |-- p1) |-- p2
proof end;

theorem Th75: :: FINSEQ_6:75
for D being non empty set
for p being Element of D
for f being FinSequence of D st p in rng f holds
rng f = (rng (f -: p)) \/ (rng (f :- p))
proof end;

theorem Th76: :: FINSEQ_6:76
for D being non empty set
for p1, p2 being Element of D
for f being FinSequence of D st p1 in rng f & p2 in (rng f) \ (rng (f -: p1)) holds
(f :- p1) :- p2 = f :- p2
proof end;

theorem Th77: :: FINSEQ_6:77
for D being non empty set
for p being Element of D
for f being FinSequence of D st p in rng f holds
p .. (f -: p) = p .. f
proof end;

theorem Th78: :: FINSEQ_6:78
for i being Nat
for D being non empty set
for f being FinSequence of D holds (f | i) | i = f | i
proof end;

theorem Th79: :: FINSEQ_6:79
for D being non empty set
for p being Element of D
for f being FinSequence of D st p in rng f holds
(f -: p) -: p = f -: p
proof end;

theorem Th80: :: FINSEQ_6:80
for D being non empty set
for p1, p2 being Element of D
for f being FinSequence of D st p1 in rng f & p2 in rng (f -: p1) holds
(f -: p1) -: p2 = f -: p2
proof end;

theorem Th81: :: FINSEQ_6:81
for D being non empty set
for p being Element of D
for f being FinSequence of D st p in rng f holds
(f -: p) ^ ((f :- p) /^ 1) = f
proof end;

theorem Th82: :: FINSEQ_6:82
for D being non empty set
for f1, f2 being FinSequence of D st f1 <> {} holds
(f1 ^ f2) /^ 1 = (f1 /^ 1) ^ f2
proof end;

theorem Th83: :: FINSEQ_6:83
for D being non empty set
for p2 being Element of D
for f being FinSequence of D st p2 in rng f & p2 .. f <> 1 holds
p2 in rng (f /^ 1)
proof end;

theorem Th84: :: FINSEQ_6:84
for D being non empty set
for p being Element of D
for f being FinSequence of D holds p .. (f :- p) = 1
proof end;

Lm3: for i being Nat
for D being non empty set
for p being Element of D
for f being FinSequence of D st p in rng f & p .. f > i holds
i + (p .. (f /^ i)) = p .. f
proof end;

theorem :: FINSEQ_6:85
canceled;

theorem Th86: :: FINSEQ_6:86
for k being Nat
for D being non empty set holds (<*> D) /^ k = <*> D
proof end;

theorem Th87: :: FINSEQ_6:87
for i, k being Nat
for D being non empty set
for f being FinSequence of D holds f /^ (i + k) = (f /^ i) /^ k
proof end;

theorem Th88: :: FINSEQ_6:88
for k being Nat
for D being non empty set
for p being Element of D
for f being FinSequence of D st p in rng f & p .. f > k holds
(f /^ k) :- p = f :- p
proof end;

theorem Th89: :: FINSEQ_6:89
for D being non empty set
for p being Element of D
for f being FinSequence of D st p in rng f & p .. f <> 1 holds
(f /^ 1) :- p = f :- p
proof end;

theorem Th90: :: FINSEQ_6:90
for i, k being Nat
for D being non empty set
for f being FinSequence of D st i + k = len f holds
Rev (f /^ k) = (Rev f) | i
proof end;

theorem Th91: :: FINSEQ_6:91
for i, k being Nat
for D being non empty set
for f being FinSequence of D st i + k = len f holds
Rev (f | k) = (Rev f) /^ i
proof end;

theorem Th92: :: FINSEQ_6:92
for D being non empty set
for p being Element of D
for f being FinSequence of D st f just_once_values p holds
Rev (f |-- p) = (Rev f) -| p
proof end;

theorem Th93: :: FINSEQ_6:93
for D being non empty set
for p being Element of D
for f being FinSequence of D st f just_once_values p holds
Rev (f :- p) = (Rev f) -: p
proof end;

theorem Th94: :: FINSEQ_6:94
for D being non empty set
for p being Element of D
for f being FinSequence of D st f just_once_values p holds
Rev (f -: p) = (Rev f) :- p
proof end;

begin

definition
let D be non empty set ;
let IT be FinSequence of D;
attr IT is circular means :Def1: :: FINSEQ_6:def 1
IT /. 1 = IT /. (len IT);
end;

:: deftheorem Def1 defines circular FINSEQ_6:def 1 :
for D being non empty set
for IT being FinSequence of D holds
( IT is circular iff IT /. 1 = IT /. (len IT) );

definition
let D be non empty set ;
let f be FinSequence of D;
let p be Element of D;
func Rotate (f,p) -> FinSequence of D equals :Def2: :: FINSEQ_6:def 2
(f :- p) ^ ((f -: p) /^ 1) if p in rng f
otherwise f;
correctness
coherence
( ( p in rng f implies (f :- p) ^ ((f -: p) /^ 1) is FinSequence of D ) & ( not p in rng f implies f is FinSequence of D ) )
;
consistency
for b1 being FinSequence of D holds verum
;
;
end;

:: deftheorem Def2 defines Rotate FINSEQ_6:def 2 :
for D being non empty set
for f being FinSequence of D
for p being Element of D holds
( ( p in rng f implies Rotate (f,p) = (f :- p) ^ ((f -: p) /^ 1) ) & ( not p in rng f implies Rotate (f,p) = f ) );

registration
let D be non empty set ;
let f be non empty FinSequence of D;
let p be Element of D;
cluster Rotate (f,p) -> non empty ;
coherence
not Rotate (f,p) is empty
proof end;
end;

registration
let D be non empty set ;
cluster non empty trivial Relation-like D -valued Function-like V31() FinSequence-like FinSubsequence-like circular FinSequence of D;
existence
ex b1 being FinSequence of D st
( b1 is circular & not b1 is empty & b1 is trivial )
proof end;
cluster non empty non trivial Relation-like D -valued Function-like V31() FinSequence-like FinSubsequence-like circular FinSequence of D;
existence
ex b1 being FinSequence of D st
( b1 is circular & not b1 is empty & not b1 is trivial )
proof end;
end;

theorem Th95: :: FINSEQ_6:95
for D being non empty set
for f being FinSequence of D holds Rotate (f,(f /. 1)) = f
proof end;

registration
let D be non empty set ;
let p be Element of D;
let f be non empty circular FinSequence of D;
cluster Rotate (f,p) -> circular ;
coherence
Rotate (f,p) is circular
proof end;
end;

theorem :: FINSEQ_6:96
for D being non empty set
for p being Element of D
for f being FinSequence of D st f is circular & p in rng f holds
rng (Rotate (f,p)) = rng f
proof end;

theorem Th97: :: FINSEQ_6:97
for D being non empty set
for p being Element of D
for f being FinSequence of D st p in rng f holds
p in rng (Rotate (f,p))
proof end;

theorem Th98: :: FINSEQ_6:98
for D being non empty set
for p being Element of D
for f being FinSequence of D st p in rng f holds
(Rotate (f,p)) /. 1 = p
proof end;

theorem Th99: :: FINSEQ_6:99
for D being non empty set
for p being Element of D
for f being FinSequence of D holds Rotate ((Rotate (f,p)),p) = Rotate (f,p)
proof end;

theorem :: FINSEQ_6:100
for D being non empty set
for p being Element of D holds Rotate (<*p*>,p) = <*p*>
proof end;

theorem Th101: :: FINSEQ_6:101
for D being non empty set
for p1, p2 being Element of D holds Rotate (<*p1,p2*>,p1) = <*p1,p2*>
proof end;

theorem :: FINSEQ_6:102
for D being non empty set
for p1, p2 being Element of D holds Rotate (<*p1,p2*>,p2) = <*p2,p2*>
proof end;

theorem Th103: :: FINSEQ_6:103
for D being non empty set
for p1, p2, p3 being Element of D holds Rotate (<*p1,p2,p3*>,p1) = <*p1,p2,p3*>
proof end;

theorem :: FINSEQ_6:104
for D being non empty set
for p1, p2, p3 being Element of D st p1 <> p2 holds
Rotate (<*p1,p2,p3*>,p2) = <*p2,p3,p2*>
proof end;

theorem :: FINSEQ_6:105
for D being non empty set
for p2, p3, p1 being Element of D st p2 <> p3 holds
Rotate (<*p1,p2,p3*>,p3) = <*p3,p2,p3*>
proof end;

theorem :: FINSEQ_6:106
for D being non empty set
for f being non trivial circular FinSequence of D holds rng (f /^ 1) = rng f
proof end;

theorem Th107: :: FINSEQ_6:107
for D being non empty set
for p being Element of D
for f being FinSequence of D holds rng (f /^ 1) c= rng (Rotate (f,p))
proof end;

theorem Th108: :: FINSEQ_6:108
for D being non empty set
for p2, p1 being Element of D
for f being FinSequence of D st p2 in (rng f) \ (rng (f -: p1)) holds
Rotate ((Rotate (f,p1)),p2) = Rotate (f,p2)
proof end;

theorem Th109: :: FINSEQ_6:109
for D being non empty set
for p2, p1 being Element of D
for f being FinSequence of D st p2 .. f <> 1 & p2 in (rng f) \ (rng (f :- p1)) holds
Rotate ((Rotate (f,p1)),p2) = Rotate (f,p2)
proof end;

theorem Th110: :: FINSEQ_6:110
for D being non empty set
for p2, p1 being Element of D
for f being FinSequence of D st p2 in rng (f /^ 1) & f just_once_values p2 holds
Rotate ((Rotate (f,p1)),p2) = Rotate (f,p2)
proof end;

theorem :: FINSEQ_6:111
for D being non empty set
for p2, p1 being Element of D
for f being FinSequence of D st f is circular & f just_once_values p2 holds
Rotate ((Rotate (f,p1)),p2) = Rotate (f,p2)
proof end;

theorem :: FINSEQ_6:112
for D being non empty set
for p being Element of D
for f being FinSequence of D st f is circular & f just_once_values p holds
Rev (Rotate (f,p)) = Rotate ((Rev f),p)
proof end;

begin

theorem :: FINSEQ_6:113
for D being non empty set
for f being trivial FinSequence of D holds
( f is empty or ex x being Element of D st f = <*x*> )
proof end;

begin

theorem :: FINSEQ_6:114
for i being Nat
for p, q being FinSequence st len p < i & ( i <= (len p) + (len q) or i <= len (p ^ q) ) holds
(p ^ q) . i = q . (i - (len p))
proof end;

theorem :: FINSEQ_6:115
for D being non empty set
for x being set
for f being FinSequence of D st 1 <= len f holds
( (f ^ <*x*>) . 1 = f . 1 & (f ^ <*x*>) . 1 = f /. 1 & (<*x*> ^ f) . ((len f) + 1) = f . (len f) & (<*x*> ^ f) . ((len f) + 1) = f /. (len f) )
proof end;

theorem Th18: :: FINSEQ_6:116
for f being FinSequence st len f = 1 holds
Rev f = f
proof end;

theorem :: FINSEQ_6:117
for D being non empty set
for f being FinSequence of D
for k being Nat holds len (f /^ k) = (len f) -' k by RFINSEQ:42;

theorem :: FINSEQ_6:118
for D being non empty set
for f being FinSequence of D
for l1, l2 being Nat holds (f /^ l1) | (l2 -' l1) = (f | l2) /^ l1 by FINSEQ_5:83;

definition
let f be FinSequence;
let k1, k2 be Nat;
func mid (f,k1,k2) -> FinSequence equals :Def1: :: FINSEQ_6:def 3
(f /^ (k1 -' 1)) | ((k2 -' k1) + 1) if k1 <= k2
otherwise Rev ((f /^ (k2 -' 1)) | ((k1 -' k2) + 1));
correctness
coherence
( ( k1 <= k2 implies (f /^ (k1 -' 1)) | ((k2 -' k1) + 1) is FinSequence ) & ( not k1 <= k2 implies Rev ((f /^ (k2 -' 1)) | ((k1 -' k2) + 1)) is FinSequence ) )
;
consistency
for b1 being FinSequence holds verum
;
;
end;

:: deftheorem Def1 defines mid FINSEQ_6:def 3 :
for f being FinSequence
for k1, k2 being Nat holds
( ( k1 <= k2 implies mid (f,k1,k2) = (f /^ (k1 -' 1)) | ((k2 -' k1) + 1) ) & ( not k1 <= k2 implies mid (f,k1,k2) = Rev ((f /^ (k2 -' 1)) | ((k1 -' k2) + 1)) ) );

definition
let D be non empty set ;
let f be FinSequence of D;
let k1, k2 be Nat;
:: original: mid
redefine func mid (f,k1,k2) -> FinSequence of D;
coherence
mid (f,k1,k2) is FinSequence of D
proof end;
end;

theorem :: FINSEQ_6:119
for D being non empty set
for f being FinSequence of D
for k1, k2 being Element of NAT st 1 <= k1 & k1 <= len f & 1 <= k2 & k2 <= len f holds
Rev (mid (f,k1,k2)) = mid ((Rev f),(((len f) -' k2) + 1),(((len f) -' k1) + 1))
proof end;

theorem Th23: :: FINSEQ_6:120
for D being non empty set
for n, m being Element of NAT
for f being FinSequence of D st 1 <= m & m + n <= len f holds
(f /^ n) . m = f . (m + n)
proof end;

theorem Th24: :: FINSEQ_6:121
for D being non empty set
for i being Element of NAT
for f being FinSequence of D st 1 <= i & i <= len f holds
(Rev f) . i = f . (((len f) - i) + 1)
proof end;

theorem :: FINSEQ_6:122
for D being non empty set
for f being FinSequence of D
for k being Nat st 1 <= k holds
mid (f,1,k) = f | k
proof end;

theorem :: FINSEQ_6:123
for D being non empty set
for f being FinSequence of D
for k being Element of NAT st k <= len f holds
mid (f,k,(len f)) = f /^ (k -' 1)
proof end;

theorem Th27: :: FINSEQ_6:124
for D being non empty set
for f being FinSequence of D
for k1, k2 being Element of NAT st 1 <= k1 & k1 <= len f & 1 <= k2 & k2 <= len f holds
( (mid (f,k1,k2)) . 1 = f . k1 & ( k1 <= k2 implies ( len (mid (f,k1,k2)) = (k2 -' k1) + 1 & ( for i being Element of NAT st 1 <= i & i <= len (mid (f,k1,k2)) holds
(mid (f,k1,k2)) . i = f . ((i + k1) -' 1) ) ) ) & ( k1 > k2 implies ( len (mid (f,k1,k2)) = (k1 -' k2) + 1 & ( for i being Element of NAT st 1 <= i & i <= len (mid (f,k1,k2)) holds
(mid (f,k1,k2)) . i = f . ((k1 -' i) + 1) ) ) ) )
proof end;

theorem :: FINSEQ_6:125
for D being non empty set
for f being FinSequence of D
for k1, k2 being Element of NAT holds rng (mid (f,k1,k2)) c= rng f
proof end;

theorem :: FINSEQ_6:126
for D being non empty set
for f being FinSequence of D st 1 <= len f holds
mid (f,1,(len f)) = f
proof end;

theorem :: FINSEQ_6:127
for D being non empty set
for f being FinSequence of D st 1 <= len f holds
mid (f,(len f),1) = Rev f
proof end;

theorem Th31: :: FINSEQ_6:128
for D being non empty set
for f being FinSequence of D
for k1, k2, i being Element of NAT st 1 <= k1 & k1 <= k2 & k2 <= len f & 1 <= i & ( i <= (k2 -' k1) + 1 or i <= (k2 - k1) + 1 or i <= (k2 + 1) - k1 ) holds
( (mid (f,k1,k2)) . i = f . ((i + k1) -' 1) & (mid (f,k1,k2)) . i = f . ((i -' 1) + k1) & (mid (f,k1,k2)) . i = f . ((i + k1) - 1) & (mid (f,k1,k2)) . i = f . ((i - 1) + k1) )
proof end;

theorem :: FINSEQ_6:129
for D being non empty set
for f being FinSequence of D
for k, i being Nat st 1 <= i & i <= k & k <= len f holds
(mid (f,1,k)) . i = f . i
proof end;

theorem :: FINSEQ_6:130
for D being non empty set
for f being FinSequence of D
for k1, k2 being Element of NAT st 1 <= k1 & k1 <= k2 & k2 <= len f holds
len (mid (f,k1,k2)) <= len f
proof end;

theorem Th55: :: FINSEQ_6:131
for D being non empty set
for f being FinSequence of D
for k being Element of NAT
for p being Element of D holds (<*p*> ^ f) | (k + 1) = <*p*> ^ (f | k)
proof end;

theorem :: FINSEQ_6:132
for D being non empty set
for f being FinSequence of D
for k1, k2 being Element of NAT st k1 < k2 & k1 in dom f holds
mid (f,k1,k2) = <*(f . k1)*> ^ (mid (f,(k1 + 1),k2))
proof end;