{"id":18695125,"url":"https://github.com/rybla/algebraexperiments","last_synced_at":"2026-01-25T02:32:50.983Z","repository":{"id":81618110,"uuid":"313795411","full_name":"rybla/AlgebraExperiments","owner":"rybla","description":"algebra experiments in Agda","archived":false,"fork":false,"pushed_at":"2020-11-26T20:00:10.000Z","size":99,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-19T00:11:49.907Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Agda","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rybla.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-11-18T02:00:48.000Z","updated_at":"2020-11-26T20:00:12.000Z","dependencies_parsed_at":"2023-03-06T01:15:16.129Z","dependency_job_id":null,"html_url":"https://github.com/rybla/AlgebraExperiments","commit_stats":null,"previous_names":["rybla/algebraexperiments"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rybla/AlgebraExperiments","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rybla%2FAlgebraExperiments","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rybla%2FAlgebraExperiments/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rybla%2FAlgebraExperiments/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rybla%2FAlgebraExperiments/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rybla","download_url":"https://codeload.github.com/rybla/AlgebraExperiments/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rybla%2FAlgebraExperiments/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28742511,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T01:40:51.112Z","status":"online","status_checked_at":"2026-01-25T02:00:06.841Z","response_time":113,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T11:14:03.128Z","updated_at":"2026-01-25T02:32:50.959Z","avatar_url":"https://github.com/rybla.png","language":"Agda","funding_links":[],"categories":[],"sub_categories":[],"readme":"# README\n\n- [Module Organization](#Module-Organization)\n- [Fibonacci Sequence via Recursive Definition](#Fibonacci-Sequence-via-Recursive-Definition)\n- [Fibonacci via Closed Formula](#Fibonacci-via-Closed-Formula)\n- [Fields](#Fields)\n- [Algebraic Field Extensions by Square Root of Square-Free Number](#Algebraic-Field-Extensions-by-Square-Root-of-Square-Free-Number)\n- [Tasks](#Tasks)\n\n## Module Organization\n\n```\nFibonacci/           # the nth Fibonacci number\nRecursive.agda       # - recursive definition\nClosed.agda          # - closed definition and correctness\n\nAlgebra/             # algebraic structures\n\nField/               # - fields\nBase.agda            #   - formalization of mathematical field\nRational.agda        #   - instantiation of the rational field\nExponentiation.agda  #   - natural exponentation over fields\nPolynomial.agda      #   - polynomials over fields\nField.agda\n\nExtension/           # - field extensions (FE)\nAlgebraic/           #   - algebraic field extensions (AFE)\n\t  E.agda         #   - AFE by square root\n  E5.agda            #   - AFE of ℚ by sqrt[5]\n\nData/                # general data structures\nSubset.agda          # - predicated terms\n```\n\n\n## Fibonacci Sequence via Recursive Definition\n\nThe Fibonacci sequence is a well-known sequence of natural numbers, and it is typically defined recursively as follows:\n\n```\nThe 0th Fibonacci number is 0.\nThe 1st Fibonacci number is 1.\nThe (n+2)th Fibonacci number is the sum of the (n+1)th and nth Fibonacci numbers, for n ≥ 0.\n```\n\nThe module `Fibonacci.Recursive` implements a function `fibonacci-recursive : ℕ → ℕ` that meets the specification above exactly. It is constructed as follows:\n\n```agda\nfibonacci-recursive : ℕ → ℕ\nfibonacci-recursive 0       = 0\nfibonacci-recursive 1       = 1\nfibonacci-recursive (suc (suc n)) = ficonacci-rec (suc n) + fibonacci-recursive n\n```\n\n## Fibonacci via Closed Formula\n\nThere is in fact a closed formula for the nth Fibonacci number, which is the following:\n\n```\nThe nth Fibonacci number is (φ ^ n - (1 - φ) ^ n) / sqrt[5]\n```\n\nwhere `φ = (1/2)(1 + sqrt[5])` is the golden ratio.\nSee `doc/fibonacci/main.pdf` for a mathematical deriviation of this closed form.\nJust as before, we can formalize this specification in Agda straightforwardly:\n\n```agda\nfibonacci-extended n = (φ ^ n - (1 - φ) ^ n) / sqrt[5]\n```\n\nObserve that the type signature is missing --- let us derive what it must be.\nFor `fibonacci-recursive`, we only needed addition, and so were safely working over just monoid of addition over `ℕ`, and so the signature `ℕ → ℕ` was perfectly safe.\nHowever, in `fibonacci-extended`, there are few new capabilities used.\n1. To use subtraction, we must have an addition group.\n2. To use exponentiation, we must have a multiplication monoid.\n3. To use division by nonzero elements, we must have a multiplication group over nonzero elements.\n\n(1.) and (2.) require that we have a (commutative) ring.\nThen (3.) requires further that we have a field.\nSince our result must eventually be reducible to a natural number,\nthe field to use should be the rational number field, `ℚ`.\nAdditionally since we are using `sqrt[5]` we must also extend `ℚ` with `sqrt[5]`, written `ℚ[sqrt[5]]`.\nSince `sqrt[5]` is a zero of the `ℚ`-polynomial `X^2 - 5` (i.e. is algebraic), this is an algebraic field extension, which is a field itself.\n\nSo, we can type `fibonacci-extended` like so:\n\n```agda\nfibonacci-extended : ℕ → ℚ[sqrt[5]]\nfibonacci-extended n = (φ ^ n - (1 - φ) ^ n) / sqrt[5]\n```\n\nBut how exactly is `ℚ[sqrt[5]]` defined in Agda?\nFirst we formalize fields in Agda\n(the Agda standard library only defines algebraic structures up to commutative rings and distributive lattices).\nThen we formalize algebraic field extensions by a the square root of a square-free number.\n\n## Fields\n\nThe following is an oversimplified formalization of a Field.\nThe fully-detailed construction is given in the module `Algebra.Field.Base`.\n\n```agda\nrecord IsField\n       {a ℓ : Level} {A : Set a}\n       (_≈_ : Rel A ℓ)\n       (0# : A) (1# : A)\n       (_+_ _*_ : Op₂ A) (-_ : Op₁ A)\n       (_⁻¹ : Op₁ A≉0#)\n       : Set (a ⊔ ℓ)\n  where\n    field\n      1#≉0# : 1# ≉ 0#\n      isCommutativeRing : IsCommutativeRing _≈_ _+_ _*_ -_ 0# 1#\n      *-isNonzeroClosed : IsClosed₂ _≉0# _*_\n      *-isAbelianGroup  : IsAbelianGroup _≈|_ _*|_ 1#| _⁻¹\n```\n\nParameters:\n- `A` is the carrier (i.e. underlying type) of the field\n- `_≈_` is the equivalence relation on `A`\n- `0#` is the additive identity\n- `1#` is the multiplicative identity\n- `_+_`, `_*_`, `-_` are the addition, multiplication, and additive inverse operations (to form a commutative ring)\n- `_⁻¹` is the multiplicative inverse on nonzero terms\n\nProperties:\n- `1#≉0#`: there is at least one nonzero term; implemented using `Data.Subset`\n- `isCommutativeRing`: `_+_`, `_*_`, `-_` form a commutative ring\n- `*-isNonzeroClosed`: the product of nonzero terms is nonzero\n- `*-isAbelianGroup`: `_*|_`, `_⁻¹` form an abelian group with identity `1#|`, where `_*|_` is `_*_` restricted to nonzero terms and `1#|` is `1#` included as a nonzero term\n\nTogether, these properties yield a mathematical field that satisfies the following field axioms:\n1. `_+_` is associative\n2. `_+_`, `_*_` are commutative\n3. `_+_`, `_*_` have identities `0#`, `1#` respectively (i.e. monoids)\n4. `_+_` has inverse `-` (i.e. group)\n5. `_*_` has inverse `⁻¹` on nonzero elements (i.e. group over nonzeros)\n6. `_*_` distributes over `_+_` (i.e. ring)\n\n## Algebraic Field Extensions by Square Root of Square-Free Number\n\nA field can be extended by adding new terms and extending the field operations such that the result is still a field.\nFurther, a field extension is called __algebraic__ if the extension is by a term that is the zero of a polynomial with coefficients in original field.\nFor example, the complex number field are an algebraic field extension of the real number field by the zero of the polnomial `X^2 + 1`.\nA nonexample is the real number field as an extension of the rational numbers, since there are real numbers such as `π` that are not the zero of any polynomial over the rationals (i.e. `π` is transcendental).\n\nA simple procedure for producing some algebraic field extensions is by extending by the zero of the polynomial `X^2 + α`, where `α` is square-free in the original field.\nWe can encode a term in such a field extension as follows, which is defined in `Algebra.Field.Extension.BySqrt`.\n\n```agda\nrecord E : Set a where\n  constructor _+sqrt[α]_\n  field\n    internal : A\n    external : A\n```\n\nHere, `A` is the original field.\nFor a term of `E`,\nits `internal` component resides in the original field,  and\nthe `external` component is extended by the new term `sqrt[α]`.\n\nThen we can define the extended terms necessary to form a field in terms of the origiginal field's terms.\nThe `′` suffix indicates that the term is the extended version of the usual field term.\n\n```agda\n0#′ : E\n0#′ = 0# +sqrt[α] 0#\n\n1#′ : E\n1#′ = 1# +sqrt[α] 0#\n\n-1#′ : E\n-1#′ = -1# + sqrt[α] 0#\n\n_≈′_ : Rel E ℓ\n(a +sqrt[α] b) ≈′ (c +sqrt[α] d) = (a ≈ c) × (b ≈ d)\n\n_+′_ : Op₂ E\n(a +sqrt[α] b) +′ (c +sqrt[α] d) = (a + c) +sqrt[α] (b + d)\n\n_*′_ : Op₂ E\n(a +sqrt[α] b) *′ (c +sqrt[α] d) =\n    ((a * c) + (α * (b * d))) +sqrt[α]\n    ((a * d) + (b * c))\n\n-′_  : Op₁ E\n-′ x = -1#′ *′ x\n\n-- omitted proofs of ≉0#′\n_⁻¹′  : Op₁ E≉0#′\n(a@(x +sqrt[α] y) # pa) ⁻¹′ =\n    ((  x  ÷ ((x ²) - (α * (y ²)) # _)) +sqrt[α]\n    ((- y) ÷ ((x ²) - (α * (y ²)) # _))) # _\n```\n\nFrom all this we can construct the `IsField` instance for a field extension.\n\n```agda\nisField-ExtensionE : IsField _≈′_ 0#′ 1#′ _+′_ _*′_ -′_ _⁻¹′\nisField-ExtensionE = _ -- omitted proofs of field properties\n```\n\n\n## Tasks\n\n- algebraic structures\n  - [x] formalization of fields; in `Algebra.Field.Base` as `IsField`\n    - [x] implement natural exponentiation over fields\n      - [ ] implement fast natural exponentiation over fields using repeated squaring and binary representations\n  - [x] formalization of algebraic field extension by square-free square root; in `Algebra.Field.Base.Extension.BySqrt`\n    - [ ] prove that such an extension is a field i.e. fill in details for `isField-E`\n  - [x] `IsField` instantiation for `ℚ[sqrt[5]]`; in `Algebra.Field.Base.Extension.BySqrt5`\n  - [x] formalization of polynomials over fields; in `Algebra.Field.Polynomial`\n      - [ ] implement multiplicative inverse for nonzero polynomials\n      - [x] implement polynomial equivalence via normalization\n      - [ ] prove that polynomial equivalence is an equivalence relation\n  - [x] formalization of power series over fields; in `Algebra.Field.Polynomial`\n    - [ ] implement power series equivalence\n    - [ ] prove that power series equivalence is an equivalence relation\n    - [x] formalization of convergence of power series\n      - [ ] define constructively rather than postulating convergence rules\n    - [ ] prove that taking the limit of a convergent power series in injective\n    - [x] prove that power series construction is injective\n- Fibonacci sequence\n  - [x] implementation of recursive `fibonacci`; in `Fibonacci.Recursive`\n  - [x] implementation of closed `fibonacci`; in `Fibonacci.Closed`\n  - [x] correctness proof of embedding recursive `fibonacci` into `ℚ[sqrt[5]]`; as `F′≡F`\n  - [x] correctness proof of Fibonacci closed form\n    - [x] prove `g₀ ≈ₛ g₁`\n    - [ ] prove `g₁ ≈ₛ g₂`\n    - [ ] prove `g₃ ⟶∞ g₄`\n    - [ ] prove `f₀ ⟶∞ f₁`\n    - [ ] prove `f₁ ≈ₚ f₂`\n    - [ ] prove `f₃ ⟶∞ f₂`\n    - [ ] prove `f₃ ≈ₛ f₄`\n    - [x] prove `f₀ ≈ₛ f₃`\n    - [x] prove `f₀ ≈ₛ f₄`\n    - [x] prove `F (n +1) ≡ h (n +1)`\n    - [x] prove `F n ≡ h n`\n    - [x] prove `fibonacci-extendedended n ≡ F′ n`\n    - [x] prove main theorem: `fibonacci-extendedracted n ≡ fibonacci-recursiveursive n`\n- Miscellaneous\n  - [ ] fill in postulates used in places where I haven't gotten around to the full proofs yet\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frybla%2Falgebraexperiments","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frybla%2Falgebraexperiments","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frybla%2Falgebraexperiments/lists"}