Modeling Constraints and Assertions
In this set of exercises, various scenarios are discussed related to modeling constraints and assertions within a system. Topics include defining initialization functions, ensuring non-null return values, handling lazy initialization, and exploring different possibilities regarding constraints on nodes. These exercises offer a practical approach to understanding and implementing constraints effectively.
Uploaded on Feb 16, 2025 | 0 Views
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Assignment Assignment 4 4 - - Alloy Alloy Shuai Wang shuai.wang@inf.ethz.ch
Exercise 1 Exercise 1 Counter Counter Model Model Define the init function and set n as 0. Increment counter other than last Always greater than or equal to zero. Counter s value never decreases.
Exercise Exercise 2 2 ImageFile ImageFile (eager (eager initialization) initialization) Except File/ImageFile already stored in the state
Exercise Exercise 2 2 ImageFile ImageFile (eager (eager initialization) initialization) Inv1: getImage always returnnon-null. Inv2: getImage always returns the same value. Always return non- null. Always return the same value, for a particular image.
Exercise Exercise 2 2 ImageFile ImageFile (lazy (lazy initialization) initialization) Check if already loaded Two cases to proceed the state from s -> s Lazy initialization
Exercise Exercise 2 2 ImageFile ImageFile (lazy (lazy initialization) initialization) Inv1: getImage always returnnon-null. Inv2: getImage always returns the same value. Shouldn t be null. Always return the same value, for a particular image.
Exercise Exercise 3 3 Assertion Assertion and and Counterexamples Counterexamples Define constraint and assertions for only one node. Every node must point to one and only one node. Then whether for every node, it is pointed by one and only one node? X0,0is a Boolean variable. Given constraint, can we violate the assertion? Solving Boolean constraints are usually super efficient.
Exercise Exercise 3 3 Assertion Assertion and and Counterexamples Counterexamples Definition constraint and assertions for two nodes. All the possibilities. Assertion. Counter example!
Exercise Exercise 3 3 Add Add a a prev edge edge A new fact: Enhancement: Every node is pointed by no more than one node.
Exercise Exercise 3 3 Add Add a a prev edge edge Define constraint and assertions for only one node. Constraint. Assertion. Given constraint, can we violate the assertion?
Exercise Exercise 3 3 Add Add a a prev edge edge Definition constraint and assertions for two nodes. Constraint. Assertion. Given constraint, can we violate the assertion?
Exercise Exercise 3 3 a a larger larger scope? scope? Every node must point to one and only one node. Every node is pointed by no more than one node. Then whether for every node, it is pointed by one and only one node? Sure. Every node must point to one and only one node. Then whether for every node, it is pointed by one and only one node? Q: solve this with math induction?