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

Ban infinite dividends #69

Closed
oscbyspro opened this issue Aug 10, 2024 · 6 comments
Closed

Ban infinite dividends #69

oscbyspro opened this issue Aug 10, 2024 · 6 comments
Labels
subtraction huh? where did it go?

Comments

@oscbyspro
Copy link
Owner

Banning infinite dividends seems like the simplest solution to (#68). It would also mean that all safe division inputs are well-behaved. Infinite dividends would be banned by setting the type to Finite<T>. Imagine the following with some conveniences:

protocol BinaryInteger {
    static func division(_ dividend: Finite<Self>, by divisor: Nonzero<Self>) -> Fallible<Division<Self, Self>>
}
@oscbyspro oscbyspro added addition oh, so shiny! subtraction huh? where did it go? labels Aug 10, 2024
@oscbyspro
Copy link
Owner Author

oscbyspro commented Aug 10, 2024

Infinite-by-infinite division is well-behaved but also uninteresting; it's a conditional subtraction. I could add nicher constraints than Finite<T> and Natural<T> but I prefer to keep it simple ™️ to the extent that it is possible.

@oscbyspro
Copy link
Owner Author

oscbyspro commented Oct 11, 2024

I've prototyped a new approach using (#95). It seems a bit annoying to maintain, but otherwise viable. I could, perhaps, reduce it to just Optional<T> since the there's only one finite error case, T.isSigned && a == T.min && b == -1. I'm not yet convinced that taking such shortcuts is a good idea, however.

@oscbyspro
Copy link
Owner Author

I've had other ideas too. Like, I could strengthen the input guarantee such that only well-behaved divisions are allowed, basically hoisting all preconditions. That might be convoluted in another way, but I don't want to dismiss the idea just yet.

@oscbyspro
Copy link
Owner Author

oscbyspro commented Oct 11, 2024

I basically want the Fallible<T> part because of invariants like this:

I8(-128).quotient(Nonzero(-1)) == I8.exactly(IXL(-128) / IXL(-1))

Division is just a weird operation where almost all inputs are valid. Sigh.

@oscbyspro
Copy link
Owner Author

oscbyspro commented Oct 11, 2024

Back to the original post: divisions of infinite dividends are useless; a blanket ban is a viable alternative.

@oscbyspro
Copy link
Owner Author

oscbyspro commented Oct 20, 2024

I'll resolve this issue by tomorrow. The combinatorial maintenance hazard of implicit error propagation was the biggest blocker and it was resolves by moving on to the new sink approach (#116) (#117).

oscbyspro added a commit that referenced this issue Oct 21, 2024
This rewrite introduces safe division protocol requirements with proper division semantics. I'm sure these methods can be derived from unsafe requirements, but this is a good place to start. I'll may consider unsafe requirements if the overhead of safety cannot be optimized away. Something, something, sufficiently smart compiler.
@oscbyspro oscbyspro removed maybe to do, or not to do? addition oh, so shiny! labels Oct 21, 2024
@oscbyspro oscbyspro added this to the Ultimathnum 0.11.0 milestone Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
subtraction huh? where did it go?
Projects
None yet
Development

No branches or pull requests

1 participant