# Why Complex numbers only work with Real numbers and not all numbers?

**URL:** https://discourse.julialang.org/t/why-complex-numbers-only-work-with-real-numbers-and-not-all-numbers/81042
**Category:** New to Julia
**Tags:** numbers, complex-numbers
**Created:** [May 13, 2022, 10:06pm UTC](https://discourse.julialang.org/t/why-complex-numbers-only-work-with-real-numbers-and-not-all-numbers/81042 "2022-05-13T22:06:13Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![davidalencia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidalencia/32/35909_2.png) [@davidalencia](https://discourse.julialang.org/u/davidalencia)
#### Post date: [May 13, 2022, 10:06pm UTC](https://discourse.julialang.org/t/why-complex-numbers-only-work-with-real-numbers-and-not-all-numbers/81042/1 "2022-05-13T22:06:13Z")

</div>

If I try to instanstate a complex number with a type T \<: Number but not \<:Real returns not defined. Why isn’t defined for all numbers.,

---

<div class="post-metadata">

### Author: ![dylanxyz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dylanxyz/32/36646_2.png) [@dylanxyz](https://discourse.julialang.org/u/dylanxyz)
#### Post date: [May 13, 2022, 10:38pm UTC](https://discourse.julialang.org/t/why-complex-numbers-only-work-with-real-numbers-and-not-all-numbers/81042/2 "2022-05-13T22:38:36Z")

</div>

What exactly is the julia code you trying to execute?

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [May 14, 2022, 1:42am UTC](https://discourse.julialang.org/t/why-complex-numbers-only-work-with-real-numbers-and-not-all-numbers/81042/3 "2022-05-14T01:42:14Z")

</div>

Because it only makes mathematical sense with real components.

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [May 14, 2022, 1:46am UTC](https://discourse.julialang.org/t/why-complex-numbers-only-work-with-real-numbers-and-not-all-numbers/81042/4 "2022-05-14T01:46:47Z")

</div>

Technically, it would be kind of sensible to define `const Quaternian{T<:Real} = Complex{Complex{T}}`

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [May 14, 2022, 2:09am UTC](https://discourse.julialang.org/t/why-complex-numbers-only-work-with-real-numbers-and-not-all-numbers/81042/5 "2022-05-14T02:09:54Z")

</div>

That seems like it would require a lot of additional care but it could work. I’m also unclear on how that leads to non-commutativity.

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [May 14, 2022, 2:45am UTC](https://discourse.julialang.org/t/why-complex-numbers-only-work-with-real-numbers-and-not-all-numbers/81042/6 "2022-05-14T02:45:19Z")

</div>

Would that really make more sense to people than a single layer of 4 distinct `Real` fields? Personally, knowing nothing about quaternions, I would interpret `(3+1im) + (3+1im)im` as `3 + 1i + 3i + i^2 = 2 + 4i`, which is already how it’s parsed. Just easier to wrap my head around “2nd field in `Complex`” is `im` is `i` is imaginary axis and nothing else.

---

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [May 14, 2022, 5:47am UTC](https://discourse.julialang.org/t/why-complex-numbers-only-work-with-real-numbers-and-not-all-numbers/81042/7 "2022-05-14T05:47:19Z")

</div>

Given any ring it makes sense mathematically to adjoin an element i that squares to -1. However if you will never get quaternions this way, since adjoining i preserves commutativity.

---

<div class="post-metadata">

### Author: ![jcook](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcook/32/18211_2.png) [@jcook](https://discourse.julialang.org/u/jcook)
#### Post date: [May 14, 2022, 5:50am UTC](https://discourse.julialang.org/t/why-complex-numbers-only-work-with-real-numbers-and-not-all-numbers/81042/8 "2022-05-14T05:50:08Z")

</div>

I had a go at something like this and wrote [BiComplex.jl](https://github.com/jwscook/BiComplex.jl). I quite quickly found a work around for what I was trying to achieve (hence the terse readme) with it so stopped developing it.

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [May 14, 2022, 1:09pm UTC](https://discourse.julialang.org/t/why-complex-numbers-only-work-with-real-numbers-and-not-all-numbers/81042/9 "2022-05-14T13:09:26Z")

</div>

That was my thought too—there’s nothing that gives the anti-commutative behavior of the quaternions so it must be a different ring. Also unclear to me if it’s even a ring at all since I vaguely recall something about there not existing a commutative ring over the reals with four generators.

---

<div class="post-metadata">

### Author: ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)
#### Post date: [May 14, 2022, 1:48pm UTC](https://discourse.julialang.org/t/why-complex-numbers-only-work-with-real-numbers-and-not-all-numbers/81042/10 "2022-05-14T13:48:49Z")

</div>

To represent quaternions a + bi + cj + dk as complex of complex, you need I and J as distinct imaginaries, i.e. I^2 = -1, J^2 = -1, and letting IJ = -JI. Then do complex of complex like (a + bI) + (c + dI) J and associate i,j,k with I, J, IJ.

---

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [May 14, 2022, 10:17pm UTC](https://discourse.julialang.org/t/why-complex-numbers-only-work-with-real-numbers-and-not-all-numbers/81042/11 "2022-05-14T22:17:48Z")

</div>

> Also unclear to me if it’s even a ring at all since I vaguely recall something about there not existing a commutative ring over the reals with four generators.

Yes, there are multiple statements of the form there are not many nice rings slightly bigger than the reals. For instance, the complex numbers is the only finite dimensional field above the real numbers. And complex + quaternions are the only finite dimensional skew fields. There are many commutative rings that are finite dimensional over the reals, however. You can always adjoin elements that satisfy some polynomial relation and you always get a ring this way.

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [May 15, 2022, 3:08pm UTC](https://discourse.julialang.org/t/why-complex-numbers-only-work-with-real-numbers-and-not-all-numbers/81042/12 "2022-05-15T15:08:04Z")

</div>

Ah yes, that makes sense. So it’s likely a ring but not a field.
