cse_templates
Stable function · Serialize as a document block
Tier: stable · Kind: function · Topic: Serialize as a document block
| Julia | Python | Rust |
|---|---|---|
cse_templates | cse_templates | cse_templates |
Julia
cse_templates(exprs::Vector{EarthSciAST.ASTExpr}; min_nodes, prefix)
cse_templates(exprs; min_nodes = 12, prefix = "jt")
-> (templates::OrderedDict{String,ASTExpr}, rewritten::Vector{ASTExpr})
Greedy largest-first extraction of repeated subtrees over exprs. Each
round interns the whole working set (input expressions plus the bodies of
templates already extracted), picks the largest subtree that occurs at least
twice and spans at least min_nodes AST nodes, names it "$(prefix)$k",
and replaces every occurrence — in the inputs AND in earlier template
bodies — with an apply_expression_template reference. Terminates when no
candidate remains; the result is a reference DAG (acyclic by strict
containment). Deterministic: ties between equally-sized candidates break by
interning (first-encounter) order over the given expression order.
Python
cse_templates(exprs: list[Expr], min_nodes: int = 12, prefix: str = 'jt')
Greedy largest-first extraction of repeated subtrees. Returns (templates: {name: body}, rewritten exprs).