@@ -382,32 +382,36 @@ def distance(self, other):
382382 if disjoint_test (self [n ], other [n ], sai , sit ):
383383 return Vector (S .ImaginaryUnit )
384384
385+ # Compute the distance along the current IterationInterval
385386 if self .function ._mem_shared :
386387 # Special case: the distance between two regular, thread-shared
387- # objects fallbacks to zero, as any other value would be nonsensical
388+ # objects falls back to zero, as any other value would be
389+ # nonsensical
390+ ret .append (S .Zero )
391+ elif degenerating_dimensions (sai , oai ):
392+ # Special case: `sai` and `oai` may be different symbolic objects
393+ # but they can be proved to systematically generate the same value
388394 ret .append (S .Zero )
389-
390395 elif sai and oai and sai ._defines & sit .dim ._defines :
391- # E.g., `self=R<f,[t + 1, x]>`, `self.itintervals=(time, x)`, `ai=t`
396+ # E.g., `self=R<f,[t + 1, x]>`, `self.itintervals=(time, x)`,
397+ # and `ai=t`
392398 if sit .direction is Backward :
393399 ret .append (other [n ] - self [n ])
394400 else :
395401 ret .append (self [n ] - other [n ])
396-
397402 elif not sai and not oai :
398403 # E.g., `self=R<a,[3]>` and `other=W<a,[4]>`
399404 if self [n ] - other [n ] == 0 :
400405 ret .append (S .Zero )
401406 else :
402407 break
403-
404408 elif sai in self .ispace and oai in other .ispace :
405409 # E.g., `self=R<f,[x, y]>`, `sai=time`,
406410 # `self.itintervals=(time, x, y)`, `n=0`
407411 continue
408-
409412 else :
410- # E.g., `self=R<u,[t+1, ii_src_0+1, ii_src_1+2]>`, `fi=p_src`, `n=1`
413+ # E.g., `self=R<u,[t+1, ii_src_0+1, ii_src_1+2]>`, `fi=p_src`,
414+ # and `n=1`
411415 return vinf (ret )
412416
413417 n = len (ret )
@@ -1408,3 +1412,19 @@ def disjoint_test(e0, e1, d, it):
14081412 i1 = sympy .Interval (min (p10 , p11 ), max (p10 , p11 ))
14091413
14101414 return not bool (i0 .intersect (i1 ))
1415+
1416+
1417+ def degenerating_dimensions (d0 , d1 ):
1418+ """
1419+ True if `d0` and `d1` are Dimensions that are possibly symbolically
1420+ different, but they can be proved to systematically degenerate to the
1421+ same value, False otherwise.
1422+ """
1423+ # Case 1: ModuloDimensions of size 1
1424+ try :
1425+ if d0 .is_Modulo and d1 .is_Modulo and d0 .modulo == d1 .modulo == 1 :
1426+ return True
1427+ except AttributeError :
1428+ pass
1429+
1430+ return False
0 commit comments