{"action":"created","issue":{"url":"https://api.github.com/repos/rust-num/num-complex/issues/2","repository_url":"https://api.github.com/repos/rust-num/num-complex","labels_url":"https://api.github.com/repos/rust-num/num-complex/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/rust-num/num-complex/issues/2/comments","events_url":"https://api.github.com/repos/rust-num/num-complex/issues/2/events","html_url":"https://github.com/rust-num/num-complex/issues/2","id":283344249,"number":2,"title":"Need common trait for floating and complex numbers","user":{"login":"cuviper","id":36186,"avatar_url":"https://avatars1.githubusercontent.com/u/36186?v=4","gravatar_id":"","url":"https://api.github.com/users/cuviper","html_url":"https://github.com/cuviper","followers_url":"https://api.github.com/users/cuviper/followers","following_url":"https://api.github.com/users/cuviper/following{/other_user}","gists_url":"https://api.github.com/users/cuviper/gists{/gist_id}","starred_url":"https://api.github.com/users/cuviper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cuviper/subscriptions","organizations_url":"https://api.github.com/users/cuviper/orgs","repos_url":"https://api.github.com/users/cuviper/repos","events_url":"https://api.github.com/users/cuviper/events{/privacy}","received_events_url":"https://api.github.com/users/cuviper/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2017-12-19T19:32:22Z","updated_at":"2017-12-19T19:32:25Z","closed_at":null,"author_association":"OWNER","body":"_From @carrutstick on July 18, 2017 23:14_\n\nThis issue in in the vein of issue #209, but a bit more ambitious; hopefully I am not too far out of scope for this project.\r\n\r\nAny mathematical function that accepts a real number can technically also accept a complex number, but currently there is no trait we can use to define a function that is generic over real and complex numbers (unless I'm missing something). \r\n\r\nI see two possible solutions:\r\n1. Shoehorn complex numbers into the existing `Float` trait (minimal work)\r\n2. Refactor the float trait so that we separate the parts that refer to mathematical objects (the trig functions, for instance) from the parts that assume specific types of implementation (`min_value()`, `max()`, etc.).\r\n\r\nOption 1\r\n-----------\r\n\r\nCertain functions in the `Float` trait may be ambiguous for complex numbers, such as the `min_value()` function. Broadly, there are three classes of functions in the trait:\r\n\r\n1. `|Self| -> Self`\r\n2. `|| -> Self`\r\n3. `|Self| -> bool`\r\n\r\nObviously the trigonometric functions of class 1 are not ambiguous (once we pick a branch cut), but functions like `floor()` and `frac()` are less obvious. I think a good rule of thumb for such functions is to have them apply independently to each part of the complex number, so that\r\n```\r\nComplex::new(x, y).floor() == Complex::new(x.floor(), y.floor())\r\n```\r\n\r\nFor class 2, I'm much less certain, but I think that these should generally produce values that are mathematically equivalent to their real counterparts, so that\r\n```\r\nComplex<F>::min_value() == Complex<F>::new(F::MIN, F::zero())\r\nComplex<F>::infinity() == Complex<F>::new(F::infinity(), F::zero())\r\n```\r\n\r\nFor class 3 I don't think there's a good rule of thumb, and we would probably need to invent rules on a case-by-case basis. For instance, we would probably want a complex number to have `is_nan() == true` if either part was `nan`, but what if the other part is infinite? Do we also have `is_infinite() == true`? Or do we decide that something that is `nan` cannot be infinite?\r\n\r\nThere is also the special case of the `min` and `max` functions. I think the only consistent way to handle these is to just have them act on the real line, like class 2.\r\n\r\nOption 2\r\n-----------\r\n\r\nMaybe someone who knows more abstract algebra than me can come up with better names, but we could have traits similar to Haskell's system, where [`RealFloat`](https://hackage.haskell.org/package/base-4.9.1.0/docs/Prelude.html#t:RealFloat) describes any kind of binary floating point number, whereas [`Floating`](https://hackage.haskell.org/package/base-4.9.1.0/docs/Numeric.html#t:Floating) is a more abstract description of any object suitable for use with trigonometric functions, etc. (this would include complex numbers, auto-differentiation primitives, diagonalizable matrices, etc.)\r\n\r\nObviously this option would be more work, and would result in at least a few breaking changes, but it would also be great to have the ability to program more generically with mathematical objects.\n\n_Copied from original issue: rust-num/num#321_"},"comment":{"url":"https://api.github.com/repos/rust-num/num-complex/issues/comments/352862785","html_url":"https://github.com/rust-num/num-complex/issues/2#issuecomment-352862785","issue_url":"https://api.github.com/repos/rust-num/num-complex/issues/2","id":352862785,"user":{"login":"cuviper","id":36186,"avatar_url":"https://avatars1.githubusercontent.com/u/36186?v=4","gravatar_id":"","url":"https://api.github.com/users/cuviper","html_url":"https://github.com/cuviper","followers_url":"https://api.github.com/users/cuviper/followers","following_url":"https://api.github.com/users/cuviper/following{/other_user}","gists_url":"https://api.github.com/users/cuviper/gists{/gist_id}","starred_url":"https://api.github.com/users/cuviper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cuviper/subscriptions","organizations_url":"https://api.github.com/users/cuviper/orgs","repos_url":"https://api.github.com/users/cuviper/repos","events_url":"https://api.github.com/users/cuviper/events{/privacy}","received_events_url":"https://api.github.com/users/cuviper/received_events","type":"User","site_admin":false},"created_at":"2017-12-19T19:32:25Z","updated_at":"2017-12-19T19:32:25Z","author_association":"OWNER","body":"_From @carrutstick on August 10, 2017 14:50_\n\n@Libbum, the problem with that is that `partial_cmp` needs to return one of `Less`, `Greater`, or `Equal`, and the `Equal` result is inappropriate for two complex numbers that just happen to have the same `norm`. Maybe it would be better to just have the comparison return `None` in a large set of cases (such as when the `norm` is equal, but the numbers are not), but I am worried that this would lead to a lot of unexpected errors."}}
{"actor":{"display_login":"cuviper"}}