Pat is a national development tool in Singapore and needs to go to the official website under http://www.comp.nus.edu.sg/~pat/
, learned a day, is a good automatic machine verification tool, feel good ah.
Verifies whether a number is a Fibonacci number and is prime
Method
First, verify that the Fibonacci number is, and then judge the prime.
Code
/*Verify that it is a Fibonacci number and is prime*/#defineGoal (b==13 && f==1);//It 's Fibonacci numbers and prime numbers .#defineNo1goal (b==21 && f==1);//It's Fibonacci numbers, not quality .#defineNo2goal (b==22 && f==1);//It's not Fibonacci numbers . varA =0;varb =1;vart =0;vars =2;varf =0; FBNQ ()=[b>0]fbnq1{t=b;b=a+b;a=t;} -fbnq () [][b>1]fbnq2{s=2;} -Zhishu (); Zhishu ()=if(s*s <= b && b%s==0) {zhishu1{f=0;} -fbnq ()}Else if(S*s <=b) {Zhishu2{s=s+1;} -Zhishu ()}Else{zhishu3{f=1;} -Zhishu ()}; #assert Fbnq () reaches goal; #assert Fbnq () reaches No1goal; #assert fbnq () reaches No2goal;
Verification process and Results 1, Fibonacci numbers and prime numbers
#define Goal (b==13 && f==1);
2. Fibonacci numbers are not quality.
#define no1goal(b==21 && f==1);
3. Not Fibonacci numbers
#define no2goal(b==22 && f==1);//
Summarize
Validation succeeded.
The Pat tool and the CSP language, an automated modeling of a problem, is indeed a powerful tool.
There is a farmer across the river problem, PPT written, also very good:
The status is:
1 farmers cross the river
– farmers at the riverside, wolves and sheep, sheep
and vegetables can not at the same time on the river
– Farmer to the other side
• 2 farmer with Wolf across the river
– farmer, Wolf at the Riverside, sheep and vegetable
cannot at the same time on the river
– farmer, Wolf to the other side
3 farmer
– farmers, sheep on the river
– farmers, sheep to the other side
• 4 farmers with vegetables across the river
– farmers, vegetables at the riverside, wolves and sheep
cannot at the same time on the river
– farmers, dishes to the other side
• 1 farmers come back
– farmers on the opposite shore, wolves and sheep, sheep and
The dish cannot be at the same time on the other side
– the farmer returns to the river
• 2 farmer with Wolf back
– farmer, Wolf on the opposite shore, sheep and vegetable not
can at the other side
– farmer, Wolf back to the river
• 3 farmer with sheep back
– farmer, sheep on the opposite side
– farmer, sheep
• 4 farmer comes back with vegetables
– farmers, vegetables on the other side, wolves and sheep not
can at the same time on the opposite shore
– farmers, vegetables back to the river
/*0 represents the river, 1 means on the other side */var farmer=0; var wolf=0; var goat=0; var carbage=0; cross () =[farmer==0 && (! (wolf==0 && goat==0)) && (! (goat==0 &&carbage==0))) ] Farmer_cross{farmer=1;} ->return () [] [farmer==0 && wolf==0 && (! (goat==0 && carbage ==0)) ]farmer_wolf_cross{farmer=1;wolf=1;} ->return () [] [farmer==0 && goat==0] farmer_goat_cross{farmer=1;goat=1;} ->return () [] [farmer==0 && carbage==0 && (! (wolf==0 && goat==0)) ]farmer_carbage_cross{farmer=1;carbage=1;} ->return (); return () =[farmer==1 && ((! (Wolf==1 && goat==1)) && (! (Goat==1 &&carbage==1))) ] farmer_return{farmer=0;} ->cross () [] [Farmer==1 && wolf==1 && (! (goat==1 && carbage ==1)) ]farmer_wolf_return{farmer=0;wolf=0;} ->cross () [] [farmer==1 && goat==1] farmer_goat_return{farmer=0;goat=0;} ->cross () [] [Farmer==1 && Carbage==1 && (! (Wolf==1 && G
Automated modeling of a problem using the PAT tool and the CSP language