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

Partial evaluation #1

Open
waern opened this issue Nov 14, 2021 · 0 comments
Open

Partial evaluation #1

waern opened this issue Nov 14, 2021 · 0 comments

Comments

@waern
Copy link

waern commented Nov 14, 2021

I'm experimenting with the partial evaluation capabilities of ciaopp, but I'm not sure how to get the best possible results. I tried to transform the following program:

:- module(test3, [test3/1], []).

generate(empty,T,T).
generate(char(X),[X|T],T).
generate(or(X,Y),H,T) :- generate(X,H,T).
generate(or(X,Y),H,T) :- generate(Y,H,T).
generate(cat(X,Y),H,T) :- generate(X,H,T1), generate(Y,T1,T).
generate(star(X),T,T).
generate(star(X),H,T) :- generate(X,H,T1), generate(star(X),T1,T).

prog(cat(char(a),star(char(b)))).
prog(or(star(char(c)), empty)).

test3(S) :-
  prog(P),
  generate(P,S,[]).

With this "driver" code:

:- use_module(ciaopp(ciaopp)).

main(_) :-
  module('test3.pl'),
  set_pp_flag(comp_rule, no_sideff_jb),
  set_pp_flag(local_control, df_hom_emb),
  set_pp_flag(global_control, hom_emb),
  set_pp_flag(fixpoint, di),
  set_pp_flag(unf_depth, 1000),
  set_pp_flag(abs_spec_defs, all),
  set_pp_flag(rem_use_cls, both),
  set_pp_flag(part_concrete, multi),
  analyze(pdb),
  transform(codegen),
  transform(spec),
  output('test3_pe.pl').

Here is the result:

:- module(_1,[test3/1],[assertions]).

:- true pred test3(_A).

test3([a]).
test3([a,b|A]) :-
    generate_1(star(char(b)),A,[]).
test3([]).
test3([c|A]) :-
    generate_2(star(char(c)),A,[]).
test3([]).

:- true pred generate_1(_A,_B,_C).

generate_1(star(char(b)),[],[]).
generate_1(star(char(b)),[b|A],[]) :-
    generate_1(star(char(b)),A,[]).

:- true pred generate_2(_A,_B,_C).

generate_2(star(char(c)),[],[]).
generate_2(star(char(c)),[c|A],[]) :-
    generate_2(star(char(c)),A,[]).

This looks good to me, and I want to express my thanks for ciaopp as a really capable open source tool. But I don't really know what I'm doing so I have some basic questions:

  • Is there some way to get rid of the duplicate test3([]). clauses? (In some bigger tests I get many of them).
  • Is there some flag to turn off generation of these kinds of statements: :- true pred...?
  • Am I going about this the right way? I'd like to be able to apply partial evaluation across a variety of programs, and so I'm looking for a configuration that works well overall.
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

1 participant