[ https://issues.apache.org/jira/browse/TINKERPOP-1632?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16197251#comment-16197251 ]
ASF GitHub Bot commented on TINKERPOP-1632: ------------------------------------------- Github user spmallette commented on a diff in the pull request: https://github.com/apache/tinkerpop/pull/729#discussion_r143518649 --- Diff: docs/src/reference/the-traversal.asciidoc --- @@ -1207,6 +1207,50 @@ system to leverage the filter for index lookups. IMPORTANT: A `where()`-step is a filter and thus, variables within a `where()` clause are not globally bound to the path of the traverser in `match()`. As such, `where()`-steps in `match()` are used for filtering, not binding. +[[math-step]] +=== Math Step + +The `math()`-step (*math*) enables scientific calculator functionality within Gremlin. This step deviates from the common +function composition and nesting formalisms to provide an easy to read string-based math processor. Variables within the +equation map to scopes in Gremlin -- e.g. path labels, side-effects, or incoming map keys. This step supports +`by()`-modulation where the `by()`-modulators are applied in the order in which the variables are first referenced +within the equation. Note that the reserved variable `_` refers to the current numeric traverser object incoming to the +`math()`-step. + +[gremlin-groovy,modern] +---- +g.V().as('a').out('knows').as('b').math('a + b').by('age') +g.V().as('a').out('created').as('b'). + math('b + a'). + by(both().count().math('_ + 100')). + by('age') +g.withSideEffect('x',10).V().values('age').math('_ / x') +g.withSack(1).V(1).repeat(sack(sum).by(constant(1))).times(10).emit().sack().math('sin _') +---- + +The operators supported by the calculator include: `*`, `+`, `\`, `^`, and `%`. +Furthermore, the following built in functions are provided: + +* `abs`: absolute value +* `acos`: arc cosine +* `asin`: arc sine +* `atan`: arc tangent +* `cbrt`: cubic root +* `ceil`: nearest upper integer +* `cos`: cosine +* `cosh`: hyperbolic cosine +* `exp`: euler's number raised to the power (`e^x`) +* `floor`: nearest lower integer +* `log`: logarithmus naturalis (base e) +* `log10`: logarithm (base 10) +* `log2`: logarithm (base 2) +* `sin`: sine +* `sinh`: hyperbolic sine +* `sqrt`: square root +* `tan`: tangent +* `tanh`: hyperbolic tangent +* `signum`: signum function + --- End diff -- please reference the ticket number here. > Create a set of default functions > --------------------------------- > > Key: TINKERPOP-1632 > URL: https://issues.apache.org/jira/browse/TINKERPOP-1632 > Project: TinkerPop > Issue Type: Improvement > Components: process > Affects Versions: 3.3.0 > Reporter: Daniel Kuppitz > > We already have a a set of default BiFunctions / operators, that are not > treated as lambdas. We should also have a bunch of simple functions, that can > then be used in {{map()}} or {{sack()}} and that can be serialized as > bytecode. For example: > {noformat} > ...map(sqrt) > ...map(log) > ...sack(sigmoid) // compute sigmoid of the current sack and update the > sack > ...sack(cos).by("x") // compute the cosine of the current element's "x" and > assign / overwrite the current sack value > {noformat} -- This message was sent by Atlassian JIRA (v6.4.14#64029)