Related
Consider the language
Consider the language
Aabb = {< M > | M is a TM, and M accepts abb}
a) What is the computational problem that is represented by Aabb?
b) Show that Aabb is undecidable.
I tried proving it but didn't know what to do.
You can use Rice's theorem directly and correctly prove the claim by noting that some TMs accept aab, some don't, and acceptance of abb is a semantic property of languages (it has to do only with the strings accepted, not the manner of accepting them). Rice guarantees this language is undecidable.
If you want another kind of proof, consider the following. There's nothing special about the string abb. If this problem is decidable, we'd expect the problem to be decidable for any arbitrary string. If it were decidable for any arbitrary string, we could use dovetailing to decide whether the language of the TM were empty. If we could decide whether the language of a TM were empty, we could take any TM, change all instances of halt-reject to halt-accept, and then decide whether the TM halts on at least one input. Etc. Etc. Basically, you can construct a chain of implications as long as you want but you quickly find known undecidable problems you can reduce to.
For instance, say I have this program (only tested in swi-prolog):
:- use_module(library(clpfd)).
:- use_module(library(lists)).
% Sorted has the same elements as List and is also sorted
clpfd_sort(List, Sorted) :-
same_length(List, Sorted),
chain(Sorted, #=<),
permutation(List, Sorted).
Where could I find enough information on how clpfd works to know whether this is an efficient solution? It might be greedy to ask such a simple solution to be n lg(n) but for all I know it's 10^n.
I've looked at sources such as this and they all do a great job of explaining the magic of clpfd but none of them explain enough of how it's implemented for me to get an idea of which programs will run quickly and which will run slowly. clpfd apparently uses attributes to hook into unification? I don't know enough about attributes to know what that means for the complexity of the programs I write. Is there somewhere I could find out?
Example experiment:
:- use_module(library(clpfd)).
:- use_module(library(lists)).
call_time(G,T) :-
statistics(runtime,[T0|_]),
G,
statistics(runtime,[T1|_]),
T is T1 - T0.
% Sorted has the same elements as List and is also sorted
clpfd_sort(List):-
same_length(List, Sorted),
chain(Sorted, #=<),
permutation(List, Sorted).
item_goal(I,clpfd_sort(I)).
n_randoms_times(NumberOfExperiments,Random_Lists,Times) :-
numlist(1,NumberOfExperiments,Experiment_Sizes),
maplist(numlist(1),Experiment_Sizes,ExperimentLists),
maplist(random_permutation,ExperimentLists,Random_Lists),
maplist(item_goal,Random_Lists,Goals),
maplist(call_time,Goals,Times).
Test:
?- n_randoms_times(15,R,T),write(T).
[0,0,0,1,1,1,2,5,4,3,16,34,43,115,246]
So it looks like the time doubles as we add one to the size of the list ...
The best way to tackle with complexities of a Prolog or clpfd program is to avoid the actual mechanisms within and concentrate on concrete answers or sets of answers first. After all, if such an analysis already indicates a very large O, any further details are just futile, as is the case in your program.
Consider a list of n equal numbers. In this case, we will get n valid permutations. Thus worst-case complexity is at least O(n!). That seems to be bad enough to reconsider your approach.
The best in this case would be to develop a constraint that relates that list of integers to the actual list directly. If my memory does serve me well such has been implemented in the context of Prolog IV.
I am currently using tkEclipse for my prolog and am currently stuck at this question.
Given base cases of an item with their name and number, I need to be able to find the smallest number without using rules such as if statements.
eg. anime(gundam, 1978), anime(steins_gate, 2011), anime(prison_school, 2015). and the answer would say gundam is the smallest number. This must not be hard coded because if you were to change the knowledge base then it should also change answer. Also, it should work if there are only two animes in the knowledge base.
I was thinking of something like this to start:
anime(X, Y), anime(A,B), Y < B, but things after that get tricky because not allowed to use :-
findall(N, anime(A, N), S),
setof(X, member(X,S), [Min|_]).
Or, in one line:
setof(N, A^anime(A, N), [Min|_]).
I have been trying to acclimate to Prolog and Horn clauses, but the transition from formal logic still feels awkward and forced. I understand there are advantages to having everything in a standard form, but:
What is the best way to define the material conditional operator --> in Prolog, where A --> B succeeds when either A = true and B = true OR B = false? That is, an if->then statement that doesn't fail when if is false without an else.
Also, what exactly are the non-obvious advantages of Horn clauses?
What is the best way to define the material conditional operator --> in Prolog
When A and B are just variables to be bound to the atoms true and false, this is easy:
cond(false, _).
cond(_, true).
But in general, there is no best way because Prolog doesn't offer proper negation, only negation as failure, which is non-monotonic. The closest you can come with actual propositions A and B is often
(\+ A ; B)
which tries to prove A, then goes on to B if A cannot be proven (which does not mean that it is false due to the closed-world assumption).
Negation, however, should be used with care in Prolog.
Also, what exactly are the non-obvious advantages of Horn clauses?
That they have a straightforward procedural reading. Prolog is a programming language, not a theorem prover. It's possible to write programs that have a clear logical meaning, but they're still programs.
To see the difference, consider the classical problem of sorting. If L is a list of numbers without duplicates, then
sort(L, S) :-
permutation(L, S),
sorted(S).
sorted([]).
sorted([_]).
sorted([X,Y|L]) :-
X < Y,
sorted([Y|L]).
is a logical specification of what it means for S to contain the elements of L in sorted order. However, it also has a procedural meaning, which is: try all the permutations of L until you have one that it sorted. This procedure, in the worst case, runs through all n! permutations, even though sorting can be done in O(n lg n) time, making it a very poor sorting program.
See also this question.
I am studying membership algorithms and I am working on this particular problem which says the following:
Exhibit an algorithm that, given any regular language L, determines whether or not L = L*
So, my first thought was, we have L* which is Kleene star of L and to determine if L = L*, well couldn't we just say that since L is regular, we know L* is by definition which states that the family of regular languages is closed under star-closure.
Therefore L will always be equal to L*?
I feel like there is definitely a lot more to it, there is probably something I am missing. Any help would be appreciated. Thanks again.
since L is regular, we know L* is by definition which states that the family of regular languages is closed under star-closure. Therefore L will always be equal to L*?
No. Regular(L) --> Regular(L*), but that does not mean that L == L*. Just because two languages are both regular does not mean that they are the same regular language. For instance, a* and b* are both regular languages, but this does not make them the same language.
A example of L != L* would be the language L = a*b*, and thus L* = (a*b*)*. The string abab is part of L* but not part of L.
As far as an algorithm goes, let me remind you that the concept of a regular language is one that can be parsed by a DFA - and for any given DFA, there is a single optimal reduction of that DFA.
The implication that you stated is wrong. Closedness under the Kleene star means only that L* is again regular, if L is regular.
One possibility to check whether L = L* is to compute the minimal automaton for both and then checking for equivalence.