Changes between Version 20 and Version 21 of Fundamentals
- Timestamp:
- 05/14/23 21:59:32 (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Fundamentals
v20 v21 150 150 A universally quantified formula has the form 151 151 152 `$forall` `(` ''variable-declarations'' (`;` ''variable-declarations'' )* (`|` ''restriction'')? `)` ''expr'' 153 154 where ''variable-declarations'' declares a list of variables of a given type with an optional domain, and has the form 155 156 ''type'' ''identifier'' (, ''identifier'')* (`:` ''domain'')? 152 `$forall` `(` ''variable-decls'' (`;` ''variable-decls'' )* (`|` ''restriction'')? `)` ''expr'' 153 154 where ''variable-decls'' has one of the forms 155 156 ''type'' ''identifier'' (, ''identifier'')* 157 158 ''type'' ''identifier'' `:` ''range'' 157 159 158 160 where ''type'' is a type name (e.g., `int` or `double`), ''identifier'' is the name of the bound variable. Moreover, ''restriction'' is a boolean expression which expresses some restriction on the values that the bound variable can take, and ''expr'' is a formula. The universally quantified formula holds iff for all values assignable to the bound variable for which the restriction holds, the formula expr holds. 159 161 162 The syntax for existential quantification is the same, with `$exists` in place of `$forall`. 163 160 164 Examples: 161 165 {{{ 162 $forall (int i | 0 <= i && i < n) a[i]==0 163 $forall (int i: 0..n-1) a[i]==0 164 $forall (int i,j | 0<=i && i<n && 0<=j && j<m) b[i][j]==0 165 $forall (int i: 0..n-1; int j: 0..m-1) b[i][j]==0 166 $forall (int i,j: ($domain){0..n-1, 0..m-1}) b[i][j]==0 167 }}} 168 169 [Note: the last form is not yet implemented] 170 166 int a[3], b[3][2]; 167 int main() { 168 int n=3, m=2; 169 $assert($forall (int i | 0 <= i && i < n) a[i]==0); 170 $assert($forall (int i: 0..n-1) a[i]==0); 171 $assert($forall (int i: 0..n-1 | i%2==0) a[i]==0); 172 $assert($forall (int i: 0..n-1; int j: 0..m-1) b[i][j]==0); 173 $assert($forall (int i: 0..n-1; int j | 0<=j && j<m) b[i][j]==0); 174 $assert($forall (int i: 0..n-1; int j: 0..m-1 | i<j ) b[i][j]==0); 175 $assert($forall (int i,j | 0<=i && i<n && 0<=j && j<m) b[i][j]==0); 176 $assert($exists (int i | 0<=i && i<n) a[i]==0); 177 } 178 }}} 171 179 172 180 * domain literals: An expression of the form `($domain) { r1, ..., rn }` where `r1`, . . . , `rn` are n expressions of type `$range`, is a ''Cartesian domain expression''. It represents the domain of dimension n which is the Cartesian product of the n ranges, i.e., it consists of all n-tuples (x1,...,xn) where x1 ∈ r1, ..., xn ∈ rn. The order on the domain is the dictionary order on tuples. The type of this expression is `$domain(n)`. When a Cartesian domain expression is used to initialize an object of domain type, the `($domain)` may be omitted. For example: `$domain(3) dom = { 0 .. 3, r2, 10 .. 2 # -2 };`
