# ¿Cómo representar una partícula?

Necesito: posición \$x\$, velocidad \$v\$, masa \$m\$, [carga \$q\$, color...]

``````

In [5]:

x = 3.
v = 1.
m = 1.

``````
``````

Out[5]:

1.0

``````

Mover la partícula:

``````

In [8]:

function mover(x, v, δt)
x = x + v*δt
end

``````
``````

Out[8]:

mover (generic function with 2 methods)

``````
``````

In [7]:

mover(1)

``````
``````

Out[7]:

4.0

``````
``````

In [15]:

x

``````
``````

x not defined

``````
``````

In [16]:

x2 = 1
v2 = 3

``````
``````

Out[16]:

3

``````

Otra representación:

``````

In [17]:

particula = [3, 4., "particulita"]
# son [x, v, etiqueta]

``````
``````

Out[17]:

3-element Array{Any,1}:
3
4.0
"particulita"

``````
``````

In [18]:

dt = 0.5
particula[1] = particula[1] + dt * particula[2]

``````
``````

Out[18]:

5.0

``````

# La solución: tipos / objetos / clases

Voy hacer una caja que contiene cosas con nombres:

``````

In [19]:

type Particula
x
v
m
end

``````
``````

In [20]:

Particula

``````
``````

Out[20]:

Particula (constructor with 1 method)

``````
``````

In [21]:

methods(Particula)

``````
``````

Out[21]:

1 method for generic function Particula: Particula(x,v,m)

``````
``````

In [22]:

p = Particula(1, 2, 3)

``````
``````

Out[22]:

Particula(1,2,3)

``````
``````

In [23]:

p

``````
``````

Out[23]:

Particula(1,2,3)

``````
``````

In [24]:

p.x

``````
``````

Out[24]:

1

``````
``````

In [25]:

p.v

``````
``````

Out[25]:

2

``````
``````

In [26]:

p.m

``````
``````

Out[26]:

3

``````
``````

In [27]:

dt = 0.5
p.x += p.v*dt  # equivalente a   p.x = p.x + p.v*dt

``````
``````

Out[27]:

2.0

``````
``````

In [28]:

p2 = Particula(4, 5, 6)

``````
``````

Out[28]:

Particula(4,5,6)

``````
``````

In [29]:

p

``````
``````

Out[29]:

Particula(2.0,2,3)

``````
``````

In [30]:

p2

``````
``````

Out[30]:

Particula(4,5,6)

``````
``````

In [31]:

p2.x, p2.v, p2.m

``````
``````

Out[31]:

(4,5,6)

``````
``````

In [32]:

p3 = Particula("hola", "soy", "yo")

``````
``````

Out[32]:

Particula("hola","soy","yo")

``````
``````

In [33]:

type Particula2
x::Real
v::Real
m::Real
end

``````
``````

In [34]:

Particula2("HOLA", "y", "eso")

``````
``````

`convert` has no method matching convert(::Type{Real}, ::ASCIIString)

in Particula2 at no file

``````
``````

In [35]:

Particula2(-3, 10, Inf)

``````
``````

Out[35]:

Particula2(-3,10,Inf)

``````
``````

In [36]:

p

``````
``````

Out[36]:

Particula(2.0,2,3)

``````
``````

In [42]:

function mover!(p::Particula, dt)
p.x += p.v * dt
end

function mover!(p::Particula2, dt)
p.x += p.v * 3*dt
end

``````
``````

Out[42]:

mover! (generic function with 2 methods)

``````
``````

In [43]:

methods(mover!)

``````
``````

Out[43]:

2 methods for generic function mover!: mover!(p::Particula,dt) at In[42]:2 mover!(p::Particula2,dt) at In[42]:6

``````
``````

In [44]:

methods(+)

``````
``````

Out[44]:

117 methods for generic function +: +(x::Bool) at bool.jl:36 +(x::Bool,y::Bool) at bool.jl:39 +(y::FloatingPoint,x::Bool) at bool.jl:49 +(A::BitArray{N},B::BitArray{N}) at bitarray.jl:848 +(A::Union(DenseArray{Bool,N},SubArray{Bool,N,A<:DenseArray{T,N},I<:(Union(Int64,Range{Int64})...,)}),B::Union(DenseArray{Bool,N},SubArray{Bool,N,A<:DenseArray{T,N},I<:(Union(Int64,Range{Int64})...,)})) at array.jl:801 +{S,T}(A::Union(SubArray{S,N,A<:DenseArray{T,N},I<:(Union(Int64,Range{Int64})...,)},DenseArray{S,N}),B::Union(DenseArray{T,N},SubArray{T,N,A<:DenseArray{T,N},I<:(Union(Int64,Range{Int64})...,)})) at array.jl:723 +{T<:Union(Int32,Int16,Int8)}(x::T<:Union(Int32,Int16,Int8),y::T<:Union(Int32,Int16,Int8)) at int.jl:16 +{T<:Union(Uint8,Uint16,Uint32)}(x::T<:Union(Uint8,Uint16,Uint32),y::T<:Union(Uint8,Uint16,Uint32)) at int.jl:20 +(x::Int64,y::Int64) at int.jl:33 +(x::Uint64,y::Uint64) at int.jl:34 +(x::Int128,y::Int128) at int.jl:35 +(x::Uint128,y::Uint128) at int.jl:36 +(x::Float32,y::Float32) at float.jl:119 +(x::Float64,y::Float64) at float.jl:120 +(z::Complex{T<:Real},w::Complex{T<:Real}) at complex.jl:110 +(x::Real,z::Complex{T<:Real}) at complex.jl:120 +(z::Complex{T<:Real},x::Real) at complex.jl:121 +(x::Rational{T<:Integer},y::Rational{T<:Integer}) at rational.jl:113 +(x::Char,y::Char) at char.jl:23 +(x::Char,y::Integer) at char.jl:26 +(x::Integer,y::Char) at char.jl:27 +(a::Float16,b::Float16) at float16.jl:132 +(x::BigInt,y::BigInt) at gmp.jl:195 +(a::BigInt,b::BigInt,c::BigInt) at gmp.jl:218 +(a::BigInt,b::BigInt,c::BigInt,d::BigInt) at gmp.jl:224 +(a::BigInt,b::BigInt,c::BigInt,d::BigInt,e::BigInt) at gmp.jl:231 +(x::BigInt,c::Union(Uint8,Uint16,Uint64,Uint32)) at gmp.jl:243 +(c::Union(Uint8,Uint16,Uint64,Uint32),x::BigInt) at gmp.jl:247 +(x::BigInt,c::Union(Int64,Int32,Int16,Int8)) at gmp.jl:259 +(c::Union(Int64,Int32,Int16,Int8),x::BigInt) at gmp.jl:260 +(x::BigFloat,y::BigFloat) at mpfr.jl:149 +(x::BigFloat,c::Union(Uint8,Uint16,Uint64,Uint32)) at mpfr.jl:156 +(c::Union(Uint8,Uint16,Uint64,Uint32),x::BigFloat) at mpfr.jl:160 +(x::BigFloat,c::Union(Int64,Int32,Int16,Int8)) at mpfr.jl:164 +(c::Union(Int64,Int32,Int16,Int8),x::BigFloat) at mpfr.jl:168 +(x::BigFloat,c::Union(Float16,Float32,Float64)) at mpfr.jl:172 +(c::Union(Float16,Float32,Float64),x::BigFloat) at mpfr.jl:176 +(x::BigFloat,c::BigInt) at mpfr.jl:180 +(c::BigInt,x::BigFloat) at mpfr.jl:184 +(a::BigFloat,b::BigFloat,c::BigFloat) at mpfr.jl:255 +(a::BigFloat,b::BigFloat,c::BigFloat,d::BigFloat) at mpfr.jl:261 +(a::BigFloat,b::BigFloat,c::BigFloat,d::BigFloat,e::BigFloat) at mpfr.jl:268 +(x::MathConst{sym},y::MathConst{sym}) at constants.jl:23 +{T<:Number}(x::T<:Number,y::T<:Number) at promotion.jl:188 +{T<:FloatingPoint}(x::Bool,y::T<:FloatingPoint) at bool.jl:46 +(x::Number,y::Number) at promotion.jl:158 +(x::Integer,y::Ptr{T}) at pointer.jl:68 +(x::Bool,A::AbstractArray{Bool,N}) at array.jl:771 +(x::Number) at operators.jl:71 +(r1::OrdinalRange{T,S},r2::OrdinalRange{T,S}) at operators.jl:325 +{T<:FloatingPoint}(r1::FloatRange{T<:FloatingPoint},r2::FloatRange{T<:FloatingPoint}) at operators.jl:331 +(r1::FloatRange{T<:FloatingPoint},r2::FloatRange{T<:FloatingPoint}) at operators.jl:348 +(r1::FloatRange{T<:FloatingPoint},r2::OrdinalRange{T,S}) at operators.jl:349 +(r1::OrdinalRange{T,S},r2::FloatRange{T<:FloatingPoint}) at operators.jl:350 +(x::Ptr{T},y::Integer) at pointer.jl:66 +{S,T<:Real}(A::Union(SubArray{S,N,A<:DenseArray{T,N},I<:(Union(Int64,Range{Int64})...,)},DenseArray{S,N}),B::Range{T<:Real}) at array.jl:731 +{S<:Real,T}(A::Range{S<:Real},B::Union(DenseArray{T,N},SubArray{T,N,A<:DenseArray{T,N},I<:(Union(Int64,Range{Int64})...,)})) at array.jl:740 +(A::AbstractArray{Bool,N},x::Bool) at array.jl:770 +{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti},B::SparseMatrixCSC{Tv,Ti}) at sparse/sparsematrix.jl:552 +{TvA,TiA,TvB,TiB}(A::SparseMatrixCSC{TvA,TiA},B::SparseMatrixCSC{TvB,TiB}) at sparse/sparsematrix.jl:544 +(A::SparseMatrixCSC{Tv,Ti<:Integer},B::Array{T,N}) at sparse/sparsematrix.jl:643 +(A::Array{T,N},B::SparseMatrixCSC{Tv,Ti<:Integer}) at sparse/sparsematrix.jl:645 +(A::SymTridiagonal{T},B::SymTridiagonal{T}) at linalg/tridiag.jl:57 +(A::Tridiagonal{T},B::Tridiagonal{T}) at linalg/tridiag.jl:247 +(A::Tridiagonal{T},B::SymTridiagonal{T}) at linalg/special.jl:99 +(A::SymTridiagonal{T},B::Tridiagonal{T}) at linalg/special.jl:98 +{T,MT,uplo}(A::Triangular{T,MT,uplo,IsUnit},B::Triangular{T,MT,uplo,IsUnit}) at linalg/triangular.jl:11 +{T,MT,uplo1,uplo2}(A::Triangular{T,MT,uplo1,IsUnit},B::Triangular{T,MT,uplo2,IsUnit}) at linalg/triangular.jl:12 +(Da::Diagonal{T},Db::Diagonal{T}) at linalg/diagonal.jl:47 +(A::Bidiagonal{T},B::Bidiagonal{T}) at linalg/bidiag.jl:92 +{T}(B::BitArray{2},J::UniformScaling{T}) at linalg/uniformscaling.jl:26 +(A::Diagonal{T},B::Bidiagonal{T}) at linalg/special.jl:89 +(A::Bidiagonal{T},B::Diagonal{T}) at linalg/special.jl:90 +(A::Diagonal{T},B::Tridiagonal{T}) at linalg/special.jl:89 +(A::Tridiagonal{T},B::Diagonal{T}) at linalg/special.jl:90 +(A::Diagonal{T},B::Triangular{T,S<:AbstractArray{T,2},UpLo,IsUnit}) at linalg/special.jl:89 +(A::Triangular{T,S<:AbstractArray{T,2},UpLo,IsUnit},B::Diagonal{T}) at linalg/special.jl:90 +(A::Diagonal{T},B::Array{T,2}) at linalg/special.jl:89 +(A::Array{T,2},B::Diagonal{T}) at linalg/special.jl:90 +(A::Bidiagonal{T},B::Tridiagonal{T}) at linalg/special.jl:89 +(A::Tridiagonal{T},B::Bidiagonal{T}) at linalg/special.jl:90 +(A::Bidiagonal{T},B::Triangular{T,S<:AbstractArray{T,2},UpLo,IsUnit}) at linalg/special.jl:89 +(A::Triangular{T,S<:AbstractArray{T,2},UpLo,IsUnit},B::Bidiagonal{T}) at linalg/special.jl:90 +(A::Bidiagonal{T},B::Array{T,2}) at linalg/special.jl:89 +(A::Array{T,2},B::Bidiagonal{T}) at linalg/special.jl:90 +(A::Tridiagonal{T},B::Triangular{T,S<:AbstractArray{T,2},UpLo,IsUnit}) at linalg/special.jl:89 +(A::Triangular{T,S<:AbstractArray{T,2},UpLo,IsUnit},B::Tridiagonal{T}) at linalg/special.jl:90 +(A::Tridiagonal{T},B::Array{T,2}) at linalg/special.jl:89 +(A::Array{T,2},B::Tridiagonal{T}) at linalg/special.jl:90 +(A::Triangular{T,S<:AbstractArray{T,2},UpLo,IsUnit},B::Array{T,2}) at linalg/special.jl:89 +(A::Array{T,2},B::Triangular{T,S<:AbstractArray{T,2},UpLo,IsUnit}) at linalg/special.jl:90 +(A::SymTridiagonal{T},B::Triangular{T,S<:AbstractArray{T,2},UpLo,IsUnit}) at linalg/special.jl:98 +(A::Triangular{T,S<:AbstractArray{T,2},UpLo,IsUnit},B::SymTridiagonal{T}) at linalg/special.jl:99 +(A::SymTridiagonal{T},B::Array{T,2}) at linalg/special.jl:98 +(A::Array{T,2},B::SymTridiagonal{T}) at linalg/special.jl:99 +(A::Diagonal{T},B::SymTridiagonal{T}) at linalg/special.jl:107 +(A::SymTridiagonal{T},B::Diagonal{T}) at linalg/special.jl:108 +(A::Bidiagonal{T},B::SymTridiagonal{T}) at linalg/special.jl:107 +(A::SymTridiagonal{T},B::Bidiagonal{T}) at linalg/special.jl:108 +{T<:Number}(x::AbstractArray{T<:Number,N}) at abstractarray.jl:362 +(A::AbstractArray{T,N},x::Number) at array.jl:774 +(x::Number,A::AbstractArray{T,N}) at array.jl:775 +(J1::UniformScaling{T<:Number},J2::UniformScaling{T<:Number}) at linalg/uniformscaling.jl:25 +(J::UniformScaling{T<:Number},B::BitArray{2}) at linalg/uniformscaling.jl:27 +(J::UniformScaling{T<:Number},A::AbstractArray{T,2}) at linalg/uniformscaling.jl:28 +(J::UniformScaling{T<:Number},x::Number) at linalg/uniformscaling.jl:29 +(x::Number,J::UniformScaling{T<:Number}) at linalg/uniformscaling.jl:30 +{TA,TJ}(A::AbstractArray{TA,2},J::UniformScaling{TJ}) at linalg/uniformscaling.jl:33 +{T}(a::HierarchicalValue{T},b::HierarchicalValue{T}) at pkg/resolve/versionweight.jl:19 +(a::VWPreBuildItem,b::VWPreBuildItem) at pkg/resolve/versionweight.jl:82 +(a::VWPreBuild,b::VWPreBuild) at pkg/resolve/versionweight.jl:120 +(a::VersionWeight,b::VersionWeight) at pkg/resolve/versionweight.jl:164 +(a::FieldValue,b::FieldValue) at pkg/resolve/fieldvalue.jl:41 +(a::Vec2,b::Vec2) at graphics.jl:60 +(bb1::BoundingBox,bb2::BoundingBox) at graphics.jl:123 +(a,b,c) at operators.jl:82 +(a,b,c,xs...) at operators.jl:83

``````
``````

In [39]:

mover(p, 1.)

``````
``````

Out[39]:

4.0

``````
``````

In [40]:

p

``````
``````

Out[40]:

Particula(4.0,2,3)

``````

``````

In [46]:

p1 = Particula(1, 2, 3)
p2 = Particula(4, 5, 6)

``````
``````

Out[46]:

Particula(4,5,6)

``````
``````

In [47]:

p1 + p2

``````
``````

`+` has no method matching +(::Particula, ::Particula)

``````

Sólo como ejemplo:

``````

In [48]:

function +(p1::Particula, p2::Particula)
Particula(p1.x+p2.x, p1.v+p2.v, p1.m+3*p2.m)
end

``````
``````

Out[48]:

+ (generic function with 118 methods)

``````
``````

In [49]:

p1 + p2

``````
``````

Out[49]:

Particula(5,7,21)

``````
``````

In [50]:

+(p1, p2)

``````
``````

Out[50]:

Particula(5,7,21)

``````
``````

In [51]:

methods(+)

``````
``````

Out[51]:

118 methods for generic function +: +(x::Bool) at bool.jl:36 +(x::Bool,y::Bool) at bool.jl:39 +(y::FloatingPoint,x::Bool) at bool.jl:49 +(A::BitArray{N},B::BitArray{N}) at bitarray.jl:848 +(A::Union(DenseArray{Bool,N},SubArray{Bool,N,A<:DenseArray{T,N},I<:(Union(Int64,Range{Int64})...,)}),B::Union(DenseArray{Bool,N},SubArray{Bool,N,A<:DenseArray{T,N},I<:(Union(Int64,Range{Int64})...,)})) at array.jl:801 +{S,T}(A::Union(SubArray{S,N,A<:DenseArray{T,N},I<:(Union(Int64,Range{Int64})...,)},DenseArray{S,N}),B::Union(DenseArray{T,N},SubArray{T,N,A<:DenseArray{T,N},I<:(Union(Int64,Range{Int64})...,)})) at array.jl:723 +{T<:Union(Int32,Int16,Int8)}(x::T<:Union(Int32,Int16,Int8),y::T<:Union(Int32,Int16,Int8)) at int.jl:16 +{T<:Union(Uint8,Uint16,Uint32)}(x::T<:Union(Uint8,Uint16,Uint32),y::T<:Union(Uint8,Uint16,Uint32)) at int.jl:20 +(x::Int64,y::Int64) at int.jl:33 +(x::Uint64,y::Uint64) at int.jl:34 +(x::Int128,y::Int128) at int.jl:35 +(x::Uint128,y::Uint128) at int.jl:36 +(x::Float32,y::Float32) at float.jl:119 +(x::Float64,y::Float64) at float.jl:120 +(z::Complex{T<:Real},w::Complex{T<:Real}) at complex.jl:110 +(x::Real,z::Complex{T<:Real}) at complex.jl:120 +(z::Complex{T<:Real},x::Real) at complex.jl:121 +(x::Rational{T<:Integer},y::Rational{T<:Integer}) at rational.jl:113 +(x::Char,y::Char) at char.jl:23 +(x::Char,y::Integer) at char.jl:26 +(x::Integer,y::Char) at char.jl:27 +(a::Float16,b::Float16) at float16.jl:132 +(x::BigInt,y::BigInt) at gmp.jl:195 +(a::BigInt,b::BigInt,c::BigInt) at gmp.jl:218 +(a::BigInt,b::BigInt,c::BigInt,d::BigInt) at gmp.jl:224 +(a::BigInt,b::BigInt,c::BigInt,d::BigInt,e::BigInt) at gmp.jl:231 +(x::BigInt,c::Union(Uint8,Uint16,Uint64,Uint32)) at gmp.jl:243 +(c::Union(Uint8,Uint16,Uint64,Uint32),x::BigInt) at gmp.jl:247 +(x::BigInt,c::Union(Int64,Int32,Int16,Int8)) at gmp.jl:259 +(c::Union(Int64,Int32,Int16,Int8),x::BigInt) at gmp.jl:260 +(x::BigFloat,y::BigFloat) at mpfr.jl:149 +(x::BigFloat,c::Union(Uint8,Uint16,Uint64,Uint32)) at mpfr.jl:156 +(c::Union(Uint8,Uint16,Uint64,Uint32),x::BigFloat) at mpfr.jl:160 +(x::BigFloat,c::Union(Int64,Int32,Int16,Int8)) at mpfr.jl:164 +(c::Union(Int64,Int32,Int16,Int8),x::BigFloat) at mpfr.jl:168 +(x::BigFloat,c::Union(Float16,Float32,Float64)) at mpfr.jl:172 +(c::Union(Float16,Float32,Float64),x::BigFloat) at mpfr.jl:176 +(x::BigFloat,c::BigInt) at mpfr.jl:180 +(c::BigInt,x::BigFloat) at mpfr.jl:184 +(a::BigFloat,b::BigFloat,c::BigFloat) at mpfr.jl:255 +(a::BigFloat,b::BigFloat,c::BigFloat,d::BigFloat) at mpfr.jl:261 +(a::BigFloat,b::BigFloat,c::BigFloat,d::BigFloat,e::BigFloat) at mpfr.jl:268 +(x::MathConst{sym},y::MathConst{sym}) at constants.jl:23 +{T<:Number}(x::T<:Number,y::T<:Number) at promotion.jl:188 +{T<:FloatingPoint}(x::Bool,y::T<:FloatingPoint) at bool.jl:46 +(x::Number,y::Number) at promotion.jl:158 +(x::Integer,y::Ptr{T}) at pointer.jl:68 +(x::Bool,A::AbstractArray{Bool,N}) at array.jl:771 +(x::Number) at operators.jl:71 +(r1::OrdinalRange{T,S},r2::OrdinalRange{T,S}) at operators.jl:325 +{T<:FloatingPoint}(r1::FloatRange{T<:FloatingPoint},r2::FloatRange{T<:FloatingPoint}) at operators.jl:331 +(r1::FloatRange{T<:FloatingPoint},r2::FloatRange{T<:FloatingPoint}) at operators.jl:348 +(r1::FloatRange{T<:FloatingPoint},r2::OrdinalRange{T,S}) at operators.jl:349 +(r1::OrdinalRange{T,S},r2::FloatRange{T<:FloatingPoint}) at operators.jl:350 +(x::Ptr{T},y::Integer) at pointer.jl:66 +{S,T<:Real}(A::Union(SubArray{S,N,A<:DenseArray{T,N},I<:(Union(Int64,Range{Int64})...,)},DenseArray{S,N}),B::Range{T<:Real}) at array.jl:731 +{S<:Real,T}(A::Range{S<:Real},B::Union(DenseArray{T,N},SubArray{T,N,A<:DenseArray{T,N},I<:(Union(Int64,Range{Int64})...,)})) at array.jl:740 +(A::AbstractArray{Bool,N},x::Bool) at array.jl:770 +{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti},B::SparseMatrixCSC{Tv,Ti}) at sparse/sparsematrix.jl:552 +{TvA,TiA,TvB,TiB}(A::SparseMatrixCSC{TvA,TiA},B::SparseMatrixCSC{TvB,TiB}) at sparse/sparsematrix.jl:544 +(A::SparseMatrixCSC{Tv,Ti<:Integer},B::Array{T,N}) at sparse/sparsematrix.jl:643 +(A::Array{T,N},B::SparseMatrixCSC{Tv,Ti<:Integer}) at sparse/sparsematrix.jl:645 +(A::SymTridiagonal{T},B::SymTridiagonal{T}) at linalg/tridiag.jl:57 +(A::Tridiagonal{T},B::Tridiagonal{T}) at linalg/tridiag.jl:247 +(A::Tridiagonal{T},B::SymTridiagonal{T}) at linalg/special.jl:99 +(A::SymTridiagonal{T},B::Tridiagonal{T}) at linalg/special.jl:98 +{T,MT,uplo}(A::Triangular{T,MT,uplo,IsUnit},B::Triangular{T,MT,uplo,IsUnit}) at linalg/triangular.jl:11 +{T,MT,uplo1,uplo2}(A::Triangular{T,MT,uplo1,IsUnit},B::Triangular{T,MT,uplo2,IsUnit}) at linalg/triangular.jl:12 +(Da::Diagonal{T},Db::Diagonal{T}) at linalg/diagonal.jl:47 +(A::Bidiagonal{T},B::Bidiagonal{T}) at linalg/bidiag.jl:92 +{T}(B::BitArray{2},J::UniformScaling{T}) at linalg/uniformscaling.jl:26 +(A::Diagonal{T},B::Bidiagonal{T}) at linalg/special.jl:89 +(A::Bidiagonal{T},B::Diagonal{T}) at linalg/special.jl:90 +(A::Diagonal{T},B::Tridiagonal{T}) at linalg/special.jl:89 +(A::Tridiagonal{T},B::Diagonal{T}) at linalg/special.jl:90 +(A::Diagonal{T},B::Triangular{T,S<:AbstractArray{T,2},UpLo,IsUnit}) at linalg/special.jl:89 +(A::Triangular{T,S<:AbstractArray{T,2},UpLo,IsUnit},B::Diagonal{T}) at linalg/special.jl:90 +(A::Diagonal{T},B::Array{T,2}) at linalg/special.jl:89 +(A::Array{T,2},B::Diagonal{T}) at linalg/special.jl:90 +(A::Bidiagonal{T},B::Tridiagonal{T}) at linalg/special.jl:89 +(A::Tridiagonal{T},B::Bidiagonal{T}) at linalg/special.jl:90 +(A::Bidiagonal{T},B::Triangular{T,S<:AbstractArray{T,2},UpLo,IsUnit}) at linalg/special.jl:89 +(A::Triangular{T,S<:AbstractArray{T,2},UpLo,IsUnit},B::Bidiagonal{T}) at linalg/special.jl:90 +(A::Bidiagonal{T},B::Array{T,2}) at linalg/special.jl:89 +(A::Array{T,2},B::Bidiagonal{T}) at linalg/special.jl:90 +(A::Tridiagonal{T},B::Triangular{T,S<:AbstractArray{T,2},UpLo,IsUnit}) at linalg/special.jl:89 +(A::Triangular{T,S<:AbstractArray{T,2},UpLo,IsUnit},B::Tridiagonal{T}) at linalg/special.jl:90 +(A::Tridiagonal{T},B::Array{T,2}) at linalg/special.jl:89 +(A::Array{T,2},B::Tridiagonal{T}) at linalg/special.jl:90 +(A::Triangular{T,S<:AbstractArray{T,2},UpLo,IsUnit},B::Array{T,2}) at linalg/special.jl:89 +(A::Array{T,2},B::Triangular{T,S<:AbstractArray{T,2},UpLo,IsUnit}) at linalg/special.jl:90 +(A::SymTridiagonal{T},B::Triangular{T,S<:AbstractArray{T,2},UpLo,IsUnit}) at linalg/special.jl:98 +(A::Triangular{T,S<:AbstractArray{T,2},UpLo,IsUnit},B::SymTridiagonal{T}) at linalg/special.jl:99 +(A::SymTridiagonal{T},B::Array{T,2}) at linalg/special.jl:98 +(A::Array{T,2},B::SymTridiagonal{T}) at linalg/special.jl:99 +(A::Diagonal{T},B::SymTridiagonal{T}) at linalg/special.jl:107 +(A::SymTridiagonal{T},B::Diagonal{T}) at linalg/special.jl:108 +(A::Bidiagonal{T},B::SymTridiagonal{T}) at linalg/special.jl:107 +(A::SymTridiagonal{T},B::Bidiagonal{T}) at linalg/special.jl:108 +{T<:Number}(x::AbstractArray{T<:Number,N}) at abstractarray.jl:362 +(A::AbstractArray{T,N},x::Number) at array.jl:774 +(x::Number,A::AbstractArray{T,N}) at array.jl:775 +(J1::UniformScaling{T<:Number},J2::UniformScaling{T<:Number}) at linalg/uniformscaling.jl:25 +(J::UniformScaling{T<:Number},B::BitArray{2}) at linalg/uniformscaling.jl:27 +(J::UniformScaling{T<:Number},A::AbstractArray{T,2}) at linalg/uniformscaling.jl:28 +(J::UniformScaling{T<:Number},x::Number) at linalg/uniformscaling.jl:29 +(x::Number,J::UniformScaling{T<:Number}) at linalg/uniformscaling.jl:30 +{TA,TJ}(A::AbstractArray{TA,2},J::UniformScaling{TJ}) at linalg/uniformscaling.jl:33 +{T}(a::HierarchicalValue{T},b::HierarchicalValue{T}) at pkg/resolve/versionweight.jl:19 +(a::VWPreBuildItem,b::VWPreBuildItem) at pkg/resolve/versionweight.jl:82 +(a::VWPreBuild,b::VWPreBuild) at pkg/resolve/versionweight.jl:120 +(a::VersionWeight,b::VersionWeight) at pkg/resolve/versionweight.jl:164 +(a::FieldValue,b::FieldValue) at pkg/resolve/fieldvalue.jl:41 +(a::Vec2,b::Vec2) at graphics.jl:60 +(bb1::BoundingBox,bb2::BoundingBox) at graphics.jl:123 +(p1::Particula,p2::Particula) at In[48]:2 +(a,b,c) at operators.jl:82 +(a,b,c,xs...) at operators.jl:83

``````
``````

In [52]:

using ValidatedNumerics

``````
``````

Warning: Method definition IPv4(String,) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:31 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:31.
Warning: Method definition IPv6(String,) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:32 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:32.
Warning: Method definition isless(T<:IpAddr,T<:IpAddr) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:37 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:37.
Warning: Method definition Dict(Any,) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:49 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:49.
Warning: Method definition round(Type{T<:Integer},Integer) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:65 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:65.
Warning: Method definition round(Type{T<:Integer},Real) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:66 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:66.
Warning: Method definition round(Type{T<:Integer},Rational{T<:Integer}) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:67 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:67.
Warning: Method definition round(Type{T},AbstractArray{R,1}) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:69 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:69.
Warning: Method definition round(Type{T},AbstractArray{R,2}) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:72 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:72.
Warning: Method definition round(Type{T},AbstractArray{T,N}) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:75 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:75.
Warning: Method definition ceil(Type{T<:Integer},Integer) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:65 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:65.
Warning: Method definition ceil(Type{T<:Integer},Real) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:66 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:66.
Warning: Method definition ceil(Type{T<:Integer},Rational{T<:Integer}) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:67 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:67.
Warning: Method definition ceil(Type{T},AbstractArray{R,1}) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:69 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:69.
Warning: Method definition ceil(Type{T},AbstractArray{R,2}) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:72 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:72.
Warning: Method definition ceil(Type{T},AbstractArray{T,N}) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:75 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:75.
Warning: Method definition floor(Type{T<:Integer},Integer) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:65 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:65.
Warning: Method definition floor(Type{T<:Integer},Real) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:66 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:66.
Warning: Method definition floor(Type{T<:Integer},Rational{T<:Integer}) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:67 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:67.
Warning: Method definition floor(Type{T},AbstractArray{R,1}) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:69 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:69.
Warning: Method definition floor(Type{T},AbstractArray{R,2}) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:72 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:72.
Warning: Method definition floor(Type{T},AbstractArray{T,N}) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:75 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:75.
Warning: Method definition trunc(Type{T<:Integer},Integer) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:65 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:65.
Warning: Method definition trunc(Type{T<:Integer},Real) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:66 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:66.
Warning: Method definition trunc(Type{T<:Integer},Rational{T<:Integer}) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:67 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:67.
Warning: Method definition trunc(Type{T},AbstractArray{R,1}) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:69 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:69.
Warning: Method definition trunc(Type{T},AbstractArray{R,2}) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:72 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:72.
Warning: Method definition trunc(Type{T},AbstractArray{T,N}) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:75 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:75.
Warning: Method definition rand(Type{Bool},) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:182 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:182.
Warning: Method definition parse(Type{T<:Integer},Char) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:203 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:203.
Warning: Method definition parse(Type{T<:Integer},Char,Integer) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:204 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:204.
Warning: Method definition parse(Type{T<:Integer},String) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:205 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:205.
Warning: Method definition parse(Type{T<:Integer},String,Integer) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:206 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:206.
Warning: Method definition parse(Type{T<:Union(Float32,Float64)},String) in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:207 overwritten in module Compat at /Users/dsanders/.julia/v0.3/Compat/src/Compat.jl:207.

``````
``````

In [53]:

a = Interval(1, 2)

``````
``````

Out[53]:

[1, 2]

``````
``````

In [54]:

b = Interval(3, 4)

``````
``````

Out[54]:

[3, 4]

``````
``````

In [55]:

a + b

``````
``````

Out[55]:

[4, 6]

``````
``````

In [56]:

a - b

``````
``````

Out[56]:

[-3, -1]

``````
``````

In [57]:

Interval(0.1)

``````
``````

Out[57]:

[0.1, 0.1]

``````
``````

In [58]:

big(0.1)

``````
``````

Out[58]:

1.0000000000000001e-01 with 53 bits of precision

``````
``````

In [59]:

@interval(0.1)

``````
``````

Out[59]:

[9.9999999999999992e-02, 1.0000000000000001e-01]₅₃

``````
``````

In [60]:

macroexpand(:(@interval(0.1)))

``````
``````

Out[60]:

:(ValidatedNumerics.big_transf(0.1))

``````
``````

In [61]:

ValidatedNumerics.big_transf(0.1)

``````
``````

Out[61]:

[9.9999999999999992e-02, 1.0000000000000001e-01]₅₃

``````
``````

In [64]:

s = "x + y"

``````
``````

Out[64]:

"x + y"

``````
``````

In [66]:

typeof(s)

``````
``````

Out[66]:

ASCIIString (constructor with 2 methods)

``````
``````

In [67]:

expr = parse(s)

``````
``````

Out[67]:

:(x + y)

``````
``````

In [69]:

typeof(expr)

``````
``````

Out[69]:

Expr

``````
``````

In [70]:

dump(expr)

``````
``````

Expr
args: Array(Any,(3,))
1: Symbol +
2: Symbol x
3: Symbol y
typ: Any

``````
``````

In [71]:

expr.args

``````
``````

Out[71]:

3-element Array{Any,1}:
:+
:x
:y

``````
``````

In [72]:

expr.args[2] = :z

``````
``````

Out[72]:

:z

``````
``````

In [73]:

expr

``````
``````

Out[73]:

:(z + y)

``````
``````

In [74]:

z

``````
``````

z not defined

``````
``````

In [75]:

y

``````
``````

y not defined

``````
``````

In [76]:

z = 3
y = 4

``````
``````

Out[76]:

4

``````
``````

In [77]:

eval(expr)

``````
``````

Out[77]:

7

``````
``````

In [78]:

expr

``````
``````

Out[78]:

:(z + y)

``````
``````

In [79]:

z

``````
``````

Out[79]:

3

``````
``````

In [80]:

:z

``````
``````

Out[80]:

:z

``````
``````

In [81]:

z = [3, 4]
y = [4, 5]

``````
``````

Out[81]:

2-element Array{Int64,1}:
4
5

``````
``````

In [82]:

eval(expr)

``````
``````

Out[82]:

2-element Array{Int64,1}:
7
9

``````
``````

In [83]:

z = Particula(1,2,3)
y = Particula(10, 20, 30)

``````
``````

Out[83]:

Particula(10,20,30)

``````
``````

In [85]:

eval(expr)

``````
``````

Out[85]:

Particula(11,22,93)

``````
``````

In [86]:

``````
``````

Out[86]:

Particula(11,22,93)

``````
``````

In [91]:

macro transf(expr)
@show expr
expr.args[2] = :z
@show expr
end

``````
``````

In [92]:

@transf(x+y)

``````
``````

expr => :(x + y)
expr => :(z + y)

Out[92]:

Particula(11,22,93)

``````
``````

In [93]:

@transf(x+x)

``````
``````

expr => :(x + x)
expr => :(z + x)

x not defined

``````
``````

In [95]:

macro transf(expr)
@show expr
for i in 2:length(expr.args)
if expr.args[i] == :x
expr.args[i] = :z
end
end
@show expr
end

``````
``````

In [96]:

@transf(x+y)

``````
``````

expr => :(x + y)
expr => :(z + y)

Out[96]:

Particula(11,22,93)

``````
``````

In [97]:

@transf(x+x)

``````
``````

expr => :(x + x)
expr => :(z + z)

Out[97]:

Particula(2,4,12)

``````
``````

In [98]:

@transf(2*x)

``````
``````

expr => :(2x)
expr => :(2z)

`*` has no method matching *(::Int64, ::Particula)

``````
``````

In [100]:

z = 3

``````
``````

Out[100]:

3

``````
``````

In [101]:

@transf(2*x)

``````
``````

expr => :(2x)
expr => :(2z)

Out[101]:

6

``````
``````

In [102]:

macroexpand(:(@transf(x+y)))

``````
``````

expr => :(x + y)
expr => :(z + y)

Out[102]:

:(z + y)

``````
``````

In [103]:

macroexpand(:(@time sin(10)))

``````
``````

Out[103]:

quote  # util.jl, line 53:
local #436#b0 = LastMain.Base.gc_bytes() # line 54:
local #437#t0 = LastMain.Base.time_ns() # line 55:
local #438#g0 = LastMain.Base.gc_time_ns() # line 56:
local #439#val = sin(10) # line 57:
local #440#g1 = LastMain.Base.gc_time_ns() # line 58:
local #441#t1 = LastMain.Base.time_ns() # line 59:
local #442#b1 = LastMain.Base.gc_bytes() # line 60:
LastMain.Base.time_print(LastMain.Base.-(#441#t1,#437#t0),LastMain.Base.-(#442#b1,#436#b0),LastMain.Base.-(#440#g1,#438#g0)) # line 61:
#439#val
end

``````
``````

In [104]:

s = :x

``````
``````

Out[104]:

:x

``````
``````

In [105]:

typeof(s)

``````
``````

Out[105]:

Symbol

``````
``````

In [107]:

ex = :(x + y)

``````
``````

Out[107]:

:(x + y)

``````
``````

In [108]:

typeof(ex)

``````
``````

Out[108]:

Expr

``````
``````

In [109]:

ex = :(x + 3y^2 - sin(16))

``````
``````

Out[109]:

:((x + 3 * y^2) - sin(16))

``````
``````

In [110]:

typeof(ex)

``````
``````

Out[110]:

Expr

``````
``````

In [111]:

dump(ex)

``````
``````

Expr
args: Array(Any,(3,))
1: Symbol -
2: Expr
args: Array(Any,(3,))
1: Symbol +
2: Symbol x
3: Expr
args: Array(Any,(3,))
typ: Any
typ: Any
3: Expr
args: Array(Any,(2,))
1: Symbol sin
2: Int64 16
typ: Any
typ: Any

``````
``````

In [112]:

ex = :(eig(M))

``````
``````

Out[112]:

:(eig(M))

``````
``````

In [113]:

dump

``````
``````

Out[113]:

dump (generic function with 12 methods)

``````
``````

In [114]:

dump(ex)

``````
``````

Expr
args: Array(Any,(2,))
1: Symbol eig
2: Symbol M
typ: Any

``````
``````

In [115]:

Meta.show_sexpr(ex)

``````
``````

(:call, :eig, :M)

``````
``````

In [ ]:

``````