ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 15 Jan 2016 14:46:28 -0600Smart set (database?)http://ask.sagemath.org/question/32217/smart-set-database/Hi,
What I would like is to define a smart hierarchical set (or database) like:
example_set={(0,0,0):[4,[7,11,0]], (0,0,1):[-5,[8,-3,6]], (0,1,0):[4,[7,11,-1]]}
The lefthand side is an hierarchy (a,b,c,d,e,...); the righthand side is some structure [*, [*,*,*,...]] consisting of nested lists. How can I quickly -via a smart design- determine for instance the sum for a higher level? For instance example_set.sum[(0,0)] would yield [4-5, [7,11,0] + [8,-3,6]] and example_set.sum[(0,)] yields [4-5+4, [7,11,0] + [8,-3,6] + [7,11,-1]].
The setting is that we have a few thousand hierarchical elements with unknown depth, but always the same structure on the righthand side. The structure could contain many nested lists with in total several hunderd values (flattened). I like to have (fast) basic operators for the lists within the structure such as addition and index.
Another example.
next_example={(0,0,0):[(5,6)], (0,0,1):[(8,9),(3,4)], (0,1,0):[(2,6)], (0,1,1):[(8,16)]}
(wanted) print next_example.sum[(0, 0)]
[(5, 6), (8, 9), (3, 4)]
I considered to define a class and I looked at [database](http://doc.sagemath.org/html/en/reference/databases/index.html). But that didn't help me much :(
To complicate matters, I would also like to connect hierarchical levels (one-direction). For instance in the first example assume (0,0,0) is connected to (0,1,1). How to store and display such a connection? For connections I looked for instance at [igraph](http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/generic_graph.html#sage.graphs.generic_graph.GenericGraph.igraph_graph). But it isn't clear to me whether it would be helpful in combination with the above mentioned set design.
To summarize: it would be awesome if a routine 'smart_set(n, structure)' would define a n-level hierarchy whereby operations like .sum(input) and .sum.connected(input) and .show_graph() would work.
Suggestions how to move forward in Sage are much appreciated!
Roland
RolandbFri, 15 Jan 2016 14:46:28 -0600http://ask.sagemath.org/question/32217/