-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could not deduce: CLog 2 (n * 2)
~ CLog 2 n + 1
#42
Comments
A workaround would be to define: import Data.Type.Equality ((:~:)(Refl))
import Unsafe.Coerce (unsafeCoerce)
clog2axiom :: (CLog 2 (n * 2)) :~: ((CLog 2 n) + 1)
clog2axiom = unsafeCoerce Refl And use it like: coerceIndices :: forall n. (KnownNat n, 1 <= n) => Index (n*2) -> (Index n, Bool)
coerceIndices = case clog2axiom @n of Refl -> bitCoerce |
@rowanG077 mentioned that we should be able to add this derivation by patching:
|
Finally, some "proof" that this equation holds: >>> import Clash.Util (clogBase)
>>> import Test.QuickCheck (quickCheck, withMaxSuccess)
>>> clog2 = clogBase 2
>>> prop_eq n = (clog2 (n*2)) == (succ <$> clog2 n)
>>> quickCheck (withMaxSuccess 1000000 prop_eq)
+++ OK, passed 1000000 tests. |
5 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This should hold for all
n
*, but the plugin doesn't infer it.*For n ~ 0 the answer is undefined in both cases
The text was updated successfully, but these errors were encountered: