程序代写代做代考 DNA go diffSq :: Integer -> Integer -> Integer

diffSq :: Integer -> Integer -> Integer
diffSq x y = (x – y) * (x + y)
diffSq 2 1
X -> Y -> Z
diffSqV3a, diffSqV3b :: Integer -> Integer -> Integer
diffSqV3a x y =
let minus = x – y
plus = x + y
in minus * plus
diffSqV3b x y = minus * plus
where
minus = x – y
plus = x + y
let in x=5 in x+1)
2 * (let
Table of Contents
,g.e ,detcepxe si noisserpxe na reverehw desu eb nac ,noisserpxe na si ¡± – ¡° :ecnereffid ehT
.erutcel retal a ni
ekil sepyt no yroeht erom tib a si erehT :esu ot woH
:rewsna regetni na sevig dna sretemarap regetni owt sekat elpmaxe sihT
sretemarap elpitlum fo snoitcnuF
.elgna wofl-lortnoc eht naht srennigeb rof retteb si elgna arbegla eht tub ,em ekil kaeps ot evah t’nod uoy ,tcerroc era selgna htoB .¡±noitcnuf siht llac¡° ton )ni gniggulp( ¡±retemarap taht ot noitcnuf siht ylppa¡° ,¡±epyt nruter¡° ton¡±niamodoc¡°,¡±01snruter¡°ton¡±01sevig/slauqe)4(f¡°yasemraehlliwuoy,sihtfoesuaceB
.)etats elbatum( selbairavnohtyProCsaton,)stnatsnocdnasnwonknurof(selbairavhtamsaselbairavlleksaH ,esiwekil;snoitcnufnohtyProCsaton,snoitcnufhtamsasnoitcnuflleksaHfoknihtottsebsitI
sh.scisaBlleksaH ni
:snoitinfied lacol fo syaw owT
stcurtsnoc noitinfied lacoL
sh.scisaBlleksaH ni
dnim fo emarF scisaB lleksaH

where
2 * (x+1 where x=5)
y = … where x=5
slowFib2
slowFactorial :: Integer -> Integer
slowFactorial 0 = 1
slowFactorial n = n * slowFactorial (n – 1)
— Slow Fibonacci (yawn) to show you can have more patterns.
— “This Fibonacci joke is as bad as the last two you heard combined.”
— https://twitter.com/sigfpe/status/776420034419658752
slowFib :: Integer -> Integer
slowFib 0 = 0
slowFib 1 = 1
slowFib n = slowFib (n-1) + slowFib (n-2)
— More fundamental form—using a “case-of” expression:
slowFib2 :: Integer -> Integer
slowFib2 x = case x of
0 -> 0
1 -> 1
n -> slowFib2 n1 + slowFib2 n2
where
n1 = n – 1
n2 = n – 2
— The other example of “where”. This one is part of “n -> …”.
where
f (x*2 + 1) :: Integer
f (x*2 + 1) :: Integer
^^^^^^^^^^^ ^^^^^^^
term type
h . g :: Char -> Bool
^^^^^ ^^^^^^^^^^^^
term type
f (x*2 + 1)
Integer
Table of Contents
,¡±
dna edoc lautca htob ni desu si tI .¡±
.esorp noitanalpxe si fo epyt eht¡° rof noitaton si sihT
:emit eht lla siht ekil gnihtemos ees lliw uoY
eulav ,mret ,epyt :yralubacoV
.seY ?sdrauG ?selpmaxe eseht rof esle-neht-fi esu uoy naC sh.scisaBlleksaH ni
noisrucerdnagnihctamnrettapfoelpmaxecisaB
.noitces txen eht ni ni nwohs ¡° esu nac uoy ecalp rehtona si erehT .lagel si ¡± ¡° ,.g.e ,noitinfied a fo trap si tI .lagelli si ¡± ¡° ,.g.e ,noisserpxe na fo trap ton si ¡± ¡°
:elpmaxe erom enO
:dellac era sgniht owt esohT

slowFactorial 0 = 1
5+4
n! = n*(n-1)!
= n * slowFactorial (n-1) by I.H.
slowFactorial n = n * slowFactorial (n-1)
Table of Contents
!n = n lairotcaFwols :PTW !)1-n( = )1-n( lairotcaFwols :sisehtopyh noitcudnI .nevig eb 1 ¡Ý n larutan teL
!snwonknu eht rof evlos ot woh tuo dnfi uoy foorp eht gnirud tub ha ,snwonknu sniatnoc llits taht gnihtemos evorp ot noitcudni esU = noitcudni dneterP :)edoc evisrucer etirw I woh( weiv sisehtnyS
.ti nur ot yrt t’nod uoy fi reisae eb nac edoc evisrucer gnitirw taht uoy wohs I .htob uoy hcaet I
).gnitcartsid si edoc evisrucer gninnur-dnah¡ªyllautca uoy sedepmi ylbaborP( .gnitirw htiw uoy pleh t’nseod llits tahT .edoc evisrucer nur ot woh sehcaet enoyrevE
.siht tuoba xal ma I tuB .eulav a si ,9 ,ti gnitaulave fo tluser eht ;mret a si :rewsnA ?¡±eulav¡° tuoba tahW
.¡±noisserpxe epyt¡° dellac osla si ¡±epyt¡° esuaceb dna ,retrohs si ti esuaceb ¡±mret¡° ekil I .¡±noisserpxe¡° sa nwonk ylediw osla si ¡±mret¡°
).edoc nur ot woh sv edoc etaerc ot woH(
noitaulave sv/dna sisehtnyS
pu edoc I fi oS
:pets noitcudnI !0 = 0 lairotcaFwols teg I
pu edoc I fi os ,1 = !0 ecitoN !0 = 0 lairotcaFwols :PTW :esac esaB
!n=nlairotcaFwols:nlarutanllaroF:PTW :lairotcaFwols pu dedoc I woH
ecitoN
sisehtnyS

slowFactorial 3
3 * slowFactorial (3 – 1)
3 * slowFactorial 2
3 * (2 * slowFactorial (2 – 1))
3 * (2 * slowFactorial 1)
3 * (2 * (1 * slowFactorial (1 – 1))) 3 * (2 * (1 * slowFactorial 0))
3 * (2 * (1 * 1))
3 * (2 * 1)
3* 2
6
[Integer] [Bool] [] Integer [] Bool []
[]
[4, 1, 6]
4 : (1 : (6 : []))
4 : 1 : 6 : []
Table of Contents
:fo eno si tsil a :)63BCSC ni sa noitinfied evisrucer( yllamroF .gnihctam nrettap ni desu eb nac smrof xatnys esehT
:siht ekil ,lanoitpo era sesehtnerap esohT
:rof ragus xatnys s’tahT :laretil tsil
:tsil ytpme
.cte , , , , :sepyt
:xatnys tsil fo rednimeR .stsil no noitcudni/noisrucer swohs elpmaxe txen ehT
:guhc dna gulP :)edoc snur tneduts devalsne na ro retupmoc a woh( weiv noitaulavE
!?erom siht od elpoep t’nod yhW .eerf 1 teg 1 yuB .foorp ssentcerroc dna edoc htob teg uoY
.yddum ton ,raelc eb ot .H.I eht deen I .evig dluohs noitcnuf ym rewsna tahw¡ªnoitacfiiceps eht nwod etirw ylluferac dna dnim ym pu ekam ot deen I :hctac ehT
.sucof em spleh sihT .ti esu tsuj I os rewsna eht em sllet ydaerla .H.I ehT .¡±?dnah yb )1-n( lairotcaFwols dlofnu I fi tahw¡° enigami ot esufer I
tros noitresni :elpmaxE regraL
.erutcurts edoc eht sediug erutcurts foorp ehT :stnemmoC
!n = n lairotcaFwols teg I
noitaulavE
¡ú ¡ú ¡ú ¡ú ¡ú ¡ú ¡ú ¡ú ¡ú ¡ú

insert
insert 4 [1,3,5,8,9,10] = [1,3,4,5,8,9,10]
insert :: Integer -> [Integer] -> [Integer]
— Structural induction on xs.
— Base case: xs is empty. Answer is [e] aka e:[]
insert e [] = [e] — e : []
— Induction step: Suppose xs has the form x:xt (and xt is shorter than xs).
— E.g., xs = [1,3,5,8], x = 1, xt = [3,5,8].
— Induction hypothesis: insert e xt = put e into the right place in xt.
insert e xs@(x:xt)
— xs@(x:xt) is an “as-pattern”, “xs as (x:xt)”,
— so xs refers to the whole list, and it also matches x:xt

— If e <= x, then e should be put before x, in fact all of xs, and be done. -- E.g., insert 1 (10 : xs) = 1 : (10 : xs) | e <= x = e : xs -- Otherwise, the answer should go like: -- x, followed by whatever is putting e into the right place in xt. -- i.e., -- x, followed by insert e xt (because IH) -- E.g., insert 25 (10 : xt) = 10 : (insert 25 xt) | otherwise = x : insert e xt insert 15 (10 : 20 : []) insert Table of Contents .meht no noitcudni esu ot nrut ruoY :esicrexE .selyts owt gnitcefler ,snoisrev owt era ereH .mhtirogla gnitros eht etelpmoc nac uoy gnisU ).tsil detros ,wen a ecudorp lliw tub ,tsil nevig eht egnarra -er t'nac ,gnitros rof ylralimiS( .ecalp thgir eht ta e htiw osla tub sx ekil s'taht tsil wen a ecudorp :daetsni tub ,sx egnahc t'nac ,stsil elbatummi htiw gnimmargorp lanoitcnuf gniod er'ew tuB ,.g.E .detros llits si elohw eht os sx ni ¡±ecalp thgir¡° eht otni e tuP .detros neeb evah ot demussa si sx .sx tsil dna e tnemele ekaT : noitcnuf repleh a evaH :ygetartS :tros noitresnI .syarra ton era esehT .gninnigeb eht morf sedon eht lla hguorht og ot emit )n(¦¨ ekat ot deen uoy ,)edon htn eht tsuj neve ro( meti htn eht hcaer oT .stsil deknil-ylgnis era esehT :noisrev noisrucer tceriD ¡ú :)][ : 02 : 01( 51 tresni etaulavE :esicrexE )psiL morf( ¡±llec snoc¡° ,edon tsil >ereh tsil a< : >ereh meti na< sh.scisaBlleksaH ni insertionSort :: [Integer] -> [Integer]
insertionSort [] = []
insertionSort (x:xt) = insert x (insertionSort xt)
acc
insertionSortAcc :: [Integer] -> [Integer]
insertionSortAcc xs = go xs []
where
— Specification for go (when you prove go correct by induction):
— for all xs, for all acc:
— Assume acc is in sorted order (precondition).
— go xs acc = add elements of xs to acc but in sorted order
go (x:xt) acc = let acc2 = insert x acc
go
go [] acc = acc
in go xt acc2
Table of Contents
.elbairav retalumucca na sledom retemarap dnoces sti ;pool-elihw a sledom noitcnuf repleh ehT :elbairav rotalumucca na dna pool-elihw a sledom noisrev rehto sihT
sh.scisaBlleksaH ni
sh.scisaBlleksaH ni