<!doctype html public "-//W3C//DTD W3 HTML//EN">
<html><head><style type="text/css"><!--
blockquote, dl, ul, ol, li { padding-top: 0 ; padding-bottom: 0 }
 --></style><title>Re: [Haskell-cafe] Proof of induction case of
simple foldl</title></head><body>
<div>At 8:45 PM +0000 3/14/09, R J wrote:</div>
<blockquote type="cite" cite><font face="Courier New">Can someone
provide the induction-case proof of the following identity:<br>
<br>
&nbsp;&nbsp; foldl (-) ((-) x y) ys = (foldl (-) x ys) - y<br>
<br>
If foldl is defined as usual:<br>
<br>
&nbsp;&nbsp;
foldl&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span
></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :: (b -&gt; a -&gt;
b) -&gt; b -&gt; [a] -&gt; b<br>
&nbsp;&nbsp; foldl f e
[]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp;
e<br>
&nbsp;&nbsp; foldl f e (x : xs)&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp;
myFoldl f (f e x) xs<br>
<br>
The first two cases, _|_ and [], are trivial.<br>
<br>
Here's my best attempt at the (y : ys) case (the left and right sides
reduce to expressions that are obviously equal, but I don't know how
to show it):<br>
<br>
&nbsp;&nbsp; Case (y : ys).</font></blockquote>
<div><br></div>
<div>Careful.&nbsp; Your introduced variables y and ys already appear
in the equation to be proved.&nbsp; Try introducing fresh
variables.</div>
<div><br></div>
<blockquote type="cite" cite><font face="Courier New"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Left-side reduction:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foldl (-) ((-) x y)
(y : ys)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp; {second equation of
&quot;foldl&quot;}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foldl (-) ((-) ((-) x
y) y) ys<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp; {notation}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foldl (-) ((-) (x -
y) y) ys<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp; {notation}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foldl (-) ((x - y) -
y) ys<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp; {arithmetic}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foldl (-) (x - 2 * y)
ys<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Right-side reduction:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (foldl (-) x (y :
ys)) - y<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp; {second equation of
&quot;foldl&quot;}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (foldl (-) ((-) x y)
ys) - y<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp; {induction hypothesis: foldl
(-) ((-) x y) ys = (foldl (-) x ys) - y}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((foldl (-) x ys) -
y) - y<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp; {arithmetic}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (foldl (-) x ys) - 2
* y</font><br>
<font face="Courier New"></font></blockquote>
<blockquote type="cite" cite><font face="Courier New">Thanks as
always.</font></blockquote>
</body>
</html>