Splunk Search

Can eval evaluate Cosines?

davecroto
Splunk Employee
Splunk Employee

Can eval evaluate Cosines?

Tags (1)

aljohnson_splun
Splunk Employee
Splunk Employee

sdorich
Communicator

Approximate functions like cosine or sine using its Taylor series!

http://www.math.sc.edu/~girardi/m142/handouts/10sTaylorPolySeries.pdf

Write a stanza in macros.conf that defines cosine as an approximation using its Taylor series.

Ex:

[cosine(1)]
args=x
description = calculates an approximate value for cosine of x
definition = eval cosineX=(1 - ((x*x)/2) + ((x*x*x*x)/(4*3*2)) - ....)

And add as many terms as you'd like - as you add more terms your approximation of cosine of x will start to converge to the actual value.

sdorich
Communicator

By the way, I haven't actually tried this so my above answer may need some tweaking.

0 Karma

sdorich
Communicator

I forgot to add money signs around all the x terms in the definition above - each x should be surrounded (i.e. $x$*$x$...)

0 Karma

dwaddle
SplunkTrust
SplunkTrust

This could be a good candidate for a custom search command. See http://www.splunk.com/base/Documentation/latest/SearchReference/Aboutcustomsearchcommands for info on how to roll your own.

Something else to consider is filing an ER (Enhancement request) for either providing additional mathematical functions in eval (If you're going to do cosine -- you might as well do sine, secant, and tangent) or providing a way to create user-defined eval functions. (Assuming, of course, that the API for an eval UDF would have any benefit at all over a custom search command. I am not certain if this is the case or not)

Ayn
Legend

No, it cannot.

A complete list of commands supported by eval is available here: http://www.splunk.com/base/Documentation/latest/SearchReference/CommonEvalFunctions

Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...