#ifndef __SortInference__
#define __SortInference__
#include "Forwards.hpp"
#include "Lib/DHMap.hpp"
namespace FMB {
using namespace Kernel;
using namespace Shell;
using namespace Lib;
struct SortedSignature{
unsigned sorts;
DArray<Stack<unsigned>> sortedConstants;
DArray<Stack<unsigned>> sortedFunctions;
DArray<DArray<unsigned>> functionSignatures;
DArray<DArray<unsigned>> predicateSignatures;
DArray<unsigned> sortBounds;
unsigned distinctSorts;
DArray<unsigned> varEqSorts;
DArray<unsigned> parents;
DHMap<unsigned,Stack<unsigned>*> distinctToVampire;
DHMap<unsigned,Stack<unsigned>*> vampireToDistinct;
DHMap<unsigned,unsigned> vampireToDistinctParent;
ZIArray<bool> monotonicSorts;
};
class SortInference {
public:
SortInference(ClauseList* clauses,
const DArray<bool>& del_f,
const DArray<bool>& del_p,
Stack<std::pair<unsigned,unsigned>>& distinct_sort_constraints,
DHMap<unsigned,DArray<signed char>*>& monotonic_vampire_sorts) :
_clauses(clauses), _del_f(del_f), _del_p(del_p),
_sort_constraints(distinct_sort_constraints),
_monotonic_vampire_sorts(monotonic_vampire_sorts)
{
_sig = new SortedSignature();
_print = env.options->showFMBsortInfo();
_ignoreInference = !clauses;
_expandSubsorts = env.options->fmbAdjustSorts() == Options::FMBAdjustSorts::EXPAND;
_usingMonotonicity = true;
_collapsingMonotonicSorts = (env.options->fmbAdjustSorts() != Options::FMBAdjustSorts::OFF &&
env.options->fmbAdjustSorts() != Options::FMBAdjustSorts::EXPAND);
_assumeMonotonic = _collapsingMonotonicSorts &&
env.options->fmbAdjustSorts() != Options::FMBAdjustSorts::GROUP;
_distinctSorts=0;
_collapsed=0;
ASS(! (_expandSubsorts && _collapsingMonotonicSorts) );
ASS( _collapsingMonotonicSorts || !_assumeMonotonic);
}
void doInference();
SortedSignature* getSignature(){ return _sig; }
private:
unsigned getDistinctSort(unsigned subsort, unsigned vampireSort, bool createNew=true);
bool _print;
bool _ignoreInference;
bool _expandSubsorts;
bool _usingMonotonicity;
bool _collapsingMonotonicSorts;
bool _assumeMonotonic;
unsigned _distinctSorts;
unsigned _collapsed;
ZIArray<unsigned> _posEqualitiesOnSort;
SortedSignature* _sig;
ClauseList* _clauses;
const DArray<bool>& _del_f;
const DArray<bool>& _del_p;
Stack<std::pair<unsigned,unsigned>>& _sort_constraints;
DHMap<unsigned,DArray<signed char>*>& _monotonic_vampire_sorts;
};
}
#endif