First time here? Check out the FAQ!

Ask Your Question
1

tree ordering in sage

asked 5 years ago

GA316 gravatar image

updated 5 years ago

FrédéricC gravatar image

I am using the following code to generate the isomorphism class of trees of order n.

sage: from sage.graphs.trees import TreeIterator
sage: def check_trees(n):
....:     trees = []
....:     for t in TreeIterator(n):    
....:         if not t.is_tree():  
....:             return False 
....:         if t.num_verts() != n: 
....:             return False   
....:         if t.num_edges() != n - 1:
....:             return False
....:         for tree in trees:
....:             if tree.is_isomorphic(t):
....:                 return False
....:         trees.append(t)
....:     return True

Then when I print the trees in TreeIterator using loops it is giving the trees in a particular order.

Can anyone explain to me what is this predefined order on trees of order n on sage?

For n = 6, we have the following order.

image description

image description

image description

image description

image description

image description

Preview: (hide)

Comments

1

As a side-comment, when pasting code in your question please mark it as pre-formatted code (there's a button on the WYSIWYG toolbar, but you can also select the code and press Ctrl-K to indent it all at once, which causes it to be treated as pre-formatted text. I have gone ahead and fixed it for you in this case.

Iguananaut gravatar imageIguananaut ( 5 years ago )

That's a good question though. I looked at the code, and even the code does not include any commentary explaining how it works. Yes, one can read the code and figure it out, but I don't think it's at all "obvious".

Iguananaut gravatar imageIguananaut ( 5 years ago )

Sorry, I shall paste it like this in future. Thanks for your comment.

GA316 gravatar imageGA316 ( 5 years ago )

2 Answers

Sort by » oldest newest most voted
3

answered 5 years ago

The documentation in the reference manual says that it is using the algorithm from this paper.

Preview: (hide)
link
-1

answered 5 years ago

Emmanuel Charpentier gravatar image
sage: r.library("fortunes")
sage: r.fortune("'WTFM'")

This is all documented in TFM. Those who WTFM don't want to have to WTFM again
on the mailing list. RTFM.
   -- Barry Rowlingson
      R-help (October 2003)

This won't give you a "ready-made" answer, but may point you in the right direction. In last resort, try the source code...

Preview: (hide)
link

Comments

It's really not that obvious. No need for snark.

Iguananaut gravatar imageIguananaut ( 5 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 5 years ago

Seen: 525 times

Last updated: Aug 07 '19