Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ New modules
* `Data.Bool.ListAction.Properties` for properties of conjunction and
disjunction of lists.

* `Data.Nat.Sqrt.Base` defines the square root of `n` as the greatest
natural number whose square is less than or equal to `n`, using a
primtive recursive definition originally due to Goodstein (1957).

* A new type of lists that grow on the right.
This is typically useful to model contexts of typing rules
or type accumulators that need to be reversed in the base case.
Expand Down
28 changes: 28 additions & 0 deletions src/Data/Nat/Sqrt/Base.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Natural number square root
--
-- Goodstein's (1957) primitive recursive definition, taken from
-- Troelstra and van Dalen, Constructivity in Mathematics, Vol. I
------------------------------------------------------------------------

{-# OPTIONS --without-K --safe #-}

module Data.Nat.Sqrt.Base where

open import Data.Bool.Base
open import Data.Nat.Base

sqrt : ℕ → ℕ
sqrt zero = zero
sqrt (suc n) = if (0 <ᵇ d) then √n else suc √n
module Sqrt where

√n = sqrt n

a*a+b∸c : ℕ → ℕ → ℕ → ℕ
Comment thread
gallais marked this conversation as resolved.
Outdated
a*a+b∸c zero b c = b ∸ c
a*a+b∸c (suc a) b c = a*a+b∸c a (suc (b + (a + a))) c

d = a*a+b∸c √n (√n + √n) n
Loading