Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ShallowRefinement includes: anElement #157

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Class {
#name : #ShallowRefinementTest,
#superclass : #TestCaseWithZ3Context,
#category : #'Refinements-Doodles'
#category : #'Refinements-Tests'
}

{ #category : #'tests - factorial' }
Expand Down Expand Up @@ -47,6 +47,14 @@ ShallowRefinementTest >> testInvertFactorial [
equals: 5
]

{ #category : #'tests - factorial' }
ShallowRefinementTest >> testNincludes1 [
| ℕ |
ℕ := Int sort | [ :k | k >= 0 ].
self assert: 1 ∈ ℕ.
self deny: -1 ∈ ℕ.
]

{ #category : #'tests - sets' }
ShallowRefinementTest >> testSubset [
| gt1 gt0 |
Expand Down
20 changes: 15 additions & 5 deletions Refinements/ShallowRefinement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ShallowRefinement class >> base: B predicate: e [
yourself
]

{ #category : #accessing }
{ #category : #'set theory' }
ShallowRefinement >> allElements [
| nu solver elements |
nu := B mkFreshConst: 'nu'.
Expand All @@ -33,7 +33,7 @@ ShallowRefinement >> allElements [
^elements
]

{ #category : #algebra }
{ #category : #'set theory' }
ShallowRefinement >> anyOne [
| nu solver instance |
nu := B mkFreshConst: 'nu'.
Expand All @@ -55,6 +55,16 @@ ShallowRefinement >> base: aSort [
B := aSort
]

{ #category : #'set theory' }
ShallowRefinement >> includes: x [
"Caveat programmator: this is purely a REFINEMENT test,
simply assuming that the sorts agree.
We can't really do much here meaningfully,
because many things can reasonably cast to many other things.
For example, 'a' casts to the integer symbolic constant a."
^x∘e
]

{ #category : #accessing }
ShallowRefinement >> predicate [
^e
Expand All @@ -81,21 +91,21 @@ ShallowRefinement >> toPredicateOver: varName [
^self predicate value: var
]

{ #category : #accessing }
{ #category : #'set theory' }
ShallowRefinement >> ∩ [ rhs
B = rhs ifTrue: [ ^self ].
B = rhs base ifFalse: [ self error: 'Incoherent sorts' ].
^B | [ :x | (e value: x) & (rhs predicate value: x) ]
]

{ #category : #accessing }
{ #category : #'set theory' }
ShallowRefinement >> ∪ [ rhs
B = rhs ifTrue: [ ^self ].
B = rhs base ifFalse: [ self error: 'Incoherent sorts' ].
^B | [ :x | (e value: x) | (rhs predicate value: x) ]
]

{ #category : #algebra }
{ #category : #'set theory' }
ShallowRefinement >> ⊆ [ rhs
| x solver |
self base == rhs base ifFalse: [ self error: 'To compare refinement types, first the base types must already be the same' ].
Expand Down