Need help beginning a modular congruence proof - proof

(∀a, b ∈ Z) a2 + b2 − 3 ≡|≡ 0 mod 4.
Hi, I'm not too sure where to start with this proof and just need some pointers on how to approach this.

a=b=3 gives 9+9-3 = 15 which is congruent to 0 mod 3, disproving your statement.

Related

Special cases of modulo operator

I included a function (a%b + b) % b in some old cold and remember concluding that this was due to some special cases of a%b that I needed to be careful about. a and b are c ints and % is the c modulo operator. Now I am having trouble seeing where these two expressions ever differ. Are they completely equivalent?
The mathematical long division demands that the remainder is zero or positive, a=q*b+r with 0 <= r < b.
In the computer implementations of this operation it is possible that a%b is negative. Thus adding b then gives the non-negative remainder. To be universally useful you either need an if-branching or another remainder operation for the case where a%b already was non-negative.
The % operator does not implement a true modulo. In fact,
a ≥ 0 -> a % b = a mod b
a < 0 -> a % b = - ((-a) mod b)
Now,
a -4 -3 -2 -1 0 1 2 3 4
a mod 4 0 1 2 3 0 1 2 3 0
a % 4 0 -3 -2 -1 0 1 2 3 0
(a % 4 + 4) % b 0 1 2 3 0 1 2 3 0
Unfortunately, this doubles the cost of the modulo, which is significant.

Outputs of a program

I am new to programming and I would like to know how to solve questions like this. I was told to expect questions like this on the exam. Can someone please tell me how I would go about solving something like this? Thanks.
x = 0
for num in range(5):
if num % 2 == 0:
x = x + 2
else:
x = x + 1
print(x)
You need to work on a skill which is to "be the compiler", in the sense that you should be able to run code in your head. Step through line by line and make sure you know what is happening. In you code example, you have
for num in range(5) means you will be iterating with num being 0,1,2,3 and 4. Inside the for loop, the if statement num % 2 == 0 is true when num/2 does not have a remainder (how % mods work). So if the number is divisible by 2, x = x+2 will execute. The only numbers divisible by 2 from the for loop are 0,2 and 4. so x=x+2 will execute twice. The else statement x = x +1 runs for all other numbers (1,3) which will execute 2 times.
Stepping through the for loop:
num = 0 //x=x+2, x is now 2
num = 1 //x=x+1, x is now 3, print(x) prints 3
num = 2 //x=x+2, x is now 5
num = 3 //x=x+1, x is now 6, print(x) prints 6
num = 4 //x+x+2, x is now 8
Therefore the answer is that 3 and 6 will be printed
In my opinion,
Whatever language you are using, you need to learn some common elements of the modern programming languages, such as flow-control (if...else in your case), loop(for, in your case)
Some common used functions, in your case, you need to what does range do in Python,
docs.python.org is a good place for you.
As you are new to programming, you can go with the flow in you mind or draw it on the paper.
Using x to store our final result
loop through every item in [0, 1, 2, 3, 4] <- range(5)
a. if
the number is divisible by 2
then increase x by adding 2 to it.
b. else
increase x by adding 1 and print it out
So the result would be :
3
6

Iterating through matrix rows in Octave without using an index or for loop

I am trying to understand if it's possible to use Octave more efficiently by removing the for loop I'm using to calculate a formula on each row of a matrix X:
myscalar = 0
for i = 1:size(X, 1),
myscalar += X(i, :) * y(i) % y is a vector of dimension size(X, 1)
...
The formula is more complicate than adding to a scalar. The question here is really how to iterate through X rows without an index, so that I can eliminate the for loop.
Yes, you can use broadcasting for this (you will need 3.6.0 or later). If you know python, this is the same (an explanation from python). Simply multiply the matrix by the column. Finnaly, cumsum does the addition but we only want the last row.
newx = X .* y;
myscalars = cumsum (newx, 1) (end,:);
or in one line without temp variables
myscalars = cumsum (X .* y, 1) (end,:);
If the sizes are right, broadcasting is automatically performed. For example:
octave> a = [ 1 2 3
1 2 3
1 2 3];
octave> b = [ 1 0 2];
octave> a .* b'
warning: product: automatic broadcasting operation applied
ans =
1 0 6
1 0 6
1 0 6
octave> a .* b
warning: product: automatic broadcasting operation applied
ans =
1 2 3
0 0 0
2 4 6
The reason for the warning is that it's a new feature that may confuse users and is not existent in Matlab. You can turn it off permanentely by adding warning ("off", "Octave:broadcast") to your .octaverc file
For anyone using an older version of Octave, the same can be accomplished by calling bsxfun directly.
myscalars = cumsum (bsxfun (#times, X, y), 1) (end,:);

Boolean Algebra, meaning of this sign...?

What does the equivalence sign with the small 3 next to it mean... I'm unfamiliar with that sign.
≡3
Thanks!
This means "is congruent to modulo 3." For example, 7 ≡3 1 because 7 mod 3 = 1 = 1 mod 3. More formally, a ≡n b iff there exists integral c0, c1, along with an integral k with 0 ≤ k < n, such that a = nc0 + k and b = nc1 + k.

If I XOR 2 numbers, do I only get identical results if the numbers are the same?

For example, suppose I have x XOR y = y XOR x = z. Is it possible to have something like a XOR b = z?
Short answer: Yes
Long answer:
XOR is a binary operation, it works on the individual bits and it's commutative.
It has the truth table:
A B Q
0 0 0
0 1 1
1 0 1
1 1 0
As the number is made up of these bits then the result will be the same as long as for each bit position the two bits have the same result.
For example take the 2 eight bit numbers 113 and 42
113 = 01110001
42 = 00101010
XOR = 01011011 = 91
but if I swap the fourth bit from the left I get
97 = 01100001
58 = 00111010
XOR = 01011011 = 91
So yes again...
Yes.
z = y because x ^ y ^ x = y
So it is entirely possible for a combination a ^ b = y = z.
In fact, for every a there exists a b such that a ^ b = z. To calculate that, b = z ^ a.
Be aware that XOR is commutative: this means that x ^ y = y ^ x.
Yes. As a degenerate proof, XORing a number with itself always results in 0.
XOR, will return true if both parameters are different, assuming that the parameters are Boolean values anyway. This is different from or, which will return true if either parameter is true, and NOR, which will return true only if both of them are false.