7.14. Statements of Examples
The exact statements behind the claims of the running examples: the folio, the account, the shift and the small histories.
theorem the_shift_file_defines_five_event_types_and_five_rules :
(loadFile shiftText).toOption.map (·.entities.map fun d => (d.events.map (·.name), d.rules.length)) =
some [(["ShiftCreated", "ShiftRescheduled", "ShiftCancelled", "EmployeeAssigned", "EmployeeUnassigned"], 5)]
theorem assigning_a_person_to_a_shift_that_does_not_exist_is_rejected :
verdict (deployedFrom [shiftText]) (assigned "anna") = .rejectedByRule 3
theorem creating_a_shift_that_ends_before_it_starts_is_rejected :
verdict (deployedFrom [shiftText]) shiftEndingBeforeItStarts = .rejectedByRule 1
theorem creating_a_shift_is_accepted :
verdict (deployedFrom [shiftText]) shiftCreated = .accepted
theorem creating_a_shift_twice_is_rejected :
verdict (afterEvents (deployedFrom [shiftText]) [shiftCreated]) shiftCreated = .rejectedByRule 1
theorem assigning_a_person_to_a_created_shift_is_accepted :
verdict (afterEvents (deployedFrom [shiftText]) [shiftCreated]) (assigned "anna") = .accepted
theorem assigning_the_same_person_twice_is_rejected :
verdict (afterEvents (deployedFrom [shiftText]) [shiftCreated, assigned "anna"]) (assigned "anna") =
.rejectedByRule 4
theorem assigning_a_second_person_to_a_full_shift_is_rejected :
verdict (afterEvents (deployedFrom [shiftText]) [shiftCreated, assigned "anna"]) (assigned "ben") =
.rejectedByRule 4
theorem unassigning_someone_who_is_not_on_the_shift_is_rejected :
verdict (afterEvents (deployedFrom [shiftText]) [shiftCreated, assigned "anna"]) (unassigned "ben") =
.rejectedByRule 5
theorem unassigning_someone_on_the_shift_is_accepted :
verdict (afterEvents (deployedFrom [shiftText]) [shiftCreated, assigned "anna"]) (unassigned "anna") =
.accepted
theorem a_place_freed_by_unassigning_can_be_taken_by_another_person :
verdict (afterEvents (deployedFrom [shiftText]) [shiftCreated, assigned "anna", unassigned "anna"]) (assigned "ben") =
.accepted
theorem cancelling_a_shift_is_accepted :
verdict (afterEvents (deployedFrom [shiftText]) [shiftCreated, assigned "anna"]) shiftCancelled = .accepted
theorem assigning_a_person_to_a_cancelled_shift_is_rejected :
verdict (afterEvents (deployedFrom [shiftText]) [shiftCreated, assigned "anna", shiftCancelled]) (assigned "carl") =
.rejectedByRule 3
theorem the_account_file_defines_two_event_types_and_two_rules :
(loadFile accountFileText).toOption.map (·.entities.map fun d => (d.events.map (·.name), d.rules.length)) =
some [(["MoneyDeposited", "MoneyWithdrawn"], 2)]
theorem a_deposit_is_accepted :
verdict (deployedFrom [accountFileText]) (accountEvent "MoneyDeposited" 100) = .accepted
theorem a_withdrawal_within_the_balance_is_accepted :
verdict (afterEvents (deployedFrom [accountFileText]) [accountEvent "MoneyDeposited" 100])
(accountEvent "MoneyWithdrawn" 30) = .accepted
theorem a_withdrawal_above_the_balance_is_rejected :
verdict (afterEvents (deployedFrom [accountFileText]) [accountEvent "MoneyDeposited" 100])
(accountEvent "MoneyWithdrawn" 101) = .rejectedByRule 1
theorem a_withdrawal_of_zero_is_rejected :
verdict (afterEvents (deployedFrom [accountFileText]) [accountEvent "MoneyDeposited" 100])
(accountEvent "MoneyWithdrawn" 0) = .rejectedByRule 2
theorem a_second_withdrawal_on_the_same_day_is_rejected :
verdict (afterEvents (deployedFrom [accountFileText]) [accountEvent "MoneyDeposited" 100, accountEvent "MoneyWithdrawn" 10])
(accountEvent "MoneyWithdrawn" 10) = .rejectedByRule 2
theorem a_withdrawal_on_the_next_day_is_accepted :
verdict (afterEvents (deployedFrom [accountFileText]) [accountEvent "MoneyDeposited" 100, accountEvent "MoneyWithdrawn" 10])
(accountEvent "MoneyWithdrawn" 10 (usPerDay + 1)) = .accepted
theorem opening_a_folio_is_accepted :
verdict (deployedFrom [folioText]) folioOpened = .accepted
theorem a_charge_on_an_open_folio_is_accepted :
verdict (afterEvents (deployedFrom [folioText]) [folioOpened]) folioCharge = .accepted
theorem a_charge_on_a_closed_folio_is_rejected :
verdict (afterEvents (deployedFrom [folioText]) [folioOpened, folioClosed]) folioCharge = .rejectedByRule 1
theorem closing_a_folio_twice_is_rejected :
verdict (afterEvents (deployedFrom [folioText]) [folioOpened, folioClosed]) folioClosed = .rejectedByRule 1
theorem a_charge_with_a_note_is_accepted :
verdict (deployedFrom [folioText])
{ folioCharge with fields := folioCharge.fields ++ [("note", .str "minibar")] } = .accepted
theorem a_charge_with_a_null_note_is_accepted :
verdict (deployedFrom [folioText])
{ folioCharge with fields := folioCharge.fields ++ [("note", .null)] } = .accepted
theorem a_charge_without_its_amount_is_not_valid :
verdict (deployedFrom [folioText])
(folioEvent "ChargePosted" [("charge_id", .str "C1")]) = .notValid
theorem a_charge_with_a_null_amount_is_not_valid :
verdict (deployedFrom [folioText])
(folioEvent "ChargePosted" [("charge_id", .str "C1"), ("gross_minor", .null)]) = .notValid
theorem a_charge_with_a_text_as_its_amount_is_not_valid :
verdict (deployedFrom [folioText])
(folioEvent "ChargePosted" [("charge_id", .str "C1"), ("gross_minor", .str "12.50")]) = .notValid
theorem a_charge_with_an_unlisted_field_is_not_valid :
verdict (deployedFrom [folioText]) { folioCharge with fields := folioCharge.fields ++ [("tip", .num 1)] } = .notValid
theorem an_event_of_an_undefined_type_is_not_valid :
verdict (deployedFrom [folioText]) (folioEvent "FolioReopened") = .notValid
theorem an_event_without_a_key_is_not_valid :
verdict (deployedFrom [folioText]) { folioOpened with key := "" } = .notValid
theorem opening_a_new_folio_expecting_revision_0_is_accepted :
verdict (deployedFrom [folioText]) { folioOpened with expected_revision := some 0 } = .accepted
theorem a_charge_expecting_the_current_revision_is_accepted :
verdict (afterEvents (deployedFrom [folioText]) [folioOpened]) { folioCharge with expected_revision := some 1 } =
.accepted
theorem a_charge_expecting_an_older_revision_is_rejected :
verdict (afterEvents (deployedFrom [folioText]) [folioOpened, folioCharge]) { folioCharge with expected_revision := some 1 } =
.wrongRevision
theorem a_deploy_that_adds_an_optional_field_is_accepted :
redeploys folioText [folioOpened, folioCharge] folioWithTipText = true
theorem a_deploy_that_adds_a_required_field_is_rejected :
redeploys folioText [folioOpened, folioCharge] folioWithTaxText = false
theorem a_deploy_that_makes_a_required_field_optional_is_accepted :
redeploys folioText [folioOpened, folioCharge] folioWithOptionalAmountText = true
theorem a_deploy_that_makes_an_optional_field_required_is_rejected :
redeploys folioText [folioOpened, folioCharge] folioWithRequiredNoteText = false
theorem a_deploy_that_changes_the_type_of_a_field_is_rejected :
redeploys folioText [folioOpened, folioCharge] folioWithTextAmountText = false
theorem a_deploy_that_removes_a_field_is_rejected :
redeploys folioText [folioOpened, folioCharge] folioWithoutChargeIdText = false
theorem a_deploy_that_removes_a_type_without_events_is_accepted :
redeploys folioText [folioOpened] folioWithoutChargesText = true
theorem a_deploy_that_removes_a_type_with_events_is_rejected :
redeploys folioText [folioOpened, folioCharge] folioWithoutChargesText = false
theorem a_field_named_at_is_rejected_on_deploy :
redeploys folioText [] folioWithFieldNamedAtText = false
theorem a_deposit_with_a_new_id_is_accepted :
verdict (afterEvents (deployedFrom [depositText]) [depositWithId "d1"]) (depositWithId "d2") = .accepted
theorem a_deposit_sent_again_with_the_same_id_is_rejected :
verdict (afterEvents (deployedFrom [depositText]) [depositWithId "d1"]) (depositWithId "d1") = .rejectedByRule 1
theorem one_divided_by_zero_is_null : valueOfExpr "1 / 0" = some .null
theorem one_third_times_three_is_one : valueOfExpr "1 / 3 * 3" = some (.num 1)
theorem a_missing_value_plus_one_is_null : valueOfExpr "(last of Missing).x + 1" = some .null
theorem round_of_2_5_is_3_and_of_minus_2_5_is_minus_3 :
valueOfExpr "round(2.5)" = some (.num 3) ∧ valueOfExpr "round(0 - 2.5)" = some (.num (-3))
theorem floor_of_2_9_is_2_and_ceil_of_2_1_is_3 :
valueOfExpr "floor(2.9)" = some (.num 2) ∧ valueOfExpr "ceil(2.1)" = some (.num 3)
theorem lower_of_a_mixed_case_email_is_lowercase :
valueOfExpr "lower('Ann@X.ch')" = some (.str "ann@x.ch")
theorem a_day_after_a_timestamp_is_the_same_time_the_next_day :
valueOfExpr "2026-12-01T10:00:00Z + 1 day" = valueOfExpr "2026-12-02T10:00:00Z"
theorem three_days_after_a_date_is_the_date_three_days_later :
valueOfExpr "2026-12-01 + 3 days" = valueOfExpr "2026-12-04"
theorem a_week_is_7_days_and_a_month_is_30_days :
valueOfExpr "1 week" = valueOfExpr "7 days" ∧ valueOfExpr "1 month" = valueOfExpr "30 days"
theorem the_range_from_the_1st_to_the_4th_of_december_has_3_days :
valueOfExpr "range(2026-12-01, 2026-12-04)" =
some (.dateRange (daysFromCivil 2026 12 1) (daysFromCivil 2026 12 4))
theorem sunday_and_the_following_monday_are_in_different_weeks :
weekOf (timestampOf 2026 12 6 12 0 0) ≠ weekOf (timestampOf 2026 12 7 12 0 0)
theorem the_last_second_of_november_and_the_first_of_december_are_in_different_months :
monthOf (timestampOf 2026 11 30 23 59 59) ≠ monthOf (timestampOf 2026 12 1 0 0 0)
theorem the_deposits_sum_to_150_and_there_is_one_withdrawal :
valueOn "sum(MoneyDeposited.amount)" accountHistory = some (.num 150) ∧
valueOn "count(MoneyWithdrawn)" accountHistory = some (.num 1)
theorem the_last_deposit_is_50_the_smallest_is_50_the_largest_is_100 :
valueOn "(last of MoneyDeposited).amount" accountHistory = some (.num 50) ∧
valueOn "min(MoneyDeposited.amount)" accountHistory = some (.num 50) ∧
valueOn "max(MoneyDeposited.amount)" accountHistory = some (.num 100)
theorem the_average_deposit_is_75 :
valueOn "sum(MoneyDeposited.amount) / count(MoneyDeposited)" accountHistory = some (.num 75)
theorem on_an_empty_history_the_sum_is_0_and_the_last_value_is_null :
valueOn "sum(MoneyDeposited.amount)" [] = some (.num 0) ∧
valueOn "(last of MoneyDeposited).amount" [] = some .null
theorem a_list_of_types_picks_the_charges_and_the_voids :
picksFrom "[ChargePosted, ChargeVoided]" folioHistory = some ["ChargePosted", "ChargeVoided"]
theorem any_except_closing_and_reopening_picks_the_other_events :
picksFrom "any except [FolioClosed, FolioReopened]" folioHistory =
some ["FolioOpened", "ChargePosted", "ChargeVoided"]
theorem a_reopened_folio_is_not_closed :
holdsOn "last of [FolioClosed, FolioReopened] is FolioClosed" folioHistory = some false ∧
holdsOn "last of [FolioClosed, FolioReopened] is FolioClosed" (folioHistory.dropLast) = some true
theorem a_folio_with_a_charge_has_ever_had_one_and_never_had_a_refund :
holdsOn "ever ChargePosted" folioHistory = some true ∧ holdsOn "never ChargeRefunded" folioHistory = some true
theorem quantities_compare_the_number_of_picked_events :
holdsOn "at least 2 [FolioOpened, ChargePosted, ChargeVoided]" folioHistory = some true ∧
holdsOn "at most 1 FolioClosed" folioHistory = some true ∧
holdsOn "exactly 2 FolioClosed" folioHistory = some false ∧
holdsOn "between 1 and 3 ChargePosted" folioHistory = some true
theorem a_comparison_with_null_is_false_and_is_null_is_true :
holdsOn "(last of Missing).x > 1" [] = some false ∧
holdsOn "(last of Missing).x != 1" [] = some false ∧
holdsOn "(last of Missing).x is null" [] = some true
theorem a_minibar_charge_on_a_folio_that_is_not_checked_in_is_rejected :
minibarRules.accepts [fo "FolioOpened"] (chargeOf "Minibar") = false
theorem the_fourth_failed_login_in_an_hour_is_allowed_and_the_fifth_is_rejected :
loginRules.accepts fails3 (fail 1300) = true ∧ loginRules.accepts (fails3 ++ [fail 1300]) (fail 1400) = false
theorem withdrawing_101_from_an_account_holding_100_is_rejected :
accountRules.accepts [amt "MoneyDeposited" 100] (amt "MoneyWithdrawn" 101) = false
theorem a_second_user_whose_email_differs_only_in_case_is_rejected :
userRules.accepts [created "U1" "Ann@x.ch"] (created "U2" "ann@X.ch") = false
theorem two_users_can_swap_emails_in_one_batch_through_a_temporary_address :
userRules.acceptsBatch ab [changed "U1" "tmp-U1@x.ch", changed "U2" "a@x.ch", changed "U1" "b@x.ch"] = true
theorem two_stored_users_with_the_same_email_break_the_email_invariant :
(userRules.violations dup).length = 1