Skip to content

Logic library provides convenient way to represent logic expression. It also allows you to do basic operations with logic expression. Additionally, the library features include a generation of a random logic expression.

Notifications You must be signed in to change notification settings

crucian11/Logic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Logic

Logic library provides a convenient way of representing a logic expression. It also allows you to perform basic operations with a logic expression(generate a truth table, find the solution with a given tuple of values). Additionally, the library features include a generation of a random logic expression, equivalent and not equivalent to a particular expression.

##Usage ####LogicExpression class First of all, you should instantiate a LogicExpression class by passing string representation into its constructor:

LogicExpression expression = new LogicExpression("p" + LogicSymbols.AND + "q" + LogicSymbols.EQU + "r");

Note that you can use either a set of LogicSymbols constants or raw unicode symbols, while creating an object:

LogicExpression expression2 = new LogicExpression("p∧q→r");

There are four operations supported by this library:

  • conjunction (LogicSymbols.AND or \u2227 unicode symbol);
  • disjunction (LogicSymbols.OR or \u2227 unicode symbol);
  • implication (LogicSymbols.IMP or \u2227 unicode symbol);
  • equivalence (LogicSymbols.EQU or \u2227 unicode symbol).

Before performing some operation, a reversed polish notation should be created, you can do it by calling makeRPolishRecord method:

expression.makeRPolishRecord();

This method creates a notation and stores it in a California property. After that, this property is used in other methods of the class. Let's see all the rest of the methods:

  • EOperand calculate() method performs a computation with existing values stored in a operands property;
  • EOperand calculate(params bool[] x) method performs a computation with given tuple of boolean values;
  • TruthTable generateTruthTable() method generates a truth table.

LEGenerator class

First of all, you should create an object-generator:

LEGenerator g = new LEGenerator();

LEGenerator class has an interface that's similar to a Random class. There are few methods in the class:

  • LogicExpression next() generates a random logic expression;
  • LogicExpression next(int maxVarsNumber) does as same as the next method, but it allows you to limit a max amount of variables;
  • LogicExpression nextEqual(LogicExpression exp) alters the expression using propositional logic transformation rules;
  • LogicExpression nextNotEqual(LogicExpression exp) generates a not equal expression to the passed one;
  • LogicExpression nextNotEqual(LogicExpression exp, int maxVarsNumber) does the same as the nextNotEqual method with limitation of a max amount of variables.

Also, there are few additional classes in the library:

  • ExpressionPart represents a single part of a logic expression(bracket, operation, operand ect.);
  • EOperand is one of the ExpressionPart derived classes, represents a particular operand in logic expression, there's a boolean "value" property that's used in calculate methods;
  • TruthTable represents truth table for a particular logic expression, contains method isTautology() for its further analyzying.

About

Logic library provides convenient way to represent logic expression. It also allows you to do basic operations with logic expression. Additionally, the library features include a generation of a random logic expression.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages