Prover/Contexts.pizza
author Christian Urban <urbanc@in.tum.de>
Thu, 15 Mar 2012 10:07:28 +0000
changeset 96 907b1fff5637
permissions -rw-r--r--
added phd and prover
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
96
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
package G4ip;
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
import java.util.Vector;
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
import G4ip.Form.*;
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
/** Context acts as a multiset.<p>
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
  * Typical contexts in logical rules are Gamma, Delta, etc.
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
  * @author      Christian Urban
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
  */
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
public class Context extends Vector {
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
  
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  public Context() { super(); }
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
  public Context(Context init_context) {
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
    super();
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
    for (int i=0;i<init_context.size();i++) {
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
      addElement(init_context.elementAt(i));
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
    }
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
  }
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
  /** should be toString, but this is a "final" method in Vector 
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
    */
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
  public String makeString() {
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
    String s = new String();
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
    int i;                      // size()-1 because the last formula
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
    for (i=0;i<size()-1;i++) {  // should be printed without a comma
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
      s=s.concat(elementAt(i).toString());
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
      s=s.concat(", ");
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
    }
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
    if (size() > 0) {           // add last formula 
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
      s=s.concat(elementAt(i).toString()); 
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
    }
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
    return s;
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
  }
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
  /** returns a context with one additional formula at the beginning 
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
    * @param   new_formula    a formula
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
    */
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
  public Context add(Form new_formula) {
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
    Context new_c = new Context(this);
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
    new_c.insertElementAt(new_formula,0);
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
    return new_c;
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
  }
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
  /** returns a context with two additional formulae at the beginning 
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
    * @param new_formula1,new_formula2    two formulae
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
    */
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  public Context add(Form new_formula1, Form new_formula2) {
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
    Context new_c = new Context(this);
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
    new_c.insertElementAt(new_formula1,0);
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
    new_c.insertElementAt(new_formula2,0);
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
    return new_c;
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
  }
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
  /** tests whether a context contains a specific atom 
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
    * @param a a formula
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
    */
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  public boolean includes(Form a) {
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
    if (a instanceof Atm) {
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
      for (int i=0;i<size();i++) {
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
        switch((Form)elementAt(i)) {
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
        case Atm(String c):
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
          if (c.compareTo(((Atm)a).c) == 0) return true; break;
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
        }
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
      }
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
    }
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
    return false;
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  }
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
907b1fff5637 added phd and prover
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
}