14 is a tool for proving formulae involving finite-precision arithmetic.
15 Given a formula it will attempt to find a counterexample; if it can't find one the formula has been proven correct.
18 is invoked on an input file with the syntax as defined below.
19 If no input file is provided, standard input is used instead.
24 to produce a table of all counterexamples rather than report just one.
25 Note that counterexamples may report bits as
27 meaning that either value will lead to a counterexample.
29 The input file consists of statements terminated by semicolons and comments using C syntax (using
36 Variable definitions, roughly:
41 Expressions (including assignments):
55 Assertions are formulae to be proved.
56 If multiple assertions are given, they are effectively "and"-ed together.
57 Each input file must have at least one assertion to be valid.
58 Assumptions are formulae that are assumed, i.e. counterexamples that would violate assumptions are never considered.
59 Exercise care with them, as contradictory assumptions will lead to any formula being true (the logician's principle of explosion).
61 Variables can be defined with C notation, but the only types supported are
65 (corresponding to machine integers of the specified size).
66 Signed integers are indicated with the keyword
72 keyword can be omitted in the presence of
82 is a set of valid declarations.
84 Unlike a programming language, it is perfectly legitimate to use a variable before it is assigned value; this means the variable is an "input" variable.
86 tries to find assignments for all input variables that render the assertions invalid.
88 Expressions can be formed just as in C, however when used in an expression, all variables are automatically promoted to an infinite size signed type.
89 The valid operators are listed below, in decreasing precedence. Note that logical operations treat all non-zero values as 1, whereas bitwise operators operate on all bits independently.
90 .TP "\w'\fL<\fR, \fL<=\fR, \fL>\fR, \fL>=\fR 'u"
92 Array indexing. The syntax is \fIvar\fL[\fIa\fL:\fIb\fR], with \fIa\fR denoting the MSB and \fIb\fR denoting the LSB.
93 Omiting \fL:\fIb\fR addresses a single bit.
94 The result is always treated as unsigned.
96 \fL!\fR, \fL~\fR, \fL+\fR, \fL-\fR
97 (Unary operators) Logical and bitwise "not", unary plus (no-op), arithmetic negation. Because of promotion, \fL~\fR and \fL-\fR operate beyond the width of variables.
99 \fL*\fR, \fL/\fR, \fL%\fR
100 Multiplication, division, modulo.
101 Division and modulo add an assumption that the divisor is non-zero.
104 Addition, subtraction.
107 Left shift, arithmetic right shift. Because of promotion, this is effectively a logical right shift on unsigned variables.
109 \fL<\fR, \fL<=\fR, \fL>\fR, \fL>=\fR
110 Less than, less than or equal to, greater than, greather than or equal to.
113 Equal to, not equal to.
131 Logical equivalence and logical implication (equivalent to
132 .B "(a != 0) == (b != 0)"
138 Ternary operator (\fLa?b:c\fR equals \fLb\fR if \fLa\fR is true and \fLc\fR otherwise).
143 One subtle point concerning assignments is that they forcibly override any previous values, i.e. expressions use the value of the latest assignments preceding them.
144 Note that the values reported as the counterexample are always the values given by the last assignment.
146 We know that, mathematically, \fIa\fR + \fIb\fR ≥ \fIa\fR if \fIb\fR ≥ 0 (which is always true for an unsigned number).
153 obviously a + b >= a;
157 will report "Proved", since it cannot find a counterexample for which this is not true.
158 In C, on the other hand, we know that this is not necessarily true.
159 The reason is that, depending on the types involved, results are truncated.
160 We can emulate this by writing
163 bit a[32], b[32], c[32];
170 will now report it as incorrect by providing a counterexample, for example
173 a = 10000000000000000000000000000000
174 b = 10000000000000000000000000000000
175 c = 00000000000000000000000000000000
178 Can we use \fIc\fR < \fIa\fR to check for overflow?
181 to confirm this using
184 bit a[32], b[32], c[32];
186 obviously c < a <=> c != a+b;
189 Here the statement to be proved is "\fIc\fR is less than \fIa\fR if and only if \fIc\fR does not equal the mathematical sum \fIa\fR + \fIb\fR (i.e. overflow has occured)".
195 Any proof is only as good as the assumptions made, in particular care has to be taken with respect to truncation of intermediate results.
197 Array indices must be constants.
199 Left shifting can produce a huge number of intermediate bits.
201 will try to identify the minimum needed number but it may be a good idea to help it by assigning the result of a left shift to a variable.
204 first appeared in 9front in March, 2018.