1754 instance .. |
1754 instance .. |
1755 |
1755 |
1756 end |
1756 end |
1757 |
1757 |
1758 |
1758 |
1759 text {* Setup for SML code generator *} |
1759 subsection {* Setup for Nitpick *} |
1760 |
|
1761 types_code |
|
1762 real ("(int */ int)") |
|
1763 attach (term_of) {* |
|
1764 fun term_of_real (p, q) = |
|
1765 let |
|
1766 val rT = HOLogic.realT |
|
1767 in |
|
1768 if q = 1 orelse p = 0 then HOLogic.mk_number rT p |
|
1769 else @{term "op / \<Colon> real \<Rightarrow> real \<Rightarrow> real"} $ |
|
1770 HOLogic.mk_number rT p $ HOLogic.mk_number rT q |
|
1771 end; |
|
1772 *} |
|
1773 attach (test) {* |
|
1774 fun gen_real i = |
|
1775 let |
|
1776 val p = random_range 0 i; |
|
1777 val q = random_range 1 (i + 1); |
|
1778 val g = Integer.gcd p q; |
|
1779 val p' = p div g; |
|
1780 val q' = q div g; |
|
1781 val r = (if one_of [true, false] then p' else ~ p', |
|
1782 if p' = 0 then 1 else q') |
|
1783 in |
|
1784 (r, fn () => term_of_real r) |
|
1785 end; |
|
1786 *} |
|
1787 |
|
1788 consts_code |
|
1789 Ratreal ("(_)") |
|
1790 |
|
1791 consts_code |
|
1792 "of_int :: int \<Rightarrow> real" ("\<module>real'_of'_int") |
|
1793 attach {* |
|
1794 fun real_of_int i = (i, 1); |
|
1795 *} |
|
1796 |
1760 |
1797 declaration {* |
1761 declaration {* |
1798 Nitpick_HOL.register_frac_type @{type_name real} |
1762 Nitpick_HOL.register_frac_type @{type_name real} |
1799 [(@{const_name zero_real_inst.zero_real}, @{const_name Nitpick.zero_frac}), |
1763 [(@{const_name zero_real_inst.zero_real}, @{const_name Nitpick.zero_frac}), |
1800 (@{const_name one_real_inst.one_real}, @{const_name Nitpick.one_frac}), |
1764 (@{const_name one_real_inst.one_real}, @{const_name Nitpick.one_frac}), |