// ----------------------------------------------------------------- // goat.txt: the goat, wolf, and cabbage problem // Concrete Abstractions: Puzzles and Games // (c) 2020, Wolfgang Schreiner, RISC, JKU Linz, Austria // ----------------------------------------------------------------- // the entities to be transfered across the river type Entity = ℕ[3]; val farmer = 0; val goat = 1; val wolf = 2; val cabbage = 3; // the sides of the river type Place = Bool; val left = ⊥; val right = ⊤; // a placement of the entity to river sides // and a sequence of such placements (including the initial one) type Placement = Map[Entity,Place]; // the side opposite to p fun other(p:Place):Place = ¬p; // placement p is safe pred safe(p:Placement) ⇔ let q = other(p[farmer]) in ¬(p[goat] = q ∧ p[wolf] = q) ∧ ¬(p[goat] = q ∧ p[cabbage] = q); // a system-based formulation shared system River { var p:Placement = Map[Entity,Place](left); invariant ¬∀e:Entity. p[e] = right; action move1() with let q = other(p[farmer]), p0 = p with [farmer] = q in safe(p0); { val q = other(p[farmer]); p[farmer] ≔ q; } action move2(e:Entity) with e ≠ farmer ∧ p[e] = p[farmer] ∧ let q = other(p[farmer]), p0 = p with [farmer] = q with [e] = q in safe(p0); { val q = other(p[farmer]); p[farmer] ≔ q; p[e] ≔ q; } } // ----------------------------------------------------------------- // end of file // -----------------------------------------------------------------