2 に答える
これは非常に興味深いプロジェクトです:)。私は今、モーダルロジックについての論文を書いています。
まず第一に、既存のソルバーでは非常に標準的な InToHyLo 入力形式を使用することをお勧めします。
InToHyLo 形式は次のようになります。
file ::= ['begin'] dml ['end']
fml ::= '(' fml ')' (* parentheses *)
| '1' | 'true' | 'True' | 'TRUE' (* truth *)
| '0' | 'false' | 'False' | 'FALSE' (* falsehood *)
| '~' fml | '-' fml (* negation *)
| '<>' fml | '<' id '>' fml (* diamonds *)
| '[]' fml | '[' id ']' fml (* boxes *)
| fml '&' fml (* conjunction *)
| fml '|' fml (* disjunction *)
| fml '->' fml (* implication *)
| fml '<->' fml (* equivalence *)
| id (* prop. var. *)
where identifiers (id) are arbitrary nonempty alphanumeric sequences: (['A'-'Z' 'a'-'z' '0'-'9']+)
数式の解析を簡素化し、実際の問題に集中するには: インスタンスを解決します。のような既存のパーサーを使用することをお勧めしますflex/bison
。
あなたの問題をインターネットで調べると (私は Python の専門家ではありません)、ライブラリ " http://pyparsing.wikispaces.com " が解析のリファレンスのようです。
その後、次のように Bison を使用するだけで、ファイルが完全に解析されます。
これが私の Bison ファイルです (ソルバー C++ で Flex/Bison を使用する場合):
/*
*
* Compile with bison.
*/
/*** Code inserted at the begin of the file. ***/
%{
#include <stdlib.h>
#include <list>
#include "Formula.h"
// yylex exists
extern int yylex();
extern char yytext[];
void yyerror(char *msg);
%}
/*** Bison declarations ***/
%union
{
bool bval;
operator_t opval;
char *sval;
TermPtr *term;
}
%token LROUND RROUND
%left IFF
%left IMP
%left OR
%left AND
%right DIAMOND
%right BOX
%right NOT
%token VALUE
%token IDENTIFIER
%type<bval> VALUE
%type<sval> IDENTIFIER
%type<term> Formula BooleanValue BooleanFormula ModalFormula PropositionalVariable UnaryFormula
%type<opval> BinaryBoolOperator UnaryBoolOperator ModalOperator
%start Start
%%
Start:
| Formula { (Formula::getFormula()).setRoot(*$1); }
;
Formula: BooleanFormula { $$ = $1; }
| ModalFormula { $$ = $1; }
| UnaryFormula { $$ = $1; }
| LROUND Formula RROUND { $$ = $2; }
;
BooleanValue: VALUE { $$ = new TermPtr( (Term*) new BooleanValue($1) ); }
;
PropositionalVariable: IDENTIFIER { $$ = new TermPtr( (Term*) new PropositionalVar($1) ); }
;
BooleanFormula: Formula BinaryBoolOperator Formula {
$$ = new TermPtr( (Term*) new BooleanOp(*$1, *$3, $2) ); /* can be (A OR B) or (A AND B) */
delete($3);
delete($1);
}
| Formula IMP Formula {
($1)->Negate();
$$ = new TermPtr( (Term*) new BooleanOp(*$1, *$3, O_OR) ); /* A -> B can be written : (¬A v B) */
delete($3);
delete($1);
}
| PropositionalVariable IFF PropositionalVariable {
PropositionalVar *Copy1 = new PropositionalVar( *((PropositionalVar*)$1->getPtr()) );
PropositionalVar *Copy3 = new PropositionalVar( *((PropositionalVar*)$3->getPtr()) );
TermPtr Negated1( (Term*)Copy1, $1->isNegated() );
TermPtr Negated3( (Term*)Copy3, $3->isNegated() );
Negated1.Negate();
Negated3.Negate();
TermPtr Or1( (Term*) new BooleanOp(Negated1, *$3, O_OR) ); /* Or1 = (¬A v B) */
TermPtr Or2( (Term*) new BooleanOp(Negated3, *$1, O_OR) ); /* Or2 = (¬B v A) */
$$ = new TermPtr( (Term*) new BooleanOp(Or1, Or2, O_AND) ); /* We add : (Or1 AND OrB) */
delete($3);
delete($1);
}
;
ModalFormula: ModalOperator LROUND Formula RROUND {
$$ = new TermPtr( (Term*) new ModalOp(*$3, $1) );
delete($3);
}
|
ModalOperator ModalFormula {
$$ = new TermPtr( (Term*) new ModalOp(*$2, $1) );
delete($2);
}
|
ModalOperator UnaryFormula {
$$ = new TermPtr( (Term*) new ModalOp(*$2, $1) );
delete($2);
}
;
UnaryFormula: BooleanValue { $$ = $1; }
| PropositionalVariable { $$ = $1; }
|
UnaryBoolOperator UnaryFormula {
if ($1 == O_NOT) {
($2)->Negate();
}
$$ = $2;
}
|
UnaryBoolOperator ModalFormula {
if ($1 == O_NOT) {
($2)->Negate();
}
$$ = $2;
}
|
UnaryBoolOperator LROUND Formula RROUND {
if ($1 == O_NOT) {
($3)->Negate();
}
$$ = $3;
}
;
ModalOperator: BOX { $$ = O_BOX; }
| DIAMOND { $$ = O_DIAMOND; }
;
BinaryBoolOperator: AND { $$ = O_AND; }
| OR { $$ = O_OR; }
;
UnaryBoolOperator: NOT { $$ = O_NOT; }
;
/*** Code inserted at the and of the file ***/
%%
void yyerror(char *msg)
{
printf("PARSER: %s", msg);
if (yytext[0] != 0)
printf(" near token '%s'\n", yytext);
else
printf("\n");
exit(-1);
}
それを適応させることで、モーダル論理式を完全かつ再帰的に解析できるようになります:)。
後で、ソルバーを既存のタブロー ソルバー (たとえば、 Spartacusなど)に挑戦させたい場合。これらのソルバーはほとんどの場合、開いている最大の Tableau に応答していることを忘れないでください。そのため、ソリューションの Kripke モデルを見つけたい場合は、これらのソルバーの方が確実に高速になります ;)
私はあなたの質問を手伝ってくれることを願っています.理論的ではありませんが、残念ながら私はこのためのPythonを習得していません:/.
ソルバーの成功をお祈りします。
よろしくお願いします。
InToHyLo を使用するという私の提案を受け入れる場合、私は最近、モーダル ロジック K の Kripke モデルのチェッカーに取り組みました。検証者/
最近、PAAR'2016 で公開されました。
モーダル ロジック K の Kripke モデルのチェックについて、Jean-Marie Lagniez、Daniel Le Berre、Tiago de Lima、Valentin Montmirail、自動推論の実践的側面に関する第 5 回ワークショップの議事録 (PAAR 2016)