% member(List,Item) (below) only works with deprecated lpi %% RCAW - Random Combination Algorithm Writer with Predicates %%Input: Algorithms, Specification of this algorithm %%Output: Possible algorithms :- dynamic debug/1. /** **-----VPS B and B to B 2 % *** Max of 6 commands at a time - possibly restart apache2 before starting ** at each stop point, close window, or possibly halt ssh root@185.176.42.28 -p 22 %% f6sEhJ1AN5qm cd ../var/www/lucianacademy.ml/ swipl -G100g -T20g -L2g [meditationnoreplace]. meditation. halt. swipl -G100g -T20g -L2g [meditationnoreplace]. [medicinenoreplace]. medicine. %%L leash(-all),visible(+all). protocol("./file.txt"). trace. caw00(off,[n,f],[[[n,append],2,1],[[n,delete],2,1],[[n,head],1,1],[[n,tail],1,1],[[n,member],1,1]],2,8,_InputVarList,_OutputVarList,[],_Program2,Ps). notrace,noprotocol. %% ** Stop - close window x halt (last time I stopped here) halt. swipl -G100g -T20g -L2g [meditationnoreplace]. time((N is 1, M is 3*250,texttobr2(N,u,u,M))). %% see below time((texttobr2(u,"file2qb.txt",u,u))). %% ** Do following separately, don't restart server (crashes even with following) %%halt. %%swipl -G100g -T20g -L2g %%[meditationnoreplace]. %%A leash(-all),visible(+all). protocol("./file.txt"). trace. caw00(off,[n,f],[[[n,append],2,1],[[n,delete],2,1],[[n,head],1,1],[[n,tail],1,1],[[n,member],1,1]],2,8,_InputVarList,_OutputVarList,[],_Program2,Ps). notrace,noprotocol. %% ** Stop - close window x halt halt. swipl -G100g -T20g -L2g [meditationnoreplace]. time((N is 1, M is 3*250,texttobr2(N,u,u,M))). %% see below time((texttobr2(u,"file2qb.txt",u,u))). *** See intructions for running texttobr before using texttobr. - DON'T USE - for mindreading x use %% For MacBook Air - use VPS instead cd /Users/luciangreen/Dropbox/Program\ Finder/possibly\ not\ working/rcaw/ swipl -G100g -T20g -L2g [meditation]. meditation. %% That so called for others is for them for Lucian %% Lucian leash(-all),visible(+all). protocol("./file.txt"). trace. %% caw00(off,f,[[[n,append],2,1],[n,delete],2,1],[n,head],1,1],[[n,tail],1,1],[n,member],1,1]],2,8,_InputVarList,_OutputVarList,[],_Program2,Ps). notrace,noprotocol. N is 15, M is 250*6, texttobr2(N,u,u,M),texttobr(N,u,u,M). %% see below texttobr2(u,"file2qb.txt",u,u),texttobr(u,"file2qb.txt",u,u). %% Adrian for Lucian protocol("./file.txt"). trace. caw00(off,f,[[append,2,1],[delete,2,1],[head,1,1],[tail,1,1],[member,1,1]],2,8,_InputVarList,_OutputVarList,[],_Program2,Ps). notrace,noprotocol. N is 15, M is 250*6, texttobr2(N,u,u,M),texttobr(N,u,u,M). %% see below texttobr2(u,"file2qb.txt",u,u),texttobr(u,"file2qb.txt",u,u). %%[medicine]. %%medicine. **--------one off br cd /Users/luciangreen/Dropbox/Program\ Finder/possibly\ not\ working/rcaw/ swipl -G100g -T20g -L2g [meditation]. texttobr2(u,u,u,u),texttobr(u,u,u,u). %%*** time((texttobr2(u,u,u,u),texttobr(u,u,u,u))),mergetexttobrdict. %% texttobr2(u,u,u,u),texttobr(u,u,u,u). %% 80 minutes for 15*90 page document on MacBook Air or 8 minutes on VPS. texttobr2(u,u,u,2000),texttobr(u,u,u,14400). **-----VPS x use B and B to B below % *** Max of 6 commands at a time - possibly restart apache2 before starting ** at each stop point, close window, or possibly halt ssh root@185.176.42.28 -p 22 %% f6sEhJ1AN5qm cd ../var/www/lucianacademy.ml/ swipl -G100g -T20g -L2g [meditation]. meditation. halt. swipl -G100g -T20g -L2g [meditation]. [medicine]. medicine. %%L leash(-all),visible(+all). protocol("./file.txt"). trace. caw00(off,[n,f],[[[n,append],2,1],[[n,delete],2,1],[[n,head],1,1],[[n,tail],1,1],[[n,member],1,1]],2,8,_InputVarList,_OutputVarList,[],_Program2,Ps). notrace,noprotocol. %% ** Stop - close window x halt (last time I stopped here) halt. swipl -G100g -T20g -L2g [meditation]. time((N is 15, M is 10146, M1 is M, M2 is M*5,texttobr2(N,u,u,M1),texttobr(N,u,u,M2))). %% see below time((texttobr2(u,"file2qb.txt",u,u),texttobr(u,"file2qb.txt",u,u))). %% ** Do following separately, don't restart server (crashes even with following) %%halt. %%swipl -G100g -T20g -L2g %%[meditation]. %%A leash(-all),visible(+all). protocol("./file.txt"). trace. caw00(off,[n,f],[[[n,append],2,1],[[n,delete],2,1],[[n,head],1,1],[[n,tail],1,1],[[n,member],1,1]],2,8,_InputVarList,_OutputVarList,[],_Program2,Ps). notrace,noprotocol. %% ** Stop - close window x halt halt. swipl -G100g -T20g -L2g [meditation]. time((N is 15, M is 10146, M1 is M, M2 is M*5, texttobr2(N,u,u,M1),texttobr(N,u,u,M2))). %% see below time((texttobr2(u,"file2qb.txt",u,u),texttobr(u,"file2qb.txt",u,u))). **-----VPS B and B to B % *** Max of 6 commands at a time - possibly restart apache2 before starting ** at each stop point, close window, or possibly halt ssh root@185.176.42.28 -p 22 %% f6sEhJ1AN5qm cd ../var/www/lucianacademy.ml/ swipl -G100g -T20g -L2g [meditationnoreplace]. meditation. halt. swipl -G100g -T20g -L2g [meditationnoreplace]. [medicinenoreplace]. medicine. %%L leash(-all),visible(+all). protocol("./file.txt"). trace. caw00(off,[n,f],[[[n,append],2,1],[[n,delete],2,1],[[n,head],1,1],[[n,tail],1,1],[[n,member],1,1]],2,8,_InputVarList,_OutputVarList,[],_Program2,Ps). notrace,noprotocol. %% ** Stop - close window x halt (last time I stopped here) halt. swipl -G100g -T20g -L2g [meditationnoreplace]. time((N is 250 *14/20, M is 20*3*250,texttobr2(N,u,u,M))). %% see below time((texttobr2(u,"file2qb.txt",u,u))). time((texttobr2(u,"file2qb.txt",u,u))). for out of reach time((texttobr2(u,"file2qb.txt",u,u))). for out of mind %% ** Do following separately, don't restart server (crashes even with following) %%halt. %%swipl -G100g -T20g -L2g %%[meditationnoreplace]. %%A leash(-all),visible(+all). protocol("./file.txt"). trace. caw00(off,[n,f],[[[n,append],2,1],[[n,delete],2,1],[[n,head],1,1],[[n,tail],1,1],[[n,member],1,1]],2,8,_InputVarList,_OutputVarList,[],_Program2,Ps). notrace,noprotocol. %% ** Stop - close window x halt halt. swipl -G100g -T20g -L2g [meditationnoreplace]. time((N is 250 *14/20, M is 20*3*250,texttobr2(N,u,u,M))). %% see below time((texttobr2(u,"file2qb.txt",u,u))). time((texttobr2(u,"file2qb.txt",u,u))). for out of reach time((texttobr2(u,"file2qb.txt",u,u))). for out of mind **NOT %% Lucian leash(-all),visible(+all). protocol("./file.txt"). trace. caw00(off,f,[[append,2,1],[delete,2,1],[head,1,1],[tail,1,1],[member,1,1]],2,8,_InputVarList,_OutputVarList,[],_Program2,Ps). notrace,noprotocol. %% STOP ** %%sleep(25). %% try halt. %% systemctl restart apache2 %% cd ../var/www/lucianacademy.ml/ swipl -G100g -T20g -L2g [meditation]. time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below % here - server or break in connection? time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below %here time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((texttobr2(u,"file2qb.txt",u,u),texttobr(u,"file2qb.txt",u,u))). %% Adrian for Lucian leash(-all),visible(+all). protocol("./file.txt"). trace. caw00(off,f,[[append,2,1],[delete,2,1],[head,1,1],[tail,1,1],[member,1,1]],2,8,_InputVarList,_OutputVarList,[],_Program2,Ps). notrace,noprotocol. %% STOP ** %%sleep(25). %% try %% might not even need this halt. %% systemctl restart apache2 %% cd ../var/www/lucianacademy.ml/ swipl -G100g -T20g -L2g [meditation]. time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below %% possibly need to halt, not restart server here v halt. %% systemctl restart apache2 %% cd ../var/www/lucianacademy.ml/ swipl -G100g -T20g -L2g [meditation]. time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below %% if it finishes it will be here v halt. systemctl restart apache2 cd ../var/www/lucianacademy.ml/ swipl -G100g -T20g -L2g [meditation]. time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((N is 1, M = all, texttobr2(N,u,u,M),texttobr(N,u,u,M))). %% see below time((texttobr2(u,"file2qb.txt",u,u),texttobr(u,"file2qb.txt",u,u))). **END NOT **---- texttobr2,texttobr2,texttobr2,texttobr2,texttobr2,texttobr2,texttobr2,texttobr2, texttobr2,texttobr2,texttobr2,texttobr2,texttobr2,texttobr2, %% 15 As texttobr2,texttobr2,texttobr2,texttobr2,texttobr2,texttobr2,texttobr2,texttobr2, texttobr2,texttobr2, texttobr2,texttobr2,texttobr2,texttobr2,texttobr2,texttobr2,texttobr2,texttobr2, texttobr2,texttobr2, texttobr2,texttobr2,texttobr2,texttobr2,texttobr2,texttobr2,texttobr2,texttobr2, texttobr2,texttobr2, texttobr2, texttobr2,texttobr2,texttobr2,texttobr2,texttobr2,texttobr2.** N is ((2*((46 %%+2 )*250)/80)+15), texttobr2(N),texttobr(N). %% see below %% do this once at start of every celebrity grace 6 month period (and new meditators started when taught), otherwise above: ** ~ October 2018, next April 2019 %% (2*(46+2)*250)/80=37 for 2*250 for 1. arem 2. arem links in following: [lucian 3. green 4. friendliness 5. medicine 6. childrenh1earningjobsprotectioninjobs 7. headsofstate 8. lucianmantrapureform 9. lucianmantrasunsafety 10. maharishisutra 11. meditationteachersutra 12. movingappearancespurusha 13. upasanasutra 14. yellowgod 15. greensutra 16. bluenature 17. appearances 18. pranayama 19. soma 20. hoursprayer 21. fiftybreasoningspersecond 22. meditationindicatorlowerriskofcancerandotherdiseasesinworkersandbroadcasters 23. meditationindicatordecreasedstress 24. meditationindicatorincreasedbloodflow 25. meditationincreasedbrainpotential 26. autobiography 27. computationalenglish 28. computerscience 29. economics 30. hermeneutics 31. pedagogy 32. breasonings 33. quantumbox 34. lucianicmeditation 35. lm 36. meditation 37. metaphysics 38. music 39. plays 40. popology 41. theology 42. qigongmantra 43. qigongsutra 44. yogamantra 45. yogasutra] 46. no cancer from cell function on diagram genetically functioning + 2 meditators per day *** add rest of utterance links on 25 9 18 v **texttobr,texttobr,texttobr,texttobr,texttobr,texttobr,texttobr,texttobr, texttobr,texttobr,texttobr,texttobr,texttobr,texttobr, %% 15 texttobr,texttobr,texttobr,texttobr,texttobr,texttobr,texttobr,texttobr, texttobr,texttobr, texttobr,texttobr,texttobr,texttobr,texttobr,texttobr,texttobr,texttobr, texttobr,texttobr, texttobr,texttobr,texttobr,texttobr,texttobr,texttobr,texttobr,texttobr, texttobr,texttobr, texttobr, texttobr,texttobr,texttobr,texttobr,texttobr,texttobr.** - For Mindreading [texttobr23]. [texttobr]. leash(-all),visible(+all). protocol("./file.txt"), trace, caw00(off,f,[[append,2,1],[delete,2,1],[head,1,1],[tail,1,1],[member,1,1]],2,8,_InputVarList,_OutputVarList,[],_Program2,Ps). notrace,noprotocol,texttobr23. texttobr23,texttobr23,texttobr23,texttobr23,texttobr23,texttobr23,texttobr23,texttobr23. texttobr,texttobr,texttobr,texttobr,texttobr,texttobr,texttobr,texttobr. - - For Daily work [listprologinterpreter1listrecursion4]. [texttobr24nodisplay]. [texttobr]. leash(-all),visible(+all). protocol("./file24.txt"), trace, caw00(off,f,[[append,2,1],[delete,2,1],[head,1,1],[tail,1,1],[member,1,1]],2,8,_InputVarList,_OutputVarList,[],_Program2,Ps). notrace,noprotocol,texttobr24. texttobr24,texttobr24,texttobr24,texttobr24,texttobr24,texttobr24,texttobr24,texttobr24. texttobr,texttobr,texttobr,texttobr,texttobr,texttobr,texttobr,texttobr. == caw00(off,f,[[append,2,1],[delete,2,1],[head,1,1],[tail,1,1],[member,1,1]],3,8,_InputVarList,_OutputVarList,[],_Program2,Ps). Random Combination Algorithm Writer - Writes random algorithms predicates may have different combinations of modes caw00(off,f,[[append,2,1],[delete,2,1],[head,1,1],[tail,1,1],[member,2,0]],50,6,[[a,1]],[[d,1]],[],Program). caw00(off,f,[[append,2,1],[delete,2,1],[head,1,1],[tail,1,1],[member,1,1]],50,7,[[a,1]],[[b,1]],[],Program). Program = [f,[1,b]],[[f,[a,b],:-,[[=,[b,a]]]]],[[b,1]] caw00(off,f,[[append,2,1],[delete,2,1],[head,1,1],[tail,1,1],[member,1,1]],50,7,[[a,[1,2]]],[[b,[1,2]]],[],Program). Program = [f,[[1,2],b]],[[f,[a,b],:-,[[=,[b,a]]]]],[[b,[1,2]]] caw00(off,f,[[append,2,1],[delete,2,1],[head,1,1],[tail,1,1],[member,1,1]],50,4,[[a,1],[b,2]],[[c,[1,2]]],[],Program). Program = interpret(off,[f,[1,2,c]],[[f,[a,b,c],:-,[[append,[a,b,g]],[=,[c,g]]]]],[[c,[1,2]]]) caw00(off,f,[[append,2,1],[delete,2,1],[head,1,1],[tail,1,1],[member,1,1]],50,6,[[a,1],[b,2],[c,3]],[[d,[1,2,3]]],[],Program). Program = [interpret(off,[f,[1,2,3,d]],[[f,[a,b,c,d],:-,[[append,[a,b,e]],[append,[e,c,f]],[=,[d,f]]]]],[[d,[1,2,3]]])] edit out repeats test rule,var better arg finders caw00(off,f,[[append,2,1],[delete,2,1],[head,1,1],[tail,1,1],[member,1,1]],50,7,[[a,[4,1,2,3]],[b,1]],[[d,[4,2,3]]],[],Program). [debug] ?- optimise([[append,[a,b,c]],[append,[c,d,e]]],[a,b,d],[a,b,c,d],[e],P). P = [[append, [a, b, c]], [append, [c, d, e]]] ; %% choose latest var as output, remove duplicate args in rules x (max 2), reverse optimise input, new rules have old outputs as args v [debug] ?- optimise([[append,[a,b,c]],[append,[a,b,c]]],[a,b],[a,b,c],[c],P). P = [[append, [a, b, c]]] ; [debug] ?- optimise([[append,[a,b,c]],[delete,[a,b,c]]],[a,b],[a,b,c],[c],P). P = [[append, [a, b, c]], [delete, [a, b, c]]] ; [debug] ?- optimise([[append,[a,b,c]],[delete,[a,b,x]]],[a,b],[a,b,c,x],[c],P). P = [[append, [a, b, c]]] ; [debug] ?- optimise([[append,[a,b,c]],[delete,[c,b,d]],[member,[c,d]]],[a,b],[a,b,c,d],[d],P). P = [[append, [a, b, c]], [delete, [c, b, d]], [member, [c, d]]] ; [debug] ?- optimise([[append,[a,b,c]],[delete,[c,b,d]],[member,[a,d]]],[a,b],[a,b,c,d],[d],P). P = [[append, [a, b, c]], [delete, [c, b, d]], [member, [a, d]]] ; [debug] ?- optimise([[append,[a,b,c]],[delete,[c,b,d]],[member,[a,x]]],[a,b],[a,b,c,d],[d],P). P = [[append, [a, b, c]], [delete, [c, b, d]]] ; [debug] ?- optimise([[append,[a,b,c]],[delete,[c,b,d]],[member,[c,x]]],[a,b],[a,b,c,d],[d],P). P = [[append, [a, b, c]], [delete, [c, b, d]]] ; Wantedly fail: optimise([[append,[a,e,c]]],[a],[a,e,c],[c],P). optimise([[append,[a,b,c]],[append,[c,d,e]]],[a,d],[a,b,c,d],[e],P). optimise([[append,[a,b,c]],[append,[c,d,e]]],[a,b],[a,b,c,d],[e],P). optimise([[delete,[a,e,c]],[append,[a,a,e]]],[a,e],[a,e,c],[c],P). P = [[delete, [a, e, c]], [append, [a, a, e]]] . optimise([[append,[a,a,e]],[delete,[a,e,c]]],[a,e],[a,e,c],[c],P). P = [[append, [a, a, e]], [delete, [a, e, c]]] . optimise([[append,[a,e,c]]],[a,e,c],[a,e,c],[c],P). P = [[append, [a, e, c]]] . findrulesflowingtopv1([[append,[a,e,c]],[member,[a,e]]],[a],[a,e,c],[c],[],R,F). R = [[append, [a, e, c]], [member, [a, e]]] check optimise works with member ef v member ef and member in inputvars2 (cde) v optimise - aeg (remove e), v does optimise work with multiple rules with same output v delete returning progs in optimise v cut rule - aea cant point to itself in optimise - needs iterative deepening aec where e not in iv1 or another pred, try first or second in prog v don't pass rule to lower predicates v don't choose outputs from non new var v don't run repeat preds make predicate, clause writer member predicates returning no output **/ %% ML max 25 :- include('algdict.pl'). caw00(Debug,PredicateName,Rules,MaxLength,TotalVars,InputVarList,OutputVarList,Program1,_Program2,Ps1) :- findall([TestNumber,Queries,Functions], test(TestNumber,Queries,Functions),Algorithms), %% Collects algorithms algorithmstopredicates(Algorithms,[],Predicates), repeat, %%MaxLength2 is MaxLength + 1, %%TotalVars = MaxLength, /**randvars(MaxLength,MaxLength,[],RandVars), populatevars(RandVars,MaxLength,[],PV), Code is MaxLength + 1 + 97, char_code(Char,Code), OutputVarList=[[[v,Char],1]],**/ retractall(debug(_)), assertz(debug(Debug)), retractall(totalvars(_)), assertz(totalvars(TotalVars)), caw0(Predicates,PredicateName,Rules,MaxLength,InputVarList,OutputVarList,Program1,_Program3,Ps), sort(Ps,Ps1),not(Ps1=[]),!. randvars(0,_,V,V) :- !. randvars(N,L,V1,V2) :- random(N1), N2A is round(97+(N1*L)), char_code(V3,N2A), V31=[v,V3], ((member(V31,V1))->randvars(N,L,V1,V2); (append(V1,[V31],V4), NA is N-1, randvars(NA,L,V4,V2))),!. randvars2(0,_L,V,V) :- !. randvars2(N,L,V1,V2) :- random(N1), N2A is round(97+(N1*L)), char_code(V3,N2A), atom_string(V3,V4), %%V41=[v,V4], ((member(V4,V1))->randvars2(N,L,V1,V2); (append(V1,[V4],V5), NA is N-1, randvars2(NA,L,V5,V2))),!. populatevars([],_,PV,PV) :- !. populatevars([RV1|RVs],MaxLength2,PV1,PV2) :- randvars2(MaxLength2,MaxLength2,[],RV2), append(PV1,[[RV1,RV2]],PV3), populatevars(RVs,MaxLength2,PV3,PV2),!. caw0(Algorithms,PredicateName,Rules,MaxLength,InputVarList,OutputVarList,Program1,Program2,Ps2) :- varnames(InputVarList,[],InputVars,[],InputValues), varnames(OutputVarList,[],OutputVars,[],_OutputValues), retractall(outputvars(_)), assertz(outputvars(OutputVars)), append(InputVars,OutputVars,Vars11), %%Vars11=InputVars, %%Vars12=InputVars, append(InputValues,OutputVars,Vars2), %%append(InputValues,OutputValues,Values), Query=[PredicateName,Vars2], caw1(Algorithms,Query,PredicateName,Rules,MaxLength,Vars11,InputVars,InputVars,_,OutputVarList,OutputVars,Program1,Program2,[],Ps2), !. caw1(_,_,_,_,0,_,_,_,_,_,_,_,_,Ps,Ps) :- !. caw1(Algorithms,Query,PredicateName,Rules,MaxLength,VarList,InputVars1,InputVars2,InputVars3,OutputVarList,OutputVars,Program1,Program2,Programs2,Ps1) :- MaxLength2 is MaxLength - 1, addrules0(InputVars2,OutputVars,OutputVars,[],Program3), %%writeln([addrules(InputVars2,OutputVars,OutputVars,[],PenultimateVars,[],Program3)]), %%optimise(Program1,InputVars1,InputVars2,PenultimateVars,Program4), %% IV2->3 %%writeln([optimise(Program1,InputVars1,InputVars2,PenultimateVars,Program4)]), append(Program1,Program3,Program5), append(InputVars1,OutputVars,Vars2), Program2=[ [PredicateName,Vars2,":-", Program5 ] ],debug(Debug), %%writeln([interpret(Debug,Query,Program2,OutputVarList2)]), interpret(Debug,Query,Program2,OutputVarList), %%writeln([interpret(Debug,Query,Program2,OutputVarList2)]), append(Programs2,[[Query,Program2,OutputVarList]],Programs3), caw1a(Algorithms,Query,PredicateName,Rules,MaxLength2,VarList,InputVars1,InputVars2,InputVars3,OutputVarList,OutputVars,[],_Program2,Programs3,Ps1),!. %%caw1(_Query,_PredicateName,_Rules,_MaxLength,_VarList,_InputVars1,_InputVars2,_InputVars3,_OutputVarList,_OutputVars,_Program1,_Program4,Ps,Ps) :- writeln(here1),!. caw1(Algorithms,Query,PredicateName,Rules,MaxLength2,VarList,InputVars1,InputVars2,InputVars3,OutputVarList,OutputVars,[],_Program2,Programs3,Programs3) :- !. %%writeln([here1, caw1(Query,PredicateName,Rules,MaxLength2,VarList,InputVars1,InputVars2,InputVars3,OutputVarList,OutputVars,[],_Program21,Programs3,Programs3)]),!. caw1a(Algorithms,Query,PredicateName,Rules,MaxLength,VarList,InputVars1,InputVars2,InputVars3,OutputVarList,OutputVars,Program1,Program4,Ps1,Ps2) :- %%writeln([caw(Query,PredicateName,Rules,MaxLength,VarList,InputVars1,InputVars2,OutputVarList,OutputVars,Program1,Program4)]), %%MaxLength2 is MaxLength - 1, %%writeln(["ml",MaxLength2]), reverse(InputVars2,InputVars5), random_member([RuleName,NumInputs,NumOutputs],Rules), %%writeln([member([RuleName,NumInputs,NumOutputs],Rules)]), %%writeln([rule(RuleName,NumInputs,NumOutputs,VarList,VarList2,Rule)]), rule(Algorithms,RuleName,NumInputs,NumOutputs,InputVars5,InputVars4,VarList,VarList2,Rule), %%writeln([inputVars1,InputVars1]), %% writeln([rule(RuleName,NumInputs,NumOutputs,InputVars5,InputVars4,VarList,VarList2,Rule)]), append(Program1,[Rule],Program3), %%writeln([inputVars3,InputVars3]), %%InputVars2=InputVars3, %%writeln([program4,Program4]), %%caw1a(Query,PredicateName,Rules,MaxLength,VarList,InputVars1,InputVars2,InputVars3,OutputVarList,OutputVars,Program1,Program4,Ps,Ps) :- %%writeln([here,caw1a(Query,PredicateName,Rules,MaxLength,VarList,InputVars1,InputVars2,InputVars3,OutputVarList,OutputVars,Program1,Program4,Ps,Ps)]) caw(Algorithms,Query,PredicateName,Rules,MaxLength,VarList2,InputVars1,InputVars4,InputVars3,OutputVarList,OutputVars,Program3,Program4,Ps1,Ps2),!. caw(_,_,_,_,0,_,_,_,_,_,_,_,_,Ps,Ps) :- !. caw(Algorithms,Query,PredicateName,Rules,MaxLength,VarList,InputVars1,InputVars2,InputVars3,OutputVarList,OutputVars,Program1,Program2,Programs1,Programs2) :- MaxLength2 is MaxLength - 1, addrules(InputVars2,OutputVars,OutputVars,[],_PenultimateVars,[],Program3), %%writeln([addrules(InputVars2,OutputVars,OutputVars,[],PenultimateVars,[],Program3)]), %%optimise(Program1,InputVars1,InputVars2,PenultimateVars,Program4), %% IV2->3 %%writeln([optimise(Program1,InputVars1,InputVars2,PenultimateVars,Program4)]), append(Program1,Program3,Program5), append(InputVars1,OutputVars,Vars2), Program2=[ [PredicateName,Vars2,":-", Program5 ] ],debug(Debug), %%*** %% () choose iv1 as args during caw, () eliminate e problem, could move forward in optimiser but don't need it v %% should have a leading edge of 1 immediately previous (new output) as an arg in latest rule v, go backwards to choose latest possible args x, 3 x rules can have same as previous rule's output as an output x: at a time %% chunks will solve having at least 1 rule that connects to last output %% can optimise number of inputs %% test member, = in caw %%writeln([interpret(Debug,Query,Program2,OutputVarList2)]), interpret(Debug,Query,Program2,OutputVarList), %%writeln([interpret(Debug,Query,Program2,OutputVarList2)]), append(Programs1,[[Query,Program2,OutputVarList]],Programs3), cawa(Algorithms,Query,PredicateName,Rules,MaxLength2,VarList,InputVars1,InputVars2,InputVars3,OutputVarList,OutputVars,[],_Program2,Programs3,Programs2),!. %%caw(_,_,_,_,_,_,_,_,_,_,_,_,Ps,Ps) :- !. caw(Algorithms,Query,PredicateName,Rules,MaxLength2,VarList,InputVars1,InputVars2,InputVars3,OutputVarList,OutputVars,[],_Program2,Programs3,Programs3) :- %%writeln([here2, caw(Query,PredicateName,Rules,MaxLength2,VarList,InputVars1,InputVars2,InputVars3,OutputVarList,OutputVars,[],_Program21,Programs3,Programs3)]), !. cawa(Algorithms,Query,PredicateName,Rules,MaxLength,VarList,InputVars1,InputVars2,InputVars3,OutputVarList,OutputVars,Program1,Program4,Ps1,Ps2) :- %%writeln([caw(Query,PredicateName,Rules,MaxLength,VarList,InputVars1,InputVars2,OutputVarList,OutputVars,Program1,Program4)]), %%MaxLength2 is MaxLength - 1, %%writeln(["ml",MaxLength2]), random_member([RuleName,NumInputs,NumOutputs],Rules), %%writeln([member([RuleName,NumInputs,NumOutputs],Rules)]), %%writeln([rule(RuleName,NumInputs,NumOutputs,VarList,VarList2,Rule)]), rule(Algorithms,RuleName,NumInputs,NumOutputs,InputVars2,InputVars4,VarList,VarList2,Rule), %%writeln([inputVars1,InputVars1]), %% writeln([rule(RuleName,NumInputs,NumOutputs,InputVars2,InputVars4,VarList,VarList2,Rule)]), append(Program1,[Rule],Program3), %%writeln([inputVars3,InputVars3]), %%InputVars2=InputVars3, %%writeln([program4,Program4]), caw(Algorithms,Query,PredicateName,Rules,MaxLength,VarList2,InputVars1,InputVars4,InputVars3,OutputVarList,OutputVars,Program3,Program4,Ps1,Ps2), !. varnames([],Vars,Vars,Values,Values) :- !. varnames(VarList,Vars1,Vars2,Values1,Values2) :- VarList=[Var|Vars3], Var=[VarName,Value], append(Vars1,[VarName],Vars4), append(Values1,[Value],Values3), varnames(Vars3,Vars4,Vars2,Values3,Values2),!. addrules0(_,_,[],Program,Program) :- !. addrules0(VarList,OutputVars1,OutputVars2,Program1,Program2) :- OutputVars2=[OutputVar|OutputVars3], random_member(Var,VarList), random_member(OutputVar,OutputVars1), append(Program1,[[[n,=],[OutputVar,Var]]],Program3), addrules0(VarList,OutputVars1,OutputVars3,Program3,Program2),!. addrules(_,_,[],PV,PV,Program,Program) :- !. addrules(VarList,OutputVars1,OutputVars2,PenultimateVars1,PenultimateVars2,Program1,Program2) :- restlast(VarList,[],_,Var), %%OutputVars2=[OutputVar|OutputVars3], random_member(OutputVar,OutputVars2), delete(OutputVars1,OutputVar,OutputVars3), %% member(Var,VarList), random_member(OutputVar,OutputVars1), append(Program1,[[[n,=],[OutputVar,Var]]],Program3), append(PenultimateVars1,[Var],PenultimateVars3), addrules2(VarList,OutputVars1,OutputVars3,PenultimateVars3,PenultimateVars2,Program3,Program2),!. addrules2(_,_,[],PV,PV,Program,Program) :- !. addrules2(VarList,OutputVars1,OutputVars2,PenultimateVars1,PenultimateVars2,Program1,Program2) :- %% restlast(VarList,[],_,Var), OutputVars2=[OutputVar|OutputVars3], random_member(Var,VarList), not(member(Var,PenultimateVars1)), random_member(OutputVar,OutputVars1), append(Program1,[[[n,=],[OutputVar,Var]]],Program3), append(PenultimateVars1,[Var],PenultimateVars3), addrules2(VarList,OutputVars1,OutputVars3,PenultimateVars3,PenultimateVars2,Program3,Program2),!. %% optimise([[append,[a,a,d]],[append,[a,a,e]],[append,[a,a,f]],[append,[a,b,g]]],[g],P). /** optimise(Program1,InputVars1,InputVars2,PenultimateVars,Program2) :- reverse(Program1,Program4), findrulesflowingtopv1(Program4,InputVars1,InputVars2,PenultimateVars,[],Rules,true), %%findrulesflowingtopv1a(Program1,_Program32,InputVars1,InputVars2,PenultimateVars,[],_Rules1), intersection(Program1,Rules,Program3), unique1(Program3,[],Program2). findrulesflowingtopv1(_,_,_,[],Rules,Rules,false). findrulesflowingtopv1(Program0,InputVars1,InputVars2,Var,Rules1,Rules2,IV1Flag1) :- (atom(Var);length(Var,1)), findrulesflowingtopv20(Program0,Program0,InputVars1,InputVars2,Var,Rules1,Rules2,IV1Flag1). findrulesflowingtopv1(Program0,InputVars1,InputVars2,Vars1,Rules1,Rules2,IV1Flag1) :- Vars1=[Var|Vars2], findrulesflowingtopv20(Program0,Program0,InputVars1,InputVars2,Var,Rules1,Rules3,IV1Flag2), findrulesflowingtopv1(Program0,InputVars1,InputVars2,Vars2,Rules3,Rules2,IV1Flag3), iv1flagdisjunction(IV1Flag2,IV1Flag3,IV1Flag1). %%findrulesflowingtopv2([],Program,Program,_,_,Rules,Rules). findrulesflowingtopv20(_,[],_InputVars1,_InputVars2,_Var,Rules,Rules,false). findrulesflowingtopv20(Program0,Rules4,InputVars1,InputVars2,Var,Rules1,Rules2,IV1Flag1) :- Rules4=[Rule|Rules], (findrulesflowingtopv2(Program0,Rule,InputVars1,InputVars2,Var,Rules1,Rules3,IV1Flag2)->true;(Rules3=Rules1,IV1Flag2=false)), %%delete(Program0,Rule,Program1), findrulesflowingtopv20(Program0,Rules,InputVars1,InputVars2,Var,Rules3,Rules2,IV1Flag3),%%p1->0 iv1flagdisjunction(IV1Flag2,IV1Flag3,IV1Flag1). %%findrulesflowingtopv2(_,[],[],_,_,_,Rules,Rules). findrulesflowingtopv2(Program0,Rule,InputVars1,InputVars2,Var,Rules1,Rules2,IV1Flag1) :- Rule=[_PredicateName,Vars], restlast(Vars,[],Rest,Var), %%delete(Program1,[PredicateName,Vars],Program2), %%Program2=Program1, %%(not(intersection(Rulesx,Rules1))-> x %% append, append, unique1 %%append(Rules1,[Rule],Rules3);Rules3=Rules1), %%member(Var2,Rest), %%member(Var2,InputVars1), length(Rest,Length1), Length1>=1, subtract(Rest,InputVars1,IV3s), length(IV3s,Length3), subtract(Rest,IV3s,IV1s), length(IV1s,Length2), Length2>=1, subtract(IV3s,InputVars2,[]), IV1Flag2=true, %%delete(Program0,Rule,Program1), %%(delete(Program0,Rule,Program3), %%iv3s1(IV3s,Program3,IV3s,[]), (Length3>=1-> (findrulesflowingtopv1(Program0,InputVars1,InputVars2,IV3s,[],Rules5,IV1Flag3),not(Rules5=[])); (Rules5=[],IV1Flag3=false)), iv1flagdisjunction(IV1Flag2,IV1Flag3,IV1Flag4), %%->true; Rules5=[],IV1Flag1=IV1Flag4), ((findrulesflowingtopv1(Program0,InputVars1,InputVars2,IV1s,[],Rules6,IV1Flag5), %%iv1s->rest, etc iv1flagdisjunction(IV1Flag4,IV1Flag5,IV1Flag1))->true;(Rules6=[],IV1Flag1=IV1Flag4)), append([Rule],Rules1,Rules9), append(Rules9,Rules5,Rules7), append(Rules7,Rules6,Rules8), unique1(Rules8,[],Rules2). /** findrulesflowingtopv2(_Program0,Rule,InputVars1,InputVars2,Var,Rules1,Rules2,IV1Flag1) :- Rule=[_PredicateName,Vars], restlast(Vars,[],Rest,Var), %%delete(Program1,[PredicateName,Vars],Program2), %%Program2=Program1, (not(member(Rule,Rules1))-> append(Rules1,[Rule],Rules2);Rules2=Rules1), subset(Rest,InputVars2), intersection(Rest,InputVars1,Intersection), length(Intersection,0), %% not((member(Var2,Rest), %% member(Var2,InputVars1))), IV1Flag1=false. **/ /** findrulesflowingtopv2(Program0,Rule,InputVars1,InputVars2,Var,Rules1,Rules2,IV1Flag1) :- Rule=[_PredicateName,Vars], restlast(Vars,[],Rest,Var), %%delete(Program1,[PredicateName,Vars],Program3), %%Program3=Program1, %%append(Rules1,[Rule],Rules3), subset(Rest,InputVars2), intersection(Rest,InputVars1,Intersection), length(Intersection,0), %% not((member(Var2,Rest), %% member(Var2,InputVars1))), %% delete(Program0,Rule,Program1), IV1Flag2=false, findrulesflowingtopv1(Program0,InputVars1,InputVars2,Rest,[],Rules4,IV1Flag3), %%not(Rules4=[]), iv1flagdisjunction(IV1Flag2,IV1Flag3,IV1Flag1), append(Rules1,[Rule],Rules7), append(Rules7,Rules4,Rules8), unique1(Rules8,[],Rules2). **/ /** %%->true;(Program2=Program1,Rules2=Rules1)). findrulesflowingtopv2(Rule,Program0,Program1,_Program2,InputVars1,InputVars,Var,Rules1,Rules2,IV1Flag1) :- Rule=[PredicateName,Vars], restlast(Vars,[],Rest,Var), %%delete(Program1,[PredicateName,Vars],Program4), %%Program4=Program1, append(Rules1,[[PredicateName,Vars]],Rules3), findrulesflowingtopv1(Program0,Program1,_Program2,InputVars1,InputVars,Rest,Rules3,Rules2,IV1Flag3), iv1flagdisjunction(IV1Flag2,IV1Flag3,IV1Flag1). %%findrulesflowingtopv2(Program5,Program2,Rest,Rules3,Rules2). **/ iv1flagdisjunction(A,B,true) :- ((A=true)->true; (B=true)),!. iv1flagdisjunction(_,_,false) :- !. /** iv3s0([],_,IV3s1,IV3s2). iv3s0(IV3s,Program0,IV3s1,IV3s2). IV3s=[IV3|IV3s3], iv3s1(IV3,Program0,IV3s1,IV3s4), iv3s0(IV3s3,Program0,IV3s4,IV3s2). iv3s1(_,[],IV3s,IV3s). iv3s1(IV3,Program0,IV3s1,IV3s2) :- Program0=[Rule|Rules], iv3s2(IV3,Rule,IV3s1,IV3s3), iv3s1(IV3,Rules,IV3s3,IV3s2). iv3s2(IV3,Rule,IV3s,IV3s1,IV3s2). Rule=[_PredicateName,Vars], restlast(Vars,[],_Rest,IV3), delete(IV3s1,IV3,IV3s2). findrulesflowingtopv1a(_,_,_,_,[],Rules,Rules). findrulesflowingtopv1a(Program1,Program2,InputVars1,InputVars2,Var,Rules1,Rules2) :- atom(Var), findrulesflowingtopv2a(Program1,Program2,InputVars1,InputVars2,Var,Rules1,Rules2). findrulesflowingtopv1a(Program1,Program2,InputVars1,InputVars2,Vars1,Rules1,Rules2) :- Vars1=[Var|Vars2], findrulesflowingtopv2(Program1,Program3,InputVars1,InputVars2,Var,Rules1,Rules3), findrulesflowingtopv1a(Program3,Program2,InputVars1,InputVars2,Vars2,Rules3,Rules2). %%findrulesflowingtopv2([],Program,Program,_,_,Rules,Rules). findrulesflowingtopv2a([],[],_,_,_,Rules,Rules). findrulesflowingtopv2a(Program1,Program2,_InputVars1,InputVars2,Var,Rules1,Rules2) :- member([PredicateName,Vars],Program1), restlast(Vars,[],Rest,Var), ( %%delete(Program1,[PredicateName,Vars],Program2), Program2=Program1, append(Rules1,[[PredicateName,Vars]],Rules2), subset(Rest,InputVars2)). findrulesflowingtopv2a(Program1,Program2,InputVars1,InputVars2,Var,Rules1,Rules2) :- member([PredicateName,Vars],Program1), restlast(Vars,[],Rest,Var), ( %%delete(Program1,[PredicateName,Vars],Program3), Program3=Program1, append(Rules1,[[PredicateName,Vars]],Rules3), subset(Rest,InputVars2)), findrulesflowingtopv1a(Program3,Program2,InputVars1,InputVars2,Rest,Rules3,Rules2). %%->true;(Program2=Program1,Rules2=Rules1)). findrulesflowingtopv2a(Program1,Program2,InputVars1,InputVars,Var,Rules1,Rules2) :- member([PredicateName,Vars],Program1), restlast(Vars,[],Rest,Var), %%delete(Program1,[PredicateName,Vars],Program4), Program4=Program1, append(Rules1,[[PredicateName,Vars]],Rules3), findrulesflowingtopv1a(Program4,Program2,InputVars1,InputVars,Rest,Rules3,Rules2). %%findrulesflowingtopv2(Program5,Program2,Rest,Rules3,Rules2). **/ **/ restlast([],_,_,_) :- fail, !. restlast([Last],Rest,Rest,Last) :- Last=[v,_],!. restlast(Last,Rest,Rest,Last) :- length(Last,1),!. restlast(Vars1,Rest1,Rest2,Last) :- Vars1=[Var|Vars2], append(Rest1,[Var],Rest3), restlast(Vars2,Rest3,Rest2,Last),!. %% check list reduced to predicate names/arity are together, error otherwise %% numbers in order, error otherwise algorithmstopredicates([],Predicates1,Predicates2) :- sort(Predicates1,Predicates2),!. algorithmstopredicates(Algorithms1,Predicates1,Predicates2) :- Algorithms1=[Algorithm1|Algorithms2], Algorithm1=[_,_,Algorithm3], Algorithm3 %% find rest of clause set in whole algorithm, not just next append_list(Predicates1,Algorithm3,Predicates4), algorithmstopredicates(Algorithms2,Predicates4,Predicates2),!. append_list(A,[],A) :-!. append_list(A,List,B) :- List=[Item|Items], append(A,[Item],C), append_list(C,Items,B). %%rule(Algorithms %% Assume predicate names are all different, or the same if they are the same, so sort them (should give error for same names, different predicate at start) rule(Algorithms,RuleName,_,_,InputVars1,InputVars2,VarList,VarList2,Rule) :- random_member(Var,InputVars1), rule2(RuleName,Var,VarList,VarList2,Rule,Var1), restlast(InputVars1,[],_,Last), %% Last should be outputs - 2nd last rule? (Var=Last->true;Last=Var1), append(InputVars1,[Var1],InputVars2),!. rule(RuleName,1,2,InputVars1,InputVars2,VarList,VarList2,Rule) :- random_member(Var,InputVars1), rule3(RuleName,Var,VarList,VarList2,Rule,Var1,Var2), restlast(InputVars1,[],_,Last), (Var=Last->true; (Last=Var1->true;Last=Var2)), append(InputVars1,[Var1,Var2],InputVars2),!. rule(RuleName,2,0,InputVars,InputVars,VarList,VarList,Rule) :- %%writeln([rule(RuleName,2,1,InputVars1,InputVars2,VarList,VarList2,Rule)]), random_member(Var,InputVars), random_member(Vara,InputVars), rule6(RuleName,Var,Vara,_VarList,_VarList2,Rule), restlast(InputVars,[],_,Last), %%writeln([last,Last]), (Var=Last->true;Vara=Last),!. rule(RuleName,2,1,InputVars1,InputVars2,VarList,VarList2,Rule) :- %%writeln([rule(RuleName,2,1,InputVars1,InputVars2,VarList,VarList2,Rule)]), random_member(Var,InputVars1), random_member(Vara,InputVars1), rule4(RuleName,Var,Vara,VarList,VarList2,Rule,Var1), restlast(InputVars1,[],_,Last), %%writeln([last,Last]), ((Var=Last->true;Vara=Last)->true; (Last=Var1)), %%writeln([var,Var,vara,Vara]), append(InputVars1,[Var1],InputVars2),!. rule(RuleName,2,2,InputVars1,InputVars2,VarList,VarList2,Rule) :- random_member(Var,InputVars), random_member(Vara,InputVars), rule5(RuleName,Var,Vara,VarList,VarList2,Rule,Var1,Var2), restlast(InputVars1,[],_,Last), ((Var=Last->true;Vara=Last)->true; (Last=Var1->true;Last=Var2)), %% make last var2, use different inputs from previous rule, make this line usea version of previous line as well (args from rule before that) - redo rules based on past programming append(InputVars1,[Var1,Var2],InputVars2),!. rule2(RuleName,Var,VarList,VarList2,Rule,Var1) :- var(VarList,Var1,VarList2), Rule=[RuleName,[Var,Var1]],!.%%, %%member(Var,!. rule3(RuleName,Var,VarList,VarList3,Rule,Var1,Var2) :- var(VarList,Var1,VarList2), var(VarList2,Var2,VarList3), Rule=[RuleName,[Var,Var1,Var2]],!. rule6(RuleName,Var,Vara,_VarList,_VarList2,Rule) :- Rule=[RuleName,[Var,Vara]],!. rule4(RuleName,Var,Vara,VarList,VarList2,Rule,Var1) :- var(VarList,Var1,VarList2), Rule=[RuleName,[Var,Vara,Var1]],!. %%ae be with predicate support also rule5(RuleName,Var,Vara,VarList,VarList3,Rule,Var1,Var2) :- var(VarList,Var1,VarList2), var(VarList2,Var2,VarList3), Rule=[RuleName,[Var,Vara,Var1,Var2]],!. %%var(Item,Var,Vars,Vars) :- %% member([Item,Var],Vars). var(Vars1,Var1,Vars2) :- length(Vars1,Vars1Length1), Vars1Length2 is Vars1Length1-1, length(Vars3,Vars1Length2), append(Vars3,[Var2],Vars1), Var2=[v,Var21], char_code(Var21,Var2Code1), Var2Code2 is Var2Code1 + 1, var2(Var2Code2,Var1), append(Vars1,[Var1],Vars2),!. var2(Code,Var1) :- outputvars(OutputVars), totalvars(TotalVars), Code2 is 96+TotalVars, Code =< Code2, %% 122 char_code(Var11,Code), Var1=[v,Var11], not(member(Var1,OutputVars)),!. var2(Var2Code,Code3) :- Var2Code2 is Var2Code + 1, totalvars(TotalVars), Code2 is 96+TotalVars, Var2Code2 =< Code2, var2(Var2Code2,Code31), Code3=[v,Code31],!. %% this goes from e.g. c not a to TotalVars %% skip over vars, start from a x reassign vars to abc etc %% if returning 12 from 12345 remove 345 args %% try lowest possible number of vars first (return shortest program first), then keep on adding number of vars %% can elimininate same program both here and in assessment verification