ProgTutorial/Tactical.thy
changeset 370 2494b5b7a85d
parent 369 74ba778b09c9
child 378 8d160d79b48c
equal deleted inserted replaced
369:74ba778b09c9 370:2494b5b7a85d
  1251   \end{readmore}
  1251   \end{readmore}
  1252 *}
  1252 *}
  1253 
  1253 
  1254 text {*
  1254 text {*
  1255   \begin{exercise}\label{ex:dyckhoff}
  1255   \begin{exercise}\label{ex:dyckhoff}
  1256   Dyckhoff presents in \cite{Dyckhoff92} inference rules for a sequent
  1256   Dyckhoff presents in \cite{Dyckhoff92} inference rules of a sequent
  1257   calculus, called G4ip, for intuitionistic propositional logic. The
  1257   calculus, called G4ip, for intuitionistic propositional logic. The
  1258   interesting feature of this calculus is that no contraction rule is needed
  1258   interesting feature of this calculus is that no contraction rule is needed
  1259   in order to be complete. As a result applying the rules exhaustively leads
  1259   in order to be complete. As a result the rules can be applied exhaustively, which
  1260   to simple decision procedure for propositional intuitionistic logic. The task
  1260   in turn leads to simple decision procedure for propositional intuitionistic logic. 
  1261   is to implement this decision procedure as a tactic. His rules are
  1261   The task is to implement this decision procedure as a tactic. His rules are
  1262 
  1262 
  1263   \begin{center}
  1263   \begin{center}
  1264   \def\arraystretch{2.3}
  1264   \def\arraystretch{2.3}
  1265   \begin{tabular}{cc}
  1265   \begin{tabular}{cc}
  1266   \infer[Ax]{A,\varGamma \Rightarrow A}{} &
  1266   \infer[Ax]{A,\varGamma \Rightarrow A}{} &
  1296   {D\longrightarrow B, \varGamma \Rightarrow C \longrightarrow D &
  1296   {D\longrightarrow B, \varGamma \Rightarrow C \longrightarrow D &
  1297   B, \varGamma \Rightarrow G}}\\
  1297   B, \varGamma \Rightarrow G}}\\
  1298   \end{tabular}
  1298   \end{tabular}
  1299   \end{center}
  1299   \end{center}
  1300 
  1300 
  1301   Note that in Isabelle the left-rules need to be implemented as elimination
  1301   Note that in Isabelle right rules need to be implemented as
  1302   rules. You need to prove separate lemmas corresponding to
  1302   introduction rule, the left rules as elimination rules. You have to to
  1303   $\longrightarrow_{L_{1..4}}$. The tactic should explore all possibilites of
  1303   prove separate theorems corresponding to $\longrightarrow_{L_{1..4}}$. The
  1304   applying these rules to a propositional formula until a goal state is
  1304   tactic should explore all possibilites of applying these rules to a
  1305   reached in which all subgoals are discharged. For this you can use the tactic 
  1305   propositional formula until a goal state is reached in which all subgoals
  1306   combinator @{ML_ind DEPTH_SOLVE in Search}. 
  1306   are discharged. For this you can use the tactic combinator @{ML_ind
       
  1307   DEPTH_SOLVE in Search} in the structure @{ML_struct Search}.
  1307   \end{exercise}
  1308   \end{exercise}
  1308 
  1309 
  1309   \begin{exercise}
  1310   \begin{exercise}
  1310   Add to the previous exercise also rules for equality and run your tactic on 
  1311   Add to the sequent calculus from the previous exercise also rules for 
  1311   the de Bruijn formulae discussed in Exercise~\ref{ex:debruijn}.
  1312   equality and run your tactic on  the de Bruijn formulae discussed 
       
  1313   in Exercise~\ref{ex:debruijn}.
  1312   \end{exercise}
  1314   \end{exercise}
  1313 *}
  1315 *}
  1314 
  1316 
  1315 section {* Simplifier Tactics *}
  1317 section {* Simplifier Tactics *}
  1316 
  1318 
  1317 text {*
  1319 text {*
  1318   A lot of convenience in reasoning with Isabelle derives from its
  1320   A lot of convenience in reasoning with Isabelle derives from its
  1319   powerful simplifier. We will describe it in this section, whereby 
  1321   powerful simplifier. We will describe it in this section. However,
  1320   we can, however, only scratch the surface due to its complexity. 
  1322   due to its complexity, we can mostly only scratch the surface. 
  1321 
  1323 
  1322   The power of the simplifier is a strength and a weakness at the same time,
  1324   The power of the simplifier is a strength and a weakness at the same time,
  1323   because you can easily make the simplifier run into a loop and in general
  1325   because you can easily make the simplifier run into a loop and in general
  1324   its behaviour can be difficult to predict. There is also a multitude of
  1326   its behaviour can be difficult to predict. There is also a multitude of
  1325   options that you can configure to change the behaviour of the
  1327   options that you can configure to change the behaviour of the
  1336    @{ML_ind asm_full_simp_tac in Simplifier}   & @{text "(simp)"}
  1338    @{ML_ind asm_full_simp_tac in Simplifier}   & @{text "(simp)"}
  1337   \end{tabular}
  1339   \end{tabular}
  1338   \end{center}
  1340   \end{center}
  1339   \end{isabelle}
  1341   \end{isabelle}
  1340 
  1342 
  1341   All of the tactics take a simpset and an integer as argument (the latter as usual 
  1343   All these tactics take a simpset and an integer as argument (the latter as usual 
  1342   to specify  the goal to be analysed). So the proof
  1344   to specify  the goal to be analysed). So the proof
  1343 *}
  1345 *}
  1344 
  1346 
  1345 lemma 
  1347 lemma 
  1346   shows "Suc (1 + 2) < 3 + 2"
  1348   shows "Suc (1 + 2) < 3 + 2"
  1384   \end{isabelle}
  1386   \end{isabelle}
  1385 
  1387 
  1386   with @{text "constr"} being a constant, like @{const "If"}, @{const "Let"}
  1388   with @{text "constr"} being a constant, like @{const "If"}, @{const "Let"}
  1387   and so on. Every simpset contains only one congruence rule for each
  1389   and so on. Every simpset contains only one congruence rule for each
  1388   term-constructor, which however can be overwritten. The user can declare
  1390   term-constructor, which however can be overwritten. The user can declare
  1389   lemmas to be congruence rules using the attribute @{text "[cong]"}. In HOL,
  1391   lemmas to be congruence rules using the attribute @{text "[cong]"}. Note that 
  1390   the user usually states these lemmas as equations, which are then internally
  1392   in HOL these congruence theorems are usually stated as equations, which are 
  1391   transformed into meta-equations.
  1393   then internally transformed into meta-equations.
  1392 
  1394 
  1393   The rewriting with theorems involving premises requires what is in Isabelle
  1395   The rewriting with theorems involving premises requires what is in Isabelle
  1394   called a subgoaler, a solver and a looper. These can be arbitrary tactics
  1396   called a subgoaler, a solver and a looper. These can be arbitrary tactics
  1395   that can be installed in a simpset and which are executed at various stages
  1397   that can be installed in a simpset and which are executed at various stages
  1396   during simplification. However, simpsets also include simprocs, which can
  1398   during simplification. 
  1397   produce rewrite rules on demand (see next section). Another component are
  1399 
  1398   split-rules, which can simplify for example the ``then'' and ``else''
  1400   Simpsets can also include simprocs, which produce rewrite rules on
  1399   branches of if-statements under the corresponding preconditions.
  1401   demand according to a pattern (see next section for a detailed description
       
  1402   of simpsets). Another component are split-rules, which can simplify for
       
  1403   example the ``then'' and ``else'' branches of if-statements under the
       
  1404   corresponding preconditions.
  1400 
  1405 
  1401   \begin{readmore}
  1406   \begin{readmore}
  1402   For more information about the simplifier see @{ML_file "Pure/meta_simplifier.ML"}
  1407   For more information about the simplifier see @{ML_file "Pure/meta_simplifier.ML"}
  1403   and @{ML_file "Pure/simplifier.ML"}. The generic splitter is implemented in 
  1408   and @{ML_file "Pure/simplifier.ML"}. The generic splitter is implemented in 
  1404   @{ML_file "Provers/splitter.ML"}.
  1409   @{ML_file "Provers/splitter.ML"}.
  1406 
  1411 
  1407   
  1412   
  1408   \footnote{\bf FIXME: Find the right place to mention this: Discrimination 
  1413   \footnote{\bf FIXME: Find the right place to mention this: Discrimination 
  1409   nets are implemented in @{ML_file "Pure/net.ML"}.}
  1414   nets are implemented in @{ML_file "Pure/net.ML"}.}
  1410 
  1415 
  1411   The most common combinators to modify simpsets are:
  1416   The most common combinators for modifying simpsets are:
  1412 
  1417 
  1413   \begin{isabelle}
  1418   \begin{isabelle}
  1414   \begin{tabular}{ll}
  1419   \begin{tabular}{l@ {\hspace{10mm}}l}
  1415   @{ML_ind addsimps in MetaSimplifier}    & @{ML_ind delsimps in MetaSimplifier}\\
  1420   @{ML_ind addsimps in MetaSimplifier}    & @{ML_ind delsimps in MetaSimplifier}\\
  1416   @{ML_ind addcongs in MetaSimplifier}    & @{ML_ind delcongs in MetaSimplifier}\\
  1421   @{ML_ind addcongs in MetaSimplifier}    & @{ML_ind delcongs in MetaSimplifier}\\
  1417   @{ML_ind addsimprocs in MetaSimplifier} & @{ML_ind delsimprocs in MetaSimplifier}\\
  1422   @{ML_ind addsimprocs in MetaSimplifier} & @{ML_ind delsimprocs in MetaSimplifier}\\
  1418   \end{tabular}
  1423   \end{tabular}
  1419   \end{isabelle}
  1424   \end{isabelle}
  1495 Congruences rules:
  1500 Congruences rules:
  1496   UNION: \<lbrakk>A = B; \<And>x. x \<in> B \<Longrightarrow> C x = D x\<rbrakk> \<Longrightarrow> \<Union>x\<in>A. C x \<equiv> \<Union>x\<in>B. D x
  1501   UNION: \<lbrakk>A = B; \<And>x. x \<in> B \<Longrightarrow> C x = D x\<rbrakk> \<Longrightarrow> \<Union>x\<in>A. C x \<equiv> \<Union>x\<in>B. D x
  1497 Simproc patterns:"}
  1502 Simproc patterns:"}
  1498 
  1503 
  1499   Notice that we had to add these lemmas as meta-equations. The @{ML empty_ss} 
  1504   Notice that we had to add these lemmas as meta-equations. The @{ML empty_ss} 
  1500   expects this form of the simplification and congruence rules. However, even 
  1505   expects this form of the simplification and congruence rules. This is
       
  1506   different, if we use for example the simpset @{ML HOL_basic_ss} (see below), 
       
  1507   where rules are usually added as equation. However, even 
  1501   when adding these lemmas to @{ML empty_ss} we do not end up with anything useful yet.
  1508   when adding these lemmas to @{ML empty_ss} we do not end up with anything useful yet.
  1502 
       
  1503   In the context of HOL, the first really useful simpset is @{ML_ind
  1509   In the context of HOL, the first really useful simpset is @{ML_ind
  1504   HOL_basic_ss in Simpdata}. While printing out the components of this simpset
  1510   HOL_basic_ss in Simpdata}. While printing out the components of this simpset
  1505 
  1511 
  1506   @{ML_response_fake [display,gray]
  1512   @{ML_response_fake [display,gray]
  1507   "print_ss @{context} HOL_basic_ss"
  1513   "print_ss @{context} HOL_basic_ss"
  1508 "Simplification rules:
  1514 "Simplification rules:
  1509 Congruences rules:
  1515 Congruences rules:
  1510 Simproc patterns:"}
  1516 Simproc patterns:"}
  1511 
  1517 
  1512   also produces ``nothing'', the printout is misleading. In fact
  1518   also produces ``nothing'', the printout is somewhat misleading. In fact
  1513   the @{ML HOL_basic_ss} is setup so that it can solve goals of the
  1519   the @{ML HOL_basic_ss} is setup so that it can solve goals of the
  1514   form  
  1520   form  
  1515 
  1521 
  1516   \begin{isabelle}
  1522   \begin{isabelle}
  1517   @{thm TrueI}, @{thm refl[no_vars]}, @{term "t \<equiv> t"} and @{thm FalseE[no_vars]}; 
  1523   @{thm TrueI}, @{thm refl[no_vars]}, @{term "t \<equiv> t"} and @{thm FalseE[no_vars]}; 
  1563 *}
  1569 *}
  1564 
  1570 
  1565 definition "MyTrue \<equiv> True"
  1571 definition "MyTrue \<equiv> True"
  1566 
  1572 
  1567 text {*
  1573 text {*
  1568   then we can use this tactic to unfold the definition of the constant.
  1574   then we can use this tactic to unfold the definition of this constant.
  1569 *}
  1575 *}
  1570 
  1576 
  1571 lemma 
  1577 lemma 
  1572   shows "MyTrue \<Longrightarrow> True"
  1578   shows "MyTrue \<Longrightarrow> True"
  1573 apply(tactic {* rewrite_goal_tac @{thms MyTrue_def} 1 *})
  1579 apply(tactic {* rewrite_goal_tac @{thms MyTrue_def} 1 *})
  1576       @{subgoals [display]}
  1582       @{subgoals [display]}
  1577       \end{isabelle} *}
  1583       \end{isabelle} *}
  1578 (*<*)oops(*>*)
  1584 (*<*)oops(*>*)
  1579 
  1585 
  1580 text {*
  1586 text {*
  1581   If you want to unfold definitions in \emph{all} subgoals not just one, 
  1587   If you want to unfold definitions in \emph{all} subgoals, not just one, 
  1582   then use the the tactic @{ML_ind rewrite_goals_tac in MetaSimplifier}.
  1588   then use the the tactic @{ML_ind rewrite_goals_tac in MetaSimplifier}.
  1583 *}
  1589 *}
  1584 
  1590 
  1585 
  1591 
  1586 text_raw {*
  1592 text_raw {*