Subgraph Isomorphism on concrete graphs: encoding and decoding #
DescriptiveComplexity.SubgraphIso is a problem on FirstOrder.Language.twoGraphs-structures.
A user starts from two concrete graphs – a pattern on p vertices and a host
on h vertices, each a finite set of directed edges – and the textbook
question, DescriptiveComplexity.ConcreteSubgraphIsoHolds: is there an
injective map from the pattern's vertices to the host's carrying every edge
of the pattern to an edge of the host? This file ties the two together in
both directions, with the machinery of DescriptiveComplexity.Encoding and
DescriptiveComplexity.Decoding, the way the two tutorials
(DescriptiveComplexity.Examples.ConjunctiveQueries,
DescriptiveComplexity.Examples.GraphCrawling) do for their domains.
DescriptiveComplexity.subgraphIsoEncoding: the pattern's vertices to the left of a sum, the host's to the right, the marks reading the side and the two adjacency relations reading the two edge sets. The size bounds are discharged at construction: the universe is the vertex set, and an edge set has at most quadratically many elements.DescriptiveComplexity.subgraphIsoEncoding_faithful: the abstract problem computes the textbook one on every encoded instance.DescriptiveComplexity.subgraphIsoDecoding: the decoder, which needs no well-formedness condition. The semantics ofSubgraphIsoignores the elements in neither mark, and never relates the pattern role and the host role of one element – the guessed map sends pattern vertices to host vertices, and a vertex may be its own image – so a structure marking an element as both is the same instance as one where that element is split in two. The decoder therefore reads every presented structure back: pattern vertices are the pattern-marked elements, host vertices the host-marked ones, each enumerated in order, and the edges are read off the tables. Contrast the crawling tutorial, where the decoder exists only on single-root websites, and compareDescriptiveComplexity.bwDecoding, the other decoder of the library whose condition is⊤.
Both directions go through one lemma,
DescriptiveComplexity.subgraphIsoOn_iff_concrete: against an enumeration of
the pattern vertices and one of the host vertices, the generic property
DescriptiveComplexity.SubgraphIsoOn is the textbook predicate. The encoding
enumerates them by the two injections of the sum, the decoding by
Finset.orderIsoOfFin on the two marked sets.
The concrete problem #
A concrete instance of Subgraph Isomorphism: a pattern graph on
Fin pat and a host graph on Fin host, each given by its set of directed
edges.
- pat : ℕ
The number of pattern vertices.
- host : ℕ
The number of host vertices.
The edges of the pattern.
The edges of the host.
Instances For
Dependency graph
Dependency graph
Equations
- One or more equations did not get rendered due to their size.
Instances For
Dependency graph
The textbook size of a concrete instance: vertices and edges of both graphs. The one audited line of the encoding.
Instances For
Dependency graph
The textbook semantics of a concrete instance: an injective map from the pattern's vertices to the host's carrying every edge of the pattern to an edge of the host.
Equations
Instances For
Dependency graph
The generic property, against enumerations of the two vertex sets #
SubgraphIsoOn as an injective map between the two subtypes: the
guessed map of the definition, restricted to the pattern, and back.
Dependency graph
The generic property is the textbook predicate, once the pattern and
host vertices are enumerated (eP, eH) and the two edge sets are read
through the enumerations (hEP, hEH). The encoding and the decoding below
each supply one pair of enumerations.
Dependency graph
The encoding #
The encoder, standalone and auditable: a plain def, so the compiler
vouches that it computes. Pattern vertices are the left injections, host
vertices the right ones, and the two adjacency relations decide membership in
the two edge sets on their own side.
Equations
- One or more equations did not get rendered due to their size.
- DescriptiveComplexity.sgRelBool i FirstOrder.Language.twoGraphsRel.patV = fun (x : Fin 1 → Fin i.pat ⊕ Fin i.host) => (x 0).isLeft
- DescriptiveComplexity.sgRelBool i FirstOrder.Language.twoGraphsRel.hostV = fun (x : Fin 1 → Fin i.pat ⊕ Fin i.host) => (x 0).isRight
Instances For
Dependency graph
The encoding of concrete instances by Language.twoGraphs-structures:
universe Fin pat ⊕ Fin host, relations by sgRelBool. The universe is the
vertex set, so nothing is padded, and an edge set has at most quadratically
many elements, so nothing is compressed.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Dependency graph
On an encoded instance, being a pattern vertex is being a left injection.
Dependency graph
On an encoded instance, being a host vertex is being a right injection.
Dependency graph
Pattern adjacency on an encoded instance, at two left injections.
Dependency graph
Host adjacency on an encoded instance, at two right injections.
Dependency graph
The pattern vertices of an encoded instance, enumerated by the left injection.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Dependency graph
The host vertices of an encoded instance, enumerated by the right injection.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Dependency graph
The encoding is faithful: SubgraphIso computes the textbook
predicate on every encoded instance.
Dependency graph
A worked instance, run #
A concrete instance: the directed triangle as pattern, the complete directed graph on four vertices as host.
Equations
Instances For
Dependency graph
The decoding #
The pattern vertices of a presented structure.
Equations
- DescriptiveComplexity.sgPatVs S = {x : Fin S.card | S.relBool FirstOrder.Language.tgPatV ![x] = true}
Instances For
Dependency graph
The host vertices of a presented structure.
Equations
- DescriptiveComplexity.sgHostVs S = {x : Fin S.card | S.relBool FirstOrder.Language.tgHostV ![x] = true}
Instances For
Dependency graph
Dependency graph
Dependency graph
The decoder: enumerate the pattern vertices and the host vertices, in order, and read the two edge sets off the tables through the enumerations. Total: every presented structure is an instance.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Dependency graph
The pattern vertices of a presented structure, enumerated in order.
Equations
Instances For
Dependency graph
The host vertices of a presented structure, enumerated in order.
Equations
Instances For
Dependency graph
Dependency graph
Dependency graph
The computable decoding of presented structures, with no
well-formedness condition. Together with subgraphIsoEncoding_faithful it
closes the loop: encoded instances are equidecided, and every nonempty
finite structure decodes to an equidecided concrete instance, so
SubgraphIso is nowhere hard only on junk.
Equations
Instances For
Dependency graph
A presented four-element structure: element 0 a pattern vertex, 1
and 2 host vertices, 3 in both roles, with the pattern edge 0 → 3 and
the host edges 3 → 1 and 1 → 2. The decoder runs on it: the pattern has
two vertices and one edge, the host three vertices and two edges.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Dependency graph
Hardness reads back to concrete data: every nonempty finite
twoGraphs-structure is decided by SubgraphIso exactly as some pair of
concrete graphs is by the textbook predicate.