[ art / civ / cult / cyb / diy / drg / feels / layer / lit / λ / q / r / sci / sec / tech / w / zzz ] archive provided by lainchan.jp

lainchan archive - /λ/ - 19383



File: 1476569564453-0.png (45.66 KB, 200x200, 6884283.png)

No.19383

Anyone proficient with Prolog?
What can it be used for?
What is the best source to learn it?

  No.19386

File: 1476572706308.png (5.8 MB, 200x200, Clause and Effect_ Prolog Programming for the Working Programmer.pdf)

Not sure if it's the best but I really liked it. It has practical examples and a very clear description of the actual workings of Prolog compared to the mathematical approach other books seem to prefer.

  No.19387

>>19383
Prolog is mainly used in Academia for AI purposes. I'm currently learning it as part of an AI course at my university. Here is a good source: http://lpn.swi-prolog.org/lpnpage.php?pageid=online

  No.19388

File: 1476575454749.png (1.93 MB, 200x200, Logic:ProgrammingAndProlog.pdf)

>>19383
>>19387
As well as this.

  No.19389

File: 1476575513648.png (1.81 MB, 200x200, Thinking as Computation - A First Course.pdf)


  No.19416

File: 1476620239575.png (2.32 MB, 200x200, gdc2006_orkin_jeff_fear.pdf)

This is a paper on how a system that was very similar to Prolog (although Prolog itself is never mentioned) was used to write the enemy AI in F.E.A.R., which to this day is still one of the most lifelike dynamic AIs you can find in in real-time games such as FPS.


  No.19418

>>19417
Please leave

  No.19419

I think Prolog (or something similar) will be _the_ language to program quantum computers. What do you think?

  No.19420

>>19419
Why would it be any better than with normal computers? Quantum computing is quite fiddly. It's hard to imagine a compiler synthesising an efficient non-classical quantum system from a declarative language.

  No.19425

>>19419
nah, quantum computers will usually be used in an oracle way, or maybe like graphics cards. It's really not worth it to use them as general-purpose computers.

  No.19430

File: 1476651418574.png (138.14 KB, 183x200, jWWPolf.jpg)

>>19418
Nothing but the truth. the guy who invented logic programming proved it's a dead end. The fifth generation computer was a massive failure. Academics let prolog die a long time ago.

  No.19431

>>19419
FYI, actual quantum computers are programmed in python.

  No.19432

>>19430
[citation needed]

  No.19433

>>19430
>Academics let prolog die a long time ago
That's why young students are getting taught Prolog.

  No.19434

>>19432
it's general plt knowledge that the guy behind logic programming is carl hewitt, that he proved that logic programming is doomed, and that he then invented the actor model as a saner alternative.

  No.19442

>>19433
>That's why young students are getting taught Prolog.
And they learn SML and Smalltalk in language courses, doesn't mean they're not dead (trying to reanimate prolog with Pharoh doesn't count, because it's still dead)

  No.20729

Bumping with FizzBuzz:

fizzbuzz(fizzbuzz, X) :- 0 is mod(X, 15), !.
fizzbuzz(fizz, X) :- 0 is mod(X, 3), !.
fizzbuzz(buzz, X) :- 0 is mod(X, 5), !.
fizzbuzz(X, X).

print_fb(1) :-
fizzbuzz(Fizzbuzz, 1),
write(Fizzbuzz), nl, !.

print_fb(X) :-
Y is X - 1,
print_fb(Y),
fizzbuzz(Fizzbuzz, X),
write(Fizzbuzz), nl, !.

goal :- print_fb(100), halt.

They say "Logic programming clears your mind", but at this point I don't feel its advantages yet. I don't think advantages may be evident on this stage though.
Are there criteria of pure Prolog program?
Were there reports on Japanese Fifth Generation Computer Systems program?
Why did it fail?

  No.20731

>>20729
Here's a metacircular interpreter in Prolog:
miprove(Goal) :- miprove_all([Goal]).

miprove_all([]).
miprove_all([Goal|Goals]) :-
miclause(Goal, Body),
append(Body, Goals, NewGoals),
miprove_all(NewGoals).

% Example clauses:
miclause(append([], Y, Y), []).
miclause(append([X|Xs], Y, [X|Zs]), [append(Xs, Y, Zs)]).

  No.20743

>>19417
>the language with static garbage collection

  No.20799

>>20729
Maybe it's just that you aren't writing the right programs with it. Fizzbuzz is not a great way to use Prolog, let alone to learn it.

  No.20864

>>20799
Yeah, I just needed to write something more complicated than Hello World.
I just don't know about its purposes yet.

Some guys say, it's bad to use cuts though. How so?

  No.20877

>>19442
Smalltalk is no more dead than Lisp.

>>19430
Okay. But I'm not going to be the one telling Joe Armstrong that.

  No.20882

>>20864
>Some guys say, it's bad to use cuts though. How so?

The worst thing about cuts is that they make it more difficult to understand a program. Cuts force one to think about the imperative implementation details of the Prolog engine. Ideally, one should only have to focus on the declarative parts offered by the language itself. They're also easy to skip over, being only one character.

Code using red cuts—those that change the behaviour of a program—are additionally prone to breaking whenever the search space changes.

Green cuts—those that don't—are certainly useful, but the benefits they offer (namely, optimisation) can often be achieved by constraining the search space with good old predicate logic.

  No.21164

>>20882
> Code using red cuts—those that change the behaviour of a program—are additionally prone to breaking whenever the search space changes.
I wonde, can there be some examples?

  No.21172

>>21164
I can elaborate, but as a novice myself I'm having trouble coming up with a good, concrete example.

When I say "whenever the search space changes" what I really mean is when clauses are added to existing predicates or the cut is (re)moved. Normally, the clauses of a predicate are order-independent*. When cuts are involved, that's no longer true. If you miss or forget a cut when you add a clause, there's a 50% chance your code will exhibit unexpected behaviour. Similarly, changing the position of the cut or removing it altogether will change the meaning of the program.

There's a thin boundary between red and green cuts that makes them dangerous as well. A green cut becomes a red cut as soon as it changes the behaviour of a program. This can easily happen when predicates are re-ordered.

* If solutions differ, it's because your program is written to accept different solutions. The set of all solutions should not change.

  No.21758

>>19387
Can it be ever useful outside of academia?
I see Prolog being used only in some very specific cases, and I doubt if it can be used for big program systems.

  No.21771

>>21758
Erlang was originally written in it...

  No.21790

>>21771
And is Erlang used outside telecommunications?

I mean using Prolog for, let's say, application development. Is it possible?

  No.21791

>>21790
Erlang is used by quite a few companies. Some examples would be Twitter and WhatsApp.
Erlang itself isn't written in Prolog anymore, though. Only the first experimental version was.

I don't see any benefits in using the actual language of Prolog in any real life project, as it's likely to be only a part of a larger system and it's very easy to write a pleasant Prolog-like DSL for the language that the rest of the system is built in.

  No.21845

>>21758
It is apparently really common in transit industries. Ticket purchasing and the associated seat planning as well as routing, scheduling, and various other forms of resource allocation are all problems the language is well-suited for.

  No.21960

there's always a case for Prolog.

I've seen Prolog systems deployed for global visual anomaly detection via satellites. (source: http://simularity.com/2016/10/29/new-product-ai-solves-image-anomaly-detection-from-space/)

prolog's declarative "lunch" was eaten a while ago, yet it's still incredibly powerful to this day.

look into it. it's worth it.

  No.21962

>>21790
>And is Erlang used outside telecommunications?
I don't know but you absolutely can make things that aren't telecommunications-related with it.
http://www.wings3d.com/

  No.22022

I program for Visual Prolog now and it's very frustating how it differs from regular Prolog in books.
Also I feel like people are taught Prolog the wrong way. Solving logical riddles doesn't seem the right way for me.

  No.22038

File: 1487013890770-0.png (19.99 KB, 200x103, screenshot_2017-02-13-19:24:25.png)

File: 1487013890771-1.png (23.78 KB, 200x74, screenshot_2017-02-13-19:34:29.png)

Disclaimer: this is homework. I don't expect you to do everything for me, I'm just stuck and need help on this particular thing.

I have to build a small language for one of my courses. Pic 1 is its grammar. Our professor wants us to build an ast and export this ast using the grammar presented in pic 2. Once this is done we have to perform type analysis using prolog by using the ast we just exported. Types are pretty simple, expressions are either bool or int and all other instructions are of type void if correctly typed. The rules I already built look like this:
typeExpr(_, true, bool). % "true" is of type bool
typeExpr(_, false, bool). % "false" is of type bool
typeExpr(_, Number, int):- number(Number). % Numbers are of type int
typeExpr(Environment, Ident, int):-
member((Ident, int), Environment). % Identifier is an int if an association (Ident, int) already exists in Environment
typeExpr(Environment, Ident, bool):-
member((Ident, bool), Environment). % Identifier is a bool if an association (Ident, bool) arlready exists in Environment

typeDec(_, var(Ident, Type), void):- % A declaration is of type void if Ident is a string and Type is int
string(Ident),
Type == int.
typeDec(_, var(Ident, Type), void):- % A declaration is of type void if Ident is a string and Type is bool
string(Ident),
Type == bool.

% A statement is correctly typed if it is a SET operation the identifier of which exists in Environment and the type of which is the same as the statement's expression
typeStat(Environment, set(Ident, Expr), void):-
member((Ident, int), Environment),
typeExpr(Environment, Expr, int).
typeStat(Environment, set(Ident, Expr), void):-
member((Ident, bool), Environment),
typeExpr(Environment, Expr, bool).
Now I have a problem. While this code works when testing manually, for example by doing this:
typeStat([("myvar", bool)], set("myvar", true), void).
I have no idea how to "automatically" build my environment (i.e. adding a new (Ident, type) couple to the list named Environment each time I encounter a new declaration). My professor refuses to help me because I'm too far ahead from my classmates so this is a little frustrating. I hope one of you is able to help me.

  No.22039

>>22038
I would do that while checking the type of Cmds. If the head of the Cmds is a Dec, you typecheck it, then add the name+type pair to the envorinment, and check the tail using the new environment.

Something like this:
typeCmds(env, [var(Name, Type)|Cmds], void) :-
typeDec(env, var(Name, Type), void),
typeCmds([(Name, Type) | env], Cmds, void).

It's been a while since I last used prolog and I'm not sure if I understood your problem but I hope it somehow helps you!

  No.22049

>>22039
Oh god, this is so simple I feel very dumb now. I really should have been able to figure that out on my own.
Well, thanks for the help Lain!