HerbCore.jl Documentation
HerbCore.AbstractConstraint
— TypeRepresents a constraint for a AbstractGrammar
. Concrete implementations can be found in HerbConstraints.jl.
HerbCore.AbstractGrammar
— TypeAbstractGrammar
Abstract type representing all grammars. It is assumed that all grammar structs have at least the following attributes:
rules::Vector{Any}
: A list of RHS of rules (subexpressions).types::Vector{Symbol}
: A list of LHS of rules (types, all symbols).isterminal::BitVector
: A bitvector where biti
represents whether rulei
is terminal.iseval::BitVector
: A bitvector where biti
represents whether rule i is an eval rule.bytype::Dict{Symbol,Vector{Int}}
: A dictionary that maps a type to all rules of said type.domains::Dict{Symbol, BitVector}
: A dictionary that maps a type to a domain bitvector. The domain bitvector has biti
set to true iff thei
th rule is of this type.childtypes::Vector{Vector{Symbol}}
: A list of types of the children for each rule.
If a rule is terminal, the corresponding list is empty.
log_probabilities::Union{Vector{Real}, Nothing}
: A list of probabilities for each rule.
If the grammar is non-probabilistic, the list can be nothing
.
For concrete types, see ContextSensitiveGrammar
within the HerbGrammar
module.
HerbCore.AbstractHole
— TypeAbstractHole <: AbstractRuleNode
A AbstractHole
is a placeholder where certain rules from the grammar can still be applied. The domain
of a AbstractHole
defines which rules can be applied. The domain
is a bitvector, where the i
th bit is set to true if the i
th rule in the grammar can be applied.
HerbCore.AbstractRuleNode
— Typeabstract type AbstractRuleNode end
Abstract type for representing expression trees. An AbstractRuleNode
is expected to implement the following functions:
isfilled(::AbstractRuleNode)::Bool
. True iff the grammar rule this node holds is not ambiguous, i.e. has domain size 1.isuniform(::AbstractRuleNode)::Bool
. True iff the children of this node are known.get_rule(::AbstractRuleNode)::Int
. Returns the index of the grammar rule it represents.get_children(::AbstractRuleNode)::Vector{AbstractRuleNode}
. Returns the children of this node.
Expression trees consist of RuleNode
s and AbstractHole
s.
- A
RuleNode
represents a certain production rule in theAbstractGrammar
. - A
AbstractHole
is a placeholder where certain rules in the grammar still can be applied.
HerbCore.AbstractUniformHole
— TypeHole <: AbstractHole
An AbstractUniformHole
is a placeholder where certain rules from the grammar can still be applied, but all rules in the domain are required to have the same childtypes.
HerbCore.Hole
— TypeHole <: AbstractHole
domain
: A bitvector, where thei
th bit is set to true if thei
th rule in the grammar can be applied.
HerbCore.HoleReference
— TypeHoleReference
Contains a hole and the path to the hole from the root of the tree.
HerbCore.RuleNode
— TypeRuleNode <: AbstractRuleNode
A RuleNode
represents a node in an expression tree. Each node corresponds to a certain rule in the AbstractGrammar
. A RuleNode
consists of:
ind
: The index of the rule in theAbstractGrammar
which this node is representing._val
: Field for caching evaluations ofRuleNode
s, preventing multiple unnecessary evaluations. The field can be used to store any needed infromation.children
: The children of this node in the expression tree
Evaluate immediately functionality is not yet supported by most of Herb.jl.
HerbCore.RuleNode
— MethodRuleNode(ind::Int, _val::Any)
Create a RuleNode
for the AbstractGrammar
rule with index ind
, _val
as immediately evaluated value and no children
Only use this constructor if you are absolutely certain that a rule is terminal and cannot have children. Use [RuleNode(ind::Int, grammar::AbstractGrammar)
] for rules that might have children. In general, AbstractHole
s should be used as a placeholder when the children of a node are not yet known.
Evaluate immediately functionality is not yet supported by most of Herb.jl.
HerbCore.RuleNode
— MethodRuleNode(ind::Int, children::Vector{AbstractRuleNode})
Create a RuleNode
for the AbstractGrammar
rule with index ind
and children
as subtrees.
HerbCore.UniformHole
— TypeUniformHole <: AbstractHole
domain
: A bitvector, where thei
th bit is set to true if thei
th rule in the grammar can be applied. All rules in the domain are required to have the same childtypes.children
: The children of this hole in the expression tree.
HerbCore.@rulenode
— Macro@rulenode
Construct a RuleNode
using the shorthand notation RuleNode
s are printed with using Base.show
. Does not support AbstractHole
s.
Examples
julia> @rulenode 1{4{5,6},1{2,3}}
1{4{5,6},1{2,3}}
julia> @rulenode 1
1
julia> @rulenode 1{2, 3}
1{2,3}
Base.isless
— MethodBase.isless(rn₁::AbstractRuleNode, rn₂::AbstractRuleNode)::Bool
Compares two RuleNode
s. Returns true if the left RuleNode
is less than the right RuleNode
. Order is determined from the index of the RuleNode
s. If both RuleNode
s have the same index, a depth-first search is performed in both RuleNode
s until nodes with a different index are found.
Base.length
— MethodBase.length(root::RuleNode)
Return the number of nodes in the tree rooted at root.
HerbCore.contains_hole
— Methodcontains_hole(rn::RuleNode) = any(contains_hole(c) for c ∈ rn.children)
Checks if an AbstractRuleNode
tree contains a AbstractHole
.
HerbCore.contains_index
— Methodcontains_index(rulenode::RuleNode, index::Int)
Returns true if the rulenode contains the index.
HerbCore.contains_nonuniform_hole
— Methodcontains_nonuniform_hole(rn::RuleNode)
Checks if an AbstractRuleNode
tree contains a Hole
.
HerbCore.depth
— Methoddepth(root::RuleNode)::Int
Return the depth of the AbstractRuleNode
tree rooted at root. Holes do count towards the depth.
HerbCore.get_children
— Methodget_children(rn::AbstractRuleNode)
Returns the children of the given AbstractRuleNode
HerbCore.get_node_at_location
— Methodget_node_at_location(root::AbstractRuleNode, location::Vector{Int})
Retrieves a RuleNode
at the given location by reference.
HerbCore.get_node_at_location
— Methodget_node_at_location(root::Hole, location::Vector{Int})
Retrieves the current hole, if location is this very hole. Throws error otherwise.
HerbCore.get_path
— Methodget_path(root::AbstractRuleNode, node::AbstractRuleNode)
Returns the path from the root
to the targetnode
. Returns nothing if no path exists.
HerbCore.get_rule
— Methodget_rule(rn::AbstractRuleNode)
Returns the index of the rule that this AbstractRuleNode
represents
HerbCore.get_rulesequence
— Methodget_rulesequence(node::RuleNode, path::Vector{Int})
Extract the derivation sequence from a path (sequence of child indices) and an AbstractRuleNode
. If the path is deeper than the deepest node, it returns what it has.
HerbCore.hasdynamicvalue
— Methodfunction hasdynamicvalue(rn::AbstractRuleNode)::Bool
Returns true iff the rule has a _val
field set up.
HerbCore.have_same_shape
— Methodhave_same_shape(node1::AbstractRuleNode, node2::AbstractRuleNode)
Returns true iff node1
and node2
have the same shape Example: RuleNode(3, [ RuleNode(1), RuleNode(1) ]) and RuleNode(9, [ RuleNode(2), Hole(domain) ]) have the same shape: 1 root with 2 children.
HerbCore.isfilled
— Methodisfilled(node::AbstractRuleNode)::Bool
Returns whether the [AbstractRuleNode
] holds a single rule. This is always the case for RuleNode
s. Holes are considered to be "filled" iff their domain size is exactly 1.
HerbCore.isuniform
— Methodisuniform(rn::AbstractRuleNode)
Returns true iff the children of the AbstractRuleNode
are known.
HerbCore.node_depth
— Methodnode_depth(root::AbstractRuleNode, node::AbstractRuleNode)::Int
Return the depth of node
for an AbstractRuleNode
tree rooted at root
. Depth is 1
when root == node
.
node
must be a subtree of root
in order for this function to work.
HerbCore.number_of_holes
— Methodnumber_of_holes(rn::AbstractRuleNode)::Int
Recursively counts the number of holes in an AbstractRuleNode
HerbCore.rulesoftype
— Functionrulesoftype(node::RuleNode, ruleset::Set{Int}[, ignoreNode::AbstractRuleNode])
rulesoftype(node::RuleNode, rule_index::Int[, ignoreNode::AbstractRuleNode])
Returns every rule in the ruleset that is also used in the AbstractRuleNode
tree, but not in the ignoreNode
subtree.
The ignoreNode
must be a subtree of node
for it to have an effect.
HerbCore.rulesoftype
— Functionrulesoftype(node::RuleNode, grammar::AbstractGrammar, ruletype::Symbol[, ignoreNode::AbstractRuleNode])
Returns every rule of nonterminal symbol ruletype
from the grammar
that is also used in the AbstractRuleNode
tree, but not in the ignoreNode
subtree.
The ignoreNode
must be a subtree of node
for it to have an effect.
HerbCore.rulesonleft
— Methodrulesonleft(expr::RuleNode, path::Vector{Int})::Set{Int}
Finds all rules that are used in the left subtree defined by the path.
HerbCore.swap_node
— Methodswap_node(expr::AbstractRuleNode, new_expr::AbstractRuleNode, path::Vector{Int})
Replace a node in expr
, specified by path
, with new_expr
. Path is a sequence of child indices, starting from the root node.
HerbCore.swap_node
— Methodswap_node(expr::RuleNode, node::RuleNode, child_index::Int, new_expr::RuleNode)
Replace child i
of a node, a part of larger expr
, with new_expr
.
Index
HerbConstraints.AbstractGrammarConstraint
HerbConstraints.AbstractLocalConstraint
HerbConstraints.AbstractStateManager
HerbConstraints.Contains
HerbConstraints.ContainsSubtree
HerbConstraints.DomainRuleNode
HerbConstraints.Forbidden
HerbConstraints.ForbiddenSequence
HerbConstraints.GenericSolver
HerbConstraints.GenericSolver
HerbConstraints.GenericSolver
HerbConstraints.LessThanOrEqualHardFail
HerbConstraints.LessThanOrEqualResult
HerbConstraints.LessThanOrEqualSoftFail
HerbConstraints.LessThanOrEqualSuccess
HerbConstraints.LessThanOrEqualSuccessEquality
HerbConstraints.LessThanOrEqualSuccessLessThan
HerbConstraints.LessThanOrEqualSuccessWithHoles
HerbConstraints.LocalContains
HerbConstraints.LocalContainsSubtree
HerbConstraints.LocalContainsSubtree
HerbConstraints.LocalForbidden
HerbConstraints.LocalForbiddenSequence
HerbConstraints.LocalOrdered
HerbConstraints.LocalUnique
HerbConstraints.MakeEqualHardFail
HerbConstraints.MakeEqualResult
HerbConstraints.MakeEqualSoftFail
HerbConstraints.MakeEqualSuccess
HerbConstraints.Ordered
HerbConstraints.PatternMatchHardFail
HerbConstraints.PatternMatchResult
HerbConstraints.PatternMatchSoftFail
HerbConstraints.PatternMatchSuccess
HerbConstraints.PatternMatchSuccessWhenHoleAssignedTo
HerbConstraints.Solver
HerbConstraints.SolverState
HerbConstraints.SolverStatistics
HerbConstraints.StateHole
HerbConstraints.StateHole
HerbConstraints.StateHole
HerbConstraints.StateInt
HerbConstraints.StateIntBackup
HerbConstraints.StateManager
HerbConstraints.StateSparseSet
HerbConstraints.StateSparseSet
HerbConstraints.StateStack
HerbConstraints.StateStack
HerbConstraints.StateStack
HerbConstraints.UniformSolver
HerbConstraints.UniformSolver
HerbConstraints.Unique
HerbConstraints.VarNode
HerbCore.AbstractConstraint
HerbCore.AbstractGrammar
HerbCore.AbstractHole
HerbCore.AbstractRuleNode
HerbCore.AbstractUniformHole
HerbCore.Hole
HerbCore.HoleReference
HerbCore.RuleNode
HerbCore.RuleNode
HerbCore.RuleNode
HerbCore.UniformHole
HerbGrammar.ContextSensitiveGrammar
HerbGrammar.NodeLoc
HerbGrammar.SymbolTable
HerbSearch.AbstractBFSIterator
HerbSearch.AbstractDFSIterator
HerbSearch.AbstractMHSearchIterator
HerbSearch.AbstractSASearchIterator
HerbSearch.AbstractVLSNSearchIterator
HerbSearch.BFSIterator
HerbSearch.DFSIterator
HerbSearch.ExpandFailureReason
HerbSearch.GeneticSearchIterator
HerbSearch.MHSearchIterator
HerbSearch.MLFSIterator
HerbSearch.ProgramIterator
HerbSearch.RandomIterator
HerbSearch.SASearchIterator
HerbSearch.StochasticSearchIterator
HerbSearch.SynthResult
HerbSearch.TopDownIterator
HerbSearch.UniformIterator
HerbSearch.UniformIterator
HerbSearch.VLSNSearchIterator
HerbSpecification.AbstractDependentTypeSpecification
HerbSpecification.AgdaSpecification
HerbSpecification.IOExample
HerbSpecification.MetricProblem
HerbSpecification.Problem
HerbSpecification.SMTSpecification
HerbSpecification.Trace
Base.collect
Base.collect
Base.findall
Base.findfirst
Base.findlast
Base.get
Base.getindex
Base.getindex
Base.in
Base.in
Base.insert!
Base.isless
Base.iterate
Base.iterate
Base.iterate
Base.iterate
Base.iterate
Base.length
Base.length
Base.length
Base.length
Base.push!
Base.rand
Base.rand
Base.rand
Base.show
Base.size
Base.size
Base.sum
HerbConstraints._contains
HerbConstraints._count_occurrences
HerbConstraints._count_occurrences
HerbConstraints._count_occurrences!
HerbConstraints._exchange_positions!
HerbConstraints._update_bounds_val_removed!
HerbConstraints._update_max_val_removed!
HerbConstraints._update_min_val_removed!
HerbConstraints.annotation2constraint
HerbConstraints.are_disjoint
HerbConstraints.are_disjoint
HerbConstraints.backup!
HerbConstraints.check_tree
HerbConstraints.check_tree
HerbConstraints.check_tree
HerbConstraints.check_tree
HerbConstraints.check_tree
HerbConstraints.check_tree
HerbConstraints.contains_varnode
HerbConstraints.deactivate!
HerbConstraints.deactivate!
HerbConstraints.decrement!
HerbConstraints.fix_point!
HerbConstraints.freeze_state
HerbConstraints.get_grammar
HerbConstraints.get_grammar
HerbConstraints.get_hole_at_location
HerbConstraints.get_hole_at_location
HerbConstraints.get_intersection
HerbConstraints.get_max_depth
HerbConstraints.get_max_size
HerbConstraints.get_nodes
HerbConstraints.get_nodes_on_path
HerbConstraints.get_priority
HerbConstraints.get_starting_symbol
HerbConstraints.get_state
HerbConstraints.get_tree
HerbConstraints.get_tree
HerbConstraints.get_tree_size
HerbConstraints.get_value
HerbConstraints.increment!
HerbConstraints.is_subdomain
HerbConstraints.is_subdomain
HerbConstraints.isfeasible
HerbConstraints.isfeasible
HerbConstraints.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_node
HerbConstraints.notify_new_nodes
HerbConstraints.notify_new_nodes
HerbConstraints.notify_tree_manipulation
HerbConstraints.notify_tree_manipulation
HerbConstraints.partition
HerbConstraints.pattern_match
HerbConstraints.pattern_match
HerbConstraints.pattern_match
HerbConstraints.pattern_match
HerbConstraints.pattern_match
HerbConstraints.pattern_match
HerbConstraints.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_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.shouldschedule
HerbConstraints.shouldschedule
HerbConstraints.simplify_hole!
HerbConstraints.substitute!
HerbCore.contains_hole
HerbCore.contains_hole
HerbCore.contains_index
HerbCore.contains_nonuniform_hole
HerbCore.depth
HerbCore.get_children
HerbCore.get_node_at_location
HerbCore.get_node_at_location
HerbCore.get_node_at_location
HerbCore.get_node_at_location
HerbCore.get_path
HerbCore.get_path
HerbCore.get_path
HerbCore.get_rule
HerbCore.get_rule
HerbCore.get_rulesequence
HerbCore.hasdynamicvalue
HerbCore.have_same_shape
HerbCore.isfilled
HerbCore.isfilled
HerbCore.isuniform
HerbCore.node_depth
HerbCore.number_of_holes
HerbCore.rulesoftype
HerbCore.rulesoftype
HerbCore.rulesonleft
HerbCore.swap_node
HerbCore.swap_node
HerbGrammar.add_rule!
HerbGrammar.add_rule!
HerbGrammar.add_rule!
HerbGrammar.addconstraint!
HerbGrammar.child_types
HerbGrammar.child_types
HerbGrammar.cleanup_removed_rules!
HerbGrammar.clearconstraints!
HerbGrammar.containedin
HerbGrammar.contains_returntype
HerbGrammar.expr2csgrammar
HerbGrammar.expr2pcsgrammar
HerbGrammar.expr2rulenode
HerbGrammar.expr2rulenode
HerbGrammar.expr2rulenode
HerbGrammar.expr2rulenode
HerbGrammar.get_childtypes
HerbGrammar.get_domain
HerbGrammar.get_domain
HerbGrammar.get_rulesequence
HerbGrammar.grammar2symboltable
HerbGrammar.init_probabilities!
HerbGrammar.iscomplete
HerbGrammar.iseval
HerbGrammar.iseval
HerbGrammar.iseval
HerbGrammar.isprobabilistic
HerbGrammar.isterminal
HerbGrammar.isterminal
HerbGrammar.isterminal
HerbGrammar.isvariable
HerbGrammar.isvariable
HerbGrammar.isvariable
HerbGrammar.isvariable
HerbGrammar.log_probability
HerbGrammar.max_arity
HerbGrammar.max_rulenode_log_probability
HerbGrammar.merge_grammars!
HerbGrammar.mindepth
HerbGrammar.mindepth_map
HerbGrammar.nchildren
HerbGrammar.nchildren
HerbGrammar.nonterminals
HerbGrammar.normalize!
HerbGrammar.parse_probabilistic_rule
HerbGrammar.probability
HerbGrammar.read_csg
HerbGrammar.read_pcsg
HerbGrammar.remove_rule!
HerbGrammar.return_type
HerbGrammar.return_type
HerbGrammar.return_type
HerbGrammar.root_node_loc
HerbGrammar.rulenode2expr
HerbGrammar.rulenode_log_probability
HerbGrammar.rulesonleft
HerbGrammar.store_csg
HerbGrammar.subsequenceof
HerbGrammar.swap_node
HerbGrammar.swap_node
HerbInterpret.evaluate_program
HerbInterpret.execute_on_input
HerbInterpret.execute_on_input
HerbInterpret.execute_on_input
HerbInterpret.execute_on_input
HerbInterpret.interpret
HerbInterpret.test_all_examples
HerbInterpret.test_examples
HerbSearch._calculate_cost
HerbSearch._find_next_complete_tree
HerbSearch.accept
HerbSearch.best_accept
HerbSearch.calculate_cost
HerbSearch.const_temperature
HerbSearch.constructNeighbourhood
HerbSearch.constructNeighbourhoodRuleSubset
HerbSearch.cross_over
HerbSearch.crossover_swap_children_1
HerbSearch.crossover_swap_children_2
HerbSearch.decreasing_temperature
HerbSearch.default_fitness
HerbSearch.derivation_heuristic
HerbSearch.derivation_heuristic
HerbSearch.derivation_heuristic
HerbSearch.enumerate_neighbours_propose
HerbSearch.evaluate
HerbSearch.extract_name_from_argument
HerbSearch.fitness
HerbSearch.generate_branches
HerbSearch.get_best_program
HerbSearch.heuristic_leftmost
HerbSearch.heuristic_random
HerbSearch.heuristic_rightmost
HerbSearch.heuristic_smallest_domain
HerbSearch.hole_heuristic
HerbSearch.is_field_decl
HerbSearch.is_kwdef
HerbSearch.mean_squared_error
HerbSearch.misclassification
HerbSearch.mutate!
HerbSearch.mutate_random!
HerbSearch.neighbourhood
HerbSearch.next_solution!
HerbSearch.priority_function
HerbSearch.priority_function
HerbSearch.priority_function
HerbSearch.priority_function
HerbSearch.probabilistic_accept
HerbSearch.probabilistic_accept_with_temperature
HerbSearch.probabilistic_accept_with_temperature_fraction
HerbSearch.processkwarg!
HerbSearch.propose
HerbSearch.random_fill_propose
HerbSearch.select_chromosome
HerbSearch.select_fitness_proportional_parents
HerbSearch.select_parents
HerbSearch.set_stateholes!
HerbSearch.synth
HerbSearch.temperature
HerbSearch.validate_iterator
StatsBase.sample
StatsBase.sample
StatsBase.sample
StatsBase.sample
HerbConstraints.@csgrammar_annotated
HerbCore.@rulenode
HerbGrammar.@cfgrammar
HerbGrammar.@csgrammar
HerbGrammar.@pcsgrammar
HerbSearch.@programiterator