Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/VDM/VDMPP/diet2japanPP/   (Wiener Entwicklungsmethode ©)  Datei vom 13.4.2020 mit Größe 1 kB image not shown  

Quelle  Diet.vdmpp   Sprache: VDM

 
\section{Diet Calculation}

\begin{vdm_al}
class Diet

values
public e = 1E-10;
public h = 1e-5; 

functions
static public BMI : realreal -> real
BMI(weight, height) ==
 let h100 = height / 100 in
 weight / h100 ** 2
pre
 weight > 0 and height > 0
post
 RESULT > 0;
\end{vdm_al}

\begin{vdm_al}
static public getWeightFromBMI : real * real -> real
getWeightFromBMI(height, aBMI) ==
 let 
  f = lambda weight : real & aBMI - BMI(weight, height) 
 in
 newton(f)(60)
pre
 height > 0 and aBMI > 0
post
 abs(aBMI - BMI(RESULT, height)) <= e;
\end{vdm_al}

\begin{vdm_al}
static public newton: (real ->real) -> real -> real
newton(f)(x) ==
 let isFinish = lambda y : real & abs(f(y)) < e,
  nextApproximate = lambda y : real & y - (f(y) / derivative(f)(y)) in
 Funtil[real](isFinish)(nextApproximate)(x);
\end{vdm_al}

\begin{vdm_al}
static public derivative : (real -> real) ->real -> real
derivative(f)(x) == (f(x+h) - f(x)) / h ;
\end{vdm_al}

\begin{vdm_al}
static public Funtil[@T] : (@T -> bool) -> (@T -> @T) -> @T -> @T
Funtil(p)(f)(x) == if p(x) then x else Funtil[@T](p)(f)(f(x));
\end{vdm_al}

\begin{vdm_al}
end Diet
\end{vdm_al}

Messung V0.5
C=100 H=91 G=95

¤ Dauer der Verarbeitung: 0.10 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.