Internal API
This page lists the internal API of AlgorithmAnalysis.jl. This documentation exists to help developers. While these methods may be used by other users, they are considered internal and therefore subject to change at any time.
As these symbols are internal API, they are not exported. Therefore, to use them outside of the package you must prefix the name with AlgorithmAnalysis.<NAME>.
Symbols
AlgorithmAnalysis.extract_symbols — Function
extract_symbols!(symbols::Set{Symbol}, expr)Recursively collects all Symbol names used across a BasicSymbolic expression or array of expressions.
AlgorithmAnalysis.get_safe_symbol — Function
get_safe_symbol(base::Symbol, expr; subscript_fn = subscript)Returns base if safe, otherwise appends subscript indices (e.g. λ -> λ₁ -> λ₂) until a collision-free symbol is found.
AlgorithmAnalysis.is_safe — Function
is_symbol_safe(candidate::Symbol, expr)Returns true if candidate does not appear anywhere inside expr.
AST
AlgorithmAnalysis.Node — Type
Node{T} = SymbolicUtils.BasicSymbolic{T}Abstract type of a symbolic expression with symtype T.
AlgorithmAnalysis.replace_node — Function
replace_node(tree, old_node, new_node)Walks the entire AST and swaps every instance that matches old_node with new_node.
AlgorithmAnalysis.find_nodes — Function
find_nodes(predicate, tree)Recursively searches a symbolic AST. Returns a vector containing every node that satisfies predicate(node).
AlgorithmAnalysis.rewrite — Function
rewrite(node, rules)Rewrites a node using the given rules. See postwalk_with_operators.
AlgorithmAnalysis.find_evaluation_points — Function
find_evaluation_points!(f, node)Finds all evaluations of the function f in the symbolic node.
AlgorithmAnalysis.postwalk_with_operators — Function
postwalk_with_operators(f, x)Apply a postwalk to the symbolic expression x in which the function f is applied recursively directly to leaf nodes and to both the operator and arguments of iscall nodes, starting at the leaves. This is similar to SymbolicUtils.Rewriters.Postwalk except that the function is also applied to the operator for iscall nodes, as these may also be symbolic expressions.
AlgorithmAnalysis.remove_transitions — Function
remove_transitions(tree, state)Remove all transitions with state from the symbolic node tree.
AlgorithmAnalysis.propagate_and_remove_transitions — Function
propagate_and_remove_transitions(tree, state)
propagate_and_remove_transitions(tree, states)Propagate all transitions of state in the tree and then remove all transitions of the state.
Transitions
AlgorithmAnalysis.transitions — Function
transitions(prop)Extract all transitions from a proposition.
AlgorithmAnalysis.apply_transition — Function
apply_transition(trans::Node{Transition}, expr::Node) -> NodeSubstitute state variables in expr with their next-step expressions defined by trans.
Each pair (state_var => next_expr) in trans is applied sequentially via a single-pass replace_node rewrite, so the result is the performance measure evaluated at the next-step state. Sequential application is correct for non-coupled transitions (e.g. gradient descent with a single state variable).
Example
@alg begin
x, xs ∈ Rⁿ
f ∈ F(Rⁿ)
α ∈ R
g = f'(x)
end
perf = (x - xs)^2
trans = Transition([x => x - α*g, xs => xs])
perf_next = apply_transition(trans, perf) # = ((x - α*g) - xs)^2Numerics
AlgorithmAnalysis.model — Function
model()Access the JuMP model within a numeric scope. See with_numerics().
AlgorithmAnalysis.instantiate_in_model — Function
instantiate_in_model(x)Instantiate an expression (e.g., variable or constraint) in the JuMP model.
AlgorithmAnalysis.hasvalue — Function
hasvalue(node)Check if a node has a numeric value, either as a constant, as a parameter, or in a JuMP model with values. Use value to get the value of the node.
AlgorithmAnalysis.value — Function
value(node)Get the numeric value of a node if available. Throws an error if no value is available. Use hasvalue to check if the node has a value.
Miscellaneous
AlgorithmAnalysis.from_matrix — Function
from_matrix(basis::Vector{<:Node}, coords::AbstractVector)Reconstructs a symbolic Node expression from a coordinate vector and a basis.
AlgorithmAnalysis.bsmin — Function
bsmin(f, a, b; tol, verbose)Binary search. Returns the smallest value between a and b (within tol) such that f(x) is true.
Assumptions
f(a)is falsef(b)is truefis monotone (only one cross-over point)
AlgorithmAnalysis.s_procedure — Function
s_procedure(constraint, ctx, f)AlgorithmAnalysis.multiplier — Function
multiplier(ctx, prop)Multiplier for a proposition in a context.