From 15b590bd6a1f17f3859752594d5d8ff534cd38b3 Mon Sep 17 00:00:00 2001 From: "Navid C. Constantinou" Date: Sat, 12 Aug 2023 06:47:17 +0300 Subject: [PATCH] Docs formatting (#50049) --- doc/src/manual/functions.md | 78 +++++++++++------------ doc/src/manual/mathematical-operations.md | 18 +++--- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/doc/src/manual/functions.md b/doc/src/manual/functions.md index a724f450dccfa..f589e9c345dfd 100644 --- a/doc/src/manual/functions.md +++ b/doc/src/manual/functions.md @@ -5,7 +5,7 @@ functions are not pure mathematical functions, because they can alter and be aff by the global state of the program. The basic syntax for defining functions in Julia is: ```jldoctest -julia> function f(x,y) +julia> function f(x, y) x + y end f (generic function with 1 method) @@ -18,7 +18,7 @@ There is a second, more terse syntax for defining a function in Julia. The tradi declaration syntax demonstrated above is equivalent to the following compact "assignment form": ```jldoctest fofxy -julia> f(x,y) = x + y +julia> f(x, y) = x + y f (generic function with 1 method) ``` @@ -30,7 +30,7 @@ both typing and visual noise. A function is called using the traditional parenthesis syntax: ```jldoctest fofxy -julia> f(2,3) +julia> f(2, 3) 5 ``` @@ -40,14 +40,14 @@ like any other value: ```jldoctest fofxy julia> g = f; -julia> g(2,3) +julia> g(2, 3) 5 ``` As with variables, Unicode can also be used for function names: ```jldoctest -julia> ∑(x,y) = x + y +julia> ∑(x, y) = x + y ∑ (generic function with 1 method) julia> ∑(2, 3) @@ -77,7 +77,7 @@ by the caller for this argument. On the other hand, the assignment `y = 7 + y` `y` to refer to a new value `7 + y`, rather than mutating the *original* object referred to by `y`, and hence does *not* change the corresponding argument passed by the caller. This can be seen if we call `f(x, y)`: ```julia-repl -julia> a = [4,5,6] +julia> a = [4, 5, 6] 3-element Vector{Int64}: 4 5 @@ -130,7 +130,7 @@ the `return` keyword causes a function to return immediately, providing an expression whose value is returned: ```julia -function g(x,y) +function g(x, y) return x * y x + y end @@ -140,19 +140,19 @@ Since function definitions can be entered into interactive sessions, it is easy definitions: ```jldoctest -julia> f(x,y) = x + y +julia> f(x, y) = x + y f (generic function with 1 method) -julia> function g(x,y) +julia> function g(x, y) return x * y x + y end g (generic function with 1 method) -julia> f(2,3) +julia> f(2, 3) 5 -julia> g(2,3) +julia> g(2, 3) 6 ``` @@ -163,18 +163,18 @@ is of real use. Here, for example, is a function that computes the hypotenuse le triangle with sides of length `x` and `y`, avoiding overflow: ```jldoctest -julia> function hypot(x,y) +julia> function hypot(x, y) x = abs(x) y = abs(y) if x > y r = y/x - return x*sqrt(1+r*r) + return x*sqrt(1 + r*r) end if y == 0 return zero(x) end r = x/y - return y*sqrt(1+r*r) + return y*sqrt(1 + r*r) end hypot (generic function with 1 method) @@ -243,7 +243,7 @@ as you would any other function: julia> 1 + 2 + 3 6 -julia> +(1,2,3) +julia> +(1, 2, 3) 6 ``` @@ -254,7 +254,7 @@ operators such as [`+`](@ref) and [`*`](@ref) just like you would with other fun ```jldoctest julia> f = +; -julia> f(1,2,3) +julia> f(1, 2, 3) 6 ``` @@ -402,7 +402,7 @@ left side of an assignment: the value on the right side is _destructured_ by ite over and assigning to each variable in turn: ```jldoctest -julia> (a,b,c) = 1:3 +julia> (a, b, c) = 1:3 1:3 julia> b @@ -417,7 +417,7 @@ This can be used to return multiple values from functions by returning a tuple o other iterable value. For example, the following function returns two values: ```jldoctest foofunc -julia> function foo(a,b) +julia> function foo(a, b) a+b, a*b end foo (generic function with 1 method) @@ -427,14 +427,14 @@ If you call it in an interactive session without assigning the return value anyw see the tuple returned: ```jldoctest foofunc -julia> foo(2,3) +julia> foo(2, 3) (5, 6) ``` Destructuring assignment extracts each value into a variable: ```jldoctest foofunc -julia> x, y = foo(2,3) +julia> x, y = foo(2, 3) (5, 6) julia> x @@ -473,7 +473,7 @@ Other valid left-hand side expressions can be used as elements of the assignment ```jldoctest julia> X = zeros(3); -julia> X[1], (a,b) = (1, (2, 3)) +julia> X[1], (a, b) = (1, (2, 3)) (1, (2, 3)) julia> X @@ -625,7 +625,7 @@ julia> foo(A(3, 4)) For anonymous functions, destructuring a single argument requires an extra comma: ``` -julia> map(((x,y),) -> x + y, [(1,2), (3,4)]) +julia> map(((x, y),) -> x + y, [(1, 2), (3, 4)]) 2-element Array{Int64,1}: 3 7 @@ -638,7 +638,7 @@ Such functions are traditionally known as "varargs" functions, which is short fo of arguments". You can define a varargs function by following the last positional argument with an ellipsis: ```jldoctest barfunc -julia> bar(a,b,x...) = (a,b,x) +julia> bar(a, b, x...) = (a, b, x) bar (generic function with 1 method) ``` @@ -647,16 +647,16 @@ The variables `a` and `b` are bound to the first two argument values as usual, a two arguments: ```jldoctest barfunc -julia> bar(1,2) +julia> bar(1, 2) (1, 2, ()) -julia> bar(1,2,3) +julia> bar(1, 2, 3) (1, 2, (3,)) julia> bar(1, 2, 3, 4) (1, 2, (3, 4)) -julia> bar(1,2,3,4,5,6) +julia> bar(1, 2, 3, 4, 5, 6) (1, 2, (3, 4, 5, 6)) ``` @@ -673,7 +673,7 @@ call instead: julia> x = (3, 4) (3, 4) -julia> bar(1,2,x...) +julia> bar(1, 2, x...) (1, 2, (3, 4)) ``` @@ -684,7 +684,7 @@ of arguments go. This need not be the case, however: julia> x = (2, 3, 4) (2, 3, 4) -julia> bar(1,x...) +julia> bar(1, x...) (1, 2, (3, 4)) julia> x = (1, 2, 3, 4) @@ -697,15 +697,15 @@ julia> bar(x...) Furthermore, the iterable object splatted into a function call need not be a tuple: ```jldoctest barfunc -julia> x = [3,4] +julia> x = [3, 4] 2-element Vector{Int64}: 3 4 -julia> bar(1,2,x...) +julia> bar(1, 2, x...) (1, 2, (3, 4)) -julia> x = [1,2,3,4] +julia> x = [1, 2, 3, 4] 4-element Vector{Int64}: 1 2 @@ -720,9 +720,9 @@ Also, the function that arguments are splatted into need not be a varargs functi often is): ```jldoctest -julia> baz(a,b) = a + b; +julia> baz(a, b) = a + b; -julia> args = [1,2] +julia> args = [1, 2] 2-element Vector{Int64}: 1 2 @@ -730,7 +730,7 @@ julia> args = [1,2] julia> baz(args...) 3 -julia> args = [1,2,3] +julia> args = [1, 2, 3] 3-element Vector{Int64}: 1 2 @@ -831,7 +831,7 @@ prior keyword arguments. The types of keyword arguments can be made explicit as follows: ```julia -function f(;x::Int=1) +function f(; x::Int=1) ### end ``` @@ -1077,13 +1077,13 @@ in advance by the library writer. More generally, `f.(args...)` is actually equivalent to `broadcast(f, args...)`, which allows you to operate on multiple arrays (even of different shapes), or a mix of arrays and scalars (see -[Broadcasting](@ref)). For example, if you have `f(x,y) = 3x + 4y`, then `f.(pi,A)` will return -a new array consisting of `f(pi,a)` for each `a` in `A`, and `f.(vector1,vector2)` will return -a new vector consisting of `f(vector1[i],vector2[i])` for each index `i` (throwing an exception +[Broadcasting](@ref)). For example, if you have `f(x, y) = 3x + 4y`, then `f.(pi, A)` will return +a new array consisting of `f(pi,a)` for each `a` in `A`, and `f.(vector1, vector2)` will return +a new vector consisting of `f(vector1[i], vector2[i])` for each index `i` (throwing an exception if the vectors have different length). ```jldoctest -julia> f(x,y) = 3x + 4y; +julia> f(x, y) = 3x + 4y; julia> A = [1.0, 2.0, 3.0]; diff --git a/doc/src/manual/mathematical-operations.md b/doc/src/manual/mathematical-operations.md index 0c33b45b609b7..c808b14f10e0e 100644 --- a/doc/src/manual/mathematical-operations.md +++ b/doc/src/manual/mathematical-operations.md @@ -22,7 +22,7 @@ are supported on all primitive numeric types: | `x ^ y` | power | raises `x` to the `y`th power | | `x % y` | remainder | equivalent to `rem(x, y)` | -A numeric literal placed directly before an identifier or parentheses, e.g. `2x` or `2(x+y)`, is treated as a multiplication, except with higher precedence than other binary operations. See [Numeric Literal Coefficients](@ref man-numeric-literal-coefficients) for details. +A numeric literal placed directly before an identifier or parentheses, e.g. `2x` or `2(x + y)`, is treated as a multiplication, except with higher precedence than other binary operations. See [Numeric Literal Coefficients](@ref man-numeric-literal-coefficients) for details. Julia's promotion system makes arithmetic operations on mixtures of argument types "just work" naturally and automatically. See [Conversion and Promotion](@ref conversion-and-promotion) for details of the promotion @@ -204,9 +204,9 @@ as `a .= a .+ b`, where `.=` is a fused *in-place* assignment operation (see the [dot syntax documentation](@ref man-vectorized)). Note the dot syntax is also applicable to user-defined operators. -For example, if you define `⊗(A,B) = kron(A,B)` to give a convenient +For example, if you define `⊗(A, B) = kron(A, B)` to give a convenient infix syntax `A ⊗ B` for Kronecker products ([`kron`](@ref)), then -`[A,B] .⊗ [C,D]` will compute `[A⊗C, B⊗D]` with no additional coding. +`[A, B] .⊗ [C, D]` will compute `[A⊗C, B⊗D]` with no additional coding. Combining dot operators with numeric literals can be ambiguous. For example, it is not clear whether `1.+x` means `1. + x` or `1 .+ x`. @@ -457,7 +457,7 @@ Juxtaposition parses like a unary operator, which has the same natural asymmetry Julia supports three forms of numerical conversion, which differ in their handling of inexact conversions. - * The notation `T(x)` or `convert(T,x)` converts `x` to a value of type `T`. + * The notation `T(x)` or `convert(T, x)` converts `x` to a value of type `T`. * If `T` is a floating-point type, the result is the nearest representable value, which could be positive or negative infinity. @@ -534,7 +534,7 @@ See [Conversion and Promotion](@ref conversion-and-promotion) for how to define | [`mod1(x, y)`](@ref) | `mod` with offset 1; returns `r∈(0, y]` for `y>0` or `r∈[y, 0)` for `y<0`, where `mod(r, y) == mod(x, y)` | | [`mod2pi(x)`](@ref) | modulus with respect to 2pi; `0 <= mod2pi(x) < 2pi` | | [`divrem(x, y)`](@ref) | returns `(div(x, y),rem(x, y))` | -| [`fldmod(x, y)`](@ref) | returns `(fld(x, y),mod(x, y ))` | +| [`fldmod(x, y)`](@ref) | returns `(fld(x, y), mod(x, y))` | | [`gcd(x, y...)`](@ref) | greatest positive common divisor of `x`, `y`,... | | [`lcm(x, y...)`](@ref) | least positive common multiple of `x`, `y`,... | @@ -557,13 +557,13 @@ See [Conversion and Promotion](@ref conversion-and-promotion) for how to define | [`cbrt(x)`](@ref), `∛x` | cube root of `x` | | [`hypot(x, y)`](@ref) | hypotenuse of right-angled triangle with other sides of length `x` and `y` | | [`exp(x)`](@ref) | natural exponential function at `x` | -| [`expm1(x)`](@ref) | accurate `exp(x)-1` for `x` near zero | -| [`ldexp(x, n)`](@ref) | `x*2^n` computed efficiently for integer values of `n` | +| [`expm1(x)`](@ref) | accurate `exp(x) - 1` for `x` near zero | +| [`ldexp(x, n)`](@ref) | `x * 2^n` computed efficiently for integer values of `n` | | [`log(x)`](@ref) | natural logarithm of `x` | | [`log(b, x)`](@ref) | base `b` logarithm of `x` | | [`log2(x)`](@ref) | base 2 logarithm of `x` | | [`log10(x)`](@ref) | base 10 logarithm of `x` | -| [`log1p(x)`](@ref) | accurate `log(1+x)` for `x` near zero | +| [`log1p(x)`](@ref) | accurate `log(1 + x)` for `x` near zero | | [`exponent(x)`](@ref) | binary exponent of `x` | | [`significand(x)`](@ref) | binary significand (a.k.a. mantissa) of a floating-point number `x` | @@ -587,7 +587,7 @@ These are all single-argument functions, with [`atan`](@ref) also accepting two corresponding to a traditional [`atan2`](https://en.wikipedia.org/wiki/Atan2) function. Additionally, [`sinpi(x)`](@ref) and [`cospi(x)`](@ref) are provided for more accurate computations -of [`sin(pi*x)`](@ref) and [`cos(pi*x)`](@ref) respectively. +of [`sin(pi * x)`](@ref) and [`cos(pi * x)`](@ref) respectively. In order to compute trigonometric functions with degrees instead of radians, suffix the function with `d`. For example, [`sind(x)`](@ref) computes the sine of `x` where `x` is specified in degrees.