Skip to content

Commit f77d2c8

Browse files
committed
Implement bv_poly_simp_eq
1 parent 3c377e4 commit f77d2c8

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

carcara/src/checker/rules/polynomial.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use super::{assert_clause_len, assert_eq, RuleArgs, RuleResult};
22
use crate::{
33
ast::{Operator, Rc, Sort, Term},
4-
checker::error::PolynomialError,
5-
checker::rules::{assert_num_premises, get_premise_term},
4+
checker::{
5+
error::PolynomialError,
6+
rules::{assert_is_expected, assert_num_premises, get_premise_term},
7+
},
68
};
79
use indexmap::{map::Entry, IndexMap};
810
use rug::{ops::NegAssign, Integer, Rational};
@@ -231,3 +233,27 @@ pub fn poly_simp_rel(RuleArgs { conclusion, premises, .. }: RuleArgs) -> RuleRes
231233
((op1, _), (op2, _)) => Err(PolynomialError::InvalidOperators(op1, op2).into()),
232234
}
233235
}
236+
237+
pub fn bv_poly_simp_eq(RuleArgs { conclusion, premises, pool, .. }: RuleArgs) -> RuleResult {
238+
assert_num_premises(premises, 1)?;
239+
assert_clause_len(conclusion, 1)?;
240+
241+
let ((c1, (x1, x2)), (c2, (y1, y2))) =
242+
match_term_err!((= (* c1 (- x1 x2)) (* c2 (- y1 y2))) = get_premise_term(&premises[0])?)?;
243+
244+
let sort = pool.sort(c1);
245+
let Sort::BitVec(width) = sort.as_sort().unwrap() else {
246+
unreachable!() // The parser ensures that the sort is a bitvector sort
247+
};
248+
let one = pool.add(Term::new_bv(Integer::from(1), *width));
249+
assert_is_expected(c1, one.clone())?;
250+
assert_is_expected(c2, one)?;
251+
252+
let ((l1, l2), (r1, r2)) = match_term_err!((= (= x1 x2) (= y1 y2)) = &conclusion[0])?;
253+
254+
assert_eq(l1, x1)?;
255+
assert_eq(l2, x2)?;
256+
assert_eq(r1, y1)?;
257+
assert_eq(r2, y2)?;
258+
Ok(())
259+
}

carcara/src/checker/shared.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ pub fn get_rule_shared(rule_name: &str, elaborated: bool) -> Option<crate::check
205205
"poly_simp" => polynomial::poly_simp,
206206
"bv_poly_simp" => polynomial::bv_poly_simp,
207207
"poly_simp_rel" => polynomial::poly_simp_rel,
208+
"bv_poly_simp_eq" => polynomial::bv_poly_simp_eq,
208209
"forall_inst" => quantifier::forall_inst,
209210
"qnt_join" => quantifier::qnt_join,
210211
"qnt_rm_unused" => quantifier::qnt_rm_unused,

0 commit comments

Comments
 (0)