# How to Use InverseFunctions.jl that can Calculate the Inverse of a Function?

**URL:** <https://discourse.julialang.org/t/how-to-use-inversefunctions-jl-that-can-calculate-the-inverse-of-a-function/91931>\
**Category:** General Usage\
**Tags:** package\
**Created:** [December 21, 2022, 7:16am UTC](https://discourse.julialang.org/t/how-to-use-inversefunctions-jl-that-can-calculate-the-inverse-of-a-function/91931 "2022-12-21T07:16:24Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [December 21, 2022, 7:28am UTC](https://discourse.julialang.org/t/how-to-use-inversefunctions-jl-that-can-calculate-the-inverse-of-a-function/91931/2 "2022-12-21T07:28:35Z")

</div>

This package wants you to express the function as a composition of functions:

```julia
julia> using InverseFunctions

julia> foo = sqrt ∘ Base.Fix1(*, 4)
sqrt ∘ Base.Fix1{typeof(*), Int64}(*, 4)

julia> inverse(foo)
Base.Fix1{typeof(\), Int64}(\, 4) ∘ InverseFunctions.square

julia> inverse(foo).(1:8)
8-element Vector{Float64}:
  0.25
  1.0
  2.25
  4.0
  6.25
  9.0
 12.25
 16.0

```

It does raise interesting questions about function composition fallbacks, something that’s recently been on my mind ([see here](https://discourse.julialang.org/t/summary-of-piping-chaining-proposal/91442/8)). It could be interesting if Julia allowed our own fallbacks for this kind of purpose. Calculating inverse functions sure is handy, e.g., when using the Kolmogorov-Nagumo Average.

Edit: On further thought, we wouldn’t need any custom fallback to satisfy this desire beyond what was suggested in that link (i.e., a composition fallback for partially-applied functions).

---

_[View the full topic](https://discourse.julialang.org/t/how-to-use-inversefunctions-jl-that-can-calculate-the-inverse-of-a-function/91931)._
