Skip to content

Commit 5765694

Browse files
authored
Merge pull request #95 from VariantSync/develop
Release 2.2
2 parents c1031b1 + 9fc94f5 commit 5765694

13 files changed

Lines changed: 412 additions & 125 deletions

File tree

.github/workflows/check.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ jobs:
1818
with:
1919
key: nix-${{ hashFiles('.github/workflows/check.yml', 'default.nix', 'nix/**') }}
2020
nix_file: nix/github-workflow-dependencies.nix
21+
- name: Setup the environment
22+
# Supress a warning about missing channels by using the shell from the environment
23+
run: echo NIX_BUILD_SHELL="$(which bash)" >> "$GITHUB_ENV"
2124
- name: Check Agda files
2225
run: nix-shell --run './scripts/check-all.sh github-action'
2326
- name: Check for sources of inconsistencies

default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
}:
1111
pkgs.agdaPackages.mkDerivation {
12-
version = "2.1";
12+
version = "2.2";
1313
pname = "Vatras";
1414
src = with pkgs.lib.fileset;
1515
toSource {

src/Vatras/Data/IndexedSet.lagda.md

Lines changed: 197 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module Eq = IsEquivalence isEquivalence
4545
## Definitions
4646

4747
```agda
48-
variable
48+
private variable
4949
iℓ jℓ kℓ : Level
5050
5151
-- An index can just be any set (of any universe, which is why it looks so complicated).
@@ -130,6 +130,19 @@ _⊢_≡ⁱ_ : ∀ {I : Set iℓ} (A : IndexedSet I) → I → I → Set ℓ
130130
A ⊢ i ≡ⁱ j = A i ≈ A j
131131
```
132132

133+
## Inverse Operations
134+
135+
```agda
136+
_∉_ : ∀ {I : Set iℓ} → Carrier → IndexedSet I → Set (ℓ ⊔ iℓ)
137+
a ∉ A = ∀ i → ¬ (a ≈ A i)
138+
139+
Disjoint : ∀ {I : Set iℓ} {J : Set jℓ} (A : IndexedSet I) (B : IndexedSet J) → Set (ℓ ⊔ iℓ ⊔ jℓ)
140+
Disjoint A B = ∀ i → A i ∉ B
141+
142+
Disjoint-flip : ∀ {I : Set iℓ} {J : Set jℓ} {A : IndexedSet I} {B : IndexedSet J} → Disjoint A B → Disjoint B A
143+
Disjoint-flip disjointAB j i Bj≈Ai = disjointAB i j (Eq.sym Bj≈Ai)
144+
```
145+
133146
## Singletons
134147

135148
```agda
@@ -164,11 +177,13 @@ We now prove the following theorems:
164177
⊆-refl i = i , Eq.refl
165178
166179
-- There is no antisymmetry definition in Relation.Binary.Indexed.Heterogeneous.Definition. Adding that to the standard library would be good and a low hanging fruit.
167-
⊆-antisym : ∀ {I : Set iℓ} {J : Set jℓ} → Antisym (_⊆_ {i₁ = I}) (_⊆_ {i₁ = J}) (_≅_)
180+
-- ⊆-antisym : ∀ {I : Set iℓ} {J : Set jℓ} → Antisym (_⊆_ {i₁ = I}) (_⊆_ {i₁ = J}) (_≅_)
181+
⊆-antisym : ∀ {I : Set iℓ} {J : Set jℓ} {A : IndexedSet I} {B : IndexedSet J} → A ⊆ B → B ⊆ A → A ≅ B
168182
⊆-antisym l r = l , r
169183
170184
-- There are no generalized transitivity, symmetry and antisymmetry definitions which allow different levels in Relation.Binary.Indexed.Heterogeneous.Definition . Adding that to the standard library would be good and a low hanging fruit.
171-
⊆-trans : Transitive (IndexedSet {iℓ}) _⊆_
185+
-- ⊆-trans : Transitive (IndexedSet {iℓ}) _⊆_
186+
⊆-trans : ∀ {I : Set iℓ} {J : Set jℓ} {K : Set kℓ} {A : IndexedSet I} {B : IndexedSet J} {C : IndexedSet K} → A ⊆ B → B ⊆ C → A ⊆ C
172187
⊆-trans A⊆B B⊆C i =
173188
-- This proof looks resembles state monad bind >>=.
174189
-- interesting... 🤔
@@ -179,10 +194,10 @@ We now prove the following theorems:
179194
≅-refl : Reflexive (IndexedSet {iℓ}) _≅_
180195
≅-refl = ⊆-refl , ⊆-refl
181196
182-
≅-sym : Symmetric (IndexedSet {iℓ}) _≅_
197+
≅-sym : ∀ {I : Set iℓ} {J : Set jℓ} {A : IndexedSet I} {B : IndexedSet J} → A ≅ B → B ≅ A
183198
≅-sym (l , r) = r , l
184199
185-
≅-trans : Transitive (IndexedSet {iℓ}) _≅_
200+
≅-trans : ∀ {I : Set iℓ} {J : Set jℓ} {K : Set kℓ} {A : IndexedSet I} {B : IndexedSet J} {C : IndexedSet K} → A ≅ B → B ≅ C → A ≅ C
186201
≅-trans (A⊆B , B⊆A) (B⊆C , C⊆B) =
187202
⊆-trans A⊆B B⊆C
188203
, ⊆-trans C⊆B B⊆A
@@ -625,6 +640,183 @@ singleton-set-is-nonempty : (A : 𝟙 iℓ) → nonempty A
625640
singleton-set-is-nonempty _ = tt
626641
```
627642

643+
## Operations
644+
645+
```agda
646+
module _ where
647+
open import Data.Sum using (_⊎_; inj₁; inj₂)
648+
private variable
649+
α : Set iℓ
650+
β : Set jℓ
651+
652+
{-|
653+
Indexed Set Union (Or):
654+
We can create the union of two indexed sets by accepting either of the input indices.
655+
-}
656+
infix 21 _⨆_
657+
_⨆_ : IndexedSet α → IndexedSet β → IndexedSet (α ⊎ β)
658+
(A ⨆ B) (inj₁ a) = A a
659+
(A ⨆ B) (inj₂ b) = B b
660+
661+
{-|
662+
Indexed Set Intersection (And):
663+
The set intersection should contain only elements that are both in A _and_ B.
664+
This means that an element is in the intersection if and only if there is an
665+
index for both A and B that both point to the element.
666+
Hence, the index set of the intersection set can be modelled as the type of
667+
all indices from A that point to elements that also B points to.
668+
-}
669+
infix 21 _⨅_
670+
_⨅_ : (A : IndexedSet α) → (B : IndexedSet β) → IndexedSet (Σ[ a ∈ α ] A a ∈ B)
671+
(A ⨅ B) (a , b , eq) = A a -- We could also pick B b here.
672+
673+
{-|
674+
Indexed Set Difference:
675+
We can remove all elements pointed to by B from an indexed set A by restricting the set of indices
676+
to those indices that do not point to elements in B.
677+
Hence, the index set of the difference set can be modelled as the type of
678+
all indices from A that point to elements that are not pointed at by B.
679+
-}
680+
infix 21 _∖_ -- use \setminus to create ∖ with Agda Input Mode in Emacs
681+
_∖_ : (A : IndexedSet α) → (B : IndexedSet β) → IndexedSet (Σ[ a ∈ α ] (A a ∉ B))
682+
(A ∖ B) (a , Aa∉B) = A a
683+
684+
module _ where
685+
open import Data.Empty using (⊥-elim)
686+
private variable
687+
γ : Set kℓ
688+
A : IndexedSet α
689+
B : IndexedSet β
690+
C : IndexedSet γ
691+
692+
-- ⨆ properties
693+
694+
⊆-⨆ : A ⊆ A ⨆ B
695+
⊆-⨆ i = inj₁ i , Eq.refl
696+
697+
⨆-⊆ : B ⊆ A → A ⨆ B ⊆ A
698+
⨆-⊆ _ (inj₁ a) = a , Eq.refl
699+
⨆-⊆ B⊆A (inj₂ b) = B⊆A b
700+
701+
⨆-idemp : A ⨆ A ≅ A
702+
⨆-idemp = ⨆-⊆ ⊆-refl , ⊆-⨆
703+
704+
⨆-comm-⊆ : A ⨆ B ⊆ B ⨆ A
705+
⨆-comm-⊆ (inj₁ a) = inj₂ a , Eq.refl
706+
⨆-comm-⊆ (inj₂ b) = inj₁ b , Eq.refl
707+
708+
⨆-comm : A ⨆ B ≅ B ⨆ A
709+
⨆-comm = ⨆-comm-⊆ , ⨆-comm-⊆
710+
711+
⨆-assoc-⊆ : (A ⨆ B) ⨆ C ⊆ A ⨆ (B ⨆ C)
712+
⨆-assoc-⊆ (inj₁ (inj₁ a)) = ⊆-⨆ a
713+
⨆-assoc-⊆ (inj₁ (inj₂ b)) = inj₂ (inj₁ b) , Eq.refl
714+
⨆-assoc-⊆ (inj₂ c) = inj₂ (inj₂ c) , Eq.refl
715+
716+
⨆-assoc-⊇ : A ⨆ (B ⨆ C) ⊆ (A ⨆ B) ⨆ C
717+
⨆-assoc-⊇ (inj₁ a) = inj₁ (inj₁ a) , Eq.refl
718+
⨆-assoc-⊇ (inj₂ (inj₁ b)) = inj₁ (inj₂ b) , Eq.refl
719+
⨆-assoc-⊇ (inj₂ (inj₂ c)) = inj₂ c , Eq.refl
720+
721+
⨆-assoc : (A ⨆ B) ⨆ C ≅ A ⨆ (B ⨆ C)
722+
⨆-assoc = ⨆-assoc-⊆ , ⨆-assoc-⊇
723+
724+
⨆-idʳ : A ⨆ 𝟘 ≅ A
725+
⨆-idʳ = ⨆-⊆ 𝟘⊆A , ⊆-⨆
726+
727+
⨆-idˡ : 𝟘 ⨆ A ≅ A
728+
⨆-idˡ = ≅-trans ⨆-comm ⨆-idʳ
729+
730+
-- ⨅ properties
731+
732+
⨅-⊆ : A ⨅ B ⊆ A
733+
⨅-⊆ (a₁ , _ ) = a₁ , Eq.refl
734+
735+
⊆-⨅ : A ⊆ B → A ⊆ A ⨅ B
736+
⊆-⨅ A⊆B a = (a , A⊆B a) , Eq.refl
737+
738+
⨅-idemp : A ⨅ A ≅ A
739+
⨅-idemp = ⨅-⊆ , ⊆-⨅ ⊆-refl
740+
741+
⨅-comm-⊆ : A ⨅ B ⊆ B ⨅ A
742+
⨅-comm-⊆ (a , b , Aa≈Bb) = (b , a , Eq.sym Aa≈Bb) , Aa≈Bb
743+
744+
⨅-comm : A ⨅ B ≅ B ⨅ A
745+
⨅-comm = ⨅-comm-⊆ , ⨅-comm-⊆
746+
747+
⨅-assoc-⊆ : (A ⨅ B) ⨅ C ⊆ A ⨅ (B ⨅ C)
748+
⨅-assoc-⊆ ((a , b , Aa≈Bb) , c , Aa≈Cc) = (a , (b , c , Eq.trans (Eq.sym Aa≈Bb) Aa≈Cc) , Aa≈Bb) , Eq.refl
749+
750+
⨅-assoc-⊇ : A ⨅ (B ⨅ C) ⊆ (A ⨅ B) ⨅ C
751+
⨅-assoc-⊇ (a , (b , c , Bb≈Cc) , Aa≈Bb) = ((a , b , Aa≈Bb) , c , Eq.trans Aa≈Bb Bb≈Cc) , Eq.refl
752+
753+
⨅-assoc : (A ⨅ B) ⨅ C ≅ A ⨅ (B ⨅ C)
754+
⨅-assoc = ⨅-assoc-⊆ , ⨅-assoc-⊇
755+
756+
⨅-zeroˡ : 𝟘 ⨅ A ≅ 𝟘
757+
⨅-zeroˡ = ⨅-⊆ , ⊆-⨅ 𝟘⊆A
758+
759+
⨅-zeroʳ : A ⨅ 𝟘 ≅ 𝟘
760+
⨅-zeroʳ = ≅-trans ⨅-comm ⨅-zeroˡ
761+
762+
-- "A ⨅ B ≅ 𝟘" and "Disjoint A B" are equivalent propositions.
763+
-- "A ⨅ B ≅ 𝟘" is the canonical way of saying that two sets are disjoint.
764+
-- "Disjoint A B" is a direct way of saying that for indexed sets.
765+
766+
⨅-empty→Disjoint : A ⨅ B ≅ 𝟘 → Disjoint A B
767+
⨅-empty→Disjoint (A⨅B⊆𝟘 , 𝟘⊆A⨅B) a b Aa≈Bb with A⨅B⊆𝟘 (a , b , Aa≈Bb)
768+
... | ()
769+
770+
Disjoint→⨅-empty : Disjoint A B → A ⨅ B ≅ 𝟘
771+
proj₁ (Disjoint→⨅-empty disjointAB) (a , b , Aa≈Bb) = ⊥-elim (disjointAB a b Aa≈Bb)
772+
proj₂ (Disjoint→⨅-empty disjointAB) = 𝟘⊆A
773+
774+
-- ∖ properties
775+
776+
∖-⊆ : A ∖ B ⊆ A
777+
∖-⊆ (a , Aa∉B) = a , Eq.refl
778+
779+
⊆-∖ : A ⨅ B ≅ 𝟘 → A ⊆ (A ∖ B)
780+
⊆-∖ A⨅B≅𝟘 a = (a , ⨅-empty→Disjoint A⨅B≅𝟘 a) , Eq.refl
781+
782+
≅-∖ : A ⨅ B ≅ 𝟘 → A ≅ (A ∖ B)
783+
≅-∖ A⨅B≅𝟘 = ⊆-∖ A⨅B≅𝟘 , ∖-⊆
784+
785+
∖-id : A ∖ 𝟘 ≅ A
786+
∖-id = ∖-⊆ , ⊆-∖ ⨅-zeroʳ
787+
788+
∖-zero-⊆ : 𝟘 ∖ A ⊆ 𝟘
789+
∖-zero-⊆ ()
790+
791+
∖-zero : 𝟘 ∖ A ≅ 𝟘
792+
∖-zero = ∖-zero-⊆ , 𝟘⊆A
793+
794+
-- combined properties
795+
796+
⨆-distrib-⨅-⊆ : A ⨆ (B ⨅ C) ⊆ (A ⨆ B) ⨅ (A ⨆ C)
797+
⨆-distrib-⨅-⊆ (inj₁ a) = (inj₁ a , ⊆-⨆ a) , Eq.refl
798+
⨆-distrib-⨅-⊆ (inj₂ (b , c , Bb≈Cc)) = (inj₂ b , inj₂ c , Bb≈Cc) , Eq.refl
799+
800+
⨆-distrib-⨅-⊇ : (A ⨆ B) ⨅ (A ⨆ C) ⊆ A ⨆ (B ⨅ C)
801+
⨆-distrib-⨅-⊇ (inj₁ a , _) = inj₁ a , Eq.refl
802+
⨆-distrib-⨅-⊇ (inj₂ b , inj₁ a , Bb≈Aa) = inj₁ a , Bb≈Aa
803+
⨆-distrib-⨅-⊇ (inj₂ b , inj₂ c , Bb≈Cc) = inj₂ (b , c , Bb≈Cc) , Eq.refl
804+
805+
⨆-distrib-⨅ : A ⨆ (B ⨅ C) ≅ (A ⨆ B) ⨅ (A ⨆ C)
806+
⨆-distrib-⨅ = ⨆-distrib-⨅-⊆ , ⨆-distrib-⨅-⊇
807+
808+
⨅-distrib-⨆-⊆ : A ⨅ (B ⨆ C) ⊆ (A ⨅ B) ⨆ (A ⨅ C)
809+
⨅-distrib-⨆-⊆ (a , inj₁ b , Aa≈Bb) = inj₁ (a , b , Aa≈Bb) , Eq.refl
810+
⨅-distrib-⨆-⊆ (a , inj₂ c , Aa≈Cc) = inj₂ (a , c , Aa≈Cc) , Eq.refl
811+
812+
⨅-distrib-⨆-⊇ : (A ⨅ B) ⨆ (A ⨅ C) ⊆ A ⨅ (B ⨆ C)
813+
⨅-distrib-⨆-⊇ (inj₁ (a , b , Aa≈Bb)) = (a , inj₁ b , Aa≈Bb) , Eq.refl
814+
⨅-distrib-⨆-⊇ (inj₂ (a , c , Aa≈Cc)) = (a , inj₂ c , Aa≈Cc) , Eq.refl
815+
816+
⨅-distrib-⨆ : A ⨅ (B ⨆ C) ≅ (A ⨅ B) ⨆ (A ⨅ C)
817+
⨅-distrib-⨆ = ⨅-distrib-⨆-⊆ , ⨅-distrib-⨆-⊇
818+
```
819+
628820
## Further Properties
629821

630822
### Reindexing

src/Vatras/Lang/ADT/Merge.agda

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,10 @@ module Named (F : 𝔽) where
6666

6767
module Prop (F : 𝔽) where
6868
open import Vatras.Data.Prop
69-
open Vatras.Lang.ADT (Prop F) V
7069
open import Vatras.Lang.ADT.Prop F V
71-
open Named (Prop F)
70+
open Named (Prop F) using (_⊕_) public
7271

73-
⊕-specₚ : {A} (l r : ADT A) (c : Assignment F)
72+
⊕-specₚ : {A} (l r : PropADT A) (c : Assignment F)
7473
⟦ l ⊕ r ⟧ₚ c ≡ ⟦ l ⟧ₚ c +ᵥ ⟦ r ⟧ₚ c
7574
⊕-specₚ (leaf v) (leaf r) c = refl
7675
⊕-specₚ (leaf l) (E ⟨ el , er ⟩) c with eval E c

src/Vatras/Lang/ADT/Prop.agda

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@ module Vatras.Lang.ADT.Prop (F : 𝔽) (V : 𝕍) where
44
open import Data.Bool using (if_then_else_)
55
open import Vatras.Data.Prop using (Prop; Assignment; eval)
66
open import Vatras.Framework.VariabilityLanguage
7-
open import Vatras.Lang.ADT (Prop F) V
87

9-
⟦_⟧ₚ : 𝔼-Semantics V (Assignment F) ADT
8+
import Vatras.Lang.ADT
9+
open Vatras.Lang.ADT using (ADT)
10+
open Vatras.Lang.ADT (Prop F) V using (⟦_⟧)
11+
open Vatras.Lang.ADT (Prop F) V using (leaf; _⟨_,_⟩) public
12+
13+
PropADT : 𝔼
14+
PropADT = ADT (Prop F) V
15+
16+
⟦_⟧ₚ : 𝔼-Semantics V (Assignment F) PropADT
1017
⟦ e ⟧ₚ c = ⟦ e ⟧ (λ D eval D c)
1118

1219
PropADTL : VariabilityLanguage V
13-
PropADTL =ADT , Assignment F , ⟦_⟧ₚ ⟫
20+
PropADTL =PropADT , Assignment F , ⟦_⟧ₚ ⟫

src/Vatras/Lang/All.agda

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Vatras.Lang.NCC
1717
import Vatras.Lang.2CC
1818
import Vatras.Lang.NADT
1919
import Vatras.Lang.ADT
20+
import Vatras.Lang.ADT.Prop
2021
import Vatras.Lang.OC
2122
import Vatras.Lang.FST
2223
import Vatras.Lang.Gruler
@@ -69,6 +70,11 @@ module ADT where
6970
module _ {F : 𝔽} {V : 𝕍} where
7071
open Vatras.Lang.ADT F V hiding (ADT; ADTL; Configuration) public
7172

73+
module PropADT where
74+
open Vatras.Lang.ADT.Prop using (PropADT; PropADTL) public
75+
module _ {F : 𝔽} {V : 𝕍} where
76+
open Vatras.Lang.ADT.Prop F V hiding (PropADT; PropADTL) public
77+
7278
module OC where
7379
open Vatras.Lang.OC using (OC; OCL; WFOC; WFOCL; Configuration) public
7480
module _ {F : 𝔽} where

src/Vatras/Lang/All/Fixed.agda

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Vatras.Lang.NCC
1010
import Vatras.Lang.2CC
1111
import Vatras.Lang.NADT
1212
import Vatras.Lang.ADT
13+
import Vatras.Lang.ADT.Prop
1314
import Vatras.Lang.OC
1415
import Vatras.Lang.FST
1516
import Vatras.Lang.Gruler
@@ -24,6 +25,7 @@ module NCC where
2425
open Vatras.Lang.NCC F n hiding (NCC; NCCL; Configuration) public
2526
module 2CC = Vatras.Lang.2CC F
2627
module NADT = Vatras.Lang.NADT F V
28+
module PropADT = Vatras.Lang.ADT.Prop F V
2729
module ADT = Vatras.Lang.ADT F V
2830
module OC = Vatras.Lang.OC F
2931
module FST = Vatras.Lang.FST F

src/Vatras/Lang/NCC.lagda.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
This module defines the choice calculus in which every choice must have the same
44
fixed number of alternatives, called $n-CC$ in our paper.
55

6-
It's required that arity $n$ is at least one to have semantics. However, we require
7-
that the arity is at least two, otherwise there is this annoying one-arity
8-
language in the NCC language family which is incomplete.
9-
In our paper, we also only inspect the languages with `n ≥ 2`.
6+
We require the arity $n$ to be at least two.
7+
An arity of zero would mean that all choices have zero alternatives.
8+
Choices with zero alternatives hence would constitute leaf terms without a clear purpose.
9+
Choices with exactly one alternative have only one way to be configured: selecting that single alternative.
10+
In both cases of an arity of zero or one, an $n-CC$ term denotes a single constant variant.
11+
For this reason, we restrict $n$ to be at least two, as we also did in our paper.
1012

1113
## Module
1214

@@ -39,10 +41,8 @@ data NCC : Size → 𝔼 where
3941
## Semantics
4042

4143
The semantics is very similar to the semantics for core choice calculus.
42-
The differences are:
43-
44-
- We can restrict configuration to choose alternatives within bounds because the arity of choices is known in advance.
45-
- We can then do a vector lookup instead of a list lookup in the semantics.
44+
The only difference is that we can restrict the configuration process to choose alternatives within bounds because the arity of choices is known in advance.
45+
We hence do a vector lookup instead of a list lookup.
4646

4747
```agda
4848
Configuration : ℂ

0 commit comments

Comments
 (0)