Calculator for fuzzy numbers

Usually, the statistical estimators (or mathematical functions) are the base of scientific decision making. In applied situations, at least one of the parameters or variables of the decision function may be fuzzy valued, instead of real valued. In such vague situations, one way to perform the calculations is using extension principle approach which has a complex form. Recently, two software packages have been freely available to perform some facilities in calculation and computation based on fuzzy numbers. In other words, these two software packages have the role of the first calculator on fuzzy numbers. This paper discussed and compared two software packages “FuzzyNumbers” and “Calculator.LR.FNs” which were recently published on CRAN by Gagolewski and Parchami, respectively. These packages have the ability of installation on R software, and in fact they propose some useful instruments and functions to the users for drawing and easily using arithmetic operators on the set of fuzzy numbers. For the convenience of the readers, the proposed methods and functions have been presented with several numerical examples to help in better understanding.

graphical devices, import/export capabilities, reporting tools, etc. These packages are developed primarily in R, and sometimes in Fortran, C, C++, and Java. A core set of packages is included with the installation of R, with more than 10,162 additional packages (till February 2017) available at the Comprehensive R Archive Network (CRAN). The "Task Views" page (subject list) on the CRAN website lists a wide range of tasks (in fields such as agriculture, finance, genetics, high-performance computing, machine learning, data mining, medical imaging, social sciences, mathematics and spatial statistics) to which R has been applied and for which packages are available [18]. Among the listed packages on CRAN, there exists 36 fuzzy packages till now. These packages cover a wide range of tasks and are listed by name below: This paper is organized as follows. Section 3 discusses the preliminary reasons for the need of a calculator in a fuzzy environment. Among the above R packages, two packages "FuzzyNumbers" and "Calculator.LR.FNs" are introduced and discussed in Sects. 4 and 5, respectively. Finally, a comparison between packages "FuzzyNumbers" and "Calculator.LR.FNs" is briefly provided in the last section.

Why do you need a calculator in fuzzy environment?
Although classical arithmetic operations can be extended by the extension principle approach, the complexity of this principle causes some computational challenges/difficulties. To explain some of such difficulties, a numerical example is given in this section for calculating the variance of several fuzzy numbers, which has been known as an important field in research during the past two decades. There are several approaches to solve this problem by defuzzification, e.g., see [1,3,4,6,7,12,15,16] and [21]. But in these works, the original "fuzzy" problem looks like a "crisp" problem after defuzzification with crisp components. Such approaches are debatable in the community of fuzzy researchers, as according to these people the essence of fuzziness has been lost. They claim that if we formulate an imprecise/fuzzy data, the result of the final answer to the problem should be initially also imprecise. According to the critics, open to criticisms from the opponents of fuzzy sets, the notion of "fuzziness" seems to be not necessary for the description of the data in all the above-mentioned works.
Example 1 Suppose that we are going to compute a fuzzy variance for fuzzy numbers using the extension principle to retain the notion of "fuzziness" in the problem. In other words, unlike the above-mentioned studies, we wish to calculate/achieve the membership function of fuzzy (and not precise) variance for fuzzy data based on the extension principle. For this, consider three triangular fuzzy numbers: x 1 = T (7.6, 8, 9), x 2 = T (4.3, 5, 5.6) and x 3 = T (6,7,8). It must be mentioned that this is one of the simplest versions of the problem to show the computational challenges, since here it is assumed that: (1) the shape functions of all L R fuzzy numbers are the same, (2) the triangular fuzzy data is considered, and (3) the sample size is small. First, one can easily compute the mean of triangular fuzzy numbers x 1 , x 2 and x 3 based on the extension principle as follows: It must be noted that if the left and the right shape functions of L R fuzzy numbers are not the same, then the summation (and hence the mean) of L R fuzzy numbers is not easily computable. Fuzzy variance computation is followed below, step by step, based on the arithmetic operations of L R fuzzy numbers: Meanwhile, as a matter of fact, the shape functions of these squares are not same and therefore their summation is not easily computable. To avoid this difficulty, we discuss three possible approaches/strategies ass follows: 1. Defuzzification is the first strategy which leads the user to a crisp value for variance. As presented at the beginning of this section, defuzzification approach is the simplest method to confront the problem and this is not our goal, since defuzzification causes elimination of the notion of "fuzziness" in the problem. 2. As another approach (second strategy), one can use a triangular approximation for the square of a triangular fuzzy number, i.e., use an approximation for the multiplication of two triangular fuzzy numbers (see, Chapter 2 from [2]). There exist two criticisms on this approach: (1) the calculation is not exactly based on the extension principle and the result will be an approximation, (2) the approximation formula for multiplication is available just for positive or negative fuzzy numbers. Here, note that the support of the difference of the third fuzzy number from the mean contains a zero point, i.e., 0 ∈ supp (x 3 x) = [−1.53, 2.03], and hence the second approach failed to compute the fuzzy variance in this example. In other words, although one can approximate (x 1 x) 2 and (x 2 x) 2 , respectively, by triangular fuzzy numbers T (−1.59, 1.77, 6.29) and T (−2.42, 2.79, 7.13), he/she has not any approximation for x 2 3 and therefore one cannot have any approximation for the summation based on the second strategy.
3. The third approach considers α-cuts of fuzzy numbers, for some α ∈ (0, 1], and working with the arithmetic operations for intervals, instead of arithmetic operations on fuzzy numbers. We refer the readers to [11] in which an algorithm is proposed to calculate the fuzzy variance based on the extension principle and it coincides with the considered method in package "FuzzyNumbers". Meanwhile, we will return to a such problem to solve it easily by package "FuzzyNumbers" in the next section (see, Example 11).
See Fig. 1 and note that the membership functions of (x i x) 2 's and the fuzzy variance are drawn by package "FuzzyNumbers", which will be discussed in the next section. This numerical example can be developed for computing the membership function of fuzzy standard deviation, and also computing the membership function of fuzzy covariance between two vectors of fuzzy numbers.
To avoid such computational difficulties/challenges in the fuzzy environment, we propose using two R packages "FuzzyNumbers" and "Calculator.LR.FNs" which are the topics of the next sections, respectively.

"FuzzyNumbers" package
The title of FuzzyNumbers is "Tools to Deal with Fuzzy Numbers" and the version of 0.4-6 published on CRAN by Gagolewski and Caha in 2019 [8]. In this section, some basic functions of package "FuzzyNumbers" has been presented and reviewed from [9] with several numerical examples.

Introducing fuzzy number
The user can introduce a fuzzy number by several methods in "FuzzyNumbers" package.

LR fuzzy number
Definition 1 (Fuzzy number in "FuzzyNumbers" package) Fuzzy number A is a fuzzy set from R with membership function To this goal, we can run the following comments, after installation and lauding "FuzzyNumbers" package in R (see Fig. 2):

Triangular and trapezoidal fuzzy numbers
Example 3 Introduction and plotting of triangular and trapezoidal fuzzy numbers (and also indicator functions) are presented in this example by several methods for "FuzzyNumbers" package.

Piecewise linear fuzzy number
Another kind of linear fuzzy numbers, named "piecewise linear fuzzy number", can be created in "FuzzyNumbers" package by function PiecewiseLinearFuzzyNumber. knot.n is one of its arguments which controls the number of knots. Using arguments knot.alpha, knot.left and knot.right, the user can be easily control the height, first and end points of knots, respectively.

Core, support and cuts of fuzzy numbers
Computing the core, support and α-cuts of a fuzzy number is possible in "FuzzyNumbers" package by using functions core , supp , and alphacut, respectively. Meanwhile, for evaluation of a real point membership degree into a fuzzy number use from function evaluate. For more clarify, see the next example [9].

Arithmetic operations on fuzzy numbers
Two-dimensional operators' addition, subtraction, multiplication and division are, respectively, introduced by +, −, · and / in "FuzzyNumbers" package, which can be considered between two fuzzy numbers. Moreover, · can be considered between a real number and a fuzzy number for scalar multiplication.

Remark 1
The "piecewised linear fuzzy numbers" can be generated by "FuzzyNumbers" package via one of the following three methods: The first function is applied for directly creating the triangular/trapezoidal piecewise fuzzy numbers. The second function is applied to exactly convert (and not approximate) a triangular/trapezoidal fuzzy number into a piecewise fuzzy number. The third function is applied to approximate an introduced fuzzy number with a piecewise fuzzy number by one of three methods, NearestEuclidean, SupportCorePreserving and Naive, which are defined via the argument method in function PiecewiseLinearApproximation. For more details, see the following examples and also [8,9].

Example 7 (Approximation of a fuzzy number with two methods NearestEuclidean and Naive)
A <-FuzzyNumber (

Numerical examples
In this sub-section, two interesting applied examples are given for "FuzzyNumbers" package. Example 10 [9] Consider the triangular fuzzy number A = T r(−2, −1, −1, 2). Compute and plot the membership functions of fuzzy numbers A 2 and A 3 (Fig. 3).

"Calculator.LR.FNs" package
The title of Calculator.LR.FNs package is "Calculator for L R Fuzzy Numbers" and the version of 1.3 published on CRAN by Parchami in 2018 [13]. In this section, some basic comments and functions of package "Calculator.LR.FNs" has been presented with several numerical examples. The main goal of this package is computing four basic arithmetic operations for L R fuzzy numbers. Moreover, this package has the ability of calculating the membership function of the scalar multiplication of a real number and an L R fuzzy number.

Introducing LR fuzzy number
It must be noted that the definition of fuzzy number in the "Calculator.LR.FNs" package differs from that in the "FuzzyNumbers" package.

Remark 2
One can consider several different kinds for the left shape and the right shape functions: e.g. left.fun(x) = ex p(−x p ) and right.fun(x) = max{0, 1 − |x| q }, where p, q ≥ 0.
Definition 3 L R fuzzy number L R(n, α, β) with right. fun(x) = left.fun(x) is named as "L fuzzy number" and shown by notation L(n, α, β).
Remark 3 Triangular and normal fuzzy numbers are two common/popular and special kinds of L fuzzy numbers for which the left and right shape functions are, respectively, equal to Note that the input and output fuzzy numbers in package "Calculator.LR.FNs" must be in the class of all L R fuzzy numbers and this package has the ability to calculate only on the set of all L R fuzzy numbers. So, it is more convenient to introduce the shape functions and then define the related fuzzy numbers. For instance, see the next example.

Example 12
By the following comments, one can easily introduce and plot the L R fuzzy number A = L R (20,12,10) in package "Calculator.LR.FNs", with the left and right shape functions left.fun(x) = 1 − x 2 , x ≥ 0 and right.fun(x) = e −x , x ≥ 0, respectively (Fig. 5).

Arithmetic operations on LR fuzzy numbers
Two-dimensional operators' addition, subtraction, multiplication and division are introduced in package "Calculator.LR.FNs" by functions a, s, m and d for two L R fuzzy numbers, respectively. Also, the function s.m is consid-ered for the scalar multiplication of a real number and an L R fuzzy number. Although the base of these operators is Zadeh's extension principle, in theory the class of L R fuzzy numbers is not close under the operations * and /. To close the output of multiplication and division on the class of L R fuzzy numbers, the calculations of multiplication and division in package "Calculator.LR.FNs" is on the basis of the proposed approximation in [2] by L R fuzzy numbers. See [13] for more details and the exact operations formulas.
To clarify firther, after introducing the left and right shape functions, suppose that the set of all fuzzy numbers L R, RL and L is named "the class of L R fuzzy numbers". Now, if the result of arithmetic calculations on "the class of L R fuzzy numbers" belong into this class, then "Calculator.LR.FNs" package gives the result to the user as an L R, RL or L fuzzy number in the Console window; otherwise, "Calculator.LR.FNs" is not able to calculate and the package "FuzzyNumbers" is proposed for such cases. Example 14 The following program generates and plots n random L R fuzzy numbers by "Calculator.LR.FNs" package and then calculates and draws the membership function of the mean for the generated fuzzy numbers. After running above comments in "Calculator.LR.FNs" package, the results of the calculations are presented by the following L R fuzzy numbers in the Console window (see Fig. 7).

Conclusions: advantages and weak points
Although the classical arithmetic operations can be extended by the extension principle approach, the complexity of this principle causes some computational difficulties/challenges. To resolve these computational challenges, two R packages Fig. 7 The membership functions of the considered input and output L R fuzzy numbers in Example 15 "FuzzyNumbers" and "Calculator.LR.FNs" have been published on CRAN in 2015 and 2016, respectively. This paper has tried to introduce and explain these R packages briefly, by presenting several numerical examples from [8,9,13]. Package "Calculator.LR.FNs" has the ability of computing the membership function of the result (as a L R fuzzy number) in Console window, which is an advantage with respect to the package "FuzzyNumbers". Although the package "FuzzyNumbers" can compute the core, support, αccuts and plot the membership function of the result, it cannot give the membership function of the result. From another point of view, the final result of the calculation may not belong to "the class of L R fuzzy numbers" and "Calculator.LR.FNs" is not capable in such cases, and so the package "FuzzyNumbers" is proposed to plot the membership function of the result. This is one of the weak points of "Calculator.LR.FNs" with respect to "FuzzyNumbers".
Finally, some suggestions are provided to improve the available packages on CRAN in future scientific works: