src/HOL/Library/Code_Real_Approx_By_Float.thy
author nipkow
Wed, 13 Feb 2019 07:48:42 +0100
changeset 69801 a99a0f5474c5
parent 69064 5840724b1d71
child 69906 55534affe445
permissions -rw-r--r--
too agressive
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
63355
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
     1
(*  Title:      HOL/Library/Code_Real_Approx_By_Float.thy
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
     2
    Author:     Florian Haftmann
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
     3
    Author:     Johannes Hölzl
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
     4
    Author:     Tobias Nipkow
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
     5
*)
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
     6
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
     7
theory Code_Real_Approx_By_Float
51542
738598beeb26 tuned imports;
wenzelm
parents: 51143
diff changeset
     8
imports Complex_Main Code_Target_Int
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
     9
begin
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
    10
63355
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
    11
text\<open>
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
    12
  \<^bold>\<open>WARNING!\<close> This theory implements mathematical reals by machine reals
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
    13
  (floats). This is inconsistent. See the proof of False at the end of the
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
    14
  theory, where an equality on mathematical reals is (incorrectly) disproved
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
    15
  by mapping it to machine reals.
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
    16
63355
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
    17
  The \<^theory_text>\<open>value\<close> command cannot display real results yet.
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
    18
63355
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
    19
  The only legitimate use of this theory is as a tool for code generation
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
    20
  purposes.
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
    21
\<close>
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
    22
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    23
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    24
  type_constructor real \<rightharpoonup>
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    25
    (SML) "real"
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    26
    and (OCaml) "float"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
    27
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    28
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    29
  constant Ratreal \<rightharpoonup>
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    30
    (SML) "error/ \"Bad constant: Ratreal\""
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
    31
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    32
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    33
  constant "0 :: real" \<rightharpoonup>
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    34
    (SML) "0.0"
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    35
    and (OCaml) "0.0"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
    36
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    37
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    38
  constant "1 :: real" \<rightharpoonup>
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    39
    (SML) "1.0"
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    40
    and (OCaml) "1.0"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
    41
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    42
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    43
  constant "HOL.equal :: real \<Rightarrow> real \<Rightarrow> bool" \<rightharpoonup>
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    44
    (SML) "Real.== ((_), (_))"
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    45
    and (OCaml) "Pervasives.(=)"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
    46
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    47
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    48
  constant "Orderings.less_eq :: real \<Rightarrow> real \<Rightarrow> bool" \<rightharpoonup>
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    49
    (SML) "Real.<= ((_), (_))"
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    50
    and (OCaml) "Pervasives.(<=)"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
    51
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    52
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    53
  constant "Orderings.less :: real \<Rightarrow> real \<Rightarrow> bool" \<rightharpoonup>
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    54
    (SML) "Real.< ((_), (_))"
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    55
    and (OCaml) "Pervasives.(<)"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
    56
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    57
code_printing
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 66148
diff changeset
    58
  constant "(+) :: real \<Rightarrow> real \<Rightarrow> real" \<rightharpoonup>
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    59
    (SML) "Real.+ ((_), (_))"
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    60
    and (OCaml) "Pervasives.( +. )"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
    61
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    62
code_printing
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 67399
diff changeset
    63
  constant "(*) :: real \<Rightarrow> real \<Rightarrow> real" \<rightharpoonup>
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    64
    (SML) "Real.* ((_), (_))"
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    65
    and (OCaml) "Pervasives.( *. )"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
    66
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    67
code_printing
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 66148
diff changeset
    68
  constant "(-) :: real \<Rightarrow> real \<Rightarrow> real" \<rightharpoonup>
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    69
    (SML) "Real.- ((_), (_))"
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    70
    and (OCaml) "Pervasives.( -. )"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
    71
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    72
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    73
  constant "uminus :: real \<Rightarrow> real" \<rightharpoonup>
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    74
    (SML) "Real.~"
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    75
    and (OCaml) "Pervasives.( ~-. )"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
    76
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    77
code_printing
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 66148
diff changeset
    78
  constant "(/) :: real \<Rightarrow> real \<Rightarrow> real" \<rightharpoonup>
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    79
    (SML) "Real.'/ ((_), (_))"
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    80
    and (OCaml) "Pervasives.( '/. )"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
    81
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    82
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    83
  constant "HOL.equal :: real \<Rightarrow> real \<Rightarrow> bool" \<rightharpoonup>
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    84
    (SML) "Real.== ((_:real), (_))"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
    85
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    86
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    87
  constant "sqrt :: real \<Rightarrow> real" \<rightharpoonup>
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    88
    (SML) "Math.sqrt"
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
    89
    and (OCaml) "Pervasives.sqrt"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
    90
declare sqrt_def[code del]
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
    91
61115
3a4400985780 modernized name space management -- more uniform qualification;
wenzelm
parents: 60500
diff changeset
    92
context
3a4400985780 modernized name space management -- more uniform qualification;
wenzelm
parents: 60500
diff changeset
    93
begin
3a4400985780 modernized name space management -- more uniform qualification;
wenzelm
parents: 60500
diff changeset
    94
63355
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
    95
qualified definition real_exp :: "real \<Rightarrow> real"
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
    96
  where "real_exp = exp"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
    97
63355
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
    98
lemma exp_eq_real_exp [code_unfold]: "exp = real_exp"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
    99
  unfolding real_exp_def ..
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   100
61115
3a4400985780 modernized name space management -- more uniform qualification;
wenzelm
parents: 60500
diff changeset
   101
end
3a4400985780 modernized name space management -- more uniform qualification;
wenzelm
parents: 60500
diff changeset
   102
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   103
code_printing
61115
3a4400985780 modernized name space management -- more uniform qualification;
wenzelm
parents: 60500
diff changeset
   104
  constant Code_Real_Approx_By_Float.real_exp \<rightharpoonup>
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   105
    (SML) "Math.exp"
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   106
    and (OCaml) "Pervasives.exp"
61115
3a4400985780 modernized name space management -- more uniform qualification;
wenzelm
parents: 60500
diff changeset
   107
declare Code_Real_Approx_By_Float.real_exp_def[code del]
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   108
declare exp_def[code del]
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   109
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   110
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   111
  constant ln \<rightharpoonup>
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   112
    (SML) "Math.ln"
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   113
    and (OCaml) "Pervasives.ln"
60017
b785d6d06430 Overloading of ln and powr, but "approximation" no longer works for powr. Code generation also fails due to type ambiguity in scala.
paulson <lp15@cam.ac.uk>
parents: 54489
diff changeset
   114
declare ln_real_def[code del]
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   115
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   116
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   117
  constant cos \<rightharpoonup>
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   118
    (SML) "Math.cos"
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   119
    and (OCaml) "Pervasives.cos"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   120
declare cos_def[code del]
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   121
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   122
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   123
  constant sin \<rightharpoonup>
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   124
    (SML) "Math.sin"
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   125
    and (OCaml) "Pervasives.sin"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   126
declare sin_def[code del]
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   127
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   128
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   129
  constant pi \<rightharpoonup>
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   130
    (SML) "Math.pi"
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   131
    and (OCaml) "Pervasives.pi"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   132
declare pi_def[code del]
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   133
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   134
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   135
  constant arctan \<rightharpoonup>
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   136
    (SML) "Math.atan"
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   137
    and (OCaml) "Pervasives.atan"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   138
declare arctan_def[code del]
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   139
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   140
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   141
  constant arccos \<rightharpoonup>
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   142
    (SML) "Math.scos"
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   143
    and (OCaml) "Pervasives.acos"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   144
declare arccos_def[code del]
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   145
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   146
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   147
  constant arcsin \<rightharpoonup>
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   148
    (SML) "Math.asin"
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   149
    and (OCaml) "Pervasives.asin"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   150
declare arcsin_def[code del]
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   151
63355
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
   152
definition real_of_integer :: "integer \<Rightarrow> real"
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
   153
  where "real_of_integer = of_int \<circ> int_of_integer"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   154
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   155
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   156
  constant real_of_integer \<rightharpoonup>
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   157
    (SML) "Real.fromInt"
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   158
    and (OCaml) "Pervasives.float (Big'_int.int'_of'_big'_int (_))"
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   159
61115
3a4400985780 modernized name space management -- more uniform qualification;
wenzelm
parents: 60500
diff changeset
   160
context
3a4400985780 modernized name space management -- more uniform qualification;
wenzelm
parents: 60500
diff changeset
   161
begin
3a4400985780 modernized name space management -- more uniform qualification;
wenzelm
parents: 60500
diff changeset
   162
63355
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
   163
qualified definition real_of_int :: "int \<Rightarrow> real"
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
   164
  where [code_abbrev]: "real_of_int = of_int"
51143
0a2371e7ced3 two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents: 47108
diff changeset
   165
63355
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
   166
lemma [code]: "real_of_int = real_of_integer \<circ> integer_of_int"
51143
0a2371e7ced3 two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents: 47108
diff changeset
   167
  by (simp add: fun_eq_iff real_of_integer_def real_of_int_def)
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   168
63355
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
   169
lemma [code_unfold del]: "0 \<equiv> (of_rat 0 :: real)"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46530
diff changeset
   170
  by simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46530
diff changeset
   171
63355
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
   172
lemma [code_unfold del]: "1 \<equiv> (of_rat 1 :: real)"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46530
diff changeset
   173
  by simp
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   174
63355
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
   175
lemma [code_unfold del]: "numeral k \<equiv> (of_rat (numeral k) :: real)"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46530
diff changeset
   176
  by simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46530
diff changeset
   177
63355
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
   178
lemma [code_unfold del]: "- numeral k \<equiv> (of_rat (- numeral k) :: real)"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46530
diff changeset
   179
  by simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46530
diff changeset
   180
61115
3a4400985780 modernized name space management -- more uniform qualification;
wenzelm
parents: 60500
diff changeset
   181
end
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   182
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   183
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   184
  constant Ratreal \<rightharpoonup> (SML)
52403
140ae824ea4a Code_Real_Approx_By_Float: remove code equations using Ratreal
hoelzl
parents: 51542
diff changeset
   185
63355
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
   186
definition Realfract :: "int \<Rightarrow> int \<Rightarrow> real"
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
   187
  where "Realfract p q = of_int p / of_int q"
52403
140ae824ea4a Code_Real_Approx_By_Float: remove code equations using Ratreal
hoelzl
parents: 51542
diff changeset
   188
140ae824ea4a Code_Real_Approx_By_Float: remove code equations using Ratreal
hoelzl
parents: 51542
diff changeset
   189
code_datatype Realfract
140ae824ea4a Code_Real_Approx_By_Float: remove code equations using Ratreal
hoelzl
parents: 51542
diff changeset
   190
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   191
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52403
diff changeset
   192
  constant Realfract \<rightharpoonup> (SML) "Real.fromInt _/ '// Real.fromInt _"
52403
140ae824ea4a Code_Real_Approx_By_Float: remove code equations using Ratreal
hoelzl
parents: 51542
diff changeset
   193
63355
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
   194
lemma [code]: "Ratreal r = case_prod Realfract (quotient_of r)"
52403
140ae824ea4a Code_Real_Approx_By_Float: remove code equations using Ratreal
hoelzl
parents: 51542
diff changeset
   195
  by (cases r) (simp add: Realfract_def quotient_of_Fract of_rat_rat)
140ae824ea4a Code_Real_Approx_By_Float: remove code equations using Ratreal
hoelzl
parents: 51542
diff changeset
   196
66148
5e60c2d0a1f1 avoid ancient [code, code del] antipattern
haftmann
parents: 66147
diff changeset
   197
declare [[code drop: "HOL.equal :: real \<Rightarrow> real \<Rightarrow> bool"
5e60c2d0a1f1 avoid ancient [code, code del] antipattern
haftmann
parents: 66147
diff changeset
   198
  "plus :: real \<Rightarrow> real \<Rightarrow> real"
5e60c2d0a1f1 avoid ancient [code, code del] antipattern
haftmann
parents: 66147
diff changeset
   199
  "uminus :: real \<Rightarrow> real"
5e60c2d0a1f1 avoid ancient [code, code del] antipattern
haftmann
parents: 66147
diff changeset
   200
  "minus :: real \<Rightarrow> real \<Rightarrow> real"
5e60c2d0a1f1 avoid ancient [code, code del] antipattern
haftmann
parents: 66147
diff changeset
   201
  "times :: real \<Rightarrow> real \<Rightarrow> real"
5e60c2d0a1f1 avoid ancient [code, code del] antipattern
haftmann
parents: 66147
diff changeset
   202
  "divide :: real \<Rightarrow> real \<Rightarrow> real"]]
63355
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
   203
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
   204
lemma [code]: "inverse r = 1 / r" for r :: real
52403
140ae824ea4a Code_Real_Approx_By_Float: remove code equations using Ratreal
hoelzl
parents: 51542
diff changeset
   205
  by (fact inverse_eq_divide)
140ae824ea4a Code_Real_Approx_By_Float: remove code equations using Ratreal
hoelzl
parents: 51542
diff changeset
   206
46530
d5d14046686f notepad is more appropriate here
haftmann
parents: 45496
diff changeset
   207
notepad
d5d14046686f notepad is more appropriate here
haftmann
parents: 45496
diff changeset
   208
begin
d5d14046686f notepad is more appropriate here
haftmann
parents: 45496
diff changeset
   209
  have "cos (pi/2) = 0" by (rule cos_pi_half)
d5d14046686f notepad is more appropriate here
haftmann
parents: 45496
diff changeset
   210
  moreover have "cos (pi/2) \<noteq> 0" by eval
63355
7b23053be254 misc tuning and modernization;
wenzelm
parents: 61424
diff changeset
   211
  ultimately have False by blast
46530
d5d14046686f notepad is more appropriate here
haftmann
parents: 45496
diff changeset
   212
end
45483
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   213
34d07cf7d207 add Code_Real_Approx_By_Float
hoelzl
parents:
diff changeset
   214
end