Logical Programming in .NET
Still definitely a work in progress, but the goal is to have a .NET Standard library to have Prolog-like functionality. LogSharp will be more formal-logic-y than Prolog though, since instead of defining rules like functions, usage involves defining implications.
Do you have dotnet? Get it.
$ git clone https://github.com/jdaless/LogSharp.git
$ cd LogSharp/
$ dotnet build
$ dotnet test
A lot of the tests will fail, they're just there to measure progress.
Prolog pulled and C# code is part of the unit tests.
From here
likes(mary,food).
likes(mary,wine).
likes(john,wine).
likes(john,mary).
?- likes(mary,food).
true.
?- likes(john,wine).
true.
?- likes(john,food).
false.
World w = new World();
Rule likes = new Rule();
w.Add(likes["mary", "food"]);
w.Add(likes["mary", "wine"]);
w.Add(likes["john", "wine"]);
w.Add(likes["john", "mary"]);
Console.WriteLine(w.Query(likes["mary","food"]);
Console.WriteLine(w.Query(likes["john","wine"]);
Console.WriteLine(w.Query(likes["john","food"]);
True
True
False
From here
son(ishmael, abraham, mother_is_slave).
son(isaac, abraham, mother_is_free).
patriarch(abraham).
freeborn(P,S) :- patriarch(P),
son(S,P,F),
eq(F,mother_is_free).
?- freeborn(X,Y).
X = abraham,
Y = isaac.
World w = new World();
Rule son = new Rule();
Rule patriarch = new Rule();
Rule freeborn = new Rule();
w.Add(son["ishmael", "abraham", "mother_is_slave"]);
w.Add(son["isaac", "abraham", "mother_is_free"]);
w.Add(patriarch["abraham"]);
using(var p = new Variable())
using(var s = new Variable())
using(var f = new Variable())
{
w.Add(freeborn[p,s] <
patriarch[p] ^
son[s,p,f] ^
Rule.Equality[f, "mother_is_free"]);
}
using(var x = new Variable())
using(var y = new Variable())
{
w.Query(freeborn[x,y]);
Console.WriteLine(x.OfType<string>().Single());
Console.WriteLine(y.OfType<string>().Single());
}
abraham
isaac