TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Not all graphs are trees

117 pointsby g0xA52A2Aabout 1 year ago

12 comments

codefloabout 1 year ago
This made me scratch my head:<p>&gt; Even in a language like Rust, which has not yet implemented mutable aliasing (an oft-requested feature stuck at the RFC stage)<p>Disallowing mutable aliasing is in fact the whole point of Rust. Perhaps it’s “requested” by people still learning the language? Is the “not yet implemented” part meant as irony? Does the author mean something else?
评论 #40233474 未加载
评论 #40233469 未加载
srcreighabout 1 year ago
Can someone explain the relationship between implementing WITH (…) AS X … and integer linear programs?<p>I wish this post had more examples of concrete non-tree queries. Is cross-joining a CTE to itself realistic?<p>Imo this discussion seems to assume multiple references of a CTE contain many of the same rows with different transforms which are later joined.. what’s an actual example of this? I don’t think I’ve ever seen it<p>Usually CTEs are shorthand for doing a few joins. And when you reference them multiple times, it’s almost always with different rows in the CTE table. AKA little-no reuse potential. Postgres WITH AS NOT MATERIALIZED of course
评论 #40232257 未加载
评论 #40237560 未加载
MrLeapabout 1 year ago
I didn&#x27;t know about datalog before reading this! I became kind of smitten with prolog in college but never found an opportunity to use it.<p>Now that I&#x27;m a gamedev, if there&#x27;s a permissively licensed C&#x2F;C++ or a DLL, or something in .net land that would let me store facts and rules and run some queries, I could put it to work.<p>If anyone that reads this has cooked with deductive databases &#x2F; theorem proving &#x2F; logic programming languages things I&#x27;d love to hear your guidepost opinions.
评论 #40232342 未加载
评论 #40233453 未加载
mfocabout 1 year ago
For clarity, in (computer science) graph theory, a tree is a rooted, strict, connected, undirected, acyclic graph.<p>Explanation:<p>rooted: One vertex (also called a node) has been designated the root. The depth of a vertex is the number of branches in the path from root to the vertex. So depth of the root itself is zero and is the only vertex in the tree with this property.<p>strict: The edges have no weight(s).<p>connected: A graph is said to be connected if there is a path (edge) between every pair of vertices. From every node to any other node, there is a path to traverse.<p>undirected: The edges have no directionality specified.<p>acyclic: The are no closed loops (no cycles of any length).<p>graph: An abstract data structure consisting of a finite set of vertices and a finite set of edges (vertices pairs).<p>As another commenter has pointed out, the definition of a tree in mathematics is somewhat different...a tree need not have a root.
评论 #40240748 未加载
Vt71fcAqt7about 1 year ago
A tree is a type of graph. Is the headline meant to reveal the fact that not all graphs are trees (which is obvious) or is it meant like &quot;not all graphs are trees, and here&#x27;s how you deal with those non-tree graphs?&quot; Even then I&#x27;m confused about the title of the article.
GrantMoyerabout 1 year ago
For anyone getting caught up in the notation, note that the actual example expressions are immaterial; you might as well replace the strange looking relational algebra operators with &quot;=&quot;s or &quot;+&quot;s. At it&#x27;s core the article is covering different ways to represent graphs, and demonstrating that one particular method allows concise representation of graphs that aren&#x27;t easily represented by linear expressions (linear in the graph sense, not the linear algebra sense).<p>In order, the representations are:<p>1. &quot;Inlining&quot;, a direct tree structure, in C++-like syntax something like `struct Node {vector&lt;Node&gt;;}`. The insight here is that if you&#x27;re not storing a tree, some of the nodes need to be duplicated.<p>2. &quot;Let Bindings&quot;, An indirect tree structure, like `struct Node {vector&lt;Node*&gt;;}`. Here, the insight is that instead of storing nodes, you store <i>names of</i> nodes (in this case pointers), so that the nodes can be re-used. Note that the nodes themselves may be stored somewhere else in the same expressions.<p>3. &quot;Self-Reference&quot;, same as above, but a node can store the name of itself, or one of its ancestors.<p>4. &quot;Fixpoint Operator&quot;, Instead of explicitly storing a graph, we store a transformation from one graph to another, then say the graph we want equals that transformation repeatedly applied to some starting graph, until the transformation&#x27;s output equals its input (a.k.a. a fixed point is found). Something like `struct ImplicitGraph {Graph initial; Graph (*)(Graph) transform;}`. If you&#x27;re unfamiliar with C++ function pointers, transform is a function from Graph to Graph. The &quot;hole&quot; the author talks about refers to the fact that the output graph of the transformation can contain copies of the input graph, so the &quot;hole&quot; is the transform parameter; there&#x27;s a &quot;hole&quot; in the output graph until the parameter is known. Since the transformation can be arbitrarily complex, any graph can be represented, although typically, you&#x27;d want as simple a transform as possible.<p>5. &quot;Explicit Listing of Edges&quot;, this method is actually more straightforward than the previous, but it requires thinking about the graph a little differently. It&#x27;s exactly what it says on the tin; instead of the graph being implicit in the structure of the data, the edges (a.k.a. links or lines) are explicitly listed. There&#x27;s more than one way to do this, for example a straightforward way might look like `struct Graph {set&lt;Node&gt;; set&lt;pair&lt;Node*, Node*&gt;&gt;;}`. From the example in the article, it looks like Datalog is closer to something like `struct Graph {set&lt;Node&gt; initial_nodes; set&lt;optional&lt;Node&gt; (*)(Node)&gt; generators;}`. Kind of like in 4., you start with a set of nodes, then repeatedly apply each generator to each node until you stop getting new nodes. The edges in this case are between each node and the nodes it generates.<p>Finally, all of these types of representations also exist syntactically, not just structurally. After all, an expression in a given syntax is just a way of representing some structure, the same way a bunch of bytes in memory can be a way of representing some structure. And each of these representations has strengths syntactically and structurally.
smitty1eabout 1 year ago
When I hear &#x27;tree&#x27; I think <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Directed_acyclic_graph" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Directed_acyclic_graph</a>
评论 #40231393 未加载
评论 #40231291 未加载
koolalaabout 1 year ago
1960: Arrays (Lisp)<p>2001: Arrays &amp; Trees (Json)<p>2042: Graphs, Trees, Arrays (XML final era)
mawekiabout 1 year ago
One of the main problems in programming is, that a self-referential structure may be cyclic and a cyclic structure combined with eager evaluation leads to a infinitely looping program.<p>As Haskell is lazy, this self-referencing is quite nice. There is this reddit-joke about implementing an is-even function. In haskell we can write an infinite list of alternating True&#x2F;False like `alt = True : False : alt` and is-even is now `is_even n = alt !! n` where !! is array access.<p>Even if the data structure is not cyclic, but you&#x27;re talking about sharing, then you have to have syntax about explicit sharing and the lifetime of the share (immutability comes to the rescue again), as detecting sharing is a very difficult problem in and of itself.
kirmerzlikinabout 1 year ago
Did anyone catch why `Let` type in the second code listing had to have both `expr` and `value` properties?
评论 #40234859 未加载
EricRieseabout 1 year ago
#NotAllGraphs
kazinatorabout 1 year ago
Not all graphs are trees, but all the graphs in this article are trees.<p>They are DAGs, which are a deduplicated representation of trees.
评论 #40233335 未加载