### 1 unstable release

0.1.0 | Mar 29, 2024 |
---|

#**355** in Math

**MIT/Apache**

180KB

1K
SLoC

# perplex_num

## Overview

is a Rust crate that provides an implementation of perplex numbers, based on the numerical abstractions of the num_traits crate. This library supports various mathematical functions such as `perplex_num`

, `pow`

, `sqrt`

, `exp`

, `ln`

, `sinh`

, `sin`

, and `cosh`

. Additionally, the crate offers a hyperbolic polar form for representing and manipulating numbers in the hyperbolic plane, as well as a matrix form representation feature based on nalgebra.`tan`

For an **in-depth explanation** (including visualizations) of perplex numbers and how they integrate with the crate's modules, see the Perplex Number Description in the repository.

## Features

- The

struct is equipped with a comprehensive set of common mathematical operations, courtesy of`Perplex`

and`std`ops`::`

.`num_traits` - Emulating the functionality of

, the`nalgebra`Complex`::`

struct mirrors most functions found in the num_complex crate, maintaining consistent naming conventions.`Perplex` - It supports the hyperbolic polar form across all sectors of the plane.
- The matrix representation feature is based upon the robust foundation of nalgebra::Matrix.

## Usage

## Installation

or add this to `cargo`` add perplex_num`

:`Cargo.toml`

`[``dependencies``]`
`perplex_num ``=` `"`0.1`"`

The

feature is enabled by default, which adds the `matrix`

crate as a dependency. This can be disabled with:`nalgebra`

`[``dependencies.perplex_num``]`
`perplex_num ``=` `"`0.1`"`
`default-features ``=` `false`

## Examples

The

directory contains various practical demonstrations of how to use the `examples`

crate. These examples not only illustrate the usage of perplex numbers but also show how to produce visualizations as seen in the Perplex Number Description.`perplex_num`

For instance,

is executed by the following command:`examples/visualize_functions.rs`

`cargo`` run`` --`example visualize_functions

This will generate an image that depicts the behavior of functions like

, `sinh`

, `cos`

, and `inv`

when applied to perplex numbers.`exp`

### Creating a Perplex Number and Performing Operations

Here's a quick example of how to get started with creating a perplex number and performing basic operations:

`use` `perplex_num``::`Perplex`;`
`fn` `main``(``)`` ``{`
`//` Create a Perplex number with real part 1.0 and hyperbolic part 0.5
`let` z `=` `Perplex``::`new`(``1.``0``,` `0.``5``)``;`
`//` Calculate the hyperbolic sine of the perplex number
`let` z_sinh `=` z`.``sinh``(``)``;`
`//` Raise the perplex number or it's inverse to the power of 2
`let` z_squared `=` z`.``powu``(``2``)``;`
`let` z_inv_squared `=` z`.``powi``(``-``2``)``.``expect``(``"`z is invertible`"``)``;`
`println!``(``"`The hyperbolic sine of `{}` is `{:.5}``"``,` z`,` z_sinh`)``;`
`println!``(``"``{}` raised to the power of 2 is `{:.3}``"``,` z`,` z_squared`)``;`
`println!``(``"``{}` raised to the power of -2 is `{:.3}``"``,` z`,` z_inv_squared`)``;`
`}`

## Coverage

Test coverage report is generated with cargo tarpaulin. Invoke it with:

`cargo`` tarpaulin`` --`verbose` --`all-targets` --`skip-clean` --`exclude-files `"`examples/*.rs`"` `"`benches/*.rs`"`

## Compatibility

The

crate is tested for rustc 1.76.`perplex_num`

## Bibliography

- The Mathematics of Minkowski Space-Time
- Hyperbolic trigonometry in two-dimensional space-time geometry
- Fundamental Theorems of Algebra for the Perplexes
- Introduction to Hybrid Numbers
- New characterizations of the ring of the split-complex numbers and the field C of complex numbers and their comparative analyses

#### Dependencies

~130–760KB

~15K SLoC