Skip to content

Commit 2ac5057

Browse files
committed
Add Eunoia definitions for BV multiplication overflow predicates
1 parent b936ead commit 2ac5057

File tree

5 files changed

+136
-31
lines changed

5 files changed

+136
-31
lines changed

include/cvc5/cvc5_proof_rule.h

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3033,38 +3033,34 @@ enum ENUM(ProofRewriteRule)
30333033
* \verbatim embed:rst:leading-asterisk
30343034
* **Bitvectors -- Unsigned multiplication overflow detection elimination**
30353035
*
3036+
* .. math::
3037+
* \texttt{bvumulo}(x,y) = t
3038+
*
3039+
* where :math:`t` is the result of eliminating the application
3040+
* of :math:`\texttt{bvumulo}`.
3041+
*
30363042
* See M.Gok, M.J. Schulte, P.I. Balzola, "Efficient integer multiplication
30373043
* overflow detection circuits", 2001.
30383044
* http://ieeexplore.ieee.org/document/987767
30393045
* \endverbatim
30403046
*/
3041-
EVALUE(BV_UMULO_ELIMINATE),
3047+
EVALUE(BV_UMULO_ELIM),
30423048
/**
30433049
* \verbatim embed:rst:leading-asterisk
30443050
* **Bitvectors -- Unsigned multiplication overflow detection elimination**
30453051
*
3052+
* .. math::
3053+
* \texttt{bvsmulo}(x,y) = t
3054+
*
3055+
* where :math:`t` is the result of eliminating the application
3056+
* of :math:`\texttt{bvsmulo}`.
3057+
*
30463058
* See M.Gok, M.J. Schulte, P.I. Balzola, "Efficient integer multiplication
30473059
* overflow detection circuits", 2001.
30483060
* http://ieeexplore.ieee.org/document/987767
30493061
* \endverbatim
30503062
*/
3051-
EVALUE(BV_SMULO_ELIMINATE),
3052-
/**
3053-
* \verbatim embed:rst:leading-asterisk
3054-
* **Bitvectors -- Combine like terms during addition by counting terms**
3055-
* \endverbatim
3056-
*/
3057-
EVALUE(BV_ADD_COMBINE_LIKE_TERMS),
3058-
/**
3059-
* \verbatim embed:rst:leading-asterisk
3060-
* **Bitvectors -- Extract negations from multiplicands**
3061-
*
3062-
* .. math::
3063-
* bvmul(bvneg(a),\ b,\ c) = bvneg(bvmul(a,\ b,\ c))
3064-
*
3065-
* \endverbatim
3066-
*/
3067-
EVALUE(BV_MULT_SIMPLIFY),
3063+
EVALUE(BV_SMULO_ELIM),
30683064
/**
30693065
* \verbatim embed:rst:leading-asterisk
30703066
* **Bitvectors -- Extract continuous substrings of bitvectors**

proofs/eo/cpc/rules/BitVectors.eo

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,120 @@
1616
:conclusion (= (repeat n a) b)
1717
)
1818

19+
;;;;; ProofRewriteRule::BV_SMULO_ELIM
20+
21+
; define: $bv_smulo_elim
22+
; args:
23+
; - xa (BitVec n): An xor term involving the first argument to bvsmulo
24+
; - xb (BitVec n): An xor term involving the second argument to bvsmulo
25+
; - ppc (BitVec 1): An intermediate bitvector term accumulated to help construct the result.
26+
; - res (BitVec 1): The current accumulated result.
27+
; - i Int: The current bit we are processing.
28+
; - nm2 Int: The bitwidth of a and b minus 2.
29+
; return: >
30+
; A portion of the result of eliminating (bvsmulo a b).
31+
(program $bv_smulo_elim_rec ((n Int) (xa (BitVec n)) (xb (BitVec n))
32+
(ppc (BitVec 1)) (res (BitVec 1)) (i Int) (nm2 Int))
33+
((BitVec n) (BitVec n) (BitVec 1) (BitVec 1) Int Int) (BitVec 1)
34+
(
35+
(($bv_smulo_elim_rec xa xb ppc res nm2 nm2) res)
36+
(($bv_smulo_elim_rec xa xb ppc res i nm2)
37+
(eo::define ((ia (eo::add nm2 (eo::neg i))))
38+
(eo::define ((ip1 (eo::add i 1)))
39+
(eo::define ((ppcn (bvor ppc (extract ia ia xa))))
40+
($bv_smulo_elim_rec xa xb ppcn (bvor res (bvand (extract ip1 ip1 xb) ppcn)) ip1 nm2)))))
41+
)
42+
)
43+
44+
; define: $bv_smulo_elim
45+
; args:
46+
; - a (BitVec n): The first argument to bvsmulo
47+
; - b (BitVec n): The second argument to bvsmulo
48+
; return: >
49+
; The result of eliminating (bvsmulo a b).
50+
(define $bv_smulo_elim ((n Int :implicit) (a (BitVec n)) (b (BitVec n)))
51+
(eo::define ((w ($bv_bitwidth (eo::typeof a))))
52+
(eo::define ((wm1 (eo::add w -1)))
53+
(eo::define ((one (eo::to_bin 1 1)))
54+
(eo::ite (eo::is_eq w 1)
55+
(= (bvand a b) one)
56+
(eo::define ((mul (bvmul (sign_extend 1 a) (sign_extend 1 b))))
57+
(eo::ite (eo::is_eq w 2)
58+
(= (bvxor (extract w w mul) (extract wm1 wm1 mul)) one)
59+
(eo::define ((xa (bvxor a (sign_extend wm1 (extract wm1 wm1 a)))))
60+
(eo::define ((xb (bvxor b (sign_extend wm1 (extract wm1 wm1 b)))))
61+
(eo::define ((wm2 (eo::add w -2)))
62+
(eo::define ((ppc (extract wm2 wm2 xa)))
63+
(eo::define ((res ($bv_smulo_elim_rec xa xb ppc (bvand (extract 1 1 xb) ppc) 1 wm2)))
64+
(= (bvor res (bvxor (extract w w mul) (extract wm1 wm1 mul))) one))))))))))))
65+
)
66+
67+
; rule: bv-smulo-elim
68+
; implements: ProofRewriteRule::BV_SMULO_ELIM
69+
; args:
70+
; - eq Bool: The equality to prove with this rule.
71+
; requires: c is the result of eliminating the left hand side.
72+
; conclusion: the given equality.
73+
(declare-rule bv-smulo-elim ((n Int) (a (BitVec n)) (b (BitVec n)) (c Bool))
74+
:args ((= (bvsmulo a b) c))
75+
:requires ((($bv_smulo_elim a b) c))
76+
:conclusion (= (bvsmulo a b) c)
77+
)
78+
79+
;;;;; ProofRewriteRule::BV_UMULO_ELIM
80+
81+
; define: $bv_umulo_elim_rec
82+
; args:
83+
; - xa (BitVec n): An xor term involving the first argument to bvumulo
84+
; - xb (BitVec n): An xor term involving the second argument to bvumulo
85+
; - ppc (BitVec 1): An intermediate bitvector term accumulated to help construct the result.
86+
; - res (BitVec 1): The current accumulated result.
87+
; - i Int: The current bit we are processing.
88+
; - nm2 Int: The bitwidth of a and b minus 2.
89+
; return: >
90+
; A portion of the result of eliminating (bvsmulo a b).
91+
(program $bv_umulo_elim_rec ((n Int) (a (BitVec n)) (b (BitVec n))
92+
(uppc (BitVec 1)) (res (BitVec 1)) (i Int))
93+
((BitVec n) (BitVec n) (BitVec 1) (BitVec 1) Int Int) (BitVec 1)
94+
(
95+
(($bv_umulo_elim_rec a b uppc res n n) res)
96+
(($bv_umulo_elim_rec a b uppc res i n)
97+
(eo::define ((ia (eo::add n -1 (eo::neg i))))
98+
(eo::define ((ip1 (eo::add i 1)))
99+
(eo::define ((uppcn (bvor (extract ia ia a) uppc)))
100+
(eo::cons bvor (bvand (extract i i b) uppc) ($bv_umulo_elim_rec a b uppcn res ip1 n))))))
101+
)
102+
)
103+
104+
; define: $bv_umulo_elim
105+
; args:
106+
; - a (BitVec n): The first argument to bvumulo
107+
; - b (BitVec n): The second argument to bvumulo
108+
; return: >
109+
; The result of eliminating (bvumulo a b).
110+
(define $bv_umulo_elim ((n Int :implicit) (a (BitVec n)) (b (BitVec n)))
111+
(eo::define ((w ($bv_bitwidth (eo::typeof a))))
112+
(eo::ite (eo::is_eq w 1)
113+
false
114+
(eo::define ((wm1 (eo::add w -1)))
115+
(eo::define ((zero (eo::to_bin 1 0)))
116+
(eo::define ((uppc (extract wm1 wm1 a)))
117+
(eo::define ((mul (bvmul (concat zero a) (concat zero b))))
118+
(eo::define ((res ($bv_umulo_elim_rec a b uppc (bvor (extract w w mul)) 1 w)))
119+
(= res (eo::to_bin 1 1))))))))))
120+
121+
; rule: bv-umulo-elim
122+
; implements: ProofRewriteRule::BV_UMULO_ELIM
123+
; args:
124+
; - eq Bool: The equality to prove with this rule.
125+
; requires: c is the result of eliminating the left hand side.
126+
; conclusion: the given equality.
127+
(declare-rule bv-umulo-elim ((n Int) (a (BitVec n)) (b (BitVec n)) (c Bool))
128+
:args ((= (bvumulo a b) c))
129+
:requires ((($bv_umulo_elim a b) c))
130+
:conclusion (= (bvumulo a b) c)
131+
)
132+
19133
;;;;; ProofRewriteRule::BV_BITWISE_SLICING
20134

21135
; program: $bv_mk_bitwise_slicing_rec

src/api/cpp/cvc5_proof_rule_template.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ const char* toString(cvc5::ProofRewriteRule rule)
286286
case ProofRewriteRule::DT_UPDATER_ELIM: return "dt-updater-elim";
287287
case ProofRewriteRule::DT_MATCH_ELIM: return "dt-match-elim";
288288
case ProofRewriteRule::MACRO_BV_EQ_SOLVE: return "macro-bv-eq-solve";
289-
case ProofRewriteRule::BV_UMULO_ELIMINATE: return "bv-umulo-eliminate";
290-
case ProofRewriteRule::BV_SMULO_ELIMINATE: return "bv-smulo-eliminate";
289+
case ProofRewriteRule::BV_UMULO_ELIM: return "bv-umulo-elim";
290+
case ProofRewriteRule::BV_SMULO_ELIM: return "bv-smulo-elim";
291291
case ProofRewriteRule::BV_ADD_COMBINE_LIKE_TERMS:
292292
return "bv-add-combine-like-terms";
293293
case ProofRewriteRule::BV_MULT_SIMPLIFY: return "bv-mult-simplify";

src/proof/alf/alf_printer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ bool AlfPrinter::isHandledTheoryRewrite(ProofRewriteRule id, const Node& n)
329329
case ProofRewriteRule::STR_REPLACE_RE_ALL_EVAL:
330330
case ProofRewriteRule::RE_INTER_INCLUSION:
331331
case ProofRewriteRule::RE_UNION_INCLUSION:
332+
case ProofRewriteRule::BV_SMULO_ELIM:
333+
case ProofRewriteRule::BV_UMULO_ELIM:
332334
case ProofRewriteRule::BV_REPEAT_ELIM:
333335
case ProofRewriteRule::BV_BITWISE_SLICING:
334336
case ProofRewriteRule::STR_OVERLAP_SPLIT_CTN:

src/theory/bv/theory_bv_rewriter.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,9 @@ TheoryBVRewriter::TheoryBVRewriter(NodeManager* nm) : TheoryRewriter(nm)
3434
initializeRewrites();
3535
registerProofRewriteRule(ProofRewriteRule::MACRO_BV_EQ_SOLVE,
3636
TheoryRewriteCtx::POST_DSL);
37-
registerProofRewriteRule(ProofRewriteRule::BV_UMULO_ELIMINATE,
37+
registerProofRewriteRule(ProofRewriteRule::BV_UMULO_ELIM,
3838
TheoryRewriteCtx::POST_DSL);
39-
registerProofRewriteRule(ProofRewriteRule::BV_SMULO_ELIMINATE,
40-
TheoryRewriteCtx::POST_DSL);
41-
registerProofRewriteRule(ProofRewriteRule::BV_ADD_COMBINE_LIKE_TERMS,
42-
TheoryRewriteCtx::POST_DSL);
43-
registerProofRewriteRule(ProofRewriteRule::BV_MULT_SIMPLIFY,
39+
registerProofRewriteRule(ProofRewriteRule::BV_SMULO_ELIM,
4440
TheoryRewriteCtx::POST_DSL);
4541
registerProofRewriteRule(ProofRewriteRule::BV_BITWISE_SLICING,
4642
TheoryRewriteCtx::POST_DSL);
@@ -101,13 +97,10 @@ Node TheoryBVRewriter::rewriteViaRule(ProofRewriteRule id, const Node& n)
10197
}
10298
}
10399
break;
104-
case ProofRewriteRule::BV_UMULO_ELIMINATE:
100+
case ProofRewriteRule::BV_UMULO_ELIM:
105101
BV_PROOF_REWRITE_CASE(UmuloEliminate)
106-
case ProofRewriteRule::BV_SMULO_ELIMINATE:
102+
case ProofRewriteRule::BV_SMULO_ELIM:
107103
BV_PROOF_REWRITE_CASE(SmuloEliminate)
108-
case ProofRewriteRule::BV_ADD_COMBINE_LIKE_TERMS:
109-
BV_PROOF_REWRITE_CASE(AddCombineLikeTerms)
110-
case ProofRewriteRule::BV_MULT_SIMPLIFY: BV_PROOF_REWRITE_CASE(MultSimplify)
111104
case ProofRewriteRule::BV_BITWISE_SLICING:
112105
BV_PROOF_REWRITE_CASE(BitwiseSlicing)
113106
case ProofRewriteRule::BV_REPEAT_ELIM:

0 commit comments

Comments
 (0)