Skip to main content

Graded Rings in Lean’s Dependent Type Theory

  • Conference paper
  • First Online:
Intelligent Computer Mathematics (CICM 2022)


In principle, dependent type theory should provide an ideal foundation for formalizing graded rings, where each grade can be of a different type. However, the power of these foundations leaves a plethora of choices for how to proceed with such a formalization. This paper explores various different approaches to how formalization could proceed, and then demonstrates precisely how the authors formalized graded algebras in Lean’s mathlib. Notably, we show how this formalization was used as an API; allowing us to formalize various graded structures such as those on tuples, free monoids, tensor algebras, and Clifford algebras.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions


  1. 1.

    Or “a graded algebra of type \(\mathbb {N}\) over the ring R with graduation A” in the language of [6, III, §3, 1.].

  2. 2.

    Where \(\mathcal {C}\ell (V, Q)\) is notation to specify the quadratic form Q and vector space V.

  3. 3.

    At least, when \(Q\ne 0\). If \(Q = 0\) then \(\mathcal {C}\ell (V, Q) = \mathcal {\bigwedge }(V)\) and we can proceed as above.

  4. 4.

    Note that literature referring to an \(\mathbb {N}\)-grading is referring to the grading on \(\mathcal {\bigwedge }(V)\) via the canonical module equivalence.

  5. 5.

  6. 6.

    Some sources use a more general definition of graded R-modules and R-algebras, where R is itself a graded ring such that \(R_iM_j \subseteq M_{i+j}\). For brevity we will not discuss these here (in essence considering only the special case when R has the trivial graduation), but our approach would extends to this straightforwardly .

  7. 7.

    In the absence of our work a proof via convexity was used instead.

  8. 8.

    Chosen for brevity due to having the fewest axioms, not because they are interesting.

  9. 9.

    Lean 4 lifts this notation restriction, but the algebraic typeclasses provided by mathlib would need reworking.

  10. 10.

    The syntax in Lean for an incomplete proof.

  11. 11.

    After enabling the appropriate by-default-disabled instances.

  12. 12.

    Thus resolving the further work in [14, §8.1].

  13. 13.

    source lines of code.

  14. 14.

    Tracked in

  15. 15.

    In geometric algebra and algebraic geometry, respectively!.


  1. Affeldt, R., Cohen, C., Kerjean, M., Mahboubi, A., Rouhling, D., Sakaguchi, K.: Competing inheritance paths in dependent type theory: a case study in functional analysis. In: Peltier, N., Sofronie-Stokkermans, V. (eds.) IJCAR 2020. LNCS (LNAI), vol. 12167, pp. 3–20. Springer, Cham (2020).

    Chapter  Google Scholar 

  2. Avigad, J., et al.: Spectral Sequences in Homotopy Type Theory, November 2015.

  3. Baanen, A.: Leanprover-community/mathlib#11750: define subobject classes from submonoid up to subfield, April 2022.

  4. Baanen, A.: Use and abuse of instance parameters in the Lean mathematical library. In: ITP 2022, Haifa, Israel, May 2022.

  5. Barton, R., Commelin, J., Buzzard, K., Lau, K., Carneiro, M.: #maths \(>\) CDGAs, June 2019.

  6. Bourbaki, N.: Algebra I, Chapters 1–3. Elements of Mathematics. Springer, Heidelberg (1989).

    Book  MATH  Google Scholar 

  7. Brunerie, G., Ljungström, A., Mörtberg, A.: Synthetic integral cohomology in cubical agda. In: Manea, F., Simpson, A. (eds.) 30th EACSL Annual Conference on Computer Science Logic (CSL 2022). Leibniz International Proceedings in Informatics (LIPIcs), vol. 216, pp. 11:1–11:19. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, Dagstuhl, Germany (2022). ISSN: 1868-8969

  8. Castelvecchi, D.: Mathematicians welcome computer-assisted proof in ‘grand unification’ theory. Nature 595(7865), 18–19 (2021).

    Article  Google Scholar 

  9. Domínguez, C., Rubio, J.: Effective homology of bicomplexes, formalized in Coq. Theoret. Comput. Sci. 412(11), 962–970 (2011).

    Article  MathSciNet  MATH  Google Scholar 

  10. de Moura, L., Kong, S., Avigad, J., van Doorn, F., von Raumer, J.: The lean theorem prover (system description). In: Felty, A.P., Middeldorp, A. (eds.) CADE 2015. LNCS (LNAI), vol. 9195, pp. 378–388. Springer, Cham (2015).

    Chapter  Google Scholar 

  11. The mathlib Community: The lean mathematical library. In: Proceedings of the 9th ACM SIGPLAN International Conference on Certified Programs and Proofs, pp. 367–381. ACM, New Orleans, January 2020.

  12. The Stacks project authors: The Stacks project (2022).

  13. Wieser, E.: Scalar actions in Lean’s mathlib. In: CICM 2021. Timisoara, Romania, August 2021.

  14. Wieser, E., Song, U.: Formalizing geometric algebra in lean. Adv. Appl. Clifford Algebras 32(3), 28 (2022).

    Article  MathSciNet  MATH  Google Scholar 

Download references


The authors would like to thank Kevin Buzzard for his justified insistence on needing an interface to talk about internal gradings, Anne Baanen for picking up the mantle dropped by the first author on the rest of the set_like refactor, and the rest of the mathlib community for the extraordinarily collaborative work providing the context for this paper. The first author is funded by a scholarship from the Cambridge Trust. The second author is funded by the Schrödinger Scholarship Scheme from Imperial College London.

Author information

Authors and Affiliations


Corresponding author

Correspondence to Eric Wieser .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2022 The Author(s), under exclusive license to Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Wieser, E., Zhang, J. (2022). Graded Rings in Lean’s Dependent Type Theory. In: Buzzard, K., Kutsia, T. (eds) Intelligent Computer Mathematics. CICM 2022. Lecture Notes in Computer Science(), vol 13467. Springer, Cham.

Download citation

  • DOI:

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-031-16680-8

  • Online ISBN: 978-3-031-16681-5

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics