Skip to content

Commit

Permalink
Some changes
Browse files Browse the repository at this point in the history
Following changes are made:
- [x] Dropped support for `/(p1::Poly, p2::Poly)` as per
  JuliaLang/METADATA.jl#7467, and,
- [x] Fixed a couple of `ERROR`-related typos in `README`.
  • Loading branch information
Arda Aytekin committed Jan 8, 2017
1 parent e859790 commit bce8961
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 43 deletions.
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@ julia> # Construct a rational function from coefficients (dropping the variable)
julia> r5 = RationalFunction([1,2,3],[2,4,6])
f(s) = num(s)/den(s), where(s) is Poly(1 + 2s + 3s^2), and,
den(s) is Poly(2 + 4s + 6s^2).

julia> # Construct a directly from polynomial division
julia> r6 = numpoly/denpoly
f(s) = num(s)/den(s), where,
num(s) is Poly(-2 + 5s - 4s^2 + s^3), and,
den(s) is Poly(-6 + 11s - 6s^2 + s^3).
```

### Convenience functions
Expand Down Expand Up @@ -155,7 +149,7 @@ Poly(1.6809852898721749 + 2.613098491401878⋅x)
julia> p2 = Poly(1+2*rand(3))
Poly(1.6629832340509254 + 2.9921125048432287x + 2.8500993637891843x^2)

julia> r7 = p1/p2
julia> r7 = RationalFunction(p1, p2)
f(x) = num(x)/den(x), where,
num(x) is Poly(1.6809852898721749 + 2.613098491401878x), and,
den(x) is Poly(1.6629832340509254 + 2.9921125048432287x + 2.8500993637891843x^2).
Expand Down Expand Up @@ -240,10 +234,12 @@ julia> denpoly
Poly(-6 + 11s - 6s^2 + s^3)

julia> r1+r2
ERROR: r1+r2: r1 and r2 have different variables ((s,RationalFunctions.Conj{false}) vs (s,RationalFunctions.Conj{true}))
WARNING: r1+r2: `r1` (s,Conj{false}) and `r2` (s,Conj{true}) have different variables
ERROR: DomainError: ...

julia> r1+r5
ERROR: r1+r2: r1 and r2 have different variables ((s,RationalFunctions.Conj{false}) vs (x,RationalFunctions.Conj{false}))
WARNING: r1+r2: `r1` (s,Conj{false}) and `r2` (x,Conj{false}) have different variables
ERROR: DomainError: ...

julia> r1+r3
f(s) = num(s)/den(s), where,
Expand All @@ -254,8 +250,6 @@ julia> r2+r4
f(s̄) = num(s̄)/den(s̄), where,
num(s) is Poly(-10.0 + 1.0s - 2.0s^2 + 38.0s^3 - 36.0s^4 + 9.0s^5), and,
den(s) is Poly(-12.0 - 2.0s - 4.0s^2 + 44.0s^3 - 32.0s^4 + 6.0s^5).
julia> r1 == r6
true

julia> r1 * denpoly == numpoly
true
Expand Down
12 changes: 0 additions & 12 deletions src/type.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ where,
* `num` and `den` objects can be either a `Number` or a `Vector`, and,
* `var` is either a `Symbol`, a `Char` or an `AbstractString`.
Construct `RationalFunction` objects by `Poly` division:
Base./(num, den)
where,
* `num` and `den` are `Poly` objects.
# Examples
```julia
julia> r1 = RationalFunction(poly([1,2,3]));
Expand All @@ -66,7 +59,6 @@ julia> r3 = RationalFunction(poly([1,2,3]), RationalFunctions.Conj{true});
julia> r4 = RationalFunction([1,2,3]);
julia> r5 = RationalFunction(1, [1, 2, 3], "s");
julia> r6 = RationalFunction([1,2,3], 't', RationalFunctions.Conj{true});
julia> r7 = poly([1,2,3])/Poly([1,2,3]);
```
See also: `RationalFunctions.Var`, `RationalFunctions.Conj`, `RationalFunctions.SymbolLike`,
Expand Down Expand Up @@ -143,10 +135,6 @@ RationalFunction{S,U<:Number}(num::U, var::SymbolLike = :x,
conj::Type{Conj{S}} = Conj{false}) = RationalFunction(Poly([num], var),
Poly([one(U)], var), conj)

# Construction from Poly division
/(p1::Poly, p2::Poly) = RationalFunction(p1, p2, Conj{false})
./(p1::Poly, p2::Poly) = /(p1,p2)

"""
Poly(r::RationalFunction)
Expand Down
37 changes: 17 additions & 20 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@ import RationalFunctions: Var, Conj

# Constructor tests
## Construction from polynomials
px = Poly([1,-2,1]) # px = (x-1)(x-1)
px_ = Poly([1,-2,1]) # px_ = (x-1)(x-1)
qx = poly([1,2,3]) # qx = (x-1)(x-2)(x-3)
ps = Poly([1,-2,1], :s) # ps = (s-1)(s-1)

@test isequal(RationalFunction(px, qx), RationalFunction(px, qx, Conj{false}))
@test isa(RationalFunction(px, qx, Conj{true}), RationalFunction{Var{px.var}, Conj{true}, eltype(px), eltype(qx)})
@test isequal(RationalFunction(px), RationalFunction(px, one(px)))
@test isequal(RationalFunction(px, Conj{true}), RationalFunction(px, one(px), Conj{true}))
@test isequal(px/qx, RationalFunction(px, qx, Conj{false}))
@test isequal(RationalFunction(px_, qx), RationalFunction(px_, qx, Conj{false}))
@test isa(RationalFunction(px_, qx, Conj{true}), RationalFunction{Var{px_.var}, Conj{true}, eltype(px_), eltype(qx)})
@test isequal(RationalFunction(px_), RationalFunction(px_, one(px_)))
@test isequal(RationalFunction(px_, Conj{true}), RationalFunction(px_, one(px_), Conj{true}))

@test_throws DomainError RationalFunction(px, ps)
@test_throws DomainError RationalFunction(px, ps, Conj{true})
@test_throws DomainError px./ps
@test_throws DomainError px/ps
@test_throws DomainError RationalFunction(px_, ps)
@test_throws DomainError RationalFunction(px_, ps, Conj{true})

@test isequal(RationalFunction(coeffs(px), qx), RationalFunction(px, coeffs(qx)))
@test isequal(RationalFunction(coeffs(px_), qx), RationalFunction(px_, coeffs(qx)))
@test isequal(RationalFunction(1, Poly([2])), RationalFunction(Poly([1]), 2))

## Construction from numbers and vectors
Expand All @@ -32,10 +29,10 @@ ps = Poly([1,-2,1], :s) # ps = (s-1)(s-1)
@test isa(RationalFunction([1, 2.], 's', Conj{true}), RationalFunction{Var{:s}, Conj{true}, Float64, Float64})

## `Poly` construction from `RationalFunction`s
r1 = px/qx
r2 = px/Poly([4])
r1 = RationalFunction(px_, qx)
r2 = RationalFunction(px_, Poly([4]))

@test isapprox(coeffs(Poly(r2)), coeffs(px/4))
@test isapprox(coeffs(Poly(r2)), coeffs(px_/4))
@test_throws DomainError Poly(r1)

# Conversion tests
Expand All @@ -46,14 +43,14 @@ p3 = poly(v3)
@test eltype([RationalFunction(v1, v2), RationalFunction(v2, v1)]) ==
RationalFunction{Var{:x}, Conj{false}, promote_type(eltype(v1), eltype(v2)),
promote_type(eltype(v1), eltype(v2))}
@test eltype([RationalFunction(px, qx), 1.]) ==
RationalFunction{Var{px.var}, Conj{false}, promote_type(eltype(px), Float64),
@test eltype([RationalFunction(px_, qx), 1.]) ==
RationalFunction{Var{px_.var}, Conj{false}, promote_type(eltype(px_), Float64),
eltype(qx)}
@test eltype([RationalFunction(px, qx, Conj{true}), p3]) ==
RationalFunction{Var{px.var}, Conj{true}, promote_type(eltype(px), eltype(p3)),
@test eltype([RationalFunction(px_, qx, Conj{true}), p3]) ==
RationalFunction{Var{px_.var}, Conj{true}, promote_type(eltype(px_), eltype(p3)),
eltype(qx)}

@test_throws DomainError [px/qx, ps]
@test_throws DomainError [RationalFunction(px_, qx), ps]

# Printing tests
# TODO: Think of some useful printing tests
Expand Down Expand Up @@ -150,7 +147,7 @@ p3 = poly([1]) # p3 = (x-1)
p4 = poly([2,3]) # p4 = (x-2)(x-3)

r1 = RationalFunction(p1, p2)
result = (polyder(p3)*p4 - p3*polyder(p4))/p4^2
result = RationalFunction(polyder(p3)*p4 - p3*polyder(p4), p4^2)
@test derivative(r1) == result
@test !isequal(derivative(r1), result)

Expand Down

0 comments on commit bce8961

Please sign in to comment.