Anonymous user
Set of real numbers: Difference between revisions
→{{header|REXX}}: added/changed comments and whitespace, used a template for the output section.
(→{{header|REXX}}: added/changed comments and whitespace, used a template for the output section.) |
|||
Line 1,647:
=={{header|REXX}}==
===no error checking, no ∞===
<lang rexx>/*REXX
call
call
call
call
call quertySet , , '[0,2) \ (1,3)'
say; say center(' start of required tasks ', 40, "═")
call quertySet , , '(0,1] union [0,2)'
call quertySet , , '[0,3] - (0,1)'
call quertySet , , '[0,3] -
exit
/*──────────────────────────────────────────────────────────────────────────────────────*/
emptySet: parse arg _;
/*──────────────────────────────────────────────────────────────────────────────────────*/
isInSet: parse arg #,x; call valSet x
if \datatype(#, 'N') then call set_bad "number isn't not numeric:" #
(@.4==')' & #>=@.3) |,
return 1
/*──────────────────────────────────────────────────────────────────────────────────────*/
quertySet: parse arg lv,hv,s1 oop s2 .; op=oop; upper op; cop=
if lv=='' then lv=0; if hv=='' then
if wordpos(op, '| or UNION')
if wordpos(op, '& ∩ AND INTER INTERSECTION') \==0
if wordpos(op, '\ - DIF DIFF DIFFERENCE') \==0
do i=lv to hv; b = isInSet(i, s1)
if cop=='&' then b= b & b2
if cop=='|' then b= b | b2
end
express = s1 center(oop, max(5, length(oop) ) ) s2
say right(i, 5) ' is in set' express": " word('no yes', b+1)
end /*i*/
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
valSet: parse arg q; q=space(q, 0); L=length(q); @.0= ','; @.4= right(q,1)
parse var q @.1 2 @.2 ',' @.3 (@.4)
if @.2>@.3 then parse var L . @.0 @.2 @.3
return space(@.1 @.2 @.0 @.3 @.4, 0)</lang>
{{out|output|text= is the same as the next REXX version (below).}}
===has error checking, ∞ support===
<lang rexx>/*REXX
call
call
call
call
call quertySet , , '[0,2) \ (1,3)'
say; say center(' start of required tasks ', 40, "═")
call quertySet , , '(0,1] union [0,2)'
call quertySet , , '[0,3] - (0,1)'
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
badSet: say; say '***error*** bad format of SET_def: ('arg(1)")";
/*──────────────────────────────────────────────────────────────────────────────────────*/
emptySet: parse arg _;
/*──────────────────────────────────────────────────────────────────────────────────────*/
isInSet: parse arg #,x; call valSet x
if \datatype(#, 'N') then call set_bad "number isn't not numeric:" #
(@.4==')' & #>=@.3) |,
return 1
/*──────────────────────────────────────────────────────────────────────────────────────*/
quertySet: parse arg lv,hv,s1 oop s2 .; op=oop; upper op; cop=
if
if wordpos(op, '| or UNION')
if wordpos(op, '& ∩ AND INTER INTERSECTION') \==0
if wordpos(op, '\ - DIF DIFF DIFFERENCE') \==0
do i=lv to hv;
if cop\==0 then do
if cop=='&' then b= b & b2
if cop=='|' then b= b | b2
if cop=='\' then b= b & \b2
express = s1 center(oop, max(5, length(oop) ) ) s2
end /*i*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
valSet: parse arg q; q=space(q, 0); L= length(q); @.0= ','
infinity = copies(9, digits() - 1)'e'copies(9, digits() - 1)0
if L<2 then call set_bad 'invalid expression'
@.4= right(q, 1)
parse var q @.1 2 @.2 ',' @.3 (@.4)
if @.1\=='(' & @.1\=="[" then call set_bad 'left boundry'
if @.4\==')' & @.4\=="]" then call set_bad 'right boundry'
do j=2 to 3; u=@.j; upper u
if right(@.j, 1)=='∞' | u="INFINITY" then @.j= '-'infinity
if \datatype(@.j, 'N') then call set_bad "value not numeric:" @.j
end /*j*/
if @.2>@.3 then parse var L . @.0 @.2 @.3
return space(@.1 @.2 @.0 @.3 @.4, 0)</lang>
{{out|output|text= when using the (internal) default inputs:}}
<pre>
1 is in set [1,2) : yes
2 is in set [1,2) : no
3 is in set [1,2) : no
0 is in set
1 is in set [0,2) union (1,3): yes
2 is in set [0,2) union (1,3): yes
0 is in set [0,1) union (2,3]: yes
1 is in set [0,1) union (2,3]: no
2 is in set [0,1) union (2,3]: no
0 is in set [0,2] inter (1,3): no
1 is in set [0,2] inter (1,3): no
2 is in set [0,2] inter (1,3): yes
0 is in set (1,2) ∩ (2,3]: no
1 is in set (1,2) ∩ (2,3]: no
2 is in set (1,2) ∩ (2,3]: no
0 is in set [0,2) \ (1,3): yes
1 is in set [0,2) \ (1,3): yes
2 is in set [0,2) \ (1,3): no
═══════ start of required tasks ════════
0 is in set (0,1] union [0,2): yes
1 is in set (0,1] union [0,2): yes
|