Skip to content

Commit

Permalink
Add Functions!Pointwise
Browse files Browse the repository at this point in the history
Adds Github issue #96
#96

[Feature]
  • Loading branch information
lemmy committed Jan 5, 2024
1 parent 64513ec commit 243fa67
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions modules/Functions.tla
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ RestrictValues(f, Test(_)) ==
(***************************************************************************)
Range(f) == { f[x] : x \in DOMAIN f }

(***************************************************************************)
(* Assuming DOMAIN f \subseteq DOMAIN g, apply the binary operation T to *)
(* the corresponding elements of the two functions f and g. *)
(* *)
(* Example: *)
(* LET f == ("a" :> 0 @@ "b" :> 1 @@ "c" :> 2) *)
(* g == ("a" :> 1 @@ "b" :> 1 @@ "c" :> 3) *)
(* IN Pointwise(f,g,+) = ("a" :> 1 @@ "b" :> 2 @@ "c" :> 5 ) *)
(***************************************************************************)
Pointwise(f, g, T(_,_)) == [ e \in DOMAIN f |-> T(f[e], g[e]) ]

(***************************************************************************)
(* The inverse of a function. *)
Expand Down
12 changes: 11 additions & 1 deletion tests/FunctionsTests.tla
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
------------------------- MODULE FunctionsTests -------------------------
EXTENDS Functions, Naturals, TLC, TLCExt, FiniteSets, Sequences
EXTENDS Functions, Integers, TLC, TLCExt, FiniteSets, Sequences

ASSUME LET T == INSTANCE TLC IN T!PrintT("FunctionsTests")

Expand Down Expand Up @@ -97,4 +97,14 @@ ASSUME
LET F == (0 :> "n1" @@ 2 :> "n2" @@ 1 :> "n3")
IN AntiFunction(AntiFunction(F)) = F

ASSUME
LET f == ("a" :> 0 @@ "b" :> 1 @@ "c" :> 2)
g == ("a" :> 1 @@ "b" :> 1 @@ "c" :> 3)
IN Pointwise(f,g,+) = ("a" :> 1 @@ "b" :> 2 @@ "c" :> 5 )

ASSUME
LET f == ("a" :> 1 @@ "b" :> 1 @@ "c" :> 2)
g == ("a" :> 1 @@ "b" :> 1 @@ "c" :> 3)
IN Pointwise(f,g,-) = ("a" :> 0 @@ "b" :> 0 @@ "c" :> (-1) )

=============================================================================

0 comments on commit 243fa67

Please sign in to comment.