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

Avoid duplicate calculation within a single rule #19

Open
robsimmons opened this issue Jun 5, 2024 · 0 comments
Open

Avoid duplicate calculation within a single rule #19

robsimmons opened this issue Jun 5, 2024 · 0 comments

Comments

@robsimmons
Copy link
Owner

robsimmons commented Jun 5, 2024

This is an issue that primarily comes up if you write

#builtin NAT_SUCC s
a :- b X, c (s (s (s X))), c (s (s (s (s X)))).

This gets compiled to

a :-
  b X,
  s X is X1
  s X1 is X2,
  s X2 is X3,
  c X3,
  s X is X4,
  s X4 is X5,
  s X5 is X6,
  s X6 is X7,
  c X6.

which should be able to be simplified to

a :-
  b X,
  s X is X1
  s X1 is X2,
  s X2 is X3,
  c X3,
  s X3 is X7,
  c X7.

This is basically common subexpression elimination, and it should (probably) be performed during compilation on the flattened program, before binarization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant