Interpreting given paragraph and turning it into Prolog code [closed] - prolog

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Isaac and Albert were excitedly describing the result of the Third Annual International Science
Fair Extravaganza in Sweden. There were three contestants, Louis, Rene, and Johannes. Isaac reported
that Louis won the fair, while Rene came in second. Albert, on the other hand, reported that Johannes
won the fair, while Louis came in second.
In fact, neither Isaac nor Albert had given a correct report of the results of the science fair. Each of them had given one correct statement and one false statement. What was the actual placing of the three contestants? Please base your solution to a Prolog program.
Well, i am beginner at prolog and i want to interpret such paragraphs into prolog code but i am not sure how to approach to this. Can you lead me about that?

We start by recording the statements of Isaac and Albert. 1 and 2 are used to identify the statements ("the first statement of Isaac..."), each list represents the participants in their order.
isaac(1,[louis,_,_]).
isaac(2,[_,rene,_]).
albert(1,[johannes,_,_]).
albert(2,[_,louis,_]).
Next we say who participated in the fair and that any answer should be a permutation of the three names. I'm working with SWI prolog, so permutation is a built-in predicate:
domain([louis,johannes,rene]).
valid(X):- domain(D), permutation(D,X).
Finally, we put everything together:
go(X) :- isaac(I,X),
albert(J,X),
valid(X),
\+ (isaac(K,X), dif(I,K)),
\+ (albert(L,X), dif(J,L)).
Two last lines ensure that only one claim of Isaac (Albert) is true.

Related

Scheme (Dr. Racket) Return Lists that Contain some atom [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am looking to be able to search through a list of lists in Scheme for an atom in some function called, say, google. If that list contains the atom, I want to return the list. Ex:
(google 'dave '((www.sillypage.com this page says dave among other things)
(www.happypage.com this page does not say the name)
(www.theone.com but this dave sure says dave)
))
should return the list:
(www.sillypage.com www.theone.com)
It sounds like this is homework; if it's not homework, please let me know!
With that assumption: this question fits well into the standard design recipe for functions on lists, as described in section 10.1 of How To Design Programs, edition 2e. Take a look, and tell us what step of the design recipe you're stuck on!

Examples of the integral that can't be done correctly by Wolfram Alpha [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Does anybody know the examples of indefinite or definite integral that can be done in the terms of elementary functions manually by a good first-year or second-year student, but which Wolfram Alpha (or Mathematica) evaluate not correctly?
In other words, I want to find some tasks for mathematical test, where students cannot easily find the answer using wolfram and just rewrite it in their papers.
Thanks in advance.
It is probably impossible. Set of functions known by 1-2 years students is constrained. Mathematica uses symbolic algebra system to transform integrals, and big repository with properties of functions.
http://functions.wolfram.com/
For example for Hypergeometric Functions you have (218,254 formulas)!
Methods of calculations of integrals are explained on wolframalpha.com as step by step solutions for pro users. ($4.75/mo billed annually or $6 billed monthly)
Calculating integrals by computers is nowadays on level comparable to chess games. You have to talk with student individually.

Writing an algorithm to complete a checklist, where to start? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm completing a dissertation in health economics and would like to explore the possibility of using an algorithm to answer a checklist that I manually filled in during my research.
The checklist is a 24-item checklist which asks questions such as "Was a discount rate reported?". Now, the articles I've been reviewing tend to be very codified. That is, there are only a few ways that they report an answer (e.g. "we discounted at 3% in this evaluation").
Theoretically, I think it would be possible to write a program that could search text and fill out the majority of these checklist items. However, I have very little experience in programming. As far as I can see, a program like this would involve writing an algorithm of sorts, but that is where my knowledge ends.
Particularly, I would like to know
- Is this possible?
- If so, how would I go about exploring this further? Ideally, I'd like to get to a point where I could play around with writing an algorithm to look through my database.
This could definitely be done with simple logic and parsing, but the key to it would be that the manual entries are consistent in the way that they are "codified".
For example, you'd parse your line for a specific token (or validation word).
In your case above you could parse word for word the string: "we discounted at 3% in this evaluation"
Code wise we could implement a basic logical comparison to each word parsed in the string.
if(currentWord is equal to "discounted")
create a checkmark.

Prolog Count The Unique Identifiers In Fact [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
We have facts
studies(cse, plc).
studies(cse, da).
studies(it, se).
studies(it, plc).
where studies(x,y) means that branch x studies module y .
Now I Want to define Rule To count number of modules in all. like here it will be 3.that are (plc,da,se).PLZ HELP.
What will be the query to find how many subjects studies under CSE.
having tagged SWI-Prolog your question, take a look at library(aggregate):
?- aggregate(count, Module, Branch^studies(Branch, Module), N).
N = 3.
library(aggregate) is powerful, learning about it can be really rewarding...
I will not tell you the solution but this can help you to find it out by yourself:
If you want to count the modules then you need a list of modules and take its length.
Always remember this sentence:
A list is either an empty list or an element and a list.
Using this you can construct lists of your modules recursively.
Make sure, no element is in the list twice.
number_of_modules(N) :-
findall(M, studies(_,M), Ms),
sort(Ms, SortedMs),
length(SortedMs, N).
?- number_of_modules(N).
N = 3.
sort/2 removes duplicate elements.
The arguments of findall/3 are, from left to right, (1) a template for the answer which is to be collected, (2) the goal from which the answer is drawn, (3) the a list of all answers. So you could, for instance, label each module as such by using a different template in (1):
number_of_modules(N, SortedMs) :-
findall(module(M), studies(_,M), Ms),
sort(Ms, SortedMs),
length(SortedMs, N).
?- number_of_modules(N, Ms).
N = 3,
Ms = [module(da), module(plc), module(se)].
Documentation on this and related predicates can be found in section 4.3 of the manual.

automated theorem proving program - where to start? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm a second year student with my discrete mathematics 2 assignment is to make an automated theorem prover. I have to make a simple prover program that works on Propositional Logic in 4 weeks (assuming that the proof always exist). I've googled so far but the materials there is really hard to understand in 4 weeks. Can anyone recommend me some book/site/open source code that is for beginners or some useful hints to start with? Thank you in advance.
Note: I flagged this to be moved to the Computer Science site because they are much more on top of ATP over there.
It would be nice if you could include what you have looked at and why it does not help you. Then we can figure out what might be better for you. Also, if you have to write a program, then knowing what languages you know will help. Most of what I do with this is done in a functional language such as OCaml or F#, or a logic language such as Prolog or Mercury.
Have you seen "Handbook of Practical Logic and Automated Reasoning" (WorldCat) by John Harrison. I included the (WorldCat) link so you can find the book in a local library as opposed to waiting to buy it which will eat up most of your time.
If you look you will find the OCaml code at the bottom of the page, and F# here and Haskell here.
In case you haven't see the ATP or Proof Assistant at Wikipedia, you might get a lead to some code and papers.

Resources