List of Philosophy Algorithms
- Prolog and List Prolog Algorithms
- From articles at http://lucianpedia.fandom.com/.
Please read the following instructions on how to install the project on your computer for running algorithms.
-
Use a search engine to find the Homebrew (or other) Terminal install command for your platform and install it, and search for the Terminal command to install swipl using Homebrew and install it or download and install SWI-Prolog for your machine at SWI-Prolog.
-
You may need to install gawk using Homebrew.
-
Install Translation Shell on Mac, etc. Change line in
culturaltranslationtool/ctt2.pl
trans_location("../../../gawk/trans").
to correct location of trans.
- In Terminal settings (Mac), make Bash the default shell:
/bin/bash
- In Terminal, edit the text file
~/.bashrcusing the text editor Nano:
nano ~/.bashrc
- Add the following to the file
~/.bashrc:
export PATH="$PATH:/opt/homebrew/bin/"
- Check if
usr/local/binexists
ls -ld /usr/local/bin
- Create the directory if missing
sudo mkdir -p /usr/local/bin
- Link to swipl in Terminal
sudo ln -s /opt/homebrew/bin/swipl /usr/local/bin/swipl
- Download:
- this repository
- listprologinterpreter
- Languages
- Cultural Translation Tool. Requires Translation Shell (you may need to install gawk using Homebrew. Install Translation Shell on Mac, etc.
Change line in culturaltranslationtool/ctt2.pl
trans_location("../../../gawk/trans").to correct location of trans). - mindreader. (Caution: Before running texttobr/mindreader, think of two radio buttons put on recordings, put through with prayer, nut and bolt, quantum box prayer 1, 1, 0.5 cm and 1, 1, 0.5 cm. Follow instructions in Instructions for Using texttobr(2) when using texttobr, texttobr2 or mind reader to avoid medical problems).
- LuciansHandBitMap-Font
- Lucian-Academy
- Prolog-to-List-Prolog
- List-Prolog-to-Prolog-Converter
- Download the LPPM Repository:
mkdir GitHub
cd GitHub/
git clone https://github.com/luciangreen/List-Prolog-Package-Manager.git
cd List-Prolog-Package-Manager
swipl
['lppm'].
lppm_install("luciangreen","Philosophy").
../
halt.
-
In Shell:
cd Philosophyswipl -
If the algorithm is a Prolog algorithm, in SWI-Prolog, in the relevant folder, enter:
['filename.pl'].
where filename is the name of the file.
-
Enter
name_of_predicate(Input,Output).where name_of_predicate is the main predicate of the algorithm, and the input and output arguments are given. -
If the algorithm is a List Prolog algorithm, run it in List Prolog.
-
In the SWI-Prolog environment in the Philosophy folder, enter:
['../listprologinterpreter/listprolog']. -
To run a specific test:
test1(off,TestNumber,Passed).where TestNumber is the test number from lpiverify4.pl in List Prolog.
-
In
swipl:['paint.pl']. -
The following
file_paint.txtfile contains the width and height of the image and a description of a text box, with number of columns (x_bounds) and rows (y_bounds), the x and y offsets, size (1,2,3 etc.), text colour and text to draw ("."):
["width",6,"height",10,
[
["text","x_bounds",1,"y_bounds",1,"x",0,"y",0,"size",1,"colour",black,"."]]]
-
Delete duplicate predicates, no matter what their name or variable names.
-
In
swipl:
cd s2g
['minimise_alg.pl'].
minimise_alg([[[n,function],[[v,a],[v,b]],":-",[[[n,+],[[v,a],[v,b]]]]],[[n,function],[[v,b],[v,a]],":-",[[[n,+],[[v,b],[v,a]]]]]],A),writeln1(A).
A = [[[n,function],[[v,a],[v,b]],":-",[[n,+],[[v,a],[v,b]]]]]
-
Open files or edit folders and move, rename or delete files or folders.
-
Remember to edit the password in
web-editor-pw.plbefore running. -
In
swipl,['web-editor1.pl'].web_editor_server(8000).Go to http://localhost:8000/webeditor or http://your IP address:8000 to access files online.
-
Enter text to paraphrase in
Philosophy/file.txtwhile reading the text in another window and the paraphrased filefile2.txtwill be produced. -
Warning: Check results for correctness.
-
In
swipl,['paraphraser1.pl'].paraphraser([file,"file.txt"],A).
-
In
paraphraser1_pl.plchange the passwordappleto something else. -
Load with
['paraphraser1_pl_ws.pl'].andparaphraser_server(8000).. -
Go to
http://localhost:8000/paraphraser. -
Enter the password.
-
Enter the file to paraphrase.
-
Enter the thesaurus or [], for example
[["a","c"], etc]where these are the pairs of bidirectional synonyms. -
Enter synonyms for additional words.
-
Save the finished paraphrasing and thesaurus.
-
Warning: Check results for correctness.
-
To run List Prolog Interpreter and enter Prolog queries, load
['lpi.pl'].and runlpi.. -
To run State Saving Interpreter and enter Prolog queries, load
['lucianpl.pl'].and runlucianpl..
sub_term_wa(Subterm, Term, Instances).
Subterm - Subterm to find
Term - Initial list to search
Instances - List of addresses and subterms
Subterm (with address) gives the "address" of a term in a term, such as [[[1], a]] for a in a, [[[1, 2], b]] for b in [a,b], (where the column number is the dimension), and put subterm with address puts an item into an address.
sub_term_wa(Subterm, Term, Instances)
sub_term_wa([a,_], [[a,b], [a,c]], Instances).
Instances = [[[1, 1], [a, b]], [[1, 2], [a, c]]]
get_sub_term_wa(Term, Address, Item)
get_sub_term_wa([[1, 4], 2, 3], [1, 1, 2], Item).
Item = 4
put_sub_term_wa(Item, Address, Term1, Term2)
put_sub_term_wa(88, [1,1], [[2, 3], 4], Term2).
Term2 = [88, 4]
put_sub_term_wa_smooth(Item, Address, Term1, Term2)
put_sub_term_wa_smooth([88,1], [1,1], [[2,3],4], Term2).
Term2 = [88, 1, 4]
delete_sub_term_wa(Instances, Term1, Term2)
delete_sub_term_wa([[1, 1], [1, 2]], [a, b], Term2).
Term2 = []
foldr(put_sub_term_wa_ae,Instances, Term1, Term2).
foldr(put_sub_term_wa_ae,[[[1, 1], [v, 2]], [[1, 2], [v, 3]]], [[v, 1], [v, 2]], Term2).
Term2 = [[v, 2], [v, 3]]
foldr(put_sub_term_wa_ae_smooth, Instances, Term1, Term2)
foldr(put_sub_term_wa_ae_smooth, [[[1, 1], [v, 2]], [[1, 2], [v, 3]]], [[v, 1], [v, 2]], Term2).
Term2 = [v, 2, v, 3]
sub_term_types_wa(Heuristic, Term, Instances)
sub_term_types_wa([all([number, string])], [1,[a,3]], Instances).
Instances = [[[1,2], [a,3]]]
Possible heuristics:
var
string
atom
[]
number
compound (non-list compounds)
all(Insert_more_heuristics) (all the items are of a type, can be used to select terminals)
heuristic(Heuristic, Output_variable) (Heuristic may be for example A=a and Output_variable=A)
A sequential term replacer using STWA:
get_put_stwa([v,_],[[v,1],[v,2]],O_stwa_i_code,findall([Ad,[v,A1]],(member([Ad,[v,A2]],O_stwa_i_code),A1 is A2+1),O_code_i_foldr),O_code_i_foldr,Term2).
O_stwa_i_code = [[[1, 1], [v, 1]], [[1, 2], [v, 2]]],
O_code_i_foldr = [[[1, 1], [v, 2]], [[1, 2], [v, 3]]],
Term2 = [[v, 2], [v, 3]]
-
A black spherical ink well represents the transformation from strings to grammar (lensgo.ai).

-
Enter possible strings to convert to a context-free grammar in
s2g/strings_to_grammar.pl. -
For example, test 1 below takes the following string and tests for outputted grammar.
[1,["[1,2,3,2,3,1,2,3,2,3]"],
[[[n,a1],"->",[[]]],
[[n,a1],"->",[[1],[[n,a2]],[[n,a1]]]],
[[n,a2],"->",[[]]],
[[n,a2],"->",[[2],[3],[[n,a2]]]]]],
-
Temporarily change the line
%writeln1(G1)towriteln1(G1)to show the outputted grammar from a particular set of strings. You can replace the test output above with this output. -
To load strings to grammar and run tests, enter:
cd s2g
['strings_to_grammar.pl'].
test_s2g.
- The output contains the following lines:
[success,1,strings_to_grammar,test]
[success,1,strings_to_grammar,check_grammar,test]
-
These give the test number. The first result is that the output matches the test output. The second result is the strings being substituted back into the found grammar working.
To convert ordinary strings:
Change e.g. "[1,2,3,2,3,1,2,3,2,3]" to "1232312323".
Change term_to_atom(T1,S) to string_strings(S,T1).
Change term_to_atom(S2,S),flatten_keep_brackets(S2,S1),append([_],S4,S1),append(S3,[_],S4) to string_strings(S,S3).
-
Starry Sunshine (a play on words on "subterm with address" and "spec to algorithm")

-
Enter possible specs to convert to a pattern-matching algorithm using a Context-Free Grammar Generator in
s2a/spec_to_algorithm.pl. -
For example, test 1 below takes the following spec and tests the outputted algorithm.
[1,
[
[[input,[['A',[1,2]]]],[output,[['B',[2,1]]]]],
[[input,[['A',[3,4]]]],[output,[['B',[4,3]]]]]
]
],
This creates the following algorithm:
algorithm(In_vars,Out_var) :-
algorithm([[['C1','C2'],[output,[['C2','C1']]]]],[[[[1,1],[[1,2]]],[[1,2],[[1,1]]]]],In_vars,Out_var).
-
The mappings ([1,1] to [1,2], etc.) represent the term addresses of the variables in input and output.
-
To load Spec to Algorithm and run tests, enter:
cd s2a
['spec_to_algorithm.pl'].
test_s2a.
- The output contains the following lines:
success
success
[success,1,spec_to_algorithm,test]
-
The first result is from producing the algorithm and the second test is from testing the produced algorithm matches the correct result. The third result gives the test number.
-
Use the query
spec_to_algorithm(algorithm,[[[input,[['A',[1,2]]]],[output,[['B',[21]]]]], [[input,[['A',[3,4]]]],[output,[['B',[43]]]]]],on,A),writeln1(A).whereonturns on breakdown of term elements to characters for recombination of characters in terms. -
Starlog is part Haskell, part Prolog and allows simple editing of patterns and code in S2A specs. -
Run generated algorithms by loading the algorithm (ensuring that
\"has been replaced with") auxiliary_s2a_used.pl and callingalgorithm(In_vars,Out_var).with the correct In_vars. Please check the name of the algorithm. -
Mind-Reading S2A uses S2A to generate algorithms. See for an example of generating S2A algorithms.
Lucian Green - Initial programmer - Lucian Academy
I licensed this project under the BSD3 License - see the LICENSE.md file for details