[Haskell-beginners] Simple function comparison

MJ Williams matthewjwilliams101 at gmail.com
Thu Nov 26 11:20:05 UTC 2015


All right, a revised version:

Let f x = x + 1
let g x = x + 2

f ( g a )
= f ( a + 2 ) ................... (g)
= ( a + 2 ) + 1 ................. (f)
...
= a + 3 ......................... (+)
therefore f ( g a ) <-> a + 3 ... (transitivity)

g ( f a )
= g ( a + 1 ) ................... (f)
= ( a + 1 ) + 2 ................. (g)
...
= a + 3 ......................... (+)
therefore g ( f a ) <-> a + 3 ... (transitivity)

therefore f ( g a ) = g ( f a ) . (transitivity)


On 26/11/2015, MJ Williams <matthewjwilliams101 at gmail.com> wrote:
> All right, how about this for a proof:
>
> Let f x = x + 1
> let g x = x + 2
>
> if f ( g a )
> then f ( a + 2 ) .............. (g)
> then ( a + 2 ) + 1 ............ (f)
> ...
> then a + 3 .................... (+)
> therefore f ( g a ) <-> a + 3
>
> if g ( f a )
> then g ( a + 1 ) .............. (f)
> then ( a + 1 ) + 2 ............ (g)
> ...
> then a + 3 .................... (+)
> therefore g ( f a ) <-> a + 3
>
> therefore f ( g a ) = g ( f a ) (transitivity)
>
> Feel free to take it apart and smash it to bits. Seriously, any
> feedback welcome.
>
> Cheers, Matthew
>
>
> On 25/11/2015, Henk-Jan van Tuyl <hjgtuyl at chello.nl> wrote:
>> On Wed, 25 Nov 2015 12:39:15 +0100, Stephen Renehan <d11124067 at mydit.ie>
>> wrote:
>>
>>> Hi,
>>>
>>> I'm looking to do a comparison between 2 simple functions to see if
>>> they are equivalent but I appear to be running into some problems if
>>> anyone can help.
>>>
>>> The two functions I want to compare are f (g a) and g (f a).
>>>
>>> I have f defined and g defined as
>>>  f :: a -> a
>>>  f = undefined
>>>
>>> g :: a -> a.
>>> g =  undefined
>>
>> As you can not say anything about the type of input or output (except
>> that
>>
>> they are equal), the only normally terminating function possible is 'id'.
>> So, if you don't want to use 'undefined' or 'error', f and g are equal.
>>
>> Regards,
>> Henk-Jan van Tuyl
>>
>>
>> --
>> Folding at home
>> What if you could share your unused computer power to help find a cure?
>> In
>>
>> just 5 minutes you can join the world's biggest networked computer and
>> get
>>
>> us closer sooner. Watch the video.
>> http://folding.stanford.edu/
>>
>>
>> http://Van.Tuyl.eu/
>> http://members.chello.nl/hjgtuyl/tourdemonad.html
>> Haskell programming
>> --
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>


More information about the Beginners mailing list