# Why not an inverse operator to \`\`\`accumulate\`\`\`?

**URL:** <https://discourse.julialang.org/t/why-not-an-inverse-operator-to-accumulate/133264>\
**Category:** Internals & Design\
**Created:** [October 18, 2025, 5:15pm UTC](https://discourse.julialang.org/t/why-not-an-inverse-operator-to-accumulate/133264 "2025-10-18T17:15:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![atteson](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@atteson](https://discourse.julialang.org/u/atteson)\
**Post date:** [October 18, 2025, 5:15pm UTC](https://discourse.julialang.org/t/why-not-an-inverse-operator-to-accumulate/133264/1 "2025-10-18T17:15:23Z")

</div>

There is a function which I find useful is the inverse of `accumulate`. I’ll call it `contrast`. Basically, `contrast`` is to `diff`what`accumulate`is to`cumsum```. My implement (not necesaarily most efficient is:

```julia-auto
contrast( op, v, init ) = [op( init, v[1] ); op.( v[1:end-1], v[2:end] )]

```

`contrast( invop, accumulate( op, v ) ) == v` module some initial value and where invop has the same relationship to op that + has to - (not exactly compositional inverses). I find this frequently useful but I think it is missing from the functional languages I’ve used. I’m in no way tied to the name above. I call it `deaccumulate` internally but a friend suggested `contrast` which I think is probably better.

---

<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:** [October 18, 2025, 8:50pm UTC](https://discourse.julialang.org/t/why-not-an-inverse-operator-to-accumulate/133264/2 "2025-10-18T20:50:55Z")

</div>

In the Transducers.jl world, this is a special case of `ScanEmit` (which is a generalization of `Scan`, which is the transducer that performs `accumulate`):

```julia
using Transducers
Contrast(op, init) = ScanEmit((u, x) -> (op(u, x), x), init)

```

and then

```julia-repl
julia> collect(Contrast(*, "a"), ["b", "c", "d", "e"])
4-element Vector{String}:
 "ab"
 "bc"
 "cd"
 "de"

```
