Hacker News new | ask | show | jobs
by contravariant 1759 days ago
I guess this is somewhat besides the point but checking if something can be multiplied by -1 is not great as a definition of subtraction. You'll typically want to use the additive inverse directly.

I mean sure you can extend any commutative group into a module over the integers but you probably don't want to make this a hard requirement just to have subtraction.

2 comments

Why would this be an issue? I'm under the impression that this is fine if we're operating with the standard addition operator and the standard field that everyone is used to working under. Isn't that the definition of the inverse? I understand that in different fields you have different operators but is that relevant here?
Random example: In geometry code, you might distinguish between points and vectors, where point + vector = point, point - point = vector etc.

It can then also be convenient to have a special type/value Origin, which (while functionally identical to point(0, 0)) allows you to e.g. write vector = point - origin to clearly express your intent of turning a vector into a point.

-1 * origin is not meaningful, but point - origin is (while point + origin is not).

But in this case I don't think you're working on the standard field. I mean you're working in different coordinates. I do understand that the example only works in R1 space with standard addition, but that's kinda the point of my question. That the "error" isn't really an error unless you're being pretty pedantic.
If you were working with the standard field then why would you need to bother defining the general concept of subtraction?

If you want to define the concept of subtraction then you probably don't want to assume you can multiply elements with an integer. Not that it can't be done but in general it will be a lot easier to define the additive inverse directly (if one exists).

I mean but under the example that the author is doing they are working with standard integers (integrals). So this appears to me to still be the standard addition and subtraction. And with standard R1 subtraction it is the same as inverse of addition.

I mean if we move into different coordinates and different fields, then yeah things change, but I don't see what the issue is with the example given here.

This is correct. The expression tested in the concept definition should not be "-1*x", but "x-x".