:: Functions and Finite Sequences of Real Numbers
:: by Jaros{\l}aw Kotowicz
::
:: Received March 15, 1993
:: Copyright (c) 1993-2021 Association of Mizar Users


registration
let f be finite Relation;
let x be object ;
cluster Coim (f,x) -> finite ;
coherence
Coim (f,x) is finite
proof end;
end;

theorem Th1: :: RFINSEQ:1
for f, g, h being FinSequence holds
( f,g are_fiberwise_equipotent iff f ^ h,g ^ h are_fiberwise_equipotent )
proof end;

theorem :: RFINSEQ:2
for f, g being FinSequence holds f ^ g,g ^ f are_fiberwise_equipotent
proof end;

theorem Th3: :: RFINSEQ:3
for f, g being FinSequence st f,g are_fiberwise_equipotent holds
( len f = len g & dom f = dom g )
proof end;

theorem Th4: :: RFINSEQ:4
for f, g being FinSequence holds
( f,g are_fiberwise_equipotent iff ex P being Permutation of (dom g) st f = g * P )
proof end;

defpred S1[ Nat] means for X being finite set
for F being Function st card (dom (F | X)) = $1 holds
ex a being FinSequence st F | X,a are_fiberwise_equipotent ;

Lm1: S1[ 0 ]
proof end;

Lm2: for n being Nat st S1[n] holds
S1[n + 1]

proof end;

theorem :: RFINSEQ:5
for F being Function
for X being finite set ex f being FinSequence st F | X,f are_fiberwise_equipotent
proof end;

definition
let n be Nat;
let f be FinSequence;
func f /^ n -> FinSequence means :Def1: :: RFINSEQ:def 1
( len it = (len f) - n & ( for m being Nat st m in dom it holds
it . m = f . (m + n) ) ) if n <= len f
otherwise it = {} ;
existence
( ( n <= len f implies ex b1 being FinSequence st
( len b1 = (len f) - n & ( for m being Nat st m in dom b1 holds
b1 . m = f . (m + n) ) ) ) & ( not n <= len f implies ex b1 being FinSequence st b1 = {} ) )
proof end;
uniqueness
for b1, b2 being FinSequence holds
( ( n <= len f & len b1 = (len f) - n & ( for m being Nat st m in dom b1 holds
b1 . m = f . (m + n) ) & len b2 = (len f) - n & ( for m being Nat st m in dom b2 holds
b2 . m = f . (m + n) ) implies b1 = b2 ) & ( not n <= len f & b1 = {} & b2 = {} implies b1 = b2 ) )
proof end;
consistency
for b1 being FinSequence holds verum
;
end;

:: deftheorem Def1 defines /^ RFINSEQ:def 1 :
for n being Nat
for f, b3 being FinSequence holds
( ( n <= len f implies ( b3 = f /^ n iff ( len b3 = (len f) - n & ( for m being Nat st m in dom b3 holds
b3 . m = f . (m + n) ) ) ) ) & ( not n <= len f implies ( b3 = f /^ n iff b3 = {} ) ) );

definition
let D be set ;
let n be Nat;
let f be FinSequence of D;
:: original: /^
redefine func f /^ n -> FinSequence of D;
coherence
f /^ n is FinSequence of D
proof end;
end;

Lm3: for n being Nat
for f being FinSequence st len f <= n holds
f | n = f

proof end;

theorem Th6: :: RFINSEQ:6
for f being FinSequence
for n, m being Nat st n in dom f & m in Seg n holds
( (f | n) . m = f . m & m in dom f )
proof end;

theorem Th7: :: RFINSEQ:7
for f being FinSequence
for n being Nat st n + 1 = len f holds
f = (f | n) ^ <*(f . (n + 1))*>
proof end;

Th8A: for D being non empty set
for f being FinSequence of D
for n being Nat holds (f | n) ^ (f /^ n) = f

proof end;

theorem Th8: :: RFINSEQ:8
for f being FinSequence
for n being Nat holds (f | n) ^ (f /^ n) = f
proof end;

registration
let f be FinSequence;
let n be Nat;
reduce (f | n) ^ (f /^ n) to f;
reducibility
(f | n) ^ (f /^ n) = f
by Th8;
end;

theorem :: RFINSEQ:9
for R1, R2 being FinSequence of REAL st R1,R2 are_fiberwise_equipotent holds
Sum R1 = Sum R2
proof end;

definition
let R be real-valued FinSequence;
func MIM R -> FinSequence of REAL means :Def2: :: RFINSEQ:def 2
( len it = len R & it . (len it) = R . (len R) & ( for n being Nat st 1 <= n & n <= (len it) - 1 holds
it . n = (R . n) - (R . (n + 1)) ) );
existence
ex b1 being FinSequence of REAL st
( len b1 = len R & b1 . (len b1) = R . (len R) & ( for n being Nat st 1 <= n & n <= (len b1) - 1 holds
b1 . n = (R . n) - (R . (n + 1)) ) )
proof end;
uniqueness
for b1, b2 being FinSequence of REAL st len b1 = len R & b1 . (len b1) = R . (len R) & ( for n being Nat st 1 <= n & n <= (len b1) - 1 holds
b1 . n = (R . n) - (R . (n + 1)) ) & len b2 = len R & b2 . (len b2) = R . (len R) & ( for n being Nat st 1 <= n & n <= (len b2) - 1 holds
b2 . n = (R . n) - (R . (n + 1)) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def2 defines MIM RFINSEQ:def 2 :
for R being real-valued FinSequence
for b2 being FinSequence of REAL holds
( b2 = MIM R iff ( len b2 = len R & b2 . (len b2) = R . (len R) & ( for n being Nat st 1 <= n & n <= (len b2) - 1 holds
b2 . n = (R . n) - (R . (n + 1)) ) ) );

theorem Th10: :: RFINSEQ:10
for R being FinSequence of REAL
for n being Nat st len R = n + 2 holds
MIM (R | (n + 1)) = ((MIM R) | n) ^ <*(R . (n + 1))*>
proof end;

theorem Th11: :: RFINSEQ:11
for R being FinSequence of REAL
for r, s being Real
for n being Nat st len R = n + 2 & R . (n + 1) = r & R . (n + 2) = s holds
MIM R = ((MIM R) | n) ^ <*(r - s),s*>
proof end;

theorem Th12: :: RFINSEQ:12
MIM (<*> REAL) = <*> REAL
proof end;

theorem Th13: :: RFINSEQ:13
for r being Real holds MIM <*r*> = <*r*>
proof end;

theorem :: RFINSEQ:14
for r, s being Real holds MIM <*r,s*> = <*(r - s),s*>
proof end;

theorem :: RFINSEQ:15
for R being FinSequence of REAL
for n being Nat holds (MIM R) /^ n = MIM (R /^ n)
proof end;

theorem Th16: :: RFINSEQ:16
for R being FinSequence of REAL st len R <> 0 holds
Sum (MIM R) = R . 1
proof end;

theorem :: RFINSEQ:17
for R being FinSequence of REAL
for n being Nat st n < len R holds
Sum (MIM (R /^ n)) = R . (n + 1)
proof end;

definition
let IT be real-valued FinSequence;
redefine attr IT is non-increasing means :Def3: :: RFINSEQ:def 3
for n being Nat st n in dom IT & n + 1 in dom IT holds
IT . n >= IT . (n + 1);
compatibility
( IT is non-increasing iff for n being Nat st n in dom IT & n + 1 in dom IT holds
IT . n >= IT . (n + 1) )
proof end;
end;

:: deftheorem Def3 defines non-increasing RFINSEQ:def 3 :
for IT being real-valued FinSequence holds
( IT is non-increasing iff for n being Nat st n in dom IT & n + 1 in dom IT holds
IT . n >= IT . (n + 1) );

registration
cluster Relation-like NAT -defined REAL -valued Function-like finite FinSequence-like FinSubsequence-like complex-valued ext-real-valued real-valued non-increasing for FinSequence of REAL ;
existence
ex b1 being FinSequence of REAL st b1 is non-increasing
proof end;
end;

theorem Th18: :: RFINSEQ:18
for R being FinSequence of REAL st ( len R = 0 or len R = 1 ) holds
R is non-increasing
proof end;

theorem Th19: :: RFINSEQ:19
for R being FinSequence of REAL holds
( R is non-increasing iff for n, m being Nat st n in dom R & m in dom R & n < m holds
R . n >= R . m )
proof end;

theorem Th20: :: RFINSEQ:20
for R being non-increasing FinSequence of REAL
for n being Nat holds R | n is non-increasing FinSequence of REAL
proof end;

theorem :: RFINSEQ:21
for R being non-increasing FinSequence of REAL
for n being Element of NAT holds R /^ n is non-increasing
proof end;

Lm4: for f, g being non-increasing FinSequence of REAL
for n being Nat st len f = n + 1 & len f = len g & f,g are_fiberwise_equipotent holds
( f . (len f) = g . (len g) & f | n,g | n are_fiberwise_equipotent )

proof end;

defpred S2[ Nat] means for R being FinSequence of REAL st $1 = len R holds
ex b being non-increasing FinSequence of REAL st R,b are_fiberwise_equipotent ;

Lm5: S2[ 0 ]
proof end;

Lm6: for n being Nat st S2[n] holds
S2[n + 1]

proof end;

theorem Th22: :: RFINSEQ:22
for R being FinSequence of REAL ex R1 being non-increasing FinSequence of REAL st R,R1 are_fiberwise_equipotent
proof end;

Lm7: for n being Nat
for g1, g2 being non-increasing FinSequence of REAL st n = len g1 & g1,g2 are_fiberwise_equipotent holds
g1 = g2

proof end;

theorem :: RFINSEQ:23
for R1, R2 being non-increasing FinSequence of REAL st R1,R2 are_fiberwise_equipotent holds
R1 = R2
proof end;

theorem :: RFINSEQ:24
for R being FinSequence of REAL
for r, s being Real st r <> 0 holds
R " {(s / r)} = (r * R) " {s}
proof end;

theorem :: RFINSEQ:25
for R being FinSequence of REAL holds (0 * R) " {0} = dom R
proof end;

theorem :: RFINSEQ:26
for f, g being Function st rng f = rng g & f is one-to-one & g is one-to-one holds
f,g are_fiberwise_equipotent
proof end;

:: from REVROT_1, 2007.03.18, A.T.
theorem :: RFINSEQ:27
for f being FinSequence holds f /^ (len f) = {}
proof end;

:: from SCMBSORT, 2007.07.26, A.T.
theorem :: RFINSEQ:28
for f, g being Function
for m, n being set st f . m = g . n & f . n = g . m & m in dom f & n in dom f & dom f = dom g & ( for k being set st k <> m & k <> n & k in dom f holds
f . k = g . k ) holds
f,g are_fiberwise_equipotent
proof end;

:: form BINARITH, 2008.08.20, A.T.
theorem :: RFINSEQ:29
for f being FinSequence
for k being Nat holds len (f /^ k) = (len f) -' k
proof end;

:: from SCPQSORT, 2008.10.12, A.T.
theorem Th30: :: RFINSEQ:30
for f, g being FinSequence
for x being set st x in dom g & f,g are_fiberwise_equipotent holds
ex y being set st
( y in dom g & f . x = g . y )
proof end;

theorem Th31: :: RFINSEQ:31
for f, g, h being FinSequence holds
( f,g are_fiberwise_equipotent iff h ^ f,h ^ g are_fiberwise_equipotent )
proof end;

theorem :: RFINSEQ:32
for f, g being FinSequence
for m, n, j being Nat st f,g are_fiberwise_equipotent & m <= n & n <= len f & ( for i being Nat st 1 <= i & i <= m holds
f . i = g . i ) & ( for i being Nat st n < i & i <= len f holds
f . i = g . i ) & m < j & j <= n holds
ex k being Nat st
( m < k & k <= n & f . j = g . k )
proof end;

theorem :: RFINSEQ:33
for t being FinSequence of INT ex u being FinSequence of REAL st
( t,u are_fiberwise_equipotent & u is FinSequence of INT & u is non-increasing )
proof end;