Documentation

DescriptiveComplexity.Problems.SubgraphIso.Encoding

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.

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.

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.

      Equations
      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 #

          theorem DescriptiveComplexity.subgraphIsoOn_iff_subtype {A : Type} (PV HV : AProp) (PE HE : AAProp) :
          SubgraphIsoOn PV HV PE HE ∃ (f : { x : A // PV x }{ y : A // HV y }), Function.Injective f ∀ (x y : { x : A // PV x }), PE x yHE (f x) (f y)

          SubgraphIsoOn as an injective map between the two subtypes: the guessed map of the definition, restricted to the pattern, and back.

          Dependency graph
          theorem DescriptiveComplexity.subgraphIsoOn_iff_concrete {A : Type} (i : SubgraphIsoInstance) (PV HV : AProp) (PE HE : AAProp) (eP : Fin i.pat { x : A // PV x }) (eH : Fin i.host { y : A // HV y }) (hEP : ∀ (a b : Fin i.pat), (a, b) i.patEdges PE (eP a) (eP b)) (hEH : ∀ (a b : Fin i.host), (a, b) i.hostEdges HE (eH a) (eH b)) :

          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
          Instances For
            Dependency graph

            The encoding of concrete instances by Language.twoGraphs-structures: universe Fin patFin 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 #

                    Dependency graph
                    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.

                              Dependency graph