0
votes

i've the following Problem. I have a List 'A' lets call it "assumptions" and with the predicate ass(A,P) I want to check, if all of this assumptions does occure in some form in the variable Proof.

For example, if I call:

?- ass([a, b], [[[1], 1, a, 'A', ''], [[2], 2, a->b, 'A',''], [[3], 3, b, 'A', '']]).

it should give the value true, cause [[1], 1, a, 'A', ''] and [[3], 3, b, 'A', '']] are the elements in P assigned to 'a' and 'b' in the list A.

?- ass([a,b],P).

e.g. should deliver P=[[[1], 1, a, 'A', ''], [[2], 2, b, 'A','']]

I've tried to solve it with the following code:

do_list(N, L):- 
  findall(Num, between(1, N, Num), L).
succ(A, P, I) :- [[I], I, A, 'A', ''] == P.
ass(A, P) :- length(A, L1), length(P,L2), L3 is max(L1,L2), do_list(L3, I), maplist(succ, A, P, I).

my problem now is, that maplist tries to check every pair of [A,P,I] and if it founds some, where succ(A,P,I) is false ass(A,P) is false, too.

Now I've two questions:

  1. Is their a way to solve my problem?
  2. Is their a way to fix the parameters P and I in the predicate succ(A,P,I), so it would be possible e.g. to membercheck simply if [[I1],I1,a,'A',''] e.g. is a member of my List P for some I1 in I.

Thanks for the help, Martin

1
Why it is not sufficient to check wheter the element is present in one of the sublists?damianodamiano
Do you mean something like: ass(A,P) :- member(X1,A), member([[I], I, X1, 'A', ''],P). The Problem is, that ?- ass([a, b],P) gives an infinite List for P with elements e.g. [[_1396], _1396, a, 'A', '']. My wish is a list of two elements of form [[_1396], _1396, a, 'A', ''], [[_1397], _1397, b, 'A', ''].Martin Kunze

1 Answers

1
votes

Very simply you can write:

ass(E,L,E1):-
    maplist(ass_(L),E,E1).
ass_(L,E,E1):-
    member(E1,L),
    member(E,E1).

?- ass([a, b], [[[1], 1, a, 'A', ''], [[2], 2, a->b, 'A',''], [[3], 3, b, 'A', '']],L).
L = [[[1], 1, a, 'A', ''], [[3], 3, b, 'A', '']]
false