
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>niche computing science &#187; Program Inversion</title>
	<atom:link href="http://www.iis.sinica.edu.tw/~scm/tag/program-inversion/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.iis.sinica.edu.tw/~scm</link>
	<description>Research Blog of 穆信成 Shin-Cheng Mu</description>
	<lastBuildDate>Mon, 21 Nov 2011 11:53:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>A grammar-based approach to invertible programs</title>
		<link>http://www.iis.sinica.edu.tw/~scm/2010/a-grammar-based-approach-to-invertible-programs/</link>
		<comments>http://www.iis.sinica.edu.tw/~scm/2010/a-grammar-based-approach-to-invertible-programs/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 06:19:29 +0000</pubDate>
		<dc:creator>Shin</dc:creator>
				<category><![CDATA[Conference]]></category>
		<category><![CDATA[Publication]]></category>
		<category><![CDATA[Program Inversion]]></category>

		<guid isPermaLink="false">http://www.iis.sinica.edu.tw/~scm/2010/a-grammar-based-approach-to-invertible-programs/</guid>
		<description><![CDATA[<a href="http://www.ipl.t.u-tokyo.ac.jp/~kztk/">Kazutaka Matsuda</a>, Shin-Cheng Mu, <a href="http://research.nii.ac.jp/~hu/">Zhenjiang Hu</a>, and <a href="http://www.ipl.t.u-tokyo.ac.jp/~takeichi/">Masato Takeichi</a>. A grammar-based approach to invertible programs. In <i>19th European Symposium on Programming (ESOP 2010)</i>, LNCS 6012, pp 448-467, March 2010.  
[<a href="http://www.iis.sinica.edu.tw/~scm/pub/esop10.pdf">PDF</a>]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ipl.t.u-tokyo.ac.jp/~kztk/">Kazutaka Matsuda</a>, Shin-Cheng Mu, <a href="http://research.nii.ac.jp/~hu/">Zhenjiang Hu</a>, and <a href="http://www.ipl.t.u-tokyo.ac.jp/~takeichi/">Masato Takeichi</a>. In <i>19th European Symposium on Programming (ESOP 2010)</i>, LNCS 6012, pp 448-467, March 2010. [<a href="http://www.iis.sinica.edu.tw/~scm/pub/esop10.pdf">PDF</a>]</p>
<p>Program inversion has many applications such as in the implementation of serialization/deserialization and in providing support for redo/undo, and has been studied by many researchers.  However, little attention has been paid to two problems: how to characterize programs that are easy or hard to invert and whether, for each class of programs, efficient inverses can be obtained.  In this paper, we propose an inversion framework that we call <i>grammar-based inversion</i>, where a program is associated with an unambiguous grammar describing the range of the program.  The complexity of the grammar indicates how hard it is to invert the program, while the complexity is related to how efficient an inverse can be obtained.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iis.sinica.edu.tw/~scm/2010/a-grammar-based-approach-to-invertible-programs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>No Inverses for Injective but Non-Surjective Functions?</title>
		<link>http://www.iis.sinica.edu.tw/~scm/2009/no-inverses-for-injective-but-non-surjective-functions/</link>
		<comments>http://www.iis.sinica.edu.tw/~scm/2009/no-inverses-for-injective-but-non-surjective-functions/#comments</comments>
		<pubDate>Mon, 11 May 2009 11:22:39 +0000</pubDate>
		<dc:creator>Shin</dc:creator>
				<category><![CDATA[Research Blog]]></category>
		<category><![CDATA[Agda]]></category>
		<category><![CDATA[Dependent Type]]></category>
		<category><![CDATA[Program Inversion]]></category>

		<guid isPermaLink="false">http://www.iis.sinica.edu.tw/~scm/?p=190</guid>
		<description><![CDATA["I cannot prove that if a function is injective, it has an inverse," <a href="http://www.ipl.t.u-tokyo.ac.jp/~hhashimoto/">Hideki Hashimoto</a> posed this question to me. Is it possible at all?]]></description>
			<content:encoded><![CDATA[<p>&#8220;I cannot prove that if a function is injective, it has an inverse,&#8221; <a href="http://www.ipl.t.u-tokyo.ac.jp/~hhashimoto/">Hideki Hashimoto</a> posed this question to me a while ago. It turned out that this was not the property he really wanted, but it got me into thinking: is it possible at all?</p>
<h3>Preliminaries</h3>
<p>Let us start with some basic definitions. A relation from A to B is denoted by the wavy arrow:</p>
<pre><code>_↝_ : Set → Set → Set1
A ↝ B = A → B → Set</code></pre>
<p>Given a relation <code>R : A ↝ B</code> we can always take its converse <code>R ˘ : B ↝ A</code>, and a function can be lifted to a relation by <code>fun</code>:</p>
<pre><code>_˘ : ∀ {A B} → (A ↝ B) → (B ↝ A)
(R ˘) b a = R a b 

fun : ∀ {A B} → (A → B) → (A ↝ B)
fun f a b = f a ≡ b</code></pre>
<p>A relation <code>R : A ↝ B</code> is <em>simple</em> if it does not map one input to multiple outputs. It is <em>entire</em> if everything in <code>A</code> is mapped to something in <code>B</code> &#8212; a more familiar word may be &#8220;total&#8221;.</p>
<pre><code>simple : ∀ {A B} → (A ↝ B) → Set
simple R = ∀ {a b₁ b₂} →  R a b₁ → R a b₂ → b₁ ≡ b₂ 

entire : ∀ {A B} → (A ↝ B) → Set
entire R = ∀ a → ∃ (λ b → R a b)</code></pre>
<p>A function is a relation that is simple and entire. Indeed, one can show that <code>fun f</code> is simple and entire for every <code>f</code>. Injectivity and surjectivity are similar notions defined for converse of <code>R</code>:</p>
<pre><code>injective : ∀ {A B} → (A ↝ B) → Set
injective R = ∀ {a₁ a₂ b} → R a₁ b → R a₂ b → a₁ ≡ a₂

surjective : ∀ {A B} → (A ↝ B) → Set
surjective R = ∀ b → ∃ (λ a → R a b)</code></pre>
<p>The (constructive variant of the) axiom of choice states that an entire relation <code>A ↝ B </code>can be refined to a function <code>A → B</code>:</p>
<pre><code>ac : ∀ {A B} → (R : A ↝ B) →
         (∀ a → ∃ (λ b → R a b)) → ∃ {A → B} (λ f → ∀ a → R a (f a))
ac R R-entire = ((λ a → proj₁ (R-entire a)) , λ a → proj₂ (R-entire a))</code></pre>
<p>See <a href="http://www.math.vanderbilt.edu/~schectex/ccc/choice.html">the axiom of choice homepage</a>, or the <a href="http://plato.stanford.edu/entries/axiom-choice/">Stanford Encyclopedia of Philosophy</a> for more information on this axiom.</p>
<h3>Inverting Injective and Surjective Functions</h3>
<p>Now, let us restate Hashimoto san&#8217;s challenge:</p>
<blockquote><p> Let <code>fun f : A → B</code> be injective. Prove that <code>f</code> has a left inverse. That is, some  <code>f⁻¹</code> such that <code>f⁻¹ (f a) = a</code> forall <code>a</code>.
</p></blockquote>
<p>It turned out that he forgot a condition: <code>f</code> is also surjective. If <code>f</code> is also (provably) surjective, one can pick some <code>g ⊆ f˘</code> using the axiom of choice (since <code>f</code> is surjective if and only if <code>f˘</code> is total) and further prove that <code>g ∘ f = id</code> using injectivity:</p>
<pre><code>inv-sur : ∀ {A B} → (f : A → B) →
               injective (fun f) → surjective (fun f) →
                  ∃ {B → A} (λ f⁻¹ → (∀ a → f⁻¹ (f a) ≡ a))
inv-sur f f-inj f-sur with ac ((fun f) ˘) f-sur
... | (g , fgb≡b) =  (g , λ a → f-inj {g (f a)} {a} {f a} (fgb≡b (f a)) refl)</code></pre>
<p>Like the proof of the constructive axiom of choice, the proof above does not really do much. The proof of surjectivity of <code>f</code> has already provided, for every <code>b : B</code>, an <code>a : A</code> such that <code>f a ≡ b</code>. So we simply let <code>f⁻¹</code> return that <code>a</code>.</p>
<p>Can we lift the restriction that <code>f</code> must be surjective? That is, can this be proved?</p>
<pre><code>inv : ∀ {A B} → (f : A → B) → injective (fun f) →
                  ∃ {B → A} (λ f⁻¹ → (∀ a → f⁻¹ (f a) ≡ a))</code></pre>
<p>To make the scenario clear: we have a (total) function <code>f : A → B</code> that is injective but not necessarily surjective. The set <code>B</code> could be &#8220;larger&#8221; than <code>A</code> in the sense that there could be some elements <code>b : B</code> for which no <code>f a</code> equals <code>b</code> &#8212; that is, <code>B</code> may not be &#8220;fully covered.&#8221; Can we construct <code>f⁻¹ : B → A</code> such that <code>f⁻¹ (f a) ≡ a</code> for all <code>a : A</code>?</p>
<p>At the first glance it did not look like something terribly difficult to do. Given <code>b</code>, if it equals some <code>f a</code>, let <code>f⁻¹</code> simply return that <code>a</code>. Otherwise <code>f⁻¹</code> could just map <code>b</code> to any element in <code>A</code>, since this <code>b</code> is not used in any invocation of <code>f⁻¹ (f a)</code> anyway. It should be possible as long as <code>A</code> is not empty, right?</p>
<p>I tried to construct this <code>f⁻¹</code> but could not help noticing something funny going on. It turns out that had this function existed, we could, <a href="http://www.iis.sinica.edu.tw/~scm/2009/proof-irrelevance-extensional-equality-and-the-excluded-middle/">again</a>, prove the law of excluded middle. That is, for any predicate <code>P : B → Set</code> and any <code>b : B</code>, there would be a decision procedure telling us whether <code>P b</code> is true or not.</p>
<p>Provided that we assume proof irrelevance, that is.</p>
<h3>Excluded Middle, Again</h3>
<p>Here we go. Let <code>B</code> be some type having decidable equality. That is, there exists some <code>eqB</code>:</p>
<pre><code>eqB : (b₁ b₂ : B) → (b₁ ≡ b₂) ⊎ (¬ (b₁ ≡ b₂))</code></pre>
<p>where <code>_⊎_</code> is disjoint sum. </p>
<p>Now take some predicate <code>P : B → Set</code>. Let <code>A</code> be defined by:</p>
<pre><code>A : (B → Set) → Set
A P = Σ B (λ b → P b)</code></pre>
<p>That is, <code>A P</code> is the subset of <code>B</code> for which <code>P</code> holds. Each element of <code>A P</code> is a pair <code>(b, Pb)</code> where <code>Pb</code> is a proof of <code>P b</code>. </p>
<p>Finally, take </p>
<pre><code>f : ∀ {P} → A P → B
f = proj₁</code></pre>
<p>Thus <code>f (b, Pb) = b</code>.</p>
<p>The function <code>f</code> is injective <em>if we assume proof irrelevance</em>. That is, if <code>f (b, Pb) = b</code> and<code> f (b', Pb') = b</code>, we must have <code>b = b'</code> and (due to proof irrelevance) <code>Pb = Pb'</code>, and therefore <code>(b, Pb) = (b', Pb')</code>. Indeed, if we postulate proof irrelevance:</p>
<pre><code>postulate irr : (P : B → Set) → ∀ {b} → (p₁ : P b) → (p₂ : P b) → p₁ ≡ p₂</code></pre>
<p>We can construct a proof that <code>f</code> is injective:</p>
<pre><code>f-inj : ∀ {P} → injective (fun (f {P}))
f-inj {P} {(.b , Pb₁)} {(.b , Pb₂)} {b} refl refl = cong (λ p → (b , p)) (irr P Pb₁ Pb₂)</code></pre>
<p>Assume that we have proved <code>inv</code>. We can now apply <code>inv</code> and obtain some <code>f⁻¹</code>, the left inverse of <code>f</code>.</p>
<p>However, with this particular choice of <code>A</code>, <code>f</code>, and <code>f⁻¹</code>, we can construct a deciding procedure for <code>P</code>. That is, for any <code>P</code> and <code>b</code>, we can determine <code>P b</code> holds or not:</p>
<pre><code>em : {P : B → Set} → ∀ b → P b ⊎ ¬ (P b)</code></pre>
<p>This is how <code>em</code> works. Given some <code>b</code>, let&#8217;s apply <code>f⁻¹</code> to <code>b</code>. The result is a pair <code>(b', Pb')</code>. Let&#8217;s compare <code>b</code> and <code>b'</code> using <code>eqB</code>:</p>
<pre><code>em {P} b with inv f (f-inj {P})
...      | (f⁻¹ , f⁻¹fa≡a) with inspect (f⁻¹ b)
...                        | (b' , Pb') with-≡ _          with eqB b b'</code></pre>
<p>If <code>b ≡ b'</code>, <code>Pb'</code> is a proof of <code>P b'</code> and also a proof of <code>P b</code>. Let us just return it (after some type casting):</p>
<pre><code>em {P} b | (f⁻¹ , f⁻¹fa≡a) | (b' , Pb') with-≡ _          | inj₁ b≡b'  =
              inj₁ (subst P (sym b≡b') Pb')</code></pre>
<p>Consider the case that <code>b</code> does not equal <code>b'</code>. We want to show that <code>P b</code> is not true. That is, a proof of <code>P b</code> leads to contradiction. Assume we have a proof <code>Pb</code> of <code>P b</code>. Since <code>f (b , P b) ≡ b</code>, we have <code>f⁻¹ b ≡ (b , Pb)</code>:</p>
<pre><code>em {P} b | (f⁻¹ , f⁻¹fa≡a) | (b' , Pb') with-≡ b'Pb'≡f⁻¹b | inj₂ ¬b≡b' =
   inj₂ (λ Pb →
           let f⁻¹b≡bPb : f⁻¹ b ≡ (b , Pb)
               f⁻¹b≡bPb = f⁻¹fa≡a (b , Pb)</code></pre>
<p>The assumption says that <code>f⁻¹ b = (b' , Pb')</code>. By transitivity we have <code>(b , Pb) ≡ (b' , Pb')</code>. </p>
<pre><code>               bPb≡b'Pb' : (b , Pb) ≡ (b' , Pb')
               bPb≡b'Pb' = sym (trans b'Pb'≡f⁻¹b f⁻¹b≡bPb)</code></pre>
<p>But if we take the first component of both sides, we get <code>b ≡ b'</code>. That contradicts our assumption that <code>b</code> does not equal <code>b'</code>:</p>
<pre><code>               b≡b' : b ≡ b'
               b≡b' = cong proj₁ bPb≡b'Pb'
           in ¬b≡b' b≡b')</code></pre>
<p>which completes the proof.</p>
<p>In retrospect, <code>f⁻¹</code> cannot exist because for it to work, it has to magically know whether <code>b</code> is in the range of <code>f</code>, that is, whether <code>P b</code> is true or not.</p>
<h3>Nakano&#8217;s Challenge</h3>
<p>When I talked about this to <a href="http://millsmess.cs.uec.ac.jp/~ksk/en/">Keisuke Nakano</a> he posed me another related challenge. Set-theoretically, we understand that if there exists an injective function <code>f : A → B</code> and another injective function <code>g : B → A</code>, the sets <code>A</code> and <code>B</code> are of the same cardinality and there ought to be a bijection <code>A → B</code>. Can we construct this bijection? That is, can we prove this theorem?</p>
<pre><code>nakano : {A B : Set} →
           (f : A → B) → injective (fun f) →
           (g : B → A) → injective (fun g) →
             ∃ {A → B} (λ h → injective (fun h) × surjective (fun h))</code></pre>
<p>I do not yet have a solution. Any one wanna give it a try?</p>
<h3>Programs</h3>
<ul>
<li><a href="http://www.iis.sinica.edu.tw/~scm/sw/2009/Hashimoto.agda">Hashimoto.agda</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.iis.sinica.edu.tw/~scm/2009/no-inverses-for-injective-but-non-surjective-functions/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>A programmable editor for developing structured documents based on bidirectional transformations</title>
		<link>http://www.iis.sinica.edu.tw/~scm/2008/a-programmable-editor-for-developing-structured-documents-based-on-bidirectional-transformations-2/</link>
		<comments>http://www.iis.sinica.edu.tw/~scm/2008/a-programmable-editor-for-developing-structured-documents-based-on-bidirectional-transformations-2/#comments</comments>
		<pubDate>Thu, 29 May 2008 02:17:53 +0000</pubDate>
		<dc:creator>Shin</dc:creator>
				<category><![CDATA[Journal]]></category>
		<category><![CDATA[Bidirectional Updating]]></category>
		<category><![CDATA[Program Inversion]]></category>

		<guid isPermaLink="false">http://www.iis.sinica.edu.tw/~scm/?p=23</guid>
		<description><![CDATA[<a href="http://www.ipl.t.u-tokyo.ac.jp/~hu/">Z. Hu</a>, S-C. Mu and <a href="http://www.ipl.t.u-tokyo.ac.jp/~takeichi/">M. Takeichi</a>, A programmable editor for developing structured documents based on bidirectional transformations. <i>Higher-Order and Symbolic Computation</i>, Vol 21(1-2), pp 89-118, May 2008.<br/>[<a href="http://www.iis.sinica.edu.tw/~scm/pub/hosc06.pdf">PDF</a>]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ipl.t.u-tokyo.ac.jp/~hu/">Z. Hu</a>, S-C. Mu and <a href="http://www.ipl.t.u-tokyo.ac.jp/~takeichi/">M. Takeichi</a>. <i>Higher-Order and Symbolic Computation</i>, Vol 21(1-2), pp 89-118, May 2008.<br/>[<a href="http://www.iis.sinica.edu.tw/~scm/pub/hosc06.pdf">PDF</a>]</p>
<p>This paper presents an application of bidirectional transformations to design and implementation of a novel editor supporting interactive refinement in the development of structured documents. The user performs a sequence of editing operations on the document view, and the editor automatically derives an efficient and reliable document source and a transformation that produces the document view. The editor is unique in its programmability, in the sense that transformation can be obtained through editing operations. The main tricks behind are the utilization of the view-updating technique developed in the database community, and a new bidirectional transformation language that can describe not only relationship between the document source and its  view, but also data dependency in the view.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iis.sinica.edu.tw/~scm/2008/a-programmable-editor-for-developing-structured-documents-based-on-bidirectional-transformations-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Constructing List Homomorphism from Left and Right Folds</title>
		<link>http://www.iis.sinica.edu.tw/~scm/2008/constructing-list-homomorphism/</link>
		<comments>http://www.iis.sinica.edu.tw/~scm/2008/constructing-list-homomorphism/#comments</comments>
		<pubDate>Sat, 09 Feb 2008 16:56:45 +0000</pubDate>
		<dc:creator>Shin</dc:creator>
				<category><![CDATA[Research Blog]]></category>
		<category><![CDATA[List Homomorphism]]></category>
		<category><![CDATA[Program Derivation]]></category>
		<category><![CDATA[Program Inversion]]></category>

		<guid isPermaLink="false">http://www.iis.sinica.edu.tw/~scm/2008/constructing-list-homomorphism-from-left-and-right-folds/</guid>
		<description><![CDATA[Back in 2003, my colleagues there were discussing about <a href="http://web.comlab.ox.ac.uk/oucl/work/jeremy.gibbons/publications/index.html#thirdht">the third homomorphism theorem</a> --- if a function <mi>f</mi> can be expressed both as a <mi>foldr</mi> and a <mi>foldl</mi>, there exists some associative binary operator <mi>⊚</mi> such that <mi>f</mi> can be computed from the middle. The aim was to automatically construct <mi>⊚</mi>.]]></description>
			<content:encoded><![CDATA[<p>Since <a href="http://joshkos.blogspot.com/2008/02/scm.html">Josh has already mentioned it</a>, I had better give it a full account.</p>
<p>Back in 2003 when I just started my postdoc in <a href="http://www.psdlab.org/e/index.html">PSD Lab</a> in University of Tokyo, my colleagues there were discussing about <a href="http://web.comlab.ox.ac.uk/oucl/work/jeremy.gibbons/publications/index.html#thirdht">the third homomorphism theorem</a>. The theorem says that if a function <mi>f</mi> can be expressed both as a <mi>foldr</mi> and a <mi>foldl</mi>:</p>
<blockquote><math>
f = foldr (≪) e<br />
f = foldl (≫) e<br />
</math>
</blockquote>
<p>there exists some associative binary operator <mi>⊚</mi> such that</p>
<blockquote><math>
  f [] = e<br />
  f [a] = a ≪ e = e ≫ a<br />
  f (xs ⧺ ys) = f xs ⊚ f ys<br />
</math>
</blockquote>
<p>Being a list homomorphism implies the potential of parallel computation.</p>
<p>The paper we studied was, of course, <a href="http://web.comlab.ox.ac.uk/oucl/work/jeremy.gibbons/publications/index.html#thirdht">The Thrid Homomorphism Theorem</a> by <a href="http://web.comlab.ox.ac.uk/oucl/work/jeremy.gibbons/">Jeremy</a>. The aim then was to automatically, or semi-automatically, derive <mi>⊚</mi>, given <mi>≪</mi>, <mi>≫</mi>, and <mi>e</mi>. The motivating examples include:</p>
<ul>
<li><mi>f = sum</mi>, where <mi>⊚</mi> can simply be <mi>+</mi>.</li>
<li><mi>f = sort</mi>, where <mi>⊚</mi> can be the function <mi>merge</mi> merging two sorted lists.</li>
<li><mi>f = scanr ⊛ e</mi>. While <mi>scanr</mi> appears to be an inherently sequential function, it is actually possible to compute <mi>f</mi> &#8220;from the middle&#8221;, provided that <mi>⊛</mi> is associative, if we take <mi>xs ⊚ (y : ys) = map (⊛y) xs ⧺ (y : ys)</mi>.</li>
</ul>
<p>Can we come up with a method to derive <mi>⊚</mi> for all these examples?</p>
<p>I myself was not particularly interested in automation. I was interested in the challenge for two reasons. Firstly, it appears that some kind of inverse function is needed. Secondly, when I looked at Jeremy&#8217;s proof, I felt there is a relational proof inside waiting to be discovered. So I tried.</p>
<h3>Setting the Stage</h3>
<p>For the ease of point-free calculation, we define alternatives of folds where the input is paired with the base-cases:</p>
<blockquote><math>
foldrp (≪) ([],a) = a<br />
foldrp (≪) (x:xs,a) = x ≪ foldrp (≪) (xs,a)<br />
foldlp (≫) (a,[]) = a<br />
foldlp (≫) (a, xs⧺[x]) = foldlp (≫) (a,xs) ≫ x<br />
</math>
</blockquote>
<p>The advantage is that we can shift a suffix or a prefix of the input list to the base case. That is:</p>
<blockquote><math>
foldr (≪) e (xs⧺ys) = foldrp≪ (xs, foldr≪ e ys)<br />
foldl (≫) e (xs⧺ys) = foldlp≪ (foldl ≪ e xs, ys)<br />
</math>
</blockquote>
<p>or, in point-free style:</p>
<blockquote><math>
foldr (≪) e . cat = foldrp (≪) . (id × foldr (≪) e)   <span style="float:right">(1)</span><br />
foldl (≫) e . cat = foldlp (≫) . (foldlp (≫)  e × id)  <span style="float:right">(2)</span><br />
</math>
</blockquote>
<p>where <mi>cat (xs,ys) = xs ⧺ ys</mi> and <mi>(f × g) (a,b) = (f a, g b)</mi>.</p>
<p>The key property, however, is one that was shown in (possibly among other literature) <a href="http://portal.acm.org/citation.cfm?id=248932">Algebra of Programming</a>: for a simple relation (i.e. a partial function) <mi>S</mi>, we have:</p>
<blockquote><math>
S . S° . S = S<br />
</math>
</blockquote>
<p>where <mi>°</mi> stands for relational converse (the relational concept of an &#8220;inverse function&#8221;).</p>
<p>Recall our aim: given <mi>f</mi>, look for <mi>⊚</mi> such that <mi>f xs ⊚ f ys = f (xs⧺ys)</mi>. It translates to point-free style as <mi>⊚ . (f × f) = f . cat</mi>.</p>
<h3>Proving the Theorem</h3>
<p>The third homomorphism theorem is a direct corollary of the following lemma:</p>
<blockquote><p>
Lemma 1: <mi>f = foldr (≪) e = f = foldl (≫) e</mi> implies that <mi>f</mi> is prefix and postfix insensitive. That is:</p>
<blockquote><math>f xs = f xs’ ∧ f ys = f ys’ ⇒ f (xs⧺ys) = f (xs’⧺ys’).</math>
</blockquote>
<p>In point-free style: <mi>f . cat . (f°. f × f°. f) = f . cat</mi>.
</p></blockquote>
<p>Once we have the lemma proved, the theorem follows by taking <mi>⊚ = f . cat . (f °× f °)</mi>. It has to be a (partial) function because <mi>⊚ . (f × f) = f . cat</mi> is a function. Futhermore, <mi>⊚</mi> is associative because <mi>cat</mi> is.</p>
<p>The proof of Lemma 1 is simply some applications of (1), (2), and <mi>S . S° . S = S</mi>:</p>
<blockquote><math>
&nbsp;&nbsp;&nbsp;&nbsp; f . cat<br />
=  &nbsp;&nbsp;&nbsp;&nbsp; <text>{ (1) }</text><br />
&nbsp;&nbsp;&nbsp;&nbsp; foldrp (≪) . (id × f)<br />
=  &nbsp;&nbsp;&nbsp;&nbsp; <text>{ since <mi>f . f° . f = f</mi> }</text><br />
&nbsp;&nbsp;&nbsp;&nbsp; foldrp (≪) . (id × f) . (id × f° . f)<br />
=  &nbsp;&nbsp;&nbsp;&nbsp; <text>{ (1) }</text><br />
&nbsp;&nbsp;&nbsp;&nbsp; f . cat . (id × f° . f)<br />
=  &nbsp;&nbsp;&nbsp;&nbsp; <text>{ (2) }</text><br />
&nbsp;&nbsp;&nbsp;&nbsp; foldlp (≫) . (f × id) . (id × f° . f)<br />
=  &nbsp;&nbsp;&nbsp;&nbsp; <text>{ since <mi>f . f° . f = f</mi> }</text><br />
&nbsp;&nbsp;&nbsp;&nbsp; foldlp (≫) . (f × id) . (f° . f × f° . f)<br />
=  &nbsp;&nbsp;&nbsp;&nbsp; <text>{ (2) }</text><br />
&nbsp;&nbsp;&nbsp;&nbsp; f . cat . (f° . f × f° . f)<br />
</math>
</blockquote>
<p>The proof is still the same as that of Jeremy&#8217;s, but in a relational disguise.</p>
<h3>Refining to Functions</h3>
<p>To derive actual algorithms, we have yet to refine <mi>⊚ = f . cat . (f°× f°)</mi> so that it uses functional components only. We shall pick some <mi>g ⊆ f°</mi> whose domain equals the range of <mi>f</mi>, such that <mi>⊚ = f . cat . (g × g)</mi>. (An equality, rather than inclusion, holds because <mi>⊚</mi> in both definitions are partial functions having the same domain.)</p>
<p>For example, consider the special case <mi>sum = foldr (+) 0 = foldl (+) 0</mi>. Here <mi>⊚ = sum . cat . (sum°× sum°)</mi>. One simple choice is to pick <mi>wrap ⊆ sum°</mi>, where <mi>wrap a = [a]</mi>. In this case <mi>a ⊚ b = sum [a, b] = a + b</mi>.</p>
<p>For <mi>sort</mi>, define <mi>sorted = ran sort</mi>. It is a partial function such that <mi>sorted xs = xs</mi> iff <mi>xs</mi> is sorted. Notice that <mi>sorted ⊆ sort°</mi>. Therefore, a possible choice for <mi>⊚</mi> would be <mi>sort . cat . (sorted × sorted)</mi> &#8212; concatenating two sorted lists, and sort them again. <a href="http://web.comlab.ox.ac.uk/oucl/work/jeremy.gibbons/publications/index.html#thirdht"">Jeremy</a> then went on with this definition and proved that <mi>⊚ = merge</mi>, taking advantage of the fact that both input lists are sorted.</p>
<h3>Some more Properties</h3>
<p>Some more properties are needed to deal with <mi>scanr</mi>. The following properties allow <mi>foldrp</mi> and <mi>foldrp</mi> to proceed by shifting elements of the list to the base case:</p>
<blockquote><math>
foldrp (≪) (xs⧺[x],a) = foldrp (≪) (xs, x ≪ a)<br />
foldlp (≫) (a, x:xs) = foldlp (≫) (a ≫ x, xs) <span style="float:right">(3)</span><br />
</math>
</blockquote>
<p>When simple approaches of refining <mi>⊚ = f . cat . (f°× f°)</mi> does not work, the following approach sometimes does. Since <mi>f</mi> is a fold, one may attempt to take one of the <mi>f°</mi> as an unfold, thus forming an &#8220;unfold, then fold&#8221; pattern:</p>
<blockquote><math>
&nbsp;&nbsp;&nbsp;&nbsp;⊚ = f . cat . (f°× f°)<br />
=  &nbsp;&nbsp;&nbsp;&nbsp; <text>{ (1) }</text><br />
&nbsp;&nbsp;&nbsp;&nbsp;foldrp (≪) . (id × f) . (f°× f°)<br />
⊇  &nbsp;&nbsp;&nbsp;&nbsp; <text>{ since <mi>f . f° ⊇ ran f</mi> }</text><br />
&nbsp;&nbsp;&nbsp;&nbsp;foldrp (≪) . (f°× ran f)<br />
=  &nbsp;&nbsp;&nbsp;&nbsp; <text>{ since <mi>f = foldl ≫ []</mi> }</text><br />
&nbsp;&nbsp;&nbsp;&nbsp;foldrp (≪) . ((foldl ≫ [])°× ran f)<br />
</math>
</blockquote>
<p>Symetrically, </p>
<blockquote><math>
 ⊚ = foldlp (≫) . (ran f × (foldr ≪ [])°) <span style="float:right">(4)</span><br />
</math>
</blockquote>
<h3>Scanr &#8220;from the Middle&#8221;</h3>
<p>Finally, consider <mi>f = scanr ⊛ e</mi> for some associative <mi>⊛</mi> with identity <mi>e</mi> (that is, <mi>e ⊛ x = x ⊛ e = x</mi>). A scan can be defined both as a <mi>foldr</mi> and a <mi>foldl</mi> as below:</p>
<blockquote><math>
scanr ⊛ e = foldr ≪ [e]<br />
&nbsp;&nbsp;&nbsp;&nbsp;x ≪ (y : xs) = x ⊛ y : y : xs<br />
scanr ⊛ e = foldl ≫ [e]<br />
&nbsp;&nbsp;&nbsp;&nbsp;xs ≫ x = map (⊛x) xs ⧺ [e]<br />
</math>
</blockquote>
<p>From <mi>⊚ = f . cat . (f°× f°)</mi>, we can prove that <mi>xs ⊚ (y : ys) = map (⊛ y) xs ⧺  ys</mi>. Here is the inductive case:</p>
<blockquote><math>
&nbsp;&nbsp;&nbsp;&nbsp;xs ⊚ (x : y : ys)<br />
=  &nbsp;&nbsp;&nbsp;&nbsp; <text>{ (4) }</text><br />
&nbsp;&nbsp;&nbsp;&nbsp;foldlp (≫) (xs, (foldr ≪ [e])° (x : y :ys))<br />
=  &nbsp;&nbsp;&nbsp;&nbsp; <text>{ definition of <mi>≪</mi>, let <mi>z ⊛ y = x</mi> }</text><br />
&nbsp;&nbsp;&nbsp;&nbsp;foldlp (≫) (xs, z : (foldr ≪ [e])° (y :ys))<br />
=  &nbsp;&nbsp;&nbsp;&nbsp; <text>{ (3) }</text><br />
&nbsp;&nbsp;&nbsp;&nbsp;foldlp (≫) (xs ≫ z, (foldr ≪ [])° (y :ys))<br />
=  &nbsp;&nbsp;&nbsp;&nbsp; <text>{ (4) }</text><br />
&nbsp;&nbsp;&nbsp;&nbsp;(xs ≫ z) ⊚ (y : ys)<br />
=  &nbsp;&nbsp;&nbsp;&nbsp; <text>{ induction }</text><br />
&nbsp;&nbsp;&nbsp;&nbsp;map (⊛ y) (xs ≫ z) ⧺ ys<br />
=  &nbsp;&nbsp;&nbsp;&nbsp; <text>{ definition of <mi>≫</mi> }</text><br />
&nbsp;&nbsp;&nbsp;&nbsp;map (⊛ y) (map (⊛ z) xs ⧺ [e]) ⧺ ys<br />
=  &nbsp;&nbsp;&nbsp;&nbsp; <text>{ map, <mi>e</mi> identity }</text><br />
&nbsp;&nbsp;&nbsp;&nbsp; map (λv → (v ⊛ y) ⊛ z) xs ⧺ [y] ⧺ ys<br />
=  &nbsp;&nbsp;&nbsp;&nbsp; <text>{ associtivity of <mi>⊛</mi> }</text><br />
&nbsp;&nbsp;&nbsp;&nbsp; map (λv → v ⊛ (y ⊛ z)) xs ⧺ [y] ⧺ ys<br />
=  &nbsp;&nbsp;&nbsp;&nbsp; <text>{ <mi>z ⊛ y =x</mi> }</text><br />
&nbsp;&nbsp;&nbsp;&nbsp;map (⊛ x) xs ⧺ [x] ⧺ (y:ys)<br />
</math>
</blockquote>
<h3>Prologue</h3>
<p>Given the complexity of the proof above, I did not think there was a hope to automatically construct <mi>⊚</mi> for a reasonably useful set of list homomorphisms. My colleagues were talking about &#8220;weak inverses&#8221; &#8212; their attempts to look for a refinement of <mi>f°</mi>, which I considered too ad-hoc.</p>
<p>Being just graduated from <a href="http://web.comlab.ox.ac.uk/oucl/research/pdt/ap/">AoP</a>, I was perhaps too arrogant and proud of all the clever derivation we did to care about automatic program construction. (Like Jeremy, in the end of my thesis I quoted &#8220;善數不用籌策 (Those who good at calculation need no mechanical aids)&#8221; from 老子 Lao Tzu. And didn&#8217;t Dijkstra say &#8220;I hardly used the computer they gave me. I was perfectly happy without it.&#8221;?) The relational method, which seemed to cover everything, gave me a false feeling that I knew the problem inside out.</p>
<p>Last year, however, my colleagues and I met again and I was told that they eventually published a paper on this subject:</p>
<blockquote><p>Kazutaka Morita, Akimasa Morihata, Kiminori Matsuzaki, Zhenjiang Hu, Masato Takeichi. <a href=" http://www.ipl.t.u-tokyo.ac.jp/~hu/pub/pldi07.pdf">Automatic Inversion Generates Divide-and-Conquer Parallel Programs</a>, PLDI 2007.</p></blockquote>
<p>They focused on weak inverses that returns only lists with fixed lengths. The advantage is that calculations like the one above are no longer necessary &#8212; since the lists are of fixed-length, <mi>⊚</mi> always takes constant time. On the other hand, <mi>scanr</mi> and <mi>scanl</mi> are special cases dealt with on a different level. Such distinction is enforced by the language they allow to construct <mi>f</mi>. No, they do not seem to have handled <mi>sort</mi>. But their approach still covered a reasonably useful collection of functions.</p>
<p>Well, I think the moral is that we cannot just stop when it appears that is no elegant solution that suits our taste. It sometimes pays to get our hands dirty, through which we may eventually discover the beauty within.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iis.sinica.edu.tw/~scm/2008/constructing-list-homomorphism/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>S Combinator is Injective, with Proofs</title>
		<link>http://www.iis.sinica.edu.tw/~scm/2007/s-combinator-is-injective-with-proofs/</link>
		<comments>http://www.iis.sinica.edu.tw/~scm/2007/s-combinator-is-injective-with-proofs/#comments</comments>
		<pubDate>Wed, 05 Dec 2007 04:39:18 +0000</pubDate>
		<dc:creator>Shin</dc:creator>
				<category><![CDATA[Research Blog]]></category>
		<category><![CDATA[Program Inversion]]></category>
		<category><![CDATA[λ calculus]]></category>

		<guid isPermaLink="false">http://www.iis.sinica.edu.tw/~scm/2007/s-combinator-is-injective-with-proofs/</guid>
		<description><![CDATA[By chance, I came upon a blog entry by <a href="http://www.tom.sfc.keio.ac.jp/~sakai/d/?date=20070827#p01">Masahiro Sakai (酒井政裕)</a> in which he, after reading my <a href="http://www.iis.sinica.edu.tw/~scm/2007/s-combinator-is-injective/">short comment</a> "Do you know that the <code>S</code> combinator is injective?", tried to construct the inverse of <code>S</code> and showed that <code>S⁻¹ ○ S = id</code> in, guess what, Agda!
]]></description>
			<content:encoded><![CDATA[<p>By chance, I came upon a blog entry by <a href="http://www.tom.sfc.keio.ac.jp/~sakai/d/?date=20070827#p01">Masahiro Sakai (酒井政裕)</a> in which he, after reading my <a href="http://www.iis.sinica.edu.tw/~scm/2007/s-combinator-is-injective/">short comment</a> on my previous homepage &#8220;Do you know that the <code>S</code> combinator is injective? I have a simple algebraic proof!&#8221;, tried to construct the inverse of <code>S</code> and showed that <code>S⁻¹ ○ S = id</code> in, guess what, Agda!</p>
<p>Wow, people were actually reading what I wrote! This made me feel that I have to be a bit more responsible and, at least, provide the proof when I claim I have one. So, here it is.</p>
<h3>S is injective</h3>
<p>Recall the definition of <code>S</code>:</p>
<pre><code>
S : (A -> B -> C) -> (A -> B) -> A -> C
S = λ x y a -> x a (y a)
</code></pre>
<p>I am assuming a simple semantics of sets and functions, and by <code>S</code> being injective I mean that <code>S x = S x' ⇒ x = x'</code>, which can be trivially shown below:</p>
<pre><code>
    S x = S x'
≡       { η expansion, for all y : A -> B, a : A }
    (∀ a, y : S x y a = S x' y a)
≡       { definition of S }
    (∀ a, y : x a (y a) = x' a (y a))
⇒       { choose y = K b for some b }
    (∀ a, b : x a (K b a) = x' a (K b a))
≡       { definition of K: K b a = b }
    (∀ a, b : x a b = x' a b)
≡       { pointwise equality }
    x = x'
</code></pre>
<p>I would usually leave out the <code>∀</code>&#8216;s in derivations, but in this case, they are explicitly written to emphasise that <code>b</code> is indeed universally quantified.</p>
<h3>So, what is the inverse of S?</h3>
<p>Now that we know <code>S</code> is injective, there ought to exist some function <code>S⁻¹</code> such that <code>S⁻¹ ○ S = id</code>. <a href="http://www.ipl.t.u-tokyo.ac.jp/~ksk/">Nakano</a> san claimed that a definition would be:</p>
<pre><code>
S⁻¹ : ((A -> B) -> A -> C) -> A -> B -> C
S⁻¹ = λ x a b -> x (K b) a
</code></pre>
<p>That <code>S⁻¹ ○ S = id</code> is easy to see:</p>
<pre><code>
   S⁻¹ (S x) a b
=  (S x) (K b) a
=  x a (K b a)
=  x a b
</code></pre>
<p>From another direction, we have only <code>S ○ S⁻¹ ⊆ id</code> since <code>S</code> is not a surjective function. How the range of <code>S</code> look like? Inspecting the definition of <code>S</code>. Since <code>y</code> is applied only once to <code>a</code>, the value of <code>y</code> on other input does not matter. That is, the range of <code>S</code> consists of only functions <code>e</code> such that:</p>
<pre><code>
e y a = e y' a     for all y, y' such that y a = y' a      ......(1)
</code></pre>
<p>We will show that <code>S (S⁻¹ e) = e</code> for all <code>e</code> satisfying (1):</p>
<pre><code>
    S (S⁻¹ e) y a
=      { definition of S }
    S⁻¹ e a (y a)
=      { definition of S⁻¹ }
    e (K (y a)) a
=      { by (1), since K (y a) a = y a }
    e y a
</code></pre>
<h3>Inverting higher-order functions?</h3>
<p>Some endnotes. Once Nakano and I thought we discovered how to invert higher-order functions (and even derive the necessary side conditions, like the one on <code>e</code> above) by drawing λ expressions as trees and manipulating them. It turned out that I overlooked something obvious in the very beginning and the result was a disaster. </p>
<p>Does anyone know of some related work on inverting higher order functions? The only one I know is Samson Abramsky&#8217;s paper <a href="http://web.comlab.ox.ac.uk/oucl/work/samson.abramsky/revised.pdf">A Structural Approach to Reversible Computation</a>, but I am not sure whether it is about reversibility/invertibility in the same sense.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iis.sinica.edu.tw/~scm/2007/s-combinator-is-injective-with-proofs/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Countdown: a case study in origami programming</title>
		<link>http://www.iis.sinica.edu.tw/~scm/2007/countdown-a-case-study-in-origami-programming/</link>
		<comments>http://www.iis.sinica.edu.tw/~scm/2007/countdown-a-case-study-in-origami-programming/#comments</comments>
		<pubDate>Wed, 20 Jun 2007 02:12:44 +0000</pubDate>
		<dc:creator>Shin</dc:creator>
				<category><![CDATA[Journal]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Optimisation Problems]]></category>
		<category><![CDATA[Program Derivation]]></category>
		<category><![CDATA[Program Inversion]]></category>
		<category><![CDATA[Thinning Theorem]]></category>

		<guid isPermaLink="false">http://www.iis.sinica.edu.tw/~scm/?p=21</guid>
		<description><![CDATA[<a href="http://web.comlab.ox.ac.uk/oucl/people/richard.bird.html">R. S. Bird</a> and S-C. Mu, Countdown: a case study in origami programming. In <i>Journal of Functional Programming Vol. 15(5)</i>, pp. 679-702, 2005.<br/>[<a href="http://www.iis.sinica.edu.tw/~scm/pub/countdown704.ps.gz">GZipped Postscript</a>]]]></description>
			<content:encoded><![CDATA[<p><a href="http://web.comlab.ox.ac.uk/oucl/people/richard.bird.html">R. S. Bird</a> and S-C. Mu. In <i>Journal of Functional Programming Vol. 15(5)</i>, pp. 679-702, 2005.<br/>[<a href="http://www.iis.sinica.edu.tw/~scm/pub/countdown704.ps.gz">GZipped Postscript</a>]</p>
<p><strong>Countdown</strong> is the name of a game in which one is given a list of source numbers and a target number, with the aim of building an arithmetic expression out of the source numbers to get as close to the target<br />
as possible. Starting with a relational specification we derive a number of functional programs for solving Countdown. These programs are obtained by exploiting the properties of the folds and unfolds of various data types, a style of programming Gibbons has aptly called <strong>origami</strong> programming. Countdown is attractive as a case study in origami programming both as an illustration of how different algorithms can emerge from a single specification, as well as the space and time trade-offs that have to be taken into account in comparing functional programs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iis.sinica.edu.tw/~scm/2007/countdown-a-case-study-in-origami-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inverting the Burrows-Wheeler transform</title>
		<link>http://www.iis.sinica.edu.tw/~scm/2007/inverting-the-burrows-wheeler-transform-2/</link>
		<comments>http://www.iis.sinica.edu.tw/~scm/2007/inverting-the-burrows-wheeler-transform-2/#comments</comments>
		<pubDate>Wed, 20 Jun 2007 02:11:04 +0000</pubDate>
		<dc:creator>Shin</dc:creator>
				<category><![CDATA[Journal]]></category>
		<category><![CDATA[Burrows-Wheeler Transform]]></category>
		<category><![CDATA[Program Derivation]]></category>
		<category><![CDATA[Program Inversion]]></category>

		<guid isPermaLink="false">http://www.iis.sinica.edu.tw/~scm/?p=20</guid>
		<description><![CDATA[<a href="http://web.comlab.ox.ac.uk/oucl/people/richard.bird.html">R. S. Bird</a> and S-C. Mu, Inverting the Burrows-Wheeler transform<a name="2003:Inverting"/>. In <i>Journal of Functional Programming Vol. 14(6) Special Issue on Functional Pearls</i>, pp. 603-612, Novermber 2004.<br/>[<a href="http://www.iis.sinica.edu.tw/~scm/pub/bwtJFP.pdf">PDF</a>][<a href="http://www.iis.sinica.edu.tw/~scm/pub/bwtJFP.ps.gz">GZipped Postscript</a>]]]></description>
			<content:encoded><![CDATA[<p><a href="http://web.comlab.ox.ac.uk/oucl/people/richard.bird.html">R. S. Bird</a> and S-C. Mu. In <i>Journal of Functional Programming Vol. 14(6) Special Issue on Functional Pearls</i>, pp. 603-612, Novermber 2004.<br/>[<a href="http://www.iis.sinica.edu.tw/~scm/pub/bwtJFP.pdf">PDF</a>][<a href="http://www.iis.sinica.edu.tw/~scm/pub/bwtJFP.ps.gz">GZipped Postscript</a>]</p>
<p>The Burrows-Wheeler Transform is a string-to-string transform which, when used as a preprocessing phase in compression, significantly enhances the compression rate. However, it often puzzles people how the inverse transform can be carried out. In this pearl we to exploit simple equational reasoning to derive the inverse of the Burrows-Wheeler transform from its specification. We also outline how to derive the inverse of two more general versions of the transform, one proposed by Schindler and the other by Chapin and Tate.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iis.sinica.edu.tw/~scm/2007/inverting-the-burrows-wheeler-transform-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An algebraic approach to bidirectional updating</title>
		<link>http://www.iis.sinica.edu.tw/~scm/2007/an-algebraic-approach-to-bidirectional-updating/</link>
		<comments>http://www.iis.sinica.edu.tw/~scm/2007/an-algebraic-approach-to-bidirectional-updating/#comments</comments>
		<pubDate>Wed, 20 Jun 2007 02:08:58 +0000</pubDate>
		<dc:creator>Shin</dc:creator>
				<category><![CDATA[Conference]]></category>
		<category><![CDATA[Bidirectional Updating]]></category>
		<category><![CDATA[Program Inversion]]></category>

		<guid isPermaLink="false">http://www.iis.sinica.edu.tw/~scm/?p=19</guid>
		<description><![CDATA[S-C. Mu, <a href="http://www.ipl.t.u-tokyo.ac.jp/~hu/">Z. Hu</a> and <a href="http://www.ipl.t.u-tokyo.ac.jp/~takeichi/">M. Takeichi</a>. An algebraic approach to bidirectional updating. In <i>The Second Asian Symposium on Programming Language and Systems</i>, pp. 2-18. November 2004.<br/>[<a href="http://www.iis.sinica.edu.tw/~scm/pub/bidirectional.pdf">PDF</a>]]]></description>
			<content:encoded><![CDATA[<p>S-C. Mu, <a href="http://www.ipl.t.u-tokyo.ac.jp/~hu/">Z. Hu</a> and <a href="http://www.ipl.t.u-tokyo.ac.jp/~takeichi/">M. Takeichi</a>. In <i>The Second Asian Symposium on Programming Language and Systems</i>, pp. 2-18. November 2004.<br/>[<a href="http://www.iis.sinica.edu.tw/~scm/pub/bidirectional.pdf">PDF</a>]</p>
<p>In many occasions would one encounter the task of maintaining the consistency of two pieces of structured data related by some transform &#8212; synchronising bookmarks in different web browsers, the source and the view in an editor, or views in databases, to name a few. This paper proposes a formal model of such tasks, basing on a programming language allowing injective functions only, inspired by previous work on program inversion. The programmer designs the transformation as if she is writing a functional program, while the synchronisation behaviour is automatically derived by algebraic reasoning. The main advantage is being able to deal with duplication and structural changes. The result will be integrated to our structure XML editor in the Programmable Structured Document project.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iis.sinica.edu.tw/~scm/2007/an-algebraic-approach-to-bidirectional-updating/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A programmable editor for developing structured documents based on bidirectional transformations</title>
		<link>http://www.iis.sinica.edu.tw/~scm/2007/a-programmable-editor-for-developing-structured-documents-based-on-bidirectional-transformations/</link>
		<comments>http://www.iis.sinica.edu.tw/~scm/2007/a-programmable-editor-for-developing-structured-documents-based-on-bidirectional-transformations/#comments</comments>
		<pubDate>Wed, 20 Jun 2007 02:07:36 +0000</pubDate>
		<dc:creator>Shin</dc:creator>
				<category><![CDATA[Conference]]></category>
		<category><![CDATA[Bidirectional Updating]]></category>
		<category><![CDATA[Program Inversion]]></category>

		<guid isPermaLink="false">http://www.iis.sinica.edu.tw/~scm/?p=18</guid>
		<description><![CDATA[<a href="http://www.ipl.t.u-tokyo.ac.jp/~hu/">Z. Hu</a>, S-C. Mu and <a href="http://www.ipl.t.u-tokyo.ac.jp/~takeichi/">M. Takeichi</a>, A programmable editor for developing structured documents based on bidirectional transformations. In <i>Partial Evaluation and Semantics-Based Program Manipulation</i>, pp. 178-189. August 2004.<br/>[<a href="http://www.iis.sinica.edu.tw/~scm/pub/p03-hu.pdf">PDF</a>]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ipl.t.u-tokyo.ac.jp/~hu/">Z. Hu</a>, S-C. Mu and <a href="http://www.ipl.t.u-tokyo.ac.jp/~takeichi/">M. Takeichi</a>. In <i>Partial Evaluation and Semantics-Based Program Manipulation</i>, pp. 178-189. August 2004.<br/>[<a href="http://www.iis.sinica.edu.tw/~scm/pub/p03-hu.pdf">PDF</a>]</p>
<p>This paper presents a novel editor supporting interactive refinement in the development of structured documents. The user performs a sequence of editing operations on the document view, and our system automatically derives an efficient and reliable document source and a transformation that produces the document view. The editor is unique in its programmability, in the sense that transformation can be obtained through editing operations. The<br />
important techniques behind this editor are the utilization of the view-updating idea developed in the database community, and a bidirectional transformation language that concisely describes the relationship between the document source and its view, as well as data dependency in the view.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iis.sinica.edu.tw/~scm/2007/a-programmable-editor-for-developing-structured-documents-based-on-bidirectional-transformations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An injective language for reversible computation</title>
		<link>http://www.iis.sinica.edu.tw/~scm/2007/an-injective-language-for-reversible-computation/</link>
		<comments>http://www.iis.sinica.edu.tw/~scm/2007/an-injective-language-for-reversible-computation/#comments</comments>
		<pubDate>Wed, 20 Jun 2007 02:06:51 +0000</pubDate>
		<dc:creator>Shin</dc:creator>
				<category><![CDATA[Conference]]></category>
		<category><![CDATA[Bidirectional Updating]]></category>
		<category><![CDATA[Program Inversion]]></category>

		<guid isPermaLink="false">http://www.iis.sinica.edu.tw/~scm/?p=17</guid>
		<description><![CDATA[S-C. Mu, <a href="http://www.ipl.t.u-tokyo.ac.jp/~hu/">Z. Hu</a> and <a href="http://www.ipl.t.u-tokyo.ac.jp/~takeichi/">M. Takeichi</a>, An injective language for reversible computation. In <i>Mathematics of Program Construction 2004</i>, LNCS 3125, pp. 289-313, July 2004.<br/>[<a href="http://www.iis.sinica.edu.tw/~scm/pub/reversible.pdf">PDF</a>]]]></description>
			<content:encoded><![CDATA[<p>S-C. Mu, <a href="http://www.ipl.t.u-tokyo.ac.jp/~hu/">Z. Hu</a> and <a href="http://www.ipl.t.u-tokyo.ac.jp/~takeichi/">M. Takeichi</a>. In <i>Mathematics of Program Construction 2004</i>, LNCS 3125, pp. 289-313, July 2004.<br/>[<a href="http://www.iis.sinica.edu.tw/~scm/pub/reversible.pdf">PDF</a>]</p>
<p>Erasure of information incurs an increase in entropy and dissipatse heat. Therefore, information-preserving computation is essential for constructing computers that use energy more effectively. A more recent motivation to understand reversible transformations also comes from the design of editors where editing actions on a view need to be reflected back to the source data.</p>
<p>In this paper we present a point-free functional language, with a relational semantics, in which the programmer is allowed to define injective functions only. Non-injective functions can be transformed into a program returning a history. The language is presented with many examples, and its relationship with Bennett&#8217;s reversible Turing machine is explained.</p>
<p>The language serves as a good model for program construction and reasoning for reversible computers, and hopefully for modelling bi-directional updating in an editor.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iis.sinica.edu.tw/~scm/2007/an-injective-language-for-reversible-computation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

