Any languages able to program (0,1] mathematical interval
04-28-2017, 01:56 PM (This post was last modified: 04-28-2017 08:18 PM by StephenG1CMZ.)
Post: #1
 StephenG1CMZ Senior Member Posts: 999 Joined: May 2015
Any languages able to program (0,1] mathematical interval
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.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
04-28-2017, 03:48 PM
Post: #2
 Gerson W. Barbosa Senior Member Posts: 1,537 Joined: Dec 2013
RE: Any languages able to program (0,1] mathematical interval
(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, 04:54 PM (This post was last modified: 04-28-2017 05:00 PM by Gerson W. Barbosa.)
Post: #3
 Gerson W. Barbosa Senior Member Posts: 1,537 Joined: Dec 2013
RE: Any languages able to program (0,1] mathematical interval
(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, 08:16 PM
Post: #4
 StephenG1CMZ Senior Member Posts: 999 Joined: May 2015
RE: Any languages able to program (0,1] mathematical interval
(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 <=

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
04-28-2017, 08:28 PM
Post: #5
 Gerson W. Barbosa Senior Member Posts: 1,537 Joined: Dec 2013
RE: Any languages able to program (0,1] mathematical interval
(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, 09:23 PM (This post was last modified: 04-29-2017 08:50 PM by pier4r.)
Post: #6
 pier4r Senior Member Posts: 2,245 Joined: Nov 2014
RE: Any languages able to program (0,1] mathematical interval
(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... }

Wikis are great, Contribute :)
04-28-2017, 10:03 PM
Post: #7
 nsg Member Posts: 60 Joined: Dec 2013
RE: Any languages able to program (0,1] mathematical interval
(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.
04-28-2017, 10:04 PM (This post was last modified: 04-30-2017 12:24 PM by SlideRule.)
Post: #8
 SlideRule Senior Member Posts: 1,386 Joined: Dec 2013
RE: Any languages able to program (0,1] mathematical interval
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
04-28-2017, 10:11 PM (This post was last modified: 04-28-2017 10:23 PM by Vtile.)
Post: #9
 Vtile Senior Member Posts: 406 Joined: Oct 2015
RE: Any languages able to program (0,1] mathematical interval
..And in 50g plot etc..

(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-29-2017, 07:29 PM
Post: #10
 StephenG1CMZ Senior Member Posts: 999 Joined: May 2015
RE: Any languages able to program (0,1] mathematical interval
(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).

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)