INTERACT FORUM

More => Old Versions => Media Center 17 => Topic started by: MrC on November 21, 2011, 11:50:55 pm

Title: Math() : available functions list...
Post by: MrC on November 21, 2011, 11:50:55 pm
Here is the list of functions and operators I've been able to determine that are valid in the Math() expression:

+ - * / % ( )
abs(x)
atan(x)
cos(x), sin(x), tan(x)
log(x), log10(x)
min(x,y), max(x,y)
pow(x, y)
rand(seed)

If there are others you are aware of, or a reference of the complete list, post them here...
Title: Re: Math() : available functions list...
Post by: Matt on November 22, 2011, 08:38:15 am
A few more:
log10
abscos
abssin
randn (random with range -x to x)
sign
equal
below
above
if
Title: Re: Math() : available functions list...
Post by: Matt on November 22, 2011, 08:39:28 am
You can also save and use variables (and string of letters will be a variable).

Multiple equations can be run.  Sub-equations should be separated by a semi-colon.
Title: Re: Math() : available functions list...
Post by: MrC on November 22, 2011, 11:38:17 am
Thanks. 

Is this the syntax of if ?

  if(tcond,tval,fval)

eg:

  if(2+1,5,2)

this seems to work, but functions in tcond part do not:

  if(equal(2,1),5,2)
Title: Re: Math() : available functions list...
Post by: MrC on November 22, 2011, 12:45:04 pm
My current notes:

This Math() function provides the ability to perform mathematical calculations. It supports the standard arithmetic operators (e.g. addition, subtraction, etc.), provides some internal functions, and allows the use of variables and multiple statements.

Arithmetic Operators:
  + Addition
  - Subtraction
  * Multiplication
  / Division
  ^ Power
  % Modulo

Boolean Operators
  ! NOT
  & AND
  | OR

Grouping Operators
  ( ) Precedence grouping

Comparitor Operators
  } Absolute value maximum (i.e. x or y that is maximum distance from 0).
  { Absolute value minimum (i.e. x or y that is minimum distance from 0).
  > Distance between x and y, positive when x greater than y, negative otherwise.
  < Distance between x and y, positive when x less than y, negative otherwise.

Order of precedence is:
  ( )
  !
  ^   (TBD - when bug fixed next release)
  * /  left to right
  + -  left to right
  | &  left to right

Functions:
abs(x) Returns the absolute value of x.
sign(x)   Returns the sign of x (1 when x >= 0, -1 when x < 0).
log(x) Returns the natural logarithm (base e) of x.
log10(x) Returns the common logarithm (base 10) of x.
pow(x, y) Returns x raised to the y-th power.
rand(x)  Returns a random value ranging between 0 to x.
randn(x) Returns a random value ranging between -x and x.

Comparison Functions
min(x,y) Returns the minimum value of x and y.
max(x,y)  Returns the maximum value of x and y.
equal(x,y) Returns 1 when x = y, 0 otherwise.
below(x,y) Returns 1 when x < y, 0 otherwise.
above(x,y) Returns 1 when x > y, 0 otherwise.

Trigonometric functions
atan(x) Returns the arctangent of x.
cos(x) Returns the cosine of x.
sin(x) Returns the sine of x.
tan(x) Returns the tangent of x.
abscos(x) Returns the absolute value of cosine(x).
abssin(x) Returns the absolute value of sin(x).

if() function.... TBD

Variables may be assigned and used by specifying a simple string of letters (e.g. val=2 or x=pow(2,3)).

Multiple equations may be specified, each separated by a semicolon. Expressions are evaluated left to right.  The final value of the Math() function will be the result of the right-most equation.
Title: Re: Math() : available functions list...
Post by: Matt on November 22, 2011, 12:53:04 pm
A few more:
Power: x^y
Min: x<y
Max: x>y
Absolute value max: x}y
Absolute value min: x{y
Not: !x
And: x&y
Or: x|y
Title: Re: Math() : available functions list...
Post by: MrC on November 22, 2011, 01:19:40 pm
A few more:
Power: x^y
Min: x<y
Max: x>y

These seem more than described:

3^2 returns 1.4601391553878784
2^3 returns 1.4464412927627563

11>4 returns 7
11<4 returns -7

so it seems these are not min/max but rather abs. distance functions, with sign indicating if less than/greater than is true.
Title: Re: Math() : available functions list...
Post by: Matt on November 22, 2011, 01:34:48 pm
These seem more than described:

3^2 returns 1.4601391553878784
2^3 returns 1.4464412927627563

It was missing a break in a case statement, so you got an extra atan(...) as a bonus.

Quote
11>4 returns 7
11<4 returns -7

If(t,a,b) uses (t > 0) to evaluate conditionals, so functionally it should be the same.
Title: Re: Math() : available functions list...
Post by: MrC on November 22, 2011, 06:01:47 pm
Ok, the new build fixes the ^ operator.

I don't get how If() works:

math( if(0,5,2) )     returns 2, correct
math( if(1,5,2) )     returns 5, correct
math( if(1+1,5,2) )  returns 5, correct

math( if(1-1,5,2)  )  returns 5, not so correct
Title: Re: Math() : available functions list...
Post by: Matt on November 22, 2011, 06:30:16 pm
The if statements are probably being evaluated by the expression language, not the math language.  I suppose we'll need to special case this (or just not support it).
Title: Re: Math() : available functions list...
Post by: MrC on November 22, 2011, 06:46:04 pm
I was thinking that too.  I'll ignore it in the docs for now.  Surely if anyone finds a need in the future, they'll speak up.
Title: Re: Math() : available functions list...
Post by: MrC on November 22, 2011, 09:03:18 pm
Wiki updated: Math()... (http://wiki.jriver.com/index.php/Media_Center_expression_language#Math.28....29:_Evaluates_a_given_mathematical_formula)
Title: Re: Math() : available functions list...
Post by: JimH on November 23, 2011, 07:01:51 am
Wiki updated: Math()... (http://wiki.jriver.com/index.php/Media_Center_expression_language#Math.28....29:_Evaluates_a_given_mathematical_formula)
Thank you.
Title: Re: Math() : available functions list...
Post by: Matt on November 23, 2011, 09:01:37 am
Ditto on the thanks.  I think we owe you the next pie.
Title: Re: Math() : available functions list...
Post by: rick.ca on November 23, 2011, 05:01:53 pm
Nice. But now I'm compelled to dream up uses for it. Maybe a Smartlist Smackdown: Math() Madness Edition would help. But for that, we need someone to submit a problem that doesn't seem to have solution. Maybe some examples would generate interest. In the spirit of Carnac, they could offered in the form, "Here's an expression. What does it do?" ;)
Title: Re: Math() : available functions list...
Post by: kroser8 on November 03, 2015, 11:14:27 am
How to calculate the number of module?
For example,
math(% [Track #])         It gives 0
Title: Re: Math() : available functions list...
Post by: blgentry on November 03, 2015, 11:36:59 am
What are you trying to calculate?  You're using the modulus operator (%), which calculates a remainder.  For example:

10 % 3 = 1
10 % 2 = 0
10 % 4 = 2

It's the remainder, after division.

Brian.
Title: Re: Math() : available functions list...
Post by: kroser8 on November 04, 2015, 09:58:00 am
What are you trying to calculate?  You're using the modulus operator (%), which calculates a remainder.  For example:

10 % 3 = 1
10 % 2 = 0
10 % 4 = 2

It's the remainder, after division.

Brian.

Yeah, I took over the function of the "abs" "module": in Russian "module" means abs.))
|x|.
Title: Re: Math() : available functions list...
Post by: blgentry on November 04, 2015, 10:07:23 am
Yeah, I took over the function of the "abs" "module": in Russian "module" means abs.))
|x|.

Wow, that's really confusing!  I'm glad you figured it out.  :)

Brian.