Jekyll2021-11-28T07:31:01+00:00http://park-sewon.github.io//feed.xmlSewon’s BlogDo you know Heung-min Son?rewriting is induction2019-05-01T10:00:00+00:002019-05-01T10:00:00+00:00http://park-sewon.github.io//type/theory/2019/05/01/rewrite-is-induction<p>When you have a type <em>T</em> and two elements <em>x, y : T</em> of the type, you can make a type, so called, equality (identity) type <em>eq T x y</em>. If you find a term of the type <em>t : eq T x y</em>, the term <em>t</em> will be an evidence that the two elements <em>x</em> and <em>y</em> are equal (hence called to be propositional equality). Equality is an inductive type with a constructor that gives a single rule making the evidence called reflexivity.</p>
<p>Being an inductive type, you can define your own equality type. In Coq:</p>
<pre><code class="language-Coq">Inductive myeq {T : Type} : T -> T -> Type :=
myrefl : forall x, myrefl x : myeq x x.
</code></pre>
<p><em>myeq</em> is an inductive type that <em>depends</em> on a given type $T$ and two elements of the type. Its constructor is called <em>myrefl</em> that <em>depends</em> on the given type <em>T</em> and an element of it <em>x : T</em>. Hence, when such arguments are given, <em>myrefl</em> is used to construct the term <em>myrefl T x : myeq T x</em>.</p>
<p>For example, <em>myeq nat 42 42</em> is the type which represents the proposition <em>42 = 42</em> of natural numbers and a proof of the proposition is <em>myrefl nat 42 : myeq nat 42 42</em>.</p>
<p>Being an inductive type, <em>myeq</em> comes with an induction principle. The below is what Coq says for the type <em>myeq</em>:</p>
<pre><code class="language-Coq">myeq_ind
: forall (T : Type) (P : forall t t0 : T, myeq t t0 -> Prop),
(forall x : T, P x x (myrefl x)) -> forall (y y0 : T) (m : myeq y y0), P y y0 m
</code></pre>
<p>It roughly says that given any predicate on triples <em>(x, y, t)</em> where <em>x, y : T</em> and <em>t</em> is a proof that <em>x</em> and <em>y</em> are equal (<em>myeq x y</em> holds), in order to prove that the predicate is satisfied for all such triples, it suffices to only prove the case where the predicate acts on triples in form $(x, x, myrefl x)$.</p>
<p>If it isn’t clear why this is the induction principle for our equality, let us recall what the induction principle for natural numbers says. <em>nat</em> is an inductive type with two constructors <em>zero : nat</em> and <em>succ : nat -> nat</em>. The induction principle says that to prove a predicate <em>P</em> on all <em>x : nat</em>, it suffices only to prove the case where <em>x</em> is <em>zero</em> and the case where <em>x</em> is <em>succ n</em> assuming <em>P n</em> for any <em>n</em>.</p>
<p>Now, let us see how the induction principle works for rewriting. Rewriting for a predicate is in this form</p>
<pre><code class="language-Coq">forall (T : Type) (Q : T -> Prop) (x y : T) , myeq x y -> Q x -> Q y
</code></pre>
<p>and we want to prove it using the induction principle for <em>myeq</em>. Assuming a type <em>T : Type</em> and a predicate on it <em>Q : T -> Prop</em>, it is to prove <em>R := forall x y : T, myeq x y -> (Q x -> Q y)</em> where <em>(Q x -> Q y)</em> is a proposition. Hence, the <em>R</em> is a predicate on triples <em>(x, y, t)</em> where <em>t : myeq x y</em>. The induction principle on <em>myeq</em> says that in order to prove the predicate on such triples, it suffices to prove only the case where the predicate acts on <em>(x, x, myrefl x)</em> which is to prove <em>Q x -> Q x</em>.</p>
<p>In Coq, you can also check this either by</p>
<pre><code class="language-Coq">fun (T : Type) (Q : T -> Prop) (x y : T) (X : myeq x y) (H : Q x) =>
myeq_ind T (fun (x0 y0 : T) (_ : myeq x0 y0) => Q x0 -> Q y0) (fun (x0 : T) (H0 : Q x0) => H0) x y X H
: forall (T : Type) (Q : T -> Prop) (x y : T), myeq x y -> Q x -> Q y
</code></pre>
<p>or</p>
<pre><code class="language-Coq">Lemma myrewrite : forall (T:Type) (Q : T -> Prop) (x y : T), myeq x y -> Q x -> Q y.
Proof.
intros T Q x y t X.
induction t.
exact X.
Qed.
</code></pre>
<p>The <a href="https://homotopytypetheory.org/book/">HoTT</a> book has a great explanation about identity types.</p>When you have a type T and two elements x, y : T of the type, you can make a type, so called, equality (identity) type eq T x y. If you find a term of the type t : eq T x y, the term t will be an evidence that the two elements x and y are equal (hence called to be propositional equality). Equality is an inductive type with a constructor that gives a single rule making the evidence called reflexivity.Questions in Multivaluedness2018-08-05T06:10:00+00:002018-08-05T06:10:00+00:00http://park-sewon.github.io//multivalue/2018/08/05/multivaluedness<p>Working on Real Computation, it is unavoidable to face multivaluedness.
Considering the fact that real numbers have undecidable equality,
(speaking in terms of Bishop’s, it’s LPO),
the following simple algorithm is not computable:</p>
<pre><code class="language-C++">if(x > 0) ... else ...
</code></pre>
<p>if the variable x represents a real number.
Instead, with some tolerance factor \(e\),<br />
<a href="http://irram.uni-trier.de/">iRRAM</a> supports such syntax:</p>
<pre><code class="language-C++">if(choose(x > - e, e > x) == 1) ... else ...
</code></pre>
<p>The iRRAM <strong>choose</strong> function returns the index whose corresponding expression gets evaluated to be <em>True</em>;
it can be implemented via parallel evaluation of the both expressions,
returning the index of whose expression happens to hold first.
Hence, even if one expression leads to Bottom,
e.g., when x = - e , the <strong>choose</strong> function works!
But, what does happen if both expressions happen to be truth?</p>
<p>Obviously, the one which holds first would be returned.
If both are evaluated to be true at the same time,
we can make some protocol which to return.
This is the matter of the fact of implementation of the language;
we can design the language to evaluate the second expression two steps whereas
the first expression one step.
Therefore, an abstract semantic of the <strong>choose</strong> function should be a set function whose output is a set of all indexes
whose corresponding expressions hold;
in abstract semantics, we do not want to talk about how the choose function and
real number representations are implemented.</p>
<p>One common mistake in first understanding this multivaluedness is that the
nondeterminism is an illusion which is only the matter of implementation;
some think that when we fix a real number \(x\),
the nondeterminism does not occur.
However, this is not the case!
Let us fix \(x=0\) and let \(e=0.1\). Let us consider two representations of the \(x\):</p>
<ol>
<li>
\[x = [0,1] :: [0,0.5] :: [0,0.25] :: \cdots\]
</li>
<li>
\[x = [-1,0] :: [-0.5,0] :: [-0.25,0] :: \cdots\]
</li>
</ol>
<p>The two sequences of closed intervals are valid names for \(0\) as they both converges to \(0\).
However, we can see that
<strong><em>choose(x > - e, e > x) == 1</em></strong> is <em>True</em> for the case 1 and <em>False</em> for the case 2.
Even if we fix a real number \(x\) and the way of implementing the <strong>choose</strong> function, multivaluedness happens.</p>
<p>Now, let us take this into the view of representation.
With \(N\) denoting a set of natural numbers, \(B := N^N\) is a Baire space.
Let \(n_A : B \rightharpoonup A\) be a surjective partial function.
If \(n_A(x) = a\) we say \(x\) realizes \(a\) and put \(x \Vdash_A a\).
Similarly, for a function \(f : A \to C\), if \(\tau : B \to B\) exists such that
\(\forall a b. b \Vdash_A a \to \tau(b) \Vdash_B f(a)\)
we call that \(\tau\) tracks the function \(f\).</p>
<p>Now, let us think in the opposite direction. Consider we have a
function \(\tau : B \to B\). What does the function \(\tau\) mean?
We can notice that this is just a boring function that receives an infinite
sequence of natural numbers and just keep printing endless sequence of natural numbers.
In order to give a meaning of the boring function, we can try to give meanings to its domain and codomain.
Suppose we let \(n_A\) and \(n_C\) be the representations of its domain and codomain.</p>
<p>Since \(n_A\) does not need to be injective, for an element \(x \in A\),
there can be several different names \(n^{-1}_A(\{x\})\); see that a real number is such a case. If \(n_C(\tau(n^{-1}_A(\{x\})))\) is a singleton for all \(x\), then we can define the meaning of \(\tau\);
let \(\chi : P(A) \rightharpoonup A\) be a trivial choice function from singleton subsets of \(A\). Then, \(Meaning(\tau, n_A, n_C) := x \mapsto \chi(n_C(\tau(n^{-1}_A(\{x\}))))\).</p>
<p>If the set \(n_C(\tau(n^{-1}_A(\{x\})))\) is not a singleton, which is the case of the displayed simple iRRAM program, then, its meaning becomes the multivalued map which can be understood as a set valued function:
\(Meaning(\tau, n_A, n_C) : A \to P(C) := x \mapsto n_C(\tau(n^{-1}_A(\{x\}))).\)
It is a little unsatisfactory for me that its meaning is a function to \(P(B)\)… What we compute with the \(\tau, n_A, n_C\) given \(x \Vdash_A n_A(x)\) is an element of \(\tau(x) \Vdash_C n_C(\tau(x))\) not a set of elements.</p>
<p>See more:</p>
<p>[1] <strong>iRRAM</strong> is a C++ library which enables the computation of real numbers. See the link for the further information, <a href="http://irram.uni-trier.de/">Click</a></p>
<p>[2] For the further information and studying materials for real computation via computable analysis, see <strong>Weihrauch, Klaus. Computable analysis: an introduction. Springer Science & Business Media, 2012.</strong></p>
<p>[3] The notions of realizability/functions in baire space tracking, can be studied in
<strong>Bauer, Andrej. “Realizability as the connection between computable and constructive mathematics.” Proceedings of CCA. 2005.</strong></p>Working on Real Computation, it is unavoidable to face multivaluedness. Considering the fact that real numbers have undecidable equality, (speaking in terms of Bishop’s, it’s LPO), the following simple algorithm is not computable: if(x > 0) ... else ... if the variable x represents a real number. Instead, with some tolerance factor \(e\), iRRAM supports such syntax: if(choose(x > - e, e > x) == 1) ... else ... The iRRAM choose function returns the index whose corresponding expression gets evaluated to be True; it can be implemented via parallel evaluation of the both expressions, returning the index of whose expression happens to hold first. Hence, even if one expression leads to Bottom, e.g., when x = - e , the choose function works! But, what does happen if both expressions happen to be truth?Proof as Object 02018-07-11T06:10:00+00:002018-07-11T06:10:00+00:00http://park-sewon.github.io//type/theory/2018/07/11/proof-1<p>Studying something related to Logic, I got wondered what a proof is.
Learning Set Theory as the only foundation of Mathematics in high school or in college,
I think it is a little natural to get confused.
in Set theory, mathematical objects and logic are separated;
we first define mathematical objects using some set of axioms then
define a deductive system on top of them.</p>
<p>However, it seems unnatural to have the two separate layers;
we can find ourselves often deal a proof of a certain lemma
as some kind of object.
Especially when we design an algorithm out of a proof,
we certainly do deal the proof as an object that yields a function.</p>
<p>Program extraction is another field of study that requires much attention.
However, in some sense, we all do program extraction; I think many of us
have an experience of writing a program out of a mathematical proof.
Let us consider a statement \(L\) and two proofs \(a, b\) of \(L\).
The point is, seeing \(a\) and \(b\) as objects, whether we can say the proofs are different. Suppose a program designed from \(a\) takes \(n^3\) and a program designed from \(b\) takes \(exp(n)\) (whatever the \(n\) is). Then, why can’t we say the two proofs are different? If a proof is not an object, how can we say that two proofs are different?</p>
<p>Type theory can be thought as an alternative foundation of mathematics that merges the separation: objects and proofs. Although there are different aspects of seeing Type Theory; e.g., a foundation of constructive mathematics.
I think the aspect of ‘proof as object’ is the most ‘touching’ one.</p>
<p>There are many things to talk about in Type Theory.
However, to be focused on the spirit of ‘proof as object’, let us see a
simple example.
Suppose we have two objects \(a\) and \(b\).
We want to argue whether the two objects are the same.
In Set Theory, \(a\) and \(b\) are some objects that may live in some set \(S\).
The proof of the statement \(a = b\) will be constructed following some rules in a deductive system which live outside of the object construction.</p>
<p>In Type Theory, given two elements \(a, b : T\) (it says \(a\) and \(b\) of type \(T\)), the statement
\(a = b\) is also a type.
We call it an equality (or identity) type of \(T\) and \(a, b\).
A proof of \(a = b\) is an element of the equality type. Hence,
the proof \(p : a = b\)
itself is a mathematical object just like \(a\) and \(b\) are.
Hence, the statement reads, ‘given two elements \(a, b\) of type \(T\), can you find an element of type \(a = b\)?’</p>
<p>Seeing a proof \(p : a = b\) as an object, we can imagine the following:
given \(p, q : a = b\), arguing \(p = q\) is again a type. Yes, we can have \(r, s : p = q\) and again argue whether \(r = s\) and so on…
This observation leads the attention to Homotopy Type Theory, which is not the topic here; however, is surely interesting.</p>
<p>The equality type is a fundamental type former in Type Theory; given a type and two elements of it, it returns a type. Similarly, there are other type formers which enable us to have counterparts of product, co-product, existential and universal quantifiers. Maybe introducing \(\Sigma\) and \(\Pi\) dependent types in Martin-Löf dependent type theory would be an interesting topic for the next posting?</p>Studying something related to Logic, I got wondered what a proof is. Learning Set Theory as the only foundation of Mathematics in high school or in college, I think it is a little natural to get confused. in Set theory, mathematical objects and logic are separated; we first define mathematical objects using some set of axioms then define a deductive system on top of them.Welcome to my blog2018-05-30T08:10:00+00:002018-05-30T08:10:00+00:00http://park-sewon.github.io//random/things/2018/05/30/welcome-to-my-blog<p>Dear visitors,
I am very pleased to meet you.
Though I have no idea what to post here,
I hope to have productive and fun conversation in this blog with you!</p>Dear visitors, I am very pleased to meet you. Though I have no idea what to post here, I hope to have productive and fun conversation in this blog with you!