-1

I need to calculate the binomial polynomial expression in r. I can calculate the polynomial expression using polynomial() function in r. But on top of evaluating the expression in polynomial, I want the expression must hold the binomial expression as well.

For example: in binomial,

we know

1+1 = 0, which is also 1 XOR 1 = 0,

Now, if we do the same in polynomial expressions, it can be done in the following way:

(1+x) + x = 1

Here we suppose,

x + x is similar to 1 + 1 which is equal to zero. Or in other words x XOR x = 0.

Before, I have added the whole of the code in R, maybe there were few people who did not understand the question, so they might thought it is better to close the question. I need to know how to implement the XOR operation in binomial polynomial expression in R.

Need to apply in following manner:

let f(x) = (1 + x + x^3) and g(x) = (x + x^3),

Therefore for the sum of f(x) and g(x), I need to do the following:

f(x) + g(x) = (1 + x + x^3) + (x + x^3)

= 1 + (1 + 1)x + (1 + 1)x^3 (using addition modulo 2 in Z2)

= 1 + (0)x + (0)x^3

= 1.

I hope, this time I more clear of what exactly I want and my question is more understandable.

Thanks in Advance

Neha
  • 91
  • 1
  • 2
  • 12
  • 1
    still not clear, sorry. R has an `xor()` operator built in. For a given logical `x` you could do the computation: `x <- TRUE; xor(xor(TRUE,x), x)`. There isn't an easy way I know of to tell R that *in general* `xor(x,x)` is FALSE (or 0). What do you mean by a "binomial polynomial expression??? – Ben Bolker Aug 17 '20 at 01:15
  • I'm beginning to get it, but I don't understand what the coefficients in your polynomial would be. Would they also be binary (TRUE/FALSE) values? – Ben Bolker Aug 17 '20 at 01:17
  • At this time, say the coefficients are 2 arguments, x and (1+x). You add them, it gives you in normal polynomial function as 1+2x. But if you do the same, in binary polynomial, it will give you 1. as we suppose x+x (x XOR x) = 0. – Neha Aug 17 '20 at 01:43
  • I'm can't figure out what you are asking. You keep switching between "binary" and "binomial", is that intentional? Also when are you defining `f(x)` does `x` stand in for 0/1 so it's really `f(0)` and `f(1)` and they produce different values? Or are you saying it's not a function and always returns the same output for any `x`? Normally in binary `1+1 = 10`, not `0`. I'm very confused by how you are using these terms. – MrFlick Aug 17 '20 at 03:46
  • Thanks, for pointing that out, that was not intentional. I updated my question, where I wrote "binary". I need to have the answer in binomial polynomial. Apart from that, f(x) will either stand on 0 or 1. f(x) is closed under z2 – Neha Aug 17 '20 at 03:52

2 Answers2

0
XOR <- function(x,y) (x+y) %% 2

would give you an XOR function fitting your definition.

pseudospin
  • 2,737
  • 1
  • 4
  • 19
  • No, This is not as simple. Taking modulus 2, will make the whole polynomial output 0. Say for example: y = 1+x, So XOR function take 2 parameter values, x and 1+x. If we take the modulus of (x + (1+x)) %% 2, the output it gives is 0. Instead, it should give 1. – Neha Aug 17 '20 at 01:40
  • So your value needs two components? The coefficient of 1 and the coefficient of x (which could both be 0 or 1)? And you want to do algebra with that? e.g. x^n == x? – pseudospin Aug 17 '20 at 02:27
  • I just updated my question. Check for the new example. It is a mathematical computation over z2, means polynomials which only work on {0,1}. – Neha Aug 17 '20 at 02:39
0

Adding a solution to my own question.

Basically we need to first calculate the polynomial. Simply how we do. That is a first step. For example for adding f(x) and g(x), create a function like below

bPolynomial<-function(f, g){
 K <- polynomial()
 K <- (1 + x + x^3) + (x + x^3) # where f is  (1 + x + x^3), and g is (x + x^3)

}

Then second is, extract the coefficients from the above polynomial and reduce them to modulo 2, using below code:

coeff <- coefficients(C_D) %% 2
    print(coeff)
    C_D <- polynomial(c(coeff))

That is it. You will get the desired result. I do feel stupid for getting stuck on something which is very basic. But implementation with mathematics computation sometimes make people confuse, same happened with me..!! Hope it will be helpful to other people. Thanks.

Neha
  • 91
  • 1
  • 2
  • 12