I'll give some comments on the first test below. I am not sure whether we should continue the discussion here on the mailing list or whether we do it on a github issue (in that case, please Cc dkrenn and myself (cheuberg)).

I also propose to discuss the issues one at a time and not combining the issues you report.

So here is my variant of your Test 1 (just a plain 'a' as a label of the transition):

sage: from sage.combinat.finite_state_machine import FSMTransition, Automaton, FSMState
sage: my_state = FSMState(1)
sage: my_transition = FSMTransition(1, 1, 'a')
sage: my_automaton = Automaton([my_transition], initial_states = [my_state])

After this code, we have three different FSMState objects, namely

- my_state
- my_transition.from_state
- my_transition.to_state

Comparing them with `==` gives True:

sage: my_state == my_transition.from_state
True
sage: my_state == my_transition.to_state
True
sage: my_transition.from_state == my_transition.to_state
True

However, they are not identical:

sage: my_state is my_transition.from_state
False
sage: my_state is my_transition.to_state
False
sage: my_transition.from_state is my_transition.to_state
False

And this causes trouble:

sage: my_state.transitions
[Transition from 1 to 1: 'a'|-]
sage: my_transition.from_state.transitions
AttributeError                            Traceback (most recent call last)
...
AttributeError: 'FSMState' object has no attribute 'transitions'

In other words, constructing automata in this way is not supported, and no warnings are thrown.

Behind the scenes, as `my_state` is given as an initial state, it is in the list of states of the automaton. Then `my_transition` is added to the automaton and added to the outgoing transitions of `my_state` (which is the state with label 1 in this particular automaton).

If you'd modify your second line to

sage: my_transition = FSMTransition(my_state, my_state, 'a')

everything would be fine.

Alternatively, you could construct your automaton in one command:

sage: my_automaton = Automaton([(1, 1, ('a'))], initial_states = [1])

In general, it seems to be best to avoid `FSMState` and `FSMTransition` as a user alltogether; there is a reason why they are not in the global namespace.
Alternatively, they should be used everywhere.

Best,

Clemens






Am 27.03.24 um 18:19 schrieb 'DANIEL LEVITIN' via sage-devel:
There seem to be at least 2 issues in the Automaton.process method, which is found in  sage.combinat.finite_state_machine. They appear in Sage 10.3.

Unexpected errors are thrown and incorrect outputs result from calling Automaton.process() when, in various combinations (a) instances of FSMTransition are declared by the label of an FSMState rather than by the instance of FSMState itself, (b) the input tape for processing is encapsulated in a tuple, rather than a list, and (c) the inputs contain commas, e.g. if the alphabet contains tuples. The documentation suggests that (a) and (b) should make no difference, and makes no mention of any issues with (c).

For instance:

from sage.combinat.finite_state_machine import FSMTransition, Automaton, 
FSMState

#Test 1
my_state = FSMState(1)
my_transition = FSMTransition(1, 1, ('a','a'))
my_automaton = Automaton([my_transition], initial_states = [my_state])
my_automaton.process([('a','a')])
#throws a ValueError with message "State 1 does not belong to a finite state machine"

#Test 2
my_state = FSMState(1)
my_transition = FSMTransition(1, 1, ('a','a'))
my_automaton = Automaton([my_transition], initial_states = [my_state])
my_automaton.process((('a','a')))
#returns the incorrect output (False, None), which indicates that (‘a’, ‘a’) was not the label of a transition starting at the initial state. Expected output is (False, 1).

#Test 3
my_state = FSMState(1)
my_transition = FSMTransition(my_state, my_state, ('a','a'))
my_automaton = Automaton([my_transition], initial_states = [my_state])
my_automaton.process([('a','a')])
#returns the expected output (False, 1)

#Test 4
my_state = FSMState(1)
my_transition = FSMTransition(my_state, my_state, ('a','a'))
my_automaton = Automaton([my_transition], initial_states = [my_state])
my_automaton.process((('a','a')))
#returns the incorrect output (False, None), which indicates that (‘a’, ‘a’) was not the label of a transition starting at the initial state. Expected output is (False, 1).

#Test 5
my_state = FSMState(1)
my_transition = FSMTransition(1, 1, ('a'))
my_automaton = Automaton([my_transition], initial_states = [my_state])
my_automaton.process(['a'])
#throws a ValueError with message "State 1 does not belong to a finite state machine"

#Test 6
my_state = FSMState(1)
my_transition = FSMTransition(1, 1, 'a')
my_automaton = Automaton([my_transition], initial_states = [my_state])
my_automaton.process(('a'))
#throws a ValueError with message "State 1 does not belong to a finite state machine"

#Test 7
my_state = FSMState(1)
my_transition = FSMTransition(my_state, my_state, 'a')
my_automaton = Automaton([my_transition], initial_states = [my_state])
my_automaton.process(['a'])
#returns the expected output (False, 1)

#Test 8
my_state = FSMState(1)
my_transition = FSMTransition(my_state, my_state, 'a')
my_automaton = Automaton([my_transition], initial_states = [my_state])
my_automaton.process(('a'))
#returns the expected output (False, 1)

My best guess is that these bugs have to do with the way FSMStates are assigned the .transitions attribute. In other tests, calling Automaton.process has thrown AttributeErrors in lines that ask for this attribute.

Best,

Daniel Levitin

P.S. I would be happy to try to fix this myself, but I do not understand the way the process iterator works. If someone here is familiar with this module and is willing to explain it to me, I would appreciate it.

--
You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com <mailto:sage-devel+unsubscr...@googlegroups.com>. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/b0553c27-55b6-4912-86b2-e316d7322c32n%40googlegroups.com <https://groups.google.com/d/msgid/sage-devel/b0553c27-55b6-4912-86b2-e316d7322c32n%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
Univ.-Prof. Dr. Clemens Heuberger        Alpen-Adria-Universität Klagenfurt
Institut für Mathematik, Universitätsstraße 65-67, 9020 Klagenfurt, Austria
Tel: +43 664 8835 8591                            Fax: +43 463 2700 99 3121
clemens.heuber...@aau.at                       https://wwwu.aau.at/cheuberg

--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/33091292-6ebe-4583-b34c-2f0f3727c05c%40aau.at.

Attachment: smime.p7s
Description: Kryptografische S/MIME-Signatur

Reply via email to