Did you know ... Search Documentation:
Pack units -- prolog/units/search.pl
PublicShow source
 common_expr(:ChildParentGoal, +Expr1, -Factor1, +Expr2, -Factor2, -CommonExpr) is nondet
Finds a common base expression CommonExpr for two input expressions Expr1 and Expr2 (typically units or quantities), along with their respective scaling factors Factor1 and Factor2.

The relationship established is that `Expr1*Factor1 = Expr2*Factor2 = CommonExpr`.

This predicate is tabled to memoize its results. It employs an iterative deepening approach to search for the closest common ancestor of Expr1 and Expr2. The search expands definitions (guided by the ChildParentGoal predicate, e.g., for unit parents or quantity parents) to establish this commonality.

Arguments:
ChildParentGoal- A meta-argument (predicate name) that defines how to expand or find parents of elements within the expressions (e.g., unit_parent for units, alias_or_child_quantity_parent for quantities).
Expr1- The first input expression (e.g., si:metre, isq:speed).
Factor1- The numerical scaling factor associated with Expr1 in the context of the common relationship.
Expr2- The second input expression.
Factor2- The numerical scaling factor associated with Expr2 in the context of the common relationship.
CommonExpr- The common base expression derived from Expr1 and Expr2.
 iterative_deepening(+InitialLimit, :Goal) is nondet
Executes Goal using an iterative deepening search strategy.

Goal is expected to take an additional argument, DepthLimit-Flag where DepthLimit is the maximum search depth and Flag is a term n(Status). Goal should set (with nb_set/2) Status to depth_limit_exceeded if it fails due to reaching DepthLimit. In this case, Goal is called again with DepthLimit + 1. If Goal, this predicate fails.

Note: We don't use call_with_depth_limit/2 because the use of exception to signal that the depth limit is reached will cut existing choice points which should be explored. Moreover, Goal is free to count depth level freely.

Arguments:
InitialLimit- The starting depth limit for the search.
Goal- The goal to execute. It must be a predicate accepting a Limit-Flag pair as an argument. Flag is n(Status) used to signal if the depth limit was hit.