#ifndef _SPLTRAIL_
#define _SPLTRAIL_ 
#include <math.h>
#include "array.h"
#include "term.h"
#include "folsubst.h"
#include "clause.h"
#include "pathidx.h"
#include "sharing.h"
#include "logic.h"
typedef struct TRAILDATA_HELP{
  TERM atom;
  unsigned cinfo;
  unsigned dinfo;
  CLAUSE reason;
  SUBST subst;
  unsigned tpos;
  unsigned ipos;
} TRAILDATA_NODE, *TRAILDATA;
typedef struct TRAIL_HELP{
  MEMORY memory;
  SYMBSTATE symbstate;
  TERMSTATE termstate;
  FOLSTATE folstate;
  SUBSTSTATE sstate;
  SHARER sharer;
  unsigned tsize;
  unsigned tcap;
  TRAILDATA trail;
  unsigned* sharedmap;
  unsigned mapcap;
  PATHIDX posidx;
  PATHIDX negidx;
  PATHIDX iter;
  unsigned dl;
  ARRAY cstack;
} TRAIL_NODE, *TRAIL;
MEMORY trail_GetMemory(TRAIL);
SYMBSTATE trail_GetSymbstate(TRAIL);
TERMSTATE trail_GetTermstate(TRAIL);
FOLSTATE trail_GetFolstate(TRAIL);
SUBSTSTATE trail_GetSubststate(TRAIL);
TRAIL trail_Create(MEMORY,SYMBSTATE,TERMSTATE,FOLSTATE,SUBSTSTATE,SHARER);
void trail_Delete(TRAIL);
void trail_SetDl(TRAIL, unsigned);
void trail_IncreaseDl(TRAIL);
unsigned trail_GetDl(TRAIL);
unsigned trail_GetSize(TRAIL);
unsigned trail_GetCapacity(TRAIL);
TRAILDATA trail_Add(TRAIL, TERM, CLAUSE, SUBST, unsigned, BOOL, BOOL);
TRAILDATA trail_Pop(TRAIL);
void trail_MakeBacktrack(TRAIL);
TRAILDATA trail_GetDecisionAtDl(TRAIL, unsigned);
unsigned trail_GetNumberLitUpToCurrDl(TRAIL);
void trail_NewDl(TRAIL);
void trail_CStackAdjustSize(TRAIL);
void trail_Print(TRAIL);
void trail_PrintStatus(VAR_STATUS);
void trail_ClausePrintSubst(TRAIL, TERMSTATE, CLAUSE, SUBST);
void trail_IsConsistent(TRAIL);
BOOL trail_IsPositiveFromTrailPos(TRAIL, unsigned);
TERM trail_GetAtomFromTrailPos(TRAIL, unsigned);
unsigned trail_GetDlFromTrailPos(TRAIL,unsigned);
unsigned trail_ClausePositionFromTrailPos(TRAIL, unsigned);
BOOL trail_IsDecisionFromTrailPos(TRAIL,unsigned);
CLAUSE trail_GetReasonFromTrailPos(TRAIL, unsigned);
TRAILDATA trail_GetDataFromTrailPos(TRAIL, unsigned);
BOOL trail_IsPositiveFromData(TRAIL, TRAILDATA);
unsigned trail_AtomIdFromData(TRAIL, TRAILDATA);
TERM trail_AtomFromData(TRAIL, TRAILDATA);
unsigned trail_LitDlFromData(TRAIL, TRAILDATA);
unsigned trail_AtomTrailPositionFromData(TRAIL, TRAILDATA);
unsigned trail_ClausePositionFromData(TRAIL, TRAILDATA);
BOOL trail_LitIsDecision(TRAIL, TRAILDATA);
CLAUSE trail_LitReasonFromData(TRAIL, TRAILDATA);
SUBST trail_LitSubstFromData(TRAIL, TRAILDATA);
void trail_PrintData(TRAIL,TRAILDATA);
BOOL trail_IsLitSet(TRAIL,TERM,SUBST);
VAR_STATUS trail_LitStatusFromLit(TRAIL,TERM,SUBST);
VAR_STATUS trail_LitStatusFromAtomPos(TRAIL, TERM, SUBST, BOOL, unsigned);
VAR_STATUS trail_LitStatusFromAtom(TRAIL,TERM,SUBST,BOOL);
unsigned trail_LitDl(TRAIL,TERM,SUBST);
CLAUSE trail_LitReason(TRAIL,TERM,SUBST);
TRAILDATA trail_LitData(TRAIL,TERM,SUBST);
TRAILDATA trail_AtomData(TRAIL,TERM,SUBST);
TRAILDATA trail_AtomDataPos(TRAIL, TERM, SUBST, unsigned);
ARRAY trail_FalseInstancesOfLit(TRAIL, TERM, SUBST, TYPING, unsigned);
ARRAY trail_FalseInstancesOfAtom(TRAIL, TERM, SUBST, BOOL, TYPING, unsigned);
ARRAY trail_FalseInstancesOfAtomPure(TRAIL, TERM, SUBST, BOOL, TYPING, ARRAY*);
BOOL trail_StartFalseInstancesIterator(TRAIL, TERM, SUBST, BOOL, TYPING);
BOOL trail_NextFalseInstanceFromIterator(TRAIL, TERM, SUBST, BOOL, TYPING);
unsigned trail_CurrTrailPosForFalseInstanceIterator(TRAIL);
BOOL trail_FalseInstancesIteratorIsRunning(TRAIL);
void trail_StopInstancesIterator(TRAIL);
BOOL trail_LitIsPositive(TRAIL,TERM);
BOOL trail_NextFalseInstanceFromIteratorPos(TRAIL, TERM, SUBST, BOOL, TYPING, unsigned);
BOOL trail_IsGLitSet(TRAIL,TERM);
VAR_STATUS trail_LitStatusFromGAtom(TRAIL,TERM,BOOL);
VAR_STATUS trail_LitStatusFromGLit(TRAIL,TERM);
unsigned trail_GLitDl(TRAIL,TERM);
CLAUSE trail_GLitReason(TRAIL,TERM);
TRAILDATA trail_GLitData(TRAIL,TERM);
TRAILDATA trail_GAtomData(TRAIL, TERM);
#endif
