# Using superscript ⁻¹ as a postfix operator for inv?

**URL:** <https://discourse.julialang.org/t/using-superscript-as-a-postfix-operator-for-inv/40413>\
**Category:** General Usage\
**Created:** [May 28, 2020, 10:32pm UTC](https://discourse.julialang.org/t/using-superscript-as-a-postfix-operator-for-inv/40413 "2020-05-28T22:32:06Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [June 2, 2020, 5:52pm UTC](https://discourse.julialang.org/t/using-superscript-as-a-postfix-operator-for-inv/40413/12 "2020-06-02T17:52:44Z")

</div>

You can actually do this with no language changes if you’re willing to write `(A)⁻¹` rather than `A⁻¹`. Here’s an example at the REPL:

```julia
julia> begin
           struct Inverter end
           const ⁻¹ = Inverter()
           Base.:(*)(A, ::Inverter) = inv(A)
       end

julia> A = rand(3,3)
3×3 Array{Float64,2}:
 0.51549 0.0616877 0.530502
 0.783366 0.0598045 0.697045
 0.381722 0.833891 0.632847

julia> (A)⁻¹
3×3 Array{Float64,2}:
 -13.5368 10.0475 0.280811
  -5.72129 3.08199 1.4014
  15.704 -10.1216 -0.435822

julia> ((A)⁻¹)*A ≈ I(3)
true

```

This works because `(a)b` is parsed as `a * b`:

```julia
julia> quote (a)b end
quote
    #= REPL[7]:1 =#
    a * b
end

```

so we need only define an object `⁻¹` which when multiplied by `A` on the left produces `inv(A)`, trivially easy with multiple dispatch.

One could do the same with `²` to make an squaring operator if they were unable to stomach reading `x^2` or `x*x`

---

_[View the full topic](https://discourse.julialang.org/t/using-superscript-as-a-postfix-operator-for-inv/40413)._
