Par Thomas Bracher
EmailChoosen
EmailConfirmed
UserValidated
Process 1
db.modify(x -> x + 1)
Process 2
db.modify(x -> x * 2)
x = 1
Process 1
tmp = db.get(x) db.set(x, tmp + 1)
Process 2
tmp = db.get(x) db.set(x, tmp * 2)
x = 1
Require Import Arith.
Require Import List.
Require Import Omega.
(* Require Import listkit. *)
(** [cutn] breaks a list into prefix, suffix at [n]. *)
Definition cutn A n (xs : list A) := (firstn n xs, skipn n xs).
(** [cutn n] is inverse of [(++)] when [n] equals the length of the first arg to [(++)]. *)
Lemma cutn_app:
forall A n (xs ys : list A),
n = length xs -> cutn A n (xs ++ ys) = (xs, ys).
Proof.
induction n; destruct xs; simpl; easy||auto.
intros.
unfold cutn in *.
simpl.
lapply (IHn xs ys).
- congruence.
- omega.
Qed.
has_id | is_green | healthy | ok ? |
---|---|---|---|
T | F | F | F |
T | F | T | T |
T | T | F | F |
T | T | T | T |
F | T | F | F |
F | T | T | T |
F | F | T | F |
F | F | F | F |
Book = {(B0)}
Name = {(N0), (N1), (N2)}
names = {(B0, N0), (B0, N2)}
name1 = {(N1)}
-- Opération de lien (->)
{(B0)} -> {(N1), (N2)} = {(B0, N1), (B0, N2)}
Book = {(B0)}
Name = {(N0), (N1), (N2)}
names = {(B0, N0), (B0, N2)}
name1 = {(N1)}
-- Addition (+)
names + Book -> name1 = {(B0, N0), (B0, N1), (B0, N2)}
Book + Name = {(B0), (N0), (N1), (N2)}
-- Jointure (.)
Book.names = {(B0)} . {(B0, N0), (B0, N2)}
Book.names = {(N0), (N2)}
names.Name = {(B0, N0), (B0, N2)} . {(B0, N0), (B0, N2)}
names.Name = {(B0)}
sig Name, Addr {}
sig Book {
// addresses = {(B0, N0, A0), (B0, N1, A2), (B1, N2, A0)}
addresses: Name -> lone Addr
}
run {} for 3
sig Name, Addr {}
sig Book {
addresses: Name -> lone Addr
}
pred show (b: Book) {
// {(B0)} . {(B0, N0, A0), (B0, N1, A2), (B1, N2, A0)}
// {(N0, A0), (N1, A2)}
#b.addresses > 1
}
run show for 3 but 1 Book
sig Name, Addr {}
sig Book {
addresses: Name -> lone Addr
}
pred add (b, b': Book, n: Name, a: Addr) {
b'.addresses = b.addresses + n -> a
}
pred showAdd (b, b': Book, n: Name, a: Addr) {
add [b, b', n, a]
#Name.(b'.addresses) > 1
}
run showAdd for 3 but 2 Book
sig Name, Addr {}
sig Book {
addresses: Name -> lone Addr
}
pred add (b, b': Book, n: Name, a: Addr) {
b'.addresses = b.addresses + n -> a
}
pred del (b, b': Book, n: Name) {
b'.addresses = b.addresses - n -> Addr
}
fun lookup (b: Book, n: Name): set Addr {
n.(b.addresses)
}
pred showAdd (b, b': Book, n: Name, a: Addr) {
add [b, b', n, a]
#Name.(b'.addresses) > 1
}
run showAdd for 3 but 2 Book
assert delUndoesAdd {
all b, b', b'': Book , n: Name, a: Addr |
add[b, b', n, a] and del[b', b'', n] implies b.addresses = b''.addresses
}
check delUndoesAdd for 3
assert delUndoesAdd {
all b, b', b'': Book , n: Name, a: Addr |
no n.(b.addresses) and add[b, b', n, a] and del[b', b'', n]
implies b.addresses = b''.addresses
}
abstract sig Target {}
sig Addr extends Target {}
abstract sig Name extends Target {}
sig Alias, Group extends Name {}
sig Book { addresses: Name -> Target }
pred show (b: Book) { some b.addresses }
run show for 3 but 1 Book
abstract sig Target {}
sig Addr extends Target {}
abstract sig Name extends Target {}
sig Alias, Group extends Name {}
sig Book { addresses: Name -> Target } {
no n: Name | n in n.^addresses
}
fact { all b: Book | no n: Name | n in n.^(b.addresses) }
pred show (b: Book) { some b.addresses }
run show for 3 but 1 Book
abstract sig Target {}
sig Addr extends Target {}
abstract sig Name extends Target {}
sig Alias, Group extends Name {}
sig Book { addresses: Name -> Target } {
no n: Name | n in n.^addresses
all a: Alias | lone a.addresses
}
pred show (b: Book) { some Alias.(b.addresses) }
run show for 3 but 1 Book
abstract sig Target {}
sig Addr extends Target {}
abstract sig Name extends Target {}
sig Alias, Group extends Name {}
sig Book {
names: set Name,
addresses: names -> some Target
} {
no n: Name | n in n.^addresses
all a: Alias | lone a.addresses
}
pred show (b: Book) { some Alias.(b.addresses) }
run show for 3 but 1 Book
pred add (b, b': Book, n: Name, t: Target) { b'.addresses = b.addresses + n -> t }
pred del (b, b': Book, n: Name, t: Target) { b'.addresses = b.addresses - n -> t }
fun lookup (b: Book, n: Name): set Addr { n.^(b.addresses) & Addr }
abstract sig Target { }
sig Addr extends Target { }
abstract sig Name extends Target { }
sig Alias, Group extends Name { }
sig Book {
names: set Name,
addresses: names->some Target
} {
no n: Name | n in n.^addresses
all a: Alias | lone a.addresses
}
pred add [b, b': Book, n: Name, t: Target] { b'.addresses = b.addresses + n->t }
pred del [b, b': Book, n: Name, t: Target] { b'.addresses = b.addresses - n->t }
fun lookup [b: Book, n: Name] : set Addr { n.^(b.addresses) & Addr }
assert delUndoesAdd {
all b, b', b'': Book, n: Name, t: Target |
no n.(b.addresses) and add [b, b', n, t] and del [b', b'', n, t]
implies b.addresses = b''.addresses
}
check delUndoesAdd for 3
assert addIdempotent {
all b, b', b'': Book, n: Name, t: Target |
add [b, b', n, t] and add [b', b'', n, t]
implies b'.addresses = b''.addresses
}
check addIdempotent for 3
assert addLocal {
all b, b': Book, n, n': Name, t: Target |
add [b, b', n, t] and n != n'
implies lookup [b, n'] = lookup [b', n']
}
check addLocal for 3 but 2 Book
assert lookupYields {
all b: Book, n: b.names | some lookup [b,n]
}
check lookupYields for 4 but 1 Book
module tour/addressBook
open util/ordering [Book] as BookOrder
abstract sig Target { }
sig Addr extends Target { }
abstract sig Name extends Target { }
sig Alias, Group extends Name { }
sig Book {
names: set Name,
addresses: names->some Target
} {
no n: Name | n in n.^addresses
all a: Alias | lone a.addresses
}
pred add [b, b': Book, n: Name, t: Target] { b'.addresses = b.addresses + n->t }
pred del [b, b': Book, n: Name, t: Target] { b'.addresses = b.addresses - n->t }
fun lookup [b: Book, n: Name] : set Addr { n.^(b.addresses) & Addr }
pred init [b: Book] { no b.addresses }
fact traces {
init [first]
all b: Book-last | let b' = b.next | some n: Name, t: Target |
add [b, b', n, t] or del [b, b', n, t]
}
pred show { }
run show for 4
assert lookupYields { all b: Book, n: b.names | some lookup [b, n] }
check lookupYields for 3 but 4 Book
t in Addr or some lookup [b, t]
no b.addresses.n or some n.(b.addresses) - t