Skip to content

Should 1^x == 1? #437

@pagnani

Description

@pagnani

Following the discussion on Discourse on the same issue:
do we want to enforce a rule to make 1^x -> 1?

There is a concern for x = ±∞ for which, I believe, the substitution although mathematically disputable should be ok.

As variables are strongly typed, a concern is what happens with one(ComplexF*)? However, it seems that

SymbolicUtils._isone(one(ComplexF64)) is true.

BTW, I tried to add toPOW_RULES something like

@rule(^(~x::_isone, ~z) => 1)

but it does not like it (stacktrace below). I do not understand how one can add more rules ....

ERROR: LoadError: ArgumentError: number of columns of each array must match (got (1, 1, 2, 1, 2, 1, 2, 1))
Stacktrace:
  [1] _typed_vcat(#unused#::Type{Metatheory.Rules.AbstractRule}, A::NTuple{8, Matrix{Metatheory.Rules.AbstractRule}})
    @ Base ./abstractarray.jl:1605
  [2] typed_vcat(::Type{Metatheory.Rules.AbstractRule}, ::Matrix{Metatheory.Rules.AbstractRule}, ::Matrix{Metatheory.Rules.AbstractRule}, ::Matrix{Metatheory.Rules.AbstractRule}, ::Vararg{Matrix{Metatheory.Rules.AbstractRule}})
    @ Base ./abstractarray.jl:1619
  [3] typed_hvcat(::Type{Metatheory.Rules.AbstractRule}, ::NTuple{8, Int64}, ::Metatheory.Rules.DynamicRule, ::Vararg{Any})
    @ Base ./abstractarray.jl:2041
  [4] hvcat(::NTuple{8, Int64}, ::Metatheory.Rules.DynamicRule, ::Vararg{Any})
    @ Base ./abstractarray.jl:2020
  [5] top-level scope
    @ ~/FORKS/SymbolicUtils.jl/src/simplify_rules.jl:4
  [6] include(mod::Module, _path::String)
    @ Base ./Base.jl:418
  [7] include(x::String)
    @ SymbolicUtils ~/FORKS/SymbolicUtils.jl/src/SymbolicUtils.jl:4
  [8] top-level scope
    @ ~/FORKS/SymbolicUtils.jl/src/SymbolicUtils.jl:55
  [9] include
    @ ./Base.jl:418 [inlined]
 [10] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt64}}, source::Nothing)
    @ Base ./loading.jl:1318
 [11] top-level scope
    @ none:1
 [12] eval
    @ ./boot.jl:373 [inlined]
 [13] eval(x::Expr)
    @ Base.MainInclude ./client.jl:453
 [14] top-level scope
    @ none:1
in expression starting at /Users/pagnani/FORKS/SymbolicUtils.jl/src/simplify_rules.jl:3
in expression starting at /Users/pagnani/FORKS/SymbolicUtils.jl/src/SymbolicUtils.jl:1
ERROR: Failed to precompile SymbolicUtils [d1185830-fcd6-423d-90d6-eec64667417b] to /Users/pagnani/.julia/compiled/v1.7/SymbolicUtils/jl_StTnCZ.
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:33
  [2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, ignore_loaded_modules::Bool)
    @ Base ./loading.jl:1466
  [3] compilecache(pkg::Base.PkgId, path::String)
    @ Base ./loading.jl:1410
  [4] _require(pkg::Base.PkgId)
    @ Base ./loading.jl:1120
  [5] require(uuidkey::Base.PkgId)
    @ Base ./loading.jl:1013
  [6] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:997
  [7] eval
    @ ./boot.jl:373 [inlined]
  [8] eval
    @ ./Base.jl:68 [inlined]
  [9] repleval(m::Module, code::Expr, #unused#::String)
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.11/scripts/packages/VSCodeServer/src/repl.jl:157
 [10] (::VSCodeServer.var"#71#73"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.11/scripts/packages/VSCodeServer/src/repl.jl:123
 [11] with_logstate(f::Function, logstate::Any)
    @ Base.CoreLogging ./logging.jl:511
 [12] with_logger
    @ ./logging.jl:623 [inlined]
 [13] (::VSCodeServer.var"#70#72"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.5.11/scripts/packages/VSCodeServer/src/repl.jl:124
 [14] #invokelatest#2
    @ ./essentials.jl:716 [inlined]
 [15] invokelatest(::Any)
    @ Base ./essentials.jl:714
 [16] macro expansion
    @ ~/.vscode/extensions/julialang.language-julia-1.5.11/scripts/packages/VSCodeServer/src/eval.jl:34 [inlined]
 [17] (::VSCodeServer.var"#55#56")()
    @ VSCodeServer ./task.jl:423

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions