Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduces machinery for manipulating permutations to VyZX. In particular:
ZXperm n
, a predicate defining the subset ofZX n n
which arepermutation-like, i.e. stacks and compositions of
Empty
,Wire
, andSwap
.perm_of_zx
, which gives the underlying permutation of a ZXperm, andshows that this determines the semantics of the diagram, so that showing the
equivalence of
ZXperm
s reduces to showing the equality of their underlyingpermutations. This task in invariably far simpler (in particular, tractable),
and we also provide significant automation for completing this task.
Moreover, we show
Z
andX
spiders absorbZXperm
s.zx_of_perm
, which realizes an arbitrary permutation as a ZX diagram.We prove this is suitably inverse to
perm_of_zx
.zx_comm n m : ZX (n + m) (m + n)
and proves its naturality, i.e.(zx0 ↕ zx1) ⟷ zx_comm m q ∝ zx_comm n p ⟷ (zx1 ↕ zx0)
(see
zx_comm_commutes_r
inZXpermFacts.v
). This gives pulling arbitrarydiagrams through Swap. Similarly generalize
a_swap
to show arbitrarydiagrams can be pulled through it.
This development is housed in the new Permutations subdirectory of src, and
comprises the following files. Dependency is indicated by the parentheticals
following each file, e.g. (1, 2) indicates dependence on (1) and (2) (only
immediate dependence is indicated).
Background files:
(1) PermutationAuxiliary: A collection of helpful lemmas across various domains,
including bool,
Prop
,nat
, andC
. They are broadly broken down by focus.Ideally, this file should be split up and its lemmas distributed to their
various appropriate destinations.
(2) MatEquivSetoid: Declares a Relation (
Setoid
) instance format_equiv
andProper
instances for many matrix operations (Mmult
,transpose
, etc.). Alsodefines an alternate to
direct_sum
,direct_sum'
, that isProper
withrespect to
mat_equiv
(the originaldirect_sum
is not, as it implicitly assumesits input matrices are WF)
Permutation Files
(3) PermutationDefinitions: Definitions of permutations and operations on them.
swap_perm
swaps any two elements,perm_inv'
is aWF_perm
version ofperm_inv
, androtr
/rotl
"rotate" left / right. The main operatorsare
stack_perms : permutation n -> permutation m -> permutation (n + m)
and
tensor_perms : permutation n -> permutation m -> permutation (n * m)
.(4) ZXperm (3): Defines
ZXperm
,perm_of_zx
, and (essentially)zx_of_perm
.Also defines some (now mostly obsolete) permutations specific to VyZX.
(5) PermutationAutomation (3,4): A large amount of automation for various tasks
across the project. This includes, amongst others:
General:
-
replace_bool_lia a b
: useful for simplifying bools in the goal. Roughlyequivalent to
replace a with b by (bdestruct a; bdestruct b; lia)
.-
bdestructΩ'
:bdestruct
all boolean expressions in the goal anddispatch as many remaining goals as possible with
easy
andlia
.bdestructΩ'simp
does this and performs intermediate simplification.-
solve_simple_mod_eqns
: attempts to extendlia
to more intelligentlyhandle expressions with
mod
.-
show_nonzero
: proves anat
is nonzero usinglia
and-
show_pow2_le
: preprocesses to simplify powers and appliesnia
-
show_moddy_lt
: a powerful tactic to showa < b
, wherea
includesmod
and/or/
. For instance, givenk < 2 ^ (m + n + o)
, it can showk mod (2^m) * 2^(n+o) + (k/(2^(m+n))) * 2^n + ((k/(2^m)) mod 2^n)
isless than the same upper bound. It works by computing a simple upper bound
on
a
(e.g.a mod c <= c - 1
forc <> 0
) which it shows is>= a
and<b
.-
simplify_bools_[moddy_]lia_one_kernel
: finds each atomic (not containingandb
,orb
, or anif
) boolean expression and attempts to replace itwith each of
true
andfalse
bybdestructΩ'
and, ifmoddy_
isadded,
show_moddy_lt
.-
simplify_bools_lia
: repeats the previous tactic. In practice,undesirably expensive;
do n [previous tactic]
is preferred, manuallydetermining the value of
n
to use.Permutations:
-
solve_modular_permutation_equalities
: usessolve_simple_mod_eqns
,bdestructΩ'
, and functional to show twonat -> nat
s are equal.-
cleanup_perm_inv
: rewrites withperm_inv_db
and callsauto
with allperm
databases below.-
cleanup_perm
: rewrites with the previous andperm_cleanup_db
, callsauto
as the previous. simplifications for permutations-
eq_by_WF_perm_eq n
: showsf = g
fromperm_eq n f g
,WF_Perm n f
,and
WF_Perm n g
, applying automation to the latter two-
perm_eq_by_inv_inj f n
: showsperm_eq n g h
fromf
being inverseto each of
g
andh
, applying automation to all goals.-
permutation_eq_by_WF_inv_inj f n
: like the previous, but for equality-
perm_by_inverse finv
: showspermutation n f
by giving an explicitinverse, applying automation to all goals.
VyZX / ZXperm:
-
simpl_permlike_zx
: performs a number of reductions akin to those ofcleanup_zx
, though often more quickly.-
clean_eqns tac
: performstac
and solves any shelved goals withlia
.Useful for using VyZX cast lemmas that may leave impossible side goals.
-
cleanup_perm_of_zx
: rewrites & callsauto
, with all below databases.The following are the defined databases. All new defined lemmas should be
put in the appropriate database to appropriately extend the automation.
-
perm_db
: resultspermutation n f
-
perm_bounded_db
: resultsperm_bounded n f
-
perm_inv_db
: resultsperm_eq n (perm_inv n f) _
,perm_inv' n f = _
,and (for now) any random results about
perm_eq
-
perm_cleanup_db
: general results to simplify instances of permutations-
zxperm_db
: resultsZXperm n zx
-
perm_of_zx_cleanup_db
: any results aboutperm_of_zx
,zx_of_perm
(6) PermutationFacts (1,5) and
(7) PermutationInstances (6): Theoretically, (6) contains facts about
general and specific permutations, while (7) contains proofs that
instances are
permutation
s,perm_bounded
,WF_Perm
, etc. In practice,there is significant intrusion of (7) into (6), as, for instance, many
facts about permutations rely on them being permutations.
Each permutation instance should have lemmas showing it is a
permutation
,showing it is a
WF_Perm
(if it is, which it almost always should be), anddefining its
perm_inv
(if possible, which again it often should be), eachof which should be added to the appropriate database. We have done this for
each permutation and operator that we define.
(8) PermMatrixFacts (2,7): Results about
perm_mat
andperm_to_matrix
, aswell as some helper lemmas to prove them. We show that the transpose of
perm_mat n f
isperm_mat n (perm_inv n f)
of the inverse and is aninverse (both left and right) of
perm_mat n f
. We also show thatperm_mat
,perm_to_matrix
are injective, soperm_mat n f = perm_mat n g
implies
perm_eq n f g
.(9) KronComm (8): the theory of
kron_comm p q : Matrix (p*q) (q*p)
, whichcommutes the tensor product. That is the main result, though we also show
it is
perm_mat (p*q) (kron_comm_perm p q)
along with various resultsabout it.
(10) PermutationSemantics (9): Specific values of
perm_to_matrix
, specificallythose relevant for VyZX, such as
rotr
.(11) ZXpermSemantics (10): Proof that the semantics of a
ZXperm
is determinedby its underlying permutation,
perm_of_zx
(up to strict equality, andhence up to proportionality). Gives rise to the tactic
by_perm_eq
, whichshows
zx0 ∝ zx1
fromZXperm n zx0
,ZXperm n zx1
, andperm_eq n (perm_of_zx zx0) (perm_of_zx zx1)
, applying automation to allthese goals.
(12) ZXpermFacts (11): Results about
perm_of_zx
andzx_of_perm
, includingthat they are mutually inverse. Also contains instances of
ZXperm
forVyZX functions (transpose, adjoint, etc.) and some specific ZX diagrams
(e.g.
a_swap
). Contains rules aboutzx_of_perm
relating ZX andpermutation operations (e.g.
Stack
andstack_perms
). Finally, containsdefinitions of
zx_comm p q : ZX (p + q) (q + p)
andzx_gap_comm p m q : ZX (p + m + q) (q + m + p)
along with proofs thateach commute stacking appropriately, that
Swap
anda_swap n
arespecial cases
zx_comm 1 1
andzx_gap_comm 1 (n-2) 1
(ifn >= 2
),and therefore that
Swap
anda_perm
commute stacking. Also includesresults showing that
X
andZ
spiders absorbZXperm
s, as well aszx_comm
andzx_gap_comm
.(13) PermutationRules (12 / all): Exports relevant files. Designed to be
imported when permutations are to be used.
Some of this work belongs in QuantumLib. How much is up for debate, but for
the moment, I believe it is better to at least have this be usable in VyZX and
move things into QuantumLib from there. As the material is mostly broken down
by section, it should be possible to assess how much material is needed to,
for example, move
KronComm
into QuantumLib. Much of the theory ofpermutations could be further migrated into QuantumLib, though that would
require including a significant amount of the automation as it is used
extensively throughout.