流的仿函数定律的证明

时间:2015-05-26 02:49:31

标签: verification idris coinduction

我一直在写类似Stream的内容。我能够证明每个算子法,但我无法找到证明它总数的方法:

    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("id", id.toString());
    doc.addField("employeeNumber", employeeNumber);
    doc.addField("name", name);
    doc.addField("url", url.toString());
    if( imageUrl != null ) doc.addField("imageUrl", imageUrl.toString());
    doc.addField("location", location.getAbsolutePath());
    doc.addField("archivedDate", format.format(archiveDate) );
    if( categories != null ) {
        for( String cat : categories ) {
            doc.addField("category", cat);
        }
    }
    server.add(doc);

给出:

module Stream

import Classes.Verified

%default total

codata MyStream a = MkStream a (MyStream a)

mapStream : (a -> b) -> MyStream a -> MyStream b
mapStream f (MkStream a s) = MkStream (f a) (mapStream f s)

streamFunctorComposition : (s : MyStream a) -> (f : a -> b) -> (g : b -> c) -> mapStream (\x => g (f x)) s = mapStream g (mapStream f s)
streamFunctorComposition (MkStream x y) f g =
  let inductiveHypothesis = streamFunctorComposition y f g
  in ?streamFunctorCompositionStepCase

---------- Proofs ----------
streamFunctorCompositionStepCase = proof
  intros
  rewrite inductiveHypothesis
  trivial

有没有一个技巧可以证明有关codata的仿函数法则也可以通过整体检查器?

1 个答案:

答案 0 :(得分:7)

我能够从Daniel Peebles (copumpkin)获得IRC的一些帮助,他们解释说能够使用命题平等而不是通常允许的东西。他指出可以定义自定义等价关系,就像Agda为Data.Stream定义的那样:

data _≈_ {A} : Stream A → Stream A → Set where
  _∷_ : ∀ {x y xs ys}
        (x≡ : x ≡ y) (xs≈ : ∞ (♭ xs ≈ ♭ ys)) → x ∷ xs ≈ y ∷ ys

我能够将这个定义直接翻译成Idris:

module MyStream

%default total

codata MyStream a = MkStream a (MyStream a)

infixl 9 =#=

data (=#=) : MyStream a -> MyStream a -> Type where
  (::) : a = b -> Inf (as =#= bs) -> MkStream a as =#= MkStream b bs

mapStream : (a -> b) -> MyStream a -> MyStream b
mapStream f (MkStream a s) = MkStream (f a) (mapStream f s)

streamFunctorComposition : (s : MyStream a) -> (f : a -> b) -> (g : b -> c) -> mapStream (\x => g (f x)) s =#= mapStream g (mapStream f s)
streamFunctorComposition (MkStream x y) f g =
  Refl :: streamFunctorComposition y f g

这很容易通过整体检查,因为我们现在正在进行简单的共同推理。

这个事实有点令人失望,因为它似乎意味着我们无法为我们的流类型定义VerifiedFunctor

丹尼尔还指出,观察类型理论确实允许命题平等超过codata,这是值得研究的。