isabelle


Defining Primtive Recursion for multiplication in Isabelle


I am new to Isabelle and I am trying to define primitive recursive functions. I have tried out addition but I am having trouble with multiplication.
datatype nati = Zero | Suc nati
primrec add :: "nati ⇒ nati ⇒ nati" where
"add Zero n = n" |
"add (Suc m) n = Suc(add m n)"
primrec mult :: "nati ⇒ nati ⇒ nati" where
"mult Suc(Zero) n = n" |
"mult (Suc m) n = add((mult m n) m)"
I get the following error for the above code
Type unification failed: Clash of types "_ ⇒ _" and "nati"
Type error in application: operator not of function type
Operator: mult m n :: nati
Operand: m :: nati
Any ideas?
The problem is your mult function: It should look like this:
primrec mult :: "nati ⇒ nati ⇒ nati" where
"mult Zero n = Zero" |
"mult (Suc m) n = add (mult m n) m"
Function application in functional programming/Lambda calculus is the operation that binds strongest and it associates to the left: something like f x y means ‘f applied to x, and the result applied to y’ – or, equivalently due to Currying: the function f applied to the parameters x and y.
Therefore, something like mult Suc(Zero) n would be read as mult Suc Zero n, i.e. the function mult would have to be a function taking three parameters, namely Suc, Zero, and n. That gives you a type error. Similarly, add ((mult m n) m) does not work, since that is identical to add (mult m n m), which would mean that add is a function taking one parameter and mult is one taking three.
Lastly, if you fix all that, you will get another error saying you have a non-primitive pattern on the left-hand side of your mult function. You cannot pattern-match on something like Suc Zero since it is not a primitive pattern. You can do that if you use fun instead of primrec, but it is not what you want to do here: You want to instead handle the cases Zero and Suc (see my solution). In your definition, mult Zero n would even be undefined.

Related Links

Find all Pairs definition
Simplify meta-universally quantified assumptions with equality
What is the syntax to use Map.thy
Collecting locally fixed parameters using Eisbach
Why does simp “fail to apply initial proof method” where blast succeeds with the same facts?
Proving a theorem about parser combinators
Manually adding an assumption to the simplifier (Isabelle)
Proving something is an instance of a locale in Isabelle
Defining multiple constants in an integral
Definition without recursion, by cases, in Isabelle
Using a definition to produce an specific example of a locale in Isabelle
Should I use universal quantification in lemma formulation?
Using syntax/translations wiith locales
Quotienting a mutually recursive family of datatypes
L2Norm with Integration
Error defining dataype in Isabelle

Categories

HOME
arduino-uno
date
minimum-spanning-tree
tizen
heroku
dictionary
stock
dot
jira
react-redux
sqlite3
sql-server-2016
callback
disassembler
baqend
synchronization
awesome-wm
fancybox-3
export-to-csv
nstableview
vb.net-2010
usergrid
jsprit
serverless-framework
contextmenu
crystal-reports-2008
scichart
csrf-protection
kvc
fish
windows-error-reporting
bpel
nouislider
catel
repo
force-layout
hexo
event-driven
android-browser
uft-api
arena-simulation
http-redirect
sas-jmp
btrace
user-accounts
flickr-api
jquery-nestable
theming
mu
git-diff
diagnostics
redundancy
abcpdf9
libpng
database-optimization
actionbardrawertoggle
hover-over
revolution-r
spim
xna-4.0
eclipse-clp
python-3.2
tmuxinator
fluid-dynamics
mmc
dia
java.util.concurrent
java-metro-framework
rebol3
rtmfp
cloud-connect
intentservice
html5-notifications
geos
gwt-rpc
eventual-consistency
hungarian-algorithm
yui-compressor
angularjs-controller
unc
libstdc++
coderush
frameset
automount
viewswitcher
wse3.0
hgsubversion
custom-backend
boost-filesystem
pydot
locationlistener
winbugs14
yslow
sudzc
thunderbird-lightning
ti-dsp
swing-app-framework
misv

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App