7

I was just wondering if it is possible to derive induction for the church-encoded Nat type on Idris, Agda, Coq and similar. Notice this is a different issue from doing it on CoC (which is known to be impossible) because we have much more expressivity on those (we're able to, for example, extract the second element of Sigma).

Here is a poor proof sketch on Idris (had a lot of syntax issues):

CN : Type
CN = (t : Type) -> t -> (t -> t) -> t

CS : CN -> CN
CS n t z s = s (n t z s)

CZ : CN
CZ t z s = z

ind :
  (p : CN -> Type) ->
  (z : p CZ) ->
  (s : (n : CN) -> p n -> p (CS n)) ->
  (n : CN) ->
  p n

ind p z s n =
  let base_case  = the (x : CN ** p x) (CZ ** z) 
      step_case  = the ((x : CN ** p x) -> (y : CN ** p y)) (\ (n ** pf) => (CS n ** s n pf))
      result     = the (x : CN ** p x) (n (x : CN ** p x) base_case step_case)
      fst_result = fst result
      snd_result = snd result
      fst_is_n   = the (fst_result = n) ?fst_is_n
  in  ?wat

I'm doing it by building a Sigma type starting from CZ ** z all way up to CS (CS ... CZ) ** s (s ... z). Problem is that, while I know the first element of it will be equal to n, I'm not sure how to prove it.

MaiaVictor
  • 51,090
  • 44
  • 144
  • 286

3 Answers3

10

Here's a related question I asked about homotopy type theory. I am also a little out my depth here, so take all this with a grain of salt.

I've proved that CN is isomorphic to Nat iff the free theorm for CN holds. Furthermore, it's known that there are no free theorems under the law of excluded middle (in HoTT). I.e. with LEM, you could could define CNs such as

foo : CN
foo T z s = if T is Bool then not z else z

which is not a proper church natural and would not be covered by the induction principle. Because excluded middle and HoTT are consistent with the type theories you are asking about (as far as I know), it follows that there will not be a proof of ind.

luqui
  • 59,485
  • 12
  • 145
  • 204
  • 1
    Ah, nice result. Do you think it could extend, at least in one direction. I mean, given UA and parametricity, would you expect that it is possible to prove that any (?) inductive type is isomorphic to its Church encoding? – chi Jan 13 '18 at 13:25
  • 1
    @chi I suspect that the technique extends to at least the regular inductive types (though proving it in general seems like it would be quite challenging due to working with generated free theorems). – luqui Jan 13 '18 at 17:12
  • Let me be sure I understand. You claim that `CN` is isomorphic to `Nat` iff the free theorem for `CN` holds. We know that the free theorem for `CN` holds on CoC, but not on Coq/Agda. Thus, one can't derive induction for `CN` on CoC, but one could assume induction for `CN` (without LEM) without breaking consistency. Is that correct? – MaiaVictor Jan 23 '19 at 18:07
  • 1
    @MaiaVictor, sounds right to me, though I would say "we 'know' that the free theorem for CN holds on CoC, but it is not provable from within the theory". (Here "knowing that it holds" is to be taken with all the usual caveats of proof theory) – luqui Jan 23 '19 at 19:01
8

It is known not to be provable because there are models of the calculus of constructions where the impredicative encoding of the natural numbers is not initial (i.e. doesn't satisfy induction). It does follow from relational parametricity as Phil Wadler has shown long time ago. Hence combining Wadler with internal relational parametricity ala Moulin and Bernardy may do the trick.

  • I'm not sure I understand exactly what you mean. If there are models of CoC where the impredicative encoding of Nat isn't initial, then that means assuming induction for it would lead to an inconsistency. But then you claim induction follows from relational parametricity, which holds on CoC... then, it shouldn't lead to an inconsistency. I think I'm misunderstanding your point because it seems contradictory. – MaiaVictor Jan 23 '19 at 18:04
  • @MaiaVictor Parametricity of CoC (with no extra axioms) is a meta-theoretical property, rather than an internal theorem. Adding axioms (such as LEM) can make parametricity fail. – Potato44 Mar 03 '19 at 08:37
4

I think there is no formal proof that it's impossible, but generally expected that it can't be done. See e.g. the introduction to this paper by Aaron Stump.

  • 2
    But as far as I understand, Aaron debates about this impossibility on the context of CoC, i.e., a language without inductive types (**only** lambda-encoded value). Idris and similar have those, so it seemed natural to wonder if having access to inductive types would make proving induction for church-encoded counterparts possible. – MaiaVictor Jan 13 '18 at 07:49