≡ ▼
```=L_ISUNIFORM(vector, [precision_n])
```
ArgumentDescriptionExample
vectorThe sequence of values you want to check{2; 3; 4; 5}
precision_nThe precision (number of decimal places) to use for evaluating equality of step sizes10

## Description

L_ISUNIFORM returns {TRUE;step} if the values in the vector are evenly spaced (all steps are identical). If FALSE, it returns {FALSE; MAX(step)-MIN(step)}.

You can set the precision_n parameter to be a number of decimal places (such as 10), and the step size will be rounded to that number of decimal places prior to testing for uniformity.

Purpose of precision_n: In some cases, precision errors in Excel may cause this function to return FALSE when you might otherwise consider the uniformity to be "close enough." For example, if MAX(step)-MIN(step) is a number smaller than 1E-10, it might be a precision error, and you might determine that a difference in step size smaller than 1E-10 is sufficient to consider the vector uniform.

In Excel, make the function return only a single value by using the @ symbol in front of the function: =@L_ISUNIFORM(...).

## Lambda Formula

This code for using L_ISUNIFORM in Excel is provided under the License as part of the LAMBDA Library, but to use just this function, you may copy the following code directly into your spreadsheet.

### Code to Create Function via the Name Manager

```Name: L_ISUNIFORM
Comment: Returns {TRUE;step} if the vector is uniformly spaced
Refers To:

=LAMBDA(vector,[precision_n],
LET(doc,"https://www.vertex42.com/lambda/isuniform.html",
rows,ROWS(vector),cols,COLUMNS(vector),
vector,TAKE(IF(AND(cols>1,rows=1),TRANSPOSE(vector),vector),,1),
steps,DROP(vector,1)-DROP(vector,-1),
unique_steps,UNIQUE(IF(ISOMITTED(precision_n),steps,ROUND(steps,precision_n))),
IF(ROWS(unique_steps)=1,
TRUE,
VSTACK(FALSE,MAX(unique_steps)-MIN(unique_steps))
)
))
```

### Code for AFE Workbook Module (Excel Labs Add-in)

```/**
* Returns {TRUE;step} if the vector is uniformly spaced (all the
* steps are identical to a precision of n decimal places)
* If FALSE, returns {FALSE, MAX(steps)-MIN(steps)}
*/
L_ISUNIFORM = LAMBDA(vector,[precision_n],
LET(doc,"https://www.vertex42.com/lambda/isuniform.html",
rows,ROWS(vector),cols,COLUMNS(vector),
vector,TAKE(IF(AND(cols>1,rows=1),TRANSPOSE(vector),vector),,1),
steps,DROP(vector,1)-DROP(vector,-1),
unique_steps,UNIQUE(IF(ISOMITTED(precision_n),steps,ROUND(steps,precision_n))),
IF(ROWS(unique_steps)=1,
TRUE,
VSTACK(FALSE,MAX(unique_steps)-MIN(unique_steps))
)
));
```

### Named Function for Google Sheets

```Name: L_ISUNIFORM
Description: Returns {TRUE;step} if the vector is uniformly spaced (steps are identical). If FALSE, returns {FALSE, MAX(steps)-MIN(steps)}
Arguments: vector, precision_n
Function:

LET(doc,"https://www.vertex42.com/lambda/isuniform.html",
r,ROWS(vector),
steps,ARRAYFORMULA(CHOOSEROWS(vector,SEQUENCE(r-1,1,2))-CHOOSEROWS(vector,SEQUENCE(r-1,1,1))),    unique_steps,UNIQUE(IF(ISBLANK(precision_n),steps,ARRAYFORMULA(ROUND(steps,precision_n)))),
ret,IF(ROWS(unique_steps)=1,TRUE,VSTACK(FALSE,MAX(unique_steps)-MIN(unique_steps))),
ret
)
```
Warning
These functions are not compatible between Excel and Google Sheets. When using these functions, you will not be able to convert the Excel file to Google Sheets or vice versa without problems.

## L_ISUNIFORM Examples

Example: Check L_LINSPACE for Uniformity
The result of L_LINSPACE is always uniform, unless there is precision or rounding error.
```Test: Copy and Paste this LET function into a cell
=LET(
vector, L_LINSPACE(1,2,4),
L_ISUNIFORM(vector)
)

Result: TRUE

=LET(
vector, {1; 1.333333; 1.666667; 2},
L_ISUNIFORM(vector)
)

Result: {FALSE; 1E-6}
```
Example: Check L_LOGSPACE for Uniformity
Using L_LOGSPACE is likely to result in a precision error if you later check it for uniformity. Note that L_LOGSPACE is not linearly uniform. However, the log of the sequence should be, so LOG10(L_LOGSPACE(...)) should be uniform.
```Test: Copy and Paste this LET function into a cell
=LET(
logseq, L_LOGSPACE(1,2,5),
L_ISUNIFORM(LOG10(logseq))
)

Result: {FALSE; 4.4409E-16}
```

In this case, if you set the precision_n parameter to 14, then the Result will be TRUE.

References & Resources