Code Monkey home page Code Monkey logo

clover's Introduction

Clover

Build Status

概要

一階述語論理式の証明を行うCommon Lisp実装のツールです。以下のアルゴリズムを実装しています。

  • Knuth-Bendixの完備化アルゴリズム
  • 導出原理(Resolution Principle)

インストール

バイナリ

LinuxとWindows向けにビルドしたバイナリをダウンロード可能です。

Releases

コマンドラインからのバッチ実行

完備化処理については、コマンドラインからバッチ的に実行することができます。

$ cat input_file.txt
(VAR x y z)
(RULES
c -> a
g(x) -> x
f(x, b) -> x
f(x, g(y)) -> f(g(x), y)
f(b, z) -> c
)
$ ./clover-linux-x86_64_ver2.4.0 input_file.txt
YES

(VAR x)
(RULES
 f(x,A) -> x
 f(A,x) -> A
 B -> A
 g(x) -> x
 C -> A
)
(COMMENT
 A < B < C < F < G
)
$

REPLの実行

導出原理と完備化による証明を実行することができます。

:def-axiomコマンドを用いて、証明したい式の前提となる式を定義します。 その後、証明したい式を入力することで証明を試行します。

導出原理による証明例

$ ./clover-linux-x86_64_ver2.2.1
Command help
    :help                    show this help
    :quit                    quit from REPL
    :def-axiom    <name>     define an axiomatic system <name>
    :show-axiom              enumerate all axiomatic system that are currently defined
    :set-axiom    <name>     set current axiomatic system to <name>
    :set-history             keep resolution history. this option automatically
                             enabled if save-tree option on.
    :unset-history           disable history
    :set-profiler            enable statistical profiler
    :unset-profiler          disable statistical profiler
    :save-tree    <path>     save Graphviz code tree to <path>
    :unsave-tree
(NIL)>>> :def-axiom human
input . to finish definition
axiom[1]>>> !love(x,y) | !love(y,x) | happy(y)
axiom[2]>>> !love(x,y) | !love(y,x) | happy(x)
axiom[3]>>> love(A,B)
axiom[4]>>> love(B,A)
axiom[5]>>> .
(human)>>> :set-history
(human)>>> happy(A)

Evaluation took:
  0.050 seconds of real time
  0.049196 seconds of total run time (0.049196 user, 0.000000 system)
  98.00% CPU
  303 lambdas converted
  98,007,272 processor cycles
  16,910,960 bytes consed

PROVABLE under the human

 □ ←← love(A,B)
 ↑
 ↑
 !love(A,B)  ←← love(B,A)
      ↑
      ↑
 !love(A,x) | !love(x,A)  ←← !happy(A)
             ↑
             ↑
 !love(y,x) | !love(x,y) | happy(y)

等式証明例

入力された式が等式である場合は、完備化を試みます。 完備化が成功した場合は、項書き換え系の元で等式を証明することができます。

(NIL)>>> :def-axiom group
input . to finish definition
axiom[1]>>> plus(ZERO,x) = x
axiom[2]>>> plus(plus(x,y),z) = plus(x, plus(y,z))
axiom[3]>>> plus(i(x),x) = ZERO
axiom[4]>>> .
Detected that a set of equations has been inputted.
Do you want to execute completion algorithm?  (yes or no) yes

The completion process was successful:
i(plus(y,x))=>plus(i(x),i(y))
i(i(x))=>x
i(ZERO)=>ZERO
plus(x,ZERO)=>x
plus(x,i(x))=>ZERO
plus(x,plus(i(x),y))=>y
plus(i(x),plus(x,y))=>y
plus(ZERO,x)=>x
plus(plus(x,y),z)=>plus(x,plus(y,z))
plus(i(x),x)=>ZERO
(group)>>> plus(plus(x,y),plus(z,w)) = plus(x, plus(y, plus(z, w)))
The equation can be PROVED under the axiom group

irreducible form under the group:
plus(x,plus(y,plus(z,w))) = plus(x,plus(y,plus(z,w)))

式の入力形式

REPL

前提となる式を定義する際には、<premise expression>の形式で入力します。 それ以外の場合は、<consequence expression>の形式で入力します。

<premise expression> ::= <equation> 
                       | <premise logical expression>

<consequence expression> ::= <equation>
                           | <consequence logical expression>
<equation> ::= <term> "=" <term> 
             | <term> "!=" <term>

<premise logical expression> ::= <symbol> <argument>
                               | "!" <symbol> <argument>
                               | <premise logical expression> "|" <premise logical expression>

<consequence logical expression> ::= <symbol> <argument>
                                   | "!" <symbol> <argument>
                                   | <consequence logical expression> "&" <consequence logical expression>

<argument> ::= "(" ")"
             | "(" <term sequence> ")"

<term> ::= "[" "]"
         | "[" <term sequence> "]"
         | <constant>
         | <symbol>
         | <symbol> "(" <term sequence> ")"

<term sequence> ::= <term>
                  | <term sequence> "," <term>

<symbol>   ::= "a" | "b" | "c" | "d" | ... | "z" | ... | "aaa" | ...
<constant> ::= "A" | "B" | "C" | "D" | ... | "Z" | ... | "AAA" | ...

コマンドラインからのバッチ実行時のファイル形式

todo

Author

  • moratori

Copyright

Copyright (c) 2018 moratori

clover's People

Contributors

moratori avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

clover's Issues

単一化子のリバース

単一化子を遡り、入力変数が最終的になにに置き換えられたか表示できるようにする

:set-profilerを実装

sbclの場合に限り、sb-profileを用いて、実行時の統計情報を表示する

別フォーマットをパースした時の式集合の同値性について

clover/src/parser.lisp

Lines 35 to 66 in 770ff24

(defun parse-premise-logical-expression (string)
(handler-case
(with-lexer (lexer 'premise-expression-lexer string)
(with-token-reader (token-reader lexer)
(parse-with-lexer token-reader %premise-expression-parser)))
(condition (con)
(error (make-condition 'expr-parse-error
:message
(format nil "~A error occurred while parsing string: ~A" con string))))))
(defun parse-conseq-logical-expression (string)
(handler-case
(with-lexer (lexer 'conseq-expression-lexer string)
(with-token-reader (token-reader lexer)
(parse-with-lexer token-reader %conseq-expression-parser)))
(condition (con)
(error (make-condition 'expr-parse-error
:message
(format nil "~A error occurred while parsing string: ~A" con string))))))
(defun parse-mkbtt-expression (string)
(handler-case
(with-lexer (lexer 'mkbtt-toplevel-lexer string)
(with-token-reader (token-reader lexer)
(convert-to-equation-set
(mkbtt-form
(parse-with-lexer token-reader %mkbtt-form-parser)))))
(condition (con)
(error (make-condition 'expr-parse-error
:message
(format nil "~A error occurred while parsing string: ~A" con string))))))

項の解釈

下記の様な項表現は、「5」として表されるべき.
項の解釈処理をユーザーが別途で定義できるようにする

successor(successor(successor(successor(successor(ZERO)))))

不可解なエラーの発生

BD94_collapse.trs

f(x,C)=>x
f(C,x)=>C
B=>C
A=>C
g(x)=>x
;
;
; compilation unit aborted
; compilation unit aborted
; compilation unit aborted
;   caught 1 fatal ERROR condition
;   caught 1 fatal ERROR condition
;   caught 1 fatal ERROR condition
;
;
; compilation unit aborted
; compilation unit aborted
; compilation unit aborted
;   caught 1 fatal ERROR condition
;   caught 1 fatal ERROR condition
;   caught 1 fatal ERROR condition

TPTP_GRP460-1_theory.trs

WARNING: lparallel: Replacing lost or dead worker.
unhandled condition occurred: The task was killed.

SK90_3.24.trs

YES

(VAR x)
(RULES
 c(c(c(x))) -> c(c(x))
 b(x) -> c(x)
 a(x) -> c(x)
)
(COMMENT
 C < B < A
)
;
;
; compilation unit aborted
; compilation unit aborted
; compilation unit aborted
;   caught 1 fatal ERROR condition
;   caught 1 fatal ERROR condition
;
;   caught 1 fatal ERROR condition
;
;   caught 1 fatal ERROR condition
; compilation unit aborted
;   caught 1 fatal ERROR condition
;
; compilation unit aborted
;   caught 1 fatal ERROR condition

TPTP_SWV262-2_theory.trs

YES

(VAR z w x y)
(RULES
 c_union(c_message_oparts(x),c_message_oparts(y),TC_MESSAGE_OMSG) -> c_message_oparts(c_union(x,y,TC_MESSAGE_OMSG))
 c_union(c_insert(x,y,w),z,w) -> c_insert(x,c_union(y,z,w),w)
 c_union(C_EMPTYSET,y,x) -> y
)
(COMMENT
 C_EMPTYSET < TC_MESSAGE_OMSG < C_MESSAGE_OPARTS < C_INSERT < C_UNION
)
;
; compilation unit aborted
; compilation unit aborted
;
;   caught 1 fatal ERROR condition
; compilation unit aborted
;   caught 1 fatal ERROR condition

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.