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

Incorrect result? #3

Closed
bertram-gil opened this issue May 13, 2022 · 2 comments
Closed

Incorrect result? #3

bertram-gil opened this issue May 13, 2022 · 2 comments

Comments

@bertram-gil
Copy link

Hi guys,

Consider the following program:

use ascent::ascent;
ascent!{
	relation a__(i32, i32);
	relation c__(i32, i32, i32);
	relation e__(i32);
	relation h__(i32, i32, i32);

	e__(a) <-- a__(b, a);
	h__(e, e, e) <-- a__(d, e), c__(e, f, e), e__(e);

}

fn main() {
	let mut prog = AscentProgram::default();
	prog.a__ = vec![(88,5), (37,24), (11,91)];
	prog.c__ = vec![(32,83,88), (2,8,5)];
	prog.e__ = vec![(44,), (83,)];
	prog.h__ = vec![(38,88,18), (76,18,65), (86,73,91), (98,26,91), (76,10,14)];

	prog.run();
	println!("{:?}", prog.h__);
}

If I run the program, I get the following for the relation h__:
[(38, 88, 18), (76, 18, 65), (86, 73, 91), (98, 26, 91), (76, 10, 14), (5, 5, 5)]

Now, if I add a subgoal c__(e, a, e) in the rule for h__ to get the following new program:

use ascent::ascent;
ascent!{
	relation a__(i32, i32);
	relation c__(i32, i32, i32);
	relation e__(i32);
	relation h__(i32, i32, i32);


	e__(a) <-- a__(b, a);
	h__(e, e, e) <-- a__(d, e), c__(e, f, e), e__(e), c__(e, a, e);
}

fn main() {
	let mut prog = AscentProgram::default();
	prog.a__ = vec![(88,5), (37,24), (11,91)];
	prog.c__ = vec![(32,83,88), (2,8,5)];
	prog.e__ = vec![(44,), (83,)];
	prog.h__ = vec![(38,88,18), (76,18,65), (86,73,91), (98,26,91), (76,10,14)];

	prog.run();
	println!("{:?}", prog.h__);
}

The result for h__ changes and I get:
[(38, 88, 18), (76, 18, 65), (86, 73, 91), (98, 26, 91), (76, 10, 14)]
Adding the subgoal c__(e, a, e) should not change the result for relation h__.
The tuple (5, 5, 5) disappears for the second program which should not have appeared for the first program in the first place.

My Cargo.toml file:

[package]
name = "ascent_project"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ascent = "0.2"

Please let me know if you cannot reproduce this or if I am doing anything wrong.

@s-arash
Copy link
Owner

s-arash commented May 13, 2022

Thanks for finding it. Indeed this is a bug. It has to do with the interaction of repeated vars in c__(e, f, e) and reordering of clauses. I will push a fix soon. Will you be able to move to 0.3 when the fix is pushed?

And if you need a quick workaround, change it to c__(e, f, e1), if e == e1

@bertram-gil
Copy link
Author

Thanks for confirming it.
Yes absolutely I can move to 0.3 when it is ready :)

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

No branches or pull requests

2 participants