ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 19 Jan 2016 13:41:06 +0100Smart set (database?)https://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
Fri, 15 Jan 2016 21:46:28 +0100https://ask.sagemath.org/question/32217/smart-set-database/Comment by vdelecroix for <p>Hi,</p>
<p>What I would like is to define a smart hierarchical set (or database) like:</p>
<pre><code> example_set={(0,0,0):[4,[7,11,0]], (0,0,1):[-5,[8,-3,6]], (0,1,0):[4,[7,11,-1]]}
</code></pre>
<p>The lefthand side is an hierarchy (a,b,c,d,e,...); the righthand side is some structure [<em>, [</em>,<em>,</em>,...]] 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]].</p>
<p>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. </p>
<p>Another example.</p>
<pre><code>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)]
</code></pre>
<p>I considered to define a class and I looked at <a href="http://doc.sagemath.org/html/en/reference/databases/index.html">database</a>. But that didn't help me much :(</p>
<p>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 <a href="http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/generic_graph.html#sage.graphs.generic_graph.GenericGraph.igraph_graph">igraph</a>. But it isn't clear to me whether it would be helpful in combination with the above mentioned set design.</p>
<p>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.</p>
<p>Suggestions how to move forward in Sage are much appreciated!</p>
<p>Roland</p>
https://ask.sagemath.org/question/32217/smart-set-database/?comment=32218#post-id-32218What is addition of two lists for you?Fri, 15 Jan 2016 23:53:42 +0100https://ask.sagemath.org/question/32217/smart-set-database/?comment=32218#post-id-32218Comment by Rolandb for <p>Hi,</p>
<p>What I would like is to define a smart hierarchical set (or database) like:</p>
<pre><code> example_set={(0,0,0):[4,[7,11,0]], (0,0,1):[-5,[8,-3,6]], (0,1,0):[4,[7,11,-1]]}
</code></pre>
<p>The lefthand side is an hierarchy (a,b,c,d,e,...); the righthand side is some structure [<em>, [</em>,<em>,</em>,...]] 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]].</p>
<p>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. </p>
<p>Another example.</p>
<pre><code>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)]
</code></pre>
<p>I considered to define a class and I looked at <a href="http://doc.sagemath.org/html/en/reference/databases/index.html">database</a>. But that didn't help me much :(</p>
<p>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 <a href="http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/generic_graph.html#sage.graphs.generic_graph.GenericGraph.igraph_graph">igraph</a>. But it isn't clear to me whether it would be helpful in combination with the above mentioned set design.</p>
<p>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.</p>
<p>Suggestions how to move forward in Sage are much appreciated!</p>
<p>Roland</p>
https://ask.sagemath.org/question/32217/smart-set-database/?comment=32243#post-id-32243For me [1,2] + [3,4] yields [1,2,3,4].Sat, 16 Jan 2016 22:55:50 +0100https://ask.sagemath.org/question/32217/smart-set-database/?comment=32243#post-id-32243Comment by ndomes for <p>Hi,</p>
<p>What I would like is to define a smart hierarchical set (or database) like:</p>
<pre><code> example_set={(0,0,0):[4,[7,11,0]], (0,0,1):[-5,[8,-3,6]], (0,1,0):[4,[7,11,-1]]}
</code></pre>
<p>The lefthand side is an hierarchy (a,b,c,d,e,...); the righthand side is some structure [<em>, [</em>,<em>,</em>,...]] 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]].</p>
<p>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. </p>
<p>Another example.</p>
<pre><code>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)]
</code></pre>
<p>I considered to define a class and I looked at <a href="http://doc.sagemath.org/html/en/reference/databases/index.html">database</a>. But that didn't help me much :(</p>
<p>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 <a href="http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/generic_graph.html#sage.graphs.generic_graph.GenericGraph.igraph_graph">igraph</a>. But it isn't clear to me whether it would be helpful in combination with the above mentioned set design.</p>
<p>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.</p>
<p>Suggestions how to move forward in Sage are much appreciated!</p>
<p>Roland</p>
https://ask.sagemath.org/question/32217/smart-set-database/?comment=32258#post-id-32258Your examples behave different. The second example concatenates lists, the first one adds up the respective items of two lists.Sun, 17 Jan 2016 19:04:49 +0100https://ask.sagemath.org/question/32217/smart-set-database/?comment=32258#post-id-32258Comment by Rolandb for <p>Hi,</p>
<p>What I would like is to define a smart hierarchical set (or database) like:</p>
<pre><code> example_set={(0,0,0):[4,[7,11,0]], (0,0,1):[-5,[8,-3,6]], (0,1,0):[4,[7,11,-1]]}
</code></pre>
<p>The lefthand side is an hierarchy (a,b,c,d,e,...); the righthand side is some structure [<em>, [</em>,<em>,</em>,...]] 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]].</p>
<p>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. </p>
<p>Another example.</p>
<pre><code>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)]
</code></pre>
<p>I considered to define a class and I looked at <a href="http://doc.sagemath.org/html/en/reference/databases/index.html">database</a>. But that didn't help me much :(</p>
<p>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 <a href="http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/generic_graph.html#sage.graphs.generic_graph.GenericGraph.igraph_graph">igraph</a>. But it isn't clear to me whether it would be helpful in combination with the above mentioned set design.</p>
<p>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.</p>
<p>Suggestions how to move forward in Sage are much appreciated!</p>
<p>Roland</p>
https://ask.sagemath.org/question/32217/smart-set-database/?comment=32286#post-id-32286Yes, the examples behave different. In general if [A[B[C]]] and [X[Y[Z]]] are element of the structure, I want to define what A+X, B+Y and C+Z are. It can be concatenating a list or the addition of numbers. The structure therefor must be defined including the addition operators.Mon, 18 Jan 2016 22:37:00 +0100https://ask.sagemath.org/question/32217/smart-set-database/?comment=32286#post-id-32286Comment by ndomes for <p>Hi,</p>
<p>What I would like is to define a smart hierarchical set (or database) like:</p>
<pre><code> example_set={(0,0,0):[4,[7,11,0]], (0,0,1):[-5,[8,-3,6]], (0,1,0):[4,[7,11,-1]]}
</code></pre>
<p>The lefthand side is an hierarchy (a,b,c,d,e,...); the righthand side is some structure [<em>, [</em>,<em>,</em>,...]] 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]].</p>
<p>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. </p>
<p>Another example.</p>
<pre><code>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)]
</code></pre>
<p>I considered to define a class and I looked at <a href="http://doc.sagemath.org/html/en/reference/databases/index.html">database</a>. But that didn't help me much :(</p>
<p>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 <a href="http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/generic_graph.html#sage.graphs.generic_graph.GenericGraph.igraph_graph">igraph</a>. But it isn't clear to me whether it would be helpful in combination with the above mentioned set design.</p>
<p>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.</p>
<p>Suggestions how to move forward in Sage are much appreciated!</p>
<p>Roland</p>
https://ask.sagemath.org/question/32217/smart-set-database/?comment=32291#post-id-32291An experiment with your examples:
https://sagecell.sagemath.org/?q=yterpqTue, 19 Jan 2016 13:41:06 +0100https://ask.sagemath.org/question/32217/smart-set-database/?comment=32291#post-id-32291