<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Proving the Existence of Stable Assignments in Democratic Forking Using Isabelle/HOL⋆</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Jan-Georg Smaus</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>IRIT, Université de Toulouse</institution>
          ,
          <addr-line>CNRS, Toulouse INP, UT3, Toulouse</addr-line>
          ,
          <country country="FR">France</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>We consider a recent game theory paper, on democratic forking: suppose you want to go to the opera with a group of 10 friends, with a choice of two operas. Everyone has a preference for one of the operas, but everyone also prefers a large community over a small one. Is there an assignment of each friend to one opera that is stable? The paper answers the question afirmatively giving an algorithm. We have formalised the main result of that paper in the proof assistant Isabelle. This provides proofs of the results that are much more reliable, since computer-checked, than paper-and-pencil proofs. The exercise has also been useful for improving the paper-and-pencil proof. We also contribute some results concerning the uniqueness of assignments.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;Higher-order logic</kwd>
        <kwd>interactive theorem proving</kwd>
        <kwd>Isabelle</kwd>
        <kwd>game theory</kwd>
        <kwd>social choice</kwd>
        <kwd>democratic forking</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>
        About three years ago, a formalism in the field of social choice (a subfield of game theory), was
presented: democratic forking [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. The scenario and the developed formalism are remarkably
simple: We have  agents who have to decide between two alternatives  or , say (A)ida
and (B)ohème. The agents each have a preference concerning the alternatives, but they also
prefer a large group over a small one. The agents might stay all together or they might fork
into two separate groups. The authors have political/societal issues in mind, such as adherence
to political parties, cryptocurrencies [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] or open-source coding projects [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ].
      </p>
      <p>An assignment is a function assigning each agent to an alternative. It is stable if no agent has
an incentive to switch. The main question is: can a stable assignment be found? The authors
give an afirmative answer via an algorithm with several variants, and also address issues such
as strategy-proofness.</p>
      <p>This seemingly simple formalism quickly leads to non-trivial considerations. E.g., while it is
relatively easy to see that stable assignments exist in the case of two alternatives, they do not
always exist for three or more alternatives.</p>
      <p>
        In this paper, we present work on implementing the proposed formalism in the proof assistant
Isabelle/HOL [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]. Specifically, we have proven the first and main theorem of the paper, stating
that a stable assignment exists.
      </p>
      <p>
        Isabelle/HOL [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ] is an interactive theorem prover (proof assistant) based on higher-order logic
(HOL). You can think of HOL as a combination of a functional programming language with
logic. Isabelle/HOL aims at being readable by humans and thus follows the usual mathematical
notation. We use standard Isabelle/HOL in Isar proof style [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] without any special libraries.
      </p>
      <p>
        More generally, theorem provers are software for conducting mathematical proofs on a
computer to obtain a high degree of confidence [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ].
      </p>
      <p>
        Initially we intended to take the main theorem of [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] and its paper-and-pencil proof and
“just” implement a corresponding Isabelle/HOL proof. In the end, we also implemented some
additional results concerning uniqueness of assignments and elicitation (see Sec. 4). On the
game theory side, our contributions are: we (1) show that for certain preferences, there is
a unique stable assignments even for more than two alternatives; (2) spell out a lemma on
elicitation (Lemma 2); (3) weaken the assumptions of [2, Prop. 2] on uniqueness; (4) discovered
that totality of preferences is not required, except possibly for the uniqueness characterisation
result of Subsec. 4.4.
      </p>
      <p>
        We have modelled our development as closely as possible on our source [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], yet in some places
the definitions are too imprecise, so we had to come up with reasonable precise definitions
ourselves, which we consider to be a contribution of this work on the theory side. Generally
speaking, the framework lent itself very well to formalisation in Isabelle.
      </p>
      <p>
        The rest of this paper is organised as follows: the next section defines the basic concepts.
Section 3 presents the algorithm for finding a stable assignment and the proof of this fact.
Section 4 gives additional results concerning uniqueness and elicitation. Section 5 concludes.
For space reasons, some of the proofs are not presented here; a technical report is available [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ].
The Isabelle code can be found at https://www.irit.fr/~Jan-Georg.Smaus/ICTCS2024/Forking.thy.
      </p>
    </sec>
    <sec id="sec-2">
      <title>2. Basic Definitions</title>
      <p>
        In this section we recall the formalism of [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], but we point out some places where we give more
explicit concepts or definitions.
      </p>
      <p>Definition 1.</p>
      <p>• Consider a set of alternatives {, } and a set of voters1  = {1, . . . , }.
• A community is an element of  := {, }× N, i.e., an alternative paired with the number
of voters who have chosen this alternative.
• A preference is a subset of  × , i.e., a relation on communities. We assume that preferences
are monotonic, i.e., (, ) ≻ (,  − 1) ≻ . . . ≻ (, 1) and (, ) ≻ (,  − 1) ≻ . . . ≻
(, 1) (and antisymmetric and transitive).
• A preference profile is an element of (2× ). It states the preferences of all voters. We
denote by ≻  the preference of voter .</p>
      <p>Example 1. Consider  = {1, 2}, where the preference profile is given by 1 : (, 2) ≻ 1
(, 1) ≻ 1 (, 2) ≻ 1 (, 1) and 2 : (, 2) ≻ 2 (, 1) ≻ 2 (, 2) ≻ 2 (, 1). E.g., 1 prefers
being alone with  to being in a group of 2 with .
1We use this word rather than “agent” to avoid the letter , to be confused with .</p>
      <p>
        At this point we state an amazing observation: in [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] it is assumed throughout that the
preferences are total orders. It seems like a natural assumption to make and we initially added
it to our Isabelle code as well. We later observed that this assumption is never used, except for
one result stated in Subsec. 4.4.
      </p>
      <p>In Isabelle, we have a so-called theory file containing all definitions and theorems, with their
proofs, of our development. For modelling the above definitions, the theory file contains the
following:
type_synonym ’Al community = "’Al * nat"
type_synonym ’Al preference = "(’Al community) rel"
definition
monotonic :: "’Al preference ⇒ bool"
where "monotonic pref = (∀ S j k. k≤ j →−
((S,j),(S,k)) ∈ pref)"</p>
      <p>In contrast to Def. 1, the set of alternatives is not fixed to being {, } but rather it is
modelled by a type parameter ’Al for the sake of generality.</p>
      <p>Note that the above lines define monotonicity but do not yet impose that all preferences used
should actually be monotonic.</p>
      <p>Definition 2. An assignment is a function  :  → {, }. It can be lifted to a community
assignment, i.e., for any voter  ∈  , the pair ( (), | − 1( ())|) gives the community of .</p>
      <p>We often denote an assignment as ⟨, ⟩ where  and  are the sets of voters mapped
to  and  respectively.</p>
      <p>In Isabelle, these definitions look as follows:
type_synonym (’V,’Al) assignment = "’V ⇒ ’Al"
definition
commAss ::"(’V,’Al) assignment ⇒ ’V ⇒ ’Al community"
where "commAss f v = (f v, card (f -‘ {f v}))"</p>
      <p>In Isabelle/HOL, -‘ gives the inverse of a function, so f -‘ {f v} is the set of voters mapped
to f v by f, and card (f -‘ {f v}) is the cardinality of that set.</p>
      <p>Given an assignment  , a subset of voters may be interested in deviating, i.e., there may be
an assignment  ′ such that for all voters in the subset,  ′ assigns them to another alternative,
and they all prefer their “ ′-community” over their “ -community”. Formally we define:</p>
      <sec id="sec-2-1">
        <title>Definition 3.</title>
        <p>• Given an assignment  :  → {, }, a deviation is an assignment  ′ :  → {, }
such that  ̸=  ′ and for all voters  where  () ̸=  ′(),
( ′(), | ′− 1( ′())|) ≻  ( (), | − 1( ())|).
(1)
• If no deviation exists, then an assignment is stable.</p>
        <p>Example 2. Consider again Ex. 1. Each voter has an alternative at which she definitely wants to
be. Thus, the only stable assignment is ⟨{1}, {2}⟩, and the community of 1 is (, 1) and that
of 2 is (, 1).</p>
        <p>
          Before we present the Isabelle versions of these definitions, we introduce the convenient
Isabelle feature of locales. A locale allows us to xfi a certain preference profile and make certain
assumptions that are also made in [
          <xref ref-type="bibr" rid="ref2">2</xref>
          ], e.g., that the voter set is finite and that the preferences
are monotonic:
locale GoodPreferences =
ifxes preferenceProfile :: " ’V ⇒ (’Al preference)"
assumes finite_V : "finite (UNIV::’V set)"
and monotonic_preferences: "∀ v. monotonic (preferenceProfile v)"
and antisym_preferences: "∀ v. antisym (preferenceProfile v)"
and trans_preferences: "∀ v. trans (preferenceProfile v)"
begin
        </p>
        <p>UNIV denotes the universal set, which can be enhanced with a type declaration, so that
finite (UNIV :: ’V set) says: the voter set is finite.</p>
        <p>We could have also fixed the alternative set to {, } here, but we decided to make the
assumption of a two-element alternative set only where needed.</p>
        <p>There is an Isabelle syntax feature allowing us to write  ⪰  ′ rather than (, ′) ∈
preferenceProfile .</p>
        <p>Now the Isabelle version of Def. 3:
definition
stable :: "(’V,’Al) assignment ⇒ bool"
where "stable f = (∄ f’. deviation f’ f)"
definition
deviation :: "(’V,’Al) assignment ⇒ (’V,’Al) assignment ⇒ bool"
where "deviation f’ f = (f’̸=f ∧
(∀ v. (f’ v) ̸= (f v) →−</p>
        <p>(commAss f’ v) ⪰  (commAss f v)))"</p>
        <p>
          Observe that the use of ⪰  in the definition of deviation means that the definition depends
on the preference profile, which is not visible in the declared type of deviation since an element
of the type (’V,’Al) assignment does not carry any information about the preferences in
it. This is possible thanks to the locale, fixing a preference profile. Around 80% of the lines of
our Isabelle code are within the scope of the locale.
3. An Algorithm for Finding a Stable Assignment
Given a (monotonic) preference profile, one may wonder whether a stable assignment always
exists and if yes, how it can be found. In [
          <xref ref-type="bibr" rid="ref2">2</xref>
          ], the algorithm shown in Fig. 1 is presented to
answer both questions afirmatively (it is Thm. 1 there 2):
2Note however that in [
          <xref ref-type="bibr" rid="ref2">2</xref>
          ] it is also said that the algorithm is polynomial.
        </p>
        <p>= ,  = ∅,  ← | |,  ← | |
while true do
 ← max{ : 0 ≤  ≤ , |{ ∈  : (,  + ) ≻  (, )}| ≥ }
if  = 0 then</p>
        <p>return {, }
else
let  = { ∈  : (,  + ) ≻  (, )}
 ←  ∪ ,  ←  ∖ 
 ← | |,  ← | |
endif
endwhile
Theorem 1. For any monotonic profile, there is a stable assignment.</p>
        <p>
          Incidentally, the presentation in [
          <xref ref-type="bibr" rid="ref2">2</xref>
          ] contains a mistake (clear from the surrounding text)
which we corrected here: it says “ ∈  ” instead of “ ∈ ”.
        </p>
        <p>To understand the algorithm better, it is useful to refine the notions of deviation and stability
by restricting the direction in which voters move:</p>
      </sec>
      <sec id="sec-2-2">
        <title>Definition 4.</title>
        <p>• Given an assignment  , an -deviation is a deviation  ′ such that for any  with  ′() ̸=
 (), we have  ′() = .</p>
        <p>• If no -deviation exists, then an assignment is -stable.</p>
        <sec id="sec-2-2-1">
          <title>In analogy we define these notions for .</title>
          <p>In Isabelle these definitions look as follows:
definition
stable_alt :: "(’V,’Al) assignment ⇒ ’Al ⇒ bool"
where "stable_alt f S = (∄ f’. dev_alt f’ f S)"
definition
dev_alt :: "(’V,’Al) assignment ⇒ (’V,’Al) assignment ⇒ ’Al⇒bool"
where "dev_alt f’ f S =</p>
          <p>(deviation f’ f ∧ (∀ v. (f’ v) ̸= (f v) →− f’ v = S))"</p>
          <p>The following Isabelle lemma, whose proof has 24 lines, states that for the two-alternative
case, -stability and -stability together imply stability:
lemma stabilityAB :
assumes "stable_alt f A" and "stable_alt f B"
and "∀ x. (x=A) = (x̸=B)"
shows "stable f"</p>
          <p>The third assumption states that there are exactly two distinct alternatives.</p>
          <p>So the algorithm initially places all voters in the -community, and the while-loop computes
a sequence of -deviations. For any threshold value  ≤ , the set { ∈  : (,  + ) ≻ 
(, )} is the set of all voters who would switch from  to  under the condition that, well,
the size of the -community grows by at least  voters. If the cardinality of that set is ≥ , then
a -deviation exists, and the algorithm actually uses the maximum value of  in each step.</p>
          <p>
            While the algorithm uses the maximal possible -deviation in each step, its correctness and
termination are guaranteed even for arbitrary -deviations.
3.1. A Paper-and-pencil Version of the Induction Step
The Isabelle/HOL implementation of the formalism of [
            <xref ref-type="bibr" rid="ref2">2</xref>
            ] is the main contribution of this paper.
However, this endeavour allowed us to spell out in detail the paper-and-pencil version of the
“induction step” of the proof of Thm. 1.
          </p>
          <p>
            Concerning the correctness of the algorithm, the proof of the theorem given in [
            <xref ref-type="bibr" rid="ref2">2</xref>
            ] says:
“Consider Algorithm 1. Let  = || and  = ||. Initially, we place all agents in  [. . . ].
If this assignment is not stable, then there exists a subset  of some  &gt; 0 agents that all
prefer (, ) to (, ). We move all these agents to  . Monotonicity implies that moving
additional agents from  to  will never cause agents in  to want to move back
to ; [. . . ]”
          </p>
          <p>
            So at the heart of the correctness proof for the algorithm lies an “induction step” saying that
due to monotonicity, there could not possibly occur a situation where voters would want to
move (back) to . This induction step is presented in [
            <xref ref-type="bibr" rid="ref2">2</xref>
            ] as if it were obvious, but in our opinion
it is not! After all, the argument does not generalise to three alternatives , ,  (see Ex. 4).
          </p>
          <p>We formalise the induction step as the following lemma:
Lemma 1. Let  be an -stable assignment and  ′ be a -deviation of  . Then  ′ is -stable.</p>
          <p>Developing the paper-and-pencil proof of this induction step helped us implement the
Isabelle/HOL proof and vice versa. Before we present the paper-and-pencil proof, we give
a brief outline: Our proof assumes, for the purpose of deriving a contradiction, that after some
“forward” step (voters moving to ), there are voters moving (back) to . If this “backward”
step only concerns voters just arrived from , then the fact that they want to go back to 
contradicts them wanting to go to  in the “forward” step. If this “backward” step concerns at
least one voter previously in , it turns out that this voter would have wanted to move to 
even before the “forward” step, which breaks our induction hypothesis.</p>
          <p>Proof. (Lemma 1) Throughout this proof, we frequently use monotonicity of preferences, and
for this, knowing the set inclusions between certain sets of voters is crucial. With the help of
some diagrams (see Fig. 2 and 3), these inclusions are easy to see.</p>
          <p>The symbol ⊎ denotes disjoint union.</p>
          <p>In this proof we consider a hypothetical “backward step” leading to assignment  ′′. We use a
three-letter notation for voter sets, indicating in what community the voters are according to  ,
AXX</p>
          <p>BBX
⇝</p>
          <p>AAA</p>
          <p>XBX
⇝
?</p>
          <p>AXA</p>
          <p>XBB
 ′, and  ′′ respectively. E.g., ABX := { |  () =  ∧  ′() = } is the set of voters moving
from  to  in the forward step with nothing specified for the backward step.
Some voters move from  to  as illustrated by the boxes linked by ⇝ in Fig. 2, where
AXX :=  − 1(), BBX :=  − 1(), AAA =  ′− 1()3, XBX =  ′− 1(), ABX := { |
 () =  ∧  ′() = }. For every voter  ∈ ABX , since she moved, we have
(, |XBX |) ≻  (, |AXX |)
(we suggest to look at Fig. 2 again).</p>
          <p>For the purpose of deriving a contradiction, assume there was a “backward step” from 
(possibly back) to . We denote by  ′′ the assignment after this backward step.
Case 1: The backward step only concerns voters originally in , i.e., { |  ′() =
 ∧  ′′() = } ⊆ ABX , or equivalently, { |  ′() =  ∧  ′′() = } = { |  () =
 ∧  ′() =  ∧  ′′() = } =: ABA. This case is illustrated in Fig. 2 and we write
AXA :=  ′′− 1(), XBB :=  ′′− 1().</p>
          <p>For every voter  ∈ ABA, since she moved, we have
By monotonicity
By transitivity, (2) and (4) imply that
(, |AXA|) ≻  (, |XBX |).
(, |AXX |) ≻  (, |AXA|).</p>
          <p>(, |XBX |) ≻  (, |AXA|).</p>
          <p>This gives a contradiction to (3).</p>
          <p>Case 2: The “backward step” concerns at least one voter originally in , i.e., { |
 ′() =  ∧  ′′() = } ∖ ABX ̸= ∅. This case is illustrated in Fig. 3 and we write XXA :=
 ′′− 1(), XBB :=  ′′− 1(), BBA := { |  () =  ′() =  ∧  ′′() = }.
3Note that by construction  ′− 1() ⊆  − 1() and  ′− 1() ⊆  ′′− 1(), so we write AAA and not XAX .
(2)
(3)
(4)
ABX
AXX</p>
          <p>BBX ⇝</p>
          <p>AAA
ABA</p>
          <p>XBX ⇝ ?
ABA</p>
          <p>XXA</p>
          <p>AXX
XBB</p>
          <p>AXX ⊎ BBA
For every voter  ∈ BBA, since she moved, we have</p>
          <p>(, |XXA|) ≻  (, |XBX |).</p>
          <p>We now consider a further set, namely AXX ⊎ BBA, i.e., the voters originally in , plus the
voters originally in  that move to  in the backward step. It is also illustrated in Fig 3 all to
the right. Observe that XXA ⊆ AXX ⊎ BBA, and so by monotonicity we have that for every
voter, in particular any  ∈ BBA,
and again by monotonicity,
By transitivity, (5)-(7) imply that
(, |AXX ⊎ BBA|) ≻  (, |XXA|),</p>
          <p>(, |XBX |) ≻  (, |BBX |).</p>
          <p>(, |AXX ⊎ BBA|) ≻  (, |BBX |)
which contradicts the assumption that  is -stable. In short, if there was such a voter , she
would have wanted to move to  even before the “forward step” took place.
So in any case, the assumption that there was a “backward step” leads to a contradiction. □
(5)
(6)
(7)
3.2. Induction Step in Isabelle
In Isabelle, Lemma 1 looks as follows:
lemma staysStable :
assumes "stable_alt f A"
and "∀ x. (x=A) = (x̸=B)"
and "dev_alt f’ f B"
shows "stable_alt f’ A"</p>
          <p>The proof of this lemma has around 120 lines of Isabelle proofscript but it relies on numerous
auxiliary lemmas. It is the main contribution of this work. Some of the additional overhead
in the Isabelle proof is related to the subset relations among the various sets of voters and the
arities of these sets. Such set-theoretic reasoning is considered trivial in paper-and-pencil proofs
but must be spelt out in the smallest detail in Isabelle.
3.3. The Entire Algorithm
The previous two subsections talk about deviations (Def. 3) and -deviations (Def. 4). These
definitions do not tell us how to construct an  ′, given  . In contrast, Algorithm 1 calculates
a number  and then a set  based on , which translates into an assignment. But is this
assignment really a -deviation? On the paper-and-pencil level this might be considered
“obvious by construction” but in Isabelle, it requires some overhead that we outline here.</p>
          <p>Given an assignment  , the4 alternative  and a natural number , we define the set of voters
who would switch to  provided the size of the -community grows by at least . We also
define the maximum  such that the cardinality of that set is greater or equal to , exactly as
this is done in the algorithm:
definition
deviators :: "(’V,’Al) assignment ⇒ ’Al ⇒ nat ⇒ ’V set"
where "deviators f B j = { v. f v ̸= B ∧</p>
          <p>(B, card (f -‘ {B}) + j) ⪰  (f v, card (f -‘ {f v}))}"
definition
dev_max :: "(’V,’Al) assignment ⇒ ’Al ⇒ nat"
where "dev_max f B = Max {j. card (deviators f B j) ≥ j}"</p>
          <p>
            We continue our Isabelle implementation of the algorithm, which is naturally in a functional
programming style, as Isabelle/HOL is based on the typed  -calculus [
            <xref ref-type="bibr" rid="ref8">8</xref>
            ]. We define the
assignment making all voters in the maximal deviators set switch towards , and letting all other
voters stay where they are:
definition
max_dev_alt :: "(’V,’Al) assignment ⇒ ’Al ⇒ (’V,’Al) assignment"
where "max_dev_alt f B =
          </p>
          <p>( v. if v∈deviators f B (dev_max f B) then B else f v)"</p>
          <p>If the deviators set is empty, then this assignment will be identical to  and we have reached
a fixpoint, which is the break condition of the algorithm loop. In this case, the assignment
reached is -stable:
lemma max_dev_alt_is_stable :
assumes "max_dev_alt f B = f"
shows "stable_alt f B"
which takes 20 lines to prove using some auxiliary lemmas.</p>
          <p>The function algo iterates max_deviat_alt, starting with the initial assignment . A, i.e.,
the assignment assigning all voters to A:
4The lemmas are formulated for Algorithm 1, which moves voters from  to , but technically, A and B are just
variables, so the lemmas also hold for  and  swapped.
fun algo
where
"algo 0 A B = ( v. A)"
| "algo (Suc j) A B = max_dev_alt (algo j A B) B"</p>
          <p>
            This function is written using the function package of Isabelle/HOL which provides excellent
support for proving termination and other things [
            <xref ref-type="bibr" rid="ref10 ref9">9, 10</xref>
            ].
          </p>
          <p>The following lemma completes the induction proof based on Lemma 1 (staysStable); the
computed assignment is -stable at all times:
lemma staysStableInduct :
assumes "∀ x. (x=A) = (x̸=B)"
shows "stable_alt (algo n A B) A"</p>
          <p>The following lemma states that after at most a number of iterations corresponding to the
number of voters, a fixpoint is reached:
lemma is_fixpoint :
shows "algo (Suc (Suc (card (UNIV::’V set)))) A B =</p>
          <p>algo (Suc (card (UNIV::’V set))) A B"</p>
          <p>For space reasons, this paper does not present any Isabelle/HOL proofs, except the proof of the
Isabelle version of Thm. 1. This proof has just five lines, and is based on some comprehensible
lemmas stated above, so we consider it the occasion to show how lemmas are tied together in
an Isabelle/HOL proof.</p>
          <p>The theorem states that after at most a number of iterations corresponding to the number
of voters, the algorithm has computed a stable assignment. In the proof, the successor of the
cardinality of the voter set is abbreviated by the macro ?n1 for readability:
lemma algo_finds_stable_assignment :
assumes "∀ x. (x=A) = (x̸=B)"
shows "stable (algo (Suc (card (UNIV::’V set))) A B)"</p>
          <p>(is "stable (algo ?n1 A B)")
proof
have "stable_alt (algo ?n1 A B) A"</p>
          <p>using assms by (rule staysStableInduct)
moreover have "algo (Suc ?n1) A B = algo ?n1 A B"</p>
          <p>by (rule is_fixpoint)
hence "max_dev_alt (algo ?n1 A B) B = algo ?n1 A B" by simp
hence "stable_alt (algo ?n1 A B) B" by (rule max_dev_alt_is_stable)
ultimately show ?thesis using assms by (rule stabilityAB)
qed</p>
          <p>Note that the third line of the proof efectively uses the recursive definition of
above.
algo given</p>
          <p>
            This completes the presentation of the Isabelle/HOL development concerning Algorithm 1
and thus the main result of [
            <xref ref-type="bibr" rid="ref2">2</xref>
            ]. It consists of just under 1000 lines.
          </p>
          <p>
            Unlike [
            <xref ref-type="bibr" rid="ref2">2</xref>
            ], we have not assumed that preferences are total. In the extreme case, we could have
preferences where any community (, _) would be unrelated to (, _). Then there could be no
deviations (it can never be better to switch to another alternative) and thus any assignment is
trivially stable. So to make our results interesting, at least some (, _), (, _) should be related.
4. Additional Results: Uniqueness and Elicitation
4.1. Clear Preferences and Unique Assignments
In [
            <xref ref-type="bibr" rid="ref2">2</xref>
            ], a non-interleaving preference is defined as a preference ≻ such that either (, 1) ≻ (, )
or (, 1) ≻ (, ). It is stated as “Observation 1” with three lines of proof that if all preferences
are non-interleaving, then the unique stable assignment is the one that assigns a voter  to 
if and only if (, 1) ≻  (, ).
          </p>
          <p>We found that this result can be generalised to an arbitrary, even infinite, number of
alternatives, so we make this assumption, in this subsection only.</p>
          <p>We say that a preference is clear if there exists an alternative that is preferred to any other
alternative even for the smallest, i.e., one-member, community. Note that this is a generalisation
of “non-interleaving” to an arbitrary number of alternatives. It is defined in Isabelle as follows:
definition
clear :: "’Al preference ⇒ bool"
where "clear p = (∃ S. ∀ T. S̸=T →−</p>
          <p>(∀ n. ((S,1),(T,n)) ∈ p))"</p>
          <p>E.g., for three alternatives, (, 2) ≻ (, 1) ≻ (, 2) ≻ (, 2) ≻ (, 1) ≻ (, 1) is a clear
preference (for ). The example also illustrates that the name “non-interleaving” would have
been inappropriate for more than two alternatives.</p>
          <p>For space reasons we only present the final result, stating that any stable assignment is
necessarily the assignment mapping each voter to her clearly preferred alternative. This
additional development consists of about 130 lines.
lemma genericUniqueStable :</p>
          <p>
            assumes "∀ v. clear (preferenceProfile v)" and "stable f"
shows "f = ( v. THE S. ∀ T. S̸=T →− (∀ n. (S,1) ⪰ (T,n)))"
4.2. Non-critically-interleaving Preferences for Elicitation
A somewhat weaker condition than “non-interleaving” is also proposed by [
            <xref ref-type="bibr" rid="ref2">2</xref>
            ]:
Definition 5. A preference is non-critically-interleaving if (, ) ≻ (, ) ≻ (,  − ) ≻
(,  − 1) or (, ) ≻ (, ) ≻ (,  − ) ≻ (,  − 1) for some  ∈ [1, ]. We say in this
case that (, ), resp. (, ), is the threshold of ≻ .5 A profile is non-critically-interleaving if it
contains only such preferences.
5This sentence has been added by us.
          </p>
          <p>The essential point is this: for a voter, there is a threshold value  at which she would definitely
want to be at her preferred alternative. Note that for  = 1, the definition stipulates · · · ≻ (, 0);
this spurious part simply disappears.</p>
          <p>Non-critically-interleaving preferences facilitate elicitation. The threshold of each voter is
suficient for deciding the condition (,  + ) ≻  (, ) of Algorithm 1. We contribute the
following lemma.</p>
          <p>Lemma 2. Consider , ,  ∈ [1, ] such that  +  =  and 0 &lt;  ≤  and a
non-criticallyinterleaving preference ≻ .</p>
          <p>If the threshold of ≻ is (, ) for some  ≤  + , or (, ) for some  &gt; , then (,  + ) ≻
(, ). Otherwise, (, ) ≻ (,  + ).</p>
          <p>In Isabelle the lemma looks as follows. This development has around 80 lines.
lemma nci_elicitation :
assumes "a+b= card (UNIV::’V set)" (is "a+b=?n") and "j ≤ a"
and "monotonic pref" and "trans pref"
and "threshold pref B t A ∨ threshold pref A t B"
shows "if ((threshold pref B t A ∧ t ≤ b+j) ∨</p>
          <p>(threshold pref A t B ∧ t &gt; a))
then ((B,b+j),(A,a)) ∈ pref else ((A,a),(B,b+j)) ∈ pref"
4.3. Strong Preferences for Uniqueness
[2, Prop. 2] states conditions for uniqueness of assignments, assuming non-critically-interleaving
preferences. We make the assumptions both weaker (we do not require
non-criticallyinterleaving preferences) and more explicit.</p>
          <p>
            Below, ′ (′) denotes the set of voters with preferred alternative  () who will definitely
be with  () in any stable assignment. Our definition of these sets is equivalent to that of [
            <xref ref-type="bibr" rid="ref2">2</xref>
            ]
but makes explicit that these are the voters who move in the first step of Algorithm 1.
Proposition 1. Let
          </p>
          <p>:=
′ :=
max{ : 0 ≤  ≤ , |{ ∈  : (, ) ≻  (, )}| ≥ }
{ ∈  : (, ) ≻  (, )}
and ′ be defined analogously. If for each voter  ∈  ∖ (′ ∪ ′), either (, |′| + 1) ≻ 
(,  − | ′|) or (, |′| + 1) ≻  (,  − | ′|), then there is a unique stable assignment.
Example 3. Consider  = 9 and suppose that
(, 1) ≻ 1 (, 9), ≻ 2=≻ 1, (, 2) ≻ 3 (, 9), (, 5) ≻ 4 (, 9), ≻ 5=≻ 4,
(, 2) ≻ 6 (, 9), ≻ 7=≻ 6,
(, 3) ≻ 8 (, 7), (, 6) ≻ 9 (, 4)
Then ′ = {1, 2, 3, 4, 5} and ′ = {6, 7}. Moreover 8 will necessarily join ′ and 9
will join ′, so there is a unique stable assignment.</p>
          <p>Here is the Isabelle version of Prop. 1:
lemma argmaxUniqueStable :
assumes "stable f"
and "∀ x. (x=A) = (x̸=B)"
and "(∀ v. v∈/ sureFirstAlt B A ∪ sureFirstAlt A B →−
((B,card (sureFirstAlt B A) + 1) ⪰</p>
          <p>(A,card (UNIV::’V set)-card (sureFirstAlt B A))) ∨
((A,card (sureFirstAlt A B) + 1) ⪰</p>
          <p>(B,card (UNIV::’V set)-card (sureFirstAlt A B))))"
shows "f = ( v. if v ∈ (sureFirstAlt A B) ∨
(A,card (sureFirstAlt A B) + 1) ⪰ 
(B,card (UNIV::’V set)-card (sureFirstAlt A B))
then A else B)"</p>
          <p>The Isabelle development consists of approximately 250 lines of code.
4.4. A Characterisation of Uniqueness
[2, Thm. 2] states that there is a unique stable assignment if and only if Algorithm 1 returns the
same assignment as its symmetric version starting from ⟨∅,  ⟩. The proof of this theorem refers
to “the properties of Algorithm 1” which we find too vague. In fact, we were very surprised
when we discovered that we needed preferences to be total, but for all previous results we do
not! And even here, we are not sure that the result really needs total preferences.</p>
          <p>To prove Thm. 2, the following lemma is useful. It says that there cannot be two distinct
stable assignments such that one is obtained from the other by switching some voters.
Lemma 3. Let  =  ⊎  ⊎  ⊎  where  ̸= ∅ and  ̸= ∅. Let 1 = ⟨ ⊎ ,  ⊎ ⟩
and 2 = ⟨ ⊎ ,  ⊎ ⟩. Assume all preferences are total.</p>
          <p>Then 1 and 2 cannot both be stable assignments.</p>
          <p>Proof. For the purpose of deriving a contradiction, let us assume that 1 and 2 are both stable
assignments.</p>
          <p>Since 1 is stable, and preferences are total, there is at least one voter  ∈  such that
(, | ⊎|) ≻  (, | ⊎ ⊎|) (otherwise the group  would move to ). By monotonicity
(, | ⊎ |) ≻  (, | ⊎ |). If || + 1 ≥ | |, then (, | ⊎ | + 1) ≻  (, | ⊎ |) and
thus (, | ⊎ | + 1) ≻  (, | ⊎ |), so  would want to deviate from 2, contradicting
the stability of 2. Therefore || + 1 &lt; ||.</p>
          <p>In the previous paragraph, by switching the roles of  and , and  and , we can show that
|| + 1 &lt; ||.</p>
          <p>This is a contradiction, so our assumption that 1 and 2 are both stable is false.
□</p>
          <p>Its Isabelle version looks as follows:
lemma noSwapStable :
assumes "∀ x. (x=A) = (x̸=B)"
and "(∀ v x y. x̸=y →− (x ⪰  y) ∨ y ⪰  x)"
and "VA ∩ C = {} ∧ VA ∩ D = {} ∧ D ∩ C = {}"
and "C̸={}" and "D̸={}"
shows "¬ (stable ( u. if u∈VA∪C then A else B) ∧</p>
          <p>stable ( u. if u∈VA∪D then A else B))"</p>
          <p>So if a profile admits (at least) two distinct stable assignments, then one must be obtained
from the other by shufling some voters from  to  or vice versa, but not both ways.</p>
        </sec>
        <sec id="sec-2-2-2">
          <title>Theorem 2. Assume that all preferences are total. Algorithm 1 and the reverse Algorithm 1 return the same assignment if and only if the profile admits a unique stable assignment.</title>
          <p>
            Proof. One direction is trivial and already clearly stated in [
            <xref ref-type="bibr" rid="ref2">2</xref>
            ].
          </p>
          <p>Now assume that Algorithm 1 as well as the reverse Algorithm 1 both return the assignment
1, and for the purpose of deriving a contradiction, that another stable assignment 2 exists.
Without loss of generality, using Lemma 3, assume that 1 has the form ⟨,  ⊎ ⟩ and 2
has the form ⟨ ⊎ , ⟩. As Algorithm 1 starts from the assignment ⟨, ∅⟩ and terminates in
⟨,  ⊎⟩, at some iteration it must have “skipped over” ⟨ ⊎, ⟩, i.e., it must be possible
to write  = ′ ⊎ ′′ with ′′ ̸= ∅,  = ′ ⊎ ′′ ⊎ ′′′ with ′ ̸= ∅, such that some iteration
of Algorithm 1 goes from ⟨ ⊎ ′ ⊎ ′′ ⊎ ′ ⊎  ′′, ′′′⟩ to ⟨ ⊎ ′ ⊎ ′, ′′′ ⊎ ′′ ⊎ ′′⟩.

This means that for each voter  ∈ ′′, we have</p>
          <p>(, |′′′ ⊎ ′′ ⊎ ′′|) ≻  (, | ⊎ ′ ⊎ ′′ ⊎ ′ ⊎ ′′|).</p>
          <p>By monotonicity,</p>
          <p>(, |′ ⊎ ′′′ ⊎ ′′ ⊎ ′′|) ≻  (, | ⊎ ′ ⊎ ′′|),
which means that the voters in ′′ have a reason to deviate from</p>
          <p>2 = ⟨ ⊎ ′ ⊎ ′′, ′ ⊎ ′′ ⊎ ′′′⟩
This contradicts the assumption that 2 is a stable assignment.
□</p>
          <p>The proof of Lemma 3 is the only place where we use the assumption of total preferences;
Thm. 2 inherits this assumption. We strongly suspect that the assumption of totality could be
replaced by an assumption along the lines “only assignments arising during the run of Algorithm
1 are considered”, and so totality would not really be needed. But given that Algorithm 1 is run
in two directions and that we rely on contradiction proofs, a-priori excluding some assignments
from the reasoning seems complicated.</p>
          <p>The Isabelle version looks as follows. The development has around 550 lines of code.
lemma twoDirectionsImplyUniqueness :
assumes "∀ x. (x=A) = (x̸=B)"
and "(∀ v x y. x̸=y →− (x ⪰  y) ∨ y ⪰  x)"
and "algo (Suc (card (UNIV::’V set))) A B =</p>
          <p>algo (Suc (card (UNIV::’V set))) B A"
and "stable f2"
shows "algo (Suc (card (UNIV::’V set))) A B = f2"</p>
          <p>Theorem 2 is not obvious and while trying to prove it we had doubts whether it actually
holds. The Isabelle code for this result corresponds to 25% of our entire Isabelle development.</p>
        </sec>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>5. Discussion and Future Work</title>
      <p>Stable assignments do not always exist for more than two alternatives:
Example 4. Olivier Létofé, a student doing an internship at at Toulouse University in 2022, has
found this example:
1 : (, 3) ≻ 1 (, 2) ≻ 1 (, 3) ≻ 1 (, 2) ≻ 1 (, 3) ≻ 1 (, 2)</p>
      <p>≻ 1 (, 1) ≻ 1 (, 1) ≻ 1 (, 1)
2 : (, 3) ≻ 2 (, 2) ≻ 2 (, 3) ≻ 2 (, 2) ≻ 2 (, 3) ≻ 2 (, 2)</p>
      <p>≻ 2 (, 1) ≻ 2 (, 1) ≻ 2 (, 1)
3 : (, 3) ≻ 3 (, 2) ≻ 3 (, 3) ≻ 3 (, 2) ≻ 3 (, 3) ≻ 3 (, 2)</p>
      <p>
        ≻ 3 (, 1) ≻ 3 (, 1) ≻ 3 (, 1)
Starting in (, 3), we turn in circles. No stable assignment exists. Independently, [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] also contains
such an example while the earlier unpublished version [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ] (from which we started our work) does
not discuss this point at all.
      </p>
      <p>Generalising the work to more than two alternatives is the obvious direction for future work:
under which conditions does a stable assignment exist, and which algorithm can find it?</p>
      <p>
        In [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] complexity issues are also discussed, such as how hard it is to access a preference
relation. This is also an issue for future work.
      </p>
      <p>Another interesting issue for future work is strategy-proofness, i.e., immunity to false
reporting of preferences.</p>
      <p>
        During the above-mentioned internship, some implementation work was done using Coq
rather than Isabelle/HOL. We found this implementation less natural, i.e., less close to the
source [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], than the one presented here; for example, the Coq implementation did not have the
notion of preferences between communities. Instead, the communities were mapped to natural
numbers that were then compared by the usual &gt; relation. We are unable to judge whether a
better design would have been possible in Coq. In any case we found no such discrepancies for
Isabelle.
      </p>
      <p>
        Relatively little work has been done on applications of proof assistants to game theory. To the
best of our knowledge, no work on formalising the framework of [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] has been published. We
believe that our work is a contribution to making the formalism proposed by [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] more precise
and the results more reliable, apart from the improvements of the theory shown in Section 4.
I would like to thank Umberto Grandi for pointing me to the article formalised in this work. I
would like to thank him as well as Ben Abramowitz, Davide Grossi and Nimrod Talmon for
fruitful discussions.
      </p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>J.-G.</given-names>
            <surname>Smaus</surname>
          </string-name>
          ,
          <article-title>Proving the Existence of Stable Assignments in Democratic Forking Using Isabelle/HOL (extended version)</article-title>
          ,
          <source>Technical Report 2024-03-FR</source>
          , Institut de Recherche en Informatique de Toulouse,
          <year>2024</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>B.</given-names>
            <surname>Abramowitz</surname>
          </string-name>
          ,
          <string-name>
            <given-names>E.</given-names>
            <surname>Elkind</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Grossi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>E.</given-names>
            <surname>Shapiro</surname>
          </string-name>
          ,
          <string-name>
            <given-names>N.</given-names>
            <surname>Talmon</surname>
          </string-name>
          ,
          <article-title>Democratic forking: Choosing sides with social choice</article-title>
          , in: D.
          <string-name>
            <surname>Fotakis</surname>
            ,
            <given-names>D. R.</given-names>
          </string-name>
          <string-name>
            <surname>Insua</surname>
          </string-name>
          (Eds.),
          <source>Algorithmic Decision Theory - 7th International Conference, ADT 2021</source>
          , Toulouse, France, November 3-
          <issue>5</issue>
          ,
          <year>2021</year>
          , Proceedings, volume
          <volume>13023</volume>
          of Lecture Notes in Computer Science, Springer,
          <year>2021</year>
          , pp.
          <fpage>341</fpage>
          -
          <lpage>356</lpage>
          . doi:
          <volume>10</volume>
          . 1007/978-3-
          <fpage>030</fpage>
          -87756-9\_
          <fpage>22</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>A.</given-names>
            <surname>Phillip</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. S.</given-names>
            <surname>Chan</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Peiris</surname>
          </string-name>
          , A new look at Cryptocurrencies,
          <source>Economics Letters</source>
          <volume>163</volume>
          (
          <year>2018</year>
          )
          <fpage>6</fpage>
          -
          <lpage>9</lpage>
          . URL: https://ideas.repec.org/a/eee/ecolet/v163y2018icp6-
          <fpage>9</fpage>
          .html. doi:
          <volume>10</volume>
          .1016/ j.econlet.
          <year>2017</year>
          .
          <volume>11</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>S.</given-names>
            <surname>Zhou</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Vasilescu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Kästner</surname>
          </string-name>
          ,
          <article-title>How has forking changed in the last 20 years?: a study of hard forks on github</article-title>
          , in: G. Rothermel, D. Bae (Eds.),
          <source>ICSE '20: 42nd International Conference on Software Engineering</source>
          , Seoul, South Korea,
          <volume>27</volume>
          <fpage>June</fpage>
          -
          <issue>19</issue>
          <year>July</year>
          ,
          <year>2020</year>
          , ACM,
          <year>2020</year>
          , pp.
          <fpage>445</fpage>
          -
          <lpage>456</lpage>
          . doi:
          <volume>10</volume>
          .1145/3377811.3380412.
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>T.</given-names>
            <surname>Nipkow</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L. C.</given-names>
            <surname>Paulson</surname>
          </string-name>
          , M. Wenzel, Isabelle/HOL - A
          <string-name>
            <surname>Proof Assistant for Higher-Order</surname>
            <given-names>Logic</given-names>
          </string-name>
          , volume
          <volume>2283</volume>
          of Lecture Notes in Computer Science, Springer,
          <year>2002</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>M.</given-names>
            <surname>Wenzel</surname>
          </string-name>
          , The Isabelle/Isar Reference Manual,
          <year>2022</year>
          . https://isabelle.in.tum.de/doc/isar-ref. pdf.
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>R.</given-names>
            <surname>Pollack</surname>
          </string-name>
          ,
          <article-title>How to Believe a Machine-Checked Proof</article-title>
          ,
          <source>Technical Report RS-97-18</source>
          , Basic Research in Computer Science, University of Aarhus,
          <year>1997</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>H.</given-names>
            <surname>Barendregt</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Abramsky</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D. M.</given-names>
            <surname>Gabbay</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T. S. E.</given-names>
            <surname>Maibaum</surname>
          </string-name>
          ,
          <source>Lambda Calculi with Types</source>
          , Oxford University Press,
          <year>1992</year>
          , pp.
          <fpage>117</fpage>
          -
          <lpage>309</lpage>
          . URL: http://citeseerx.ist.psu.edu/viewdoc/ summary?doi=10.1.1.26.4391.
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>A.</given-names>
            <surname>Krauss</surname>
          </string-name>
          , Defining recursive functions in Isabelle/HOL,
          <year>2006</year>
          . Tutorial available via https: //isabelle.in.tum.de/doc/functions.pdf.
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>A.</given-names>
            <surname>Krauss</surname>
          </string-name>
          ,
          <article-title>Partial recursive functions in higher-order logic</article-title>
          , in: U. Furbach, N. Shankar (Eds.),
          <source>Automated Reasoning</source>
          , Third International Joint Conference, IJCAR 2006, Seattle, WA, USA,
          <year>August</year>
          17-
          <issue>20</issue>
          ,
          <year>2006</year>
          , Proceedings, volume
          <volume>4130</volume>
          of Lecture Notes in Computer Science, Springer,
          <year>2006</year>
          , pp.
          <fpage>589</fpage>
          -
          <lpage>603</lpage>
          . doi:
          <volume>10</volume>
          .1007/11814771\_
          <fpage>48</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <given-names>B.</given-names>
            <surname>Abramowitz</surname>
          </string-name>
          ,
          <string-name>
            <given-names>E.</given-names>
            <surname>Elkind</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Grossi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>E.</given-names>
            <surname>Shapiro</surname>
          </string-name>
          ,
          <string-name>
            <given-names>N.</given-names>
            <surname>Talmon</surname>
          </string-name>
          ,
          <article-title>Democratic forking: Choosing sides with social choice</article-title>
          ,
          <source>CoRR abs/2103</source>
          .03652 (
          <year>2021</year>
          ). URL: https://arxiv.org/abs/2103.03652. arXiv:
          <volume>2103</volume>
          .
          <fpage>03652</fpage>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>