Skip to content

Instantly share code, notes, and snippets.

@MovGP0
Last active August 29, 2015 14:11
Show Gist options
  • Save MovGP0/9a97da2188f43581d064 to your computer and use it in GitHub Desktop.
Save MovGP0/9a97da2188f43581d064 to your computer and use it in GitHub Desktop.
Various formulas
/// <summary>Takes a list of values and scales the values, so that the sum of the result is always 1 (100%).</summary>
/// <param name="values">A list of values that need to be scaled.</param>
/// <returns>Scaled values, from which the sum is 1.</returns>
let scaleSoThatSumIsOne (values:seq<decimal>) =
let Σ = Seq.sum values
match Σ with
| 0.0m ->
let n = decimal (Seq.length values)
seq {
for p in values do
yield p + (1m / n)
}
| _ ->
let ΔΣ = 1m - Σ
seq {
for p in values do
yield p + (p * ΔΣ/Σ)
}
[<EntryPoint>]
let main argv =
for p in scaleSoThatSumIsOne [ 0.0m; -0.0m ] do
printfn "%M" p
0
let ε =
let rec δ λ =
match λ+1.0 with
| 1.0 -> λ
| _ -> δ(λ/2.0)
δ(1.0)
[<EntryPoint>]
let main argv =
printfn "ε = %e" ε
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment