> 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/sec.md).

# sec

Use the `sec()` function to calculate the secant of a numeric value specified in radians. The secant is the reciprocal of the cosine function.

## Syntax

```sql
sec(<numeric_expression>)
```

## Parameters

| Name                 | Type           | Required | Description                                                                                           |
| -------------------- | -------------- | -------- | ----------------------------------------------------------------------------------------------------- |
| `numeric_expression` | integer, float | Yes      | The angle in radians for which to calculate the secant. The value must not be an odd multiple of p/2. |

## Returns

**Type**: float

**Description**: The `sec()` function returns the secant of the input angle, which is equivalent to `1 / cos(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 `sec()` function accepts any real number except values where `cos(x) = 0` (i.e., odd multiples of p/2), where the secant is undefined.
* **Undefined Values**: At odd multiples of p/2 (for example, p/2, 3p/2), the function returns `infinity`, `NaN`, or `null` since the secant is undefined at these points.
* **Null Handling**: If the input expression is `null`, the function returns `null`.
* **Relationship**: `sec(x) = 1 / cos(x)`.
* **Result Range**: The result is always = -1 or = 1 (never between -1 and 1).
* **Common Use Cases**: This function is typically used within the `alter` stage for trigonometric calculations, optics computations, and engineering analysis.

## Examples

### Example 1: Calculate secant of literal values

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

**XQL code**:

```sql
dataset = xdr_data
| limit 1
| alter result1 = sec(0), result2 = sec(pi()), result3 = sec(1)
| fields result1, result2, result3
```

**Explanation**: `sec(0)` returns `1.0` (since `cos(0) = 1`), `sec(p)` returns `-1.0` (since `cos(p) = -1`), and `sec(1)` returns approximately `1.8508`.

**Output**:

| RESULT1 | RESULT2 | RESULT3 |
| ------- | ------- | ------- |
| 1.0     | -1.0    | 1.85082 |

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

**Goal**: Calculate the secant of values stored in a dataset field.

**XQL code**:

```sql
config timeframe = 1d
| dataset = sample_xql_raw
| alter sec_val = sec(numeric_value)
| fields event_id, numeric_value, sec_val
| limit 3
```

**Explanation**: This query computes the secant for each value in the `numeric_value` field and stores the result in `sec_val`.

**Output**:

| EVENT\_ID | NUMERIC\_VALUE | SEC\_VAL |
| --------- | -------------- | -------- |
| 101       | 0.0            | 1.0      |
| 102       | 1.0            | 1.85082  |
| 103       | 3.14159        | -1.0     |

### Example 3: Verify secant as reciprocal of cosine

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

**XQL code**:

```sql
config timeframe = 1d
| dataset = sample_xql_raw
| alter sec_val = sec(numeric_value)
| alter reciprocal_cos = divide(1, cos(numeric_value))
| fields event_id, numeric_value, sec_val, reciprocal_cos
| limit 3
```

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

**Output**:

| EVENT\_ID | NUMERIC\_VALUE | SEC\_VAL | RECIPROCAL\_COS |
| --------- | -------------- | -------- | --------------- |
| 101       | 0.0            | 1.0      | 1.0             |
| 102       | 1.0            | 1.85082  | 1.85082         |
| 103       | 3.14159        | -1.0     | -1.0            |

## Related articles

* **Stages**: [`alter`](/xql-command-reference-guide/readme/stages/alter.md), [`fields`](/xql-command-reference-guide/readme/stages/fields.md), [`limit`](/xql-command-reference-guide/readme/stages/limit.md)
* **Functions**: [`cos()`](/xql-command-reference-guide/readme/functions/cos.md), [`csc()`](/xql-command-reference-guide/readme/functions/csc.md), `sech()`, [`cot()`](/xql-command-reference-guide/readme/functions/cot.md)
* **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/sec.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.
