Skip to content

Commit

Permalink
add simplify() for GreyNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
jbytecode committed Sep 1, 2023
1 parent bdfcebc commit 1a03fac
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
### 0.7.8 (Upcoming release)
### 0.7.9 (Upcoming release)


### 0.7.8

- Add normalization option to WPM method
- XYZMethod() now defines the default normalization for the possible copeland calls.
- Test code coverage increased.
- Added isfinite(), isnan(), one() for GreyNumber.
- Added simplify() for GreyNumber.

### 0.7.7

Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "JMcDM"
uuid = "358108f5-d052-4d0a-8344-d5384e00c0e5"
authors = ["Mehmet Hakan Satman (jbytecode) <[email protected]>", "Bahadir Fatih Yildirim <[email protected]>", "Ersagun Kuruca"]
version = "0.7.7"
version = "0.7.8"

[deps]
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Expand Down
4 changes: 2 additions & 2 deletions src/JMcDM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ import .SCDM: SavageResult, HurwiczResult, MLEResult, ExpectedRegretResult
import .SCDM:
laplace, maximax, maximin, minimax, minimin, savage, hurwicz, mle, expectedregret

import .GreyNumbers: GreyNumber, kernel, whitenizate
import .GreyNumbers: GreyNumber, kernel, whitenizate, simplify

import .Utilities: *
using .Utilities
Expand Down Expand Up @@ -316,7 +316,7 @@ import JMcDM.Copeland: copeland
export copeland

# export Grey Number elements
export GreyNumber, kernel, whitenizate
export GreyNumber, kernel, whitenizate, simplify

export Normalizations

Expand Down
14 changes: 13 additions & 1 deletion src/greynumber.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,22 @@ function Base.isfinite(g::GreyNumber)::Bool
return isfinite(g.a) || isfinite(g.b)
end

function simplify(n::Number)
return n
end

function simplify(g::GreyNumber)::Union{Number, GreyNumber}
if g.a == g.b
return simplify(g.a)
else
return g
end
end


export GreyNumber
export kernel
export whitenizate

export simplify

end # module
15 changes: 15 additions & 0 deletions test/testgreynumber.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,19 @@
GreyNumber(GreyNumber(-5.0, -5.0), GreyNumber(-5.0, -5.0)),
GreyNumber(GreyNumber(15.0, 15.0), GreyNumber(15.0, 15.0))]
end

@testset "Simplify" begin
@testset "Simplify matrix" begin
v = GreyNumber[
GreyNumber(GreyNumber(-5.0, -5.0), GreyNumber(-5.0, -5.0)),
GreyNumber(GreyNumber(15.0, 15.0), GreyNumber(15.0, 15.0))]
result = simplify.(v)

@test result == [-5.0, 15.0]
end

@testset "Simplify basic" begin
@test simplify(GreyNumber(5.0, 5.0)) == 5.0
end
end
end

0 comments on commit 1a03fac

Please sign in to comment.