The symbols() function is designed to be a convenience function to
make it easy to define many symbols at once. Since an empty symbol is
not something virtually anyone would want to make, it is disallowed.
Something like symbols('a,,b') is more likely to be a typo than
intentional.

However, you can still create symbols manually using the Symbol
constructor. Symbol itself allows any string at all, including the
empty string or strings containing unicode characters.

The empty string does work, although you're likely to run into
printing problems if you use it. For example, you can see that latex()
generates invalid latex because it assumes the symbol name is not
empty.

>>> Symbol("")

>>> srepr(Symbol(""))
"Symbol('')"
>>> latex(Symbol("")**2)
'^{2}'

This is sort of a "bug", but honestly not a very important one. The
printers mostly just assume symbol names are legal names for whatever
language they print to without actually checking.

I'm afraid I am not really following your suggestion about ~ or
spaces. In general, I would avoid using spaces or strange characters
in symbol names, as it would be unexpected and could potentially break
things like the latex printer, but like I said, Symbol itself does not
prevent you from putting any string you want.

Aaron Meurer

On Thu, Mar 31, 2022 at 3:08 AM Kuldeep Borkar
<[email protected]> wrote:
>
> While looking at `test_symbol.py` I saw these things:
> raise ValueError for the following:
> ```
> >>> symbols('')
> >>> symbols(',')
> >>> symbols('x,,y,,z')
> >>> symbols(('x', '',  '', 'z'))
> ```
> From the first one i.e. `symbols('')` I realized an empty or say invisible 
> symbol can't be created and then I tried with different `str` in `symbols` 
> then I saw few things:
>
> 1) When we use this `~` in symbols we can see that an invisible `Symbol` is 
> created.
> Then I tried with emoji's if the same thing happens or not.
>
> 2) Emoji's can be created as a symbol like:
> ```
> >>> symbols("😀")
> ```
> And we would be able to see emoji's in the output but,
>
>
> --> I don't know if the same thing (like `~`) happens for something else as 
> well but my point is :
>
> i) Should this thing i.e. Creating an empty/invisible `Symbol` even exist in 
> `Sympy` or we should similarly raise a value error if user uses  this `~`.
>
> ii) Should this be used as a feature and be included in the documentation, 
> say to provide some empty spaces between symbols like
> ```
> >>> from sympy import *
> >>> a, b = symbols("~a, ~b")
> >>> c, d = symbols("c, d")
> >>> print(b**a) #This will provide spaces.
> >>> print(d**c) #This won't provide spaces.
> ```
> Also, I was first opening an issue for this but I don't think that would be 
> the right place to talk about this thing was I correct?
>
> (I know it would be rare for a user using a symbol like this ~ even I saw 
> this thing when I was looking if I could write/improve some test cases for a 
> file and specifically how to write some good test cases in SymPy to start 
> adding some code in my contributions now.)
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/b76513c2-20bd-4714-b379-6a23dadfb0b7n%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6LATHRqwxRY9wPYpXPFduap_PDpZs_vExNyzpuVtk_o2A%40mail.gmail.com.

Reply via email to