luciangreen / Combination-Algorithm-Writer-Multiple-Predicates

Writes algorithms with multiple predicates

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Combination Algorithm Writer with Multiple Predicates

Combination Algorithm Writer with Multiple Predicates (CAWMP) is a SWI-Prolog algorithm that finds algorithms from given rules, algorithm parts (from algdict.pl) and writes algorithms with multiple predicates that satisfy the given input and output.

Please contact Lucian Green at luciangreen@lucianacademy.com with questions, comments and feedback about CAWMP. Please use this citation for research.

Getting Started

Please read the following instructions on how to install the project on your computer for writing code.

Prerequisites

Install List Prolog Interpreter Repository (https://github.com/luciangreen/listprologinterpreter) first.

Installation from List Prolog Package Manager (LPPM)

mkdir GitHub
cd GitHub/
git clone https://github.com/luciangreen/List-Prolog-Package-Manager.git
cd List-Prolog-Package-Manager
swipl

loading LPPM with ['lppm']. then installing the package by running lppm_install("luciangreen","Combination-Algorithm-Writer-Multiple-Predicates")..

Installing

  • Download this repository.
  • In SWI-Prolog, enter:
['cawplistprolog'].
  • Running

  • Try CAWP regression tests (in cawpverify.pl): Example cawptest1(off,N,S). where N is the test number 1-8. Example Output

[cawptest,passed,[[[n,add0],[[v,a],[v,b],[v,c]],":-",[[[n,+],[[v,a],[v,b],[v,d]]],[[n,=],[[v,d],[v,c]]]]]]]

Example cawptest1a(off,7,S). Example Output

[cawptest,7,passed]
S = passed.

Running Random Combination Algorithm Writer (RCAW)

  • RCAW generates random algorithms.

  • To load and install, follow the instructions above.

Notes on CAWMP:

  • Variables should be named a, b, c, and so on, without any gaps.
  • In inputted data, i.e. specifications, the above applies.

CAWMP is called with the command: caw00(Debug,Function,Rules,MaxLength,MaxPredicates,TotalVars,NumInputs,NumOutputs,Specifications,AlgDict,Program1,Program2). e.g.

caw00(off,add0,[],2,1,3,[1,2],[0,1],
%% Specs
[[[[[[v,a],1],[[v,b],2]],[],true],
[[[[v,a],2],[[v,b],1]],[],true]]],
[ %% Algorithm dictionary
        [[[n,1],1,1],[[v,a],[v,b]],":-",
        [       [[n,+],[[v,a],1,[v,c]]],
                [[n,=],[[v,c],[v,b]]]]],

        [[[n,1],1,1],[[v,a],[v,b]],":-",
        [       [[n,-],[[v,a],1,[v,c]]],
                [[n,=],[[v,c],[v,b]]]]]
],

[],Program2).

It has the output:

Program2=
[
	[[n,1],[[v,a],[v,b]],":-",
		[[[n,+],[[v,a],1,[v,c]]],
		[[n,=],[[v,c],[v,b]]]]],
	[[n,1],[[v,a],[v,b]],":-",
		[[[n,-],[[v,a],1,[v,c]]],
		[[n,=],[[v,c],[v,b]]]]],
	[[n,add0],[[v,a],[v,b]],":-",
		[[[n,1],[[v,b],[v,c]]],
		[[n,=],[[v,a],[v,c]]]]]
].
  • Debug is true for trace, false for no trace.
  • Function is the inputted name of the algorithm.
  • Rules are the commands to build the code from, e.g. [[[n,+],2,1],[[n,[]],1,0]], which mean the "+" function has 2 inputs and one output and the [] function has one input and verifies an empty list. See the List Prolog Interpreter Documentation for more commands.
  • MaxLength is the maximum number of commands per predicate.
  • MaxPredicates is the maximum number of predicates per algorithm.
  • TotalVars is the number of different variables per predicate.
  • Specifications have the form A=[Input_variable_list, Output_variable_list, True (if this specification in true, or false if trying to eliminate possibilities)], where a variable list is [B] where B is e.g. [[v,c],[1,2]]. There is a list of specifications, e.g. [A1,A2] for a predicate (i.e. not the whole algorithm), and [[A1,A2],[B1,B2]] for the specifications for the algorithm, e.g.
[[[[[[v,a],1],[[v,b],2]],[],true],
[[[[v,a],2],[[v,b],1]],[],true]]]
  • Program1 is the initial program (usually []). Planned: partial multiple predicate algorithms may be given to the algorithm to complete.
  • Program2 is the final outputted algorithm.
  • CAWMP allows shorter and shorter lists of specifications to specify algorithms as its dictionary grows.

Not tested updates

Neither Prolog nor List Prolog can return non-deterministic results after point of execution passes from a clause to a child clause, so the result of testing the repository is that multiple clauses cannot be generated in this case.

See the CAWPS Repository because it is all that is needed to build an algorithm bottom-up. Without generating base cases first, neither CAWMP nor CAWPS can work, and CAWPS can generate more commands per predicate than CAWMP.

Documentation of List Prolog Interpreter CAWMP Commands

See Documentation of List Prolog Interpreter CAWMP Commands.

Authors

Lucian Green - Initial programmer - Lucian Academy

License

I licensed this project under the BSD3 License - see the LICENSE.md file for details

About

Writes algorithms with multiple predicates

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Prolog 99.6%Language:TeX 0.4%