Skip to content

Commit

Permalink
Fix spelling
Browse files Browse the repository at this point in the history
  • Loading branch information
kfl committed Mar 23, 2017
1 parent f2d2fbc commit 4666d43
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 43 deletions.
15 changes: 4 additions & 11 deletions Expr.sml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
structure Expr =
struct

(* Labled expression with labels of type 'e on sub expressions, and
(* Labelled expression with labels of type 'e on sub expressions, and
labels of type 'v on variables. Constants are unlabled.
*)
datatype ('e, 'v) Labled =
datatype ('e, 'v) Labelled =
X of 'v * int
| Con of real
| Neg of ('e, 'v) Expr
Expand All @@ -13,7 +13,7 @@ datatype ('e, 'v) Labled =
| Exp of ('e, 'v) Expr (* e^x *)
| Sin of ('e, 'v) Expr (* sin x *)
| Cos of ('e, 'v) Expr (* cos x *)
withtype ('e, 'v) Expr = 'e * ('e, 'v) Labled
withtype ('e, 'v) Expr = 'e * ('e, 'v) Labelled



Expand All @@ -37,7 +37,7 @@ fun eval (_, exp) xs =
fun unit_elab e = ((), e)
val & = unit_elab

val const = & o Con
fun const e = &(Con e)

fun ref_elab e = (ref NONE, e)

Expand Down Expand Up @@ -86,13 +86,6 @@ fun bigTime ad esize n_vars x0 =
end









fun makeFib elab vlab n =
let infix ++
fun x ++ y = elab(Plus(x, y))
Expand Down
20 changes: 6 additions & 14 deletions Forward.sml
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
(*
datatype Expr = X of int
| Con of real
| Neg of Expr
| Plus of Expr * Expr
| Mult of Expr * Expr
| Exp of Expr (* e^x *)
| Sin of Expr (* sin x *)
| Cos of Expr (* cos x *)
*)
local
datatype Labelled = datatype Expr.Labelled
fun & e = Expr.unit_elab e
in

datatype Labled = datatype Expr.Labled
val & = Expr.&

fun zipWith f xs ys = Vector.mapi (fn (i, x) => f(x, Vector.sub(ys, i))) xs


fun zeroS n = Vector.tabulate(n, fn _ => Expr.const 0.0)
fun directionS n i = Vector.tabulate(n, fn j => if i = j then Expr.const 1.0 else Expr.const 0.0)
fun scalarS x v = Vector.map (fn e => &(Mult(x, e))) v


fun diff (labled as (_, expr)) n =
case expr of
X(_, i) => directionS n i
Expand Down Expand Up @@ -71,3 +62,4 @@ fun forward xs expr =
in (Math.cos ex, scalar (~(Math.sin ex)) ed) end
in #2(diffEval expr) end

end
24 changes: 6 additions & 18 deletions ReverseAD.sml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

datatype Labled = datatype Expr.Labled

local
datatype Labelled = datatype Expr.Labelled
in

(* evalDecorate label each sub expression with its evaluation *)
fun evalDecorate xs expr =
let fun decorate (_, expr) =
Expand Down Expand Up @@ -79,17 +80,6 @@ fun reverse xs expr =














(* derivativeDecorate and reduce can be fused *)
fun derivativeReduce n expr =
let infix +=
Expand Down Expand Up @@ -130,10 +120,6 @@ fun reverse_fused xs expr =







(* Problem: evalDecorate destroys sharing *)


Expand Down Expand Up @@ -191,3 +177,5 @@ fun reverse_imp xs expr =
val _ = evalUpdate xs expr
in derivativeReduce2 n expr
end

end

0 comments on commit 4666d43

Please sign in to comment.