Skip to content

Commit

Permalink
Add free_associative_algebra_type
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Oct 2, 2024
1 parent 3fe0405 commit 5abf56e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
21 changes: 21 additions & 0 deletions src/FreeAssociativeAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,24 @@ end
function rand(S::FreeAssociativeAlgebra, term_range, exp_bound, v...)
rand(GLOBAL_RNG, S, term_range, exp_bound, v...)
end

###############################################################################
#
# free_associative_algebra constructor
#
###############################################################################

function free_associative_algebra(
R::AbstractAlgebra.Ring,
s::Vector{Symbol};
cached::Bool = true,
)
parent_obj = Generic.FreeAssociativeAlgebra{elem_type(R)}(R, s, cached)
return (parent_obj, gens(parent_obj))
end

free_associative_algebra_type(::Type{T}) where T<:RingElement = Generic.FreeAssociativeAlgebra{T}

free_associative_algebra_type(::Type{S}) where S<:Ring = free_associative_algebra_type(elem_type(S))
free_associative_algebra_type(x) = free_associative_algebra_type(typeof(x)) # to stop this method from eternally recursing on itself, we better add ...
free_associative_algebra_type(::Type{T}) where T = throw(ArgumentError("Type `$T` must be subtype of `RingElement`."))

Check warning on line 277 in src/FreeAssociativeAlgebra.jl

View check run for this annotation

Codecov / codecov/patch

src/FreeAssociativeAlgebra.jl#L277

Added line #L277 was not covered by tests
1 change: 1 addition & 0 deletions src/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export finish
export fit!
export fraction_field
export free_associative_algebra
export free_associative_algebra_type
export free_module
export function_field
export gcd
Expand Down
16 changes: 0 additions & 16 deletions src/generic/FreeAssociativeAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -696,19 +696,3 @@ function _map(g::S, a::FreeAssociativeAlgebraElem{T}, Rx) where {S, T <: RingEle

return finish(M)
end


###############################################################################
#
# free_associative_algebra constructor
#
###############################################################################

function free_associative_algebra(
R::AbstractAlgebra.Ring,
s::Vector{Symbol};
cached::Bool = true,
)
parent_obj = FreeAssociativeAlgebra{elem_type(R)}(R, s, cached)
return (parent_obj, gens(parent_obj))
end
2 changes: 1 addition & 1 deletion src/misc/VarNames.jl
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ macro varnames_interface(e::Expr, options::Expr...)
end
end

@varnames_interface Generic.free_associative_algebra(R::Ring, s)
@varnames_interface free_associative_algebra(R::Ring, s)
@varnames_interface Generic.laurent_polynomial_ring(R::Ring, s)
@varnames_interface Generic.rational_function_field(K::Field, s)

Expand Down
4 changes: 4 additions & 0 deletions test/generic/FreeAssociativeAlgebra-test.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
@testset "Generic.FreeAssociativeAlgebra.constructors" begin
R, x = ZZ["y"]
@test free_associative_algebra_type(R) == free_associative_algebra_type(typeof(R))
@test free_associative_algebra_type(R) == free_associative_algebra_type(elem_type(R))
@test isconcretetype(free_associative_algebra_type(R))

for num_vars = 1:5
var_names = ["x$j" for j in 1:num_vars]

S, varlist = free_associative_algebra(R, var_names)
@test S isa free_associative_algebra_type(R)

@test free_associative_algebra(R, var_names, cached = true)[1] === free_associative_algebra(R, var_names, cached = true)[1]
@test free_associative_algebra(R, var_names, cached = false)[1] !== free_associative_algebra(R, var_names, cached = true)[1]
Expand Down

0 comments on commit 5abf56e

Please sign in to comment.