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 4 years ago.
Improve this question
What does "In these situations the thread of the NFA's existence corresponding to those states simply dies" mean in my textbook?
Consider the nondeterministic finite automaton with states A, B, C, D, input alphabet {0}, and the transition function given by
canGoFrom(A, 0) = {B, C}
canGoFrom(B, 0) = {}
canGoFrom(C, 0) = {D}
canGoFrom(D, 0) = {}
That is, it looks somewhat like this:
A
/ \
B C
\
D
with all edges pointing downwards and having label 0. Suppose that D is the accepting state.
Suppose that you now want to check whether input string 00 is accepted by the automaton.
You start with a single thread, the reading head pointing to first 0, and in start state A. When you read the first zero, the NFA has two transitions it can make, and it must make all possible transitions at once, so the thread of NFA's existence splits into two threads: one is now in state B, the other is in state C.
Now the automaton has to consume the second zero. Because the second thread of existence canGoFrom(C, 0) = {D}, it happily transitions from C to the accepting state D, without splitting any further. However, the first thread of existence canGoFrom(B, 0) = {}, that is, it has nowhere to go. In this situation, the first thread of NFA's existence simply dies. It no longer contributes anything to the decision whether the input is accepted or not.
If all threads of existence die, then the input is not accepted.
Here, the second thread of existence reached the accepting state D, so the input is accepted.
Related
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 2 years ago.
Improve this question
Can Someone help me with the code for "finding if a no is armstrong no or not using prolog programming"?
I can't seem to find a solution anywhere.
Narcissistic numbers have different aliases such as Armstrong number, pluperfect digital invariant (PPDI) or plus perfect number.
numberToDigitsR(N,_,[]):-
N < 0, !.
numberToDigitsR(N,B,[N]):-
N < B, !.
numberToDigitsR(N,B,[Mod|R]):-
Mod is N mod B,
Div is N div B,
numberToDigitsR(Div,B,R).
powerList([],_,0).
powerList([H|T],E,Sum):-
powerList(T,E,TT),
Sum is (H**E)+TT.
narcissist(N,B):-
B>1,
numberToDigitsR(N,B,D),
length(D,E),
powerList(D,E,N).
tests:
?- narcissist(54748,10).
true.
?- narcissist(54748,9).
false.
?- narcissist(62,4).
true.
?- member(B,[2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]), narcissist(54748,B).
B = 10 ;
false.
Thanks David for linking the wiki site.
The program first creates a list of the "digits" for a given number N and a given base B. Then it calculates the number of digits E and calculates the sum of each digit to the power of E. If the output equals the number N then this is a narcissistic number. If the base B is not known before, simply state the domain as shown in the last example.
Please note that this algorithm does not work for B=1.
Also note that the number N is given with decimal format. So if you look up numbers from this website, please convert the numbers to base 10 first.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 5 years ago.
Improve this question
How do I get from premise ~~(AvB) to ~~(BvA).
Been working on it for a long time but I haven't found the solution yet. Appreciate the help!
Let <-> denote equivalence. We have,
~~(A v B) <-> A v B ; law of double negation
A v B <-> B v A ; because v is commutative
B v A <-> ~~(B v A) ; again, double negation
Thus
~~(A v B) <-> ~~(B v A)
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
Prolog how to add numbers in a list in a loop?
I have the loop and I would need to add the numbers into a list and render it in the end.
Prolog is a logical language and not a imperative one. You may need to formulate the problem a bit differently. By formulating what you want and not how you want it.
This is a recursive version:
the list of numbers between A and B is empty if A >= B or else
the list of numbers between A ans B is A and the list of numbers between A+1 and B
This is a version with some of prologs features.
find all numbers X between A and B
These two versions can be transferred into prolog quite directly. There is no 'loop' because prolog is not about commands (do this! do that! put that value there! increase!) but about formulating the problem.
I don't know what you mean by rendering, but you can create a list of number easily via recursion, since prolog doesn't have loops:
range_list(M,M,[M]).
range_list(M,N,[M|R]) :-
M < N ,
M1 is M+1 ,
range_list(M1,N,R)
.
range_list(M,N,[M|R]) :-
M > N ,
M1 is M-1 ,
range_list(M1,N,R)
.
You could also use built-in predicates to get what you want:
range_list(From,To,Result) :-
findall(X,between(From,To,X),Result)
.
I have to draw a Finite Automaton that accepts the following string
Λ, a, aabc, acba and accb
In my view a(a+b+c)* this might be it's regular expression as the string is starting from a and includes an empty string as well.
Now I didn't find the logic of drawing FA as in below image
Question 1: If the string is starting with a then in FA, We are moving from x to y while reading b
Why we don't read a here.
Question 2: Why we use loop of a,b on state y and z
The language L = {λ, a, aabc, acba, accb} is finite. Therefore, L is not equivalent to the language denoted by the Kleene closure of the regular expression a(a + b + c), which is infinite. There is a simple algorithm that generates the nondeterministic finite automaton accepting a finite language, which consists of drawing paths accepting each of the strings in the language.
It's unclear what the relationship between the two languages and the diagram in the original post is, since the automaton in the diagram accepts neither language. Assuming that the nodes are labeled with their names, and circled nodes indicate acceptance, the language accepted by the automaton in the diagram is (a + b)*. In this case, the loops are used to accept the Kleene closure of (a + b). That said, it would be useful if you could clarify the meaning of the diagram.
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
Mathematica is giving me a weird output when I am asking for a specific element of a nested list.
I have:
testroots = {{0, 0, 0}, {0, 0, 0}}
When I ask for
testroots[[0,0]]
which should give me a 0, instead Mathematica says
Symbol
I don't understand why this is or what I've done wrong.
Thanks!
Mathematica indices start with 1, not zero. So the [[0,0]] entry of testroots doesn't exist. You can get the first element using
testroots[[1, 1]]
As b.gatessucks and bill s already wrote, Mathematica lists start at Index 1. However the index 0 is also allowed and gives the Head of the expression. Now what does that mean?
Well, a list {a,b,c} in Mathematica is internally an expression of the Form List[a, b, c]. You can see that by applying FullForm to it:
FullForm[{a, b, c}]
(*
==> List[a, b, c]
*)
Thhe part in front of the opening bracket, here List, is called the head of the expression. And testroots[[0]] is equivalent to Head[testroots] which gives List for a list. Which makes sense, given that in the complete expression, the List precedes the elements.
However what about your expression testroots[[0,0]]? It accesses the head of the head of your list. The head of your list is List. But what is the head of List? After all, it doesn't have the form Head[arg1, arg2, ...].
For atomic expressions, Mathematica gives a symbol describing the type of the atom. For example Head[1] is Integer, Head["Hello"] is String and Head[foo] is Symbol (assuming foo has not been assigned to). Note that the head of an expression of the above form also can be considered the type of the expression. The type of a list is List, and the type of a+b, full form Plus[a, b] is Plus, that is, a sum.
Now List is a symbol, and therefore Head[List] is Symbol. Therefore for any list, like your testroots, testroots[[0,0]] will evaluate to Symbol.
To get the first element of the first element of the list, use testroots[[1,1]].