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.

Note

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_symbolsFunction
extract_symbols!(symbols::Set{Symbol}, expr)

Recursively collects all Symbol names used across a BasicSymbolic expression or array of expressions.

source
AlgorithmAnalysis.get_safe_symbolFunction
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.

source

AST

AlgorithmAnalysis.find_nodesFunction
find_nodes(predicate, tree)

Recursively searches a symbolic AST. Returns a vector containing every node that satisfies predicate(node).

source
AlgorithmAnalysis.postwalk_with_operatorsFunction
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.

source

Transitions

AlgorithmAnalysis.apply_transitionFunction
apply_transition(trans::Node{Transition}, expr::Node) -> Node

Substitute 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)^2
source

Numerics

AlgorithmAnalysis.hasvalueFunction
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.

source
AlgorithmAnalysis.valueFunction
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.

source

Miscellaneous

AlgorithmAnalysis.from_matrixFunction
from_matrix(basis::Vector{<:Node}, coords::AbstractVector)

Reconstructs a symbolic Node expression from a coordinate vector and a basis.

source
AlgorithmAnalysis.bsminFunction
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 false
  • f(b) is true
  • f is monotone (only one cross-over point)
source