blob: 44f5d60a62f673536c9af9987836d84cb309ef7a (
plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
/********************* */
/*! \file theory_bool.cpp
** \verbatim
** Original author: mdeters
** Major contributors: none
** Minor contributors (to current version): none
** This file is part of the CVC4 prototype.
** Copyright (c) 2009, 2010 The Analysis of Computer Systems Group (ACSys)
** Courant Institute of Mathematical Sciences
** New York University
** See the file COPYING in the top-level source directory for licensing
** information.\endverbatim
**
** \brief The theory of booleans.
**
** The theory of booleans.
**/
#include "theory/theory.h"
#include "theory/booleans/theory_bool.h"
#include "theory/valuation.h"
namespace CVC4 {
namespace theory {
namespace booleans {
Node TheoryBool::getValue(TNode n, Valuation* valuation) {
NodeManager* nodeManager = NodeManager::currentNM();
switch(n.getKind()) {
case kind::VARIABLE:
// case for Boolean vars is implemented in TheoryEngine (since it
// appeals to the PropEngine to get the value)
Unreachable();
case kind::EQUAL: // 2 args
// should be handled by IFF
Unreachable();
case kind::NOT: // 1 arg
return nodeManager->mkConst(! valuation->getValue(n[0]).getConst<bool>());
case kind::AND: { // 2+ args
for(TNode::iterator i = n.begin(),
iend = n.end();
i != iend;
++i) {
if(! valuation->getValue(*i).getConst<bool>()) {
return nodeManager->mkConst(false);
}
}
return nodeManager->mkConst(true);
}
case kind::IFF: // 2 args
return nodeManager->mkConst( valuation->getValue(n[0]).getConst<bool>() ==
valuation->getValue(n[1]).getConst<bool>() );
case kind::IMPLIES: // 2 args
return nodeManager->mkConst( (! valuation->getValue(n[0]).getConst<bool>()) ||
valuation->getValue(n[1]).getConst<bool>() );
case kind::OR: { // 2+ args
for(TNode::iterator i = n.begin(),
iend = n.end();
i != iend;
++i) {
if(valuation->getValue(*i).getConst<bool>()) {
return nodeManager->mkConst(true);
}
}
return nodeManager->mkConst(false);
}
case kind::XOR: // 2 args
return nodeManager->mkConst( valuation->getValue(n[0]).getConst<bool>() !=
valuation->getValue(n[1]).getConst<bool>() );
case kind::ITE: // 3 args
// all ITEs should be gone except (bool,bool,bool) ones
Assert( n[1].getType() == nodeManager->booleanType() &&
n[2].getType() == nodeManager->booleanType() );
return nodeManager->mkConst( valuation->getValue(n[0]).getConst<bool>() ?
valuation->getValue(n[1]).getConst<bool>() :
valuation->getValue(n[2]).getConst<bool>() );
default:
Unhandled(n.getKind());
}
}
}/* CVC4::theory::booleans namespace */
}/* CVC4::theory namespace */
}/* CVC4 namespace */
|