carl  24.04
Computer ARithmetic Library
symmetry.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <vector>
6 
7 namespace carl {
8 namespace formula {
9 
10 /**
11  * A symmetry \f$\sigma\f$ represents a bijection on a set of variables.
12  * For every entry in the vector we have \f$\sigma(e.first) = e.second\f$.
13  */
14 using Symmetry = std::vector<std::pair<Variable,Variable>>;
15 
16 /**
17  * Represents a list of symmetries.
18  */
19 using Symmetries = std::vector<Symmetry>;
20 
21 }
22 }
23 
24 #ifdef USE_BLISS
25 
26 #include "SymmetryFinder.h"
27 #include "SymmetryBreaker.h"
28 
29 namespace carl {
30 namespace formula {
31 
32 /**
33  * Find syntactic symmetries in the given formula.
34  * Builds a graph that syntactically represents the formula and find automorphisms on its vertices.
35  */
36 template<typename Poly>
37 Symmetries findSymmetries(const Formula<Poly>& f) {
38  symmetry::GraphBuilder<Poly> g(f);
39  return g.symmetries();
40 }
41 
42 /// Construct symmetry breaking formulae for the given symmetries.
43 template<typename Poly>
44 Formula<Poly> breakSymmetries(const Symmetries& symmetries, bool onlyFirst = true) {
45  Formulas<Poly> res;
46  for (const auto& s: symmetries) {
47  res.emplace_back(symmetry::lexLeaderConstraint<Poly>(s));
48  if (onlyFirst) return res.back();
49  }
50  return Formula<Poly>(FormulaType::AND, std::move(res));
51 }
52 
53 /// Construct symmetry breaking formulae for symmtries from the given formula.
54 template<typename Poly>
55 Formula<Poly> breakSymmetries(const Formula<Poly>& f, bool onlyFirst = true) {
56  return breakSymmetries<Poly>(findSymmetries(f), onlyFirst);
57 }
58 
59 }
60 }
61 
62 #else
63 
64 namespace carl {
65 namespace formula {
66 
67 template<typename Poly>
69  return Symmetries();
70 }
71 
72 template<typename Poly>
73 Formula<Poly> breakSymmetries(const Symmetries& symmetries, bool onlyFirst = true) {
75 }
76 
77 template<typename Poly>
78 Formula<Poly> breakSymmetries(const Formula<Poly>& f, bool onlyFirst = true) {
80 }
81 
82 }
83 }
84 
85 
86 #endif
carl is the main namespace for the library.
std::vector< std::pair< Variable, Variable > > Symmetry
A symmetry represents a bijection on a set of variables.
Definition: symmetry.h:14
Symmetries findSymmetries(const Formula< Poly > &f)
Definition: symmetry.h:68
std::vector< Symmetry > Symmetries
Represents a list of symmetries.
Definition: symmetry.h:19
Formula< Poly > breakSymmetries(const Symmetries &symmetries, bool onlyFirst=true)
Definition: symmetry.h:73
const Formula & back() const
Definition: Formula.h:518