>
type Fexpr =
| Const of float
| X
| Add of Fexpr * Fexpr
| Sub of Fexpr * Fexpr
| Mul of Fexpr * Fexpr
| Div of Fexpr * Fexpr
| Sin of Fexpr
| Cos of Fexpr
| Log of Fexpr
| Exp of Fexpr
val D : _arg1:Fexpr -> Fexpr
>
let rec D = function
| Const _ -> Const 0.0
| X -> Const 1.0
| Add(fe, ge) -> Add(D fe, D ge)
| Sub(fe, ge) -> Sub(D fe, D ge)
| Mul(fe, ge) -> Add(Mul(D fe,ge), Mul(fe, D ge))
| Div(fe, ge) -> Div(Sub(Mul(D fe, ge), Mul(fe, D ge)), Mul(ge, ge))
| Sin fe -> Mul(Cos fe, D fe)
| Cos fe -> Mul(Const -1.0, Mul(Sin fe, D fe))
| Log fe -> Div(D fe, fe)
| Exp fe -> Mul(Exp fe, D fe)
;;
val D : _arg1:Fexpr -> Fexpr
> D(Sin (Mul(X, X)));;
val it : Fexpr =
Mul (Cos (Mul (X,X)),Add (Mul (Const 1.0,X),Mul (X,Const 1.0)))
> D(Mul(Const 3.0, Exp X));;
val it : Fexpr =
Add (Mul (Const 0.0,Exp X),Mul (Const 3.0,Mul (Exp X,Const 1.0)))
>
F#简易符号求导程序
最新推荐文章于 2022-10-13 18:11:54 发布