Skip to content

veselatereza/tgpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python module for the normalization of ternary generalized pseudostandard words. Examples can be found in the Jupyter notebook Examples.ipynb

API:

class tgpc.Normalizer012

Bases: object

Object for normalizing a ternary directive bi-sequences using the new normalization algorithm.

normalize(delta, theta)

Ternary normalization algorithm.

Normalization function that returns the normalized directive bi-sequence giving the same generalized pseudostandard word as (delta, theta).

Parameters:
  • delta (str) – The sequence delta of the directive bi-sequence. It should be composed of the letters ‘0’, ‘1’ and ‘2’.
  • theta (str) – The sequence theta of the directive bi-sequence. It should be composed from the letters ‘R’, ‘0’, ‘1’ and ‘2’, where the last three stand for E_0, E_1 and E_2.
Returns:

Returns the tuple (new_delta, new_theta, notchanged) where (new_delta, new_theta) is the normalized bi-sequence of (delta, theta). The boolean notchanged is True if the bi-sequence (delta, theta) was already normalized, otherwise it is False.

Examples

>>> n = Normalizer012()
>>> n.normalize("0011", "00RR")
('0011', '00RR', True)

>>> n.normalize("0102110", "02R0121")

print_all_factor_rules() Prints in a readable form all the factor normalization rules


class tgpc.NaiveNormalizer012

Bases: object

Object for normalizing ternary directive bi-sequences using a naive algorithm.

normalize(delta, theta)

Ternary naive normalization algorithm.

Naive normalization function that returns the normalized directive bi-sequence giving the same generalized pseudostandard word as (delta, theta). It creates the prefixes w_i by generalized pseudopalindromic closures a then checks if those are the only pseudopalindromic prefixes in the word created by the directive bi-sequence.

Parameters:
  • delta (str) – The sequence delta of the directive bi-sequence. It should be composed of the letters ‘0’, ‘1’ and ‘2’.
  • theta (str) – The sequence theta of the directive bi-sequence. It should be composed from the letters ‘R’, ‘0’, ‘1’ and ‘2’, where the last three stand for E_0, E_1 and E_2. Theta should be of the same length as delta.
Returns:

Returns the tuple (new_delta, new_theta, notchanged) where (new_delta, new_theta) is the normalized bi-sequence of (delta, theta). The boolean notchanged is True if the bi-sequence (delta, theta) was already normalized, otherwise it is False.

Examples

>>> nn = NaiveNormalizer012()
>>> nn.normalize("0011", "00RR")
('0011', '00RR', True)

>>> nn.normalize("0102110", "02R0121")
('01021102', '02R01201', False)

tgpc.Ei(i) The involutory antimorphism Ei.

Parameters: i – Either 0, 1, 2 or “0”, “1”, “2”
Returns: A tuple corresponding to the involutory antimorphism Ei.

Examples

>>> Ei(0)
('0', '2', '1')
>>> Ei(1)
('2', '1', '0')
>>> Ei(2)
('1', '0', '2')

tgpc.is_eipal(seq, i) Checks if a word is an Ei-palindrome.

Parameters:
  • seq (string) – The word checked composed of the letters “0”, “1” and “2”.
  • i – Pseudopalindromic type, can be either 0, 1, 2, or “0”, “1”, “2”, standing for E_0, E_1 and E_2.
Returns:

True if the word is an Ei-palindrome, otherwise False.

Examples

>>> is_eipal("012", 1)
True
>>> is_eipal("002", 1)
False

tgpc.is_pal(seq) Checks if a word is an R-palindrome.

Parameters: seq (string) – The word checked.
Returns: True if the word is an Ei-palindrome, otherwise False.

Examples

>>> is_pal("012")
False
>>> is_pal("010")
True

tgpc.make_eipal_closure(seq, i) Makes an Ei-palindromic closure of a string.

Parameters:
  • seq (string) – A word composed of the letters “0”, “1” and “2”.
  • i – Pseudopalindromic type, can be either 0, 1, 2, or “0”, “1”, “2”, standing for E_0, E_1 and E_2.
Returns:

The palindromic closure of the word.

Examples

>>> make_eipal_closure("102", 0)
'102'
>>> make_eipal_closure("101", 1)
'10121'

tgpc.make_pal_closure(seq) Makes a palindromic closure of a string.

Parameters: seq (string) – A word.
Returns: The palindromic closure of the word.

Examples

>>> make_pal_closure("101")
'101'
>>> make_pal_closure("102")
'10201'

tgpc.make_word012(delta, theta,*seed='') Makes a ternary GPS word from (delta, theta).

Parameters:
  • delta (str) – The sequence delta of the directive bi-sequence, composed of the letters ‘0’, ‘1’ and ‘2’.
  • theta (str) – The sequence theta of the directive bi-sequence, composed from the letters ‘R’, ‘0’, ‘1’ and ‘2’, where the last three stand for E_0, E_1 and E_2. Must have the same length as delta.
  • seed (str) – seed (initial w_0), optional.
Returns:

A string made by pseudopalindromic closure from (delta, theta).

Examples

>>> make_word012("0011", "012R")
'00221112200'

tgpc.set_logging(logging level='ERROR') Sets the logging level of the module.

If the level is set to “ERROR”, the functions log only errors. If it is set to “INFO” or “DEBUG”, the fuction prints more information about how ternary words are being processed.

Parameters: level (str) – “ERROR” (default), “INFO” or “DEBUG”

About

Ternary generalized pseudopalindromic closures and normalization.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published