Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7074661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:05:05+00:00 2026-05-28T06:05:05+00:00

As a school assignment, I am supposed to create a program in C# that

  • 0

As a school assignment, I am supposed to create a program in C# that multiplies two polynomials using FFT over a finite field.
My finite field of choice would be Zp (all operations modulo p, the elements are {0,…,p – 1} ). I realized the p has to be large enough so that the factors in the resulting polynomial are not changed by the modulo operation.
Finding the nth primitive root of unity is easy for small n(in a corresponding finite field). However, I needed to find it for n = 220. I practically needed only this one as computing it for all the lower powers of 2 is done by squaring. I tried to write a simple program that would compute it(using the fact that there is 2r th root of unity in the finite field Zc*2r + 1), ran it for a pretty long time and it didn’t finish. So I tried to Google something and only found a table of primitive nth roots for n = 2k for k = 0..30 in the field Z70383776563201 and used it. Of course when I used longint, it resulted in overflow and therefore, wrong answers. So I started using the BigInteger structure from the System.Numerics namespace. This is where I am, having a correct algorithm that is extremely slow:

private static List<BigInteger> FFT(List<BigInteger> input, BigInteger Omega)
            {
                if (input.Count == 1)
                {
                    return new List<BigInteger>() { input[0] };
                }
                else
                {
                    List<BigInteger> evenInput = new List<BigInteger>();
                    for (int i = 0; i < input.Count; i += 2)
                    {
                        evenInput.Add(input[i]);
                    }
                    List<BigInteger> oddInput = new List<BigInteger>();
                    for (int i = 1; i < input.Count; i += 2)
                    {
                        oddInput.Add(input[i]);
                    }
                    List<BigInteger> even = FFT(evenInput, (Omega * Omega));
                    List<BigInteger> odd = FFT(oddInput, (Omega * Omega));
                    BigInteger[] outputArr = new BigInteger[input.Count];
                    int count = 0;
                    for (int i = 0; i < input.Count / 2; i++)
                    {
                        outputArr[i] = (even[i] + BigInteger.Pow(Omega, i) * odd[i]);
                        outputArr[i + input.Count / 2] = (even[i] - BigInteger.Pow(Omega, i) * odd[i]);
                        count += 2;
                    }
                    List<BigInteger> output = new List<BigInteger>();
                    for (int i = 0; i < count; i++)
                    {
                        output.Add(outputArr[i] % finiteField);
                    }
                    return output;
                }
            }

I know that creating all the lists doesn’t help the speed, but the main problem is the BigInteger structure of course.(I tried basically the same code with System.Numerics.Complex structure and it was as fast as it should be) The modulo operation takes extremely long, so I know I have to go back to longint. The problem is finding the primitive nth root of unity. I don’t know if it’s even possible to use the 220 th primitive root of unity with longint without having to worry about overflow. If not, for which n can I use longint and thus have a fast algorithm?
Is there a way of computing the primitive roots for large n faster? Maybe someone knows of a table of precomputed primitive roots in finite fields? Or should I consider using other finite fields? This is the only kind I know of. I have been searching for quite a long time and didn’t come across anything useful. I have been told by the teacher that this area is well documented, but it doesn’t seem to be the case.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:05:06+00:00Added an answer on May 28, 2026 at 6:05 am

    I haven’t thought it through completely, but it seems you shouldn’t see that big of a difference when switching to BigIntegers – 10x maybe? Your doing math mod 2^20, so your numbers should remain pretty small. It looks to me like these are your problems: Omega * Omega, and especially even[i] + BigInteger.Pow(Omega, i) * odd[i]. That will let your numbers grow much larger than they need to be.

    Biginteger.Pow has an exponential running time in the length of the exponent. You’re doing modular math, so you should be able to reduce modulo finiteField more often: Omega * Omega % finiteField, and even[i] + BigInteger.ModPow(Omega, i, finiteField) * odd[i].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an assignment from school where the program is supposed to close when
In a school assignment I'm supposed to complete a method that should return an
I am trying to build a program for a school assignment that generates transitive
For a school assignment, I am trying to create a simple HTTP server using
I currently have a school assignment that involves both PHP and asp.net. Now the
I am working on a school assignment that requires me to be able to
I need help using Bouncy Castle RSA Libraries for a school assignment, but it
I'm writing a program as an assignment for school and I though I had
Ok, so I have a simple c++ program that's supposed to run a couple
I have a school assignment where I need to create a data-driven style of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.