Strange behavior in relabeling a graph in Sage 9.2

14 views
Skip to first unread message

Nikos Apostolakis

unread,
Jan 8, 2021, 10:06:36 AM1/8/21
to sage-s...@googlegroups.com

Dear list,

Relabeling a graph in Sage 9.2 exhibits some strange behavior.  If the argument is a dictionary constructed by dictionary comprehension Sage seems to just ignore it.  If the dictionary is explicitly given then everything works.  Here is an example

sage: bar = DiGraph([((2, 3), (1, 2), 2), ((3, 4), (3, 5), 3), ((3, 5), (2, 3), 3), ((5, 6), (5, 7), 5), ((5, 7), (3, 5), 5)])
sage: foo = [(5,6), (3,4), (5,7), (3,5), (2,3), (1,2)]
sage: bar.relabel({foo[i]: i for i in range(6)})
sage: bar.vertices()
[(1, 2), (2, 3), (3, 4), (3, 5), (5, 6), (5, 7)]
sage: ## However if I explicitly give the dictionary
sage: {foo[i]: i for i in range(6)}
{(5,6): 0, (3,4): 1, (5,7): 2, (3,5): 3, (2,3): 4, (1,2): 5}
sage: bar.relabel({(5,6): 0, (3,4): 1, (5,7): 2, (3,5): 3, (2,3): 4, (1,2): 5})
sage: bar.vertices()
[0, 1, 2, 3, 4, 5]
sage: sage0_version()
'SageMath version 9.2, Release Date: 2020-10-24'


This problem doesn't seem to happen in older versions of Sage. I have Sage 8.8 in another box and the problem doesn't occur:

sage: bar = DiGraph([((2, 3), (1, 2), 2), ((3, 4), (3, 5), 3), ((3, 5), (2, 3), 3), ((5, 6), (5, 7), 5), ((5, 7), (3, 5), 5)])
sage: foo = [(5,6), (3,4), (5,7), (3,5), (2,3), (1,2)]
sage: bar.relabel({foo[i]: i for i in range(6)})
sage: bar.vertices()
[0, 1, 2, 3, 4, 5]
sage: sage0_version()
'SageMath version 8.8, Release Date: 2019-06-26'

I wonder if this is caused by the transition to Python3. Some kind of lazy evaluation?

Thanks,
Nikos Apostolakis
--
Οι ελαφροί ας με λέγουν ελαφρόν.
Στα σοβαρά πράγματα ήμουν πάντοτε
επιμελέστατος.

The frivolous can call me frivolous. In serious matters I've always been most diligent.
  K. P. Kavafy
Reply all
Reply to author
Forward
0 new messages