Skip to content

Commit feace22

Browse files
committed
update readme and tagbot
1 parent 2e3b031 commit feace22

File tree

2 files changed

+13
-132
lines changed

2 files changed

+13
-132
lines changed

.github/workflows/TagBot.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ jobs:
1212
- uses: JuliaRegistries/TagBot@v1
1313
with:
1414
token: ${{ secrets.GITHUB_TOKEN }}
15+
ssh: ${{ secrets.DOCUMENTER_KEY }}

README.md

Lines changed: 12 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# MultiplesOfPi
22

3-
[![Build Status](https://travis-ci.com/jishnub/MultiplesOfPi.jl.svg?branch=master)](https://travis-ci.com/jishnub/MultiplesOfPi.jl)
4-
[![Build Status](https://ci.appveyor.com/api/projects/status/github/jishnub/MultiplesOfPi.jl?svg=true)](https://ci.appveyor.com/project/jishnub/MultiplesOfPi-jl)
3+
54
[![Codecov](https://codecov.io/gh/jishnub/MultiplesOfPi.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/jishnub/MultiplesOfPi.jl)
65
[![Coverage Status](https://coveralls.io/repos/github/jishnub/MultiplesOfPi.jl/badge.svg?branch=master)](https://coveralls.io/github/jishnub/MultiplesOfPi.jl?branch=master)
76

87
# Introduction
98

10-
This package exports the type `PiExpTimes{N,T}` that satisfies `PiExpTimes{N,T}(x) = x*π^N`, and the type `PiTimes` that is aliased to `PiExpTimes{1}`. It also provides the constant `Pi` for convenience, defined as `PiTimes(1)`, that behaves like `π` except it produces results with higher accuracy in certain trigonometric and algebraic contexts. In most scenarios the numbers `Pi` and `π` are interchangable.
9+
This package exports the type `PiExpTimes` that satisfies `PiExpTimes(x, n) = x*π^n`. It also provides the constant `Pi` for convenience, defined as `PiExpTimes(1, 1)`, that behaves like `π` except it produces results with higher accuracy in certain trigonometric and algebraic contexts. In most scenarios the numbers `Pi` and `π` are interchangable.
1110

1211
```julia
1312
julia> Pi^2 == π^2
@@ -24,7 +23,7 @@ The number `π` is represented as an `Irrational` type in julia, and may be comp
2423

2524
## Arithmetic
2625

27-
Delaying the conversion of `π` to a float results in satisfying mathematical expressions such as
26+
Delaying the conversion of `π` to a float results in precise mathematical expressions such as
2827

2928
```julia
3029
julia> (1//3+ (4//3== (5//3
@@ -34,7 +33,7 @@ julia> (1//3)Pi + (4//3)Pi == (5//3)Pi
3433
true
3534
```
3635

37-
We may also simplify algebraic expressions involving powers of `Pi` as
36+
We may also simplify algebraic expressions involving powers of `Pi` as
3837

3938
```julia
4039
julia> (2Pi^2//3) // (4Pi//5)
@@ -44,21 +43,14 @@ julia> Pi^-2 / 4Pi^3
4443
0.25*Pi^-5
4544
```
4645

47-
The powers of `Pi` cancel as expected, and `Pi^0` is automatically converted to an ordinary real number wherever possible.
48-
49-
```julia
50-
julia> Pi^2 / Pi^2
51-
1.0
52-
```
53-
5446
Expressions involving `Pi` are automatically promoted to `Complex` as necessary, eg.
5547

5648
```julia
5749
julia> (1+im)Pi^3 / 2Pi^2
5850
0.5*Pi + 0.5*Pi*im
5951

6052
julia> (1+im)Pi^3 / 2Pi^2 * 2/Pi
61-
1.0 + 1.0im
53+
Pi^0 + Pi^0*im
6254
```
6355

6456
## Trigonometric functions
@@ -114,61 +106,22 @@ julia> cosh(im*Pi/2)
114106
0.0 + 0.0im
115107
```
116108

117-
## Algebra
118-
119-
We may convert between types having different exponents without losing accuracy.
120-
121-
```julia
122-
julia> convert(PiExpTimes{3},Pi)
123-
Pi^-2*Pi^3
124-
125-
julia> convert(PiExpTimes{3},Pi) == Pi
126-
true
127-
```
128-
129-
Such an expression may be reduced to a simple form using `simplify`.
130-
131-
```julia
132-
julia> convert(PiExpTimes{3},Pi) |> MultiplesOfPi.simplify
133-
Pi
134-
```
135-
136-
## Look out
137-
138-
### Type-instability
139-
140-
The type `PiExpTimes{N}` stores the exponent as a type-parameter, therefore exponentiation is not type-stable in general.
141-
142-
### Constructor-abuse to avoid nesting
143-
144-
`PiExpTimes{N}(PiExpTimes{M})` is automatically simplified to `PiExpTimes{N+M}`. This is an abuse of Julia's constructors as the type of the object changes, however this avoids nested expressions that have performance issues.
145-
146-
```julia
147-
julia> PiExpTimes{2}(PiExpTimes{3}(4))
148-
4Pi^5
149-
150-
julia> PiExpTimes{2}(PiExpTimes{3}(4)) |> typeof
151-
PiExpTimes{5,Int64}
152-
```
153-
154109
### Interactions with π
155110

156-
The irrational number `π` is usually aggressively converted to `PiTimes(1)`, eg:
111+
The irrational number `π` is usually aggressively converted to `Pi`, eg:
157112

158113
```julia
159-
julia> PiTimes(π)
114+
julia> π * Pi
160115
Pi^2
161116
```
162117

163-
This ensures that subsequent calculation would not get promoted to a floating-point type. However if this behavior is not desired then one may specify the type explicitly while constructing the object as
118+
This ensures that subsequent calculation would not get promoted to a floating-point type. However if this behavior is not desired then one may specify the type explicitly while constructing the object as
164119

165120
```julia
166-
julia> PiTimes{Irrational{:π}}(π)
167-
π = 3.1415926535897...*Pi
121+
julia> PiExpTimes{Irrational{:π}}(π)
122+
π*Pi^0
168123
```
169124

170-
However, it is not possible to convert a number to the type `PiTimes{Irrational{:π}}`.
171-
172125
### Floating-point promotion
173126

174127
Addition and subtraction involving mixed exponents of `Pi` will involve floating-point conversions, and the resulting expression will have the minimum exponent out of the terms being summed.
@@ -183,89 +136,16 @@ julia> Pi + 3Pi^2
183136

184137
This fits with the intuition of the expression being factorized as `Pi + 3Pi^2 == Pi*(1 + 3Pi)`.
185138

186-
Note that `π` is promoted to `Pi` in such operations, so we obtain
139+
Note that `π` is promoted to `Pi` in such operations, so we obtain
187140

188141
```julia
189142
julia> Pi + π
190143
2Pi
191144
```
192145

193-
### Conversion vs construction
194-
195-
Constructors for `PiExpTimes` act as a wrapper and not as a conversion. Conversion to the type retains the value of a number, whereas construction implies multiplication by an exponent of `Pi`.
196-
197-
```julia
198-
julia> PiTimes(1)
199-
Pi
200-
201-
julia> convert(PiTimes,1)
202-
Pi^-1*Pi
203-
```
204-
205-
### Promotion of mixed types
206-
207-
`promote` and `promote_type` work differently with types having different exponents. `promote` converts both the types to one that has the minimum exponent, whereas `promote_type` leaves the exponent as a free parameter.
208-
209-
```julia
210-
julia> promote(Pi,Pi^2) |> typeof
211-
Tuple{PiExpTimes{1,Real},PiExpTimes{1,Real}}
212-
213-
julia> promote_type(typeof(Pi),typeof(Pi^2))
214-
PiExpTimes{N,Int64} where N
215-
```
216-
217-
This is so that structs of `PiTimes` — such as complex numbers — do not lose accuracy in conversion. The behaviour is explained below with some examples:
218-
219-
#### Arrays of mixed types
220-
221-
Storing different exponents of `Pi` in an array will in general lead to conversion to a supertype that can store all the values.
222-
223-
```julia
224-
julia> [Pi,Pi^2] # element type is not concrete
225-
2-element Array{PiExpTimes{N,Int64} where N,1}:
226-
Pi
227-
Pi^2
228-
```
229-
230-
Such an array will not be the most performant, as the element type is not concrete. This may be avoided by specifying a type while creating the array. A concrete type will not be able to store all the numbers losslessly.
231-
232-
```julia
233-
julia> PiExpTimes{2,Real}[Pi,Pi^2] # exponent is fixed but Real is not a concrete type
234-
2-element Array{PiExpTimes{2,Real},1}:
235-
Pi^-1*Pi^2
236-
Pi^2
237-
238-
julia> PiExpTimes{2,Float64}[Pi,Pi^2] # eltype is concrete, but result loses accuracy
239-
2-element Array{PiExpTimes{2,Float64},1}:
240-
0.3183098861837907*Pi^2
241-
Pi^2
242-
```
243-
244-
#### Complex numbers
245-
246-
Complex numbers rely on `promote` to generate the element type
247-
248-
```julia
249-
julia> Complex(Pi,Pi^2)
250-
Pi + Pi*Pi*im
251-
252-
julia> Complex(Pi,Pi^2) |> typeof
253-
Complex{PiExpTimes{1,Real}}
254-
```
255-
256-
In this case converting either the real or imaginary part to a floating-point type would have resulted in a loss of accuracy. Such a type might not be performant, so if a conversion is desired then it might be enforced by specifying the element type while constructing the `Complex` struct:
257-
258-
```julia
259-
julia> Complex{PiTimes{Float64}}(Pi,Pi^2)
260-
Pi + 3.141592653589793*Pi*im
261-
262-
julia> Complex{PiTimes{Float64}}(Pi,Pi^2) |> typeof
263-
Complex{PiExpTimes{1,Float64}}
264-
```
265-
266146
# Installation
267147

268-
Install the package using
148+
Install the package using
269149

270150
```julia
271151
pkg> add MultiplesOfPi

0 commit comments

Comments
 (0)