-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: cdot or ⋅ as a binary operator #3434
Comments
What would the precedence be? Maybe between |
Edit: This isn't a good solution because it also changes the behavior of |
I played around with this and it's pretty straightforward to add: diff --git a/M2/Macaulay2/d/actors5.d b/M2/Macaulay2/d/actors5.d
index fdde6bcd9a..821f671d57 100644
--- a/M2/Macaulay2/d/actors5.d
+++ b/M2/Macaulay2/d/actors5.d
@@ -198,6 +198,9 @@ setup(AmpersandS,ampersandfun);
hathatfun(lhs:Code,rhs:Code):Expr := binarymethod(lhs,rhs,HatHatS);
setup(HatHatS,hathatfun);
+interpunctfun(lhs:Code, rhs:Code):Expr := binarymethod(lhs, rhs, InterpunctS);
+setup(InterpunctS, interpunctfun);
+
Tildefun(rhs:Code):Expr := unarymethod(rhs,TildeS);
setuppostfix(TildeS,Tildefun);
diff --git a/M2/Macaulay2/d/binding.d b/M2/Macaulay2/d/binding.d
index a561f8249d..9640a02138 100644
--- a/M2/Macaulay2/d/binding.d
+++ b/M2/Macaulay2/d/binding.d
@@ -285,6 +285,8 @@ bumpPrecedence();
export MinusS := makeKeyword(unarybinaryleft("-")); -- also binary
export PlusS := makeKeyword(unarybinaryleft("+")); -- also binary
export PlusPlusS := makeKeyword(binaryleft("++"));
+bumpPrecedence();
+ export InterpunctS := makeKeyword(binaryleft("·"));
bumpPrecedence();
export StarStarS := makeKeyword(binaryleft("**"));
bumpPrecedence();
@@ -510,7 +512,8 @@ export opsWithBinaryMethod := array(SymbolClosure)(
PowerGreaterEqualS, UnderscoreGreaterEqualS,
PowerLessS, UnderscoreLessS,
PowerLessEqualS, UnderscoreLessEqualS,
- PowerStarStarS
+ PowerStarStarS,
+ InterpunctS
);
export opsWithUnaryMethod := array(SymbolClosure)(
StarS, MinusS, PlusS, LessLessS, QuestionQuestionS,
diff --git a/M2/Macaulay2/m2/exports.m2 b/M2/Macaulay2/m2/exports.m2
index c52ac919ae..c28facd05c 100644
--- a/M2/Macaulay2/m2/exports.m2
+++ b/M2/Macaulay2/m2/exports.m2
@@ -57,6 +57,7 @@ export {
"_>=",
"_<",
"_<=",
+ "·",
"Acknowledgement",
"AdditionalPaths",
"Adjacent", It seems to then work out of the box: i1 : Vector · Vector := (v, w) -> ((transpose v#0) * w#0)_(0, 0)
o1 = FunctionClosure[stdio:1:20-1:60]
o1 : FunctionClosure
i2 : vector {1,2,3} · vector {4, 5, 6}
o2 = 32 |
Fantastic! Is I think we should still add
This is a great tip! However, it opens a can of worms: should we consider supporting tex input by default? e.g. should |
Parsing without spaces doesn't work: i4 : v·w
o4 = v·w
o4 : Symbol But i6 : methods symbol ·
o6 = {0 => ((·, =), Type, Type) }
{1 => ((·, =), Thing, Thing)}
{2 => (·, Thing, Thing) }
{3 => (·, Vector, Vector) }
o6 : NumberedVerticalList
i7 : locate 3
o7 = stdio:1:20-1:60
o7 : FilePosition
i8 : code oo
o8 = stdio:1:20-1:60: --source code:
Vector · Vector := (v, w) -> ((transpose v#0) * w#0)_(0, 0) |
That's not what I meant, is this output the same if you replace + with cdot? i2 : peek locate (pseudocode functionBody(() -> 1 + 1))
o2 = FilePosition{stdio, 2, 45, 2, 58, 2, 51} |
It ends at column 59 instead of 58, so I'm guessing that's coming from the extra byte in the Unicode character. i2 : peek locate (pseudocode functionBody(() -> 1 · 1))
o2 = FilePosition{stdio, 2, 45, 2, 59, 2, 51} |
It would be ideal if we could get this to work, for instance i25 : A⊗B
stdio:25:0:(3): error: no method for binary operator ** applied to objects:
A (of class Symbol)
** B (of class Symbol) |
the reason |
Thanks! This is very helpful. Taking a brief look, is it not possible to add cdot as an exception? I don't think there are too many of them. |
why don't you use
|
Incidentally, if you want to see all characters starting with 226 (which contains a bunch of non mathematical symbols as well -- we could be more selective), try in the browser:
|
|
actually in your original post you used |
What difference does it make? |
|
In emacs, open M2 then enter i1 : ascii "·"
o1 = {194, 183} We want something that is easily usable. |
Currently we have a number of unicode synonyms defined in exports.m2. I think it would be useful to introduce the interpuct ($\cdot$ ) as a binary operator. This could be implemented as a synonym to a binary keyword
cdot
(similar toand
,or
, etc. but bound to a top-level method).However, it would even be more interesting if M2-mode (and other editors) could automatically convert$\cdot$ similar to, for instance, in agda-mode, and we could freely type
\cdot
toC⋅D
(without spaces) and have M2 recognize this.This would be pretty straightforward, mostly duplicating sections related to
and
in the interpreter, but there are two tricky things:⋅
as a keyword operator in the interpreter so thatC⋅D
works?The main applications for this is intersection product and of course dot product of vectors. If this goes well, I think replacing$\circ$ would be amazing!
@@
withcirc
andThe text was updated successfully, but these errors were encountered: