Set: Difference between revisions

1,793 bytes added ,  1 year ago
m (syntax highlighting fixup automation)
Line 6,808:
Set A is not a subset of set B
Set A is not equal to set B
</pre>
 
=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.7}}
{| class="wikitable"
! RPL code
! Comment
|-
|
≪ POS SIGN ≫ ''''IN?'''' STO
≪ → a b
≪ a 1 b SIZE '''FOR''' j
b j GET '''IF''' a OVER POS '''THEN''' DROP '''ELSE''' + '''END'''
'''NEXT'''
≫ ≫ ''''UNION'''' STO
≪ → a b
≪ { } 1 a SIZE '''FOR''' j
a j GET '''IF''' b OVER POS '''THEN''' + '''ELSE''' DROP '''END'''
NEXT
≫ ≫ ''''INTER'''' STO
≪ → a b
≪ { } 1 a SIZE '''FOR''' j
a j GET IF b OVER POS '''THEN''' DROP '''ELSE''' + '''END'''
'''NEXT'''
≫ ≫ ''''DIFFL'''' STO
≪ → a b
≪ 1 CF 1 a SIZE '''FOR''' j
'''IF''' b a j GET POS NOT '''THEN''' 1 SF a SIZE 'j' STO '''END'''
'''NEXT''' 1 FC?
≫ ≫ ''''INCL'''?' STO
≪DUP2 '''INCL?''' ROT ROT SWAP '''INCL?''' AND
≫ ''''SAME?'''' STO
|
'''IN?''' ''( {A} m -- boolean )'' // 1 if m ∈ A
.
'''UNION''' ''( {A} {B} -- {A ∪ B} )''
Scan {B}...
... and add to {A} all {B} items not already in {A}
.
.
.
.
'''INTER''' ''( {A} {B} -- {A ∩ B} )''
Scan {A}...
... and keep {A} items also in {B}
.
.
'''DIFFL''' ''( {A} {B} -- {A ∖ B} )''
Scan {A}...
... and keep {A} items not in {B}
.
.
.
'''INCL?''' ''( {A} {B} -- boolean )'' // true if {A} ⊆ {B}
Scan {A}...
... and break loop if an {A} item is not in {B}
return flag 1, set if loop has been broken
.
.
'''SAME?''' ''( {A} {B} -- boolean )'' // true if {A} = {B}
{A} = {B} <=> {A} ⊆ {B} and {B} ⊆ {A}
|}
 
{{in}}
<pre>
3 {1 2 3 4} IN?
{1 2 3 4} {3 5 6} UNION
{1 2 3 4} {3 5 6} INTER
{1 2 3 4} {3 5 6} DIFFL
{1 2} {1 2 3 4} INCL?
{1 2 3} {3 1 2} SAME?
 
</pre>
{{out}}
<pre>
6: 1
5: { 1 2 3 4 5 6 }
4: { 3 }
3: { 1 2 4 }
2: 1
1: 1
</pre>
 
1,150

edits