PADEC - Coq Library
Library Padec.MessagePassing.AlgorithmMP
A Framework for Certified Self-Stabilization
PADEC Coq Library
- Jan 2019 (Description of the network and the algorithm)
From Padec Require Import SetoidUtil.
From Padec Require Import OptionUtil.
From Padec Require Import ListUtils.
Open Scope signature_scope.
Set Implicit Arguments.
From Padec Require Import OptionUtil.
From Padec Require Import ListUtils.
Open Scope signature_scope.
Set Implicit Arguments.
Distributed Algorithm:
- Channels (In and Out)
- Network
- Algorithm
exists an Algorithm (the one to be proven) (uses *Channels)
forall Network using *Channels,
the Algorithm meets its specification
defined on Network and *Channels
(provided some assumption on Network and *Channels).
Classes *Channels:
Channels are used to model the access of a node to its neighbors. An incoming channel (Type InChannel) cin connects a node n to its neighbor n': n <-cin---- n' An outgoing channel (Type OutChannel) cout connects a node n to its neighbor n': n -cout----> n'
Class InChannels :=
mkInChannels {
InChannel: Type;
InChannel_setoid :> Setoid InChannel;
InChannel_dec: Decider (equiv (A:=InChannel))
}.
Class OutChannels :=
mkOutChannels {
OutChannel: Type;
OutChannel_setoid :> Setoid OutChannel;
OutChannel_dec: Decider (equiv (A:=OutChannel))
}.
mkInChannels {
InChannel: Type;
InChannel_setoid :> Setoid InChannel;
InChannel_dec: Decider (equiv (A:=InChannel))
}.
Class OutChannels :=
mkOutChannels {
OutChannel: Type;
OutChannel_setoid :> Setoid OutChannel;
OutChannel_dec: Decider (equiv (A:=OutChannel))
}.
Class DirNetwork:
A network is described by its nodes (Type Node) and links (arcs) between nodes. A directed connection (arc) linking two nodes has two channels: one InChannel (at the destination) and one OutChannel (at the source).
Class DirNetwork {InChans: InChannels} {OutChans: OutChannels} :=
mkNet {
Node: Type;
Node_setoid :> Setoid Node;
Node_dec: Decider (equiv (A := Node));
mkNet {
Node: Type;
Node_setoid :> Setoid Node;
Node_dec: Decider (equiv (A := Node));
inLink: inLink (n,c) is
- either None when c is not a outChannel from n
- either Some (n',c') when n -c---c'-> n', i.e. n is linked to n' through an arc with outChannel c at n and inchannel c' at n'.
inLink: Node * OutChannel -> option (Node * InChannel);
outLink: Node * InChannel -> option (Node * OutChannel);
outLink: Node * InChannel -> option (Node * OutChannel);
inLink and outLink are inverse of each other
inLink and outLink are compatible
is_valid_dest checks whether the provided (dest : Node * InChannel)
is an actual arc of the network
The number of nodes is finite: this is modeled using
a (finite) list of nodes and with the predicate:
every node is in this list.
Global Instance is_valid_dest_compat {InChans: InChannels} {OutChans: OutChannels} {DNet: DirNetwork}:
Proper fequiv is_valid_dest.
Note on compatibility:
Let us consider the above function
The assumption
We say in this case that f is compatible
(implicitely: f is compatible with respect to the (partial) equivalence
relations on its parameter(s) and result).
The explanation applies to hardly every function in PADEC
(eg. inLink and outLink above).
Extend decidability to destinations, of type Node*InChannel
f: Node -> A
Proper fequiv f
means that when taking two equivalent nodes n1 and n2,
i.e., s.t.
n1 == n2
(in this model, this means that n1 and n2 are equal and
represent the same node in the network),
we expect that (f n1)
and (f n2)
produce the same
result. Again "same result" is expressed using relation:
(f n1) == (f n2)
when A is a setoid or
(f n1) =~= (f n2)
when A is a partial setoid.
Lemma dest_dec {InChans: InChannels} {OutChans: OutChannels} {DNet: DirNetwork}:
Decider (equiv (A := (Node * InChannel))).
Decider (equiv (A := (Node * InChannel))).
Class MPAlgorithm: TO BE UPDATED
run s om
run s om
returns a new state for the node and
a (possibly empty) list of messages that the node wants to
send. Each element of the list specifies what and where to send.
Type State: state of a node
Type Msg: a message
run: see above
run: State -> option (InChannel * Msg) -> (State * (list (OutChannel*Msg)));
run_compat :> Proper fequiv run;
}.
run_compat :> Proper fequiv run;
}.
Stable Variable
Class Stable_Variable {InChans: InChannels} {OutChans: OutChannels}
(Algo: MPAlgorithm) (VarType: Type) (GetVar: State -> VarType) :=
{
(Algo: MPAlgorithm) (VarType: Type) (GetVar: State -> VarType) :=
{
VarType: type of the projection
projection is compatible
GetVar projection is preserved by run