:: Euler's Polyhedron Formula
:: by Jesse Alama
::
:: Copyright (c) 2007-2018 Association of Mizar Users

theorem Th1: :: POLYFORM:1
for X being set
for c, d being object st ex a, b being object st
( a <> b & X = {a,b} ) & c in X & d in X & c <> d holds
X = {c,d}
proof end;

theorem :: POLYFORM:2
canceled;

::\$CT
theorem Th2: :: POLYFORM:3
for k being Integer st 1 <= k holds
k is Nat
proof end;

theorem Th3: :: POLYFORM:4
1 is odd
proof end;

theorem Th4: :: POLYFORM:5
2 is even
proof end;

theorem Th5: :: POLYFORM:6
3 is odd
proof end;

theorem Th6: :: POLYFORM:7
4 is even
proof end;

theorem Th7: :: POLYFORM:8
for n being Nat st n is even holds
(- 1) |^ n = 1
proof end;

theorem Th8: :: POLYFORM:9
for n being Nat st n is odd holds
(- 1) |^ n = - 1
proof end;

theorem :: POLYFORM:10
canceled;

Lm1: for x being Element of NAT st 0 < x holds
0 + 1 <= x

by NAT_1:13;

theorem Th9: :: POLYFORM:11
for p, q, r being FinSequence holds len (p ^ q) <= len (p ^ (q ^ r))
proof end;

theorem Th10: :: POLYFORM:12
for n being Nat holds 1 < n + 2
proof end;

theorem Th11: :: POLYFORM:13
(- 1) |^ 2 = 1
proof end;

theorem Th12: :: POLYFORM:14
for n being Nat holds (- 1) |^ n = (- 1) |^ (n + 2)
proof end;

:: A theorem on telescoping sequences of integers.
theorem Th13: :: POLYFORM:15
for a, b, s being FinSequence of INT st len s > 0 & len a = len s & len b = len s & ( for n being Nat st 1 <= n & n <= len s holds
s . n = (a . n) + (b . n) ) & ( for k being Nat st 1 <= k & k < len s holds
b . k = - (a . (k + 1)) ) holds
Sum s = (a . 1) + (b . (len s))
proof end;

theorem Th14: :: POLYFORM:16
for p, q, r being FinSequence holds len ((p ^ q) ^ r) = ((len p) + (len q)) + (len r)
proof end;

theorem Th15: :: POLYFORM:17
for x being set
for p, q being FinSequence holds ((<*x*> ^ p) ^ q) . 1 = x
proof end;

theorem Th16: :: POLYFORM:18
for x being set
for p, q being FinSequence holds ((p ^ q) ^ <*x*>) . (((len p) + (len q)) + 1) = x
proof end;

theorem Th17: :: POLYFORM:19
for p, q, r being FinSequence
for k being Nat st len p < k & k <= len (p ^ q) holds
((p ^ q) ^ r) . k = q . (k - (len p))
proof end;

definition
let a be Integer;
:: original: <*
redefine func <*a*> -> FinSequence of INT ;
coherence
<*a*> is FinSequence of INT
proof end;
end;

definition
let a, b be Integer;
:: original: <*
redefine func <*a,b*> -> FinSequence of INT ;
coherence
<*a,b*> is FinSequence of INT
proof end;
end;

definition
let a, b, c be Integer;
:: original: <*
redefine func <*a,b,c*> -> FinSequence of INT ;
coherence
<*a,b,c*> is FinSequence of INT
proof end;
end;

theorem Th18: :: POLYFORM:20
for k being Integer
for p being FinSequence of INT holds Sum (<*k*> ^ p) = k + (Sum p)
proof end;

theorem Th19: :: POLYFORM:21
for p, q, r being FinSequence of INT holds Sum ((p ^ q) ^ r) = ((Sum p) + (Sum q)) + (Sum r)
proof end;

theorem :: POLYFORM:22
for a being Element of Z_2 holds Sum <*a*> = a by FINSOP_1:11;

:: An incidence matrix is a function that says of any two objects
:: (contained in some set) whether they are incidence to each other.
definition
let X, Y be set ;
mode incidence-matrix of X,Y is Element of Funcs ([:X,Y:],{(),()});
end;

theorem Th21: :: POLYFORM:23
for X, Y being set holds [:X,Y:] --> () is incidence-matrix of X,Y
proof end;

:: A polyhedron (one might call it an abstract polyhedron) consists of
:: two pieces of data: a sequence of ordered sets, representing the
:: polytope sets (they are ordered for convenience's sake) and a
:: sequence of incidence matrices, which lays out the incidence
:: relation between the (k-1)-polytopes and the k-polytopes.
definition end;

:: The following properties, polyhedron_1', polyhedron_2', and
:: `polyhedron_3' are admittedly a bit contrived. However, they ensure
:: that a PolyhedronStr is a polyhedron: that there is one more polytope set
:: than incidence matrix, that the incidience matrices are incidence matrices
:: of the right sets, and that each term of the polytope sequence is an
:: enumeration of the respective polytope set.
definition
let p be PolyhedronStr ;
attr p is polyhedron_1 means :: POLYFORM:def 1
len the IncidenceF of p = (len the PolytopsF of p) - 1;
attr p is polyhedron_2 means :Def2: :: POLYFORM:def 2
for n being Nat st 1 <= n & n < len the PolytopsF of p holds
the IncidenceF of p . n is incidence-matrix of (rng ( the PolytopsF of p . n)),(rng ( the PolytopsF of p . (n + 1)));
attr p is polyhedron_3 means :Def3: :: POLYFORM:def 3
for n being Nat st 1 <= n & n <= len the PolytopsF of p holds
( not the PolytopsF of p . n is empty & the PolytopsF of p . n is one-to-one );
end;

:: deftheorem defines polyhedron_1 POLYFORM:def 1 :
for p being PolyhedronStr holds
( p is polyhedron_1 iff len the IncidenceF of p = (len the PolytopsF of p) - 1 );

:: deftheorem Def2 defines polyhedron_2 POLYFORM:def 2 :
for p being PolyhedronStr holds
( p is polyhedron_2 iff for n being Nat st 1 <= n & n < len the PolytopsF of p holds
the IncidenceF of p . n is incidence-matrix of (rng ( the PolytopsF of p . n)),(rng ( the PolytopsF of p . (n + 1))) );

:: deftheorem Def3 defines polyhedron_3 POLYFORM:def 3 :
for p being PolyhedronStr holds
( p is polyhedron_3 iff for n being Nat st 1 <= n & n <= len the PolytopsF of p holds
( not the PolytopsF of p . n is empty & the PolytopsF of p . n is one-to-one ) );

registration
existence
ex b1 being PolyhedronStr st
( b1 is polyhedron_1 & b1 is polyhedron_2 & b1 is polyhedron_3 )
proof end;
end;

definition end;

:: The dimension dim(p) of a polyhedron p is just the number of
:: polytope sets that it has.
definition
let p be polyhedron;
func dim p -> Element of NAT equals :: POLYFORM:def 4
len the PolytopsF of p;
coherence
len the PolytopsF of p is Element of NAT
;
end;

:: deftheorem defines dim POLYFORM:def 4 :
for p being polyhedron holds dim p = len the PolytopsF of p;

:: For integers k such that 0 <= k <= dim(p), the set of k-polytopes
:: is data already given by the polyhedron. For k = dim(p), the set
:: is the singleton {p}, which seems clear enough. For k = -1, it is
:: convenient to define the set of k-polytopes to be {{}}. Doing this
:: ensures that, if p is simply connected, then any two vertices are
:: connected by a system of edges.
::
:: For k < -1 and k > dim(p), the set of k-polytopes of p is empty.
definition
let p be polyhedron;
let k be Integer;
func k -polytopes p -> finite set means :Def5: :: POLYFORM:def 5
( ( k < - 1 implies it = {} ) & ( k = - 1 implies it = ) & ( - 1 < k & k < dim p implies it = rng ( the PolytopsF of p . (k + 1)) ) & ( k = dim p implies it = {p} ) & ( k > dim p implies it = {} ) );
existence
ex b1 being finite set st
( ( k < - 1 implies b1 = {} ) & ( k = - 1 implies b1 = ) & ( - 1 < k & k < dim p implies b1 = rng ( the PolytopsF of p . (k + 1)) ) & ( k = dim p implies b1 = {p} ) & ( k > dim p implies b1 = {} ) )
proof end;
uniqueness
for b1, b2 being finite set st ( k < - 1 implies b1 = {} ) & ( k = - 1 implies b1 = ) & ( - 1 < k & k < dim p implies b1 = rng ( the PolytopsF of p . (k + 1)) ) & ( k = dim p implies b1 = {p} ) & ( k > dim p implies b1 = {} ) & ( k < - 1 implies b2 = {} ) & ( k = - 1 implies b2 = ) & ( - 1 < k & k < dim p implies b2 = rng ( the PolytopsF of p . (k + 1)) ) & ( k = dim p implies b2 = {p} ) & ( k > dim p implies b2 = {} ) holds
b1 = b2
proof end;
end;

:: deftheorem Def5 defines -polytopes POLYFORM:def 5 :
for p being polyhedron
for k being Integer
for b3 being finite set holds
( b3 = k -polytopes p iff ( ( k < - 1 implies b3 = {} ) & ( k = - 1 implies b3 = ) & ( - 1 < k & k < dim p implies b3 = rng ( the PolytopsF of p . (k + 1)) ) & ( k = dim p implies b3 = {p} ) & ( k > dim p implies b3 = {} ) ) );

theorem Th22: :: POLYFORM:24
for p being polyhedron
for k being Integer st - 1 < k & k < dim p holds
( k + 1 is Nat & 1 <= k + 1 & k + 1 <= dim p )
proof end;

theorem Th23: :: POLYFORM:25
for p being polyhedron
for k being Integer holds
( not k -polytopes p is empty iff ( - 1 <= k & k <= dim p ) )
proof end;

theorem :: POLYFORM:26
for p being polyhedron
for k being Integer st k < dim p holds
k - 1 < dim p by ;

:: As we defined the set of k-polytopes for all integers k, we define
:: the an incidence matrix, eta(p,k), for any integer k. Naturally,
:: for almost all k, this is the empty matrix (empty function). The
:: two cases in which we extend the data already given by the
:: polyhedron itself is for k = 0 and k = dim(p). For the latter, we
:: declare that the empty set (the unique -1-dimensional polytope) is
:: incident to all 0-polytopes. For the latter, we declare that every
:: (dim(p)-1)-polytope is incidence to p, the unique dim(p)-polytope
:: of p.
definition
let p be polyhedron;
let k be Integer;
func eta (p,k) -> incidence-matrix of ((k - 1) -polytopes p),() means :Def6: :: POLYFORM:def 6
( ( k < 0 implies it = {} ) & ( k = 0 implies it = [:,():] --> () ) & ( 0 < k & k < dim p implies it = the IncidenceF of p . k ) & ( k = dim p implies it = [:(((dim p) - 1) -polytopes p),{p}:] --> () ) & ( k > dim p implies it = {} ) );
existence
ex b1 being incidence-matrix of ((k - 1) -polytopes p),() st
( ( k < 0 implies b1 = {} ) & ( k = 0 implies b1 = [:,():] --> () ) & ( 0 < k & k < dim p implies b1 = the IncidenceF of p . k ) & ( k = dim p implies b1 = [:(((dim p) - 1) -polytopes p),{p}:] --> () ) & ( k > dim p implies b1 = {} ) )
proof end;
uniqueness
for b1, b2 being incidence-matrix of ((k - 1) -polytopes p),() st ( k < 0 implies b1 = {} ) & ( k = 0 implies b1 = [:,():] --> () ) & ( 0 < k & k < dim p implies b1 = the IncidenceF of p . k ) & ( k = dim p implies b1 = [:(((dim p) - 1) -polytopes p),{p}:] --> () ) & ( k > dim p implies b1 = {} ) & ( k < 0 implies b2 = {} ) & ( k = 0 implies b2 = [:,():] --> () ) & ( 0 < k & k < dim p implies b2 = the IncidenceF of p . k ) & ( k = dim p implies b2 = [:(((dim p) - 1) -polytopes p),{p}:] --> () ) & ( k > dim p implies b2 = {} ) holds
b1 = b2
proof end;
end;

:: deftheorem Def6 defines eta POLYFORM:def 6 :
for p being polyhedron
for k being Integer
for b3 being incidence-matrix of ((k - 1) -polytopes p),() holds
( b3 = eta (p,k) iff ( ( k < 0 implies b3 = {} ) & ( k = 0 implies b3 = [:,():] --> () ) & ( 0 < k & k < dim p implies b3 = the IncidenceF of p . k ) & ( k = dim p implies b3 = [:(((dim p) - 1) -polytopes p),{p}:] --> () ) & ( k > dim p implies b3 = {} ) ) );

definition
let p be polyhedron;
let k be Integer;
func k -polytope-seq p -> FinSequence means :Def7: :: POLYFORM:def 7
( ( k < - 1 implies it = <*> {} ) & ( k = - 1 implies it = ) & ( - 1 < k & k < dim p implies it = the PolytopsF of p . (k + 1) ) & ( k = dim p implies it = <*p*> ) & ( k > dim p implies it = <*> {} ) );
existence
ex b1 being FinSequence st
( ( k < - 1 implies b1 = <*> {} ) & ( k = - 1 implies b1 = ) & ( - 1 < k & k < dim p implies b1 = the PolytopsF of p . (k + 1) ) & ( k = dim p implies b1 = <*p*> ) & ( k > dim p implies b1 = <*> {} ) )
proof end;
uniqueness
for b1, b2 being FinSequence st ( k < - 1 implies b1 = <*> {} ) & ( k = - 1 implies b1 = ) & ( - 1 < k & k < dim p implies b1 = the PolytopsF of p . (k + 1) ) & ( k = dim p implies b1 = <*p*> ) & ( k > dim p implies b1 = <*> {} ) & ( k < - 1 implies b2 = <*> {} ) & ( k = - 1 implies b2 = ) & ( - 1 < k & k < dim p implies b2 = the PolytopsF of p . (k + 1) ) & ( k = dim p implies b2 = <*p*> ) & ( k > dim p implies b2 = <*> {} ) holds
b1 = b2
proof end;
end;

:: deftheorem Def7 defines -polytope-seq POLYFORM:def 7 :
for p being polyhedron
for k being Integer
for b3 being FinSequence holds
( b3 = k -polytope-seq p iff ( ( k < - 1 implies b3 = <*> {} ) & ( k = - 1 implies b3 = ) & ( - 1 < k & k < dim p implies b3 = the PolytopsF of p . (k + 1) ) & ( k = dim p implies b3 = <*p*> ) & ( k > dim p implies b3 = <*> {} ) ) );

definition
let p be polyhedron;
let k be Integer;
func num-polytopes (p,k) -> Element of NAT equals :: POLYFORM:def 8
card ();
coherence
card () is Element of NAT
;
end;

:: deftheorem defines num-polytopes POLYFORM:def 8 :
for p being polyhedron
for k being Integer holds num-polytopes (p,k) = card ();

:: It will be convenient to use these in the cases of Euler's
:: polyhedron formula that interest us.
definition
let p be polyhedron;
func num-vertices p -> Element of NAT equals :: POLYFORM:def 9
num-polytopes (p,0);
correctness
coherence
num-polytopes (p,0) is Element of NAT
;
;
func num-edges p -> Element of NAT equals :: POLYFORM:def 10
num-polytopes (p,1);
correctness
coherence
num-polytopes (p,1) is Element of NAT
;
;
func num-faces p -> Element of NAT equals :: POLYFORM:def 11
num-polytopes (p,2);
correctness
coherence
num-polytopes (p,2) is Element of NAT
;
;
end;

:: deftheorem defines num-vertices POLYFORM:def 9 :
for p being polyhedron holds num-vertices p = num-polytopes (p,0);

:: deftheorem defines num-edges POLYFORM:def 10 :
for p being polyhedron holds num-edges p = num-polytopes (p,1);

:: deftheorem defines num-faces POLYFORM:def 11 :
for p being polyhedron holds num-faces p = num-polytopes (p,2);

theorem Th25: :: POLYFORM:27
for p being polyhedron
for k being Integer holds dom () = Seg (num-polytopes (p,k))
proof end;

theorem Th26: :: POLYFORM:28
for p being polyhedron
for k being Integer holds len () = num-polytopes (p,k)
proof end;

theorem Th27: :: POLYFORM:29
for p being polyhedron
for k being Integer holds rng () = k -polytopes p
proof end;

theorem Th28: :: POLYFORM:30
for p being polyhedron holds num-polytopes (p,(- 1)) = 1
proof end;

theorem Th29: :: POLYFORM:31
for p being polyhedron holds num-polytopes (p,(dim p)) = 1
proof end;

:: The k-polytope sets aren't really sets: they're ordered sets
:: (finite sequences).
::
:: Since the k-polytope sets are empty for k < -1 and k > dim(p), we
:: have to put a condition on n and k for the definition to make
:: sense.
definition
let p be polyhedron;
let k be Integer;
let n be Nat;
assume A1: ( 1 <= n & n <= num-polytopes (p,k) ) ;
func n -th-polytope (p,k) -> Element of k -polytopes p equals :Def12: :: POLYFORM:def 12
() . n;
coherence
() . n is Element of k -polytopes p
proof end;
end;

:: deftheorem Def12 defines -th-polytope POLYFORM:def 12 :
for p being polyhedron
for k being Integer
for n being Nat st 1 <= n & n <= num-polytopes (p,k) holds
n -th-polytope (p,k) = () . n;

theorem Th30: :: POLYFORM:32
for p being polyhedron
for k being Integer st - 1 <= k & k <= dim p holds
for x being Element of k -polytopes p ex n being Nat st
( x = n -th-polytope (p,k) & 1 <= n & n <= num-polytopes (p,k) )
proof end;

theorem Th31: :: POLYFORM:33
for p being polyhedron
for k being Integer holds k -polytope-seq p is one-to-one
proof end;

theorem Th32: :: POLYFORM:34
for p being polyhedron
for k being Integer
for m, n being Nat st 1 <= n & n <= num-polytopes (p,k) & 1 <= m & m <= num-polytopes (p,k) & n -th-polytope (p,k) = m -th-polytope (p,k) holds
m = n
proof end;

definition
let p be polyhedron;
let k be Integer;
let x be Element of (k - 1) -polytopes p;
let y be Element of k -polytopes p;
assume that
A1: 0 <= k and
A2: k <= dim p ;
func incidence-value (x,y) -> Element of Z_2 equals :Def13: :: POLYFORM:def 13
(eta (p,k)) . (x,y);
coherence
(eta (p,k)) . (x,y) is Element of Z_2
proof end;
end;

:: deftheorem Def13 defines incidence-value POLYFORM:def 13 :
for p being polyhedron
for k being Integer
for x being Element of (k - 1) -polytopes p
for y being Element of k -polytopes p st 0 <= k & k <= dim p holds
incidence-value (x,y) = (eta (p,k)) . (x,y);

:: The set of subsets of the k-polytopes naturally forms a vector
:: space over the field Z_2. Addition is disjoint union, and scalar
:: multiplication is defined by the equations 1*x = x, 0*x = 0.
definition
let p be polyhedron;
let k be Integer;
coherence ;
end;

:: deftheorem defines -chain-space POLYFORM:def 14 :
for p being polyhedron
for k being Integer holds k -chain-space p = bspace ();

theorem :: POLYFORM:35
for p being polyhedron
for k being Integer
for x being Element of k -polytopes p holds (0. ()) @ x = 0. Z_2 by BSPACE:14;

theorem Th34: :: POLYFORM:36
for p being polyhedron
for k being Integer holds num-polytopes (p,k) = dim ()
proof end;

:: A k-chain is a set of k-polytopes.
definition
let p be polyhedron;
let k be Integer;
func k -chains p -> non empty finite set equals :: POLYFORM:def 15
bool ();
coherence
bool () is non empty finite set
;
end;

:: deftheorem defines -chains POLYFORM:def 15 :
for p being polyhedron
for k being Integer holds k -chains p = bool ();

definition
let p be polyhedron;
let k be Integer;
let x be Element of (k - 1) -polytopes p;
let v be Element of ();
func incidence-sequence (x,v) -> FinSequence of Z_2 means :Def16: :: POLYFORM:def 16
( ( (k - 1) -polytopes p is empty implies it = <*> {} ) & ( not (k - 1) -polytopes p is empty implies ( len it = num-polytopes (p,k) & ( for n being Nat st 1 <= n & n <= num-polytopes (p,k) holds
it . n = (v @ (n -th-polytope (p,k))) * (incidence-value (x,(n -th-polytope (p,k)))) ) ) ) );
existence
ex b1 being FinSequence of Z_2 st
( ( (k - 1) -polytopes p is empty implies b1 = <*> {} ) & ( not (k - 1) -polytopes p is empty implies ( len b1 = num-polytopes (p,k) & ( for n being Nat st 1 <= n & n <= num-polytopes (p,k) holds
b1 . n = (v @ (n -th-polytope (p,k))) * (incidence-value (x,(n -th-polytope (p,k)))) ) ) ) )
proof end;
uniqueness
for b1, b2 being FinSequence of Z_2 st ( (k - 1) -polytopes p is empty implies b1 = <*> {} ) & ( not (k - 1) -polytopes p is empty implies ( len b1 = num-polytopes (p,k) & ( for n being Nat st 1 <= n & n <= num-polytopes (p,k) holds
b1 . n = (v @ (n -th-polytope (p,k))) * (incidence-value (x,(n -th-polytope (p,k)))) ) ) ) & ( (k - 1) -polytopes p is empty implies b2 = <*> {} ) & ( not (k - 1) -polytopes p is empty implies ( len b2 = num-polytopes (p,k) & ( for n being Nat st 1 <= n & n <= num-polytopes (p,k) holds
b2 . n = (v @ (n -th-polytope (p,k))) * (incidence-value (x,(n -th-polytope (p,k)))) ) ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def16 defines incidence-sequence POLYFORM:def 16 :
for p being polyhedron
for k being Integer
for x being Element of (k - 1) -polytopes p
for v being Element of ()
for b5 being FinSequence of Z_2 holds
( b5 = incidence-sequence (x,v) iff ( ( (k - 1) -polytopes p is empty implies b5 = <*> {} ) & ( not (k - 1) -polytopes p is empty implies ( len b5 = num-polytopes (p,k) & ( for n being Nat st 1 <= n & n <= num-polytopes (p,k) holds
b5 . n = (v @ (n -th-polytope (p,k))) * (incidence-value (x,(n -th-polytope (p,k)))) ) ) ) ) );

theorem Th35: :: POLYFORM:37
for p being polyhedron
for k being Integer
for c, d being Element of ()
for x being Element of k -polytopes p holds (c + d) @ x = (c @ x) + (d @ x)
proof end;

theorem Th36: :: POLYFORM:38
for p being polyhedron
for k being Integer
for c, d being Element of ()
for x being Element of (k - 1) -polytopes p holds incidence-sequence (x,(c + d)) = (incidence-sequence (x,c)) + (incidence-sequence (x,d))
proof end;

theorem Th37: :: POLYFORM:39
for p being polyhedron
for k being Integer
for c, d being Element of ()
for x being Element of (k - 1) -polytopes p holds Sum ((incidence-sequence (x,c)) + (incidence-sequence (x,d))) = (Sum (incidence-sequence (x,c))) + (Sum (incidence-sequence (x,d)))
proof end;

theorem Th38: :: POLYFORM:40
for p being polyhedron
for k being Integer
for c, d being Element of ()
for x being Element of (k - 1) -polytopes p holds Sum (incidence-sequence (x,(c + d))) = (Sum (incidence-sequence (x,c))) + (Sum (incidence-sequence (x,d)))
proof end;

theorem Th39: :: POLYFORM:41
for p being polyhedron
for k being Integer
for c being Element of ()
for a being Element of Z_2
for x being Element of k -polytopes p holds (a * c) @ x = a * (c @ x)
proof end;

theorem Th40: :: POLYFORM:42
for p being polyhedron
for k being Integer
for c being Element of ()
for a being Element of Z_2
for x being Element of (k - 1) -polytopes p holds incidence-sequence (x,(a * c)) = a * (incidence-sequence (x,c))
proof end;

theorem Th41: :: POLYFORM:43
for p being polyhedron
for k being Integer
for c, d being Element of () holds
( c = d iff for x being Element of k -polytopes p holds c @ x = d @ x )
proof end;

theorem Th42: :: POLYFORM:44
for p being polyhedron
for k being Integer
for c, d being Element of () holds
( c = d iff for x being Element of k -polytopes p holds
( x in c iff x in d ) )
proof end;

scheme :: POLYFORM:sch 1
ChainEx{ F1() -> polyhedron, F2() -> Integer, P1[ Element of F2() -polytopes F1()] } :
ex c being Subset of (F2() -polytopes F1()) st
for x being Element of F2() -polytopes F1() holds
( x in c iff ( P1[x] & x in F2() -polytopes F1() ) )
proof end;

:: The boundary of a k-chain v is the (k-1)-chain consisting of the
:: (k-1)-polytopes that are on the "perimeter" of v. Being on the
:: perimeter amounts the sum of the incidence sequence being non-zero,
:: i.e., being equal to 1.
definition
let p be polyhedron;
let k be Integer;
let v be Element of ();
func Boundary v -> Element of ((k - 1) -chain-space p) means :Def17: :: POLYFORM:def 17
( ( (k - 1) -polytopes p is empty implies it = 0. ((k - 1) -chain-space p) ) & ( not (k - 1) -polytopes p is empty implies for x being Element of (k - 1) -polytopes p holds
( x in it iff Sum (incidence-sequence (x,v)) = 1. Z_2 ) ) );
existence
ex b1 being Element of ((k - 1) -chain-space p) st
( ( (k - 1) -polytopes p is empty implies b1 = 0. ((k - 1) -chain-space p) ) & ( not (k - 1) -polytopes p is empty implies for x being Element of (k - 1) -polytopes p holds
( x in b1 iff Sum (incidence-sequence (x,v)) = 1. Z_2 ) ) )
proof end;
uniqueness
for b1, b2 being Element of ((k - 1) -chain-space p) st ( (k - 1) -polytopes p is empty implies b1 = 0. ((k - 1) -chain-space p) ) & ( not (k - 1) -polytopes p is empty implies for x being Element of (k - 1) -polytopes p holds
( x in b1 iff Sum (incidence-sequence (x,v)) = 1. Z_2 ) ) & ( (k - 1) -polytopes p is empty implies b2 = 0. ((k - 1) -chain-space p) ) & ( not (k - 1) -polytopes p is empty implies for x being Element of (k - 1) -polytopes p holds
( x in b2 iff Sum (incidence-sequence (x,v)) = 1. Z_2 ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def17 defines Boundary POLYFORM:def 17 :
for p being polyhedron
for k being Integer
for v being Element of ()
for b4 being Element of ((k - 1) -chain-space p) holds
( b4 = Boundary v iff ( ( (k - 1) -polytopes p is empty implies b4 = 0. ((k - 1) -chain-space p) ) & ( not (k - 1) -polytopes p is empty implies for x being Element of (k - 1) -polytopes p holds
( x in b4 iff Sum (incidence-sequence (x,v)) = 1. Z_2 ) ) ) );

theorem Th43: :: POLYFORM:45
for p being polyhedron
for k being Integer
for c being Element of ()
for x being Element of (k - 1) -polytopes p holds () @ x = Sum (incidence-sequence (x,c))
proof end;

:: Every dimension k has its own boundary operation.
definition
let p be polyhedron;
let k be Integer;
func k -boundary p -> Function of (),((k - 1) -chain-space p) means :Def18: :: POLYFORM:def 18
for c being Element of () holds it . c = Boundary c;
existence
ex b1 being Function of (),((k - 1) -chain-space p) st
for c being Element of () holds b1 . c = Boundary c
proof end;
uniqueness
for b1, b2 being Function of (),((k - 1) -chain-space p) st ( for c being Element of () holds b1 . c = Boundary c ) & ( for c being Element of () holds b2 . c = Boundary c ) holds
b1 = b2
proof end;
end;

:: deftheorem Def18 defines -boundary POLYFORM:def 18 :
for p being polyhedron
for k being Integer
for b3 being Function of (),((k - 1) -chain-space p) holds
( b3 = k -boundary p iff for c being Element of () holds b3 . c = Boundary c );

theorem Th44: :: POLYFORM:46
for p being polyhedron
for k being Integer
for c, d being Element of () holds Boundary (c + d) = () + ()
proof end;

theorem Th45: :: POLYFORM:47
for p being polyhedron
for k being Integer
for a being Element of Z_2
for c being Element of () holds Boundary (a * c) = a * ()
proof end;

:: As defined, the k-boundary operator gives rise to a linear
:: transformation.
theorem Th46: :: POLYFORM:48
for p being polyhedron
for k being Integer holds k -boundary p is linear-transformation of (),((k - 1) -chain-space p)
proof end;

registration
let p be polyhedron;
let k be Integer;
coherence
( k -boundary p is homogeneous & k -boundary p is additive )
by Th46;
end;

:: The term "circuit" is used in Lakatos. (A more customary term is
:: "cycle".)
definition
let p be polyhedron;
let k be Integer;
func k -circuit-space p -> Subspace of k -chain-space p equals :: POLYFORM:def 19
ker ();
coherence
ker () is Subspace of k -chain-space p
;
end;

:: deftheorem defines -circuit-space POLYFORM:def 19 :
for p being polyhedron
for k being Integer holds k -circuit-space p = ker ();

definition
let p be polyhedron;
let k be Integer;
func k -circuits p -> non empty Subset of (k -chains p) equals :: POLYFORM:def 20
[#] ();
coherence
[#] () is non empty Subset of (k -chains p)
by VECTSP_4:def 2;
end;

:: deftheorem defines -circuits POLYFORM:def 20 :
for p being polyhedron
for k being Integer holds k -circuits p = [#] ();

definition
let p be polyhedron;
let k be Integer;
func k -bounding-chain-space p -> Subspace of k -chain-space p equals :: POLYFORM:def 21
im ((k + 1) -boundary p);
coherence
im ((k + 1) -boundary p) is Subspace of k -chain-space p
;
end;

:: deftheorem defines -bounding-chain-space POLYFORM:def 21 :
for p being polyhedron
for k being Integer holds k -bounding-chain-space p = im ((k + 1) -boundary p);

definition
let p be polyhedron;
let k be Integer;
func k -bounding-chains p -> non empty Subset of (k -chains p) equals :: POLYFORM:def 22
[#] ();
coherence
[#] () is non empty Subset of (k -chains p)
by VECTSP_4:def 2;
end;

:: deftheorem defines -bounding-chains POLYFORM:def 22 :
for p being polyhedron
for k being Integer holds k -bounding-chains p = [#] ();

definition
let p be polyhedron;
let k be Integer;
func k -bounding-circuit-space p -> Subspace of k -chain-space p equals :: POLYFORM:def 23
() /\ ();
coherence
() /\ () is Subspace of k -chain-space p
;
end;

:: deftheorem defines -bounding-circuit-space POLYFORM:def 23 :
for p being polyhedron
for k being Integer holds k -bounding-circuit-space p = () /\ ();

definition
let p be polyhedron;
let k be Integer;
func k -bounding-circuits p -> non empty Subset of (k -chains p) equals :: POLYFORM:def 24
[#] ();
coherence
[#] () is non empty Subset of (k -chains p)
by VECTSP_4:def 2;
end;

:: deftheorem defines -bounding-circuits POLYFORM:def 24 :
for p being polyhedron
for k being Integer holds k -bounding-circuits p = [#] ();

theorem :: POLYFORM:49
for p being polyhedron
for k being Integer holds dim () = (rank ()) + (nullity ()) by RANKNULL:44;

:: The property of being simply connected is that circuits are
:: bounding, and vice versa (any bounding chain is a circuit).
definition
let p be polyhedron;
attr p is simply-connected means :: POLYFORM:def 25
for k being Integer holds k -circuits p = k -bounding-chains p;
end;

:: deftheorem defines simply-connected POLYFORM:def 25 :
for p being polyhedron holds
( p is simply-connected iff for k being Integer holds k -circuits p = k -bounding-chains p );

theorem Th48: :: POLYFORM:50
for p being polyhedron holds
( p is simply-connected iff for n being Integer holds n -circuit-space p = n -bounding-chain-space p )
proof end;

definition
let p be polyhedron;
func alternating-f-vector p -> FinSequence of INT means :Def26: :: POLYFORM:def 26
( len it = (dim p) + 2 & ( for k being Nat st 1 <= k & k <= (dim p) + 2 holds
it . k = ((- 1) |^ k) * (num-polytopes (p,(k - 2))) ) );
existence
ex b1 being FinSequence of INT st
( len b1 = (dim p) + 2 & ( for k being Nat st 1 <= k & k <= (dim p) + 2 holds
b1 . k = ((- 1) |^ k) * (num-polytopes (p,(k - 2))) ) )
proof end;
uniqueness
for b1, b2 being FinSequence of INT st len b1 = (dim p) + 2 & ( for k being Nat st 1 <= k & k <= (dim p) + 2 holds
b1 . k = ((- 1) |^ k) * (num-polytopes (p,(k - 2))) ) & len b2 = (dim p) + 2 & ( for k being Nat st 1 <= k & k <= (dim p) + 2 holds
b2 . k = ((- 1) |^ k) * (num-polytopes (p,(k - 2))) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def26 defines alternating-f-vector POLYFORM:def 26 :
for p being polyhedron
for b2 being FinSequence of INT holds
( b2 = alternating-f-vector p iff ( len b2 = (dim p) + 2 & ( for k being Nat st 1 <= k & k <= (dim p) + 2 holds
b2 . k = ((- 1) |^ k) * (num-polytopes (p,(k - 2))) ) ) );

definition
let p be polyhedron;
func alternating-proper-f-vector p -> FinSequence of INT means :Def27: :: POLYFORM:def 27
( len it = dim p & ( for k being Nat st 1 <= k & k <= dim p holds
it . k = ((- 1) |^ (k + 1)) * (num-polytopes (p,(k - 1))) ) );
existence
ex b1 being FinSequence of INT st
( len b1 = dim p & ( for k being Nat st 1 <= k & k <= dim p holds
b1 . k = ((- 1) |^ (k + 1)) * (num-polytopes (p,(k - 1))) ) )
proof end;
uniqueness
for b1, b2 being FinSequence of INT st len b1 = dim p & ( for k being Nat st 1 <= k & k <= dim p holds
b1 . k = ((- 1) |^ (k + 1)) * (num-polytopes (p,(k - 1))) ) & len b2 = dim p & ( for k being Nat st 1 <= k & k <= dim p holds
b2 . k = ((- 1) |^ (k + 1)) * (num-polytopes (p,(k - 1))) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def27 defines alternating-proper-f-vector POLYFORM:def 27 :
for p being polyhedron
for b2 being FinSequence of INT holds
( b2 = alternating-proper-f-vector p iff ( len b2 = dim p & ( for k being Nat st 1 <= k & k <= dim p holds
b2 . k = ((- 1) |^ (k + 1)) * (num-polytopes (p,(k - 1))) ) ) );

definition
let p be polyhedron;
func alternating-semi-proper-f-vector p -> FinSequence of INT means :Def28: :: POLYFORM:def 28
( len it = (dim p) + 1 & ( for k being Nat st 1 <= k & k <= (dim p) + 1 holds
it . k = ((- 1) |^ (k + 1)) * (num-polytopes (p,(k - 1))) ) );
existence
ex b1 being FinSequence of INT st
( len b1 = (dim p) + 1 & ( for k being Nat st 1 <= k & k <= (dim p) + 1 holds
b1 . k = ((- 1) |^ (k + 1)) * (num-polytopes (p,(k - 1))) ) )
proof end;
uniqueness
for b1, b2 being FinSequence of INT st len b1 = (dim p) + 1 & ( for k being Nat st 1 <= k & k <= (dim p) + 1 holds
b1 . k = ((- 1) |^ (k + 1)) * (num-polytopes (p,(k - 1))) ) & len b2 = (dim p) + 1 & ( for k being Nat st 1 <= k & k <= (dim p) + 1 holds
b2 . k = ((- 1) |^ (k + 1)) * (num-polytopes (p,(k - 1))) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def28 defines alternating-semi-proper-f-vector POLYFORM:def 28 :
for p being polyhedron
for b2 being FinSequence of INT holds
( b2 = alternating-semi-proper-f-vector p iff ( len b2 = (dim p) + 1 & ( for k being Nat st 1 <= k & k <= (dim p) + 1 holds
b2 . k = ((- 1) |^ (k + 1)) * (num-polytopes (p,(k - 1))) ) ) );

theorem Th49: :: POLYFORM:51
for p being polyhedron
for n being Nat st 1 <= n & n <= len holds
. n = (((- 1) |^ (n + 1)) * (dim ((n - 2) -bounding-chain-space p))) + (((- 1) |^ (n + 1)) * (dim ((n - 1) -circuit-space p)))
proof end;

:: The term "eulerian" comes from Lakatos.
definition
let p be polyhedron;
attr p is eulerian means :: POLYFORM:def 29
Sum = 1 + ((- 1) |^ ((dim p) + 1));
end;

:: deftheorem defines eulerian POLYFORM:def 29 :
for p being polyhedron holds
( p is eulerian iff Sum = 1 + ((- 1) |^ ((dim p) + 1)) );

theorem Th50: :: POLYFORM:52
for p being polyhedron holds alternating-semi-proper-f-vector p = ^ <*((- 1) |^ (dim p))*>
proof end;

:: Another characterization of Eulerian polyhedra
definition
let p be polyhedron;
redefine attr p is eulerian means :: POLYFORM:def 30
Sum = 1;
compatibility
( p is eulerian iff Sum = 1 )
proof end;
end;

:: deftheorem defines eulerian POLYFORM:def 30 :
for p being polyhedron holds
( p is eulerian iff Sum = 1 );

theorem Th51: :: POLYFORM:53
for p being polyhedron holds alternating-f-vector p = <*(- 1)*> ^
proof end;

:: Yet another characterization of eulerian polyhedra
definition
let p be polyhedron;
redefine attr p is eulerian means :: POLYFORM:def 31
Sum = 0 ;
compatibility
( p is eulerian iff Sum = 0 )
proof end;
end;

:: deftheorem defines eulerian POLYFORM:def 31 :
for p being polyhedron holds
( p is eulerian iff Sum = 0 );

theorem Th52: :: POLYFORM:54
for p being polyhedron holds not 0 -polytopes p is empty
proof end;

theorem Th53: :: POLYFORM:55
for p being polyhedron holds card ([#] ((- 1) -chain-space p)) = 2
proof end;

theorem Th54: :: POLYFORM:56
for p being polyhedron holds [#] ((- 1) -chain-space p) =
proof end;

theorem Th55: :: POLYFORM:57
for p being polyhedron
for k being Integer
for x being Element of k -polytopes p
for e being Element of (k - 1) -polytopes p st k = 0 & e = {} holds
incidence-value (e,x) = 1. Z_2
proof end;

theorem Th56: :: POLYFORM:58
for p being polyhedron
for k being Integer
for x being Element of k -polytopes p
for v being Element of ()
for e being Element of (k - 1) -polytopes p
for n being Nat st k = 0 & v = {x} & e = {} & x = n -th-polytope (p,k) & 1 <= n & n <= num-polytopes (p,k) holds
(incidence-sequence (e,v)) . n = 1. Z_2
proof end;

theorem Th57: :: POLYFORM:59
for p being polyhedron
for k being Integer
for x being Element of k -polytopes p
for e being Element of (k - 1) -polytopes p
for v being Element of ()
for m, n being Nat st k = 0 & v = {x} & x = n -th-polytope (p,k) & 1 <= m & m <= num-polytopes (p,k) & 1 <= n & n <= num-polytopes (p,k) & m <> n holds
(incidence-sequence (e,v)) . m = 0. Z_2
proof end;

theorem Th58: :: POLYFORM:60
for p being polyhedron
for k being Integer
for x being Element of k -polytopes p
for v being Element of ()
for e being Element of (k - 1) -polytopes p st k = 0 & v = {x} & e = {} holds
Sum (incidence-sequence (e,v)) = 1. Z_2
proof end;

theorem Th59: :: POLYFORM:61
for p being polyhedron
for x being Element of 0 -polytopes p holds () . {x} =
proof end;

theorem Th60: :: POLYFORM:62
for p being polyhedron
for k being Integer st k = - 1 holds
dim () = 1
proof end;

theorem Th61: :: POLYFORM:63
for p being polyhedron holds card ([#] ((dim p) -chain-space p)) = 2
proof end;

theorem Th62: :: POLYFORM:64
for p being polyhedron holds {p} is Element of ((dim p) -chain-space p)
proof end;

theorem Th63: :: POLYFORM:65
for p being polyhedron holds {p} in [#] ((dim p) -chain-space p)
proof end;

theorem Th64: :: POLYFORM:66
for p being polyhedron holds not ((dim p) - 1) -polytopes p is empty
proof end;

registration
let p be polyhedron;
cluster ((dim p) - 1) -polytopes p -> non empty finite ;
coherence
not ((dim p) - 1) -polytopes p is empty
by Th64;
end;

theorem Th65: :: POLYFORM:67
for p being polyhedron holds [#] ((dim p) -chain-space p) = {(0. ((dim p) -chain-space p)),{p}}
proof end;

theorem Th66: :: POLYFORM:68
for p being polyhedron
for x being Element of ((dim p) -chain-space p) holds
( x = 0. ((dim p) -chain-space p) or x = {p} )
proof end;

theorem Th67: :: POLYFORM:69
for p being polyhedron
for x, y being Element of ((dim p) -chain-space p) holds
( not x <> y or x = 0. ((dim p) -chain-space p) or y = 0. ((dim p) -chain-space p) )
proof end;

theorem :: POLYFORM:70
for p being polyhedron holds (dim p) -polytope-seq p = <*p*> by Def7;

theorem Th69: :: POLYFORM:71
for p being polyhedron holds 1 -th-polytope (p,(dim p)) = p
proof end;

theorem Th70: :: POLYFORM:72
for p being polyhedron
for c being Element of ((dim p) -chain-space p)
for x being Element of (dim p) -polytopes p st c = {p} holds
c @ x = 1. Z_2
proof end;

theorem Th71: :: POLYFORM:73
for p being polyhedron
for x being Element of ((dim p) - 1) -polytopes p
for c being Element of (dim p) -polytopes p st c = p holds
incidence-value (x,c) = 1. Z_2
proof end;

theorem Th72: :: POLYFORM:74
for p being polyhedron
for x being Element of ((dim p) - 1) -polytopes p
for c being Element of ((dim p) -chain-space p) st c = {p} holds
incidence-sequence (x,c) = <*()*>
proof end;

theorem Th73: :: POLYFORM:75
for p being polyhedron
for x being Element of ((dim p) - 1) -polytopes p
for c being Element of ((dim p) -chain-space p) st c = {p} holds
Sum (incidence-sequence (x,c)) = 1. Z_2
proof end;

:: The boundary operation applied to the unique non-zero vector of the
:: dim(p)-chain space gives the "top" vector of the (dim(p)-1)-chain
:: space. In other words, every (dim(p)-1)-polytope is incidence to
:: the whole polyhedron.
theorem Th74: :: POLYFORM:76
for p being polyhedron holds ((dim p) -boundary p) . {p} = ((dim p) - 1) -polytopes p
proof end;

theorem Th75: :: POLYFORM:77
for p being polyhedron holds (dim p) -boundary p is one-to-one
proof end;

theorem Th76: :: POLYFORM:78
for p being polyhedron holds dim (((dim p) - 1) -bounding-chain-space p) = 1
proof end;

theorem Th77: :: POLYFORM:79
for p being polyhedron st p is simply-connected holds
dim (((dim p) - 1) -circuit-space p) = 1
proof end;

theorem Th78: :: POLYFORM:80
for p being polyhedron
for n being Nat st 1 < n & n < (dim p) + 2 holds
. n = . (n - 1)
proof end;

theorem Th79: :: POLYFORM:81
for p being polyhedron holds alternating-f-vector p = () ^ <*((- 1) |^ (dim p))*>
proof end;

theorem Th80: :: POLYFORM:82
for p being polyhedron st dim p is odd holds
Sum = - 2
proof end;

theorem Th81: :: POLYFORM:83
for p being polyhedron st dim p is even holds
Sum = Sum
proof end;

theorem Th82: :: POLYFORM:84
for p being polyhedron st dim p = 1 holds
Sum = num-polytopes (p,0)
proof end;

theorem Th83: :: POLYFORM:85
for p being polyhedron st dim p = 2 holds
Sum = (num-polytopes (p,0)) - (num-polytopes (p,1))
proof end;

theorem Th84: :: POLYFORM:86
for p being polyhedron st dim p = 3 holds
Sum = ((num-polytopes (p,0)) - (num-polytopes (p,1))) + (num-polytopes (p,2))
proof end;

:: A trivial special case
theorem Th85: :: POLYFORM:87
for p being polyhedron st dim p = 0 holds
p is eulerian
proof end;

theorem Th86: :: POLYFORM:88
for p being polyhedron st p is simply-connected holds
p is eulerian
proof end;

:: Euler's Polyhedron Formula in One Dimension: simply-connected
:: 1-dimensional polyhedra are just line segments.
theorem :: POLYFORM:89
for p being polyhedron st p is simply-connected & dim p = 1 holds
num-vertices p = 2
proof end;

:: Euler's Polyhedron Formula in Two Dimensions: polygons have exactly
:: as many vertices as edges.
theorem :: POLYFORM:90
for p being polyhedron st p is simply-connected & dim p = 2 holds
num-vertices p = num-edges p
proof end;

:: Euler's Polyhedron Formula in Three Dimensions: V - E + F = 2.
:: Euler's Polyhedron Formula
theorem :: POLYFORM:91
for p being polyhedron st p is simply-connected & dim p = 3 holds
(() - ()) + () = 2
proof end;