1 /******************************************************************************
2 * Top contributors (to current version):
3 * Morgan Deters, Tim King, Mathias Preiner
5 * This file is part of the cvc5 project.
7 * Copyright (c) 2009-2022 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 * Enumerators for rationals and integers.
16 #include "cvc5_private.h"
18 #ifndef CVC5__THEORY__ARITH__TYPE_ENUMERATOR_H
19 #define CVC5__THEORY__ARITH__TYPE_ENUMERATOR_H
21 #include "expr/kind.h"
22 #include "expr/type_node.h"
23 #include "theory/type_enumerator.h"
24 #include "util/integer.h"
25 #include "util/rational.h"
27 namespace cvc5::internal
{
31 class RationalEnumerator
: public TypeEnumeratorBase
<RationalEnumerator
> {
35 RationalEnumerator(TypeNode type
, TypeEnumeratorProperties
* tep
= nullptr)
36 : TypeEnumeratorBase
<RationalEnumerator
>(type
), d_rat(0)
38 Assert(type
.getKind() == kind::TYPE_CONSTANT
39 && type
.getConst
<TypeConstant
>() == REAL_TYPE
);
42 Node
operator*() override
44 return NodeManager::currentNM()->mkConstReal(d_rat
);
46 RationalEnumerator
& operator++() override
48 // sequence is 0, then diagonal with negatives interleaved
49 // ( 0, 1/1, -1/1, 2/1, -2/1, 1/2, -1/2, 3/1, -3/1, 1/3, -1/3,
50 // 4/1, -4/1, 3/2, -3/2, 2/3, -2/3, 1/4, -1/4, ...)
53 } else if(d_rat
< 0) {
55 Integer num
= d_rat
.getNumerator();
56 Integer den
= d_rat
.getDenominator();
64 d_rat
= Rational(num
, den
);
65 } while(d_rat
.getNumerator() != num
);
72 bool isFinished() override
{ return false; }
73 };/* class RationalEnumerator */
75 class IntegerEnumerator
: public TypeEnumeratorBase
<IntegerEnumerator
> {
79 IntegerEnumerator(TypeNode type
, TypeEnumeratorProperties
* tep
= nullptr)
80 : TypeEnumeratorBase
<IntegerEnumerator
>(type
), d_int(0)
82 Assert(type
.getKind() == kind::TYPE_CONSTANT
83 && type
.getConst
<TypeConstant
>() == INTEGER_TYPE
);
86 Node
operator*() override
88 return NodeManager::currentNM()->mkConstInt(Rational(d_int
));
91 IntegerEnumerator
& operator++() override
93 // sequence is 0, 1, -1, 2, -2, 3, -3, ...
102 bool isFinished() override
{ return false; }
103 };/* class IntegerEnumerator */
106 } // namespace theory
107 } // namespace cvc5::internal
109 #endif /* CVC5__THEORY__ARITH__TYPE_ENUMERATOR_H */