From e928466be829eb7410cf07525a058df29a55a31a Mon Sep 17 00:00:00 2001 From: Tim Beurskens Date: Thu, 19 Dec 2024 13:28:18 +0100 Subject: [PATCH 1/8] prevent suffix for `Real` --- smtlib/src/sorts.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/smtlib/src/sorts.rs b/smtlib/src/sorts.rs index 1d16b46..a17939b 100644 --- a/smtlib/src/sorts.rs +++ b/smtlib/src/sorts.rs @@ -55,7 +55,7 @@ impl Index { pub(crate) fn is_built_in_sort(name: &str) -> bool { match name { - "Int" | "Bool" => true, + "Int" | "Bool" | "Real" => true, _ => false, } } @@ -63,10 +63,6 @@ pub(crate) fn is_built_in_sort(name: &str) -> bool { impl Sort { pub fn new(name: impl Into) -> Self { let mut name = name.into(); - if !is_built_in_sort(&name) { - // HACK: how should we handle this? or should we event handle it? - name += "_xxx"; - } Self { name, index: Vec::new(), From 60ca43afbc47c31e462a755593c0a8ed62a0ab1c Mon Sep 17 00:00:00 2001 From: Tim Beurskens Date: Thu, 19 Dec 2024 13:37:36 +0100 Subject: [PATCH 2/8] add commands from maximal satisfaction paper --- lowlevel/src/ast.rs | 48 +++++++++++++++++++++++++++++++++++++++++++++ xtask/src/spec.toml | 13 ++++++++++++ 2 files changed, 61 insertions(+) diff --git a/lowlevel/src/ast.rs b/lowlevel/src/ast.rs index 86b353c..4fdfa83 100644 --- a/lowlevel/src/ast.rs +++ b/lowlevel/src/ast.rs @@ -1406,6 +1406,12 @@ pub enum Command { SetOption(Option), /// `(simplify )` Simplify(Term), + /// `(maximize )` + Maximize(Term), + /// `(minimize )` + Minimize(Term), + /// `(assert-soft )` + AssertSoft(Term), } impl std::fmt::Display for Command { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { @@ -1459,6 +1465,9 @@ impl std::fmt::Display for Command { Self::SetLogic(m0) => write!(f, "(set-logic {})", m0), Self::SetOption(m0) => write!(f, "(set-option {})", m0), Self::Simplify(m0) => write!(f, "(simplify {})", m0), + Self::Maximize(m0) => write!(f, "(maximize {})", m0), + Self::Minimize(m0) => write!(f, "(minimize {})", m0), + Self::AssertSoft(m0) => write!(f, "(assert-soft {})", m0), } } } @@ -1485,6 +1494,12 @@ impl SmtlibParse for Command { || (p.nth(offset) == Token::LParen && p.nth_matches(offset + 1, Token::Reserved, "check-sat-assuming") && p.nth(offset + 2) == Token::LParen) + || (p.nth(offset) == Token::LParen + && p.nth_matches(offset + 1, Token::Symbol, "assert-soft")) + || (p.nth(offset) == Token::LParen + && p.nth_matches(offset + 1, Token::Symbol, "minimize")) + || (p.nth(offset) == Token::LParen + && p.nth_matches(offset + 1, Token::Symbol, "maximize")) || (p.nth(offset) == Token::LParen && p.nth_matches(offset + 1, Token::Symbol, "simplify")) || (p.nth(offset) == Token::LParen @@ -1633,6 +1648,33 @@ impl SmtlibParse for Command { #[allow(clippy::useless_conversion)] return Ok(Self::CheckSatAssuming(m0.into())); } + if p.nth(offset) == Token::LParen + && p.nth_matches(offset + 1, Token::Symbol, "assert-soft") + { + p.expect(Token::LParen)?; + p.expect_matches(Token::Symbol, "assert-soft")?; + let m0 = ::parse(p)?; + p.expect(Token::RParen)?; + #[allow(clippy::useless_conversion)] return Ok(Self::AssertSoft(m0.into())); + } + if p.nth(offset) == Token::LParen + && p.nth_matches(offset + 1, Token::Symbol, "minimize") + { + p.expect(Token::LParen)?; + p.expect_matches(Token::Symbol, "minimize")?; + let m0 = ::parse(p)?; + p.expect(Token::RParen)?; + #[allow(clippy::useless_conversion)] return Ok(Self::Minimize(m0.into())); + } + if p.nth(offset) == Token::LParen + && p.nth_matches(offset + 1, Token::Symbol, "maximize") + { + p.expect(Token::LParen)?; + p.expect_matches(Token::Symbol, "maximize")?; + let m0 = ::parse(p)?; + p.expect(Token::RParen)?; + #[allow(clippy::useless_conversion)] return Ok(Self::Maximize(m0.into())); + } if p.nth(offset) == Token::LParen && p.nth_matches(offset + 1, Token::Symbol, "simplify") { @@ -1902,6 +1944,9 @@ impl Command { Self::SetLogic(_) => false, Self::SetOption(_) => false, Self::Simplify(_) => true, + Self::Maximize(_) => false, + Self::Minimize(_) => false, + Self::AssertSoft(_) => false, } } pub fn parse_response( @@ -2044,6 +2089,9 @@ impl Command { ), ) } + Self::Maximize(_) => Ok(None), + Self::Minimize(_) => Ok(None), + Self::AssertSoft(_) => Ok(None), } } } diff --git a/xtask/src/spec.toml b/xtask/src/spec.toml index 5774fde..a6d1a9a 100644 --- a/xtask/src/spec.toml +++ b/xtask/src/spec.toml @@ -263,6 +263,19 @@ syntax = "( set-option