Category:CafeOBJ: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 43:
 
vars N N' : Nat
-- A very short sorting program using transitionson transition equation in POA logic, which is a type of rewrite logic/
-- The program is in the form of a condition transition, which will swap N and N' if N is larger or equal to N'.
-- This is a equation in POA logic so there is no need for an intermediate variable to do the swap.
ctrans [swap] : (N . N') => (N' . N) if N' <= N .
}
Line 50 ⟶ 52:
open SORTING-NAT
exec (3 . 2 . 1) .
**> We can consider sorting as a path through the state space of the permutations of N numbers.
**> There are N! permutations only one of which is sorted.
**> Sorting natural numbers using search command
**> we can use (show path N) with this command, where N is the nubernumber of possible states.
red (3 . 2 . 1) =(1,1)=>* (1 . 2 . 3) .
red (3 . 2 . 1) =(1,2)=>* (1 . 2 . 3) .
101

edits