File: DNFWR.c

package info (click to toggle)
qepcad 1.74%2Bds-5
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 4,848 kB
  • sloc: ansic: 27,242; cpp: 2,995; makefile: 1,287; perl: 91
file content (46 lines) | stat: -rw-r--r-- 1,483 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*======================================================================
                      DNFWR(V,F)

Disjunctive Normal Form Write.

\Input
   \parm{V} is a non-null list of distinct variables.
   \parm{F} is a disjunctive normal form with variables in $V$,
            written out to the output strem
======================================================================*/
#include "qepcad.h"

void DNFWR(Word V, Word F)
{
       Word F1,Fp,T;

Step1: /* Classify the formula F. */
       T = FIRST(F);
       if (T == OROP) goto Step3;
       if (T == ANDOP) goto Step4;
       if (T == NOTOP)   FAIL("DNFWR","NOTOP not expected.");
       if (T == RIGHTOP) FAIL("DNFWR","RIGHTOP not expected.");
       if (T == LEFTOP)  FAIL("DNFWR","LEFTOP not expected."); 
       if (T == EQUIOP)  FAIL("DNFWR","EQUIPOP not expected."); 

Step2: /* Atomic formula. */
       ATOMFWR(V,F); goto Return;

Step3: /* Disjunction. */
       Fp = RED(F);
       if (LENGTH(Fp) == 1) { DNFWR(V,FIRST(Fp)); goto Return; }
       ADV(Fp,&F1,&Fp); DNFWR(V,F1);
       while (Fp != NIL)
         { ADV(Fp,&F1,&Fp); SWRITE("    "); LGOPWR(T); SWRITE("\n"); DNFWR(V,F1); }
       goto Return;

Step4: /* Conjunction. */
       Fp = RED(F);
       if (LENGTH(Fp) == 1) { DNFWR(V,FIRST(Fp)); goto Return; }
       ADV(Fp,&F1,&Fp); DNFWR(V,F1);
       while (Fp != NIL)
         { ADV(Fp,&F1,&Fp); SWRITE(" "); LGOPWR(T); SWRITE(" "); DNFWR(V,F1); }

Return: /* Prepare for return. */
       return;
}