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

Initial expressify test #248

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 4 additions & 26 deletions src/GenericCyclotomicFractions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,12 @@
return GenericCycloFrac(new_numerator, new_denominator, a.exceptions; simplify=false)
end

function show(io::IO, x::GenericCycloFrac)
io = pretty(io)
if isone(x.denominator)
print(io, "$(x.numerator)")
else
if isone(length(x.numerator.f))
print(io, "$(x.numerator)//")
else
print(io, "($(x.numerator))//")
end
if isone(length(x.denominator.f))
argument, modulus = collect(x.denominator.f)[1]
if iszero(argument) && (is_monomial(modulus) || is_constant(modulus))
print(io, "$(x.denominator)")
else
print(io, "($(x.denominator))")
end
else
print(io, "($(x.denominator))")
end
end
if is_restriction(x.exceptions)
print(io, "\nWith exceptions:\n", Indent())
print(io, x.exceptions)
print(io, Dedent())
end
function expressify(x::GenericCycloFrac; context = nothing)
return Expr(:call, ://, expressify(x.numerator, context = context), expressify(x.denominator, context = context))

Check warning on line 27 in src/GenericCyclotomicFractions.jl

View check run for this annotation

Codecov / codecov/patch

src/GenericCyclotomicFractions.jl#L26-L27

Added lines #L26 - L27 were not covered by tests
end

@enable_all_show_via_expressify GenericCycloFrac

isone(x::GenericCycloFrac) = isone(x.numerator) && isone(x.denominator)

@doc raw"""
Expand Down
22 changes: 5 additions & 17 deletions src/GenericCyclotomics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,27 +211,15 @@
end
end

function show(io::IO, x::GenericCyclo) # TODO Use OSCAR's expressify system here.
function expressify(x::GenericCyclo; context = nothing)
if iszero(x)
print(io, "0")
return nothing
end
for (i, (argument, modulus)) in enumerate(x.f)
if iszero(argument)
print(io, modulus)
elseif isone(modulus)
print(io, "exp(2π𝑖($(argument)))")
elseif is_monomial(modulus)
print(io, "$(modulus)*exp(2π𝑖($(argument)))")
else
print(io, "($(modulus))*exp(2π𝑖($(argument)))")
end
if i < length(x.f)
print(io, " + ")
end
return 0

Check warning on line 216 in src/GenericCyclotomics.jl

View check run for this annotation

Codecov / codecov/patch

src/GenericCyclotomics.jl#L216

Added line #L216 was not covered by tests
end
return reduce((a, b) -> Expr(:call, :+, a, b), map(p -> Expr(:call, :*, expressify(p[2], context = context), Expr(:call, Symbol("exp"), Expr(:call, :*, Symbol("2π𝑖"), expressify(p[1], context = context)))), collect(x.f)))
end

@enable_all_show_via_expressify GenericCyclo

# Unary operations

function -(x::GenericCyclo)
Expand Down
Loading