Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫  π  -¹ ² ³ °

You are not logged in.

#51 2014-03-02 02:08:12

bobbym
From: Bumpkinland
Registered: 2009-04-12
Posts: 93,935

Re: Four Squares Reborn

Do you understand what a pure function is?

In mathematics, you don't understand things. You just get used to them.

I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.

Offline

#52 2014-03-02 02:19:51

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 20,331
Website

Re: Four Squares Reborn

Do LISP programmers call it a lambda function? It is an anonymous function

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

#53 2014-03-02 02:21:35

bobbym
From: Bumpkinland
Registered: 2009-04-12
Posts: 93,935

Re: Four Squares Reborn

Yes, that is exactly correct. It is borrowed from the Lambda Calculus.

M uses a slot # and a & to make one.

In mathematics, you don't understand things. You just get used to them.

I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.

Offline

#54 2014-03-02 02:29:28

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 20,331
Website

Re: Four Squares Reborn

Lambda Calculus?

I do not understand the # and & part, it looks very creepy. Please illustrate

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

#55 2014-03-02 02:31:52

bobbym
From: Bumpkinland
Registered: 2009-04-12
Posts: 93,935

Re: Four Squares Reborn

It is used right here:

``````FindInstance[a^2 + b^2 + c^2 + d^2 == n, {a, b, c, d},
Integers, RandomSeed -> #]& /@ Range[20];``````

But there is one more thing before we get to it...

In mathematics, you don't understand things. You just get used to them.

I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.

Offline

#56 2014-03-02 02:38:09

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 20,331
Website

Re: Four Squares Reborn

yes?

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

#57 2014-03-02 02:39:33

bobbym
From: Bumpkinland
Registered: 2009-04-12
Posts: 93,935

Re: Four Squares Reborn

M uses options to enhance the commands. They are put in like this

(Name of the option) -> value, usually at the end of the command.

In mathematics, you don't understand things. You just get used to them.

I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.

Offline

#58 2014-03-02 02:47:12

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 20,331
Website

Re: Four Squares Reborn

Yes, I have seen that. There are a lot of options in the commands that do Interactive things

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

#59 2014-03-02 02:49:49

bobbym
From: Bumpkinland
Registered: 2009-04-12
Posts: 93,935

Re: Four Squares Reborn

``````FindInstance[a^2 + b^2 + c^2 + d^2 == n, {a, b, c, d},
Integers, RandomSeed -> #]& /@ Range[20];``````

FindInstance uses random methods to arrive at answers as well as all known math methods. Because it sometimes has to use random numbers it requires a seed. Do you know what a random seed?

In mathematics, you don't understand things. You just get used to them.

I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.

Offline

#60 2014-03-02 03:17:09

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 20,331
Website

Re: Four Squares Reborn

I think it is a number which is used to intiatalise a PRNG

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

#61 2014-03-02 03:23:18

bobbym
From: Bumpkinland
Registered: 2009-04-12
Posts: 93,935

Re: Four Squares Reborn

That is correct so instead of doing

FindInstance[a^2 + b^2 + c^2 + d^2 == n, {a, b, c, d},Integers, RandomSeed -> 1]

FindInstance[a^2 + b^2 + c^2 + d^2 == n, {a, b, c, d},Integers, RandomSeed -> 2]

FindInstance[a^2 + b^2 + c^2 + d^2 == n, {a, b, c, d},Integers, RandomSeed -> 3]
.
.
.
FindInstance[a^2 + b^2 + c^2 + d^2 == n, {a, b, c, d},Integers, RandomSeed -> 20]

to get 20 different seeds ( remember we want 20 different answers and hope that if he starts from different seeds he will get a different answer). We map the slot operator # to {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20} which does the above but without all the work of writing that.

In mathematics, you don't understand things. You just get used to them.

I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.

Offline

#62 2014-03-02 03:29:53

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 20,331
Website

Re: Four Squares Reborn

Why do you have to supply the seed manually?

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

#63 2014-03-02 03:33:55

bobbym
From: Bumpkinland
Registered: 2009-04-12
Posts: 93,935

Re: Four Squares Reborn

Because the seed could be anything, how can M know which one I want?

In mathematics, you don't understand things. You just get used to them.

I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.

Offline

#64 2014-03-02 04:34:45

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 20,331
Website

Re: Four Squares Reborn

What is this?

ans = Union[Flatten[ans, 1]];

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

#65 2014-03-02 14:35:23

bobbym
From: Bumpkinland
Registered: 2009-04-12
Posts: 93,935

Re: Four Squares Reborn

Flatten removes all dimensionality and returns a list. Union is the same as the mathematical set command.

In mathematics, you don't understand things. You just get used to them.

I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.

Offline

#66 2014-03-02 15:17:13

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 20,331
Website

Re: Four Squares Reborn

What would the output look like without that command?

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

#67 2014-03-02 15:20:43

bobbym
From: Bumpkinland
Registered: 2009-04-12
Posts: 93,935

Re: Four Squares Reborn

Quite confusing. Generally the Flatten command does this,

Flatten[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}]

{1, 2, 3, 4, 5, 6, 7, 8, 9}

notice all list brackets were destroyed and the matrix is flattened into a list.

In mathematics, you don't understand things. You just get used to them.

I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.

Offline

#68 2014-03-02 15:37:20

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 20,331
Website

Re: Four Squares Reborn

WHy did you use it in that code?

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

#69 2014-03-02 15:39:49

bobbym
From: Bumpkinland
Registered: 2009-04-12
Posts: 93,935

Re: Four Squares Reborn

I wanted to make sure the Union command and the Length command would work correctly.

In mathematics, you don't understand things. You just get used to them.

I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.

Offline

#70 2014-03-02 15:46:28

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 20,331
Website

Re: Four Squares Reborn

``````square4[n_] :=
Block[{ans},
ans = FindInstance[a^2 + b^2 + c^2 + d^2 == n, {a, b, c, d},
Integers, RandomSeed -> #]& /@ Range[200,220];
ans = Union[Flatten[ans, 1]];
If[Length[ans] == 20, {a, b, c, d} /. ans]]``````

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

#71 2014-03-02 15:48:47

bobbym
From: Bumpkinland
Registered: 2009-04-12
Posts: 93,935

Re: Four Squares Reborn

We sure could but is it anymore correct then what I have done? I mean, we are still gambling that 20 different seeds will coax FindInstance to get the 20 different answers we require.

In mathematics, you don't understand things. You just get used to them.

I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.

Offline

#72 2014-03-02 15:51:29

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 20,331
Website

Re: Four Squares Reborn

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

#73 2014-03-02 15:54:27

bobbym
From: Bumpkinland
Registered: 2009-04-12
Posts: 93,935

Re: Four Squares Reborn

It will run if that is what you mean and get the correct answer.

In mathematics, you don't understand things. You just get used to them.

I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.

Offline

#74 2014-03-02 16:08:28

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 20,331
Website

Re: Four Squares Reborn

Okay, May I ask you a question that you'll not enjoy answering?

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

#75 2014-03-02 16:11:02

bobbym
From: Bumpkinland
Registered: 2009-04-12
Posts: 93,935

Re: Four Squares Reborn

Hmmm, I am afraid to ask. What is the question?

In mathematics, you don't understand things. You just get used to them.

I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.

Offline