847 structure Nat_LA_Data: LIN_ARITH_DATA = |
847 structure Nat_LA_Data: LIN_ARITH_DATA = |
848 struct |
848 struct |
849 val ccontr = ccontr; |
849 val ccontr = ccontr; |
850 val conjI = conjI; |
850 val conjI = conjI; |
851 val lessD = Suc_leI; |
851 val lessD = Suc_leI; |
852 val nat_neqE = nat_neqE; |
852 val neqE = nat_neqE; |
853 val notI = notI; |
853 val notI = notI; |
854 val not_leD = not_leE RS Suc_leI; |
854 val not_leD = not_leE RS Suc_leI; |
855 val not_lessD = leI; |
855 val not_lessD = leI; |
856 val sym = sym; |
856 val sym = sym; |
857 |
857 |
858 val nat = Type("nat",[]); |
|
859 val boolT = Type("bool",[]); |
|
860 |
|
861 fun nnb T = T = ([nat,nat] ---> boolT); |
|
862 |
|
863 (* Turn term into list of summand * multiplicity plus a constant *) |
858 (* Turn term into list of summand * multiplicity plus a constant *) |
864 fun poly(Const("Suc",_)$t, (p,i)) = poly(t, (p,i+1)) |
859 fun poly(Const("Suc",_)$t, (p,i)) = poly(t, (p,i+1)) |
865 | poly(Const("op +",Type("fun",[Type("nat",[]),_])) $ s $ t, pi) = |
860 | poly(Const("op +",_) $ s $ t, pi) = poly(s,poly(t,pi)) |
866 poly(s,poly(t,pi)) |
|
867 | poly(t,(p,i)) = |
861 | poly(t,(p,i)) = |
868 if t = Const("0",nat) then (p,i) |
862 if t = Const("0",HOLogic.natT) then (p,i) |
869 else (case assoc(p,t) of None => ((t,1)::p,i) |
863 else (case assoc(p,t) of None => ((t,1)::p,i) |
870 | Some m => (overwrite(p,(t,m+1)), i)) |
864 | Some m => (overwrite(p,(t,m+1)), i)) |
|
865 |
|
866 fun nnb T = T = ([HOLogic.natT,HOLogic.natT] ---> HOLogic.boolT); |
871 |
867 |
872 fun decomp2(rel,T,lhs,rhs) = |
868 fun decomp2(rel,T,lhs,rhs) = |
873 if not(nnb T) then None else |
869 if not(nnb T) then None else |
874 let val (p,i) = poly(lhs,([],0)) and (q,j) = poly(rhs,([],0)) |
870 let val (p,i) = poly(lhs,([],0)) and (q,j) = poly(rhs,([],0)) |
875 in case rel of |
871 in case rel of |
906 "(i = j) & (k = l) ==> i + k = j + (l::nat)" |
902 "(i = j) & (k = l) ==> i + k = j + (l::nat)" |
907 ]; |
903 ]; |
908 |
904 |
909 fun is_False thm = |
905 fun is_False thm = |
910 let val _ $ t = #prop(rep_thm thm) |
906 let val _ $ t = #prop(rep_thm thm) |
911 in t = Const("False",boolT) end; |
907 in t = Const("False",HOLogic.boolT) end; |
912 |
908 |
913 fun is_nat(t) = fastype_of1 t = nat; |
909 fun is_nat(t) = fastype_of1 t = HOLogic.natT; |
914 |
910 |
915 fun mk_nat_thm sg t = |
911 fun mk_nat_thm sg t = |
916 let val ct = cterm_of sg t and cn = cterm_of sg (Var(("n",0),nat)) |
912 let val ct = cterm_of sg t and cn = cterm_of sg (Var(("n",0),HOLogic.natT)) |
917 in instantiate ([],[(cn,ct)]) le0 end; |
913 in instantiate ([],[(cn,ct)]) le0 end; |
918 |
914 |
919 end; |
915 end; |
920 |
916 |
921 structure Fast_Nat_Arith = Fast_Lin_Arith(Nat_LA_Data); |
917 structure Fast_Nat_Arith = Fast_Lin_Arith(Nat_LA_Data); |