Skip to content

Commit fe16fb5

Browse files
committed
print prettier SymbolicComplex
1 parent ca22ff8 commit fe16fb5

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

include/autoq/complex/symbolic_complex.hh

+7-3
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,13 @@ struct AUTOQ::Complex::SymbolicComplex : std::map<Term, Complex> {
124124
for (const auto &tc : static_cast<std::map<Term, Complex>>(obj)) {
125125
if (tc.second.isZero()) continue;
126126
if (!isFirst) os << " + ";
127-
os << tc.second;
128-
if (!tc.first.empty())
129-
os << " * " << tc.first;
127+
if (tc.second != Complex(1) || tc.first.empty())
128+
os << tc.second;
129+
if (!tc.first.empty()) {
130+
if (tc.second != Complex(1))
131+
os << " * ";
132+
os << tc.first;
133+
}
130134
isFirst = false;
131135
}
132136
if (obj.empty()) os << "0";

src/inclusion.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,9 @@ bool AUTOQ::Automata<AUTOQ::Symbol::Concrete>::operator<=(const Automata<AUTOQ::
379379
}
380380

381381
template <typename Symbol>
382-
bool AUTOQ::Automata<Symbol>::operator<=(const Automata<Symbol> &autB) const {}
382+
bool AUTOQ::Automata<Symbol>::operator<=(const Automata<Symbol> &) const {
383+
THROW_AUTOQ_ERROR("The operator <= is not defined for the given type of automata.");
384+
}
383385

384386
bool AUTOQ::check_validity(Constraint C, const PredicateAutomata::Symbol &ps, const SymbolicAutomata::Symbol &te) {
385387
std::string str(ps);

src/timbuk_serializer.cc

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*****************************************************************************/
1010

1111
// AUTOQ headers
12+
#include <regex>
1213
#include "autoq/error.hh"
1314
#include "autoq/aut_description.hh"
1415
#include "autoq/symbol/concrete.hh"
@@ -77,9 +78,12 @@ std::string TimbukSerializer::Serialize(Automata<Symbol> desc)
7778
if (it == leafMap.end()) {
7879
if constexpr(std::is_same_v<Symbol, AUTOQ::Symbol::Concrete>)
7980
result += "c" + std::to_string(leafMap.size()) + " := " + Convert::ToString(sym) + "\n";
80-
else if constexpr(std::is_same_v<Symbol, AUTOQ::Symbol::Symbolic>)
81-
result += "e" + std::to_string(leafMap.size()) + " := " + Convert::ToString(sym) + "\n";
82-
else if constexpr(std::is_same_v<Symbol, AUTOQ::Symbol::Predicate>)
81+
else if constexpr(std::is_same_v<Symbol, AUTOQ::Symbol::Symbolic>) {
82+
auto str = Convert::ToString(sym);
83+
str = std::regex_replace(str, std::regex(R"(([^ ]+)R)"), "real($1)");
84+
str = std::regex_replace(str, std::regex(R"(([^ ]+)I)"), "imag($1)");
85+
result += "e" + std::to_string(leafMap.size()) + " := " + str + "\n";
86+
} else if constexpr(std::is_same_v<Symbol, AUTOQ::Symbol::Predicate>)
8387
result += "p" + std::to_string(leafMap.size()) + " := " + Convert::ToString(sym) + "\n";
8488
leafMap[sym] = leafMap.size();
8589
}

0 commit comments

Comments
 (0)