Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transducer: convenience option for process words iteratively (and showing output) #18118

Closed
dkrenn opened this issue Apr 3, 2015 · 27 comments
Closed

Comments

@dkrenn
Copy link
Contributor

dkrenn commented Apr 3, 2015

This ticket introduces a new option so that iter_processs gives the output of a transducer (when processing a word) step by step. If the transducer branches (non-deterministic transducer), an exception is raised.

This is in contrast to the existing implementation, where the full output (including information on all branches of the process) is given back in each step during iteration.

An example:

sage: inverter = Transducer({'A': [('A', 0, 1), ('A', 1, 0)]},
....:     initial_states=['A'], final_states=['A'])
sage: it = inverter.iter_process(
....:     words.FibonacciWord(), iterator_type='simple')
sage: from itertools import islice
sage: [o for o in islice(it, 0, 5)]  # only output the first 5 letters
[1, 0, 1, 1, 0]

CC: @cheuberg @sagetrac-skropf

Component: finite state machines

Keywords: sd66

Author: Daniel Krenn

Branch/Commit: 9a88fc1

Reviewer: Clemens Heuberger

Issue created by migration from https://trac.sagemath.org/ticket/18118

@dkrenn dkrenn added this to the sage-6.6 milestone Apr 3, 2015
@dkrenn
Copy link
Contributor Author

dkrenn commented Apr 3, 2015

Branch: u/dkrenn/fsm/iter_process-simple

@dkrenn
Copy link
Contributor Author

dkrenn commented Apr 3, 2015

New commits:

54c99b9implement type-simple-iterator
9bf4d02iter_process_simple: docstring and small renaming of parameter

@dkrenn
Copy link
Contributor Author

dkrenn commented Apr 3, 2015

Author: Daniel Krenn

@dkrenn
Copy link
Contributor Author

dkrenn commented Apr 3, 2015

Commit: 9bf4d02

@videlec
Copy link
Contributor

videlec commented Apr 3, 2015

comment:4

Even better example

sage: inverter = Transducer({'A': [('A', 0, 1), ('A', 1, 0)]},
....:                initial_states=['A'], final_states=['A'])
sage: it = inverter.iter_process(
....: words.FibonacciWord(), iterator_type='simple')
sage: u = Words([0,1])(it)
sage: u
word: 1011010110110101101011011010110110101101...

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 3, 2015

Changed commit from 9bf4d02 to 9376b18

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 3, 2015

Branch pushed to git repo; I updated commit sha1. New commits:

9376b18improved doctests (using words)

@dkrenn
Copy link
Contributor Author

dkrenn commented Apr 3, 2015

comment:6

Replying to @videlec:

Even better example

sage: inverter = Transducer({'A': [('A', 0, 1), ('A', 1, 0)]},
....:                initial_states=['A'], final_states=['A'])
sage: it = inverter.iter_process(
....: words.FibonacciWord(), iterator_type='simple')
sage: u = Words([0,1])(it)
sage: u
word: 1011010110110101101011011010110110101101...

Included. Thanks.

@videlec
Copy link
Contributor

videlec commented Apr 3, 2015

comment:7

Couldn't we do better? I tried to use inverter.process directly, but sadly it does not return only a word. My dream would be that the following just works

sage: W = Words([0,1])
sage: inverter.process(W([0,1,0])
word: 101
sage: inverter.process(words.FibonacciWord([0,1]))
word: 1011010110110101101011011010110110101101...

What do you think?

Vincent

@dkrenn
Copy link
Contributor Author

dkrenn commented Apr 3, 2015

comment:8

Replying to @videlec:

Couldn't we do better? I tried to use inverter.process directly, but sadly it does not return only a word. My dream would be that the following just works

sage: W = Words([0,1])
sage: inverter.process(W([0,1,0])
word: 101
sage: inverter.process(words.FibonacciWord([0,1]))
word: 1011010110110101101011011010110110101101...

What do you think?

Would be nice to have, but takes some effort (not sure if possible with the infinite (lazy) words). This is now #18123.

Daniel

@cheuberg
Copy link
Contributor

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 17, 2015

Changed commit from 9376b18 to 137cbf9

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 17, 2015

Branch pushed to git repo; I updated commit sha1. New commits:

a6e0fe2Trac #18118: Reviewer Patch: Fix ReST formatting error
137cbf9Trac #18118: Reviewer Patch: Add doctest

@cheuberg
Copy link
Contributor

comment:11
  • Added two minor commits, please cross-review

  • The description of iter_process does not explain why a user would want to have a simple iterator. Could you elaborate and/or provide an illustrating example (for simplicity, for finite input instead of an infinite word) on how the standard and the simple iterator differ?

  • IMHO, there should be doctests for all error conditions in _iter_process_simple_

  • I do not understand the code of _iter_process_simple_:

    • why do you need to set output = outputs[0] and iterate over output instead of outputs[0]?
    • why do you reset outputs[0] = [] at the end?

    Could you please add comments on that?

  • Please add a SEE ALSO block for _iter_process_simple_ even if it does not currently show up in the reference manual.

@cheuberg
Copy link
Contributor

Work Issues: see comment 10

@cheuberg
Copy link
Contributor

Reviewer: Clemens Heuberger

@cheuberg cheuberg changed the title transducer: convenience option for process words iterativly (and showing output) transducer: convenience option for process words iteratively (and showing output) Apr 18, 2015
@dkrenn
Copy link
Contributor Author

dkrenn commented Sep 9, 2015

@dkrenn
Copy link
Contributor Author

dkrenn commented Sep 9, 2015

comment:15

Replying to @cheuberg:

  • Added two minor commits, please cross-review

Done....ok.

  • The description of iter_process does not explain why a user would want to have a simple iterator. Could you elaborate and/or provide an illustrating example (for simplicity, for finite input instead of an infinite word) on how the standard and the simple iterator differ?

  • IMHO, there should be doctests for all error conditions in _iter_process_simple_

  • I do not understand the code of _iter_process_simple_:

    • why do you need to set output = outputs[0] and iterate over output instead of outputs[0]?
    • why do you reset outputs[0] = [] at the end?

    Could you please add comments on that?

  • Please add a SEE ALSO block for _iter_process_simple_ even if it does not currently show up in the reference manual.

Addressed all these comments in the new commits.


New commits:

4bc8bc6add additional examples to show difference between 'simple'-option and not using it
f00e904seealso block in _iter_process_simple_
a28221bminor simplifiction of code and add a comment explaining resetting of output
29a54c3doctests for error conditions and rephrase these errors to get more information when raised

@dkrenn
Copy link
Contributor Author

dkrenn commented Sep 9, 2015

Changed commit from 137cbf9 to 29a54c3

@dkrenn
Copy link
Contributor Author

dkrenn commented Sep 9, 2015

Changed work issues from see comment 10 to none

@cheuberg
Copy link
Contributor

@cheuberg
Copy link
Contributor

comment:17

I added two commits, please cross-review them and set to positive_review.


New commits:

7d9e481Trac #18118: Additional doctest
3ecc012Trac #18118: Rephrase error message.

@cheuberg
Copy link
Contributor

Changed commit from 29a54c3 to 3ecc012

@dkrenn
Copy link
Contributor Author

dkrenn commented Sep 14, 2015

@cheuberg
Copy link
Contributor

comment:20

the commit field did not update, so I add a comment to do so.


New commits:

9a88fc1simplify code of a doctest (use islice)

@cheuberg
Copy link
Contributor

Changed commit from 3ecc012 to 9a88fc1

@vbraun
Copy link
Member

vbraun commented Sep 15, 2015

Changed branch from u/dkrenn/fsm/iter_process-simple to 9a88fc1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants