Presentation is loading. Please wait.

Presentation is loading. Please wait.

A Gentle Introduction to Software Modeling & Analysis

Similar presentations


Presentation on theme: "A Gentle Introduction to Software Modeling & Analysis"— Presentation transcript:

1 A Gentle Introduction to Software Modeling & Analysis
Roger L. Costello July 30, 2017

2 Table of Contents Introduction
Learn a bit about the tool we will model/analyze – lots of screenshots A model of the tool Analysis of the model The model, expressed in a modeling language Analysis, expressed in a modeling language

3 What is a model?

4 A map is a model of the physical world
This is a model of an actual airplane

5 A model is the essence of something, it is an abstraction of something

6 What is analysis?

7 Aircraft companies create models before building an aircraft.
Why?

8 Answer: Because models are more convenient to analyze, and because the actual aircraft contains lots of details that are irrelevant for analysis. Aircraft models can be analyzed: they can be put through wind tunnels to check for aerodynamic efficiency, computers can check flight behavior, and so forth.

9 Why do people create software models?
model of the software software (application)

10 Answer: Because models are more convenient to analyze, and because the actual software contains lots of details that are irrelevant for analysis. Software models can be analyzed: they can be checked for security vulnerabilities, checked for the presence (or absence) of required properties, and so forth. model of the software software (application) key point key point

11 We will model a tool that manages photos
The tool is called Phase One ( We will model a few of its essential commands

12 We will model a tool that manages photos
The tool is called Phase One ( We will model a few of its essential commands a.k.a., the “application” (I will use the terms “tool” and “application” interchangeably)

13 Benefit of modeling an existing tool
Ideally, models are created first and then the tool (software) is built. Analogously, aircraft models are created first, before building the actual aircraft. Nonetheless, it is useful to model an existing tool: Get deep insight into the tool's commands. At first glance a tool's commands may seem obvious, but are subtler when examined carefully. A model can expose errors and confusions in the tool. If there are plans to extend the tool, a model can identify if the new functionality will compromise the clarity of existing key abstractions.

14 Acknowledgement The model shown in these slides comes from this fantastic book, pages

15 Table of Contents Introduction
Learn a bit about the tool we will model/analyze – lots of screenshots A model of the tool Analysis of the model The model, expressed in a modeling language Analysis, expressed in a modeling language

16 This is the first screen you see when you open the application

17 Import your photos into the tool

18 Open a folder and select a photo

19 The tool organizes photos into “catalogs”

20 You can give the catalog a name

21 Butterfly catalog

22 Let's create a second catalog

23 Drag and drop photos in here

24 A bunch of photos placed into this catalog

25 Save the catalog under a name

26 Bruce Lee catalog

27 Create more catalogs …

28 Arnold Schwarzenneger catalog

29 Bodybuilder catalog

30 Summary The tool (application) contains catalogs
Each catalog contains photos (assets)

31 Summary The tool (application) contains catalogs
Each catalog contains photos (assets) I will often use the general term “assets” because the tool can manage more than just photos. It can also manage movies and soundtracks.

32 “select” photos

33 Two photos were “selected” by clicking on them

34 No photos selected i.e., selection = empty (Undefined)

35 Five photos “showing” Two photos “selected”

36 2 “hidden” photos

37 Can only select photos that are showing (i. e
Can only select photos that are showing (i.e., cannot select hidden photos)

38 “selection” is either Undefined (empty) or a subset of “showing”

39 “selection” is either Undefined (empty) or a subset of “showing”
This is always true (for every catalog), i.e., it's an invariant. “selection” is either Undefined (empty) or a subset of “showing”

40 Let's cut two photos from the Bodybuilder catalog and paste them to the Arnold Schwarzenegger catalog

41 Bodybuilder catalog Arnold Schwarzenegger catalog Clipboard cut paste

42 Select the photos to be cut

43 “Cut” the selected photos

44 The cut photos are stored in the application's clipboard

45 Here's the catalog after executing the cut command

46 Can we execute a “cut” command if nothing is selected?

47 Notice that no photos are selected

48 “Cut” is grayed out

49 The cut command can only be executed when one or more photos are selected

50 Now let's paste the photos in the clipboard to the Arnold Schwarzenegger catalog

51 Clipboard paste

52 Clipboard Notice that this photo already exists in the catalog

53 “Paste” the photos in the clipboard into this catalog

54 Here's the catalog after executing the paste command

55 Notice that the pasted photo is “selected” and the other photo is not pasted since it already existed in the catalog

56 Now let's see how to hide assets

57 Select one or more photos. Here I selected one photo.

58 “Hide Selected” command

59 1 hidden photo

60 Let's hide this photo as well

61 2 hidden photos

62 Can we execute a hide command if no photos are selected?

63 Notice that no photos are selected

64 “Hide Selected” is grayed out

65 The hide selected command can only be executed when one or more photos are selected

66 After executing a hide selected command, are the photos still selected?

67 After executing a hide selected command, are the photos still selected?
How can we tell? After all, we can't see the hidden photos.

68 See if the “cut” command is grayed out – recall that it is available only if assets are selected

69 I just finished the “Hide Selected” command
I just finished the “Hide Selected” command. Are any of the hidden photos selected?

70 “Cut” is grayed out

71 There are no selected photos after executing the “Hide Selected” command, either in the visible section or in the hidden section

72 What's the relationship between hidden photos and showing photos?

73 1 photo showing 2 hidden photos

74 hidden + showing = assets

75 What happens if we paste a photo that is already present in the hidden area? Will the hidden photo move to showing?

76 Show All

77 All the photos in this catalog are showing

78 Copy the selected photo

79 Create a new catalog and paste the photo into it. Here's the result.

80 Back to the other catalog. Hide the photo.

81 1 hidden photo

82 The photo is in two catalogs

83 Cut the photo from here and paste it into this catalog

84 Here's the result. You can see that the photo remains hidden
1 hidden photo

85 Pasting does not cause a photo to go from hidden to showing

86 Let's see how to show only the photos that are selected

87 Select some photos

88 We want the tool to show only the selected photos

89 “Show Selected” command

90 Here's the catalog after executing the “Show Selected” command

91 2 hidden photos

92 Notice that the selected assets remain selected

93 Now let's show just one photo, so select it

94 “Show Selected” command

95 Here's the catalog after executing the “Show Selected” command

96 3 hidden photos

97 What will happen if we execute “Show Selected” when no photos are selected?

98 Notice that no photos are selected

99 “Show Selected” is grayed out

100 The “Show Selected” command can be executed only when one or more photos are selected

101 Both “Hide Selected” and “Show Selected” hide assets
After the “Hide Selected” command After the “Show Selected” command hidden photos hidden photos

102 Difference between “Hide Selected” and “Show Selected”
After the “Hide Selected” command After the “Show Selected” command selection (after) = empty selection (after) = selection (before)

103 Phew! Time for a breather
We've seen a few of the tool's commands. Even with these few commands, the details are getting a bit complex – after executing this command the remaining assets are not selected, after executing that command the remaining assets are selected. A model would be very helpful. It would enable us to capture these details, without getting mired in irrelevant details. Okay, let's start modeling! key point

104 Table of Contents Introduction
Learn a bit about the tool we will model/analyze – lots of screenshots A model of the tool Analysis of the model The model, expressed in a modeling language Analysis, expressed in a modeling language

105 3 parts to modeling Structure: The things that are relevant to us, such as catalogs, assets, hidden assets, showing assets, etc. Behavior: The effect of the commands on the things in (1). For example, the “Hide Selected” command augments the hidden assets and subtracts from the showing assets. Analysis: Analysis of (1) and (2). For example, if we execute a cut followed by a paste is the application the same after as before?

106 (1) Structure: Identify relevant things

107 Catalogs

108 Assets

109 Selection Two photos “selected”

110 Hidden 2 “hidden” photos

111 Showing Five photos “showing”

112 Clipboard Bodybuilder catalog Clipboard Arnold Schwarzenegger catalog
cut paste

113 Summary of relevant things
- catalogs - assets - selection (set of selected assets) - hidden (set of hidden assets) - showing (set of assets that are showing) - clipboard

114 Summary of relevant things
- catalogs - assets - selection (set of selected assets) - hidden (set of hidden assets) - showing (set of assets that are showing) - clipboard key point If we were to look inside the tool would we see these things? Is this all we would see? No. This is our “abstraction” of the tool. It is a collection of things that represent our understanding of the tool. It is part of our model of the tool.

115 Next, identify things that describe the state of the application

116 Open catalogs These are the catalogs that I have open

117 For each open catalog, the catalog's state
state of this catalog state of this catalog state of this catalog state of this catalog

118 The “current” catalog This is the catalog that I am working on at this moment

119 Assets on the clipboard

120 Summary of things that describe the state of the application
- open catalogs - for each open catalog, its state - the “current” catalog - assets on the clipboard

121 Next, identify things that describe the state of a catalog

122 Catalog's assets These are the photos (assets) that are in the Bruce Lee catalog

123 Catalog's assets that are showing, that are hidden

124 Catalog's assets that are selected

125 Summary of the things that describe the state of a catalog
- catalog's assets - catalog's assets that are showing - catalog's assets that are hidden - catalog's assets that are selected (or none selected)

126 (2) Behavior: Describe the effects of each command on the things in the previous slides

127 But first, some notation
Let: xs denote the application’s state before executing the command xs' denote the application’s state after executing the command cs denote the state of the current catalog before executing the command cs' denote the state of the current catalog after executing the command buffer denote the application’s clipboard Undefined denote no selection (selection is empty)

128 Describe the effects of the “cut” command

129 Precondition to using the cut command: photos must be selected
No photos selected

130 Precondition to using the cut command: photos must be selected
cs.selection != Undefined

131 An effect of the cut command is to replace the content of the clipboard with the selection

132 An effect of the cut command is to replace the content of the clipboard with the selection
xs'.buffer = cs.selection

133 Contrast with the behavior of the emacs editor
cut The stuff in the clipboard is not overwritten. It is pushed onto a stack. stack

134 An effect of the cut command is to remove the selected assets from the catalog

135 An effect of the cut command is to remove the selected assets from the catalog
cs'.assets = cs.assets - cs.selection

136 An effect of the cut command is to remove the selected assets from the set of showing assets

137 An effect of the cut command is to remove the selected assets from the set of showing assets
cs'.showing = cs.showing - cs.selection

138 An effect of the cut command is to clear selection

139 An effect of the cut command is to clear selection
cs'.selection = Undefined

140 Only the current catalog changes

141 Only the current catalog changes
xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' Update the application's record of catalog states to reflect the modified catalog

142 No change to the set of open catalogs

143 No change to the set of open catalogs
xs'.catalogs = xs.catalogs

144 No change to the choice of the “current” catalog

145 No change to the choice of the “current” catalog
xs'.currentCatalog = xs.currentCatalog

146 Summary of the effects of the “cut” command
Precondition: cs.selection != Undefined xs'.buffer = cs.selection cs'.assets = cs.assets - cs.selection cs'.showing = cs.showing - cs.selection cs'.selection = Undefined xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

147 Describe the effects of the “paste” command

148 Notation Let: new denote the photos to be pasted into the catalog which are not already present in the catalog

149 An effect of the paste command is to add the new assets in the clipboard to the current catalog

150 An effect of the paste command is to add the new assets in the clipboard to the current catalog
cs'.assets = cs.assets + new

151 An effect of the paste command is to augment the set of showing assets with the new assets

152 An effect of the paste command is to augment the set of showing assets with the new assets
cs'.showing = cs.showing + new

153 An effect of the paste command is for selection to become the newly added assets (if there are some new assets, else Undefined) paste

154 An effect of the paste command is for selection to become the newly added assets (if there are some new assets, else Undefined) paste cs'.selection = (some new => new else Undefined)

155 Only the current catalog changes

156 Only the current catalog changes
xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' Update the application's record of catalog states to reflect the modified catalog

157 No change to the set of open catalogs

158 No change to the set of open catalogs
xs'.catalogs = xs.catalogs

159 No change to the choice of the “current” catalog

160 No change to the choice of the “current” catalog
xs'.currentCatalog = xs.currentCatalog

161 Summary of the effects of the “paste” command
xs'.buffer = xs.buffer cs'.assets = cs.assets + new cs'.showing = cs.showing + new cs'.selection = (some new => new else Undefined) xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

162 Describe the effects of the “hide selected” command

163 Precondition to executing the hide selected command: photos must be selected
No photos selected

164 Precondition to executing the hide selected command: photos must be selected
cs.selection != Undefined

165 An effect of the hide selected command is to augment the set of hidden assets
1 hidden photo

166 An effect of the hide selected command is to augment the set of hidden assets
cs'.hidden = cs.hidden + cs.selection

167 An effect of the hide selected command is to clear the selection
1 hidden photo

168 An effect of the hide selected command is to clear the selection
cs'.selection = Undefined

169 No change to the set of assets in the catalog
1 hidden photo

170 No change to the set of assets in the catalog
cs'.assets = cs.assets

171 Summary of the effects of the “hide selected” command
Precondition: cs.selection != Undefined cs'.hidden = cs.hidden + cs.selection cs'.selection = Undefined cs'.assets = cs.assets

172 Summary of the effects of the “hide selected” command
Precondition: cs.selection != Undefined cs'.hidden = cs.hidden + cs.selection cs'.selection = Undefined cs'.assets = cs.assets cs'.showing = cs.showing - cs.selection Why didn’t the previous slide have this?

173 Summary of the effects of the “hide selected” command
Precondition: cs.selection != Undefined cs'.hidden = cs.hidden + cs.selection cs'.selection = Undefined cs'.assets = cs.assets cs'.showing = cs.showing - cs.selection Recall from an earlier slide: showing + hidden = assets If you know the hidden assets and the total assets, then you know the showing assets. The statement circled above is true, but redundant.

174 Describe the effects of the “show selected” command

175 Precondition to executing the show selected command: photos must be selected
No photos selected

176 Precondition to executing the show selected command: photos must be selected
cs.selection != Undefined

177 An effect of the show selected command is to replace the set of showing assets
2 hidden photos

178 An effect of the show selected command is to replace the set of showing assets
cs'.showing = cs.selected

179 No change to the set of selected assets
show selected 2 hidden photos

180 No change to the set of selected assets
show selected cs'.selection = cs.selection

181 No change to the set of assets in the catalog
2 hidden photos

182 No change to the set of assets in the catalog
cs'.assets = cs.assets

183 Summary of the effects of the “show selected” command
Precondition: cs.selection != Undefined cs'.showing = cs.selected cs'.selection = cs.selection cs'.assets = cs.assets

184 Recap of the model The model identifies things that are relevant to us
catalogs, assets, selection, hidden, showing, clipboard The model defines the state of the application the set of open catalogs, the state of each open catalog, the “current” catalog, the assets on the clipboard The model defines the state of each catalog catalog's assets, catalog's assets that are showing, catalog's assets that are hidden, catalog's assets that are selected The model describes the effects of each command cut, paste, hide selected, show selected

185 Table of Contents Introduction
Learn a bit about the tool we will model/analyze – lots of screenshots A model of the tool Analysis of the model The model, expressed in a modeling language Analysis, expressed in a modeling language

186 Hey computer, please analyze the model: does paste undo cut?

187 Does paste undo cut? Suppose we execute a cut command followed by a paste (to the same catalog). Is the application the same after as before?

188 Does paste undo cut? Suppose we execute a cut command followed by a paste (to the same catalog). Is the application the same after as before? This is analogous to an algebra expression where we add b to “a” and then subtract b: a - b + b = a

189 Does paste undo cut? Suppose we execute a cut command followed by a paste (to the same catalog). Is the application the same after as before? In other words, does the application have algebraic properties?

190 Results: the computer found examples of where the application is not the same after as before
Here's one example

191 First, cut this photo of Schwarzenegger, Katz, & Draper

192 This is on the clipboard

193 If we desired, we could paste the stuff in the clipboard to a catalog

194 This is the “before state” of the application
This is the “before state” of the application. We're ready to start our analysis.

195 Select this photo and then do a cut command

196 Here's the catalog after doing the cut command

197 Next, do the paste command

198 Here's the catalog after doing the paste command

199 Before After

200 More precisely, this is the before and after state

201 Before After

202 Before After Before and after are different.  The clipboards differ.

203 The application does not have the algebraic property

204 Paste does not undo cut

205 Paste does not undo cut The reason that paste does not undo cut is because cut replaces (overwrites) the contents of the clipboard and the paste doesn't retrieve the previous content.

206 Let's do a second analysis

207 Would that violate anything?
Hey computer, suppose I changed the model so that the “hide selected” command retains the selection, i.e. cs'.selection = cs.selection Would that violate anything?

208 Recall the invariant:

209 Results: the computer found examples of where the application violates the invariant
Here's one example

210 I used the hide selected command to hide two photos
I used the hide selected command to hide two photos. The (erroneous) model says cs'.selected = cs.selected

211 cs'.selected = cs.selected
I used the hide selected command to hide two photos. The (erroneous) model says cs'.selected = cs.selected The selected assets are not a subset of showing. That violates the invariant.

212 Wow, a computer is able to analyze models and find examples like those?

213 Yes, provided you express the model in the right language – Alloy
Yes, provided you express the model in the right language – Alloy. Then the Alloy Analyzer will find examples like that.

214 Alloy was created at MIT by Daniel Jackson

215 The Alloy language Alloy is a language. Like all languages, it takes study and practice to become fluent. The previous slides gave you a sense for these modeling activities: abstract the application identify relevant items describe the effects of the application's commands on the items ask questions about the model -- ask the computer to analyze the model Now it’s time to express these things using the Alloy language.

216 Table of Contents Introduction
Learn a bit about the tool we will model/analyze – lots of screenshots A model of the tool Analysis of the model The model, expressed in a modeling language Analysis, expressed in a modeling language

217 Set of catalogs sig Catalog {}

218 sig Catalog {} sig = signature, use to define a set of values, in this case a set of catalogs.

219 sig Catalog {}

220 sig Catalog {} This represents the set of all past, present and future catalogs. Wow! That is cool.

221 Run Alloy (double click on this jar file)

222 Type sig Catalog {} in here

223 This is a (simple) model! Expressed in the Alloy language.

224 Select Execute >> Show Metamodel

225 This is a model diagram. Box denotes a set of values
This is a model diagram. Box denotes a set of values. The label inside the box is the name of the set of values. Thus, this model diagram says that Catalog is a set of values.

226 Hover your mouse over this icon, then you can see that there are two documents, the text and graphic version of the model.

227 Save the (text) model. Select File >> Save As…

228 Name the file this.

229 Alloy files end with the suffix .als

230 Set of assets sig Asset {}

231 sig Asset {}

232 sig Asset {} This represents the set of all past, present and future assets. Awesome!

233 Add this signature declaration. Then view the model diagram.

234 Two boxes = two sets. The model (currently) consists of a set of Catalogs and a set of Assets.

235 A singleton set, used to indicate an empty selection
one sig Undefined {}

236 one sig Undefined {} Multiplicity, how many values in the set. If not specified, the multiplicity is set. I.e., the default multiplicity is set.

237 Add this signature declaration. Then view the model diagram.

238 Catalog and Asset sets contain an unbounded number of values
Catalog and Asset sets contain an unbounded number of values. Undefined contains just one value.

239 (2) state of each catalog (3) catalog that is the “current” catalog
Previously, we saw that the state of the application is specified by the: set of open catalogs (2) state of each catalog (3) catalog that is the “current” catalog (4) clipboard (buffer) content Let’s specify “application state” using the Alloy language.

240 sig ApplicationState { catalogs: set Catalog,
catalogState: catalogs -> one CatalogState, currentCatalog: catalogs, buffer: set Asset } Explanation on following slides

241 Set of application states
sig ApplicationState { catalogs: set Catalog, catalogState: catalogs -> one CatalogState, currentCatalog: catalogs, buffer: set Asset }

242 sig ApplicationState { catalogs: set Catalog,
Set of open catalogs sig ApplicationState { catalogs: set Catalog, catalogState: catalogs -> one CatalogState, currentCatalog: catalogs, buffer: set Asset }

243 Open catalogs For example, at one point these are the catalogs that I had open.

244 Open catalogs i.e., at one application state
For example, at one point these are the catalogs that I had open.

245 sig ApplicationState { catalogs: set Catalog,
Set of open catalogs Each ApplicationState has a set of open catalogs sig ApplicationState { catalogs: set Catalog, catalogState: catalogs -> one CatalogState, currentCatalog: catalogs, buffer: set Asset }

246 sig ApplicationState { catalogs: set Catalog,
This is a field within ApplicationState. sig ApplicationState { catalogs: set Catalog, catalogState: catalogs -> one CatalogState, currentCatalog: catalogs, buffer: set Asset }

247 sig ApplicationState { catalogs: set Catalog,
This is a field within ApplicationState. It maps each value of ApplicationState to a set of values of Catalog. sig ApplicationState { catalogs: set Catalog, catalogState: catalogs -> one CatalogState, currentCatalog: catalogs, buffer: set Asset }

248 sig ApplicationState { catalogs: set Catalog,
This multiplicity indicates how many values of Catalog may be associated to a value of ApplicationState. If not specified, the multiplicity is one. I.e., the default multiplicity is one. sig ApplicationState { catalogs: set Catalog, catalogState: catalogs -> one CatalogState, currentCatalog: catalogs, buffer: set Asset }

249 ApplicationState Catalog catalogs ApplicationStatei

250 Arnold-Schwarzenneger
catalogs ApplicationStatei Arnold-Schwarzenneger ApplicationStatei Bodybuilder ApplicationStatei Bruce-Lee ApplicationStatei Butterfly

251 ApplicationState = { (ApplicationState1), (ApplicationState2), …, (ApplicationStatei), … } Catalog = { (Africa), (Albert-Einstein), (Alex-Grey), (Arnold-Schwarzenneger), (Ballerina), (Bodybuilder), (Bruce-Lee), (Butterfly), (Crossfit), (Echart-Tolle), (Mars), (Yogi) } catalogs = { …, (ApplicationStatei, Arnold-Schwarzenneger), (ApplicationStatei, Bodybuilder), (ApplicationStatei, Bruce-Lee), (ApplicationStatei, Butterfly), … }

252 Three ways to depict what is meant by this
sig ApplicationState { catalogs: set Catalog, catalogState: catalogs -> one CatalogState, currentCatalog: catalogs, buffer: set Asset }

253 Arnold-Schwarzenneger
Catalog Catalog The Alloy tools (i.e., the Alloy Analyzer) treats sets abstractly. It names the values generically, with the set name followed by a number. Arnold-Schwarzenneger Bodybuilder Bruce-Lee Butterfly Africa Albert-Einstein Alex-Grey Ballerina . . . Catalog0 Catalog1 Catalog2 Catalog3 Catalog4 Catalog5 Catalog6 Catalog7 . . .

254 . . . . . . ApplicationState ApplicationState ApplicationState3

255 catalogs ApplicationState5 Catalog3 ApplicationState5 Catalog5

256 catalogs This is a binary relation. That is, it’s a mapping between two sets. ApplicationState5 Catalog3 ApplicationState5 Catalog5 ApplicationState5 Catalog6 ApplicationState5 Catalog7

257 State of each open catalog
sig ApplicationState { catalogs: set Catalog, catalogState: catalogs -> one CatalogState, currentCatalog: catalogs, buffer: set Asset }

258 sig ApplicationState { catalogs: set Catalog,
Map each value in catalogs to exactly one CatalogState. sig ApplicationState { catalogs: set Catalog, catalogState: catalogs -> one CatalogState, currentCatalog: catalogs, buffer: set Asset }

259 catalogState

260 catalogs is the set of open catalogs, at ApplicationStatei.
catalogState

261 catalogState is the state of each open catalog (at ApplicationStatei).

262 catalogState ApplicationStatei Arnold-Schwarzenneger
ArnoldCatalogState ApplicationStatei Bodybuilder BodybuilderCatalogState ApplicationStatei Bruce-Lee Bruce-LeeCatalogState ApplicationStatei Butterfly ButterflyCatalogState

263 This is a ternary relation
catalogState This is a ternary relation ApplicationStatei Arnold-Schwarzenneger ArnoldCatalogState ApplicationStatei Bodybuilder BodybuilderCatalogState ApplicationStatei Bruce-Lee Bruce-LeeCatalogState ApplicationStatei Butterfly ButterflyCatalogState

264 sig ApplicationState { catalogs: set Catalog,
The arrow operator. sig ApplicationState { catalogs: set Catalog, catalogState: catalogs -> one CatalogState, currentCatalog: catalogs, buffer: set Asset }

265 A -> B means all possible pairings between values in A with values in B.
{ (A0,B0), (A0,B1), (A0,B2), …, (A1,B0), (A1,B1), (A1, B2), … }

266 A -> one B means pair each value in A to exactly one value in B.
{ (A0,B5), (A1,B0), (A2,B9), … }

267 Catalog that is the “current” catalog
sig ApplicationState { catalogs: set Catalog, catalogState: catalogs -> one CatalogState, currentCatalog: catalogs, buffer: set Asset }

268 The Bruce-Lee catalog is the current catalog

269 sig ApplicationState { catalogs: set Catalog,
This field declaration has a multiplicity sig ApplicationState { catalogs: set Catalog, catalogState: catalogs -> one CatalogState, currentCatalog: catalogs, buffer: set Asset } This field declaration does not have a multiplicity. The default multiplicity is one.

270 Equivalent currentCatalog: catalogs currentCatalog: one catalogs
currentCatalog maps an ApplicationState to one of the open catalogs.

271 currentCatalog ApplicationStatei Bruce-Lee

272 Set of assets in the clipboard (buffer)
sig ApplicationState { catalogs: set Catalog, catalogState: catalogs -> one CatalogState, currentCatalog: catalogs, buffer: set Asset }

273 buffer: set Asset

274 buffer ApplicationStatei Schwarzenneger, Katz, Draper photo
Schwarzenneger, Zane, Jacobs, Draper photo

275 Set of application states
sig ApplicationState { catalogs: set Catalog, catalogState: catalogs -> one CatalogState, currentCatalog: catalogs, buffer: set Asset }

276 Each state of the application is described by these fields
sig ApplicationState { catalogs: set Catalog, catalogState: catalogs -> one CatalogState, currentCatalog: catalogs, buffer: set Asset }

277 Type this into the Alloy tool.
Then, select Execute >> Show Metamodel

278 Error because the signature for CatalogState has not (yet) been defined.

279 Previously, we saw that the state of a catalog is described by the catalog's:
assets (2) assets that are showing (3) assets that are hidden (4) assets that are selected (or Undefined)

280 Assets

281 All the assets are showing

282 No hidden assets

283 Selected assets

284 Let’s specify “catalog state” using the Alloy language.

285 disj hidden, showing: set assets, selection: set showing + Undefined
sig CatalogState { assets: set Asset, disj hidden, showing: set assets, selection: set showing + Undefined } { hidden + showing = assets } Explanation on following slides

286 disj hidden, showing: set assets, selection: set showing + Undefined
Set of catalog states sig CatalogState { assets: set Asset, disj hidden, showing: set assets, selection: set showing + Undefined } { hidden + showing = assets }

287 Each catalog has a series of states.
hide selected 1 hidden photo

288 disj hidden, showing: set assets, selection: set showing + Undefined
Set of assets sig CatalogState { assets: set Asset, disj hidden, showing: set assets, selection: set showing + Undefined } { hidden + showing = assets }

289 disj hidden, showing: set assets, selection: set showing + Undefined
Set of assets Each CatalogState has a set of assets sig CatalogState { assets: set Asset, disj hidden, showing: set assets, selection: set showing + Undefined } { hidden + showing = assets }

290 Hidden assets and showing assets are disjoint
sig CatalogState { assets: set Asset, disj hidden, showing: set assets, selection: set showing + Undefined } { hidden + showing = assets }

291 Showing assets 1 hidden photo Hidden assets Catalog assets

292 Selection may be either a set of values from showing or Undefined
sig CatalogState { assets: set Asset, disj hidden, showing: set assets, selection: set showing + Undefined } { hidden + showing = assets }

293 disj hidden, showing: set assets, selection: set showing + Undefined
union operator sig CatalogState { assets: set Asset, disj hidden, showing: set assets, selection: set showing + Undefined } { hidden + showing = assets }

294 disj hidden, showing: set assets, selection: set showing + Undefined
This is called a signature fact. sig CatalogState { assets: set Asset, disj hidden, showing: set assets, selection: set showing + Undefined } { hidden + showing = assets }

295 disj hidden, showing: set assets, selection: set showing + Undefined
This is called a signature fact. It specifies a constraint on each CatalogState value. sig CatalogState { assets: set Asset, disj hidden, showing: set assets, selection: set showing + Undefined } { hidden + showing = assets }

296 disj hidden, showing: set assets, selection: set showing + Undefined
The set of hidden assets plus the set of showing assets equals the set of assets sig CatalogState { assets: set Asset, disj hidden, showing: set assets, selection: set showing + Undefined } { hidden + showing = assets }

297 Type this into the Alloy tool.
Then, select Execute >> Show Metamodel

298 The bold words are Alloy keywords.
sig Catalog {} sig Asset {} one sig Undefined {} sig ApplicationState { catalogs: set Catalog, catalogState: catalogs -> one CatalogState, currentCatalog: catalogs, buffer: set Asset } sig CatalogState { assets: set Asset, disj hidden, showing: set assets, selection: set showing + Undefined } { hidden + showing = assets This is how we describe the application and its catalogs. It is our abstraction of the tool. It is our model of the tool. It is expressed using the Alloy language. The bold words are Alloy keywords.

299 “selection” is either Undefined or a subset of “showing”
Express this invariant “selection” is either Undefined or a subset of “showing”

300 pred catalogInv (cs: CatalogState) { cs.selection = Undefined or
(some cs.selection and cs.selection in cs.showing) } For any catalog cs the selected assets is either empty (Undefined) or the selected assets is non-empty and the selected assets are a subset of the showing assets. pred = predicate (define a constraint, in this case a constraint on “selection”)

301 pred appInv (xs: ApplicationState) {
all cs: xs.catalogs | catalogInv [xs.catalogState[cs]] } The invariant on the previous slide applies to all catalogs in the application.

302 Now let's describe the tool's commands

303 First, the “cut” command

304 Explanation on following slides
pred cut (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), sel = cs.selection { sel != Undefined xs'.buffer = sel some cs': CatalogState { cs'.assets = cs.assets - sel cs'.showing = cs.showing - sel cs'.selection = Undefined xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog Explanation on following slides

305 Let cs denote the application's current catalog
pred cut (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), sel = cs.selection { sel != Undefined xs'.buffer = sel some cs': CatalogState { cs'.assets = cs.assets - sel cs'.showing = cs.showing - sel cs'.selection = Undefined xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

306 Let sel denote the set of selected assets in the current catalog
pred cut (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), sel = cs.selection { sel != Undefined xs'.buffer = sel some cs': CatalogState { cs'.assets = cs.assets - sel cs'.showing = cs.showing - sel cs'.selection = Undefined xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

307 The precondition for the cut command is that at least one asset is selected
pred cut (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), sel = cs.selection { sel != Undefined xs'.buffer = sel some cs': CatalogState { cs'.assets = cs.assets - sel cs'.showing = cs.showing - sel cs'.selection = Undefined xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

308 After the cut command has been executed, the clipboard (buffer) contains the selected assets
pred cut (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), sel = cs.selection { sel != Undefined xs'.buffer = sel some cs': CatalogState { cs'.assets = cs.assets - sel cs'.showing = cs.showing - sel cs'.selection = Undefined xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

309 After the cut command has been executed, there is a catalog state cs' satisfying these properties …
pred cut (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), sel = cs.selection { sel != Undefined xs'.buffer = sel some cs': CatalogState { cs'.assets = cs.assets - sel cs'.showing = cs.showing - sel cs'.selection = Undefined xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

310 … its assets are the catalog's original assets minus the selected assets
pred cut (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), sel = cs.selection { sel != Undefined xs'.buffer = sel some cs': CatalogState { cs'.assets = cs.assets - sel cs'.showing = cs.showing - sel cs'.selection = Undefined xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

311 … its assets that are showing are those that were originally showing minus the selected assets
pred cut (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), sel = cs.selection { sel != Undefined xs'.buffer = sel some cs': CatalogState { cs'.assets = cs.assets - sel cs'.showing = cs.showing - sel cs'.selection = Undefined xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

312 … it has no selected assets.
pred cut (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), sel = cs.selection { sel != Undefined xs'.buffer = sel some cs': CatalogState { cs'.assets = cs.assets - sel cs'.showing = cs.showing - sel cs'.selection = Undefined xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

313 The application's record of each catalog's state is updated to reflect the change to the current catalog pred cut (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), sel = cs.selection { sel != Undefined xs'.buffer = sel some cs': CatalogState { cs'.assets = cs.assets - sel cs'.showing = cs.showing - sel cs'.selection = Undefined xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

314 The set of open catalogs doesn't change with the cut command
pred cut (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), sel = cs.selection { sel != Undefined xs'.buffer = sel some cs': CatalogState { cs'.assets = cs.assets - sel cs'.showing = cs.showing - sel cs'.selection = Undefined xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

315 The current catalog doesn't change with the cut command
pred cut (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), sel = cs.selection { sel != Undefined xs'.buffer = sel some cs': CatalogState { cs'.assets = cs.assets - sel cs'.showing = cs.showing - sel cs'.selection = Undefined xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

316 Next, the “paste” command

317 Explanation on following slides
pred paste (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), buf = xs.buffer, new = buf - cs.assets { xs'.buffer = buf some cs': CatalogState { cs'.assets = cs.assets + new cs'.showing = cs.showing + new cs'.selection = (some new => new else Undefined) xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog Explanation on following slides

318 Let cs denote the application's current catalog
pred paste (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), buf = xs.buffer, new = buf - cs.assets { xs'.buffer = buf some cs': CatalogState { cs'.assets = cs.assets + new cs'.showing = cs.showing + new cs'.selection = (some new => new else Undefined) xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

319 Let buf denote the clipboard (buffer)
pred paste (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), buf = xs.buffer, new = buf - cs.assets { xs'.buffer = buf some cs': CatalogState { cs'.assets = cs.assets + new cs'.showing = cs.showing + new cs'.selection = (some new => new else Undefined) xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

320 Let new denote the assets that are in the clipboard but not in the catalog
pred paste (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), buf = xs.buffer, new = buf - cs.assets { xs'.buffer = buf some cs': CatalogState { cs'.assets = cs.assets + new cs'.showing = cs.showing + new cs'.selection = (some new => new else Undefined) xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

321 The clipboard (buffer) doesn't change with the execution of the paste command
pred paste (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), buf = xs.buffer, new = buf - cs.assets { xs'.buffer = buf some cs': CatalogState { cs'.assets = cs.assets + new cs'.showing = cs.showing + new cs'.selection = (some new => new else Undefined) xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

322 After the paste command has been executed, there is a catalog state cs' satisfying these properties … pred paste (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), buf = xs.buffer, new = buf - cs.assets { xs'.buffer = buf some cs': CatalogState { cs'.assets = cs.assets + new cs'.showing = cs.showing + new cs'.selection = (some new => new else Undefined) xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

323 … it has more assets – the new assets in the clipboard
pred paste (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), buf = xs.buffer, new = buf - cs.assets { xs'.buffer = buf some cs': CatalogState { cs'.assets = cs.assets + new cs'.showing = cs.showing + new cs'.selection = (some new => new else Undefined) xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

324 … it is showing more assets – the new assets in the clipboard
pred paste (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), buf = xs.buffer, new = buf - cs.assets { xs'.buffer = buf some cs': CatalogState { cs'.assets = cs.assets + new cs'.showing = cs.showing + new cs'.selection = (some new => new else Undefined) xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

325 … if the value of “new” is non-empty, then the selected assets are the new assets, otherwise the selected assets is empty (Undefined). pred paste (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), buf = xs.buffer, new = buf - cs.assets { xs'.buffer = buf some cs': CatalogState { cs'.assets = cs.assets + new cs'.showing = cs.showing + new cs'.selection = (some new => new else Undefined) xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

326 The application's record of each catalog's state is updated to reflect the change to the current catalog pred paste (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), buf = xs.buffer, new = buf - cs.assets { xs'.buffer = buf some cs': CatalogState { cs'.assets = cs.assets + new cs'.showing = cs.showing + new cs'.selection = (some new => new else Undefined) xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

327 The set of open catalogs doesn't change with the paste command
pred paste (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), buf = xs.buffer, new = buf - cs.assets { xs'.buffer = buf some cs': CatalogState { cs'.assets = cs.assets + new cs'.showing = cs.showing + new cs'.selection = (some new => new else Undefined) xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

328 The current catalog doesn't change with the paste command
pred paste (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), buf = xs.buffer, new = buf - cs.assets { xs'.buffer = buf some cs': CatalogState { cs'.assets = cs.assets + new cs'.showing = cs.showing + new cs'.selection = (some new => new else Undefined) xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog

329 Next, the “hide selected” command

330 Explanation on following slides
pred hideSelected (cs, cs': CatalogState) { cs.selection != Undefined cs'.hidden = cs.hidden + cs.selection cs'.selection = Undefined cs'.assets = cs.assets } Explanation on following slides

331 Precondition – can't do the hide selected command unless something is selected
pred hideSelected (cs, cs': CatalogState) { cs.selection != Undefined cs'.hidden = cs.hidden + cs.selection cs'.selection = Undefined cs'.assets = cs.assets }

332 As a result of executing the hide selected command there are more hidden assets – the existing hidden assets plus the selected assets pred hideSelected (cs, cs': CatalogState) { cs.selection != Undefined cs'.hidden = cs.hidden + cs.selection cs'.selection = Undefined cs'.assets = cs.assets }

333 After executing the hide selected command there are no selected assets
pred hideSelected (cs, cs': CatalogState) { cs.selection != Undefined cs'.hidden = cs.hidden + cs.selection cs'.selection = Undefined cs'.assets = cs.assets }

334 The hide selected command doesn't change the assets in the catalog
pred hideSelected (cs, cs': CatalogState) { cs.selection != Undefined cs'.hidden = cs.hidden + cs.selection cs'.selection = Undefined cs'.assets = cs.assets }

335 Next, the “show selected” command

336 Explanation on following slides
pred showSelected (cs, cs': CatalogState) { cs.selection != Undefined cs'.showing = cs.selection cs'.selection = cs.selection cs'.assets = cs.assets } Explanation on following slides

337 Precondition – can't do the show selected command unless something is selected
pred showSelected (cs, cs': CatalogState) { cs.selection != Undefined cs'.showing = cs.selection cs'.selection = cs.selection cs'.assets = cs.assets }

338 After executing the show selected command only the selected assets are showing
pred showSelected (cs, cs': CatalogState) { cs.selection != Undefined cs'.showing = cs.selection cs'.selection = cs.selection cs'.assets = cs.assets }

339 The show selected command doesn't change the set of selected assets
pred showSelected (cs, cs': CatalogState) { cs.selection != Undefined cs'.showing = cs.selection cs'.selection = cs.selection cs'.assets = cs.assets }

340 The show selected command doesn't change the set of assets in the catalog
pred showSelected (cs, cs': CatalogState) { cs.selection != Undefined cs'.showing = cs.selection cs'.selection = cs.selection cs'.assets = cs.assets }

341 Here is our model of the tool's commands, expressed in the Alloy language

342 pred cut (xs, xs': ApplicationState) {
let cs = xs.currentCatalog.(xs.catalogState), sel = cs.selection { sel != Undefined xs'.buffer = sel some cs': CatalogState { cs'.assets = cs.assets - sel cs'.showing = cs.showing - sel cs'.selection = Undefined xs'.catalogState = xs.catalogState ++ xs.currentCatalog -> cs' } xs'.catalogs = xs.catalogs xs'.currentCatalog = xs.currentCatalog pred paste (xs, xs': ApplicationState) { let cs = xs.currentCatalog.(xs.catalogState), buf = xs.buffer, new = buf - cs.assets { xs'.buffer = buf cs'.assets = cs.assets + new cs'.showing = cs.showing + new cs'.selection = (some new => new else Undefined) pred hideSelected (cs, cs': CatalogState) { cs.selection != Undefined cs'.hidden = cs.hidden + cs.selection cs'.selection = Undefined cs'.assets = cs.assets } pred showSelected (cs, cs': CatalogState) { cs'.showing = cs.selection cs'.selection = cs.selection

343 Table of Contents Introduction
Learn a bit about the tool we will model/analyze – lots of screenshots A model of the tool Analysis of the model The model, expressed in a modeling language Analysis, expressed in a modeling language

344 Alloy = modeling language + analyzer
Alloy Analyzer Model (expressed using the Alloy language) COTS SAT solver

345 (expressed using the Alloy language)
Alloy Analyzer Model (expressed using the Alloy language) COTS SAT solver Hey Alloy Analyzer, please analyze the photo model – does paste undo cut?

346 Explanation on following slides
assert CutPaste { all xs, xs', xs'': ApplicationState | appInv [xs] and cut [xs, xs'] and paste [xs', xs''] => sameApplicationState [xs, xs''] } check CutPaste Explanation on following slides

347 The cut command results in the application going from state xs to xs'
The cut command results in the application going from state xs to xs'. If we then execute a paste command, the application goes from state xs' to xs''. I hereby assert that application state xs is the same as application state xs''. assert CutPaste { all xs, xs', xs'': ApplicationState | appInv [xs] and cut [xs, xs'] and paste [xs', xs''] => sameApplicationState [xs, xs''] } check CutPaste

348 assert CutPaste { all xs, xs', xs'': ApplicationState | appInv [xs] and cut [xs, xs'] and paste [xs', xs''] => sameApplicationState [xs, xs''] } check CutPaste pred sameApplicationState (xs, xs': ApplicationState) { xs'.catalogs = xs.catalogs all c: xs.catalogs | sameCatalogState [c.(xs.catalogState), c.(xs'.catalogState)] xs'.currentCatalog = xs.currentCatalog xs'.buffer = xs.buffer } pred sameCatalogState (cs, cs': CatalogState) { cs'.assets = cs.assets cs'.showing = cs.showing cs'.selection = cs.selection Here's our definition of what it means for two application states to be the “same”

349 The set of open catalogs is the same before and after
pred sameApplicationState (xs, xs': ApplicationState) { xs'.catalogs = xs.catalogs all c: xs.catalogs | sameCatalogState [c.(xs.catalogState), c.(xs'.catalogState)] xs'.currentCatalog = xs.currentCatalog xs'.buffer = xs.buffer } pred sameCatalogState (cs, cs': CatalogState) { cs'.assets = cs.assets cs'.showing = cs.showing cs'.selection = cs.selection The set of open catalogs is the same before and after

350 The state of all catalogs is the same before and after
pred sameApplicationState (xs, xs': ApplicationState) { xs'.catalogs = xs.catalogs all c: xs.catalogs | sameCatalogState [c.(xs.catalogState), c.(xs'.catalogState)] xs'.currentCatalog = xs.currentCatalog xs'.buffer = xs.buffer } pred sameCatalogState (cs, cs': CatalogState) { cs'.assets = cs.assets cs'.showing = cs.showing cs'.selection = cs.selection The state of all catalogs is the same before and after

351 The catalog that is the current catalog is the same before and after
pred sameApplicationState (xs, xs': ApplicationState) { xs'.catalogs = xs.catalogs all c: xs.catalogs | sameCatalogState [c.(xs.catalogState), c.(xs'.catalogState)] xs'.currentCatalog = xs.currentCatalog xs'.buffer = xs.buffer } pred sameCatalogState (cs, cs': CatalogState) { cs'.assets = cs.assets cs'.showing = cs.showing cs'.selection = cs.selection The catalog that is the current catalog is the same before and after

352 The clipboard (buffer) is the same before and after
pred sameApplicationState (xs, xs': ApplicationState) { xs'.catalogs = xs.catalogs all c: xs.catalogs | sameCatalogState [c.(xs.catalogState), c.(xs'.catalogState)] xs'.currentCatalog = xs.currentCatalog xs'.buffer = xs.buffer } pred sameCatalogState (cs, cs': CatalogState) { cs'.assets = cs.assets cs'.showing = cs.showing cs'.selection = cs.selection The clipboard (buffer) is the same before and after

353 pred sameApplicationState (xs, xs': ApplicationState) {
xs'.catalogs = xs.catalogs all c: xs.catalogs | sameCatalogState [c.(xs.catalogState), c.(xs'.catalogState)] xs'.currentCatalog = xs.currentCatalog xs'.buffer = xs.buffer } pred sameCatalogState (cs, cs': CatalogState) { cs'.assets = cs.assets cs'.showing = cs.showing cs'.selection = cs.selection Here's our definition of what it means for two catalog states to be the same

354 The catalog's assets are the same before and after
pred sameApplicationState (xs, xs': ApplicationState) { xs'.catalogs = xs.catalogs all c: xs.catalogs | sameCatalogState [c.(xs.catalogState), c.(xs'.catalogState)] xs'.currentCatalog = xs.currentCatalog xs'.buffer = xs.buffer } pred sameCatalogState (cs, cs': CatalogState) { cs'.assets = cs.assets cs'.showing = cs.showing cs'.selection = cs.selection The catalog's assets are the same before and after

355 The assets that are showing are the same before and after
pred sameApplicationState (xs, xs': ApplicationState) { xs'.catalogs = xs.catalogs all c: xs.catalogs | sameCatalogState [c.(xs.catalogState), c.(xs'.catalogState)] xs'.currentCatalog = xs.currentCatalog xs'.buffer = xs.buffer } pred sameCatalogState (cs, cs': CatalogState) { cs'.assets = cs.assets cs'.showing = cs.showing cs'.selection = cs.selection The assets that are showing are the same before and after

356 The assets that are selected are the same before and after
pred sameApplicationState (xs, xs': ApplicationState) { xs'.catalogs = xs.catalogs all c: xs.catalogs | sameCatalogState [c.(xs.catalogState), c.(xs'.catalogState)] xs'.currentCatalog = xs.currentCatalog xs'.buffer = xs.buffer } pred sameCatalogState (cs, cs': CatalogState) { cs'.assets = cs.assets cs'.showing = cs.showing cs'.selection = cs.selection The assets that are selected are the same before and after

357 Alloy Analyzer, see if you can find a counterexample to the assert, i
Alloy Analyzer, see if you can find a counterexample to the assert, i.e., see if you can find an example where paste does not undo cut. assert CutPaste { all xs, xs', xs'': ApplicationState | appInv [xs] and cut [xs, xs'] and paste [xs', xs''] => sameApplicationState [xs, xs''] } check CutPaste

358 The Alloy Analyzer finds a counterexample

359 Before After Before and after are different.  The clipboards differ.

360 Suppose we decide that it's acceptable for the buffers to differ, how to revise the model?

361 Simply modify the definition of “same”

362 pred sameApplicationState (xs, xs': ApplicationState) {
xs'.catalogs = xs.catalogs all c: xs.catalogs | sameCatalogState [c.(xs.catalogState), c.(xs'.catalogState)] xs'.currentCatalog = xs.currentCatalog // xs'.buffer = xs.buffer } pred sameCatalogState (cs, cs': CatalogState) { cs'.assets = cs.assets cs'.showing = cs.showing cs'.selection = cs.selection I commented out the line that says the buffers must be the same before and after

363 Now the Alloy Analyzer does not find a counterexample

364 Next, let's analyze the model's definition of how the “hide selected” command effects selection

365 change to pred hideSelected (cs, cs': CatalogState) {
cs.selection != Undefined cs'.hidden = cs.hidden + cs.selection cs'.selection = Undefined cs'.assets = cs.assets } pred hideSelected (cs, cs': CatalogState) { cs.selection != Undefined cs'.hidden = cs.hidden + cs.selection cs'.selection = cs.selection cs'.assets = cs.assets } change to

366 Does the “hide selected” command preserve the invariant?

367 Explanation on following slides
assert HidePreserveInv { all cs, cs': CatalogState | catalogInv [cs] and hideSelected [cs, cs'] => catalogInv [cs'] } check HidePreserveInv Explanation on following slides

368 I hereby assert that for all catalogs, if catalog cs satisfies the catalog invariant and the hide selected command is executed, then the resulting catalog cs' satisfies the catalog invariant. assert HidePreserveInv { all cs, cs': CatalogState | catalogInv [cs] and hideSelected [cs, cs'] => catalogInv [cs'] } check HidePreserveInv

369 Alloy Analyzer, see if you can find a counterexample to the assert, i
Alloy Analyzer, see if you can find a counterexample to the assert, i.e., see if you can find an example where the hide selected command yields a catalog that does not satisfy the catalog invariant. assert HidePreserveInv { all cs, cs': CatalogState | catalogInv [cs] and hideSelected [cs, cs'] => catalogInv [cs'] } check HidePreserveInv

370 The Alloy Analyzer finds a counterexample

371 cs'.selected = cs.selected
I used the hide selected command to hide two photos. The (erroneous) model says cs'.selected = cs.selected The selected assets are not a subset of showing. That violates the invariant.

372 I hope you've enjoyed this tutorial
The End I hope you've enjoyed this tutorial Roger Costello, July


Download ppt "A Gentle Introduction to Software Modeling & Analysis"

Similar presentations


Ads by Google