src/HOL/ex/svc_funcs.ML
changeset 34974 18b41bba42b5
parent 32740 9dd0a2f83429
child 35010 d6e492cea6e4
equal deleted inserted replaced
34973:ae634fad947e 34974:18b41bba42b5
   105                      in
   105                      in
   106                         (Const ("SVC_Oracle.iff_" ^ cname, dummyT) $ u1 $ u2,
   106                         (Const ("SVC_Oracle.iff_" ^ cname, dummyT) $ u1 $ u2,
   107                          b1 orelse b2)
   107                          b1 orelse b2)
   108                      end
   108                      end
   109                  else (*might be numeric equality*) (t, is_intnat T)
   109                  else (*might be numeric equality*) (t, is_intnat T)
   110            | Const(@{const_name HOL.less}, Type ("fun", [T,_]))  => (t, is_intnat T)
   110            | Const(@{const_name Algebras.less}, Type ("fun", [T,_]))  => (t, is_intnat T)
   111            | Const(@{const_name HOL.less_eq}, Type ("fun", [T,_])) => (t, is_intnat T)
   111            | Const(@{const_name Algebras.less_eq}, Type ("fun", [T,_])) => (t, is_intnat T)
   112            | _ => (t, false)
   112            | _ => (t, false)
   113          end
   113          end
   114    in #1 o tag end;
   114    in #1 o tag end;
   115 
   115 
   116  (*Map expression e to 0<=a --> e, where "a" is the name of a nat variable*)
   116  (*Map expression e to 0<=a --> e, where "a" is the name of a nat variable*)
   144                become part of the Var's name*)
   144                become part of the Var's name*)
   145       | var (t,_) = fail t;
   145       | var (t,_) = fail t;
   146     (*translation of a literal*)
   146     (*translation of a literal*)
   147     val lit = snd o HOLogic.dest_number;
   147     val lit = snd o HOLogic.dest_number;
   148     (*translation of a literal expression [no variables]*)
   148     (*translation of a literal expression [no variables]*)
   149     fun litExp (Const(@{const_name HOL.plus}, T) $ x $ y) =
   149     fun litExp (Const(@{const_name Algebras.plus}, T) $ x $ y) =
   150           if is_numeric_op T then (litExp x) + (litExp y)
   150           if is_numeric_op T then (litExp x) + (litExp y)
   151           else fail t
   151           else fail t
   152       | litExp (Const(@{const_name HOL.minus}, T) $ x $ y) =
   152       | litExp (Const(@{const_name Algebras.minus}, T) $ x $ y) =
   153           if is_numeric_op T then (litExp x) - (litExp y)
   153           if is_numeric_op T then (litExp x) - (litExp y)
   154           else fail t
   154           else fail t
   155       | litExp (Const(@{const_name HOL.times}, T) $ x $ y) =
   155       | litExp (Const(@{const_name Algebras.times}, T) $ x $ y) =
   156           if is_numeric_op T then (litExp x) * (litExp y)
   156           if is_numeric_op T then (litExp x) * (litExp y)
   157           else fail t
   157           else fail t
   158       | litExp (Const(@{const_name HOL.uminus}, T) $ x)   =
   158       | litExp (Const(@{const_name Algebras.uminus}, T) $ x)   =
   159           if is_numeric_op T then ~(litExp x)
   159           if is_numeric_op T then ~(litExp x)
   160           else fail t
   160           else fail t
   161       | litExp t = lit t
   161       | litExp t = lit t
   162                    handle Match => fail t
   162                    handle Match => fail t
   163     (*translation of a real/rational expression*)
   163     (*translation of a real/rational expression*)
   164     fun suc t = Interp("+", [Int 1, t])
   164     fun suc t = Interp("+", [Int 1, t])
   165     fun tm (Const(@{const_name Suc}, T) $ x) = suc (tm x)
   165     fun tm (Const(@{const_name Suc}, T) $ x) = suc (tm x)
   166       | tm (Const(@{const_name HOL.plus}, T) $ x $ y) =
   166       | tm (Const(@{const_name Algebras.plus}, T) $ x $ y) =
   167           if is_numeric_op T then Interp("+", [tm x, tm y])
   167           if is_numeric_op T then Interp("+", [tm x, tm y])
   168           else fail t
   168           else fail t
   169       | tm (Const(@{const_name HOL.minus}, T) $ x $ y) =
   169       | tm (Const(@{const_name Algebras.minus}, T) $ x $ y) =
   170           if is_numeric_op T then
   170           if is_numeric_op T then
   171               Interp("+", [tm x, Interp("*", [Int ~1, tm y])])
   171               Interp("+", [tm x, Interp("*", [Int ~1, tm y])])
   172           else fail t
   172           else fail t
   173       | tm (Const(@{const_name HOL.times}, T) $ x $ y) =
   173       | tm (Const(@{const_name Algebras.times}, T) $ x $ y) =
   174           if is_numeric_op T then Interp("*", [tm x, tm y])
   174           if is_numeric_op T then Interp("*", [tm x, tm y])
   175           else fail t
   175           else fail t
   176       | tm (Const(@{const_name HOL.inverse}, T) $ x) =
   176       | tm (Const(@{const_name Algebras.inverse}, T) $ x) =
   177           if domain_type T = HOLogic.realT then
   177           if domain_type T = HOLogic.realT then
   178               Rat(1, litExp x)
   178               Rat(1, litExp x)
   179           else fail t
   179           else fail t
   180       | tm (Const(@{const_name HOL.uminus}, T) $ x) =
   180       | tm (Const(@{const_name Algebras.uminus}, T) $ x) =
   181           if is_numeric_op T then Interp("*", [Int ~1, tm x])
   181           if is_numeric_op T then Interp("*", [Int ~1, tm x])
   182           else fail t
   182           else fail t
   183       | tm t = Int (lit t)
   183       | tm t = Int (lit t)
   184                handle Match => var (t,[])
   184                handle Match => var (t,[])
   185     (*translation of a formula*)
   185     (*translation of a formula*)
   209                                     [Buildin("<", [tx, suc ty]),
   209                                     [Buildin("<", [tx, suc ty]),
   210                                      Buildin("<", [ty, suc tx])])
   210                                      Buildin("<", [ty, suc tx])])
   211                    else fail t
   211                    else fail t
   212             end
   212             end
   213         (*inequalities: possible types are nat, int, real*)
   213         (*inequalities: possible types are nat, int, real*)
   214       | fm pos (t as Const(@{const_name HOL.less},  Type ("fun", [T,_])) $ x $ y) =
   214       | fm pos (t as Const(@{const_name Algebras.less},  Type ("fun", [T,_])) $ x $ y) =
   215             if not pos orelse T = HOLogic.realT then
   215             if not pos orelse T = HOLogic.realT then
   216                 Buildin("<", [tm x, tm y])
   216                 Buildin("<", [tm x, tm y])
   217             else if is_intnat T then
   217             else if is_intnat T then
   218                 Buildin("<=", [suc (tm x), tm y])
   218                 Buildin("<=", [suc (tm x), tm y])
   219             else fail t
   219             else fail t
   220       | fm pos (t as Const(@{const_name HOL.less_eq},  Type ("fun", [T,_])) $ x $ y) =
   220       | fm pos (t as Const(@{const_name Algebras.less_eq},  Type ("fun", [T,_])) $ x $ y) =
   221             if pos orelse T = HOLogic.realT then
   221             if pos orelse T = HOLogic.realT then
   222                 Buildin("<=", [tm x, tm y])
   222                 Buildin("<=", [tm x, tm y])
   223             else if is_intnat T then
   223             else if is_intnat T then
   224                 Buildin("<", [tm x, suc (tm y)])
   224                 Buildin("<", [tm x, suc (tm y)])
   225             else fail t
   225             else fail t