Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cubical reflection machinery and Solvers for Paths #1150

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

marcinjangrzybowski
Copy link
Contributor

@marcinjangrzybowski marcinjangrzybowski commented Aug 28, 2024

For this to work, it requires following PR's merged to Agda agda/agda#7287, agda/agda#6629
(here is my branch incorporating thosoe changes into latest version of agda)
detaills of the issue adrressed by thosoe PRs, are explained in Agda issue 7288

Solvers for Cubical Terms

This is the main goal of the PR, all the other modules are used by those solvers.

features:

  • applying groupoid laws
  • functoriallity of cong
    (congFunct generalised for arbitrary many arguments , both explicit and impllicit)
  • all the laws are aplied recursively for subterms as necessary
  • in single solution, solver will deal with as many diferent types in subterms as necessary, each one from arbitraty universe level.
  • handling paths defined as free variables, abstract defs, HITs, constructors, ua , build with funExt or as subfaces and diagonalls of higer dimensional cubes
  • Interval expressions involving (i ∨ ~ i , i ∧ ~ i , etc ... ) are interpolated as necessary into "non degenerated forms" (also in higher dimensions)

there are two solvers implemented, with overlaping functinality, but slightly different limitations:

Cubical.Tactics.PathSolver.NSolver (examples) (tests)

This solver, besides fillng squares, is able to prove coherences up to arbitrary dimension. (by coherences I mean that it is able to prove pentagon identity, but not Eckmann-Hilton cube)
One of the limitation is that it treats every cubical cell as seperate path, thus failing in goals analogus to cong₂Funct

Cubical.Tactics.PathSolver.MonoidalSolver (examples)

This solver applies generalised version of cong₂Funct, but does not provide coherences, it can be used only to fill squares.
(Monoidal nomenclature comes from the idea that n-cong is treated as functor from path in n-prod, there is surely better name for this, but this was my first intuition)

Visualisation of example solutions of simple goals:

module _ {ℓ} (A : Type ℓ) {x y z w v : A} {x : A} (p : x ≡ y) (q q' : y ≡ z) (r : z ≡ w) (s : w ≡ v) where
 ex1 : (q ∙ sym q' ∙ q) ∙ (sym q ∙∙ q' ∙∙ r)  ≡
        sym p ∙ p ∙ q ∙ r ∙ s ∙ sym s
 ex1 = solvePaths
 
 ex2 : Square
         (q ∙ sym q' ∙ q)
         (q ∙ r ∙ s ∙ sym s)
         (sym p ∙ p)
         (sym q ∙∙ q' ∙∙ r)
 ex2 = solvePaths

Helper modules

Utilities for handling dimensions and faces Cubical.Tactics.Reflection.Dimensions.agda

  • This module elaborates on handling interval expressions and face expressions (FExpr) in reflected syntax.
  • Abstract representations for interval expressions (IExpr) and operations like disjunction (∨'), conjunction (∧'), and negation (~') , allows for more agresive normalisation ( i ∨ i => i)
  • Utilities for converting between IExpr and FExpr, functions for adding interval dimensions to contexts, various operations for specyfic transformations face expressions.
  • Interpollating between "degenerated?" Interval expression, and equivalent, simple form : (i ∧ ~ i) => i0

Specialised Term Representation Cubical.Tactics.Reflection.CuTerm.agda

This module introduces a representation for cubical terms, focusing particularly on compositions and higher-dimensional constructs. The CuTerm' includes specialized constructors like hco' for hcomps and cell' for cells, enabling a more nuanced manipulation of terms. Partial elements , and abstrations over Interval variables are also abstracted away.

  • Rendering and Conversion: Functions for converting CuTerm' into Agda's reflected R.Term and vice versa, facilitating reflection-based manipulations.
  • Normalization and Evaluation: Utilities like cuEval and normaliseCells provide mechanisms for evaluating and normalizing terms within the CuTerm' representation, essential for solver operations and macro utility functions.
  • Code Generation & Pretty Printer: A codeGen utility for translating CuTerm' representations back into Agda code, useful for debugging and macro-generated code validation, thera are also macros for inspecting cubical terms, and generating normalised terms (currently, cubical terms cannot be reliably given using C-u C-u C-c C-m), this provides workaround.

demo-pp

Macros for Handling Cubical Terms Cubical.Tactics.PathSolver.Macro.agda. (examples)

some of the utills used by folders are wrapped into seperate macros.

here is demo of macro for convinient composition code generation:

macro-demo

Syntactic sugar via Instances + monad transformers

For long I was avoiding introducing all this transformers machinery to my code, eventualy when I submited, it imensly improved redability/maintability/ease of developement of the code in this PR.

  • Modules: Cubical.Reflection.Sugar.agda, including submodules Base and Instances.
    • Design Assumption: Created with a focus on utility and ease of macro writing. Formal reasoning about their categorical nature was not a goal. Purposufully put this into Reflection module, to make it clear that this is NOT formalisation of the concept.
    • Content:
      • Definitions for RawMonad, RawApplicative, RawMonadTransformer, and IdentityFunctor.
      • Instances for common types like Maybe, List, and Sum, operators for combining monads, traversal and maps realying on RawMonad instances
    • Independence: The Base submodule does not depend in any way on cubical library.

External integrations

Additionally, machinery form PR allows for integration with external tools that operate on Agda's AST, with the focus of terms including interatively nested hcomps:
(integration code is not part of the PR, link are for external files)

Dedekind.agda

CubeViz2Export.agda

Cartesian Experiment

as demonstration of utility of cubical reflection machinery I included macro transforming terms to a equivalent form where all interval expressions are either i0, i1, or a single interval variable (This transformation excludes the implicit φ argument of hcomp, which is effectively a face expression), crudely mimicking transpillation to Cartesian cubical theory (I think?)

@marcinjangrzybowski
Copy link
Contributor Author

@felixwellen this is PR we discussed earlier
I prepared code for initiall round of review by providing comments, and refactoring modules into sane strucutre,
before doing full code cleanup (nice names for all lemmas, nice foormatting) I would like to get some initial aproval of general idea.

@marcinjangrzybowski marcinjangrzybowski changed the title Cubcial reflectoin machinery and Solvers for Paths Cubical reflection machinery and Solvers for Paths Aug 28, 2024
@felixwellen
Copy link
Collaborator

This is awesome :-)
Pending a suitable release of agda and reviewing/polishing of your changes, this should be merged.
We should also look on the type checking time - if there is a big increase, I think we should come up with a workaround.

@marcinjangrzybowski
Copy link
Contributor Author

I am thinking on providing Lightweigh and Havy (basic/extended?) version of tests/examples,
and exclude them from default CI run (either by using existing check-except option in Everythings.hs or adding other mechanism - will share proof of concept of that)

@felixwellen
Copy link
Collaborator

I think one important point is, that we won't slow down the agda ci (so whatever they use to check if cubical still checks with agda should not get worse).

preventing ua from beaing inlined in pretty-print macro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants