Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
0

How to define function

asked 4 years ago

anonymous user

Anonymous

updated 4 years ago

I want to generate a random function from GF(2)4 to GF(2)4. So my function takes 4 bit input value and 4 bit output value. Also how to define if my function is say f(x1,x2,x3,x4)=(x1x2,x3,x4,x1)?

Preview: (hide)

Comments

What do you mean by random? You want it uniformly among all possible functions?

vdelecroix gravatar imagevdelecroix ( 4 years ago )

Yes, it is taken uniformly among all possible functions.

Sanu gravatar imageSanu ( 4 years ago )

1 Answer

Sort by » oldest newest most voted
0

answered 3 years ago

Max Alekseyev gravatar image

updated 3 years ago

We can create a random function as a substitution table (over arbitrary Cartesian power d of a finite object K, also doing some coersing):

import random
from sage.combinat.cartesian_product import CartesianProduct_iters

def get_random_function(K,d):
  E = [tuple(e) for e in CartesianProduct_iters(*([K]*d))]
  print(E)
  D = dict( zip(E,random.choices(E,k=len(E))) )
  def rf(x):
    return D[tuple(K(e) for e in x)]
  return rf

Now, we get get two particular random function my_func1 and my_func2, and evaluate them on all elements of GF(2)4:

my_func1 = get_random_function(GF(2),4)
print([my1_func(x) for x in CartesianProduct_iters(*([GF(2)]*4))])
my_func2 = get_random_function(GF(2),4)
print([my_func2(x) for x in CartesianProduct_iters(*([GF(2)]*4))])

Answer to the second question is straightforward:

def f(x):
   y = (x[0]+x[1], x[2], x[3], x[0])
   return (GF(2)(e) for e in y)
print( f( (1,1,1,1) ) )
Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 4 years ago

Seen: 494 times

Last updated: Apr 28 '21