Generate all polynomials with coefficients 0 or 1 given degree n

Rebin

I am trying to enumerate in 'C#' all the possible polynomials given the degree. Is there any algorithm to enumerate all possible polynomials given degree n? Maybe I don't know how to ask this question precisely but these are the examples:

For example:

for n=1:

x+1    return [1 1]
x      return [1 0]

for n=2:

x^2+x+1  return [1 1 1]
x^2+x    return [1 1 0] 
x^2      return [1 0 0]
x^2+1    return [1 0 1] 

for n=3:

x^3           return [1 0 0 0]
x^3+x^2       return [1 1 0 0]
x^3+x         return [1 0 1 0]
x^3+x^2+x     return [1 1 1 0]
x^3+1         return [1 0 0 1]
x^3+x^2+1     return [1 1 0 1]
x^3+x+1       return [1 0 1 1]
x^3+x^2+x+1   return [1 1 1 1]

Any pseudo code or algorithm would help.

dana

Set the leftmost bit, then do a binary counter on the right n bits. You actually need n+1 bits to account for x^0, (in my first attempt I was off by 1).

You can generate an enumeration like so:

IEnumerable<int[]> GenPolys(int n)
{
    int[] a = new int[n + 1];
    a[0] = 1;
    bool ok = true;
    while (ok)
    {
        yield return a;
        ok = false;
        for (int i = 1; i < a.Length; i++)
        {
            a[i] = 1 - a[i]; // flip the ith bit
            if (a[i] == 1)
            {
                ok = true;
                break;
            }
        }
    }
}

Usage:

foreach (int[] poly in GenPolys(4))
{
    // your code here
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Storing in a matrix - n polynomials of degree (n-1), one row for each x

From Dev

Generating 2nd Degree Polynomials Given 3-Tuples

From Dev

Generating 2nd Degree Polynomials Given 3-Tuples

From Dev

SML - Multiplying Coefficients of Polynomials

From Dev

Sympy polynomials with `mpfr` coefficients?

From Dev

how to multiply Polynomials coefficients

From Dev

Coefficients of polynomials maxima

From Dev

Rails - Return all users given parameter gives ArguemntError (1 for 0)

From Dev

Generate random polynomials with MATLAB

From Dev

Generate all vectors of certain length with 0 or 1 elements

From Dev

Solving polynomials with complex coefficients using sympy

From Dev

numpy fit coefficients to linear combination of polynomials

From Dev

Fast way to generate pseudo-random bits with a given probability of 0 or 1 for each bit

From Dev

Why is Numpy inconsistent in ordering polynomial coefficients by degree?

From Dev

Why is Numpy inconsistent in ordering polynomial coefficients by degree?

From Dev

Plotting polynomial with given coefficients

From Dev

css transform. How to get rotation degree value from "matrix( 0, 1, -1, 0, 0, 0")?

From Dev

Is there any algorithm to generate all subsets of a given set in O(n^2) time?

From Dev

Generate all IP addresses given a string in scala

From Dev

php generate all combinations from given array

From Dev

Generate all IP addresses given a string in scala

From Dev

Generate all way of arranging a given number of elements

From Dev

Generate all possible permutations given input values

From Dev

Generate all numbers by deleting digits of a given number

From Dev

LASSO coefficients equal to 0 using opt1D

From Dev

Given a tensor [5,4,3,4], how to generate a constant tensor where each row has n ones and m zeros, n=5,4,3,4, and m=0,1,2,1.

From Dev

Generating 2nd Degree Polynomials from 3-tuples

From Dev

Comparing two polynomials with vector's coefficients C++

From Dev

generate random 0 or 1 - Oracle

Related Related

  1. 1

    Storing in a matrix - n polynomials of degree (n-1), one row for each x

  2. 2

    Generating 2nd Degree Polynomials Given 3-Tuples

  3. 3

    Generating 2nd Degree Polynomials Given 3-Tuples

  4. 4

    SML - Multiplying Coefficients of Polynomials

  5. 5

    Sympy polynomials with `mpfr` coefficients?

  6. 6

    how to multiply Polynomials coefficients

  7. 7

    Coefficients of polynomials maxima

  8. 8

    Rails - Return all users given parameter gives ArguemntError (1 for 0)

  9. 9

    Generate random polynomials with MATLAB

  10. 10

    Generate all vectors of certain length with 0 or 1 elements

  11. 11

    Solving polynomials with complex coefficients using sympy

  12. 12

    numpy fit coefficients to linear combination of polynomials

  13. 13

    Fast way to generate pseudo-random bits with a given probability of 0 or 1 for each bit

  14. 14

    Why is Numpy inconsistent in ordering polynomial coefficients by degree?

  15. 15

    Why is Numpy inconsistent in ordering polynomial coefficients by degree?

  16. 16

    Plotting polynomial with given coefficients

  17. 17

    css transform. How to get rotation degree value from "matrix( 0, 1, -1, 0, 0, 0")?

  18. 18

    Is there any algorithm to generate all subsets of a given set in O(n^2) time?

  19. 19

    Generate all IP addresses given a string in scala

  20. 20

    php generate all combinations from given array

  21. 21

    Generate all IP addresses given a string in scala

  22. 22

    Generate all way of arranging a given number of elements

  23. 23

    Generate all possible permutations given input values

  24. 24

    Generate all numbers by deleting digits of a given number

  25. 25

    LASSO coefficients equal to 0 using opt1D

  26. 26

    Given a tensor [5,4,3,4], how to generate a constant tensor where each row has n ones and m zeros, n=5,4,3,4, and m=0,1,2,1.

  27. 27

    Generating 2nd Degree Polynomials from 3-tuples

  28. 28

    Comparing two polynomials with vector's coefficients C++

  29. 29

    generate random 0 or 1 - Oracle

HotTag

Archive