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

Supporting Set operations and comprehensions #56

Closed
Takashiidobe opened this issue Oct 20, 2022 · 3 comments
Closed

Supporting Set operations and comprehensions #56

Takashiidobe opened this issue Oct 20, 2022 · 3 comments
Assignees
Labels
Milestone

Comments

@Takashiidobe
Copy link

Takashiidobe commented Oct 20, 2022

It would be nice to support some more set operations and comprehensions, since they're pretty easy to use in python. (I assume this is going to be fairly difficult though, since it requires a fair amount of information from the python ast)

For example, this code:

@latexify.with_latex
def solve():
    return {x ** 2 for x in range(1, 10)}

Returns this currently:

\displaystyle \mathrm{solve}() \triangleq <ast.SetComp object at 0x7f6920238160>

It would be nice to show something like this:

\displaystyle \mathrm{solve}() \triangleq \{x\mid x^2\in\Bbb \(1..10\)\}

$$ \displaystyle \mathrm{solve}() \triangleq {x\mid x^2\in\Bbb (1..10)} $$

And operations on sets:

@latexify.with_latex
def solve(x: set, y: set):
    return x | y
    

Returns this currently:

\displaystyle \mathrm{solve}(x, y) \triangleq \mathrm{unknown\_binop}(x, y)

It could be something like this:

\displaystyle \mathrm{solve}(x, y) \triangleq x \cup y

$$ \displaystyle \mathrm{solve}(x, y) \triangleq x \cup y $$

in and not in could also be supported, like x in A or x not in A like this:

x\in A, x\notin A

$$ \displaystyle \mathrm{solve}() \triangleq x\in A $$

$$ \displaystyle \mathrm{solve}() \triangleq x\notin A $$

@Takashiidobe Takashiidobe changed the title Supporting List and Set operations Supporting Set operations and comprehensions Oct 20, 2022
@odashi odashi added this to the v0.2 milestone Oct 20, 2022
@odashi
Copy link
Collaborator

odashi commented Oct 21, 2022

Tahnks! I think this is reasonable proposal.

To clarify, this includes 3 distinct features as follows:

We need to take care about the second case because set operations shares the same syntax with bit operations and it is not essentially distinguishable by the syntax tree. We may need something like:

  • Add argument to tell which set/bit operations are preferred
  • Rely on typing information (this is stretchy, not applicable for now)

@odashi
Copy link
Collaborator

odashi commented Nov 8, 2022

I will work on this issue this week. As for comprehension, we can support it similarly to that of sum/prod operations. Since binary/set operations are not trivial to distinguish, it may be good to provide a flag to switch these operators by users.

@odashi
Copy link
Collaborator

odashi commented Nov 14, 2022

All are now supported. Since it is hard to disambiguate set/bit operations, it is now controlled by a flag.

@odashi odashi closed this as completed Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants