# Why is \`+(::Number, UniformScaling)\` deprecated?

**URL:** <https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021>\
**Category:** Internals & Design\
**Created:** [September 21, 2017, 12:41pm UTC](https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021 "2017-09-21T12:41:00Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [September 21, 2017, 12:41pm UTC](https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021/1 "2017-09-21T12:41:00Z")

</div>

This deprecation makes writing generic code that works with both matrices and scalars harder. What’s the logic behind it?

```julia
WARNING: x::Number + J::UniformScaling is deprecated, use x + J.λ instead.
Stacktrace:
 [1] depwarn(::String, ::Symbol) at ./deprecated.jl:70
 [2] +(::Int64, ::UniformScaling{Int64}) at ./deprecated.jl:57
 [3] eval(::Module, ::Any) at ./boot.jl:235
 [4] eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:66
 [5] macro expansion at ./REPL.jl:97 [inlined]
 [6] (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:73
while loading no file, in expression starting on line 0
2

```

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [September 21, 2017, 1:32pm UTC](https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021/2 "2017-09-21T13:32:19Z")

</div>

[https://github.com/JuliaLang/julia/issues/17083](https://github.com/JuliaLang/julia/issues/17083)

Could you post some examples where you would like to use it so someone can show us the preferred formulation?

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [September 21, 2017, 1:40pm UTC](https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021/3 "2017-09-21T13:40:23Z")

</div>

Ah, but they are about to deprecate `+(::Matrix, ::Number)` in favour of `.+` notation, so that issue won’t be valid in 0.7.

The usage is pretty simple:

```julia
function foo(G)
## do something
R = G - I
end

```

---

<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:** [September 22, 2017, 2:32am UTC](https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021/4 "2017-09-22T02:32:31Z")

</div>

Yup, that’s exactly why we’re deprecating that 🙂

---

<div class="post-metadata">

**Author:** ![morningkyle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/morningkyle/32/1684_2.png) [@morningkyle](https://discourse.julialang.org/u/morningkyle)\
**Post date:** [September 22, 2017, 4:55am UTC](https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021/5 "2017-09-22T04:55:27Z")

</div>

It seems both + UniformScaling and .+ UniformScaling are deprecated in 0.7(Version 0.7.0-DEV.1816 (2017-09-17 15:48 UTC)).

```julia
julia> 1 + I
WARNING: x::Number + J::UniformScaling is deprecated, use x + J.λ instead.
Stacktrace:
 [1] depwarn(::String, ::Symbol) at .\deprecated.jl:68
 [2] +(::Int64, ::UniformScaling{Int64}) at .\deprecated.jl:56
 [3] eval(::Module, ::Expr) at .\repl\REPL.jl:3
 [4] eval_user_input(::Any, ::Base.REPL.REPLBackend) at .\repl\REPL.jl:69
 [5] macro expansion at .\repl\REPL.jl:100 [inlined]
 [6] (::getfield(Base.REPL, Symbol("##1#2")){Base.REPL.REPLBackend})() at .\event.jl:96
while loading no file, in expression starting on line 0
2

julia> 1 .+ I
WARNING: x::Number + J::UniformScaling is deprecated, use x + J.λ instead.
Stacktrace:
 [1] depwarn(::String, ::Symbol) at .\deprecated.jl:68
 [2] +(::Int64, ::UniformScaling{Int64}) at .\deprecated.jl:56
 [3] (::getfield(Main, Symbol("##1#2")))(::UniformScaling{Int64}) at .\<missing>:0
 [4] broadcast(::Function, ::UniformScaling{Int64}) at .\broadcast.jl:434
 [5] eval(::Module, ::Expr) at .\repl\REPL.jl:3
 [6] eval_user_input(::Any, ::Base.REPL.REPLBackend) at .\repl\REPL.jl:69
 [7] macro expansion at .\repl\REPL.jl:100 [inlined]
 [8] (::getfield(Base.REPL, Symbol("##1#2")){Base.REPL.REPLBackend})() at .\event.jl:96
while loading no file, in expression starting on line 0
2

```

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [September 22, 2017, 6:08am UTC](https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021/6 "2017-09-22T06:08:43Z")

</div>

My point is once `1 + rand(2,2)` no longer works, `1+I` should be reenabled as there is no longer an issue of associativity

---

<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:** [September 22, 2017, 3:39pm UTC](https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021/7 "2017-09-22T15:39:21Z")

</div>

One is an old deprecation, the other is a new one. We can/should delete the old one now.

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [September 22, 2017, 4:08pm UTC](https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021/8 "2017-09-22T16:08:28Z")

</div>

You mean delete the old warning, and leave the old behaviour working? (That is, cancel the old deprecation since it’s no longer inconsistent.)

---

<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:** [September 22, 2017, 11:04pm UTC](https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021/9 "2017-09-22T23:04:50Z")

</div>

Yes, exactly.

---

<div class="post-metadata">

**Author:** ![morningkyle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/morningkyle/32/1684_2.png) [@morningkyle](https://discourse.julialang.org/u/morningkyle)\
**Post date:** [September 23, 2017, 3:31am UTC](https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021/10 "2017-09-23T03:31:48Z")

</div>

Maybe an unrelated question following this topic:

```julia
julia> ones(1, 1) + ones(1, 1) == ones(1, 1) + I
true

julia> ones(1, 1) == I
false

julia> 1 + I == 1 + 1
true

julia> 1 == I
false

```

**Can I expect ‘true’ for the 2nd and 4th equality comparison?** The ‘false’ output makes me to think ‘number + UniformScaling’ and ‘matrix + UniformScaling’ an invalid operation. Because ‘a + b == a + c’ should result ‘b == c’ in my math. The equality property should be the same or even more important as associativity.

Edit: But if both ‘I == 1’ and ‘I == ones(1, 1)’ are true, then it results true for ‘1 == ones(1, 1)’. This is also obviously wrong.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 23, 2017, 6:37am UTC](https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021/11 "2017-09-23T06:37:26Z")

</div>

Hint: try `size(I)`. If you accept the premise that `x == y` requires `size(x) == size(y)`, the above is the logical behaviour.

---

<div class="post-metadata">

**Author:** ![morningkyle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/morningkyle/32/1684_2.png) [@morningkyle](https://discourse.julialang.org/u/morningkyle)\
**Post date:** [September 23, 2017, 7:03am UTC](https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021/12 "2017-09-23T07:03:58Z")

</div>

I tend to the point that 1 does not equal to I in any case. My actual concern is that if we could break following rule:  
`a + b == a + c ==> b == c`  
If this rule has a higher priority, then we should not take ‘number + UniformScaling’ an valid operation. I am not 100% sure this opinion is correct though.

```julia
julia> size(I)
ERROR: MethodError: no method matching size(::UniformScaling{Int64})
Closest candidates are:
  size(::Any, ::Integer, ::Integer, ::Integer...) where N at abstractarray.jl:33
  size(::Char) at char.jl:13
  size(::Char, ::Any) at char.jl:14
  ...

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 23, 2017, 7:13am UTC](https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021/13 "2017-09-23T07:13:51Z")

</div>

> [@morningkyle](#):
>
> we could break following rule:
> 
> `a + b == a + c ==> b == c`

But there is no such “rule”. Eg

```julia
julia> a = b = 1.0
1.0

julia> c = 1+eps()
1.0000000000000002

julia> a + b == a + c
true

julia> b == c
false

```

---

<div class="post-metadata">

**Author:** ![morningkyle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/morningkyle/32/1684_2.png) [@morningkyle](https://discourse.julialang.org/u/morningkyle)\
**Post date:** [September 23, 2017, 7:26am UTC](https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021/14 "2017-09-23T07:26:10Z")

</div>

Wow, I didn’t know it was already a failed rule. Great example, thanks!

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [September 23, 2017, 2:51pm UTC](https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021/15 "2017-09-23T14:51:32Z")

</div>

IIUC at least @andyferris and @StefanKarpinski want scalars to act more like `UniformScaling` in this context, so the result of `1+I` would be `2I`. This differs from the present result of 2, so it’s not simply a reversion.

Further, it looks as if the result of `1+eye(n)` would be `2*eye(n)` after a deprecation cycle. I presume this would be added as “new syntax” sometime after the 1.0 release. Will scalar+array simply be an error for 1.0?

This would be a step towards making Julia syntax follow conventions of pure math when they deviate from those of other programming languages. It will be interesting to see how this plays out.

For reference, here is the new deprecation mentioned above, with discussion:  
[https://github.com/JuliaLang/julia/pull/22932](https://github.com/JuliaLang/julia/pull/22932)

---

<div class="post-metadata">

**Author:** ![morningkyle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/morningkyle/32/1684_2.png) [@morningkyle](https://discourse.julialang.org/u/morningkyle)\
**Post date:** [September 23, 2017, 3:03pm UTC](https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021/16 "2017-09-23T15:03:33Z")

</div>

`1 + I == 2I == I + I ==> 1 == I`  
So change the result of 1 + I to 2I could not solve my question above.

Yes, it would be interesting to see how this would evolve in future.

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [September 23, 2017, 6:38pm UTC](https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021/17 "2017-09-23T18:38:00Z")

</div>

> [@Ralph\_Smith](#):
>
> This would be a step towards making Julia syntax follow conventions of pure math

To my knowledge, this notation is only used in the context of functional analysis, where the operators are ostensibly scalar differential operators.

I’ve never seen the notation `1-A` used when A is a matrix: it’s always `I-A`

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [September 23, 2017, 7:36pm UTC](https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021/18 "2017-09-23T19:36:19Z")

</div>

Perhaps I was over-generalizing; functional analysis is indeed what I had in mind.

I thought I had an example in a more general context, but on page 1 Trefethen and Embree say

_throughout this book_ z-A _is shorthand for_ zI-A

so that doesn’t count.

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [September 23, 2017, 7:50pm UTC](https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021/19 "2017-09-23T19:50:50Z")

</div>

`I` itself is just shorthand: I’ve never seen a mathematical definition equivalent to `UniformScaling`.

Operators in the mathematical sense need spaces attached (as they are defined by their graph). Essentially `I` always needs context to infer the space. In the case of `1+I`, I would infer the space as R, and hence the result should be 2.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [September 23, 2017, 8:25pm UTC](https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021/20 "2017-09-23T20:25:07Z")

</div>

> [@dlfivefifty](#):
>
> I’ve never seen the notation `1-A` used when A is a matrix: it’s always `I-A`

The identity operator is often represented as blackboard “1” (or even a regular “1”) in quantum mechanics (but perhaps this can be considered part of functional analysis in some way).

[Next page](https://discourse.julialang.org/t/why-is-number-uniformscaling-deprecated/6021.md?page=2)
