Add <*> to the list of parseable operators

101 views
Skip to first unread message

Stas Versilov

unread,
May 17, 2018, 5:10:02 AM5/17/18
to elixir-lang-core
Hello!

I'am developing a matrix manipulation library for Elixir (https://github.com/versilov/matrex)
and it would be really nice to have <*> operator, so that it could be overriden for matrices dot product (or element-wise multiplication).

Is it possible to add it?

José Valim

unread,
May 17, 2018, 5:24:28 AM5/17/18
to elixir-l...@googlegroups.com
Hi Stas,

Given that we already have <|>, I don't see a problem with adding <*>. My only question is why choose dot product to have an operator? Wouldn't matrex end-up requiring other operators anyway? If we add <*>, how would those other operators look like in terms of consistency?



José Valim
Founder and 
Director of R&D

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/b7f939f4-50a1-49f7-bcc6-c82405c1eb33%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stas Versilov

unread,
May 17, 2018, 6:42:21 AM5/17/18
to elixir-lang-core
The problem is that other math operators used on matrices are only in element-wise form (+, -, /, *), so, usual math operators are enough for this.
But multiplication can be element-wise or dot-product, hence, we need two separate operators.

I saw Swift guys using <*> for dot-product, seemed like a good choice for me.




On Thursday, May 17, 2018 at 1:24:28 PM UTC+4, José Valim wrote:
Hi Stas,

Given that we already have <|>, I don't see a problem with adding <*>. My only question is why choose dot product to have an operator? Wouldn't matrex end-up requiring other operators anyway? If we add <*>, how would those other operators look like in terms of consistency?



José Valim
Founder and 
Director of R&D

On Thu, May 17, 2018 at 11:10 AM, Stas Versilov <stas.v...@gmail.com> wrote:
Hello!

I'am developing a matrix manipulation library for Elixir (https://github.com/versilov/matrex)
and it would be really nice to have <*> operator, so that it could be overriden for matrices dot product (or element-wise multiplication).

Is it possible to add it?

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.

José Valim

unread,
May 17, 2018, 6:52:36 AM5/17/18
to elixir-l...@googlegroups.com
Thanks for the clarification.

Let's go ahead and add <*>. Regardless of this use case, I think it fits the current set of custom operators.



José Valim
Founder and 
Director of R&D

To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/8cebaaeb-fe12-4601-a3ac-5af683304fc2%40googlegroups.com.

Stas Versilov

unread,
May 17, 2018, 6:57:23 AM5/17/18
to elixir-lang-core
Many thanks!

Should I open an issue on GitHub or something?

Michał Muskała

unread,
May 17, 2018, 7:04:50 AM5/17/18
to elixir-l...@googlegroups.com
I wonder if it would make sense to have a whole suite of <_> wrapped math operators. I could imagine, for example, the Decimal library implementing them and you could import to the decimal calculations easily without sacrificing the regular math operators.

Michał.

José Valim

unread,
May 17, 2018, 7:13:39 AM5/17/18
to elixir-l...@googlegroups.com
Michał, I think the issue with your proposed approach is precedence. <+> and <*> need to have different precedences and where should we put those operators compared to all others?



José Valim
Founder and 
Director of R&D

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.

Michał Muskała

unread,
May 17, 2018, 7:26:55 AM5/17/18
to elixir-l...@googlegroups.com
On 17 May 2018, 13:13 +0200, José Valim <jose....@gmail.com>, wrote:

Michał, I think the issue with your proposed approach is precedence. <+> and <*> need to have different precedences and where should we put those operators compared to all others?
 


That's a good point. What if we put them at the same level as the regular operators? Would that work?

Michał.

José Valim

unread,
May 17, 2018, 7:37:25 AM5/17/18
to elixir-l...@googlegroups.com
It would but it is worth saying we are adding a new rule that we don't have right now. Today all custom operators currently have the same precedence:


José Valim
Founder and 
Director of R&D

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.

Stas Versilov

unread,
May 17, 2018, 8:27:16 AM5/17/18
to elixir-lang-core
For my application (and for Decimal also) the same precedence as traditional math would be the key success factor of the new operators.

Lower precedence (as now for custom operators) would be counter-intuitive, cause hardly detectable errors in calculations
and lead to excessive use of brackets, because a <+> b<*>c (or a + b<*>c, as in my case) would actually work like (a + b)<*>c, not like a + (b<*>c)
as one would expect by default.


On Thursday, May 17, 2018 at 3:37:25 PM UTC+4, José Valim wrote:
It would but it is worth saying we are adding a new rule that we don't have right now. Today all custom operators currently have the same precedence:


José Valim
Founder and 
Director of R&D

On Thu, May 17, 2018 at 1:26 PM, Michał Muskała <mic...@muskala.eu> wrote:
On 17 May 2018, 13:13 +0200, José Valim <jose....@gmail.com>, wrote:

Michał, I think the issue with your proposed approach is precedence. <+> and <*> need to have different precedences and where should we put those operators compared to all others?
 


That's a good point. What if we put them at the same level as the regular operators? Would that work?

Michał.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.

José Valim

unread,
May 17, 2018, 8:29:57 AM5/17/18
to elixir-l...@googlegroups.com
Let's go with this proposal then: <+>, <->, <*> and </> with the same precedence as the math equivalents.



José Valim
Founder and 
Director of R&D

To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/f3fcbbbb-0f0f-40d8-8b8d-3b87107962ec%40googlegroups.com.

Michał Muskała

unread,
May 17, 2018, 8:40:54 AM5/17/18
to elixir-l...@googlegroups.com
On 17 May 2018, 14:29 +0200, José Valim <jose....@gmail.com>, wrote:

Let's go with this proposal then: <+>, <->, <*> and </> with the same precedence as the math equivalents.
 

I believe this might not be enough for the matrix library, because it would need to multiplications - for dot product and cross product. I think it planned to use regular * for dot product and <*> for cross product (or the reverse). But now the plan is to drop "raw" * and use <*> instead, this leaves the other product operator not accounted for. Should we go for something like <@> or maybe <x> for the other product operator?

Michał.

Stas Versilov

unread,
May 17, 2018, 9:12:46 AM5/17/18
to elixir-lang-core
I planned to use "raw" +,-,/ and * for element-wise operations and <*> for dot product. But yes, it's always nice to have some options like <@>, as Michal suggests.
It could also be great to have ./ and .* for element-wize, like in MathLab/Octave, but this syntactic sugar is not worth the confusion it will bring into the language, I believe.

Łukasz Niemier

unread,
May 31, 2018, 5:56:47 AM5/31/18
to elixir-lang-core
I would say that all <_> operators should have the same precedence, if someone want to change that there are always () operators for them to use.
Reply all
Reply to author
Forward
0 new messages