simproc | The simple microprocessor | Command Line Interface library
kandi X-RAY | simproc Summary
kandi X-RAY | simproc Summary
The simple microprocessor
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Run the pipeline
- Execute instruction
- Decode a line into a tuple
- Fetch next line
- Check if a parameter is a memory reference
- Return the value of a memory reference
- Load code
- Print memory information
simproc Key Features
simproc Examples and Code Snippets
Community Discussions
Trending Discussions on simproc
QUESTION
Consider the following simplified lambda-calculus with the peculiarity that bound variables can occur on the bound type:
...ANSWER
Answered 2020-Jun-19 at 09:45I am glad that you were able to work out the solution. Nonetheless, I would still like to elaborate on the comment that I previously made. In particular, I would like to emphasize that nominal_datatype
already provides a very similar function automatically: it is the function fv_trm
. This function is, effectively, equivalent to the function fv
in your question. Here is a rough sketch (the proof will need to be refined) of a theory that demonstrates this:
QUESTION
I want to implement a simproc capable of rewriting the argument of sin into a linear combination x + k * pi + k' * pi / 2 (where ideally k' = 0 or k' = 1) and then apply existing lemmas about additions of arguments in sines.
The steps could be as follows:
- Pattern match the goal to extract the argument of sin(expr):
ANSWER
Answered 2019-Nov-20 at 10:54I would start easy and ignore the pi / 2
part for now.
You probably want to build a simproc that matches on anything of the form sin x
. Then you want to write a conversion that takes that term x
(which is assumed to be a sum of several terms) and brings it into the form a + of_int b * p
.
A conversion is essentially a function of type cterm → thm
which takes a cterm ct
and returns a theorem of the form ct ≡ …
, i.e. it's a form of deterministic rewriting (a conversion can also fail by throwing a CTERM
exception, by convention). There are a lot of combinators for building and using these in Pure/conv.ML
.
This is probably a bit fiddly. You essentially have to descend through the term and, for each atom (i.e. anything not of the form _ + _
) you have to figure out whether it can be brought into the form of_int … * pi
(e.g. again by writing a conversion that does this transformation – to make it easy you can omit this part so that your procedure only works if the terms are already in that form) and then group all the terms of the form of_int … * pi
to the right and all the terms not of that form to the left using associativity and commutativity.
I would suggest this:
- Define a function
SIN_SIMPROC_ATOM x n = x + of_int n * pi
- Write a conversion
sin_atom_conv
that rewritesof_int n * pi
toSIN_SIMPROC_ATOM 0 n
and everything else intoSIN_SIMPROC_ATOM x 0
- Write a conversion that descends through
+
, appliessin_atom_conv
to every atom, and then applies some kind of combination rule likeSIN_SIMPROC_ATOM x1 n1 + SIN_SIMPROC_ATOM x2 n2 = SIN_SIMPROC_ATOM (x1 + x2) (n1 + n2)
- In the end, you have rewritten your entire form to the form
sin (SIN_SIMPROC_ATOM x n)
, and then you can apply some suitable rule to that.
It's not quite clear to me how to best handle the parity of n
. You could rewrite sin (SIN_SIMPROC_ATOM x n) = (-1) ^ nat ¦n¦ * sin x
but I'm not sure if that's what the user really wants in most cases. It might make more sense to only do that if you can deduce the parity of n
statically (e.g. by using the simplifier) and then directly simplify to sin x
or -sin x
.
The situation becomes even more complicated if you want to include halves of π. You can of course extend SIN_SIMPROC_ATOM
by a second term for halves of π (and one for doubles of π as well to make it more uniform). Or you could ad all of them together so that you just have a single integer n
that describes your multiples of π/2, and k
multiples of π simply contribute 2k
to that term. And then you have to figure out what n mod 4
is – possibly again with the simplifier or with some clever static method.
QUESTION
I'm writing a simproc for sine simplifications. Here is an example rewriting sin(x+8pi+pi/2) to cos(x):
...ANSWER
Answered 2019-Nov-20 at 10:15In the first example, your simproc is not called becaus simprocs (if I remember correctly) are only called after exhausting all ‘normal’ rewriting, and your goal is immediately rewritten to sin (17 * pi / 2 + x) = cos x
. Since your simproc does not match that goal anymore, it is not called.
In the second example, your simproc is called (you can verify this by inserting e.g. a val _ = @{print} "foo"
into your let
block) and it indeed produces a rewrite rule. Unfortunately, this rewrite rule still has the precondition 8 ≡ 2 * real_of_int 4
, which simp
cannot solve with the very basic simplifier setup you are using, so it fails to apply the rule.
You can find out what's going on there using the simplifier trace:
QUESTION
If I apply the simp-method to a goal containing an if-expression, the simplifier automatically introduces a case distinction:
...ANSWER
Answered 2017-Nov-05 at 16:41That feature is enabled by the splitter. The simplifier itself is a big loop that not only performs rewriting, but also afterwards a variety of other things, before it starts rewriting again.
For if, the relevant split
rules are if_splits
:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install simproc
You can use simproc like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page