Asciimath-related mathjs expression extension proposals #3364
Replies: 3 comments
-
Here's another proposal sufficiently different from the table above that I thought I should give it a separate entry: consider adopting some form of Civet unary function shorthand. This needs a special character to stand for that argument. Civet uses &, so if bitwise AND were tripled, that would be available to match. Even if not, $ is also available. The gist of the idea is that an expression like If more easy ways to write functions are desired, Civet also has a concept of a placeholder character that makes a function call into a shorthand for a new function. Say for mathjs bare The difference between the unary function shorthand and the placeholder notation is that the unary function shorthand is stopped/contained by a function call, whereas the placeholder incorporates the first enclosing function call into the definition of the function it generates, and it can only occur inside a function call. To summarize this with examples say the unary function shorthand symbol is & and the placeholder is $. Then |
Beta Was this translation helpful? Give feedback.
-
Here's another one, from the discussion in #3374: |
Beta Was this translation helpful? Give feedback.
-
A comment in the function |
Beta Was this translation helpful? Give feedback.
-
By now there is a fairly well established Asciimath convention for representing mathematical typography (not exactly mathematical calculation) that would suggest some further additions/features to the mathjs expression language, not to mention quite a few issues/discussions over the years for such features. So I am creating this discussion to collect such proposals that rely only on the 7-bit ASCII character set (I will create another discussion for Unicode extensions to the mathjs expression language). This can be used to survey the possibilities and hopefully at some point select those worthy of implementation and decide against others.
P => Q <=> R
P implies Q
if_and_only_if R
<=>
on boolean values would be identical to==
. Also if we want a simplified notation for anonymous functions (e.g., to use inmap
) one attractive option would bex => x+1
ala JavaScript; on the other hand, the more AsciiMath consistent notation for that would bex |-> x+1
. Otherwise a perfectly sensible proposal.$
r /_ theta
r*(cos(theta) + i*sin(theta))
x && y || z
x and y or z
|x|
abs(x)
a|b
being bitwise OR, and even without, is|a|b|c|
parsed asabs(a)*b*abs(c)
orabs(a * abs(b) *c)
-- those are semantically quite different? I see two options for making this parseable: (A) Only interpret|
with whitespace or string boundary immediately adjacent on exactly one side as an absolute value bar; if the whitespace or string start is on the left, then it is an "open absolute" and if whitespace or string end is on the right, it is a "close absolute". Thus the ambiguous expression above would be disambiguated as either|a| b |c|
or|a |b| c|
. All other|
(with whitespace on both sides or neither) would be bitwise OR. Another option here would be to disallow|
without any adjacent whitespace or string boundary, so bitwise OR must be set off by whitespace on both sides. (B) Follow F# and use|||
for bitwise OR (since it is infrequently used), freeing up|
for absolute value. That change would still leave|a|b|c|
ambiguous, so either a whitespace-based rule would be needed, or simply adopt the rule that absolute values always close as soon as possible. In other words, this expression would be disambiguated asabs(a)*b*abs(c)
, so if you want the other interpretation you must add parens:|(a|b|c)|
. --- With|
so common in mathematical notation and bitwise OR a relatively uncommonly-used operation, I would recommend serious consideration of one of these proposals or some other parseable scheme along these lines. Personally I like (B). Note also that in (B) bitwise AND is presumably&&&
, potentially freeing single&
for another worthwhile use.||v||
norm(v)
||a||b||c||
ambiguity. If the final call is that single|
must be kept as bitwise OR, I think this option (C) becomes my favorite.sum_(i=1)^5 i^2
sum(range(1,5)
.map(_(i)=i^2)
prod_(i=1)^5 i^2
product(range(1,5)
.map(_(i)=i^2)
x ?? y
a ++ b
or maybea .+ b
ora && b
concat(a, b)
add
was removed.a += x
anda *= x
etc.a = a + x
ora = a*x
etc.-=
instance of this pattern is nearly in conflict with the belowis congruent to
meaning from AsciiMath, but perhaps the presence or absence of the(mod m)
part disambiguates sufficiently, because if you meant that you wanted to subtract the remainder of y mod m from x you would writex -= y % m
and if you meant that you wanted to subtract y from x and reduce the result mod m, you could writex = (x - y) % m
, or possibly we could allow(x -= y) %= m
, and I really don't know what else you would write for this. So I think that leaves things clear for the(mod m)
suffix to mean that the preceding-=
is the logical operator of congruence, not a mutating assignment operator, if we want to maximize AsciiMath consistency.x -= y (mod m)
(x - y) % m == 0
|_ x _|
floor(x)
|~x~|
ceil(x)
|
being bitwise OR and~
being bitwise not: you would need to disambiguatew|~x|~y~|
betweenw * ceil(bitwiseOr(x, bitwiseNot(y)))
andbitwiseOr(w, bitwiseNot(x)*ceil(y))
. Maybe as ceiling is a significantly less-used function than floor and~
is not that high up in a lot of fonts, so this doesn't really look like a ceiling bracket, better to just skip this one.|-x-|
round(x)
ceil
is not implemented, I would definitely not recommend adding this new thing. On the other hand, if bitwise OR is tripled, then all of these|
digraphs become much easier to parse.x |-> x+1
_(x) = x+1
f'(x)
derivative(f, x)
'
is also allowed for string quotes, and used for the conjugate transpose of a matrix. Maybe this would make it just too overloaded?a uu b nn c
setUnion(a, setIntersect(b))
a /_\ b
setSymDifference(a, b)
v o. w
dotMultiply(v,w)
.
object accessor notation, because otherwise this would be ambiguous withv * o.w
. But I would actually be fine with that, as I findobj. key
to be pretty unreadable (and conversely if there is going to be whitespace there,obj .key
to be much better). But it would be a breaking change.v xx w
cross(v, w)
A ox B
kron(A,B)
Please feel free to propose additional possibilities for this table or discuss any of the particular proposals above. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions