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[\fIidx\fL:\fIn\fR] to address \fIn\fR bits with the least-significant bit at \fIidx\fR.
93 Omiting \fL:\fIn\fR addresses a single bit.
95 \fL!\fR, \fL~\fR, \fL+\fR, \fL-\fR
96 (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.
98 \fL*\fR, \fL/\fR, \fL%\fR
99 Multiplication, division, modulo.
100 Division and modulo add an assumption that the divisor is non-zero.
103 Addition, subtraction.
106 Left shift, arithmetic right shift. Because of promotion, this is effectively a logical right shift on unsigned variables.
108 \fL<\fR, \fL<=\fR, \fL>\fR, \fL>=\fR
109 Less than, less than or equal to, greater than, greather than or equal to.
112 Equal to, not equal to.
130 Logical equivalence and logical implication (equivalent to
131 .B "(a != 0) == (b != 0)"
137 Ternary operator (\fLa?b:c\fR equals \fLb\fR if \fLa\fR is true and \fLc\fR otherwise).
142 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.
143 Note that the values reported as the counterexample are always the values given by the last assignment.
145 We know that, mathematically, \fIa\fR + \fIb\fR ≥ \fIa\fR if \fIb\fR ≥ 0 (which is always true for an unsigned number).
152 obviously a + b >= a;
156 will report "Proved", since it cannot find a counterexample for which this is not true.
157 In C, on the other hand, we know that this is not necessarily true.
158 The reason is that, depending on the types involved, results are truncated.
159 We can emulate this by writing
162 bit a[32], b[32], c[32];
169 will now report it as incorrect by providing a counterexample, for example
172 a = 10000000000000000000000000000000
173 b = 10000000000000000000000000000000
174 c = 00000000000000000000000000000000
177 Can we use \fIc\fR < \fIa\fR to check for overflow?
180 to confirm this using
183 bit a[32], b[32], c[32];
185 obviously c < a <=> c != a+b;
188 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)".
194 Any proof is only as good as the assumptions made, in particular care has to be taken with respect to truncation of intermediate results.
196 Array indices must be constants.
198 Left shifting can produce a huge number of intermediate bits.
200 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.
203 first appeared in 9front in March, 2018.