/** * fc(x, y) = g(h(x, y)) = g(h(y, x)) = fc(y, x) iff h isCommutative * @return true iff f(x, y) = f(y, x) for any x, y */ @Override public boolean isCommutative() { return h.isCommutative(); }
/** * fc(x, y) = f(g(x), h(y)) = f(h(y), g(x)) * fc(y, x) = f(g(y), h(x)) = f(h(x), g(y)) * Either g(x) = g(y) for any x, y and h(x) = h(y) for any x, y or g = h and f isCommutative. * Can only check if g = h (reference equality, assuming they're both the same static function in * this file) and f isCommutative. There are however other scenarios when this might happen that are NOT * covered by this definition. * @return true iff f(x, y) = f(y, x) for any x, y */ @Override public boolean isCommutative() { return g.equals(h) && f.isCommutative(); }
/** * @return true iff f(x, y) = f(y, x) for any x, y AND f(x, f(y, z)) = f(f(x, y), z) for any x, y, z */ public boolean isAssociativeAndCommutative() { return isAssociative() && isCommutative(); }
@Test public void testIsCommutative() { if (!function.isCommutative()) { return; } for (int i = 0; i < NUM_POINTS; ++i) { double x = random.nextDouble(); double y = random.nextDouble(); assertEquals(functionName, function.apply(x, y), function.apply(y, x), Constants.EPSILON); } }
/** * fc(x, y) = g(h(x, y)) = g(h(y, x)) = fc(y, x) iff h isCommutative * @return true iff f(x, y) = f(y, x) for any x, y */ @Override public boolean isCommutative() { return h.isCommutative(); }
/** * fc(x, y) = f(g(x), h(y)) = f(h(y), g(x)) * fc(y, x) = f(g(y), h(x)) = f(h(x), g(y)) * Either g(x) = g(y) for any x, y and h(x) = h(y) for any x, y or g = h and f isCommutative. * Can only check if g = h (reference equality, assuming they're both the same static function in * this file) and f isCommutative. There are however other scenarios when this might happen that are NOT * covered by this definition. * @return true iff f(x, y) = f(y, x) for any x, y */ @Override public boolean isCommutative() { return g.equals(h) && f.isCommutative(); }
/** * @return true iff f(x, y) = f(y, x) for any x, y AND f(x, f(y, z)) = f(f(x, y), z) for any x, y, z */ public boolean isAssociativeAndCommutative() { return isAssociative() && isCommutative(); }