-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLibBoolEE.h
More file actions
65 lines (51 loc) · 3 KB
/
LibBoolEE.h
File metadata and controls
65 lines (51 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef LIBBOOLEE_H
#define LIBBOOLEE_H
/******************************************************************************
Created by Adam Streck, 2016, adam.streck@gmail.com
This file is part of the LibBoolEE library.
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU lesser General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Class able to resolve any logical function in propositional logic.
///
/// This is a static helper class able of resolving any preposition logic formula.
/// Formula construction:
/// -# \f$tt\f$ (true) and \f$ff\f$ (false) are formulas representing true and false respectively,
/// -# any variable is a formula,
/// -# for \f$\varphi\f$ formula is \f$!\varphi\f$ formula,
/// -# for \f$\psi, \varphi\f$ formulas are \f$(\psi|\varphi)\f$, \f$(\psi\&\varphi)\f$ formulas representing logical disjunction and conjunction respectively,
/// -# nothing else is a formula,
/// -# whitespaces are ignored.
///
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <map>
#include <string>
#include <vector>
#include <utility>
#include <stdexcept>
class LibBoolEE {
public:
typedef std::map<std::string, bool> Vals; ///< Valuation of atomic propositions
typedef std::pair<std::string, bool> Val; ///< A single proposition valuation
// @return true iff the formula is true under the valuation (where the valuation are pairs (variable,value))
static bool resolve(const std::string & source, const Vals & valuation);
private:
static std::vector<std::string> singleParse(const std::string & formula, const char op);
// @return true iff ch is possibly part of a valid name
static bool belongsToName(const char ch);
// @return true iff the formula is true under the valuation (where the valuation are pairs (variable,value))---used internally
static bool resolveRec(const std::string & source, const Vals & valuation);
// @return new string made from the source by removing the leading and trailing white spaces
static std::string trim(const std::string & source);
// @return new string made from the source by removing whitespaces
static std::string removeWhitespaces(const std::string & source);
};
#endif