c778a89cc1e7c00c3a3270b64be6d7c81c9cb0a1
1 /******************************************************************************
2 * Top contributors (to current version):
3 * Andrew Reynolds, Tim King, Tianyi Liang
5 * This file is part of the cvc5 project.
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 * ****************************************************************************
13 * The extended theory callback for non-linear arithmetic
16 #include "theory/arith/nl/ext_theory_callback.h"
18 #include "theory/arith/arith_utilities.h"
19 #include "theory/uf/equality_engine.h"
21 using namespace cvc5::kind
;
28 NlExtTheoryCallback::NlExtTheoryCallback(eq::EqualityEngine
* ee
) : d_ee(ee
)
30 d_zero
= NodeManager::currentNM()->mkConst(Rational(0));
33 bool NlExtTheoryCallback::getCurrentSubstitution(
35 const std::vector
<Node
>& vars
,
36 std::vector
<Node
>& subs
,
37 std::map
<Node
, std::vector
<Node
>>& exp
)
39 // get the constant equivalence classes
40 std::map
<Node
, std::vector
<int>> rep_to_subs_index
;
43 for (unsigned i
= 0; i
< vars
.size(); i
++)
48 Node nr
= d_ee
->getRepresentative(n
);
52 Trace("nl-subs") << "Basic substitution : " << n
<< " -> " << nr
54 exp
[n
].push_back(n
.eqNode(nr
));
59 rep_to_subs_index
[nr
].push_back(i
);
69 // return true if the substitution is non-trivial
73 bool NlExtTheoryCallback::isExtfReduced(
74 int effort
, Node n
, Node on
, std::vector
<Node
>& exp
, ExtReducedId
& id
)
79 if (k
!= NONLINEAR_MULT
&& !isTranscendentalKind(k
) && k
!= IAND
)
81 id
= ExtReducedId::ARITH_SR_LINEAR
;
87 id
= ExtReducedId::ARITH_SR_ZERO
;
88 if (on
.getKind() == NONLINEAR_MULT
)
90 Trace("nl-ext-zero-exp")
91 << "Infer zero : " << on
<< " == " << n
<< std::endl
;
92 // minimize explanation if a substitution+rewrite results in zero
93 const std::set
<Node
> vars(on
.begin(), on
.end());
95 for (unsigned i
= 0, size
= exp
.size(); i
< size
; i
++)
97 Trace("nl-ext-zero-exp")
98 << " exp[" << i
<< "] = " << exp
[i
] << std::endl
;
99 std::vector
<Node
> eqs
;
100 if (exp
[i
].getKind() == EQUAL
)
102 eqs
.push_back(exp
[i
]);
104 else if (exp
[i
].getKind() == AND
)
106 for (const Node
& ec
: exp
[i
])
108 if (ec
.getKind() == EQUAL
)
115 for (unsigned j
= 0; j
< eqs
.size(); j
++)
117 for (unsigned r
= 0; r
< 2; r
++)
119 if (eqs
[j
][r
] == d_zero
&& vars
.find(eqs
[j
][1 - r
]) != vars
.end())
121 Trace("nl-ext-zero-exp")
122 << "...single exp : " << eqs
[j
] << std::endl
;
124 exp
.push_back(eqs
[j
]);
136 } // namespace theory