Skip to content
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

Infix operators #10

Closed
tkf opened this issue Nov 26, 2018 · 10 comments
Closed

Infix operators #10

tkf opened this issue Nov 26, 2018 · 10 comments

Comments

@tkf
Copy link
Member

tkf commented Nov 26, 2018

As briefly discussed in #8 (comment), it'd be nice to have some infix operator for Mul and Add.

FYI here is the list of infix operators with plus and time precedence (from https://github.com/JuliaLang/julia/blob/master/src/julia-parser.scm):

(define prec-plus (append! '($) (add-dots '(+ - |\|| ⊕ ⊖ ⊞ ⊟ |++| ∪ ∨ ⊔ ± ∓ ∔ ∸ ≏ ⊎ ⊻ ⊽ ⋎ ⋓ ⧺ ⧻ ⨈ ⨢ ⨣ ⨤ ⨥ ⨦ ⨧ ⨨ ⨩ ⨪ ⨫ ⨬ ⨭ ⨮ ⨹ ⨺ ⩁ ⩂ ⩅ ⩊ ⩌ ⩏ ⩐ ⩒ ⩔ ⩖ ⩗ ⩛ ⩝ ⩡ ⩢ ⩣))))

(define prec-times (add-dots '(* / ÷ % & ⋅ ∘ × |\\| ∩ ∧ ⊗ ⊘ ⊙ ⊚ ⊛ ⊠ ⊡ ⊓ ∗ ∙ ∤ ⅋ ≀ ⊼ ⋄ ⋆ ⋇ ⋉ ⋊ ⋋ ⋌ ⋏ ⋒ ⟑ ⦸ ⦼ ⦾ ⦿ ⧶ ⧷ ⨇ ⨰ ⨱ ⨲ ⨳ ⨴ ⨵ ⨶ ⨷ ⨸ ⨻ ⨼ ⨽ ⩀ ⩃ ⩄ ⩋ ⩍ ⩎ ⩑ ⩓ ⩕ ⩘ ⩚ ⩜ ⩞ ⩟ ⩠ ⫛ ⊍ ▷ ⨝ ⟕ ⟖ ⟗)))

We can also add suffixes and combining characters JuliaLang/julia#22089

Some ideas:

  • *″ +″: Declare some common suffix to represent lazy version (e.g., double-prime ). It would be handy if we need more operators in the future (e.g, -″).

  • *ₗ +ₗ: Same idea but with a subscript l (or maybe superscript).

  • : Same idea but with combining character. It may be hard to recognize in some fonts.

  • : good for lazy multiplication, as it looks like * but sufficiently different to distinguish?

  • : good for lazy sum as it already has semantics of element wise sum (direct sum)? But this does not apply to Mul.

I think common suffix (like and ) is a good choice as it provides a uniform style and it is extensible.

@tkf
Copy link
Member Author

tkf commented Nov 26, 2018

Here is a snippet to show * and + with the combining characters

for c in '\u0300':'\u036f'
    print("*", c, " ", "+", c, " ")
end
println()

Output:

*̀ +̀ *́ +́ *̂ +̂ *̃ +̃ *̄ +̄ *̅ +̅ *̆ +̆ *̇ +̇ *̈ +̈ *̉ +̉ *̊ +̊ *̋ +̋ *̌ +̌ *̍ +̍ *̎ +̎ *̏ +̏ *̐ +̐ *̑ +̑ *̒ +̒ *̓ +̓ *̔ +̔ *̕ +̕ *̖ +̖ *̗ +̗ *̘ +̘ *̙ +̙ *̚ +̚ *̛ +̛ *̜ +̜ *̝ +̝ *̞ +̞ *̟ +̟ *̠ +̠ *̡ +̡ *̢ +̢ *̣ +̣ *̤ +̤ *̥ +̥ *̦ +̦ *̧ +̧ *̨ +̨ *̩ +̩ *̪ +̪ *̫ +̫ *̬ +̬ *̭ +̭ *̮ +̮ *̯ +̯ *̰ +̰ *̱ +̱ *̲ +̲ *̳ +̳ *̴ +̴ *̵ +̵ *̶ +̶ *̷ +̷ *̸ +̸ *̹ +̹ *̺ +̺ *̻ +̻ *̼ +̼ *̽ +̽ *̾ +̾ *̿ +̿ *̀ +̀ *́ +́ *͂ +͂ *̓ +̓ *̈́ +̈́ *ͅ +ͅ *͆ +͆ *͇ +͇ *͈ +͈ *͉ +͉ *͊ +͊ *͋ +͋ *͌ +͌ *͍ +͍ *͎ +͎ *͏ +͏ *͐ +͐ *͑ +͑ *͒ +͒ *͓ +͓ *͔ +͔ *͕ +͕ *͖ +͖ *͗ +͗ *͘ +͘ *͙ +͙ *͚ +͚ *͛ +͛ *͜ +͜ *͝ +͝ *͞ +͞ *͟ +͟ *͠ +͠ *͡ +͡ *͢ +͢ *ͣ +ͣ *ͤ +ͤ *ͥ +ͥ *ͦ +ͦ *ͧ +ͧ *ͨ +ͨ *ͩ +ͩ *ͪ +ͪ *ͫ +ͫ *ͬ +ͬ *ͭ +ͭ *ͮ +ͮ *ͯ +ͯ

Here is how it looks in my terminal (using UbuntuMono font in urxvt):

image

@tkf
Copy link
Member Author

tkf commented Nov 26, 2018

Here is how it is rendered in Emacs with DejaVu Sans Mono:

image

It looks like combining characters going below the symbol (e.g., *̰ +̰) are easier to recognize in general.

@dlfivefifty
Copy link
Member

Unfortunately the subscript l does not show up for me (in either Juno or REPL), so I think that's out, unless there's an easy fix.

I just added to mean rmaterialize(Mul(...)): that is, to force the materialize to go right-to-left. Though this syntax has not been tagged, so we can easily change that to, say, . I think at the moment I like best, but let me think a bit more.

@tkf
Copy link
Member Author

tkf commented Nov 26, 2018

Sadly, cannot be rendered in my environment (in browser, terminal and editor).

sounds good to me too, but I'd like to have a lazy addition API as well. How about ?

@tkf tkf mentioned this issue Nov 26, 2018
@dlfivefifty
Copy link
Member

I don't know about : it means direct sum and I think of it more of a a "block-diagonal" operation, and based on the definition you might expect (A ⊕ B) * (C ⊕ D) == (A*B) ⊕ (C*D), though I suppose if the group operation is + then its a different story.

Do we envision other lazy operations? If so, a sub/superscript may be the best. If only subscript l rendered for me!

@tkf
Copy link
Member Author

tkf commented Nov 26, 2018

Ah, I get what you are saying about . Yes, would be confusing.

Do we envision other lazy operations?

Point-wise subtraction could be useful to have.

If only subscript l rendered for me!

How about the superscript?:

@tkf
Copy link
Member Author

tkf commented Nov 26, 2018

Do we envision other lazy operations?

I think an important question here is if we want to have a lazy Hadamard/elementwise product because then we need two flavors of *. But I can't imagine the situation you'd need it.

@dlfivefifty
Copy link
Member

I think an important question here is if we want to have a lazy Hadamard/elem

Remember we always have the explicit broadcasted(*, A, B) and BroadcastArray(*, A, B) so the unicode are only needed for often used cases. I don't think lazy Hadamard is important enough to warrant a special syntax.

@tkf
Copy link
Member Author

tkf commented Nov 27, 2018

I just wanted to point out the naming system that just append a suffix is going to break if we want infix operator for the two flavors of multiplication. But I agree that's very unlikely.

@dlfivefifty
Copy link
Member

I think @~ has superseded this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants