Got it! This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
Here is some information about using the rmsDSL for permutations for Prolog. This system helps in generating permutations for finite domains to help solve problems involving finite domains.
It is a DSL (Domain Specific Language) system in that the source code allows the possibility of generating other languages at some future time using the same specification.
3. Finite domains
A finite domain is a domain that is not infinite. It is finite.
Here are some examples of finite domains.
The digits from 0 to 9.
The colors "red", "green" and "blue".
4. Source code
Selecting "New" currently provides a starter source code such as the following.
Here is the DSL code.
In this case, the names "A", "B" and "C" are to be permuted using the values 1, 2 and 3.
5. Grammar
Here is the grammar and syntax diagram for the permutation DSL.
Here is the associated EBNF (Extended Backus Naur Form) grammar.
Dsl = "dsl" Name For Body "end" .
For = "for" String .
Body = { Domain Values Names } .
Domain = "domain" Name .
Values = "values" { Value } .
Names = "names" { Name } .
Value = Integer | String .
6. Notes
Note the following.
The domain should start with a lowercase letter (i.e., Prolog atom).
All names should start with an uppercase letter (i.e., Prolog variable).
Any line starting with "//" is a comment line and is ignored. Values can be numbers (integers) or strings in double quotes.
If there are more names than values then, since each name must be different, no output would ever be generated (an error message is generated).
7. Syntax diagrams
Here is the associated EBNF syntax diagram(s).
8. Run
The "Run" button generates a TuProlog Prolog program to generate and output the requested permutations.
In practice, such as in solving puzzles, only part of the program is needed, but the entire program is generated so one can easily verify that it works.
9. Output
In practice, the relevant output below would be copied to a Prolog program/script and constraints would be added to prune the search.
Here is the output of the DSL code.
10. Generated program
Here is the generated program from above.
Here is the Prolog code.
Note that in practice one needs only part of the output and can select that part as desired.
11. Output
The number of permutations of 2 objects is 2! = 2*1 = 2.
The number of permutations of 3 objects is 3! = 3*2*1 = 6.
Below are all 12 permutations of the bits 0 to 1 and the colors "red", "green" and "blue".
Note that in Prolog it often requires assert and retract to output a numbered list in the presence of fail.
Here is the output of the Prolog code.
12. Integration
The DSL for Prolog permutations can be useful in creating the facts and rules needed to obtain permutations for various parts of puzzle solutions.