doc-next-gen

Mathlib.Data.Finset.Filter

Module docstring

{"# Filtering a finite set

Main declarations

  • Finset.filter: Given a decidable predicate p : α → Prop, s.filter p is the finset consisting of those elements in s satisfying the predicate p.

Tags

finite sets, finset

","### filter "}

Finset.filter definition
(s : Finset α) : Finset α
Full source
/-- `Finset.filter p s` is the set of elements of `s` that satisfy `p`.

For example, one can use `s.filter (· ∈ t)` to get the intersection of `s` with `t : Set α`
as a `Finset α` (when a `DecidablePred (· ∈ t)` instance is available). -/
def filter (s : Finset α) : Finset α :=
  ⟨_, s.2.filter p⟩
Filtering a finite set by a predicate
Informal description
Given a decidable predicate \( p : \alpha \to \text{Prop} \) and a finite set \( s : \text{Finset } \alpha \), the function \( \text{Finset.filter } p \ s \) returns the finite subset of \( s \) consisting of all elements that satisfy \( p \). For example, \( s \text{.filter } (\cdot \in t) \) gives the intersection of \( s \) with \( t : \text{Set } \alpha \) as a finite set when a decidable instance for membership in \( t \) is available.
Mathlib.Meta.knownToBeFinsetNotSet definition
(expectedType? : Option Expr) : TermElabM Bool
Full source
/-- Return `true` if `expectedType?` is `some (Finset ?α)`, throws `throwUnsupportedSyntax` if it is
`some (Set ?α)`, and returns `false` otherwise. -/
def knownToBeFinsetNotSet (expectedType? : Option Expr) : TermElabM Bool :=
  -- As we want to reason about the expected type, we would like to wait for it to be available.
  -- However this means that if we fall back on `elabSetBuilder` we will have postponed.
  -- This is undesirable as we want set builder notation to quickly elaborate to a `Set` when no
  -- expected type is available.
  -- tryPostponeIfNoneOrMVar expectedType?
  match expectedType? with
  | somesome expectedType =>
    match_expr expectedType with
    -- If the expected type is known to be `Finset ?α`, return `true`.
    | Finset _ => pure true
    -- If the expected type is known to be `Set ?α`, give up.
    | Set _ => throwUnsupportedSyntax
    -- If the expected type is known to not be `Finset ?α` or `Set ?α`, return `false`.
    | _ => pure false
  -- If the expected type is not known, return `false`.
  | none => pure false
Check for Finset Expected Type
Informal description
Given an optional expected type `expectedType?`, this function returns `true` if `expectedType?` is known to be of the form `Finset α` for some type `α`, throws an error if it is known to be of the form `Set α`, and returns `false` otherwise. This is used to determine whether to elaborate a term as a finite set (`Finset`) or a general set (`Set`).
Mathlib.Meta.elabFinsetBuilderSep definition
: TermElab
Full source
/-- Elaborate set builder notation for `Finset`.

`{x ∈ s | p x}` is elaborated as `Finset.filter (fun x ↦ p x) s` if either the expected type is
`Finset ?α` or the expected type is not `Set ?α` and `s` has expected type `Finset ?α`.

See also
* `Data.Set.Defs` for the `Set` builder notation elaborator that this elaborator partly overrides.
* `Data.Fintype.Basic` for the `Finset` builder notation elaborator handling syntax of the form
  `{x | p x}`, `{x : α | p x}`, `{x ∉ s | p x}`, `{x ≠ a | p x}`.
* `Order.LocallyFinite.Basic` for the `Finset` builder notation elaborator handling syntax of the
  form `{x ≤ a | p x}`, `{x ≥ a | p x}`, `{x < a | p x}`, `{x > a | p x}`.

TODO: Write a delaborator
-/
@[term_elab setBuilder]
def elabFinsetBuilderSep : TermElab
  | `({ $x:ident ∈ $s:term | $p }), expectedType? => do
    -- If the expected type is known to be `Set ?α`, give up. If it is not known to be `Set ?α` or
    -- `Finset ?α`, check the expected type of `s`.
    unless ← knownToBeFinsetNotSet expectedType? do
      let ty ← try whnfR (← inferType (← elabTerm s none)) catch _ => throwUnsupportedSyntax
      -- If the expected type of `s` is not known to be `Finset ?α`, give up.
      match_expr ty with
      | Finset _ => pure ()
      | _ => throwUnsupportedSyntax
    -- Finally, we can elaborate the syntax as a finset.
    -- TODO: Seems a bit wasteful to have computed the expected type but still use `expectedType?`.
    elabTerm (← `(Finset.filter (fun $x:ident ↦ $p) $s)) expectedType?
  | _, _ => throwUnsupportedSyntax
Finite set builder notation elaborator
Informal description
The elaborator for the finite set builder notation `{x ∈ s | p x}`, which constructs a finite set consisting of elements `x` in the finite set `s` that satisfy the predicate `p`. The notation is elaborated as `Finset.filter (fun x ↦ p x) s` when the expected type is known to be a finite set (`Finset α`) or when the type of `s` is known to be a finite set.
Finset.filter_val theorem
(s : Finset α) : (filter p s).1 = s.1.filter p
Full source
@[simp]
theorem filter_val (s : Finset α) : (filter p s).1 = s.1.filter p :=
  rfl
Underlying Multiset of Filtered Finite Set Equals Filtered Underlying Multiset
Informal description
For any finite set $s$ of type $\alpha$ and any decidable predicate $p$ on $\alpha$, the underlying multiset of the filtered set $s.\mathrm{filter}\,p$ is equal to the multiset obtained by filtering the underlying multiset of $s$ with $p$.
Finset.filter_subset theorem
(s : Finset α) : s.filter p ⊆ s
Full source
@[simp]
theorem filter_subset (s : Finset α) : s.filter p ⊆ s :=
  Multiset.filter_subset _ _
Filtered Finite Set is Subset of Original Set
Informal description
For any finite set $s$ of type $\alpha$ and any decidable predicate $p$ on $\alpha$, the filtered subset $s.\mathrm{filter}\,p$ is contained in $s$.
Finset.mem_filter theorem
{s : Finset α} {a : α} : a ∈ s.filter p ↔ a ∈ s ∧ p a
Full source
@[simp]
theorem mem_filter {s : Finset α} {a : α} : a ∈ s.filter pa ∈ s.filter p ↔ a ∈ s ∧ p a :=
  Multiset.mem_filter
Characterization of Membership in Filtered Finite Set
Informal description
For any finite set $s$ of type $\alpha$ and any element $a \in \alpha$, the element $a$ belongs to the filtered subset $s.\mathrm{filter}\,p$ if and only if $a$ belongs to $s$ and satisfies the predicate $p$.
Finset.mem_of_mem_filter theorem
{s : Finset α} (x : α) (h : x ∈ s.filter p) : x ∈ s
Full source
theorem mem_of_mem_filter {s : Finset α} (x : α) (h : x ∈ s.filter p) : x ∈ s :=
  Multiset.mem_of_mem_filter h
Membership in Filtered Finite Set Implies Membership in Original Set
Informal description
For any finite set $s$ of type $\alpha$ and any element $x \in \alpha$, if $x$ belongs to the filtered subset $s.\mathrm{filter}\,p$, then $x$ belongs to $s$.
Finset.filter_ssubset theorem
{s : Finset α} : s.filter p ⊂ s ↔ ∃ x ∈ s, ¬p x
Full source
theorem filter_ssubset {s : Finset α} : s.filter p ⊂ ss.filter p ⊂ s ↔ ∃ x ∈ s, ¬p x :=
  ⟨fun h =>
    let ⟨x, hs, hp⟩ := Set.exists_of_ssubset h
    ⟨x, hs, mt (fun hp => mem_filter.2 ⟨hs, hp⟩) hp⟩,
    fun ⟨_, hs, hp⟩ => ⟨s.filter_subset _, fun h => hp (mem_filter.1 (h hs)).2⟩⟩
Strict Subset Condition for Filtered Finite Sets: $s.\mathrm{filter}\,p \subset s \leftrightarrow \exists x \in s, \neg p x$
Informal description
For any finite set $s$ of type $\alpha$ and any decidable predicate $p$ on $\alpha$, the filtered subset $s.\mathrm{filter}\,p$ is a strict subset of $s$ if and only if there exists an element $x \in s$ that does not satisfy $p$.
Finset.filter_filter theorem
(s : Finset α) : (s.filter p).filter q = s.filter fun a => p a ∧ q a
Full source
theorem filter_filter (s : Finset α) : (s.filter p).filter q = s.filter fun a => p a ∧ q a :=
  ext fun a => by
    simp only [mem_filter, and_assoc, Bool.decide_and, Bool.decide_coe, Bool.and_eq_true]
Double Filtering Equals Conjunction Filtering for Finite Sets
Informal description
For any finite set $s$ of type $\alpha$ and predicates $p, q : \alpha \to \text{Prop}$, the result of filtering $s$ by $p$ and then filtering the result by $q$ is equal to filtering $s$ by the conjunction of $p$ and $q$. That is, $$(s \text{.filter } p) \text{.filter } q = s \text{.filter } (\lambda a, p a \land q a).$$
Finset.filter_comm theorem
(s : Finset α) : (s.filter p).filter q = (s.filter q).filter p
Full source
theorem filter_comm (s : Finset α) : (s.filter p).filter q = (s.filter q).filter p := by
  simp_rw [filter_filter, and_comm]
Commutativity of Double Filtering for Finite Sets
Informal description
For any finite set $s$ of type $\alpha$ and predicates $p, q : \alpha \to \text{Prop}$, the result of filtering $s$ by $p$ and then filtering the result by $q$ is equal to filtering $s$ by $q$ and then filtering the result by $p$. That is, $$(s \text{.filter } p) \text{.filter } q = (s \text{.filter } q) \text{.filter } p.$$
Finset.filter_congr_decidable theorem
(s : Finset α) (p : α → Prop) (h : DecidablePred p) [DecidablePred p] : @filter α p h s = s.filter p
Full source
theorem filter_congr_decidable (s : Finset α) (p : α → Prop) (h : DecidablePred p)
    [DecidablePred p] : @filter α p h s = s.filter p := by congr
Equality of Explicit and Implicit Filtering for Finite Sets
Informal description
For any finite set $s$ of type $\alpha$ and a decidable predicate $p : \alpha \to \text{Prop}$, the filtered set obtained using the explicit decidability instance $h$ for $p$ is equal to the filtered set obtained using the implicit decidability instance for $p$. That is, $\text{filter } p \ s = s.\text{filter } p$.
Finset.filter_True theorem
{h} (s : Finset α) : @filter _ (fun _ => True) h s = s
Full source
@[simp]
theorem filter_True {h} (s : Finset α) : @filter _ (fun _ => True) h s = s := by ext; simp
Filtering with True Predicate Preserves Finite Set
Informal description
For any finite set $s$ of type $\alpha$ and the trivial predicate $\fun \_ \Rightarrow \text{True}$, the filtered set $s \text{.filter } (\fun \_ \Rightarrow \text{True})$ is equal to $s$ itself.
Finset.filter_False theorem
{h} (s : Finset α) : @filter _ (fun _ => False) h s = ∅
Full source
@[simp]
theorem filter_False {h} (s : Finset α) : @filter _ (fun _ => False) h s =  := by ext; simp
Filtering with False Predicate Yields Empty Set
Informal description
For any finite set $s$ of type $\alpha$ and the constant predicate $p(x) = \text{False}$ for all $x \in \alpha$, the filtered set $s \text{.filter } p$ is equal to the empty set $\emptyset$.
Finset.filter_eq_self theorem
: s.filter p = s ↔ ∀ x ∈ s, p x
Full source
lemma filter_eq_self : s.filter p = s ↔ ∀ x ∈ s, p x := by simp [Finset.ext_iff]
Filtered Set Equals Original Set if and only if All Elements Satisfy Predicate
Informal description
For a finite set $s$ and a predicate $p$, the filtered set $s \text{.filter } p$ is equal to $s$ if and only if every element $x$ in $s$ satisfies $p(x)$. In other words, $s \text{.filter } p = s \leftrightarrow (\forall x \in s, p(x))$.
Finset.filter_eq_empty_iff theorem
: s.filter p = ∅ ↔ ∀ ⦃x⦄, x ∈ s → ¬p x
Full source
theorem filter_eq_empty_iff : s.filter p = ∅ ↔ ∀ ⦃x⦄, x ∈ s → ¬p x := by simp [Finset.ext_iff]
Empty Filtered Set Characterizes Predicate Falsity on Entire Set
Informal description
For a finite set $s$ and a predicate $p$, the filtered set $s \text{.filter } p$ is empty if and only if no element $x \in s$ satisfies $p(x)$. In other words, $s \text{.filter } p = \emptyset \leftrightarrow (\forall x \in s, \neg p(x))$.
Finset.filter_nonempty_iff theorem
: (s.filter p).Nonempty ↔ ∃ a ∈ s, p a
Full source
theorem filter_nonempty_iff : (s.filter p).Nonempty ↔ ∃ a ∈ s, p a := by
  simp only [nonempty_iff_ne_empty, Ne, filter_eq_empty_iff, Classical.not_not, not_forall,
    exists_prop]
Nonempty Filtered Set iff Predicate Holds for Some Element
Informal description
For a finite set $s$ and a predicate $p$, the filtered set $s \text{.filter } p$ is nonempty if and only if there exists an element $a \in s$ that satisfies $p(a)$. In other words, $(s \text{.filter } p) \neq \emptyset \leftrightarrow (\exists a \in s, p(a))$.
Finset.filter_true_of_mem theorem
(h : ∀ x ∈ s, p x) : s.filter p = s
Full source
/-- If all elements of a `Finset` satisfy the predicate `p`, `s.filter p` is `s`. -/
theorem filter_true_of_mem (h : ∀ x ∈ s, p x) : s.filter p = s := filter_eq_self.2 h
Filtered Set Equals Original Set When All Elements Satisfy Predicate
Informal description
For a finite set $s$ and a predicate $p$, if every element $x \in s$ satisfies $p(x)$, then the filtered set $s \text{.filter } p$ is equal to $s$.
Finset.filter_false_of_mem theorem
(h : ∀ x ∈ s, ¬p x) : s.filter p = ∅
Full source
/-- If all elements of a `Finset` fail to satisfy the predicate `p`, `s.filter p` is `∅`. -/
theorem filter_false_of_mem (h : ∀ x ∈ s, ¬p x) : s.filter p =  := filter_eq_empty_iff.2 h
Empty Filtered Set When Predicate Fails Everywhere
Informal description
For any finite set $s$ and predicate $p$, if no element $x \in s$ satisfies $p(x)$, then the filtered set $s \text{.filter } p$ is empty, i.e., $s \text{.filter } p = \emptyset$.
Finset.filter_const theorem
(p : Prop) [Decidable p] (s : Finset α) : (s.filter fun _a => p) = if p then s else ∅
Full source
@[simp]
theorem filter_const (p : Prop) [Decidable p] (s : Finset α) :
    (s.filter fun _a => p) = if p then s else ∅ := by split_ifs <;> simp [*]
Filtering with Constant Predicate: $s \text{.filter } (\lambda \_ \Rightarrow p) = \text{if } p \text{ then } s \text{ else } \emptyset$
Informal description
For any finite set $s$ of type $\alpha$ and a decidable proposition $p$, the filtered set $s \text{.filter } (\lambda \_ \Rightarrow p)$ is equal to $s$ if $p$ is true, and the empty set $\emptyset$ otherwise.
Finset.filter_congr theorem
{s : Finset α} (H : ∀ x ∈ s, p x ↔ q x) : filter p s = filter q s
Full source
theorem filter_congr {s : Finset α} (H : ∀ x ∈ s, p x ↔ q x) : filter p s = filter q s :=
  eq_of_veq <| Multiset.filter_congr H
Equality of Filtered Finite Sets under Equivalent Predicates
Informal description
For any finite set $s$ of elements of type $\alpha$ and predicates $p, q : \alpha \to \text{Prop}$, if for every element $x \in s$ the predicates $p(x)$ and $q(x)$ are equivalent, then the filtered sets $\text{filter}\ p\ s$ and $\text{filter}\ q\ s$ are equal.
Finset.filter_empty theorem
: filter p ∅ = ∅
Full source
@[simp]
theorem filter_empty : filter p  =  :=
  subset_empty.1 <| filter_subset _ _
Filtering the Empty Set Yields the Empty Set: $\text{filter}\,p\,\emptyset = \emptyset$
Informal description
For any decidable predicate $p : \alpha \to \text{Prop}$, the filtered finite set of the empty set $\emptyset$ is equal to $\emptyset$, i.e., $\text{filter}\,p\,\emptyset = \emptyset$.
Finset.filter_subset_filter theorem
{s t : Finset α} (h : s ⊆ t) : s.filter p ⊆ t.filter p
Full source
@[gcongr]
theorem filter_subset_filter {s t : Finset α} (h : s ⊆ t) : s.filter p ⊆ t.filter p := fun _a ha =>
  mem_filter.2 ⟨h (mem_filter.1 ha).1, (mem_filter.1 ha).2⟩
Filtered Subset Preserves Inclusion: $s \subseteq t \implies s.\mathrm{filter}(p) \subseteq t.\mathrm{filter}(p)$
Informal description
For any finite sets $s$ and $t$ of elements of type $\alpha$, if $s$ is a subset of $t$, then the filtered subset $s.\mathrm{filter}(p)$ is contained in the filtered subset $t.\mathrm{filter}(p)$.
Finset.monotone_filter_left theorem
: Monotone (filter p)
Full source
theorem monotone_filter_left : Monotone (filter p) := fun _ _ => filter_subset_filter p
Monotonicity of Finite Set Filtering with Respect to Subset Inclusion
Informal description
For any decidable predicate $p : \alpha \to \text{Prop}$, the function $\text{filter } p$ is monotone with respect to the subset relation on finite sets. That is, for any finite sets $s, t \subseteq \alpha$, if $s \subseteq t$, then $s.\text{filter}(p) \subseteq t.\text{filter}(p)$.
Finset.monotone_filter_right theorem
(s : Finset α) ⦃p q : α → Prop⦄ [DecidablePred p] [DecidablePred q] (h : p ≤ q) : s.filter p ⊆ s.filter q
Full source
@[gcongr]
theorem monotone_filter_right (s : Finset α) ⦃p q : α → Prop⦄ [DecidablePred p] [DecidablePred q]
    (h : p ≤ q) : s.filter p ⊆ s.filter q :=
  Multiset.subset_of_le (Multiset.monotone_filter_right s.val h)
Monotonicity of Finite Set Filtering with Respect to Predicate Implication: $p \leq q \implies s.\mathrm{filter}(p) \subseteq s.\mathrm{filter}(q)$
Informal description
For any finite set $s$ of type $\alpha$ and any two decidable predicates $p, q : \alpha \to \text{Prop}$ such that $p(x)$ implies $q(x)$ for all $x \in \alpha$, the filtered subset $s.\mathrm{filter}(p)$ is contained in $s.\mathrm{filter}(q)$.
Finset.coe_filter theorem
(s : Finset α) : ↑(s.filter p) = ({x ∈ ↑s | p x} : Set α)
Full source
@[simp, norm_cast]
theorem coe_filter (s : Finset α) : ↑(s.filter p) = ({ x ∈ ↑s | p x } : Set α) :=
  Set.ext fun _ => mem_filter
Set Correspondence of Filtered Finite Set: $\overline{s.\mathrm{filter}\,p} = \{x \in s \mid p x\}$
Informal description
For any finite set $s$ of type $\alpha$ and any decidable predicate $p : \alpha \to \text{Prop}$, the set corresponding to the filtered finite set $s.\mathrm{filter}\,p$ is equal to the set $\{x \in s \mid p x\}$.
Finset.subset_coe_filter_of_subset_forall theorem
(s : Finset α) {t : Set α} (h₁ : t ⊆ s) (h₂ : ∀ x ∈ t, p x) : t ⊆ s.filter p
Full source
theorem subset_coe_filter_of_subset_forall (s : Finset α) {t : Set α} (h₁ : t ⊆ s)
    (h₂ : ∀ x ∈ t, p x) : t ⊆ s.filter p := fun x hx => (s.coe_filter p).symm⟨h₁ hx, h₂ x hx⟩
Subset Preservation under Filtering: $t \subseteq s \land (\forall x \in t, p(x)) \implies t \subseteq s.\mathrm{filter}\,p$
Informal description
Let $s$ be a finite subset of a type $\alpha$, and let $t$ be a set such that $t \subseteq s$. If every element $x \in t$ satisfies the predicate $p(x)$, then $t$ is a subset of the filtered finite set $s.\mathrm{filter}\,p$.
Finset.disjoint_filter_filter theorem
{s t : Finset α} {p q : α → Prop} [DecidablePred p] [DecidablePred q] : Disjoint s t → Disjoint (s.filter p) (t.filter q)
Full source
theorem disjoint_filter_filter {s t : Finset α}
    {p q : α → Prop} [DecidablePred p] [DecidablePred q] :
    Disjoint s t → Disjoint (s.filter p) (t.filter q) :=
  Disjoint.mono (filter_subset _ _) (filter_subset _ _)
Disjointness Preservation under Filtering: $s \cap t = \emptyset \implies s.\mathrm{filter}\,p \cap t.\mathrm{filter}\,q = \emptyset$
Informal description
For any two finite sets $s$ and $t$ of type $\alpha$ and any two decidable predicates $p$ and $q$ on $\alpha$, if $s$ and $t$ are disjoint, then the filtered sets $s.\mathrm{filter}\,p$ and $t.\mathrm{filter}\,q$ are also disjoint.
Set.pairwiseDisjoint_filter theorem
[DecidableEq β] (f : α → β) (s : Set β) (t : Finset α) : s.PairwiseDisjoint fun x ↦ t.filter (f · = x)
Full source
lemma _root_.Set.pairwiseDisjoint_filter [DecidableEq β] (f : α → β) (s : Set β) (t : Finset α) :
    s.PairwiseDisjoint fun x ↦ t.filter (f · = x) := by
  rintro i - j - h u hi hj x hx
  obtain ⟨-, rfl⟩ : x ∈ tx ∈ t ∧ f x = i := by simpa using hi hx
  obtain ⟨-, rfl⟩ : x ∈ tx ∈ t ∧ f x = j := by simpa using hj hx
  contradiction
Pairwise Disjointness of Filtered Sets under a Function
Informal description
Let $\beta$ be a type with decidable equality, $f : \alpha \to \beta$ a function, $s$ a set of elements of type $\beta$, and $t$ a finite subset of $\alpha$. Then the family of sets $\{ t.\mathrm{filter}\,(f \cdot = x) \mid x \in s \}$ is pairwise disjoint.
Finset.disjoint_filter_and_not_filter theorem
: Disjoint (s.filter (fun x ↦ p x ∧ ¬q x)) (s.filter (fun x ↦ q x ∧ ¬p x))
Full source
theorem disjoint_filter_and_not_filter :
    Disjoint (s.filter (fun x ↦ p x ∧ ¬q x)) (s.filter (fun x ↦ q x ∧ ¬p x)) := by
  intro _ htp htq
  simp only [bot_eq_empty, le_eq_subset, subset_empty, ← not_nonempty_iff_eq_empty]
  rintro ⟨_, hx⟩
  exact (mem_filter.mp (htq hx)).2.2 (mem_filter.mp (htp hx)).2.1
Disjointness of Filtered Sets with Complementary Predicates
Informal description
For any finite set $s$ and predicates $p$ and $q$, the filtered sets $\{x \in s \mid p(x) \land \neg q(x)\}$ and $\{x \in s \mid q(x) \land \neg p(x)\}$ are disjoint.
Finset.filter_inj theorem
: s.filter p = t.filter p ↔ ∀ ⦃a⦄, p a → (a ∈ s ↔ a ∈ t)
Full source
lemma filter_inj : s.filter p = t.filter p ↔ ∀ ⦃a⦄, p a → (a ∈ s ↔ a ∈ t) := by
  simp [Finset.ext_iff]
Equality of Filtered Finite Sets via Membership Condition
Informal description
For finite sets $s$ and $t$ and a predicate $p$, the filtered sets $s \text{.filter } p$ and $t \text{.filter } p$ are equal if and only if for every element $a$ satisfying $p(a)$, we have $a \in s$ if and only if $a \in t$.
Finset.filter_inj' theorem
: s.filter p = s.filter q ↔ ∀ ⦃a⦄, a ∈ s → (p a ↔ q a)
Full source
lemma filter_inj' : s.filter p = s.filter q ↔ ∀ ⦃a⦄, a ∈ s → (p a ↔ q a) := by
  simp [Finset.ext_iff]
Equality of Filtered Finite Sets via Predicate Equivalence
Informal description
For a finite set $s$ and predicates $p$ and $q$, the filtered sets $s \text{.filter } p$ and $s \text{.filter } q$ are equal if and only if for every element $a \in s$, $p(a)$ holds if and only if $q(a)$ holds.