[Haskell-cafe] Propositions in Haskell

28 views
Skip to first unread message

Patrick Browne

unread,
May 15, 2013, 11:34:28 AM5/15/13
to haskel...@haskell.org
-- Hi
-- I am trying to show that a set of propositions and a conclusion the form a valid argument.
-- I used two approaches; 1) using if-then-else, 2) using pattern matching.
-- The version using if-then-else seems to be consistent with my knowledge of Haskell and logic (either of which could be wrong).
-- Can the second approach be improved to better reflect the propositions and conclusion? Maybe type level reasoning could be used?
--
-- Valid argument?
-- 1. I work hard or I play piano
-- 2. If I work hard then I will get a bonus
-- 3. But I did not get a bonus
--     Therefore I played piano
-- Variables: p = Piano, w = worked hard, b = got a bonus
--    (w \/ p) /\ (w => b) /\ ¬(b)
--   ---------------------------
--                p

-- First approach using language control structure if-then-else
w, p, b::Bool
-- Two equivalences for (w \/ p) as an implication.
-- 1. (w \/ p) =equivalent-to=> (not p) => w
-- 2. (w \/ p) =equivalent-to=> (not w) => p
-- Picked 2
p = if (not w) then True else False
-- Contrapositive:  (w => b)  =equivalent-to=>  ~b => ~w
w = if (not b) then False else True
b = False
-- gives p is true and w is false

-- Second approach using pattern matching
-- I think the rewriting goes from left to right but the logical inference goes in the opposite direction.
w1, p1, b1::Bool
p1 = (not w1)
w1 = b1 -- Not consistent with statements, but I do not know how to write ~b1 => ~w1 in Haskell
b1 = False
-- Again gives p1 is true and w1 is false


Tá an teachtaireacht seo scanta ó thaobh ábhar agus víreas ag Seirbhís Scanta Ríomhphost de chuid Seirbhísí Faisnéise, ITBÁC agus meastar í a bheith slán. http://www.dit.ie
This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie

Dan Mead

unread,
May 15, 2013, 12:34:33 PM5/15/13
to Patrick Browne, Haskell Café
i don't understand what you're trying to do with that code, however you seem to be asking about theorem proving in general

check out

http://www.haskell.org/haskellwiki/Libraries_and_tools/Theorem_provers


and

http://en.wikipedia.org/wiki/Automated_theorem_proving


hope it helps


_______________________________________________
Haskell-Cafe mailing list
Haskel...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Alberto G. Corona

unread,
May 15, 2013, 12:56:37 PM5/15/13
to Patrick Browne, haskell-cafe
Not exactly what you ask, but it is noteworthy that the mind has different logic processors. The fastest one work with IF THEN ELSE rules applied specifically to deals. This is why your example (and most examples of logic) involves a kind of deal expressed in the first person. This trigger a fast mental evaluation, while an equivalent but more general case is harder to process and need some paper work.  (That special treatment of first person deals logic respond to the need to detect breaks of deals as fast as possible)
 
 
That's why higher level languages have redundant logical structures and do not follow a general abstract and short mathematical notation. Therefore  "higher level", in programming languages, does not mean higher mathematical abstraction, but to be closer to the way the mind works.


2013/5/15 Patrick Browne <patrick...@dit.ie>
_______________________________________________
Haskell-Cafe mailing list
Haskel...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe




--
Alberto.

Patrick Browne

unread,
May 15, 2013, 1:15:53 PM5/15/13
to Dan Mead, Haskell Café

The relation to theorem proving is the main motivation for my question.

In am trying to understand why some equations are ok and others not.

I suspect that in Haskell equations are definitions rather than assertions.

If approach 2 is a non-starter in Haskell, then can approach 1, using if-then-else, achieve the same results for propositions?


Thanks
Pat


On 15/05/13, Dan Mead <d.w....@gmail.com> wrote:
i don't understand what you're trying to do with that code, however you seem to be asking about theorem proving in general

check out

http://www.haskell.org/haskellwiki/Libraries_and_tools/Theorem_provers


and

http://en.wikipedia.org/wiki/Automated_theorem_proving


hope it helps

MigMit

unread,
May 15, 2013, 2:04:28 PM5/15/13
to Patrick Browne, Haskell Café
You can stop suspecting: in Haskell, equations ARE definitions.
> http://www.haskell.org/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
Haskel...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Keshav Kini

unread,
May 15, 2013, 10:33:48 PM5/15/13
to haskel...@haskell.org
Patrick Browne <patrick...@dit.ie> writes:
> -- Hi

By the way, this is unrelated to your actual question, but if you
haven't already, you might want to check out Bird-style Literate Haskell
so you don't have to put "-- " in front of all of your non-Haskell text
in a comment-heavy code-light file (or email message) :)

http://www.haskell.org/haskellwiki/Literate_programming#Bird_Style

-Keshav

Patrick Browne

unread,
May 16, 2013, 5:27:43 AM5/16/13
to Alberto G. Corona, haskell-cafe
I do understand the difference between theorem provers and Haskell programs.
Logic can be used to reason 'about' Haskell programs and logic can be used 'within' Haskell programs.
I am trying to clarify the difference between 'about' and 'within'
Is approach 1 concerned with  |= (model based 'within'), whereas approach 2 is concerned with |- (proof based 'about')?

Thanks,
Pat


On 15/05/13, "Alberto G. Corona " <agoc...@gmail.com> wrote:
Not exactly what you ask, but it is noteworthy that the mind has different logic processors. The fastest one work with IF THEN ELSE rules applied specifically to deals. This is why your example (and most examples of logic) involves a kind of deal expressed in the first person. This trigger a fast mental evaluation, while an equivalent but more general case is harder to process and need some paper work.  (That special treatment of first person deals logic respond to the need to detect breaks of deals as fast as possible)


That's why higher level languages have redundant logical structures and do not follow a general abstract and short mathematical notation. Therefore  "higher level", in programming languages, does not mean higher mathematical abstraction, but to be closer to the way the mind works.


2013/5/15 Patrick Browne <patrick...@dit.ie <patrick...@dit.ie>>

Dan Mead

unread,
May 16, 2013, 7:29:15 AM5/16/13
to haskell-cafe
maybe this will help?

Haskell code in and of itself isn't special. proofs can happen with the type system, but typically you'd want to define a target language and do assertions about it, similar to how a compiler inspects it's input programs. Haskell is not homoiconic nor is it like coq or prolog. But it is  really really good at defining an ast and doing operations on it.


Tillmann Rendel

unread,
May 17, 2013, 4:58:10 PM5/17/13
to Patrick Browne, Haskell Café
Hi,

Patrick Browne wrote:
> In am trying to understand why some equations are ok and others not.
>
> I suspect that in Haskell equations are definitions rather than assertions.

Yes. Haskell function definitions look like equations, but in many ways,
they aren't. Here is an example for an equation that is not valid as a
Haskell function definition:

g x = 42
f (g x) = x -- not valid

The problem is that we cannot use g at the left-hand side.


Here is an example that doesn't mean what you might be hoping for:

f x = f x
f x = 42

Seen as an equation system, this should constrain f to be a function
that always returns 42. But in Haskell, it defines f to be a
non-terminating function. The reason is that only the first line counts,
because it covers all possible argument values. The second line is ignored.

The behavior changes if we swap the two lines:

g x = 42
g x = g x

Again, only the first line counts, so g is the function that always
returns 42.

Here is a more complicated example:

h 27 = 42
h x = h x
h 13 = 100

What function is h?

Tillmann

_______________________________________________
Haskell-Cafe mailing list
Haskel...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply all
Reply to author
Forward
0 new messages