Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor readability optimisation improvements #138

Merged
merged 3 commits into from
Feb 2, 2017
Merged

Conversation

MattWindsor91
Copy link
Collaborator

This is part of the #136 effort, and adds a few new heuristics to the integer optimisation logic such as

x + 5 + y + 12 -> x + y + 17
x + (y - 5) -> (x + y) - 5
x + 5 <= 6 -> x <= 1
x - 6 > 0 -> x > 6

and so on.

This doesn't do much for us in practice, as most of the problem for #136 is in complex nested Booleans, though it's managed to simplify

    exists ArcFoot:Set<ArcNode> :: (
        acc(ArcFoot) &*&
        (
            ((before_28_1_x in ArcFoot && 1 <= before_28_1_x.count) &&
                ((goal_36_n <= 2) ||
                    (goal_35_x != before_28_1_x) ||
                    (goal_35_x != before_28_1_x) ||
                    ((((goal_36_n - 2) + 1) <= 0) ||
                        (goal_35_x in ArcFoot && ((goal_36_n - 2) + 1) <= goal_35_x.count))) &&
                ((goal_35_x == before_28_1_x) ||
                    (goal_36_n <= 2) ||
                    (goal_35_x != before_28_1_x) ||
                    (goal_35_x != before_28_1_x) ||
                    ((((goal_36_n + (goal_36_n - 2)) + 1) <= 0) ||
                        (goal_35_x in ArcFoot && ((goal_36_n + (goal_36_n - 2)) + 1) <= goal_35_x.count))) &&
                ((goal_35_x == before_28_1_x) ||
                    (goal_36_n <= 2) ||
                    (goal_35_x != before_28_1_x) ||
                    (((goal_36_n + (goal_36_n - 2)) <= 0) ||
                        (goal_35_x in ArcFoot && (goal_36_n + (goal_36_n - 2)) <= goal_35_x.count))) &&
                ((goal_35_x == before_28_1_x) ||
                    (goal_35_x != before_28_1_x) ||
                    (((goal_36_n + 1) <= 0) ||
                        (goal_35_x in ArcFoot && (goal_36_n + 1) <= goal_35_x.count))) &&
                ((goal_35_x != before_28_1_x) ||
                    (goal_36_n <= 2) ||
                    (((goal_36_n - 2) <= 0) ||
                        (goal_35_x in ArcFoot && (goal_36_n - 2) <= goal_35_x.count))) &&
                ((goal_35_x == before_28_1_x) ||
                    ((goal_36_n <= 0) ||
                        (goal_35_x in ArcFoot && goal_36_n <= goal_35_x.count))))
        )
    )

to

    exists ArcFoot:Set<ArcNode> :: (
        acc(ArcFoot) &*&
        (
            ((before_28_1_x in ArcFoot && 1 <= before_28_1_x.count) &&
                ((goal_36_n <= 2) ||
                    (goal_35_x != before_28_1_x) ||
                    (goal_35_x != before_28_1_x) ||
                    ((goal_36_n <= 1) ||
                        (goal_35_x in ArcFoot && (goal_36_n - 1) <= goal_35_x.count))) &&
                ((goal_35_x == before_28_1_x) ||
                    (goal_36_n <= 2) ||
                    (goal_35_x != before_28_1_x) ||
                    (goal_35_x != before_28_1_x) ||
                    (((goal_36_n + goal_36_n) <= 1) ||
                        (goal_35_x in ArcFoot && ((goal_36_n + goal_36_n) - 1) <= goal_35_x.count))) &&
                ((goal_35_x == before_28_1_x) ||
                    (goal_36_n <= 2) ||
                    (goal_35_x != before_28_1_x) ||
                    (((goal_36_n + goal_36_n) <= 2) ||
                        (goal_35_x in ArcFoot && ((goal_36_n + goal_36_n) - 2) <= goal_35_x.count))) &&
                ((goal_35_x == before_28_1_x) ||
                    (goal_35_x != before_28_1_x) ||
                    ((goal_36_n <= -1) ||
                        (goal_35_x in ArcFoot && (goal_36_n + 1) <= goal_35_x.count))) &&
                ((goal_35_x != before_28_1_x) ||
                    (goal_36_n <= 2) ||
                    ((goal_36_n <= 2) ||
                        (goal_35_x in ArcFoot && (goal_36_n - 2) <= goal_35_x.count))) &&
                ((goal_35_x == before_28_1_x) ||
                    ((goal_36_n <= 0) ||
                        (goal_35_x in ArcFoot && goal_36_n <= goal_35_x.count))))
        )
    )

@MattWindsor91
Copy link
Collaborator Author

Note that the biggest problem we have in the above query is statements of the form

X==Y || X!=Y

which could be blown away with some effort, but making that work in practice might be akin to writing a full blown symbolic evaluator.

@septract
Copy link
Owner

septract commented Feb 2, 2017

This looks fine to me.

@MattWindsor91 MattWindsor91 merged commit 3772421 into master Feb 2, 2017
@MattWindsor91 MattWindsor91 deleted the mw-grass-optimise branch February 2, 2017 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants