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

[ derive ] Impement multi-stage algorithm for calculation of ordering #183

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

buzden
Copy link
Owner

@buzden buzden commented Aug 15, 2024

No description provided.

@buzden buzden added code: enhancement New feature or improvement part: derivation Related to automated derivation of generators issue: compilation error When compilation error raises because of the library issue: performance When work takes too much resources derive: least-effort Relates to the `LeastEffort` derivation algorithm code: fix Fixing some issues labels Aug 15, 2024
@buzden buzden force-pushed the multistage-ordering-algorithm branch 13 times, most recently from b26aa3e to 305612e Compare August 21, 2024 14:00
@buzden buzden force-pushed the multistage-ordering-algorithm branch 4 times, most recently from 5256b08 to d9a3113 Compare September 2, 2024 12:23
@buzden buzden force-pushed the multistage-ordering-algorithm branch from d9a3113 to 98535b1 Compare September 6, 2024 14:14
@buzden buzden force-pushed the multistage-ordering-algorithm branch 5 times, most recently from 1c1a3a8 to 0f4015b Compare September 20, 2024 11:28
@buzden buzden force-pushed the multistage-ordering-algorithm branch 7 times, most recently from 1be2fa5 to 02fee24 Compare September 25, 2024 16:29
@buzden
Copy link
Owner Author

buzden commented Sep 26, 2024

Currently, we are choosing candidates of generation one by one, because the order matters: if we choose one of them, its generation can release more candidates, which can be more important than already existing candidates.

It seems to be important that we would take GADT status of their type arguments into account. This would require us to analyse

  • for each candidate type (or for each type at all, if we precalculate this)

    • for each type argument

      • for each constructor decide whether it is

        • a single constructor's argument name (i.e. parametric);
        • contains only constructor's arguments and names of constructors/types (i.e. easily pattern-matchable);
        • other (i.e. including application of arbitrary functions, thus shouldn't be given).

Open question is to which f a belongs, where both f and a are constructor arguments. This is important once we support polymorphic types. Maybe the second class above should be reformulated as "application of names of constructors/types to constructor arguments or names of constructors/types".

@buzden buzden force-pushed the multistage-ordering-algorithm branch from b88ba55 to f6e3603 Compare September 26, 2024 14:33
@buzden buzden force-pushed the multistage-ordering-algorithm branch from f6e3603 to aa16dbe Compare October 2, 2024 11:29
@buzden
Copy link
Owner Author

buzden commented Oct 2, 2024

The newly suggested algorithm can be described in the following way.

We consider a constructor and its arguments as a graph, nodes are arguments. Edges are of four sorts:

  • weak (parametric) forward determination (dash lines);
  • normal forward determination (normal lines);
  • strong forward determination (thick lines);
  • strong back determination (double lines).

Forward determination goes from argument b to argument a if type of argument b depends on argument a. Weak forward determination goes when a is used as a parameter (i.e. not as index) in a type of b (in current context). Normal forward determination goes when a is used as a type index in a type of b and only constructors applied to (constructors applied to)* con args are used in all index expressions. Strong forward determination is used if non-constructor functions are used in index expressions in type declaration of type of b. Semantically forward determination means that when we generated b, we can generate a along with it in a dependent pair, unless a is already generated, in which case it needs to be a given argument in generation of b. Strong forward determination means that this particular argument a cannot be used as given for b.

Strong back determination goes from argument a to argument b if argument a is used in a type of argument b inside a function application, like (b : S a `LT` c). Strong back determination means semantically that we need to generate a before b in case they are not generated by anything else.

You can consider an example of such a graph for the constructor NodeLT of type AllLT from the sorted-tree-naive example:

alllt-nodelt-determ

We consider also already generated or otherwise present arguments. We start with the fact that given arguments are already present.


We start a step with counting how many outgoing normal forward determination links go to already present (given or generated) arguments. The more the number, the higher the priority is assigned to this node. This priority also gets back along strong back determination, normal foward determination and strong forward determination edges (e.g. from #6 to #1 (x) in the example on the picture above) taking max with the current priority (0 by default).

After that we determine which edges to not have any incoming normal forward determination, strong forward determination or strong back determination edges. Among them we choose one with the highes priority and mark as generated all not yet generated nodes to which any forward detemination edge goes from the newly added. Then repeat the step until no not generated arguments left.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code: enhancement New feature or improvement code: fix Fixing some issues derive: least-effort Relates to the `LeastEffort` derivation algorithm issue: compilation error When compilation error raises because of the library issue: performance When work takes too much resources part: derivation Related to automated derivation of generators
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant