def polish_notation(self): r""" Convert the calling boolean formula into polish notation INPUT: - ``self`` -- calling object OUTPUT: A string representation of the formula in polish notation. EXAMPLES: This example illustrates converting a formula to polish notation. :: sage: import sage.logic.propcalc as propcalc sage: f = propcalc.formula("~~a|(c->b)") sage: f.polish_notation() '|~~a->cb' :: sage: g = propcalc.formula("(a|~b)->c") sage: g.polish_notation() '->|a~bc' AUTHORS: - Paul Scurek (2013-08-03) """ return ''.join(flatten(logicparser.polish_parse(repr(self))))
def full_tree(self): r""" This function returns a full syntax parse tree of the calling boolean formula. INPUT: self -- the calling object, which is a boolean formula OUTPUT: Returns a list containing the full syntax parse tree of self, with the symbols arranged from left to right as in polish notation. EXAMPLES: sage: import sage.logic.propcalc as propcalc sage: s = propcalc.formula("a->(b&c)") sage: s.full_tree() ['->', 'a', ['&', 'b', 'c']] sage: t = propcalc.formula("a & ((~b | c) ^ a -> c) <-> ~b") sage: t.full_tree() ['<->', ['&', 'a', ['->', ['^', ['|', ['~', 'b'], 'c'], 'a'], 'c']], ['~', 'b']] sage: f = propcalc.formula("~~(a&~b)") sage: f.full_tree() ['~', ['~', ['&', 'a', ['~', 'b']]]] """ return logicparser.polish_parse(repr(self))
def full_tree(self): r""" Return a full syntax parse tree of the calling formula. INPUT: - ``self`` -- calling object. This is a boolean formula. OUTPUT: The full syntax parse tree as a nested list EXAMPLES: This example shows how to find the full syntax parse tree of a formula. :: sage: import sage.logic.propcalc as propcalc sage: s = propcalc.formula("a->(b&c)") sage: s.full_tree() ['->', 'a', ['&', 'b', 'c']] :: sage: t = propcalc.formula("a & ((~b | c) ^ a -> c) <-> ~b") sage: t.full_tree() ['<->', ['&', 'a', ['->', ['^', ['|', ['~', 'b'], 'c'], 'a'], 'c']], ['~', 'b']] :: sage: f = propcalc.formula("~~(a&~b)") sage: f.full_tree() ['~', ['~', ['&', 'a', ['~', 'b']]]] .. NOTE:: This function is used by other functions in the logic module that perform syntactic operations on a boolean formula. AUTHORS: - Paul Scurek (2013-08-03) """ return logicparser.polish_parse(repr(self))
def polish_notation(self): r""" This function returns the calling formula in polish notation in the form of a string. INPUT: self -- the calling object, which is a boolean formula OUTPUT: Returns the caling formula in polish notation as a string EXAMPLES: sage: import sage.logic.propcalc as propcalc sage: f = propcalc.formula("~~a|(c->b)") sage: f.polish_notation() '|~~a->cb' sage: g = propcalc.formula("(a|~b)->c") sage: g.polish_notation() '->|a~bc' """ return ''.join(flatten(logicparser.polish_parse(repr(self))))