author | Jan Rocnik <jan.rocnik@student.tugraz.at> |
Fri, 31 Aug 2012 19:19:07 +0200 | |
changeset 42461 | 94c9a0735e2f |
parent 42444 | 2768aa42a383 |
child 48789 | 498ed5bb1004 |
permissions | -rwxr-xr-x |
jan@42461 | 1 |
|
jan@42443 | 2 |
|
jan@42443 | 3 |
theory example_3 imports Isac |
jan@42443 | 4 |
begin |
jan@42443 | 5 |
|
jan@42444 | 6 |
section{*Function Decleration*} |
jan@42444 | 7 |
text{*Following code should only represent an example and was taken as a |
jan@42444 | 8 |
snipset from Rationals.thy located in |
jan@42444 | 9 |
\texttt{/src/Tools/isac/Knowledge}*} |
jan@42444 | 10 |
|
jan@42443 | 11 |
(*----START----Example Function Decleration from Rationals.thy----*) |
jan@42444 | 12 |
|
jan@42444 | 13 |
text{*Define Method name and input, output types*} |
jan@42444 | 14 |
|
jan@42443 | 15 |
consts |
jan@42443 | 16 |
get_denominator :: "real => real" |
jan@42443 | 17 |
|
jan@42444 | 18 |
text{*Always add a comment with the method name and where it can be found.*} |
jan@42444 | 19 |
|
jan@42443 | 20 |
ML {* |
jan@42443 | 21 |
(* |
jan@42443 | 22 |
*("get_denominator", |
jan@42443 | 23 |
* ("Rational.get_denominator", eval_get_denominator "")) |
jan@42443 | 24 |
*) |
jan@42443 | 25 |
fun eval_get_denominator (thmid:string) _ |
jan@42443 | 26 |
(t as Const ("Rational.get_denominator", _) $ |
jan@42443 | 27 |
(Const ("Rings.inverse_class.divide", _) $num |
jan@42443 | 28 |
$denom)) thy = |
jan@42443 | 29 |
SOME (mk_thmid thmid "" |
jan@42443 | 30 |
(Print_Mode.setmp [] |
jan@42443 | 31 |
(Syntax.string_of_term (thy2ctxt thy)) denom) "", |
jan@42443 | 32 |
Trueprop $ (mk_equality (t, denom))) |
jan@42443 | 33 |
| eval_get_denominator _ _ _ _ = NONE; |
jan@42443 | 34 |
*} |
jan@42443 | 35 |
(*----END----Example Function Decleration from Rationals.thy----*) |
jan@42443 | 36 |
|
jan@42444 | 37 |
text{*Apply the Method to an expression.*} |
jan@42444 | 38 |
|
jan@42443 | 39 |
ML{* |
jan@42444 | 40 |
val input = term_of (the (parse thy "get_denominator ((a + b) / c)")); |
jan@42443 | 41 |
val SOME (_, output) = eval_get_denominator "" 0 input thy; |
jan@42443 | 42 |
*} |
jan@42443 | 43 |
|
jan@42443 | 44 |
ML{* |
jan@42443 | 45 |
term2str output; |
jan@42443 | 46 |
*} |
jan@42443 | 47 |
|
jan@42443 | 48 |
end |