Tensor M2 = Tensors.parse("Power[M,2]");
Tensor pT = Tensors.parse("pT");
Tensor s = Tensors.parse("s");
TreeTraverseIterator iterator;
long start, stop;
boolean status;
int i;
start = System.currentTimeMillis();
Tensor ptM = null;
for (i = 0; i < 100; ++i) {
iterator = new TreeTraverseIterator(target);
while (iterator.next() != null)
if (TensorUtils.equalsExactly(iterator.current(), pT))
iterator.set(M);
ptM = iterator.result();
}
stop = System.currentTimeMillis();
status = TensorUtils.equalsExactly(ptM, pTToM);
System.out.println("pT -> M : " + status + ". Time: " + (stop - start) + " ms");
start = System.currentTimeMillis();
Tensor sM = null;
for (i = 0; i < 100; ++i) {
iterator = new TreeTraverseIterator(target);
while (iterator.next() != null)
if (TensorUtils.equalsExactly(iterator.current(), s))
iterator.set(M2);
sM = iterator.result();
}
status = TensorUtils.equalsExactly(sM, sToM);
stop = System.currentTimeMillis();
System.out.println("s -> M^2 : " + status + ". Time: " + (stop - start) + " ms");
start = System.currentTimeMillis();
Tensor allM = null;
for (i = 0; i < 100; ++i) {
iterator = new TreeTraverseIterator(target);
while (iterator.next() != null)
if (TensorUtils.equalsExactly(iterator.current(), pT))
iterator.set(M);
else if (TensorUtils.equalsExactly(iterator.current(), s))
iterator.set(M2);
allM = iterator.result();
}
status = TensorUtils.equalsExactly(allM, AllToM);
stop = System.currentTimeMillis();
System.out.println("pT-> M and s -> M^2 : " + status + ". Time: " + (stop - start) + " ms");
}