Version: dev

cse_templates

Stable function · Serialize as a document block

Tier: stable · Kind: function · Topic: Serialize as a document block

JuliaPythonRust
cse_templatescse_templatescse_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.

Source

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).

Source

Rust

pub fn cse_templates(exprs: &[Expr], min_nodes: usize, prefix: &str) -> (Vec<(String, Expr)>, Vec<Expr>)

Greedy largest-first extraction; deterministic (first-encounter order, first-max tie-break) to match the reference byte-for-byte.

Source · Rust docs