How to resolve the algorithm Set of real numbers step by step in the F# programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Set of real numbers step by step in the F# 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 F# programming language
Source code in the fsharp programming language
open System
let union s1 s2 =
fun x -> (s1 x) || (s2 x);
let difference s1 s2 =
fun x -> (s1 x) && not (s2 x)
let intersection s1 s2 =
fun x -> (s1 x) && (s2 x)
[<EntryPoint>]
let main _ =
//test set union
let u1 = union (fun x -> 0.0 < x && x <= 1.0) (fun x -> 0.0 <= x && x < 2.0)
assert (u1 0.0)
assert (u1 1.0)
assert (not (u1 2.0))
//test set difference
let d1 = difference (fun x -> 0.0 <= x && x < 3.0) (fun x -> 0.0 < x && x < 1.0)
assert (d1 0.0)
assert (not (d1 0.5))
assert (d1 1.0)
assert (d1 2.0)
let d2 = difference (fun x -> 0.0 <= x && x < 3.0) (fun x -> 0.0 <= x && x <= 1.0)
assert (not (d2 0.0))
assert (not (d2 1.0))
assert (d2 2.0)
let d3 = difference (fun x -> 0.0 <= x && x <= Double.PositiveInfinity) (fun x -> 1.0 <= x && x <= 2.0)
assert (d3 0.0)
assert (not (d3 1.5))
assert (d3 3.0)
//test set intersection
let i1 = intersection (fun x -> 0.0 <= x && x < 2.0) (fun x -> 1.0 < x && x <= 2.0)
assert (not (i1 0.0))
assert (not (i1 1.0))
assert (not (i1 2.0))
0 // return an integer exit code
You may also check:How to resolve the algorithm Read entire file step by step in the K programming language
You may also check:How to resolve the algorithm Empty program step by step in the SQL PL programming language
You may also check:How to resolve the algorithm Interactive programming (repl) step by step in the Elena programming language
You may also check:How to resolve the algorithm Variadic function step by step in the Plain English programming language
You may also check:How to resolve the algorithm RPG attributes generator step by step in the Commodore BASIC programming language