Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: prolog like search

  • To: mathgroup at smc.vnet.net
  • Subject: [mg76675] Re: prolog like search
  • From: dh <dh at metrohm.ch>
  • Date: Fri, 25 May 2007 06:47:02 -0400 (EDT)
  • References: <f33rbj$mod$1@smc.vnet.net>


Hi Nameless,

try this:

entities={william,henry,diana,charles};

Sonof[_,_]=False;

Sonof[william,diana]=True;

Sonof[william,charles]=True;

Sonof[henry,diana]=True;

Sonof[henry,charles]=True;

Sonof[_,_]=False;



Married[a_,b_]:=Or@@(Sonof[#,a]&&Sonof[#,b]&&(a=!=b)&/@ entities);

PrologSearch[fun_,ent_]:=Cases[Outer[{fun[#1,#2],fun,{#1,#2}}&, 

ent,ent],{True,x__}:>{x},{2}];



PrologSearch[Married, entities]



hope this helps, Daniel









siewsk at bp.com wrote:

> I would like to do prolog like searches in Mathematica

> 

> entities={ william , henry , diana , charles }

> Sonof(william,diana);

> Sonof(william,charles);

> Sonof(henry,diana);

> Sonof(henry,charles);

> 

> Married(A,B) := Sonof(S,A) && Sonof(S,B) && A != B;

> 

> PrologSearch(Married,entities)

> 

> returns { Married(diana,charles), Married(charles,diana) }

> 

> Any idea how this could be implemented in Mathematica?

> 

> 




  • Prev by Date: Re: V6 evaluation inside Table and plot
  • Next by Date: Re: On typesetting
  • Previous by thread: Re: prolog like search
  • Next by thread: New in Version 6