Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Add some unicode function synonyms and infix operators #6582

Merged
merged 20 commits into from
May 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0625671
Add ⊗ as synonym for kron
jiahao Apr 19, 2014
2a26899
Add √ as synonym for sqrt
jiahao Apr 19, 2014
fae924a
Add obelus (÷) as synonym for div
jiahao Apr 19, 2014
67ce8b5
Add ∅ (empty set) as synonym for Set{Any}({})
jiahao Apr 19, 2014
01d98fe
Add ∈ as synonym for `in` and ∋ for containment
jiahao Apr 19, 2014
edf4e3d
Add ⋅ as synonym for `dot`
jiahao Apr 19, 2014
7369326
Add ⊆ as synonym for `issubset`
jiahao Apr 19, 2014
ad12241
More set relations ⊈, ⊂, ⊄, ⊊.
jiahao Apr 19, 2014
e81e2bb
Add ∩ and ∪ as synonyms for `intersect` and `union` resp.
jiahao Apr 19, 2014
73f65ed
Add △ as synonym for `symdiff`
jiahao Apr 19, 2014
6036e78
Add negated element containments ∉, ∌
jiahao Apr 19, 2014
672ca6e
More comparsion operators ≠ (!=), ≡ (===), ≢ (!==), ≤ (<=), ≥ (>=), .…
jiahao Apr 19, 2014
915ba49
Add double solidus (⫽) as synonym for rational division (//)
jiahao Apr 19, 2014
efcc36b
Adds ∣ (divides) and its negation ∤
jiahao Apr 19, 2014
971756a
Add × (cross product) as synonym for `cross`
jiahao Apr 19, 2014
3cd38a5
Remove ∅ (empty set) and undefines ⊂ and ⊄
jiahao Apr 19, 2014
4a98190
Changed operator precedence for ∩ and ∪. Undefine △.
jiahao Apr 22, 2014
a243cc6
Add ∨ and ∧, and circled and boxed arithmetic operators
jiahao Apr 22, 2014
e4fbbef
Merge branch 'master' of github.com:JuliaLang/julia into uniops-552
JeffBezanson May 3, 2014
970938e
update set of unicode operators and fix exports
JeffBezanson May 3, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,23 +190,29 @@ export
# Operators
!,
!=,
≠,
!==,
≡,
≢,
$,
%,
&,
*,
+,
-,
.!=,
.≠,
.+,
.-,
.*,
./,
.<,
.<=,
.≤,
.==,
.>,
.>=,
.≥,
.\,
.^,
/,
Expand All @@ -215,9 +221,11 @@ export
<:,
<<,
<=,
≤,
==,
>,
>=,
≥,
>>,
#.>>,
#.<<,
Expand All @@ -227,6 +235,7 @@ export
|,
~,
:,
÷,
A_ldiv_B!,
A_ldiv_Bc,
A_ldiv_Bt,
Expand Down Expand Up @@ -442,6 +451,7 @@ export
unsigned,
widemul,
zero,
√,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for cbrt?

for angle?

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to parse as a prefix operator.


# specfun
airy,
Expand Down Expand Up @@ -660,6 +670,8 @@ export
triu!,
triu,
vecnorm,
⋅,
×,

# sparse
etree,
Expand Down Expand Up @@ -746,6 +758,17 @@ export
union,
unique,
values,
∈,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for all?

∉,
∋,
∌,
⊆,
⊈,
⊂,
⊄,
⊊,
∩,
∪,

# strings and text output
ascii,
Expand Down
3 changes: 2 additions & 1 deletion base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export sin, cos, tan, sinh, cosh, tanh, asin, acos, atan,
besselj0, besselj1, besselj, bessely0, bessely1, bessely,
hankelh1, hankelh2, besseli, besselk, besselh,
beta, lbeta, eta, zeta, polygamma, invdigamma, digamma, trigamma,
erfinv, erfcinv
erfinv, erfcinv, √

import Base: log, exp, sin, cos, tan, sinh, cosh, tanh, asin,
acos, atan, asinh, acosh, atanh, sqrt, log2, log10,
Expand Down Expand Up @@ -284,6 +284,7 @@ sqrt(x::Float64) = box(Float64,sqrt_llvm(unbox(Float64,x)))
sqrt(x::Float32) = box(Float32,sqrt_llvm(unbox(Float32,x)))
sqrt(x::Real) = sqrt(float(x))
@vectorize_1arg Number sqrt
const √=sqrt

for f in (:ceil, :trunc, :significand) # :rint, :nearbyint
@eval begin
Expand Down
33 changes: 30 additions & 3 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ isequal(T::Type, S::Type) = typeseq(T, S)
isequal(x,y) = is(x,y)
==(x,y) = isequal(x,y)
!=(x,y) = !(x==y)
const ≠ = !=
const ≡ = is
!==(x,y) = !is(x,y)

const ≢ = !==
< (x,y) = isless(x,y)
> (x,y) = y < x
<=(x,y) = !(y < x)
const ≤ = <=
>=(x,y) = (y <= x)
const ≥ = >=
.> (x,y) = y.<x
.>=(x,y) = y.<=x
const .≥ = .>=

# this definition allows Number types to implement < instead of isless,
# which is more idiomatic:
Expand Down Expand Up @@ -84,6 +89,8 @@ end
.!=(x::Number,y::Number) = x!=y
.< (x::Real,y::Real) = x<y
.<=(x::Real,y::Real) = x<=y
const .≤ = .<=
const .≠ = .!=

# core << >> and >>> takes Int32 as second arg
<<(x,y::Integer) = x << convert(Int32,y)
Expand All @@ -104,6 +111,7 @@ fld{T<:Real}(x::T, y::T) = convert(T,round((x-mod(x,y))/y))
# operator alias
const % = rem
.%(x::Real, y::Real) = x%y
const ÷ = div

# mod returns in [0,y) whereas mod1 returns in (0,y]
mod1{T<:Real}(x::T, y::T) = y-mod(y-x,y)
Expand Down Expand Up @@ -343,7 +351,7 @@ function ifelse(c::AbstractArray{Bool}, x, y::AbstractArray)
end

# some operators not defined yet
global //, .>>, .<<, >:, <|, |>, hcat, hvcat
global //, .>>, .<<, >:, <|, |>, hcat, hvcat, ⋅, ×, ∈, ∉, ∋, ∌, ⊆, ⊈, ⊊, ∩, ∪

module Operators

Expand Down Expand Up @@ -380,6 +388,12 @@ export
==,
>,
>=,
≥,
≤,
≠,
.≥,
.≤,
.≠,
>>,
.>>,
.<<,
Expand All @@ -390,6 +404,18 @@ export
|>,
<|,
~,
÷,
⋅,
×,
∈,
∉,
∋,
∌,
⊆,
⊈,
⊊,
∩,
∪,
colon,
hcat,
vcat,
Expand All @@ -402,6 +428,7 @@ export
import Base: !, !=, $, %, .%, &, *, +, -, .!=, .+, .-, .*, ./, .<, .<=, .==, .>,
.>=, .\, .^, /, //, <, <:, <<, <=, ==, >, >=, >>, .>>, .<<, >>>,
<|, |>, \, ^, |, ~, !==, >:, colon, hcat, vcat, hvcat, getindex, setindex!,
transpose, ctranspose
transpose, ctranspose,
≥, ≤, ≠, .≥, .≤, .≠, ÷, ⋅, ×, ∈, ∉, ∋, ∌, ⊆, ⊈, ⊊, ∩, ∪

end
4 changes: 4 additions & 0 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ function in(x, itr)
end
return false
end
const ∈ = in
∉(x, itr)=!∈(x, itr)
∋(itr, x)= ∈(x, itr)
∌(itr, x)=!∋(itr, x)

function contains(itr, x)
depwarn("contains(collection, item) is deprecated, use in(item, collection) instead", :contains)
Expand Down
5 changes: 5 additions & 0 deletions base/set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function union(s::Set, sets::Set...)
end
return u
end
const ∪ = union

intersect(s::Set) = copy(s)
function intersect(s::Set, sets::Set...)
Expand All @@ -64,6 +65,7 @@ function intersect(s::Set, sets::Set...)
end
return i
end
const ∩ = intersect

function setdiff(a::Set, b::Set)
d = copy(a)
Expand All @@ -85,6 +87,9 @@ function issubset(l, r)
end
return true
end
const ⊆ = issubset
⊊(l::Set, r::Set) = ⊆(l, r) && l!=r
⊈(l::Set, r::Set) = !⊆(l, r)

function unique(C)
out = Array(eltype(C),0)
Expand Down
2 changes: 2 additions & 0 deletions base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ include("sparse.jl")
importall .SparseMatrix
include("linalg.jl")
importall .LinAlg
const ⋅ = dot
const × = cross
include("broadcast.jl")
importall .Broadcast

Expand Down
6 changes: 3 additions & 3 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
; the way the lexer works, every prefix of an operator must also
; be an operator.
(-- -->)
(> < >= <= == === != !== |.>| |.<| |.>=| |.<=| |.==| |.!=| |.=| |.!| |<:| |>:|)
(> < >= <= == === != !== |.>| |.<| |.>=| |.≥| |.<=| |.≤| |.==| |.!=| |.≠| |.=| |.!| |<:| |>:| ∈ ∉ ∋ ∌ ⊆ ⊈ ⊂ ⊄ ⊊)
(|\|>| |<\||)
(: |..|)
(+ - |.+| |.-| |\|| $)
(+ - ⊕ ⊖ ⊞ ⊟ |.+| |.-| |\|| ∪ ∨ $ ⊓)
(<< >> >>> |.<<| |.>>| |.>>>|)
(* / |./| % |.%| & |.*| |\\| |.\\|)
(* / |./| ÷ % ⋅ ∘ × |.%| |.*| |\\| |.\\| & ∩ ∧ ⊗ ⊘ ⊙ ⊚ ⊛ ⊠ ⊡ ⊔)
(// .//)
(^ |.^|)
(|::|)
Expand Down