Class Quantifiers


  • public class Quantifiers
    extends Object
    Auxiliary class containing factory methods and helpers for Quantifier.
    • Method Detail

      • fromExpressions

        @Nonnull
        public static <E extends RelationalExpression,​Q extends QuantifierList<Q> fromExpressions​(@Nonnull
                                                                                                          Iterable<? extends ExpressionRef<E>> rangesOverExpressions,
                                                                                                          @Nonnull
                                                                                                          Function<ExpressionRef<E>,​Q> creator)
        Create a list of quantifiers given a list of references these quantifiers should range over.
        Type Parameters:
        E - type parameter to constrain expressions to RelationalExpression
        Q - the type of the quantifier to be created
        Parameters:
        rangesOverExpressions - iterable of ExpressionRefs the quantifiers will be created to range over
        creator - lambda to to be called for each expression reference contained in rangesOverExpressions to create the actual quantifier. This allows for callers to create different kinds of quantifier based on needs.
        Returns:
        a list of quantifiers where each quantifier ranges over an reference contained in the given iterable
      • translate

        @Nonnull
        public static AliasMap translate​(@Nonnull
                                         Quantifier from,
                                         @Nonnull
                                         Quantifier to)
        Convenience helper to create a single ID translation map from the alias of one quantifier to the alias of another quantifier.
        Parameters:
        from - quantifier
        to - quantifier
        Returns:
        a new translation map mapping from from.getAlias() to to.getAlias()
      • toIDMap

        @Nonnull
        public static AliasMap toIDMap​(@Nonnull
                                       com.google.common.collect.BiMap<Quantifier,​Quantifier> map)
        Convenience helper to create an alias translation map based on a translation map using quantifiers. of another quantifier.
        Parameters:
        map - quantifier to quantifier bi-map
        Returns:
        a new AliasMap mapping from from.getAlias() to to.getAlias()
      • match

        @Nonnull
        public static Iterable<AliasMap> match​(@Nonnull
                                               Collection<? extends Quantifier> quantifiers,
                                               @Nonnull
                                               Collection<? extends Quantifier> otherQuantifiers,
                                               boolean canCorrelate,
                                               @Nonnull
                                               AliasMap equivalencesMap,
                                               @Nonnull
                                               Quantifiers.MatchingPredicate predicate)
        Method to match up the quantifiers this expression owns with the given set of other quantifiers using an equivalence map. Two quantifiers can be considered a match if the given predicate returns true. This method attempts to match up each quantifier from the set of quantifiers this expression owns to the given other set of quantifiers such that the given predicate returns true for each mapping. Note that there may be multiple distinct matches between the quantifier sets. This method returns an Iterable of such matches where each match is only computed when it is requested by an iterator's Iterator.hasNext(). Thus it can be assumed that this method never pre-computes all possible matches. This method returns an empty mapping if e.g. the number quantifiers in the respective sets doesn't match. For expressions that cannot introduce correlations, this method is simply O(n!) where is the number of quantifiers (which is equal for both sets). This path is taken by UNIONs and other set operations. For expressions that introduce correlations, the matching process is more complicated. First, we determine one topologically correct ordering. Then we iterate through all topologically correct orderings of the set of quantifiers this expression owns. For each element in the permutation of quantifiers that is returned by the TopologicalSort.TopologicalOrderPermutationIterator we try to math the quantifiers between the sets topologically from left to right (using predicate). For each match we find we add an equivalence between the alias of this and the other quantifier that matched in an equivalence map that extends the given equivalence map.
        Parameters:
        quantifiers - collection of quantifiers
        otherQuantifiers - collection of _other_ quantifiers
        canCorrelate - indicator if the expression containing these quantifiers can actively introduce correlations
        equivalencesMap - equivalence map
        predicate - that tests if two quantifiers and their graph they range over can be considered equivalent
        Returns:
        An AliasMap containing a mapping from the quantifiers this expression owns to the quantifiers in otherQuantifiers. Note that the mapping is bijective and can therefore be inverted.