Skip to content

Commit

Permalink
Isabelle pragmas (#105)
Browse files Browse the repository at this point in the history
* Adds pragmas and builtins needed for the translation to Isabelle/HOL.
* Depends on anoma/juvix#2868
  • Loading branch information
lukaszcz authored Jul 19, 2024
1 parent 2ff6172 commit 1621150
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions Stdlib/Data/Bool/Base.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Juvix.Builtin.V1.Bool open public;
import Stdlib.Data.Fixity open;

--- Logical negation.
{-# isabelle-function: {name: "¬"} #-}
not : Bool → Bool
| true := false
| false := true;
Expand Down
5 changes: 4 additions & 1 deletion Stdlib/Data/List/Base.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ foldl {A B} (f : B → A → B) (z : B) : List A → B

syntax iterator for {init := 1; range := 1};

{-# inline: 0 #-}
{-# inline: 0, isabelle-function: {name: "foldl"} #-}
for : {A B : Type} → (B → A → B) → B → List A → B := foldl;

syntax iterator map {init := 0; range := 1};
Expand All @@ -71,6 +71,7 @@ filter {A} (f : A → Bool) : List A → List A
length {A} (l : List A) : Nat := for (acc := zero) (_ in l) {suc acc};

--- 𝒪(𝓃). Returns the given ;List; in reverse order.
{-# isabelle-function: {name: "rev"} #-}
reverse {A} (l : List A) : List A := for (acc := nil) (x in l) {x :: acc};

--- Returns a ;List; of length n where every element is the given value.
Expand Down Expand Up @@ -123,6 +124,7 @@ syntax operator ++ cons;
snoc {A} (xs : List A) (x : A) : List A := xs ++ x :: nil;

--- Concatenates a ;List; of ;List;s.
{-# isabelle-function: {name: "concat"} #-}
flatten : {A : Type} → List (List A) → List A := foldl (++) nil;

--- 𝒪(𝓃). Inserts the given element before every element in the given ;List;.
Expand All @@ -136,6 +138,7 @@ intersperse {A} (sep : A) : List A → List A
| (x :: xs) := x :: prependToAll sep xs;

--- 𝒪(1). Drops the first element of a ;List;.
{-# isabelle-function: {name: "tl"} #-}
tail {A} : List A → List A
| (_ :: xs) := xs
| nil := nil;
Expand Down
2 changes: 1 addition & 1 deletion Stdlib/Data/Maybe/Base.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fromMaybe {A} (a : A) : Maybe A → A

--- Applies a function to the value from a ;Maybe; if present, else returns the
--- given value.
{-# inline: true #-}
{-# inline: true, isabelle-function: {name: "case_option"} #-}
maybe {A B} (b : B) (f : A → B) : Maybe A → B
| nothing := b
| (just a) := f a;
1 change: 1 addition & 0 deletions Stdlib/Data/Pair/Base.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Stdlib.Data.Fixity open;
syntax operator , pair;

--- Inductive pair. I.e. a tuple with two components.
builtin pair
type Pair (A B : Type) := , : A → B → Pair A B;

--- Converts a function of two arguments to a function with a product argument.
Expand Down
2 changes: 2 additions & 0 deletions Stdlib/Trait/DivMod.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ module Stdlib.Trait.DivMod;
trait
type DivMod A :=
mkDivMod {
{-# isabelle-operator: {name: "div", prec: 70, assoc: left} #-}
div : A -> A -> A;
{-# isabelle-operator: {name: "mod", prec: 70, assoc: left} #-}
mod : A -> A -> A
};

Expand Down
4 changes: 2 additions & 2 deletions Stdlib/Trait/Eq.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ type Eq A := mkEq {eq : A -> A -> Bool};
syntax operator == comparison;
syntax operator /= comparison;

{-# inline: always #-}
{-# inline: always, isabelle-operator: {name: "=", prec: 50, assoc: none} #-}
== {A} {{Eq A}} : A -> A -> Bool := Eq.eq;

--- Tests for inequality.
{-# inline: always #-}
{-# inline: always, isabelle-operator: {name: "≠", prec: 50, assoc: none} #-}
/= {A} {{Eq A}} (x y : A) : Bool := not (x == y);
1 change: 1 addition & 0 deletions Stdlib/Trait/Integral.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Integral A :=
mkIntegral {
naturalI : Natural A;
syntax operator - additive;
{-# isabelle-operator: {name: "-", prec: 65, assoc: left} #-}
- : A -> A -> A;
builtin from-int
fromInt : Int -> A
Expand Down
8 changes: 4 additions & 4 deletions Stdlib/Trait/Ord.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Ord A := mkOrd {cmp : A -> A -> Ordering};
syntax operator <= comparison;

--- Returns ;true; iff the first element is less than or equal to the second.
{-# inline: always #-}
{-# inline: always, isabelle-operator: {name: "≤", prec: 50, assoc: none} #-}
<= {A} {{Ord A}} (x y : A) : Bool :=
case Ord.cmp x y of
| EQ := true
Expand All @@ -47,7 +47,7 @@ syntax operator <= comparison;
syntax operator < comparison;

--- Returns ;true; iff the first element is less than the second.
{-# inline: always #-}
{-# inline: always, isabelle-operator: {name: "<", prec: 50, assoc: none} #-}
< {A} {{Ord A}} (x y : A) : Bool :=
case Ord.cmp x y of
| EQ := false
Expand All @@ -57,13 +57,13 @@ syntax operator < comparison;
syntax operator > comparison;

--- Returns ;true; iff the first element is greater than the second.
{-# inline: always #-}
{-# inline: always, isabelle-operator: {name: ">", prec: 50, assoc: none} #-}
> {A} {{Ord A}} (x y : A) : Bool := y < x;

syntax operator >= comparison;

--- Returns ;true; iff the first element is greater than or equal to the second.
{-# inline: always #-}
{-# inline: always, isabelle-operator: {name: "≥", prec: 50, assoc: none} #-}
>= {A} {{Ord A}} (x y : A) : Bool := y <= x;

--- Returns the smaller element.
Expand Down
3 changes: 2 additions & 1 deletion Stdlib/Trait/Ord/Eq.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fromOrdToEq {A} {{Ord A}} : Eq.Eq A := Eq.mkEq (==);

syntax operator == comparison;

{-# isabelle-operator: {name: "=", prec: 50, assoc: none} #-}
== {A} {{Ord A}} (x y : A) : Bool :=
case Ord.cmp x y of
| EQ := true
Expand All @@ -17,5 +18,5 @@ syntax operator == comparison;
syntax operator /= comparison;

--- Tests for inequality.
{-# inline: true #-}
{-# inline: true, isabelle-operator: {name: "≠", prec: 50, assoc: none} #-}
/= {A} {{Ord A}} (x y : A) : Bool := not (x == y);

0 comments on commit 1621150

Please sign in to comment.