Last active
May 12, 2017 19:23
-
-
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"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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