Feel++ expressions
1. Using Mathematical expressions
Mathematical expressions are described as strings in C++, python or json files. An expression is composed of symbols and operations acting on them.
Available standard operations and functions are :
-
+, -, *, /
addition, substraction, multiplication and division respectively -
^
given two real numbersx
andy
,x^y
computex`
to the powery
-
log
-
exp
-
sin
-
cos
-
tan
-
asin
-
acos
-
atan
-
sinh
-
cosh
-
tanh
-
asinh
-
acosh
-
atanh
-
atan2
-
sqrt
-
mod
: given integersx
andy
, computemod(x,y)
-
min
,max
: given 2 real numbersx
andy
,min(x,y)
andmax(x,y)
compute the minimum and maximym respectively. -
lgamma
: Evaluation oflgamma(x)
, the natural logarithm of the Gamma function. -
tgamma
: Evaluation oftgamma(x)
, the true Gamma function.
2. Additional Mathematical functions
2.1. ceil
- Description
-
ceil(v)
computes the smallest integer value not less than arg. - Keyword
-
ceil
- Math
-
Given real number \(x\), integer \(m\) and the set of integers \(\mathbb{Z}\), ceil can be defined by the equation
C++ example
|
json example
|
2.2. floor
- Description
-
floor(v)
computes the largest integer value not greater than arg. - Keyword
-
floor
- Math
-
Given real number \(x\), integer \(m\) and the set of integers \(\mathbb{Z}\), floor can be defined by the equation
C++ example
|
json example
|
2.3. fract
- Description
-
fract(v)
compute the fractional part of the argument. This is calculated as \(v - floor(v)\). - Keyword
-
fract
- Math
-
The fractional part is the sawtooth function, denoted by \(\{x\}\) for real \(x\) and defined by the formula
For all \(x\), we have
C++ example
|
json example
|
2.4. clamp
- Description
-
clamp(v,lo,hi)
If v compares less than lo, returns lo; otherwise if hi compares less than v, returns hi; otherwise returns v. - Keyword
-
clamp
C++ example
|
json example
|
2.5. Modulo
- Description
-
mod(x,y)
compute the modulo operation: it returns the remainder or signed remainder of the division \(x/y\). - Keyword
-
mod
auto e = expr("mod(u,v):u:v");
e.setParameterValues( { { "u", 2 }, { "v", 1 }} );
CHECK( std::abs( e.evaluate()(0,0) ) < 1e-12 ) << "Error in modulo";
e.setParameterValues( { { "u", 3 }, { "v", 6 }} );
CHECK( std::abs( e.evaluate()(0,0) - 3) < 1e-12 ) << "Error in modulo";
e.setParameterValues( { { "u", 6.1 }, { "v", 3 }} );
CHECK( std::abs( e.evaluate()(0,0) - 0.1) < 1e-12 ) << "Error in modulo";
}
3. Mappings
3.1. mapabcd
mapabcd
is the function \(f\) that allows to map \([a,b]\) to \([c,d]\), it is defines as follows
with \(f(a)=c\) and \(f(b)=d\).
auto e = expr("mapabcd(t,1,2,-1,1):t");
e.setParameterValues( { { "t", 1 } } );
CHECK( std::abs(e.evaluate()(0,0)- (-1)) < 1e-12 ) << "Invalid mapping";
e.setParameterValues( { { "t", 2 } } );
CHECK( std::abs( e.evaluate()(0,0)- 1 ) < 1e-12 ) << "Invalid mapping";
e.setParameterValues( { { "t", 1.5 } } );
CHECK( std::abs( e.evaluate()(0,0) ) < 1e-12 ) << "Invalid mapping";
4. Step functions
A function \(f\colon \mathbb{R} \rightarrow \mathbb{R}\) is called a step function if it can be written as
where \(n\ge 0\), \(\alpha_i\) are real numbers, \(A_i\) are intervals, and \(\chi_A\) is the indicator function of \(A\):
4.1. step1
- Description
-
step1(u,edge)
return 0 isu
is strictly less thanedge
, 1 otherwise. - Keyword
-
step1
C++ example
|
json example
|
4.2. smoothstep
- Description
-
smoothstep(u,lo,hi)
is calculated as follows:
smoothstep
uses the clamp
function
- Keyword
-
smoothstep
C++ example
|
json example
|