/// Setup MathJax and HTML helpers
@"<script src=""https://raw.githubusercontent.com/mathjax/MathJax/master/latest.js?config=TeX-AMS-MML_CHTM""></script>" |> Util.Html |> Display
let html x = { Html = x }
let h1 text = { Html = "<h1>" + text + "</h1>" }
let h2 text = { Html = "<h2>" + text + "</h2>" }
let h3 text = { Html = "<h3>" + text + "</h3>" }
let ul text = { Html = "<ul><li>" + text + "</li></ul>" }
let ul3 text = { Html = "<ul><li><h3>" + text + "</h3></li></ul>" }
let img url = { Html = "<img src=\"" + url + "\"" + " style=\"align:center\" />" }
let uli text url = { Html = "<ul><li>" + text + "<img src=\"" + url + "\"" + " style=\"align:center\" />" + "</li></ul>" }
let uli2 text url = { Html = "<h2><ul><li>" + text + "<img src=\"" + url + "\"" + " style=\"align:center\" />" + "</li></ul></h2>" }
let uli3 text url = { Html = "<h3><ul><li>" + text + "<img src=\"" + url + "\"" + " style=\"align:center\" />" + "</li></ul></h3>" }
let inline (^+^) (x:HtmlOutput) (y:HtmlOutput) = { Html = x.Html + y.Html }
// Use the Sylvester.Tensors package from NuGet
#load "Paket.fsx"
Paket.Package["Sylvester.Arithmetic"; "Sylvester.Tensors"; "Sylvester.DataFrame"; "FSharp.Interop.Dynamic"]
#load "Paket.Generated.Refs.fsx"
open System
open System.Collections.Generic
open System.Linq;
open FSharp.Interop.Dynamic
open Sylvester.Data
open Sylvester.Arithmetic
open Sylvester.Arithmetic.N10
open Sylvester.Arithmetic.Collections
open Sylvester.Tensors
uli2 "West Indies" "https://upload.wikimedia.org/wikipedia/commons/9/98/Caribbean_general_map.png"
uli2 "Indians came to Trinidad in the 19th century as indentured labourers" "https://thepeopleafterslavery.files.wordpress.com/2014/03/indentured-labourers-2.png"
uli2 "Today Trinidad is multi-ethnic and multi-cultural" "http://currentriggers.com/wp-content/uploads/2016/11/4-17.jpg"
uli2 "Divali and other religious festivals celebrated by all" "https://www.guardian.co.tt/image-3.1974716.c274fa76ed?size=512"
uli2 "Cricket!" "https://akm-img-a-in.tosshub.com/indiatoday/images/story/201810/AP18297590913026.jpeg?P8W81HcX8oQiGA9xATv_s0lOWQKR3LH9"
let titanic = new CsvFile("https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv")
titanic.["Pclass"].First().Type <- typeof<int>
let dt = Frame(titanic)
query {
for r in dt do
groupBy r?Pclass into g
sortBy g.Key
select (
let survived = (g.Where(fun p -> p?Survived = "1").Count()) |> float
let died = (g.Where(fun p -> p?Survived = "0").Count()) |> float
let ctotal = survived + died
let psurvived = round(100.0 * survived / ctotal)
let pdied = round(100.0 * died / ctotal)
(g.Key, pdied, psurvived)
)} |> Util.Table
Item1 | Item2 | Item3 |
---|---|---|
1 | 37 | 63 |
2 | 53 | 47 |
3 | 76 | 24 |
let v1 = Vec<1000>.Rand //Create a vector of length 1000
let v2 = Vec<500>.Rand //Create a vector of length 500
v1 + v2 //Can we do this?
Type constraint mismatch. The type 'Vector<float32,0,0,0,0,0,0,0,5,0,0>' is not compatible with type 'Vector<float32,0,0,0,0,0,0,1,0,0,0>'
The Future of Programming is Dependent Types... https://medium.com/background-thread/the-future-of-programming-is-dependent-types-programming-word-of-the-day-fcd5f2634878
Idris, a language that will change the way you think about programming...https://crufter.com/idris-a-language-that-will-change-the-way-you-think-about-programming
...but
Dependent ML (DML) is a conservative extension of the functional programming language ML. The type system of DML enriches that of ML with a restricted form of dependent types. This allows many interesting program properties such as memory safety and termination to be captured in the type system of DML and then be verified at compiler-time.
// Create typed instance of some natural numbers
let a = new N<1000>()
let b = new N<900>()
a +< b
Sylvester.Arithmetic.Bool+False
a +> b
Sylvester.Arithmetic.Bool+True
a +!= b
Sylvester.Arithmetic.Bool+True
a +== b
Sylvester.Arithmetic.Bool+False
check((b * a) +== zero) //Causes type error
This expression was expected to have type 'Success' but here has type 'Failure'
check ((a - b) +> zero) // But this is ok
zero - a //This results in another type, not a compiler error
N10Underflow