Package test

Examples of test.Replace


    }
  }

  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;
    }

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

TOP

Related Classes of test.Replace

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.