interval notation, was: Plot options foo=bar vs [foo, bar]
Subject: interval notation, was: Plot options foo=bar vs [foo, bar]
From: Robert Dodier
Date: Sat, 10 Jun 2006 10:17:36 -0600
On 6/9/06, Stavros Macrakis <macrakis at gmail.com> wrote:
> > How about x=a..b notation for interval?
>
>
> I've always liked that notation, used in several programming languages.
I might be in favor of this, but here are a couple of comments.
(1) Whatever we pick for interval notation in plotting should
also be acceptable as a general-purpose interval notation.
(2) a, ..., b in written math typically indicates a finite set.
Intervals are indicated by a variety of notations
[a, b], (a, b), (a, b], ]a, b[, which collide with established
uses of [ and ( in Maxima. Maybe it's better to make the
interval operator something like interval(a,b) or I(a,b)
or In(a,b) or intvl(a,b) instead of adopting a somewhat
misleading notation.
> Before we add it, though, we should probably fix the
> Maxima lexer/parser so that various cases are treated
> more intuitively:
>
> infix("..")$
>
> 0..2 => error, is treated as 0. followed by .2; should be 0 .. 2
> 0.. 2 => treated like 0. . 2; should be 0 .. 2
> 0...2 => treated like 0. .. 2, not 0 .. .2 (maybe OK)
Well, at present the Maxima lexer is easy to describe:
it is greedy. If we change the parser, we should adopt
a policy which is likewise simple.
FWIW I'm inclined to leaver the lexer as it stands.
> I would also recommend that we clarify the semantics of ".." before we put
> it out. I would suggest that a..b be defined as the set of all numbers x
> such that a<=x<=b. Thus, a..a == a and a..b where b<a == empty set.
>
> We might also want to define a ternary operator a..b..c meaning the set of
> all x=a+I*b (I a non-negative integer) such that a<=x<=c.
Agreed, we should settle this stuff.
These issues apply whatever syntax is adopted.
Another issue is how to indicated open and closed intervals.
An idea here is to make (open) and (closed) postfix operators.
Maxima seems to parse these OK. Here is a session.
(%i1) infix ("..");
(%o1) ..
(%i2) postfix ("(closed)");
(%o2) (closed)
(%i3) postfix ("(open)");
(%o3) (open)
(%i4) a .. b (closed);
(%o4) a .. b (closed)
(%i5) op (%);
(%o5) (closed)
(%i6) a .. b (open);
(%o6) a .. b (open)
(%i7) a..b(closed) + c..d(open);
(%o7) c .. d (open) + a .. b (closed)
(%i8) op (%);
(%o8) +
(%i9) F(a..b(closed),c..d(open));
(%o9) F(a .. b (closed), c .. d (open))
(%i10) (closed,open);
(%o10) open
(%i11) (open,closed);
(%o11) closed
FWIW
Robert