Skip to content

[TG-634] Logical expression building utility #1424

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

Closed
wants to merge 2 commits into from
Closed

[TG-634] Logical expression building utility #1424

wants to merge 2 commits into from

Conversation

LAJW
Copy link
Contributor

@LAJW LAJW commented Sep 26, 2017

This PR implements an exprt wrapper for constructing logical expression hierarchies using C++ operators.

Additionally, this PR contains small refactor on one of the most used string functions to show that it's working as intended.

For example, it lets following code:

exprt res_length=plus_exprt( 
  s1.length(), minus_exprt(end_index, start_index));
binary_relation_exprt prem(end_index, ID_gt, start_index); 
implies_exprt a1(prem, equal_exprt(res.length(), res_length));

be expressed this way:

exprt a1 = end_index > start_index >>=
           axt(s1.length()) + end_index - start_index == axt(res.length());

Part 2 of String Refinement overhaul PR

@LAJW
Copy link
Contributor Author

LAJW commented Sep 26, 2017

@reuk @jasigal @romainbrenguier Take a look if you have some spare time on your hands.

Copy link
Contributor

@reuk reuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and idiomatic 👍

Copy link
Contributor

@jasigal jasigal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good :)

axt operator==(const axt& rhs) const
{ return axt(equal_exprt(expr_, rhs.expr_)); }
// Implication
axt operator>>=(const axt& rhs) const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not use ->?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because -> is an unary operator. An alias for (*ptr).<method_name>

axt operator||(const axt& rhs) const
{ return axt(or_exprt(expr_, rhs.expr_)); }
axt operator[](const axt& index) const
{ return axt(to_string_expr(expr_)[index.expr_]); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we cast to a string expression? Is this only going to be for the string solver?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now it's only used in the string solver, but ultimately this should represent index_of_exprt (taking an array_exprt on the left) this will be unified once the new version of the string solver is merged as strings will be represented by arrays.

{ return !(*this<rhs); }
axt operator<=(const axt& rhs) const
{ return !(*this>rhs); }
axt operator==(const axt& rhs) const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we also add != for notequal_exprt?

axt operator||(const axt& rhs) const
{ return axt(or_exprt(expr_, rhs.expr_)); }
axt operator[](const axt& index) const
{ return axt(to_string_expr(expr_)[index.expr_]); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to use this for index_exprt in case it's not a string_exprt

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I shall wait then until they become one and the same thing.

axt operator<(const axt& rhs) const
{ return axt(binary_relation_exprt(expr_, ID_lt, rhs.expr_)); }
axt operator>=(const axt& rhs) const
{ return !(*this<rhs); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use axt(binary_relation_exprt(expr_, ID_ge, rhs.expr_))

axt operator>=(const axt& rhs) const
{ return !(*this<rhs); }
axt operator<=(const axt& rhs) const
{ return !(*this>rhs); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use axt(binary_relation_exprt(expr_, ID_le, rhs.expr_))

@martin-cs
Copy link
Collaborator

We had this code; pretty much exactly. It was called oexpr and in util/oexpr.h. It was deleted by PR #347 : 2db625 as part of a clean up in moving to a new C++ version, having been marked as "old" 346495 .

As I recall, I thought of it and suggested it to Daniel on the basis you could have one piece of code that was both concrete or symbolic depending on the types used (of course you can also achieve this by doing everything symbolically and then constant folding via simply_expr, anyway, I thought I was clever at the time), he implemented it because, why not, it then sat there and wasn't used because it turns out to not be as useful as you'd originally think and then was removed because it wasn't being used.

I guess there are multiple conclusions one could draw from this story and I'll let you pick your own.

Lukasz A.J. Wrona added 2 commits November 16, 2017 08:22
Implements an exprt wrapper for constructing logical and arithmetic
expressions using C++ operators.
Copy link
Collaborator

@martin-cs martin-cs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Over all ... I'm not convinced it gains us that much. A slight reduction in characters in long lines but that is traded against obfuscating what is symbolic and what is literal.

As I said before, I used to think this was a great idea but I've not yet seen a compelling use-case.


#include <util/expr.h>
#include <util/string_expr.h>

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have thought this would be happier in util/ as nothing it does is specific to refinement. Also, maybe we should just resurrect oexpr.

@@ -12,6 +12,7 @@ Author: Romain Brenguier, [email protected]
/// strings

#include <solvers/refinement/string_constraint_generator.h>
#include "axt.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include in the usual style.

const array_string_exprt &s1_,
const array_string_exprt &s2_,
const exprt &start_index_,
const exprt &end_index_)
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these renamed?

@LAJW LAJW changed the title TG-634 Logical expression building utility [TG-634] Logical expression building utility Mar 14, 2018
@LAJW
Copy link
Contributor Author

LAJW commented Jan 9, 2020

Change too controversial, was attempted before and rejected. Closing.

@LAJW LAJW closed this Jan 9, 2020
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.

5 participants