Skip to content

Handling of rewrites with respect to types #46

@HarrisonGrodin

Description

@HarrisonGrodin

How much should we care about the types of equivalent expressions? For example:

  • Given a negative Int value of a, should (3 ^ a) ^ a be rewritten to 3 ^ (a^2), even though this would normally throw an error if a isn't converted to a float?
julia> x = -2;

julia> (3 ^ x) ^ x
ERROR: DomainError with -2:
Cannot raise an integer x to a negative power -2.
Make x a float by adding a zero decimal (e.g., 2.0^-2 instead of 2^-2), or write 1/x^2, float(x)^-2, or (x//1)^-2
Stacktrace:
 [1] throw_domerr_powbysq(::Int64, ::Int64) at ./intfuncs.jl:176
 [2] power_by_squaring(::Int64, ::Int64) at ./intfuncs.jl:196
 [3] ^(::Int64, ::Int64) at ./intfuncs.jl:220
 [4] top-level scope at none:0

julia> 3 ^ (x^2)
81
  • Should A * 0.0 be rewritten to zero(A), even though the resulting value may be of a different type?
julia> A = [1 2; 3 4];

julia> A * 0.0
2×2 Array{Float64,2}:
 0.0  0.0
 0.0  0.0

julia> zero(A)
2×2 Array{Int64,2}:
 0  0
 0  0

Metadata

Metadata

Labels

questionFurther information is requested

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions