How to resolve the algorithm Set of real numbers step by step in the Elena programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Set of real numbers step by step in the Elena programming language

Table of Contents

Problem Statement

All real numbers form the uncountable set ℝ. Among its subsets, relatively simple are the convex sets, each expressed as a range between two real numbers a and b where a ≤ b. There are actually four cases for the meaning of "between", depending on open or closed boundary: Note that if a = b, of the four only [a, a] would be non-empty. Task Implementation notes Optional work |sin(π x)| > 1/2 is the same as n + 1/6 < x < n + 5/6 for all integers n; your program does not need to derive this by itself.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Set of real numbers step by step in the Elena programming language

Source code in the elena programming language

import extensions;
 
extension setOp
{
    union(func)
        = (val => self(val) || func(val) );
 
    intersection(func)
        = (val => self(val) && func(val) );
 
    difference(func)
        = (val => self(val) && (func(val)).Inverted );
}
 
public program()
{
    // union
    var set := (x => x >= 0.0r && x <= 1.0r ).union:(x => x >= 0.0r && x < 2.0r );
 
    set(0.0r).assertTrue();
    set(1.0r).assertTrue();
    set(2.0r).assertFalse();
 
    // intersection
    var set2 := (x => x >= 0.0r && x < 2.0r ).intersection:(x => x >= 1.0r && x <= 2.0r );
 
    set2(0.0r).assertFalse();
    set2(1.0r).assertTrue();
    set2(2.0r).assertFalse();
 
    // difference
    var set3 := (x => x >= 0.0r && x < 3.0r ).difference:(x => x >= 0.0r && x <= 1.0r );
 
    set3(0.0r).assertFalse();
    set3(1.0r).assertFalse();
    set3(2.0r).assertTrue();
}

  

You may also check:How to resolve the algorithm Function composition step by step in the D programming language
You may also check:How to resolve the algorithm Magic 8-ball step by step in the 8080 Assembly programming language
You may also check:How to resolve the algorithm Sorting algorithms/Pancake sort step by step in the C programming language
You may also check:How to resolve the algorithm Permutations step by step in the Prolog programming language
You may also check:How to resolve the algorithm Rosetta Code/Fix code tags step by step in the Ruby programming language