admin管理员组文章数量:1336183
I am writing a class PredicateSet in Java to model the mathematical definition of a countable set using predicates to accept or reject membership. But I am having trouble coming up with an equals method. I want two PredicateSets to be equal if the membership test returns the same value for any Object (not necessarily an object already in both sets). For example if we have two sets of objects defined by 1=1 and 2 = 2 respectively, both sets would equivalent to the universal set since any Object could be added to either set.
Obviously infinity doesn't work in practice, but I want to get as close as possible to the real definition of equality.
Does anyone have any suggestions?
I am writing a class PredicateSet in Java to model the mathematical definition of a countable set using predicates to accept or reject membership. But I am having trouble coming up with an equals method. I want two PredicateSets to be equal if the membership test returns the same value for any Object (not necessarily an object already in both sets). For example if we have two sets of objects defined by 1=1 and 2 = 2 respectively, both sets would equivalent to the universal set since any Object could be added to either set.
Obviously infinity doesn't work in practice, but I want to get as close as possible to the real definition of equality.
Does anyone have any suggestions?
Share asked Nov 19, 2024 at 20:14 21kondav21kondav 195 bronze badges 1- It depends on what you mean by "as close as possible to the real definition of equality". You can check dozen random integer and if they have same predicate result then sets are equal. – talex Commented Nov 19, 2024 at 20:32
1 Answer
Reset to default 2This is not remotely doable in general; it runs straight into the Halting Problem to determine if two programs (the arbitrary predicates) are equivalent. You might be able to detect equality for some very simple predicates, like "the set of elements that equal 0," but that's as far as it goes.
For anything more involved, you're really going to need an entirely different framework and probably language to reason about predicate equality. This would be a pretty normal thing to do in Agda, for example, but no language can solve the halting problem: It restricts the ways in which you can express your predicates (if you want it to reason about predicate equality).
Given that you have a countable set, if you add the caveat that a predicate must give the same answer to a given value every time, you could simply check the end result for all possible values. If that isn't going to end up being a performance issue, then by all means. There is no way in java to enforce the 'must give consistent answers' requirement.
本文标签: mathMathematical Predicate Equality in JavaStack Overflow
版权声明:本文标题:math - Mathematical Predicate Equality in Java - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742401064a2467893.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论