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

Revise zero and define zerounit? #24853

Open
omus opened this issue Nov 29, 2017 · 13 comments
Open

Revise zero and define zerounit? #24853

omus opened this issue Nov 29, 2017 · 13 comments
Labels
kind:speculative Whether the change will be implemented is speculative

Comments

@omus
Copy link
Member

omus commented Nov 29, 2017

We may want to revise zero to match how one works. This would also mean we would need to create a zerounit.

julia> using Dates

julia> one(Minute)
1

julia> oneunit(Minute)
1 minute

julia> zero(Minute)
0 minutes

julia> zerounit(Minute)
ERROR: UndefVarError: zerounit not defined
@Sacha0
Copy link
Member

Sacha0 commented Nov 29, 2017

Related: #24595 :).

@fredrikekre
Copy link
Member

fredrikekre commented Nov 29, 2017

But zero should be the additive identity, so zero == zerounit, right? So (if anything) it is the zeronounit function that is missing.

@stevengj
Copy link
Member

stevengj commented Nov 30, 2017

You can always do zero(one(T)) if you want zero without units, but this is not an additive identity for T.

@Sacha0
Copy link
Member

Sacha0 commented Nov 30, 2017

The asymmetry and minor ambiguity in one/oneunit and ?/zero supports the symmetric pairs onemul/oneadd and zeromul/zeroadd discussed previously. No ambiguity or inconsistency of any kind there :). Best!

@omus
Copy link
Member Author

omus commented Nov 30, 2017

I was mainly noting the style inconsistency. My ideal world would have Dates.Minute(0) == 0 be true

@mschauer
Copy link
Contributor

(Partly summarising from slack:)

Note that one does not always exist when zero does, so zero(one(T)) is not a full solution. But a unitless zero cannot be multiplied or added to unitful quantities, so it is hard to come up with examples where this would be needed. After a long time I came up with the first situation where I actually did.
In this case to get a unitless white noise vector, which is to be scaled with a unitful scale. Because the scale carries a unit, the white noise vector, shouldn't. This could be conveniently written as randn!(zeronounit(x)). Perhaps the only case.

@mschauer
Copy link
Contributor

Post scriptum: I think this could be closed in favour of #22216

@stevengj
Copy link
Member

Note that one does not always exist when zero does, so zero(one(T)) is not a full solution.

But a "unitless" zero is only meaningful when you have multiplication, in which case you should have one, no?

@dalum
Copy link
Contributor

dalum commented Nov 1, 2018

This is not related to units, but from a purely abstract point of view:

  • zero(x) is the identity element under the operator +.
  • one(x) is the identity element under the operator *.
  • oneunit(x) is the generative element under the operator +.
  • zeronounit(x) would be the absorbing element under the operator *.

Assuming one(x) exists, zero(one(x)) would be synonymous with zeronounit(x). However, it is not at all inconceivable that an identity element under multiplication would not exist for an arbitrarily defined object, while the absorbing element would. For instance, numbers on the interval [0, 1) that only allow multiplication onto themselves.

I do not think zeronounit is a good name for the absorbing element, though.

@mschauer
Copy link
Contributor

mschauer commented Nov 1, 2018

I would differentiate that zeronounit may be an ugly name, but would be a good name in so far that this is the name different people came up independently when running into this.

@andreasnoack
Copy link
Member

Assuming one(x) exists, zero(one(x)) would be synonymous with zeronounit(x).

I don't think that theorem is true. Try with a Float64. hint The absorbing element for Float64s under * isn't 0.0.

@StefanKarpinski
Copy link
Sponsor Member

The absorbing element for Float64s under * isn't 0.0.

0.0 also isn't the additive identity for Float64, technically.

@goretkin
Copy link
Contributor

If I can ask a concrete-algebra question, what would you do with the absorbing element of a type? I can only imagine using it to multiply an instance of the type.

y = zeronounit(x) * x

but in that case you might as well just do

y = zero(x)

@brenhinkeller brenhinkeller added the kind:speculative Whether the change will be implemented is speculative label Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:speculative Whether the change will be implemented is speculative
Projects
None yet
Development

No branches or pull requests

10 participants