Re: [Haskell-cafe] Disjunctive Normal Form

2007-11-01 Thread Luke Palmer
On 11/2/07, Luke Palmer <[EMAIL PROTECTED]> wrote: > On 11/1/07, Arnar Birgisson <[EMAIL PROTECTED]> wrote: > > dnf :: LS -> DNF > > dnf (Var s) = [[Pos s]] > > dnf (Or l1 l2) = (dnf l1) ++ (dnf l2) > > dnf (And l1 l2) = [t1 ++ t2 | t1 <- dnf l1, t2 <- dnf l2] > > dnf (Not (Not d)) = dnf d > > dnf

Re: [Haskell-cafe] Disjunctive Normal Form

2007-11-01 Thread Luke Palmer
On 11/1/07, Arnar Birgisson <[EMAIL PROTECTED]> wrote: > I'm learning too and found this an interesting problem. Luke, is this > similar to what you meant? Heh, your program is almost identical to the one I wrote to make sure I wasn't on crack. :-) > data LS = Var String | Not LS | And LS LS | O

Re: [Haskell-cafe] Disjunctive Normal Form

2007-11-01 Thread Arnar Birgisson
Hey folks, On Nov 1, 2007 6:41 PM, Luke Palmer <[EMAIL PROTECTED]> wrote: > A good way to approach this is data-structure-driven programming. You > want a data structure which represents, and can _only_ represent, > propositions in DNF. So: > > data Term = Pos Var | Neg Var > type Conj = [Term]

Re: [Haskell-cafe] Disjunctive Normal Form

2007-11-01 Thread Jules Bean
It's much much easier to work with n-ary than binary. It's also easier to define disjunctive normal form by mutual recursion with conjunctive normal form. Jules ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/lis

Re: [Haskell-cafe] Disjunctive Normal Form

2007-11-01 Thread Christopher L Conway
Jim, Lukes suggestion is a good one, and should help focus you on the syntactic constraints of DNF. A property that your dnf function should have is that the right-hand side of each case should yield a DNF formula. Take, for example, dnf (And s1 s2) = And (dnf s1) (dnf s2) Does And'ing t

Re: [Haskell-cafe] Disjunctive Normal Form

2007-11-01 Thread Luke Palmer
A good way to approach this is data-structure-driven programming. You want a data structure which represents, and can _only_ represent, propositions in DNF. So: data Term = Pos Var | Neg Var type Conj = [Term] type DNF = [Conj] Then write: dnf :: LS -> DNF The inductive definition of dnf is

[Haskell-cafe] Disjunctive Normal Form

2007-11-01 Thread Jim Burton
I am trying to rewrite sentences in a logical language into DNF, and wonder if someone would point out where I'm going wrong. My dim understanding of it is that I need to move And and Not inwards and Or out, but the function below fails, for example: > dnf (Or (And A B) (Or (And C D) E))