Package ket.math

Examples of ket.math.Branch


  public static Argument[] toRow(Argument argument) {
    // TODO: Does the function type matter: currently commas, vectors, and anything are allowed, but this means that a*b*c -> [a,b,c].
    if (argument==null || argument instanceof Token) {
      return null;
    }
    Branch rowBranch = (Branch) argument;
    if (rowBranch.size()==0) {
      return null
    }
    Argument[] row = new Argument[rowBranch.size()];
    for (int i=0; i<row.length; i++) {
      row[i] = rowBranch.getChild(i);
    }
    return row;
  }
View Full Code Here


      return false;
    }
    Vector<Branch> aAncestors = a.getAncestors();
    Vector<Branch> bAncestors = b.getAncestors();
    for (int k=0; k<aAncestors.size(); k++) {
      Branch aNext = aAncestors.get(k);
      Branch bNext = bAncestors.get(k);
      if ( ! aNext.elementEquals(bNext) ) {
        return false;
      }
    }
    return true;
View Full Code Here

      return false;
    }
    Vector<Branch> aAncestors = a.getAncestors();
    Vector<Branch> bAncestors = b.getAncestors();
    for (int k=0; k<aAncestors.size(); k++) {
      Branch aNext = aAncestors.get(k);
      Branch bNext = bAncestors.get(k);
      if (aNext.getIndex()!=bNext.getIndex()) {
        return false;
      }
    }
    return true;
  }
View Full Code Here

  }

  public static Branch getSameFunctionAncestor(Branch branch) { // dangerous for non-branches.
    Function function = branch.getFunction();
    Vector<Branch> ancestors = branch.getAncestors();
    Branch root = branch;
    for (Branch a : ancestors) {
      if (a.getFunction()==function) {
        root = a;
      } else {
        return root;
View Full Code Here

  public static boolean parentsEquals(Argument before, Argument after) {
    if (before.isRoot() || after.isRoot()) {
      return before.isRoot() && after.isRoot();
    } else {
      Branch beforeParent = before.getParentBranch();
      Branch afterParent = after.getParentBranch();
      return beforeParent!=null && beforeParent.elementEquals(afterParent);
    }
  }
View Full Code Here

    } else if (before instanceof Token) {
      // Both are tokens
      return true;
    } else {
      // Both are branches
      Branch beforeBranch = (Branch) before;
      Branch afterBranch = (Branch) after;
      return beforeBranch.childElementsEqual(afterBranch);
    }
  }
View Full Code Here

   */
  public static Function effectiveUnitaryAncestorOperation(Argument target, Branch top) {
    //D Ket.out.println("Route:");
    //D Ket.out.println("\targument: " + (target!=null?target:null));
    //D Ket.out.println("\ttop: " + (top!=null?top:null));
    Branch parent = target.getParentBranch();
    Function unitary = Type.getUnitaryFunction(target);
    if (unitary==null) {
      //D Ket.out.println("\t !!! Null unitary function !!! ");
      return null;
    }
    //D Ket.out.println("\tunitary function = '" + unitary.getName() + "'");
    Function composition=unitary;
    while (parent!=null && parent!=top) {
      //D Ket.out.println("\tparent = '" + parent + "'");
      target = parent;
      parent = parent.getParentBranch();
      if (parent==null || parent==top) {
        break;
      }
      unitary = Type.getUnitaryFunction(target);
      if (unitary==null) {
View Full Code Here

      case 1:
        return terms.firstElement();

      default:
        Branch power = new Branch(Function.TIMES);
        for (Argument product : terms) {
          power.append(product);
        }
        return power;
    }
  }
View Full Code Here

  private Argument toPower(int mantissa, int exponent) {
    Token m = new Token(mantissa);
    if (exponent>1) {
      Token e = new Token(exponent);
      return new Branch(Function.POWER, m, e);
    } else {
      return m;
    }
  }
View Full Code Here

TOP

Related Classes of ket.math.Branch

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.