Grover oracle
DefinitionoracleThe Grover oracle for a marked index w0: the reflection I - 2|w0><w0|, which flips the sign of the amplitude on the marked basis state |w0> and leaves every other basis state fixed.
import Mathlib
namespace Grover
/-- The Grover oracle for a marked index `w0`: the reflection `I - 2|w0⟩⟨w0|`, which flips the
sign of the amplitude on the marked basis state `|w0⟩` and leaves every other basis state fixed. -/
noncomputable def oracle {N : ℕ} (w0 : Fin N) :
EuclideanSpace ℂ (Fin N) →L[ℂ] EuclideanSpace ℂ (Fin N) :=
ContinuousLinearMap.id ℂ _ -
(2 : ℂ) • InnerProductSpace.rankOne ℂ
(EuclideanSpace.single w0 (1 : ℂ)) (EuclideanSpace.single w0 (1 : ℂ))
end Grover
Read-back
What the Lean code literally says, in plain math · claude-sonnet-5
For an implicit natural number and an explicit index ranging over (the type of being nonempty already forces , though this is not stated as a hypothesis, only implied by 's existence), oracle w0 is defined as the continuous -linear map on given by the identity map minus times the rank-one operator built from the standard basis vector (the vector with coordinate value at index and elsewhere), used as both the "output" and "input" vector of that rank-one operator. Concretely, the rank-one operator sends , and since , this rank-one operator sends ; hence for any , oracle w0 sends to the vector whose -th coordinate is and whose -th coordinate for every equals unchanged — that is, the map negates exactly the -th coordinate and leaves every other coordinate fixed.
Confirmed by the mission captain (proposal self-audit).