A brief introduction to R

R is an open source programming language and software environment for statistical computing and graphics that is supported by the R foundation for statistical computing. The R language is widely used among statisticians for developing their statistical computations which show that R’s popularity has increased substantially in recent years. The source code for the R software environment is written primarily in C, Fortran, and R. R and its packages are freely available under the GNU general public license, and pre-compiled binary versions are provided for various operating systems [18].

Available fuzzy packages on CRAN

The capabilities of R are extended through user-created packages, which allow specialized statistical techniques, 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:

  • AnalyzeTS (Analyze Fuzzy Time Series)

  • anfis (Adaptive Neuro Fuzzy Inference System in R)

  • Calculator.LR.FNs (Calculator for LR Fuzzy Numbers)

  • coppeCosenzaR (COPPE-Cosenza Fuzzy Hierarchy Model)

  • fclust (Fuzzy Clustering)

  • fcm (Inference of Fuzzy Cognitive Maps (FCMs))

  • FCMapper (Fuzzy Cognitive Mapping)

  • FLR (Fuzzy Logic Rule Classifier)

  • frbs (Fuzzy Rule-Based Systems for Classification and Regression Tasks)

  • fso (Fuzzy Set Ordination)

  • fugeR (Fuzzy Genetic, a machine learning algorithm to construct prediction model based on fuzzy logic)

  • fuzzyFDR (Exact calculation of fuzzy decision rules for multiple testing)

  • Fuzzy.p.value (Computing Fuzzy p-Value)

  • FuzzyAHP ((Fuzzy) AHP Calculation)

  • fuzzyFDR (Exact calculation of fuzzy decision rules for multiple testing)

  • fuzzyforest (Fuzzy Forests)

  • FuzzyLP (Fuzzy Linear Programming)

  • FuzzyMCDM (Multi-Criteria Decision Making Methods for Fuzzy Data)

  • FuzzyNumbers (Tools to Deal with Fuzzy Numbers)

  • FuzzyNumbers.Ext.2 (Apply Two Fuzzy Numbers on a Monotone Function)

  • FuzzyR (Fuzzy Logic Toolkit for R)

  • fuzzyRankTests (Fuzzy Rank Tests and Confidence Intervals)

  • FuzzyStatProb (Fuzzy Stationary Probabilities from a Sequence of Observations of an Unknown Markov Chain)

  • FuzzyStatTra (Statistical Methods for Trapezoidal Fuzzy Numbers)

  • FuzzyToolkitUoN (Type 1 Fuzzy Logic Toolkit)

  • fuzzywuzzyR (Fuzzy String Matching)

  • lfl (Linguistic Fuzzy Logic)

  • RcmdrPlugin.FuzzyClust (R Commander Plug-in for Fuzzy Clustering Methods (Fuzzy C-Means and Gustafson Kessel))

  • rdd (Regression Discontinuity Estimation)

  • Rfmtool (Fuzzy Measure Tools for R)

  • RoughSets (Data Analysis Using Rough Set and Fuzzy Rough Set Theories)

  • SAFD (Statistical Analysis of Fuzzy Data)

  • SDEFSR (Subgroup Discovery with Evolutionary Fuzzy Systems in R)

  • spatialClust (Spatial Clustering using Fuzzy Geographically Weighted Clustering)

  • vegclust (Fuzzy clustering of vegetation data)

  • Weighted.Desc.Stat (Weighted Descriptive Statistics)

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 LR 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:

$$\begin{aligned} {\bar{x}}= & {} \frac{1}{3} \odot \left( x_1 \oplus x_2 \oplus x_3 \right) \\= & {} \frac{1}{3} \odot \left[ T(7.6,8,9) \oplus T(4.3,5,5.6) \oplus T(6,7,8) \right] \\= & {} T\left( \frac{7.6+4.3+6}{3}, \frac{8+5+7}{3}, \frac{9+5.6+8}{3}\right) \\= & {} T(5.97,6.67,7.53). \end{aligned}$$

It must be noted that if the left and the right shape functions of LR fuzzy numbers are not the same, then the summation (and hence the mean) of LR fuzzy numbers is not easily computable.

Fig. 1
figure 1

Membership functions of triangular fuzzy numbers and the elements needed for calculating their mean and variance in Example 1

Fuzzy variance computation is followed below, step by step, based on the arithmetic operations of LR fuzzy numbers:

$$\begin{aligned} s^2= & {} \frac{1}{3} \odot \left\{ \oplus _{i=1}^{3} \left( x_i \ominus {\bar{x}} \right) ^2 \right\} \\= & {} \frac{1}{3} \odot \left\{ \left( x_1 \ominus {\bar{x}} \right) ^2 \oplus \left( x_2 \ominus {\bar{x}} \right) ^2 \oplus \left( x_3 \ominus {\bar{x}} \right) ^2 \right\} \\= & {} \frac{1}{3} \odot \bigg \{ \left[ T(7.6,8,9) \ominus T(5.97,6.67,7.53) \right] ^2 \\&\ \ \ \ \ \ \ \ \oplus \,\left[ T(4.3,5,5.6) \ominus T(5.97,6.67,7.53) \right] ^2 \\&\ \ \ \ \ \ \ \ \oplus \,\left[ T(6,7,8) \ominus T(5.97,6.67,7.53) \right] ^2 \ \bigg \} \\= & {} \frac{1}{3} \odot \{ \ T(0.07,1.33,3.03)^2 \\&\ \ \ \ \ \ \ \ \oplus \,T(-3.23,-1.67,-0.37)^2 \\&\ \ \ \ \ \ \ \ \oplus \,T(-1.53,0.33,2.03)^2 \ \}. \end{aligned}$$

Till now, the computation is exactly based on the extension principle, but the results for the square of triangular fuzzy numbers \( T(0.07,1.33,3.03)^2 \), \( T(-3.23,-1.67,-0.37)^2\) and \(T(-1.53,0.33,2.03)^2 \) are not triangular 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. 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. 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 \in \texttt {supp}\left( x_3 \ominus {\bar{x}} \right) = [-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 \( \left( x_1 \ominus {\bar{x}} \right) ^2 \) and \( \left( x_2 \ominus {\bar{x}} \right) ^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_3^2 \) and therefore one cannot have any approximation for the summation based on the second strategy.

  3. 3.

    The third approach considers \( \alpha \)-cuts of fuzzy numbers, for some \( \alpha \in (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 \( \left( x_i \ominus {\bar{x}} \right) ^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

$$\begin{aligned} \mu _A(x) = \left\{ \begin{array}{llr} 0 &{} \texttt {if} &{} x<a_1, \\ \texttt {left} \left( \frac{x-a_1}{a_2-a_1} \right) &{} \texttt {if} &{} \ \ \ a_1 \le x< a_2, \\ 1 &{} \texttt {if} &{} a_2 \le x< a_3, \\ \texttt {right} \left( \frac{x-a_3}{a_4-a_3} \right) \ \ \ \ &{} \texttt {if} &{} a_3 \le x< a_4, \\ 0 &{} \texttt {if} &{} a_4 < x, \end{array} \right. \end{aligned}$$
(1)

in which \( a_1, a_2, a_3, a_4 \in R \), \( \texttt {left}: [0,1]\rightarrow [0,1] \) is a non-increasing function and \( \texttt {right}: [0,1]\rightarrow [0,1] \) is a non-increasing function.

Example 2

Let us introduce and plot fuzzy number \(A_1\) with core \( (a_2,a_3)=(2,4) \), support \( (a_1,a_4)=(1,7) \) and left and right shape functions \( \texttt {left(x)}=x \) and \( \texttt {right(x)}=1-x^2 \). To this goal, we can run the following comments, after installation and lauding “FuzzyNumbers” package in R (see Fig. 2):

figure a

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.

figure b

Piecewise linear fuzzy number

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

Example 4

(Creating a piecewise linear fuzzy number)

figure c
Fig. 2
figure 2

The membership function of the fuzzy number in Example 2

Power fuzzy number

Considering the shape functions \( \texttt {left}(x)=x^{p.left} \) and \( \texttt {right}(x)=(1-x)^{p.right} \) for the introduced fuzzy number in Eq. (1), create a special kind of fuzzy non-linear number called “power fuzzy number”. This kind of fuzzy number can easily be created in package “FuzzyNumbers” by function \( \texttt {PowerFuzzyNumber} \). It is obvious that any trapezoidal fuzzy number is a special case of “power fuzzy number” with \( p.left=p.right=1 \).

Core, support and cuts of fuzzy numbers

Computing the core, support and \(\alpha \)-cuts of a fuzzy number is possible in “FuzzyNumbers” package by using functions \( \texttt {core} \) , \( \texttt {supp} \) , and \( \texttt {alphacut} \), respectively. Meanwhile, for evaluation of a real point membership degree into a fuzzy number use from function \( \texttt {evaluate} \). For more clarify, see the next example [9].

Example 5

figure d

Arithmetic operations on fuzzy numbers

Two-dimensional operators’ addition, subtraction, multiplication and division are, respectively, introduced by \( + \), \( - \), \( \cdot \) and  /  in “FuzzyNumbers” package, which can be considered between two fuzzy numbers. Moreover, \( \cdot \) can be considered between a real number and a fuzzy number for scalar multiplication.

Example 6

(Addition and subtraction of two triangular/trapezoidal fuzzy numbers)

figure e
Fig. 3
figure 3

The membership functions of fuzzy numbers \(A, A^2\) and \(A^3\) in Example 10

Although the addition and subtraction of two triangular/trapezoidal fuzzy numbers can be easily computed directly, before considering other operations or using other kinds of fuzzy numbers in “FuzzyNumbers” package, first the fuzzy numbers must be piecewise by function \(\texttt {PiecewiseLinearFuzzyNumber} \) and then the arithmetic operation is applicable on the piecewised/sliced fuzzy numbers.

Remark 1

The “piecewised linear fuzzy numbers” can be generated by “FuzzyNumbers” package via one of the following three methods:

  1. (1)

    creation (by function \( \texttt {PiecewiseLinearFuzzy}\)\(\texttt {Number}\)),

  2. (2)

    conversion (by function \( \texttt {as.PiecewiseLinear}\)\(\texttt {FuzzyNumber} \)), and

  3. (3)

    approximation (by function \( \texttt {PiecewiseLinear}\)\(\texttt {Approximation} \)).

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, \( \texttt {NearestEuclidean} \), \( \texttt {SupportCorePreserving} \) and \( \texttt {Naive},\) which are defined via the argument \( \texttt {method} \) in function \(\texttt {PiecewiseLinearApproximation} \). For more details, see the following examples and also [8, 9].

Example 7

(Approximation of a fuzzy number with two methods \(\texttt {NearestEuclidean} \) and \( \texttt {Naive} \))

figure f

Example 8

figure g

Repeat the running of the comments by \( \texttt {knot.n=1} \) once again, and compare the observed result with the result of Example 8.

Example 9

Regarding Page 107 from [10], we compute four basic arithmetic operations on two triangular fuzzy numbers \( A=T(-1, 1, 3) \) and \( B=T(1, 3, 5) \).

figure h
Fig. 4
figure 4

Membership functions of fuzzy observation and their mean, variance and standard deviation in Example 11

Numerical examples

In this sub-section, two interesting applied examples are given for “FuzzyNumbers” package.

Example 10

[9] Consider the triangular fuzzy number \( A=Tr(-2,-1,-1,2) \). Compute and plot the membership functions of fuzzy numbers \( A^2 \) and \( A^3 \) (Fig. 3).

figure i

Example 11

Suppose that we are going to plot the membership functions of mean, standard deviation and variance of three fuzzy numbers \( X_1=Tr(0,1,2,3) \), \( X_2=T(-1,2,2.5) \) and \( X_3=Tr(2,3,4,4.5) \) (see Fig. 4).

figure j
figure k

See [8, 9] to orient with other abilities of “FuzzyNumbers” package, such as applying a fuzzy number on a monotone function and computing the distance of two fuzzy numbers.

“Calculator.LR.FNs” package

The title of Calculator.LR.FNs package is “Calculator for LR 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 LR fuzzy numbers. Moreover, this package has the ability of calculating the membership function of the scalar multiplication of a real number and an LR 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.

Definition 2

[2] (LR fuzzy number in “Calculator.LR.FNs” package) Let fuzzy number N be a fuzzy subset from R with the following membership function:

$$\begin{aligned} \mu _N(x) = \left\{ \begin{array}{llr} \texttt {left.fun} \left( \frac{n-x}{\alpha } \right) \ \ \ \ \ &{} \texttt {if} &{} \ \ \ x \le n, \\ \texttt {right.fun} \left( \frac{x-n}{\beta } \right) &{} \texttt {if} &{} \ \ \ x > n, \end{array} \right. \end{aligned}$$
(2)

in which \( \texttt {left.fun}: R^+\cup 0\rightarrow [0,1] \) and \( \texttt {right.fun}: R^+\cup 0\rightarrow [0,1] \) are two non-decreasing functions, \( \texttt {right.fun}(0)=\texttt {left.fun}(0)=1 \) and \( \alpha ,\beta >0 \). N is called an “LR fuzzy number” and shown by \( N = LR(n,\alpha ,\beta ) \) notation, in which n, \( \alpha \), \( \beta \), \( \texttt {left.fun} \) and \( \texttt {right.fun} \) are called core, left spread, right spread, left shape function and right shape function, respectively.

Remark 2

One can consider several different kinds for the left shape and the right shape functions: e.g. \( \texttt {left.fun}(x)=exp(-x^p) \) and \( \texttt {right.fun}(x)=max\{0, 1-|x|^q\} \), where \( p,q \ge 0 \).

Definition 3

LR fuzzy number \( LR(n,\alpha ,\beta ) \) with \( \texttt {right.}{} \mathtt{fun}(x)=\texttt {left.fun}(x) \) is named as “L fuzzy number” and shown by notation \( L(n,\alpha ,\beta ) \).

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

$$\begin{aligned} \texttt {left.fun}(x) = \left\{ \begin{array}{lr} 1-x, \ \ \ \ \ \ &{} 0 \le x \le 1 \\ \ 0, &{} 1< x \ \end{array} \right. \end{aligned}$$

and

$$\begin{aligned} \texttt {left.fun}(x) = e^{-x^2}, \ \ \ x \ge 0. \end{aligned}$$

Note that the input and output fuzzy numbers in package “Calculator.LR.FNs” must be in the class of all LR fuzzy numbers and this package has the ability to calculate only on the set of all LR 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 LR fuzzy number \( A = LR(20, 12, 10) \) in package “Calculator.LR.FNs”, with the left and right shape functions \( \texttt {left.fun}(x) = 1-x^2, \ x \ge 0 \) and \( \texttt {right.fun}(x) = e^{-x}, \ x \ge 0 \), respectively (Fig. 5).

figure l
Fig. 5
figure 5

The membership function of LR fuzzy number A in Example 12

Example 13

(Three kinds of LR fuzzy numbers)

Introducing an LR fuzzy number:

figure m

Introducing an RL fuzzy number:

figure n

Introducing a L fuzzy number (see Fig. 6):

figure o
Fig. 6
figure 6

The membership function of three fuzzy numbers, LR, RL and L in Example 13

Remark 4

Plotting the membership functions of LR fuzzy numbers in “Calculator.LR.FNs” package is possible, using the function LRFN.plot. It is more appropriate to define the limits of x’s axis via the argument xlim, in plotting the membership function of the first fuzzy number. Moreover, for drawing several plot on a figure (like Example 13), setting the argument add=TRUE is emergent for the second, third, ... fuzzy numbers.

Arithmetic operations on LR fuzzy numbers

Two-dimensional operators’ addition, subtraction, multiplication and division are introduced in package “Calculator.LR.FNs” by functions \( \texttt {a} \), \( \texttt {s} \), \( \texttt {m} \) and \( \texttt {d} \) for two LR fuzzy numbers, respectively. Also, the function \( \texttt {s.m} \) is considered for the scalar multiplication of a real number and an LR fuzzy number. Although the base of these operators is Zadeh’s extension principle, in theory the class of LR fuzzy numbers is not close under the operations * and /. To close the output of multiplication and division on the class of LR fuzzy numbers, the calculations of multiplication and division in package “Calculator.LR.FNs” is on the basis of the proposed approximation in [2] by LR 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 LR, RL and L is named “the class of LR fuzzy numbers”. Now, if the result of arithmetic calculations on “the class of LR fuzzy numbers” belong into this class, then “Calculator.LR.FNs” package gives the result to the user as an LR, 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 LR fuzzy numbers by “Calculator.LR.FNs” package and then calculates and draws the membership function of the mean for the generated fuzzy numbers.

figure p

Example 15

Consider LR fuzzy numbers \( A = LR(5, 0.5, 1) \), \( B = LR(2, 0.3, 0.6) \), \( C = RL(1, 0.7, 1.5) \) and \( D = LR(0.5, 0.5, 1) \) with the shape functions \( \texttt {left.fun}(x)=1-x^3, \ x \ge 0 \) and \( \texttt {right.fun}(x)=1-x, \ x \ge 0 \). After plotting these four fuzzy numbers on a figure, we compute and plot the membership functions of \( (A+B)/2 \), \( \left[ (A+B)/2 \right] -C \) and \( \left\{ \left[ (A+B)/2 \right] -C \right\} \times D \).

figure q
figure r

After running above comments in “Calculator.LR.FNs” package, the results of the calculations are presented by the following LR fuzzy numbers in the Console window (see Fig. 7).

$$\begin{aligned}&(A+B)/2 = LR(3.5,0.4,0.8) \\&\left[ (A+B)/2 \right] -C = LR(2.5,1.9,1.5) \\&\left\{ \left[ (A+B)/2 \right] -C \right\} \times D = LR(1.25,2.2,3.2) \\ \end{aligned}$$
Fig. 7
figure 7

The membership functions of the considered input and output LR fuzzy numbers in Example 15

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 “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 LR fuzzy number) in Console window, which is an advantage with respect to the package “FuzzyNumbers”. Although the package “FuzzyNumbers” can compute the core, support, \(\alpha \)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 LR 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:

  1. 1.

    Define/consider the abbreviated version for the name of functions, e.g., introducing function \( \texttt {PL} \) instead of function \( \texttt {PiecewiseLinearFuzzyNumber} \) in package “FuzzyNumbers”.

  2. 2.

    Notions \( + \), \( - \), \( * \) and  /  are more appropriate than notions \( \texttt {a} \), \( \texttt {s} \), \( \texttt {m} \) and \( \texttt {d} \), which are respectively defined for operators’ addition, subtraction, multiplication and division in package “Calculator.LR.FNs”.

  3. 3.

    Merge and combine some packages (which have a same/similar goal) to achieve a more powerful package.

  4. 4.

    Introduce useful packages to the fuzzy researchers by publishing and comparing related manuscripts.

  5. 5.

    Like the usual calculators for crisp data, the calculator for fuzzy numbers can be developed in future for more complex functions; e.g. for functions \(e^x\), log(x), \( \frac{1}{x} \), \(x^y\)x! and sin(x) .

  6. 6.

    Package “FuzzyNumbers” is able to extend one-variable monotone function f(.) based on extension principle by the \( \texttt {fapply} \) function for a fuzzy number. Package “FuzzyNumbers.Ext.2” is able to extend two-variable monotone function f(., .) based on extension principle by the \( \texttt {f2apply} \) function [14]. Study of the extension of any k-variable monotone function, s.t. \(k \in \{1,2,3, \ldots \}\), is a potential subject for further research.