# One vs 1 in algebra

**URL:** <https://discourse.julialang.org/t/one-vs-1-in-algebra/3874>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 23, 2017, 10:21am UTC](https://discourse.julialang.org/t/one-vs-1-in-algebra/3874 "2017-05-23T10:21:09Z")\
**Posts on this page:** 3\
**Page:** 1

<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:** [May 23, 2017, 10:21am UTC](https://discourse.julialang.org/t/one-vs-1-in-algebra/3874/1 "2017-05-23T10:21:09Z")

</div>

I am writing functions which are basically algebra coded up (from an economic model), with code like

```julia
(1-βᵢ)*(1-αᵢ)*ωᵢ / ((1-βᵢ + γᵢ*βᵢ)*(1-αᵢ)*ωᵢ + γᵢβₖ*(1-αₖ)*ωₖ)

```

and it gets worse. They should work with `Float64`, `Rational{Int64}` (for unit tests!), and `ForwardDiff.Dual`.

Out of habit (following suggestions in the manual), I use `one(...)` for `1`, but now I have come to question this, because the compiler seems to produce the same code for the literal `1` (which is neatly promoted) and `one(...)`. MWE:

```julia
with1(x) = 1+x
withone(x) = one(x) + x

```

eg `@code_warntype` is the same.

So is it an OK habit to use `1` in formulas? Or is there a downside?

PS: I of course understand that a standalone application for a generic type where no promotion applies would require `one(...)` for type stability.

---

<div class="post-metadata">

**Author:** ![MikeInnes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikeinnes/32/3656_2.png) [@MikeInnes](https://discourse.julialang.org/u/MikeInnes)\
**Post date:** [May 23, 2017, 10:30am UTC](https://discourse.julialang.org/t/one-vs-1-in-algebra/3874/2 "2017-05-23T10:30:33Z")

</div>

Yeah this is completely fine. Since you’re not storing the `1` in a variable or anything that could change type, the flow of types is unambiguous.

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [May 23, 2017, 12:34pm UTC](https://discourse.julialang.org/t/one-vs-1-in-algebra/3874/3 "2017-05-23T12:34:48Z")

</div>

Talking about writing math, I sometimes wish there was a nice symbol for fractions that doesn’t require parenthesis. I haven’t really found anything very natural though.

```julia
∷(a,b) = a/b

f(x) = x+1 ∷ x-1

#vs

f(x) = (x+1) / (x-1)

```
