Skip to content

Implement additional simplifications for predicate function negation #51558

@jakobjpeters

Description

@jakobjpeters

Predicate function negation (source code) (proposed in #44748 and implemented in #44752) defines a method to simplify the case of !!f to f. Based on this, I propose implementing three similar simplifications.

Current

julia> !identity
!identity

julia> !!
!(!)

julia> !(identity  !)
!(identity  (!))

Proposed

julia> Base.:!(::typeof(identity)) = !;

julia> Base.:!(::typeof(!)) = identity;

julia> Base.:!(f::ComposedFunction{typeof(identity)}) = !f.inner;

julia> !identity
! (generic function with 7 methods)

julia> !!
identity (generic function with 1 method)

julia> !(identity  !)
identity (generic function with 1 method)

As demonstrated, these methods can simplify several cases while preserving semantics. If this seems like a good idea, I'd be happy to make a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureIndicates new feature / enhancement requests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions