简体   繁体   English

如何在 Agda 中定义归纳定义类型的子公式?

[英]How to define a subformula of an inductively defined type in Agda?

I'm trying to define a simple predicate to determine if a formula is a subformula of a given formal over a simple inductively defined syntax.我试图定义一个简单的谓词来确定一个公式是否是一个给定形式的子公式,而不是一个简单的归纳定义的语法。 I'm running into a few, presumably simple, problems.我遇到了一些可能很简单的问题。

(i) I'd rather use a parameterized module with a given type A. How can one import the information that A is a set, in the sense that A has decideable equality? (i) 我宁愿使用具有给定类型 A 的参数化模块。从 A 具有可判定相等的意义上说,如何导入 A 是集合的信息? If this can't be done, what are some workarounds?如果这无法完成,有哪些解决方法? This is why I have Nat instead.这就是为什么我用 Nat 代替。

(ii) Is the t1 ≡ (t2 // t3) (and similairly defined) predicates isSubFormula the proper way to deal with equal subformulas? (ii) t1 ≡ (t2 // t3) (和类似定义)谓词isSubFormula是处理相等子isSubFormula的正确方法吗? If not, how else does one easily do this?如果不是,那么人们如何轻松地做到这一点? I've also considered writing a predicate for equalFmla and then making a global subformula predicate with isSubFormula ⊎ equalFmla but am not sure if this is so clean.我还考虑过为equalFmla编写一个谓词,然后使用isSubFormula ⊎ equalFmla制作一个全局子公式谓词,但我不确定这是否如此干净。

(iii) Why do the last three lines highlight blue when I pattern match internal to the first one? (iii) 当我在第一行内部进行模式匹配时,为什么最后三行突出显示蓝色? How can I fix this我怎样才能解决这个问题

(iv) Why won't the {!Data.Nat._≟_ n1 n2 !} refine below? (iv) 为什么下面的{!Data.Nat._≟_ n1 n2 !}不会细化?

module categorial1 (A : Set) where

open import Data.Nat using (ℕ)
open import Data.Empty
open import Data.Sum
open import Relation.Binary.PropositionalEquality

-- type symbols
data tSymb : Set where
  -- base : A → tSymb
  base : ℕ → tSymb
  ~ : tSymb → tSymb
  _\\_ : tSymb → tSymb → tSymb
  _//_ : tSymb → tSymb → tSymb

-- A needs a decideable notion of equality
isSubFormula : tSymb → tSymb → Set
-- isSubFormula y (base x) = {!!}
isSubFormula (base n1) (base n2) = {!Data.Nat._≟_ n1 n2 !}
isSubFormula (~ t1) (base x) = ⊥
isSubFormula (t1 \\ t2) (base x) = ⊥
isSubFormula (t1 // t2) (base x) = ⊥
isSubFormula t1 (~ t2) = t1 ≡ (~ t2) ⊎ isSubFormula t1 t2
isSubFormula t1 (t2 \\ t3) = t1 ≡ (t2 \\ t3) ⊎ isSubFormula t1 t2 ⊎ isSubFormula t1 t3
isSubFormula t1 (t2 // t3) = t1 ≡ (t2 // t3) ⊎ isSubFormula t1 t2 ⊎ isSubFormula t1 t3

That's quite a lot of different questions;这是很多不同的问题; Stack Overflow works better if you post each question separately.如果您单独发布每个问题,堆栈溢出效果会更好。

Nevertheless, here are some answers:尽管如此,这里有一些答案:

(i) I'd rather use a parameterized module with a given type A. How can one import the information that A is a set, in the sense that A has decideable equality? (i) 我宁愿使用具有给定类型 A 的参数化模块。从 A 具有可判定相等的意义上说,如何导入 A 是集合的信息?

You can parametrize your module by the decision procedure, ie something like this:您可以通过决策程序参数化您的模块,即像这样:

open import Relation.Binary
open import Relation.Binary.PropositionalEquality

module categorical1 {A : Set} (_≟_ : Decidable (_≡_ {A = A})) where

Note that we import Relation.Binary (for Decidable ) and RBPropositionalEquality (for _≡_ ) before the module header, since the parameter types of our module depend on these definitions.请注意,我们在模块头之前导入Relation.Binary (用于Decidable )和RBPropositionalEquality (用于_≡_ ),因为我们模块的参数类型取决于这些定义。

(iii) Why do the last three lines highlight blue when I pattern match internal to the first one? (iii) 当我在第一行内部进行模式匹配时,为什么最后三行突出显示蓝色? How can I fix this我怎样才能解决这个问题

This is Agda warning you that those clauses won't hold definitionally, because they depend on the previous clauses not matching on t1 .这是 Agda 警告您,这些子句在定义上不成立,因为它们依赖于与t1不匹配的先前子句。

(iv) Why won't the {!Data.Nat. (iv) 为什么 {!Data.Nat. n1 n2 !} refine below? n1 n2 !} 在下面细化?

Because isSubFormula returns a Set , but n1 ≟ n2 returns a Dec _≡_ .因为isSubFormula返回一个Set ,但是n1 ≟ n2返回一个Dec _≡_

I think there is confusion in your code about whether isSubFormula is supposed to be a proposition or a decision procedure.我认为您的代码中关于isSubFormula应该是命题还是决策程序存在混淆。 If it returns a Set , it means it is a proposition.如果它返回一个Set ,则意味着它是一个命题。 You can write that without decidable equality since there is nothing to decide -- isSubFormula -ness of two base values means they are equal:您可以在没有可判定相等性的情况下编写它,因为没有什么可决定的——两个base值的isSubFormula表示它们相等:

isSubFormula : tSymb → tSymb → Set
isSubFormula (base n1) (base n2) = n1 ≡ n2

If you want a decision procedure, you could do it "boolean-blindly" by instead writing isSubFormula : tSymb → tSymb → Bool , or by keeping isSubFormula as a proposition and writing decSubFormula : Decidable isSubFormula .如果你想要一个决策程序,你可以通过写isSubFormula : tSymb → tSymb → Bool或者通过将isSubFormula作为一个命题并写decSubFormula : Decidable isSubFormula来“盲目地”做到这decSubFormula : Decidable isSubFormula

Note also that you only need decidable equality on A if you are trying to decide isSubFormula , so you can do另请注意,如果您尝试确定isSubFormula ,则只需要AA可判定相等isSubFormula ,因此您可以这样做

module categorical1 (A : Set) where

... 

isSubFormula : tSymb → tSymb → Set

decSubFormula : Decidable (_≡_ {A = A}) → Decidable isSubFormula
decSubFormula _≟A_ = ? -- You can use _≟A_ here to decide equality of A values

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM