コード例 #1
0
def check(p, tptp_properties, verbose=False):
    not_applicable = ""
    if (tptp_properties["vampire_axiom_clauses"] + tptp_properties["vampire_axiom_formulas"] +\
       tptp_properties["vampire_goal_clauses"] > MAX_SIZE) or tptp_properties["vampire_subformulas"] > 1000:
        not_applicable = "too large"
    if tptp_properties["vampire_equality_atoms"] > 0:
        not_applicable = "equality"
    print(p)
    sys.stdout.flush()
    res = {"error": not_applicable, "success": False}
    if not not_applicable:
        ofilename = "Problems/" + p[:3] + "/" + p + ".p"
        filename = "cnfs/" + p + ".p"
        content = data.get_problem(filename)
        if not content.strip():
            return {"error": "empty", "success": False}

        rf = open("boundedx.txt", "r")
        restrained_list = rf.read()

        formulas = tptp.parse_problem(content, verbose)
        print("parsed")
        fs = [c.formula for c in formulas]
        lss = [literals(c) for c in fs]
        strat = is_stratified(fs)
        res["is_epr0"] = tptp_properties["vampire_max_fun_arity"] == 0 and \
          tptp_properties["num_exists"] == 0 and tptp_properties["num_forall"] == 0
        res["is_epr"] = is_epr(fs)
        if res["is_epr"] and not strat:
            print("EPR but not stratified: " + p)
        if res["is_epr0"] and not res["is_epr"]:
            print("EPR0 but not EPR: " + p)
        res["is_guarded"] = is_guarded(lss)
        res["is_stratified"] = strat
        res["is_restrained"] = (p in restrained_list)
        res["success"] = strat
        res["is_pvd"] = is_pvd(lss)
        #res["is_pvd1"] = is_pvd1(lss)
        content = data.get_problem(ofilename)
        status = "% Status   : "
        sat = "SAT" if status + "Satisfiable" in content else \
          "UNSAT" if status + "Unsatisfiable" in content else \
          "THM" if status + "Theorem" in content else \
          "CSAT" if status + "CounterSatisfiable" in content else \
          "CAXS" if status + "ContradictoryAxioms" in content else "?"
        res["status"] = sat
        if strat:
            print(p + " " + sat)

    return res
コード例 #2
0
def check(p, tptp_properties, verbose=False):
    not_applicable = ""
    MAX_SIZE = 500
    in_cnf = tptp_properties["vampire_axiom_clauses"] > 0
    #if not in_cnf:
    #  not_applicable = "not in cnf"
    if tptp_properties["vampire_axiom_clauses"] > MAX_SIZE:
        not_applicable = "too large"
    elif tptp_properties["vampire_equality_atoms"] > 0:
        not_applicable = "equality"
    #print(p)
    res = {"error": not_applicable, "success": False}
    if not not_applicable:
        filename = "Problems/" + p[:
                                   3] + "/" + p + ".p" if in_cnf else "cnfs/" + p + ".p"
        content = data.get_problem(filename)
        if not content or "negated_conjecture, ($false))." in content:
            res = {"error": "empty", "success": False}
        elif len([l for l in content.splitlines() if "cnf(" in l]) > MAX_SIZE:
            res = {"error": "too large", "success": False}
        else:
            #print(p + ": " + filename)
            formulas = tptp.parse_problem(content, verbose)
            ((bndp, bndn), success, technique, guarded, pvd,
             strat), msg = check_ground(p, formulas)
            res["pos_bounded"] = bndp
            res["neg_bounded"] = bndn
            res["success"] = success
            res["is_guarded"] = guarded
            res["is_stratified"] = strat
            res["is_pvd"] = pvd
            res["technique"] = technique
            res["flipped"] = msg
            #if success:
            #  print("SUCCESS")
            # need original file for status
            filename = "Problems/" + p[:3] + "/" + p + ".p"
            content = data.get_problem(filename)
            res["status"] = "SAT" if "% Status   : Satisfiable" in content else \
              "UNSAT" if "% Status   : Unsatisfiable" in content else \
              "THM" if "% Status   : Theorem" in content else \
              "CSAT" if "% Status   : CounterSatisfiable" in content else "UNK"

    return res
コード例 #3
0
    cts = cyclic_types(tvisitor.types)
    cs2 = []
    svisitor = SortRefinementVisitor(cts, tvisitor)
    for c in cs:
        c.accept(svisitor)
        c2 = c.get_cyclic_parts()
        cs2 = cs2 + [c2] if c2 else cs2
    return cs2


if __name__ == "__main__":
    p = sys.argv[1]
    #print(p)
    #filename = "Problems/" + p[:3] + "/" + p + ".p"
    content = data.get_problem(p)
    cs = [c.formula for c in tptp.parse_problem(content, False)]
    print("stratified: %r " % is_stratified(cs))


def is_guarded(lss):
    def is_weakly_covering(l):
        # every functional subterm of literal l contains all variables in l
        vs = l.vars()
        ts = l.subterms()
        return forall(
            lambda t: vars(t) == vs
            if not t.is_var() and len(t.args) > 0 else True, ts)

    def vardepth1(l):
        ts = l.args if isinstance(l, expr.Pred) else l.arg.args
        return forall(lambda v: isinstance(v, expr.Var) or len(v.vars()) == 0,
コード例 #4
0
ファイル: data.py プロジェクト: bytekid/koala
def compute_properties(p, tptp_properties, verbose = False):
  start = time.time()
  formulas = tptp.parse_problem(p, verbose)
  parse_time = (time.time() - start)
  start = time.time()
  log = ""
  properties = {}
  #print(properties)

  def property(key):
     return tptp_properties[key] if key in tptp_properties else None
  
  # sanity check: compare with TPTP comments
  def compare(counted, in_tptp, what):
    if verbose or (counted != in_tptp and in_tptp != None):
      return ("  " + str(counted) + " (vs " + str(in_tptp) + ") " + what + "\n")
    return ""
 
  cnfs = [f.formula for f in formulas if isinstance(f,Cnf)]
  fofs = [f.formula for f in formulas if isinstance(f,Fof)]
  tffs = [f.formula for f in formulas if isinstance(f,Tff)] # no type formulas
  all = cnfs + fofs + tffs

  properties = tptp_properties.copy()

  ### count clauses/formulas (only one property)
  if "num_formulae" in tptp_properties:
    num_p = tptp_properties["num_formulae"]
    log = log + compare(len(fofs + tffs), num_p, "formulae")
    properties["num_formulae"] = len(all)
  if "num_clauses" in tptp_properties:
    num_p = tptp_properties["num_clauses"]
    log = log + compare(len(cnfs), num_p, "clauses ")
    del properties["num_clauses"]
    properties["num_formulae"] = len(all)

  ### count predicates
  visitor = BooleanVisitor()
  for f in all:
    f.accept(visitor)
  log = log + compare(visitor.count(), property("num_atoms"), "atoms")
  properties["num_atoms"] = visitor.count()
  log = log + compare(visitor.predicate_count(), property("num_predicates"), "predicates")
  properties["num_predicates"] = visitor.predicate_count()
  log = log + compare(visitor.predicate_count(), property("num_equality"), "equalities")
  properties["num_equalities"] = visitor.equality_count()

  num_unit = len([u for u in all if not(isinstance(u, TypeExpr)) and u.is_literal()])
  tptp_unit = property("num_unit")
  if not tptp_unit:
    tptp_unit = property("num_unit_clauses")
  log = log + compare(num_unit, tptp_unit, "units")
  properties["num_units"] = num_unit
  properties["is_UEQ"] = 1 if num_unit == len(all) else 0

  log = log + compare(visitor.connective_count(), property("num_connectives"), "connectives")
  properties["num_connectives"] = visitor.connective_count()
  log = log + compare(visitor.num_not, property("num_not"), "nots")
  properties["num_not"] = visitor.num_not
  log = log + compare(visitor.binops["&"], property("num_&"), "ands")
  properties["num_&"] = visitor.binops["&"]

  log = log + compare(visitor.binops["|"], property("num_|"), "ors")
  properties["num_|"] = visitor.binops["|"]

  log = log + compare(visitor.binops["~&"], property("num_~&"), "nands")
  properties["num_~&"] = visitor.binops["~&"]
  
  log = log + compare(visitor.binops["~|"], property("num_~|"), "nors")
  properties["num_~|"] = visitor.binops["~|"]

  log = log + compare(visitor.binops["<=>"], property("num_<=>"), "iffs")
  properties["num_<=>"] = visitor.binops["<=>"]

  log = log + compare(visitor.binops["=>"], property("num_=>"), "implies")
  properties["num_=>"] = visitor.binops["=>"]
  
  log = log + compare(visitor.binops["<="], property("num_<="), "implies left")
  properties["num_<="] = visitor.binops["<="]

  log = log + compare(visitor.binops["<~>"], property("num_<~>"), "niffs")
  properties["num_<~>"] = visitor.binops["<~>"]

  ### count variables
  visitor = VarCountVisitor()
  for f in all:
    f.accept(visitor)
    visitor.nextFormula()
  log = log + compare(visitor.var_count, property("num_variables"), "variables")
  properties["num_variables"] = visitor.var_count
  log = log + compare(visitor.forall_count, property("num_forall"), "universal variables")
  properties["num_forall"] = visitor.forall_count
  log = log + compare(visitor.exists_count, property("num_exists"), "existential variables")
  properties["num_exists"] = visitor.exists_count

  ### count function symbols
  fvisitor = FunCountVisitor()
  for f in all:
    f.accept(fvisitor)
  n = property("num_functions")
  log = log + compare(fvisitor.count(), n, "function symbols")
  properties["num_functions"] = fvisitor.count()
  c = property("num_constants")
  log = log + compare(fvisitor.countConsts(), c, "constants")
  properties["num_constants"] = fvisitor.countConsts()

  #print("before unification")
  ### count unifiable positive and negative literals (not counting equality)
  vis = LiteralVisitor()
  for f in all:
    vis.visit(f)
  ps, ns = vis.non_eq_atoms()
  ps = [p.rename() for p in ps]
  idx = FingerprintIndex.make(ns, len(all), properties["is_EPR"])
  unifs = 0
  if len(all) < 10000:
    for p in ps:
      unifs = unifs + len(idx.unifiables(p))
  else:
    unifs = vis.pred_unifiables_approximation()
  properties["num_unifiable_pos_neg"] = unifs
  #print("after unification (1)")

  eqs, _ = vis.eq_atoms()
  # collect non-variable terms on one side of equation
  # TODO: take orientability into account?
  if eqs:
    terms = []
    lhss = []
    for e in eqs:
      lhs, rhs = e.args
      if is_rewrite_rule((lhs, rhs)):
        lhss.append(lhs)
      elif isinstance(lhs, Fun):
        terms.append(lhs)
      if is_rewrite_rule((rhs, lhs)):
        lhss.append(rhs)
      elif isinstance(rhs, Fun):
        terms.append(rhs)
    if len(all) < 10000:
      rew_visitor = RewriteVisitor(lhss, terms, len(all), properties["is_EPR"])
      for f in all:
        f.accept(rew_visitor)
      properties["num_match_eq"] = rew_visitor.match_count
      properties["num_unif_eq"] = rew_visitor.unif_count
    else: # very large, approximate by counting root symbol occurrences
      unifs = 0
      for t in terms:
        root = t.name
        unifs = unifs + fvisitor.occurrence_count(root)
      properties["num_match_eq"] = unifs
      properties["num_unif_eq"] = unifs
  else:
    properties["num_match_eq"] = 0
    properties["num_unif_eq"] = 0
  #print("after unification (2)")
  
  # formula/term depth
  if not("max_formula_depth" in properties and "avg_formula_depth" in properties):
    (af, at, mf, mt) = get_depths(all)
    properties["avg_formula_depth"] = af
    properties["avg_term_depth"] = at
    properties["max_formula_depth"] = mf
    properties["max_term_depth"] = mt

  analysis_time = (time.time() - start)
  return (properties, log, parse_time, analysis_time)
コード例 #5
0
ファイル: all_properties.py プロジェクト: bytekid/koala
def check(p, props, verbose = False):
  not_applicable = ""
  MAX_SIZE = 500
  in_cnf = props["vampire_axiom_clauses"] > 0
  if props["vampire_axiom_clauses"] > MAX_SIZE:
    not_applicable = "too large"
  elif props["vampire_equality_atoms"] > 0:
    not_applicable = "equality"
  elif props["num_type_connectives"] > 0:
    not_applicable = "type connectives"
  res = {"error": not_applicable, "success": False}
  if not not_applicable:
    filename = "Problems/" + p[:3] + "/" + p + ".p" if in_cnf else "cnfs/" + p + ".p"
    content = data.get_problem(filename)
    if len([l for l in content.splitlines() if "cnf(" in l]) > MAX_SIZE:
      res = {"error": "too large", "success": False}
    else:
      try:
        formulas = tptp.parse_problem(content, verbose)
        ((bndp, bndn), success, technique), msg = check_ground(p, formulas)
        fs = [c.formula for c in formulas]
        lss = [literals(c) for c in fs] 
        res["pos_restrained"] = bndp
        res["neg_restrained"] = bndn
        res["is_restrained"] = bndp or bndn
        res["success"] = success
        res["is_guarded"] = is_guarded(lss)
        res["is_stratified"] = is_stratified(fs)
        res["is_ackermann"] = is_ackermann(lss)
        res["is_pvd_restrained_splittable"] = is_pvd_restrained_splittable(fs)
        res["is_pvd"] = is_pvd(lss)
        res["technique"] = technique
        res["flipped"] = msg
        res["is_ground"] = props["num_variables"] == 0
        res["is_epr"] = is_epr(fs)
        res["is_monadic"] = props["vampire_max_pred_arity"] <= 1
        res["is_2var"] = props["vampire_max_variables_in_clause"] <= 2 and props["vampire_max_fun_arity"] <= 0
        (pos_horn, pos_contr), (neg_horn, neg_contr) = is_controlled(p, formulas)
        res["is_pos_horn"] = pos_horn
        res["is_neg_horn"] = neg_horn
        res["is_horn"] = neg_horn or pos_horn
        res["is_pos_controlled"] = pos_contr
        res["is_neg_controlled"] = neg_contr
        res["is_controlled"] = neg_contr or pos_contr
        if res["is_pvd_restrained_splittable"]  and not (res["is_pvd"] or res["is_restrained"]):
          print (" SPLITTING advantage")
        if res["is_stratified"]:
          res["is_sort_pvd"] = True
          res["is_sort_restrained"] = True
        else:
          non_strat = non_stratified_part(fs)
          if res["is_restrained"]:
            res["is_sort_restrained"] = True
          else:
            non_strat_cnf = [Cnf("x", 0, f) for f in non_strat]
            ((bndp, bndn), success2, _), _ = check_ground(p, non_strat_cnf, mode="sort-restrained")
            res["is_sort_restrained"] = success2
          if res["is_pvd"]:
            res["is_sort_pvd"] = True
          else:
            res["is_sort_pvd"] = is_pvd([literals(c) for c in non_strat])
        koala_out = "sggsruns/" + p + ".txt"
        if os.path.exists(koala_out):
          res["koala stats"] = problem_stats(koala_out)
        else:
          res["koala stats"] = None
      except ParseException:
        res = {"error": "parse error", "success": False}
        print("parse error on " + p)
      # need original file for status
      filename = "Problems/" + p[:3] + "/" + p + ".p"
      content = data.get_problem(filename)
      res["status"] = "SAT" if "% Status   : Satisfiable" in content else \
        "UNSAT" if "% Status   : Unsatisfiable" in content else \
        "THM" if "% Status   : Theorem" in content else \
        "CSAT" if "% Status   : CounterSatisfiable" in content else "UNK"
      res["rating"] = props["rating"]

  return res