From: Alexander Iljin Date: Mon, 22 Jan 2018 12:16:13 +0000 (+0100) Subject: boolean-expr: resurrected X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor-unmaintained.git;a=commitdiff_plain;h=f44fc09729386b7f3ee16b7af1b69bdd14ace1d3 boolean-expr: resurrected --- diff --git a/boolean-expr/authors.txt b/boolean-expr/authors.txt deleted file mode 100644 index 1901f27..0000000 --- a/boolean-expr/authors.txt +++ /dev/null @@ -1 +0,0 @@ -Slava Pestov diff --git a/boolean-expr/boolean-expr.factor b/boolean-expr/boolean-expr.factor deleted file mode 100644 index 33e5e92..0000000 --- a/boolean-expr/boolean-expr.factor +++ /dev/null @@ -1,95 +0,0 @@ -! Copyright (C) 2008 Slava Pestov. -! See http://factorcode.org/license.txt for BSD license. -USING: accessors arrays classes kernel sequences sets -io prettyprint multi-methods ; -IN: boolean-expr - -! Demonstrates the use of Unicode symbols in source files, and -! multi-method dispatch. - -TUPLE: ⋀ x y ; -TUPLE: ⋁ x y ; -TUPLE: ¬ x ; - -SINGLETONS: ⊤ ⊥ ; - -SINGLETONS: P Q R S T U V W X Y Z ; - -UNION: □ ⋀ ⋁ ¬ ⊤ ⊥ P Q R S T U V W X Y Z ; - -GENERIC: ⋀ ( x y -- expr ) - -METHOD: ⋀ { ⊤ □ } nip ; -METHOD: ⋀ { □ ⊤ } drop ; -METHOD: ⋀ { ⊥ □ } drop ; -METHOD: ⋀ { □ ⊥ } nip ; - -METHOD: ⋀ { ⋁ □ } [ [ x>> ] dip ⋀ ] [ [ y>> ] dip ⋀ ] 2bi ⋁ ; -METHOD: ⋀ { □ ⋁ } [ x>> ⋀ ] [ y>> ⋀ ] 2bi ⋁ ; - -METHOD: ⋀ { □ □ } \ ⋀ boa ; - -GENERIC: ⋁ ( x y -- expr ) - -METHOD: ⋁ { ⊤ □ } drop ; -METHOD: ⋁ { □ ⊤ } nip ; -METHOD: ⋁ { ⊥ □ } nip ; -METHOD: ⋁ { □ ⊥ } drop ; - -METHOD: ⋁ { □ □ } \ ⋁ boa ; - -GENERIC: ¬ ( x -- expr ) - -METHOD: ¬ { ⊤ } drop ⊥ ; -METHOD: ¬ { ⊥ } drop ⊤ ; - -METHOD: ¬ { ⋀ } [ x>> ¬ ] [ y>> ¬ ] bi ⋁ ; -METHOD: ¬ { ⋁ } [ x>> ¬ ] [ y>> ¬ ] bi ⋀ ; - -METHOD: ¬ { □ } \ ¬ boa ; - -: → ( x y -- expr ) ¬ ⋀ ; -: ⊕ ( x y -- expr ) [ ⋁ ] [ ⋀ ¬ ] 2bi ⋀ ; -: ≣ ( x y -- expr ) [ ⋀ ] [ [ ¬ ] bi@ ⋀ ] 2bi ⋁ ; - -GENERIC: (cnf) ( expr -- cnf ) - -METHOD: (cnf) { ⋀ } [ x>> (cnf) ] [ y>> (cnf) ] bi append ; -METHOD: (cnf) { □ } 1array ; - -GENERIC: cnf ( expr -- cnf ) - -METHOD: cnf { ⋁ } [ x>> cnf ] [ y>> cnf ] bi append ; -METHOD: cnf { □ } (cnf) 1array ; - -GENERIC: satisfiable? ( expr -- ? ) - -METHOD: satisfiable? { ⊤ } drop t ; -METHOD: satisfiable? { ⊥ } drop f ; - -: partition ( seq quot -- left right ) - [ [ not ] compose filter ] [ filter ] 2bi ; inline - -: (satisfiable?) ( seq -- ? ) - [ \ ¬ instance? ] partition [ x>> ] map intersect empty? ; - -METHOD: satisfiable? { □ } - cnf [ (satisfiable?) ] any? ; - -GENERIC: (expr.) ( expr -- ) - -METHOD: (expr.) { □ } pprint ; - -: op. ( expr -- ) - "(" write - [ x>> (expr.) ] - [ bl class pprint bl ] - [ y>> (expr.) ] - tri - ")" write ; - -METHOD: (expr.) { ⋀ } op. ; -METHOD: (expr.) { ⋁ } op. ; -METHOD: (expr.) { ¬ } [ class pprint ] [ x>> (expr.) ] bi ; - -: expr. ( expr -- ) (expr.) nl ; diff --git a/boolean-expr/summary.txt b/boolean-expr/summary.txt deleted file mode 100644 index 9b51186..0000000 --- a/boolean-expr/summary.txt +++ /dev/null @@ -1 +0,0 @@ -Simple boolean expression evaluator and simplifier