HerbInterpret.jl Documentation
HerbInterpret._is_input_tag — Method
_is_input_tag(tag, input_set)Checks whether a tag is an input. A tag is treated as an input terminal if:
- it is a
Symbolthat contains the substring"_arg_"(the default convention), OR input_setis provided andtag ∈ input_set.
HerbInterpret._qualify — Method
_qualify(target_module::Module, f)Resolve symbol f in target_module at compile time.
HerbInterpret.build_match_cases — Method
build_match_cases(grammar; target_module=@__MODULE__, input_symbols=nothing)Return a vector of "guarded return" branches of the form:
r == k && return <rhs>These branches are intended to be spliced into a block after r = get_rule(prog); c = get_children(prog).
Returns a vector of branching expressions.
HerbInterpret.build_match_cases_stateful — Method
build_match_cases_stateful_rgf(grammar; target_module=@__MODULE__, state_name=:state, max_steps=1000)Like build_match_cases_stateful, but emits code for a RuntimeGeneratedFunction body:
- recursion is expressed as
self(self, child, state) WHILEis inlined (bounded bymax_steps) to avoid needing external helpers
HerbInterpret.evaluate_program — Method
evaluate_program(program::RuleNode, examples::Vector{<:IOExample}, grammar::AbstractGrammar, evaluation_function::Function)Runs a program on the examples and returns tuples of actual desired output and the program's output
HerbInterpret.execute_on_input — Method
execute_on_input(grammar::AbstractGrammar, program::RuleNode, input::Dict{Symbol, T})::Any where TConverts a RuleNode program into an expression using a given grammar, then evaluates this expression with a single input dictionary input and a symbol table derived from the grammar using execute_on_input(tab::SymbolTable, expr::Any, input::Dict{Symbol, T}).
Arguments
grammar::AbstractGrammar: A grammar object used to convert theRuleNodeinto an executable expression.program::RuleNode: The program, represented as aRuleNode, to be converted and evaluated.input::Dict{Symbol, T}: A dictionary providing input values for symbols used in the generated expression.
Returns
Any: The result of evaluating the generated expression with the given input dictionary.
HerbInterpret.execute_on_input — Method
execute_on_input(grammar::AbstractGrammar, program::RuleNode, input::Vector{T})::Vector{Any} where T <: Dict{Symbol, <:Any}Converts a RuleNode program into an expression using a given grammar, then evaluates this expression for each input dictionary in a vector input and a symbol table derived from the grammar using execute_on_input(tab::SymbolTable, expr::Any, input::Dict{Symbol, T}).
Arguments
grammar::AbstractGrammar: A grammar object used to convert theRuleNodeinto an executable expression.program::RuleNode: The program, represented as aRuleNode, to be converted and evaluated.input::Vector{T}: A vector of dictionaries, each providing input values for symbols used in the generated expression.
Returns
Vector{Any}: A vector containing the results of evaluating the generated expression for each input dictionary.
HerbInterpret.execute_on_input — Method
execute_on_input(tab::SymbolTable, expr::Any, input::Dict{Symbol, T})::Any where TEvaluates an expression expr within the context of a symbol table tab and a single input dictionary input. The input dictionary keys should match the symbols used in the expression, and their values are used during the expression's evaluation.
Arguments
tab::SymbolTable: A symbol table containing predefined symbols and their associated values or functions.expr::Any: The expression to be evaluated. Can be any Julia expression that is valid within the context of the provided symbol table and input.input::Dict{Symbol, T}: A dictionary where each key is a symbol used in the expression, and the value is the corresponding value to be used in the expression's evaluation. The typeTcan be any type.
Returns
Any: The result of evaluating the expression with the given symbol table and input dictionary.
HerbInterpret.execute_on_input — Method
execute_on_input(tab::SymbolTable, expr::Any, input::Vector{T})::Vector{<:Any} where T <: Dict{Symbol, <:Any}Wrapper around execute_on_input to execute all inputs given as an array.
Arguments
tab::SymbolTable: A symbol table containing predefined symbols and their associated values or functions.expr::Any: The expression to be evaluated for each input dictionary.inputs::Vector{T}: A vector of dictionaries, each serving as an individual set of inputs for the expression's evaluation.
Returns
Vector{<:Any}: A vector containing the results of evaluating the expression for each input dictionary.
HerbInterpret.interpret — Method
interpret(tab::SymbolTable, ex::Expr)Evaluates an expression without compiling it. Uses AST and symbol lookups. Only supports :call and :(=) expressions at the moment.
Example usage:
tab = SymbolTable(:f => f, :x => x)
ex = :(f(x))
interpret(tab, ex)WARNING: This function throws exceptions that are caused in the given expression. These exceptions have to be handled by the caller of this function.
HerbInterpret.make_interpreter — Method
make_interpreter(grammar::AbstractGrammar; input_symbols::Union{Nothing,AbstractVector{Symbol}} = nothing, target_module::Module = @__MODULE__, cache_module::Module = HerbInterpret)Construct a fast, runtime-generated interpreter for programs represented as HerbCore.AbstractRuleNodes.
The returned value is a callable GeneratedInterpreter (a small wrapper around a RuntimeGeneratedFunctions.RuntimeGeneratedFunction) that can be applied to:
- a single input dictionary:
interp(prog, input::AbstractDict{Symbol,Any}) - a vector of input dictionaries:
interp(prog, inputs::AbstractVector{<:AbstractDict{Symbol,Any}}) - a single
HerbSpecification.IOExample:interp(prog, ex::IOExample)(usesex.in) - a vector of
IOExamples:interp(prog, exs::AbstractVector{<:IOExample})
Arguments
grammar: The grammar whose rule indices define the operational semantics. The interpreter dispatches byr = HerbCore.get_rule(prog).
Keyword arguments
input_symbols: Optional list of symbols that should be interpreted as inputs. If provided, terminals matching these symbols (and any symbol following the_arg_convention) are read from theinputdict.target_module: Module in which operator/function symbols appearing in the grammar are resolved. This is important when the grammar uses domain-specific primitives (e.g.concat_cvc,substr_cvc) that are defined in a benchmark module rather than in the caller’s module.cache_module: Module used byRuntimeGeneratedFunctions.jlto store its internal cache.
HerbInterpret.make_stateful_interpreter — Method
make_stateful_interpreter_rgf(grammar; target_module=@__MODULE__, cache_module=HerbInterpret, max_steps=1000)Build a RuntimeGeneratedFunctions-backed state-threading interpreter.
target_modulecontrols where primitives (inc, moveRight, etc.) are resolved.cache_modulecontrols where RGF stores its cache. This module must haveRuntimeGeneratedFunctions.init(@__MODULE__)executed at module top level.max_stepsbounds generated WHILE loops.
Index
HerbConstraints.ASPSolverHerbConstraints.ASPSolverHerbConstraints.AbstractGrammarConstraintHerbConstraints.AbstractLocalConstraintHerbConstraints.AbstractStateManagerHerbConstraints.AnnotatedGrammarHerbConstraints.ContainsHerbConstraints.ContainsSubtreeHerbConstraints.DomainRuleNodeHerbConstraints.ForbiddenHerbConstraints.ForbiddenSequenceHerbConstraints.GenericSolverHerbConstraints.GenericSolverHerbConstraints.GenericSolverHerbConstraints.LessThanOrEqualHardFailHerbConstraints.LessThanOrEqualResultHerbConstraints.LessThanOrEqualSoftFailHerbConstraints.LessThanOrEqualSuccessHerbConstraints.LessThanOrEqualSuccessEqualityHerbConstraints.LessThanOrEqualSuccessLessThanHerbConstraints.LessThanOrEqualSuccessWithHolesHerbConstraints.LocalContainsHerbConstraints.LocalContainsSubtreeHerbConstraints.LocalContainsSubtreeHerbConstraints.LocalForbiddenHerbConstraints.LocalForbiddenSequenceHerbConstraints.LocalOrderedHerbConstraints.LocalUniqueHerbConstraints.MakeEqualHardFailHerbConstraints.MakeEqualResultHerbConstraints.MakeEqualSoftFailHerbConstraints.MakeEqualSuccessHerbConstraints.OrderedHerbConstraints.PatternMatchHardFailHerbConstraints.PatternMatchResultHerbConstraints.PatternMatchSoftFailHerbConstraints.PatternMatchSuccessHerbConstraints.PatternMatchSuccessWhenHoleAssignedToHerbConstraints.SolverHerbConstraints.SolverStateHerbConstraints.StateHoleHerbConstraints.StateHoleHerbConstraints.StateHoleHerbConstraints.StateIntHerbConstraints.StateIntBackupHerbConstraints.StateManagerHerbConstraints.StateSparseSetHerbConstraints.StateSparseSetHerbConstraints.StateStackHerbConstraints.StateStackHerbConstraints.StateStackHerbConstraints.UniformSolverHerbConstraints.UniformSolverHerbConstraints.UniqueHerbConstraints.VarNodeHerbCore.AbstractConstraintHerbCore.AbstractGrammarHerbCore.AbstractHoleHerbCore.AbstractRuleNodeHerbCore.AbstractUniformHoleHerbCore.HoleHerbCore.HoleReferenceHerbCore.RuleNodeHerbCore.RuleNodeHerbCore.RuleNodeHerbCore.UniformHoleHerbGrammar.ContextSensitiveGrammarHerbGrammar.NodeLocHerbGrammar.SymbolTableHerbSearch.AbstractAddressHerbSearch.AbstractBFSIteratorHerbSearch.AbstractCostBasedBottomUpIteratorHerbSearch.AbstractDFSIteratorHerbSearch.AbstractMHSearchIteratorHerbSearch.AbstractSASearchIteratorHerbSearch.AbstractVLSNSearchIteratorHerbSearch.AccessAddressHerbSearch.BFSASPIteratorHerbSearch.BFSIteratorHerbSearch.BankEntryHerbSearch.BottomUpIteratorHerbSearch.BottomUpStateHerbSearch.CombineAddressHerbSearch.ConstraintStyleHerbSearch.CostBasedBottomUpIteratorHerbSearch.DFSASPIteratorHerbSearch.DFSIteratorHerbSearch.DepthBasedBottomUpIteratorHerbSearch.ExpandFailureReasonHerbSearch.GenericBUStateHerbSearch.GeneticSearchIteratorHerbSearch.MHSearchIteratorHerbSearch.MLFSIteratorHerbSearch.MeasureHashedBankHerbSearch.ProgramIteratorHerbSearch.RandomIteratorHerbSearch.SASearchIteratorHerbSearch.SizeBasedBottomUpIteratorHerbSearch.StochasticSearchIteratorHerbSearch.SynthResultHerbSearch.TopDownIteratorHerbSearch.UniformASPIteratorHerbSearch.UniformASPIteratorHerbSearch.UniformIteratorHerbSearch.UniformIteratorHerbSearch.VLSNSearchIteratorHerbSpecification.AbstractDependentTypeSpecificationHerbSpecification.AgdaSpecificationHerbSpecification.IOExampleHerbSpecification.MetricProblemHerbSpecification.ProblemHerbSpecification.SMTSpecificationHerbSpecification.TraceBase.collectBase.collectBase.collectBase.findallBase.findfirstBase.findlastBase.getBase.getindexBase.getindexBase.inBase.inBase.insert!Base.islessBase.iterateBase.iterateBase.iterateBase.iterateBase.iterateBase.iterateBase.iterateBase.lengthBase.lengthBase.lengthBase.lengthBase.lengthBase.push!Base.randBase.randBase.randBase.showBase.sizeBase.sizeBase.sizeBase.sumHerbConstraints._containsHerbConstraints._count_occurrencesHerbConstraints._count_occurrencesHerbConstraints._count_occurrences!HerbConstraints._exchange_positions!HerbConstraints._update_bounds_val_removed!HerbConstraints._update_max_val_removed!HerbConstraints._update_min_val_removed!HerbConstraints.are_disjointHerbConstraints.are_disjointHerbConstraints.backup!HerbConstraints.check_treeHerbConstraints.check_treeHerbConstraints.check_treeHerbConstraints.check_treeHerbConstraints.check_treeHerbConstraints.check_treeHerbConstraints.contains_varnodeHerbConstraints.deactivate!HerbConstraints.deactivate!HerbConstraints.decrement!HerbConstraints.expr2csgrammar_annotatedHerbConstraints.fix_point!HerbConstraints.freeze_stateHerbConstraints.get_bylabelHerbConstraints.get_grammarHerbConstraints.get_grammarHerbConstraints.get_grammarHerbConstraints.get_grammarHerbConstraints.get_hole_at_locationHerbConstraints.get_hole_at_locationHerbConstraints.get_intersectionHerbConstraints.get_labeldomainHerbConstraints.get_max_depthHerbConstraints.get_max_depthHerbConstraints.get_max_sizeHerbConstraints.get_max_sizeHerbConstraints.get_nodesHerbConstraints.get_nodes_on_pathHerbConstraints.get_priorityHerbConstraints.get_rule_annotationsHerbConstraints.get_starting_symbolHerbConstraints.get_starting_symbolHerbConstraints.get_stateHerbConstraints.get_treeHerbConstraints.get_treeHerbConstraints.get_tree_sizeHerbConstraints.get_valueHerbConstraints.increment!HerbConstraints.is_subdomainHerbConstraints.is_subdomainHerbConstraints.isfeasibleHerbConstraints.isfeasibleHerbConstraints.load_state!HerbConstraints.make_equal!HerbConstraints.make_less_than_or_equal!HerbConstraints.make_less_than_or_equal!HerbConstraints.make_less_than_or_equal!HerbConstraints.new_state!HerbConstraints.notify_new_nodeHerbConstraints.notify_new_nodesHerbConstraints.notify_new_nodesHerbConstraints.notify_tree_manipulationHerbConstraints.notify_tree_manipulationHerbConstraints.partitionHerbConstraints.pattern_matchHerbConstraints.pattern_matchHerbConstraints.pattern_matchHerbConstraints.pattern_matchHerbConstraints.pattern_matchHerbConstraints.pattern_matchHerbConstraints.post!HerbConstraints.post!HerbConstraints.propagate!HerbConstraints.propagate!HerbConstraints.propagate!HerbConstraints.propagate!HerbConstraints.propagate!HerbConstraints.propagate!HerbConstraints.propagate!HerbConstraints.remove!HerbConstraints.remove!HerbConstraints.remove!HerbConstraints.remove!HerbConstraints.remove!HerbConstraints.remove_above!HerbConstraints.remove_above!HerbConstraints.remove_above!HerbConstraints.remove_all_but!HerbConstraints.remove_all_but!HerbConstraints.remove_all_but!HerbConstraints.remove_all_but!HerbConstraints.remove_all_but!HerbConstraints.remove_all_but!HerbConstraints.remove_below!HerbConstraints.remove_below!HerbConstraints.remove_below!HerbConstraints.remove_node!HerbConstraints.restore!HerbConstraints.restore!HerbConstraints.restore!HerbConstraints.save_state!HerbConstraints.save_state!HerbConstraints.save_state!HerbConstraints.schedule!HerbConstraints.set_infeasible!HerbConstraints.set_infeasible!HerbConstraints.set_value!HerbConstraints.shouldscheduleHerbConstraints.shouldscheduleHerbConstraints.simplify_hole!HerbConstraints.substitute!HerbCore.contains_holeHerbCore.contains_holeHerbCore.contains_indexHerbCore.contains_nonuniform_holeHerbCore.depthHerbCore.depthHerbCore.get_childrenHerbCore.get_node_at_locationHerbCore.get_node_at_locationHerbCore.get_node_at_locationHerbCore.get_node_at_locationHerbCore.get_pathHerbCore.get_pathHerbCore.get_pathHerbCore.get_ruleHerbCore.get_ruleHerbCore.get_rulesequenceHerbCore.hasdynamicvalueHerbCore.have_same_shapeHerbCore.is_domain_validHerbCore.isfilledHerbCore.isfilledHerbCore.issameHerbCore.isuniformHerbCore.node_depthHerbCore.number_of_holesHerbCore.rulesoftypeHerbCore.rulesoftypeHerbCore.rulesonleftHerbCore.swap_nodeHerbCore.swap_nodeHerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbGrammar.add_rule!HerbGrammar.add_rule!HerbGrammar.add_rule!HerbGrammar.addconstraint!HerbGrammar.addconstraint!HerbGrammar.child_typesHerbGrammar.child_typesHerbGrammar.cleanup_removed_rules!HerbGrammar.clearconstraints!HerbGrammar.containedinHerbGrammar.contains_returntypeHerbGrammar.expr2csgrammarHerbGrammar.expr2pcsgrammarHerbGrammar.expr2rulenodeHerbGrammar.expr2rulenodeHerbGrammar.expr2rulenodeHerbGrammar.expr2rulenodeHerbGrammar.get_childtypesHerbGrammar.get_domainHerbGrammar.get_domainHerbGrammar.get_rulesequenceHerbGrammar.grammar2symboltableHerbGrammar.init_probabilities!HerbGrammar.iscompleteHerbGrammar.isevalHerbGrammar.isevalHerbGrammar.isevalHerbGrammar.isprobabilisticHerbGrammar.isterminalHerbGrammar.isterminalHerbGrammar.isterminalHerbGrammar.isvariableHerbGrammar.isvariableHerbGrammar.isvariableHerbGrammar.isvariableHerbGrammar.log_probabilityHerbGrammar.max_arityHerbGrammar.max_rulenode_log_probabilityHerbGrammar.merge_grammars!HerbGrammar.mindepthHerbGrammar.mindepth_mapHerbGrammar.nchildrenHerbGrammar.nchildrenHerbGrammar.nonterminalsHerbGrammar.normalize!HerbGrammar.parse_probabilistic_ruleHerbGrammar.probabilityHerbGrammar.read_csgHerbGrammar.read_pcsgHerbGrammar.remove_rule!HerbGrammar.return_typeHerbGrammar.return_typeHerbGrammar.return_typeHerbGrammar.root_node_locHerbGrammar.rulenode2exprHerbGrammar.rulenode_log_probabilityHerbGrammar.rulesonleftHerbGrammar.store_csgHerbGrammar.subsequenceofHerbGrammar.swap_nodeHerbGrammar.swap_nodeHerbInterpret._is_input_tagHerbInterpret._qualifyHerbInterpret.build_match_casesHerbInterpret.build_match_cases_statefulHerbInterpret.evaluate_programHerbInterpret.execute_on_inputHerbInterpret.execute_on_inputHerbInterpret.execute_on_inputHerbInterpret.execute_on_inputHerbInterpret.interpretHerbInterpret.make_interpreterHerbInterpret.make_stateful_interpreterHerbSearch._calc_measureHerbSearch._calc_measureHerbSearch._calc_measureHerbSearch._calculate_costHerbSearch._extract_name_from_argumentHerbSearch._find_next_complete_treeHerbSearch._hash_outputs_to_u64vecHerbSearch._is_field_declHerbSearch._is_kwdefHerbSearch._processkwarg!HerbSearch.acceptHerbSearch.add_to_bank!HerbSearch.add_to_bank!HerbSearch.add_to_bank!HerbSearch.best_acceptHerbSearch.calc_measureHerbSearch.calc_measureHerbSearch.calculate_costHerbSearch.combineHerbSearch.combineHerbSearch.compute_new_horizonHerbSearch.compute_new_horizonHerbSearch.const_temperatureHerbSearch.constraint_styleHerbSearch.constructNeighbourhoodHerbSearch.constructNeighbourhoodRuleSubsetHerbSearch.convert_to_rulenode!HerbSearch.cross_overHerbSearch.crossover_swap_children_1HerbSearch.crossover_swap_children_2HerbSearch.decreasing_temperatureHerbSearch.default_fitnessHerbSearch.derivation_heuristicHerbSearch.derivation_heuristicHerbSearch.derivation_heuristicHerbSearch.enumerate_neighbours_proposeHerbSearch.evaluateHerbSearch.fill_hole!HerbSearch.fitnessHerbSearch.generate_branchesHerbSearch.generate_branchesHerbSearch.get_bankHerbSearch.get_best_programHerbSearch.get_entriesHerbSearch.get_indexHerbSearch.get_measureHerbSearch.get_measure_limitHerbSearch.get_measure_limitHerbSearch.get_measure_limitHerbSearch.get_measuresHerbSearch.get_next_programHerbSearch.get_programsHerbSearch.get_return_typeHerbSearch.get_rule_costHerbSearch.get_solverHerbSearch.get_typesHerbSearch.heuristic_leftmostHerbSearch.heuristic_randomHerbSearch.heuristic_rightmostHerbSearch.heuristic_smallest_domainHerbSearch.hole_heuristicHerbSearch.init_combine_structureHerbSearch.is_observationally_equivalentHerbSearch.mean_squared_errorHerbSearch.measure_typeHerbSearch.measure_typeHerbSearch.misclassificationHerbSearch.mutate!HerbSearch.mutate_random!HerbSearch.neighbourhoodHerbSearch.new_addressHerbSearch.next_solution!HerbSearch.next_solution!HerbSearch.populate_bank!HerbSearch.populate_bank!HerbSearch.priority_functionHerbSearch.priority_functionHerbSearch.priority_functionHerbSearch.priority_functionHerbSearch.probabilistic_acceptHerbSearch.probabilistic_accept_with_temperatureHerbSearch.probabilistic_accept_with_temperature_fractionHerbSearch.proposeHerbSearch.random_fill_proposeHerbSearch.retrieveHerbSearch.retrieveHerbSearch.retrieveHerbSearch.select_chromosomeHerbSearch.select_fitness_proportional_parentsHerbSearch.select_parentsHerbSearch.set_stateholes!HerbSearch.set_stateholes!HerbSearch.synthHerbSearch.temperatureHerbSearch.validate_iteratorStatsBase.sampleStatsBase.sampleStatsBase.sampleStatsBase.sampleHerbConstraints.@csgrammar_annotatedHerbCore.@rulenodeHerbGrammar.@cfgrammarHerbGrammar.@csgrammarHerbGrammar.@pcsgrammarHerbSearch.@programiterator