Accept via "a < (b + c): a < c; 0 <= b".

This commit is contained in:
Nigel Tao committed 2017-06-01 21:24:39 +10:00
1 parent 6396b47849
commit 1bfd5804bf
3 files changed
+30 -6

No files matched your search

+18 -1
View File
@@ -217,7 +217,24 @@ var reasons = [...]struct {
s string
r reason
}{
{`"a < b: a < c <= b"`, func(q *checker, n *a.Assert) error {
{`"a < (b + c): a < c; 0 <= b"`, func(q *checker, n *a.Assert) error {
op, a, bc := parseBinaryOp(n.Condition())
if op != t.KeyXBinaryLessThan {
return errFailed
}
op, b, c := parseBinaryOp(bc)
if op != t.KeyXBinaryPlus {
return errFailed
}
if !q.proveBinaryOp(t.KeyXBinaryLessThan, a, c) {
return fmt.Errorf("cannot prove \"%s < %s\"", a.String(q.idMap), c.String(q.idMap))
}
if !q.proveBinaryOp(t.KeyXBinaryLessEq, zeroExpr, b) {
return fmt.Errorf("cannot prove \"%s <= %s\"", zeroExpr.String(q.idMap), b.String(q.idMap))
}
return nil
}},
{`"a < b: a < c; c <= b"`, func(q *checker, n *a.Assert) error {
c := argValue(q.idMap, n.Args(), "c")
if c == nil {
return errFailed
+10 -4
View File
@@ -27,8 +27,15 @@ var (
zero = big.NewInt(0)
one = big.NewInt(1)
ffff = big.NewInt(0xFFFF)
zeroExpr = a.NewExpr(a.FlagsTypeChecked, 0, t.IDUnderscore, nil, nil, nil, nil)
)
func init() {
zeroExpr.SetConstValue(zero)
zeroExpr.SetMType(TypeExprIdealNumber)
}
func btoi(b bool) *big.Int {
if b {
return one
@@ -160,12 +167,11 @@ func (q *checker) bcheckStatement(n *a.Node) error {
lhs := a.NewExpr(a.FlagsTypeChecked, 0, n.Name(), nil, nil, nil, nil)
lhs.SetMType(n.XType())
rhs := n.Value()
// "var x T" has an implicit "= _".
if rhs == nil {
rhs = a.NewExpr(a.FlagsTypeChecked, 0, t.IDUnderscore, nil, nil, nil, nil)
// "var x T" has an implicit "= _".
//
// TODO: check that T is an integer type.
rhs.SetConstValue(zero)
rhs.SetMType(TypeExprIdealNumber)
rhs = zeroExpr
}
return q.bcheckAssignment(lhs, t.IDEq, rhs)
+2 -1
View File
@@ -20,10 +20,11 @@ pub func lzw_decoder.decode?(dst ptr io.buf1, src ptr io.buf1, src_final bool)()
while true,
pre n_bits < 8,
{
assert n_bits < (width + 8) via "a < (b + c): a < c; 0 <= b"()
while n_bits < width,
post n_bits >= width,
{
assert n_bits < 12 via "a < b: a < c <= b"(c:width)
assert n_bits < 12 via "a < b: a < c; c <= b"(c:width)
bits |= 0 // TODO.
n_bits += 8
}