1 /********************* */
2 /*! \file type_enumerator.h
4 ** Top contributors (to current version):
5 ** Morgan Deters, Tim King, Mathias Preiner
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2020 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.\endverbatim
12 ** \brief Enumerators for rationals and integers
14 ** Enumerators for rationals and integers.
17 #include "cvc4_private.h"
19 #ifndef CVC4__THEORY__ARITH__TYPE_ENUMERATOR_H
20 #define CVC4__THEORY__ARITH__TYPE_ENUMERATOR_H
22 #include "expr/kind.h"
23 #include "expr/type_node.h"
24 #include "theory/type_enumerator.h"
25 #include "util/integer.h"
26 #include "util/rational.h"
32 class RationalEnumerator
: public TypeEnumeratorBase
<RationalEnumerator
> {
36 RationalEnumerator(TypeNode type
, TypeEnumeratorProperties
* tep
= nullptr)
37 : TypeEnumeratorBase
<RationalEnumerator
>(type
), d_rat(0)
39 Assert(type
.getKind() == kind::TYPE_CONSTANT
40 && type
.getConst
<TypeConstant
>() == REAL_TYPE
);
43 Node
operator*() override
{ return NodeManager::currentNM()->mkConst(d_rat
); }
44 RationalEnumerator
& operator++() override
46 // sequence is 0, then diagonal with negatives interleaved
47 // ( 0, 1/1, -1/1, 2/1, -2/1, 1/2, -1/2, 3/1, -3/1, 1/3, -1/3,
48 // 4/1, -4/1, 3/2, -3/2, 2/3, -2/3, 1/4, -1/4, ...)
51 } else if(d_rat
< 0) {
53 Integer num
= d_rat
.getNumerator();
54 Integer den
= d_rat
.getDenominator();
62 d_rat
= Rational(num
, den
);
63 } while(d_rat
.getNumerator() != num
);
70 bool isFinished() override
{ return false; }
71 };/* class RationalEnumerator */
73 class IntegerEnumerator
: public TypeEnumeratorBase
<IntegerEnumerator
> {
77 IntegerEnumerator(TypeNode type
, TypeEnumeratorProperties
* tep
= nullptr)
78 : TypeEnumeratorBase
<IntegerEnumerator
>(type
), d_int(0)
80 Assert(type
.getKind() == kind::TYPE_CONSTANT
81 && type
.getConst
<TypeConstant
>() == INTEGER_TYPE
);
84 Node
operator*() override
86 return NodeManager::currentNM()->mkConst(Rational(d_int
));
89 IntegerEnumerator
& operator++() override
91 // sequence is 0, 1, -1, 2, -2, 3, -3, ...
100 bool isFinished() override
{ return false; }
101 };/* class IntegerEnumerator */
103 }/* CVC4::theory::arith namespace */
104 }/* CVC4::theory namespace */
105 }/* CVC4 namespace */
107 #endif /* CVC4__THEORY__ARITH__TYPE_ENUMERATOR_H */