Remove/postpone confusing canonicalization of inner

Issue #107 new
Jan Blechta created an issue

From the time when inner was symmetric, operands used to get sorted at the node definition time to allow

  1. common subexpression elimination (CSE),
  2. canonicalize hash.

Now inner is Hermitian symmetric and UFL is in general (compute_form_data is called) complex so hash(inner(a, b)) == hash(inner(b, a)) is not true and 2. is not relevant any more.

The objection is that now canonicalization yields unpredictable graphs:

from ufl import *
a = as_vector((Constant(interval), Constant(interval)))
b = as_vector((Constant(interval), Constant(interval)))
print(inner(a, b))
print(inner(b, a))

gives

([w_0, w_1]) : ([w_2, w_3])
conj((([w_0, w_1]) : ([w_2, w_3])))

Stephan and Lawrence suggest that sorting is done later (to keep supporting CSE) with something like:

def inner(self, o, a, b):
   if (a, b) != tuple(sorted_expr((a, b))):
       return Conj(Inner(b, a))
   return Inner(a, b)

Comments (1)

  1. Log in to comment