GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/expr/subs.h Lines: 1 1 100.0 %
Date: 2021-11-07 Branches: 1 2 50.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8
 * in the top-level source directory and their institutional affiliations.
9
 * All rights reserved.  See the file COPYING in the top-level source
10
 * directory for licensing information.
11
 * ****************************************************************************
12
 *
13
 * Simple substitution utility.
14
 */
15
16
#ifndef CVC5__EXPR__SUBS_H
17
#define CVC5__EXPR__SUBS_H
18
19
#include <map>
20
#include <optional>
21
#include <vector>
22
23
#include "expr/node.h"
24
25
namespace cvc5 {
26
27
/**
28
 * Helper substitution class. Stores a substitution in parallel vectors
29
 * d_vars and d_subs, both of which may be arbitrary terms, having the same
30
 * types pairwise.
31
 *
32
 * Notice this class applies substitutions using Node::substitute. Furthermore,
33
 * it does not insist that the terms in d_vars are unique.
34
 */
35
34557
class Subs
36
{
37
 public:
38
  /** Is the substitution empty? */
39
  bool empty() const;
40
  /** The size of the substitution */
41
  size_t size() const;
42
  /** Does the substitution contain v? */
43
  bool contains(Node v) const;
44
  /** Get the substitution for v if it exists, or null otherwise */
45
  Node getSubs(Node v) const;
46
  /** Find the substitution for v, or return std::nullopt */
47
  std::optional<Node> find(TNode v) const;
48
  /** Add v -> k for fresh skolem of the same type as v */
49
  void add(Node v);
50
  /** Add v -> k for fresh skolem of the same type as v for each v in vs */
51
  void add(const std::vector<Node>& vs);
52
  /** Add v -> s to the substitution */
53
  void add(Node v, Node s);
54
  /** Add vs -> ss to the substitution */
55
  void add(const std::vector<Node>& vs, const std::vector<Node>& ss);
56
  /** Add eq[0] -> eq[1] to the substitution */
57
  void addEquality(Node eq);
58
  /** Append the substitution s to this */
59
  void append(Subs& s);
60
  /** Return the result of this substitution on n */
61
  Node apply(Node n, bool doRewrite = false) const;
62
  /** Return the result of the reverse of this substitution on n */
63
  Node rapply(Node n, bool doRewrite = false) const;
64
  /** Apply this substitution to all nodes in the range of s */
65
  void applyToRange(Subs& s, bool doRewrite = false) const;
66
  /** Apply the reverse of this substitution to all nodes in the range of s */
67
  void rapplyToRange(Subs& s, bool doRewrite = false) const;
68
  /** Get equality (= v s) where v -> s is the i^th position in the vectors */
69
  Node getEquality(size_t i) const;
70
  /** Convert substitution to map */
71
  std::map<Node, Node> toMap() const;
72
  /** Get string for this substitution */
73
  std::string toString() const;
74
  /** clear the substitution */
75
  void clear();
76
  /** The data */
77
  std::vector<Node> d_vars;
78
  std::vector<Node> d_subs;
79
};
80
81
/**
82
 * Serializes a given substitution to the given stream.
83
 *
84
 * @param out the output stream to use
85
 * @param s the substitution to output to the stream
86
 * @return the stream
87
 */
88
std::ostream& operator<<(std::ostream& out, const Subs& s);
89
90
}  // namespace cvc5
91
92
#endif /* CVC5__EXPR__SUBS_H */