Package test.peano.types

Examples of test.peano.types.Nat


  public Factory getPeanoFactory() {
    return factory;
  }

  public Nat make(int n) {
    Nat N = factory.makeNat_Zero();
    for (int i = 0; i < n; i++) {
      N = factory.makeNat_Suc(N);
    }

    return N;
View Full Code Here


  }

  public void run1() {
    int n = 17;
    int r = fib(n);
    Nat N = make(n);
    Nat R = fib(N);

    if (unmake(R) != r) {
      System.err.println("unexpected result of computation!");
      System.exit(1);
    }
View Full Code Here

  public void run2() {
    //    GenericTraversal traversal = new GenericTraversal();
    Replace replace = new Replace() {
      public ATerm apply(ATerm atermSubject) {
        Nat subject = (Nat) atermSubject;
        if (subject.isPlus()) {
          Nat arg1 = subject.getArg1();
          Nat arg2 = subject.getArg2();
          if (arg2.isZero()) {
            return arg1;
          }
          else if (arg2.isSuc()) {
            Nat y = arg2.getPred();
            return getPeanoFactory().makeNat_Suc(getPeanoFactory().makeNat_Plus(arg1, y));
          }
        }
        else if (subject.isFib()) {
          Nat t = subject.getArg1();
          if (t.isZero()) {
            return getPeanoFactory().makeNat_Suc(t);
          }
          else if (t.isSuc() && t.getPred().isZero()) {
            return t.getPred();
          }
          else {
            Nat pred1 = t.getPred();
            Nat pred2 = pred1.getPred();
            return getPeanoFactory().makeNat_Plus(
              getPeanoFactory().makeNat_Fib(pred2),
              getPeanoFactory().makeNat_Fib(pred1));
          }
        }
        return null;
      }
    };

    int n = 17;
    int r = fib(n);
    Nat N = make(n);
    Nat R = factory.makeNat_Fib(N);

    Nat res = null;
    while (res != R) {
      res = (Nat) replace.apply(R);
      R = res;
    }
View Full Code Here

  public Nat plus(Nat t1, Nat t2) {
    if (t2.isZero()) {
      return t1;
    }
    else if (t2.isSuc()) {
      Nat y = t2.getPred();
      return factory.makeNat_Suc(plus(t1, y));
    }
    else {
      return null;
    }
View Full Code Here

    }
    else if (t.isSuc() && t.getPred().isZero()) {
      return factory.makeNat_Zero();
    }
    else {
      Nat pred1 = t.getPred();
      Nat pred2 = pred1.getPred();

      return plus(fib(pred2), fib(pred1));
    }
  }
View Full Code Here

TOP

Related Classes of test.peano.types.Nat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.