Engine

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)]

proof: spec/Spec/Examples/Shift.lean:83

theorem assigning_a_person_to_a_shift_that_does_not_exist_is_rejected : verdict (deployedFrom [shiftText]) (assigned "anna") = .rejectedByRule 3

proof: spec/Spec/Examples/Shift.lean:89

theorem creating_a_shift_that_ends_before_it_starts_is_rejected : verdict (deployedFrom [shiftText]) shiftEndingBeforeItStarts = .rejectedByRule 1

proof: spec/Spec/Examples/Shift.lean:94

theorem creating_a_shift_is_accepted : verdict (deployedFrom [shiftText]) shiftCreated = .accepted

proof: spec/Spec/Examples/Shift.lean:99

theorem creating_a_shift_twice_is_rejected : verdict (afterEvents (deployedFrom [shiftText]) [shiftCreated]) shiftCreated = .rejectedByRule 1

proof: spec/Spec/Examples/Shift.lean:104

theorem assigning_a_person_to_a_created_shift_is_accepted : verdict (afterEvents (deployedFrom [shiftText]) [shiftCreated]) (assigned "anna") = .accepted

proof: spec/Spec/Examples/Shift.lean:109

theorem assigning_the_same_person_twice_is_rejected : verdict (afterEvents (deployedFrom [shiftText]) [shiftCreated, assigned "anna"]) (assigned "anna") = .rejectedByRule 4

proof: spec/Spec/Examples/Shift.lean:114

theorem assigning_a_second_person_to_a_full_shift_is_rejected : verdict (afterEvents (deployedFrom [shiftText]) [shiftCreated, assigned "anna"]) (assigned "ben") = .rejectedByRule 4

proof: spec/Spec/Examples/Shift.lean:120

theorem unassigning_someone_who_is_not_on_the_shift_is_rejected : verdict (afterEvents (deployedFrom [shiftText]) [shiftCreated, assigned "anna"]) (unassigned "ben") = .rejectedByRule 5

proof: spec/Spec/Examples/Shift.lean:126

theorem unassigning_someone_on_the_shift_is_accepted : verdict (afterEvents (deployedFrom [shiftText]) [shiftCreated, assigned "anna"]) (unassigned "anna") = .accepted

proof: spec/Spec/Examples/Shift.lean:132

theorem a_place_freed_by_unassigning_can_be_taken_by_another_person : verdict (afterEvents (deployedFrom [shiftText]) [shiftCreated, assigned "anna", unassigned "anna"]) (assigned "ben") = .accepted

proof: spec/Spec/Examples/Shift.lean:138

theorem cancelling_a_shift_is_accepted : verdict (afterEvents (deployedFrom [shiftText]) [shiftCreated, assigned "anna"]) shiftCancelled = .accepted

proof: spec/Spec/Examples/Shift.lean:144

theorem assigning_a_person_to_a_cancelled_shift_is_rejected : verdict (afterEvents (deployedFrom [shiftText]) [shiftCreated, assigned "anna", shiftCancelled]) (assigned "carl") = .rejectedByRule 3

proof: spec/Spec/Examples/Shift.lean:149

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)]

proof: spec/Spec/Examples/Account.lean:43

theorem a_deposit_is_accepted : verdict (deployedFrom [accountFileText]) (accountEvent "MoneyDeposited" 100) = .accepted

proof: spec/Spec/Examples/Account.lean:49

theorem a_withdrawal_within_the_balance_is_accepted : verdict (afterEvents (deployedFrom [accountFileText]) [accountEvent "MoneyDeposited" 100]) (accountEvent "MoneyWithdrawn" 30) = .accepted

proof: spec/Spec/Examples/Account.lean:54

theorem a_withdrawal_above_the_balance_is_rejected : verdict (afterEvents (deployedFrom [accountFileText]) [accountEvent "MoneyDeposited" 100]) (accountEvent "MoneyWithdrawn" 101) = .rejectedByRule 1

proof: spec/Spec/Examples/Account.lean:60

theorem a_withdrawal_of_zero_is_rejected : verdict (afterEvents (deployedFrom [accountFileText]) [accountEvent "MoneyDeposited" 100]) (accountEvent "MoneyWithdrawn" 0) = .rejectedByRule 2

proof: spec/Spec/Examples/Account.lean:66

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

proof: spec/Spec/Examples/Account.lean:72

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

proof: spec/Spec/Examples/Account.lean:78

theorem opening_a_folio_is_accepted : verdict (deployedFrom [folioText]) folioOpened = .accepted

proof: spec/Spec/Examples/Folio.lean:38

theorem a_charge_on_an_open_folio_is_accepted : verdict (afterEvents (deployedFrom [folioText]) [folioOpened]) folioCharge = .accepted

proof: spec/Spec/Examples/Folio.lean:43

theorem a_charge_on_a_closed_folio_is_rejected : verdict (afterEvents (deployedFrom [folioText]) [folioOpened, folioClosed]) folioCharge = .rejectedByRule 1

proof: spec/Spec/Examples/Folio.lean:48

theorem closing_a_folio_twice_is_rejected : verdict (afterEvents (deployedFrom [folioText]) [folioOpened, folioClosed]) folioClosed = .rejectedByRule 1

proof: spec/Spec/Examples/Folio.lean:53

theorem a_charge_with_a_note_is_accepted : verdict (deployedFrom [folioText]) { folioCharge with fields := folioCharge.fields ++ [("note", .str "minibar")] } = .accepted

proof: spec/Spec/Examples/Folio.lean:58

theorem a_charge_with_a_null_note_is_accepted : verdict (deployedFrom [folioText]) { folioCharge with fields := folioCharge.fields ++ [("note", .null)] } = .accepted

proof: spec/Spec/Examples/Folio.lean:64

theorem a_charge_without_its_amount_is_not_valid : verdict (deployedFrom [folioText]) (folioEvent "ChargePosted" [("charge_id", .str "C1")]) = .notValid

proof: spec/Spec/Examples/Folio.lean:70

theorem a_charge_with_a_null_amount_is_not_valid : verdict (deployedFrom [folioText]) (folioEvent "ChargePosted" [("charge_id", .str "C1"), ("gross_minor", .null)]) = .notValid

proof: spec/Spec/Examples/Folio.lean:76

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

proof: spec/Spec/Examples/Folio.lean:82

theorem a_charge_with_an_unlisted_field_is_not_valid : verdict (deployedFrom [folioText]) { folioCharge with fields := folioCharge.fields ++ [("tip", .num 1)] } = .notValid

proof: spec/Spec/Examples/Folio.lean:88

theorem an_event_of_an_undefined_type_is_not_valid : verdict (deployedFrom [folioText]) (folioEvent "FolioReopened") = .notValid

proof: spec/Spec/Examples/Folio.lean:93

theorem an_event_without_a_key_is_not_valid : verdict (deployedFrom [folioText]) { folioOpened with key := "" } = .notValid

proof: spec/Spec/Examples/Folio.lean:98

theorem opening_a_new_folio_expecting_revision_0_is_accepted : verdict (deployedFrom [folioText]) { folioOpened with expected_revision := some 0 } = .accepted

proof: spec/Spec/Examples/Folio.lean:103

theorem a_charge_expecting_the_current_revision_is_accepted : verdict (afterEvents (deployedFrom [folioText]) [folioOpened]) { folioCharge with expected_revision := some 1 } = .accepted

proof: spec/Spec/Examples/Folio.lean:108

theorem a_charge_expecting_an_older_revision_is_rejected : verdict (afterEvents (deployedFrom [folioText]) [folioOpened, folioCharge]) { folioCharge with expected_revision := some 1 } = .wrongRevision

proof: spec/Spec/Examples/Folio.lean:114

theorem a_deploy_that_adds_an_optional_field_is_accepted : redeploys folioText [folioOpened, folioCharge] folioWithTipText = true

proof: spec/Spec/Examples/FolioChanges.lean:146

theorem a_deploy_that_adds_a_required_field_is_rejected : redeploys folioText [folioOpened, folioCharge] folioWithTaxText = false

proof: spec/Spec/Examples/FolioChanges.lean:151

theorem a_deploy_that_makes_a_required_field_optional_is_accepted : redeploys folioText [folioOpened, folioCharge] folioWithOptionalAmountText = true

proof: spec/Spec/Examples/FolioChanges.lean:156

theorem a_deploy_that_makes_an_optional_field_required_is_rejected : redeploys folioText [folioOpened, folioCharge] folioWithRequiredNoteText = false

proof: spec/Spec/Examples/FolioChanges.lean:161

theorem a_deploy_that_changes_the_type_of_a_field_is_rejected : redeploys folioText [folioOpened, folioCharge] folioWithTextAmountText = false

proof: spec/Spec/Examples/FolioChanges.lean:166

theorem a_deploy_that_removes_a_field_is_rejected : redeploys folioText [folioOpened, folioCharge] folioWithoutChargeIdText = false

proof: spec/Spec/Examples/FolioChanges.lean:171

theorem a_deploy_that_removes_a_type_without_events_is_accepted : redeploys folioText [folioOpened] folioWithoutChargesText = true

proof: spec/Spec/Examples/FolioChanges.lean:176

theorem a_deploy_that_removes_a_type_with_events_is_rejected : redeploys folioText [folioOpened, folioCharge] folioWithoutChargesText = false

proof: spec/Spec/Examples/FolioChanges.lean:181

theorem a_field_named_at_is_rejected_on_deploy : redeploys folioText [] folioWithFieldNamedAtText = false

proof: spec/Spec/Examples/FolioChanges.lean:205

theorem a_deposit_with_a_new_id_is_accepted : verdict (afterEvents (deployedFrom [depositText]) [depositWithId "d1"]) (depositWithId "d2") = .accepted

proof: spec/Spec/Examples/Deposit.lean:39

theorem a_deposit_sent_again_with_the_same_id_is_rejected : verdict (afterEvents (deployedFrom [depositText]) [depositWithId "d1"]) (depositWithId "d1") = .rejectedByRule 1

proof: spec/Spec/Examples/Deposit.lean:44

theorem one_divided_by_zero_is_null : valueOfExpr "1 / 0" = some .null

proof: spec/Spec/Examples/Values.lean:17

theorem one_third_times_three_is_one : valueOfExpr "1 / 3 * 3" = some (.num 1)

proof: spec/Spec/Examples/Values.lean:21

theorem a_missing_value_plus_one_is_null : valueOfExpr "(last of Missing).x + 1" = some .null

proof: spec/Spec/Examples/Values.lean:25

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))

proof: spec/Spec/Examples/Values.lean:29

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)

proof: spec/Spec/Examples/Values.lean:36

theorem lower_of_a_mixed_case_email_is_lowercase : valueOfExpr "lower('Ann@X.ch')" = some (.str "ann@x.ch")

proof: spec/Spec/Examples/Values.lean:43

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"

proof: spec/Spec/Examples/Values.lean:48

theorem three_days_after_a_date_is_the_date_three_days_later : valueOfExpr "2026-12-01 + 3 days" = valueOfExpr "2026-12-04"

proof: spec/Spec/Examples/Values.lean:69

theorem a_week_is_7_days_and_a_month_is_30_days : valueOfExpr "1 week" = valueOfExpr "7 days" ∧ valueOfExpr "1 month" = valueOfExpr "30 days"

proof: spec/Spec/Examples/Values.lean:76

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))

proof: spec/Spec/Examples/Values.lean:83

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)

proof: spec/Spec/Examples/Values.lean:97

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)

proof: spec/Spec/Examples/Values.lean:102

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)

proof: spec/Spec/Examples/Values.lean:111

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)

proof: spec/Spec/Examples/Values.lean:118

theorem the_average_deposit_is_75 : valueOn "sum(MoneyDeposited.amount) / count(MoneyDeposited)" accountHistory = some (.num 75)

proof: spec/Spec/Examples/Values.lean:127

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

proof: spec/Spec/Examples/Values.lean:133

theorem a_list_of_types_picks_the_charges_and_the_voids : picksFrom "[ChargePosted, ChargeVoided]" folioHistory = some ["ChargePosted", "ChargeVoided"]

proof: spec/Spec/Examples/Values.lean:144

theorem any_except_closing_and_reopening_picks_the_other_events : picksFrom "any except [FolioClosed, FolioReopened]" folioHistory = some ["FolioOpened", "ChargePosted", "ChargeVoided"]

proof: spec/Spec/Examples/Values.lean:149

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

proof: spec/Spec/Examples/Values.lean:155

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

proof: spec/Spec/Examples/Values.lean:164

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

proof: spec/Spec/Examples/Values.lean:170

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

proof: spec/Spec/Examples/Values.lean:182

theorem a_minibar_charge_on_a_folio_that_is_not_checked_in_is_rejected : minibarRules.accepts [fo "FolioOpened"] (chargeOf "Minibar") = false

proof: spec/Spec/Examples/Small.lean:19

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

proof: spec/Spec/Examples/Small.lean:23

theorem withdrawing_101_from_an_account_holding_100_is_rejected : accountRules.accepts [amt "MoneyDeposited" 100] (amt "MoneyWithdrawn" 101) = false

proof: spec/Spec/Examples/Small.lean:28

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

proof: spec/Spec/Examples/Small.lean:32

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

proof: spec/Spec/Examples/Small.lean:36

theorem two_stored_users_with_the_same_email_break_the_email_invariant : (userRules.violations dup).length = 1

proof: spec/Spec/Examples/Small.lean:41

theorem an_invariant_that_reads_the_incoming_event_is_not_well_typed : bad (.inv (.always (.cmp .gt (.incoming "gross_minor") 0))) = true

proof: spec/Spec/Examples/Small.lean:45