-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
Complexity and csp definitions (and theorems... soon) #69
Draft
williamdemeo
wants to merge
6
commits into
ualib:master
Choose a base branch
from
stereotypeb:complexity
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
397a453
forgot to add the "parent" Complexity module
williamdemeo 61c9114
Merge branch 'ualib:master' into complexity
williamdemeo df6d230
generalize/improve CSP definitions
williamdemeo 209e858
Merge branch 'complexity' of github.com:williamdemeo/agda-algebras in…
williamdemeo 9bf8bc1
make levels more precise
williamdemeo 9749b49
Merge branch 'ualib:master' into complexity
williamdemeo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
layout: default | ||
title : Complexity module (The Agda Universal Algebra Library) | ||
date : 2021-07-13 | ||
author: [agda-algebras development team][] | ||
--- | ||
|
||
## Complexity Theory | ||
|
||
\begin{code} | ||
|
||
{-# OPTIONS --without-K --exact-split --safe #-} | ||
|
||
module Complexity where | ||
|
||
open import Complexity.Basic | ||
open import Complexity.CSP | ||
open import Complexity.FiniteCSP | ||
|
||
\end{code} | ||
|
||
|
||
-------------------------------- | ||
|
||
[agda-algebras development team]: https://github.com/ualib/agda-algebras#the-agda-algebras-development-team |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
--- | ||
layout: default | ||
title : Complexity.FiniteCSP module (The Agda Universal Algebra Library) | ||
date : 2021-07-14 | ||
author: [agda-algebras development team][] | ||
--- | ||
|
||
### Constraint Satisfaction Problems | ||
|
||
\begin{code} | ||
|
||
{-# OPTIONS --without-K --exact-split --safe #-} | ||
|
||
module Complexity.FiniteCSP where | ||
|
||
open import Agda.Primitive using ( _⊔_ ; lsuc ; Level) | ||
renaming ( Set to Type ) | ||
open import Data.Product using ( _,_ ; Σ ; Σ-syntax ) | ||
open import Data.Nat.Base using ( ℕ ) | ||
open import Data.Fin.Base using ( Fin ) | ||
open import Function.Base using ( _∘_ ) | ||
open import Relation.Unary using ( _∈_; Pred ) | ||
|
||
open import Relations.Continuous using ( Rel ) | ||
open import Algebras.Basic using ( Signature ) | ||
|
||
\end{code} | ||
|
||
|
||
#### Finite CSP | ||
|
||
An instance of a (finite) constraint satisfaction problem is a triple 𝑃 = (𝑉, 𝐷, 𝐶) where | ||
|
||
* 𝑉 is a finite set of variables, | ||
* 𝐷 is a finite domain, | ||
* 𝐶 is a finite list of constraints, where | ||
each constraint is a pair 𝐶 = (𝑥, 𝑅) in which | ||
* 𝑥 is a tuple of variables of length 𝑛, called the scope of 𝐶, and | ||
* 𝑅 is an 𝑛-ary relation on 𝐷, called the constraint relation of 𝐶. | ||
|
||
\begin{code} | ||
|
||
private variable χ ρ : Level | ||
|
||
record Constraint (∣V∣ ∣D∣ : ℕ) : Type (lsuc (χ ⊔ ρ)) where | ||
field | ||
scope : Fin ∣V∣ → Type χ -- a subset of Fin ∣V∣ | ||
|
||
relation : ((v : Fin ∣V∣ ) → v ∈ scope → Fin ∣D∣) → Type ρ | ||
-- a subset of "tuples" (i.e., functions 𝑓 : scope → Fin ∣D∣) | ||
|
||
-- An assignment 𝑓 : 𝑉 → 𝐷 of values in the domain to variables in 𝑉 | ||
-- *satisfies* the constraint 𝐶 = (𝑥, 𝑅) if 𝑓 ↾ 𝑥 ∈ 𝑅. | ||
satisfies : (Fin ∣V∣ → Fin ∣D∣) → Type ρ | ||
satisfies f = (λ v _ → f v) ∈ relation | ||
|
||
|
||
open Constraint | ||
|
||
record CSPInstance : Type (lsuc (χ ⊔ ρ)) where | ||
field | ||
∣V∣ -- # of variables, | ||
∣D∣ -- # of elements in the domain, | ||
∣C∣ -- # of constraints (resp.) | ||
: ℕ | ||
𝐶 : Fin ∣C∣ → Constraint{χ} ∣V∣ ∣D∣ | ||
|
||
-- An assignment 𝑓 *solves* the instance 𝑃 if it satisfies all the constraints. | ||
isSolution : (Fin ∣V∣ → Fin ∣D∣) → Type ρ | ||
isSolution f = ∀ i → (satisfies (𝐶 i)) f | ||
|
||
\end{code} | ||
|
||
|
||
|
||
#### References | ||
|
||
Some of the informal (i.e., non-agda) material in this module is similar to that presented in | ||
|
||
* Ross Willard's slides: [Constraint Satisfaction Problems: a Survey](http://www.math.uwaterloo.ca/~rdwillar/documents/Slides/willard-boulder2016-rev2.pdf) | ||
|
||
* [Polymorphisms, and How to Use Them](https://drops.dagstuhl.de/opus/volltexte/2017/6959/pdf/DFU-Vol7-15301-1.pdf | ||
|
||
|
||
|
||
-------------------------------------- | ||
|
||
[agda-algebras development team]: https://github.com/ualib/agda-algebras#the-agda-algebras-development-team | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems overly general. There is little point in having witnesses to whether something is in scope. You might as well use
Bool
instead. And thenVec (Fin |V|) Bool
might be easier?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good point. I want to make the FiniteCSP module very special and easy to use, so I'll try the
Vec
approach you suggest. (That's actually what I started with, but thought it was maybe too special... but probably you're right.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because
Fin |V|
has decidable equality (and is finite!), you gain very little from havingscope
be so very general. You may as well have other things also have decidable equality.