Headless Prolog?

I’ve been playing around with prolog and realised something. You can do everything without predicate names.

e.g. Just change all predicates

$ $ a(b,c,d,e,..)$ $

into

$ $ prop(a,b,c,d,e,..)$ $

Where $ prop$ is some character that you can use for all function names.

So $ isRed(X)$ becomes $ prop(isRed,X)$ .

Which makes me wonder if there is any point to prolog having function heads? Couldn’t everthing be done using lists? e.g. $ loves(romeo,juliet)$ could just as easily be written $ [loves,romeo,juliet]$ without loss of information.

Have I missed something or is there anything special about predicate function heads?

It is possible (and how to do) forward chaining (inference) in (standard) Prolog?

Forward chaining (inference) is an easy process that tries to deduct interesting consequences from some set of axioms/rules/premises. The hard thing is to focus on the deduction path that gives some results of any worth, there can be deduced many uninteresting results along the many possible deduction paths as well and that can lead to the wasted resources. The article http://www.isle.org/~langley/papers/icarus.rrl.ilp05.pdf uses symbolic (relational) reinforcement learning method to learn deduction paths to the interesting set of consequences. So, there is some theory about forward chaining.

My question is – is it possible and how to do the full first order forward chaining with Prolog? Prolog is intended for the backward chaining, but maybe it is possible to use it for forward chaining as well?

I am reading https://content.sciendo.com/view/journals/ausi/8/1/article-p41.xml and that can lead to some ideas about answer.

Substructural Prolog?

Substructural logic is logic without some or all of the structural rules. Is substructural Prolog, substructural logic programming possible? My question is connected with article https://link.springer.com/chapter/10.1007/3-540-40030-3_8 Grammar Induction as Substructural Inductive Logic Programming – if substructural Prolog is possible then one can implement substructural inductive logic programming in it (e.g. http://ilasp.com/ for the answer set version of ILP over Prolog in the non-substructural setting) and apply, e.g. in grammar induction case.

How hard the usual (e.g. SWI) Prolog should be remade to be used as substructural Prolog?

Ejercicio prolog

Tengo un par de dudas con dos predicados en prolog, tengo el predicado lista_hojas(Lista,Hojas) y quiero que me devuelva en otra lista las hojas, como por ejemplo:

lista_hojas([1,2,3],Hojas) Hojas = [tree(1,void,void),tree(2,void,void),tree(3,void,void)] 

Y por otro lado, un predicado hojas_árbol(Hoja, Com, Arbol) que devuelve el árbol inicial, de la siguiente manera:

tree(1,tree(1,tree(1,void,void),tree(2,void,void)),tree(3,void,void)) 

Un saludo y gracias.

problema com jogo em Prolog usando Matriz numérica

Eu estou fazendo um “jogo” no Prolog, a partir de uma posição inicial em uma matriz, o jogo deve retornar todos os caminhos possíveis, onde toda a matriz é -1 e a posição atual é definida como 0. Deve escrever todas as rotas possíveis em um arquivo .txt

Estou editando por sublime, compilando usando SWI-Prolog.

inicia(X,Y,Matriz,Caminho) :- jogar(Matriz,X,Y,Caminho), escreveArq(Caminho). 

Imprime a matriz atual do jogo

imprimeMatriz([]). imprimeMatriz([H|T]) :- imprimeLista(H),nl, imprimeMatriz(T). imprimeLista([]). imprimeLista([H|T]) :- write(H),  write(", "), imprimeLista(T). 

Escreve no arquivo

escreveArq([]). escreveArq(Rota) :- open('caminho.txt', write, ID), writeq(ID,Rota), write(ID,'\n'), close(ID). 

Recupera elemento da lista

recuperaElemento(X, Y, Elemento,Matriz) :- achaElemento(X,0,Matriz,ListaX), achaElemento(Y,0,ListaX,Elemento). 

Acha um elemento.

achaElemento(_,_,[],_) :- false. achaElemento(Elemento,Aux,[H|_],H) :- Elemento == Aux. achaElemento(Elemento,Aux,[_|HT],R) :- Aux1 is Aux + 1, achaElemento(Elemento,Aux1,HT,R). 

Descobre vizinhos de (X,Y)

elementoSuperior(X,Y,Elemento,Matriz) :- N is X-1, recuperaElemento(N,Y,Elemento, Matriz). elementoSuperior(_,_,-5,_). elementoInferior(X,Y,Elemento,Matriz) :- N is X+1, recuperaElemento(N,Y,Elemento,Matriz). elementoInferior(_,_,-5,_). elementoDireita(X,Y,Elemento,Matriz) :- N is Y+1, recuperaElemento(X,N,Elemento,Matriz). elementoDireita(_,_,-5,_). elementoEsquerda(X,Y,Elemento,Matriz) :- N is Y-1, recuperaElemento(X,N,Elemento,Matriz). elementoEsquerda(_,_,-5,_). 

Verifica se jogo chegou ao fim

fimDeJogo(Matriz) :- verificaFim(Matriz,R), R == 1.     verificaFim([],X) :- X is 0.     verificaFim([H|T],X) :- verificaFimColuna(H,X1), verificaFim(T,X2), X is X1 + X2.     verificaFimColuna([],X) :- X is 0, !.     verificaFimColuna([H|T],R) :- H == -1, verificaFimColuna(T, R).     verificaFimColuna([H|T],X) :- H == 0, verificaFimColuna(T, R), X is R+1. 

Jogo em si

jogar(Matriz, _,_,_) :- fimDeJogo(Matriz). jogar(Matriz, X,Y,["S"|Rota]) :- elementoSuperior(X,Y,Z,Matriz),Z > -1,decrementa(X,Y,Matriz,NMAtriz),                                                                                         NX is X-1,jogar(NMAtriz, NX, Y,Rota). jogar(Matriz, X,Y,["I"|Rota]) :- elementoInferior(X,Y,Z,Matriz),Z > -1,decrementa(X,Y,Matriz,NMAtriz),                                                                                         NX is X+1,jogar(NMAtriz, NX, Y,Rota). jogar(Matriz, X,Y,["E"|Rota]) :- elementoEsquerda(X,Y,Z,Matriz),Z > -1,decrementa(X,Y,Matriz,NMAtriz),                                                                                         NY is Y-1,jogar(NMAtriz, X, NY,Rota). jogar(Matriz, X,Y,["D"|Rota]) :- elementoDireita(X,Y,Z,Matriz) ,Z > -1,decrementa(X,Y,Matriz,NMAtriz),                                                                                         NY is Y+1,jogar(NMAtriz, X, NY,Rota). 

Muda numero em (X,Y)

decrementa(X,Y,Matriz, MatrizAtualizada) :- reduzX(X,Y,0,0,Matriz,MatrizAtualizada).     reduzX(_,_,    _,    _,    [],         []) .     reduzX(X,Y,    X, AuxY, [H|T], [LAlt|Mat]) :- NX is X+1,reduzY(X,Y, AuxY,  AuxY, H, LAlt), reduzX(X,Y,NX, AuxY, T, Mat).     reduzX(X,Y, AuxX, AuxY, [H|T], [   H|Mat]) :- NAuxX is AuxX+1, reduzX(X,Y,NAuxX, AuxY, T,  Mat).         reduzY(_,_, _,    _,    [],       []) .         reduzY(_,Y, _,    Y, [H|T], [NH|MAT]) :- NH is H-1, NY is Y+1,   reduzY(_,Y, _, NY, T, MAT).         reduzY(_,Y, _, AuxY, [H|T], [ H|MAT]) :-           NY is AuxY+1, reduzY(_,Y, _, NY, T, MAT). 

Meu problema: para algumas matrizes, exemplo [[1,1,1], [1,1,1], [1,1,1]] gera um caminho errado e apresenta apenas um caminho.

IDEA: Content is not allowed in prolog

My Jetbains IDEA encountered a major error. When I run any project, including a new project, the standard output window show below:

Buildfile: C:\Users\kent\IdeaProjs\Demo\src\main\java\com\kent\Test.java

BUILD FAILED C:\Users\kent\IdeaProjs\Demo\src\main\java\com\kent\Test.java:1: Content is not allowed in prolog.

Total time: 0 seconds

Process finished with exit code 1

And the content of Test.java only is :

package com.kent.test;  public class Test {    public static void main(String[] args) {        System.out.println("hihi");    } } 

Basic logic problem in Prolog

I thought it would be a good idea to take some easy to solve (by hand) problems and model them in Prolog for practice. Here is a problem I modeled in Prolog:

A messy kid wrote a multiplication problem.

  1. Alice saw 100 x 6.
  2. Bob saw 101 x 6.
  3. Dan saw 102 x 9.

Each one only misread one digit. What is the real solution to the problem?

It proved to be (much) trickier to model than solve by hand, but here is what I came up with:

%- Read person saw number at position. saw(alice, 1, 0). saw(alice, 0, 1). saw(alice, 0, 2). saw(alice, 6, 3).  saw(bob, 1, 0). saw(bob, 0, 1). saw(bob, 1, 2). saw(bob, 6, 3).  saw(dan, 1, 0). saw(dan, 0, 1). saw(dan, 2, 2). saw(dan, 9, 3).  %- Consider the case when two people see one number and one person saw a anoth- % er number. This doesnt actually mean the person "definitely" misread the nu- % mber, but if the problem can be solved it measns they definitely did. definitely_misread(Person, Digit, Position) :-   saw(Person, Digit, Position),   saw(Q, D, Position), Q \== Person, D \== Digit,   saw(R, D, Position), R \== Q, R \== Person.  %- Read a person misread the digit at poisition at position. misread(Person, Digit, Position) :-   saw(Person, Digit, Position),   not((definitely_misread(Person, D, P), D \== Digit, P \== Position)),   (saw(Q, D1, Position), Q \== Person, D1 \== Digit),   (saw(R, D2, Position), R \== Q, R \== Person, D2 \== Digit).  %- Resolve if the question is actually the correct digit at that position. correct(Digit, Position) :-   (saw(alice, Digit, Position), not(misread(alice, Digit, Position)));   (saw(bob, Digit, Position), not(misread(bob, Digit, Position)));   (saw(dan, Digit, Position), not(misread(dan, Digit, Position))). 

And thus one can get the correct solutions by calling correct (although, it displays some digit position pairings multiple times):

?- correct(D, P). D = 1, P = 0 ; D = 0, P = 1 ; D = 6, P = 3 ; D = 1, P = 0 ; D = 0, P = 1 ; D = 6, P = 3 ; D = 1, P = 0 ; D = 0, P = 1 ; D = P, P = 2 ; false.