HarrisonGrodin / HarrisonGrodin/Simplify.jl

Handling of rewrites with respect to types

Open
#46 5 comments 0 reactions 1 assignee Claimed by @HarrisonGrodin View on GitHub
question
Dominant language
Julia
Stars
83
Forks
6
PR merge metrics
No merged PRs in 30d

Description

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
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
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
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.