# Exponentiation (\`^\`) on a non-US keyboard

**URL:** <https://discourse.julialang.org/t/exponentiation-on-a-non-us-keyboard/69361>\
**Category:** General Usage\
**Created:** [October 7, 2021, 11:00am UTC](https://discourse.julialang.org/t/exponentiation-on-a-non-us-keyboard/69361 "2021-10-07T11:00:17Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![met-j](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/met-j/32/21919_2.png) [@met-j](https://discourse.julialang.org/u/met-j)\
**Post date:** [October 7, 2021, 11:00am UTC](https://discourse.julialang.org/t/exponentiation-on-a-non-us-keyboard/69361/1 "2021-10-07T11:00:17Z")

</div>

I am lost.  
What changed so the simple algebra like `2ˆ2` does not work anymore (Julia v1.6.3) in the REPL (on MacOS)?

And how would I draw the power of a int or a float?

I get

```julia
julia> 2ˆ2
ERROR: UndefVarError: ˆ2 not defined
Stacktrace:
 [1] top-level scope
   @ REPL[31]:1

```

And

```julia
julia> 2 ˆ 2
ERROR: syntax: extra token "ˆ" after end of expression
Stacktrace:
 [1] top-level scope
   @ none:1

```

And

```julia
2 ˆ2
ERROR: syntax: extra token "ˆ2" after end of expression
Stacktrace:
 [1] top-level scope
   @ none:1

```

and

```julia
julia> 2ˆ 2
ERROR: syntax: extra token "2" after end of expression
Stacktrace:
[1] top-level scope
@ none:1

```

and finally

```julia
julia>2.0ˆ2.0
ERROR: syntax: extra token "0.0" after end of expression
Stacktrace:
[1] top-level scope
@ none:1

```

Thanks for your shard of enlightment.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [October 7, 2021, 11:07am UTC](https://discourse.julialang.org/t/exponentiation-on-a-non-us-keyboard/69361/2 "2021-10-07T11:07:24Z")

</div>

You have probably copy/pasted the `ˆ` from somewhere, try this one:

```julia
2^2

```

or the single `^`.  
Copy/paste one of my suggestions.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [October 7, 2021, 11:10am UTC](https://discourse.julialang.org/t/exponentiation-on-a-non-us-keyboard/69361/3 "2021-10-07T11:10:06Z")

</div>

You are using “Modifier Letter Circumflex Accent” with code

```julia
julia> Char('ˆ')
'ˆ': Unicode U+02C6 (category Lm: Letter, modifier)

```

You need CIRCUMFLEX ACCENT

```julia
julia> Char('^')
'^': ASCII/Unicode U+005E (category Sk: Symbol, modifier)

```

(edited: using Char instead of UInt16, 👍 to @Palli )

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [October 7, 2021, 11:13am UTC](https://discourse.julialang.org/t/exponentiation-on-a-non-us-keyboard/69361/4 "2021-10-07T11:13:56Z")

</div>

It still may be a MacOS thing, so someone with that system may know better…

---

<div class="post-metadata">

**Author:** ![met-j](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/met-j/32/21919_2.png) [@met-j](https://discourse.julialang.org/u/met-j)\
**Post date:** [October 7, 2021, 11:17am UTC](https://discourse.julialang.org/t/exponentiation-on-a-non-us-keyboard/69361/5 "2021-10-07T11:17:53Z")

</div>

Phenomenal!  
It just had to be something like this.  
In fact, I am new to the Mac-keyboard and it is these small things that make doubt this path.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [October 7, 2021, 11:23am UTC](https://discourse.julialang.org/t/exponentiation-on-a-non-us-keyboard/69361/6 "2021-10-07T11:23:10Z")

</div>

> [@met-j](#):
>
> and it is these small things that make doubt this path.

Well, this can happen in every system,e.g. R REPL just the same:

```julia
> 2**2
[1] 4
> 2^2
[1] 4
> 2ˆ2
Fehler: unerwartete Eingabe in "2ˆ"

```

No doubts appropriate! Instead, delight is today’s feeling! 😉

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [October 7, 2021, 12:02pm UTC](https://discourse.julialang.org/t/exponentiation-on-a-non-us-keyboard/69361/7 "2021-10-07T12:02:21Z")

</div>

Or Python

```python
>>> 2**2
4
>>> 2^2
0
>>> 2ˆ2
  File "<stdin>", line 1
    2ˆ2
     ^
SyntaxError: invalid syntax

```

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [October 7, 2021, 12:14pm UTC](https://discourse.julialang.org/t/exponentiation-on-a-non-us-keyboard/69361/8 "2021-10-07T12:14:10Z")

</div>

> [@met-j](#):
>
> I am new to this system and it is these small things that make doubt this path.

I’m conflicted here. With the correct ASCII operator `^` this works, but Julia does provide Unicode options in many cases, and could also support `ˆ` “Modifier Letter Circumflex Accent” for this. I’m not sure what else it could mean usefully. Does anyone use it for anything else?

For me `^` is the most natural power operator and `**` just bad, that other languages like Python have.

Note, `^` is xor in other some other languages (e.g. C and Python, so can be a pitfall porting code), while Julia has `⊻` operator for it written \xor tab, or as a function xor(a, b). All operators in Julia are ASCII by default (often Unicode also) in Julia except that one, there the ASCII version is a function only.

---

<div class="post-metadata">

**Author:** ![met-j](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/met-j/32/21919_2.png) [@met-j](https://discourse.julialang.org/u/met-j)\
**Post date:** [October 7, 2021, 12:33pm UTC](https://discourse.julialang.org/t/exponentiation-on-a-non-us-keyboard/69361/9 "2021-10-07T12:33:58Z")

</div>

My main struggle is actually the MacBook keyboard where the ASCI tilde and ^ are _hidden_ from simple key strokes.  
My left pinky is just getting board while the others are starting emacs like yoga exercises without any emacs in sight.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [October 7, 2021, 12:44pm UTC](https://discourse.julialang.org/t/exponentiation-on-a-non-us-keyboard/69361/10 "2021-10-07T12:44:57Z")

</div>

If it’s not on the keyboard that seems like an argument for some workaround… If Julia does it allowing the other `ˆ` it makes for some slight visual distinction in code bases, why I’m conflicted. It’s most likely also a _technical_ breaking change. Maybe there’s some editor support available that maps it to `^`? You can’t be the first to run into this problem… Xor is a rarely used function, so `^` for it in Python and C isn’t a deal breaker, but `^` (for power) is very common so Julia must be easy. Possibly it could be a warning, and then only in the REPL.

---

<div class="post-metadata">

**Author:** ![met-j](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/met-j/32/21919_2.png) [@met-j](https://discourse.julialang.org/u/met-j)\
**Post date:** [October 8, 2021, 1:10pm UTC](https://discourse.julialang.org/t/exponentiation-on-a-non-us-keyboard/69361/11 "2021-10-08T13:10:58Z")

</div>

Resolved the twist!  
My keyboard was set to en-US international instead of just en-US.

[https://apple.stackexchange.com/questions/234352/how-do-i-input-instead-of-ˆ](https://apple.stackexchange.com/questions/234352/how-do-i-input-instead-of-%CB%86)

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 8, 2021, 2:22pm UTC](https://discourse.julialang.org/t/exponentiation-on-a-non-us-keyboard/69361/12 "2021-10-08T14:22:25Z")

</div>

2 posts were split to a new topic: [^ vs exp for exponentiation](https://discourse.julialang.org/t/vs-exp-for-exponentiation/69437)

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [October 8, 2021, 1:44pm UTC](https://discourse.julialang.org/t/exponentiation-on-a-non-us-keyboard/69361/13 "2021-10-08T13:44:08Z")

</div>

By the way, it’s quite easy to add your own REPL shortcuts, if there’s a particular character you need to type which isn’t in the REPL’s built-in tab completion dictionary:

For example, to have `\power` expand to `^`:

```julia
using REPL
REPL.REPLCompletions.latex_symbols["\\power"] = "\u005e"

```

![completions-1](https://global.discourse-cdn.com/julialang/original/3X/5/5/557a492bd4030303c3edd333450bb37dc40eb18d.gif)

Put it in your ~/.julia/config/startup.jl file to run it every time you start a REPL.

---

<div class="post-metadata">

**Author:** ![met-j](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/met-j/32/21919_2.png) [@met-j](https://discourse.julialang.org/u/met-j)\
**Post date:** [October 8, 2021, 1:55pm UTC](https://discourse.julialang.org/t/exponentiation-on-a-non-us-keyboard/69361/14 "2021-10-08T13:55:34Z")

</div>

neat trick.  
You would not have a table or list of Unicodes you would recommend, would you?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 8, 2021, 2:06pm UTC](https://discourse.julialang.org/t/exponentiation-on-a-non-us-keyboard/69361/15 "2021-10-08T14:06:26Z")

</div>

> [@met-j](#):
>
> My main struggle is actually the MacBook keyboard where the ASCI tilde and ^ are _hidden_ from simple key strokes.

😕 According to the images of current Mac laptops on Apple’s web site, these characters are where they always are on a US keyboard: at the upper left (with shift-```) for `~` and at shift-`6` for `^`:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/9/69fadbab5ee5776a855efe7fe9de6c9f552dbc91.png)

---

<div class="post-metadata">

**Author:** ![met-j](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/met-j/32/21919_2.png) [@met-j](https://discourse.julialang.org/u/met-j)\
**Post date:** [October 8, 2021, 2:17pm UTC](https://discourse.julialang.org/t/exponentiation-on-a-non-us-keyboard/69361/16 "2021-10-08T14:17:30Z")

</div>

Well, I in fact have a physical Swiss-German keyboard and was running the en-US international layout.  
Little did I know the en-US layout would be what I wanted and my fingers are used to.  
But that was a quick fix.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 8, 2021, 2:20pm UTC](https://discourse.julialang.org/t/exponentiation-on-a-non-us-keyboard/69361/18 "2021-10-08T14:20:36Z")

</div>

> [@Palli](#):
>
> Julia does provide Unicode options in many cases, and could also support `ˆ` “Modifier Letter Circumflex Accent” for this

No it could not. `ˆ` ([U+02C6](https://www.fileformat.info/info/unicode/char/02c6/index.htm)) is a modifier letter in Unicode ([category Lm](https://www.fileformat.info/info/unicode/category/Lm/list.htm)), and all modifier letters are allowed as part of identifiers in Julia ~~as long as they follow an ordinary letter~~. e.g. `xˆ2` is a valid identifier:

```julia
julia> xˆ2 = 16
16

julia> √xˆ2
4.0

```

Changing Julia to parse `ˆ` as a binary operator would therefore be a breaking change, and is hence technically disallowed in Julia 1.x.

(This is a weird case, so it’s not clear if anyone is actually _using_ U+02C6 for identifiers in real code, and maybe it could be argued as a “minor” change for Julia 1.x. On the other hand, the ordinary `^` is an ASCII character (U+005E), and it is reasonable to require that anyone programming in any modern programming language be capable of typing it.)

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 8, 2021, 2:36pm UTC](https://discourse.julialang.org/t/exponentiation-on-a-non-us-keyboard/69361/19 "2021-10-08T14:36:05Z")

</div>

> [@stevengj](#):
>
> all modifier letters are allowed as part of identifiers in Julia ~~as long as they follow an ordinary letter~~.

In fact, it doesn’t have to follow an ordinary letter:

```julia
julia> const ˆ2 = exp2
exp2 (generic function with 10 methods)

julia> ˆ2(16)
65536.0

```

This is also allowed in Python 3:

```julia
>>> xˆ2 = 16
>>> xˆ2
16
>>> from numpy import exp2 as ˆ2
>>> ˆ2(16)
65536.0

```

In fact, I suspect that most modern computer languages allow this. The reason is that the general Unicode recommendations on identifier characters ([Unicode Annex #31](https://unicode.org/reports/tr31/)) suggest allowing modifier letters to start identifiers (property `ID_Start`). They do [include a caveat](https://unicode.org/reports/tr31/#Modifier_Letters) that languages “may” want to specially handle modifier letters that resemble punctuation or other special characters, but I don’t know whether any languages do this for U+02C6.
