tla-ts 0.0.10-dev.28c823e4b → 0.0.10-dev.3a85c3a9e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/compile.cjs +6 -6
- package/dist/compile.js +10 -10
- package/dist/deciders.cjs +41 -37
- package/dist/deciders.js +57 -53
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +2683 -427
- package/dist/prove.js +2681 -425
- package/dist/run.cjs +45 -42
- package/dist/run.js +47 -44
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +42 -39
- package/dist/transfer.js +44 -41
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/ast.ts +41 -36
- package/src/builtins.ts +4 -13
- package/src/check-failure.ts +116 -0
- package/src/check-trace.ts +282 -0
- package/src/check.ts +353 -549
- package/src/cli/options.ts +6 -31
- package/src/cli/shared.ts +1 -1
- package/src/cli/tlapm.ts +433 -70
- package/src/cli/tlc-arguments.ts +222 -210
- package/src/cli/tlc-output.ts +687 -0
- package/src/cli/tlc-usage.ts +1 -2
- package/src/cli/tlc.ts +34 -701
- package/src/cli/xml-exporter.ts +23 -33
- package/src/codegen.ts +5 -10
- package/src/coverage.ts +3 -10
- package/src/dependencies.ts +30 -14
- package/src/dfid.ts +16 -16
- package/src/environment-config.ts +315 -0
- package/src/environment.ts +45 -333
- package/src/errors.ts +33 -5
- package/src/evaluate.ts +5 -4
- package/src/exit-codes.ts +1 -0
- package/src/fingerprints.ts +65 -1
- package/src/instances.ts +47 -10
- package/src/java-hash.ts +7 -0
- package/src/json.ts +4 -7
- package/src/levels.ts +39 -42
- package/src/lexer.ts +5 -3
- package/src/liveness-checker.ts +553 -237
- package/src/liveness.ts +94 -86
- package/src/obligations/action.ts +14 -17
- package/src/obligations/anonymize.ts +37 -16
- package/src/obligations/enabled-axioms.ts +218 -0
- package/src/obligations/equality.ts +1 -3
- package/src/obligations/expression.ts +36 -8
- package/src/obligations/format.ts +0 -2
- package/src/obligations/generate.ts +66 -54
- package/src/obligations/index.ts +38 -8
- package/src/obligations/levels.ts +24 -11
- package/src/obligations/module.ts +28 -41
- package/src/obligations/normalize.ts +26 -14
- package/src/obligations/operators.ts +0 -2
- package/src/obligations/pragma.ts +53 -16
- package/src/obligations/printer.ts +43 -13
- package/src/obligations/proof.ts +3 -2
- package/src/obligations/regroup.ts +0 -2
- package/src/obligations/simplify.ts +55 -50
- package/src/obligations/source.ts +118 -74
- package/src/obligations/subexpression.ts +45 -18
- package/src/obligations/substitution.ts +1 -3
- package/src/obligations/temporal.ts +5 -7
- package/src/obligations/tuples.ts +0 -2
- package/src/parallel-worker.ts +10 -30
- package/src/parallel.ts +24 -47
- package/src/parser.ts +580 -180
- package/src/pretty-print.ts +1 -1
- package/src/prover/decide-pool.ts +3 -3
- package/src/prover/deciders.ts +12 -9
- package/src/prover/isabelle/decide.ts +3 -25
- package/src/prover/isabelle/encode.ts +72 -42
- package/src/prover/isabelle/isar/attrib.ts +250 -0
- package/src/prover/isabelle/isar/context.ts +335 -0
- package/src/prover/isabelle/isar/induct.ts +382 -0
- package/src/prover/isabelle/isar/inner-syntax.ts +158 -7
- package/src/prover/isabelle/isar/method.ts +509 -212
- package/src/prover/isabelle/isar/proof.ts +570 -14
- package/src/prover/isabelle/isar/rule-cases.ts +224 -0
- package/src/prover/isabelle/isar/theory.ts +487 -76
- package/src/prover/isabelle/isar/toplevel.ts +331 -0
- package/src/prover/isabelle/isar/type-check.ts +89 -14
- package/src/prover/isabelle/provers/blast/blast.ts +7 -65
- package/src/prover/isabelle/provers/blast/branch.ts +0 -2
- package/src/prover/isabelle/provers/blast/prove.ts +0 -2
- package/src/prover/isabelle/provers/blast/rules.ts +0 -2
- package/src/prover/isabelle/provers/blast/state.ts +0 -2
- package/src/prover/isabelle/provers/blast/term.ts +0 -2
- package/src/prover/isabelle/provers/clasimp.ts +0 -2
- package/src/prover/isabelle/provers/classical.ts +45 -20
- package/src/prover/isabelle/provers/hypsubst.ts +17 -28
- package/src/prover/isabelle/pure/bicompose.ts +9 -27
- package/src/prover/isabelle/pure/consts.ts +0 -2
- package/src/prover/isabelle/pure/conv.ts +2 -10
- package/src/prover/isabelle/pure/drule.ts +72 -6
- package/src/prover/isabelle/pure/envir.ts +0 -2
- package/src/prover/isabelle/pure/goal.ts +1 -3
- package/src/prover/isabelle/pure/logic.ts +1 -3
- package/src/prover/isabelle/pure/name.ts +0 -2
- package/src/prover/isabelle/pure/net.ts +0 -2
- package/src/prover/isabelle/pure/object-logic.ts +13 -7
- package/src/prover/isabelle/pure/pattern.ts +0 -2
- package/src/prover/isabelle/pure/raw-simplifier.ts +4 -15
- package/src/prover/isabelle/pure/rewriter.ts +6 -17
- package/src/prover/isabelle/pure/search.ts +0 -2
- package/src/prover/isabelle/pure/seq.ts +0 -2
- package/src/prover/isabelle/pure/simplifier.ts +26 -7
- package/src/prover/isabelle/pure/table.ts +2 -3
- package/src/prover/isabelle/pure/tactic.ts +0 -2
- package/src/prover/isabelle/pure/tactical.ts +42 -37
- package/src/prover/isabelle/pure/term-ord.ts +0 -2
- package/src/prover/isabelle/pure/term.ts +0 -2
- package/src/prover/isabelle/pure/thm.ts +14 -13
- package/src/prover/isabelle/pure/type.ts +0 -2
- package/src/prover/isabelle/pure/unify.ts +0 -2
- package/src/prover/isabelle/pure/variable.ts +0 -2
- package/src/prover/isabelle/tla/classical-setup.ts +18 -16
- package/src/prover/isabelle/tla/context.ts +58 -11
- package/src/prover/isabelle/tla/logic-data.ts +1 -1
- package/src/prover/isabelle/tla/logic.ts +49 -21
- package/src/prover/isabelle/tla/simpdata.ts +1 -12
- package/src/prover/isabelle/tools/intuitionistic.ts +28 -12
- package/src/prover/ocaml.ts +4 -1
- package/src/prover/prep/action.ts +30 -31
- package/src/prover/prep/enabled-axioms.ts +11 -2
- package/src/prover/prep/fingerprint.ts +2 -5
- package/src/prover/prep/methods.ts +181 -51
- package/src/prover/prep/normalize.ts +38 -9
- package/src/prover/prove.ts +395 -94
- package/src/prover/ptl/decide.ts +95 -50
- package/src/prover/ptl/encode.ts +2 -3
- package/src/prover/ptl/tableau.ts +28 -2
- package/src/prover/smt/arithmetic.ts +310 -0
- package/src/prover/smt/axioms.ts +12 -8
- package/src/prover/smt/context.ts +43 -8
- package/src/prover/smt/data.ts +498 -379
- package/src/prover/smt/encode.ts +148 -57
- package/src/prover/smt/extensionality.ts +5 -3
- package/src/prover/smt/flatten.ts +4 -6
- package/src/prover/smt/format.ts +28 -4
- package/src/prover/smt/instances.ts +7 -1
- package/src/prover/smt/layout.ts +91 -0
- package/src/prover/smt/rewrite.ts +1021 -618
- package/src/prover/smt/simplify.ts +441 -0
- package/src/prover/smt/solver/ackermannize-bv-tactic.ts +61 -0
- package/src/prover/smt/solver/ackr-helper.ts +179 -0
- package/src/prover/smt/solver/ackr-model-converter.ts +105 -0
- package/src/prover/smt/solver/act-cache.ts +0 -1
- package/src/prover/smt/solver/add-bounds-tactic.ts +59 -0
- package/src/prover/smt/solver/aig-tactic.ts +52 -0
- package/src/prover/smt/solver/aig.ts +889 -0
- package/src/prover/smt/solver/arith-rewriter.ts +613 -6
- package/src/prover/smt/solver/arith-terms.ts +121 -0
- package/src/prover/smt/solver/array-decl-plugin.ts +175 -0
- package/src/prover/smt/solver/array-rewriter.ts +309 -0
- package/src/prover/smt/solver/asserted-formulas.ts +87 -16
- package/src/prover/smt/solver/ast-lt.ts +166 -12
- package/src/prover/smt/solver/ast-util.ts +160 -2
- package/src/prover/smt/solver/ast.ts +1427 -41
- package/src/prover/smt/solver/auf-solver.ts +2 -6
- package/src/prover/smt/solver/bit-blast-tactic.ts +582 -0
- package/src/prover/smt/solver/bit-blaster.ts +871 -0
- package/src/prover/smt/solver/bound-manager.ts +196 -0
- package/src/prover/smt/solver/bound-simplifier.ts +600 -0
- package/src/prover/smt/solver/bv-bound-chk.ts +492 -0
- package/src/prover/smt/solver/bv-decl-plugin.ts +338 -0
- package/src/prover/smt/solver/bv-divrem-bounds.ts +95 -0
- package/src/prover/smt/solver/bv-rewriter.ts +1901 -0
- package/src/prover/smt/solver/bv1-blast.ts +214 -0
- package/src/prover/smt/solver/bv2fpa-converter.ts +174 -0
- package/src/prover/smt/solver/bv2int-rewriter.ts +544 -0
- package/src/prover/smt/solver/bv2real-rewriter.ts +533 -0
- package/src/prover/smt/solver/card2bv.ts +110 -0
- package/src/prover/smt/solver/case-split-queue.ts +0 -2
- package/src/prover/smt/solver/cg-table.ts +39 -25
- package/src/prover/smt/solver/check-logic.ts +330 -0
- package/src/prover/smt/solver/clause.ts +0 -1
- package/src/prover/smt/solver/cofactor-elim-term-ite.ts +278 -0
- package/src/prover/smt/solver/conflict-resolution.ts +78 -2
- package/src/prover/smt/solver/context.ts +516 -115
- package/src/prover/smt/solver/ctx-simplify.ts +20 -10
- package/src/prover/smt/solver/ctx-solver-simplify.ts +122 -0
- package/src/prover/smt/solver/datatype-decl-plugin.ts +572 -0
- package/src/prover/smt/solver/datatype-rewriter.ts +82 -0
- package/src/prover/smt/solver/demodulator.ts +786 -0
- package/src/prover/smt/solver/dependent-expr-state.ts +81 -0
- package/src/prover/smt/solver/der.ts +38 -10
- package/src/prover/smt/solver/diff-neq.ts +206 -0
- package/src/prover/smt/solver/distribute-forall.ts +57 -0
- package/src/prover/smt/solver/dom-simplify.ts +511 -0
- package/src/prover/smt/solver/dt2bv-tactic.ts +260 -0
- package/src/prover/smt/solver/dyn-ack.ts +0 -1
- package/src/prover/smt/solver/e-matching.ts +7 -8
- package/src/prover/smt/solver/elim-small-bv-tactic.ts +129 -0
- package/src/prover/smt/solver/elim-uncnstr.ts +545 -0
- package/src/prover/smt/solver/enode.ts +100 -3
- package/src/prover/smt/solver/eq2bv-tactic.ts +218 -0
- package/src/prover/smt/solver/euf/arith-axioms.ts +403 -0
- package/src/prover/smt/solver/euf/arith-internalize.ts +653 -0
- package/src/prover/smt/solver/euf/arith-solver.ts +889 -0
- package/src/prover/smt/solver/euf/array-axioms.ts +527 -0
- package/src/prover/smt/solver/euf/array-internalize.ts +428 -0
- package/src/prover/smt/solver/euf/array-solver.ts +306 -0
- package/src/prover/smt/solver/euf/bv-ackerman.ts +162 -0
- package/src/prover/smt/solver/euf/bv-internalize.ts +748 -0
- package/src/prover/smt/solver/euf/bv-solver.ts +449 -0
- package/src/prover/smt/solver/euf/dt-solver.ts +618 -0
- package/src/prover/smt/solver/euf/egraph.ts +907 -0
- package/src/prover/smt/solver/euf/euf-solver.ts +1205 -0
- package/src/prover/smt/solver/euf/fpa-solver.ts +317 -0
- package/src/prover/smt/solver/euf/mam.ts +1050 -0
- package/src/prover/smt/solver/euf/q-ematch.ts +830 -0
- package/src/prover/smt/solver/euf/q-mbi.ts +587 -0
- package/src/prover/smt/solver/euf/q-model-fixer.ts +296 -0
- package/src/prover/smt/solver/euf/q-solver.ts +361 -0
- package/src/prover/smt/solver/euf/th-solver.ts +335 -0
- package/src/prover/smt/solver/euf/th-solvers.ts +30 -0
- package/src/prover/smt/solver/expr-ref.ts +0 -1
- package/src/prover/smt/solver/expr-safe-replace.ts +26 -2
- package/src/prover/smt/solver/expr2polynomial.ts +146 -0
- package/src/prover/smt/solver/factor.ts +141 -0
- package/src/prover/smt/solver/fd-solver.ts +265 -0
- package/src/prover/smt/solver/fingerprints.ts +15 -15
- package/src/prover/smt/solver/fix-dl-var.ts +148 -0
- package/src/prover/smt/solver/flat-literals.ts +0 -1
- package/src/prover/smt/solver/fm-tactic.ts +884 -0
- package/src/prover/smt/solver/fpa-decl-plugin.ts +618 -0
- package/src/prover/smt/solver/fpa-rewriter.ts +640 -0
- package/src/prover/smt/solver/fpa2bv-converter.ts +2249 -0
- package/src/prover/smt/solver/fpa2bv-rewriter.ts +348 -0
- package/src/prover/smt/solver/fpa2bv-tactic.ts +73 -0
- package/src/prover/smt/solver/goal.ts +175 -15
- package/src/prover/smt/solver/goal2nlsat.ts +189 -0
- package/src/prover/smt/solver/guard-set.ts +219 -0
- package/src/prover/smt/solver/hash.ts +0 -1
- package/src/prover/smt/solver/hashtable.ts +30 -16
- package/src/prover/smt/solver/inf-eps.ts +63 -0
- package/src/prover/smt/solver/inj-axiom.ts +101 -0
- package/src/prover/smt/solver/internalizer.ts +110 -38
- package/src/prover/smt/solver/lackr.ts +381 -0
- package/src/prover/smt/solver/lbool.ts +0 -1
- package/src/prover/smt/solver/lia2card.ts +268 -0
- package/src/prover/smt/solver/lia2pb.ts +154 -0
- package/src/prover/smt/solver/literal.ts +0 -1
- package/src/prover/smt/solver/logic-tactics.ts +345 -0
- package/src/prover/smt/solver/lp/bound-propagator.ts +0 -1
- package/src/prover/smt/solver/lp/constraints.ts +0 -1
- package/src/prover/smt/solver/lp/containers.ts +0 -1
- package/src/prover/smt/solver/lp/core-solver.ts +18 -3
- package/src/prover/smt/solver/lp/cross-nested.ts +0 -1
- package/src/prover/smt/solver/lp/dep-intervals.ts +0 -3
- package/src/prover/smt/solver/lp/dependency.ts +0 -2
- package/src/prover/smt/solver/lp/dioph-eq.ts +1 -10
- package/src/prover/smt/solver/lp/explanation.ts +0 -1
- package/src/prover/smt/solver/lp/gomory.ts +0 -1
- package/src/prover/smt/solver/lp/hnf-cutter.ts +1 -2
- package/src/prover/smt/solver/lp/hnf.ts +0 -3
- package/src/prover/smt/solver/lp/int-cube.ts +3 -4
- package/src/prover/smt/solver/lp/int-solver.ts +0 -2
- package/src/prover/smt/solver/lp/lar-solver.ts +40 -4
- package/src/prover/smt/solver/lp/lar-term.ts +0 -1
- package/src/prover/smt/solver/lp/lp-settings.ts +0 -1
- package/src/prover/smt/solver/lp/maximize-term.ts +59 -10
- package/src/prover/smt/solver/lp/nex-creator.ts +0 -1
- package/src/prover/smt/solver/lp/nex.ts +0 -1
- package/src/prover/smt/solver/lp/nla-backoff.ts +0 -2
- package/src/prover/smt/solver/lp/nla-basics.ts +0 -2
- package/src/prover/smt/solver/lp/nla-core.ts +42 -11
- package/src/prover/smt/solver/lp/nla-divisions.ts +0 -2
- package/src/prover/smt/solver/lp/nla-emonics.ts +0 -1
- package/src/prover/smt/solver/lp/nla-factorization.ts +0 -1
- package/src/prover/smt/solver/lp/nla-grobner.ts +9 -4
- package/src/prover/smt/solver/lp/nla-horner.ts +0 -2
- package/src/prover/smt/solver/lp/nla-intervals.ts +0 -1
- package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +0 -2
- package/src/prover/smt/solver/lp/nla-monotone.ts +0 -1
- package/src/prover/smt/solver/lp/nla-order.ts +0 -2
- package/src/prover/smt/solver/lp/nla-patcher.ts +0 -1
- package/src/prover/smt/solver/lp/nla-powers.ts +220 -0
- package/src/prover/smt/solver/lp/nla-tangents.ts +0 -2
- package/src/prover/smt/solver/lp/nla-throttle.ts +0 -1
- package/src/prover/smt/solver/lp/nla-transcendentals.ts +324 -0
- package/src/prover/smt/solver/lp/nla-types.ts +0 -2
- package/src/prover/smt/solver/lp/nla-var-eqs.ts +0 -1
- package/src/prover/smt/solver/lp/nra-solver.ts +25 -4
- package/src/prover/smt/solver/lp/numeric-pair.ts +0 -1
- package/src/prover/smt/solver/lp/pdd-interval.ts +0 -1
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +0 -1
- package/src/prover/smt/solver/lp/pdd-solver.ts +0 -2
- package/src/prover/smt/solver/lp/pdd.ts +2 -2
- package/src/prover/smt/solver/lp/random-updater.ts +0 -2
- package/src/prover/smt/solver/lp/static-matrix.ts +0 -1
- package/src/prover/smt/solver/lp/union-find.ts +7 -2
- package/src/prover/smt/solver/macro-finder.ts +530 -0
- package/src/prover/smt/solver/mam-compiler.ts +122 -90
- package/src/prover/smt/solver/mam-interpreter.ts +0 -1
- package/src/prover/smt/solver/max-bv-sharing-tactic.ts +17 -0
- package/src/prover/smt/solver/max-cliques.ts +105 -0
- package/src/prover/smt/solver/maxcore.ts +309 -0
- package/src/prover/smt/solver/maximize-ac-sharing.ts +8 -6
- package/src/prover/smt/solver/maxlex.ts +115 -0
- package/src/prover/smt/solver/maxsmt-base.ts +105 -0
- package/src/prover/smt/solver/maxsmt.ts +92 -0
- package/src/prover/smt/solver/mbp/mbp-arith.ts +467 -0
- package/src/prover/smt/solver/mbp/mbp-basic-tg.ts +101 -0
- package/src/prover/smt/solver/mbp/mbp-plugin.ts +287 -0
- package/src/prover/smt/solver/mbp/mbp-qel.ts +48 -0
- package/src/prover/smt/solver/mbp/mbp-solve-plugin.ts +271 -0
- package/src/prover/smt/solver/mbp/mbp-term-graph.ts +606 -0
- package/src/prover/smt/solver/model-based-opt.ts +844 -0
- package/src/prover/smt/solver/model-checker.ts +18 -27
- package/src/prover/smt/solver/model-evaluator.ts +188 -12
- package/src/prover/smt/solver/model-finder.ts +12 -18
- package/src/prover/smt/solver/model-generator.ts +56 -29
- package/src/prover/smt/solver/model-macro-solver.ts +49 -46
- package/src/prover/smt/solver/model-printer.ts +214 -0
- package/src/prover/smt/solver/mpf.ts +711 -0
- package/src/prover/smt/solver/mus.ts +51 -0
- package/src/prover/smt/solver/muz/dl-context.ts +404 -0
- package/src/prover/smt/solver/muz/dl-mk-bit-blast.ts +97 -0
- package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +167 -0
- package/src/prover/smt/solver/muz/dl-mk-elim-term-ite.ts +125 -0
- package/src/prover/smt/solver/muz/dl-mk-interp-tail-simplifier.ts +299 -0
- package/src/prover/smt/solver/muz/dl-mk-rule-inliner.ts +455 -0
- package/src/prover/smt/solver/muz/dl-mk-slice.ts +340 -0
- package/src/prover/smt/solver/muz/dl-mk-subsumption-checker.ts +163 -0
- package/src/prover/smt/solver/muz/dl-rule-set.ts +273 -0
- package/src/prover/smt/solver/muz/dl-rule-transformer.ts +123 -0
- package/src/prover/smt/solver/muz/dl-rule.ts +496 -0
- package/src/prover/smt/solver/muz/hnf.ts +201 -0
- package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +176 -0
- package/src/prover/smt/solver/muz/horn-tactic.ts +201 -0
- package/src/prover/smt/solver/muz/rule-properties.ts +337 -0
- package/src/prover/smt/solver/muz/spacer-context.ts +1406 -0
- package/src/prover/smt/solver/muz/spacer-dl-interface.ts +52 -0
- package/src/prover/smt/solver/muz/spacer-generalizers.ts +241 -0
- package/src/prover/smt/solver/muz/spacer-manager.ts +127 -0
- package/src/prover/smt/solver/muz/spacer-pdr.ts +218 -0
- package/src/prover/smt/solver/muz/spacer-prop-solver.ts +333 -0
- package/src/prover/smt/solver/muz/spacer-util.ts +282 -0
- package/src/prover/smt/solver/muz/substitution.ts +203 -0
- package/src/prover/smt/solver/nla2bv-tactic.ts +285 -0
- package/src/prover/smt/solver/nlqsat.ts +484 -0
- package/src/prover/smt/solver/nlsat/algebraic.ts +125 -12
- package/src/prover/smt/solver/nlsat/atoms.ts +20 -6
- package/src/prover/smt/solver/nlsat/evaluator.ts +0 -1
- package/src/prover/smt/solver/nlsat/explain.ts +63 -23
- package/src/prover/smt/solver/nlsat/interval-set.ts +1 -2
- package/src/prover/smt/solver/nlsat/levelwise.ts +3 -9
- package/src/prover/smt/solver/nlsat/mpbq.ts +45 -1
- package/src/prover/smt/solver/nlsat/polynomial.ts +13 -6
- package/src/prover/smt/solver/nlsat/solver.ts +234 -36
- package/src/prover/smt/solver/nlsat/transcendental-eval.ts +310 -0
- package/src/prover/smt/solver/nlsat/transcendentals.ts +367 -0
- package/src/prover/smt/solver/nlsat/types.ts +0 -2
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -4
- package/src/prover/smt/solver/nlsat/upolynomial.ts +0 -2
- package/src/prover/smt/solver/nlsat-tactic.ts +82 -0
- package/src/prover/smt/solver/nnf.ts +105 -23
- package/src/prover/smt/solver/normalize-bounds.ts +53 -0
- package/src/prover/smt/solver/occf.ts +97 -0
- package/src/prover/smt/solver/opt-context.ts +787 -0
- package/src/prover/smt/solver/opt-nlsat.ts +375 -0
- package/src/prover/smt/solver/opt-pareto.ts +282 -0
- package/src/prover/smt/solver/opt-preprocess.ts +101 -0
- package/src/prover/smt/solver/opt-solver.ts +308 -0
- package/src/prover/smt/solver/opt-value.ts +55 -0
- package/src/prover/smt/solver/optsmt.ts +692 -0
- package/src/prover/smt/solver/parallel-tactic.ts +299 -0
- package/src/prover/smt/solver/pattern-inference.ts +19 -11
- package/src/prover/smt/solver/pb-rewriter.ts +284 -0
- package/src/prover/smt/solver/pb2bv-tactic.ts +540 -0
- package/src/prover/smt/solver/poly-rewriter.ts +202 -57
- package/src/prover/smt/solver/probes.ts +512 -0
- package/src/prover/smt/solver/propagate-values.ts +37 -21
- package/src/prover/smt/solver/proto-model.ts +648 -19
- package/src/prover/smt/solver/pull-quant.ts +28 -12
- package/src/prover/smt/solver/purify-arith.ts +632 -0
- package/src/prover/smt/solver/qe-arith-plugin.ts +1098 -0
- package/src/prover/smt/solver/qe-lite-der.ts +2 -3
- package/src/prover/smt/solver/qe-lite-fm.ts +3 -4
- package/src/prover/smt/solver/qe-lite.ts +37 -17
- package/src/prover/smt/solver/qe-mbp.ts +270 -0
- package/src/prover/smt/solver/qe.ts +1498 -0
- package/src/prover/smt/solver/qel.ts +25 -0
- package/src/prover/smt/solver/qi-queue.ts +0 -1
- package/src/prover/smt/solver/qsat.ts +814 -0
- package/src/prover/smt/solver/quant-hoist.ts +196 -0
- package/src/prover/smt/solver/quant-tactics.ts +16 -56
- package/src/prover/smt/solver/quantifier-analyzer.ts +19 -20
- package/src/prover/smt/solver/quantifier-manager.ts +8 -16
- package/src/prover/smt/solver/quasi-macros.ts +243 -0
- package/src/prover/smt/solver/random-gen.ts +0 -1
- package/src/prover/smt/solver/rational.ts +45 -1
- package/src/prover/smt/solver/recfun-decl-plugin.ts +261 -0
- package/src/prover/smt/solver/recfun-rewriter.ts +107 -0
- package/src/prover/smt/solver/reduce-args.ts +225 -0
- package/src/prover/smt/solver/reduce-bv-size.ts +119 -0
- package/src/prover/smt/solver/ref-vector.ts +0 -1
- package/src/prover/smt/solver/relevancy.ts +1 -2
- package/src/prover/smt/solver/rewriter-tpl.ts +77 -10
- package/src/prover/smt/solver/rewriter.ts +475 -36
- package/src/prover/smt/solver/rlimit.ts +25 -2
- package/src/prover/smt/solver/sat/asymm-branch.ts +325 -0
- package/src/prover/smt/solver/sat/big.ts +177 -0
- package/src/prover/smt/solver/sat/clause-use-list.ts +71 -0
- package/src/prover/smt/solver/sat/clause.ts +203 -0
- package/src/prover/smt/solver/sat/cleaner.ts +94 -0
- package/src/prover/smt/solver/sat/config.ts +122 -0
- package/src/prover/smt/solver/sat/consequences.ts +203 -0
- package/src/prover/smt/solver/sat/elim-eqs.ts +142 -0
- package/src/prover/smt/solver/sat/goal2sat.ts +526 -0
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +378 -0
- package/src/prover/smt/solver/sat/model-converter.ts +136 -0
- package/src/prover/smt/solver/sat/pb-constraint.ts +261 -0
- package/src/prover/smt/solver/sat/pb-solver.ts +1577 -0
- package/src/prover/smt/solver/sat/probing.ts +170 -0
- package/src/prover/smt/solver/sat/sat-tactic.ts +43 -0
- package/src/prover/smt/solver/sat/sat2goal.ts +165 -0
- package/src/prover/smt/solver/sat/scc.ts +142 -0
- package/src/prover/smt/solver/sat/simplifier.ts +1618 -0
- package/src/prover/smt/solver/sat/solver.ts +2127 -0
- package/src/prover/smt/solver/sat/var-queue.ts +117 -0
- package/src/prover/smt/solver/sat/watch-list.ts +140 -0
- package/src/prover/smt/solver/search-tree.ts +284 -0
- package/src/prover/smt/solver/seq-axioms.ts +1010 -0
- package/src/prover/smt/solver/seq-decl-plugin.ts +819 -0
- package/src/prover/smt/solver/seq-derive.ts +1301 -0
- package/src/prover/smt/solver/seq-eq-approx.ts +236 -0
- package/src/prover/smt/solver/seq-eq-solver.ts +439 -0
- package/src/prover/smt/solver/seq-factory.ts +89 -0
- package/src/prover/smt/solver/seq-monadic.ts +728 -0
- package/src/prover/smt/solver/seq-range-predicate.ts +235 -0
- package/src/prover/smt/solver/seq-re-rewriter.ts +1170 -0
- package/src/prover/smt/solver/seq-re-util.ts +758 -0
- package/src/prover/smt/solver/seq-regex-bisim.ts +144 -0
- package/src/prover/smt/solver/seq-regex-live.ts +200 -0
- package/src/prover/smt/solver/seq-rewriter.ts +2402 -0
- package/src/prover/smt/solver/seq-skolem.ts +317 -0
- package/src/prover/smt/solver/seq-subset.ts +165 -0
- package/src/prover/smt/solver/seq-view-witness.ts +353 -0
- package/src/prover/smt/solver/smt-consequences.ts +297 -0
- package/src/prover/smt/solver/smt-kernel.ts +83 -0
- package/src/prover/smt/solver/smt-logics.ts +66 -0
- package/src/prover/smt/solver/smt-setup.ts +496 -0
- package/src/prover/smt/solver/smt2-printer.ts +765 -0
- package/src/prover/smt/solver/smtlib-parser.ts +3126 -316
- package/src/prover/smt/solver/smtlib-script.ts +1631 -0
- package/src/prover/smt/solver/solve-eqs.ts +929 -0
- package/src/prover/smt/solver/solver.ts +113 -22
- package/src/prover/smt/solver/static-features.ts +314 -0
- package/src/prover/smt/solver/sticky-generations.ts +0 -1
- package/src/prover/smt/solver/tactic.ts +1986 -0
- package/src/prover/smt/solver/term-enumeration.ts +205 -0
- package/src/prover/smt/solver/theory-array.ts +1240 -0
- package/src/prover/smt/solver/theory-bv.ts +1200 -0
- package/src/prover/smt/solver/theory-char.ts +355 -0
- package/src/prover/smt/solver/theory-datatype.ts +598 -0
- package/src/prover/smt/solver/theory-finite-set.ts +30 -0
- package/src/prover/smt/solver/theory-fpa.ts +389 -0
- package/src/prover/smt/solver/theory-lra-axioms.ts +53 -2
- package/src/prover/smt/solver/theory-lra-bounds.ts +31 -6
- package/src/prover/smt/solver/theory-lra-final-check.ts +56 -70
- package/src/prover/smt/solver/theory-lra-internalize.ts +86 -27
- package/src/prover/smt/solver/theory-lra-model.ts +20 -35
- package/src/prover/smt/solver/theory-lra-propagate.ts +24 -26
- package/src/prover/smt/solver/theory-lra-state.ts +6 -22
- package/src/prover/smt/solver/theory-lra.ts +188 -1
- package/src/prover/smt/solver/theory-pb.ts +934 -0
- package/src/prover/smt/solver/theory-polymorphism.ts +58 -0
- package/src/prover/smt/solver/theory-recfun.ts +307 -0
- package/src/prover/smt/solver/theory-seq-regex.ts +867 -0
- package/src/prover/smt/solver/theory-seq-solve.ts +1373 -0
- package/src/prover/smt/solver/theory-seq-state.ts +871 -0
- package/src/prover/smt/solver/theory-seq.ts +961 -0
- package/src/prover/smt/solver/theory.ts +189 -0
- package/src/prover/smt/solver/tseitin-cnf.ts +485 -0
- package/src/prover/smt/solver/var-subst.ts +36 -14
- package/src/prover/smt/table.ts +3 -2
- package/src/prover/smt/types.ts +146 -0
- package/src/prover/tlapm/cache.ts +50 -19
- package/src/prover/tlapm/tlapm.ts +15 -9
- package/src/prover/tlapm-library.ts +3208 -0
- package/src/prover/verdict.ts +9 -0
- package/src/prover/zenon/check/check.ts +1 -2
- package/src/prover/zenon/check/records.ts +1 -1
- package/src/prover/zenon/check/relations.ts +2 -1
- package/src/prover/zenon/check/rewrites.ts +2 -15
- package/src/prover/zenon/check/sets.ts +40 -58
- package/src/prover/zenon/check/terms.ts +1 -2
- package/src/prover/zenon/decide.ts +10 -7
- package/src/prover/zenon/encode.ts +0 -2
- package/src/prover/zenon/eqrel.ts +2 -2
- package/src/prover/zenon/equality-rules.ts +0 -2
- package/src/prover/zenon/expr.ts +7 -2
- package/src/prover/zenon/index-table.ts +9 -21
- package/src/prover/zenon/isar-case.ts +0 -2
- package/src/prover/zenon/isar.ts +35 -37
- package/src/prover/zenon/llproof.ts +2 -13
- package/src/prover/zenon/mltoll.ts +12 -30
- package/src/prover/zenon/node.ts +20 -5
- package/src/prover/zenon/parse.ts +9 -8
- package/src/prover/zenon/phrase.ts +0 -2
- package/src/prover/zenon/proof.ts +0 -2
- package/src/prover/zenon/propositional-rules.ts +0 -2
- package/src/prover/zenon/rules.ts +0 -2
- package/src/prover/zenon/search.ts +11 -19
- package/src/prover/zenon/tla/functions.ts +2 -4
- package/src/prover/zenon/tla/llproof.ts +9 -13
- package/src/prover/zenon/tla/records.ts +1 -8
- package/src/prover/zenon/tla/rewrites.ts +0 -2
- package/src/prover/zenon/tla/sets.ts +22 -22
- package/src/prover/zenon/tla/terms.ts +0 -2
- package/src/prover/zenon/tla/tla.ts +7 -8
- package/src/resolve.ts +55 -72
- package/src/sany/generation.ts +394 -0
- package/src/sany/generator-def-entries.ts +210 -0
- package/src/sany/generator-definitions.ts +686 -0
- package/src/sany/generator-expressions.ts +1100 -0
- package/src/sany/generator-proofs.ts +662 -0
- package/src/sany/generator.ts +155 -2625
- package/src/sany/levels.ts +0 -2
- package/src/sany/lexer.ts +17 -16
- package/src/sany/linter.ts +0 -2
- package/src/sany/nodes.ts +6 -13
- package/src/sany/report.ts +3 -6
- package/src/sany/selectors.ts +35 -38
- package/src/sany/xml.ts +23 -55
- package/src/search.ts +196 -43
- package/src/simulate.ts +157 -133
- package/src/spec-description.ts +33 -48
- package/src/standard-modules.ts +16 -32
- package/src/state-graph.ts +2 -9
- package/src/substitution-levels.ts +5 -4
- package/src/successors.ts +6 -8
- package/src/symmetry.ts +2 -2
- package/src/tableau.ts +2 -2
- package/src/tlc/fingerprint.ts +81 -9
- package/src/tlc/messages.ts +20 -15
- package/src/tlc/order.ts +2 -9
- package/src/tlc/random.ts +4 -4
- package/src/tlc/replay.ts +8 -15
- package/src/tlc/summary.ts +29 -14
- package/src/tlc/tlc-operators.ts +2 -3
- package/src/tlc/trace-spec.ts +25 -45
- package/src/typed-tier.ts +6535 -0
- package/src/typescript/actions.ts +2 -4
- package/src/typescript/collections.ts +34 -20
- package/src/typescript/compile.ts +1 -3
- package/src/typescript/formula.ts +5 -3
- package/src/typescript/model.ts +4 -5
- package/src/typescript/steps.ts +20 -18
- package/src/values.ts +63 -158
- package/src/prover/isabelle/isar/statement.ts +0 -52
- package/src/prover/smt/solver/z3-license.txt +0 -10
- package/src/prover/tlaps-module.ts +0 -510
- package/src/prover/zenon/LICENSE +0 -32
|
@@ -0,0 +1,3208 @@
|
|
|
1
|
+
// tlapm's standard library, verbatim from lib/tlapm/stdlib, so that proofs citing it load without
|
|
2
|
+
// tlapm installed. Folds, Functions and FunctionTheorems come from the CommunityModules that tlapm
|
|
3
|
+
// installs there. tlapm's license follows, then CommunityModules'.
|
|
4
|
+
//
|
|
5
|
+
// Copyright (c) 2008 INRIA and Microsoft Corporation
|
|
6
|
+
// Copyright (c) 2023 Linux Foundation
|
|
7
|
+
//
|
|
8
|
+
// Redistribution and use in source and binary forms, with or without
|
|
9
|
+
// modification, are permitted provided that the following conditions are
|
|
10
|
+
// met:
|
|
11
|
+
//
|
|
12
|
+
// * Redistributions of source code must retain the above copyright
|
|
13
|
+
// notice, this list of conditions and the following disclaimer.
|
|
14
|
+
//
|
|
15
|
+
// * Redistributions in binary form must reproduce the above copyright
|
|
16
|
+
// notice, this list of conditions and the following disclaimer in
|
|
17
|
+
// the documentation and/or other materials provided with the
|
|
18
|
+
// distribution.
|
|
19
|
+
//
|
|
20
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
21
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
22
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
23
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
24
|
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
25
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
26
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
27
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
28
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
29
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
30
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
31
|
+
//
|
|
32
|
+
// MIT License
|
|
33
|
+
//
|
|
34
|
+
// Copyright (c) 2019 TLA+
|
|
35
|
+
//
|
|
36
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
37
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
38
|
+
// in the Software without restriction, including without limitation the rights
|
|
39
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
40
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
41
|
+
// furnished to do so, subject to the following conditions:
|
|
42
|
+
//
|
|
43
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
44
|
+
// copies or substantial portions of the Software.
|
|
45
|
+
//
|
|
46
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
47
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
48
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
49
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
50
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
51
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
52
|
+
// SOFTWARE.
|
|
53
|
+
export const TLAPM_LIBRARY = new Map([
|
|
54
|
+
[
|
|
55
|
+
"TLAPS",
|
|
56
|
+
`------------------------------- MODULE TLAPS --------------------------------
|
|
57
|
+
|
|
58
|
+
(* Backend pragmas. *)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
(***************************************************************************)
|
|
62
|
+
(* Each of these pragmas can be cited with a BY or a USE. The pragma that *)
|
|
63
|
+
(* is added to the context of an obligation most recently is the one whose *)
|
|
64
|
+
(* effects are triggered. *)
|
|
65
|
+
(***************************************************************************)
|
|
66
|
+
|
|
67
|
+
(***************************************************************************)
|
|
68
|
+
(* The following pragmas should be used only as a last resource. They are *)
|
|
69
|
+
(* dependent upon the particular backend provers, and are unlikely to have *)
|
|
70
|
+
(* any effect if the set of backend provers changes. Moreover, they are *)
|
|
71
|
+
(* meaningless to a reader of the proof. *)
|
|
72
|
+
(***************************************************************************)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
(**************************************************************************)
|
|
76
|
+
(* Backend pragma: use the SMT solver for arithmetic. *)
|
|
77
|
+
(* *)
|
|
78
|
+
(* This method exists under this name for historical reasons. *)
|
|
79
|
+
(**************************************************************************)
|
|
80
|
+
|
|
81
|
+
SimpleArithmetic == TRUE (*{ by (prover:"smt3") }*)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
(**************************************************************************)
|
|
85
|
+
(* Backend pragma: SMT solver *)
|
|
86
|
+
(* *)
|
|
87
|
+
(* This method translates the proof obligation to SMTLIB2. The supported *)
|
|
88
|
+
(* fragment includes first-order logic, set theory, functions and *)
|
|
89
|
+
(* records. *)
|
|
90
|
+
(* SMT calls the smt-solver with the default timeout of 5 seconds *)
|
|
91
|
+
(* while SMTT(n) calls the smt-solver with a timeout of n seconds. *)
|
|
92
|
+
(* *)
|
|
93
|
+
(* SMTT also accepts a string argument of the form "rN" to bound the *)
|
|
94
|
+
(* underlying Z3 solver by a deterministic \`rlimit\` budget instead of a *)
|
|
95
|
+
(* wall-clock timeout, e.g. SMTT("r5"). N is a multiple of a fixed base *)
|
|
96
|
+
(* resource count, so a small readable budget like "r5" is meaningful. *)
|
|
97
|
+
(* Unlike a wall-clock timeout, an \`rlimit\` budget does not depend on CPU *)
|
|
98
|
+
(* speed or load, so the proof's pass/fail outcome reproduces on any *)
|
|
99
|
+
(* machine and every rerun (for a fixed Z3 build); how long it takes to *)
|
|
100
|
+
(* consume the budget still varies by machine. This is Z3-specific. *)
|
|
101
|
+
(**************************************************************************)
|
|
102
|
+
|
|
103
|
+
SMT == TRUE (*{ by (prover:"smt3") }*)
|
|
104
|
+
SMTT(X) == TRUE (*{ by (prover:"smt3"; timeout:@) }*)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
(**************************************************************************)
|
|
108
|
+
(* Backend pragma: CVC4 SMT solver *)
|
|
109
|
+
(* *)
|
|
110
|
+
(* These methods translate the proof obligation to SMTLIB2 and call CVC4. *)
|
|
111
|
+
(**************************************************************************)
|
|
112
|
+
|
|
113
|
+
(* The CVC3* methods are here for backward compatibility. They call CVC4. *)
|
|
114
|
+
CVC3 == TRUE (*{ by (prover: "cvc33") }*)
|
|
115
|
+
CVC3T(X) == TRUE (*{ by (prover:"cvc33"; timeout:@) }*)
|
|
116
|
+
|
|
117
|
+
CVC4 == TRUE (*{ by (prover: "cvc33") }*)
|
|
118
|
+
CVC4T(X) == TRUE (*{ by (prover:"cvc33"; timeout:@) }*)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
(**************************************************************************)
|
|
122
|
+
(* Backend pragma: Yices SMT solver *)
|
|
123
|
+
(* *)
|
|
124
|
+
(* This method translates the proof obligation to Yices native language. *)
|
|
125
|
+
(**************************************************************************)
|
|
126
|
+
|
|
127
|
+
Yices == TRUE (*{ by (prover: "yices3") }*)
|
|
128
|
+
YicesT(X) == TRUE (*{ by (prover:"yices3"; timeout:@) }*)
|
|
129
|
+
|
|
130
|
+
(**************************************************************************)
|
|
131
|
+
(* Backend pragma: veriT SMT solver *)
|
|
132
|
+
(* *)
|
|
133
|
+
(* This method translates the proof obligation to SMTLIB2 and calls veriT.*)
|
|
134
|
+
(**************************************************************************)
|
|
135
|
+
|
|
136
|
+
veriT == TRUE (*{ by (prover: "verit") }*)
|
|
137
|
+
veriTT(X) == TRUE (*{ by (prover:"verit"; timeout:@) }*)
|
|
138
|
+
|
|
139
|
+
(**************************************************************************)
|
|
140
|
+
(* Backend pragma: Zipperposition solver *)
|
|
141
|
+
(* *)
|
|
142
|
+
(* This method translates the proof obligation to TPTP and *)
|
|
143
|
+
(* calls Zipperposition. *)
|
|
144
|
+
(**************************************************************************)
|
|
145
|
+
|
|
146
|
+
Zipper == TRUE (*{ by (prover: "zipper") }*)
|
|
147
|
+
ZipperT(X) == TRUE (*{ by (prover:"zipper"; timeout:@) }*)
|
|
148
|
+
|
|
149
|
+
(**************************************************************************)
|
|
150
|
+
(* Backend pragma: Z3 SMT solver *)
|
|
151
|
+
(* *)
|
|
152
|
+
(* This method translates the proof obligation to SMTLIB2 and calls Z3. *)
|
|
153
|
+
(* Z3 is used by default but you can also explicitly call it. *)
|
|
154
|
+
(* Z3T(n) bounds Z3 by a wall-clock timeout of n seconds, while Z3T("rN") *)
|
|
155
|
+
(* bounds it by a deterministic \`rlimit\` budget of N base units, which *)
|
|
156
|
+
(* reproduces the same outcome on any machine (see SMTT). *)
|
|
157
|
+
(**************************************************************************)
|
|
158
|
+
|
|
159
|
+
Z3 == TRUE (*{ by (prover: "z33") }*)
|
|
160
|
+
Z3T(X) == TRUE (*{ by (prover:"z33"; timeout:@) }*)
|
|
161
|
+
|
|
162
|
+
(**************************************************************************)
|
|
163
|
+
(* Backend pragma: SPASS superposition prover *)
|
|
164
|
+
(* *)
|
|
165
|
+
(* This method translates the proof obligation to the DFG format language *)
|
|
166
|
+
(* supported by the ATP SPASS. The translation is based on the SMT one. *)
|
|
167
|
+
(**************************************************************************)
|
|
168
|
+
|
|
169
|
+
Spass == TRUE (*{ by (prover: "spass") }*)
|
|
170
|
+
SpassT(X) == TRUE (*{ by (prover:"spass"; timeout:@) }*)
|
|
171
|
+
|
|
172
|
+
(**************************************************************************)
|
|
173
|
+
(* Backend pragma: The PTL propositional linear time temporal logic *)
|
|
174
|
+
(* prover. It currently is the LS4 backend. *)
|
|
175
|
+
(* *)
|
|
176
|
+
(* This method translates the negetation of the proof obligation to *)
|
|
177
|
+
(* Seperated Normal Form (TRP++ format) and checks for unsatisfiability *)
|
|
178
|
+
(**************************************************************************)
|
|
179
|
+
|
|
180
|
+
LS4 == TRUE (*{ by (prover: "ls4") }*)
|
|
181
|
+
LS4T(X) == TRUE (*{ by (prover: "ls4"; timeout:@) }*)
|
|
182
|
+
PTL == TRUE (*{ by (prover: "ls4") }*)
|
|
183
|
+
|
|
184
|
+
(**************************************************************************)
|
|
185
|
+
(* Backend pragma: Zenon with different timeouts (default is 10 seconds) *)
|
|
186
|
+
(* *)
|
|
187
|
+
(**************************************************************************)
|
|
188
|
+
|
|
189
|
+
Zenon == TRUE (*{ by (prover:"zenon") }*)
|
|
190
|
+
ZenonT(X) == TRUE (*{ by (prover:"zenon"; timeout:@) }*)
|
|
191
|
+
|
|
192
|
+
(********************************************************************)
|
|
193
|
+
(* Backend pragma: Isabelle with different timeouts and tactics *)
|
|
194
|
+
(* (default is 30 seconds/auto) *)
|
|
195
|
+
(********************************************************************)
|
|
196
|
+
|
|
197
|
+
Isa == TRUE (*{ by (prover:"isabelle") }*)
|
|
198
|
+
IsaT(X) == TRUE (*{ by (prover:"isabelle"; timeout:@) }*)
|
|
199
|
+
IsaM(X) == TRUE (*{ by (prover:"isabelle"; tactic:@) }*)
|
|
200
|
+
IsaMT(X,Y) == TRUE (*{ by (prover:"isabelle"; tactic:@; timeout:@) }*)
|
|
201
|
+
|
|
202
|
+
(***************************************************************************)
|
|
203
|
+
(* The following theorem expresses the (useful implication of the) law of *)
|
|
204
|
+
(* set extensionality, which can be written as *)
|
|
205
|
+
(* *)
|
|
206
|
+
(* THEOREM \\A S, T : (S = T) <=> (\\A x : (x \\in S) <=> (x \\in T)) *)
|
|
207
|
+
(* *)
|
|
208
|
+
(* Theorem SetExtensionality is sometimes required by the SMT backend for *)
|
|
209
|
+
(* reasoning about sets. It is usually counterproductive to include *)
|
|
210
|
+
(* theorem SetExtensionality in a BY clause for the Zenon or Isabelle *)
|
|
211
|
+
(* backends. Instead, use the pragma IsaWithSetExtensionality to instruct *)
|
|
212
|
+
(* the Isabelle backend to use the rule of set extensionality. *)
|
|
213
|
+
(***************************************************************************)
|
|
214
|
+
IsaWithSetExtensionality == TRUE
|
|
215
|
+
(*{ by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")}*)
|
|
216
|
+
|
|
217
|
+
THEOREM SetExtensionality == \\A S,T : (\\A x : x \\in S <=> x \\in T) => S = T
|
|
218
|
+
OBVIOUS
|
|
219
|
+
|
|
220
|
+
(***************************************************************************)
|
|
221
|
+
(* The following theorem is needed to deduce NotInSetS \\notin SetS from *)
|
|
222
|
+
(* the definition *)
|
|
223
|
+
(* *)
|
|
224
|
+
(* NotInSetS == CHOOSE v : v \\notin SetS *)
|
|
225
|
+
(***************************************************************************)
|
|
226
|
+
THEOREM NoSetContainsEverything == \\A S : \\E x : x \\notin S
|
|
227
|
+
OBVIOUS (*{by (isabelle "(auto intro: inIrrefl)")}*)
|
|
228
|
+
-----------------------------------------------------------------------------
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
(********************************************************************)
|
|
233
|
+
(********************************************************************)
|
|
234
|
+
(********************************************************************)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
(********************************************************************)
|
|
238
|
+
(* Old versions of Zenon and Isabelle pragmas below *)
|
|
239
|
+
(* (kept for compatibility) *)
|
|
240
|
+
(********************************************************************)
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
(**************************************************************************)
|
|
244
|
+
(* Backend pragma: Zenon with different timeouts (default is 10 seconds) *)
|
|
245
|
+
(* *)
|
|
246
|
+
(**************************************************************************)
|
|
247
|
+
|
|
248
|
+
SlowZenon == TRUE (*{ by (prover:"zenon"; timeout:20) }*)
|
|
249
|
+
SlowerZenon == TRUE (*{ by (prover:"zenon"; timeout:40) }*)
|
|
250
|
+
VerySlowZenon == TRUE (*{ by (prover:"zenon"; timeout:80) }*)
|
|
251
|
+
SlowestZenon == TRUE (*{ by (prover:"zenon"; timeout:160) }*)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
(********************************************************************)
|
|
256
|
+
(* Backend pragma: Isabelle's automatic search ("auto") *)
|
|
257
|
+
(* *)
|
|
258
|
+
(* This pragma bypasses Zenon. It is useful in situations involving *)
|
|
259
|
+
(* essentially simplification and equational reasoning. *)
|
|
260
|
+
(* Default imeout for all isabelle tactics is 30 seconds. *)
|
|
261
|
+
(********************************************************************)
|
|
262
|
+
Auto == TRUE (*{ by (prover:"isabelle"; tactic:"auto") }*)
|
|
263
|
+
SlowAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:120) }*)
|
|
264
|
+
SlowerAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:480) }*)
|
|
265
|
+
SlowestAuto == TRUE (*{ by (prover:"isabelle"; tactic:"auto"; timeout:960) }*)
|
|
266
|
+
|
|
267
|
+
(********************************************************************)
|
|
268
|
+
(* Backend pragma: Isabelle's "force" tactic *)
|
|
269
|
+
(* *)
|
|
270
|
+
(* This pragma bypasses Zenon. It is useful in situations involving *)
|
|
271
|
+
(* quantifier reasoning. *)
|
|
272
|
+
(********************************************************************)
|
|
273
|
+
Force == TRUE (*{ by (prover:"isabelle"; tactic:"force") }*)
|
|
274
|
+
SlowForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:120) }*)
|
|
275
|
+
SlowerForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:480) }*)
|
|
276
|
+
SlowestForce == TRUE (*{ by (prover:"isabelle"; tactic:"force"; timeout:960) }*)
|
|
277
|
+
|
|
278
|
+
(***********************************************************************)
|
|
279
|
+
(* Backend pragma: Isabelle's "simplification" tactics *)
|
|
280
|
+
(* *)
|
|
281
|
+
(* These tactics simplify the goal before running one of the automated *)
|
|
282
|
+
(* tactics. They are often necessary for obligations involving record *)
|
|
283
|
+
(* or tuple projections. Use the SimplfyAndSolve tactic unless you're *)
|
|
284
|
+
(* sure you can get away with just Simplification *)
|
|
285
|
+
(***********************************************************************)
|
|
286
|
+
SimplifyAndSolve == TRUE
|
|
287
|
+
(*{ by (prover:"isabelle"; tactic:"clarsimp auto?") }*)
|
|
288
|
+
SlowSimplifyAndSolve == TRUE
|
|
289
|
+
(*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:120) }*)
|
|
290
|
+
SlowerSimplifyAndSolve == TRUE
|
|
291
|
+
(*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:480) }*)
|
|
292
|
+
SlowestSimplifyAndSolve == TRUE
|
|
293
|
+
(*{ by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:960) }*)
|
|
294
|
+
|
|
295
|
+
Simplification == TRUE (*{ by (prover:"isabelle"; tactic:"clarsimp") }*)
|
|
296
|
+
SlowSimplification == TRUE
|
|
297
|
+
(*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:120) }*)
|
|
298
|
+
SlowerSimplification == TRUE
|
|
299
|
+
(*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:480) }*)
|
|
300
|
+
SlowestSimplification == TRUE
|
|
301
|
+
(*{ by (prover:"isabelle"; tactic:"clarsimp"; timeout:960) }*)
|
|
302
|
+
|
|
303
|
+
(**************************************************************************)
|
|
304
|
+
(* Backend pragma: Isabelle's tableau prover ("blast") *)
|
|
305
|
+
(* *)
|
|
306
|
+
(* This pragma bypasses Zenon and uses Isabelle's built-in theorem *)
|
|
307
|
+
(* prover, Blast. It is almost never better than Zenon by itself, but *)
|
|
308
|
+
(* becomes very useful in combination with the Auto pragma above. The *)
|
|
309
|
+
(* AutoBlast pragma first attempts Auto and then uses Blast to prove what *)
|
|
310
|
+
(* Auto could not prove. (There is currently no way to use Zenon on the *)
|
|
311
|
+
(* results left over from Auto.) *)
|
|
312
|
+
(**************************************************************************)
|
|
313
|
+
Blast == TRUE (*{ by (prover:"isabelle"; tactic:"blast") }*)
|
|
314
|
+
SlowBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:120) }*)
|
|
315
|
+
SlowerBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:480) }*)
|
|
316
|
+
SlowestBlast == TRUE (*{ by (prover:"isabelle"; tactic:"blast"; timeout:960) }*)
|
|
317
|
+
|
|
318
|
+
AutoBlast == TRUE (*{ by (prover:"isabelle"; tactic:"auto, blast") }*)
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
(**************************************************************************)
|
|
322
|
+
(* Backend pragmas: multi-back-ends *)
|
|
323
|
+
(* *)
|
|
324
|
+
(* These pragmas just run a bunch of back-ends one after the other in the *)
|
|
325
|
+
(* hope that one will succeed. This saves time and effort for the user at *)
|
|
326
|
+
(* the expense of computation time. *)
|
|
327
|
+
(**************************************************************************)
|
|
328
|
+
|
|
329
|
+
(* CVC3 goes first because it's bundled with TLAPS, then the other SMT
|
|
330
|
+
solvers are unlikely to succeed if CVC3 fails, so we run zenon and
|
|
331
|
+
Isabelle before them. *)
|
|
332
|
+
AllProvers == TRUE (*{
|
|
333
|
+
by (prover:"cvc33")
|
|
334
|
+
by (prover:"zenon")
|
|
335
|
+
by (prover:"isabelle"; tactic:"auto")
|
|
336
|
+
by (prover:"spass")
|
|
337
|
+
by (prover:"smt3")
|
|
338
|
+
by (prover:"yices3")
|
|
339
|
+
by (prover:"verit")
|
|
340
|
+
by (prover:"z33")
|
|
341
|
+
by (prover:"isabelle"; tactic:"force")
|
|
342
|
+
by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")
|
|
343
|
+
by (prover:"isabelle"; tactic:"clarsimp auto?")
|
|
344
|
+
by (prover:"isabelle"; tactic:"clarsimp")
|
|
345
|
+
by (prover:"isabelle"; tactic:"auto, blast")
|
|
346
|
+
}*)
|
|
347
|
+
AllProversT(X) == TRUE (*{
|
|
348
|
+
by (prover:"cvc33"; timeout:@)
|
|
349
|
+
by (prover:"zenon"; timeout:@)
|
|
350
|
+
by (prover:"isabelle"; tactic:"auto"; timeout:@)
|
|
351
|
+
by (prover:"spass"; timeout:@)
|
|
352
|
+
by (prover:"smt3"; timeout:@)
|
|
353
|
+
by (prover:"yices3"; timeout:@)
|
|
354
|
+
by (prover:"verit"; timeout:@)
|
|
355
|
+
by (prover:"z33"; timeout:@)
|
|
356
|
+
by (prover:"isabelle"; tactic:"force"; timeout:@)
|
|
357
|
+
by (prover:"isabelle"; tactic:"(auto intro: setEqualI)"; timeout:@)
|
|
358
|
+
by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:@)
|
|
359
|
+
by (prover:"isabelle"; tactic:"clarsimp"; timeout:@)
|
|
360
|
+
by (prover:"isabelle"; tactic:"auto, blast"; timeout:@)
|
|
361
|
+
}*)
|
|
362
|
+
|
|
363
|
+
AllSMT == TRUE (*{
|
|
364
|
+
by (prover:"cvc33")
|
|
365
|
+
by (prover:"smt3")
|
|
366
|
+
by (prover:"yices3")
|
|
367
|
+
by (prover:"verit")
|
|
368
|
+
by (prover:"z33")
|
|
369
|
+
}*)
|
|
370
|
+
AllSMTT(X) == TRUE (*{
|
|
371
|
+
by (prover:"cvc33"; timeout:@)
|
|
372
|
+
by (prover:"smt3"; timeout:@)
|
|
373
|
+
by (prover:"yices3"; timeout:@)
|
|
374
|
+
by (prover:"verit"; timeout:@)
|
|
375
|
+
by (prover:"z33"; timeout:@)
|
|
376
|
+
}*)
|
|
377
|
+
|
|
378
|
+
AllIsa == TRUE (*{
|
|
379
|
+
by (prover:"isabelle"; tactic:"auto")
|
|
380
|
+
by (prover:"isabelle"; tactic:"force")
|
|
381
|
+
by (prover:"isabelle"; tactic:"(auto intro: setEqualI)")
|
|
382
|
+
by (prover:"isabelle"; tactic:"clarsimp auto?")
|
|
383
|
+
by (prover:"isabelle"; tactic:"clarsimp")
|
|
384
|
+
by (prover:"isabelle"; tactic:"auto, blast")
|
|
385
|
+
}*)
|
|
386
|
+
AllIsaT(X) == TRUE (*{
|
|
387
|
+
by (prover:"isabelle"; tactic:"auto"; timeout:@)
|
|
388
|
+
by (prover:"isabelle"; tactic:"force"; timeout:@)
|
|
389
|
+
by (prover:"isabelle"; tactic:"(auto intro: setEqualI)"; timeout:@)
|
|
390
|
+
by (prover:"isabelle"; tactic:"clarsimp auto?"; timeout:@)
|
|
391
|
+
by (prover:"isabelle"; tactic:"clarsimp"; timeout:@)
|
|
392
|
+
by (prover:"isabelle"; tactic:"auto, blast"; timeout:@)
|
|
393
|
+
}*)
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
(**************************************************************************)
|
|
397
|
+
(* The pragma ExpandEnabled invokes expansion of the operator ENABLED. *)
|
|
398
|
+
(* *)
|
|
399
|
+
(* The pragma ExpandCdot invokes expansion of the operator \\cdot. *)
|
|
400
|
+
(* *)
|
|
401
|
+
(* The pragma AutoUSE invokes automated expansion of definitions, *)
|
|
402
|
+
(* for both of ExpandEnabled and ExpandCdot, when each is present. *)
|
|
403
|
+
(* *)
|
|
404
|
+
(* The pragma Lambdify invokes expansion of the operators *)
|
|
405
|
+
(* ENABLED and \\cdot to an intermediate form with bound VARIABLES, *)
|
|
406
|
+
(* which is a form before introducing rigid quantifiers. *)
|
|
407
|
+
(* The pragma Lambdify is sound for occurrences of ENABLED and \\cdot *)
|
|
408
|
+
(* that are not nested. *)
|
|
409
|
+
(**************************************************************************)
|
|
410
|
+
ExpandENABLED == TRUE (*{ by (prover:"expandenabled") }*)
|
|
411
|
+
ExpandCdot == TRUE (*{ by (prover:"expandcdot") }*)
|
|
412
|
+
AutoUSE == TRUE (*{ by (prover:"autouse") }*)
|
|
413
|
+
Lambdify == TRUE (*{ by (prover:"lambdify") }*)
|
|
414
|
+
ENABLEDaxioms == TRUE (*{ by (prover:"enabledaxioms") }*)
|
|
415
|
+
LevelComparison == TRUE (*{ by (prover:"levelcomparison") }*)
|
|
416
|
+
|
|
417
|
+
(* The operators EnabledWrapper and CdotWrapper occur in an intermediate *)
|
|
418
|
+
(* representation within TLAPM. *)
|
|
419
|
+
EnabledWrapper(Op(_)) == FALSE
|
|
420
|
+
CdotWrapper(Op(_)) == FALSE
|
|
421
|
+
|
|
422
|
+
(***************************************************************************)
|
|
423
|
+
(* The following may be used in a \`BY ONLY ThmName\` for unit testing the *)
|
|
424
|
+
(* triviality checks in TLAPM. *)
|
|
425
|
+
(***************************************************************************)
|
|
426
|
+
Trivial == TRUE (*{ by (prover:"trivial") }*)
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
=============================================================================
|
|
430
|
+
|
|
431
|
+
The material below is obsolete: the TLA proof rules below are superseded by
|
|
432
|
+
the PTL decision procedure, and their formulation is unsound for the semantics
|
|
433
|
+
of temporal reasoning that TLAPS adopts.
|
|
434
|
+
|
|
435
|
+
----------------------------------------------------------------------------
|
|
436
|
+
(***************************************************************************)
|
|
437
|
+
(* TEMPORAL LOGIC *)
|
|
438
|
+
(* *)
|
|
439
|
+
(* The following rules are intended to be used when TLAPS handles temporal *)
|
|
440
|
+
(* logic. They will not work now. Moreover when temporal reasoning is *)
|
|
441
|
+
(* implemented, these rules may be changed or omitted, and additional *)
|
|
442
|
+
(* rules will probably be added. However, they are included mainly so *)
|
|
443
|
+
(* their names will be defined, preventing the use of identifiers that are *)
|
|
444
|
+
(* likely to produce name clashes with future versions of this module. *)
|
|
445
|
+
(***************************************************************************)
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
(***************************************************************************)
|
|
449
|
+
(* The following proof rules (and their names) are from the paper "The *)
|
|
450
|
+
(* Temporal Logic of Actions". *)
|
|
451
|
+
(***************************************************************************)
|
|
452
|
+
THEOREM RuleTLA1 == ASSUME STATE P, STATE f,
|
|
453
|
+
P /\\ (f' = f) => P'
|
|
454
|
+
PROVE []P <=> P /\\ [][P => P']_f
|
|
455
|
+
|
|
456
|
+
THEOREM RuleTLA2 == ASSUME STATE P, STATE Q, STATE f, STATE g,
|
|
457
|
+
ACTION A, ACTION B,
|
|
458
|
+
P /\\ [A]_f => Q /\\ [B]_g
|
|
459
|
+
PROVE []P /\\ [][A]_f => []Q /\\ [][B]_g
|
|
460
|
+
|
|
461
|
+
THEOREM RuleINV1 == ASSUME STATE I, STATE F, ACTION N,
|
|
462
|
+
I /\\ [N]_F => I'
|
|
463
|
+
PROVE I /\\ [][N]_F => []I
|
|
464
|
+
|
|
465
|
+
THEOREM RuleINV2 == ASSUME STATE I, STATE f, ACTION N
|
|
466
|
+
PROVE []I => ([][N]_f <=> [][N /\\ I /\\ I']_f)
|
|
467
|
+
|
|
468
|
+
THEOREM RuleWF1 == ASSUME STATE P, STATE Q, STATE f, ACTION N, ACTION A,
|
|
469
|
+
P /\\ [N]_f => (P' \\/ Q'),
|
|
470
|
+
P /\\ <<N /\\ A>>_f => Q',
|
|
471
|
+
P => ENABLED <<A>>_f
|
|
472
|
+
PROVE [][N]_f /\\ WF_f(A) => (P ~> Q)
|
|
473
|
+
|
|
474
|
+
THEOREM RuleSF1 == ASSUME STATE P, STATE Q, STATE f,
|
|
475
|
+
ACTION N, ACTION A, TEMPORAL F,
|
|
476
|
+
P /\\ [N]_f => (P' \\/ Q'),
|
|
477
|
+
P /\\ <<N /\\ A>>_f => Q',
|
|
478
|
+
[]P /\\ [][N]_f /\\ []F => <> ENABLED <<A>>_f
|
|
479
|
+
PROVE [][N]_f /\\ SF_f(A) /\\ []F => (P ~> Q)
|
|
480
|
+
|
|
481
|
+
(***************************************************************************)
|
|
482
|
+
(* The rules WF2 and SF2 in "The Temporal Logic of Actions" are obtained *)
|
|
483
|
+
(* from the following two rules by the following substitutions: \`. *)
|
|
484
|
+
(* *)
|
|
485
|
+
(* ___ ___ _______________ *)
|
|
486
|
+
(* M <- M , g <- g , EM <- ENABLED <<M>>_g .' *)
|
|
487
|
+
(***************************************************************************)
|
|
488
|
+
THEOREM RuleWF2 == ASSUME STATE P, STATE f, STATE g, STATE EM,
|
|
489
|
+
ACTION A, ACTION B, ACTION N, ACTION M,
|
|
490
|
+
TEMPORAL F,
|
|
491
|
+
<<N /\\ B>>_f => <<M>>_g,
|
|
492
|
+
P /\\ P' /\\ <<N /\\ A>>_f /\\ EM => B,
|
|
493
|
+
P /\\ EM => ENABLED A,
|
|
494
|
+
[][N /\\ ~B]_f /\\ WF_f(A) /\\ []F /\\ <>[]EM => <>[]P
|
|
495
|
+
PROVE [][N]_f /\\ WF_f(A) /\\ []F => []<><<M>>_g \\/ []<>(~EM)
|
|
496
|
+
|
|
497
|
+
THEOREM RuleSF2 == ASSUME STATE P, STATE f, STATE g, STATE EM,
|
|
498
|
+
ACTION A, ACTION B, ACTION N, ACTION M,
|
|
499
|
+
TEMPORAL F,
|
|
500
|
+
<<N /\\ B>>_f => <<M>>_g,
|
|
501
|
+
P /\\ P' /\\ <<N /\\ A>>_f /\\ EM => B,
|
|
502
|
+
P /\\ EM => ENABLED A,
|
|
503
|
+
[][N /\\ ~B]_f /\\ SF_f(A) /\\ []F /\\ []<>EM => <>[]P
|
|
504
|
+
PROVE [][N]_f /\\ SF_f(A) /\\ []F => []<><<M>>_g \\/ <>[](~EM)
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
(***************************************************************************)
|
|
508
|
+
(* The following rule is a special case of the general temporal logic *)
|
|
509
|
+
(* proof rule STL4 from the paper "The Temporal Logic of Actions". The *)
|
|
510
|
+
(* general rule is for arbitrary temporal formulas F and G, but it cannot *)
|
|
511
|
+
(* yet be handled by TLAPS. *)
|
|
512
|
+
(***************************************************************************)
|
|
513
|
+
THEOREM RuleInvImplication ==
|
|
514
|
+
ASSUME STATE F, STATE G,
|
|
515
|
+
F => G
|
|
516
|
+
PROVE []F => []G
|
|
517
|
+
PROOF OMITTED
|
|
518
|
+
|
|
519
|
+
(***************************************************************************)
|
|
520
|
+
(* The following rule is a special case of rule TLA2 from the paper "The *)
|
|
521
|
+
(* Temporal Logic of Actions". *)
|
|
522
|
+
(***************************************************************************)
|
|
523
|
+
THEOREM RuleStepSimulation ==
|
|
524
|
+
ASSUME STATE I, STATE f, STATE g,
|
|
525
|
+
ACTION M, ACTION N,
|
|
526
|
+
I /\\ I' /\\ [M]_f => [N]_g
|
|
527
|
+
PROVE []I /\\ [][M]_f => [][N]_g
|
|
528
|
+
PROOF OMITTED
|
|
529
|
+
|
|
530
|
+
(***************************************************************************)
|
|
531
|
+
(* The following may be used to invoke a decision procedure for *)
|
|
532
|
+
(* propositional temporal logic. *)
|
|
533
|
+
(***************************************************************************)
|
|
534
|
+
PropositionalTemporalLogic == TRUE
|
|
535
|
+
=============================================================================
|
|
536
|
+
`,
|
|
537
|
+
],
|
|
538
|
+
[
|
|
539
|
+
"Bags",
|
|
540
|
+
`----------------------------- MODULE Bags --------------------------------
|
|
541
|
+
(**************************************************************************)
|
|
542
|
+
(* A bag, also called a multiset, is a set that can contain multiple *)
|
|
543
|
+
(* copies of the same element. A bag can have infinitely many elements, *)
|
|
544
|
+
(* but only finitely many copies of any single element. *)
|
|
545
|
+
(* *)
|
|
546
|
+
(* We represent a bag in the usual way as a function whose range is a *)
|
|
547
|
+
(* subset of the positive integers. An element e belongs to bag B iff e *)
|
|
548
|
+
(* is in the domain of B, in which case bag B contains B[e] copies of e. *)
|
|
549
|
+
(**************************************************************************)
|
|
550
|
+
LOCAL INSTANCE Naturals
|
|
551
|
+
|
|
552
|
+
IsABag(B) ==
|
|
553
|
+
(************************************************************************)
|
|
554
|
+
(* True iff B is a bag. *)
|
|
555
|
+
(************************************************************************)
|
|
556
|
+
B \\in [DOMAIN B -> {n \\in Nat : n > 0}]
|
|
557
|
+
|
|
558
|
+
BagToSet(B) == DOMAIN B
|
|
559
|
+
(************************************************************************)
|
|
560
|
+
(* The set of elements at least one copy of which is in B. *)
|
|
561
|
+
(************************************************************************)
|
|
562
|
+
|
|
563
|
+
SetToBag(S) == [e \\in S |-> 1]
|
|
564
|
+
(************************************************************************)
|
|
565
|
+
(* The bag that contains one copy of every element of the set S. *)
|
|
566
|
+
(************************************************************************)
|
|
567
|
+
|
|
568
|
+
BagIn(e,B) == e \\in BagToSet(B)
|
|
569
|
+
(************************************************************************)
|
|
570
|
+
(* The \\in operator for bags. *)
|
|
571
|
+
(************************************************************************)
|
|
572
|
+
|
|
573
|
+
EmptyBag == SetToBag({})
|
|
574
|
+
|
|
575
|
+
B1 (+) B2 ==
|
|
576
|
+
(************************************************************************)
|
|
577
|
+
(* The union of bags B1 and B2. *)
|
|
578
|
+
(************************************************************************)
|
|
579
|
+
[e \\in (DOMAIN B1) \\cup (DOMAIN B2) |->
|
|
580
|
+
(IF e \\in DOMAIN B1 THEN B1[e] ELSE 0)
|
|
581
|
+
+ (IF e \\in DOMAIN B2 THEN B2[e] ELSE 0) ]
|
|
582
|
+
|
|
583
|
+
B1 (-) B2 ==
|
|
584
|
+
(************************************************************************)
|
|
585
|
+
(* The bag B1 with the elements of B2 removed--that is, with one copy *)
|
|
586
|
+
(* of an element removed from B1 for each copy of the same element in *)
|
|
587
|
+
(* B2. If B2 has at least as many copies of e as B1, then B1 (-) B2 *)
|
|
588
|
+
(* has no copies of e. *)
|
|
589
|
+
(************************************************************************)
|
|
590
|
+
LET B == [e \\in DOMAIN B1 |-> IF e \\in DOMAIN B2 THEN B1[e] - B2[e]
|
|
591
|
+
ELSE B1[e]]
|
|
592
|
+
IN [e \\in {d \\in DOMAIN B : B[d] > 0} |-> B[e]]
|
|
593
|
+
|
|
594
|
+
LOCAL Sum(f) ==
|
|
595
|
+
(******************************************************************)
|
|
596
|
+
(* The sum of f[x] for all x in DOMAIN f. The definition assumes *)
|
|
597
|
+
(* that f is a Nat-valued function and that f[x] equals 0 for all *)
|
|
598
|
+
(* but a finite number of elements x in DOMAIN f. *)
|
|
599
|
+
(******************************************************************)
|
|
600
|
+
LET DSum[S \\in SUBSET DOMAIN f] ==
|
|
601
|
+
LET elt == CHOOSE e \\in S : TRUE
|
|
602
|
+
IN IF S = {} THEN 0
|
|
603
|
+
ELSE f[elt] + DSum[S \\ {elt}]
|
|
604
|
+
IN DSum[DOMAIN f]
|
|
605
|
+
|
|
606
|
+
BagUnion(S) ==
|
|
607
|
+
(************************************************************************)
|
|
608
|
+
(* The bag union of all elements of the set S of bags. *)
|
|
609
|
+
(************************************************************************)
|
|
610
|
+
[e \\in UNION {BagToSet(B) : B \\in S} |->
|
|
611
|
+
Sum( [B \\in S |-> IF BagIn(e, B) THEN B[e] ELSE 0] ) ]
|
|
612
|
+
|
|
613
|
+
B1 \\sqsubseteq B2 ==
|
|
614
|
+
(************************************************************************)
|
|
615
|
+
(* The subset operator for bags. B1 \\sqsubseteq B2 iff, for all e, bag *)
|
|
616
|
+
(* B2 has at least as many copies of e as bag B1 does. *)
|
|
617
|
+
(************************************************************************)
|
|
618
|
+
/\\ (DOMAIN B1) \\subseteq (DOMAIN B2)
|
|
619
|
+
/\\ \\A e \\in DOMAIN B1 : B1[e] \\leq B2[e]
|
|
620
|
+
|
|
621
|
+
SubBag(B) ==
|
|
622
|
+
(************************************************************************)
|
|
623
|
+
(* The set of all subbags of bag B. *)
|
|
624
|
+
(* *)
|
|
625
|
+
(* The following definition is not the one described in the TLA+ book, *)
|
|
626
|
+
(* but rather one that TLC can evaluate. *)
|
|
627
|
+
(************************************************************************)
|
|
628
|
+
|
|
629
|
+
LET RemoveFromDom(x, f) == [y \\in (DOMAIN f) \\ {x} |-> f[y]]
|
|
630
|
+
Combine(x, BagSet) ==
|
|
631
|
+
BagSet \\cup
|
|
632
|
+
{[y \\in (DOMAIN f) \\cup {x} |-> IF y = x THEN i ELSE f[y]] :
|
|
633
|
+
f \\in BagSet, i \\in 1..B[x]}
|
|
634
|
+
Biggest == LET Range1 == {B[x] : x \\in DOMAIN B}
|
|
635
|
+
IN IF Range1 = {} THEN 0
|
|
636
|
+
ELSE CHOOSE r \\in Range1 :
|
|
637
|
+
\\A s \\in Range1 : r \\geq s
|
|
638
|
+
RSB[BB \\in UNION {[S -> 1..Biggest] : S \\in SUBSET DOMAIN B}] ==
|
|
639
|
+
IF BB = << >> THEN {<< >>}
|
|
640
|
+
ELSE LET x == CHOOSE x \\in DOMAIN BB : TRUE
|
|
641
|
+
IN Combine(x, RSB[RemoveFromDom(x, BB)])
|
|
642
|
+
IN RSB[B]
|
|
643
|
+
|
|
644
|
+
(******************* Here is the definition from the TLA+ book. ********
|
|
645
|
+
LET AllBagsOfSubset ==
|
|
646
|
+
(******************************************************************)
|
|
647
|
+
(* The set of all bags SB such that BagToSet(SB) \\subseteq *)
|
|
648
|
+
(* BagToSet(B). *)
|
|
649
|
+
(******************************************************************)
|
|
650
|
+
UNION {[SB -> {n \\in Nat : n > 0}] : SB \\in SUBSET BagToSet(B)}
|
|
651
|
+
IN {SB \\in AllBagsOfSubset : \\A e \\in DOMAIN SB : SB[e] \\leq B[e]}
|
|
652
|
+
***************************************************************************)
|
|
653
|
+
|
|
654
|
+
BagOfAll(F(_), B) ==
|
|
655
|
+
(************************************************************************)
|
|
656
|
+
(* The bag analog of the set {F(x) : x \\in B} for a set B. It's the bag *)
|
|
657
|
+
(* that contains, for each element e of B, one copy of F(e) for every *)
|
|
658
|
+
(* copy of e in B. This defines a bag iff, for any value v, the set of *)
|
|
659
|
+
(* e in B such that F(e) = v is finite. *)
|
|
660
|
+
(************************************************************************)
|
|
661
|
+
[e \\in {F(d) : d \\in BagToSet(B)} |->
|
|
662
|
+
Sum( [d \\in BagToSet(B) |-> IF F(d) = e THEN B[d] ELSE 0] ) ]
|
|
663
|
+
|
|
664
|
+
BagCardinality(B) ==
|
|
665
|
+
(************************************************************************)
|
|
666
|
+
(* If B is a finite bag (one such that BagToSet(B) is a finite set), *)
|
|
667
|
+
(* then this is its cardinality (the total number of copies of elements *)
|
|
668
|
+
(* in B). Its value is unspecified if B is infinite. *)
|
|
669
|
+
(************************************************************************)
|
|
670
|
+
Sum(B)
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
=============================================================================
|
|
674
|
+
|
|
675
|
+
(* Last modified on Fri 26 Jan 2007 at 8:45:03 PST by lamport *)
|
|
676
|
+
|
|
677
|
+
6 Apr 99 : Modified version for standard module set
|
|
678
|
+
7 Dec 98 : Corrected error found by Stephan Merz.
|
|
679
|
+
6 Dec 98 : Modified comments based on suggestions by Lyle Ramshaw.
|
|
680
|
+
5 Dec 98 : Initial version.
|
|
681
|
+
`,
|
|
682
|
+
],
|
|
683
|
+
[
|
|
684
|
+
"BagsTheorems",
|
|
685
|
+
`---------------------------- MODULE BagsTheorems ---------------------------
|
|
686
|
+
(**************************************************************************)
|
|
687
|
+
(* A bag, also called a multiset, is a set that can contain multiple *)
|
|
688
|
+
(* copies of the same element. A bag can have infinitely many elements, *)
|
|
689
|
+
(* but only finitely many copies of any single element. *)
|
|
690
|
+
(* *)
|
|
691
|
+
(* We represent a bag in the usual way as a function whose range is a *)
|
|
692
|
+
(* subset of the positive integers. An element e belongs to bag B iff e *)
|
|
693
|
+
(* is in the domain of B, in which case bag B contains B[e] copies of e. *)
|
|
694
|
+
(**************************************************************************)
|
|
695
|
+
EXTENDS Bags
|
|
696
|
+
|
|
697
|
+
LOCAL INSTANCE Naturals
|
|
698
|
+
|
|
699
|
+
CopiesIn(e, B) ==
|
|
700
|
+
(************************************************************************)
|
|
701
|
+
(* If B is a bag, then CopiesIn(e, B) is the number of copies of e in *)
|
|
702
|
+
(* B. If ~BagIn(e, B), then CopiesIn(e, B) = 0. *)
|
|
703
|
+
(************************************************************************)
|
|
704
|
+
IF BagIn(e, B) THEN B[e] ELSE 0
|
|
705
|
+
|
|
706
|
+
Scaling(n, B) ==
|
|
707
|
+
(************************************************************************)
|
|
708
|
+
(* If B is a bag, then Scaling(e, B) is the Bag containing the same *)
|
|
709
|
+
(* elements of B with n times their copies *)
|
|
710
|
+
(************************************************************************)
|
|
711
|
+
IF n>0 THEN [i \\in DOMAIN B |-> n*B[i] ] ELSE EmptyBag
|
|
712
|
+
|
|
713
|
+
|
|
714
|
+
(***************************************************************************)
|
|
715
|
+
(* Converts a sequence into a bag *)
|
|
716
|
+
(***************************************************************************)
|
|
717
|
+
|
|
718
|
+
SeqToBag(seq) == [ x \\in Range(seq) |-> Cardinality({i \\in DOMAIN seq: seq[i]=x}) ]
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
(***************************************************************************)
|
|
722
|
+
(* \\sqsubseteq is a PARTIAL ORDER relattion *)
|
|
723
|
+
(***************************************************************************)
|
|
724
|
+
|
|
725
|
+
(*Reflexivity*)
|
|
726
|
+
THEOREM Bags_SqsubsetPO_Reflexivity ==
|
|
727
|
+
ASSUME NEW B, IsABag(B)
|
|
728
|
+
PROVE B \\sqsubseteq B
|
|
729
|
+
|
|
730
|
+
(*Antisymmetry*)
|
|
731
|
+
THEOREM Bags_SqsubseteqPO_AntiSymmetry ==
|
|
732
|
+
ASSUME NEW A, NEW B, IsABag(A), IsABag(B),
|
|
733
|
+
A \\sqsubseteq B, B \\sqsubseteq A
|
|
734
|
+
PROVE A = B
|
|
735
|
+
|
|
736
|
+
(*Transitivity*)
|
|
737
|
+
THEOREM Bags_SqsubseteqPO_Transitivity ==
|
|
738
|
+
ASSUME NEW A, NEW B, NEW C, IsABag(A), IsABag(B), IsABag(C),
|
|
739
|
+
A \\sqsubseteq B, B \\sqsubseteq C
|
|
740
|
+
PROVE A \\sqsubseteq C
|
|
741
|
+
|
|
742
|
+
(***************************************************************************)
|
|
743
|
+
(* Lemmas on EmptyBags *)
|
|
744
|
+
(***************************************************************************)
|
|
745
|
+
|
|
746
|
+
THEOREM Bags_EmptyBag ==
|
|
747
|
+
ASSUME NEW B, IsABag(B)
|
|
748
|
+
PROVE /\\ IsABag(EmptyBag)
|
|
749
|
+
/\\ B=EmptyBag <=> DOMAIN B ={}
|
|
750
|
+
/\\ DOMAIN EmptyBag ={}
|
|
751
|
+
/\\ EmptyBag \\sqsubseteq B
|
|
752
|
+
/\\ \\A e: ~BagIn(e, EmptyBag)
|
|
753
|
+
|
|
754
|
+
(***************************************************************************)
|
|
755
|
+
(* Lemmas on Scaling Operator for Bags *)
|
|
756
|
+
(***************************************************************************)
|
|
757
|
+
|
|
758
|
+
THEOREM Bags_Scaling ==
|
|
759
|
+
ASSUME NEW B, IsABag(B), NEW n \\in Nat, NEW m \\in Nat
|
|
760
|
+
PROVE /\\ IsABag(Scaling(n, B))
|
|
761
|
+
/\\ Scaling(n, EmptyBag)=EmptyBag
|
|
762
|
+
/\\ Scaling(0, B)=EmptyBag
|
|
763
|
+
/\\ Scaling(1, B)= B
|
|
764
|
+
/\\ Scaling(n*m, B) = Scaling(n, Scaling(m, B))
|
|
765
|
+
/\\ n>0 => DOMAIN(Scaling(n, B)) = DOMAIN B
|
|
766
|
+
|
|
767
|
+
(***************************************************************************)
|
|
768
|
+
(* SetToBag and BagToSet are inverse of each other *)
|
|
769
|
+
(***************************************************************************)
|
|
770
|
+
|
|
771
|
+
THEOREM Bags_Inverse ==
|
|
772
|
+
ASSUME NEW S
|
|
773
|
+
PROVE BagToSet(SetToBag(S))=S
|
|
774
|
+
|
|
775
|
+
THEOREM Bags_Inverse1 ==
|
|
776
|
+
ASSUME NEW B, IsABag(B)
|
|
777
|
+
PROVE SetToBag(BagToSet(B)) \\sqsubseteq B
|
|
778
|
+
|
|
779
|
+
(***************************************************************************)
|
|
780
|
+
(* SetToBag Preserves Equality *)
|
|
781
|
+
(***************************************************************************)
|
|
782
|
+
|
|
783
|
+
THEOREM Bags_SetToBagEquality ==
|
|
784
|
+
ASSUME NEW A, NEW B
|
|
785
|
+
PROVE A=B <=> SetToBag(A)=SetToBag(B)
|
|
786
|
+
|
|
787
|
+
(***************************************************************************)
|
|
788
|
+
(* Union of Bags *)
|
|
789
|
+
(***************************************************************************)
|
|
790
|
+
|
|
791
|
+
THEOREM Bags_Union ==
|
|
792
|
+
ASSUME NEW B1, NEW B2, IsABag(B1), IsABag(B2)
|
|
793
|
+
PROVE /\\ IsABag(B1 (+) B2)
|
|
794
|
+
/\\ DOMAIN(B1 (+) B2) = DOMAIN B1 \\cup DOMAIN B2
|
|
795
|
+
/\\ \\A e : CopiesIn(e, B1(+)B2) = CopiesIn(e,B1) + CopiesIn(e,B2)
|
|
796
|
+
|
|
797
|
+
(***************************************************************************)
|
|
798
|
+
(* Difference of Bags *)
|
|
799
|
+
(***************************************************************************)
|
|
800
|
+
|
|
801
|
+
THEOREM Bags_Difference ==
|
|
802
|
+
ASSUME NEW B1, NEW B2, IsABag(B1), IsABag(B2)
|
|
803
|
+
PROVE /\\ IsABag(B1 (-) B2)
|
|
804
|
+
/\\ DOMAIN (B1 (-) B2) =
|
|
805
|
+
{e \\in DOMAIN B1 : e \\notin DOMAIN B2 \\/ B1[e] > B2[e]}
|
|
806
|
+
/\\ \\A e : CopiesIn(e, B1 (-) B2) =
|
|
807
|
+
IF BagIn(e, B1(-)B2) THEN CopiesIn(e,B1) - CopiesIn(e,B2)
|
|
808
|
+
ELSE 0
|
|
809
|
+
|
|
810
|
+
(***************************************************************************)
|
|
811
|
+
(* Union is commutative. *)
|
|
812
|
+
(***************************************************************************)
|
|
813
|
+
|
|
814
|
+
THEOREM Bags_UnionCommutative ==
|
|
815
|
+
ASSUME NEW B1, NEW B2, IsABag(B1), IsABag(B2)
|
|
816
|
+
PROVE B1(+)B2 = B2(+)B1
|
|
817
|
+
|
|
818
|
+
(***************************************************************************)
|
|
819
|
+
(* Unon is associative. *)
|
|
820
|
+
(***************************************************************************)
|
|
821
|
+
THEOREM Bags_UnionAssociative ==
|
|
822
|
+
ASSUME NEW B1, NEW B2, NEW B3, IsABag(B1), IsABag(B2), IsABag(B3)
|
|
823
|
+
PROVE (B1(+)B2) (+) B3 = B1 (+) (B2(+)B3)
|
|
824
|
+
|
|
825
|
+
(***************************************************************************)
|
|
826
|
+
(* Given Bags B1, B2 then B1 \\sqsubseteq B1(+)B2 *)
|
|
827
|
+
(***************************************************************************)
|
|
828
|
+
|
|
829
|
+
THEOREM Bags_UnionSqSubset ==
|
|
830
|
+
ASSUME NEW B1, NEW B2, IsABag(B1), IsABag(B2)
|
|
831
|
+
PROVE B1 \\sqsubseteq B1(+)B2
|
|
832
|
+
|
|
833
|
+
(***************************************************************************)
|
|
834
|
+
(* Scaling is monotonic in the scaling factor. *)
|
|
835
|
+
(***************************************************************************)
|
|
836
|
+
|
|
837
|
+
THEOREM Bags_ScalingMonotonic ==
|
|
838
|
+
ASSUME NEW B, IsABag(B), NEW n \\in Nat, NEW m \\in Nat, m <= n
|
|
839
|
+
PROVE Scaling(m, B) \\sqsubseteq Scaling(n, B)
|
|
840
|
+
|
|
841
|
+
(***************************************************************************)
|
|
842
|
+
(* Given Bags A and B, A(-)B \\sqsubseteq A *)
|
|
843
|
+
(***************************************************************************)
|
|
844
|
+
|
|
845
|
+
THEOREM Bags_DifferenceSqsubset ==
|
|
846
|
+
ASSUME NEW A, NEW B, IsABag(A), IsABag(B)
|
|
847
|
+
PROVE A(-)B \\sqsubseteq A
|
|
848
|
+
|
|
849
|
+
(***************************************************************************)
|
|
850
|
+
(* EmptyBag is the additive identity. *)
|
|
851
|
+
(***************************************************************************)
|
|
852
|
+
|
|
853
|
+
THEOREM Bags_EmptyBagOperations ==
|
|
854
|
+
ASSUME NEW B, IsABag(B)
|
|
855
|
+
PROVE /\\ B (+) EmptyBag = B
|
|
856
|
+
/\\ B (-) EmptyBag = B
|
|
857
|
+
|
|
858
|
+
(***************************************************************************)
|
|
859
|
+
(* SetToBag of a set is a bag. *)
|
|
860
|
+
(***************************************************************************)
|
|
861
|
+
|
|
862
|
+
THEOREM Bags_SetToBagIsABag ==
|
|
863
|
+
ASSUME NEW S
|
|
864
|
+
PROVE IsABag(SetToBag(S))
|
|
865
|
+
|
|
866
|
+
(***************************************************************************)
|
|
867
|
+
(* CopiesIn is monotone w.r.t \\sqsubseteq *)
|
|
868
|
+
(***************************************************************************)
|
|
869
|
+
|
|
870
|
+
THEOREM Bags_CopiesInBagsInMonotone ==
|
|
871
|
+
ASSUME NEW B1, NEW B2, NEW e, IsABag(B1), IsABag(B2), B1 \\sqsubseteq B2
|
|
872
|
+
PROVE /\\ BagIn(e, B1) => BagIn(e, B2)
|
|
873
|
+
/\\ CopiesIn(e, B1) <= CopiesIn(e, B2)
|
|
874
|
+
|
|
875
|
+
(***************************************************************************)
|
|
876
|
+
(* Given Bag B and Natural n, CopiesIn(e, Scaling(n, B))=n*CopiesIn(e, B) *)
|
|
877
|
+
(***************************************************************************)
|
|
878
|
+
|
|
879
|
+
THEOREM Bags_CopiesInScaling ==
|
|
880
|
+
ASSUME NEW B, IsABag(B), NEW n \\in Nat, NEW e
|
|
881
|
+
PROVE CopiesIn(e, Scaling(n, B)) = n*CopiesIn(e, B)
|
|
882
|
+
|
|
883
|
+
(***************************************************************************)
|
|
884
|
+
(* Given set S, CopiesIn(e, SetToBag(S))=IF e \\in B THEN 1 ELSE 0 *)
|
|
885
|
+
(***************************************************************************)
|
|
886
|
+
|
|
887
|
+
THEOREM Bags_CopiesInSetToBag ==
|
|
888
|
+
ASSUME NEW B, NEW e
|
|
889
|
+
PROVE CopiesIn(e, SetToBag(B))=IF e \\in B THEN 1 ELSE 0
|
|
890
|
+
|
|
891
|
+
(***************************************************************************)
|
|
892
|
+
(* Given sequence seq, SeqToBag(seq) is a Bag *)
|
|
893
|
+
(***************************************************************************)
|
|
894
|
+
|
|
895
|
+
THEOREM Bags_IsABagSeqToBag ==
|
|
896
|
+
ASSUME NEW S, NEW seq \\in Seq(S)
|
|
897
|
+
PROVE IsABag(SeqToBag(seq))
|
|
898
|
+
|
|
899
|
+
=============================================================================
|
|
900
|
+
`,
|
|
901
|
+
],
|
|
902
|
+
[
|
|
903
|
+
"FiniteSets",
|
|
904
|
+
`---------------------------- MODULE FiniteSets -----------------------------
|
|
905
|
+
LOCAL INSTANCE Naturals
|
|
906
|
+
LOCAL INSTANCE Sequences
|
|
907
|
+
(*************************************************************************)
|
|
908
|
+
(* Imports the definitions from Naturals and Sequences, but doesn't *)
|
|
909
|
+
(* export them. *)
|
|
910
|
+
(*************************************************************************)
|
|
911
|
+
|
|
912
|
+
IsFiniteSet(S) ==
|
|
913
|
+
(*************************************************************************)
|
|
914
|
+
(* A set S is finite iff there is a finite sequence containing all its *)
|
|
915
|
+
(* elements. *)
|
|
916
|
+
(*************************************************************************)
|
|
917
|
+
\\E seq \\in Seq(S) : \\A s \\in S : \\E n \\in 1..Len(seq) : seq[n] = s
|
|
918
|
+
|
|
919
|
+
Cardinality(S) ==
|
|
920
|
+
(*************************************************************************)
|
|
921
|
+
(* Cardinality is defined only for finite sets. *)
|
|
922
|
+
(*************************************************************************)
|
|
923
|
+
LET CS[T \\in SUBSET S] == IF T = {} THEN 0
|
|
924
|
+
ELSE 1 + CS[T \\ {CHOOSE x : x \\in T}]
|
|
925
|
+
IN CS[S]
|
|
926
|
+
=============================================================================
|
|
927
|
+
`,
|
|
928
|
+
],
|
|
929
|
+
[
|
|
930
|
+
"FiniteSetTheorems",
|
|
931
|
+
`------------------------- MODULE FiniteSetTheorems --------------------------
|
|
932
|
+
(***************************************************************************)
|
|
933
|
+
(* \`^{\\large\\bf \\vspace{12pt} *)
|
|
934
|
+
(* Facts about finite sets and their cardinality. *)
|
|
935
|
+
(* Originally contributed by Tom Rodeheffer, MSR. *)
|
|
936
|
+
(* \\vspace{12pt}}^' *)
|
|
937
|
+
(***************************************************************************)
|
|
938
|
+
|
|
939
|
+
EXTENDS FiniteSets, Integers, Functions, WellFoundedInduction
|
|
940
|
+
|
|
941
|
+
(***************************************************************************)
|
|
942
|
+
(* \`. .' *)
|
|
943
|
+
(* *)
|
|
944
|
+
(* A set S is finite iff there exists a natural number n such that there *)
|
|
945
|
+
(* exist a surjection (or a bijection) from 1..n to S. *)
|
|
946
|
+
(* *)
|
|
947
|
+
(* \`. .' *)
|
|
948
|
+
(***************************************************************************)
|
|
949
|
+
|
|
950
|
+
LEMMA FS_NatSurjection ==
|
|
951
|
+
ASSUME NEW S
|
|
952
|
+
PROVE IsFiniteSet(S) <=> \\E n \\in Nat : ExistsSurjection(1..n,S)
|
|
953
|
+
|
|
954
|
+
LEMMA FS_NatBijection ==
|
|
955
|
+
ASSUME NEW S
|
|
956
|
+
PROVE IsFiniteSet(S) <=> \\E n \\in Nat : ExistsBijection(1..n,S)
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
(***************************************************************************)
|
|
960
|
+
(* \`. .' *)
|
|
961
|
+
(* *)
|
|
962
|
+
(* If there exists n \\in Nat such that a bijection exists from 1..n to S, *)
|
|
963
|
+
(* then Cardinality(S) = n. *)
|
|
964
|
+
(* *)
|
|
965
|
+
(* \`. .' *)
|
|
966
|
+
(***************************************************************************)
|
|
967
|
+
|
|
968
|
+
LEMMA FS_CountingElements ==
|
|
969
|
+
ASSUME NEW S, NEW n \\in Nat, ExistsBijection(1..n,S)
|
|
970
|
+
PROVE Cardinality(S) = n
|
|
971
|
+
|
|
972
|
+
|
|
973
|
+
(***************************************************************************)
|
|
974
|
+
(* Corollary: a surjection from 1..n to S provides a cardinality bound. *)
|
|
975
|
+
(***************************************************************************)
|
|
976
|
+
THEOREM FS_SurjCardinalityBound ==
|
|
977
|
+
ASSUME NEW S, NEW n \\in Nat, ExistsSurjection(1..n, S)
|
|
978
|
+
PROVE Cardinality(S) <= n
|
|
979
|
+
|
|
980
|
+
|
|
981
|
+
(***************************************************************************)
|
|
982
|
+
(* \`. .' *)
|
|
983
|
+
(* *)
|
|
984
|
+
(* For any finite set S, Cardinality(S) \\in Nat. Moreover, there is a *)
|
|
985
|
+
(* bijection from 1 .. Cardinality(S) to S. *)
|
|
986
|
+
(* *)
|
|
987
|
+
(* \`. .' *)
|
|
988
|
+
(***************************************************************************)
|
|
989
|
+
THEOREM FS_CardinalityType ==
|
|
990
|
+
ASSUME NEW S, IsFiniteSet(S)
|
|
991
|
+
PROVE /\\ Cardinality(S) \\in Nat
|
|
992
|
+
/\\ ExistsBijection(1..Cardinality(S), S)
|
|
993
|
+
|
|
994
|
+
|
|
995
|
+
(***************************************************************************)
|
|
996
|
+
(* \`. .' *)
|
|
997
|
+
(* *)
|
|
998
|
+
(* The image of a finite set under a bijection is finite. *)
|
|
999
|
+
(* *)
|
|
1000
|
+
(* \`. .' *)
|
|
1001
|
+
(***************************************************************************)
|
|
1002
|
+
THEOREM FS_Bijection ==
|
|
1003
|
+
ASSUME NEW S, NEW T, IsFiniteSet(S), ExistsBijection(S,T)
|
|
1004
|
+
PROVE /\\ IsFiniteSet(T)
|
|
1005
|
+
/\\ Cardinality(T) = Cardinality(S)
|
|
1006
|
+
|
|
1007
|
+
THEOREM FS_SameCardinalityBij ==
|
|
1008
|
+
ASSUME NEW S, NEW T, IsFiniteSet(S), IsFiniteSet(T),
|
|
1009
|
+
Cardinality(S) = Cardinality(T)
|
|
1010
|
+
PROVE ExistsBijection(S,T)
|
|
1011
|
+
|
|
1012
|
+
|
|
1013
|
+
(***************************************************************************)
|
|
1014
|
+
(* \`. .' *)
|
|
1015
|
+
(* *)
|
|
1016
|
+
(* Any surjection between two finite sets of equal cardinality is *)
|
|
1017
|
+
(* an injection. *)
|
|
1018
|
+
(* *)
|
|
1019
|
+
(* \`. .' *)
|
|
1020
|
+
(***************************************************************************)
|
|
1021
|
+
THEOREM FS_SurjSameCardinalityImpliesInj ==
|
|
1022
|
+
ASSUME NEW S, NEW T, IsFiniteSet(S), Cardinality(S) = Cardinality(T),
|
|
1023
|
+
NEW f \\in Surjection(S,T)
|
|
1024
|
+
PROVE f \\in Injection(S,T)
|
|
1025
|
+
|
|
1026
|
+
|
|
1027
|
+
(***************************************************************************)
|
|
1028
|
+
(* \`. .' *)
|
|
1029
|
+
(* *)
|
|
1030
|
+
(* The image of a finite set is finite. *)
|
|
1031
|
+
(* NB: Note that any function is a surjection on its range by theorem *)
|
|
1032
|
+
(* Fun_RangeProperties. *)
|
|
1033
|
+
(* *)
|
|
1034
|
+
(* \`. .' *)
|
|
1035
|
+
(***************************************************************************)
|
|
1036
|
+
THEOREM FS_Surjection ==
|
|
1037
|
+
ASSUME NEW S, NEW T, NEW f \\in Surjection(S,T), IsFiniteSet(S)
|
|
1038
|
+
PROVE /\\ IsFiniteSet(T)
|
|
1039
|
+
/\\ Cardinality(T) <= Cardinality(S)
|
|
1040
|
+
/\\ Cardinality(T) = Cardinality(S) <=> f \\in Injection(S,T)
|
|
1041
|
+
|
|
1042
|
+
THEOREM FS_Image ==
|
|
1043
|
+
ASSUME NEW S, IsFiniteSet(S), NEW Op(_)
|
|
1044
|
+
PROVE LET T == {Op(x) : x \\in S}
|
|
1045
|
+
IN /\\ IsFiniteSet(T)
|
|
1046
|
+
/\\ Cardinality(T) <= Cardinality(S)
|
|
1047
|
+
|
|
1048
|
+
(***************************************************************************)
|
|
1049
|
+
(* \`. .' *)
|
|
1050
|
+
(* *)
|
|
1051
|
+
(* Symmetric theorem for injections and the pigeonhole principle. *)
|
|
1052
|
+
(* *)
|
|
1053
|
+
(* \`. .' *)
|
|
1054
|
+
(***************************************************************************)
|
|
1055
|
+
THEOREM FS_Injection ==
|
|
1056
|
+
ASSUME NEW S, NEW T, NEW f \\in Injection(S,T), IsFiniteSet(T)
|
|
1057
|
+
PROVE /\\ IsFiniteSet(S)
|
|
1058
|
+
/\\ Cardinality(S) <= Cardinality(T)
|
|
1059
|
+
/\\ Cardinality(S) = Cardinality(T) <=> f \\in Surjection(S,T)
|
|
1060
|
+
|
|
1061
|
+
THEOREM FS_PigeonHole ==
|
|
1062
|
+
ASSUME NEW S, IsFiniteSet(S),
|
|
1063
|
+
NEW T, IsFiniteSet(T), Cardinality(T) < Cardinality(S),
|
|
1064
|
+
NEW f \\in [S -> T]
|
|
1065
|
+
PROVE \\E x,y \\in S : x # y /\\ f[x] = f[y]
|
|
1066
|
+
|
|
1067
|
+
|
|
1068
|
+
(***************************************************************************)
|
|
1069
|
+
(* \`. .' *)
|
|
1070
|
+
(* *)
|
|
1071
|
+
(* The cardinality of a finite set S is 0 iff S is empty. *)
|
|
1072
|
+
(* *)
|
|
1073
|
+
(* \`. .' *)
|
|
1074
|
+
(***************************************************************************)
|
|
1075
|
+
THEOREM FS_EmptySet ==
|
|
1076
|
+
/\\ IsFiniteSet({})
|
|
1077
|
+
/\\ Cardinality({}) = 0
|
|
1078
|
+
/\\ \\A S : IsFiniteSet(S) => (Cardinality(S) = 0 <=> S = {})
|
|
1079
|
+
|
|
1080
|
+
|
|
1081
|
+
(***************************************************************************)
|
|
1082
|
+
(* \`. .' *)
|
|
1083
|
+
(* *)
|
|
1084
|
+
(* If S is finite, so are S \\cup {x} and S \\ {x}. *)
|
|
1085
|
+
(* *)
|
|
1086
|
+
(* \`. .' *)
|
|
1087
|
+
(***************************************************************************)
|
|
1088
|
+
THEOREM FS_AddElement ==
|
|
1089
|
+
ASSUME NEW S, NEW x, IsFiniteSet(S)
|
|
1090
|
+
PROVE /\\ IsFiniteSet(S \\cup {x})
|
|
1091
|
+
/\\ Cardinality(S \\cup {x}) =
|
|
1092
|
+
IF x \\in S THEN Cardinality(S) ELSE Cardinality(S)+1
|
|
1093
|
+
|
|
1094
|
+
THEOREM FS_RemoveElement ==
|
|
1095
|
+
ASSUME NEW S, NEW x, IsFiniteSet(S)
|
|
1096
|
+
PROVE /\\ IsFiniteSet(S \\ {x})
|
|
1097
|
+
/\\ Cardinality(S \\ {x}) =
|
|
1098
|
+
IF x \\in S THEN Cardinality(S)-1 ELSE Cardinality(S)
|
|
1099
|
+
|
|
1100
|
+
|
|
1101
|
+
(***************************************************************************)
|
|
1102
|
+
(* \`. .' *)
|
|
1103
|
+
(* *)
|
|
1104
|
+
(* In particular, a singleton set is finite. *)
|
|
1105
|
+
(* *)
|
|
1106
|
+
(* \`. .' *)
|
|
1107
|
+
(***************************************************************************)
|
|
1108
|
+
THEOREM FS_Singleton ==
|
|
1109
|
+
/\\ \\A x : IsFiniteSet({x}) /\\ Cardinality({x}) = 1
|
|
1110
|
+
/\\ \\A S : IsFiniteSet(S) => (Cardinality(S) = 1 <=> \\E x: S = {x})
|
|
1111
|
+
|
|
1112
|
+
|
|
1113
|
+
(***************************************************************************)
|
|
1114
|
+
(* \`. .' *)
|
|
1115
|
+
(* *)
|
|
1116
|
+
(* Any subset of a finite set is finite. *)
|
|
1117
|
+
(* *)
|
|
1118
|
+
(* \`. .' *)
|
|
1119
|
+
(***************************************************************************)
|
|
1120
|
+
THEOREM FS_Subset ==
|
|
1121
|
+
ASSUME NEW S, IsFiniteSet(S), NEW T \\in SUBSET S
|
|
1122
|
+
PROVE /\\ IsFiniteSet(T)
|
|
1123
|
+
/\\ Cardinality(T) <= Cardinality(S)
|
|
1124
|
+
/\\ Cardinality(S) = Cardinality(T) => S = T
|
|
1125
|
+
|
|
1126
|
+
|
|
1127
|
+
(***************************************************************************)
|
|
1128
|
+
(* \`. .' *)
|
|
1129
|
+
(* *)
|
|
1130
|
+
(* a..b is a finite set for any a,b \\in Int. *)
|
|
1131
|
+
(* *)
|
|
1132
|
+
(* \`. .' *)
|
|
1133
|
+
(***************************************************************************)
|
|
1134
|
+
THEOREM FS_Interval ==
|
|
1135
|
+
ASSUME NEW a \\in Int, NEW b \\in Int
|
|
1136
|
+
PROVE /\\ IsFiniteSet(a..b)
|
|
1137
|
+
/\\ Cardinality(a..b) = IF a > b THEN 0 ELSE b-a+1
|
|
1138
|
+
|
|
1139
|
+
THEOREM FS_BoundedSetOfNaturals ==
|
|
1140
|
+
ASSUME NEW S \\in SUBSET Nat, NEW n \\in Nat,
|
|
1141
|
+
\\A s \\in S : s <= n
|
|
1142
|
+
PROVE /\\ IsFiniteSet(S)
|
|
1143
|
+
/\\ Cardinality(S) \\leq n+1
|
|
1144
|
+
|
|
1145
|
+
|
|
1146
|
+
(***************************************************************************)
|
|
1147
|
+
(* \`. .' *)
|
|
1148
|
+
(* *)
|
|
1149
|
+
(* Induction for finite sets. *)
|
|
1150
|
+
(* *)
|
|
1151
|
+
(* \`. .' *)
|
|
1152
|
+
(***************************************************************************)
|
|
1153
|
+
|
|
1154
|
+
THEOREM FS_Induction ==
|
|
1155
|
+
ASSUME NEW S, IsFiniteSet(S),
|
|
1156
|
+
NEW P(_), P({}),
|
|
1157
|
+
ASSUME NEW T \\in SUBSET S, IsFiniteSet(T), P(T), NEW x \\in S \\ T
|
|
1158
|
+
PROVE P(T \\cup {x})
|
|
1159
|
+
PROVE P(S)
|
|
1160
|
+
|
|
1161
|
+
|
|
1162
|
+
(***************************************************************************)
|
|
1163
|
+
(* \`. .' *)
|
|
1164
|
+
(* *)
|
|
1165
|
+
(* The finite subsets form a well-founded ordering with respect to strict *)
|
|
1166
|
+
(* set inclusion. *)
|
|
1167
|
+
(* *)
|
|
1168
|
+
(* \`. .' *)
|
|
1169
|
+
(***************************************************************************)
|
|
1170
|
+
|
|
1171
|
+
FiniteSubsetsOf(S) == { T \\in SUBSET S : IsFiniteSet(T) }
|
|
1172
|
+
StrictSubsetOrdering(S) == { ss \\in (SUBSET S) \\X (SUBSET S) :
|
|
1173
|
+
ss[1] \\subseteq ss[2] /\\ ss[1] # ss[2] }
|
|
1174
|
+
|
|
1175
|
+
LEMMA FS_FiniteSubsetsOfFinite ==
|
|
1176
|
+
ASSUME NEW S, IsFiniteSet(S)
|
|
1177
|
+
PROVE FiniteSubsetsOf(S) = SUBSET S
|
|
1178
|
+
|
|
1179
|
+
|
|
1180
|
+
(*****************************************************************************)
|
|
1181
|
+
(* The formulation of the following theorem doesn't require S being finite. *)
|
|
1182
|
+
(* If S is finite, it implies *)
|
|
1183
|
+
(* IsWellFoundedOn(StrictSubsetOrdering(S), SUBSET S) *)
|
|
1184
|
+
(* using lemma FS_FiniteSubsetsOfFinite. *)
|
|
1185
|
+
(*****************************************************************************)
|
|
1186
|
+
THEOREM FS_StrictSubsetOrderingWellFounded ==
|
|
1187
|
+
ASSUME NEW S
|
|
1188
|
+
PROVE IsWellFoundedOn(StrictSubsetOrdering(S), FiniteSubsetsOf(S))
|
|
1189
|
+
|
|
1190
|
+
|
|
1191
|
+
(***************************************************************************)
|
|
1192
|
+
(* \`. .' *)
|
|
1193
|
+
(* *)
|
|
1194
|
+
(* Well-founded induction for finite subsets. *)
|
|
1195
|
+
(* *)
|
|
1196
|
+
(* \`. .' *)
|
|
1197
|
+
(***************************************************************************)
|
|
1198
|
+
|
|
1199
|
+
THEOREM FS_WFInduction ==
|
|
1200
|
+
ASSUME NEW P(_), NEW S, IsFiniteSet(S),
|
|
1201
|
+
ASSUME NEW T \\in SUBSET S,
|
|
1202
|
+
\\A U \\in (SUBSET T) \\ {T} : P(U)
|
|
1203
|
+
PROVE P(T)
|
|
1204
|
+
PROVE P(S)
|
|
1205
|
+
|
|
1206
|
+
|
|
1207
|
+
(***************************************************************************)
|
|
1208
|
+
(* \`. .' *)
|
|
1209
|
+
(* *)
|
|
1210
|
+
(* The union of two finite sets is finite. *)
|
|
1211
|
+
(* *)
|
|
1212
|
+
(* \`. .' *)
|
|
1213
|
+
(***************************************************************************)
|
|
1214
|
+
THEOREM FS_Union ==
|
|
1215
|
+
ASSUME NEW S, IsFiniteSet(S),
|
|
1216
|
+
NEW T, IsFiniteSet(T)
|
|
1217
|
+
PROVE /\\ IsFiniteSet(S \\cup T)
|
|
1218
|
+
/\\ Cardinality(S \\cup T) =
|
|
1219
|
+
Cardinality(S) + Cardinality(T) - Cardinality(S \\cap T)
|
|
1220
|
+
|
|
1221
|
+
|
|
1222
|
+
(***************************************************************************)
|
|
1223
|
+
(* \`. .' *)
|
|
1224
|
+
(* *)
|
|
1225
|
+
(* Corollary: two majorities intersect. More precisely, any two subsets *)
|
|
1226
|
+
(* of a finite set U such that the sum of cardinalities of the subsets *)
|
|
1227
|
+
(* exceeds that of U must have non-empty intersection. *)
|
|
1228
|
+
(* *)
|
|
1229
|
+
(* \`. .' *)
|
|
1230
|
+
(***************************************************************************)
|
|
1231
|
+
THEOREM FS_MajoritiesIntersect ==
|
|
1232
|
+
ASSUME NEW U, NEW S, NEW T, IsFiniteSet(U),
|
|
1233
|
+
S \\subseteq U, T \\subseteq U,
|
|
1234
|
+
Cardinality(S) + Cardinality(T) > Cardinality(U)
|
|
1235
|
+
PROVE S \\cap T # {}
|
|
1236
|
+
|
|
1237
|
+
|
|
1238
|
+
(***************************************************************************)
|
|
1239
|
+
(* \`. .' *)
|
|
1240
|
+
(* *)
|
|
1241
|
+
(* The intersection of a finite set with an arbitrary set is finite. *)
|
|
1242
|
+
(* *)
|
|
1243
|
+
(* \`. .' *)
|
|
1244
|
+
(***************************************************************************)
|
|
1245
|
+
|
|
1246
|
+
|
|
1247
|
+
THEOREM FS_Intersection ==
|
|
1248
|
+
ASSUME NEW S, IsFiniteSet(S), NEW T
|
|
1249
|
+
PROVE /\\ IsFiniteSet(S \\cap T)
|
|
1250
|
+
/\\ IsFiniteSet(T \\cap S)
|
|
1251
|
+
/\\ Cardinality(S \\cap T) <= Cardinality(S)
|
|
1252
|
+
/\\ Cardinality(T \\cap S) <= Cardinality(S)
|
|
1253
|
+
|
|
1254
|
+
|
|
1255
|
+
(***************************************************************************)
|
|
1256
|
+
(* \`. .' *)
|
|
1257
|
+
(* *)
|
|
1258
|
+
(* The difference between a finite set and an arbitrary set is finite. *)
|
|
1259
|
+
(* *)
|
|
1260
|
+
(* \`. .' *)
|
|
1261
|
+
(***************************************************************************)
|
|
1262
|
+
THEOREM FS_Difference ==
|
|
1263
|
+
ASSUME NEW S, NEW T, IsFiniteSet(S)
|
|
1264
|
+
PROVE /\\ IsFiniteSet(S \\ T)
|
|
1265
|
+
/\\ Cardinality(S \\ T) = Cardinality(S) - Cardinality(S \\cap T)
|
|
1266
|
+
|
|
1267
|
+
|
|
1268
|
+
(***************************************************************************)
|
|
1269
|
+
(* \`. .' *)
|
|
1270
|
+
(* *)
|
|
1271
|
+
(* The union of a finite number of finite sets is finite. *)
|
|
1272
|
+
(* *)
|
|
1273
|
+
(* \`. .' *)
|
|
1274
|
+
(***************************************************************************)
|
|
1275
|
+
THEOREM FS_UNION ==
|
|
1276
|
+
ASSUME NEW S, IsFiniteSet(S), \\A T \\in S : IsFiniteSet(T)
|
|
1277
|
+
PROVE IsFiniteSet(UNION S)
|
|
1278
|
+
|
|
1279
|
+
|
|
1280
|
+
(***************************************************************************)
|
|
1281
|
+
(* \`. .' *)
|
|
1282
|
+
(* *)
|
|
1283
|
+
(* The product of two finite sets is finite. *)
|
|
1284
|
+
(* *)
|
|
1285
|
+
(* \`. .' *)
|
|
1286
|
+
(***************************************************************************)
|
|
1287
|
+
THEOREM FS_Product ==
|
|
1288
|
+
ASSUME NEW S, IsFiniteSet(S),
|
|
1289
|
+
NEW T, IsFiniteSet(T)
|
|
1290
|
+
PROVE /\\ IsFiniteSet(S \\X T)
|
|
1291
|
+
/\\ Cardinality(S \\X T) = Cardinality(S) * Cardinality(T)
|
|
1292
|
+
|
|
1293
|
+
|
|
1294
|
+
(***************************************************************************)
|
|
1295
|
+
(* \`. .' *)
|
|
1296
|
+
(* *)
|
|
1297
|
+
(* The powerset of a finite set is finite. *)
|
|
1298
|
+
(* *)
|
|
1299
|
+
(* \`. .' *)
|
|
1300
|
+
(***************************************************************************)
|
|
1301
|
+
THEOREM FS_SUBSET ==
|
|
1302
|
+
ASSUME NEW S, IsFiniteSet(S)
|
|
1303
|
+
PROVE /\\ IsFiniteSet(SUBSET S)
|
|
1304
|
+
/\\ Cardinality(SUBSET S) = 2^Cardinality(S)
|
|
1305
|
+
|
|
1306
|
+
=============================================================================
|
|
1307
|
+
\\* Modification History
|
|
1308
|
+
\\* Last modified Wed Jan 08 17:43:30 CET 2020 by merz
|
|
1309
|
+
\\* Last modified Thu Jul 04 15:15:07 CEST 2013 by bhargav
|
|
1310
|
+
\\* Last modified Tue Jun 04 11:44:51 CEST 2013 by bhargav
|
|
1311
|
+
\\* Last modified Fri May 03 12:02:51 PDT 2013 by tomr
|
|
1312
|
+
\\* Created Fri Oct 05 15:04:18 PDT 2012 by tomr
|
|
1313
|
+
`,
|
|
1314
|
+
],
|
|
1315
|
+
[
|
|
1316
|
+
"Folds",
|
|
1317
|
+
`------------------------------- MODULE Folds -------------------------------
|
|
1318
|
+
(***************************************************************************)
|
|
1319
|
+
(* This module provides a general framework for folding operations over *)
|
|
1320
|
+
(* sets with flexible element selection and transformation. *)
|
|
1321
|
+
(* *)
|
|
1322
|
+
(* The main operator MapThenFoldSet is the foundation for many other *)
|
|
1323
|
+
(* folding operations found in: *)
|
|
1324
|
+
(* - FiniteSetsExt.FoldSet (simplified for sets) *)
|
|
1325
|
+
(* - Functions.FoldFunction (specialized for functions) *)
|
|
1326
|
+
(* - SequencesExt.FoldSeq (specialized for sequences) *)
|
|
1327
|
+
(* *)
|
|
1328
|
+
(***************************************************************************)
|
|
1329
|
+
|
|
1330
|
+
MapThenFoldSet(op(_,_), base, f(_), choose(_), S) ==
|
|
1331
|
+
(******************************************************************************)
|
|
1332
|
+
(* Starting from base, apply op to f(x), for all x \\in S, by choosing the set *)
|
|
1333
|
+
(* elements with \`choose\`. If there are multiple ways for choosing an element,*)
|
|
1334
|
+
(* op should be associative and commutative. Otherwise, the result may depend *)
|
|
1335
|
+
(* on the concrete implementation of \`choose\`. *)
|
|
1336
|
+
(* *)
|
|
1337
|
+
(* FoldSet, a simpler version for sets is contained in FiniteSetsEx. *)
|
|
1338
|
+
(* FoldFunction, a simpler version for functions is contained in Functions. *)
|
|
1339
|
+
(* FoldSequence, a simpler version for sequences is contained in SequencesExt.*)
|
|
1340
|
+
(* *)
|
|
1341
|
+
(* Example: *)
|
|
1342
|
+
(* *)
|
|
1343
|
+
(* MapThenFoldSet(LAMBDA x,y: x \\cup y, *)
|
|
1344
|
+
(* {}, *)
|
|
1345
|
+
(* LAMBDA x: {{x}}, *)
|
|
1346
|
+
(* LAMBDA set: CHOOSE x \\in set: TRUE, *)
|
|
1347
|
+
(* {1,2}) *)
|
|
1348
|
+
(* = {{1},{2}} *)
|
|
1349
|
+
(******************************************************************************)
|
|
1350
|
+
LET iter[s \\in SUBSET S] ==
|
|
1351
|
+
IF s = {} THEN base
|
|
1352
|
+
ELSE LET x == choose(s)
|
|
1353
|
+
IN op(f(x), iter[s \\ {x}])
|
|
1354
|
+
IN iter[S]
|
|
1355
|
+
|
|
1356
|
+
|
|
1357
|
+
=============================================================================
|
|
1358
|
+
`,
|
|
1359
|
+
],
|
|
1360
|
+
[
|
|
1361
|
+
"Functions",
|
|
1362
|
+
`------------------------------ MODULE Functions -----------------------------
|
|
1363
|
+
(***************************************************************************)
|
|
1364
|
+
(* \`^{\\large\\bf \\vspace{12pt} *)
|
|
1365
|
+
(* Notions about functions including injection, surjection, and bijection.*)
|
|
1366
|
+
(* Originally contributed by Tom Rodeheffer, MSR. *)
|
|
1367
|
+
(* \\vspace{12pt}}^' *)
|
|
1368
|
+
(***************************************************************************)
|
|
1369
|
+
|
|
1370
|
+
EXTENDS Integers, Folds
|
|
1371
|
+
|
|
1372
|
+
(***************************************************************************)
|
|
1373
|
+
(* Restriction of a function to a set (should be a subset of the domain). *)
|
|
1374
|
+
(***************************************************************************)
|
|
1375
|
+
Restrict(f,S) == [ x \\in S |-> f[x] ]
|
|
1376
|
+
|
|
1377
|
+
(***************************************************************************)
|
|
1378
|
+
(* Restriction of a function to the subset of its domain satisfying a *)
|
|
1379
|
+
(* test predicate. *)
|
|
1380
|
+
(* *)
|
|
1381
|
+
(* Example: *)
|
|
1382
|
+
(* (LET f == (0 :> "a" @@ 1 :> "b" @@ 2 :> "c") *)
|
|
1383
|
+
(* IN RestrictDomain(f, LAMBDA x : x \\in {0,2})) *)
|
|
1384
|
+
(* = (0 :> "a" @@ 2 :> "c") *)
|
|
1385
|
+
(***************************************************************************)
|
|
1386
|
+
RestrictDomain(f, Test(_)) == Restrict(f, {x \\in DOMAIN f : Test(x)})
|
|
1387
|
+
|
|
1388
|
+
(***************************************************************************)
|
|
1389
|
+
(* Restriction of a function to the subset of its domain for which the *)
|
|
1390
|
+
(* function values satisfy a test predicate. *)
|
|
1391
|
+
(* *)
|
|
1392
|
+
(* Example: *)
|
|
1393
|
+
(* (LET f == ("a" :> 0 @@ "b" :> 1 @@ "c" :> 2) *)
|
|
1394
|
+
(* IN RestrictValues(f, LAMBDA y : y \\in {0,2})) *)
|
|
1395
|
+
(* = ("a" :> 0 @@ "b" :> 2) *)
|
|
1396
|
+
(* *)
|
|
1397
|
+
(* This is similar to the operator SelectSeq from the standard Sequences *)
|
|
1398
|
+
(* module and related to standard "filter" functions in functional *)
|
|
1399
|
+
(* programming. However, SelectSeq produces sequences, whereas *)
|
|
1400
|
+
(* RestrictValues will in general not. For example, *)
|
|
1401
|
+
(* *)
|
|
1402
|
+
(* RestrictValues([0,1,2], LAMBDA y : y \\in {0,2}) *)
|
|
1403
|
+
(* = (1 :> 0 @@ 3 :> 2) *)
|
|
1404
|
+
(***************************************************************************)
|
|
1405
|
+
RestrictValues(f, Test(_)) ==
|
|
1406
|
+
LET S == {x \\in DOMAIN f : Test(f[x])}
|
|
1407
|
+
IN Restrict(f, S)
|
|
1408
|
+
|
|
1409
|
+
(***************************************************************************)
|
|
1410
|
+
(* Check if a function narrow is a restriction of a function wide, i.e. *)
|
|
1411
|
+
(* Is the domain of narrow a subset of that of wide, and does the *)
|
|
1412
|
+
(* projection of wide on the domain of narrow have the same image as *)
|
|
1413
|
+
(* narrow does. *)
|
|
1414
|
+
(* *)
|
|
1415
|
+
(* Examples: *)
|
|
1416
|
+
(* IsRestriction([one |-> 1], [one |-> 1, two |-> 2]) *)
|
|
1417
|
+
(* IsRestriction([one |-> 1], [one |-> 1]) *)
|
|
1418
|
+
(* ~IsRestriction([one |-> 1, two |-> 2], [one |-> 1, two |-> 3]) *)
|
|
1419
|
+
(* ~IsRestriction([one |-> 1], [2 |-> two]) *)
|
|
1420
|
+
(* ~IsRestriction([one |-> 1, two |-> 2], [two |-> 2]) *)
|
|
1421
|
+
(***************************************************************************)
|
|
1422
|
+
IsRestriction(narrow, wide) ==
|
|
1423
|
+
/\\ DOMAIN narrow \\subseteq DOMAIN wide
|
|
1424
|
+
/\\ \\A x \\in DOMAIN narrow \\intersect DOMAIN wide: narrow[x] = wide[x]
|
|
1425
|
+
|
|
1426
|
+
(***************************************************************************)
|
|
1427
|
+
(* Range of a function. *)
|
|
1428
|
+
(* Note: The image of a set under function f can be defined as *)
|
|
1429
|
+
(* Range(Restrict(f,S)). *)
|
|
1430
|
+
(***************************************************************************)
|
|
1431
|
+
Range(f) == { f[x] : x \\in DOMAIN f }
|
|
1432
|
+
|
|
1433
|
+
(***************************************************************************)
|
|
1434
|
+
(* Assuming DOMAIN f \\subseteq DOMAIN g, apply the binary operation T to *)
|
|
1435
|
+
(* the corresponding elements of the two functions f and g. *)
|
|
1436
|
+
(* *)
|
|
1437
|
+
(* Example: *)
|
|
1438
|
+
(* LET f == ("a" :> 0 @@ "b" :> 1 @@ "c" :> 2) *)
|
|
1439
|
+
(* g == ("a" :> 1 @@ "b" :> 1 @@ "c" :> 3) *)
|
|
1440
|
+
(* IN Pointwise(f,g,+) = ("a" :> 1 @@ "b" :> 2 @@ "c" :> 5 ) *)
|
|
1441
|
+
(***************************************************************************)
|
|
1442
|
+
Pointwise(f, g, T(_,_)) == [ e \\in DOMAIN f |-> T(f[e], g[e]) ]
|
|
1443
|
+
|
|
1444
|
+
(***************************************************************************)
|
|
1445
|
+
(* The inverse of a function. *)
|
|
1446
|
+
(* Example: *)
|
|
1447
|
+
(* LET f == ("a" :> 0 @@ "b" :> 1 @@ "c" :> 2) *)
|
|
1448
|
+
(* IN Inverse(f, DOMAIN f, Range(f)) = *)
|
|
1449
|
+
(* (0 :> "a" @@ 1 :> "b" @@ 2 :> "c") *)
|
|
1450
|
+
(* Example: *)
|
|
1451
|
+
(* LET f == ("a" :> 0 @@ "b" :> 1 @@ "c" :> 2) *)
|
|
1452
|
+
(* IN Inverse(f, DOMAIN f, {1,3}) = *)
|
|
1453
|
+
(* 1 :> "b" @@ 3 :> "a") *)
|
|
1454
|
+
(***************************************************************************)
|
|
1455
|
+
Inverse(f,S,T) == [t \\in T |-> CHOOSE s \\in S : t \\in Range(f) => f[s] = t]
|
|
1456
|
+
|
|
1457
|
+
(***************************************************************************)
|
|
1458
|
+
(* The inverse of a function. *)
|
|
1459
|
+
(***************************************************************************)
|
|
1460
|
+
AntiFunction(f) == Inverse(f, DOMAIN f, Range(f))
|
|
1461
|
+
|
|
1462
|
+
(***************************************************************************)
|
|
1463
|
+
(* A function is injective iff it maps each element in its domain to a *)
|
|
1464
|
+
(* distinct element. *)
|
|
1465
|
+
(* *)
|
|
1466
|
+
(* This definition is overridden by TLC in the Java class Functions.java *)
|
|
1467
|
+
(* The operator is overridden by the Java method with the same name. *)
|
|
1468
|
+
(***************************************************************************)
|
|
1469
|
+
IsInjective(f) == \\A a,b \\in DOMAIN f : f[a] = f[b] => a = b
|
|
1470
|
+
|
|
1471
|
+
(***************************************************************************)
|
|
1472
|
+
(* Set of injections between two sets. *)
|
|
1473
|
+
(***************************************************************************)
|
|
1474
|
+
Injection(S,T) == { M \\in [S -> T] : IsInjective(M) }
|
|
1475
|
+
|
|
1476
|
+
|
|
1477
|
+
(***************************************************************************)
|
|
1478
|
+
(* A map is a surjection iff for each element in the range there is some *)
|
|
1479
|
+
(* element in the domain that maps to it. *)
|
|
1480
|
+
(***************************************************************************)
|
|
1481
|
+
Surjection(S,T) == { M \\in [S -> T] : \\A t \\in T : \\E s \\in S : M[s] = t }
|
|
1482
|
+
|
|
1483
|
+
|
|
1484
|
+
(***************************************************************************)
|
|
1485
|
+
(* A map is a bijection iff it is both an injection and a surjection. *)
|
|
1486
|
+
(***************************************************************************)
|
|
1487
|
+
Bijection(S,T) == Injection(S,T) \\cap Surjection(S,T)
|
|
1488
|
+
|
|
1489
|
+
|
|
1490
|
+
(***************************************************************************)
|
|
1491
|
+
(* An injection, surjection, or bijection exists if the corresponding set *)
|
|
1492
|
+
(* is nonempty. *)
|
|
1493
|
+
(***************************************************************************)
|
|
1494
|
+
ExistsInjection(S,T) == Injection(S,T) # {}
|
|
1495
|
+
ExistsSurjection(S,T) == Surjection(S,T) # {}
|
|
1496
|
+
ExistsBijection(S,T) == Bijection(S,T) # {}
|
|
1497
|
+
|
|
1498
|
+
--------------------------------------------------------------------------------
|
|
1499
|
+
|
|
1500
|
+
(***************************************************************************)
|
|
1501
|
+
(* Applies the binary operator op on the elements f[i] for i \\in indices, *)
|
|
1502
|
+
(* a subset of DOMAIN f, in an unspecified order, starting from value *)
|
|
1503
|
+
(* base. The result is *)
|
|
1504
|
+
(* op(f[i],op(f[j], ..., op(f[k],base) ...)) *)
|
|
1505
|
+
(* where i,j,k range over the sets indices. *)
|
|
1506
|
+
(* *)
|
|
1507
|
+
(* op should be associative and commutative, because we can not assume a *)
|
|
1508
|
+
(* particular ordering of i, j, and k *)
|
|
1509
|
+
(* *)
|
|
1510
|
+
(* Example: *)
|
|
1511
|
+
(* FoldFunctionOnSet(LAMBDA x,y: {x} \\cup y, {}, <<1,2>>, {}) = {} *)
|
|
1512
|
+
(***************************************************************************)
|
|
1513
|
+
FoldFunctionOnSet(op(_,_), base, fun, indices) ==
|
|
1514
|
+
MapThenFoldSet(op, base, LAMBDA i : fun[i], LAMBDA s: CHOOSE x \\in s : TRUE, indices)
|
|
1515
|
+
|
|
1516
|
+
(***************************************************************************)
|
|
1517
|
+
(* Special case of the above where indices = DOMAIN fun. In other words, *)
|
|
1518
|
+
(* the values f[i] for all i \\in DOMAIN fun, are combined using the binary *)
|
|
1519
|
+
(* operator op, in an unspecified order. *)
|
|
1520
|
+
(* *)
|
|
1521
|
+
(* Example: *)
|
|
1522
|
+
(* FoldFunction(LAMBDA x,y: {x} \\cup y, {}, <<1,2,1>>) = {1,2} *)
|
|
1523
|
+
(***************************************************************************)
|
|
1524
|
+
FoldFunction(op(_,_), base, fun) ==
|
|
1525
|
+
FoldFunctionOnSet(op, base, fun, DOMAIN fun)
|
|
1526
|
+
|
|
1527
|
+
(***************************************************************************)
|
|
1528
|
+
(* Sum the values f[i] for i \\in indices, a subset of DOMAIN f. *)
|
|
1529
|
+
(* *)
|
|
1530
|
+
(* Example: *)
|
|
1531
|
+
(* SumFunctionOnSet(<<4,5,6>>, {1,2}) = 9 *)
|
|
1532
|
+
(* SumFunction(<<4,5,6>>) = 15 *)
|
|
1533
|
+
(***************************************************************************)
|
|
1534
|
+
SumFunctionOnSet(fun, indices) == FoldFunctionOnSet(+, 0, fun, indices)
|
|
1535
|
+
SumFunction(fun) == SumFunctionOnSet(fun, DOMAIN fun)
|
|
1536
|
+
|
|
1537
|
+
=============================================================================
|
|
1538
|
+
\\* Created Thu Apr 11 10:30:48 PDT 2013 by tomr
|
|
1539
|
+
`,
|
|
1540
|
+
],
|
|
1541
|
+
[
|
|
1542
|
+
"FunctionTheorems",
|
|
1543
|
+
`------------------------ MODULE FunctionTheorems ----------------------------
|
|
1544
|
+
(***************************************************************************)
|
|
1545
|
+
(* \`^{\\large \\vspace{12pt} *)
|
|
1546
|
+
(* Proofs of facts about functions. *)
|
|
1547
|
+
(* Originally contributed by Tom Rodeheffer, MSR. *)
|
|
1548
|
+
(* \\vspace{12pt}}^' *)
|
|
1549
|
+
(***************************************************************************)
|
|
1550
|
+
|
|
1551
|
+
EXTENDS Functions, Integers, FiniteSets
|
|
1552
|
+
|
|
1553
|
+
(***************************************************************************)
|
|
1554
|
+
(* \`. .' *)
|
|
1555
|
+
(* *)
|
|
1556
|
+
(* Function restriction. *)
|
|
1557
|
+
(* *)
|
|
1558
|
+
(* \`. .' *)
|
|
1559
|
+
(***************************************************************************)
|
|
1560
|
+
THEOREM Fun_RestrictProperties ==
|
|
1561
|
+
ASSUME NEW S, NEW T, NEW f \\in [S -> T], NEW A \\in SUBSET S
|
|
1562
|
+
PROVE /\\ Restrict(f,A) \\in [A -> T]
|
|
1563
|
+
/\\ \\A x \\in A : Restrict(f,A)[x] = f[x]
|
|
1564
|
+
|
|
1565
|
+
(***************************************************************************)
|
|
1566
|
+
(* \`. .' *)
|
|
1567
|
+
(* *)
|
|
1568
|
+
(* Range of a function. *)
|
|
1569
|
+
(* *)
|
|
1570
|
+
(* \`. .' *)
|
|
1571
|
+
(***************************************************************************)
|
|
1572
|
+
THEOREM Fun_RangeProperties ==
|
|
1573
|
+
ASSUME NEW S, NEW T, NEW f \\in [S -> T]
|
|
1574
|
+
PROVE /\\ Range(f) \\subseteq T
|
|
1575
|
+
/\\ \\A y \\in Range(f) : \\E x \\in S : f[x] = y
|
|
1576
|
+
/\\ f \\in Surjection(S, Range(f))
|
|
1577
|
+
|
|
1578
|
+
|
|
1579
|
+
(***************************************************************************)
|
|
1580
|
+
(* \`. .' *)
|
|
1581
|
+
(* *)
|
|
1582
|
+
(* Inverse of a function. *)
|
|
1583
|
+
(* *)
|
|
1584
|
+
(* \`. .' *)
|
|
1585
|
+
(***************************************************************************)
|
|
1586
|
+
THEOREM Fun_InverseProperties ==
|
|
1587
|
+
ASSUME NEW S, NEW T, NEW f \\in [S -> T]
|
|
1588
|
+
PROVE /\\ (S = {} => T = {}) => Inverse(f,S,T) \\in [T -> S]
|
|
1589
|
+
/\\ \\A y \\in Range(f) : f[Inverse(f,S,T)[y]] = y
|
|
1590
|
+
|
|
1591
|
+
|
|
1592
|
+
(***************************************************************************)
|
|
1593
|
+
(* \`. .' *)
|
|
1594
|
+
(* *)
|
|
1595
|
+
(* Introduction rules for injections, surjections, bijections. *)
|
|
1596
|
+
(* *)
|
|
1597
|
+
(* \`. .' *)
|
|
1598
|
+
(***************************************************************************)
|
|
1599
|
+
THEOREM Fun_IsInj ==
|
|
1600
|
+
ASSUME NEW S, NEW T, NEW F \\in [S -> T],
|
|
1601
|
+
\\A a,b \\in S : F[a] = F[b] => a = b
|
|
1602
|
+
PROVE F \\in Injection(S,T)
|
|
1603
|
+
|
|
1604
|
+
THEOREM Fun_IsSurj ==
|
|
1605
|
+
ASSUME NEW S, NEW T, NEW F \\in [S -> T],
|
|
1606
|
+
\\A t \\in T : \\E s \\in S : F[s] = t
|
|
1607
|
+
PROVE F \\in Surjection(S,T)
|
|
1608
|
+
|
|
1609
|
+
THEOREM Fun_IsBij ==
|
|
1610
|
+
ASSUME NEW S, NEW T, NEW F,
|
|
1611
|
+
\\/ F \\in Injection(S,T)
|
|
1612
|
+
\\/ (F \\in [S -> T] /\\ \\A a,b \\in S : F[a] = F[b] => a = b),
|
|
1613
|
+
|
|
1614
|
+
\\/ F \\in Surjection(S,T)
|
|
1615
|
+
\\/ (F \\in [S -> T] /\\ \\A t \\in T : \\E s \\in S : F[s] = t)
|
|
1616
|
+
PROVE F \\in Bijection(S,T)
|
|
1617
|
+
|
|
1618
|
+
|
|
1619
|
+
|
|
1620
|
+
(***************************************************************************)
|
|
1621
|
+
(* \`. .' *)
|
|
1622
|
+
(* *)
|
|
1623
|
+
(* Properties of injections, surjections, and bijections. *)
|
|
1624
|
+
(* *)
|
|
1625
|
+
(* \`. .' *)
|
|
1626
|
+
(***************************************************************************)
|
|
1627
|
+
THEOREM Fun_InjectionProperties ==
|
|
1628
|
+
ASSUME NEW S, NEW T, NEW F \\in Injection(S,T)
|
|
1629
|
+
PROVE /\\ F \\in [S -> T]
|
|
1630
|
+
/\\ \\A a,b \\in S : F[a] = F[b] => a = b
|
|
1631
|
+
|
|
1632
|
+
THEOREM Fun_SurjectionProperties ==
|
|
1633
|
+
ASSUME NEW S, NEW T, NEW F \\in Surjection(S,T)
|
|
1634
|
+
PROVE /\\ F \\in [S -> T]
|
|
1635
|
+
/\\ \\A t \\in T : \\E s \\in S : F[s] = t
|
|
1636
|
+
/\\ Range(F) = T
|
|
1637
|
+
|
|
1638
|
+
THEOREM Fun_BijectionProperties ==
|
|
1639
|
+
ASSUME NEW S, NEW T, NEW F \\in Bijection(S,T)
|
|
1640
|
+
PROVE /\\ F \\in [S -> T]
|
|
1641
|
+
/\\ F \\in Injection(S,T)
|
|
1642
|
+
/\\ F \\in Surjection(S,T)
|
|
1643
|
+
/\\ \\A a,b \\in S : F[a] = F[b] => a = b
|
|
1644
|
+
/\\ \\A t \\in T : \\E s \\in S : F[s] = t
|
|
1645
|
+
|
|
1646
|
+
|
|
1647
|
+
(***************************************************************************)
|
|
1648
|
+
(* \`. .' *)
|
|
1649
|
+
(* *)
|
|
1650
|
+
(* A surjection in [S -> T] such that there is no surjection from any *)
|
|
1651
|
+
(* subset of S to T is a bijection. *)
|
|
1652
|
+
(* *)
|
|
1653
|
+
(* \`. .' *)
|
|
1654
|
+
(***************************************************************************)
|
|
1655
|
+
THEOREM Fun_SmallestSurjectionIsBijection ==
|
|
1656
|
+
ASSUME NEW S, NEW T, NEW f \\in Surjection(S,T),
|
|
1657
|
+
\\A U \\in SUBSET S : U # S => Surjection(U,T) = {}
|
|
1658
|
+
PROVE f \\in Bijection(S,T)
|
|
1659
|
+
|
|
1660
|
+
|
|
1661
|
+
(***************************************************************************)
|
|
1662
|
+
(* \`. .' *)
|
|
1663
|
+
(* *)
|
|
1664
|
+
(* Transitivity of injections, surjections, bijections. *)
|
|
1665
|
+
(* *)
|
|
1666
|
+
(* \`. .' *)
|
|
1667
|
+
(***************************************************************************)
|
|
1668
|
+
THEOREM Fun_InjTransitive ==
|
|
1669
|
+
ASSUME NEW S, NEW T, NEW U,
|
|
1670
|
+
NEW F \\in Injection(S,T),
|
|
1671
|
+
NEW G \\in Injection(T,U)
|
|
1672
|
+
PROVE [s \\in S |-> G[F[s]]] \\in Injection(S,U)
|
|
1673
|
+
|
|
1674
|
+
THEOREM Fun_SurjTransitive ==
|
|
1675
|
+
ASSUME NEW S, NEW T, NEW U,
|
|
1676
|
+
NEW F \\in Surjection(S,T),
|
|
1677
|
+
NEW G \\in Surjection(T,U)
|
|
1678
|
+
PROVE [s \\in S |-> G[F[s]]] \\in Surjection(S,U)
|
|
1679
|
+
|
|
1680
|
+
THEOREM Fun_BijTransitive ==
|
|
1681
|
+
ASSUME NEW S, NEW T, NEW U,
|
|
1682
|
+
NEW F \\in Bijection(S,T),
|
|
1683
|
+
NEW G \\in Bijection(T,U)
|
|
1684
|
+
PROVE [s \\in S |-> G[F[s]]] \\in Bijection(S,U)
|
|
1685
|
+
|
|
1686
|
+
|
|
1687
|
+
(***************************************************************************)
|
|
1688
|
+
(* \`. .' *)
|
|
1689
|
+
(* *)
|
|
1690
|
+
(* The inverse of a surjection is an injection and vice versa. *)
|
|
1691
|
+
(* *)
|
|
1692
|
+
(* \`. .' *)
|
|
1693
|
+
(***************************************************************************)
|
|
1694
|
+
THEOREM Fun_SurjInverse ==
|
|
1695
|
+
ASSUME NEW S, NEW T, NEW f \\in Surjection(S,T)
|
|
1696
|
+
PROVE Inverse(f,S,T) \\in Injection(T,S)
|
|
1697
|
+
|
|
1698
|
+
THEOREM Fun_InjInverse ==
|
|
1699
|
+
ASSUME NEW S, NEW T, NEW f \\in Injection(S,T), S = {} => T = {}
|
|
1700
|
+
PROVE Inverse(f,S,T) \\in Surjection(T,S)
|
|
1701
|
+
|
|
1702
|
+
|
|
1703
|
+
(***************************************************************************)
|
|
1704
|
+
(* \`. .' *)
|
|
1705
|
+
(* *)
|
|
1706
|
+
(* Properties of the inverse of a bijection. *)
|
|
1707
|
+
(* *)
|
|
1708
|
+
(* \`. .' *)
|
|
1709
|
+
(***************************************************************************)
|
|
1710
|
+
THEOREM Fun_BijInverse ==
|
|
1711
|
+
ASSUME NEW S, NEW T, NEW f \\in Bijection(S,T)
|
|
1712
|
+
PROVE /\\ Inverse(f,S,T) \\in Bijection(T,S)
|
|
1713
|
+
/\\ \\A s \\in S : Inverse(f,S,T)[f[s]] = s
|
|
1714
|
+
/\\ Inverse(Inverse(f,S,T), T,S) = f
|
|
1715
|
+
|
|
1716
|
+
(***************************************************************************)
|
|
1717
|
+
(* We cannot conclude that a function f is a bijection if its inverse is *)
|
|
1718
|
+
(* a bijection, and the following is a counter-example. *)
|
|
1719
|
+
(* *)
|
|
1720
|
+
(* S = {1,2} T = {3,4} *)
|
|
1721
|
+
(* f = [x \\in S |-> 3] *)
|
|
1722
|
+
(* *)
|
|
1723
|
+
(* Then, Inverse(f,S,T) can very well be (3 :> 1) @@ (4 :> 2), which is a *)
|
|
1724
|
+
(* bijection although f is not. *)
|
|
1725
|
+
(***************************************************************************)
|
|
1726
|
+
|
|
1727
|
+
(***************************************************************************)
|
|
1728
|
+
(* \`. .' *)
|
|
1729
|
+
(* *)
|
|
1730
|
+
(* The restriction of a bijection is a bijection. *)
|
|
1731
|
+
(* *)
|
|
1732
|
+
(* \`. .' *)
|
|
1733
|
+
(***************************************************************************)
|
|
1734
|
+
THEOREM Fun_BijRestrict ==
|
|
1735
|
+
ASSUME NEW S, NEW T, NEW F \\in Bijection(S,T),
|
|
1736
|
+
NEW R \\in SUBSET S
|
|
1737
|
+
PROVE Restrict(F, R) \\in Bijection(R, Range(Restrict(F, R)))
|
|
1738
|
+
|
|
1739
|
+
|
|
1740
|
+
(***************************************************************************)
|
|
1741
|
+
(* \`. .' *)
|
|
1742
|
+
(* *)
|
|
1743
|
+
(* Given F an injection from S to T, then F is a bijection from S to F(S). *)
|
|
1744
|
+
(* *)
|
|
1745
|
+
(* \`. .' *)
|
|
1746
|
+
(***************************************************************************)
|
|
1747
|
+
THEOREM Fun_InjMeansBijImage ==
|
|
1748
|
+
ASSUME NEW S, NEW T, NEW F \\in Injection(S,T)
|
|
1749
|
+
PROVE F \\in Bijection(S, Range(F))
|
|
1750
|
+
|
|
1751
|
+
|
|
1752
|
+
-----------------------------------------------------------------------------
|
|
1753
|
+
(***************************************************************************)
|
|
1754
|
+
(* \`^{\\large \\vspace{12pt} *)
|
|
1755
|
+
(* Facts about exists jections. *)
|
|
1756
|
+
(* \\vspace{12pt}}^' *)
|
|
1757
|
+
(***************************************************************************)
|
|
1758
|
+
|
|
1759
|
+
|
|
1760
|
+
|
|
1761
|
+
(***************************************************************************)
|
|
1762
|
+
(* \`. .' *)
|
|
1763
|
+
(* *)
|
|
1764
|
+
(* Definitions restated as facts. *)
|
|
1765
|
+
(* *)
|
|
1766
|
+
(* \`. .' *)
|
|
1767
|
+
(***************************************************************************)
|
|
1768
|
+
THEOREM Fun_ExistsInj ==
|
|
1769
|
+
\\A S,T : ExistsInjection(S,T) <=> Injection(S,T) # {}
|
|
1770
|
+
|
|
1771
|
+
THEOREM Fun_ExistsSurj ==
|
|
1772
|
+
\\A S,T : ExistsSurjection(S,T) <=> Surjection(S,T) # {}
|
|
1773
|
+
|
|
1774
|
+
THEOREM Fun_ExistsBij ==
|
|
1775
|
+
\\A S,T : ExistsBijection(S,T) <=> Bijection(S,T) # {}
|
|
1776
|
+
|
|
1777
|
+
|
|
1778
|
+
(***************************************************************************)
|
|
1779
|
+
(* \`. .' *)
|
|
1780
|
+
(* *)
|
|
1781
|
+
(* There is a surjection from any set S to any non-empty subset T of S. *)
|
|
1782
|
+
(* (Note that there cannot be a surjection to {} except if S is empty.) *)
|
|
1783
|
+
(* *)
|
|
1784
|
+
(* \`. .' *)
|
|
1785
|
+
(***************************************************************************)
|
|
1786
|
+
THEOREM Fun_ExistsSurjSubset ==
|
|
1787
|
+
ASSUME NEW S, NEW T \\in SUBSET S, T # {}
|
|
1788
|
+
PROVE ExistsSurjection(S,T)
|
|
1789
|
+
|
|
1790
|
+
|
|
1791
|
+
(***************************************************************************)
|
|
1792
|
+
(* \`. .' *)
|
|
1793
|
+
(* *)
|
|
1794
|
+
(* If there is a surjection from S to T, then there is an injection from T *)
|
|
1795
|
+
(* to S. *)
|
|
1796
|
+
(* *)
|
|
1797
|
+
(* \`. .' *)
|
|
1798
|
+
(***************************************************************************)
|
|
1799
|
+
THEOREM Fun_ExistsSurjMeansExistsRevInj ==
|
|
1800
|
+
ASSUME NEW S, NEW T, ExistsSurjection(S,T)
|
|
1801
|
+
PROVE ExistsInjection(T,S)
|
|
1802
|
+
|
|
1803
|
+
|
|
1804
|
+
(***************************************************************************)
|
|
1805
|
+
(* \`. .' *)
|
|
1806
|
+
(* *)
|
|
1807
|
+
(* ExistsBijection is reflexive, symmetric, and transitive. *)
|
|
1808
|
+
(* *)
|
|
1809
|
+
(* \`. .' *)
|
|
1810
|
+
(***************************************************************************)
|
|
1811
|
+
THEOREM Fun_ExistsBijReflexive ==
|
|
1812
|
+
ASSUME NEW S
|
|
1813
|
+
PROVE ExistsBijection(S,S)
|
|
1814
|
+
|
|
1815
|
+
THEOREM Fun_ExistsBijSymmetric ==
|
|
1816
|
+
ASSUME NEW S, NEW T, ExistsBijection(S,T)
|
|
1817
|
+
PROVE ExistsBijection(T,S)
|
|
1818
|
+
|
|
1819
|
+
THEOREM Fun_ExistsBijTransitive ==
|
|
1820
|
+
ASSUME NEW S, NEW T, NEW U, ExistsBijection(S,T), ExistsBijection(T,U)
|
|
1821
|
+
PROVE ExistsBijection(S,U)
|
|
1822
|
+
|
|
1823
|
+
|
|
1824
|
+
(***************************************************************************)
|
|
1825
|
+
(* \`. .' *)
|
|
1826
|
+
(* *)
|
|
1827
|
+
(* Existence of injections and surjections is reflexive and transitive. *)
|
|
1828
|
+
(* *)
|
|
1829
|
+
(* \`. .' *)
|
|
1830
|
+
(***************************************************************************)
|
|
1831
|
+
THEOREM Fun_ExistsInjReflexive ==
|
|
1832
|
+
ASSUME NEW S
|
|
1833
|
+
PROVE ExistsInjection(S,S)
|
|
1834
|
+
|
|
1835
|
+
THEOREM Fun_ExistsSurjReflexive ==
|
|
1836
|
+
ASSUME NEW S
|
|
1837
|
+
PROVE ExistsSurjection(S,S)
|
|
1838
|
+
|
|
1839
|
+
THEOREM Fun_ExistsInjTransitive ==
|
|
1840
|
+
ASSUME NEW S, NEW T, NEW U,
|
|
1841
|
+
ExistsInjection(S,T), ExistsInjection(T,U)
|
|
1842
|
+
PROVE ExistsInjection(S,U)
|
|
1843
|
+
|
|
1844
|
+
THEOREM Fun_ExistsSurjTransitive ==
|
|
1845
|
+
ASSUME NEW S, NEW T, NEW U,
|
|
1846
|
+
ExistsSurjection(S,T), ExistsSurjection(T,U)
|
|
1847
|
+
PROVE ExistsSurjection(S,U)
|
|
1848
|
+
|
|
1849
|
+
|
|
1850
|
+
-----------------------------------------------------------------------------
|
|
1851
|
+
(***************************************************************************)
|
|
1852
|
+
(* \`^{\\large \\vspace{12pt} *)
|
|
1853
|
+
(* The Cantor-Bernstein-Schroeder theorem. *)
|
|
1854
|
+
(* \\vspace{12pt}}^' *)
|
|
1855
|
+
(***************************************************************************)
|
|
1856
|
+
|
|
1857
|
+
|
|
1858
|
+
(***************************************************************************)
|
|
1859
|
+
(* \`. .' *)
|
|
1860
|
+
(* *)
|
|
1861
|
+
(* If there exists an injection from S to T, where T is a subset of S, *)
|
|
1862
|
+
(* then there exists a bijection from S to T. *)
|
|
1863
|
+
(* *)
|
|
1864
|
+
(* A lemma for the Cantor-Bernstein-Schroeder theorem. *)
|
|
1865
|
+
(* *)
|
|
1866
|
+
(* This proof is formalized from *)
|
|
1867
|
+
(* \`^\\url{http://www.proofwiki.org/wiki/Cantor-Bernstein-Schroeder\\_Theorem/Lemma}^' *)
|
|
1868
|
+
(* retrieved April 29, 2013. *)
|
|
1869
|
+
(* *)
|
|
1870
|
+
(* \`. .' *)
|
|
1871
|
+
(***************************************************************************)
|
|
1872
|
+
THEOREM Fun_CantorBernsteinSchroeder_Lemma ==
|
|
1873
|
+
ASSUME NEW S, NEW T, T \\subseteq S, ExistsInjection(S,T)
|
|
1874
|
+
PROVE ExistsBijection(S,T)
|
|
1875
|
+
|
|
1876
|
+
|
|
1877
|
+
(***************************************************************************)
|
|
1878
|
+
(* \`. .' *)
|
|
1879
|
+
(* *)
|
|
1880
|
+
(* If an injection exists from S to T and an injection exists from T to S, *)
|
|
1881
|
+
(* then there is a bijection from S to T. *)
|
|
1882
|
+
(* *)
|
|
1883
|
+
(* This is the Cantor-Bernstein-Schroeder theorem. *)
|
|
1884
|
+
(* *)
|
|
1885
|
+
(* This proof is formalized from *)
|
|
1886
|
+
(* \`^\\url{http://www.proofwiki.org/wiki/Cantor-Bernstein-Schroeder_Theorem/Proof_5}^' *)
|
|
1887
|
+
(* retrieved April 29, 2013. *)
|
|
1888
|
+
(* *)
|
|
1889
|
+
(* \`. .' *)
|
|
1890
|
+
(***************************************************************************)
|
|
1891
|
+
THEOREM Fun_CantorBernsteinSchroeder ==
|
|
1892
|
+
ASSUME NEW S, NEW T,
|
|
1893
|
+
ExistsInjection(S,T), ExistsInjection(T,S)
|
|
1894
|
+
PROVE ExistsBijection(S,T)
|
|
1895
|
+
|
|
1896
|
+
|
|
1897
|
+
(***************************************************************************)
|
|
1898
|
+
(* \`. .' *)
|
|
1899
|
+
(* *)
|
|
1900
|
+
(* Applications of the Cantor-Bernstein-Schroeder Theorem. *)
|
|
1901
|
+
(* If there exists an injection f: A->B and a surjection g: A->B, then *)
|
|
1902
|
+
(* there exists a bijection between A and B. *)
|
|
1903
|
+
(* Also, if there are surjections between A and B, then there is a *)
|
|
1904
|
+
(* bijection. *)
|
|
1905
|
+
(* *)
|
|
1906
|
+
(* \`. .' *)
|
|
1907
|
+
(***************************************************************************)
|
|
1908
|
+
|
|
1909
|
+
THEOREM Fun_ExistInjAndSurjThenBij ==
|
|
1910
|
+
ASSUME NEW S, NEW T,
|
|
1911
|
+
ExistsInjection(S,T), ExistsSurjection(S,T)
|
|
1912
|
+
PROVE ExistsBijection(S,T)
|
|
1913
|
+
|
|
1914
|
+
THEOREM Fun_ExistSurjAndSurjThenBij ==
|
|
1915
|
+
ASSUME NEW S, NEW T,
|
|
1916
|
+
ExistsSurjection(S,T), ExistsSurjection(T,S)
|
|
1917
|
+
PROVE ExistsBijection(S,T)
|
|
1918
|
+
|
|
1919
|
+
|
|
1920
|
+
(***************************************************************************)
|
|
1921
|
+
(* \`. .' *)
|
|
1922
|
+
(* *)
|
|
1923
|
+
(* Equivalences for ExistsBijection. *)
|
|
1924
|
+
(* *)
|
|
1925
|
+
(* \`. .' *)
|
|
1926
|
+
(***************************************************************************)
|
|
1927
|
+
THEOREM Fun_ExistsBijEquiv ==
|
|
1928
|
+
ASSUME NEW S, NEW T
|
|
1929
|
+
PROVE /\\ ExistsBijection(S,T) <=> ExistsBijection(T,S)
|
|
1930
|
+
/\\ ExistsBijection(S,T) <=> ExistsInjection(S,T) /\\ ExistsInjection(T,S)
|
|
1931
|
+
/\\ ExistsBijection(S,T) <=> ExistsInjection(S,T) /\\ ExistsSurjection(S,T)
|
|
1932
|
+
/\\ ExistsBijection(S,T) <=> ExistsInjection(T,S) /\\ ExistsSurjection(T,S)
|
|
1933
|
+
/\\ ExistsBijection(S,T) <=> ExistsSurjection(S,T) /\\ ExistsSurjection(T,S)
|
|
1934
|
+
|
|
1935
|
+
|
|
1936
|
+
-----------------------------------------------------------------------------
|
|
1937
|
+
(***************************************************************************)
|
|
1938
|
+
(* \`^{\\large \\vspace{12pt} *)
|
|
1939
|
+
(* Facts about jections involving 1..n. *)
|
|
1940
|
+
(* \\vspace{12pt}}^' *)
|
|
1941
|
+
(***************************************************************************)
|
|
1942
|
+
|
|
1943
|
+
|
|
1944
|
+
(***************************************************************************)
|
|
1945
|
+
(* \`. .' *)
|
|
1946
|
+
(* *)
|
|
1947
|
+
(* There is a bijection from 1..b-a+1 to a..b for integers a,b with a <= b.*)
|
|
1948
|
+
(* *)
|
|
1949
|
+
(* \`. .' *)
|
|
1950
|
+
(***************************************************************************)
|
|
1951
|
+
THEOREM Fun_ExistsBijInterval ==
|
|
1952
|
+
ASSUME NEW a \\in Int, NEW b \\in Int, a <= b
|
|
1953
|
+
PROVE ExistsBijection(1 .. b-a+1, a .. b)
|
|
1954
|
+
|
|
1955
|
+
|
|
1956
|
+
(***************************************************************************)
|
|
1957
|
+
(* \`. .' *)
|
|
1958
|
+
(* *)
|
|
1959
|
+
(* There is an injection from 1..n to 1..m iff n \\leq m. *)
|
|
1960
|
+
(* *)
|
|
1961
|
+
(* \`. .' *)
|
|
1962
|
+
(***************************************************************************)
|
|
1963
|
+
THEOREM Fun_NatInjLeq ==
|
|
1964
|
+
ASSUME NEW n \\in Nat, NEW m \\in Nat
|
|
1965
|
+
PROVE ExistsInjection(1..n,1..m) <=> n \\leq m
|
|
1966
|
+
|
|
1967
|
+
|
|
1968
|
+
(***************************************************************************)
|
|
1969
|
+
(* \`. .' *)
|
|
1970
|
+
(* *)
|
|
1971
|
+
(* If a surjection from 1..n to S exists (for some n \\in Nat) then a *)
|
|
1972
|
+
(* bijection from 1..m to S exists (for some m \\in Nat) and m \\leq n. *)
|
|
1973
|
+
(* *)
|
|
1974
|
+
(* \`. .' *)
|
|
1975
|
+
(***************************************************************************)
|
|
1976
|
+
THEOREM Fun_NatSurjImpliesNatBij ==
|
|
1977
|
+
ASSUME NEW S, NEW n \\in Nat, ExistsSurjection(1..n,S)
|
|
1978
|
+
PROVE \\E m \\in Nat : ExistsBijection(1..m,S) /\\ m \\leq n
|
|
1979
|
+
|
|
1980
|
+
|
|
1981
|
+
(***************************************************************************)
|
|
1982
|
+
(* Simple corollary. *)
|
|
1983
|
+
(***************************************************************************)
|
|
1984
|
+
THEOREM Fun_NatSurjEquivNatBij ==
|
|
1985
|
+
ASSUME NEW S
|
|
1986
|
+
PROVE (\\E n \\in Nat : ExistsSurjection(1..n,S))
|
|
1987
|
+
<=> (\\E m \\in Nat : ExistsBijection(1..m,S))
|
|
1988
|
+
|
|
1989
|
+
|
|
1990
|
+
(***************************************************************************)
|
|
1991
|
+
(* \`. .' *)
|
|
1992
|
+
(* *)
|
|
1993
|
+
(* For any set S, given n, m \\in Nat such that bijections exist from 1..n *)
|
|
1994
|
+
(* to S and from 1..m to S, then it must be the case that n = m. *)
|
|
1995
|
+
(* *)
|
|
1996
|
+
(* \`. .' *)
|
|
1997
|
+
(***************************************************************************)
|
|
1998
|
+
THEOREM Fun_NatBijSame ==
|
|
1999
|
+
ASSUME NEW S,
|
|
2000
|
+
NEW n \\in Nat, ExistsBijection(1..n,S),
|
|
2001
|
+
NEW m \\in Nat, ExistsBijection(1..m,S)
|
|
2002
|
+
PROVE n = m
|
|
2003
|
+
|
|
2004
|
+
|
|
2005
|
+
(***************************************************************************)
|
|
2006
|
+
(* \`. .' *)
|
|
2007
|
+
(* *)
|
|
2008
|
+
(* S is empty iff there exists a bijection from 1..0 to S. *)
|
|
2009
|
+
(* *)
|
|
2010
|
+
(* \`. .' *)
|
|
2011
|
+
(***************************************************************************)
|
|
2012
|
+
THEOREM Fun_NatBijEmpty ==
|
|
2013
|
+
ASSUME NEW S
|
|
2014
|
+
PROVE ExistsBijection(1..0,S) <=> S = {}
|
|
2015
|
+
|
|
2016
|
+
|
|
2017
|
+
(***************************************************************************)
|
|
2018
|
+
(* \`. .' *)
|
|
2019
|
+
(* *)
|
|
2020
|
+
(* S is a singleton iff there exists a bijection from 1..1 to S. *)
|
|
2021
|
+
(* *)
|
|
2022
|
+
(* \`. .' *)
|
|
2023
|
+
(***************************************************************************)
|
|
2024
|
+
THEOREM Fun_NatBijSingleton ==
|
|
2025
|
+
ASSUME NEW S
|
|
2026
|
+
PROVE ExistsBijection(1..1,S) <=> \\E s : S = {s}
|
|
2027
|
+
|
|
2028
|
+
|
|
2029
|
+
(***************************************************************************)
|
|
2030
|
+
(* \`. .' *)
|
|
2031
|
+
(* *)
|
|
2032
|
+
(* If there exists a bijection from 1..m to S (for some m \\in Nat), then *)
|
|
2033
|
+
(* there exists a bijection from 1..n to T (for some n \\in Nat), where T *)
|
|
2034
|
+
(* is a subset of S. Furthermore n \\leq m. *)
|
|
2035
|
+
(* *)
|
|
2036
|
+
(* \`. .' *)
|
|
2037
|
+
(***************************************************************************)
|
|
2038
|
+
THEOREM Fun_NatBijSubset ==
|
|
2039
|
+
ASSUME NEW S, NEW m \\in Nat, ExistsBijection(1..m,S),
|
|
2040
|
+
NEW T \\in SUBSET S
|
|
2041
|
+
PROVE \\E n \\in Nat : ExistsBijection(1..n,T) /\\ n \\leq m
|
|
2042
|
+
|
|
2043
|
+
|
|
2044
|
+
(***************************************************************************)
|
|
2045
|
+
(* \`. .' *)
|
|
2046
|
+
(* *)
|
|
2047
|
+
(* If there exists a bijection from 1..m to S (for some m \\in Nat), then *)
|
|
2048
|
+
(* there exists a bijection from 1..(m+1) to S \\cup {x}, where x \\notin S. *)
|
|
2049
|
+
(* *)
|
|
2050
|
+
(* *)
|
|
2051
|
+
(* \`. .' *)
|
|
2052
|
+
(***************************************************************************)
|
|
2053
|
+
THEOREM Fun_NatBijAddElem ==
|
|
2054
|
+
ASSUME NEW S, NEW m \\in Nat, ExistsBijection(1..m,S),
|
|
2055
|
+
NEW x, x \\notin S
|
|
2056
|
+
PROVE ExistsBijection(1..(m+1), S \\cup {x})
|
|
2057
|
+
|
|
2058
|
+
|
|
2059
|
+
(***************************************************************************)
|
|
2060
|
+
(* \`. .' *)
|
|
2061
|
+
(* *)
|
|
2062
|
+
(* If there exists a bijection from 1..m to S (for some m \\in Nat), then *)
|
|
2063
|
+
(* there exists a bijection from 1..(m-1) to S \\ {x}, where x \\in S. *)
|
|
2064
|
+
(* *)
|
|
2065
|
+
(* *)
|
|
2066
|
+
(* \`. .' *)
|
|
2067
|
+
(***************************************************************************)
|
|
2068
|
+
THEOREM Fun_NatBijSubElem ==
|
|
2069
|
+
ASSUME NEW S, NEW m \\in Nat, ExistsBijection(1..m,S),
|
|
2070
|
+
NEW x, x \\in S
|
|
2071
|
+
PROVE ExistsBijection(1..(m-1), S \\ {x})
|
|
2072
|
+
|
|
2073
|
+
-----------------------------------------------------------------------------
|
|
2074
|
+
|
|
2075
|
+
(***************************************************************************)
|
|
2076
|
+
(* Folding a function for an empty set of indices yields the base value. *)
|
|
2077
|
+
(***************************************************************************)
|
|
2078
|
+
THEOREM FoldFunctionOnSetEmpty ==
|
|
2079
|
+
ASSUME NEW op(_,_), NEW base, NEW fun
|
|
2080
|
+
PROVE FoldFunctionOnSet(op, base, fun, {}) = base
|
|
2081
|
+
|
|
2082
|
+
(***************************************************************************)
|
|
2083
|
+
(* Folding a function for a non-empty set of indices corresponds to *)
|
|
2084
|
+
(* applying the binary operator to f[i], for some i \\in indices, and the *)
|
|
2085
|
+
(* result of recursing for the set indices \\ {i}. *)
|
|
2086
|
+
(***************************************************************************)
|
|
2087
|
+
THEOREM FoldFunctionOnSetNonempty ==
|
|
2088
|
+
ASSUME NEW op(_,_), NEW base, NEW fun,
|
|
2089
|
+
NEW indices, indices # {}, IsFiniteSet(indices)
|
|
2090
|
+
PROVE \\E i \\in indices : FoldFunctionOnSet(op, base, fun, indices) =
|
|
2091
|
+
op(fun[i], FoldFunctionOnSet(op, base, fun, indices \\ {i}))
|
|
2092
|
+
|
|
2093
|
+
(***************************************************************************)
|
|
2094
|
+
(* The type of folding a function corresponds to the type associated with *)
|
|
2095
|
+
(* the binary operator that underlies the fold. *)
|
|
2096
|
+
(***************************************************************************)
|
|
2097
|
+
THEOREM FoldFunctionOnSetType ==
|
|
2098
|
+
ASSUME NEW Typ, NEW op(_,_), NEW base \\in Typ,
|
|
2099
|
+
\\A t,u \\in Typ : op(t,u) \\in Typ,
|
|
2100
|
+
NEW indices, IsFiniteSet(indices), NEW fun,
|
|
2101
|
+
\\A i \\in indices : fun[i] \\in Typ
|
|
2102
|
+
PROVE FoldFunctionOnSet(op, base, fun, indices) \\in Typ
|
|
2103
|
+
|
|
2104
|
+
(***************************************************************************)
|
|
2105
|
+
(* Folding two functions that agree on every element of the set of indices *)
|
|
2106
|
+
(* yields the same value. *)
|
|
2107
|
+
(***************************************************************************)
|
|
2108
|
+
THEOREM FoldFunctionOnSetEqual ==
|
|
2109
|
+
ASSUME NEW op(_,_), NEW base, NEW f, NEW g,
|
|
2110
|
+
NEW indices, IsFiniteSet(indices),
|
|
2111
|
+
\\A i \\in indices : f[i] = g[i]
|
|
2112
|
+
PROVE FoldFunctionOnSet(op, base, f, indices) =
|
|
2113
|
+
FoldFunctionOnSet(op, base, g, indices)
|
|
2114
|
+
|
|
2115
|
+
(***************************************************************************)
|
|
2116
|
+
(* If the binary operator is associative and commutative, the result of *)
|
|
2117
|
+
(* folding a function over a non-empty set corresponds to applying the *)
|
|
2118
|
+
(* operator to an arbitrary element of the set and the result of folding *)
|
|
2119
|
+
(* the function over the remainder of the set. *)
|
|
2120
|
+
(***************************************************************************)
|
|
2121
|
+
THEOREM FoldFunctionOnSetAC ==
|
|
2122
|
+
ASSUME NEW Typ, NEW op(_,_), NEW base \\in Typ,
|
|
2123
|
+
\\A t,u \\in Typ : op(t,u) \\in Typ,
|
|
2124
|
+
\\A t,u \\in Typ : op(t,u) = op(u,t),
|
|
2125
|
+
\\A t,u,v \\in Typ : op(t, op(u,v)) = op(op(t,u),v),
|
|
2126
|
+
NEW indices, IsFiniteSet(indices), NEW i \\in indices, NEW fun,
|
|
2127
|
+
\\A j \\in indices : fun[j] \\in Typ
|
|
2128
|
+
PROVE FoldFunctionOnSet(op, base, fun, indices) =
|
|
2129
|
+
op(fun[i], FoldFunctionOnSet(op, base, fun, indices \\ {i}))
|
|
2130
|
+
|
|
2131
|
+
\\* reformulation in terms of adding an index to the set
|
|
2132
|
+
THEOREM FoldFunctionOnSetACAddIndex ==
|
|
2133
|
+
ASSUME NEW Typ, NEW op(_,_), NEW base \\in Typ,
|
|
2134
|
+
\\A t,u \\in Typ : op(t,u) \\in Typ,
|
|
2135
|
+
\\A t,u \\in Typ : op(t,u) = op(u,t),
|
|
2136
|
+
\\A t,u,v \\in Typ : op(t, op(u,v)) = op(op(t,u),v),
|
|
2137
|
+
NEW indices, IsFiniteSet(indices), NEW i, i \\notin indices,
|
|
2138
|
+
NEW fun, \\A j \\in indices \\union {i} : fun[j] \\in Typ
|
|
2139
|
+
PROVE FoldFunctionOnSet(op, base, fun, indices \\union {i}) =
|
|
2140
|
+
op(fun[i], FoldFunctionOnSet(op, base, fun, indices))
|
|
2141
|
+
|
|
2142
|
+
(*************************************************************************)
|
|
2143
|
+
(* For an AC operator, folding an EXCEPT construction can be reduced to *)
|
|
2144
|
+
(* folding the original function. *)
|
|
2145
|
+
(*************************************************************************)
|
|
2146
|
+
THEOREM FoldFunctionOnSetACExcept ==
|
|
2147
|
+
ASSUME NEW Typ, NEW op(_,_), NEW base \\in Typ,
|
|
2148
|
+
\\A t,u \\in Typ : op(t,u) \\in Typ,
|
|
2149
|
+
\\A t,u \\in Typ : op(t,u) = op(u,t),
|
|
2150
|
+
\\A t,u,v \\in Typ : op(t, op(u,v)) = op(op(t,u),v),
|
|
2151
|
+
NEW fun, NEW i, NEW y \\in Typ,
|
|
2152
|
+
NEW indices \\in SUBSET (DOMAIN fun), IsFiniteSet(indices),
|
|
2153
|
+
\\A j \\in indices : fun[j] \\in Typ
|
|
2154
|
+
PROVE FoldFunctionOnSet(op, base, [fun EXCEPT ![i] = y], indices) =
|
|
2155
|
+
IF i \\in indices
|
|
2156
|
+
THEN op(y, FoldFunctionOnSet(op, base, fun, indices \\ {i}))
|
|
2157
|
+
ELSE FoldFunctionOnSet(op, base, fun, indices)
|
|
2158
|
+
|
|
2159
|
+
(*************************************************************************)
|
|
2160
|
+
(* For an AC operator \`op\` for which \`base\` is the neutral element, *)
|
|
2161
|
+
(* folding a function commutes with set union, for disjoint sets. *)
|
|
2162
|
+
(*************************************************************************)
|
|
2163
|
+
THEOREM FoldFunctionOnSetDisjointUnion ==
|
|
2164
|
+
ASSUME NEW Typ, NEW op(_,_), NEW base \\in Typ,
|
|
2165
|
+
\\A t,u \\in Typ : op(t,u) \\in Typ,
|
|
2166
|
+
\\A t,u \\in Typ : op(t,u) = op(u,t),
|
|
2167
|
+
\\A t,u,v \\in Typ : op(t, op(u,v)) = op(op(t,u),v),
|
|
2168
|
+
\\A t \\in Typ : op(base, t) = t,
|
|
2169
|
+
NEW S, IsFiniteSet(S), NEW T, IsFiniteSet(T), S \\cap T = {},
|
|
2170
|
+
NEW fun, \\A i \\in S \\union T : fun[i] \\in Typ
|
|
2171
|
+
PROVE FoldFunctionOnSet(op, base, fun, S \\union T) =
|
|
2172
|
+
op(FoldFunctionOnSet(op, base, fun, S), FoldFunctionOnSet(op, base, fun, T))
|
|
2173
|
+
|
|
2174
|
+
(*************************************************************************)
|
|
2175
|
+
(* Analogous theorems for FoldFunction. Note that the theorems about *)
|
|
2176
|
+
(* adding an index and about disjoint union do not make sense here. *)
|
|
2177
|
+
(*************************************************************************)
|
|
2178
|
+
THEOREM FoldFunctionEmpty ==
|
|
2179
|
+
ASSUME NEW op(_,_), NEW base, NEW fun, DOMAIN fun = {}
|
|
2180
|
+
PROVE FoldFunction(op, base, fun) = base
|
|
2181
|
+
|
|
2182
|
+
THEOREM FoldFunctionNonempty ==
|
|
2183
|
+
ASSUME NEW op(_,_), NEW base, NEW fun,
|
|
2184
|
+
DOMAIN fun # {}, IsFiniteSet(DOMAIN fun)
|
|
2185
|
+
PROVE \\E i \\in DOMAIN fun : FoldFunction(op, base, fun) =
|
|
2186
|
+
op(fun[i], FoldFunctionOnSet(op, base, fun, DOMAIN fun \\ {i}))
|
|
2187
|
+
|
|
2188
|
+
THEOREM FoldFunctionType ==
|
|
2189
|
+
ASSUME NEW Typ, NEW op(_,_), NEW base \\in Typ,
|
|
2190
|
+
\\A t,u \\in Typ : op(t,u) \\in Typ,
|
|
2191
|
+
NEW fun, IsFiniteSet(DOMAIN fun),
|
|
2192
|
+
\\A i \\in DOMAIN fun : fun[i] \\in Typ
|
|
2193
|
+
PROVE FoldFunction(op, base, fun) \\in Typ
|
|
2194
|
+
|
|
2195
|
+
THEOREM FoldFunctionAC ==
|
|
2196
|
+
ASSUME NEW Typ, NEW op(_,_), NEW base \\in Typ,
|
|
2197
|
+
\\A t,u \\in Typ : op(t,u) \\in Typ,
|
|
2198
|
+
\\A t,u \\in Typ : op(t,u) = op(u,t),
|
|
2199
|
+
\\A t,u,v \\in Typ : op(t, op(u,v)) = op(op(t,u),v),
|
|
2200
|
+
NEW fun, IsFiniteSet(DOMAIN fun), NEW i \\in DOMAIN fun,
|
|
2201
|
+
\\A j \\in DOMAIN fun : fun[j] \\in Typ
|
|
2202
|
+
PROVE FoldFunction(op, base, fun) =
|
|
2203
|
+
op(fun[i], FoldFunctionOnSet(op, base, fun, (DOMAIN fun) \\ {i}))
|
|
2204
|
+
|
|
2205
|
+
THEOREM FoldFunctionACExcept ==
|
|
2206
|
+
ASSUME NEW Typ, NEW op(_,_), NEW base \\in Typ,
|
|
2207
|
+
\\A t,u \\in Typ : op(t,u) \\in Typ,
|
|
2208
|
+
\\A t,u \\in Typ : op(t,u) = op(u,t),
|
|
2209
|
+
\\A t,u,v \\in Typ : op(t, op(u,v)) = op(op(t,u),v),
|
|
2210
|
+
NEW fun, NEW i, NEW y \\in Typ,
|
|
2211
|
+
IsFiniteSet(DOMAIN fun),
|
|
2212
|
+
\\A j \\in DOMAIN fun : fun[j] \\in Typ
|
|
2213
|
+
PROVE FoldFunction(op, base, [fun EXCEPT ![i] = y]) =
|
|
2214
|
+
IF i \\in DOMAIN fun
|
|
2215
|
+
THEN op(y, FoldFunctionOnSet(op, base, fun, (DOMAIN fun) \\ {i}))
|
|
2216
|
+
ELSE FoldFunction(op, base, fun)
|
|
2217
|
+
|
|
2218
|
+
(*************************************************************************)
|
|
2219
|
+
(* Summing a function that returns natural numbers, resp. integers, *)
|
|
2220
|
+
(* yields a natural number, resp. an integer. *)
|
|
2221
|
+
(*************************************************************************)
|
|
2222
|
+
THEOREM SumFunctionOnSetNat ==
|
|
2223
|
+
ASSUME NEW fun, NEW indices, IsFiniteSet(indices),
|
|
2224
|
+
\\A i \\in indices : fun[i] \\in Nat
|
|
2225
|
+
PROVE SumFunctionOnSet(fun, indices) \\in Nat
|
|
2226
|
+
|
|
2227
|
+
THEOREM SumFunctionOnSetInt ==
|
|
2228
|
+
ASSUME NEW fun, NEW indices, IsFiniteSet(indices),
|
|
2229
|
+
\\A i \\in indices : fun[i] \\in Int
|
|
2230
|
+
PROVE SumFunctionOnSet(fun, indices) \\in Int
|
|
2231
|
+
|
|
2232
|
+
(*************************************************************************)
|
|
2233
|
+
(* Summing two functions that agree on all relevant indices yields the *)
|
|
2234
|
+
(* same result. *)
|
|
2235
|
+
(*************************************************************************)
|
|
2236
|
+
THEOREM SumFunctionOnSetEqual ==
|
|
2237
|
+
ASSUME NEW f, NEW g, NEW indices, IsFiniteSet(indices),
|
|
2238
|
+
\\A i \\in indices : f[i] = g[i]
|
|
2239
|
+
PROVE SumFunctionOnSet(f, indices) = SumFunctionOnSet(g, indices)
|
|
2240
|
+
|
|
2241
|
+
(*************************************************************************)
|
|
2242
|
+
(* Summing a function over the empty set is 0. *)
|
|
2243
|
+
(*************************************************************************)
|
|
2244
|
+
THEOREM SumFunctionOnSetEmpty ==
|
|
2245
|
+
ASSUME NEW fun
|
|
2246
|
+
PROVE SumFunctionOnSet(fun, {}) = 0
|
|
2247
|
+
|
|
2248
|
+
(*************************************************************************)
|
|
2249
|
+
(* Summing a function over a non-empty set corresponds to the sum of *)
|
|
2250
|
+
(* element of the set and the sum of the function over the remainder. *)
|
|
2251
|
+
(*************************************************************************)
|
|
2252
|
+
THEOREM SumFunctionOnSetNonempty ==
|
|
2253
|
+
ASSUME NEW fun, NEW indices, IsFiniteSet(indices), NEW i \\in indices,
|
|
2254
|
+
\\A j \\in indices : fun[j] \\in Int
|
|
2255
|
+
PROVE SumFunctionOnSet(fun, indices) =
|
|
2256
|
+
fun[i] + SumFunctionOnSet(fun, indices \\ {i})
|
|
2257
|
+
|
|
2258
|
+
\\* reformulation in terms of adding an index
|
|
2259
|
+
THEOREM SumFunctionOnSetAddIndex ==
|
|
2260
|
+
ASSUME NEW fun, NEW indices, IsFiniteSet(indices),
|
|
2261
|
+
NEW i, i \\notin indices,
|
|
2262
|
+
\\A j \\in indices \\union {i} : fun[j] \\in Int
|
|
2263
|
+
PROVE SumFunctionOnSet(fun, indices \\union {i}) =
|
|
2264
|
+
fun[i] + SumFunctionOnSet(fun, indices)
|
|
2265
|
+
|
|
2266
|
+
\\* corresponding lemma for removing an index
|
|
2267
|
+
THEOREM SumFunctionOnSetRemoveIndex ==
|
|
2268
|
+
ASSUME NEW fun, NEW indices, IsFiniteSet(indices), NEW i \\in indices,
|
|
2269
|
+
\\A j \\in indices : fun[j] \\in Int
|
|
2270
|
+
PROVE SumFunctionOnSet(fun, indices \\ {i}) =
|
|
2271
|
+
SumFunctionOnSet(fun, indices) - fun[i]
|
|
2272
|
+
|
|
2273
|
+
(*************************************************************************)
|
|
2274
|
+
(* Reduce the sum of an EXCEPT to the sum of the original function. *)
|
|
2275
|
+
(*************************************************************************)
|
|
2276
|
+
THEOREM SumFunctionOnSetExcept ==
|
|
2277
|
+
ASSUME NEW fun, NEW i, NEW y \\in Int,
|
|
2278
|
+
NEW indices \\in SUBSET (DOMAIN fun), IsFiniteSet(indices),
|
|
2279
|
+
\\A j \\in indices : fun[j] \\in Int
|
|
2280
|
+
PROVE SumFunctionOnSet([fun EXCEPT ![i] = y], indices) =
|
|
2281
|
+
IF i \\in indices
|
|
2282
|
+
THEN SumFunctionOnSet(fun, indices) + y - fun[i]
|
|
2283
|
+
ELSE SumFunctionOnSet(fun, indices)
|
|
2284
|
+
|
|
2285
|
+
(*************************************************************************)
|
|
2286
|
+
(* Summing a function distributes over disjoint union. *)
|
|
2287
|
+
(*************************************************************************)
|
|
2288
|
+
THEOREM SumFunctionOnSetDisjointUnion ==
|
|
2289
|
+
ASSUME NEW S, IsFiniteSet(S),
|
|
2290
|
+
NEW T, IsFiniteSet(T), S \\cap T = {},
|
|
2291
|
+
NEW fun, \\A x \\in S \\union T : fun[x] \\in Int
|
|
2292
|
+
PROVE SumFunctionOnSet(fun, S \\union T) =
|
|
2293
|
+
SumFunctionOnSet(fun, S) + SumFunctionOnSet(fun, T)
|
|
2294
|
+
|
|
2295
|
+
(*************************************************************************)
|
|
2296
|
+
(* Summing a Nat-valued function is monotonic in the subset relation. *)
|
|
2297
|
+
(*************************************************************************)
|
|
2298
|
+
THEOREM SumFunctionNatOnSubset ==
|
|
2299
|
+
ASSUME NEW S, IsFiniteSet(S), NEW T \\in SUBSET S,
|
|
2300
|
+
NEW fun, \\A s \\in S : fun[s] \\in Nat
|
|
2301
|
+
PROVE SumFunctionOnSet(fun, T) <= SumFunctionOnSet(fun, S)
|
|
2302
|
+
|
|
2303
|
+
(*************************************************************************)
|
|
2304
|
+
(* The sum of a Nat-valued function is zero iff all relevant function *)
|
|
2305
|
+
(* values are zero. *)
|
|
2306
|
+
(*************************************************************************)
|
|
2307
|
+
THEOREM SumFunctionOnSetZero ==
|
|
2308
|
+
ASSUME NEW S, IsFiniteSet(S),
|
|
2309
|
+
NEW fun, \\A x \\in S : fun[x] \\in Nat
|
|
2310
|
+
PROVE SumFunctionOnSet(fun, S) = 0 <=> \\A x \\in S : fun[x] = 0
|
|
2311
|
+
|
|
2312
|
+
(*************************************************************************)
|
|
2313
|
+
(* Given any Int-valued function f and finite set S such that f[s] = c *)
|
|
2314
|
+
(* for all s \\in S, summing f over S yields c multiplied by the *)
|
|
2315
|
+
(* cardinality of S. For example, for *)
|
|
2316
|
+
(* f == [s \\in {"a", "b", "c"} |-> IF s = "c" THEN 42 ELSE 5], *)
|
|
2317
|
+
(* SumFunctionOnSet(f, {"a","b"}) = 10. *)
|
|
2318
|
+
(*************************************************************************)
|
|
2319
|
+
THEOREM SumFunctionOnSetConst ==
|
|
2320
|
+
ASSUME NEW D, NEW S \\in SUBSET D, IsFiniteSet(S),
|
|
2321
|
+
NEW f \\in [D -> Int], NEW c \\in Int, \\A x \\in S : f[x] = c
|
|
2322
|
+
PROVE SumFunctionOnSet(f, S) = c * Cardinality(S)
|
|
2323
|
+
|
|
2324
|
+
(*************************************************************************)
|
|
2325
|
+
(* Summing a function is monotonic in the function argument. *)
|
|
2326
|
+
(*************************************************************************)
|
|
2327
|
+
THEOREM SumFunctionOnSetMonotonic ==
|
|
2328
|
+
ASSUME NEW S, IsFiniteSet(S),
|
|
2329
|
+
NEW f, \\A s \\in S : f[s] \\in Int,
|
|
2330
|
+
NEW g, \\A s \\in S : g[s] \\in Int,
|
|
2331
|
+
\\A s \\in S : f[s] <= g[s]
|
|
2332
|
+
PROVE SumFunctionOnSet(f, S) <= SumFunctionOnSet(g, S)
|
|
2333
|
+
|
|
2334
|
+
(*************************************************************************)
|
|
2335
|
+
(* The sum over function f is strictly smaller than the sum over g if *)
|
|
2336
|
+
(* f[x] <= g[x] for all x \\in S and f[x] < g[s] holds for at least some *)
|
|
2337
|
+
(* element s \\in S. *)
|
|
2338
|
+
(*************************************************************************)
|
|
2339
|
+
THEOREM SumFunctionOnSetStrictlyMonotonic ==
|
|
2340
|
+
ASSUME NEW S, IsFiniteSet(S),
|
|
2341
|
+
NEW f, \\A s \\in S : f[s] \\in Int,
|
|
2342
|
+
NEW g, \\A s \\in S : g[s] \\in Int,
|
|
2343
|
+
\\A x \\in S : f[x] <= g[x],
|
|
2344
|
+
NEW s \\in S, f[s] < g[s]
|
|
2345
|
+
PROVE SumFunctionOnSet(f, S) < SumFunctionOnSet(g, S)
|
|
2346
|
+
|
|
2347
|
+
(*************************************************************************)
|
|
2348
|
+
(* Similar theorems for SumFunction. *)
|
|
2349
|
+
(*************************************************************************)
|
|
2350
|
+
THEOREM SumFunctionNat ==
|
|
2351
|
+
ASSUME NEW fun, IsFiniteSet(DOMAIN fun),
|
|
2352
|
+
\\A x \\in DOMAIN fun : fun[x] \\in Nat
|
|
2353
|
+
PROVE SumFunction(fun) \\in Nat
|
|
2354
|
+
|
|
2355
|
+
THEOREM SumFunctionInt ==
|
|
2356
|
+
ASSUME NEW fun, IsFiniteSet(DOMAIN fun),
|
|
2357
|
+
\\A x \\in DOMAIN fun : fun[x] \\in Int
|
|
2358
|
+
PROVE SumFunction(fun) \\in Int
|
|
2359
|
+
|
|
2360
|
+
THEOREM SumFunctionEmpty ==
|
|
2361
|
+
ASSUME NEW fun, DOMAIN fun = {}
|
|
2362
|
+
PROVE SumFunction(fun) = 0
|
|
2363
|
+
|
|
2364
|
+
THEOREM SumFunctionNonempty ==
|
|
2365
|
+
ASSUME NEW fun, IsFiniteSet(DOMAIN fun), NEW x \\in DOMAIN fun,
|
|
2366
|
+
\\A i \\in DOMAIN fun : fun[i] \\in Int
|
|
2367
|
+
PROVE SumFunction(fun) = fun[x] + SumFunctionOnSet(fun, (DOMAIN fun) \\ {x})
|
|
2368
|
+
|
|
2369
|
+
THEOREM SumFunctionExcept ==
|
|
2370
|
+
ASSUME NEW fun, NEW i, NEW y \\in Int, IsFiniteSet(DOMAIN fun),
|
|
2371
|
+
\\A x \\in DOMAIN fun : fun[x] \\in Int
|
|
2372
|
+
PROVE SumFunction([fun EXCEPT ![i] = y]) =
|
|
2373
|
+
IF i \\in DOMAIN fun
|
|
2374
|
+
THEN SumFunction(fun) + y - fun[i]
|
|
2375
|
+
ELSE SumFunction(fun)
|
|
2376
|
+
|
|
2377
|
+
THEOREM SumFunctionZero ==
|
|
2378
|
+
ASSUME NEW fun, IsFiniteSet(DOMAIN fun),
|
|
2379
|
+
\\A x \\in DOMAIN fun : fun[x] \\in Nat
|
|
2380
|
+
PROVE SumFunction(fun) = 0 <=> \\A x \\in DOMAIN fun : fun[x] = 0
|
|
2381
|
+
|
|
2382
|
+
(*************************************************************************)
|
|
2383
|
+
(* Summing a constant function yields the constant multiplied by the *)
|
|
2384
|
+
(* cardinality of its domain. For example, *)
|
|
2385
|
+
(* SumFunction([s \\in {"a","b","c"} |-> 5]) = 15. *)
|
|
2386
|
+
(*************************************************************************)
|
|
2387
|
+
THEOREM SumFunctionConst ==
|
|
2388
|
+
ASSUME NEW S, IsFiniteSet(S), NEW c \\in Int
|
|
2389
|
+
PROVE SumFunction([s \\in S |-> c]) = c * Cardinality(S)
|
|
2390
|
+
|
|
2391
|
+
THEOREM SumFunctionMonotonic ==
|
|
2392
|
+
ASSUME NEW f, IsFiniteSet(DOMAIN f), NEW g, DOMAIN g = DOMAIN f,
|
|
2393
|
+
\\A x \\in DOMAIN f : f[x] \\in Int,
|
|
2394
|
+
\\A x \\in DOMAIN f : g[x] \\in Int,
|
|
2395
|
+
\\A x \\in DOMAIN f : f[x] <= g[x]
|
|
2396
|
+
PROVE SumFunction(f) <= SumFunction(g)
|
|
2397
|
+
|
|
2398
|
+
THEOREM SumFunctionStrictlyMonotonic ==
|
|
2399
|
+
ASSUME NEW f, IsFiniteSet(DOMAIN f), NEW g, DOMAIN g = DOMAIN f,
|
|
2400
|
+
\\A x \\in DOMAIN f : f[x] \\in Int,
|
|
2401
|
+
\\A x \\in DOMAIN f : g[x] \\in Int,
|
|
2402
|
+
\\A x \\in DOMAIN f : f[x] <= g[x],
|
|
2403
|
+
NEW s \\in DOMAIN f, f[s] < g[s]
|
|
2404
|
+
PROVE SumFunction(f) < SumFunction(g)
|
|
2405
|
+
|
|
2406
|
+
=============================================================================
|
|
2407
|
+
\\* Created Thu Apr 11 10:36:10 PDT 2013 by tomr
|
|
2408
|
+
`,
|
|
2409
|
+
],
|
|
2410
|
+
[
|
|
2411
|
+
"NaturalsInduction",
|
|
2412
|
+
`------------------------- MODULE NaturalsInduction --------------------------
|
|
2413
|
+
(***************************************************************************)
|
|
2414
|
+
(* This module contains useful theorems for inductive proofs and recursive *)
|
|
2415
|
+
(* definitions over the naturals. *)
|
|
2416
|
+
(* *)
|
|
2417
|
+
(* Some of the statements of the theorems are decomposed in terms of *)
|
|
2418
|
+
(* definitions. This is done for two reasons: *)
|
|
2419
|
+
(* *)
|
|
2420
|
+
(* - It makes it easier for the backends to instantiate the theorems *)
|
|
2421
|
+
(* when those definitions are not expanded. *)
|
|
2422
|
+
(* *)
|
|
2423
|
+
(* - It can be convenient when writing proofs to use those definitions *)
|
|
2424
|
+
(* rather than having to write out their expansions. *)
|
|
2425
|
+
(***************************************************************************)
|
|
2426
|
+
EXTENDS Integers
|
|
2427
|
+
|
|
2428
|
+
(***************************************************************************)
|
|
2429
|
+
(* The following is the simple statement of inductions over the naturals. *)
|
|
2430
|
+
(* For predicates P defined by a moderately complex operator, it is often *)
|
|
2431
|
+
(* useful to hide the operator definition before using this theorem. That *)
|
|
2432
|
+
(* is, you first define a suitable operator P (not necessarily by that *)
|
|
2433
|
+
(* name), prove the two hypotheses of the theorem, and then hide the *)
|
|
2434
|
+
(* definition of P when using the theorem. *)
|
|
2435
|
+
(***************************************************************************)
|
|
2436
|
+
THEOREM NatInduction ==
|
|
2437
|
+
ASSUME NEW P(_),
|
|
2438
|
+
P(0),
|
|
2439
|
+
\\A n \\in Nat : P(n) => P(n+1)
|
|
2440
|
+
PROVE \\A n \\in Nat : P(n)
|
|
2441
|
+
|
|
2442
|
+
(***************************************************************************)
|
|
2443
|
+
(* A useful corollary of NatInduction *)
|
|
2444
|
+
(***************************************************************************)
|
|
2445
|
+
THEOREM DownwardNatInduction ==
|
|
2446
|
+
ASSUME NEW P(_), NEW m \\in Nat, P(m),
|
|
2447
|
+
\\A n \\in 1 .. m : P(n) => P(n-1)
|
|
2448
|
+
PROVE P(0)
|
|
2449
|
+
|
|
2450
|
+
(***************************************************************************)
|
|
2451
|
+
(* The following theorem expresses a stronger induction principle, *)
|
|
2452
|
+
(* also known as course-of-values induction, where the induction *)
|
|
2453
|
+
(* hypothesis is available for all strictly smaller natural numbers. *)
|
|
2454
|
+
(***************************************************************************)
|
|
2455
|
+
THEOREM GeneralNatInduction ==
|
|
2456
|
+
ASSUME NEW P(_),
|
|
2457
|
+
\\A n \\in Nat : (\\A m \\in 0..(n-1) : P(m)) => P(n)
|
|
2458
|
+
PROVE \\A n \\in Nat : P(n)
|
|
2459
|
+
|
|
2460
|
+
(***************************************************************************)
|
|
2461
|
+
(* The following theorem expresses the \`\`least-number principle'': *)
|
|
2462
|
+
(* if P(n) is true for some natural number n then there is a *)
|
|
2463
|
+
(* smallest natural number for which P is true. It could be derived in *)
|
|
2464
|
+
(* module WellFoundedInduction as a corollary of the fact that the natural *)
|
|
2465
|
+
(* numbers are well ordered, but we give a direct proof. *)
|
|
2466
|
+
(***************************************************************************)
|
|
2467
|
+
THEOREM SmallestNatural ==
|
|
2468
|
+
ASSUME NEW P(_), NEW n \\in Nat, P(n)
|
|
2469
|
+
PROVE \\E m \\in Nat : /\\ P(m)
|
|
2470
|
+
/\\ \\A k \\in 0 .. m-1 : ~ P(k)
|
|
2471
|
+
|
|
2472
|
+
(***************************************************************************)
|
|
2473
|
+
(* The following theorem says that a recursively defined function f over *)
|
|
2474
|
+
(* the natural numbers is well-defined if for every n \\in Nat the *)
|
|
2475
|
+
(* definition of f[n] depends only on arguments smaller than n. *)
|
|
2476
|
+
(***************************************************************************)
|
|
2477
|
+
THEOREM RecursiveFcnOfNat ==
|
|
2478
|
+
ASSUME NEW Def(_,_),
|
|
2479
|
+
ASSUME NEW n \\in Nat, NEW g, NEW h,
|
|
2480
|
+
\\A i \\in 0..(n-1) : g[i] = h[i]
|
|
2481
|
+
PROVE Def(g, n) = Def(h, n)
|
|
2482
|
+
PROVE LET f[n \\in Nat] == Def(f, n)
|
|
2483
|
+
IN f = [n \\in Nat |-> Def(f, n)]
|
|
2484
|
+
|
|
2485
|
+
(***************************************************************************)
|
|
2486
|
+
(* The following theorem NatInductiveDef is what you use to justify a *)
|
|
2487
|
+
(* function defined by primitive recursion over the naturals. *)
|
|
2488
|
+
(***************************************************************************)
|
|
2489
|
+
NatInductiveDefHypothesis(f, f0, Def(_,_)) ==
|
|
2490
|
+
(f = CHOOSE g : g = [i \\in Nat |-> IF i = 0 THEN f0 ELSE Def(g[i-1], i)])
|
|
2491
|
+
NatInductiveDefConclusion(f, f0, Def(_,_)) ==
|
|
2492
|
+
f = [i \\in Nat |-> IF i = 0 THEN f0 ELSE Def(f[i-1], i)]
|
|
2493
|
+
|
|
2494
|
+
THEOREM NatInductiveDef ==
|
|
2495
|
+
ASSUME NEW Def(_,_), NEW f, NEW f0,
|
|
2496
|
+
NatInductiveDefHypothesis(f, f0, Def)
|
|
2497
|
+
PROVE NatInductiveDefConclusion(f, f0, Def)
|
|
2498
|
+
|
|
2499
|
+
(***************************************************************************)
|
|
2500
|
+
(* The following two theorems allow you to prove the type of a recursively *)
|
|
2501
|
+
(* defined function over the natural numbers. *)
|
|
2502
|
+
(***************************************************************************)
|
|
2503
|
+
THEOREM RecursiveFcnOfNatType ==
|
|
2504
|
+
ASSUME NEW f, NEW S, NEW Def(_,_), f = [n \\in Nat |-> Def(f,n)],
|
|
2505
|
+
ASSUME NEW n \\in Nat, NEW g, \\A i \\in 0 .. n-1 : g[i] \\in S
|
|
2506
|
+
PROVE Def(g,n) \\in S
|
|
2507
|
+
PROVE f \\in [Nat -> S]
|
|
2508
|
+
|
|
2509
|
+
THEOREM NatInductiveDefType ==
|
|
2510
|
+
ASSUME NEW Def(_,_), NEW S, NEW f, NEW f0 \\in S,
|
|
2511
|
+
NatInductiveDefConclusion(f, f0, Def),
|
|
2512
|
+
f0 \\in S,
|
|
2513
|
+
\\A v \\in S, n \\in Nat \\ {0} : Def(v, n) \\in S
|
|
2514
|
+
PROVE f \\in [Nat -> S]
|
|
2515
|
+
|
|
2516
|
+
(***************************************************************************)
|
|
2517
|
+
(* The following theorems show uniqueness of functions recursively defined *)
|
|
2518
|
+
(* over Nat. *)
|
|
2519
|
+
(***************************************************************************)
|
|
2520
|
+
THEOREM RecursiveFcnOfNatUnique ==
|
|
2521
|
+
ASSUME NEW Def(_,_), NEW f, NEW g,
|
|
2522
|
+
f = [n \\in Nat |-> Def(f,n)],
|
|
2523
|
+
g = [n \\in Nat |-> Def(g,n)],
|
|
2524
|
+
ASSUME NEW n \\in Nat, NEW ff, NEW gg,
|
|
2525
|
+
\\A i \\in 0..(n-1) : ff[i] = gg[i]
|
|
2526
|
+
PROVE Def(ff, n) = Def(gg, n)
|
|
2527
|
+
PROVE f = g
|
|
2528
|
+
|
|
2529
|
+
THEOREM NatInductiveUnique ==
|
|
2530
|
+
ASSUME NEW Def(_,_), NEW f, NEW g, NEW f0,
|
|
2531
|
+
NatInductiveDefConclusion(f, f0, Def),
|
|
2532
|
+
NatInductiveDefConclusion(g, f0, Def)
|
|
2533
|
+
PROVE f = g
|
|
2534
|
+
|
|
2535
|
+
(***************************************************************************)
|
|
2536
|
+
(* The following theorems are analogous to the preceding ones but for *)
|
|
2537
|
+
(* functions defined over intervals of natural numbers. *)
|
|
2538
|
+
(***************************************************************************)
|
|
2539
|
+
|
|
2540
|
+
FiniteNatInductiveDefHypothesis(f, c, Def(_,_), m, n) ==
|
|
2541
|
+
(f = CHOOSE g : g = [i \\in m..n |-> IF i = m THEN c ELSE Def(g[i-1], i)])
|
|
2542
|
+
FiniteNatInductiveDefConclusion(f, c, Def(_,_), m, n) ==
|
|
2543
|
+
f = [i \\in m..n |-> IF i = m THEN c ELSE Def(f[i-1], i)]
|
|
2544
|
+
|
|
2545
|
+
THEOREM FiniteNatInductiveDef ==
|
|
2546
|
+
ASSUME NEW Def(_,_), NEW f, NEW c, NEW m \\in Nat, NEW n \\in Nat,
|
|
2547
|
+
FiniteNatInductiveDefHypothesis(f, c, Def, m, n)
|
|
2548
|
+
PROVE FiniteNatInductiveDefConclusion(f, c, Def, m, n)
|
|
2549
|
+
|
|
2550
|
+
THEOREM FiniteNatInductiveDefType ==
|
|
2551
|
+
ASSUME NEW S, NEW Def(_,_), NEW f, NEW c \\in S, NEW m \\in Nat, NEW n \\in Nat,
|
|
2552
|
+
FiniteNatInductiveDefConclusion(f, c, Def, m, n),
|
|
2553
|
+
\\A v \\in S, i \\in (m+1) .. n : Def(v,i) \\in S
|
|
2554
|
+
PROVE f \\in [m..n -> S]
|
|
2555
|
+
|
|
2556
|
+
THEOREM FiniteNatInductiveUnique ==
|
|
2557
|
+
ASSUME NEW Def(_,_), NEW f, NEW g, NEW c, NEW m \\in Nat, NEW n \\in Nat,
|
|
2558
|
+
FiniteNatInductiveDefConclusion(f, c, Def, m, n),
|
|
2559
|
+
FiniteNatInductiveDefConclusion(g, c, Def, m, n)
|
|
2560
|
+
PROVE f = g
|
|
2561
|
+
|
|
2562
|
+
=============================================================================
|
|
2563
|
+
|
|
2564
|
+
(***************************************************************************)
|
|
2565
|
+
(* The following example shows how this module is used. *)
|
|
2566
|
+
(***************************************************************************)
|
|
2567
|
+
|
|
2568
|
+
factorial[n \\in Nat] == IF n = 0 THEN 1 ELSE n * factorial[n-1]
|
|
2569
|
+
|
|
2570
|
+
THEOREM FactorialDefConclusion == NatInductiveDefConclusion(factorial, 1, LAMBDA v,n : n*v)
|
|
2571
|
+
<1>1. NatInductiveDefHypothesis(factorial, 1, LAMBDA v,n : n*v)
|
|
2572
|
+
BY DEF NatInductiveDefHypothesis, factorial
|
|
2573
|
+
<1>2. QED
|
|
2574
|
+
BY <1>1, NatInductiveDef
|
|
2575
|
+
|
|
2576
|
+
THEOREM FactorialDef == \\A n \\in Nat : factorial[n] = IF n = 0 THEN 1 ELSE n * factorial[n-1]
|
|
2577
|
+
BY FactorialDefConclusion DEF NatInductiveDefConclusion
|
|
2578
|
+
|
|
2579
|
+
THEOREM FactorialType == factorial \\in [Nat -> Nat]
|
|
2580
|
+
<1>1. \\A v \\in Nat, n \\in Nat \\ {0} : n * v \\in Nat
|
|
2581
|
+
OBVIOUS
|
|
2582
|
+
<1>2. QED
|
|
2583
|
+
BY <1>1, NatInductiveDefType, FactorialDefConclusion, Isa
|
|
2584
|
+
|
|
2585
|
+
|
|
2586
|
+
\\* Modification History
|
|
2587
|
+
\\* Last modified Thu Aug 22 15:29:20 CEST 2019 by merz
|
|
2588
|
+
\\* Last modified Tue Oct 15 12:06:48 CEST 2013 by shaolin
|
|
2589
|
+
\\* Last modified Sat Nov 26 08:49:59 CET 2011 by merz
|
|
2590
|
+
\\* Last modified Mon Nov 07 08:58:05 PST 2011 by lamport
|
|
2591
|
+
\\* Created Mon Oct 31 02:52:05 PDT 2011 by lamport
|
|
2592
|
+
`,
|
|
2593
|
+
],
|
|
2594
|
+
[
|
|
2595
|
+
"RealTime",
|
|
2596
|
+
`----------------------------- MODULE RealTime -------------------------------
|
|
2597
|
+
EXTENDS Reals
|
|
2598
|
+
VARIABLE now
|
|
2599
|
+
|
|
2600
|
+
RTBound(A, v, D, E) ==
|
|
2601
|
+
LET TNext(t) == t' = IF <<A>>_v \\/ ~(ENABLED <<A>>_v)'
|
|
2602
|
+
THEN 0
|
|
2603
|
+
ELSE t + (now'-now)
|
|
2604
|
+
|
|
2605
|
+
Timer(t) == (t=0) /\\ [][TNext(t)]_<<t, v, now>>
|
|
2606
|
+
|
|
2607
|
+
MaxTime(t) == [](t \\leq E)
|
|
2608
|
+
|
|
2609
|
+
MinTime(t) == [][A => t \\geq D]_v
|
|
2610
|
+
IN \\EE t : Timer(t) /\\ MaxTime(t) /\\ MinTime(t)
|
|
2611
|
+
-----------------------------------------------------------------------------
|
|
2612
|
+
RTnow(v) == LET NowNext == /\\ now' \\in {r \\in Real : r > now}
|
|
2613
|
+
/\\ UNCHANGED v
|
|
2614
|
+
IN /\\ now \\in Real
|
|
2615
|
+
/\\ [][NowNext]_now
|
|
2616
|
+
/\\ \\A r \\in Real : WF_now(NowNext /\\ (now'>r))
|
|
2617
|
+
=============================================================================
|
|
2618
|
+
`,
|
|
2619
|
+
],
|
|
2620
|
+
[
|
|
2621
|
+
"SequenceTheorems",
|
|
2622
|
+
`-------------------------- MODULE SequenceTheorems --------------------------
|
|
2623
|
+
(***************************************************************************)
|
|
2624
|
+
(* This module contains theorems about operations on sequences. *)
|
|
2625
|
+
(***************************************************************************)
|
|
2626
|
+
EXTENDS Sequences, Functions
|
|
2627
|
+
LOCAL INSTANCE NaturalsInduction
|
|
2628
|
+
LOCAL INSTANCE TLAPS
|
|
2629
|
+
|
|
2630
|
+
|
|
2631
|
+
(***************************************************************************)
|
|
2632
|
+
(* Elementary properties about Seq(S) *)
|
|
2633
|
+
(***************************************************************************)
|
|
2634
|
+
|
|
2635
|
+
LEMMA SeqDef == \\A S : Seq(S) = UNION {[1..n -> S] : n \\in Nat}
|
|
2636
|
+
|
|
2637
|
+
THEOREM SeqMonotonic ==
|
|
2638
|
+
ASSUME NEW S, NEW T, NEW seq \\in Seq(S),
|
|
2639
|
+
S \\subseteq T
|
|
2640
|
+
PROVE seq \\in Seq(T)
|
|
2641
|
+
|
|
2642
|
+
THEOREM ElementOfSeq ==
|
|
2643
|
+
ASSUME NEW S, NEW seq \\in Seq(S),
|
|
2644
|
+
NEW n \\in 1..Len(seq)
|
|
2645
|
+
PROVE seq[n] \\in S
|
|
2646
|
+
|
|
2647
|
+
THEOREM EmptySeq ==
|
|
2648
|
+
ASSUME NEW S
|
|
2649
|
+
PROVE /\\ << >> \\in Seq(S)
|
|
2650
|
+
/\\ Len(<< >>) = 0
|
|
2651
|
+
/\\ \\A seq \\in Seq(S) : (seq # << >>) => (Len(seq) \\in Nat \\ {0})
|
|
2652
|
+
|
|
2653
|
+
THEOREM LenProperties ==
|
|
2654
|
+
ASSUME NEW S, NEW seq \\in Seq(S)
|
|
2655
|
+
PROVE /\\ Len(seq) \\in Nat
|
|
2656
|
+
/\\ seq \\in [1..Len(seq) -> S]
|
|
2657
|
+
/\\ DOMAIN seq = 1 .. Len(seq)
|
|
2658
|
+
|
|
2659
|
+
THEOREM IsASeq ==
|
|
2660
|
+
ASSUME NEW n \\in Nat, NEW e(_), NEW S,
|
|
2661
|
+
\\A i \\in 1..n : e(i) \\in S
|
|
2662
|
+
PROVE [i \\in 1..n |-> e(i)] \\in Seq(S)
|
|
2663
|
+
|
|
2664
|
+
THEOREM ExceptSeq ==
|
|
2665
|
+
ASSUME NEW S, NEW seq \\in Seq(S), NEW i \\in 1 .. Len(seq), NEW e \\in S
|
|
2666
|
+
PROVE /\\ [seq EXCEPT ![i] = e] \\in Seq(S)
|
|
2667
|
+
/\\ Len([seq EXCEPT ![i] = e]) = Len(seq)
|
|
2668
|
+
/\\ \\A j \\in 1 .. Len(seq) : [seq EXCEPT ![i] = e][j] = IF j=i THEN e ELSE seq[j]
|
|
2669
|
+
|
|
2670
|
+
THEOREM SeqEqual ==
|
|
2671
|
+
ASSUME NEW S, NEW s \\in Seq(S), NEW t \\in Seq(S),
|
|
2672
|
+
Len(s) = Len(t), \\A i \\in 1 .. Len(s) : s[i] = t[i]
|
|
2673
|
+
PROVE s = t
|
|
2674
|
+
|
|
2675
|
+
(**************************************************************************)
|
|
2676
|
+
(* Properties of concatenation (\\o) *)
|
|
2677
|
+
(**************************************************************************)
|
|
2678
|
+
|
|
2679
|
+
THEOREM ConcatProperties ==
|
|
2680
|
+
ASSUME NEW S, NEW s1 \\in Seq(S), NEW s2 \\in Seq(S)
|
|
2681
|
+
PROVE /\\ s1 \\o s2 \\in Seq(S)
|
|
2682
|
+
/\\ Len(s1 \\o s2) = Len(s1) + Len(s2)
|
|
2683
|
+
/\\ \\A i \\in 1 .. Len(s1) + Len(s2) : (s1 \\o s2)[i] =
|
|
2684
|
+
IF i <= Len(s1) THEN s1[i] ELSE s2[i - Len(s1)]
|
|
2685
|
+
|
|
2686
|
+
THEOREM ConcatEmptySeq ==
|
|
2687
|
+
ASSUME NEW S, NEW seq \\in Seq(S)
|
|
2688
|
+
PROVE /\\ seq \\o << >> = seq
|
|
2689
|
+
/\\ << >> \\o seq = seq
|
|
2690
|
+
|
|
2691
|
+
THEOREM ConcatEqualIffEmpty ==
|
|
2692
|
+
ASSUME NEW S, NEW s \\in Seq(S), NEW t \\in Seq(S)
|
|
2693
|
+
PROVE /\\ s \\o t = s <=> t = << >>
|
|
2694
|
+
/\\ s \\o t = t <=> s = << >>
|
|
2695
|
+
/\\ s \\o t = << >> <=> s = << >> /\\ t = << >>
|
|
2696
|
+
|
|
2697
|
+
THEOREM ConcatAssociative ==
|
|
2698
|
+
ASSUME NEW S, NEW s \\in Seq(S), NEW t \\in Seq(S), NEW u \\in Seq(S)
|
|
2699
|
+
PROVE (s \\o t) \\o u = s \\o (t \\o u)
|
|
2700
|
+
|
|
2701
|
+
(****************************************************************************)
|
|
2702
|
+
(* Intentionally not written as an ASSUME ... PROVE such that the conjuncts *)
|
|
2703
|
+
(* can be named individually. *)
|
|
2704
|
+
(****************************************************************************)
|
|
2705
|
+
THEOREM ConcatSimplifications ==
|
|
2706
|
+
/\\ idRight:: \\A S : \\A s,t \\in Seq(S) : s \\o t = s => t = <<>>
|
|
2707
|
+
/\\ idLeft:: \\A S : \\A s,t \\in Seq(S) : s \\o t = t => s = <<>>
|
|
2708
|
+
/\\ concIsEmpty:: \\A S : \\A s,t \\in Seq(S) : s \\o t = <<>> => s = <<>> /\\ t = <<>>
|
|
2709
|
+
/\\ cancelLeft:: \\A S : \\A s,t,v \\in Seq(S) : s \\o t = s \\o v => t = v
|
|
2710
|
+
/\\ cancelRight:: \\A S : \\A s,t,v \\in Seq(S) : s \\o v = t \\o v => s = t
|
|
2711
|
+
|
|
2712
|
+
(***************************************************************************)
|
|
2713
|
+
(* SubSeq, Head and Tail *)
|
|
2714
|
+
(***************************************************************************)
|
|
2715
|
+
|
|
2716
|
+
THEOREM SubSeqProperties ==
|
|
2717
|
+
ASSUME NEW S, NEW s, NEW m \\in Int, NEW n \\in Int,
|
|
2718
|
+
\\A i \\in m .. n : s[i] \\in S
|
|
2719
|
+
PROVE /\\ SubSeq(s,m,n) \\in Seq(S)
|
|
2720
|
+
/\\ Len(SubSeq(s,m,n)) = IF m<=n THEN n-m+1 ELSE 0
|
|
2721
|
+
/\\ \\A i \\in 1 .. n-m+1 : SubSeq(s,m,n)[i] = s[m+i-1]
|
|
2722
|
+
|
|
2723
|
+
THEOREM SubSeqEmpty ==
|
|
2724
|
+
ASSUME NEW s, NEW m \\in Int, NEW n \\in Int, n < m
|
|
2725
|
+
PROVE SubSeq(s,m,n) = << >>
|
|
2726
|
+
|
|
2727
|
+
THEOREM SubSeqRange ==
|
|
2728
|
+
ASSUME NEW S, NEW s \\in Seq(S), NEW m \\in 1 .. Len(s), NEW n \\in 1 .. Len(s)
|
|
2729
|
+
PROVE Range(SubSeq(s,m,n)) \\subseteq Range(s)
|
|
2730
|
+
|
|
2731
|
+
THEOREM HeadTailProperties ==
|
|
2732
|
+
ASSUME NEW S,
|
|
2733
|
+
NEW s \\in Seq(S), s # << >>
|
|
2734
|
+
PROVE /\\ Head(s) \\in S
|
|
2735
|
+
/\\ Head(s) \\in Range(s)
|
|
2736
|
+
/\\ Tail(s) \\in Seq(S)
|
|
2737
|
+
/\\ Len(Tail(s)) = Len(s)-1
|
|
2738
|
+
/\\ \\A i \\in 1 .. Len(Tail(s)) : Tail(s)[i] = s[i+1]
|
|
2739
|
+
/\\ Range(Tail(s)) \\subseteq Range(s)
|
|
2740
|
+
|
|
2741
|
+
THEOREM TailIsSubSeq ==
|
|
2742
|
+
ASSUME NEW S,
|
|
2743
|
+
NEW s \\in Seq(S), s # << >>
|
|
2744
|
+
PROVE Tail(s) = SubSeq(s, 2, Len(s))
|
|
2745
|
+
|
|
2746
|
+
THEOREM SubSeqRestrict ==
|
|
2747
|
+
ASSUME NEW S, NEW seq \\in Seq(S), NEW n \\in 0 .. Len(seq)
|
|
2748
|
+
PROVE SubSeq(seq, 1, n) = Restrict(seq, 1 .. n)
|
|
2749
|
+
|
|
2750
|
+
THEOREM HeadTailOfSubSeq ==
|
|
2751
|
+
ASSUME NEW S, NEW seq \\in Seq(S),
|
|
2752
|
+
NEW m \\in 1 .. Len(seq), NEW n \\in m .. Len(seq)
|
|
2753
|
+
PROVE /\\ Head(SubSeq(seq,m,n)) = seq[m]
|
|
2754
|
+
/\\ Tail(SubSeq(seq,m,n)) = SubSeq(seq, m+1, n)
|
|
2755
|
+
|
|
2756
|
+
THEOREM SubSeqRecursive ==
|
|
2757
|
+
ASSUME NEW S, NEW seq \\in Seq(S),
|
|
2758
|
+
NEW m \\in 1 .. Len(seq), NEW n \\in m .. Len(seq)
|
|
2759
|
+
PROVE /\\ SubSeq(seq, m, n) = << seq[m] >> \\o SubSeq(seq, m+1, n)
|
|
2760
|
+
/\\ SubSeq(seq, m, n) = SubSeq(seq, m, n-1) \\o << seq[n] >>
|
|
2761
|
+
|
|
2762
|
+
(***************************************************************************)
|
|
2763
|
+
(* Subsequences of subsequences. *)
|
|
2764
|
+
(***************************************************************************)
|
|
2765
|
+
THEOREM SubSeqOfSubSeq ==
|
|
2766
|
+
ASSUME NEW S, NEW s \\in Seq(S), NEW t \\in Seq(S),
|
|
2767
|
+
NEW i \\in 1 .. Len(s), NEW j \\in 1 .. Len(s),
|
|
2768
|
+
NEW m \\in 1 .. j-i+1, NEW n \\in 1 .. j-i+1
|
|
2769
|
+
PROVE SubSeq(SubSeq(s,i,j),m,n) = SubSeq(s, i+m-1, i+n-1)
|
|
2770
|
+
|
|
2771
|
+
(*****************************************************************************)
|
|
2772
|
+
(* Adjacent subsequences can be concatenated to obtain a longer subsequence. *)
|
|
2773
|
+
(*****************************************************************************)
|
|
2774
|
+
THEOREM ConcatAdjacentSubSeq ==
|
|
2775
|
+
ASSUME NEW S, NEW seq \\in Seq(S),
|
|
2776
|
+
NEW m \\in 1 .. Len(seq)+1,
|
|
2777
|
+
NEW k \\in m-1 .. Len(seq),
|
|
2778
|
+
NEW n \\in k .. Len(seq)
|
|
2779
|
+
PROVE SubSeq(seq, m, k) \\o SubSeq(seq, k+1, n) = SubSeq(seq, m, n)
|
|
2780
|
+
|
|
2781
|
+
(***************************************************************************)
|
|
2782
|
+
(* Special cases of subsequences of concatenations. *)
|
|
2783
|
+
(***************************************************************************)
|
|
2784
|
+
THEOREM SubSeqOfConcat1 ==
|
|
2785
|
+
ASSUME NEW S, NEW s \\in Seq(S), NEW t \\in Seq(S),
|
|
2786
|
+
NEW m \\in 1 .. Len(s), NEW n \\in 1 .. Len(s)
|
|
2787
|
+
PROVE SubSeq(s \\o t, m, n) = SubSeq(s, m, n)
|
|
2788
|
+
|
|
2789
|
+
THEOREM SubSeqOfConcat2 ==
|
|
2790
|
+
ASSUME NEW S, NEW s \\in Seq(S), NEW t \\in Seq(S),
|
|
2791
|
+
NEW m \\in Len(s)+1 .. Len(s)+Len(t), NEW n \\in Len(s)+1 .. Len(s)+Len(t)
|
|
2792
|
+
PROVE SubSeq(s \\o t, m, n) = SubSeq(t, m - Len(s), n - Len(s))
|
|
2793
|
+
|
|
2794
|
+
(***************************************************************************)
|
|
2795
|
+
(* Theorems about Append *)
|
|
2796
|
+
(***************************************************************************)
|
|
2797
|
+
|
|
2798
|
+
THEOREM AppendProperties ==
|
|
2799
|
+
ASSUME NEW S, NEW seq \\in Seq(S), NEW elt \\in S
|
|
2800
|
+
PROVE /\\ Append(seq, elt) \\in Seq(S)
|
|
2801
|
+
/\\ Append(seq, elt) # << >>
|
|
2802
|
+
/\\ Len(Append(seq, elt)) = Len(seq)+1
|
|
2803
|
+
/\\ \\A i \\in 1.. Len(seq) : Append(seq, elt)[i] = seq[i]
|
|
2804
|
+
/\\ Append(seq, elt)[Len(seq)+1] = elt
|
|
2805
|
+
/\\ Range(Append(seq, elt)) = Range(seq) \\cup {elt}
|
|
2806
|
+
|
|
2807
|
+
THEOREM AppendIsConcat ==
|
|
2808
|
+
ASSUME NEW S, NEW seq \\in Seq(S), NEW elt \\in S
|
|
2809
|
+
PROVE Append(seq, elt) = seq \\o <<elt>>
|
|
2810
|
+
|
|
2811
|
+
THEOREM HeadTailAppend ==
|
|
2812
|
+
ASSUME NEW S, NEW seq \\in Seq(S), NEW elt
|
|
2813
|
+
PROVE /\\ Head(Append(seq, elt)) = IF seq = <<>> THEN elt ELSE Head(seq)
|
|
2814
|
+
/\\ Tail(Append(seq, elt)) = IF seq = <<>> THEN <<>> ELSE Append(Tail(seq), elt)
|
|
2815
|
+
|
|
2816
|
+
THEOREM AppendInjective ==
|
|
2817
|
+
ASSUME NEW S, NEW e \\in S, NEW s \\in Seq(S), NEW f \\in S, NEW t \\in Seq(S)
|
|
2818
|
+
PROVE Append(s,e) = Append(t,f) <=> s = t /\\ e = f
|
|
2819
|
+
|
|
2820
|
+
THEOREM SequenceEmptyOrAppend ==
|
|
2821
|
+
ASSUME NEW S, NEW seq \\in Seq(S), seq # << >>
|
|
2822
|
+
PROVE \\E s \\in Seq(S), elt \\in S : seq = Append(s, elt)
|
|
2823
|
+
|
|
2824
|
+
(***************************************************************************)
|
|
2825
|
+
(* Inductive reasoning for sequences *)
|
|
2826
|
+
(***************************************************************************)
|
|
2827
|
+
|
|
2828
|
+
THEOREM SequencesInductionAppend ==
|
|
2829
|
+
ASSUME NEW P(_), NEW S,
|
|
2830
|
+
P(<< >>),
|
|
2831
|
+
\\A s \\in Seq(S), e \\in S : P(s) => P(Append(s,e))
|
|
2832
|
+
PROVE \\A seq \\in Seq(S) : P(seq)
|
|
2833
|
+
|
|
2834
|
+
THEOREM SequencesInductionTail ==
|
|
2835
|
+
ASSUME NEW S, NEW P(_),
|
|
2836
|
+
P(<< >>),
|
|
2837
|
+
\\A s \\in Seq(S) : (s # << >>) /\\ P(Tail(s)) => P(s)
|
|
2838
|
+
PROVE \\A s \\in Seq(S) : P(s)
|
|
2839
|
+
|
|
2840
|
+
|
|
2841
|
+
(***************************************************************************)
|
|
2842
|
+
(* RANGE OF SEQUENCE *)
|
|
2843
|
+
(***************************************************************************)
|
|
2844
|
+
|
|
2845
|
+
THEOREM RangeOfSeq ==
|
|
2846
|
+
ASSUME NEW S, NEW seq \\in Seq(S)
|
|
2847
|
+
PROVE Range(seq) \\in SUBSET S
|
|
2848
|
+
|
|
2849
|
+
THEOREM RangeEquality ==
|
|
2850
|
+
ASSUME NEW S, NEW seq \\in Seq(S)
|
|
2851
|
+
PROVE Range(seq) = { seq[i] : i \\in 1 .. Len(seq) }
|
|
2852
|
+
|
|
2853
|
+
THEOREM SeqOfRange ==
|
|
2854
|
+
ASSUME NEW S, NEW seq \\in Seq(S)
|
|
2855
|
+
PROVE seq \\in Seq(Range(seq))
|
|
2856
|
+
|
|
2857
|
+
(* The range of the concatenation of two sequences is the union of the ranges *)
|
|
2858
|
+
THEOREM RangeConcatenation ==
|
|
2859
|
+
ASSUME NEW S, NEW s1 \\in Seq(S), NEW s2 \\in Seq(S)
|
|
2860
|
+
PROVE Range(s1 \\o s2) = Range(s1) \\cup Range(s2)
|
|
2861
|
+
|
|
2862
|
+
(***************************************************************************)
|
|
2863
|
+
(* Theorems about injective sequences, i.e. sequences without duplicates. *)
|
|
2864
|
+
(***************************************************************************)
|
|
2865
|
+
|
|
2866
|
+
LEMMA EmptySingletonIsInjective ==
|
|
2867
|
+
/\\ IsInjective(<< >>)
|
|
2868
|
+
/\\ \\A e : IsInjective(<< e >>)
|
|
2869
|
+
|
|
2870
|
+
LEMMA ConcatInjectiveSeq ==
|
|
2871
|
+
ASSUME NEW S, NEW s \\in Seq(S), NEW t \\in Seq(S)
|
|
2872
|
+
PROVE IsInjective(s \\o t) <=>
|
|
2873
|
+
IsInjective(s) /\\ IsInjective(t) /\\ Range(s) \\cap Range(t) = {}
|
|
2874
|
+
|
|
2875
|
+
LEMMA AppendInjectiveSeq ==
|
|
2876
|
+
ASSUME NEW S, NEW seq \\in Seq(S), NEW e \\in S
|
|
2877
|
+
PROVE IsInjective(Append(seq,e)) <=> IsInjective(seq) /\\ e \\notin Range(seq)
|
|
2878
|
+
|
|
2879
|
+
LEMMA TailInjectiveSeq ==
|
|
2880
|
+
ASSUME NEW S, NEW seq \\in Seq(S), IsInjective(seq), seq # << >>
|
|
2881
|
+
PROVE /\\ IsInjective(Tail(seq))
|
|
2882
|
+
/\\ Range(Tail(seq)) = Range(seq) \\ {Head(seq)}
|
|
2883
|
+
|
|
2884
|
+
=============================================================================
|
|
2885
|
+
`,
|
|
2886
|
+
],
|
|
2887
|
+
[
|
|
2888
|
+
"WellFoundedInduction",
|
|
2889
|
+
`------------------------ MODULE WellFoundedInduction ------------------------
|
|
2890
|
+
(***************************************************************************)
|
|
2891
|
+
(* This module contains useful theorems for inductive proofs and recursive *)
|
|
2892
|
+
(* definitions based on a well-founded ordering. *)
|
|
2893
|
+
(* *)
|
|
2894
|
+
(* Most of the statements of the theorems are decomposed in terms of *)
|
|
2895
|
+
(* definitions. This is done for two reasons: *)
|
|
2896
|
+
(* *)
|
|
2897
|
+
(* - It makes it easier for the backends to instantiate the theorems *)
|
|
2898
|
+
(* when those definitions are not expanded. In fact, at the moment *)
|
|
2899
|
+
(* the provers can't prove any of those theorems from the theorem *)
|
|
2900
|
+
(* itself if the definitions are made usable. *)
|
|
2901
|
+
(* *)
|
|
2902
|
+
(* - It can be convenient when writing proofs to use those definitions *)
|
|
2903
|
+
(* rather than having to write out their expansions. *)
|
|
2904
|
+
(* *)
|
|
2905
|
+
(* A relation is represented as a set of ordered pairs, where we write *)
|
|
2906
|
+
(* <<x, y>> \\in R instead of x R y. It is more convenient to represent *)
|
|
2907
|
+
(* relations this way rather than as operators such as < . *)
|
|
2908
|
+
(***************************************************************************)
|
|
2909
|
+
EXTENDS NaturalsInduction
|
|
2910
|
+
|
|
2911
|
+
(***************************************************************************)
|
|
2912
|
+
(* The following defines what it means for a relation R to be transitively *)
|
|
2913
|
+
(* closed on a set S. In this and other definitions, we think of R as a *)
|
|
2914
|
+
(* relation on S, meaning that it is a subset of S \\X S. However, this is *)
|
|
2915
|
+
(* not necessary. Our results do not require this as a hypothesis, and it *)
|
|
2916
|
+
(* is often convenient to apply them when R is a relation on a set *)
|
|
2917
|
+
(* containing S as a subset. They're even true (though uninteresting) if *)
|
|
2918
|
+
(* R and S \\X S are disjoint sets. *)
|
|
2919
|
+
(***************************************************************************)
|
|
2920
|
+
IsTransitivelyClosedOn(R, S) ==
|
|
2921
|
+
\\A i, j, k \\in S : (<<i, j>> \\in R) /\\ (<<j, k>> \\in R)
|
|
2922
|
+
=> (<<i, k>> \\in R)
|
|
2923
|
+
(***************************************************************************)
|
|
2924
|
+
(* If we think of R as a less-than relation, then R is well founded on S *)
|
|
2925
|
+
(* iff there is no "infinitely descending" sequence of elements of S. The *)
|
|
2926
|
+
(* canonical example of a well founded relation is the ordinary less-than *)
|
|
2927
|
+
(* relation on the natural numbers. *)
|
|
2928
|
+
(* *)
|
|
2929
|
+
(* A S with a well-founded ordering is often called well-ordered. *)
|
|
2930
|
+
(***************************************************************************)
|
|
2931
|
+
IsWellFoundedOn(R, S) ==
|
|
2932
|
+
~ \\E f \\in [Nat -> S] : \\A n \\in Nat : <<f[n+1], f[n]>> \\in R
|
|
2933
|
+
|
|
2934
|
+
LEMMA EmptyIsWellFounded == \\A S : IsWellFoundedOn({}, S)
|
|
2935
|
+
|
|
2936
|
+
|
|
2937
|
+
LEMMA IsWellFoundedOnSubset ==
|
|
2938
|
+
ASSUME NEW R, NEW S, NEW T \\in SUBSET S,
|
|
2939
|
+
IsWellFoundedOn(R,S)
|
|
2940
|
+
PROVE IsWellFoundedOn(R,T)
|
|
2941
|
+
|
|
2942
|
+
|
|
2943
|
+
LEMMA IsWellFoundedOnSubrelation ==
|
|
2944
|
+
ASSUME NEW S, NEW R, NEW RR, RR \\cap (S \\X S) \\subseteq R,
|
|
2945
|
+
IsWellFoundedOn(R,S)
|
|
2946
|
+
PROVE IsWellFoundedOn(RR,S)
|
|
2947
|
+
|
|
2948
|
+
(***************************************************************************)
|
|
2949
|
+
(* If we think of R as a less-than relation on S, then the following is *)
|
|
2950
|
+
(* the set of elements of S that are less than x. *)
|
|
2951
|
+
(***************************************************************************)
|
|
2952
|
+
SetLessThan(x, R, S) == {y \\in S : <<y, x>> \\in R}
|
|
2953
|
+
|
|
2954
|
+
(***************************************************************************)
|
|
2955
|
+
(* If we think of R as a less-than relation on S, then R is well-founded *)
|
|
2956
|
+
(* iff every non-empty subset of S has a minimal element. *)
|
|
2957
|
+
(***************************************************************************)
|
|
2958
|
+
|
|
2959
|
+
THEOREM WFMin ==
|
|
2960
|
+
ASSUME NEW R, NEW S,
|
|
2961
|
+
IsWellFoundedOn(R, S),
|
|
2962
|
+
NEW T, T \\subseteq S, T # {}
|
|
2963
|
+
PROVE \\E x \\in T : \\A y \\in T : ~ (<<y, x>> \\in R)
|
|
2964
|
+
|
|
2965
|
+
|
|
2966
|
+
THEOREM MinWF ==
|
|
2967
|
+
ASSUME NEW R, NEW S,
|
|
2968
|
+
\\A T \\in SUBSET S : T # {} => \\E x \\in T : \\A y \\in T : ~ (<<y, x>> \\in R)
|
|
2969
|
+
PROVE IsWellFoundedOn(R,S)
|
|
2970
|
+
|
|
2971
|
+
(***************************************************************************)
|
|
2972
|
+
(* The two following lemmas are simple consequences of theorem WFMin. *)
|
|
2973
|
+
(***************************************************************************)
|
|
2974
|
+
LEMMA WellFoundedIsIrreflexive ==
|
|
2975
|
+
ASSUME NEW R, NEW S, NEW x \\in S,
|
|
2976
|
+
IsWellFoundedOn(R, S)
|
|
2977
|
+
PROVE <<x, x>> \\notin R
|
|
2978
|
+
|
|
2979
|
+
LEMMA WellFoundedIsAsymmetric ==
|
|
2980
|
+
ASSUME NEW R, NEW S, NEW x \\in S, NEW y \\in S,
|
|
2981
|
+
IsWellFoundedOn(R,S),
|
|
2982
|
+
<<x,y>> \\in R, <<y,x>> \\in R
|
|
2983
|
+
PROVE FALSE
|
|
2984
|
+
|
|
2985
|
+
(***************************************************************************)
|
|
2986
|
+
(* The following lemmas are simple facts about operator SetLessThan. *)
|
|
2987
|
+
(***************************************************************************)
|
|
2988
|
+
LEMMA WFSetLessThanIrreflexive ==
|
|
2989
|
+
ASSUME NEW R, NEW S, NEW x \\in S,
|
|
2990
|
+
IsWellFoundedOn(R,S)
|
|
2991
|
+
PROVE x \\notin SetLessThan(x,R,S)
|
|
2992
|
+
|
|
2993
|
+
LEMMA SetLessTransitive ==
|
|
2994
|
+
ASSUME NEW R, NEW S, NEW x \\in S, NEW y \\in SetLessThan(x,R,S),
|
|
2995
|
+
IsTransitivelyClosedOn(R, S)
|
|
2996
|
+
PROVE SetLessThan(y, R, S) \\subseteq SetLessThan(x, R, S)
|
|
2997
|
+
|
|
2998
|
+
----------------------------------------------------------------------------
|
|
2999
|
+
(***************************************************************************)
|
|
3000
|
+
(* The following theorem is the basis for proof by induction over a *)
|
|
3001
|
+
(* well-founded set. It generalizes theorem GeneralNatInduction of module *)
|
|
3002
|
+
(* NaturalsInduction. *)
|
|
3003
|
+
(***************************************************************************)
|
|
3004
|
+
THEOREM WFInduction ==
|
|
3005
|
+
ASSUME NEW P(_), NEW R, NEW S,
|
|
3006
|
+
IsWellFoundedOn(R, S),
|
|
3007
|
+
\\A x \\in S : (\\A y \\in SetLessThan(x, R, S) : P(y))
|
|
3008
|
+
=> P(x)
|
|
3009
|
+
PROVE \\A x \\in S : P(x)
|
|
3010
|
+
|
|
3011
|
+
(***************************************************************************)
|
|
3012
|
+
(* Theorem WFInductiveDef below justifies recursive definitions based on a *)
|
|
3013
|
+
(* well-founded ordering. We first prove it with the hypothesis that the *)
|
|
3014
|
+
(* ordering is transitively closed. We prove the theorem for an arbitrary *)
|
|
3015
|
+
(* well-founded relation by applying the special case to its transitive *)
|
|
3016
|
+
(* closure. *)
|
|
3017
|
+
(***************************************************************************)
|
|
3018
|
+
WFDefOn(R, S, Def(_,_)) ==
|
|
3019
|
+
\\A g, h :
|
|
3020
|
+
\\A x \\in S :
|
|
3021
|
+
(\\A y \\in SetLessThan(x, R, S) : g[y] = h[y])
|
|
3022
|
+
=> (Def(g,x) = Def(h,x))
|
|
3023
|
+
|
|
3024
|
+
OpDefinesFcn(f, S, Def(_,_)) ==
|
|
3025
|
+
f = CHOOSE g : g = [x \\in S |-> Def(g, x)]
|
|
3026
|
+
|
|
3027
|
+
WFInductiveDefines(f, S, Def(_,_)) ==
|
|
3028
|
+
f = [x \\in S |-> Def(f, x)]
|
|
3029
|
+
|
|
3030
|
+
WFInductiveUnique(S, Def(_,_)) ==
|
|
3031
|
+
\\A g, h : /\\ WFInductiveDefines(g, S, Def)
|
|
3032
|
+
/\\ WFInductiveDefines(h, S, Def)
|
|
3033
|
+
=> (g = h)
|
|
3034
|
+
|
|
3035
|
+
THEOREM WFDefOnUnique ==
|
|
3036
|
+
ASSUME NEW Def(_,_), NEW R, NEW S,
|
|
3037
|
+
IsWellFoundedOn(R, S), WFDefOn(R, S, Def)
|
|
3038
|
+
PROVE WFInductiveUnique(S, Def)
|
|
3039
|
+
|
|
3040
|
+
LEMMA WFInductiveDefLemma ==
|
|
3041
|
+
ASSUME NEW Def(_,_), NEW R, NEW S, NEW f,
|
|
3042
|
+
IsWellFoundedOn(R, S),
|
|
3043
|
+
IsTransitivelyClosedOn(R, S),
|
|
3044
|
+
WFDefOn(R, S, Def),
|
|
3045
|
+
OpDefinesFcn(f, S, Def)
|
|
3046
|
+
PROVE WFInductiveDefines(f, S, Def)
|
|
3047
|
+
|
|
3048
|
+
(***************************************************************************)
|
|
3049
|
+
(* The following defines the transitive closure of the relation R on S. *)
|
|
3050
|
+
(* More precisely, it is the transitive closure of the restriction of R *)
|
|
3051
|
+
(* to S. We give an abstract definition of transitive closure as the *)
|
|
3052
|
+
(* smallest relation that contains R (restricted to S \\X S) and that is *)
|
|
3053
|
+
(* transitively closed, then prove some relevant properties. *)
|
|
3054
|
+
(***************************************************************************)
|
|
3055
|
+
TransitiveClosureOn(R,S) ==
|
|
3056
|
+
{ ss \\in S \\X S :
|
|
3057
|
+
\\A U \\in SUBSET (S \\X S) :
|
|
3058
|
+
/\\ R \\cap S \\X S \\subseteq U
|
|
3059
|
+
/\\ IsTransitivelyClosedOn(U, S)
|
|
3060
|
+
=> ss \\in U }
|
|
3061
|
+
|
|
3062
|
+
LEMMA TransitiveClosureThm ==
|
|
3063
|
+
\\A R, S :
|
|
3064
|
+
/\\ R \\cap S \\X S \\subseteq TransitiveClosureOn(R, S)
|
|
3065
|
+
/\\ IsTransitivelyClosedOn(TransitiveClosureOn(R, S), S)
|
|
3066
|
+
|
|
3067
|
+
LEMMA TransitiveClosureMinimal ==
|
|
3068
|
+
ASSUME NEW R, NEW S, NEW U \\in SUBSET (S \\X S),
|
|
3069
|
+
R \\cap S \\X S \\subseteq U,
|
|
3070
|
+
IsTransitivelyClosedOn(U,S)
|
|
3071
|
+
PROVE TransitiveClosureOn(R,S) \\subseteq U
|
|
3072
|
+
|
|
3073
|
+
(***************************************************************************)
|
|
3074
|
+
(* The following lemmas are consequences of the two previous ones. The *)
|
|
3075
|
+
(* first three state closure properties of transitive closure, the fourth *)
|
|
3076
|
+
(* lemma allows one to chop off a step in the underlying relation for any *)
|
|
3077
|
+
(* pair in the transitive closure. *)
|
|
3078
|
+
(***************************************************************************)
|
|
3079
|
+
|
|
3080
|
+
LEMMA TCTCTC ==
|
|
3081
|
+
ASSUME NEW R, NEW S, NEW i \\in S, NEW j \\in S, NEW k \\in S,
|
|
3082
|
+
<<i,j>> \\in TransitiveClosureOn(R,S),
|
|
3083
|
+
<<j,k>> \\in TransitiveClosureOn(R,S)
|
|
3084
|
+
PROVE <<i,k>> \\in TransitiveClosureOn(R,S)
|
|
3085
|
+
|
|
3086
|
+
LEMMA TCRTC ==
|
|
3087
|
+
ASSUME NEW R, NEW S, NEW i \\in S, NEW j \\in S, NEW k \\in S,
|
|
3088
|
+
<<i,j>> \\in TransitiveClosureOn(R,S), <<j,k>> \\in R
|
|
3089
|
+
PROVE <<i,k>> \\in TransitiveClosureOn(R,S)
|
|
3090
|
+
|
|
3091
|
+
LEMMA RTCTC ==
|
|
3092
|
+
ASSUME NEW R, NEW S, NEW i \\in S, NEW j \\in S, NEW k \\in S,
|
|
3093
|
+
<<i,j>> \\in R, <<j,k>> \\in TransitiveClosureOn(R,S)
|
|
3094
|
+
PROVE <<i,k>> \\in TransitiveClosureOn(R,S)
|
|
3095
|
+
|
|
3096
|
+
LEMMA TransitiveClosureChopLast ==
|
|
3097
|
+
ASSUME NEW R, NEW S, NEW i \\in S, NEW k \\in S, <<i,k>> \\in TransitiveClosureOn(R,S)
|
|
3098
|
+
PROVE \\E j \\in S : /\\ <<j,k>> \\in R
|
|
3099
|
+
/\\ i = j \\/ <<i,j>> \\in TransitiveClosureOn(R,S)
|
|
3100
|
+
|
|
3101
|
+
(***************************************************************************)
|
|
3102
|
+
(* NB: In a similar way to the preceding lemma, one could prove *)
|
|
3103
|
+
(* ASSUME NEW R, NEW S, NEW x \\in S, NEW y \\in S, *)
|
|
3104
|
+
(* <<x,y>> \\in TransitiveClosureOn(R,S) *)
|
|
3105
|
+
(* PROVE \\E n \\in Nat : \\E f \\in [0..(n+1) -> S] : *)
|
|
3106
|
+
(* /\\ \\A i \\in 0..n : <<f[i], f[i+1]>> \\in R *)
|
|
3107
|
+
(* /\\ x = f[0] /\\ y = f[n+1] *)
|
|
3108
|
+
(* which provides a more constructive characterization of transitive *)
|
|
3109
|
+
(* closure. The converse theorem would be proved by induction on n, *)
|
|
3110
|
+
(* using the above closure properties. *)
|
|
3111
|
+
(***************************************************************************)
|
|
3112
|
+
|
|
3113
|
+
THEOREM TransitiveClosureWF ==
|
|
3114
|
+
ASSUME NEW R, NEW S, IsWellFoundedOn(R,S)
|
|
3115
|
+
PROVE IsWellFoundedOn(TransitiveClosureOn(R, S), S)
|
|
3116
|
+
|
|
3117
|
+
THEOREM WFInductiveDef ==
|
|
3118
|
+
ASSUME NEW Def(_,_), NEW R, NEW S, NEW f,
|
|
3119
|
+
IsWellFoundedOn(R, S),
|
|
3120
|
+
WFDefOn(R, S, Def),
|
|
3121
|
+
OpDefinesFcn(f, S, Def)
|
|
3122
|
+
PROVE WFInductiveDefines(f, S, Def)
|
|
3123
|
+
|
|
3124
|
+
(***************************************************************************)
|
|
3125
|
+
(* Theorem WFInductiveDef allows us to conclude that a recursively defined *)
|
|
3126
|
+
(* function satisfies its recursion equation. The following result allows *)
|
|
3127
|
+
(* us to deduce the range of this function. *)
|
|
3128
|
+
(***************************************************************************)
|
|
3129
|
+
THEOREM WFInductiveDefType ==
|
|
3130
|
+
ASSUME NEW Def(_,_), NEW f, NEW R, NEW S, NEW T,
|
|
3131
|
+
T # {},
|
|
3132
|
+
IsWellFoundedOn(R, S),
|
|
3133
|
+
WFDefOn(R, S, Def),
|
|
3134
|
+
WFInductiveDefines(f, S, Def),
|
|
3135
|
+
\\A g \\in [S -> T], s \\in S : Def(g, s) \\in T
|
|
3136
|
+
PROVE f \\in [S -> T]
|
|
3137
|
+
|
|
3138
|
+
----------------------------------------------------------------------------
|
|
3139
|
+
(***************************************************************************)
|
|
3140
|
+
(* Below are some theorems that allow us to derive some useful *)
|
|
3141
|
+
(* well-founded relations from a given well-founded relation. First, we *)
|
|
3142
|
+
(* define the operator OpToRel that constructs a relation (a set of *)
|
|
3143
|
+
(* ordered pairs) from a relation expressed as an operator. *)
|
|
3144
|
+
(***************************************************************************)
|
|
3145
|
+
OpToRel(_\\prec_, S) == {ss \\in S \\X S : ss[1] \\prec ss[2]}
|
|
3146
|
+
|
|
3147
|
+
(***************************************************************************)
|
|
3148
|
+
(* To construct well-founded relations from the less-than relation on the *)
|
|
3149
|
+
(* natural numbers, we first prove that it is well-founded. *)
|
|
3150
|
+
(***************************************************************************)
|
|
3151
|
+
THEOREM NatLessThanWellFounded == IsWellFoundedOn(OpToRel(<,Nat), Nat)
|
|
3152
|
+
|
|
3153
|
+
(***************************************************************************)
|
|
3154
|
+
(* The next definition would be easier to read if we used the TLA+ *)
|
|
3155
|
+
(* construct {<<x, y>> \\in T : ... }. However, TLAPS does not suport *)
|
|
3156
|
+
(* that notation. (It's meaning is rather complicated in the general case *)
|
|
3157
|
+
(* when T is not a Cartesian product of sets.) *)
|
|
3158
|
+
(***************************************************************************)
|
|
3159
|
+
PreImage(f(_), S, R) == {ss \\in S \\X S : <<f(ss[1]), f(ss[2])>> \\in R}
|
|
3160
|
+
|
|
3161
|
+
THEOREM PreImageWellFounded ==
|
|
3162
|
+
ASSUME NEW S, NEW T, NEW R, NEW f(_),
|
|
3163
|
+
\\A s \\in S : f(s) \\in T,
|
|
3164
|
+
IsWellFoundedOn(R, T)
|
|
3165
|
+
PROVE IsWellFoundedOn(PreImage(f, S, R), S)
|
|
3166
|
+
|
|
3167
|
+
(***************************************************************************)
|
|
3168
|
+
(* We now prove that the lexicographical ordering on the Cartesian product *)
|
|
3169
|
+
(* of two well-ordered sets is well-ordered. *)
|
|
3170
|
+
(***************************************************************************)
|
|
3171
|
+
LexPairOrdering(R1, R2, S1, S2) ==
|
|
3172
|
+
{ss \\in (S1 \\X S2) \\X (S1 \\X S2) :
|
|
3173
|
+
\\/ <<ss[1][1], ss[2][1]>> \\in R1
|
|
3174
|
+
\\/ /\\ ss[1][1] = ss[2][1]
|
|
3175
|
+
/\\ <<ss[1][2], ss[2][2]>> \\in R2}
|
|
3176
|
+
|
|
3177
|
+
THEOREM WFLexPairOrdering ==
|
|
3178
|
+
ASSUME NEW R1, NEW R2, NEW S1, NEW S2,
|
|
3179
|
+
IsWellFoundedOn(R1, S1),
|
|
3180
|
+
IsWellFoundedOn(R2, S2)
|
|
3181
|
+
PROVE IsWellFoundedOn(LexPairOrdering(R1, R2, S1, S2), S1 \\X S2)
|
|
3182
|
+
|
|
3183
|
+
(***************************************************************************)
|
|
3184
|
+
(* The preceding theorem generalizes in the obvious way to the Cartesian *)
|
|
3185
|
+
(* product of a finite number of well-ordered sets. However, the *)
|
|
3186
|
+
(* statement of the general theorem is rather complicated, so we state it *)
|
|
3187
|
+
(* for the most useful case: the Cartesian product of n copies of the same *)
|
|
3188
|
+
(* set. *)
|
|
3189
|
+
(***************************************************************************)
|
|
3190
|
+
LexProductOrdering(R, S, n) ==
|
|
3191
|
+
{ ff \\in [1..n -> S] \\X [1..n -> S] :
|
|
3192
|
+
\\E j \\in 1..n :
|
|
3193
|
+
/\\ \\A i \\in 1..(j-1) : ff[1][i] = ff[2][i]
|
|
3194
|
+
/\\ <<ff[1][j], ff[2][j]>> \\in R }
|
|
3195
|
+
|
|
3196
|
+
THEOREM WFLexProductOrdering ==
|
|
3197
|
+
ASSUME NEW R, NEW S, NEW n \\in Nat,
|
|
3198
|
+
IsWellFoundedOn(R, S)
|
|
3199
|
+
PROVE IsWellFoundedOn(LexProductOrdering(R, S, n), [1..n -> S])
|
|
3200
|
+
|
|
3201
|
+
=============================================================================
|
|
3202
|
+
\\* Modification History
|
|
3203
|
+
\\* Last modified Thu Aug 22 18:31:26 CEST 2019 by merz
|
|
3204
|
+
\\* Last modified Sun Jan 01 18:39:23 CET 2012 by merz
|
|
3205
|
+
\\* Last modified Wed Nov 23 10:13:18 PST 2011 by lamport
|
|
3206
|
+
`,
|
|
3207
|
+
],
|
|
3208
|
+
]);
|