> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/xql-command-reference-guide/readme/functions/cot.md).

# cot

Use the `cot()` function to calculate the cotangent of a numeric value specified in radians. The cotangent is the reciprocal of the tangent function.

## Syntax

```sql
cot(<numeric_expression>)
```

## Parameters

| Name                 | Type           | Required | Description                                                                                               |
| -------------------- | -------------- | -------- | --------------------------------------------------------------------------------------------------------- |
| `numeric_expression` | integer, float | Yes      | The angle in radians for which to calculate the cotangent. The value must not be zero or a multiple of π. |

## Returns

**Type**: float

**Description**: The `cot()` function returns the cotangent of the input angle, which is equivalent to `cos(x) / sin(x)` or `1 / tan(x)`. If the input is `null`, the function returns `null`.

## Usage notes

* **Input type**: XQL doesn't support NaN or infinite values as input and these value types also can not be returned.
* **Valid Input Range**: The `cot()` function accepts any real number except values where `sin(x) = 0` (i.e., multiples of π), where the cotangent is undefined.
* **Undefined Values**: At `x = 0` and multiples of π, the function returns `infinity`, `NaN`, or `null` since the cotangent is undefined at these points.
* **Null Handling**: If the input expression is `null`, the function returns `null`.
* **Relationship**: `cot(x) = 1 / tan(x) = cos(x) / sin(x)`.
* **Common Use Cases**: This function is typically used within the `alter` stage for trigonometric calculations, geometric analysis, and engineering computations.

## Examples

### Example 1: Calculate cotangent of literal values

**Goal**: Calculate the cotangent for specific radian values to verify known mathematical results.

**XQL code**:

```sql
dataset = xdr_data
| limit 1
| alter result1 = cot(divide(pi(), 4)), result2 = cot(divide(pi(), 2)), result3 = cot(1)
| fields result1, result2, result3
```

**Explanation**: You use `cot()` on three different radian values. `cot(π/4)` returns `1.0` (since `tan(π/4) = 1`), `cot(π/2)` returns approximately `0.0` (since `tan(π/2)` approaches infinity), and `cot(1)` returns approximately `0.6421`.

**Output**:

| RESULT1 | RESULT2 | RESULT3 |
| ------- | ------- | ------- |
| 1.0     | 0.0     | 0.64209 |

### Example 2: Calculate cotangent from a field value

**Goal**: Calculate the cotangent of values stored in a dataset field, filtering out values near zero.

**XQL code**:

```sql
config timeframe = 1d
| dataset = sample_xql_raw
| filter numeric_value != 0
| alter cot_val = cot(numeric_value)
| fields event_id, numeric_value, cot_val
| limit 3
```

**Explanation**: This query filters out zero values (where cotangent is undefined), then computes the cotangent for each remaining value in the `numeric_value` field.

**Output**:

| EVENT\_ID | NUMERIC\_VALUE | COT\_VAL |
| --------- | -------------- | -------- |
| 101       | 0.5            | 1.83049  |
| 102       | 1.0            | 0.64209  |
| 103       | 2.0            | -0.45766 |

### Example 3: Verify cotangent as reciprocal of tangent

**Goal**: Demonstrate that `cot(x)` equals `1 / tan(x)` by computing both and comparing.

**XQL code**:

```sql
config timeframe = 1d
| dataset = sample_xql_raw
| filter numeric_value != 0
| alter cot_val = cot(numeric_value)
| alter reciprocal_tan = divide(1, tan(numeric_value))
| fields event_id, numeric_value, cot_val, reciprocal_tan
| limit 3
```

**Explanation**: This query computes both `cot(numeric_value)` and `1 / tan(numeric_value)` to verify they produce the same result, confirming the mathematical identity `cot(x) = 1 / tan(x)`.

**Output**:

| EVENT\_ID | NUMERIC\_VALUE | COT\_VAL | RECIPROCAL\_TAN |
| --------- | -------------- | -------- | --------------- |
| 101       | 0.5            | 1.83049  | 1.83049         |
| 102       | 1.0            | 0.64209  | 0.64209         |
| 103       | 2.0            | -0.45766 | -0.45766        |

## Related articles

* **Stages**: [`alter`](/xql-command-reference-guide/readme/stages/alter.md), [`filter`](/xql-command-reference-guide/readme/stages/filter.md), [`fields`](/xql-command-reference-guide/readme/stages/fields.md), [`limit`](/xql-command-reference-guide/readme/stages/limit.md)
* **Functions**: [`tan()`](/xql-command-reference-guide/readme/functions/tan.md), [`cos()`](/xql-command-reference-guide/readme/functions/cos.md), [`sin()`](/xql-command-reference-guide/readme/functions/sin.md), `coth()`
* **Datasets**: [`xdr_data`](https://docs-cortex.paloaltonetworks.com/r/Cortex-XQL-Schema-Reference-Guide/Introduction)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cortex-docs.paloaltonetworks.com/xql-command-reference-guide/readme/functions/cot.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
