Skip to content

Commit 4b9c6f0

Browse files
authored
Merge pull request ucsd-progsys#1869 from renanroberto/floating-spec
Add spec for Floating typeclass
2 parents 3a2e31f + eb41a14 commit 4b9c6f0

19 files changed

+110
-24
lines changed

liquid-base/src/GHC/Float.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module GHC.Float (module Exports) where
22

3+
import GHC.Types
4+
import GHC.Real
35
import "base" GHC.Float as Exports

liquid-base/src/GHC/Float.spec

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module spec GHC.Float where
2+
3+
import GHC.Types
4+
5+
class (GHC.Real.Fractional a) => GHC.Float.Floating a where
6+
GHC.Float.pi :: a
7+
GHC.Float.exp :: a -> {y:a | y > 0}
8+
GHC.Float.log :: {x:a | x > 0} -> a
9+
GHC.Float.sqrt :: {x:a | x >= 0} -> {y:a | y >= 0}
10+
(GHC.Float.**) :: x:a -> {y:a | x = 0 => y >= 0} -> a
11+
GHC.Float.logBase :: {b:a | b > 0 && b /= 1} -> {x:a | x > 0} -> a
12+
GHC.Float.sin :: a -> {y:a | -1 <= y && y <= 1}
13+
GHC.Float.cos :: a -> {y:a | -1 <= y && y <= 1}
14+
GHC.Float.tan :: a -> a
15+
GHC.Float.asin :: {x:a | -1 <= x && x <= 1} -> a
16+
GHC.Float.acos :: {x:a | -1 <= x && x <= 1} -> a
17+
GHC.Float.atan :: a -> a
18+
GHC.Float.sinh :: a -> a
19+
GHC.Float.cosh :: a -> {y:a | y >= 1}
20+
GHC.Float.tanh :: a -> {y:a | -1 < y && y < 1}
21+
GHC.Float.asinh :: a -> a
22+
GHC.Float.acosh :: {y:a | y >= 1} -> a
23+
GHC.Float.atanh :: {y:a | -1 < y && y < 1} -> a
24+
GHC.Float.log1p :: a -> a
25+
GHC.Float.expm1 :: a -> a
26+
GHC.Float.log1pexp :: a -> a
27+
GHC.Float.log1mexp :: a -> a

liquid-base/src/Prelude.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import GHC.List
1212
import GHC.Maybe
1313
import GHC.Num
1414
import GHC.Real
15+
import GHC.Float
1516
import GHC.Types
1617
import GHC.Word
1718

liquid-base/src/Prelude.spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import GHC.List
66
import GHC.Maybe
77
import GHC.Num
88
import GHC.Real
9+
import GHC.Float
910
import GHC.Word
1011

1112
import Data.Foldable

tests/errors/ElabLocation3.hs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -183,28 +183,6 @@ part1 _ = do
183183
let allRounds2 = iterate {- (Main.round 8 3 m2) -} id input in
184184
print $ allRounds2 !! 20
185185

186-
part2 :: () -> IO ()
187-
part2 _ = do
188-
putStrLn "Part 2"
189-
let m1 = computeModulus example in do
190-
putStrLn $ "Working mod " ++ show m1
191-
let allRounds = iterate {- (Main.round 4 1 m1) -} id example in do
192-
print $ allRounds !! 1000
193-
print $ allRounds !! 2000
194-
print $ allRounds !! 3000
195-
print $ allRounds !! 4000
196-
print $ allRounds !! 5000
197-
print $ allRounds !! 6000
198-
print $ allRounds !! 7000
199-
print $ allRounds !! 8000
200-
print $ allRounds !! 9000
201-
print $ allRounds !! 10000
202-
203-
let m2 = computeModulus input in do
204-
putStrLn $ "Working mod " ++ show m2
205-
let allRounds2 = iterate {- (Main.round 8 1 m2) -} id input in
206-
print $ allRounds2 !! 10000
207-
208186
mymain :: IO ()
209-
mymain = part1 () >> part2 ()
187+
mymain = part1 ()
210188

tests/neg/CosNegTest.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{-@ LIQUID "--expect-error-containing=CosNegTest.hs:6:1" @-}
2+
module CosNegTest where
3+
4+
{-@ test :: a -> {x:a | x > 1} @-}
5+
test :: Floating a => a -> a
6+
test x = cos x

tests/neg/ExpNegTest.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{-@ LIQUID "--expect-error-containing=ExpNegTest.hs:6:1" @-}
2+
module ExpNegTest where
3+
4+
{-@ test :: a -> {x:a | x <= 0} @-}
5+
test :: Floating a => a -> a
6+
test x = exp x

tests/neg/ExponentiationNegTest.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{-@ LIQUID "--expect-error-containing=ExponentiationNegTest.hs:5:1" @-}
2+
module ExponentiationNegTest where
3+
4+
test :: Floating a => a
5+
test = 0 ** (-1)

tests/neg/LogNegTest.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{-@ LIQUID "--expect-error-containing=LogNegTest.hs:5:1" @-}
2+
module LogNegTest where
3+
4+
test :: Floating a => a
5+
test = log 0

tests/neg/SinNegTest.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{-@ LIQUID "--expect-error-containing=SinNegTest.hs:6:1" @-}
2+
module SinNegTest where
3+
4+
{-@ test :: a -> {x:a | x > 1} @-}
5+
test :: Floating a => a -> a
6+
test x = sin x

0 commit comments

Comments
 (0)