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

Define behaviour for empty expressions #370

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

YehorBoiar
Copy link
Contributor

This PR is based on the Chris's and Oz's comment on Teams:

"
Chris:
I'd get existing PRs merged in first, but then it might be worth making a pass over empty constraints, I think (please check essence semantics , and I'm not sure which are implemented yet):

and([]) = true
or([]) = false
sum([]) = 0
product([]) = 1

it's worth getting these right because (from experience), while no-one is likely to write these, they often end up getting created as parts of more interesting expressions.

Oz:
min([]) and max([]) are a bit different, as min([])=x is always false, but this falseness will arise naturally from the fact they will end up turning into an 'and([])' and an 'or([])', and the or will be false, so there is no need to special-case empty min([]) and max([]) (hopefully!)

we can define an abstraction which has a zero vale and an append operator for these.
and is true, /
or is false, /
sum is 0, +
product is 1, *
regarding min and max, we already did a bunch of definedness work with Felix last semester (Soph and Yehor taking over this now)
"

@ozgurakgun
Copy link
Contributor

we should also actually remove Nothing, shouldn't we?

@YehorBoiar
Copy link
Contributor Author

YehorBoiar commented Oct 17, 2024

Will do. The reason why we are not deleting it yet is that we want to ensure that all empty rules work before deleting Nothing.

/// ```text
/// or([]) ~> false
/// X([]) ~> Nothing
/// ```
#[register_rule(("Base", 8800))]
fn remove_empty_expression(expr: &Expr, _: &Model) -> ApplicationResult {
Copy link
Contributor

Choose a reason for hiding this comment

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

I just noticed: why is this a separate rule instead of being handled by the full evaluator?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

By the look of git blame, seems to just be because Nothing was added before the evaluator.

I agree that it should be an evaluation step.

Copy link
Contributor Author

@YehorBoiar YehorBoiar Oct 19, 2024

Choose a reason for hiding this comment

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

So we don't need this rule at all. We should just define an empty expression behaviour in rules, is that correct?

Copy link
Contributor

@ozgurakgun ozgurakgun Oct 19, 2024

Choose a reason for hiding this comment

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

don't know what you mean by "We should just define an empty expression behaviour in rules"

for context, full evaluator here:

fn apply_eval_constant(expr: &Expr, _: &Model) -> ApplicationResult {

partial evaluator here:

fn partial_evaluator(expr: &Expr, _: &Model) -> ApplicationResult {

Copy link
Contributor

Choose a reason for hiding this comment

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

and if it all was working correctly this would already do it?

I think there is a bug. how well tested is the full evaluator?

remove_empty_expression is at 8800, and full evaluator is at 9001, so that should take precedence even if this rule was buggy (which I think it is)

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.

3 participants