Esempio n. 1
0
def gen_irreducible_Z_polys(n):
    polys = [] 
    for i in range(n):
        k = i // 2 + 1
        if i % 2 == 1:
            k = -k
        polys.append(cratylus.poly_from_var('x', modulo=0) + cratylus.poly_from_constant(k, modulo=0))
    return polys
Esempio n. 2
0
def translate_monomial(table, monomial, options):
    key, coef = monomial.coefficients().items()[0]
    res = cratylus.poly_from_constant(1, OPTIONS['target_modulo'])
    for var, power in key:
        if var in table:
            res = res * table[var] ** power
        else:
            assert var in options['initial_table']
            res = res * options['initial_table'][var] ** power
    return res
Esempio n. 3
0
def gen_irreducible_Z_polys(n):
    polys = []
    for i in range(n):
        k = i // 2 + 1
        if i % 2 == 1:
            k = -k
        polys.append(
            cratylus.poly_from_var('x', modulo=0) +
            cratylus.poly_from_constant(k, modulo=0))
    return polys
Esempio n. 4
0
def translate_monomial(table, monomial, options):
    key, coef = monomial.coefficients().items()[0]
    res = cratylus.poly_from_constant(1, OPTIONS['target_modulo'])
    for var, power in key:
        if var in table:
            res = res * table[var]**power
        else:
            assert var in options['initial_table']
            res = res * options['initial_table'][var]**power
    return res
Esempio n. 5
0
def irreducible_elements(n, translation_type):
    "Return n irreducible elements appropiate for the given translation type"
    if translation_type == 'fractran':
        return [cratylus.poly_from_constant(p, modulo=0) for p in gen_primes(n)]
    elif translation_type == 'univariate':
        return gen_irreducible_Z_polys(n)
    elif translation_type == 'binary':
        return gen_irreducible_Zk_polys(n, k=2)
    elif translation_type == 'vars_compact':
        return gen_compact_vars(n)
    elif translation_type == 'words':
        return gen_words(n)
    elif translation_type == 'mixed':
        return gen_mixed(n)
    else:
        assert False
Esempio n. 6
0
def irreducible_elements(n, translation_type):
    "Return n irreducible elements appropiate for the given translation type"
    if translation_type == 'fractran':
        return [
            cratylus.poly_from_constant(p, modulo=0) for p in gen_primes(n)
        ]
    elif translation_type == 'univariate':
        return gen_irreducible_Z_polys(n)
    elif translation_type == 'binary':
        return gen_irreducible_Zk_polys(n, k=2)
    elif translation_type == 'vars_compact':
        return gen_compact_vars(n)
    elif translation_type == 'words':
        return gen_words(n)
    elif translation_type == 'mixed':
        return gen_mixed(n)
    else:
        assert False