Group Abstract Group Abstract

Message Boards Message Boards

0
|
5.7K Views
|
7 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

Listing objects under conditions

Posted 11 years ago

Hello, I cannot find how I could list all the 3-uples of integers {a,b,c} such that 0 < a ? b ? c < a+b and for instance c ? 10. I tried the condition command (/;) , Select, Cases,and other commands given in the Wolfram Documentation without any result. My goal is to let a discrete function act on those 3-uples that match the given condition. Could You please see the attached notebook and help me to find the correct coding to obtain ONLY the solutions and get rid of the useless "Null" .

That you very much for help.

Attachments:
POSTED BY: Richard KAUSCH
7 Replies
Posted 11 years ago

I think this may be what you are trying to do. where the n can be any number.

f[n_] := Cases[
  Tuples[Range[n], {3}], {a_, b_, c_} /; 
   a <= b <= c && c <= a + b && IntegerQ[Sqrt[2 a^2 + 2 b^2 - c^2]/2]]


 f[10]

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

Paul.

I noticed that some of those results were zero, so if we want to test for the Integer part to be greater than zero we can add another test like so

f[n_] := Cases[
  Tuples[Range[n], {3}], {a_, b_, c_} /; 
   a <= b <= c && c <= a + b && c > 0 && 
    IntegerQ[p = Sqrt[2 a^2 + 2 b^2 - c^2]/2] && p > 0]

Notice I set the sqrt part to equal p and then tested the p to be greater than zero afterwards.

P

POSTED BY: Paul Cleary
Posted 11 years ago
POSTED BY: Richard KAUSCH
Posted 11 years ago
POSTED BY: Richard KAUSCH
Posted 11 years ago

Sorry, I missed that the last condition is indeed <. Moreover, # is the same as #1 that is why there was no differenc after your change. Is this ok now? Don't hesitate to ask if something is still not clear.

POSTED BY: Kuba Podkalicki
Posted 11 years ago

The only question that puzzles me is that I may read the code erroneously because the condition a ? b ? c is not visible ( I understand that the code gives a ? b+c, b ? c+a , c ? a+b ). This reading must be wrong.

POSTED BY: Richard KAUSCH
Posted 11 years ago

Select applies function in second argument to each triple {a,b,c}. When we have # < #3 & @@ #& it means we check if a&lt;c in that triple. You can write it #[[1]] < #[[3]] & to skip function composition.

Ok, now in our code we are doing a<=b<=c<a+b check which checks those conditions simultaneuosly, like e.g. 1 <= 2 <= 3 < 4.

POSTED BY: Kuba Podkalicki
Posted 11 years ago

Semi automatic, brute force approach, but works for less memory consuming examples:

Select[Tuples[Range[10], {3}], # <= #2 <= #3 < # + #2 & @@ # &   ]
POSTED BY: Kuba Podkalicki
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard