Debian Codegraph @

doc/refman/reference-backup.md

raw
1 Gory Details {#gorydetails}
2 ============
3
4 This chapter presents all syntactic elements of CafeOBJ as
5 well as several meta-concepts in alphabetic order. Concepts are
6 cross-linked for easy accessibility.
7
8 ## `?` ## {#help}
9
10 lists all top-level commands. The `?` can be used after many of the
11 top-level commands to obtain help.
12
13 ## `! <command>` ## {#commandexec}
14
15 TODO Currently not working!!
16
17 On Unix only, forks a shell and executes the given `<command>`.
18
19 ## `**`, `**>` ## {#starstar}
20
21 Starts a comment which extends to the end of the line.
22 With the additional `>` the comment is displayed while
23 evaluated by the interpreter.
24
25 Related: [`--`](#dashdash) [comments](#comments)
26
27 ## `--`, `-->` ## {#dashdash}
28
29 Starts a comment which extends to the end of the line.
30 With the additional `>` the comment is displayed while
31 evaluated by the interpreter.
32
33 Related: [`**`](#starstar) [comments](#comments)
34
35 ## `=` ## {#axeq}
36
37 The syntax element `=` introduces an axiom of the equational theory,
38 and is different from `==` which specifies an equality based on
39 rewriting.
40
41 Related: [`==`](#equality) [`eq`](#eq)
42
43 ## `==` ## {#equality}
44
45 The predicate `==` is a binary operator defined for each visible sort
46 and is defined in terms of evaluation. That is, for ground terms `t`
47 and `t'` of the same sort, `t == t'` evaluates to `true` iff terms
48 reduce to a common term. This is different from the equational `=`
49 which specifies the equality of the theory.
50
51 ## `==>` ## {#transrel}
52
53 This binary predicate is defined on each visible sort, and defines the
54 transition relation, which is reflexive, transitive, and closed under
55 operator application. It expresses the fact that two states (terms)
56 are connected via transitions.
57
58 Related: [`trans`](#trans) [`=(*)=>`](#transsearch)
59
60 ## `=*=` ## {#bequality}
61
62 The predicate for behavioural equivalence, written `=*=`, is a binary
63 operator defined on each hidden sort.
64
65 TODO: old manual very unclear ... both about `=*=` and
66 `accept =*= proof` ??? (page 46 of old manual)
67
68 ## `=(n)=>` `=(n,m)=>` ## {#transsearch}
69
70 See [search predicate](#searchpredicate)
71
72 ## `=/=` ## {#ineq}
73
74 Negation of the predicate [`==`](#equality).
75
76 ## `accept =*= proof` switch ## {#switch-accept}
77
78 TODO missing documentation
79 difficult - see TODO for [`=*=`](#bequality)
80
81
82 ## `all axioms` switch ## {#switch-all-axioms)
83
84 Controls whether axioms from included modules are shown
85 during a `show` invocation.
86
87 Related: [`show`](#show)
88
89 ## `always memo` switch ## {#switch-always-memo)
90
91 Turns on memorization of computation also for operators without
92 the [`memo`](#opattr) operator attribute.
93
94 Related: [`memo` switch](#switch-memo) [operator attributes](#opattr)
95
96
97 ## `apply <action> [ <subst> ] <range> <selection>` ## {#apply}
98
99 Applies one of the following actions `reduce`, `exec`, `print`, or a
100 rewrite rule to the term in focus.
101
102 `reduce`, `exec`, `print`
103 ~ the operation acts on the (sub)term specified by `<range>` and
104 `<selection>`.
105
106 rewrite rule
107 ~ in this case a rewrite rule spec has to be given in the following
108 form:
109
110 `[+|-][<mod_name>].<rule-id>`
111
112 where `<mod_name>` is the name of a module, and `<rule-id>` either
113 a number n - in which case the n. equation in the current module
114 is used, or the label of an equation. If the `<mod_name>` is not
115 given, the equations of the current module are considered. If the
116 leading `+` or no leading character is given, the equation is
117 applied left-to-right, which with a leading `-` the equation is
118 applied right-to-left.
119
120 The `<subst>` is of the form
121
122 `with { <var_name> = <term> } +,`
123
124 and is used when applying a rewrite rule. In this case the variables
125 in the rule are bound to the given term.
126
127 `<range>` is either `within` or `at`. In the former case the action is
128 applied at or inside the (sub)term specified by the following
129 selection. In the later case it means exactely at the (sub)term.
130
131 Finally, the `<selection>` is an expression
132
133 `<selector> { of <selector> } *`
134
135 where each `<selector>` is one of
136
137 `top`, `term`
138 ~ Selects the whole term
139
140 `subterm`
141 ~ Selects the pre-chosen subterm (see [`choose`](#choose))
142
143 `( <number_list> )`
144 ~ A list of numbers separated by blanks as in `(2 1)` indicates a
145 subterm by tree search. `(2 1)` means the first argument of the
146 second argument.
147
148 `[ <number1> .. <number2> ]`
149 ~ This selector can only be used with associative operators. It
150 indicates a subterm in a flattened structure and selects the
151 subterm between and including the two numbers given. `[n .. n]`
152 can be abbreviated to `[n]`.
153
154 Example: If the term is `a * b * c * d * e`, then the
155 expression `[2 .. 4]` selects the subterm `b * c * d`.
156
157 `{ <number_set> }`
158 ~ This selector can only be used with associative and commutative
159 operators. It indicates a subterm in a multiset structure obtained
160 from selecting the subterms at position given by the numbers.
161
162 Example: If the operator `_*_` is declared as associative and
163 commutative, and the current term is `b * c * d * c * e`, then
164 then the expression `{2, 4, 5}` selects the subterm `c * c * e`.
165
166
167 Related: [`choose`](#choose) [`start`](#start)
168
169 ## `auto context` switch ## {#switch-auto-context}
170
171 Possible values: `on` or `off`, default is `off`.
172
173 If this switch is `on`, the context will automatically switch to
174 the most recent module, i.e., defining a module or inspecting
175 a module's content will switch the current module.
176
177
178 ## `autoload` ## {#autoload}
179
180 TODO No documentation in original manual, no idea!
181
182 ## `axioms { <decls> }` ## {#axioms}
183
184 Block enclosing declarations of variables, equations, and
185 transitions.
186 Other statements are not allowed within the `axioms` block.
187 Optional structuring of the statements in a module.
188
189 Related: [`signature`](#signature) [`imports`](#imports)
190 [`var`](#var) [`eq`](#eq) [`trans`](#trans)
191
192
193 ## `bceq [ <op-exp> ] <term> = <term> if <boolterm> .` ## {#bceq}
194
195 Alias: `bcq`
196
197 Defines a behaviour conditional equation. For details see [`ceq`](#ceq).
198
199 Related: [`eq`](#eq) [`ceq`](#ceq) [`beq`](#beq)
200
201 ## `beq [ <op-exp> ] <term> = <term> .` ## {#beq}
202
203 Defines a behaviour equation. For details see [`eq`](#eq).
204
205 Related: [`eq`](#eq) [`ceq`](#ceq) [`bceq`](#bceq)
206
207
208 ## `bctrans [ <label-exp> ] <term> => <term> if <bool> .` ## {#bctrans}
209
210 Defines a behaviour conditional transition.
211 For details see [`ctrans`](#ctrans).
212
213 Related [`trans`](#trans) [`ctrans`](#ctrans) [`btrans`](#btrans)
214
215 ## `bop <op-spec> : <sorts> -> <sort>` ## {#bop}
216
217 Defines a behavioural operator by its domain, codomain, and the term
218 construct. `<sorts>` is a space separated list of sort names containing
219 *exactely* one hidden sort. `<sort>` is a single sort name.
220
221 For `<op-spec>` see the explanations of [`op`](#op).
222
223 Related: [`op`](#op)
224
225 ## `bpred <op-spec> : <sorts>` ## {#bpred}
226
227 Short hand for `op <op-spec> : <sorts> -> Bool` defining a
228 behavioural predicate.
229
230 Related: [`op`](#op) [`bop`](#op) [`pred`](#bpred)
231
232
233 ## `breduce [ in <mod-exp> : ] <term> .` ## {#breduce}
234
235 Alias: `bred`
236
237 Reduce the given term in the given module, if `<mod-exp>` is given,
238 otherwise in the current module.
239
240 For `breduce` equations, possibly conditional, possibly behavioural, are taken
241 into account for reduction.
242
243 Related: [`execute`](#execute) [`reduce`](#reduce)
244
245
246 ## `btrans [ <label-exp> ] <term> => <term> .` ## {#btrans}
247
248 Defines a behaviour transition. For details see [`trans`](#trans).
249
250 Related [`trans`](#trans) [`ctrans`](#ctrans) [`bctrans`](#bctrans)
251
252 ## `cbred` ## {#cbred}
253
254 TODO no documentation
255
256 ## `cd <dirname>` ## {#cd}
257
258 Change the current working directory, like the Unix counterpart.
259 The argument is necessary. No kind of expansion or substitution is done.
260
261 Related: [`pwd`](#pwd) [`ls`](#ls)
262
263 ## `ceq [ <op-exp> ] <term> = <term> if <boolterm> .` ## {#ceq}
264
265 Defines a conditional equation. Spaces around the `if` are obligatory.
266 `<boolterm>` needs to be a Boolean term. For other requirements
267 see [`eq`](#eq).
268
269 Related: [`eq`](#eq) [`beq`](#beq) [`bceq`](#bceq)
270
271 ## `check <something>` switch ## {#switch-check}
272
273 These switches turn on automatic checking of certain properties:
274
275 `check coherency`
276 ~ TODO
277
278 `check compatibility`
279 ~ see the [`check`](#check) command
280
281 `check import`
282 ~ TODO
283
284 `check regularity`
285 ~ see the [`check`](#check) command
286
287 `check sensible`
288 ~ TODO
289
290 ## `check <options>` ## {#check}
291
292 This command allows for checking of certain properties of modules and
293 operators.
294
295 `check regularity <mod_exp>`
296 ~ Checks whether the module given by the module expression
297 `<mod_exp>` is regular.
298
299 `check compatibility <mod_exp>`
300 ~ Checks whether term rewriting system of the module given by the
301 module expression `<mod_exp>` is compatible, i.e., every
302 application of every rewrite rule to every well-formed term
303 results in a well-formed term. (This is not necessarily the case
304 in order-sorted rewriting!)
305
306 `check laziness <op_name>`
307 ~ Checks whether the given operator can be evaluated lazily. If not
308 `<op_name>` is given, all operators of the current module are
309 checked.
310
311 Related: [`regularize`](#regularize)
312
313
314 ## `choose <selection>` ## {#choose}
315
316 Chooses a subterm by the given `<selection>`. See [`apply`](#apply)
317 for details on `<selection>`.
318
319 Related: [`apply`](#apply) [`start`](#start)
320 [`strat` in operator attributes](#opattr)
321
322
323 ## `clean memo` ## {#cleanmemo}
324
325 Resets (clears) the memo storages of the system. Memorized computations
326 are forgotten.
327
328 Related: [`clean memo` switch](#switch-clean-memo)
329
330 ## `clean memo` switch ## {#switch-clean-memo}
331
332 Possible values: `on`, `off`, default `off`.
333
334 tells the system to be forgetful.
335
336 TODO what is the difference between `set memo off` and `set clean memo off`
337
338 ## `close` ## {#close}
339
340 This command closes a modification of a module started by `open`.
341
342 Related: [`open`](#open)
343
344 ## comments ## {#comments}
345
346 The interpreter accepts the following strings as start of a comment
347 that extends to the end of the line: `--`, `-->`, `**`, `**>`.
348
349 The difference in the variants with `>` is that the comment is
350 displayed when run through the interpreter.
351
352 Related: [`**`](#starstar) [`--`](#dashdash)
353
354 ## `cond limit` switch ## {#switch-cond-limit}
355
356 TODO missing documentation
357
358 ## `ctrans [ <label-exp> ] <term> => <term> .` ## {#ctrans}
359
360 Defines a conditional transition. For details see [`trans`](#trans)
361 and [`ceq`](#ceq).
362
363 Related [`trans`](#trans) [`btrans`](#ctrans) [`bctrans`](#bctrans)
364
365
366 ## `describe <something>` ## {#describe}
367
368 like the `show` command with more details. See `describe ?` for
369 the possible set of invocations.
370
371 Related: [`show`](#show)
372
373 ## `eof` ## {#eof}
374
375 Terminates reading of the current file. Allows for keeping
376 untested code or documentations below the `eof` mark. Has
377 to be on a line by itself without leading spaces.
378
379
380 ## `eq [ <op-exp> ] <term> = <term> .` ## {#eq}
381
382 Declares an axiom, or equation.
383
384 Spaces around the `=` are necessary to separate the left from
385 the right hand side. The terms given must belong to the
386 same connected component in the graph defined by the sort ordering.
387
388 In simple words, the objects determined by the terms must be
389 interpretable as of the same sort.
390
391 The optional part `<op-exp>` serves two purposes, one is to give
392 an axiom an identifier, and one is to modify its behaviour. The
393 `<op-exp>` is of the form:
394
395 ` [ <modifier> <label> ] : `
396
397 Warning: The square brackets here are *not* specifying optional
398 components, but syntactical elements. Thus, a labeled axiom
399 can look like:
400
401 `eq[foobar] : foo = bar .`
402
403 The `<modifier>` part is used to change the rewriting behaviour of
404 the axiom. There are at the moment two possible
405 modifiers, namely `:m-and` and `:m-or`. Both make sense only for
406 operators where the arguments come from an associative sort.
407 In this case both modifiers create all possible permutations
408 of the arguments and rewrite the original term to the conjunction
409 in case of `:m-and` or to the disjunction in case of `:m-or` of all
410 the generated terms.
411
412 Assume that `NatSet` is a sort with associative constructor modelling
413 a set of natural number, and let
414
415 `````
416 pred p1: Nat .
417 ops q1 q2 : NatSet -> Bool .
418 eq [:m-and]: q1(N1:Nat NS:NatSet) = p1(N1) .
419 eq [:m-or]: q2(N1:Nat NS:NatSet) = p1(N1) .
420 `````
421
422 In this case an expression like `q1(1 2 3)` would reduce to
423 `p1(1) and p1(2) and p1(3)` (modulo AC), and `q2(1 2 3)` into
424 the same term with `or` instead.
425
426
427 Related: [`ceq`](#ceq) [`beq`](#beq) [`bceq`](#bceq)
428
429
430 ## `eval` `evalq` ## {#eval}
431
432 TODO missing documentation
433
434 Related: [`lisp`](#lisp)
435
436 ## `exec limit` switch ## {#switch-exec-limit}
437
438 Possible values: integers, default limit 4611686018427387903.
439
440 Controls the number of maximal transition steps.
441
442 Related: [`reduce`](#reduce)
443
444 ## `exec trace` switch ## {#switch-exec-trace}
445
446 Possible values: `on` `off, default `off`.
447
448 controls whether further output is provided during reductions.
449
450 Related: [`reduce`](#reduce)
451
452 ## `execute [ in <mod-exp> : ] <term> .` ## {#execute}
453
454 Alias: `exec`
455
456 Reduce the given term in the given module, if `<mod-exp>` is given,
457 otherwise in the current module.
458
459 For `execute` equations and transitions, possibly conditional, are taken
460 into account for reduction.
461
462 Related: [`breduce`](#breduce) [`reduce`](#reduce)
463
464
465 ## `extending ( <modexp> )` ## {#extending}
466
467 Alias: `ex`
468
469 imports the object specified by `modexp` into the current
470 module, allowing models to be inflated, but not collapsing.
471 See [`module expression`](#moduleexpression) for format of `modexp`.
472
473 Related: [`including`](#including) [`protecting`](#protecting)
474 [`using`](#using)
475
476
477 ## `find` ## {#find}
478
479 TODO missing documentation
480
481 ## `find all rules` switch ## {#switch-find-all-rules}
482
483 TODO missing documentation
484
485 ## `full reset` ## {#fullreset}
486
487 Reinitializes the internal state of the system. All supplied modules
488 definitions are lost.
489
490 Related: [`reset`](#reset)
491
492 ## `imports { <import-decl> }` ## {#imports}
493
494 Block enclosing import of other modules (`protecting` etc).
495 Other statements are not allowed within the `imports` block.
496 Optional structuring of the statements in a module.
497
498 Related: [`signature`](#signature) [`axioms`](#axioms)
499 [`extending`](#extending) [`including`](#including)
500 [`protecting`](#protecting) [`using`](#using)
501
502
503 ## `include BOOL` switch ## {#switch-include-bool}
504
505 Possible values: `on` `off`, default `on`.
506
507 By default a couple of built-in modules are implicitly imported with
508 protecting mode. In particular, BOOL is of practical importance. It
509 defines Boolean operators. It is imported to admit conditional
510 axioms.
511
512 This switch allows to disable automatic inclusion of BOOL.
513
514 ## `include RWL` switch ## {#switch-include-rwl}
515
516 Possible values: `on` `off`, default `off`.
517
518 This switch allows to disable automatic inclusion of RWL.
519
520 ## `including ( <modexp> )` ## {#including}
521
522 Alias: `in`
523
524 imports the object specified by `modexp` into the current
525 module.
526
527 See [`module expression`](#moduleexpression) for format of `modexp`.
528
529 Related: [`extending`](#including) [`protecting`](#protecting)
530 [`using`](#using) [`module expression`](#moduleexpression)
531
532 ## `input <pathname>` ## {#input}
533
534 requests the system to read the file specified by the
535 pathname. The file itself may contain `input` commands.
536 CafeOBJ reads the file up to the end, or until it encounters
537 a line that only contains (the literal) `eof`.
538
539
540 ## instantiation of parametrised modules ## {#instantiation}
541
542 Parametrized modules allow for instantiation. The process of
543 instantiation binds actual parameters to formal parameters. The result
544 of an instantiation is a new module, obtained by replacing occurrences
545 of parameter sorts and operators by their actual counterparts. If, as
546 a result of instantiation, a module is imported twice, it is assumed
547 to be imported once and shared throughout.
548
549 Instantiation is done by
550
551 `<module_name> ( <bindings> )`
552
553 where `<module_name>` is the name of a parametrized module, and
554 `<bindings>` is a comma-separated list of binding constructs.
555
556 using declared views
557 ~ you may bind an already declared view to a parameter:
558
559 `<parameter> <= <view_name>`
560
561 If a module `M` has a parameter `X :: T` and a view `V` from `T`
562 to `M'` is declared, `V` may be bound to `X`, with the effect that
563
564 1. The sort and operator names of `T` that appear in the body
565 of `M` are replaced by those in `M'`, in accordance with `V`,
566
567 2. The common submodules of `M` and `M'` are shared.
568
569 using ephemeral views
570 ~ In this case the view is declared and used at the same time.
571
572 `<parameter> <= view to <mod_name> { <view_elements> }`
573
574 See [`view`](#view) for details concerning `<view_elements>`. The
575 `from` parameter in the `view` declaration is taken from
576 `<parameter>`.
577
578
579 To make notation more succinct, parameters can be identified also by
580 position instead of names as in
581
582 `<mod_name> ( <view_name>, <view_name> )`
583
584 which would bind the `<view_name>`s to the respective parameters
585 of the parametrized module `<mod_name>`.
586
587 This can be combined with the ephemeral defintion of a view like in
588 the following example (assume `ILIST` has two parameters):
589
590 ~~~~~
591 module NAT-ILIST {
592 protecting ( ILIST(SIMPLE-NAT { sort Elt -> Nat },
593 DATATYPE { sort Elt -> Data }) )
594 }
595 ~~~~~
596
597
598 ## `let <identifier> = <term> .` ## {#let}
599
600 Using `let` one can define aliases, or context variables. Bindings
601 are local to the current module. Variable defined with `let` can be
602 used in various commands like `reduce` and `parse`.
603
604 Although `let` defined variable behave very similar to syntactic
605 shorthands, they are not. The right hand side `<term>` needs to
606 be a fully parsable expression.
607
608 ## `libpath` switch ## {#switch-libpath}
609
610 Possible values: list of strings.
611
612 The switch `libpath` contains a list of directories where CafeOBJ
613 searches for include files. Addition and removal of directories can be
614 done with
615
616 `````
617 set libpath + <path1>:<path2>:...
618 set libpath - <path1>:<path2>:...
619 `````
620
621 or the full libpath reset by `set libpath <path1>:<path2>:...`
622
623 The current directory has a privileged status: It is always searched
624 first and cannot be suppressed.
625
626
627 ## `lisp`, `lispq` ## {#lisp}
628
629 TODO missing documentation `lispq` is ??quiet??
630
631 These two commands evaluate an arbitrary lisp expression, example:
632 `````
633 CafeOBJ> lisp (+ 4 5)
634 (+ 4 5) -> 9
635 `````
636
637 Related: [`eval`](#eval)
638
639 ## `look up <something>` ## {#lookup}
640
641 TODO to be written, currently segfaults
642
643 ## `ls <pathname>` ## {#ls}
644
645 lists the given `pathname`. Argument is obligatory.
646
647 Related: [`cd`](#ls) [`pwd`](#pwd)
648
649
650 ## `make <mod_name> ( <mod_exp> )` ## {#make}
651
652 This commands defines a new module `<mod_name>` by evaluating the
653 module expression `<mod_exp>`.
654
655 Related: [module expressions](#moduleexpression)
656
657
658 ## `match <term_spec> to <pattern> .` ## {#match}
659
660 Matches the term denoted by `<term_spec>` to the
661 pattern. `<term_spec>` is either `top` or `term` for the term set by
662 the `start` command; `subterm` for the term selected by the `choose`
663 command; `it` has the same meaning as `subterm` if `choose` was used,
664 otherwise the same meaning as `top`, or a normal term expression.
665
666 The given `<pattern>` is either `rules`, `-rules`, `+rules`, one of
667 these three prefixed by `all`, or a term. If one of the `rules` are
668 given, all the rules where the left side (for `+rules`), the right
669 side (for `-rules`), or any side (for `rules`) matches. If the `all`
670 (with separating space) is given all rules in the current context,
671 including those declared in built-in modules, are inspected.
672
673 If a term is given, then the two terms are matched, and if successful,
674 the matching substitution is printed.
675
676
677 ## `module[!|*] <modname> [ ( <params> ) ] [ <principal_sort_spec> ] { mod_elements ... }` ## {#module}
678
679 Alias: `mod`
680
681 defines a module, the basic building block of CafeOBJ. Possible elements
682 are declarations of
683
684 - import - see `protecting`, `extending`, `including`, `using`
685 - sorts - see `sort declaration`
686 - variable - see `var`
687 - equation - see `op`, `eq`, `ceq`, `bop`, `beq`, `bceq`
688 - transition - see `trans`, `ctrans`, `btrans`, `bctrans`
689
690 `modname` is an arbitrary string.
691
692 `module*` introduces a loose semantic based module.
693
694 `module!` introduces a strict semantic based module.
695
696 `module` introduces a module without specified semantic type.
697
698 If `params` are given, it is a parametrized module. See `parametrized module`
699 for more details.
700
701 If `principal_sort_spec` is given, it has to be of the form
702 `principal-sort <sortname>` (or `p-sort <sortname>`). The principal
703 sort of the module is specified, which allows more concise `view`s from
704 single-sort modules as the sort mapping needs not be given.
705
706 ## module expression ## {#moduleexpression}
707
708 In various syntax elements not only module names itself, but whole
709 module expressions can appear. A typical example is
710
711 `open <mod_exp> .`
712
713 which opens a module expression. The following constructs are
714 supported:
715
716 module name
717 ~ using the name of a module
718
719 renaming
720 ~ `<mod_exp> * { <mappings> }`
721
722 This expressions describes a new module where sort and/or
723 operators are renamed.
724 `<mappings>` are like in the case of [`view`](#view) a comma
725 separated list of mappings of either sorts (`sort` and `hsort`) or
726 operators (`op` and `bop`). Source names may be qualified, while
727 target names are not, they are required to be new names. Renaming
728 is often used in combination with [instantiantion](#instantiation).
729
730 summation
731 ~ `<mod_exp> + <mod_exp>`
732
733 This expression describes a module consisting of all the module
734 elements of the summands. If a submodule is imported more than
735 once, it is assumed to be shared.
736
737 ## parametrized module ## {#parametrizedmodule}
738
739 A module with a parameter list (see `module`) is a parametrized module.
740 Parameters are given as a comma (`,`) separated list. Each parameter is
741 of the form `[ <import_mode> ] <param_name> :: <module_name>`
742 (spaces around `::` are obligatory).
743
744 The parameter's module gives minimal requirements on the module
745 instantiation.
746
747 Within the module declaration sorts and operators of the parameter
748 are qualified with `.<parameter_name>` as seen in the example below.
749
750 Example:
751
752 ~~~~~
753 mod* C {
754 [A]
755 op add : A A -> A .
756 }
757 mod! TWICE(X :: C) {
758 op twice : A.X -> A.X .
759 eq twice(E:A.X) = add.X(E,E) .
760 }
761 ~~~~~
762
763 Related: [qualified sort etc](#qualifiedother)
764
765 ## `memo` switch ## {#switch-memo}
766
767 controls the memorization of computations. The system memorizes
768 evaluations of operators declared with the [`memo`](#opattr) operator
769 attribute. Turning this switch off disables all memorization.
770
771 ## on-the-fly declarations ## {#onthefly}
772
773 Variables and constants can be declared *on-the-fly* (or *inline*). If an
774 equation contains a qualified variable (see [qualified term](#qualified)),
775 i.e., `<name>:<sort-name>`, then from this point on *within* the current
776 equation only `<name>` is declared as a variable of sort `<sort-name>`.
777
778 It is allowed to redeclare a previously defined variable name via
779 an on-the-fly declaration, but as mentioned above, not via an
780 explicit redeclaration.
781
782 Using a predeclared variable name within an equation first as is,
783 that is as the predeclared variable, and later on in the same
784 equation with an on-the-fly declaration is forbidden. That is, under
785 the assumption that `A` has been declared beforehand, the following
786 equation is *not* valid:
787
788 `eq foo(A, A:S) = A .`
789
790 On-the-fly declaration of constants are done the same way, where the
791 `<name>` is a constant name as in `\`a:Nat`. Using this construct is
792 similar to defining an operator
793
794 `op <name> : -> <sort>`
795
796 or in the above example, `op a : -> Nat .`, besides that the
797 on-the-fly declaration of constants, like to one of variables, is only
798 valid in the current context (i.e., term or axiom). These constant
799 definitions are quite common in proof scores.
800
801 Related: [`var`](#var)
802
803 ## `op <op-spec> : <sorts> -> <sort> { <attribute-list> }` ## {#op}
804
805 Defines an operator by its domain, codomain, and the term construct.
806 `<sorts>` is a space separated list of sort names, `<sort>` is a
807 single sort name.
808 `<op-spec>` can be of the following forms:
809
810 prefix-spec
811 ~ the `<op-spec>` does not contain a literal `_`:
812 This defines a normal prefix operator with domain `<sorts>` and
813 codomain `<sort>`
814
815 Example: `op f : S T -> U`
816 mixfix-spec
817 ~ the `<op-spec>` contains exactely as many literal `_` as there are
818 sort names in `<sorts>`:
819 This defines an arbitrary mixfix (including postfix) operator
820 where the arguments are inserted into the positions designated
821 by the underbars.
822
823 Example: `op _+_ : S S -> S`
824
825 For the description of `<attribute-list>` see the entry for
826 [operator attributes](#opattr).
827
828 ## `open <mod_exp> .` ## {#open}
829
830 This command opens the module specified by the module expression
831 `<mod_exp>` and allows for declaration of new sorts, operators, etc.
832
833 Related: [`close`](#close) [module expression](#moduleexpression)
834 [`select`](#select)
835
836 ## operator attributes ## {#opattr}
837
838 In the specification of an operator using the [`op`](#op) (and
839 related) keyword, attributes of the operator can be specified.
840 An `<attribute-list>` is a space-separate list of single
841 attribute definitions. Currently the following attributes are
842 supported
843
844 `associative`
845 ~ specifies an associative operator, alias `assoc`
846
847 `commutative`
848 ~ specifies a commutative operator, alias `comm`
849
850 `itempotence`
851 ~ specifies an idempotent operator, alias `idem`
852
853 `id: <const>`
854 ~ specifies that an identity of the operator exists and
855 that it is `<const>`
856
857 `prec: <int>`
858 ~ specifies the parsing precedence of the operator, an integer <int>.
859 Smaller precedence values designate stronger binding. See
860 [operator precedence](#opprec) for details of the predefined
861 operator precedence values.
862
863 `l-assoc` and `r-assoc`
864 ~ specifies that the operator is left-associative or
865 right-associative
866
867 `constr`
868 ~ specifies that the operator is a constructor of the coarity sort.
869 (not evaluated at the moment)
870
871
872 `strat: ( <int-list> )`
873 ~ specifies the evaluation strategy. Each integer in the list refers
874 to an argument of the operator, where `0` refers to the whole term,
875 `1` for the first argument, etc. Evaluation proceeds in order of
876 the `<int-list>`. Example:
877
878 `op if_then_else_fi : Bool Int Int -> Int { strat: (1 0) }`
879
880 In this case the first argument (the boolean term) is tried to
881 be evaluated, and depending on that either the second or third.
882 But if the first (boolean) argument cannot be evaluated,
883 no evaluation in the subterms will appear.
884
885 Using negative values allows for lazy evaluation of the corresponding
886 arguments.
887
888 `memo`
889 ~ tells the system to remember the results of evaluations where the
890 operator appeared. See [`memo` switch](#switch-memo) for details.
891
892 Remarks:
893
894 - Several operators of the same arity/coarity can be defined by
895 using `ops` instead of `op`:
896
897 `ops f g : S -> S`
898
899 For the case of mixfix operators the underbars have to be given
900 and the expression surrounded by parenthesis:
901
902 `ops (_+_) (_*_) : S S -> S`
903
904 - Spaces *can* be part of the operator name, thus an operator
905 definition of `op foo op : S -> S` is valid, but not advisable,
906 as parsing needs hints.
907
908 - A single underbar cannot be an operator name.
909
910 Related: [`bop`](#bop)
911
912 ## operator precedence ## {#opprec}
913
914 CafeOBJ allows for complete freedom of syntax, in particular infix
915 operators and overloading. To correctly parse terms that are ambigous,
916 all operators have precedence values. These values can be adjusted
917 manually during definition of the operator
918 (see [operator attributes](#opattr)). In absence of manual
919 specification of the operator precedence, the values are determined by
920 the following rules:
921
922 - standard prefix operators, i.e., those of the form `op f : S1 .. Sk -> S`,
923 receive operator precedence value 0.
924 - unary operators, i.e., those of the form `op u_ : S1 -> S`, receive
925 precedence 15.
926 - mix-fix operators with forst and last token being arguments, i.e.,
927 those of the form `op _ arg-or-op _ : S1 .. Sk -> S`, receive
928 precedence 41.
929 - all other operators (constants, operators of the form `a _ b`, etc.)
930 receive precedence 0.
931
932 Related: [operator attributes](#opattr)
933
934
935 ## `parse [ in <mod-exp> : ] <term> .` ## {#parse}
936
937 Tries to parse the given term within the module specified by
938 the module expression `<mod-exp>`, or the current module if not given,
939 and returns the parsed and qualified term.
940
941 In case of ambiguous terms, i.e., different possible parse trees, the
942 command will prompt for one of the trees.
943
944 Related: [qualified term](#qualified)
945
946
947 ## `parse normalize` switch ## {#switch-parse-normalize}
948
949 TODO missing documentation
950
951
952 ## `pred <op-spec> : <sorts>` ## {#pred}
953
954 Short hand for `op <op-spec> : <sorts> -> Bool` defining a predicate.
955
956 Related: [`op`](#op) [`bpred`](#bpred)
957
958
959 ## `print depth` switch ## {#switch-print-depth}
960
961 Possible values: natural numbers, default `unlimited`.
962
963 Controls to which depth terms are printed.
964
965
966 ## `print mode` switch ## {#switch-print-mode}
967
968 Possible values: `normal` `fancy` `tree` `s-expr`
969
970 Selects one of the print modes.
971
972 ## `protect <module-name>` ## {#protect}
973
974 Protect a module from being overwritten.
975 Some modules vital for the system are initially protected.
976 Can be reversed with `unprotect`.
977
978 Related: [`unprotect`](#unprotect)
979
980
981 ## `protecting ( <modexp> )` ## {#protecting}
982
983 Alias: `pr`
984
985 imports the object specified by `modexp` into the current
986 module, preserving all intended models as they are. See `module expression`
987 for format of `modexp`.
988
989 Related: [`extending`](#extending) [`using`](#using) [`including`](#including)
990
991 ## `provide <feature>` ## {#provide}
992
993 discharges a feature requirement: once `provide`d, all the subsequent
994 `require`ments of a feature are assumed to have been fulfilled
995 already.
996
997 Related: [`require`](#require)
998
999 ## `pwd` ## {#pwd}
1000
1001 Prints the current working directory.
1002
1003 Related: [`cd`](#cd) [`ls`](#ls)
1004
1005 ## qualified sort/operator/parameter ## {#qualifiedother}
1006
1007 CafeOBJ allows for using the same name for different sorts,
1008 operators, and parameters. One example is declaring the same sort in
1009 different modules. In case it is necessary to qualify the sort,
1010 operator, or parameter, the intended module name can be affixed after
1011 a literal `.`: `<name>.<modname>`
1012
1013 Example: In case the same sort `Nat` is declared in both the module
1014 `SIMPLE-NAT` and `PANAT`, one can use `Nat.SIMPLE-NAT` to reference
1015 the sort from the former module.
1016
1017 Furthermore, a similar case can arise when operators of the same name
1018 have been declared with different number of arguments. During operator
1019 renaming (see [view](#view)) the need
1020 for qualification of the number of parameters might arise. In this
1021 case the number can be specified after an affixed `/`:
1022 `<opname>/<argnr>`
1023
1024 Related: [parametrized module](#parametrizedmodule) [qualified term](#qualified)
1025
1026 ## qualified term ## {#qualified}
1027
1028 In case that a term can be parsed into different sort, it is possible to
1029 qualify the term to one of the possible sorts by affixing it with
1030 `: <sort-name>` (spaces before and after the `:` are optional).
1031
1032 Example: `1:NzNat` `2:Nat`
1033
1034 Related: [`parse`](#parse)
1035
1036
1037 ## `quiet` switch ## {#switch-quiet}
1038
1039 Possible values: `on` `off`, default `off`
1040
1041 If set to `on`, the system only issues error messages.
1042
1043 Related: [`verbose` switch](#switch-verbose)
1044
1045 ## `quit` ## {#quit}
1046
1047 Leaves the CafeOBJ interpreter.
1048
1049 ## `reduce [ in <mod-exp> : ] <term> .` ## {#reduce}
1050
1051 Alias: `red`
1052
1053 Reduce the given term in the given module, if `<mod-exp>` is given,
1054 otherwise in the current module.
1055
1056 For `reduce` only equations and conditional equations are taken into
1057 account for reduction.
1058
1059 Related: [`execute`](#execute) [`breduce`](#breduce)
1060
1061
1062 ## `reduce conditions` switch ## {#switch-reduce-conditions}
1063
1064 Possible values: `on` `off`, default `off`.
1065
1066 When using [`apply`](#apply) to step through a reduction, this switch
1067 allows to turn on automatic reduction of conditions in conditional
1068 equations.
1069
1070 Related: [`apply`](#apply)
1071
1072
1073 ## `regularize <mod-name>` ## {#regularize}
1074
1075 Regularizes the signature of the given module, ensuring that every
1076 term has exactely one minimal parse tree. In this process additional
1077 sorts are generated to ensure unique least sort of all terms.
1078
1079 Modules can be automatically regularized by the interpreter if the
1080 `regularize signature` switch is turn to `on`.
1081
1082 TODO -- should we give more details here -- unclear to me.
1083
1084 ## `regularize signature` switch ## {#switch-regularize-signature}
1085
1086 See [`regularize](#regularize)
1087
1088
1089 ## `require <feature> [ <pathname> ]` ## {#require}
1090
1091 requires a feature, which usually
1092 denotes a set of module definitions. Given this command, the
1093 system searches for a file named the feature, and read the file
1094 if found. If a pathname is given, the system searches for a file
1095 named the pathname instead.
1096
1097 Related: [`provide`](#provide)
1098
1099 ## `reset` ## {#reset}
1100
1101 Restores the definitions of built-in modules and preludes, but does not
1102 affect other modules.
1103
1104 Related: [`full reset`](#fullreset)
1105
1106 ## `restore <pathname>` ## {#restore}
1107
1108 restores module definitions from the designated file `pathname` which
1109 has been saved with the `save` command. `input` can also be used but
1110 the effects might be different.
1111
1112 TODO -- should we keep the different effects? What is the real difference?
1113
1114 Related: [`input`](#input) [`save`](#save)
1115 [`save-system`](#save-system)
1116
1117 ## `rewrite limit` switch ## {#switch-rewrite}
1118
1119 Possible values: positive integers, default not specified.
1120
1121 Allows limiting the number of rewrite steps during a stepwise
1122 execution.
1123
1124 Related: [`step` switch](#switch-step)
1125
1126 ## `save <pathname>` ## {#save}
1127
1128 saves module definitions into the designated file `pathname`.
1129 File names should be suffixed with `.bin`.
1130
1131 `save` also saves the contents of prelude files as well as module definitions
1132 given in the current session.
1133
1134 Related: [`input`](#input) [`restore`](#restore) [`save-system`](#save-system)
1135
1136 ## `save-system <pathname>` ## {#save-system}
1137
1138 dumps the image of the whole system into a file. This is functionality
1139 provided by the underlying Common Lisp system and might carry some
1140 restrictons.
1141
1142 Related: [`input`](#input) [`save`](#save) [`restore`](#restore)
1143
1144 ## search predicates ## {#searchpredicate}
1145
1146 CafeOBJ provides a whole set of search predicates `=(n,m)=>` for
1147 searching transitions starting from a given term. The first value `n`
1148 specifies the maximum number of solutions searched, and can be either
1149 a natural number of `*`, in which case all solutions are searched. The
1150 second value `m` is the maximum depth, and can be a natural number
1151 (but not `*`).
1152
1153 TODO: `=(n,m)=>+` ??? other specifiers?
1154
1155
1156 ## `select <mod_exp> . ` ## {#select}
1157
1158 Selects a module given by the module expression `<mod_exp>` as the
1159 current module. All further operations are carried out within the
1160 given module. In constrast to `open` this does not allow for
1161 modification of the module, e.g., addition of new sorts etc.
1162
1163 Related: [`open`](#open) [module expression](#moduleexpression)
1164
1165
1166 ## `set <name> [option] <value>` ## {#set}
1167
1168 Depending on the type of the switch, options and value specification varies.
1169 Possible value types for switches are boolean (`on`, `off`), string (`"value"`),
1170 integers (5434443), lists (lisp syntax).
1171
1172 For a list of all available switches, use `set ?`. To see the current
1173 values, use `show switches`. To single out two general purpose switches,
1174 `verbose` and `quiet` tell the system to behave in the respective way.
1175
1176 Related: [`show`](#show) [`switches`](#switches)
1177
1178 ## `show <something>` ## {#show}
1179
1180 The `show` command provides various ways to inspect all kind of objects
1181 of the CafeOBJ language. For a full list call `show ?`.
1182
1183 Some of the more important (but far from complete list) ways to call
1184 the `show` command are:
1185
1186 - `show [ <modexp> ]` - describes the current modules of the one specified
1187 as argument
1188 - `show switches` - lists all possible switches
1189 - `show <term>` - displays a term, posible in tree format
1190
1191 See the entry for `switches` for a full list.
1192
1193 Related: [`switches`](#switches) [`describe`](#describe)
1194
1195 ## `show mode` switch ## {#switch-show-mode}
1196
1197 Possible values for `set show mode <mode>` are `cafeobj` and `meta`.
1198
1199 TODO no further information on what this changes
1200
1201 ## `signature { <sig-decl> }` ## {#signature}
1202
1203 Block enclosing declarations of sorts and operators.
1204 Other statements are not allowed within the `signature` block.
1205 Optional structuring of the statements in a module.
1206
1207 Related: [`axioms`](#axioms) [`imports`](#imports)
1208 [`sort`](#sort) [`op`](#op)
1209
1210
1211 ## sort declaration ## {#sort}
1212
1213 CafeOBJ supports two kind of sorts, visible and hidden sorts. Visible
1214 sorts are introduced between `[` and `]`, while hidden sorts are introduced
1215 between `*[` and `]*`.
1216
1217 ~~~~
1218 [ Nat ]
1219 *[ Obs ]*
1220 ~~~~
1221
1222 Several sorts can be declared at the same time, as in `[ Nat Int ]`.
1223
1224 Since CafeOBJ is based on order sorting, sorts can form a partial order.
1225 Definition of the partial order can be interleaved by giving
1226
1227 ~~~~
1228 [ <sorts> < <sorts> ]
1229 ~~~~
1230
1231 Where `sorts` is a list of sort names. This declaration defines an inclusion
1232 relation between each pair or left and right sorts.
1233
1234 Example:
1235
1236 ~~~~
1237 [ A B , C D < A < E, B < D ]
1238 ~~~~
1239
1240 defines five sorts `A`,...,`E`, with the following relations:
1241 `C < A`, `D < A`, `A < E`, `B < D`.
1242
1243
1244 ## `start <term> .` ## {#start}
1245
1246 Sets the focus onto the given term `<term>` of the currently opened
1247 module or context. Commands like `apply`, `choose`, or `match` will
1248 then operate on this term.
1249
1250 Related: [`apply`](#apply) [`choose`](#choose) [`match`](#match)
1251
1252
1253 ## `statistics` switch ## {#switch-statistics}
1254
1255 Possible values: `on` `off`, default `on`.
1256
1257 After each reduction details about the reduction are
1258 shown. Information shown are the time for parsing the expression, the
1259 number of rewrites and run time during rewriting, and the number of
1260 total matches performed during the reduce.
1261
1262 TODO: verify
1263
1264 ## `step` switch ## {#switch-step}
1265
1266 Possible values: `on` `off`, default `off`.
1267
1268 With this switch turned on, rewriting proceeds in steps and prompts
1269 the user interactively. At each prompt the following commands can be
1270 given to the stepper (with our without leading colon `:`):
1271
1272 `help`
1273 : (`h`, `?`) print out help page
1274 `next`
1275 : (`n`) go one step
1276 `continue`
1277 : (`c`) continue rewriting without stepping
1278 `quit`
1279 : (`q`) leave stepper continuing rewrite
1280 `abort`
1281 : (`a`) abort rewriting
1282 `rule`
1283 : (`r`) print out current rewrite rule
1284 `subst`
1285 : (`s`) print out substitution
1286 `limit`
1287 : (`l`) print out rewrite limit count
1288 `pattern`
1289 : (`p`) print out stop pattern
1290 `stop [<term>] .`
1291 : set (or unset) stop pattern
1292 `rwt [<number>] .`
1293 : set (or unset) max number of rewrite
1294
1295 Other standard CafeOBJ commands that can be used are [`show`](#show),
1296 [`describe`](#describe), [`set`](#set), [`cd`](#cd), [`ls`](#ls),
1297 [`pwd`](#pwd), [`lisp`](#lisp), [`lispq`](#lisp), and (on Unix only)
1298 [`!`](#commandexec).
1299
1300 ## `stop pattern` switch ## {#switch-stop-pattern}
1301
1302 This command causes reductions to stop when the reductants get to
1303 containing subterms that match the given term. If no term is given,
1304 this restriction is lifted.
1305
1306 TODO does not work as far as I see -- shouldn't the following code
1307 fragment stop at the occurrence of `(s 2)`, before rewriting it to
1308 the final 3?
1309
1310 `````
1311 CafeOBJ> open NAT .
1312
1313 -- opening module NAT.. done.
1314
1315 %NAT> set stop pattern (s 2) .
1316
1317 %NAT> red (s (s (s 0))) .
1318 -- reduce in %NAT : (s (s (s 0))):NzNat
1319 (3):NzNat
1320 (0.000 sec for parse, 3 rewrites(0.000 sec), 3 matches)
1321
1322 %NAT>
1323 `````
1324
1325 Related: [`step` switch](#switch-step)
1326
1327 ## switches ## {#switches}
1328
1329 Switches control various aspects of the computations and behaviour
1330 of CafeOBJ. The current list of switches and their values can be
1331 shown with
1332
1333 `````
1334 show switches
1335 `````
1336
1337 The single switches are described separately in this manual.
1338
1339 Related: [`set`](#set) [`show`](#show)
1340
1341
1342 ## `trace [whole]` switch ## {#switch-trace}
1343
1344 During evaluation, it is sometimes desirable to see the rewrite
1345 sequences, not just the results. Setting the switch `trace whole` will
1346 result in the resultant term of each rewrite step being
1347 printed. Setting the switch `trace` will result in the display of
1348 which rule, substitution, and replacement are used.
1349
1350
1351 ## `trans [ <label-exp> ] <term> => <term> .` ## {#trans}
1352
1353 Defines a transition, which is like an equation but without
1354 symmetry.
1355
1356 See [`eq`](#eq) for specification of requirements on `<label-exp>`
1357 and the terms.
1358
1359 Transitions and equations server similar, but different purpose. In
1360 particular, reductions (both with or without behavior axioms used) do
1361 not take transitions into account. Only [`exec`](#execute) also uses
1362 transitions. On the other hand, the built-in
1363 [search predicate](#searchpredicate) searches all possible transitions
1364 from a given term.
1365
1366 ## `unprotect <module-name>` ## {#unprotect}
1367
1368 Remove overwrite protection from a module that has been protected
1369 with the `protect` call. Some modules vital for the system
1370 are initially protected.
1371
1372 Related: [`protect`](#protect)
1373
1374
1375 ## `using ( <modexp> )` ## {#using}
1376
1377 Alias: `us`
1378
1379 imports the object specified by `modexp` into the current
1380 module without any restrictions on the models.
1381 See `module expression` for format of `modexp`.
1382
1383 Related: [`extending`](#extending) [`including`](#including)
1384 [`protecting`](#protecting)
1385
1386
1387 ## `var <var-name> : <sort-name>` ## {#var}
1388
1389 Declares a variable `<var-name>` to be of sort `<sort-name>`.
1390 The scope of the variable is the current module.
1391 Redeclarations of variable names are not allowed.
1392 Several variable of the same sort can be declared at the same time
1393 using the `vars` construct:
1394
1395 `vars <var-name> ... : <sort-name>`
1396
1397 Related: [`op`](#op) [qualified term](#qualified) [on-the-fly](#onthefly)
1398
1399 ## `verbose` switch ## {#switch-verbose}
1400
1401 Possible values: `on` `off`, default `off`.
1402
1403 If turn `on`, the system is much more verbose in many commands.
1404
1405 Related: [`quiet` switch](#switch-quiet)
1406
1407 ## `version` ## {#version}
1408
1409 Prints out the version of CafeOBJ.
1410
1411 ## `view <name> from <modname> to <modname> { <viewelems> }` ## {#view}
1412
1413 A view specifies ways to bind actual parameters to formal parameters
1414 (see [parametrized module](#parametrizedmodule)). The view has to
1415 specify the mapping of the sorts as well as the operators.
1416
1417 The `<viewelems>` is a comma-separated list of expressions specifying
1418 these mappings:
1419
1420 ~~~~
1421 sort <sortname> -> <sortname>
1422 hsort <sortname> -> <sortname>
1423 op <opname> -> <opname>
1424 bop <opname> -> <opname>
1425 ~~~~
1426
1427 and also can contain variable declarations.
1428
1429 Infix operators are represented as terms containing the operator with
1430 either literal underscores `_`, or variables: `_*_` or `X * Y`.
1431 The `<opname>` can be qualified.
1432
1433 Example: Assume a module `MONOID` with sort `M` and ops `e` and `*`
1434 are given, and another `SIMPLE-NAT` with sort `Nat` and operators `0`
1435 and `+` (with the same arity). Then the following expression
1436 constitutes a view:
1437
1438 ~~~~~
1439 view NAT-AS-MONOID from MONOID to SIMPLE-NAT {
1440 sort M -> Nat,
1441 op e -> 0,
1442 op _*_ -> _+_
1443 }
1444 ~~~~~
1445
1446 In specifying views some rules can be omitted:
1447
1448 1. If the source and target modules have common submodules, all the
1449 sorts and modules decalred therein are assumed to be mapped to
1450 themselves;
1451
1452 2. If the source and target modules have sorts and/or operators with
1453 identical names, they are mapped to their respective counterparts;
1454
1455 3. If the source module has a single sort and the target has a
1456 principal sort, the single sort is mapped to the principal sort.
1457
1458
1459 Related: [instantiation](#instantiation)
1460