note description: "Tri-valued logic, True, False, and Indeterminate." author: "Mischa Megens" date: "$Date: 2022/5 $" revision: "$Revision: 0.2$" expanded class KLEENEAN inherit KLEENEAN_ANCESTOR redefine default_create end create default_create, from_boolean convert from_boolean({BOOLEAN}) feature default_create do is_indeterminate := true end feature -- Conversion from_boolean(b: BOOLEAN) do is_certainly_true := b is_indeterminate := false end feature -- Access item: KLEENEAN -- Ternary Boolean value do Result := Current end feature indeterminate: KLEENEAN once -- Result.default_create end feature is_indeterminate: BOOLEAN is_certainly_true: BOOLEAN is_certainly_false: BOOLEAN do Result := not is_certainly_true and not is_indeterminate end set_is_certainly_true(b: BOOLEAN) do is_certainly_true := b is_indeterminate := false end feature -- Element change set_item (b: KLEENEAN) -- Make `b' the `item' value. do is_certainly_true := b.is_certainly_true is_indeterminate := b.is_indeterminate end feature -- Basic operations conjuncted alias "and" (other: KLEENEAN): KLEENEAN -- Boolean conjunction with `other' do Result := is_certainly_true and other.is_certainly_true if (is_indeterminate and not other.is_certainly_false) or (other.is_indeterminate and not is_certainly_false) then Result := indeterminate end end negated alias "not": KLEENEAN -- Negation do Result := not is_certainly_true if is_indeterminate then Result := indeterminate end end disjuncted alias "or" (other: KLEENEAN): KLEENEAN -- Boolean disjunction with `other' do Result := is_certainly_true or other.is_certainly_true if (is_indeterminate and not other.is_certainly_true) or (other.is_indeterminate and not is_certainly_true) then Result := indeterminate end end disjuncted_exclusive alias "xor" (other: KLEENEAN): KLEENEAN -- Boolean exclusive or with `other' do Result := (Current or other) and not (Current and other) end is_kleenean_equal (other: KLEENEAN): KLEENEAN do Result := (Current and other) or (not Current and not other); end invariant is_certainly_true implies not is_indeterminate; is_certainly_true implies not is_certainly_false; is_certainly_false implies not is_indeterminate; is_certainly_false implies not is_certainly_true; is_indeterminate implies not is_certainly_true; is_indeterminate implies not is_certainly_false; ((not is_certainly_false) and (not is_certainly_true)) implies is_indeterminate; end