2004-04-23 11:58:43 +01:00
|
|
|
#ifndef KNOWLEDGE
|
|
|
|
#define KNOWLEDGE
|
|
|
|
|
2004-07-24 20:07:29 +01:00
|
|
|
#include "term.h"
|
|
|
|
#include "termlist.h"
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-05-15 13:33:01 +01:00
|
|
|
//! Knowledge structure.
|
|
|
|
/**
|
|
|
|
* Contains a miminal representation of a knowledge set.
|
|
|
|
*/
|
2004-04-23 11:58:43 +01:00
|
|
|
struct knowledge
|
|
|
|
{
|
2004-05-15 13:33:01 +01:00
|
|
|
//! A list of non-encrypted terms.
|
2004-04-23 11:58:43 +01:00
|
|
|
Termlist basic;
|
2004-05-15 13:33:01 +01:00
|
|
|
//! A list of terms encrypted, such that the inverse is not in the knowledge set.
|
2004-04-23 11:58:43 +01:00
|
|
|
Termlist encrypt;
|
2006-01-02 21:06:08 +00:00
|
|
|
//! List of inverse pairs (thus length of list is even)
|
2004-04-23 11:58:43 +01:00
|
|
|
Termlist inverses;
|
2004-05-26 09:42:34 +01:00
|
|
|
//! List of open variables in the knowledge set.
|
|
|
|
/**
|
|
|
|
* This list is used to determine whether the knowledge needs to be rewritten.
|
|
|
|
* If a new substitution is done, one of the elements of this list will become closed,
|
|
|
|
* and we need to reconstruct the knowledge set.
|
|
|
|
*/
|
|
|
|
Termlist vars; // special: denotes unsubstituted variables
|
2004-04-23 11:58:43 +01:00
|
|
|
};
|
|
|
|
|
2004-05-15 13:33:01 +01:00
|
|
|
//! Shorthand for knowledge pointer.
|
2004-04-23 11:58:43 +01:00
|
|
|
typedef struct knowledge *Knowledge;
|
|
|
|
|
|
|
|
void knowledgeInit (void);
|
|
|
|
void knowledgeDone (void);
|
|
|
|
Knowledge makeKnowledge ();
|
|
|
|
Knowledge emptyKnowledge ();
|
|
|
|
Knowledge knowledgeDuplicate (Knowledge know);
|
|
|
|
void knowledgeDelete (Knowledge know);
|
|
|
|
void knowledgeDestroy (Knowledge know);
|
|
|
|
int knowledgeAddTerm (Knowledge know, Term term);
|
|
|
|
int knowledgeAddTermlist (Knowledge know, Termlist tl);
|
|
|
|
void knowledgeAddInverse (Knowledge know, Term t1, Term t2);
|
|
|
|
void knowledgeSetInverses (Knowledge know, Termlist tl);
|
|
|
|
void knowledgeSimplify (Knowledge know, Term decryptkey);
|
|
|
|
int inKnowledge (const Knowledge know, Term term);
|
|
|
|
void knowledgePrint (Knowledge know);
|
2004-08-06 12:59:27 +01:00
|
|
|
void knowledgePrintShort (const Knowledge know);
|
2004-04-23 11:58:43 +01:00
|
|
|
void knowledgeInversesPrint (Knowledge know);
|
|
|
|
int isKnowledgeEqual (Knowledge know1, Knowledge know2);
|
2004-07-20 10:07:43 +01:00
|
|
|
Termlist knowledgeSet (const Knowledge know);
|
|
|
|
Termlist knowledgeGetInverses (const Knowledge know);
|
|
|
|
Termlist knowledgeGetBasics (const Knowledge know);
|
2004-04-23 11:58:43 +01:00
|
|
|
int knowledgeSubstNeeded (const Knowledge know);
|
|
|
|
Knowledge knowledgeSubstDo (const Knowledge know);
|
|
|
|
void knowledgeSubstUndo (const Knowledge know);
|
|
|
|
Termlist knowledgeNew (const Knowledge oldk, const Knowledge newk);
|
|
|
|
|
2004-05-15 13:33:01 +01:00
|
|
|
//! Harnass macro for recursive procedures.
|
2004-04-23 11:58:43 +01:00
|
|
|
#define mindwipe(k,recurse) \
|
2004-05-26 10:34:08 +01:00
|
|
|
Termlist tl; \
|
|
|
|
Term oldsubst; \
|
|
|
|
int flag; \
|
2004-04-23 11:58:43 +01:00
|
|
|
if (k != NULL && k->vars != NULL) { \
|
2004-05-26 10:34:08 +01:00
|
|
|
tl = k->vars; \
|
2004-04-23 11:58:43 +01:00
|
|
|
while (tl != NULL) { \
|
|
|
|
if (tl->term->subst != NULL) { \
|
|
|
|
Term oldsubst = tl->term->subst; \
|
|
|
|
tl->term->subst = NULL; \
|
2004-05-26 10:34:08 +01:00
|
|
|
flag = recurse; \
|
2004-04-23 11:58:43 +01:00
|
|
|
tl->term->subst = oldsubst; \
|
|
|
|
return flag; \
|
|
|
|
} \
|
|
|
|
tl = tl->next; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|