logo
down
shadow

Prolog array in rules and operation


Prolog array in rules and operation

By : user2954379
Date : November 22 2020, 01:01 AM
wish help you to fix your issue I have a little problem with define facts and search in array in Prolog. I dont know, how add to rule my array and result of it. , You are missing a member/2 call to get an element out of an array:
code :
foodForPerson(F,C) :-
    isAllergic(F, Xs),
    members(X,Xs),
    allergen(X,C).
isAllergic(john, fish).
isAllergic(john, milk).
isAllergic(john, [fish, milk]).

allergen(sharkWitHPotato, [fish, potato]).

foodForPerson(F,X) :-
    isAllergic(F, As),
    allergen(X,Cs),
    member(A,As),
    member(A,Cs).


Share : facebook icon twitter icon
prolog: Trying to model equation with 3 rules - how to get prolog to match the right one?

prolog: Trying to model equation with 3 rules - how to get prolog to match the right one?


By : user6219008
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , It's always the first rule that is called, resulting in those errors when variables are not instantiated.
You could write
code :
equation(RESULT, NUMERATOR, DENOMINATOR) :-
        nonvar(NUMERATOR), nonvar(DENOMINATOR), !,
        RESULT is NUMERATOR // DENOMINATOR.

equation(RESULT, NUMERATOR, DENOMINATOR) :-
        nonvar(DENOMINATOR), nonvar(RESULT), !,
        NUMERATOR is DENOMINATOR * RESULT.

equation(RESULT, NUMERATOR, DENOMINATOR) :-
        nonvar(NUMERATOR), nonvar(RESULT), !,
        DENOMINATOR is NUMERATOR // RESULT.
:- [library(clpr)].
ohm(V, R, I) :- {V = R * I}.
17 ?- ohm(20,N,10).
N = 2.0 .
~$ gprolog
GNU Prolog 1.3.0
By Daniel Diaz
Copyright (C) 1999-2007 Daniel Diaz

| ?- [user].
compiling user for byte code...
ohm(V,R,I) :- V #= R * I.

user compiled, 2 lines read - 338 bytes written, 23339 ms

(4 ms) yes
| ?- ohm(1,10,10).

no
| ?- ohm(V,10,10).

V = 100

yes
| ?- ohm(5,X,10). 

no
| ?- ohm(30,X,10).
Any specific rules for converting MySQL data to Prolog rules for exploratory mining?

Any specific rules for converting MySQL data to Prolog rules for exploratory mining?


By : ktleungaf2016
Date : March 29 2020, 07:55 AM
it helps some times You could maybe use nth1/1 and the "univ" operator, doing something like this:
code :
fieldnames(t, [id,this,that]).
get_field(Field, Tuple, Value) :- 
    Tuple =.. [Table|Fields],
    fieldnames(Table, Names),
    nth1(Idx, Names, Field),
    nth1(Idx, Fields, Value).
?- get_field(this, t(testId, testThis, testThat), Value)
Value = testThis
findThisById(X, This) :- get_field(this, X, This).
get_field(Field, Tuple, Value) :-
    functor(Tuple, Table, _),
    fieldnames(Table, Names),
    nth1(Idx, Names, Field),
    arg(Idx, Tuple, Value).
Prolog Rules in example

Prolog Rules in example


By : Hamza Trabelsi
Date : March 29 2020, 07:55 AM
will help you I have a database in Prolog like this: , I would try this:
code :
transport(A, B, [Method]) :- connection(A, B, Method).
transport(A, C, [Method|Others]) :-
    connection(A, B, Method),
    transport(B, C, Others).
?- transport(a, c, M).
M = [bus, metro] ;
false.

?- transport(a, d, M).
M = [bus, taxi] ;
false.

?- transport(a, e, M).
M = [bus, taxi, bus] ;
false.
can't make this prolog program work, prolog rules, 'or' operator, prolog arithmetics

can't make this prolog program work, prolog rules, 'or' operator, prolog arithmetics


By : rgba
Date : March 29 2020, 07:55 AM
wish helps you There are a couple of things to mention with respect to the question posting.
You listed example facts as:
code :
COBOL, 1960
PASCAL, 1971
C, 1971
language('COBOL', 1960).
language('PASCAL', 1971).
language('C', 1971).
lang_precedes_decade(Lp, L) :-
    ( language(Lp, X),
      language(L, Y),
      ((X-Y) > 9) )
    ; ((X-Y) < -9).
lang_precedes_decade(Lp, L) :-
    language(Lp, X),
    language(L, Y),
    ( ((X-Y) > 9); ((X-Y) < -9) ).
| ?- lang_precedes_decade(Lp, L).

L = 'PASCAL'
Lp = 'COBOL' ? ;

L = 'C'
Lp = 'COBOL' ? ;

L = 'COBOL'
Lp = 'PASCAL' ? ;

L = 'COBOL'
Lp = 'C' ? ;

no
lang_precedes_decade(Lp, L) :-
    language(Lp, YearLp),
    language(L, YearL),
    (YearL-YearLp) > 9.    % Lp precedes L
| ?- lang_precedes_decade(Lp, L).

L = 'PASCAL'
Lp = 'COBOL' ? a

L = 'C'
Lp = 'COBOL'

no
| ?- 
About rules in prolog . .

About rules in prolog . .


By : Brandon Phipps
Date : March 29 2020, 07:55 AM
Does that help You can generate any sort and amount of code in most modern Prolog environment using term expansion, with some help from the universal operator. The following example works for SWI:
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org