Alloy Analyzer 4 Tutorial Session 1: Intro and Logic Greg Dennis and Rob Seater Software Design Group, MIT.

Slides:



Advertisements
Similar presentations
Artificial Intelligence
Advertisements

Chapter 2 Revision of Mathematical Notations and Techniques
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 2.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2013 Lecture 4.
– Seminar in Software Engineering Cynthia Disenfeld
Micromodels of Software
Alloy Vatche Ishakian Boston University- CS511 March/24/2008 Contributors: Andrei Lapets, Michalis Potamias, Mark Reynolds.
Copyright © Cengage Learning. All rights reserved.
Sets Lecture 11: Oct 24 AB C. This Lecture We will first introduce some basic set theory before we do counting. Basic Definitions Operations on Sets Set.
Discrete Mathematics Lecture 5 Alexander Bukharovich New York University.
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 1: (Part 2): The Foundations: Logic and Proofs.
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
Discrete Mathematics Lecture 4 Harper Langston New York University.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Propositional Calculus Math Foundations of Computer Science.
Sets.
 2004 SDU Introduction to the Theory of Computation My name: 冯好娣 My office: 计算中心 430
Systems Architecture I1 Propositional Calculus Objective: To provide students with the concepts and techniques from propositional calculus so that they.
1 The Theory of NP-Completeness 2012/11/6 P: the class of problems which can be solved by a deterministic polynomial algorithm. NP : the class of decision.
SAT and SMT solvers Ayrat Khalimov (based on Georg Hofferek‘s slides) AKDV 2014.
February 18, 2015CS21 Lecture 181 CS21 Decidability and Tractability Lecture 18 February 18, 2015.
Computational Complexity Theory Lecture 2: Reductions, NP-completeness, Cook-Levin theorem Indian Institute of Science.
Theory of Computing Lecture 17 MAS 714 Hartmut Klauck.
Alloy Daniel Jackson MIT Lab for Computer Science 6898: Advanced Topics in Software Design February 11, 2002.
Set, Combinatorics, Probability & Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Set,
Mathematical Preliminaries (Hein 1.1 and 1.2) Sets are collections in which order of elements and duplication of elements do not matter. – {1,a,1,1} =
CS6133 Software Specification and Verification
Chapter 2 Mathematical preliminaries 2.1 Set, Relation and Functions 2.2 Proof Methods 2.3 Logarithms 2.4 Floor and Ceiling Functions 2.5 Factorial and.
CS201: Data Structures and Discrete Mathematics I
CompSci 102 Discrete Math for Computer Science
1 IS 2150 / TEL 2810 Introduction to Security James Joshi Associate Professor, SIS Lecture 3 September 15, 2009 Mathematical Review Security Policies.
Arjav Dave Jitendra Gupta Nishit Shah. Agenda  Overview  Alloy Architecture  Alloy Specification Language  Alloy Analyzer Demo  Comparisons  Conclusion.
Mathematical Preliminaries
UW CSE 503 ▪ Software Engineering ▪ Spring 2004 ▪ Rob DeLine1 CSE 503 – Software Engineering Lecture 3: An introduction to Alloy Rob DeLine 5 Apr 2004.
Models of Computation: Automata and Formal Languages Sam M. Kim.
Section 2.1. Sets A set is an unordered collection of objects. the students in this class the chairs in this room The objects in a set are called the.
ALLOY: A Formal Methods Tool Glenn Gordon Indiana University of Pennsylvania COSC 481- Formal Methods Dr. W. Oblitey 26 April 2005.
Chapter 2 1. Chapter Summary Sets (This Slide) The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions.
English for Economic Informatics I Tomáš Foltýnek Theoretical Foundations of Informatics.
Alloy Analyzer 4 Tutorial Session 2: Language and Analysis Greg Dennis and Rob Seater Software Design Group, MIT.
Debugging declarative models using core extraction Robert Seater with Ilya Shlyakhter, Daniel Jackson, Manu Sridharan, Mana Taghdiri December 20, 2005.
Alloy Analyzer 4 Tutorial Session 3: Static Modeling Greg Dennis and Rob Seater Software Design Group, MIT.
Sets, Permutations, and Combinations. Lecture 4-1: Sets Sets: Powerful tool in computer science to solve real world problems. A set is a collection of.
Session 4: Dynamic Modeling
CSE15 Discrete Mathematics 01/23/17
Set, Combinatorics, Probability & Number Theory
Formal Modeling Concepts
Polynomial-Time Reduction
Chapter 2: Intro to Relational Model
Exercises Show that (P  Q)  (P)  (Q)
IS 2150 / TEL 2810 Information Security & Privacy
Intro to Theory of Computation
Propositional Calculus: Boolean Algebra and Simplification
Navigating through Alloy relations
CSE 311 Foundations of Computing I
Alloy Daniel Jackson MIT Lab for Computer Science 6898: Advanced Topics in Software Design February 11, 2002.
Model the non-negative even integers
Use Alloy to model and find a solution to the Farmer, Goat, Cabbage, and Wolf problem Roger L. Costello July 14, 2018.
Chapter 8 NP and Computational Intractability
IS 2150 / TEL 2810 Introduction to Security
MCS680: Foundations Of Computer Science
Department of Computer Science
Rigorous Software Engineering
CSE 6408 Advanced Algorithms.
Logic Logic is a discipline that studies the principles and methods used to construct valid arguments. An argument is a related sequence of statements.
Alloy = FOL + transitive closure + sets + relations
Instructor: Aaron Roth
IS 2150 / TEL 2810 Introduction to Security
IS 2150 / TEL 2810 Information Security & Privacy
Presentation transcript:

Alloy Analyzer 4 Tutorial Session 1: Intro and Logic Greg Dennis and Rob Seater Software Design Group, MIT

agenda M.C. Escher ● Session 1: Intro & Logic – break ● Session 2: Language & Analysis – lunch ● Session 3: Static Modeling – break ● Session 4: Dynamic Modeling

trans-atlantic analysis Oxford, home of Z Pittsburgh, home of SMV ● notation inspired by Z – sets and relations – uniformity – but not easily analyzed ● analysis inspired by SMV – billions of cases in seconds – counterexamples not proofs – but not declarative

why declarative design? I conclude there are two ways of constructing a software design. One way is to make it so simple there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. – Tony Hoare [Turing Award Lecture, 1980]

why automated analysis? The first principle is that you must not fool yourself, and you are the easiest person to fool. – Richard P. Feynman

alloy case studies ● Multilevel security (Bolton) ● Multicast key management (Taghdiri) ● Rendezvous (Jazayeri) ● Firewire (Jackson) ● Intentional naming (Khurshid) ● Java views (Waingold) ● Access control (Zao) ● Proton therapy (Seater, Dennis) ● Chord peer-to-peer (Kaashoek) ● Unison file sync (Pierce) ● Telephone switching (Zave)

four key ideas... 1)everything is a relation 2)non-specialized logic 3)counterexamples & scope 4)analysis by SAT

1) everything's a relation ● Alloy uses relations for – all data types – even sets, scalars, tuples – structures in space and time ● key operator is dot join – relational join – field navigation – function application s1s1

why relations? There is no problem in computer science that cannot be solved by an extra level of indirection. – David Wheeler ● easy to understand – binary relation is a graph or mapping ● easy to analyze – first order (tractable) ● uniform Wheel er

2) non-specialized logic ● No special constructs for state machines, traces, synchronization, concurrency...

3) counterexamples & scope testing: a few cases of arbitrary size scope-complete: all cases within a small bound ● observations about design analysis: – most assertions are wrong – most flaws have small counterexamples

4) analysis by SAT Stephen Cook Eugene Goldberg Sharad Malik Henry Kautz ● SAT, the quintessential hard problem (Cook 1971) – SAT is hard, so reduce SAT to your problem ● SAT, the universal constraint solver (Kautz, Selman, 's) – SAT is easy, so reduce your problem to SAT – solvers: Chaff (Malik), Berkmin (Goldberg & Novikov),... Yakov Novikov

Moore's Law

SAT performance

SAT trophies

install the Alloy Analyzer ➢ Requires Java 5 runtime environment – ➢ download the Alloy Analyzer 4 – ➢ run the Analyzer – double click alloy4.jar or – execute java -jar alloy4.jar at the command line ➢ this bullet indicates something you should do

verify the installation ➢ Click the “file” menu, then click “open sample models” to open examples/toys/ceilingsAndFloors.als ➢ click the “Execute” icon – output shows graphic ● need troubleshooting? –

modeling “ceilings and floors” sig Platform {} there are “Platform” things sig Man {ceiling, floor: Platform} each Man has a ceiling and a floor Platform pred Above [m, n: Man] {m.floor = n.ceiling} Man m is “above” Man n if m's floor is n's ceiling fact {all m: Man | some n: Man | Above[n,m] } "One Man's Ceiling Is Another Man's Floor"

checking “ceilings and floors” assert BelowToo { all m: Man | some n: Man | Above [m,n] } "One Man's Floor Is Another Man's Ceiling"? check BelowToo for 2 check "One Man's Floor Is Another Man's Ceiling" counterexample with 2 or less platforms and men? ● clicking “Execute” ran this command – counterexample found, shown in graphic

counterexample to “BelowToo” McNaughton

Alloy = logic + language + analysis ● logic – first order logic + relational calculus ● language – syntax for structuring specifications in the logic ● analysis – bounded exhaustive search for counterexample to a claimed property using SAT

software abstractions

logic: relations of atoms ● atoms are Alloy's primitive entities – indivisible, immutable, uninterpreted ● relations associate atoms with one another – set of tuples, tuples are sequences of atoms ● every value in Alloy logic is a relation! – relations, sets, scalars all the same thing

logic: everything's a relation ● sets are unary (1 column) relations Name = {(N0), Addr = {(A0), Book = {(B0), (N1), (A1), (B1)} (N2)} (A2)} ● scalars are singleton sets myName = {(N1)} yourName = {(N2)} myBook = {(B0)} ● binary relation names = {(B0, N0), (B0, N1), (B1, N2)} ● ternary relation addrs = {(B0, N0, A0), (B0, N1, A1), (B1, N1, A2), (B1, N2, A2)}

logic: relations ● rows are unordered ● columns are ordered but unnamed ● all relations are first-order – relations cannot contain relations, no sets of sets addrs = {(B0, N0, A0), (B0, N1, A1), (B1, N1, A2), (B1, N2, A2)} B0 N0 A0 B0 N1 A1 B1 N1 A2 B1 N2 A2 arity = 3 size = 4

logic: address book example Name = {(N0), (N1), (N2)} Addr = {(A0), (A1), (A2)} Target = {(N0), (N1), (N2), (A0), (A1), (A2)} address = {(N0, A1), (N1, N2), (N2, A1), (N2, A0)} Target Name N2N2 N0N0 N1N1 Addr A0A0 A2A2 A1A1 address

logic: constants none empty set univ universal set iden identity relation Name = {(N0), (N1), (N2)} Addr = {(A0), (A1)} none = {} univ = {(N0), (N1), (N2), (A0), (A1)} iden = {(N0, N0), (N1, N1), (N2, N2), (A0, A0), (A1, A1)}

logic: set operators + union & intersection - difference in subset = equality Name = {(N0), (N1), (N2)} Alias = {(N1), (N2)} Group = {(N0)} RecentlyUsed = {(N0), (N2)} Alias + Group = {(N0), (N1), (N2)} Alias & RecentlyUsed = {(N2)} Name – RecentlyUsed = {(N1)} RecentlyUsed in Alias = false RecentlyUsed in Name = true Name = Group + Alias = true greg = {(N0)} rob = {(N1)} greg + rob = {(N0), (N1)} greg = rob = false rob in none = false cacheAddr = {(N0, A0), (N1, A1)} diskAddr = {(N0, A0), (N1, A2)} cacheAddr + diskAddr = {(N0, A0), (N1, A1), (N1, A2)} cacheAddr & diskAddr = {(N0, A0)} cacheAddr = diskAddr = false

logic: product operator -> cross product Name = {(N0), (N1)} Addr = {(A0), (A1)} Book = {(B0)} Name->Addr = {(N0, A0), (N0, A1), (N1, A0), (N1, A1)} Book->Name->Addr = {(B0, N0, A0), (B0, N0, A1), (B0, N1, A0), (B0, N1, A1)} b = {(B0)} b' = {(B1)} address = {(N0, A0), (N1, A1)} address' = {(N2, A2)} b->b' = {(B0, B1)} b->address + b'->address' = {(B0, N0, A0), (B0, N1, A1), (B1, N2, A2)}

logic: relational join (a, b) (a, c) (b, d) (a, d, c) (b, c, c) (c, c, c) (b, a, d) (a, c, c) (a, a, d) (c) x.f ≡ · = (a, b) (b, d) (c, a) (d, a) (a) p.q ≡ · = pqpq xfxf

logic: join operators. dot join [] box join Book = {(B0)} Name = {(N0), (N1), (N2)} Addr = {(A0), (A1), (A2)} Host = {(H0), (H1)} myName = {(N1)} myAddr = {(A0)} address = {(B0, N0, A0), (B0, N1, A0), (B0, N2, A2)} host = {(A0, H0), (A1, H1), (A2, H1)} Book.address = {(N0, A0), (N1, A0), (N2, A2)} Book.address[myName] = {(A0)} Book.address.myName = {} host[myAddr] = {(H0)} address.host = {(B0, N0, H0), (B0, N1, H0), (B0, N2, H1)} e1[e2] = e2.e1 a.b.c[d] = d.(a.b.c)

logic: unary operators ~ transpose ^ transitive closure * reflexive transitive closure apply only to binary relations Node = {(N0), (N1), (N2), (N3)} next = {(N0, N1), (N1, N2), (N2, N3)} ~next = {(N1, N0), (N2, N1), (N3, N2)} ^next = {(N0, N1), (N0, N2), (N0, N3), (N1, N2), (N1, N3), (N2, N3)} *next = {(N0, N0), (N0, N1), (N0, N2), (N0, N3), (N1, N1), (N1, N2), (N1, N3), (N2, N2), (N2, N3), (N3, N3)} ^r = r + r.r + r.r.r + … *r = iden + ^r first = {(N0)} rest = {(N1), (N2), (N3)} first.^next = rest first.*next = Node

logic: restriction and override <: domain restriction :> range restriction ++ override Name = {(N0), (N1), (N2)} Alias = {(N0), (N1)} Addr = {(A0)} address = {(N0, N1), (N1, N2), (N2, A0)} address :> Addr = {(N2, A0)} Alias Name = {(N0, N1), (N1, N2)} address :> Alias = {(N0, N1)} workAddress = {(N0, N1), (N1, A0)} address ++ workAddress = {(N0, N1), (N1, A0), (N2, A0)} p ++ q = p – (domain[q] <: p) + q m' = m ++ (k -> v) update map m with key-value pair (k, v)

logic: boolean operators !not negation &&and conjunction ||or disjunction =>implies implication else alternative iff bi- implication four equivalent constraints: F => G else H F implies G else H (F && G) || ((!F) && H) (F and G) or ((not F) and H)

logic: quantifiers all F holds for every x in e some F holds for at least one x in e no F holds for no x in e lone F holds for at most one x in e one F holds for exactly one x in e all x: e | F all x: e1, y: e2 | F all x, y: e | F all disj x, y: e | F some n: Name, a: Address | a in n.address some name maps to some address — address book not empty no n: Name | n in n.^address no name can be reached by lookups from itself — address book acyclic all n: Name | lone a: Address | a in n.address every name maps to at most one address — address book is functional all n: Name | no disj a, a': Address | (a + a') in n.address no name maps to two or more distinct addresses — same as above

logic: set declarations set any number one exactly one lone zero or one some one or more x: m e x: e x: one e RecentlyUsed: set Name RecentlyUsed is a subset of the set Name senderAddress: Addr senderAddress is a singleton subset of Addr senderName: lone Name senderName is either empty or a singleton subset of Name receiverAddresses: some Addr receiverAddresses is a nonempty subset of Addr Q x: m e

logic: relation declarations r: A m -> n B Q r: A m -> n B r: A -> B r: A set -> set B workAddress: Name -> lone Addr each alias refers to at most one work address homeAddress: Name -> one Addr each alias refers to exactly one home address members: Name lone -> some Addr address belongs to at most one group name and group contains at least one address (r: A m -> n B) ((all a: A | n a.r) and (all b: B | m r.b)) r: A -> (B m -> n C) all a: A | a.r: B m -> n C r: (A m -> n B) -> C all c: C | r.c: A m -> n B

logic: quantified expressions some Name set of names is not empty some address address book is not empty – it has a tupl e no (address.Addr – Name) nothing is mapped to addresses except names all n: Name | lone n.address every name maps to at most one address some e e has at least one tuple no e e has no tuples lone e e has at most one tuple one e e has exactly one tuple

logic: comprehensions {x1: e1, x2: e2,..., xn: en | F} {n: Name | no n.^address & Addr} set of names that don't resolve to any actual addresses {n: Name, a: Address | n -> a in ^address} binary relation mapping names to reachable addresses

logic: if and let f implies e1 else e2 let x = e | formula let x = e | expression four equivalent constraints: all n: Name | (some n.workAddress implies n.address = n.workAddress else n.address = n.homeAddress) all n: Name | let w = n.workAddress, a = n.address | (some w implies a = w else a = n.homeAddress) all n: Name | let w = n.workAddress | n.address = (some w implies w else n.homeAddress) all n: Name | n.address = (let w = n.workAddress | (some w implies w else n.homeAddress))

logic: cardinalities #r number of tuples in r 0,1,... integer literal + plus - minus all b: Bag | #b.marbles =< 3 all bags have 3 or less marbles #Marble = sum b: Bag | #b.marbles the sum of the marbles across all bags equals the total number of marbles = equals < less than > greater than =< less than or equal to >= greater than or equal to sum x: e | ie sum of integer expression ie for all singletons x drawn from e

2 logics in one ● “everybody loves a winner” ● predicate logic –  w | Winner(w)   p | Loves(p, w) ● relational calculus – Person  Winner  loves ● Alloy logic – any way you want – all p: Person, w: Winner | p -> w in loves – Person -> Winner in loves – all p: Person | Winner in p.loves

logic exercises: binary relations & join ➢ Download properties.als from the tutorial website – explores properties of binary relations ➢ Download distribution.als from the tutorial website – explores the distributivity of the join operator ➢ Follow the instructions in the models ➢ Don't hesitate to ask questions

logic exercise: modeling the tube ➢ Download tube.als from the tutorial website ● a simplified portion of the London Underground: ➢ follow the instructions in the model Stanmore Baker Street Epping Jubilee Line Central Line Circle Line