HP Forums

Full Version: Any languages able to program (0,1] mathematical interval
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Mathematicians often use brackets to indicate whether or not a limit value is included or excluded, e.g. (0,9] might be programmed as 0<=x<9... I don't use that syntax often so wouldn't be sure which bracket is which without checking. Update: It seems I have the brackets the wrong way round.

Are there any programming languages that recognise that syntax directly, thereby avoiding the need to check and code it differently?

I am mainly interested in mainstream languages (Basic, C, Lua, Python ... And of course HP PPL) rather than Mathematica and the like.

Alternatively, is there a different way of writing such an interval concisely, yet making which is included/excluded clearer.
(04-28-2017 01:56 PM)StephenG1CMZ Wrote: [ -> ]Alternatively, is there a different way of writing such an interval concisely, yet making which is included/excluded clearer.

[0, 9[ ?
(04-28-2017 01:56 PM)StephenG1CMZ Wrote: [ -> ]Mathematicians often use brackets to indicate whether or not a limit value is included or excluded, e.g. (0,9] might be programmed as 0<=x<9... I don't use that syntax often so wouldn't be sure which bracket is which without checking.

It appears the correct syntax is [0, 9).

W|A understands the notation I was taught in middle school:

Plot [0, 9[
(04-28-2017 03:48 PM)Gerson W. Barbosa Wrote: [ -> ]
(04-28-2017 01:56 PM)StephenG1CMZ Wrote: [ -> ]Alternatively, is there a different way of writing such an interval concisely, yet making which is included/excluded clearer.

[0, 9[ ?

? I don't find that any clearer...
The only notation I recall clearly from my maths class is < or <=
(04-28-2017 08:16 PM)StephenG1CMZ Wrote: [ -> ]
(04-28-2017 03:48 PM)Gerson W. Barbosa Wrote: [ -> ][0, 9[ ?

? I don't find that any clearer...
The only notation I recall clearly from my maths class is < or <=

[0 clearly encloses 0 while in 9[ 9 is definitely out. This doesn't seem to be a standard notation, though.
(04-28-2017 01:56 PM)StephenG1CMZ Wrote: [ -> ]Alternatively, is there a different way of writing such an interval concisely, yet making which is included/excluded clearer.

To emphasize the equal.

Code:

if ( (a < 0 and a > 9) or (a == 0) ) {
  //this avoid the subtle <= that may be overlooked more easily than an extended condition. 
  //Code maintenance is more important than performance most of the time. Brain time is more precious than CPU time.
  ...code...
}
(04-28-2017 08:28 PM)Gerson W. Barbosa Wrote: [ -> ][0 clearly encloses 0 while in 9[ 9 is definitely out. This doesn't seem to be a standard notation, though.

It may be not standard, but I was taught it in school too. Have to admit, never seen it after school, it seemed to have been replaced by [a,b) convention.
When I get to my bookshelf I will check for it in some older texts.
ALL

From the publication Pre-Calculaus for Dummies, second edition:

You can use interval notation to express where a set of solutions begins and here it ends. Interval notation is a common way to express the solution set to an inequality, and it’s important because it’s how you express solution sets in calculus. Most pre-calculus books and some pre-calculus teachers now require all sets to be written in interval notation. If the endpoint of the interval isn’t included in the solution (for < or >), the interval is called an open interval. You show it on the graph with an open circle at the point and by using parentheses in notation. If the endpoint is included in the solution (for or ) the interval is called a closed interval, which you show on the graph with a filled-in circle at the point and by using square brackets in notation.
For example, the solution set -2 < x ≤ 3, rewrite this solution set as an and statement: -2 < x AND x ≤ 3. In interval notation, you write this solution as (–2, 3].


BEST!
SlideRule
..And in 50g plot etc..

Y1(X)=(Your function)*(0≤X)*(9>X)

(0≤X)*(9>X) Boolean AND

If X is less than zero and is less than 9 then 0*0=0
If X is more than zero but is less than 9 then 1*1=1
If X is more than zero and is more than or equal of 9 then 1*0=0

PS. (–2, 3] So utterly ugly !!
(04-28-2017 09:23 PM)pier4r Wrote: [ -> ]
(04-28-2017 01:56 PM)StephenG1CMZ Wrote: [ -> ]Alternatively, is there a different way of writing such an interval concisely, yet making which is included/excluded clearer.

To emphasize the equal.

Code:

if ( (a < 0 and a < 9) or (a == 0) ) {
  //this avoid the subtle <= that may be overlooked more easily than an extended condition. 
  //Code maintenance is more important than performance most of the time. Brain time is more precious than CPU time.
  ...code...
}

I can see that that would be less easy to skip over or mistype than "=".

I can imagine times when being able to copy the (0,9] syntax in a spec into the code would make it clearer that the code limits match the spec. On the other hand when implementing and debugging the code, the <= syntax or your separate < and = make it clearer what the code is doing (when (0,9] is used infrequently).
Reference URL's