# Question on LazySets and Plots: translate not defined

**URL:** <https://discourse.julialang.org/t/question-on-lazysets-and-plots-translate-not-defined/85859>\
**Category:** General Usage\
**Created:** [August 17, 2022, 6:23am UTC](https://discourse.julialang.org/t/question-on-lazysets-and-plots-translate-not-defined/85859 "2022-08-17T06:23:26Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [August 17, 2022, 6:23am UTC](https://discourse.julialang.org/t/question-on-lazysets-and-plots-translate-not-defined/85859/1 "2022-08-17T06:23:27Z")

</div>

Hi all,

after following It’s all Set tutorial on JuliaCon2021 I have found a speed bump when I try this:

```julia
using Plots, LazySets, LaTeXStrings

p(args...; kwargs...) = plot(xlims=(0,4), ylims=(0,4), ratio=1, lab="",
                        xlab=L"x_{1}", ylab=L"x_{2}", args...; kwargs...)
p!(args...; kwargs...) = plot!(lab="", args...; kwargs...);

X = BallInf([1.5, 2.0], 1.0)
v = [1.5, -1.0]
Y = translate(X, v)

# arrows
p([0, v[1]], [0, v[2]], linecolor=:gray, arrow-:arrow, linestyle=:dot, width=2)
p!([high(X, 1), high(Y, 1)], [high(X, 2), high(Y, 2)], linecolor=:gray,
    arrow=:arrow, linestyle=:dot, width=2)
p!([center(X,1), center(Y, 1)], [center(X, 2), center(Y, 2)], linecolor=:gray,
    arrow=:arrow, linestyle=:dot, width=2)

# sets
p!(X, lab="X")
p!(Singleton(v), alpha=0.8, lab="v")
p!(Y, lab="X + v")

```

I got an error of:  
**WARNING: both LazySets and Plots export “translate”; uses of it in module Main must be qualified**  
**ERROR: LoadError: UndefVarError: translate not defined**  
**Stacktrace:**  
\*\* [1] top-level scope\*\*  
\*\* @ ~/LasthrimProjection/plot.jl:9\*\*  
\*\* [2] include(fname::String)\*\*  
\*\* @ Base.MainInclude ./client.jl:451\*\*  
\*\* [3] top-level scope\*\*  
\*\* @ REPL[4]:1\*\*  
**in expression starting at /home/browni/LasthrimProjection/plot.jl:9**

Is translate a function of another package? In every row I write the `using LazySets, Plots,...` again because I might not run the first row at the notebook.

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [August 17, 2022, 6:43am UTC](https://discourse.julialang.org/t/question-on-lazysets-and-plots-translate-not-defined/85859/2 "2022-08-17T06:43:05Z")

</div>

> [@Freya\_the\_Goddess](#):
>
> **WARNING: both LazySets and Plots export “translate”; uses of it in module Main must be qualified**

As the warning says, both `Plots` and `LazySets` define different functions that have the same name `translate`, and both are exported by those packages, so there’s a conflict. When you call `translate(X, v)`, Julia doesn’t know which `translate` you’re referring to - whether the one from `Plots` or the one from `LazySets` - so there’s an error.

You can fix the error by changing the `Y = translate(X, v)` line to `Y = LazySets.translate(X, v)` to specify that that’s the function you want.

Or better, if you’re only using `plot` and `plot!` functions from Plots.jl, you can do:

```julia
using LazySets, LaTeXStrings
using Plots: plots, plots!

```

at the beginning to avoid the conflict in the first place.

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [August 17, 2022, 6:45am UTC](https://discourse.julialang.org/t/question-on-lazysets-and-plots-translate-not-defined/85859/3 "2022-08-17T06:45:50Z")

</div>

Yes, both packages contain the method translate.

```julia
?LazySets.translate
translate(hs::HalfSpace, v::AbstractVector; [share]::Bool=false)
Translate (i.e., shift) a half-space by a given vector.

Input
hs – half-space
v – translation vector
share – (optional, default: false) flag for sharing unmodified parts of the original set representation
Output
A translated half-space.

```

and  
?Plots.translate

```julia
translate(shape, x, y = x)
translate!(shape, x, y = x)
#Translate a Shape in space.

```

Hence you should replace translate in your code either by `LazySets.translate` or by `Plots.translate`.

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [August 17, 2022, 6:52am UTC](https://discourse.julialang.org/t/question-on-lazysets-and-plots-translate-not-defined/85859/4 "2022-08-17T06:52:13Z")

</div>

I try with:

```julia
Y = LazySets.translate(X, v)

```

I get:

**MethodError: no method matching -(::typeof(arrow), ::Symbol)**  
**Closest candidates are:**  
\*\* -(::Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}}, ::T) where T at ~/.julia/packages/MathOptInterface/YDdD3/src/Utilities/functions.jl:1725\*\*  
\*\* -(::ChainRulesCore.AbstractThunk, ::Any) at ~/.julia/packages/ChainRulesCore/ctmSK/src/tangent\_types/thunks.jl:34\*\*  
\*\* -(::ChainRulesCore.NoTangent, ::Any) at ~/.julia/packages/ChainRulesCore/ctmSK/src/tangent\_arithmetic.jl:61\*\*  
\*\* …\*\*

**Stacktrace:**  
\*\* [1] top-level scope\*\*  
\*\* @ In[15]:13\*\*  
\*\* [2] eval\*\*  
\*\* @ ./boot.jl:373 [inlined]\*\*  
\*\* [3] include\_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)\*\*  
\*\* @ Base ./loading.jl:1196\*\*

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [August 17, 2022, 6:52am UTC](https://discourse.julialang.org/t/question-on-lazysets-and-plots-translate-not-defined/85859/5 "2022-08-17T06:52:57Z")

</div>

When I try

```julia
Y = Plots.translate(X, v)

```

I get:

**MethodError: no method matching translate(::BallInf{Float64, Vector{Float64}}, ::Vector{Float64})**

**Stacktrace:**  
\*\* [1] top-level scope\*\*  
\*\* @ In[16]:10\*\*  
\*\* [2] eval\*\*  
\*\* @ ./boot.jl:373 [inlined]\*\*  
\*\* [3] include\_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)\*\*  
\*\* @ Base ./loading.jl:1196\*\*

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [August 17, 2022, 7:31am UTC](https://discourse.julialang.org/t/question-on-lazysets-and-plots-translate-not-defined/85859/6 "2022-08-17T07:31:38Z")

</div>

This sounds like it’s just from the typo: in the line

```
 p([0, v[1]], [0, v[2]], linecolor=:gray, arrow-:arrow, linestyle=:dot, width=2)

```

instead of `arrow = :arrow` you have `arrow-:arrow`.

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [August 17, 2022, 8:08am UTC](https://discourse.julialang.org/t/question-on-lazysets-and-plots-translate-not-defined/85859/7 "2022-08-17T08:08:22Z")

</div>

I fixed it, but still got this:

**MethodError: no method matching translate(::BallInf{Float64, Vector{Float64}}, ::Vector{Float64})**

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [August 17, 2022, 8:31am UTC](https://discourse.julialang.org/t/question-on-lazysets-and-plots-translate-not-defined/85859/8 "2022-08-17T08:31:10Z")

</div>

Have you removed the originial `using` line and replaced it with:

```julia
using LazySets, LaTeXStrings
using Plots: plots, plots!

```

as suggested? And if so, have you restarted the notebook after you did that?

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [August 17, 2022, 8:40am UTC](https://discourse.julialang.org/t/question-on-lazysets-and-plots-translate-not-defined/85859/9 "2022-08-17T08:40:00Z")

</div>

This is the code now:

```julia
using LazySets, LaTeXStrings
using Plots: plots, plots!

p(args...; kwargs...) = plot(xlims=(0,4), ylims=(0,4), ratio=1, lab="",
                        xlab=L"x_{1}", ylab=L"x_{2}", args...; kwargs...)
p!(args...; kwargs...) = plot!(lab="", args...; kwargs...);

X = BallInf([1.5, 2.0], 1.0)
v = [1.5, -1.0]
Y = Plots.translate(X, v)

# arrows
p([0, v[1]], [0, v[2]], linecolor=:gray, arrow=:arrow, linestyle=:dot, width=2)
p!([high(X, 1), high(Y, 1)], [high(X, 2), high(Y, 2)], linecolor=:gray,
    arrow=:arrow, linestyle=:dot, width=2)
p!([center(X,1), center(Y, 1)], [center(X, 2), center(Y, 2)], linecolor=:gray,
    arrow=:arrow, linestyle=:dot, width=2)

# sets
p!(X, lab="X")
p!(Singleton(v), alpha=0.8, lab="v")
p!(Y, lab="X + v")

```

This is the error after that code:  
**UndefVarError: plots not defined**

**Stacktrace:**  
\*\* [1] eval\*\*  
\*\* @ ./boot.jl:373 [inlined]\*\*  
\*\* [2] include\_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)\*\*  
\*\* @ Base ./loading.jl:1196\*\*

I have restarted it too.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [August 17, 2022, 9:27am UTC](https://discourse.julialang.org/t/question-on-lazysets-and-plots-translate-not-defined/85859/10 "2022-08-17T09:27:31Z")

</div>

`plots` and `plots!` don’t exist, the functions are called `plot` and `plot!`

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [August 17, 2022, 9:37am UTC](https://discourse.julialang.org/t/question-on-lazysets-and-plots-translate-not-defined/85859/11 "2022-08-17T09:37:15Z")

</div>

It is really confusing here, sorry for I am not catching it quite right, but the function is Plots:

I try again:

```julia
using LazySets, LaTeXStrings
using Plots: plots, plots!

p(args...; kwargs...) = plots(xlims=(0,4), ylims=(0,4), ratio=1, lab="",
                        xlab=L"x_{1}", ylab=L"x_{2}", args...; kwargs...)
p!(args...; kwargs...) = plots!(lab="", args...; kwargs...);

X = BallInf([1.5, 2.0], 1.0)
v = [1.5, -1.0]
Y = LazySets.translate(X, v)

# arrows
p([0, v[1]], [0, v[2]], linecolor=:gray, arrow=:arrow, linestyle=:dot, width=2)
p!([high(X, 1), high(Y, 1)], [high(X, 2), high(Y, 2)], linecolor=:gray,
    arrow=:arrow, linestyle=:dot, width=2)
p!([center(X,1), center(Y, 1)], [center(X, 2), center(Y, 2)], linecolor=:gray,
    arrow=:arrow, linestyle=:dot, width=2)

# sets
p!(X, lab="X")
p!(Singleton(v), alpha=0.8, lab="v")
p!(Y, lab="X + v")

```

Get:

**UndefVarError: plots not defined**

**Stacktrace:**  
\*\* [1] eval\*\*  
\*\* @ ./boot.jl:373 [inlined]\*\*  
\*\* [2] include\_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)\*\*  
\*\* @ Base ./loading.jl:1196\*\*

When checking the packages:

```julia
]st

      Status `~/LasthrimProjection/Project.toml`
  [3391f64e] CDDLib v0.7.0
  [13f3f980] CairoMakie v0.5.10
  [39dd38d3] Dierckx v0.5.2
  [b4f34e82] Distances v0.10.7
  [d997a800] Implicit3DPlotting v0.2.3 `https://github.com/matthiashimmelmann/Implicit3DPlotting.jl.git#main`
  [a98d9a8b] Interpolations v0.14.4
  [d1acc4aa] IntervalArithmetic v0.20.7
  [b964fa9f] LaTeXStrings v1.3.0
  [b4f0291d] LazySets v2.0.0
  [ae8d54c2] Luxor v3.5.0
  [429524aa] Optim v1.7.1
  [f0f68f2c] PlotlyJS v0.18.8
  [91a5bcdd] Plots v1.31.7
  [67491407] Polyhedra v0.6.17
  [438e738f] PyCall v1.93.1
  [ce6b1742] RDatasets v0.7.7
  [9ec6d097] TruthTables v0.4.1

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [August 17, 2022, 9:40am UTC](https://discourse.julialang.org/t/question-on-lazysets-and-plots-translate-not-defined/85859/12 "2022-08-17T09:40:13Z")

</div>

No it’s not. Make sure to run your code line-by-line in a fresh Julia session whenever posting here to make sure you understand where your errors appear and that you have no hidden state.

```julia
julia> using Plots: plots # should be plot
ERROR: UndefVarError: plots not defined

```

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [August 17, 2022, 9:44am UTC](https://discourse.julialang.org/t/question-on-lazysets-and-plots-translate-not-defined/85859/13 "2022-08-17T09:44:05Z")

</div>

I get it works now, thanks @nilshg !

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [August 17, 2022, 9:44am UTC](https://discourse.julialang.org/t/question-on-lazysets-and-plots-translate-not-defined/85859/14 "2022-08-17T09:44:45Z")

</div>

How to know I have hidden state?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [August 17, 2022, 9:48am UTC](https://discourse.julialang.org/t/question-on-lazysets-and-plots-translate-not-defined/85859/15 "2022-08-17T09:48:07Z")

</div>

By hidden state I just mean old definitions hanging around - so the longer you’ve got a session running the more likely it is that you’ve got some hidden state. Then when someone asks you to try something it might fail for you, e.g. because you have overwritten some definition in Base. A classic is something like:

```julia
julia> sum = 5+5 # seems like a sensible variable name?
10

julia> sum([1, 2, 3]) # Oh no!
ERROR: MethodError: objects of type Int64 are not callable

```

Therefore it’s always useful to try things in a fresh Julia session when interacting with people on here, to ensure that other people can recreate what you’re seeing locally.

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [August 17, 2022, 10:22am UTC](https://discourse.julialang.org/t/question-on-lazysets-and-plots-translate-not-defined/85859/16 "2022-08-17T10:22:34Z")

</div>

> [@nilshg](#):
>
> `plots` and `plots!` don’t exist, the functions are called `plot` and `plot!`

Oops, that’s on me. Somehow had a brainfart between writing “if you’re only using `plot` and `plot!` functions from Plots.jl” and the `using` line right after it, and managed to misspell it. Thanks for catching it!
