Skip to content

Instantly share code, notes, and snippets.

@blrB
Last active May 12, 2017 19:23
Show Gist options
  • Save blrB/61b6fd830ed4f5c850a6baf9c327de3d to your computer and use it in GitHub Desktop.
Save blrB/61b6fd830ed4f5c850a6baf9c327de3d to your computer and use it in GitHub Desktop.
If string(variable formula) is propositional formula, function canConvolutionFormula(formula) will return "true"
function canConvolutionFormula(formula){
var replaceForSubFormula = "A";
var atomOrConst = "([A-Z]|[0-1])";
var atomOrConstInPatter = "<ATOM_OR_CONST>";
var regFormula = "([(][!]<ATOM_OR_CONST>[)])|([(]<ATOM_OR_CONST>((&)|(\\|)|(->)|(~))<ATOM_OR_CONST>[)])";
regFormula = regFormula.replace(new RegExp(atomOrConstInPatter, 'g'), atomOrConst);
regFormula = new RegExp(regFormula);
var oldFormula;
do {
oldFormula = formula;
formula = formula.replace(regFormula, replaceForSubFormula);
} while (formula != oldFormula);
var arrOutput = formula.match(new RegExp(atomOrConst, 'g'));
if ((formula.length == 1) && (arrOutput != null) && (arrOutput.length == 1)) {
return true;
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment