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

# sech

Use the `sech()` function to calculate the hyperbolic secant of a numeric value. The hyperbolic secant is the reciprocal of the hyperbolic cosine function.

## Syntax

```sql
sech(<number>)
```

## Parameters

| Name     | Type           | Required | Description                                                                               |
| -------- | -------------- | -------- | ----------------------------------------------------------------------------------------- |
| `number` | integer, float | Yes      | The numeric value for which to calculate the hyperbolic secant. Any real number is valid. |

## Returns

**Type**: float

**Description**: The `sech()` function returns the hyperbolic secant of the input value, which is equivalent to `1 / cosh(x)`. The result is always in the range (0, 1]. 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 `sech()` function accepts any real number as input.
* **Null Handling**: If the input expression is `null`, the function returns `null`.
* **Symmetry**: The function is even, meaning `sech(-x) = sech(x)`.
* **Maximum Value**: `sech(0)` returns `1.0`, which is the maximum value of the function.
* **Asymptotic Behavior**: As `x` approaches positive or negative infinity, `sech(x)` approaches `0`.
* **Result Range**: The output is always > 0 and ≤ 1.
* **Common Use Cases**: This function is typically used within the `alter` stage for mathematical modeling, signal processing, and scientific computations.

## Examples

### Example 1: Calculate hyperbolic secant of literal values

**Goal**: Calculate the hyperbolic secant for specific numeric literals to verify known mathematical results.

**XQL code**:

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

**Explanation**: `sech(0)` returns `1.0` (the maximum value). `sech(1)` and `sech(-1)` both return approximately `0.6481`, demonstrating the even symmetry of the function.

**Output**:

| RESULT1 | RESULT2 | RESULT3 |
| ------- | ------- | ------- |
| 1.0     | 0.64805 | 0.64805 |

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

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

**XQL code**:

```sql
config timeframe = 1d
| dataset = sample_xql_raw
| alter sech_result = sech(duration_seconds)
| fields event_id, duration_seconds, sech_result
| limit 3
```

**Explanation**: This query computes the hyperbolic secant for each value in the `duration_seconds` field. No filtering is needed since `sech()` accepts any real number.

**Output**:

| EVENT\_ID | DURATION\_SECONDS | SECH\_RESULT |
| --------- | ----------------- | ------------ |
| 101       | 0.0               | 1.0          |
| 102       | 1.0               | 0.64805      |
| 103       | 3.0               | 0.09933      |

### Example 3: Verify sech as reciprocal of cosh

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

**XQL code**:

```sql
config timeframe = 1d
| dataset = sample_xql_raw
| alter sech_val = sech(numeric_value)
| alter reciprocal_cosh = divide(1, cosh(numeric_value))
| fields event_id, numeric_value, sech_val, reciprocal_cosh
| limit 3
```

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

**Output**:

| EVENT\_ID | NUMERIC\_VALUE | SECH\_VAL | RECIPROCAL\_COSH |
| --------- | -------------- | --------- | ---------------- |
| 101       | 0.0            | 1.0       | 1.0              |
| 102       | 1.0            | 0.64805   | 0.64805          |
| 103       | 2.0            | 0.26580   | 0.26580          |

## Related articles

* **Stages**: [`alter`](https://cortex-docs.paloaltonetworks.com/xql-command-reference-guide/readme/stages/alter.md), [`fields`](https://cortex-docs.paloaltonetworks.com/xql-command-reference-guide/readme/stages/fields.md), [`limit`](https://cortex-docs.paloaltonetworks.com/xql-command-reference-guide/readme/stages/limit.md)
* **Functions**: [`cosh`](https://cortex-docs.paloaltonetworks.com/xql-command-reference-guide/readme/functions/cosh.md), [`sec`](https://cortex-docs.paloaltonetworks.com/xql-command-reference-guide/readme/functions/sec.md), [`csch`](https://cortex-docs.paloaltonetworks.com/xql-command-reference-guide/readme/functions/csch.md), [`tanh`](https://cortex-docs.paloaltonetworks.com/xql-command-reference-guide/readme/functions/tanh.md)


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
