Skip to content

Rewrite assumes x^n is same type as x * x #227

@odow

Description

@odow

See:

# An expression like `base ^ exponent`, where the `base` is a
# non-trivial expression that also needs to be re-written. We need
# `!vectorized` otherwise `A .+ (A + A)^2` would be rewritten as
# `broadcast!!(add_mul, x, AA, AA)` where `AA` is `A + A`.
MulType = :($promote_operation(
*,
typeof($(inner_factor.args[2])),
typeof($(inner_factor.args[2])),
))
if inner_factor.args[3] == 0
# If the exponent is 0, rewrite
# new_var = base^0
# as
# new_var = 1
return _rewrite(
vectorized,
minus,
:(one($MulType)),

This is not always true, for example, in jump-dev/JuMP.jl#3474.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions