1
/**************************************************************/
2
/* ********************************************************** */
4
/* * EXTENDED MODAL LOGICS ROUTINES * */
9
/* $Revision: 1.7 $ * */
11
/* * This program is free software; you can redistribute * */
12
/* * it and/or modify it under the terms of the FreeBSD * */
15
/* * This program is distributed in the hope that it will * */
16
/* * be useful, but WITHOUT ANY WARRANTY; without even * */
17
/* * the implied warranty of MERCHANTABILITY or FITNESS * */
18
/* * FOR A PARTICULAR PURPOSE. See the LICENCE file * */
19
/* * for more details. * */
20
/* $Date: 2010-02-22 14:09:58 $ * */
21
/* $Author: weidenb $ * */
24
/* * Renate Schmidt * */
25
/* * School of Computer Science * */
26
/* * University of Manchester * */
27
/* * Oxford Rd, Manchester M13 9PL, UK * */
28
/* * Email: Renate.Schmidt@manchester.ac.uk * */
30
/* ********************************************************** */
31
/**************************************************************/
34
/* $RCSfile: eml.c,v $ */
55
LIST eml_SYMBOLS; /* eml junctor symbols */
57
LIST *eml_PROPINDEXTOFOSYMBOL; /* list of FO symbols associated with
58
eml prop/junctor symbols */
59
SYMBOL eml_SEMIFNDESYMBOLS[symbol__MAXSIGNATURE];
60
/* nde symbols associated with diamonds */
61
SYMBOL eml_NARYSYMBOLS[symbol__MAXSIGNATURE][eml__MAXMODALDEPTH];
62
/* FO symbols with particular
63
* arity associated with p's */
65
static const char* eml_PREDNAMEPREFIX[6] = { "SkQ", "SkR", "SkNde" , "SkQ", "SkNde", "SkS" };
67
static const char* eml_RELPROPERTYLABELS[6] = { "", "serial",
68
"reflexive" , "symmetric", "transitive", "euclidean" };
70
static TERM eml_RemoveTrivialAtomsAndOps(TERM);
71
static TERM eml_RemoveTrivialOperator(TERM Term);
73
static TERM eml_EmbedInRelCalculusProp(TERM);
74
static TERM eml_EmbedInRelCalculusRel(TERM);
76
static TERM eml_RelationalTranslationProp(TERM, SYMBOL, FLAGSTORE, PRECEDENCE);
77
static TERM eml_RelationalTranslationRel(TERM, SYMBOL, SYMBOL, FLAGSTORE, PRECEDENCE);
79
static TERM eml_FunctTranslProp(TERM, TERM, FLAGSTORE, PRECEDENCE);
80
static TERM eml_FunctTranslRel(TERM, TERM, FLAGSTORE, PRECEDENCE);
81
static TERM eml_FunctTranslItoNaryPredProp(TERM, LIST, char*, int, FLAGSTORE, PRECEDENCE);
82
static TERM eml_FunctTranslItoNaryPredRel(TERM, LIST, char*, int, FLAGSTORE, PRECEDENCE);
84
static TERM eml_SemiFunctTranslProp(TERM, TERM, int, FLAGSTORE, PRECEDENCE);
85
static TERM eml_SemiFunctTranslRelBox(TERM, TERM, TERM, FLAGSTORE, PRECEDENCE);
86
static TERM eml_SemiFunctTranslRelDia(TERM, TERM, FLAGSTORE, PRECEDENCE);
88
static TERM eml_RelFunctTranslProp(TERM, SYMBOL, char*, FLAGSTORE, PRECEDENCE);
89
static TERM eml_RelFunctTranslRel(TERM, SYMBOL, SYMBOL, char*, FLAGSTORE, PRECEDENCE);
91
/**************************************************************/
92
/* ********************************************************** */
96
/* ********************************************************** */
97
/**************************************************************/
99
void eml_Init(PRECEDENCE Precedence)
100
/**************************************************************
103
USAGE: extern public.
104
SUMMARY: Initializes the Eml Module.
105
EFFECTS: All additional extended modal logic symbols are created.
106
(The first-order symbols are created in fol_Init.)
107
And, creates an array for the list of
108
propositional/first-order symbol pairs as well as Eml logical
109
symbols/first-order logical symbol lists.
110
CAUTION: MUST BE CALLED BEFORE ANY OTHER eml-FUNCTION.
111
***************************************************************/
115
eml_BOX = symbol_CreateJunctor("box", 2, symbol_STATLEX, Precedence);
116
eml_COMP = symbol_CreateJunctor("comp", 2, symbol_STATLEX, Precedence);
117
eml_CONV = symbol_CreateJunctor("conv", 1, symbol_STATLEX, Precedence);
118
eml_DIA = symbol_CreateJunctor("dia", 2, symbol_STATLEX, Precedence);
119
eml_DIV = symbol_CreatePredicate("div", 0, symbol_STATLEX, Precedence);
120
eml_DOMAIN = symbol_CreateJunctor("domain", 1, symbol_STATLEX, Precedence);
121
eml_DOMRESTR = symbol_CreateJunctor("domrestr", 2, symbol_STATLEX, Precedence);
122
eml_ID = symbol_CreatePredicate("id", 0, symbol_STATLEX, Precedence);
123
eml_RANGE = symbol_CreateJunctor("range", 1, symbol_STATLEX, Precedence);
124
eml_RANRESTR = symbol_CreateJunctor("ranrestr", 2, symbol_STATLEX, Precedence);
125
eml_SUM = symbol_CreateJunctor("sum", 2, symbol_STATLEX, Precedence);
126
eml_TEST = symbol_CreateJunctor("test", 1, symbol_STATLEX, Precedence);
127
symbol_AddProperty(eml_DIV, PREDEFINED);
128
symbol_AddProperty(eml_ID, PREDEFINED);
131
list_Cons((POINTER)eml_BOX, list_Cons((POINTER)eml_COMP,
132
list_Cons((POINTER)eml_CONV, list_Cons((POINTER)eml_DIA,
133
list_Cons((POINTER)eml_DIV, list_Cons((POINTER)eml_DOMAIN,
134
list_Cons((POINTER)eml_DOMRESTR, list_Cons((POINTER)eml_ID,
135
list_Cons((POINTER)eml_RANGE, list_Cons((POINTER)eml_RANRESTR,
136
list_Cons((POINTER)eml_SUM, list_List((POINTER)eml_TEST))))))))))));
138
eml_PROPINDEXTOFOSYMBOL = (LIST*)memory_Malloc(sizeof(LIST) * symbol__MAXSIGNATURE);
139
for (i=0;i< symbol__MAXSIGNATURE;i++)
140
eml_PROPINDEXTOFOSYMBOL[i] = list_Nil();
142
eml_SetPropFoSymbolAssocList(eml_Dia(),
143
list_Cons((POINTER)fol_Exist(), list_List((POINTER)fol_And())));
144
eml_SetPropFoSymbolAssocList(eml_Box(),
145
list_Cons((POINTER)fol_All(), list_List((POINTER)fol_Implies())));
146
eml_SetPropFoSymbolAssocList(eml_Comp(),
147
list_Cons((POINTER)fol_Exist(), list_List((POINTER)fol_And())));
148
eml_SetPropFoSymbolAssocList(eml_Sum(),
149
list_Cons((POINTER)fol_All(), list_List((POINTER)fol_Or())));
150
eml_SetPropFoSymbolAssocList(eml_Domain(),
151
list_List((POINTER)fol_Exist()));
152
eml_SetPropFoSymbolAssocList(eml_Range(),
153
list_List((POINTER)fol_Exist()));
154
eml_SetPropFoSymbolAssocList(eml_Id(),
155
list_List((POINTER)fol_Equality()));
158
BOOL eml_FormulaContainsEMLTheorySymbol(TERM Formula)
159
/**************************************************************
160
INPUT: A term or a formula
161
RETURNS: TRUE iff <Formula> contains an EML theory symbol.
162
USAGE: extern public.
163
***************************************************************/
168
Top = term_TopSymbol(Formula);
170
if (symbol_IsPredicate(Top)) {
171
if (symbol_Equal(eml_DIV,Top) || symbol_Equal(eml_ID,Top))
176
if (symbol_IsFunction(Top) || symbol_IsVariable(Top))
179
if (symbol_Equal(Top, eml_BOX) || symbol_Equal(Top, eml_COMP) || symbol_Equal(Top, eml_CONV) ||
180
symbol_Equal(Top, eml_SUM) || symbol_Equal(Top, eml_DIV) || symbol_Equal(Top, eml_DOMAIN) ||
181
symbol_Equal(Top, eml_DOMRESTR) || symbol_Equal(Top, eml_RANGE) || symbol_Equal(Top, eml_RANRESTR) ||
182
symbol_Equal(Top, eml_TEST))
185
if (fol_IsQuantifier(Top))
186
Scan = list_Cdr(term_ArgumentList(Formula));
188
Scan = term_ArgumentList(Formula);
190
while (!list_Empty(Scan)) {
191
if (eml_FormulaContainsEMLTheorySymbol((TERM)list_First(Scan)))
193
Scan = list_Cdr(Scan);
200
void eml_InitFunctTransl(FLAGSTORE Flags, PRECEDENCE Precedence)
201
/**************************************************************
204
USAGE: static intern.
205
SUMMARY: Initializes the routines for the functional translation of
206
basic (serial) modal logics ito n-ary predicates.
207
EFFECTS: Additonal flags are set.
208
CAUTION: Prerequisite for the functional translation ito n-ary predicates
210
***************************************************************/
212
/* printf("\nDoing eml_InitFunctTransl()\n"); */
214
/* Dynamic memory allocation of eml_NARYSYMBOLS??
215
* This does not work:
216
eml_NARYSYMBOLS = (SYMBOL **)memory_Malloc(sizeof(SYMBOL) * symbol__MAXSIGNATURE *
217
symbol__MAXSIGNATURE);
219
if ( (flag_GetFlagIntValue(Flags, flag_EMLTR) == flag_EMLTRSEMIFUNC) ||
220
!flag_GetFlagIntValue(Flags, flag_EMLFNARY)) {
221
eml_APPLYF = symbol_CreateFunction("app", 2, symbol_STATLEX, Precedence);
222
/* fol_SYMBOLS = list_Cons((POINTER)eml_APPLYF, fol_SYMBOLS);*/
229
/**************************************************************
232
EFFECT: The eml related memory used by the eml module is freed.
233
***************************************************************/
237
list_Delete(eml_SYMBOLS);
239
for (i=0;i< symbol__MAXSIGNATURE;i++)
240
list_Delete(eml_PROPINDEXTOFOSYMBOL[i]);
242
memory_Free(eml_PROPINDEXTOFOSYMBOL, sizeof(LIST) * symbol__MAXSIGNATURE);
244
/* list_Delete(eml_NARYSYMBOLS); ?? */
247
LIST eml_NullaryPredList()
248
/**************************************************************
250
RETURNS: The list of nullary predicate symbols in the signature
252
EFFECTS: Creates a table for the list of
253
propositional/first-order symbol pairs.
254
***************************************************************/
256
LIST nullaryPredList;
259
if (!symbol_SignatureExists()) {
260
fprintf(stderr,"\n\t eml_NullaryPredList(): no signature!?\n");
264
nullaryPredList = list_Nil();
265
for(i = 1; i < symbol_ACTINDEX; i++)
266
if (!symbol_IsFreed(i) &&
267
eml_IsNullaryPredicate(symbol_GetSigSymbol(i)))
269
list_Cons((POINTER)(symbol_GetSigSymbol(i)),
273
printf("\n nullaryPredList: ");
274
for (Scan=nullaryPredList; !list_Empty(Scan); Scan=list_Cdr(Scan)) {
275
symbol_Print((SYMBOL)list_Car(Scan));
281
return nullaryPredList;
284
static SYMBOL eml_GetFoSymbolAssocWithPropSymbol(SYMBOL
285
PropSymbol, NAT Arity, eml_SYMBOLTYPE SymbolType)
286
/**************************************************************
287
INPUT: a (propositional) symbol, the arity of the corresponding
288
predicate symbol, the symbol type.
289
RETURNS: The corresponding first-order symbol.
291
***************************************************************/
293
/* printf("\n PropSymbol = "); */
294
/* symbol_Print(PropSymbol); */
295
if (eml_NaryType(SymbolType)) {
296
/* Retrieve symbol with given arity */
298
/* printf("\n eml_NaryType"); */
299
symbol = eml_NARYSYMBOLS[symbol_Index(PropSymbol)][Arity-1];
300
if (symbol_IsSymbol(symbol))
303
else if (eml_SemiFuncNdeType(SymbolType)) {
304
/* Retrieve nde symbol for semi-functional translation */
306
/* printf("\n eml_SemiFuncNdeType"); */
307
symbol = eml_SEMIFNDESYMBOLS[symbol_Index(PropSymbol)];
308
if (symbol_IsSymbol(symbol))
311
else if (eml_VarSortType(SymbolType)) {
312
/* Reuse propositional symbol as predicate symbol to indicate the
314
/* printf("\n eml_VarSortType"); */
315
return PropSymbol; /* Struture sharing!
316
* Alternatively, set up another array called
317
* eml_PROPINDEXTOSORTSYMBOL, say */
320
/* Retrieve predicate symbol: P_p for p, and R_r for r */
322
/* printf("\n not eml_NaryType and not eml_VarSortType"); */
323
symbolList = eml_PROPINDEXTOFOSYMBOL[symbol_Index(PropSymbol)];
324
if (!list_Empty(symbolList))
325
return (SYMBOL) list_First(symbolList);
328
/* printf("\n not eml_NaryType and not eml_VarSortType and symbolList is empty"); */
333
SYMBOL eml_CreateFoSymbol(SYMBOL PropSymbol, eml_SYMBOLTYPE SymbolType,
334
int Arity, int Status, PRECEDENCE Precedence)
335
/*******************************************************
336
INPUT: A symbol (which MUST be a propositonal symbol/nullary
337
predicate symbol), a symbol type (of the fo symbol to be
338
created), the arity of the new symbol, The status of the new
340
RETURNS: A first-order symbol corresponding to PropSymbol.
341
********************************************************/
347
if (eml_NaryType(SymbolType)) {
348
char* arityStr = string_IntToString(Arity);
349
size = strlen(eml_PREDNAMEPREFIX[SymbolType])+strlen(arityStr)+strlen(symbol_Name(PropSymbol))+1;
350
newName = memory_Malloc(size*sizeof(char));
352
/* Note: if SymbolType is n-ary then any propositional symbol can
353
* be associated with more than one n-ary predicate symbol, for
354
* that reason no user defined FoSymbols will be considered */
355
sprintf(newName,"%s%s%s", eml_PREDNAMEPREFIX[SymbolType], arityStr,
356
symbol_Name(PropSymbol));
357
foSymbol = symbol_CreatePredicate(newName, Arity, Status, Precedence);
358
eml_SetPropNarySymbolAssocList(PropSymbol, Arity, foSymbol);
360
memory_Free(newName,size*sizeof(char));
361
string_StringFree(arityStr);
363
else if (eml_SemiFuncNdeType(SymbolType)) {
364
size = strlen(eml_PREDNAMEPREFIX[eml_NDE])+strlen(symbol_Name(PropSymbol))+1;
365
newName = memory_Malloc(size*sizeof(char));
367
/* NOTE: For the moment no user defined FoSymbols will be
368
* considered. This restriction is provisional */
369
sprintf(newName,"%s%s", eml_PREDNAMEPREFIX[eml_NDE],
370
symbol_Name(PropSymbol));
371
foSymbol = symbol_CreatePredicate(newName, Arity, Status, Precedence);
372
eml_SetPropSemiFNdeSymbolAssocList(PropSymbol, Arity, foSymbol);
374
memory_Free(newName,size*sizeof(char));
377
size = strlen(eml_PREDNAMEPREFIX[SymbolType])+strlen(symbol_Name(PropSymbol))+1;
378
newName = memory_Malloc(size*sizeof(char));
380
sprintf(newName,"%s%s", eml_PREDNAMEPREFIX[SymbolType],
381
symbol_Name(PropSymbol));
382
foSymbol = symbol_CreatePredicate(newName, Arity, Status, Precedence);
383
eml_SetPropFoSymbolAssocList(PropSymbol,list_List((POINTER)foSymbol));
385
memory_Free(newName,size*sizeof(char));
391
TERM eml_CreateQuantifier(TERM Term, SYMBOL Quantifier, LIST VarList,
393
/*******************************************************
394
INPUT: A term (dummy, not used), symbol (which MUST be a fol
395
quantifier), a list of variables that will be bound, and
397
RETURNS: A new quantified term.
398
********************************************************/
400
return term_Create(Quantifier,
401
list_Cons(term_Create(fol_Varlist(), VarList),
405
static TERM eml_RplacWithQuantifier(TERM Term, SYMBOL Quantifier,
406
LIST VarList, LIST Arguments)
407
/**************************************************************
408
INPUT: A formula, a symbol (quantifier), two list of terms.
409
RETURNS: A quantifier replacement.
410
EFFECT: Note, a term node is created for the variable list.
411
CAUTION: The term in destructively changed.
412
***************************************************************/
414
term_RplacTop(Term,Quantifier);
415
term_RplacArgumentList(Term,
416
list_Cons(term_Create(fol_Varlist(), VarList), Arguments));
421
static TERM eml_BuildSortQuantifierFor(TERM Term, SYMBOL ModalTop,
422
SYMBOL RelSubTop, SYMBOL Var, BOOL WithSort,
423
LIST Arguments, POINTER (*BuildFunction)(),
424
PRECEDENCE Precedence)
425
/*******************************************************
426
INPUT: A term (which MUST be a modal term, i.e. dia(..) or box (...)),
427
a single variable, a Boolean value indicating whether sorts or
428
required, and a list of arguments.
429
RETURNS: A quantified term, possibly restricted by the appropriate sort.
430
CAUTION: The term is potentially destructively changed (depends on the
432
********************************************************/
435
if (!eml_IsModalOpSymbol(ModalTop)) {
436
printf("\n\nIllegal input in eml_BuildSortQuantifierFor\n");
442
eml_SYMBOLTYPE symbolType;
445
if (!eml_IsNullaryPredicate(RelSubTop)) {
446
printf("\n\nIllegal relational argument of modal operator, in eml_BuildSortQuantifierFor\n");
451
symbolType = eml_VARSORT;
452
foSymbol = eml_GetFoSymbolAssocWithPropSymbol(RelSubTop, 1, symbolType);
453
if (foSymbol == symbol__NULL) {
454
foSymbol = eml_CreateFoSymbol(RelSubTop, symbolType, 1, symbol_STATLEX, Precedence);
455
/* Inheritance of precedence? */
456
/* symbol_SetOrdering(Precedence, foSymbol,symbol_Ordering(Precedence, PropSymbol)); */
458
return BuildFunction(Term, eml_FoQuantAssocWithPropSymbol(ModalTop),
459
list_List(term_Create(Var,list_Nil())),
460
list_List(term_Create(eml_FoJunctorAssocWithPropSymbol(ModalTop),
461
list_Cons(term_Create(foSymbol,list_List(term_Create(Var,list_Nil()))), Arguments))));
462
/* exists x S(x) /\ ...
463
* forall x S(x) -> ... */
466
return BuildFunction(Term, eml_FoQuantAssocWithPropSymbol(ModalTop),
467
list_List(term_Create(Var,list_Nil())), Arguments);
473
static TERM eml_RplacWithDesignatedPropAtom(TERM Term, SYMBOL RplacSymbol)
474
/**************************************************************
475
INPUT: A formula and a symbol.
476
RETURNS: A replacement without arguments, e.g. true, false, id, etc.
477
CAUTION: The term in destructively changed.
478
***************************************************************/
480
term_RplacTop(Term,RplacSymbol);
481
list_DeleteWithElement(term_ArgumentList(Term),(void (*)())term_Delete);
482
term_RplacArgumentList(Term,list_Nil());
487
static TERM eml_RplacWithOpAndArgs(TERM Term, SYMBOL RplacSymbol,
489
/**************************************************************
490
INPUT: A formula, a symbol and a list of terms.
491
RETURNS: A replacement with argument list.
492
CAUTION: The term in destructively changed.
493
***************************************************************/
495
term_RplacTop(Term,RplacSymbol);
496
term_RplacArgumentList(Term,Arguments);
501
static TERM eml_RemoveTrivialOperator(TERM Term)
502
/**************************************************************
504
RETURNS: The formula after
505
removal of "or", "and", "comp" and "sum" with only one argument
506
CAUTION: The term in destrucively changed.
507
***************************************************************/
509
if (eml_IsNaryJunctor(term_TopSymbol(Term)) &&
510
list_Empty(list_Cdr(term_ArgumentList(Term)))) {
511
TERM helpTerm = term_FirstArgument(Term);
512
list_Delete(term_ArgumentList(Term));
513
Term = eml_RplacWithOpAndArgs(Term, term_TopSymbol(helpTerm), term_ArgumentList(helpTerm));
520
static TERM eml_RemoveTrivialAtomsAndOps(TERM Term)
521
/**************************************************************
523
RETURNS: The formula after applying
524
or(true,...) -> true, and(true,phi) -> phi
525
or(false,phi) -> phi, and(false,...) -> false
527
dia(alpha,false) -> false, box(alpha,true) -> true
528
dia(false,phi) -> false, box(false,phi) -> true
529
CAUTION: The term in destructively changed.
530
***************************************************************/
532
SYMBOL Top, Subtop, RelSubtop;
534
TERM Subterm, RelSubterm;
537
if (!term_IsComplex(Term))
540
Top = term_TopSymbol(Term);
543
/* Term = and(...) */
544
if (symbol_Equal(Top,fol_And())) {
545
for (Scan=term_ArgumentList(Term); !list_Empty(Scan); Scan=list_Cdr(Scan)) {
546
Subterm = eml_RemoveTrivialAtomsAndOps(list_Car(Scan));
547
Subtop = term_TopSymbol(Subterm);
548
if (symbol_Equal(Subtop,fol_True()))
550
else if (symbol_Equal(Subtop,fol_False())) {
551
/* and(..., false, ...) -> false */
552
return eml_RplacWithDesignatedPropAtom(Term,fol_False());
556
/* and(..., true, ..., true, ...) -> and(..., ..., ...) */
557
term_RplacArgumentList(Term,list_DeleteElementIfFree(term_ArgumentList(Term),(BOOL (*)())fol_IsTrue,(void (*)())term_Delete));
558
if (list_Empty(term_ArgumentList(Term))) {
559
term_RplacTop(Term,fol_True());
563
return eml_RemoveTrivialOperator(Term); /* and(phi) -> phi */
566
else if (symbol_Equal(Top,fol_Or())) {
567
for (Scan=term_ArgumentList(Term); !list_Empty(Scan); Scan=list_Cdr(Scan)) {
568
Subterm = eml_RemoveTrivialAtomsAndOps(list_Car(Scan));
569
Subtop = term_TopSymbol(Subterm);
570
if (symbol_Equal(Subtop,fol_False()))
572
else if (symbol_Equal(Subtop,fol_True())) {
573
/* or(..., true, ...) -> true */
574
return eml_RplacWithDesignatedPropAtom(Term,fol_True());
578
term_RplacArgumentList(Term,list_DeleteElementIfFree(term_ArgumentList(Term),(BOOL (*)())fol_IsFalse,(void (*)())term_Delete));
579
if (list_Empty(term_ArgumentList(Term))) {
580
term_RplacTop(Term,fol_False());
584
return eml_RemoveTrivialOperator(Term); /* or(phi) -> phi */
586
/* Term = not(...) */
587
else if (symbol_Equal(Top,fol_Not())) {
588
Subterm = eml_RemoveTrivialAtomsAndOps(term_FirstArgument(Term));
589
Subtop = term_TopSymbol(Subterm);
590
if (eml_IsDesignatedPropSymbol(Subtop)) {
591
/* not(false) -> true, not(true) -> false, not(div) -> id, not(id) -> div */
592
return eml_RplacWithDesignatedPropAtom(Term,eml_GetDualSymbol(Subtop));
595
/* Term = forall(...) or Term = exists(...) */
596
else if (fol_IsQuantifier(Top)) {
597
Subterm = eml_RemoveTrivialAtomsAndOps(term_SecondArgument(Term));
598
Subtop = term_TopSymbol(Subterm);
599
if (symbol_Equal(Subtop,fol_True())) {
600
/* forall ... true -> true, exists ... true -> true */
601
return eml_RplacWithDesignatedPropAtom(Term,fol_True());
603
else if (symbol_Equal(Subtop,fol_False())) {
604
/* forall ... false -> false, exists ... false -> false */
605
return eml_RplacWithDesignatedPropAtom(Term,fol_False());
608
/* Term = dia(...) or Term = box(...) */
609
else if (eml_IsModalOpSymbol(Top)) {
610
RelSubterm = eml_RemoveTrivialAtomsAndOps(term_FirstArgument(Term));
611
RelSubtop = term_TopSymbol(RelSubterm);
612
Subterm = eml_RemoveTrivialAtomsAndOps(term_SecondArgument(Term));
613
Subtop = term_TopSymbol(Subterm);
614
if (symbol_Equal(Top,eml_Dia()) &&
615
(symbol_Equal(Subtop,fol_False()) || symbol_Equal(RelSubtop,fol_False()))) {
616
/* dia(alpha,false) -> false, dia(false,phi) -> false */
617
return eml_RplacWithDesignatedPropAtom(Term,fol_False());
619
else if (symbol_Equal(Top,eml_Box()) &&
620
(symbol_Equal(Subtop,fol_True()) || symbol_Equal(RelSubtop,fol_False()))) {
621
/* box(alpha,true) -> true, box(true,phi) -> true */
622
return eml_RplacWithDesignatedPropAtom(Term,fol_True());
624
else if (symbol_Equal(RelSubtop, eml_Id())) {
625
/* dia(id,phi) -> phi, box(id,phi) -> phi */
626
term_Delete(RelSubterm);
627
list_Delete(term_ArgumentList(Term));
628
Term = eml_RplacWithOpAndArgs(Term, Subtop, term_ArgumentList(Subterm));
633
/* Term = domain(...) or Term = range(...) */
634
else if (symbol_Equal(Top,eml_Domain()) || symbol_Equal(Top,eml_Range())) {
635
RelSubterm = eml_RemoveTrivialAtomsAndOps(term_FirstArgument(Term));
636
RelSubtop = term_TopSymbol(RelSubterm);
637
if (symbol_Equal(RelSubtop,fol_False())) {
638
/* domain(false) -> false, range(false) -> false */
639
return eml_RplacWithDesignatedPropAtom(Term,fol_False());
641
else if (symbol_Equal(RelSubtop, eml_Id())) {
642
/* domain(id) -> true, range(id) -> true */
643
return eml_RplacWithDesignatedPropAtom(Term,fol_True());
646
/* Term = implies(...) */
647
else if (symbol_Equal(Top,fol_Implies())) {
648
Subterm = eml_RemoveTrivialAtomsAndOps(term_FirstArgument(Term));
649
Subtop = term_TopSymbol(Subterm);
650
if (symbol_Equal(Subtop,fol_False())) {
651
/* implies(false,phi) -> true */
652
return eml_RplacWithDesignatedPropAtom(Term,fol_True());
654
else if (symbol_Equal(Subtop,fol_True())) {
655
/* implies(true,phi) -> phi */
656
term_Delete(Subterm);
657
Subterm = term_SecondArgument(Term);
658
list_Delete(term_ArgumentList(Term));
659
Term = eml_RplacWithOpAndArgs(Term,term_TopSymbol(Subterm),term_ArgumentList(Subterm));
661
return eml_RemoveTrivialAtomsAndOps(Term);
663
Subterm = eml_RemoveTrivialAtomsAndOps(term_SecondArgument(Term));
664
Subtop = term_TopSymbol(Subterm);
665
if (symbol_Equal(Subtop,fol_True())) {
666
/* implies(phi,true) -> true */
667
return eml_RplacWithDesignatedPropAtom(Term,fol_True());
669
else if (symbol_Equal(Subtop,fol_False())) {
670
/* implies(phi,false) -> not(phi) */
671
Term = eml_RplacWithOpAndArgs(Term, fol_Not(),
672
list_DeleteElementIfFree(term_ArgumentList(Term),
673
(BOOL (*)())fol_IsFalse, (void (*)())term_Delete));
674
return eml_RemoveTrivialAtomsAndOps(Term);
677
/* Term = implied(...) */
678
else if (symbol_Equal(Top,fol_Implied())) {
679
Subterm = eml_RemoveTrivialAtomsAndOps(term_SecondArgument(Term));
680
Subtop = term_TopSymbol(Subterm);
681
if (symbol_Equal(Subtop,fol_False())) {
682
/* implied(phi,false) -> true */
683
return eml_RplacWithDesignatedPropAtom(Term,fol_True());
685
else if (symbol_Equal(Subtop,fol_True())) {
686
/* implied(phi,true) -> phi */
687
term_Delete(Subterm);
688
Subterm = term_FirstArgument(Term);
689
list_Delete(term_ArgumentList(Term));
690
Term = eml_RplacWithOpAndArgs(Term,term_TopSymbol(Subterm),term_ArgumentList(Subterm));
692
return eml_RemoveTrivialAtomsAndOps(Term);
694
Subterm = eml_RemoveTrivialAtomsAndOps(term_FirstArgument(Term));
695
Subtop = term_TopSymbol(Subterm);
696
if (symbol_Equal(Subtop,fol_True()))
697
/* implied(true,phi) -> true */
698
return eml_RplacWithDesignatedPropAtom(Term,fol_True());
699
else if (symbol_Equal(Subtop,fol_False())) {
700
/* implied(false,phi) -> not(phi) */
701
Term = eml_RplacWithOpAndArgs(Term, fol_Not(),
702
list_DeleteElementIfFree(term_ArgumentList(Term),
703
(BOOL (*)())fol_IsFalse, (void (*)())term_Delete));
704
return eml_RemoveTrivialAtomsAndOps(Term);
707
/* Term = equiv(...) */
708
else if (symbol_Equal(Top,fol_Equiv())) {
709
Subterm = eml_RemoveTrivialAtomsAndOps(term_FirstArgument(Term));
710
Subtop = term_TopSymbol(Subterm);
711
if (symbol_Equal(Subtop,fol_False())) {
712
/* equiv(false,phi) -> not(phi) */
713
Term = eml_RplacWithOpAndArgs(Term, fol_Not(),
714
list_DeleteElementIfFree(term_ArgumentList(Term),
715
(BOOL (*)())fol_IsFalse, (void (*)())term_Delete));
716
return eml_RemoveTrivialAtomsAndOps(Term);
718
else if (symbol_Equal(Subtop,fol_True())) {
719
/* equiv(true,phi) -> phi */
720
term_Delete(Subterm);
721
Subterm = term_SecondArgument(Term);
722
list_Delete(term_ArgumentList(Term));
723
Term = eml_RplacWithOpAndArgs(Term, term_TopSymbol(Subterm),
724
term_ArgumentList(Subterm));
726
return eml_RemoveTrivialAtomsAndOps(Term);
728
Subterm = eml_RemoveTrivialAtomsAndOps(term_SecondArgument(Term));
729
Subtop = term_TopSymbol(Subterm);
730
if (symbol_Equal(Subtop,fol_False())) {
731
/* equiv(phi,false) -> not(phi) */
732
Term = eml_RplacWithOpAndArgs(Term, fol_Not(),
733
list_DeleteElementIfFree(term_ArgumentList(Term),
734
(BOOL (*)())fol_IsFalse, (void (*)())term_Delete));
735
return eml_RemoveTrivialAtomsAndOps(Term);
737
else if (symbol_Equal(Subtop,fol_True())) {
738
/* equiv(phi,true) -> phi */
739
term_Delete(Subterm);
740
Subterm = term_FirstArgument(Term);
741
list_Delete(term_ArgumentList(Term));
742
Term = eml_RplacWithOpAndArgs(Term, term_TopSymbol(Subterm),
743
term_ArgumentList(Subterm));
747
/* Term = comp(...) */
748
else if (symbol_Equal(Top,eml_Comp())) {
749
for (Scan=term_ArgumentList(Term); !list_Empty(Scan); Scan=list_Cdr(Scan)) {
750
Subterm = eml_RemoveTrivialAtomsAndOps(list_Car(Scan));
751
Subtop = term_TopSymbol(Subterm);
752
if (symbol_Equal(Subtop,eml_Id()))
754
else if (symbol_Equal(Subtop,fol_False())) {
755
/* comp(..., false, ...) -> false */
756
return eml_RplacWithDesignatedPropAtom(Term,fol_False());
760
/* comp(..., id, ..., id, ...) -> comp(..., ..., ...) */
761
term_RplacArgumentList(Term,
762
list_DeleteElementIfFree(term_ArgumentList(Term),
763
(BOOL (*)())eml_IsId, (void (*)())term_Delete));
764
if (list_Empty(term_ArgumentList(Term))) {
765
term_RplacTop(Term,eml_Id());
769
return eml_RemoveTrivialOperator(Term); /* comp(alpha) -> alpha */
771
/* Term = sum(...) */
772
else if (symbol_Equal(Top,eml_Sum())) {
773
for (Scan=term_ArgumentList(Term); !list_Empty(Scan); Scan=list_Cdr(Scan)) {
774
Subterm = eml_RemoveTrivialAtomsAndOps(list_Car(Scan));
775
Subtop = term_TopSymbol(Subterm);
776
if (symbol_Equal(Subtop,eml_Div()))
778
else if (symbol_Equal(Subtop,fol_True())) {
779
/* sum(..., true, ...) -> true */
780
return eml_RplacWithDesignatedPropAtom(Term,fol_True());
784
/* sum(..., div, ..., div, ...) -> sum(..., ..., ...) */
785
term_RplacArgumentList(Term,
786
list_DeleteElementIfFree(term_ArgumentList(Term),
787
(BOOL (*)())eml_IsDiv, (void (*)())term_Delete));
788
if (list_Empty(term_ArgumentList(Term))) {
789
term_RplacTop(Term,eml_Div());
793
return eml_RemoveTrivialOperator(Term); /* sum(alpha) -> alpha */
795
/* Term = test(...) */
796
else if (symbol_Equal(Top,eml_Test())) {
797
Subterm = eml_RemoveTrivialAtomsAndOps(term_FirstArgument(Term));
798
Subtop = term_TopSymbol(Subterm);
799
if (symbol_Equal(Subtop,fol_False())) {
800
/* test(false) -> false */
801
return eml_RplacWithDesignatedPropAtom(Term,fol_False());
803
else if (symbol_Equal(Subtop, fol_True())) {
804
/* test(true) -> id */
805
return eml_RplacWithDesignatedPropAtom(Term,eml_Id());
808
/* Term = conv(...) */
809
else if (symbol_Equal(Top,eml_Conv())) {
810
RelSubterm = eml_RemoveTrivialAtomsAndOps(term_FirstArgument(Term));
811
RelSubtop = term_TopSymbol(RelSubterm);
812
if (symbol_Equal(RelSubtop,fol_True()) ||
813
symbol_Equal(RelSubtop,fol_False()) ||
814
symbol_Equal(RelSubtop,eml_Id()) ||
815
symbol_Equal(RelSubtop,eml_Div())) {
816
/* conv(false) -> false, conv(true) -> true, conv(id) -> id, conv(div) -> div */
817
return eml_RplacWithDesignatedPropAtom(Term,RelSubtop);
819
else if (symbol_Equal(RelSubtop,eml_Test())) {
820
/* conv(test(...)) -> test(...) */
821
list_Delete(term_ArgumentList(Term));
822
Term = eml_RplacWithOpAndArgs(Term, RelSubtop, term_ArgumentList(RelSubterm));
823
term_Free(RelSubterm);
827
/* Term = domrestr(...) or Term = ranrestr(...) */
828
else if (symbol_Equal(Top,eml_DomRestr()) || symbol_Equal(Top,eml_RanRestr())) {
829
RelSubterm = eml_RemoveTrivialAtomsAndOps(term_FirstArgument(Term));
830
RelSubtop = term_TopSymbol(RelSubterm);
831
Subterm = eml_RemoveTrivialAtomsAndOps(term_SecondArgument(Term));
832
Subtop = term_TopSymbol(Subterm);
833
if (symbol_Equal(RelSubtop,fol_False()) || symbol_Equal(Subtop,fol_False())) {
834
/* domrestr(false,...), domrestr(...,false) -> false,
835
* ranrestr(false,...), ranrestr(...,false) -> false */
836
return eml_RplacWithDesignatedPropAtom(Term,fol_False());
838
else if (symbol_Equal(Subtop, fol_True())) {
839
/* domrestr(alpha,true) -> alpha, ranrestr(alpha,true) -> alpha */
840
term_Delete(Subterm);
841
list_Delete(term_ArgumentList(Term));
842
Term = eml_RplacWithOpAndArgs(Term, RelSubtop, term_ArgumentList(RelSubterm));
843
term_Free(RelSubterm);
851
static TERM eml_CreateModalTerm(SYMBOL ModOp, LIST RelTermList, TERM PropTerm)
852
/**************************************************************
853
INPUT: A symbol (either box or dia), a list of relational terms,
854
a list with one propositional term.
855
RETURNS: A nested box(..., box(..., box(..., ....)))
856
or dia(..., dia(..., dia(..., ....))) term
857
***************************************************************/
859
if (list_Empty(RelTermList)) {
863
return term_Create(ModOp,
864
list_Cons(list_Car(RelTermList),
865
list_List(eml_CreateModalTerm(ModOp, list_Cdr(RelTermList), PropTerm))));
869
static TERM eml_EliminateComp(TERM Term)
870
/**************************************************************
872
RETURNS: eliminates comp if possible by replacing, e.g.
873
box(comp(..., ...., ....), ....) with
874
box(..., box(..., box(..., ....))).
875
CAUTION: The Term is destructively changed.
876
***************************************************************/
881
Top = term_TopSymbol(Term);
883
/* box(comp(..., ...., ....), ....) -> box(..., box(..., box(..., ....)))
884
dia(comp(..., ...., ....), ....) -> dia(..., dia(..., dia(..., ....))) */
885
if (eml_IsModalOpSymbol(Top)) {
886
RelSubterm = term_FirstArgument(Term);
887
if (symbol_Equal(term_TopSymbol(RelSubterm),eml_Comp())) {
889
ArgsList = list_Cons(list_Car(term_ArgumentList(RelSubterm)),
890
list_List(eml_CreateModalTerm(Top,
891
list_Cdr(term_ArgumentList(RelSubterm)),
892
eml_EliminateComp(term_SecondArgument(Term)))));
893
list_Delete(term_ArgumentList(RelSubterm));
894
term_Free(RelSubterm);
895
list_Delete(term_ArgumentList(Term));
896
Term = eml_RplacWithOpAndArgs(Term, Top, ArgsList);
898
} else if (!symbol_IsPredicate(Top)) {
900
for (Scan=term_ArgumentList(Term);!list_Empty(Scan);Scan=list_Cdr(Scan))
901
eml_EliminateComp(list_Car(Scan));
907
static TERM eml_MakeOneAndOrCompSum(TERM Term)
908
/**************************************************************
910
RETURNS: Takes all arguments of an and together.
911
CAUTION: The Term is destructively changed.
912
***************************************************************/
918
Top = term_TopSymbol(Term);
920
/* and(..., and( ..., ...)) -> and(..., ..., ...) */
921
if (symbol_Equal(Top,fol_And())) {
922
Scan = term_ArgumentList(Term);
923
while (!list_Empty(Scan)) {
924
Subterm = (TERM)list_Car(Scan);
925
eml_MakeOneAndOrCompSum(Subterm);
926
if (symbol_Equal(term_TopSymbol(Subterm),fol_And())) {
927
Scan = list_Cdr(Scan);
928
term_RplacArgumentList(Term,
929
list_Nconc(term_ArgumentList(Subterm),list_PointerDeleteElement(term_ArgumentList(Term),Subterm)));
933
Scan = list_Cdr(Scan);
936
/* or(..., or( ..., ...)) -> or(..., ..., ...) */
937
} else if (symbol_Equal(Top,fol_Or())) {
938
Scan = term_ArgumentList(Term);
939
while (!list_Empty(Scan)) {
940
Subterm = (TERM)list_Car(Scan);
941
eml_MakeOneAndOrCompSum(Subterm);
942
if (symbol_Equal(term_TopSymbol(Subterm),fol_Or())) {
943
Scan = list_Cdr(Scan);
944
term_RplacArgumentList(Term,
945
list_Nconc(term_ArgumentList(Subterm),list_PointerDeleteElement(term_ArgumentList(Term),Subterm)));
949
Scan = list_Cdr(Scan);
952
/* comp(..., comp( ..., ...)) -> comp(..., ..., ...) */
953
} else if (symbol_Equal(Top,eml_Comp())) {
954
Scan = term_ArgumentList(Term);
955
while (!list_Empty(Scan)) {
956
Subterm = (TERM)list_Car(Scan);
957
eml_MakeOneAndOrCompSum(Subterm);
958
if (symbol_Equal(term_TopSymbol(Subterm),eml_Comp())) {
959
Scan = list_Cdr(Scan);
960
term_RplacArgumentList(Term,
961
list_Nconc(term_ArgumentList(Subterm),list_PointerDeleteElement(term_ArgumentList(Term),Subterm)));
965
Scan = list_Cdr(Scan);
968
/* sum(..., sum( ..., ...)) -> sum(..., ..., ...) */
969
} else if (symbol_Equal(Top,eml_Sum())) {
970
Scan = term_ArgumentList(Term);
971
while (!list_Empty(Scan)) {
972
Subterm = (TERM)list_Car(Scan);
973
eml_MakeOneAndOrCompSum(Subterm);
974
if (symbol_Equal(term_TopSymbol(Subterm),eml_Sum())) {
975
Scan = list_Cdr(Scan);
976
term_RplacArgumentList(Term,
977
list_Nconc(term_ArgumentList(Subterm),list_PointerDeleteElement(term_ArgumentList(Term),Subterm)));
981
Scan = list_Cdr(Scan);
984
} else if (!symbol_IsPredicate(Top))
985
for (Scan=term_ArgumentList(Term);!list_Empty(Scan);Scan=list_Cdr(Scan))
986
eml_MakeOneAndOrCompSum(list_Car(Scan));
991
TERM eml_SimplifyQuantors(TERM Term)
992
/**************************************************************
994
RETURNS: The formula after
995
removal of bindings of variables that don't occur in the
996
respective subformula and possible mergings of quantors
997
CAUTION: The term is destrucively changed.
998
NOTE: This procedure conincides with cnf_SimplifyQuantors()
999
***************************************************************/
1004
Top = term_TopSymbol(Term);
1006
if (symbol_IsPredicate(Top) || symbol_Equal(Top,fol_Varlist()))
1009
if (fol_IsQuantifier(Top)) {
1011
TERM Var,Subterm,Aux;
1013
Subterm = term_SecondArgument(Term);
1015
while (symbol_Equal(term_TopSymbol(Subterm),Top)) {
1016
term_RplacArgumentList(term_FirstArgument(Term),
1017
list_Nconc(fol_QuantifierVariables(Term),fol_QuantifierVariables(Subterm)));
1018
term_Free(term_FirstArgument(Subterm));
1019
Aux = term_SecondArgument(Subterm);
1020
list_Delete(term_ArgumentList(Subterm));
1022
list_Rplaca(list_Cdr(term_ArgumentList(Term)),Aux);
1026
for(Scan=fol_QuantifierVariables(Term);!list_Empty(Scan);Scan=list_Cdr(Scan)) {
1027
Var = (TERM)list_Car(Scan);
1028
if (!fol_VarOccursFreely(Var,Subterm))
1029
Vars = list_Cons(Var,Vars);
1031
if (!list_Empty(Vars)) {
1032
Subterm = term_FirstArgument(Term);
1033
term_RplacArgumentList(Subterm,list_NPointerDifference(term_ArgumentList(Subterm),Vars));
1034
list_DeleteWithElement(Vars, (void (*)())term_Delete);
1035
if (list_Empty(term_ArgumentList(Subterm))) {
1036
Subterm = term_SecondArgument(Term);
1037
term_Delete(term_FirstArgument(Term));
1038
list_Delete(term_ArgumentList(Term));
1040
return eml_SimplifyQuantors(Subterm);
1045
for (Scan=term_ArgumentList(Term);!list_Empty(Scan);Scan=list_Cdr(Scan))
1046
list_Rplaca(Scan,eml_SimplifyQuantors(list_Car(Scan)));
1051
TERM eml_ObviousSimplifications(TERM Term, FLAGSTORE Flags)
1052
/**************************************************************
1053
INPUT: An eml formula.
1054
RETURNS: The formula after performing the following simplifications:
1055
- eliminate true, false, id, etc
1056
- remove "or" and "and" with only one argument
1058
CAUTION: The term is destructively changed.
1059
NOTE: This does not obliviate simplification of the first-order
1060
formula. E.g. dia(alpha,true) cannot be reduced in the modal
1062
Nested expression of n-ary associative operations (and, comp,
1063
...) are reduced later.
1064
***************************************************************/
1066
Term = eml_RemoveTrivialAtomsAndOps(Term);
1067
Term = eml_SimplifyQuantors(Term); /* strictly only needed for non-propositional formulae */
1069
/* Attempt to eliminate composition by applying */
1070
if (flag_GetFlagIntValue(Flags, flag_EMLELIMCOMP)) {
1071
Term = eml_MakeOneAndOrCompSum(Term);
1072
Term = eml_EliminateComp(Term);
1078
BOOL eml_IsPropositional(TERM Term)
1079
/**************************************************************
1081
RETURNS: True, if formula does not contain an n-ary predicate symbol
1082
or a first order quantifier.
1083
***************************************************************/
1089
if (term_IsComplex(Term)) {
1090
if (symbol_IsPredicate(term_TopSymbol(Term)) ||
1091
fol_IsQuantifier(term_TopSymbol(Term)))
1094
for(Scan=term_ArgumentList(Term); result && !list_Empty(Scan); Scan=list_Cdr(Scan))
1095
result = eml_IsPropositional(list_Car(Scan));
1101
static TERM eml_RplacPropByFoAtom(TERM Atom, eml_SYMBOLTYPE SymbolType,
1102
int Arity, LIST Args, FLAGSTORE Flags, PRECEDENCE Precedence)
1103
/**************************************************************
1104
INPUT: A propositional atom, a symbol type, a natural number, and a
1106
RETURNS: A first-order atom with the specified arity formed with the
1107
symbol of the specified type and the specified arguments.
1108
The predicate name is built from the propositional name.
1109
EFFECT: If the predicate symbol does not exist in the signature it is
1110
created and inherits its precedence setting.
1111
CAUTION: The atom is destructively changed.
1112
***************************************************************/
1114
SYMBOL propSymbol, foSymbol;
1117
if (list_Empty(term_ArgumentList(Atom)) {
1118
misc_StartErrorReport();
1119
misc_ErrorReport("\n In eml_RplacPropByFoAtom: Propositional atom must not have argument list.");
1120
misc_FinishErrorReport();
1124
propSymbol = term_TopSymbol(Atom);
1126
if (symbol_Equal(propSymbol, fol_True()) ||
1127
symbol_Equal(propSymbol, fol_False())) {
1128
list_DeleteWithElement(Args, (void (*)())term_Delete);
1129
return Atom; /* Attempt to simplify ?? */
1132
if (symbol_Equal(propSymbol, eml_Id())) { /* Arguments should be nil, propositional */
1133
symbol_SetOrdering(Precedence, fol_Equality(), symbol_Ordering(Precedence, eml_Id()));
1134
return eml_RplacWithOpAndArgs(Atom, fol_Equality(), Args);
1136
else if (symbol_Equal(propSymbol, eml_Div())) {
1137
return eml_RplacWithOpAndArgs(Atom, fol_Not(),
1138
list_List(term_Create(fol_Equality(), Args)));
1141
foSymbol = eml_GetFoSymbolAssocWithPropSymbol(propSymbol, Arity, SymbolType);
1144
if (!eml_NaryType(SymbolType) && (foSymbol != symbol__NULL) &&
1145
(symbol_Arity(foSymbol) != Arity)) {
1146
fprintf(stderr, "Symbol %s declared with arity %d, but arity %d required\n",
1147
symbol_Name(foSymbol), symbol_Arity(foSymbol),Arity);
1153
if (foSymbol == symbol__NULL) {
1154
foSymbol = eml_CreateFoSymbol(propSymbol, SymbolType, Arity, symbol_STATLEX, Precedence);
1155
/* Precedence among the first-order symbols is inherited from that among
1156
* the propositional symbols */
1157
symbol_SetOrdering(Precedence, foSymbol,symbol_Ordering(Precedence, propSymbol));
1160
return eml_RplacWithOpAndArgs(Atom, foSymbol, Args);
1163
SYMBOL eml_CreateNarySymbol(SYMBOL PropSymbol, eml_SYMBOLTYPE SymbolType,
1164
const char* NameSuffix, int Arity, int Status, PRECEDENCE Precedence)
1165
/*******************************************************
1166
INPUT: A symbol (which MUST be a propositonal symbol/nullary
1167
predicate symbol), a symbol type (of the fo symbol to be
1168
created), the predefined name suffix, the arity of the new
1169
symbol, the status of the new symbol.
1170
RETURNS: A first-order symbol corresponding to PropSymbol (special for
1171
the functial translation in terms of n-ary predicates with the sorts
1172
encoded in the predicate names).
1173
REMARK: Similar to dfg_SymbolDecl. Prototypical.
1174
********************************************************/
1181
arityStr = string_IntToString(Arity);
1183
size = strlen(eml_PREDNAMEPREFIX[SymbolType])+strlen(symbol_Name(PropSymbol))+1+strlen(arityStr)+strlen(NameSuffix)+1;
1184
newName = (char*)memory_Malloc(sizeof(char)*size);
1185
sprintf(newName,"%s%s_%s%s", eml_PREDNAMEPREFIX[SymbolType],symbol_Name(PropSymbol), arityStr, NameSuffix);
1187
/* Check if this symbol was declared earlier */
1188
symbol = symbol_Lookup(newName);
1190
/* Symbol was declared before
1191
* Check if the old and new symbol type are equal */
1192
/* Eventually we would want more checking to be done here, i.e.
1193
* we need new designated symbol types */
1194
if ( !symbol_IsPredicate(symbol)) {
1195
fprintf(stderr, "In eml_CreateNarySymbol: Symbol %s was already declared as ",
1197
switch (symbol_Type(symbol)) {
1198
case symbol_CONSTANT:
1199
case symbol_FUNCTION:
1200
fputs("function\n", stderr); break;
1201
case symbol_JUNCTOR:
1202
fputs("junctor", stderr); break;
1204
fputs("unknown non-predicate type\n", stderr);
1208
/* Now check the old and new arity if specified */
1209
if (Arity != -2 && Arity != symbol_Arity(symbol)) {
1210
fprintf(stderr, "In eml_CreateNarySymbol: Symbol %s was already declared with arity %d\n",
1211
newName, symbol_Arity(symbol));
1215
/* Symbol was not declared before */
1216
symbol = symbol_CreatePredicate(newName, Arity, Status, Precedence);
1218
string_StringFree(arityStr);
1219
memory_Free(newName,sizeof(char)*size);
1224
static TERM eml_RplacPropByNaryAtom(TERM Atom, eml_SYMBOLTYPE
1225
SymbolType, char* NameSuffix, int Arity, LIST Args,
1226
FLAGSTORE Flags, PRECEDENCE Precedence)
1227
/**************************************************************
1228
INPUT: A propositional atom, a symbol type, a string, a natural
1229
number, and a list of variables.
1230
RETURNS: A first-order atom with the specified arity formed with the
1231
symbol of the specified type and the specified arguments.
1232
The predicate name is built from the propositional name and
1233
(different from eml_RplacPropByFoAtom) the given name suffix.
1234
EFFECT: A new predicate symbol is created and inherits its precedence
1236
CAUTION: The atom is destructively changed.
1237
***************************************************************/
1239
SYMBOL propSymbol, foSymbol;
1241
propSymbol = term_TopSymbol(Atom);
1243
if (symbol_Equal(propSymbol,fol_True()) || symbol_Equal(propSymbol,fol_False())) {
1244
list_DeleteWithElement(Args, (void (*)())term_Delete);
1248
if (flag_GetFlagIntValue(Flags, flag_EMLFFSORTS)) /* with explicit sorts */
1249
foSymbol = eml_CreateNarySymbol(propSymbol, SymbolType,
1250
symbol_Name(propSymbol), Arity, symbol_STATLEX, Precedence);
1251
else /* sort info encoded in predicate names */
1252
foSymbol = eml_CreateNarySymbol(propSymbol, SymbolType, NameSuffix, Arity,
1253
symbol_STATLEX, Precedence);
1254
symbol_SetOrdering(Precedence, foSymbol,symbol_Ordering(Precedence, propSymbol)); /* ?? */
1256
return eml_RplacWithOpAndArgs(Atom, foSymbol, Args);
1259
static TERM eml_EmbedInRelCalculusProp(TERM Term)
1260
/**************************************************************
1261
INPUT: An Eml (propositional) formula.
1262
RETURNS: Its translation into a relational formula as a right
1264
CAUTION: The term is destructively changed.
1265
***************************************************************/
1269
Top = term_TopSymbol(Term);
1272
if (symbol_IsPredicate(Top)) {
1273
list_Delete(term_ArgumentList(Term)); /* shouldn't be needed */
1274
return eml_RplacWithOpAndArgs(Term, eml_Comp(),
1275
list_Cons(term_Copy(Term),
1276
list_List(term_Create(fol_True(), list_Nil()))));
1279
/* Term = not(phi), or(...), and(...), comp(...), sum(...),
1280
* test(phi), domrestr(...), ranrestr(...) */
1281
else if (eml_IsRelationalJunctor(Top)) { /* Seems strange, but makes sense */
1283
for (Scan=term_ArgumentList(Term); !list_Empty(Scan); Scan=list_Cdr(Scan))
1284
eml_EmbedInRelCalculusProp(list_Car(Scan));
1287
/* Term = dia(alpha,phi) */
1288
else if (symbol_Equal(Top, eml_Dia())) {
1290
args = list_Cons(eml_EmbedInRelCalculusRel(term_FirstArgument(Term)),
1291
list_List(eml_EmbedInRelCalculusProp(term_SecondArgument(Term))));
1292
list_Delete(term_ArgumentList(Term));
1293
return eml_RplacWithOpAndArgs(Term, eml_Comp(), args);
1294
/* comp(alpha,tr(phi)) */
1296
/* Term = box(alpha,phi) */
1297
else if (symbol_Equal(Top, eml_Box())) {
1299
helpTerm = term_Create(eml_Comp(),
1300
list_Cons(eml_EmbedInRelCalculusRel(term_FirstArgument(Term)),
1301
list_List(term_Create(fol_Not(),
1302
list_List(eml_EmbedInRelCalculusProp(term_SecondArgument(Term)))))));
1303
list_Delete(term_ArgumentList(Term));
1304
return eml_RplacWithOpAndArgs(Term, fol_Not(), list_List(helpTerm));
1305
/* not(comp(alpha,not(tr(phi)))) */
1307
/* Term = domain(alpha) or Term = range(alpha) */
1308
else if (symbol_Equal(Top,eml_Domain()) || symbol_Equal(Top,eml_Range())) {
1310
term_RplacTop(Term, eml_Comp());
1311
if (symbol_Equal(Top,eml_Domain()))
1312
args = list_Cons(eml_EmbedInRelCalculusRel(term_FirstArgument(Term)),
1313
list_List(term_Create(fol_True(), list_Nil())));
1315
args = list_Cons(term_Create(fol_True(), list_Nil()),
1316
list_List(eml_EmbedInRelCalculusRel(term_FirstArgument(Term))));
1317
list_Delete(term_ArgumentList(Term));
1318
term_RplacArgumentList(Term,args);
1321
/* comp(alpha,true) or comp(true,alpha) */
1324
fprintf(stderr, "\nNo case for %s in eml_EmbedInRelCalculusProp()\n",
1332
static TERM eml_EmbedInRelCalculusRel(TERM Term)
1333
/**************************************************************
1334
INPUT: An Eml (propositional) formula.
1335
RETURNS: Its translation into a relational formula as a right
1337
CAUTION: The term is destructively changed.
1338
***************************************************************/
1343
Top = term_TopSymbol(Term);
1346
if (symbol_IsPredicate(Top)) {
1349
/* Term = test(phi) */
1350
else if (symbol_Equal(Top, eml_Test())) {
1351
args = list_Cons(eml_EmbedInRelCalculusProp(term_FirstArgument(Term)),
1352
list_List(term_Create(eml_Id(), list_Nil())));
1353
list_Delete(term_ArgumentList(Term));
1354
return eml_RplacWithOpAndArgs(Term, fol_And(), args);
1357
/* Term = domrestr(alpha,phi) */
1358
else if (symbol_Equal(Top, eml_DomRestr())) {
1359
args = list_Cons(term_FirstArgument(Term),
1360
list_List(eml_EmbedInRelCalculusProp(term_SecondArgument(Term))));
1361
list_Delete(term_ArgumentList(Term));
1362
return eml_RplacWithOpAndArgs(Term, fol_And(), args);
1363
/* alpha /\ tr(phi) */
1365
/* Term = ranrestr(alpha,phi) */
1366
else if (symbol_Equal(Top, eml_RanRestr())) {
1367
args = list_Cons(term_FirstArgument(Term),
1368
list_List(term_Create(eml_Conv(),
1369
list_List(eml_EmbedInRelCalculusProp(term_SecondArgument(Term))))));
1370
list_Delete(term_ArgumentList(Term));
1371
return eml_RplacWithOpAndArgs(Term, fol_And(), args);
1372
/* alpha /\ conv(tr(phi)) */
1374
/* Term = not(phi), or(...), and(...), comp(...), sum(...) */
1375
/* It is important that this test is done last */
1376
else if (eml_IsRelationalJunctor(Top)) {
1378
for (Scan=term_ArgumentList(Term); !list_Empty(Scan); Scan=list_Cdr(Scan))
1379
eml_EmbedInRelCalculusRel(list_Car(Scan));
1383
fprintf(stderr, "\nNo case for %s in eml_EmbedInRelCalculusRel()\n",
1392
static TERM eml_RelationalTranslationProp(TERM Term, SYMBOL Var,
1393
FLAGSTORE Flags, PRECEDENCE Precedence)
1394
/**************************************************************
1395
INPUT: An eml (propositional) formula and a variable (the free variable).
1396
RETURNS: Its standard (relational) translation.
1397
CAUTION: The term is destructively changed.
1398
***************************************************************/
1402
Top = term_TopSymbol(Term);
1405
if (symbol_IsPredicate(Top)) {
1406
return eml_RplacPropByFoAtom(Term, eml_PROP, 1, list_List(term_Create(Var,list_Nil())), Flags, Precedence);
1408
/* Term = not(phi), Term = or(...) or Term = and(...) */
1409
else if (eml_IsPropJunctor(Top)) {
1411
for (Scan=term_ArgumentList(Term); !list_Empty(Scan); Scan=list_Cdr(Scan))
1412
eml_RelationalTranslationProp(list_Car(Scan),Var, Flags, Precedence);
1415
/* Term = dia(alpha,phi) or Term = box(alpha,phi) */
1416
else if (eml_IsModalOpSymbol(Top)) {
1419
newVar = symbol_CreateStandardVariable();
1420
helpTerm = term_Create(eml_FoJunctorAssocWithPropSymbol(Top),
1421
list_Cons(eml_RelationalTranslationRel(term_FirstArgument(Term),Var,newVar, Flags, Precedence),
1422
list_List(eml_RelationalTranslationProp(term_SecondArgument(Term),newVar, Flags, Precedence))));
1423
list_Delete(term_ArgumentList(Term));
1424
return eml_RplacWithQuantifier(Term, eml_FoQuantAssocWithPropSymbol(Top), list_List(term_Create(newVar,list_Nil())),
1425
list_List(helpTerm));
1426
/* exists y tr(alpha)(x,y) /\ tr(phi)(y) or
1427
* forall y tr(alpha)(x,y) -> tr(phi)(y) */
1429
/* Term = domain(alpha) or Term = range(alpha) */
1430
else if (symbol_Equal(Top,eml_Domain()) || symbol_Equal(Top,eml_Range())) {
1433
newVar = symbol_CreateStandardVariable();
1434
if (symbol_Equal(Top,eml_Domain()))
1435
helpTerm = eml_RelationalTranslationRel(term_FirstArgument(Term),Var,newVar, Flags, Precedence);
1437
helpTerm = eml_RelationalTranslationRel(term_FirstArgument(Term),newVar,Var, Flags, Precedence);
1439
list_Delete(term_ArgumentList(Term));
1440
return eml_RplacWithQuantifier(Term, eml_FoQuantAssocWithPropSymbol(Top), list_List(term_Create(newVar,list_Nil())),
1441
list_List(helpTerm));
1442
/* exists y tr(alpha)(x,y) or exists y tr(alpha)(y,x) */
1445
fprintf(stderr, "\nNo case for %s in eml_RelationalTranslationProp()\n",
1453
static TERM eml_RelationalTranslationRel(TERM Term, SYMBOL VarX, SYMBOL VarY,
1454
FLAGSTORE Flags, PRECEDENCE Precedence)
1455
/**************************************************************
1456
INPUT: An eml (relational) formula, two variables (the free
1457
variables), a string encoding of the sorts of the arguments
1458
and the modal depth.
1459
RETURNS: Its standard (relational) translation.
1460
CAUTION: The term is destructively changed.
1461
***************************************************************/
1465
Top = term_TopSymbol(Term);
1468
if (symbol_IsPredicate(Top)) {
1469
return eml_RplacPropByFoAtom(Term, eml_REL, 2, list_Cons(term_Create(VarX,list_Nil()),list_List(term_Create(VarY,list_Nil()))), Flags, Precedence);
1471
/* Term = not(alpha), Term = or(...) or Term = and(...) */
1472
else if (eml_IsPropJunctor(Top)) {
1474
for (Scan=term_ArgumentList(Term); !list_Empty(Scan); Scan=list_Cdr(Scan))
1475
eml_RelationalTranslationRel(list_Car(Scan),VarX,VarY, Flags, Precedence);
1478
/* Term = conv(alpha) */
1479
else if (symbol_Equal(Top,eml_Conv())) {
1481
helpTerm = eml_RelationalTranslationRel(term_FirstArgument(Term),VarY,VarX, Flags, Precedence);
1482
list_Delete(term_ArgumentList(Term));
1483
Term = eml_RplacWithOpAndArgs(Term, term_TopSymbol(helpTerm),
1484
term_ArgumentList(helpTerm));
1485
term_Free(helpTerm);
1487
/* tr(alpha)(y,x) */
1489
/* Term = comp(...) or sum(...)*/
1490
else if (symbol_Equal(Top,eml_Comp()) || symbol_Equal(Top,eml_Sum())) {
1495
varList = list_Nil();
1496
for (Scan=term_ArgumentList(Term); !list_Empty(list_Cdr(Scan)); Scan=list_Cdr(Scan)) {
1497
newVar = symbol_CreateStandardVariable();
1498
varList = list_Nconc(varList, list_List(term_Create(newVar,list_Nil())));
1499
eml_RelationalTranslationRel(list_Car(Scan),var,newVar, Flags, Precedence);
1502
eml_RelationalTranslationRel(list_Car(Scan),var,VarY, Flags, Precedence);
1504
helpTerm = term_Create(eml_FoJunctorAssocWithPropSymbol(Top), term_ArgumentList(Term)); /* Sharing including argument list */
1505
return eml_RplacWithQuantifier(Term,
1506
eml_FoQuantAssocWithPropSymbol(Top), varList, list_List(helpTerm));
1507
/* exists z1,z2 tr(alpha1)(x,z1) /\ tr(alpha2)(z1,z2) /\ tr(alpha3)(z2,y) ... or
1508
* forall z1,z2 tr(alpha1)(x,z1) \/ tr(alpha2)(z1,z2) \/ tr(alpha3)(z2,y) ... */
1510
/* Term = test(phi) */
1511
else if (symbol_Equal(Top,eml_Test())) {
1513
helpTerm = eml_RelationalTranslationProp(term_FirstArgument(Term),VarY, Flags, Precedence);
1514
list_Delete(term_ArgumentList(Term));
1515
return eml_RplacWithOpAndArgs(Term, fol_And(),
1516
list_Cons(term_Create(fol_Equality(),
1517
list_Cons(term_Create(VarX,list_Nil()), list_List(term_Create(VarY,list_Nil())))),
1518
list_List(helpTerm)));
1519
/* equal(x,y) /\ tr(phi)(y) */
1521
/* Term = domrestr(alpha,phi) or ranrestr(alpha,phi) */
1522
else if (symbol_Equal(Top,eml_DomRestr()) || symbol_Equal(Top,eml_RanRestr())) {
1523
TERM helpTerm, helpTermRel;
1524
helpTermRel = eml_RelationalTranslationRel(term_FirstArgument(Term),VarX,VarY, Flags, Precedence);
1525
if (symbol_Equal(Top,eml_DomRestr()))
1526
helpTerm = eml_RelationalTranslationProp(term_SecondArgument(Term),VarX, Flags, Precedence);
1528
helpTerm = eml_RelationalTranslationProp(term_SecondArgument(Term),VarY, Flags, Precedence);
1529
list_Delete(term_ArgumentList(Term));
1530
return eml_RplacWithOpAndArgs(Term, fol_And(),
1531
list_Cons(helpTermRel, list_List(helpTerm)));
1532
/* tr(alpha)(x,y) /\ tr(phi)(x) or tr(alpha)(x,y) /\ tr(phi)(y) */
1535
fprintf(stderr, "\nNo case for %s in eml_RelationalTranslationRel()\n",
1543
static TERM eml_RelationalTranslation(TERM Term, FLAGSTORE Flags, PRECEDENCE Precedence)
1544
/**************************************************************
1545
INPUT: An eml (propositional) formula.
1546
RETURNS: Its standard (relational) translation.
1547
CAUTION: The term is destructively changed.
1548
***************************************************************/
1550
TERM newVarX, helpTerm;
1552
symbol_ResetStandardVarCounter();
1554
newVarX = term_Create(symbol_CreateStandardVariable(), list_Nil());
1556
/* Embedding into the relational calculus */
1557
if (flag_GetFlagIntValue(Flags, flag_EML2REL)) {
1560
Term = eml_EmbedInRelCalculusProp(Term);
1561
if (flag_GetFlagIntValue(Flags, flag_EMLPTRANS)) {
1562
printf("\n [Rel] \t");fol_PrintDFG(Term);
1565
newVarY = term_Create(symbol_CreateStandardVariable(), list_Nil());
1566
helpTerm = eml_RelationalTranslationRel(Term,term_TopSymbol(newVarX),term_TopSymbol(newVarY), Flags, Precedence);
1568
if (flag_GetFlagIntValue(Flags, flag_EMLPTRANS))
1569
printf("\n [RelTr] \t");
1570
return term_Create(fol_All(), list_Cons(term_Create(fol_Varlist(),list_Cons(newVarX,list_List(newVarY))), list_List(helpTerm)));
1571
/* forall x y tr(Term,x,y) */
1573
/* Relational functional/path-based translation */
1574
else if (flag_GetFlagIntValue(Flags, flag_EMLFNARY)) {
1575
char nameSuffix[] = "";
1577
flag_SetFlagIntValue(Flags, flag_EMLFFSORTS, flag_EMLFFSORTSOFF);
1578
/* Don't use explicit sorts! Important for creation of
1579
* new atoms in eml_RplacPropByNaryAtom() */
1581
helpTerm = eml_RelFunctTranslProp(Term, term_TopSymbol(newVarX), nameSuffix, Flags, Precedence);
1583
if (flag_GetFlagIntValue(Flags, flag_EMLPTRANS))
1584
printf("\n [RelFuncTr] \t");
1585
return term_Create(fol_All(), list_Cons(term_Create(fol_Varlist(),list_List(newVarX)), list_List(helpTerm)));
1587
/* Standard relational translation */
1589
helpTerm = eml_RelationalTranslationProp(Term,term_TopSymbol(newVarX), Flags, Precedence);
1591
if (flag_GetFlagIntValue(Flags, flag_EMLPTRANS))
1592
printf("\n [RelTr] \t");
1593
return term_Create(fol_All(), list_Cons(term_Create(fol_Varlist(),list_List(newVarX)), list_List(helpTerm)));
1594
/* forall x tr(Term,x) */
1598
static TERM eml_FunctTranslItoNaryPredProp(TERM Term, LIST VarList,
1599
char* SortEncoding, int VarListLength,
1600
FLAGSTORE Flags, PRECEDENCE Precedence)
1601
/**************************************************************
1602
INPUT: An eml (propositional) formula, a variable list, a string
1603
encoding of the sorts of the arguments and the length of the
1605
RETURNS: Its functional translation ito n-ary predicates.
1606
CAUTION: The term is destructively changed.
1607
***************************************************************/
1611
Top = term_TopSymbol(Term);
1614
if (VarListLength != list_Length(VarList)) {
1615
fprintf(stderr, "Arity VarListLength conflict\n");
1622
if (symbol_IsPredicate(Top)) {
1623
VarList = list_CopyWithElement(VarList,(POINTER (*)())term_Copy);
1624
return eml_RplacPropByNaryAtom(Term, eml_NARYPROP, SortEncoding,
1625
VarListLength, VarList, Flags, Precedence);
1627
/* Term = not(phi), Term = or(...) or Term = and(...) */
1628
else if (eml_IsPropJunctor(Top)) {
1630
for (Scan=term_ArgumentList(Term); !list_Empty(Scan); Scan=list_Cdr(Scan))
1631
eml_FunctTranslItoNaryPredProp(list_Car(Scan), VarList,
1632
SortEncoding, VarListLength, Flags, Precedence);
1635
/* Term = dia(r,phi) or Term = box(r,phi) */
1636
else if (eml_IsModalOpSymbol(Top)) {
1637
TERM relSubTerm, newVar, helpTerm, anotherHelpTerm;
1639
char* newSortEncoding;
1642
relSubTerm = term_FirstArgument(Term);
1643
newVar = term_Create(symbol_CreateStandardVariable(), list_Nil());
1644
newVarList = list_Nconc(list_CopyWithElement(VarList,(POINTER (*)())term_Copy), list_List(newVar));
1646
size = strlen(SortEncoding)+strlen(symbol_Name(term_TopSymbol(relSubTerm)))+1;
1647
newSortEncoding = memory_Malloc(size*sizeof(char));
1648
sprintf(newSortEncoding,"%s%s", SortEncoding, symbol_Name(term_TopSymbol(relSubTerm)));
1650
if (flag_GetFlagIntValue(Flags, flag_EMLFUNCNDEQ)) {
1651
helpTerm = eml_BuildSortQuantifierFor(Term, Top, term_TopSymbol(relSubTerm),
1652
term_TopSymbol(newVar), flag_GetFlagIntValue(Flags, flag_EMLFFSORTS),
1653
list_List(eml_FunctTranslItoNaryPredProp(term_SecondArgument(Term),
1654
newVarList, newSortEncoding, VarListLength+1, Flags, Precedence)),
1655
(POINTER (*)())eml_CreateQuantifier, Precedence);
1656
list_Delete(term_ArgumentList(Term));
1657
anotherHelpTerm = eml_RplacWithOpAndArgs(Term, eml_FoJunctorAssocWithPropSymbol(Top),
1658
list_Cons(eml_FunctTranslItoNaryPredRel(relSubTerm,
1659
VarList, SortEncoding, VarListLength, Flags, Precedence),
1660
list_List(helpTerm)));
1661
list_DeleteWithElement(newVarList,(void (*)())term_Delete);
1662
return anotherHelpTerm;
1663
/* nde_r(vl) /\ exists y_r tr(phi)(vl,y) or
1664
* nde_r(vl) -> forall y_r tr(phi)(vl,y) */
1667
TERM relSubTermCopy = term_Copy(relSubTerm); /* make a copy; important */
1668
helpTerm = term_Create(eml_FoJunctorAssocWithPropSymbol(Top),
1669
list_Cons(eml_FunctTranslItoNaryPredRel(relSubTerm,
1670
VarList, SortEncoding, VarListLength, Flags, Precedence),
1671
list_List(eml_FunctTranslItoNaryPredProp(term_SecondArgument(Term),
1672
newVarList, newSortEncoding, VarListLength+1, Flags, Precedence))));
1673
list_Delete(term_ArgumentList(Term));
1674
anotherHelpTerm = eml_BuildSortQuantifierFor(Term, Top,
1675
term_TopSymbol(relSubTermCopy), term_TopSymbol(newVar),
1676
flag_GetFlagIntValue(Flags, flag_EMLFFSORTS),
1677
list_List(helpTerm), (POINTER (*)())eml_RplacWithQuantifier, Precedence);
1678
list_DeleteWithElement(newVarList,(void (*)())term_Delete);
1679
term_Delete(relSubTermCopy);
1680
return anotherHelpTerm;
1681
/* exists y_r nde_r(vl) /\ tr(phi)(vl,y) or
1682
* forall y_r nde_r(vl) -> tr(phi)(vl,y) */
1685
memory_Free(newSortEncoding,size*sizeof(char));
1688
fprintf(stderr, "\nNo case for %s in eml_FunctTranslItoNaryPredProp()\n",
1696
static TERM eml_FunctTranslItoNaryPredRel(TERM Term, LIST VarList,
1697
char* SortEncoding, int VarListLength,
1698
FLAGSTORE Flags, PRECEDENCE Precedence)
1699
/**************************************************************
1700
INPUT: An EML relational formula, a variable list, a string (encoding
1701
the sorts of the accessibility relations in the scope), and
1702
the length of the variable list (corresponds to the modal
1704
RETURNS: Its functional translation ito n-ary predicates.
1705
CAUTION: The term is destructively changed.
1706
***************************************************************/
1710
Top = term_TopSymbol(Term);
1713
if (symbol_IsPredicate(Top)) {
1714
switch (flag_GetFlagIntValue(Flags, flag_EMLTHEORY)) {
1715
case flag_EMLTHEORYKD:
1716
return eml_RplacWithDesignatedPropAtom(Term, fol_True());
1718
case flag_EMLTHEORYK:
1719
VarList = list_CopyWithElement(VarList,(POINTER (*)())term_Copy);
1720
return eml_RplacPropByNaryAtom(Term, eml_NARYNDE,
1721
SortEncoding, VarListLength, VarList, Flags, Precedence);
1724
fprintf(stderr, "\nThe option EMLTheory = %d is not implemented in eml_FunctTranslItoNaryPredRel()\n",
1725
flag_GetFlagIntValue(Flags, flag_EMLTHEORY));
1732
fprintf(stderr, "\nNo case for %s in eml_FunctTranslItoNaryPredRel()\n",
1739
static TERM eml_FunctTranslProp(TERM Term, TERM WorldPath,
1740
FLAGSTORE Flags, PRECEDENCE Precedence)
1741
/**************************************************************
1742
INPUT: An eml (propositional) formula, a variable list and its
1744
RETURNS: Its functional translation.
1745
CAUTION: The term is destructively changed.
1746
NOTE: WorldPath needs to be copied before it is "used"
1747
***************************************************************/
1751
Top = term_TopSymbol(Term);
1754
if (symbol_IsPredicate(Top)) {
1755
return eml_RplacPropByFoAtom(Term, eml_PROP, 1, list_List(term_Copy(WorldPath)), Flags, Precedence);
1757
/* Term = not(phi), Term = or(...) or Term = and(...) */
1758
else if (eml_IsPropJunctor(Top)) {
1760
for (Scan=term_ArgumentList(Term); !list_Empty(Scan); Scan=list_Cdr(Scan))
1761
eml_FunctTranslProp(list_Car(Scan), WorldPath, Flags, Precedence);
1764
/* Term = dia(alpha,phi) or Term = box(alpha,phi) */
1765
else if (eml_IsModalOpSymbol(Top)) {
1766
TERM newVar, newWorldPath, relSubTerm, helpTerm, anotherHelpTerm;
1767
relSubTerm = term_FirstArgument(Term);
1768
newVar = term_Create(symbol_CreateStandardVariable(), list_Nil());
1769
newWorldPath = term_Create(eml_ApplyFunct(), list_Cons(term_Copy(WorldPath),
1770
list_List(newVar)));
1771
if (flag_GetFlagIntValue(Flags, flag_EMLFUNCNDEQ)) {
1772
helpTerm = eml_BuildSortQuantifierFor(Term, Top, term_TopSymbol(relSubTerm),
1773
term_TopSymbol(newVar), TRUE,
1774
list_List(eml_FunctTranslProp(term_SecondArgument(Term),
1775
newWorldPath, Flags, Precedence)), (POINTER (*)())eml_CreateQuantifier, Precedence);
1776
/*printf("\n [*]\t"); fol_PrintDFG(helpTerm);*/
1777
list_Delete(term_ArgumentList(Term));
1778
anotherHelpTerm = eml_RplacWithOpAndArgs(Term, eml_FoJunctorAssocWithPropSymbol(Top),
1779
list_Cons(eml_FunctTranslRel(relSubTerm, WorldPath, Flags, Precedence),
1780
list_List(helpTerm)));
1781
/*printf("\n [**]\t"); fol_PrintDFG(anotherHelpTerm);*/
1782
term_Delete(newWorldPath);
1783
return anotherHelpTerm;
1784
/* nde_r(wp) /\ exists y_r tr(phi)(app(wp,y_r)) or
1785
* nde_r(wp) -> forall y_r tr(phi)(app(wp,y_r)) */
1788
helpTerm = term_Create(eml_FoJunctorAssocWithPropSymbol(Top),
1789
list_Cons(eml_FunctTranslRel(relSubTerm, WorldPath, Flags, Precedence),
1790
list_List(eml_FunctTranslProp(term_SecondArgument(Term), newWorldPath, Flags, Precedence))));
1791
list_Delete(term_ArgumentList(Term));
1792
anotherHelpTerm = eml_BuildSortQuantifierFor(Term, Top, term_TopSymbol(relSubTerm),
1793
term_TopSymbol(newVar), TRUE,
1794
list_List(helpTerm), (POINTER (*)())eml_RplacWithQuantifier, Precedence);
1795
term_Delete(newWorldPath);
1796
return anotherHelpTerm;
1797
/* exists y_r nde_r(wp) /\ tr(phi)(app(wp,y_r)) or
1798
* forall y_r nde_r(wp) -> tr(phi)(app(wp,y_r)) */
1802
fprintf(stderr, "\nNo case for %s in eml_FunctTranslProp()\n",
1810
static TERM eml_FunctTranslRel(TERM Term, TERM WorldPath,
1811
FLAGSTORE Flags, PRECEDENCE Precedence)
1812
/**************************************************************
1813
INPUT: An eml (propositional) formula, a variable list and its
1815
RETURNS: Its functional translation.
1816
CAUTION: The term is destructively changed.
1817
***************************************************************/
1821
Top = term_TopSymbol(Term);
1824
if (symbol_IsPredicate(Top)) {
1825
switch (flag_GetFlagIntValue(Flags, flag_EMLTHEORY)) {
1826
case flag_EMLTHEORYKD:
1827
return eml_RplacWithDesignatedPropAtom(Term, fol_True());
1829
case flag_EMLTHEORYK:
1830
return eml_RplacPropByFoAtom(Term, eml_NDE, 1, list_List(term_Copy(WorldPath)), Flags, Precedence);
1833
fprintf(stderr, "\nThe option EMLTheory = %d is not implemented in eml_FunctTranslRel()\n",
1834
flag_GetFlagIntValue(Flags, flag_EMLTHEORY));
1841
fprintf(stderr, "\nNo case for %s in eml_FunctTranslRel()\n",
1849
static TERM eml_FunctionalTranslation(TERM Term, BOOL ItoNaryPreds,
1850
FLAGSTORE Flags, PRECEDENCE Precedence)
1851
/**************************************************************
1852
INPUT: An eml (propositional) formula and a flag.
1853
RETURNS: Its functional translation. If the flag is true the
1854
translation is into ordered first-order logic or the
1855
Bernays-Schoenfinkel class, meaning n-ary predicates
1857
CAUTION: The term is destructively changed.
1858
***************************************************************/
1860
symbol_ResetStandardVarCounter();
1863
char nameSuffix[] = "";
1865
if (flag_GetFlagIntValue(Flags, flag_EMLPTRANS))
1866
printf("\n [FuncFTr] \t");
1867
Term = eml_FunctTranslItoNaryPredProp(Term, list_Nil(), nameSuffix, 0, Flags, Precedence);
1868
/* Check whether sharing is possible on the name suffixes,
1869
* e.g. whether the iterative allocation of new memory in
1870
* eml_FunctTranslItoNaryPredProp is necessary. */
1872
/* note: without world quantifier */
1875
TERM newVar, helpTerm;
1876
if (flag_GetFlagIntValue(Flags, flag_EMLPTRANS))
1877
printf("\n [FuncTr] \t");
1878
newVar = term_Create(symbol_CreateStandardVariable(), list_Nil());
1879
helpTerm = eml_FunctTranslProp(Term,newVar, Flags, Precedence);
1880
/*printf("\n [**]\t"); fol_PrintDFG(helpTerm);*/
1881
return term_Create(fol_All(), list_Cons(term_Create(fol_Varlist(),list_List(newVar)), list_List(helpTerm)));
1882
/* forall x tr(Term,x) */
1887
static TERM eml_SemiFunctTranslProp(TERM Term, TERM WorldTerm, int Polarity,
1888
FLAGSTORE Flags, PRECEDENCE Precedence)
1889
/**************************************************************
1890
INPUT: An eml (propositional) formula, term of type world, and the
1891
polarity of the formula (Term) in the original formula
1893
RETURNS: Its functional translation.
1894
CAUTION: The term is destructively changed.
1895
***************************************************************/
1899
Top = term_TopSymbol(Term);
1902
if (symbol_IsPredicate(Top)) {
1903
return eml_RplacPropByFoAtom(Term, eml_PROP, 1, list_List(term_Copy(WorldTerm)), Flags, Precedence);
1905
/* Term = not(phi) */
1906
else if (eml_IsNotSymbol(Top)) {
1907
eml_SemiFunctTranslProp(term_FirstArgument(Term),
1908
WorldTerm, Polarity * -1, Flags, Precedence);
1911
/* Term = implies(...) */
1912
else if (eml_IsImpliesSymbol(Top)) {
1913
eml_SemiFunctTranslProp(term_FirstArgument(Term), WorldTerm, Polarity * -1, Flags, Precedence);
1914
eml_SemiFunctTranslProp(term_SecondArgument(Term), WorldTerm, Polarity, Flags, Precedence);
1917
/* Term = implied(...) */
1918
else if (eml_IsImpliedSymbol(Top)) {
1919
eml_SemiFunctTranslProp(term_SecondArgument(Term), WorldTerm, Polarity * -1, Flags, Precedence);
1920
eml_SemiFunctTranslProp(term_FirstArgument(Term), WorldTerm, Polarity, Flags, Precedence);
1923
/* Term = equiv(...) */
1924
else if (eml_IsEquivSymbol(Top)) {
1925
TERM termL, termR, termLneg, termRneg;
1926
termL = term_FirstArgument(Term);
1927
termR = term_SecondArgument(Term);
1928
termLneg = term_Create(fol_Not(), list_List(term_Copy(termL)));
1929
termRneg = term_Create(fol_Not(), list_List(term_Copy(termR)));
1930
if ( Polarity == 1 ) {
1931
term_RplacTop(Term, fol_And());
1932
list_Rplaca(term_ArgumentList(Term),
1933
term_Create(fol_Or(), list_Cons(termLneg, list_List(termR))));
1934
list_RplacSecond(term_ArgumentList(Term),
1935
term_Create(fol_Or(), list_Cons(termRneg, list_List(termL))));
1937
else if (Polarity == -1) {
1938
term_RplacTop(Term, fol_Or());
1939
list_Rplaca(term_ArgumentList(Term),
1940
term_Create(fol_And(), list_Cons(termLneg, list_List(termRneg))));
1941
list_RplacSecond(term_ArgumentList(Term),
1942
term_Create(fol_And(), list_Cons(termL, list_List(termR))));
1944
eml_SemiFunctTranslProp(Term, WorldTerm, Polarity, Flags, Precedence);
1947
/* Term = or(...), Term = and(...) */
1948
/* must be tested after eml_IsNotSymbol, eml_IsImpliesSymbol amd eml_IsEquivSymbol */
1949
else if (eml_IsPropJunctor(Top)) {
1951
for (Scan = term_ArgumentList(Term);
1953
Scan = list_Cdr(Scan))
1954
eml_SemiFunctTranslProp(list_Car(Scan), WorldTerm, Polarity, Flags, Precedence);
1957
else if (eml_IsModalOpSymbol(Top)) {
1958
/* Term = dia(alpha,phi), in the negation normal form (!) */
1959
if ( ( eml_IsDiaSymbol(Top) && (Polarity == 1) ) ||
1960
( eml_IsBoxSymbol(Top) && (Polarity == -1) ) ) {
1961
TERM newVar, newWorldTerm, relSubTerm, helpTerm, anotherHelpTerm;
1962
relSubTerm = term_FirstArgument(Term);
1963
newVar = term_Create(symbol_CreateStandardVariable(), list_Nil());
1964
newWorldTerm = term_Create(eml_ApplyFunct(),
1965
list_Cons(term_Copy(WorldTerm), list_List(newVar)));
1966
if (flag_GetFlagIntValue(Flags, flag_EMLFUNCNDEQ)) {
1967
helpTerm = eml_BuildSortQuantifierFor(Term, Top, term_TopSymbol(relSubTerm), term_TopSymbol(newVar), TRUE,
1968
list_List(eml_SemiFunctTranslProp(term_SecondArgument(Term),
1969
newWorldTerm, Polarity, Flags, Precedence)),
1970
(POINTER (*)())eml_CreateQuantifier, Precedence);
1971
list_Delete(term_ArgumentList(Term));
1972
anotherHelpTerm = eml_RplacWithOpAndArgs(Term, eml_FoJunctorAssocWithPropSymbol(Top),
1973
list_Cons(eml_SemiFunctTranslRelDia(relSubTerm, WorldTerm, Flags, Precedence),
1974
list_List(helpTerm)));
1975
term_Delete(newWorldTerm);
1976
return anotherHelpTerm;
1977
/* nde_r(w) /\ exists y_r tr(phi)(app(w,y_r)) */
1980
helpTerm = term_Create(eml_FoJunctorAssocWithPropSymbol(Top),
1981
list_Cons(eml_SemiFunctTranslRelDia(relSubTerm, WorldTerm, Flags, Precedence),
1982
list_List(eml_SemiFunctTranslProp(term_SecondArgument(Term), newWorldTerm, Polarity, Flags, Precedence))));
1983
list_Delete(term_ArgumentList(Term));
1984
anotherHelpTerm = eml_BuildSortQuantifierFor(Term, Top, term_TopSymbol(relSubTerm),
1985
term_TopSymbol(newVar), TRUE,
1986
list_List(helpTerm), (POINTER (*)())eml_RplacWithQuantifier, Precedence);
1987
term_Delete(newWorldTerm);
1988
return anotherHelpTerm;
1989
/* exists y_r nde_r(w) /\ tr(phi)(app(w,y_r)) */
1992
/* Term = box(alpha,phi), in the negation normal form (!) */
1994
TERM newVar, helpTerm;
1995
newVar = term_Create(symbol_CreateStandardVariable(), list_Nil());
1996
helpTerm = term_Create(eml_FoJunctorAssocWithPropSymbol(Top),
1997
list_Cons(eml_SemiFunctTranslRelBox(term_FirstArgument(Term), WorldTerm, newVar, Flags, Precedence),
1998
list_List(eml_SemiFunctTranslProp(term_SecondArgument(Term), newVar, Polarity, Flags, Precedence))));
1999
list_Delete(term_ArgumentList(Term));
2000
return eml_RplacWithQuantifier(Term, eml_FoQuantAssocWithPropSymbol(Top), list_List(newVar),
2001
list_List(helpTerm));
2002
/* forall y tr(alpha)(w,y) -> tr(phi)(y) */
2006
fprintf(stderr, "\nNo case for %s in eml_SemiFunctTranslProp()\n",
2015
static TERM eml_SemiFunctTranslRelDia(TERM Term, TERM WorldTerm,
2016
FLAGSTORE Flags, PRECEDENCE Precedence)
2017
/**************************************************************
2018
INPUT: An eml (propositional) formula, argument term.
2019
RETURNS: Its semi functional translation.
2020
CAUTION: The term is destructively changed.
2021
***************************************************************/
2025
Top = term_TopSymbol(Term);
2028
if (symbol_IsPredicate(Top)) {
2029
switch (flag_GetFlagIntValue(Flags, flag_EMLTHEORY)) {
2030
case flag_EMLTHEORYKD:
2031
return eml_RplacWithDesignatedPropAtom(Term, fol_True());
2033
case flag_EMLTHEORYK:
2034
return eml_RplacPropByFoAtom(Term, eml_SEMIFNDE, 1, list_List(term_Copy(WorldTerm)), Flags, Precedence);
2037
fprintf(stderr, "\nThe option EMLTheory = %d is not implemented in eml_SemiFunctTranslRel()\n",
2038
flag_GetFlagIntValue(Flags, flag_EMLTHEORY));
2045
fprintf(stderr, "\nNo case for %s in eml_SemiFunctTranslRel()\n",
2052
static TERM eml_SemiFunctTranslRelBox(TERM Term, TERM WorldTerm, TERM VarY,
2053
FLAGSTORE Flags, PRECEDENCE Precedence)
2054
/**************************************************************
2055
INPUT: An eml (relational) formula, a term and a variable
2056
(the free variable).
2057
RETURNS: Its standard (relational) translation.
2058
CAUTION: The term is destructively changed.
2059
***************************************************************/
2063
Top = term_TopSymbol(Term);
2066
if (symbol_IsPredicate(Top)) {
2067
return eml_RplacPropByFoAtom(Term, eml_REL, 2,
2068
list_Cons(term_Copy(WorldTerm), list_List(term_Copy(VarY))), Flags, Precedence);
2071
fprintf(stderr, "\nNo case for %s in eml_SemiFunctTranslRelBox()\n",
2081
static TERM eml_SemiFunctionalTranslation(TERM Term, int Polarity,
2082
FLAGSTORE Flags, PRECEDENCE Precedence)
2083
/**************************************************************
2084
INPUT: An eml (propositional) formula.
2085
RETURNS: Its semi functional translation.
2086
CAUTION: The term is destructively changed.
2087
***************************************************************/
2089
TERM newVar, helpTerm;
2091
symbol_ResetStandardVarCounter();
2093
if (flag_GetFlagIntValue(Flags, flag_EMLPTRANS))
2094
printf("\n [SemiFuncTr] \t");
2095
newVar = term_Create(symbol_CreateStandardVariable(), list_Nil());
2096
helpTerm = eml_SemiFunctTranslProp(Term, newVar, Polarity, Flags, Precedence);
2097
return term_Create(fol_All(), list_Cons(term_Create(fol_Varlist(),list_List(newVar)), list_List(helpTerm)));
2098
/* forall x tr(Term,x) */
2104
static TERM eml_RelFunctTranslProp(TERM Term, SYMBOL Var,
2105
char* SortEncoding, FLAGSTORE Flags, PRECEDENCE Precedence)
2106
/**************************************************************
2107
INPUT: An eml (propositional) formula, a variable, a string
2108
encoding of the sorts of the arguments and the modal depth.
2109
RETURNS: Its translation using the relational functional/path-based
2110
encoding of de Rijke et al.
2111
CAUTION: The term is destructively changed.
2112
***************************************************************/
2116
Top = term_TopSymbol(Term);
2119
if (symbol_IsPredicate(Top)) {
2120
return eml_RplacPropByNaryAtom(Term, eml_PROP, SortEncoding,
2121
1, list_List(term_Create(Var,list_Nil())), Flags, Precedence);
2123
/* Term = not(phi), Term = or(...) or Term = and(...) */
2124
else if (eml_IsPropJunctor(Top)) {
2126
for (Scan=term_ArgumentList(Term); !list_Empty(Scan); Scan=list_Cdr(Scan))
2127
eml_RelFunctTranslProp(list_Car(Scan), Var,
2128
SortEncoding, Flags, Precedence);
2131
/* Term = dia(r,phi) or Term = box(r,phi) */
2132
else if (eml_IsModalOpSymbol(Top)) {
2136
char* newSortEncoding;
2138
newVar = symbol_CreateStandardVariable();
2140
relSubTop = term_TopSymbol(term_FirstArgument(Term));
2141
size = strlen(SortEncoding)+strlen(symbol_Name(relSubTop))+1;
2142
newSortEncoding = (char*)memory_Malloc(size*sizeof(char));
2143
sprintf(newSortEncoding,"%s%s", SortEncoding, symbol_Name(relSubTop));
2144
helpTerm = term_Create(eml_FoJunctorAssocWithPropSymbol(Top),
2145
list_Cons(eml_RelFunctTranslRel(term_FirstArgument(Term),Var,newVar,newSortEncoding, Flags, Precedence),
2146
list_List(eml_RelFunctTranslProp(term_SecondArgument(Term),newVar,newSortEncoding, Flags, Precedence))));
2147
list_Delete(term_ArgumentList(Term));
2148
memory_Free(newSortEncoding,size*sizeof(char));
2149
return eml_RplacWithQuantifier(Term, eml_FoQuantAssocWithPropSymbol(Top), list_List(term_Create(newVar,list_Nil())),
2150
list_List(helpTerm));
2151
/* exists y R_r(x,y) /\ tr(phi)(y) or
2152
* forall y R_r(x,y) -> tr(phi)(y) */
2155
fprintf(stderr, "\nNo case for %s in eml_RelFunctTranslProp()\n",
2163
static TERM eml_RelFunctTranslRel(TERM Term, SYMBOL VarX, SYMBOL VarY,
2164
char* SortEncoding, FLAGSTORE Flags, PRECEDENCE Precedence)
2165
/**************************************************************
2166
INPUT: An EML relational formula, a variable list, a string (encoding
2167
the sorts of the accessibility relations in the scope), and
2168
the length of the variable list (corresponds to the modal
2170
RETURNS: Its functional translation ito n-ary predicates.
2171
CAUTION: The term is destructively changed.
2172
***************************************************************/
2176
Top = term_TopSymbol(Term);
2179
if (symbol_IsPredicate(Top)) {
2180
switch (flag_GetFlagIntValue(Flags, flag_EMLTHEORY)) {
2181
case flag_EMLTHEORYK:
2182
return eml_RplacPropByNaryAtom(Term, eml_REL,
2183
SortEncoding, 2, list_Cons(term_Create(VarX,list_Nil()),list_List(term_Create(VarY,list_Nil()))), Flags, Precedence);
2186
fprintf(stderr, "\nThe option EMLTheory = %d is not implemented in eml_RelFunctTranslRel()\n",
2187
flag_GetFlagIntValue(Flags, flag_EMLTHEORY));
2194
fprintf(stderr, "\nNo case for %s in eml_RelFunctTranslRel()\n",
2204
static TERM eml_TranslateToFol(TERM Term, int Polarity,
2205
FLAGSTORE Flags, PRECEDENCE Precedence)
2206
/**************************************************************
2207
INPUT: An eml formula.
2208
RETURNS: Its translation as specified by flag_EMLTR, provided
2209
the formula is provided, otherwise the simplification of the
2211
CAUTION: The term is destructively changed.
2212
***************************************************************/
2214
if (!eml_IsPropositional(Term))
2215
fol_NormalizeVars(Term);
2217
Term = eml_ObviousSimplifications(Term, Flags);
2218
/* Term = eml_MakeOneAndOrCompSum(Term); */
2219
if (flag_GetFlagIntValue(Flags, flag_EMLPTRANS)) {
2220
printf("\n [Simpl]\t");
2221
if ( (Polarity == -1) ) { /* Conjecture */
2222
symbol_Print(fol_Not());
2224
/* printf("(not "); */
2233
if (eml_IsPropositional(Term)) {
2234
switch (flag_GetFlagIntValue(Flags, flag_EMLTR)) {
2236
Term = eml_RelationalTranslation(Term, Flags, Precedence);
2238
case flag_EMLTRFUNC:
2239
case flag_EMLTROPTFUNC:
2240
Term = eml_FunctionalTranslation(Term, flag_GetFlagIntValue(Flags, flag_EMLFNARY), Flags, Precedence);
2242
case flag_EMLTRSEMIFUNC:
2243
Term = eml_SemiFunctionalTranslation(Term, Polarity, Flags, Precedence);
2246
fprintf(stderr, "\nFlag = %d is not implemented in eml_TranslateToFol()\n",
2247
flag_GetFlagIntValue(Flags, flag_EMLTR));
2253
if (flag_GetFlagIntValue(Flags, flag_EMLPTRANS))
2254
printf("\n [FOL]\t");
2259
static TERM eml_CreateTheoryTerm(int Flag, SYMBOL Symbol)
2260
/**************************************************************
2261
INPUT: A flag, must be of a logic determined by one axiom schema
2262
RETURNS: A single theory formula, e.g. for the flag flag_EMLTHEORYKD it
2263
returns forall x exists y R(x,y)
2264
REMARK: Prototypical. Only implemented for the relational
2265
translation and a few axiom schemas (D, T, B, 4, 5)
2266
***************************************************************/
2268
TERM newVarX, newVarY, newVarZ, helpTerm;
2269
TERM term; /* theory formula */
2273
case flag_EMLTHEORYKD:
2275
newVarX = term_Create(symbol_CreateStandardVariable(), list_Nil());
2276
newVarY = term_Create(symbol_CreateStandardVariable(), list_Nil());
2277
term = term_Create(Symbol, /* R(x,y) */
2278
list_Nconc(list_List(newVarX), list_List(newVarY)));
2279
/*printf("\n [*]\t"); fol_PrintDFG(term);*/
2280
helpTerm = term_Create(fol_Exist(), /* exists y R(x,y) */
2281
list_Cons(term_Create(fol_Varlist(), list_List(term_Copy(newVarY))),
2283
/*printf("\n [**]\t"); fol_PrintDFG(helpTerm);*/
2284
term = term_Create(fol_All(), /* forall x exists y R(x,y) */
2285
list_Cons(term_Create(fol_Varlist(), list_List(term_Copy(newVarX))),
2286
list_List(helpTerm) ));
2287
/*printf("\n [***]\t"); fol_PrintDFG(term);*/
2291
case flag_EMLTHEORYKT:
2293
newVarX = term_Create(symbol_CreateStandardVariable(), list_Nil());
2294
helpTerm = term_Create(Symbol, /* R(x,x) */
2295
list_Nconc(list_List(newVarX), list_List(term_Copy(newVarX))));
2296
/*printf("\n [*]\t"); fol_PrintDFG(helpTerm);*/
2297
term = term_Create(fol_All(), /* forall x R(x,x) */
2298
list_Cons(term_Create(fol_Varlist(), list_List(term_Copy(newVarX))),
2299
list_List(helpTerm) ));
2303
case flag_EMLTHEORYKB:
2305
newVarX = term_Create(symbol_CreateStandardVariable(), list_Nil());
2306
newVarY = term_Create(symbol_CreateStandardVariable(), list_Nil());
2307
term = term_Create(Symbol, /* R(x,y) */
2308
list_Nconc(list_List(newVarX), list_List(newVarY)));
2309
/*printf("\n [*]\t"); fol_PrintDFG(term);*/
2310
helpTerm = term_Create(Symbol, /* R(y,x) */
2311
list_Nconc(list_List(term_Copy(newVarY)), list_List(term_Copy(newVarX))));
2312
/*printf("\n [**]\t"); fol_PrintDFG(helpTerm);*/
2313
helpTerm = term_Create(fol_Implies(), /* R(x,y) -> R(y,x) */
2314
list_Cons(term, list_List(helpTerm)));
2315
/*printf("\n [***]\t"); fol_PrintDFG(helpTerm);*/
2316
term = term_Create(fol_All(), /* forall x y R(x,y) -> R(y,x) */
2317
list_Cons(term_Create(fol_Varlist(),
2318
list_Cons(term_Copy(newVarX), list_List(term_Copy(newVarY)))),
2319
list_List(helpTerm) ));
2320
/*printf("\n [****]\t"); fol_PrintDFG(term);*/
2324
case flag_EMLTHEORYK4:
2326
newVarX = term_Create(symbol_CreateStandardVariable(), list_Nil());
2327
newVarY = term_Create(symbol_CreateStandardVariable(), list_Nil());
2328
newVarZ = term_Create(symbol_CreateStandardVariable(), list_Nil());
2329
term = term_Create(Symbol, /* R(x,y) */
2330
list_Nconc(list_List(newVarX), list_List(newVarY)));
2331
/*printf("\n [*]\t"); fol_PrintDFG(term);*/
2332
helpTerm = term_Create(Symbol, /* R(y,z) */
2333
list_Nconc(list_List(term_Copy(newVarY)), list_List(newVarZ)));
2334
/*printf("\n [**]\t"); fol_PrintDFG(helpTerm);*/
2335
helpTerm = term_Create(fol_And(), /* R(x,y) /\ R(y,z) */
2336
list_Cons(term, list_List(helpTerm)));
2337
/*printf("\n [***]\t"); fol_PrintDFG(helpTerm);*/
2338
term = term_Create(Symbol, /* R(x,z) */
2339
list_Nconc(list_List(term_Copy(newVarX)), list_List(term_Copy(newVarZ))));
2340
/*printf("\n [****]\t"); fol_PrintDFG(term);*/
2341
helpTerm = term_Create(fol_Implies(), /* (R(x,y) /\ R(y,z)) -> R(x,z) */
2342
list_Cons(helpTerm, list_List(term)));
2343
/*printf("\n [*****]\t"); fol_PrintDFG(helpTerm);*/
2344
term = term_Create(fol_All(), /* forall x y z (R(x,y) /\ R(y,z)) -> R(x,z) */
2345
list_Cons(term_Create(fol_Varlist(),
2346
list_Cons(term_Copy(newVarX),
2347
list_Cons(term_Copy(newVarY),
2348
list_List(term_Copy(newVarZ))))),
2349
list_List(helpTerm) ));
2350
/*printf("\n [******]\t"); fol_PrintDFG(term);*/
2354
case flag_EMLTHEORYK5:
2356
newVarX = term_Create(symbol_CreateStandardVariable(), list_Nil());
2357
newVarY = term_Create(symbol_CreateStandardVariable(), list_Nil());
2358
newVarZ = term_Create(symbol_CreateStandardVariable(), list_Nil());
2359
term = term_Create(Symbol, /* R(x,y) */
2360
list_Nconc(list_List(newVarX), list_List(newVarY)));
2361
/*printf("\n [*]\t"); fol_PrintDFG(term);*/
2362
helpTerm = term_Create(Symbol, /* R(x,z) */
2363
list_Nconc(list_List(term_Copy(newVarX)), list_List(newVarZ)));
2364
/*printf("\n [**]\t"); fol_PrintDFG(helpTerm);*/
2365
helpTerm = term_Create(fol_And(), /* R(x,y) /\ R(x,z) */
2366
list_Cons(term, list_List(helpTerm)));
2367
/*printf("\n [***]\t"); fol_PrintDFG(helpTerm);*/
2368
term = term_Create(Symbol, /* R(y,z) */
2369
list_Nconc(list_List(term_Copy(newVarY)), list_List(term_Copy(newVarZ))));
2370
/*printf("\n [****]\t"); fol_PrintDFG(term);*/
2371
helpTerm = term_Create(fol_Implies(), /* (R(x,y) /\ R(x,z)) -> R(y,z) */
2372
list_Cons(helpTerm, list_List(term)));
2373
/*printf("\n [*****]\t"); fol_PrintDFG(helpTerm);*/
2374
term = term_Create(fol_All(), /* forall x y z (R(x,y) /\ R(x,z)) -> R(y,z) */
2375
list_Cons(term_Create(fol_Varlist(),
2376
list_Cons(term_Copy(newVarX),
2377
list_Cons(term_Copy(newVarY),
2378
list_List(term_Copy(newVarZ))))),
2379
list_List(helpTerm) ));
2380
/*printf("\n [******]\t"); fol_PrintDFG(term);*/
2385
fprintf(stderr, "\nFlag = %d is not implemented in eml_CreateTheoryTerm()\n",
2392
static void eml_AddBackgroundTheory(LIST* Axiomlist, FLAGSTORE Flags)
2393
/**************************************************************
2394
INPUT: The list of axioms
2396
EFFECT: Additional axioms may be added to the list of axioms.
2397
REMARK: Prototypical. Only implemented for the relational
2398
translation and a few logics (K, KD, KT, KB, K4, K5, S4, S5 )
2399
***************************************************************/
2405
LIST pair = list_Nil(); /* theory formula plus label */
2406
LIST theory = list_Nil(); /* list of theory formulae */
2408
/*printf("\n Beginning of eml_AddBackgroundTheory()\t");*/
2410
if ( (flag_GetFlagIntValue(Flags, flag_EMLTHEORY) != flag_EMLTHEORYK) &&
2411
(flag_GetFlagIntValue(Flags, flag_EMLTR) == flag_EMLTRREL) ) {
2413
for (i = 1; i < symbol_ActIndex(); i++) {
2414
if (!symbol_IsFreed(i)) {
2415
symbol = symbol_Signature(i)->info;
2416
/* printf("\n []\t"); symbol_Print(symbol); */
2417
if ( symbol_IsPredicate(symbol) &&
2418
(symbol_Signature(i)->arity == 2) &&
2419
!symbol_Equal(symbol, fol_Equality())) {
2420
flag = flag_GetFlagIntValue(Flags, flag_EMLTHEORY);
2423
case flag_EMLTHEORYKD:
2424
case flag_EMLTHEORYKT:
2425
case flag_EMLTHEORYKB:
2426
case flag_EMLTHEORYK4:
2427
case flag_EMLTHEORYK5:
2428
sprintf(L,"%s%s", eml_RELPROPERTYLABELS[flag], symbol_Name(symbol));
2429
label = memory_Malloc(sizeof(char) * (strlen(L) + 1));
2430
sprintf(label, "%s", L);
2431
pair = list_PairCreate(label, eml_CreateTheoryTerm(flag, symbol));
2432
/*printf("\nLabel : %s", (char*) list_PairFirst(pair)); */
2433
/*printf("\nTheory formula : "); fol_PrintDFG(list_PairSecond(pair));*/
2434
theory = list_Nconc(theory, list_List(pair));
2437
case flag_EMLTHEORYS4:
2438
/* T / reflexivity */
2439
sprintf(L,"%s%s", eml_RELPROPERTYLABELS[flag_EMLTHEORYKT], symbol_Name(symbol));
2440
label = memory_Malloc(sizeof(char) * (strlen(L) + 1));
2441
sprintf(label, "%s", L);
2442
pair = list_PairCreate(label, eml_CreateTheoryTerm(flag_EMLTHEORYKT, symbol));
2443
/*printf("\nLabel : %s", (char*) list_PairFirst(pair)); */
2444
/*printf("\nTheory formula : "); fol_PrintDFG(list_PairSecond(pair));*/
2445
theory = list_Nconc(theory, list_List(pair));
2446
/* 4 / transitivity */
2447
sprintf(L,"%s%s", eml_RELPROPERTYLABELS[flag_EMLTHEORYK4], symbol_Name(symbol));
2448
label = memory_Malloc(sizeof(char) * (strlen(L) + 1));
2449
sprintf(label, "%s", L);
2450
pair = list_PairCreate(label, eml_CreateTheoryTerm(flag_EMLTHEORYK4, symbol));
2451
/*printf("\nLabel : %s", (char*) list_PairFirst(pair)); */
2452
/*printf("\nTheory formula : "); fol_PrintDFG(list_PairSecond(pair));*/
2453
theory = list_Nconc(theory, list_List(pair));
2456
case flag_EMLTHEORYS5:
2457
/* T / reflexivity */
2458
sprintf(L,"%s%s", eml_RELPROPERTYLABELS[flag_EMLTHEORYKT], symbol_Name(symbol));
2459
label = memory_Malloc(sizeof(char) * (strlen(L) + 1));
2460
sprintf(label, "%s", L);
2461
pair = list_PairCreate(label, eml_CreateTheoryTerm(flag_EMLTHEORYKT, symbol));
2462
/*printf("\nLabel : %s", (char*) list_PairFirst(pair)); */
2463
/*printf("\nTheory formula : "); fol_PrintDFG(list_PairSecond(pair));*/
2464
theory = list_Nconc(theory, list_List(pair));
2466
sprintf(L,"%s%s", eml_RELPROPERTYLABELS[flag_EMLTHEORYKB], symbol_Name(symbol));
2467
label = memory_Malloc(sizeof(char) * (strlen(L) + 1));
2468
sprintf(label, "%s", L);
2469
pair = list_PairCreate(label, eml_CreateTheoryTerm(flag_EMLTHEORYKB, symbol));
2470
/*printf("\nLabel : %s", (char*) list_PairFirst(pair)); */
2471
/*printf("\nTheory formula : "); fol_PrintDFG(list_PairSecond(pair));*/
2472
theory = list_Nconc(theory, list_List(pair));
2473
/* 4 / transitivity */
2474
sprintf(L,"%s%s", eml_RELPROPERTYLABELS[flag_EMLTHEORYK4], symbol_Name(symbol));
2475
label = memory_Malloc(sizeof(char) * (strlen(L) + 1));
2476
sprintf(label, "%s", L);
2477
pair = list_PairCreate(label, eml_CreateTheoryTerm(flag_EMLTHEORYK4, symbol));
2478
/*printf("\nLabel : %s", (char*) list_PairFirst(pair)); */
2479
/*printf("\nTheory formula : "); fol_PrintDFG(list_PairSecond(pair));*/
2480
theory = list_Nconc(theory, list_List(pair));
2483
fprintf(stderr, "\nThe option EMLTheory = %d is not implemented in eml_AddBackgroundTheory()\n",
2484
flag_GetFlagIntValue(Flags, flag_EMLTHEORY));
2489
if (list_Empty(theory)) {
2490
fprintf(stderr, "In eml_AddBackgroundTheory(): theory is empty\n");
2493
if (list_Empty(*Axiomlist)) {
2494
fprintf(stderr, "In eml_AddBackgroundTheory(): *Axiomlist is empty\n");
2501
*Axiomlist = list_Nconc(theory, *Axiomlist);
2506
void eml_TranslateToFolMain(LIST* AxiomList, LIST* ConjectureList,
2507
BOOL KeepProofSearch, FLAGSTORE Flags, PRECEDENCE Precedence)
2508
/**************************************************************
2509
INPUT: A list of axiom formulae,
2510
a list of conjecture formulae,
2511
a hasharray in which for every clause the list of labels
2512
of the terms used for deriving the clause is stored (if DocProof
2515
RETURNS: If KeepProofSearch is TRUE, then the ProofSearch object is not
2517
Else, NULL is returned.
2518
***************************************************************/
2524
/* NOTE: EMLAUTO mode not as yet implemented */
2526
/* Print warnings for non-sensical flag combinations */
2527
flag_emltr = flag_GetFlagIntValue(Flags, flag_EMLTR);
2528
if (flag_GetFlagIntValue(Flags, flag_DOCPROOF) || flag_GetFlagIntValue(Flags, flag_EMLPTRANS)) {
2529
flag_CheckEmlTranslationFlags(Flags, flag_emltr);
2532
/* Set additional flags */
2533
if (flag_emltr == flag_EMLTROPTFUNC) {
2534
flag_SetFlagIntValue(Flags, flag_CNFQUANTEXCH, flag_CNFQUANTEXCHON);
2536
/* This caused a memory leak because of the allocation done in
2537
* cnf_Init; fixed with warnings
2538
* if (flag_GetFlagIntValue(Flags, flag_CNFQUANTEXCH)) {
2539
flag_SetFlagIntValue(Flags, flag_CNFOPTSKOLEM, flag_CNFOPTSKOLEMOFF);
2540
flag_SetFlagIntValue(Flags, flag_CNFSTRSKOLEM, flag_CNFSTRSKOLEMOFF);
2543
if ((flag_emltr == flag_EMLTRFUNC || flag_emltr == flag_EMLTROPTFUNC) &&
2544
flag_GetFlagIntValue(Flags, flag_EMLFFSORTS)) {
2545
flag_SetFlagIntValue(Flags, flag_SORTS, flag_SORTSMONADICWITHVARIABLE);
2547
/* RS: Check with Christoph?? */
2549
/* Limitations of current implementation */
2551
if ( !list_Empty(Scan) && !list_Empty(list_Car(Scan)) ) {
2552
if ( flag_emltr == flag_EMLTROPTFUNC ) {
2553
fprintf(stderr, "ERROR: With the current implementation of the translation routines\n");
2554
fprintf(stderr, " no axioms are allowed when the optimised functional translation\n");
2555
fprintf(stderr, " is used (EMLTranslation=2)\n");
2559
if ( flag_GetFlagIntValue(Flags, flag_EMLFNARY) ) {
2560
fprintf(stderr, "ERROR: With the current implementation of the translation routines\n");
2561
fprintf(stderr, " no axioms are allowed when the encoding is in terms of\n");
2562
fprintf(stderr, " n-ary predicates (EMLFuncNary=1)\n");
2568
if (flag_GetFlagIntValue(Flags, flag_EMLPTRANS)) {
2569
printf("\n--------------------EML-TRANSLATION-START-------------------------");
2570
printf("\n Special : ");
2571
flag_PrintEmlTranslationMethod(flag_emltr);
2572
flag_PrintEmlTranslationFlags(Flags);
2573
printf("\n Precedence: "); symbol_PrintPrecedence(Precedence);
2574
printf("\nAxioms:");
2577
/* Initialisation */
2578
switch (flag_GetFlagIntValue(Flags, flag_EMLTR)) {
2579
case flag_EMLTRFUNC:
2580
case flag_EMLTROPTFUNC:
2581
case flag_EMLTRSEMIFUNC:
2582
eml_InitFunctTransl(Flags, Precedence);
2589
for(Scan=*AxiomList; !list_Empty(Scan); Scan = list_Cdr(Scan)) {
2590
Pair = list_Car(Scan);
2591
helpTerm = (TERM) list_PairSecond(Pair);
2592
if (flag_GetFlagIntValue(Flags, flag_EMLPTRANS)) {
2593
if ( !list_Empty(list_PairFirst(Pair)) ) {
2594
printf("\nLabel : %s", (char*) list_PairFirst(Pair));
2596
if (eml_IsPropositional(helpTerm))
2597
printf("\n [%s]\t", flag_Name(flag_EML));
2599
printf("\n [FOL]\t");
2600
fol_PrintDFG(helpTerm);
2602
helpTerm = eml_TranslateToFol(helpTerm, 1, Flags, Precedence);
2603
/* positive polarity */
2604
if (flag_GetFlagIntValue(Flags, flag_EMLPTRANS)) {
2605
fol_PrintDFG(helpTerm);
2608
list_Rplacd(Pair, (LIST) helpTerm);
2611
if (flag_GetFlagIntValue(Flags, flag_EMLPTRANS))
2612
printf("\n\nConjecture:");
2614
for(Scan=*ConjectureList; !list_Empty(Scan); Scan = list_Cdr(Scan)) {
2615
Pair = list_Car(Scan);
2616
helpTerm = (TERM) list_PairSecond(Pair);
2617
if (flag_GetFlagIntValue(Flags, flag_EMLPTRANS)) {
2618
if ( !list_Empty(list_PairFirst(Pair)) ) {
2619
printf("\nLabel : %s", (char*) list_PairFirst(Pair));
2621
if (eml_IsPropositional(helpTerm))
2622
printf("\n [%s]\t", flag_Name(flag_EML));
2624
printf("\n [FOL]\t");
2625
fol_PrintDFG(helpTerm);
2628
if (!symbol_Equal(term_TopSymbol(helpTerm),fol_Not())) {
2629
fprintf(stderr, "In eml_TranslateToFolMain(): The list of conjectures should have been negated\n");
2634
term_RplacFirstArgument(helpTerm,
2635
eml_TranslateToFol(term_FirstArgument(helpTerm), -1, Flags, Precedence));
2636
/* negative polarity */
2637
if (flag_GetFlagIntValue(Flags, flag_EMLPTRANS)) {
2638
fol_PrintDFG(helpTerm);
2640
list_Rplacd(Pair, (LIST) helpTerm);
2642
if (flag_GetFlagIntValue(Flags, flag_EMLPTRANS))
2645
eml_AddBackgroundTheory(AxiomList, Flags);
2647
/* Check whether the following does the job (as it is supposed to).
2648
* Deleting the symbol list causes a segmentation fault later on in cnf.c.
2649
* Is this possbily due to a missing
2650
* if (!list_PointerMember(symbol_FREEDSYMBOLS,(POINTER)Index))