Infinite graphs in sage

asked 2012-02-21 09:46:11 +0100

Thomas gravatar image

I wonder if there is some sort of lazy evaluation in sage. Assume I want to answer a finite question about some infinite structure that can be represented using finite data. As a contrived example: Consider the graph that has as its vertices the natural numbers and an edge (i,j) whenever i divides j. Is there an elegant (lazy evaluation) way to represent this? For instance I could think of a function that investigates the sizes of connected components below the first 500 primes or such.

edit retag flag offensive close merge delete


I don't see why not. That's what things like yield statements and so forth are about. I supposed you'd need to use a Python class to do this - make a class instantiating this graph. But you *would* have to use some Python fu to do this, I suspect, if I understand what you mean by "lazy evaluation". I may not, and my apologies if I've totally misinterpreted your question.

kcrisman gravatar imagekcrisman ( 2012-02-21 10:34:07 +0100 )edit

Alright, thanks. What I was thinking of is too much to ask for: Let the work of implementing all the logic of local exploration of the data be done by the compiler. There are theoretical reasons for this being impossible in python, for instance you need strict static typing (like in Haskell).

Thomas gravatar imageThomas ( 2012-02-23 11:53:11 +0100 )edit