Sum Of Square

ShaunN

New member
Joined
Feb 27, 2022
Messages
2
Hi I'm actually trying to optimise a computer science solution. The question I have if you have an array of numbers e.g. array A -> 1 2 3 and a square of that array array B -> 1 4 9 . Is there any prove or how do I prove if the length of both arrays are equal ( A and B is the length of 3 in this example) then the sum of the squares of A is equal to the sum of B
 
Hi I'm actually trying to optimise a computer science solution. The question I have if you have an array of numbers e.g. array A -> 1 2 3 and a square of that array array B -> 1 4 9 . Is there any prove or how do I prove if the length of both arrays are equal ( A and B is the length of 3 in this example) then the sum of the squares of A is equal to the sum of B
Every natural number has "only one" square

what would that tell you?​
 
Hi I'm actually trying to optimise a computer science solution. The question I have if you have an array of numbers e.g. array A -> 1 2 3 and a square of that array array B -> 1 4 9 . Is there any prove or how do I prove if the length of both arrays are equal ( A and B is the length of 3 in this example) then the sum of the squares of A is equal to the sum of B
Are you saying that A could be any array of n integers, not necessarily starting at 1 or consecutive? You didn't specify.

If I take what you say literally, then the answer is obvious: the sum of squares of A is by definition the same as the sum of B, whose elements are those squares (so it necessarily has the same length as A!).

So I'm trying to figure out what you might really mean. (If you are in computer science, you really need to learn to specify a problem clearly!)
 
Are you saying that A could be any array of n integers, not necessarily starting at 1 or consecutive? You didn't specify.

If I take what you say literally, then the answer is obvious: the sum of squares of A is by definition the same as the sum of B, whose elements are those squares (so it necessarily has the same length as A!).

So I'm trying to figure out what you might really mean. (If you are in computer science, you really need to learn to specify a problem clearly!)
Apologies I realized that wasnt really asked well :( .

Are you saying that A could be any array of n integers, not necessarily starting at 1 or consecutive? Yes

I basically trying to test given two array A and B. Does B contain squares of every integer in A . So given A any five integers (even duplicates) is there a square of the integer in B.
A [ 2 3 3 4 1 1] - > B [4 9 9 16 1 1 ]

These are steps that seem valid for me to shorten computation in terms of CPU
1. Are the length equal if not return false
2. Sum the squares of A into x
3. Sum B into y
4. If x= y return true if not return false

Would the above work for A of any length containing integers? If not is there a simple way to prove why it wont work using math notations?

The obvious way is to go through nested loops but this CPU intensive if the arrays are quite large
 
I basically trying to test given two array A and B. Does B contain squares of every integer in A . So given A any five integers (even duplicates) is there a square of the integer in B.
A [ 2 3 3 4 1 1] - > B [4 9 9 16 1 1 ]

As I now understand it, you want an efficient algorithm so that, given two arrays of integers, A and B, you can determine whether ... what? Is it whether the square of each element of A occurs somewhere within B (so that you are treating them as sets rather than arrays, in which order matters)? That is not what your steps do.

If you are thinking that the sum of two arrays of squares can't be the same unless the squares individually are the same, the answer is no. For a simple counterexample, the sums 7^2 + 24^2 = 625 and 15^2 + 20^2 = 625 are equal, though the squares are different.

I'm not sure you've yet stated what the algorithm has to do. In your example, would you want to say yes or no if we replaced one of the 9's in B with, say, 10, or 25, or just removed it entirely? Then the square of everything in A would be in B (which is the condition you state), but not everything in B would be the square of something in A. I suspect you may want to determine whether B is a permutation of the squares of elements of A (treated as a multiset); I'd search for such algorithms, if I were you.
 
Top