Skip to content

Commit

Permalink
refined interval computations and compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed Jul 7, 2018
1 parent ac37e9f commit c348a7a
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 45 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ os:
- osx
julia:
- 0.6
- 0.7
- nightly
matrix:
allow_failures:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Installation of latest release version using Julia:
```Julia
julia> Pkg.add("Dendriform")
```
Provides the types `PBTree` for planar binary trees, `Grove` for tree collections of constant degree, and `GroveBin` to compress grove data. This package defines various essential operations on planar binary trees and groves like `` for `union`; `` for `graft`; `left` and `right` for branching; ``, ``, `<`, `>`, ``, `` for Tamari's partial ordering; `` for `between`; `` and `` (i.e. `over` and `under`); and the `dashv` and `vdash` operations ``, ``, `+`, `*` for dendriform algebra.
Provides the types `PBTree` for planar binary trees, `Grove` for tree collections of constant degree, and `GroveBin` to compress grove data. This package defines various essential operations on planar binary trees and groves like `` for `union`; `` for `graft`; `left` and `right` for branching; ``, ``, `<`, `>`, ``, `` for Tamari's partial ordering; `` for `between`; `/` and `\` (i.e. `over` and `under`); and the `dashv` and `vdash` operations ``, ``, `+`, `*` for dendriform algebra.

View the documentation [stable](https://chakravala.github.io/Dendriform.jl/stable) / [latest](https://chakravala.github.io/Dendriform.jl/latest) for more features and examples.

Expand Down
16 changes: 14 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

matrix:
allow_failures:
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

branches:
only:
Expand All @@ -18,6 +25,11 @@ notifications:

install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# If there's a newer build queued for the same PR, cancel this one
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
throw "There are newer queued builds for this pull request, failing early." }
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$env:JULIA_URL,
Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Installation of latest release version using Julia:
```Julia
julia> Pkg.add("Dendriform")
```
Provides the types `PBTree` for planar binary trees, `Grove` for tree collections of constant degree, and `GroveBin` to compress grove data. This package defines various essential operations on planar binary trees and groves like `` for `union`; `` for `graft`; `left` and `right` for branching; `<`, `>`, ``, `` for Tamari's partial ordering; `` and `` (i.e. `over` and `under`); and the `dashv` and `vdash` operations ``, ``, `+`, `*` for dendriform algebra.
Provides the types `PBTree` for planar binary trees, `Grove` for tree collections of constant degree, and `GroveBin` to compress grove data. This package defines various essential operations on planar binary trees and groves like `` for `union`; `` for `graft`; `left` and `right` for branching; `<`, `>`, ``, `` for Tamari's partial ordering; `/` and `\` (i.e. `over` and `under`); and the `dashv` and `vdash` operations ``, ``, `+`, `*` for dendriform algebra.

## Background

Expand Down
8 changes: 0 additions & 8 deletions docs/src/library.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,6 @@ over
under
```

```@docs
```

```@docs
```

```@docs
/
```
Expand Down
14 changes: 8 additions & 6 deletions src/Dendriform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ module Dendriform
# This file is part of Dendriform.jl. It is licensed under the GPL license
# Dendriform Copyright (C) 2017 Michael Reed

using Combinatorics, Compat

export PBTree, Grove, GroveBin, ==, Cn, grovesort, grovesort!, σ, print, grovecomposition, grovedisplay

import Base: ==, +,*, /, , <, >, , , promote_rule, convert, show, print

# definitions

abstract type AbstractGrove end

importall Base
using Combinatorics, Compat

"""
Planar Binary Tree with Loday's notation
Expand Down Expand Up @@ -144,6 +145,7 @@ GroveBin(d::UI8I,s::Int,i::Integer) = GroveBin(UInt8(d),s,i,Float16(100i//(2^Cn(
==(a::PBTree,b::PBTree)=(a.degr == b.degr && a.Y == b.Y)
==(a::Grove,b::Grove)=(a.degr==b.degr && a.size==b.size && grovesort!(a).Y==grovesort!(b).Y)
==(a::BaseTree,b::BaseTree)=(a.μ==b.μ)
==(a::GroveBin,b::GroveBin)=(a.degr==b.degr && a.size==b.size && a.gbin==b.gbin)

# conversions / promotions

Expand All @@ -167,8 +169,8 @@ convert(::Type{Grove},g::Array{Any,1}) = convert(Grove,convert(Array{UInt8,1},g)
convert(::Type{Grove},g::Array{Any,2}) = convert(Grove,convert(Array{UInt8,2},g))
convert(::Type{Grove},g::GroveBin) = Grove(g.degr,g.gbin)
convert(::Type{Grove},d::UI8I) = Υ(UInt8(d))
promote_rule{T<:Ar1UI8I}(::Type{PBTree},::Type{T}) = PBTree
promote_rule{T<:Union{Ar1UI8I,Ar2UI8I,PBTree,UI8I}}(::Type{Grove},::Type{T})=Grove
promote_rule(::Type{PBTree},::Type{T}) where T<:Ar1UI8I = PBTree
promote_rule(::Type{Grove},::Type{T}) where T<:Union{Ar1UI8I,Ar2UI8I,PBTree,UI8I} = Grove

# display

Expand Down Expand Up @@ -410,7 +412,7 @@ function print(io::IO,υ::PBTree,μ::BaseTree)
if grovedisplay()
print(io,"")
for ω 1:length.Y)
μ.μ[ω]==[] ? print(io,''):show(io,convert(Array{Int,1},μ.μ[ω]))
μ.μ[ω]==[] ? print(io,'') : show(io,convert(Array{Int,1},μ.μ[ω]))
end
print(io,"")
print(io,tin,"/",Cn(n)," or ")
Expand Down
10 changes: 5 additions & 5 deletions src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ function ∪(x::Grove,y::Vararg{Grove})
s += y[i].size
end
s = s - out.size
s 0 && info("$s duplicate$(s>1?'s':"") in grove union")
s 0 && info("$s duplicate$(s>1 ? 's' : "") in grove union")
return out
end

(x::NotGrove,y::Vararg{Grove}) = (convert(Grove,x),y...)
{T<:Union{NotGrove,Grove}}(x::Grove,y::Vararg{T}) = (promote(x,y...)...)
{T<:NotGrove}(x::NotGrove,y::Vararg{T}) = (promote(convert(Grove,x),y...)...)
(x::Grove,y::Vararg{T}) where T<:Union{NotGrove,Grove} = (promote(x,y...)...)
(x::NotGrove,y::Vararg{T}) where T<:NotGrove = (promote(convert(Grove,x),y...)...)
(x::NotGrove) = Grove(x); (x::Grove) = x

# grafting
Expand Down Expand Up @@ -64,7 +64,7 @@ Returns the left branch of an AbstractPBTree
"""
function left(t::PBTree)
fx = findfirst->==t.degr),t.Y)
fx>1 && (return PBTree(fx-1,t.Y[1:fx-1]))
typeof(fx) == Int && fx>1 && (return PBTree(fx-1,t.Y[1:fx-1]))
return PBTree(0x00,Array{UInt8,1}(0))
end

Expand All @@ -77,7 +77,7 @@ Returns the right branch of an AbstractPBTree
"""
function right(t::PBTree)
fx = findfirst->==t.degr),t.Y)
fx<t.degr && (return PBTree(t.Y[fx+1:end]))
typeof(fx) == Int && fx<t.degr && (return PBTree(t.Y[fx+1:end]))
return PBTree(0x00,Array{UInt8,1}(0))
end

Expand Down
5 changes: 3 additions & 2 deletions src/morphism.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Returns Bool that tells if PBTree is valid
treecheck(d::UI8I,t::Int) = t > 0 && t <= Cn(d)
treecheck(t::PBTree) = treecheck(t.degr,treeindex(t))
treecheck(t::Ar1UI8I) = treecheck(convert(PBTree,t))
treecheck(g::Grove) = findfirst(x->(x==0),treeindex(g)) == 0
treecheck(g::Grove) = findfirst(x->(x==0),treeindex(g)) == (VERSION < v"0.7.0" ? 0 : nothing)
treecheck(g::NotGrove) = treecheck(convert(Grove,g))

"""
Expand Down Expand Up @@ -72,7 +72,8 @@ function treeindex(d::UI8I,l::Int,g::Ar2UI8I)
ind=Array{Int,1}(l)
i=TreeInteger(g)
for c 1:l
ind[c] = findfirst(v.==i[c])
indc = findfirst(v.==i[c])
ind[c] = indc == nothing ? 0 : indc
end
return ind
end
Expand Down
113 changes: 94 additions & 19 deletions src/poset.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is part of Dendriform.jl. It is licensed under the GPL license
# Dendriform Copyright (C) 2017 Michael Reed

export , , posetnext, posetprev, between, , over, under, ↗, ↖
export , , posetnext, posetprev, between, , over, under

# poset coverings

Expand Down Expand Up @@ -179,43 +179,118 @@ import Base: /, \
"""
over(a::AbstractPBTree, b::AbstractPBTree)
Returns PBTRee obtained from a over b operation
Returns PBTree obtained from a over b operation
"""
over(x::PBTree,y::PBTree) = y.degr > 0 ? over(x,left(y)) right(y) : x
over(x::AbstractPBTree,y::AbstractPBTree) = over(PBTree(x),PBTree(y))

"""
↗(a::AbstractPBTree, b::AbstractPBTree)
Returns PBTRee obtained from a over b operation
"""
↗(x::AbstractPBTree,y::AbstractPBTree) = over(x,y)

"""
/(a::PBTree, b::PBTree)
Returns PBTRee obtained from a over b operation
Returns PBTree obtained from a over b operation
"""
/(x::PBTree,y::PBTree) = over(x,y)

"""
under(a::AbstractPBTree, b::AbstractPBTree)
Returns PBTRee obtained from a under b operation
Returns PBTree obtained from a under b operation
"""
under(x::PBTree,y::PBTree) = x.degr > 0 ? left(x) under(right(x),y) : y
under(x::AbstractPBTree,y::AbstractPBTree) = under(PBTree(x),PBTree(y))

"""
(a::AbstractPBTree, b::AbstractPBTree)
\\(a::PBTree, b::PBTree)
Returns PBTRee obtained from a under b operation
Returns PBTree obtained from a under b operation
"""
(x::AbstractPBTree,y::AbstractPBTree) = under(x,y)
\(x::PBTree,y::PBTree) = under(x,y)

"""
\(a::PBTree, b::PBTree)
# interval tools

Returns PBTRee obtained from a under b operation
"""
\(x::PBTree,y::PBTree) = under(x,y)
function intervals(d::Int)
g = Array{BigInt,1}()
for i1:Int(Cn(d)),j1:Int(Cn(d))
t = PBTree(d,i) PBTree(d,j)
t Grove(0) && push!(g,GroveBin(t).gbin)
end
return sort!(g)
end

function intcomp(d::Int)
ins = intervals(d)
lins = length(ins)
cc = zeros(Int,lins)
cn = 0
for q 1:d-1
for i 1:Int(groveindex(Grove(q))), j 1:Int(groveindex(Grove(d-q)))
z = GroveBin(Grove(q,i) + Grove(d-q,j))
f = find(s->s==z.gbin, ins)
length(f) == 0 ? (cn += 1) : (cc[f] += 1)
end
end
info("Non-intervals: $cn")
return cc
end

function intcompt(d::Int)
ins = intervals(d)
lins = length(ins)
cc = zeros(Int,lins)
cn = 0
for q 1:d-1
for i 1:Int(Cn(q)), j 1:Int(Cn(d-q))
z = GroveBin(PBTree(q,i) + PBTree(d-q,j))
f = find(s->s==z.gbin, ins)
length(f) == 0 ? (cn += 1) : (cc[f] += 1)
end
end
#info("Non-intervals: $cn")
return cc
end

function between_list_full(a::PBTree,b::PBTree)
a == b && return true
h = posetnext_list(a)
not = true
for i 1:length(h)
if h[i] b
not = not & between_list_full(h[i],b)
else
not = false
end
end
return not
end

function intervals_full(d::Int)
g = Array{BigInt,1}()
f = BitArray{1}()
for i1:Int(Cn(d)),j1:Int(Cn(d))
t = PBTree(d,i) PBTree(d,j)
t Grove(0) && (push!(g,GroveBin(t).gbin);push!(f,between_list_full(PBTree(d,i),PBTree(d,j))))
end
return f[sortperm(g)]
end

function print_interval_bin(d::Int)
ins = intervals(d)
for i ins
lpad(bin(i),Cn(d),"0") |> println
end
end

function print_intcomp_bin(d::Int)
ins = intervals(d)[find(s->s>0,intcomp(d))]
inst = intervals(d)[find(s->s>0,intcompt(d))]
for i ins
i inst && (lpad(bin(i),Cn(d),"0") |> println)
end
end

function print_intcompt_bin(d::Int)
ins = intervals(d)[find(s->s>0,intcompt(d))]
for i ins
lpad(bin(i),Cn(d),"0") |> println
end
end
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ d = 5
grovedisplay(false)
@test ((x,y)=(Grove(3,7),Grove(2,1)); σ(x+y)==σ(y)+σ(x) && σ(x*y)==σ(x)*σ(y))
@test ((x,y)=(PBTree(3,4),PBTree(4,7)); σ(xy)==σ(y)σ(x)
&& σ((x,y))==(σ(y),σ(x)) && σ((x,y))==(σ(y),σ(x)))
&& σ(/(x,y))==\(σ(y),σ(x)) && σ(\(x,y))==/(σ(y),σ(x)))
@test (PBTree(1,1) / PBTree(1,1)) == σ(PBTree(1,1) \ PBTree(1,1))
@test (f=PBTree([1,2,5,2,1,11,1,2,5,2,1]); ==(typeof.([Dendriform.posetprev(f),Dendriform.posetnext(f)])...))
@test [1,3,1] [3,2,1] && [3,2,1] [1,3,1]
Expand Down

0 comments on commit c348a7a

Please sign in to comment.