How to simplify modulo - math

I am trying to find the modulo of an expression. All I know is that
(a+b) mod N = ((a mod N) + (b mod N)) mod N
How do I use it to simplify the following modulo operation?
(a - 2*b + 1) mod N
There must be some way to simplify it by considering it as
(a - b - b + 1) mod N ?
EDIT:
I have stumbled upon the following property too:
ab mod N = ((a mod N) (b mod N)) mod N
Will this be helpful somehow?

If: (a+b) mod N = ((a mod N) + (b mod N)) mod N
then:
(a - 2*b + 1) mod N = ((a mod N) - (b mod N) - (b mod N) + (1 mod N)) mod N
It is simpler with large values of a and b and a small value for N.
For example: a=85773, b = 77733340, N=5:
which would you rather solve
(85773 - 77733340 - 77733340 + 1) mod 5
or
((85773 mod 5) - (77733340 mod 5) - (77733340 mod 5) + (1 mod 5)) mod 5
for the second one i get (3 - 0 - 0 + 1) % 5 = 4

There is no way to simplify (b*-2 + a + 1) % n unfortunately.

Related

proof by contraposition in agda using solvers

can you use the Nat solver in agda-stdlib for proof by contradiction? In particular I have a gnarly bit of algebra I'd rather not do by hand, but I'm not sure how to use a solver to make my life easier. For reference this is the result I want to prove:
{n m : ℕ} → 3 + (n + (3 + (n + (3 + (n + n * (3 + n)))))) ≡ 1 + m + (1 + m + (1 + m + 0)) + 2 → ⊥

Can we simplify (x XOR a) + (x XOR b) + (x XOR c)?

(x XOR a) + (x XOR b) + (x XOR c)
Can we simplify this further?
Here '+' is addition not a logical disjunction.
x, a, b, c are numbers.
Example :
x = 10 , a = 5 , b = 4 , c = 6
(10 XOR 5) + (10 XOR 4) + (10 XOR 6) = 41.

How to get a big-O, Big-Ω and big-Θ for this function?

I have a function f(n) defined as follows:
f(n) = (n-1)(n+1)lg(n+5)/(n+3)
Here, lg is log2. I'd like to determine the big-O, big-Ω, and big-Θ values for this function. How would I go about approaching this?
Thanks!
Let's start off by simplifying your expression:
f(n) = (n-1)(n+1)lg(n+5)/(n+3)
= ((n2 - 1) lg (n + 5)) / (n + 3)
For now, let's pretend that the additive constants are there. If we delete those constants, we get this function g(n):
g(n) = n2 lg n / n = n lg n
Since we don't expect those constants to make all that much of a difference in the long term, it's reasonable to venture a guess that this function is Θ(n log n). We can prove this by taking the limit of f(n) / n log n as n tends toward infinity. If we get back a nonzero finite value, then we known that f(n) = Θ(n log n).
So let's try it!
limn → ∞ f(n) / n log n
= limn → ∞ (((n2 - 1) lg (n + 5)) / (n + 3)) / n lg n
= limn → ∞ ((n2 - 1) lg (n + 5)) / n lg n (n + 3)
= (limn → ∞ (n2 - 1) / n(n+3)) (limn → ∞ (lg (n + 5) / lg n)
= (limn → ∞ (n2 - 1) / (n2 + n)) (limn → ∞ (lg (n + 5) / lg n)
Both of these limits are degenerate forms of type ∞ / ∞, so we can use l'Hopital's rule and replace each with its derivative:
limn → ∞ (n2 - 1) / (n2 + n)
= limn → ∞ (2n / 2n + 1)
= 1
and
limn → ∞ lg (n + 5) / lg n
= limn → ∞ (1 / (n+5)) / (1 / n)
= limn → ∞ (n / (n+5))
= 1
Therefore, we get
(limn → ∞ (n2 - 1) / (n2 + n)) (limn → ∞ (lg (n + 5) / lg n)
= 1
Consequently, the ratio of f(n) / n lg n tends toward 1 as n goes to infinity, and so we have that f(n) = Θ(n log n), as required. Because of this, we also get that f(n) = O(n log n) and f(n) = Ω(n log n). We also have that f(n) ~ n log n, which is a much stronger claim.
Hope this helps!

Find x in a^x = a (mod n)

I want to calculate am mod n, where n is a prime number, and m is very large. Rather doing this with binary power calculation, I'd like to find such x that ax = a (mod n) and then calculate a(m mod x) mod n.
Obviously such x exists for any a, because powers mod n loop at some point, but I didn't find out how to calculate it with modular arithmetics. I wonder if I missed something or maybe there exists some numerical method for that?
Your modulus is prime, that makes it easy to get a start, as by Fermat's (inappropriately dubbed "little") theorem, then
a^n ≡ a (mod n)
for all a. Equivalent is the formulation
a^(n-1) ≡ 1 (mod n), if n doesn't divide a.
Then you have
a^m ≡ 0 (mod n) if a ≡ 0 (mod n) and m > 0
and
a^m ≡ a^(m % (n-1)) (mod n) otherwise
(note that your suggested a^(m % x) is in general not correct, if m = q*x + r, you'd have
a^m ≡ (a^x)^q * a^r ≡ a^q * a^r ≡ a^(q+r) (mod n)
and you'd need to repeat that reduction for q+r until you obtain an exponent smaller than x).
If you are really interested in the smallest x > 1 such that a^x ≡ a (mod n), again the case of a ≡ 0 (mod n) is trivial [x = 2], and for the other cases, let y = min { k > 0 : a^k ≡ 1 (mod n) }, then the desired x = y+1, and, since the units in the ring Z/(n) form a (cyclic) group of order n-1, we know that y is a divisor of n-1.
If you have the factorisation of n-1, the divisors and hence candidates for y are easily found and checked, so it isn't too much work to find y then - but it usually is still far more work than computing a^r (mod n) for one single 0 <= r < n-1.
Finding the factorisation of n-1 can be trivial (e.g. for Fermat primes), but it can also be very hard. In addition to the fact that finding the exact period of a modulo n is usually far more work than just computing a^r (mod n) for some 0 <= r < n-1, that makes it very doubtful whether it's worth even attempting to reduce the exponent further.
Generally, when the modulus is not a prime, the case when gcd(a,n) = 1 is analogous, with n-1 replaced by λ(n) [where λ is the Carmichael function, which yields the smallest exponent of the group of units of Z/(n); for primes n, we have λ(n) = n-1].

Data structure - run-time and Asymptotic bounds [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
if a>0 is a fixed variable, Prove then: lg(n+a) = Θ(lg n)
please advice.
To prove that f(n) = Θ(g(n)), you need to prove that there is a nonzero k such that
lim (n → ∞) f(n) / g(n) = k
In your case, we want to show that
lim (n → ∞) lg(n + a) / (lg n)
This is an indeterminate form of type ∞ / ∞, so we can apply l'Hôpital's rule and take the derivative of the numerator and denominator to get
lim (n → ∞) lg(n + a) / (lg n) =
lim (n → ∞) (1 / n + a) / (1 / n) =
lim (n → ∞) n / (n + a)
This again is an indeterminate form, so applying l'Hôpital's rule gives
lim (n → ∞) n / (n + a)
= lim (n → ∞) 1 / 1
= 1
Therefore, there is a nonzero constant (namely 1) such that the limit of lg(n + a) / lg n as n goes to infinity equals that constant, and therefore lg(n + a) = Θ(lg n).
Hope this helps!

Resources