Semiring solver (#50)

This commit is contained in:
Patrick Stevens
2019-10-12 11:14:27 +01:00
committed by GitHub
parent 5af4030361
commit 96d15c6017
7 changed files with 306 additions and 25 deletions

View File

@@ -8,28 +8,3 @@ module Numbers.Integers.Definition where
data : Set where
nonneg :
negSucc :
data Simple : Set where
negativeSucc : (a : ) Simple
positiveSucc : (a : ) Simple
zZero : Simple
convertZ : Simple
convertZ (nonneg zero) = zZero
convertZ (nonneg (succ x)) = positiveSucc x
convertZ (negSucc x) = negativeSucc x
convertZ' : Simple
convertZ' (negativeSucc a) = negSucc a
convertZ' (positiveSucc a) = nonneg (succ a)
convertZ' zZero = nonneg 0
zIsZ : (a : ) convertZ' (convertZ a) a
zIsZ (nonneg zero) = refl
zIsZ (nonneg (succ x)) = refl
zIsZ (negSucc x) = refl
zIsZ' : (a : Simple) convertZ (convertZ' a) a
zIsZ' (negativeSucc a) = refl
zIsZ' (positiveSucc a) = refl
zIsZ' zZero = refl

View File

@@ -10,6 +10,7 @@ open import Numbers.Naturals.Addition
open import Numbers.Naturals.Order
open import Numbers.Naturals.Multiplication
open import Numbers.Naturals.Exponentiation
open import Numbers.Naturals.Subtraction
open import Semirings.Definition
open import Monoids.Definition
@@ -20,6 +21,7 @@ module Numbers.Naturals.Naturals where
open Numbers.Naturals.Multiplication using (_*N_ ; multiplicationNIsCommutative) public
open Numbers.Naturals.Exponentiation using (_^N_) public
open Numbers.Naturals.Order using (_<N_ ; le; succPreservesInequality; succIsPositive; addingIncreases; zeroNeverGreater; noIntegersBetweenXAndSuccX; a<SuccA; canRemoveSuccFrom<N) public
open Numbers.Naturals.Subtraction using (_-N'_) public
Semiring : Semiring 0 1 _+N_ _*N_
Monoid.associative (Semiring.monoid Semiring) a b c = equalityCommutative (additionNIsAssociative a b c)

View File

@@ -0,0 +1,27 @@
{-# OPTIONS --warning=error --safe --without-K #-}
open import LogicalFormulae
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import WellFoundedInduction
open import Functions
open import Orders
open import Numbers.Naturals.Definition
open import Numbers.Naturals.Addition
open import Numbers.Naturals.Order
open import Numbers.Naturals.Multiplication
open import Numbers.Naturals.Exponentiation
open import Semirings.Definition
open import Monoids.Definition
open import Maybe
module Numbers.Naturals.Subtraction where
_-N'_ : (a b : ) Maybe
zero -N' zero = yes 0
zero -N' succ b = no
succ a -N' zero = yes (succ a)
succ a -N' succ b = a -N' b
subtractZero : (a : ) a -N' 0 yes a
subtractZero zero = refl
subtractZero (succ a) = refl