Opened 9 years ago

Closed 8 years ago

#15018 closed enhancement (fixed)

add recover_formula and prefix_to_infix functions to logicparser.py

Reported by: Paul Scurek Owned by: Paul Scurek
Priority: major Milestone: sage-6.3
Component: misc Keywords: logic, logicparser, prefix, infix
Cc: Merged in:
Authors: Paul Scurek Reviewers: Frédéric Chapoton, Travis Scrimshaw
Report Upstream: N/A Work issues:
Branch: 521ba42 (Commits, GitHub, GitLab) Commit: 521ba42dc81c1ebe1a13e0c9acff72cdcced6727
Dependencies: #14951, #14952, #15013 Stopgaps:

Status badges

Description

In the patch for this ticket, the functions recover_formula and prefix_to_infix are added to logicparser.py in the logic module. The function recover_formula allows for the recovery of a boolean formula from its parse tree. The function prefix_to_infix converts a parse tree from prefix form to infix form. Here are some examples.

sage: import sage.logic.logicparser as logicparser
sage: t = ['->', ['~', 'a'], ['|', 'c', ['~', 'd']]]
sage: logicparser.recover_formula(t)
'~a->(c|~d)'
sage: import sage.logic.logicparser as logicparser
sage: t = ['->', ['~', 'a'], ['|', 'c', ['~', 'd']]]
sage: logicparser.prefix_to_infix(t)
[['~', 'a'], '->', ['c', '|', ['~', 'd']]]

Attachments (5)

trac_14951_tokenize_tree_fix.patch (41.3 KB) - added by Paul Scurek 9 years ago.
apply first
trac_14952_logic_if_while_syntax.patch (25.6 KB) - added by Paul Scurek 9 years ago.
apply second
trac_15013_logic_docstrings.patch (98.3 KB) - added by Paul Scurek 9 years ago.
apply third
trac_15018_recover_formula.2.patch (8.8 KB) - added by Paul Scurek 9 years ago.
Apply this last. This is the patch for this ticket, but depends on the previous 3.
trac_15018_recover_formula.patch (8.8 KB) - added by Paul Scurek 9 years ago.
This file is the same as trac_15018_recover_formula.2.patch.

Download all attachments as: .zip

Change History (21)

comment:1 Changed 9 years ago by Paul Scurek

Type: PLEASE CHANGEenhancement

Changed 9 years ago by Paul Scurek

apply first

Changed 9 years ago by Paul Scurek

apply second

Changed 9 years ago by Paul Scurek

apply third

comment:2 Changed 9 years ago by William Stein

Referee:

  • trivial typo: "argrument" (in multiple places!)

  • delete parens here: "prefix_to_infix() takes a parse tree as input"

  • Someday somebody should change this... type(tree[1]) is ListType to isinstance(tree[1], list).

That's it.

Changed 9 years ago by Paul Scurek

Apply this last. This is the patch for this ticket, but depends on the previous 3.

Changed 9 years ago by Paul Scurek

This file is the same as trac_15018_recover_formula.2.patch.

comment:3 Changed 9 years ago by Paul Scurek

I forgot to check the box for replacing the file with the same name. That is why there are attachments called trac_15018_recover_formula.patch and trac_15018_recover_formula.2.patch. They are exactly the same, so only apply one of them when testing the patch. I would get right of one of them, but I don't see an option for removing attachments.

comment:4 Changed 9 years ago by Paul Scurek

Status: newneeds_review

comment:5 Changed 9 years ago by Paul Scurek

The last patch listed in the attachments, trac_15018_recover_formula.patch, is the only patch that should be integrated into sage for this ticket. The first three patches are the patches from the dependencies for this ticket that were placed here for the convenience of the reviewer. The patch, trac_15018_recover_formula.2.patch is identical to trac_15018_recover_formula.patch.

Last edited 9 years ago by Paul Scurek (previous) (diff)

comment:6 Changed 9 years ago by Volker Braun

Status: needs_reviewneeds_work

First patch of the series does not apply any more, please fix.

comment:7 Changed 9 years ago by Travis Scrimshaw

Branch: public/ticket/15018
Commit: 86e7f6e0cb68c59a11fd05b7652f55b2b8378fdf
Status: needs_workneeds_review

I've rebased this and made some minor doc changes. If everything is good, then positive review.


New commits:

9798dcaTrac 15018: added recover_formula, recover_formula_internal, prefix_to_infix, and to_infix_internal to logicparser.py
22ec476Minor review tweaks.
bb23f1bMerge branch 'develop' into public/ticket/15018
86e7f6eMerge branch 'develop' into public/ticket/15018

comment:8 Changed 9 years ago by For batch modifications

Milestone: sage-6.1sage-6.2

comment:9 Changed 8 years ago by Frédéric Chapoton

Status: needs_reviewneeds_work
Work issues: needs rebase

comment:10 Changed 8 years ago by For batch modifications

Milestone: sage-6.2sage-6.3

comment:11 Changed 8 years ago by git

Commit: 86e7f6e0cb68c59a11fd05b7652f55b2b8378fdfb4e8f25e140c688315d026add7318c65211e367c

Branch pushed to git repo; I updated commit sha1. New commits:

b4e8f25Merge branch 'public/ticket/15018' of trac.sagemath.org:sage into public/ticket/15018

comment:12 Changed 8 years ago by Travis Scrimshaw

Status: needs_workneeds_review
Work issues: needs rebase

comment:13 Changed 8 years ago by git

Commit: b4e8f25e140c688315d026add7318c65211e367c521ba42dc81c1ebe1a13e0c9acff72cdcced6727

Branch pushed to git repo; I updated commit sha1. New commits:

521ba42change raise syntax to python3 style

comment:14 Changed 8 years ago by Frédéric Chapoton

Reviewers: Frédéric Chapoton
Status: needs_reviewpositive_review

looks good to me, positive review.

comment:15 Changed 8 years ago by Travis Scrimshaw

Reviewers: Frédéric ChapotonFrédéric Chapoton, Travis Scrimshaw

Thanks Frederic.

comment:16 Changed 8 years ago by Volker Braun

Branch: public/ticket/15018521ba42dc81c1ebe1a13e0c9acff72cdcced6727
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.