Enable post-condition strenghtening by default for non-syntax restricted invariant...
authorAndrew Reynolds <andrew.j.reynolds@gmail.com>
Fri, 23 Mar 2018 17:20:23 +0000 (12:20 -0500)
committerGitHub <noreply@github.com>
Fri, 23 Mar 2018 17:20:23 +0000 (12:20 -0500)
src/options/quantifiers_options.toml
src/theory/quantifiers/sygus/ce_guided_single_inv.cpp
src/theory/quantifiers/sygus/sygus_grammar_cons.cpp
src/theory/quantifiers/sygus/sygus_grammar_cons.h

index 8f07384d641469aaf47c12e0e96845fe88c40cf4..ab74fbc79a66048f4bc48adefb6fc0858cce855e 100644 (file)
@@ -1017,11 +1017,20 @@ header = "options/quantifiers_options.h"
   category   = "regular"
   long       = "sygus-inv-templ=MODE"
   type       = "CVC4::theory::quantifiers::SygusInvTemplMode"
-  default    = "CVC4::theory::quantifiers::SYGUS_INV_TEMPL_MODE_NONE"
+  default    = "CVC4::theory::quantifiers::SYGUS_INV_TEMPL_MODE_POST"
   handler    = "stringToSygusInvTemplMode"
   includes   = ["options/quantifiers_modes.h"]
   read_only  = true
-  help       = "template mode for sygus invariant synthesis"
+  help       = "template mode for sygus invariant synthesis (weaken pre-condition, strengthen post-condition, or none)"
+
+[[option]]
+  name       = "sygusInvTemplWhenSyntax"
+  category   = "regular"
+  long       = "sygus-inv-templ-when-sg"
+  type       = "bool"
+  default    = "false"
+  read_only  = false
+  help       = "use invariant templates (with solution reconstruction) for syntax guided problems"
 
 [[option]]
   name       = "sygusInvAutoUnfold"
index d59f1f37088cfdc4454e296a9975b99b1cecc838..a951ec867cb2564f471fbed2909c1872cc209127 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "options/quantifiers_options.h"
 #include "theory/arith/arith_msum.h"
+#include "theory/quantifiers/sygus/sygus_grammar_cons.h"
 #include "theory/quantifiers/term_enumeration.h"
 #include "theory/quantifiers/term_util.h"
 
@@ -154,7 +155,26 @@ void CegConjectureSingleInv::initialize( Node q ) {
       //check if it is single invocation
       if (!d_sip->isPurelySingleInvocation())
       {
-        if( options::sygusInvTemplMode() != SYGUS_INV_TEMPL_MODE_NONE ){
+        SygusInvTemplMode tmode = options::sygusInvTemplMode();
+        if (tmode != SYGUS_INV_TEMPL_MODE_NONE)
+        {
+          // currently only works for single predicate synthesis
+          if (q[0].getNumChildren() > 1 || !q[0][0].getType().isPredicate())
+          {
+            tmode = SYGUS_INV_TEMPL_MODE_NONE;
+          }
+          else if (!options::sygusInvTemplWhenSyntax())
+          {
+            // only use invariant templates if no syntactic restrictions
+            if (CegGrammarConstructor::hasSyntaxRestrictions(q))
+            {
+              tmode = SYGUS_INV_TEMPL_MODE_NONE;
+            }
+          }
+        }
+
+        if (tmode != SYGUS_INV_TEMPL_MODE_NONE)
+        {
           //if we are doing invariant templates, then construct the template
           Trace("cegqi-si") << "- Do transition inference..." << std::endl;
           d_ti[q].process( qq );
@@ -234,12 +254,15 @@ void CegConjectureSingleInv::initialize( Node q ) {
                 }
               }
             }
+            Trace("cegqi-inv") << "Make the template... " << tmode << " "
+                               << templ << std::endl;
             if( templ.isNull() ){
-              if( options::sygusInvTemplMode() == SYGUS_INV_TEMPL_MODE_PRE ){
+              if (tmode == SYGUS_INV_TEMPL_MODE_PRE)
+              {
                 //d_templ[prog] = NodeManager::currentNM()->mkNode( AND, NodeManager::currentNM()->mkNode( OR, d_trans_pre[prog], invariant ), d_trans_post[prog] );
                 templ = NodeManager::currentNM()->mkNode( OR, d_trans_pre[prog], d_templ_arg[prog] );
               }else{
-                Assert( options::sygusInvTemplMode() == SYGUS_INV_TEMPL_MODE_POST );
+                Assert(tmode == SYGUS_INV_TEMPL_MODE_POST);
                 //d_templ[prog] = NodeManager::currentNM()->mkNode( OR, d_trans_pre[prog], NodeManager::currentNM()->mkNode( AND, d_trans_post[prog], invariant ) );
                 templ = NodeManager::currentNM()->mkNode( AND, d_trans_post[prog], d_templ_arg[prog] );
               }
index 1ca774c5d76fa155c85ff1876c7366ff060595e2..08b0dc8377c6393b6b24310eaac15502f12e37d8 100644 (file)
@@ -36,6 +36,25 @@ CegGrammarConstructor::CegGrammarConstructor(QuantifiersEngine* qe,
 {
 }
 
+bool CegGrammarConstructor::hasSyntaxRestrictions(Node q)
+{
+  Assert(q.getKind() == FORALL);
+  for (const Node& f : q[0])
+  {
+    Node gv = f.getAttribute(SygusSynthGrammarAttribute());
+    if (!gv.isNull())
+    {
+      TypeNode tn = gv.getType();
+      if (tn.isDatatype()
+          && static_cast<DatatypeType>(tn.toType()).getDatatype().isSygus())
+      {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
 void CegGrammarConstructor::collectTerms( Node n, std::map< TypeNode, std::vector< Node > >& consts ){
   std::unordered_map<TNode, bool, TNodeHashFunction> visited;
   std::unordered_map<TNode, bool, TNodeHashFunction>::iterator it;
index 4e486f88fc46e52f4e262c5e48d15fbec2c7220b..d8a77848bf2ce66f91066f982c3d22f21e3dd980 100644 (file)
@@ -83,7 +83,13 @@ public:
   *   fun is for naming
   */
   static TypeNode mkSygusTemplateType( Node templ, Node templ_arg, TypeNode templ_arg_sygus_type, Node bvl, const std::string& fun );
-private:
+  /**
+   * Returns true iff there are syntax restrictions on the
+   * functions-to-synthesize of sygus conjecture q.
+   */
+  static bool hasSyntaxRestrictions(Node q);
+
+ private:
   /** reference to quantifier engine */
   QuantifiersEngine * d_qe;
   /** parent conjecture