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.

How to enumerate trees from a context-free grammar

53 pointsby luu11 months ago

3 comments

bmc750511 months ago
This is a very nice approach. Unfortunately, Piantadosi&#x27;s pairing function does not work for acyclic grammars (i.e., finite CFLs). We found a variant that handles enumerating all trees of a certain width from an arbitrary CFG, i.e., L(G) ∩ Σ^n, or whose language is finite [1]:<p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;breandan&#x2F;galoisenne&#x2F;blob&#x2F;master&#x2F;latex&#x2F;lafi2024&#x2F;acmart.pdf">https:&#x2F;&#x2F;github.com&#x2F;breandan&#x2F;galoisenne&#x2F;blob&#x2F;master&#x2F;latex&#x2F;laf...</a>
rictic11 months ago
Related work: Functional Enumeration of Algebraic Data Types - <a href="https:&#x2F;&#x2F;mengwangoxf.github.io&#x2F;Papers&#x2F;Haskell12.pdf" rel="nofollow">https:&#x2F;&#x2F;mengwangoxf.github.io&#x2F;Papers&#x2F;Haskell12.pdf</a><p>It&#x27;s quite efficient, able to generate the 10^100th element in ~a second on 2013 hardware. It also groups the generated values by size, so you can e.g. randomly sample among ASTs with N nodes.
08234987234987211 months ago
I prefer to enumerate via a shortlex variant, primary key being number of leaves and secondary being the index of the particular expansion.
评论 #40698679 未加载
评论 #40703002 未加载