Wed Jun 26 13:51:09 UTC 2019

fuzzy 2.0.1 released!

This version adds the this keyword referring to the current class object. This supports more for the object style. You can write like this:

term TEMPERATURE(100, 200, 5)
    fuzzy low = 100;
    fuzzy medium = 150;
    fuzzy high = 200;

term SPEED(0, 100, 5)
    fuzzy low = 0;
    fuzzy medium = 50;
    fuzzy high = 100;
    void SetRules(int temp_input) {
        temp = temp_input;
        rule temp.low => low;
        rule temp.medium => medium;
        rule temp.high => high;
    int Defuzz() { return Defuzz(this); }

SPEED speed;
print speed.Defuzz();

Sun Jun 23 07:05:40 UTC 2019

fuzzy 2.0 released!

Changes in this version:
1) Fixed the implementation of fuzzy inference rules
Perform fuzzy logic operations on the left of the inference symbol => first, then inference. Previously, fuzzy logic operations were performed on the target fuzzy set on the right of the inference symbol => so the results were not close to the desired rules.
2) Setup the fuzzy terms automatically according to left bound, right bound and size of fuzzy set
Fuzzy sets created are hybrid fuzzy sets, they have membership function that are continuous functions and read input values ​​as continuous values, but the elements of the fuzzy sets are discrete with the number of elements being size of declared fuzzy term.
For example,
term WIND(0, 100, 11)
    fuzzy gale = 100;
    fuzzy strong = 60;
    fuzzy moderate = 40;
    fuzzy breeze = 20;
    fuzzy calm = 0;
define a fuzzy term with 5 fuzzy sets, each fuzzy set has 11 elements with values ​​in the range from 0 to 100. Each fuzzy set is initialized with its central value through assignment.
3) Add fuzzy operations EXTREMELY, SEEMED, BIT
EXTREMELY is equivalent to VERY VERY VERY.
Because hybrid fuzzy sets are created automatically, it is necessary to add an operation called BIT. This operation is often used to get a bit of information of a fuzzy set to union another fuzzy set. The result is a  union fuzzy set.
For example there are two fuzzy sets
wind.calm := (1/0, 0.4/10, 0.04/20, 0.0006/30, 0.000002/40, 0/50)
wind.breeze := (0.04/0, 0.4/10, 1/20, 0.4/30, 0.04/40, 0/50)

LITTLE LITTLE wind.calm is
(1/0, 0.8/10, 0.45/20, 0.16/30, 0.04/40, 0/50)

BIT wind.breeze is
(0.02/0, 0.2/10, 0.5/20, 0.2/30, 0.02/40, 0/50)

Hence LITTLE LITTLE wind.calm OR BIT wind.breeze will be
(1/0, 0.8/10, 0.5/20, 0.2/30, 0.04/40, 0/50)

4) Add built-in function Classify() used to classify fuzzy sets
This function uses a special defuzzification method. See Is it possible to do defuzzication a discrete fuzzy set?
The Classify() function has the signature
The function returns a value that represents the class of the fuzzy set or the fuzzy term fuzzy.
A complete example of using this function is in the Sail solution.

5) Defuzz() function is no longer needed to classify, but it is retained for historical reasons, or used for other calculations or presenting information
The function is also modified, with two arguments instead of one as before:
Defuzz(fuzzy, bContinuous = false)
This function by default returns the defuzzification value of the discrete fuzzy set according to the centroid method.
If bContinuous is true, fuzzy set fuzzy is treated as a continuous fuzzy set with membership function whose graph is linear lines connecting the vertices of the elements of the fuzzy set.

Sun Jun 16 00:28:29 UTC 2019

fuzzy 1.5.1 released!

This version adds a built-in function named PutReading() to read the input for fuzzy sets instead of the put keyword which has to be done with many code lines. Many code lines like

put wind := (0/0, 0.5/10, 1/i, 0.5/30, 0/40, 0/50, 0/60, 0/70, 0/80, 0/90, 0/100);
can be replaced with:
PutReading (wind, i);
Its 5-argument version has more options:

PutReading (fuzzy, val, grade, rate, clear)
fuzzy: A fuzzy set or a fuzzy term
val: A numeric value or a variable of type int or Number
grade: A grade value set for the fuzzy set element with value val
rate: Grade ratio for the neighbor elements
clear: A variable or value of type boolean. If it is true, all the grades of the fuzzy set are set to zero before setting the new value. If it is false, the old grades remain intact. Then PutReading() function can be used multiple times on a fuzzy set.
For example,
PutReading (wind, 42, 1, 0.5, true);
will set the data for the wind term as follows
(0/0, 0/10, 0/20, 0.5/30, 1/40, 0.5/50, 0/60, 0/70, 0/80, 0/90, 0/100)
The value set for the element of the fuzzy set does not need to match exactly. The function will automatically find the closest value.

PutReading (wind, 105, 0.5, 0, false);
The result is
(0/0, 0/10, 0/20, 0.5/30, 1/40, 0.5/50, 0/60, 0/70, 0/80, 0/90, 0.5/100)
The PutReading() function returns the actual value of the element that is set grade:
Number val = PutReading (wind, 105, 0.5, 0, false);
print val;

This version also adds a pre-declared variable named 'size' containing the number of elements of the fuzzy set of the fuzzy terms. So you can write like this:
term WIND(11) {};

WIND wind;
print wind.size;
The output will be 11.

Fri Jun 14 07:25:13 UTC 2019

fuzzy 1.4.1 released!

This version adds a way to pass information from the outside into a Fuzzy program via the command line argument, and return the result from the program via the exit code as an expression.
Suppose you have val1, val2, val3 values ​​that want to read into a program named myfuzzy.c, run the following command:

fuzzy -r "val1 val2 val3" myfuzzy.c

Inside the myfuzzy.c program you can handle the pre-declared global variables system_reading_count and system_reading_array. system_reading_count is a variable of type int containing the number of values ​​in the command line argument. system_reading_array is an array of type String containing values ​​in the command line argument. So you can write like this:

int count = system_reading_count;
for (int i = 0; i < count; i ++)
    print system_reading_array[i];

Program exit codes can be used as results returned from the program. Assume that the program file myfuzzy.c has the following content:

int score = 2;
exit (score);

Running Python will result:

Tip: For a portable binary version you compile as below at the src directory:

g++ -Wno-return-type -o fuzzy *.cc

Sun Sep 2 16:39:37 UTC 2018

fuzzy 1.3.1 released!

Configuring and building:

./configure --prefix=/usr

Now, as the root user:

make install

GitHub: https://github.com/phamtyn/fuzzy

Mon Nov 14 00:26:23 UTC 2016
Fuzzy 1.3 released!
Fixed scope for user-defined type in the function (body) which be member of an array element

Tue Nov 8 10:06:03 UTC 2016
Fuzzy 1.2 released!
Fixed and extended overloading functions

Sat Nov 5 15:25:38 UTC 2016
Fuzzy 1.1 released!
Fixed statement return in loop and switch statements

Thu Nov 3 15:37:49 UTC 2016
FUZZY Programming Language

Fuzzy 1.0 released!


    fuzzy PROGRAM-FILE
fuzzy -h

Fuzzy is an implementation of the FUZZY programming language. Fuzzy is designed to process linguistic variables and fuzzy sets with vague concepts such as HIGH, LOW, MEDIUM, VERY HIGH, NOT VERY LOW. Fuzzy reads the FUZZY program source from the file PROGRAM-FILE.


    -h Display the help and exit


Hello World program
FUZZY programs have no main function. The source codes of a simplest program may like this

print "Hello World";

Basic types
Basic types are int, Number, String, bool and fuzzy. Most of them can be assigned to another, for instance

int i = 100;
i += 50;
String text = i;
speed.high = i + 50; // speed.high is a fuzzy set

Control Statements
Control Statements while, for, if, else, break, continue, return are similar to C/C++. Statement switch can be used for String type

switch(text) // text is a String variable
case "abc":
// do something
case "def":
// do something

Override functions
Similar to C++, Fuzzy can be used to override functions and operators. operator= can be used with return type is void. Member variables can be initialized inside a struct

struct OBJECT
int m_i = 50;
String m_string = "abc";
Number m_array[10]; //an array of Number
void operator = (OBJECT t)
m_i = t.m_i;
m_string = t.m_string;
for(int i = 0; i < 10; i++)
m_array[i] = t.m_array[i];
OBJECT operator - ()
obj.m_i = -m_i;
return obj;

fuzzy set and fuzzy term
Discrete fuzzy sets must be declared inside a discrete fuzzy term. The following example shows a fuzzy term with three fuzzy sets. Each one has five elements, each element is a pair grade/value

fuzzy discrete low(1/100, 0.5/125, 0.25/150, 0.1/175, 0/200);
fuzzy discrete medium(0.25/100, 0.5/125, 1/150, 0.5/175, 0.25/200);
fuzzy discrete high(0/100, 0/125, 0.25/150, 0.75/175, 1/200);

Put data into a fuzzy term
Keyword put be used to set values and membership values for fuzzy terms

TEMPERATURE temperature;
temperature := (0/100, 0/125, 0.5/150, 0.25/175, 0/200);

Apply fuzzy rules

rule temperature.medium AND pressure.medium OR weather.bad OR traffic.bad => speed.low;
rule VERY
temperature.high AND pressure.low OR NOT VERY temperature.high AND pressure.medium AND NOT VERY traffic.bad => speed.high;
temperature.low AND pressure.high AND REALLY weather.normal OR traffic.normal => speed.medium;
rule (
temperature.medium OR pressure.low) AND weather.good OR pressure.low AND traffic.good => speed.high;
temperature.medium AND LITTLE pressure.high AND VERY VERY weather.good => speed.high;

Print fuzzy sets and fuzzy terms
The following statement prints defuzzification value of a fuzzy term

print speed;

if you want to print its fuzzy data, you can use statement prints

prints speed;

Defuzzification method be used is centroid method, function Defuzz returns defuzzification value of a fuzzy term

Number val = Defuzz(pressure);

Reset fuzzy sets and fuzzy terms
Function ZeroFuzz be used to reset all data of a fuzzy set or fuzzy term to zero


Transfer fuzzy data to array
There is a built-in struct named FuzzyPair. To transfer fuzzy data to array, you declare an array of FuzzyPair whose size is sufficient to store data, then use function FuzzyToArray like this

FuzzyPair array[8];
FuzzyToArray(speed, array);

The struct FuzzyPair has two members, they are m_grade and m_value

for(int i = 0; i < 8; i++)
print array[i].m_grade, " ", array[i].m_value;

Continuous fuzzy
This type of fuzzy be applied for fuzzy sets which have a declared domain and a center value. The membership function be used is Gaussian function

term TEMPERATURE(100, 200)
fuzzy low = 100;
fuzzy medium = 150;
fuzzy high = 200;

Print to file
Token > be used to redirect output to file for print and prints

print speed > "filename.txt";

Token >> be used to redirect for print and prints, append output to the file

prints speed >> "filename.txt";

Execute a shell command
Execute a shell command with keyword system

String command_text = "sudo makeca -f";

Math functions
Built-in functions of math are sin, cos, tan, atan, ln, log10, exp, pow, sqrt, floor, round, abs, min, and max

Include file
Include file is similar to C/C++

#include "filename.h"

Comment is similar to C/C++, used with token // or pair /* and */

  • See also

Ngôn ngữ lập trình FUZZY: chiến lược bảng băm

Ngôn ngữ lập trình FUZZY: giải mờ một ví dụ quen thuộc

Ngôn ngữ lập trình FUZZY: biến String và phép gán dưới khía cạnh ngôn ngữ

Một chương trình Fuzzy đơn giản

Ngôn ngữ lập trình FUZZY (ngôn ngữ mờ) – chương trình dịch Fuzzy 1.0