287 \begin{quote} |
287 \begin{quote} |
288 \verb!@!\verb!{thm_style stylename thm}!\\ |
288 \verb!@!\verb!{thm_style stylename thm}!\\ |
289 \verb!@!\verb!{term_style stylename term}! |
289 \verb!@!\verb!{term_style stylename term}! |
290 \end{quote} |
290 \end{quote} |
291 |
291 |
292 A ``style'' is a transformation of terms; there are three predefined |
292 A ``style'' is a transformation of terms. There are three predefined |
293 styles, named \verb!lhs!, \verb!rhs! and \verb!concl!, which obvious |
293 styles, named \verb!lhs!, \verb!rhs! and \verb!conclusion!, with obvious |
294 meanings, e.~g.~the output |
294 meanings. For example, the output |
295 |
|
296 \begin{center} |
295 \begin{center} |
297 \begin{tabular}{l@ {~~@{text "="}~~}l} |
296 \begin{tabular}{l@ {~~@{text "="}~~}l} |
298 @{thm_style lhs foldl_Nil} & @{thm_style rhs foldl_Nil}\\ |
297 @{thm_style lhs foldl_Nil} & @{thm_style rhs foldl_Nil}\\ |
299 @{thm_style lhs foldl_Cons} & @{thm_style rhs foldl_Cons} |
298 @{thm_style lhs foldl_Cons} & @{thm_style rhs foldl_Cons} |
300 \end{tabular} |
299 \end{tabular} |
301 \end{center} |
300 \end{center} |
302 |
|
303 \noindent |
|
304 is produced by the following code: |
301 is produced by the following code: |
305 |
|
306 \begin{quote} |
302 \begin{quote} |
307 \verb!\begin{center}!\\ |
303 \verb!\begin{center}!\\ |
308 \verb!\begin{tabular}{l@ {~~!\verb!@!\verb!{text "="}~~}l}!\\ |
304 \verb!\begin{tabular}{l@ {~~!\verb!@!\verb!{text "="}~~}l}!\\ |
309 \verb!@!\verb!{thm_style lhs foldl_Nil} & @!\verb!{thm_style rhs foldl_Nil}!\\ |
305 \verb!@!\verb!{thm_style lhs foldl_Nil} & @!\verb!{thm_style rhs foldl_Nil}!\\ |
310 \verb!@!\verb!{thm_style lhs foldl_Cons} & @!\verb!{thm_style rhs foldl_Cons}!\\ |
306 \verb!@!\verb!{thm_style lhs foldl_Cons} & @!\verb!{thm_style rhs foldl_Cons}!\\ |
311 \verb!\end{tabular}!\\ |
307 \verb!\end{tabular}!\\ |
312 \verb!\end{center}! |
308 \verb!\end{center}! |
313 \end{quote} |
309 \end{quote} |
314 |
|
315 \noindent |
|
316 Note the space between \verb!@! and \verb!{! in the tabular argument. |
310 Note the space between \verb!@! and \verb!{! in the tabular argument. |
317 It prevents Isabelle from interpreting \verb!@ {~~...~~}! |
311 It prevents Isabelle from interpreting \verb!@ {~~...~~}! |
318 as antiquotation. Both styles \verb!lhs! and \verb!rhs! |
312 as an antiquotation. Both styles \verb!lhs! and \verb!rhs! |
319 try to be smart about the interpretation of the theorem they transform |
313 try to be smart about the interpretation of the theorem they transform |
320 they work just as well for meta equality @{text "\<equiv>"} and other |
314 they work just as well for meta equality @{text "\<equiv>"} and other |
321 binary operators like @{text "<"}. |
315 binary operators like @{text "<"}. |
322 |
316 |
323 Likewise \verb!conclusion! may be used as style to show just the conclusion |
317 Likewise \verb!conclusion! may be used as style to show just the conclusion |
324 of a formula: |
318 of a formula: |
325 |
|
326 \begin{center} |
319 \begin{center} |
327 @{thm_style conclusion hd_Cons_tl} |
320 @{thm_style conclusion hd_Cons_tl} |
328 \end{center} |
321 \end{center} |
329 |
|
330 \noindent |
|
331 is produced by |
322 is produced by |
332 |
|
333 \begin{quote} |
323 \begin{quote} |
334 \verb!\begin{center}!\\ |
324 \verb!\begin{center}!\\ |
335 \verb!@!\verb!{thm_style conclusion hd_Cons_tl}!\\ |
325 \verb!@!\verb!{thm_style conclusion hd_Cons_tl}!\\ |
336 \verb!\end{center}! |
326 \verb!\end{center}! |
337 \end{quote} |
327 \end{quote} |
338 |
328 |
339 If you aren't afraid about ML, you may also define your own styles; |
329 If you are not afraid of ML, you may also define your own styles. |
340 a style is simply implemented by a ML function \verb!Term.term -> Term.term!. |
330 A style is simply implemented by an ML function of type \verb!term -> term!. |
341 Have a look at the following example (which indeed shows just the way the |
331 Have a look at the following example (which indeed shows just the way the |
342 \verb!lhs! style is implemented): |
332 \verb!lhs! style is implemented): |
343 |
|
344 \begin{quote} |
333 \begin{quote} |
345 \verb!setup {!\verb!*!\\ |
334 \verb!setup {!\verb!*!\\ |
346 \verb!!\\ |
|
347 \verb!let!\\ |
335 \verb!let!\\ |
348 \verb! fun my_lhs (Const ("==", _) $ t $ _) = t!\\ |
336 \verb! fun my_lhs (Const ("==", _) $ t $ _) = t!\\ |
349 \verb! | my_lhs (Const ("Trueprop", _) $ t) = my_lhs t!\\ |
337 \verb! | my_lhs (Const ("Trueprop", _) $ t) = my_lhs t!\\ |
350 \verb! | my_lhs (Const ("==>", _) $ _ $ t) = my_lhs t!\\ |
338 \verb! | my_lhs (Const ("==>", _) $ _ $ t) = my_lhs t!\\ |
351 \verb! | my_lhs (_ $ t $ _) = t!\\ |
339 \verb! | my_lhs (_ $ t $ _) = t!\\ |
352 \verb! | my_lhs _ = error ("Binary operator expected")!\\ |
340 \verb! | my_lhs _ = error ("Binary operator expected")!\\ |
353 \verb! in [Style.put_style "new_lhs" my_lhs]!\\ |
341 \verb! in [Style.put_style "new_lhs" my_lhs]!\\ |
354 \verb!end;!\\ |
342 \verb!end;!\\ |
355 \verb!!\\ |
|
356 \verb!*!\verb!}!\\ |
343 \verb!*!\verb!}!\\ |
357 \end{quote} |
344 \end{quote} |
358 |
345 This code must go into your theory file, not as part of your |
|
346 \LaTeX\ text but as a separate command in front of it. |
359 Like in this example, it is recommended to put the definition of the style |
347 Like in this example, it is recommended to put the definition of the style |
360 function into a \verb!let! expression, in order not to pollute the |
348 function into a \verb!let! expression, in order not to pollute the |
361 ML global namespace. The mapping from identifier name to the style function |
349 ML global namespace. The mapping from identifier name to the style function |
362 is done by the \verb!Style.put_style! expression which expects the desired |
350 is done by the \verb!Style.put_style! expression which expects the desired |
363 style name and the style function as arguments. After this \verb!setup!, |
351 style name and the style function as arguments. After this \verb!setup!, |
364 there will be a new style available named \verb!new_lhs!, then allowing |
352 there will be a new style available named \verb!new_lhs! allowing |
365 antiquoations like \verb!@!\verb!{term_style new_lhs rev_map}! |
353 antiquoations like \verb!@!\verb!{thm_style new_lhs rev_map}! |
366 yielding \verb!rev (map f xs)!. |
354 yielding @{thm_style lhs rev_map}. |
367 |
355 |
368 The example above may be used as as a ``copy-and-paste'' pattern to write |
356 The example above may be used as as a ``copy-and-paste'' pattern to write |
369 your own styles; for a description of the constructs used, please refer |
357 your own styles; for a description of the constructs used, please refer |
370 to the Isabelle reference manual. |
358 to the Isabelle reference manual. |
371 |
359 |