Skip to content

Symbolic functions break the __hash__ contract #14608

@vbraun

Description

@vbraun

Equal objects must have the same hash if they are hashable (http://docs.python.org/2/reference/datamodel.html#object.__hash__):

sage: my_func = function('func',nargs=1)
sage: f = my_func(0)
sage: bool(f == f.simplify())
True
sage: hash(f) == hash(f.simplify())
False

As reported on http://ask.sagemath.org/question/2587/simplify-shenanigans, hash lookup errors then leads to undesirable behavior:

sage: ex = my_func(0) + my_func(1)
sage: ex.subs(my_func(0)==1)
func(1) + 1
sage: ex.simplify().subs(my_func(0)==1)
func(0) + func(1)

Component: symbolics

Issue created by migration from https://trac.sagemath.org/ticket/14608

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions