<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>
<title>tcl.git - Tcl is a high-level, general-purpose, interpreted, dynamic programming language. It was designed with the goal of being very simple but powerful.</title>
<meta name='generator' content='cgit v0.12'/>
<meta name='robots' content='index, nofollow'/>
<link rel='stylesheet' type='text/css' href='/cgit-data/cgit-techsat.css'/>
<link rel='shortcut icon' href='/favicon.ico'/>
<link rel='alternate' title='Atom feed' href='http://service.techsat.com/oss-git/tcl.git/atom/library/msgcat/msgcat.tcl?h=bug_3173086' type='application/atom+xml'/>
</head>
<body>
<div id='cgit'><table id='header'>
<tr>
<td class='logo' rowspan='2'><a href='/oss-git/'><img src='/cgit-data/cgit.png' alt='cgit logo'/></a></td>
<td class='main'><a href='/oss-git/'>index</a> : <a title='tcl.git' href='/oss-git/tcl.git/'>tcl.git</a></td><td class='form'><form method='get' action=''>
<input type='hidden' name='id' value='85cce0b8cf9c49a685815514b160d47503d3c78a'/><select name='h' onchange='this.form.submit();'>
<option value='8_5_with_8_6_regexp'>8_5_with_8_6_regexp</option>
<option value='Coverity_CID_1251203'>Coverity_CID_1251203</option>
<option value='ISC_peephole'>ISC_peephole</option>
<option value='activestate_nre_excised_variant_1_roll_forward'>activestate_nre_excised_variant_1_roll_forward</option>
<option value='activestate_nre_excised_variant_2_subtracted'>activestate_nre_excised_variant_2_subtracted</option>
<option value='adjust_fix'>adjust_fix</option>
<option value='ajuba_ajuba2_2_0_synthetic'>ajuba_ajuba2_2_0_synthetic</option>
<option value='ajuba_ajuba2_2_1_base_synthetic'>ajuba_ajuba2_2_1_base_synthetic</option>
<option value='aku_mem_debug_allow_regular'>aku_mem_debug_allow_regular</option>
<option value='aku_review'>aku_review</option>
<option value='aku_tip_280_cl_perf_trial'>aku_tip_280_cl_perf_trial</option>
<option value='aku_tkt_6141c15186'>aku_tkt_6141c15186</option>
<option value='amg_array_enum_c_api'>amg_array_enum_c_api</option>
<option value='amg_string_insert'>amg_string_insert</option>
<option value='androwish'>androwish</option>
<option value='apn_hash_opt'>apn_hash_opt</option>
<option value='array_search_unset'>array_search_unset</option>
<option value='aspect_async_pipe'>aspect_async_pipe</option>
<option value='aspect_bug_391bc0fd2c'>aspect_bug_391bc0fd2c</option>
<option value='aspect_lreplace_cleanup'>aspect_lreplace_cleanup</option>
<option value='aspect_lreplace_fix'>aspect_lreplace_fix</option>
<option value='aspect_lreplace_refix'>aspect_lreplace_refix</option>
<option value='aspect_shimmer_singleton_lists'>aspect_shimmer_singleton_lists</option>
<option value='aspect_string_match'>aspect_string_match</option>
<option value='aspect_tip288'>aspect_tip288</option>
<option value='avl_strcat_fix'>avl_strcat_fix</option>
<option value='avl_tip_282'>avl_tip_282</option>
<option value='backout_memaccounting'>backout_memaccounting</option>
<option value='bch_coverity'>bch_coverity</option>
<option value='better_deprecation'>better_deprecation</option>
<option value='better_deprecation_85'>better_deprecation_85</option>
<option value='bg_tip_282'>bg_tip_282</option>
<option value='bsg_0d_radix_prefix'>bsg_0d_radix_prefix</option>
<option value='bug3036566'>bug3036566</option>
<option value='bug_010f4162ef'>bug_010f4162ef</option>
<option value='bug_0520d17284'>bug_0520d17284</option>
<option value='bug_05489ce335'>bug_05489ce335</option>
<option value='bug_0b874c344d'>bug_0b874c344d</option>
<option value='bug_0b874c344d_ak_info_frame_coro'>bug_0b874c344d_ak_info_frame_coro</option>
<option value='bug_0b8c387cf7'>bug_0b8c387cf7</option>
<option value='bug_0c043a175'>bug_0c043a175</option>
<option value='bug_0e4d88b650'>bug_0e4d88b650</option>
<option value='bug_0f42ff7871'>bug_0f42ff7871</option>
<option value='bug_1189293'>bug_1189293</option>
<option value='bug_1224888'>bug_1224888</option>
<option value='bug_12b0997ce7'>bug_12b0997ce7</option>
<option value='bug_13d3af3ad5'>bug_13d3af3ad5</option>
<option value='bug_13d3af3ad5_fork'>bug_13d3af3ad5_fork</option>
<option value='bug_1493a43044'>bug_1493a43044</option>
<option value='bug_1536227'>bug_1536227</option>
<option value='bug_16828b3744'>bug_16828b3744</option>
<option value='bug_1712098'>bug_1712098</option>
<option value='bug_1758a0b603'>bug_1758a0b603</option>
<option value='bug_1a25fdfec6'>bug_1a25fdfec6</option>
<option value='bug_1b0266d8bb'>bug_1b0266d8bb</option>
<option value='bug_2152292'>bug_2152292</option>
<option value='bug_219866c1e9'>bug_219866c1e9</option>
<option value='bug_2413550'>bug_2413550</option>
<option value='bug_2502002'>bug_2502002</option>
<option value='bug_25842c161f'>bug_25842c161f</option>
<option value='bug_272e866f1e'>bug_272e866f1e</option>
<option value='bug_2902268'>bug_2902268</option>
<option value='bug_2911139'>bug_2911139</option>
<option value='bug_2992970'>bug_2992970</option>
<option value='bug_2a94652ee1'>bug_2a94652ee1</option>
<option value='bug_2f7cbd01c3'>bug_2f7cbd01c3</option>
<option value='bug_2f9df4c4fa'>bug_2f9df4c4fa</option>
<option value='bug_3024359'>bug_3024359</option>
<option value='bug_3033307'>bug_3033307</option>
<option value='bug_3092089'>bug_3092089</option>
<option value='bug_3154ea2759'>bug_3154ea2759</option>
<option value='bug_31661d2135'>bug_31661d2135</option>
<option value='bug_3173086' selected='selected'>bug_3173086</option>
<option value='bug_3185407'>bug_3185407</option>
<option value='bug_3202171'>bug_3202171</option>
<option value='bug_3216070'>bug_3216070</option>
<option value='bug_3288345'>bug_3288345</option>
<option value='bug_3293874'>bug_3293874</option>
<option value='bug_32ae34e63a'>bug_32ae34e63a</option>
<option value='bug_3362446'>bug_3362446</option>
<option value='bug_336441ed59'>bug_336441ed59</option>
<option value='bug_3365156'>bug_3365156</option>
<option value='bug_3389764'>bug_3389764</option>
<option value='bug_3392070'>bug_3392070</option>
<option value='bug_3397515'>bug_3397515</option>
<option value='bug_3401704'>bug_3401704</option>
<option value='bug_3413857'>bug_3413857</option>
<option value='bug_3414754'>bug_3414754</option>
<option value='bug_3418547'>bug_3418547</option>
<option value='bug_3466099'>bug_3466099</option>
<option value='bug_3475569'>bug_3475569</option>
<option value='bug_3480599'>bug_3480599</option>
<option value='bug_3484402'>bug_3484402</option>
<option value='bug_3485833'>bug_3485833</option>
<option value='bug_3493120'>bug_3493120</option>
<option value='bug_3496014'>bug_3496014</option>
<option value='bug_3508771'>bug_3508771</option>
<option value='bug_3511806'>bug_3511806</option>
<option value='bug_3514475'>bug_3514475</option>
<option value='bug_3519357'>bug_3519357</option>
<option value='bug_3522560'>bug_3522560</option>
<option value='bug_3525762'>bug_3525762</option>
<option value='bug_3525907'>bug_3525907</option>
<option value='bug_3530536'>bug_3530536</option>
<option value='bug_3532959'>bug_3532959</option>
<option value='bug_3536888'>bug_3536888</option>
<option value='bug_3544685'>bug_3544685</option>
<option value='bug_3545363'>bug_3545363</option>
<option value='bug_3555001'>bug_3555001</option>
<option value='bug_3562640'>bug_3562640</option>
<option value='bug_3562640_alt'>bug_3562640_alt</option>
<option value='bug_3564735'>bug_3564735</option>
<option value='bug_3566106'>bug_3566106</option>
<option value='bug_3567063'>bug_3567063</option>
<option value='bug_3588687'>bug_3588687</option>
<option value='bug_3592747'>bug_3592747</option>
<option value='bug_3598300'>bug_3598300</option>
<option value='bug_3598580'>bug_3598580</option>
<option value='bug_3599789'>bug_3599789</option>
<option value='bug_3600057'>bug_3600057</option>
<option value='bug_3600057_85'>bug_3600057_85</option>
<option value='bug_3600058_td'>bug_3600058_td</option>
<option value='bug_3600328'>bug_3600328</option>
<option value='bug_3601260'>bug_3601260</option>
<option value='bug_3602706'>bug_3602706</option>
<option value='bug_3603434'>bug_3603434</option>
<option value='bug_3603553'>bug_3603553</option>
<option value='bug_3603695'>bug_3603695</option>
<option value='bug_3604074'>bug_3604074</option>
<option value='bug_3604576'>bug_3604576</option>
<option value='bug_3605401'>bug_3605401</option>
<option value='bug_3605447'>bug_3605447</option>
<option value='bug_3606121'>bug_3606121</option>
<option value='bug_3606683'>bug_3606683</option>
<option value='bug_3606683_84'>bug_3606683_84</option>
<option value='bug_3606683_85'>bug_3606683_85</option>
<option value='bug_3607246'>bug_3607246</option>
<option value='bug_3607372'>bug_3607372</option>
<option value='bug_3608360'>bug_3608360</option>
<option value='bug_3608714'>bug_3608714</option>
<option value='bug_3609693'>bug_3609693</option>
<option value='bug_3610026'>bug_3610026</option>
<option value='bug_3610383'>bug_3610383</option>
<option value='bug_3610404'>bug_3610404</option>
<option value='bug_3611974'>bug_3611974</option>
<option value='bug_3613609'>bug_3613609</option>
<option value='bug_3613671'>bug_3613671</option>
<option value='bug_3614342'>bug_3614342</option>
<option value='bug_39f6304c2e'>bug_39f6304c2e</option>
<option value='bug_46f801ea5a'>bug_46f801ea5a</option>
<option value='bug_473946'>bug_473946</option>
<option value='bug_47d66253c9'>bug_47d66253c9</option>
<option value='bug_4a0c163d24'>bug_4a0c163d24</option>
<option value='bug_4b61afd660'>bug_4b61afd660</option>
<option value='bug_4dbdd9af14'>bug_4dbdd9af14</option>
<option value='bug_50750c735a'>bug_50750c735a</option>
<option value='bug_510001'>bug_510001</option>
<option value='bug_547989'>bug_547989</option>
<option value='bug_57945b574a'>bug_57945b574a</option>
<option value='bug_57945b574a_without_stub'>bug_57945b574a_without_stub</option>
<option value='bug_581937ab1e'>bug_581937ab1e</option>
<option value='bug_58b96f6744'>bug_58b96f6744</option>
<option value='bug_593baa032c'>bug_593baa032c</option>
<option value='bug_5adc350683'>bug_5adc350683</option>
<option value='bug_5adc350683_86'>bug_5adc350683_86</option>
<option value='bug_5d170b5ca5'>bug_5d170b5ca5</option>
<option value='bug_5f71353740'>bug_5f71353740</option>
<option value='bug_67aa9a2070'>bug_67aa9a2070</option>
<option value='bug_6ca52aec14'>bug_6ca52aec14</option>
<option value='bug_716b427f76'>bug_716b427f76</option>
<option value='bug_734138ded8'>bug_734138ded8</option>
<option value='bug_75b8433707'>bug_75b8433707</option>
<option value='bug_7a87a9bc5b'>bug_7a87a9bc5b</option>
<option value='bug_7f02ff1efa'>bug_7f02ff1efa</option>
<option value='bug_80304238ac'>bug_80304238ac</option>
<option value='bug_85ce4bf928'>bug_85ce4bf928</option>
<option value='bug_86ceb4e2b6'>bug_86ceb4e2b6</option>
<option value='bug_879a0747be'>bug_879a0747be</option>
<option value='bug_894da183c8'>bug_894da183c8</option>
<option value='bug_8bd13f07bd'>bug_8bd13f07bd</option>
<option value='bug_900cb0284bc'>bug_900cb0284bc</option>
<option value='bug_96c3f3b47d1'>bug_96c3f3b47d1</option>
<option value='bug_97069ea11a'>bug_97069ea11a</option>
<option value='bug_9b47029467631832'>bug_9b47029467631832</option>
<option value='bug_a3309d01db'>bug_a3309d01db</option>
<option value='bug_adb198c256'>bug_adb198c256</option>
<option value='bug_af08e89777'>bug_af08e89777</option>
<option value='bug_b26e38a3e4'>bug_b26e38a3e4</option>
<option value='bug_b5ced5865b'>bug_b5ced5865b</option>
<option value='bug_b87ad7e914'>bug_b87ad7e914</option>
<option value='bug_b9b2079e6d'>bug_b9b2079e6d</option>
<option value='bug_ba44e415a0'>bug_ba44e415a0</option>
<option value='bug_bbc304f61a'>bug_bbc304f61a</option>
<option value='bug_bc1a96407a'>bug_bc1a96407a</option>
<option value='bug_bd7f17bce8'>bug_bd7f17bce8</option>
<option value='bug_bdd91c7e43'>bug_bdd91c7e43</option>
<option value='bug_c4e230f29b'>bug_c4e230f29b</option>
<option value='bug_c7d0bc9a549714e0'>bug_c7d0bc9a549714e0</option>
<option value='bug_d2ffcca163'>bug_d2ffcca163</option>
<option value='bug_d3071887dbc7aeac'>bug_d3071887dbc7aeac</option>
<option value='bug_d4e464ae48'>bug_d4e464ae48</option>
<option value='bug_d4e7780ca1'>bug_d4e7780ca1</option>
<option value='bug_d5ddbc7f49'>bug_d5ddbc7f49</option>
<option value='bug_db0a5f6417'>bug_db0a5f6417</option>
<option value='bug_dcc03414f5'>bug_dcc03414f5</option>
<option value='bug_dfc08326e3'>bug_dfc08326e3</option>
<option value='bug_e0a7b3e5f8'>bug_e0a7b3e5f8</option>
<option value='bug_e21fc32c2aa'>bug_e21fc32c2aa</option>
<option value='bug_e711ffb458'>bug_e711ffb458</option>
<option value='bug_f1253530cd'>bug_f1253530cd</option>
<option value='bug_f1253530cd_alt'>bug_f1253530cd_alt</option>
<option value='bug_f4f44174e'>bug_f4f44174e</option>
<option value='bug_f97d4ee020'>bug_f97d4ee020</option>
<option value='bug_f9fe90d0fa'>bug_f9fe90d0fa</option>
<option value='bug_io_32_11'>bug_io_32_11</option>
<option value='bug_itcl_1b2865'>bug_itcl_1b2865</option>
<option value='bug_unknown_no_errorcode'>bug_unknown_no_errorcode</option>
<option value='bugfix_832a1994c7_for_precompiled_bc'>bugfix_832a1994c7_for_precompiled_bc</option>
<option value='cjo_hydra'>cjo_hydra</option>
<option value='compile_ensemble'>compile_ensemble</option>
<option value='contrib_patrick_fradin_code_cleanup'>contrib_patrick_fradin_code_cleanup</option>
<option value='core_8_0_2_synthetic'>core_8_0_2_synthetic</option>
<option value='core_8_0_3_pr'>core_8_0_3_pr</option>
<option value='core_8_0_4_synthetic'>core_8_0_4_synthetic</option>
<option value='core_8_0_5_base_synthetic'>core_8_0_5_base_synthetic</option>
<option value='core_8_0_5_branch'>core_8_0_5_branch</option>
<option value='core_8_0_5_synthetic'>core_8_0_5_synthetic</option>
<option value='core_8_0_6_branch'>core_8_0_6_branch</option>
<option value='core_8_1_0_synthetic'>core_8_1_0_synthetic</option>
<option value='core_8_1_b1_synthetic'>core_8_1_b1_synthetic</option>
<option value='core_8_1_b2_synthetic'>core_8_1_b2_synthetic</option>
<option value='core_8_1_b3_synthetic'>core_8_1_b3_synthetic</option>
<option value='core_8_1_branch_old'>core_8_1_branch_old</option>
<option value='core_8_2_1_branch'>core_8_2_1_branch</option>
<option value='core_8_2_b1_synthetic'>core_8_2_b1_synthetic</option>
<option value='core_8_2_b3_branch'>core_8_2_b3_branch</option>
<option value='core_8_3_1_branch'>core_8_3_1_branch</option>
<option value='core_8_3_1_io_rewrite'>core_8_3_1_io_rewrite</option>
<option value='core_8_3_1_synthetic'>core_8_3_1_synthetic</option>
<option value='core_8_4_20_rc'>core_8_4_20_rc</option>
<option value='core_8_4_a2_synthetic'>core_8_4_a2_synthetic</option>
<option value='core_8_4_branch'>core_8_4_branch</option>
<option value='core_8_5_10_rc'>core_8_5_10_rc</option>
<option value='core_8_5_11_rc'>core_8_5_11_rc</option>
<option value='core_8_5_12_rc'>core_8_5_12_rc</option>
<option value='core_8_5_13_rc'>core_8_5_13_rc</option>
<option value='core_8_5_14rc'>core_8_5_14rc</option>
<option value='core_8_5_15_rc'>core_8_5_15_rc</option>
<option value='core_8_5_16_rc'>core_8_5_16_rc</option>
<option value='core_8_5_17_rc'>core_8_5_17_rc</option>
<option value='core_8_5_18_rc'>core_8_5_18_rc</option>
<option value='core_8_5_19_rc'>core_8_5_19_rc</option>
<option value='core_8_5_a5_synthetic'>core_8_5_a5_synthetic</option>
<option value='core_8_5_branch'>core_8_5_branch</option>
<option value='core_8_5_branch_fix_1997007'>core_8_5_branch_fix_1997007</option>
<option value='core_8_6_0_rc'>core_8_6_0_rc</option>
<option value='core_8_6_1_rc'>core_8_6_1_rc</option>
<option value='core_8_6_2_rc'>core_8_6_2_rc</option>
<option value='core_8_6_3_rc'>core_8_6_3_rc</option>
<option value='core_8_6_4_rc'>core_8_6_4_rc</option>
<option value='core_8_6_5_rc'>core_8_6_5_rc</option>
<option value='core_8_6_6_rc'>core_8_6_6_rc</option>
<option value='core_8_6_7_rc'>core_8_6_7_rc</option>
<option value='core_8_6_b2_rc'>core_8_6_b2_rc</option>
<option value='core_8_6_b3_rc'>core_8_6_b3_rc</option>
<option value='core_8_6_branch'>core_8_6_branch</option>
<option value='core_8_6_branch_fork'>core_8_6_branch_fork</option>
<option value='core_8_7_a1_rc'>core_8_7_a1_rc</option>
<option value='core_stabilizer_branch'>core_stabilizer_branch</option>
<option value='core_stabilizer_merge_synthetic'>core_stabilizer_merge_synthetic</option>
<option value='core_zip_vfs'>core_zip_vfs</option>
<option value='core_zip_vfs_c_encoder'>core_zip_vfs_c_encoder</option>
<option value='core_zip_vfs_static'>core_zip_vfs_static</option>
<option value='cpuid_on_unix'>cpuid_on_unix</option>
<option value='cygwin_environment_changes'>cygwin_environment_changes</option>
<option value='dah_proc_arg_upvar'>dah_proc_arg_upvar</option>
<option value='damkerngt_file_utime'>damkerngt_file_utime</option>
<option value='daves_chop_branch'>daves_chop_branch</option>
<option value='daves_mk_branch'>daves_mk_branch</option>
<option value='dev_8_1_stubs_branch'>dev_8_1_stubs_branch</option>
<option value='dev_hobbs_branch'>dev_hobbs_branch</option>
<option value='dev_stubs_branch'>dev_stubs_branch</option>
<option value='dgp_3401704'>dgp_3401704</option>
<option value='dgp_async_socket'>dgp_async_socket</option>
<option value='dgp_bug_find'>dgp_bug_find</option>
<option value='dgp_bye_ctx_eval_flag'>dgp_bye_ctx_eval_flag</option>
<option value='dgp_bye_location_eval_list'>dgp_bye_location_eval_list</option>
<option value='dgp_channel_flag_repair'>dgp_channel_flag_repair</option>
<option value='dgp_cmd_epoch'>dgp_cmd_epoch</option>
<option value='dgp_compile_list_shimmer'>dgp_compile_list_shimmer</option>
<option value='dgp_defer_string_rep'>dgp_defer_string_rep</option>
<option value='dgp_demo'>dgp_demo</option>
<option value='dgp_dup_encoding_fix'>dgp_dup_encoding_fix</option>
<option value='dgp_ecr'>dgp_ecr</option>
<option value='dgp_encoding_flags'>dgp_encoding_flags</option>
<option value='dgp_ensemble_rewrite'>dgp_ensemble_rewrite</option>
<option value='dgp_eof'>dgp_eof</option>
<option value='dgp_experiment'>dgp_experiment</option>
<option value='dgp_flush_channel'>dgp_flush_channel</option>
<option value='dgp_hoehrmann_decoder'>dgp_hoehrmann_decoder</option>
<option value='dgp_init_bytecode'>dgp_init_bytecode</option>
<option value='dgp_list_simplify'>dgp_list_simplify</option>
<option value='dgp_literal_reform'>dgp_literal_reform</option>
<option value='dgp_may_be_pointless'>dgp_may_be_pointless</option>
<option value='dgp_move_buffers'>dgp_move_buffers</option>
<option value='dgp_no_buffer_recycle'>dgp_no_buffer_recycle</option>
<option value='dgp_optimize_output_stage'>dgp_optimize_output_stage</option>
<option value='dgp_pkg_migration'>dgp_pkg_migration</option>
<option value='dgp_properbytearray'>dgp_properbytearray</option>
<option value='dgp_purge_NRRunObjProc'>dgp_purge_NRRunObjProc</option>
<option value='dgp_read_bytes'>dgp_read_bytes</option>
<option value='dgp_read_bytes_detour'>dgp_read_bytes_detour</option>
<option value='dgp_read_chars'>dgp_read_chars</option>
<option value='dgp_refactor'>dgp_refactor</option>
<option value='dgp_refactor_merge_synthetic'>dgp_refactor_merge_synthetic</option>
<option value='dgp_remove_string_result'>dgp_remove_string_result</option>
<option value='dgp_review'>dgp_review</option>
<option value='dgp_revise_parsedvarnametype'>dgp_revise_parsedvarnametype</option>
<option value='dgp_scan_element'>dgp_scan_element</option>
<option value='dgp_slow_read'>dgp_slow_read</option>
<option value='dgp_sprintf'>dgp_sprintf</option>
<option value='dgp_stack_depth_tester'>dgp_stack_depth_tester</option>
<option value='dgp_stackedstdchan'>dgp_stackedstdchan</option>
<option value='dgp_stop_regexp_test_crash'>dgp_stop_regexp_test_crash</option>
<option value='dgp_string_cat'>dgp_string_cat</option>
<option value='dgp_string_find'>dgp_string_find</option>
<option value='dgp_stringcat_delaystringrep'>dgp_stringcat_delaystringrep</option>
<option value='dgp_switch_compile'>dgp_switch_compile</option>
<option value='dgp_tailcall_errorinfo'>dgp_tailcall_errorinfo</option>
<option value='dgp_tailcall_errorinfo_alt'>dgp_tailcall_errorinfo_alt</option>
<option value='dgp_tcs_rewrite'>dgp_tcs_rewrite</option>
<option value='dgp_thread_leaks'>dgp_thread_leaks</option>
<option value='dgp_trunk_flag_repair'>dgp_trunk_flag_repair</option>
<option value='dgp_trunk_read'>dgp_trunk_read</option>
<option value='dgp_win_specific_strict'>dgp_win_specific_strict</option>
<option value='dgp_writebytes_optimize'>dgp_writebytes_optimize</option>
<option value='dkf_64bit_support_branch'>dkf_64bit_support_branch</option>
<option value='dkf_alias_encoding'>dkf_alias_encoding</option>
<option value='dkf_asm_crash_20131022'>dkf_asm_crash_20131022</option>
<option value='dkf_bcc_optimize'>dkf_bcc_optimize</option>
<option value='dkf_better_try_compilation'>dkf_better_try_compilation</option>
<option value='dkf_bytecode_8_6'>dkf_bytecode_8_6</option>
<option value='dkf_bytecode_8_6_eval'>dkf_bytecode_8_6_eval</option>
<option value='dkf_bytecode_8_6_join'>dkf_bytecode_8_6_join</option>
<option value='dkf_bytecode_8_6_next'>dkf_bytecode_8_6_next</option>
<option value='dkf_bytecode_8_6_string_is'>dkf_bytecode_8_6_string_is</option>
<option value='dkf_bytecode_8_6_string_replace'>dkf_bytecode_8_6_string_replace</option>
<option value='dkf_bytecode_8_6_yield'>dkf_bytecode_8_6_yield</option>
<option value='dkf_bytecode_optimizer'>dkf_bytecode_optimizer</option>
<option value='dkf_command_type'>dkf_command_type</option>
<option value='dkf_compile_improvements'>dkf_compile_improvements</option>
<option value='dkf_dict_with_compiled'>dkf_dict_with_compiled</option>
<option value='dkf_documentation_figures'>dkf_documentation_figures</option>
<option value='dkf_expose_ptrgetvar'>dkf_expose_ptrgetvar</option>
<option value='dkf_expose_ptrgetvar_8_6'>dkf_expose_ptrgetvar_8_6</option>
<option value='dkf_http_cookies'>dkf_http_cookies</option>
<option value='dkf_improved_disassembler'>dkf_improved_disassembler</option>
<option value='dkf_loop_exception_range_work'>dkf_loop_exception_range_work</option>
<option value='dkf_namespace_as_ensemble'>dkf_namespace_as_ensemble</option>
<option value='dkf_notifier_poll'>dkf_notifier_poll</option>
<option value='dkf_oo_override_definition_namespaces'>dkf_oo_override_definition_namespaces</option>
<option value='dkf_quieter_compiles'>dkf_quieter_compiles</option>
<option value='dkf_review'>dkf_review</option>
<option value='dkf_utf16_branch'>dkf_utf16_branch</option>
<option value='dkf_wait_with_poll'>dkf_wait_with_poll</option>
<option value='dogeen_assembler_branch'>dogeen_assembler_branch</option>
<option value='dogeen_assembler_merge_synthetic'>dogeen_assembler_merge_synthetic</option>
<option value='drh_micro_optimization'>drh_micro_optimization</option>
<option value='editorconfig'>editorconfig</option>
<option value='empty_bodies'>empty_bodies</option>
<option value='experiment'>experiment</option>
<option value='experimental'>experimental</option>
<option value='ferrieux_nacl'>ferrieux_nacl</option>
<option value='fix_1997007'>fix_1997007</option>
<option value='fix_42202ba1e5ff566e'>fix_42202ba1e5ff566e</option>
<option value='fix_8_5_578155d5a19b348d'>fix_8_5_578155d5a19b348d</option>
<option value='fix_win_native_access'>fix_win_native_access</option>
<option value='fix_windows_zlib'>fix_windows_zlib</option>
<option value='forgiving_pkgconfig'>forgiving_pkgconfig</option>
<option value='freq_3010352_impl'>freq_3010352_impl</option>
<option value='frq_3527238'>frq_3527238</option>
<option value='frq_3544967'>frq_3544967</option>
<option value='frq_3579001'>frq_3579001</option>
<option value='frq_3599786'>frq_3599786</option>
<option value='gahr_split_install'>gahr_split_install</option>
<option value='gahr_ticket_dee3d66bc7'>gahr_ticket_dee3d66bc7</option>
<option value='gahr_ticket_e6f27aa56f'>gahr_ticket_e6f27aa56f</option>
<option value='gahr_tip_447'>gahr_tip_447</option>
<option value='griffin_numlevels'>griffin_numlevels</option>
<option value='htmlCopyrightsFix'>htmlCopyrightsFix</option>
<option value='htmlhelpFix'>htmlhelpFix</option>
<option value='http3'>http3</option>
<option value='hypnotoad'>hypnotoad</option>
<option value='hypnotoad_bug_3598385'>hypnotoad_bug_3598385</option>
<option value='hypnotoad_prefer_native_8_6'>hypnotoad_prefer_native_8_6</option>
<option value='hypnotoad_vexpr'>hypnotoad_vexpr</option>
<option value='info_linkedname'>info_linkedname</option>
<option value='initsubsystems'>initsubsystems</option>
<option value='initsubsystems2'>initsubsystems2</option>
<option value='initsubsystems2_split'>initsubsystems2_split</option>
<option value='iocmd_leaks'>iocmd_leaks</option>
<option value='ios'>ios</option>
<option value='irontcl'>irontcl</option>
<option value='jcr_notifier_poll'>jcr_notifier_poll</option>
<option value='je_tty_cleanup'>je_tty_cleanup</option>
<option value='jenglish_termios_cleanup'>jenglish_termios_cleanup</option>
<option value='jn_0d_radix_prefix'>jn_0d_radix_prefix</option>
<option value='jn_Tcl_requirement'>jn_Tcl_requirement</option>
<option value='jn_emptystring'>jn_emptystring</option>
<option value='jn_frq_3257396'>jn_frq_3257396</option>
<option value='jn_no_struct_names'>jn_no_struct_names</option>
<option value='jn_unc_vfs'>jn_unc_vfs</option>
<option value='jn_wide_printf'>jn_wide_printf</option>
<option value='kbk_clock_encoding_ensembles'>kbk_clock_encoding_ensembles</option>
<option value='kennykb_numerics_branch'>kennykb_numerics_branch</option>
<option value='kennykb_tip_22_33'>kennykb_tip_22_33</option>
<option value='kennykb_tip_22_33_botched'>kennykb_tip_22_33_botched</option>
<option value='lanam_array_for_impl'>lanam_array_for_impl</option>
<option value='libtommath'>libtommath</option>
<option value='libtommath_1_0'>libtommath_1_0</option>
<option value='libtommath_1_0_1'>libtommath_1_0_1</option>
<option value='libtommath_tcl_fixes_75'>libtommath_tcl_fixes_75</option>
<option value='little'>little</option>
<option value='macosx_8_4_branch'>macosx_8_4_branch</option>
<option value='master'>master</option>
<option value='merge_tzdata_to_trunk'>merge_tzdata_to_trunk</option>
<option value='micro_opt'>micro_opt</option>
<option value='mig_alloc_reform'>mig_alloc_reform</option>
<option value='mig_catch_compiler'>mig_catch_compiler</option>
<option value='mig_err'>mig_err</option>
<option value='mig_no280'>mig_no280</option>
<option value='mig_nre_mods'>mig_nre_mods</option>
<option value='mig_opt2'>mig_opt2</option>
<option value='mig_opt2_tmp'>mig_opt2_tmp</option>
<option value='mig_opt_foreach'>mig_opt_foreach</option>
<option value='mig_optimize'>mig_optimize</option>
<option value='mig_review'>mig_review</option>
<option value='mig_stacklevels'>mig_stacklevels</option>
<option value='mig_strip_brutal'>mig_strip_brutal</option>
<option value='mig_tailcall_cleanup'>mig_tailcall_cleanup</option>
<option value='mig_tmp'>mig_tmp</option>
<option value='mig_tmp_optimize'>mig_tmp_optimize</option>
<option value='minimal_fix_for_3598300_problems'>minimal_fix_for_3598300_problems</option>
<option value='miniz'>miniz</option>
<option value='mistachkin_review'>mistachkin_review</option>
<option value='mistake'>mistake</option>
<option value='mistake_20110314'>mistake_20110314</option>
<option value='mistake_20110314a'>mistake_20110314a</option>
<option value='mistkae'>mistkae</option>
<option value='mod_8_3_4_branch'>mod_8_3_4_branch</option>
<option value='more_macros'>more_macros</option>
<option value='msgcat_dyn_locale'>msgcat_dyn_locale</option>
<option value='msofer_bcEngine'>msofer_bcEngine</option>
<option value='msofer_wcodes_branch'>msofer_wcodes_branch</option>
<option value='msvc_with_64bit_zlib1_dll'>msvc_with_64bit_zlib1_dll</option>
<option value='no_shimmer_string_length'>no_shimmer_string_length</option>
<option value='no_smartref'>no_smartref</option>
<option value='nonmonotonic_obj_alloc'>nonmonotonic_obj_alloc</option>
<option value='notifier'>notifier</option>
<option value='novem'>novem</option>
<option value='novem_64bit_sizes'>novem_64bit_sizes</option>
<option value='novem_ak_iframe_direct'>novem_ak_iframe_direct</option>
<option value='novem_ak_preserve_experiments'>novem_ak_preserve_experiments</option>
<option value='novem_bighash'>novem_bighash</option>
<option value='novem_bug_3598300'>novem_bug_3598300</option>
<option value='novem_demo_bug_3588687'>novem_demo_bug_3588687</option>
<option value='novem_freeifrefcountzero'>novem_freeifrefcountzero</option>
<option value='novem_more_memory_API'>novem_more_memory_API</option>
<option value='novem_no_register_objtypes'>novem_no_register_objtypes</option>
<option value='novem_no_shimmer_string_length'>novem_no_shimmer_string_length</option>
<option value='novem_no_startcmd'>novem_no_startcmd</option>
<option value='novem_numbers_eias'>novem_numbers_eias</option>
<option value='novem_purge_literals'>novem_purge_literals</option>
<option value='novem_reduced_bytecodes'>novem_reduced_bytecodes</option>
<option value='novem_reduced_symbol_export'>novem_reduced_symbol_export</option>
<option value='novem_remove_string_result'>novem_remove_string_result</option>
<option value='novem_remove_va'>novem_remove_va</option>
<option value='novem_rename_memory_API'>novem_rename_memory_API</option>
<option value='novem_review'>novem_review</option>
<option value='novem_saveresult_as_macro'>novem_saveresult_as_macro</option>
<option value='novem_support'>novem_support</option>
<option value='novem_two_layer_list'>novem_two_layer_list</option>
<option value='novem_unversioned_stub'>novem_unversioned_stub</option>
<option value='off_8_4_branch'>off_8_4_branch</option>
<option value='off_trunk'>off_trunk</option>
<option value='on_hold_84'>on_hold_84</option>
<option value='on_hold_85'>on_hold_85</option>
<option value='on_hold_trunk'>on_hold_trunk</option>
<option value='oo_copy_ns'>oo_copy_ns</option>
<option value='other_64bit_candidates'>other_64bit_candidates</option>
<option value='package_files'>package_files</option>
<option value='panic_noreturn'>panic_noreturn</option>
<option value='prevent_inline'>prevent_inline</option>
<option value='private'>private</option>
<option value='pseudotrunk_2011_03_08'>pseudotrunk_2011_03_08</option>
<option value='pyk_emptystring'>pyk_emptystring</option>
<option value='pyk_expr_numeric'>pyk_expr_numeric</option>
<option value='pyk_listdictstringrep'>pyk_listdictstringrep</option>
<option value='pyk_pkgrequirenre'>pyk_pkgrequirenre</option>
<option value='pyk_trunk'>pyk_trunk</option>
<option value='remove_pathappend_intrep'>remove_pathappend_intrep</option>
<option value='remove_trim_header'>remove_trim_header</option>
<option value='revert_3396731'>revert_3396731</option>
<option value='rfe_1711975'>rfe_1711975</option>
<option value='rfe_3216010'>rfe_3216010</option>
<option value='rfe_3389978'>rfe_3389978</option>
<option value='rfe_3432962'>rfe_3432962</option>
<option value='rfe_3464401'>rfe_3464401</option>
<option value='rfe_3473670'>rfe_3473670</option>
<option value='rfe_6c0d7aec67'>rfe_6c0d7aec67</option>
<option value='rfe_854941'>rfe_854941</option>
<option value='rfe_b42b208ba4'>rfe_b42b208ba4</option>
<option value='rfe_dfc08326e3'>rfe_dfc08326e3</option>
<option value='rfe_notifier_fork'>rfe_notifier_fork</option>
<option value='rmax_ipv6_branch'>rmax_ipv6_branch</option>
<option value='rmax_ipv6_merge_synthetic'>rmax_ipv6_merge_synthetic</option>
<option value='robust_async_connect_tests'>robust_async_connect_tests</option>
<option value='scriptics_sc_1_0_branch'>scriptics_sc_1_0_branch</option>
<option value='scriptics_sc_1_1_branch'>scriptics_sc_1_1_branch</option>
<option value='scriptics_sc_2_0_b2_synthetic'>scriptics_sc_2_0_b2_synthetic</option>
<option value='scriptics_sc_2_0_b5_synthetic'>scriptics_sc_2_0_b5_synthetic</option>
<option value='scriptics_sc_2_0_fixed_synthetic'>scriptics_sc_2_0_fixed_synthetic</option>
<option value='scriptics_tclpro_1_2'>scriptics_tclpro_1_2</option>
<option value='scriptics_tclpro_1_2_old'>scriptics_tclpro_1_2_old</option>
<option value='scriptics_tclpro_1_2_synthetic'>scriptics_tclpro_1_2_synthetic</option>
<option value='scriptics_tclpro_1_3_b2_branch'>scriptics_tclpro_1_3_b2_branch</option>
<option value='scriptics_tclpro_1_3_b3_synthetic'>scriptics_tclpro_1_3_b3_synthetic</option>
<option value='sebres_8_5_event_perf_branch'>sebres_8_5_event_perf_branch</option>
<option value='sebres_8_5_timerate'>sebres_8_5_timerate</option>
<option value='sebres_8_6_clock_speedup'>sebres_8_6_clock_speedup</option>
<option value='sebres_8_6_clock_speedup_cr1'>sebres_8_6_clock_speedup_cr1</option>
<option value='sebres_8_6_event_perf_branch'>sebres_8_6_event_perf_branch</option>
<option value='sebres_8_6_timerate'>sebres_8_6_timerate</option>
<option value='sebres_clean_core_8_5'>sebres_clean_core_8_5</option>
<option value='sebres_clock_speedup'>sebres_clock_speedup</option>
<option value='sebres_clock_tz_fix'>sebres_clock_tz_fix</option>
<option value='sebres_event_perf_fix_busy_wait'>sebres_event_perf_fix_busy_wait</option>
<option value='sebres_optimized_8_5'>sebres_optimized_8_5</option>
<option value='sebres_trunk_clock_speedup'>sebres_trunk_clock_speedup</option>
<option value='sebres_trunk_timerate'>sebres_trunk_timerate</option>
<option value='semver'>semver</option>
<option value='stwo_dev86'>stwo_dev86</option>
<option value='tclPlatformEngine'>tclPlatformEngine</option>
<option value='tcl_nosize'>tcl_nosize</option>
<option value='tclchan_assertions'>tclchan_assertions</option>
<option value='tclpro_1_5_0_synthetic'>tclpro_1_5_0_synthetic</option>
<option value='tcltest_verbose_desc'>tcltest_verbose_desc</option>
<option value='tgl_pg_re'>tgl_pg_re</option>
<option value='thread_leaks'>thread_leaks</option>
<option value='ticket_9b2e636361'>ticket_9b2e636361</option>
<option value='ticket_e770d92d6'>ticket_e770d92d6</option>
<option value='tip280_test_coverage'>tip280_test_coverage</option>
<option value='tip404_tcl8_5'>tip404_tcl8_5</option>
<option value='tip429_only_id'>tip429_only_id</option>
<option value='tip_106_impl'>tip_106_impl</option>
<option value='tip_162_branch'>tip_162_branch</option>
<option value='tip_257_implementation_branch'>tip_257_implementation_branch</option>
<option value='tip_257_implementation_branch_root_synthetic'>tip_257_implementation_branch_root_synthetic</option>
<option value='tip_257_merge1_branch_20061020T1300'>tip_257_merge1_branch_20061020T1300</option>
<option value='tip_278_branch'>tip_278_branch</option>
<option value='tip_282'>tip_282</option>
<option value='tip_302'>tip_302</option>
<option value='tip_312'>tip_312</option>
<option value='tip_318_update'>tip_318_update</option>
<option value='tip_388_impl'>tip_388_impl</option>
<option value='tip_389_impl'>tip_389_impl</option>
<option value='tip_395_with_alt_name'>tip_395_with_alt_name</option>
<option value='tip_398_impl'>tip_398_impl</option>
<option value='tip_400_impl'>tip_400_impl</option>
<option value='tip_401'>tip_401</option>
<option value='tip_404'>tip_404</option>
<option value='tip_405_impl_td'>tip_405_impl_td</option>
<option value='tip_427'>tip_427</option>
<option value='tip_428'>tip_428</option>
<option value='tip_429'>tip_429</option>
<option value='tip_436'>tip_436</option>
<option value='tip_440_alt'>tip_440_alt</option>
<option value='tip_440_backport'>tip_440_backport</option>
<option value='tip_444'>tip_444</option>
<option value='tip_445'>tip_445</option>
<option value='tip_445_fork'>tip_445_fork</option>
<option value='tip_445_reject'>tip_445_reject</option>
<option value='tip_452'>tip_452</option>
<option value='tip_456'>tip_456</option>
<option value='tip_456_fork'>tip_456_fork</option>
<option value='tip_457'>tip_457</option>
<option value='tip_458'>tip_458</option>
<option value='tip_458_experiment'>tip_458_experiment</option>
<option value='tip_463'>tip_463</option>
<option value='tip_465'>tip_465</option>
<option value='tip_468'>tip_468</option>
<option value='tip_468_bis'>tip_468_bis</option>
<option value='tip_469'>tip_469</option>
<option value='tip_470'>tip_470</option>
<option value='tip_473'>tip_473</option>
<option value='tip_59_implementation'>tip_59_implementation</option>
<option value='tip_improve_exec'>tip_improve_exec</option>
<option value='tk_bug_9eb55debc5'>tk_bug_9eb55debc5</option>
<option value='tkt3328635_posix_monotonic_clock'>tkt3328635_posix_monotonic_clock</option>
<option value='tkt_04e26c02c0'>tkt_04e26c02c0</option>
<option value='tkt_414d10346b'>tkt_414d10346b</option>
<option value='tkt_4d5ae7d88a'>tkt_4d5ae7d88a</option>
<option value='unbreak_tclcompiler'>unbreak_tclcompiler</option>
<option value='unknown_rewrite'>unknown_rewrite</option>
<option value='unproven'>unproven</option>
<option value='unsetThreadData'>unsetThreadData</option>
<option value='unwanted'>unwanted</option>
<option value='updateextended'>updateextended</option>
<option value='vc_reform'>vc_reform</option>
<option value='vs_ide_compile'>vs_ide_compile</option>
<option value='werner_utf_max_6'>werner_utf_max_6</option>
<option value='win32_arm'>win32_arm</option>
<option value='winFixes'>winFixes</option>
<option value='win_console_panic'>win_console_panic</option>
<option value='win_sock_async_connect_race_fix'>win_sock_async_connect_race_fix</option>
<option value='z_modifier'>z_modifier</option>
<option value='zipfs'>zipfs</option>
<option value='zippy_fifo'>zippy_fifo</option>
<option value='zlib_1_2_6'>zlib_1_2_6</option>
</select> <input type='submit' name='' value='switch'/></form></td></tr>
<tr><td class='sub'>Tcl is a high-level, general-purpose, interpreted, dynamic programming language. It was designed with the goal of being very simple but powerful.</td><td class='sub right'></td></tr></table>
<table class='tabs'><tr><td>
<a href='/oss-git/tcl.git/?h=bug_3173086'>summary</a><a href='/oss-git/tcl.git/refs/?h=bug_3173086&amp;id=85cce0b8cf9c49a685815514b160d47503d3c78a'>refs</a><a class='active' href='/oss-git/tcl.git/log/library/msgcat/msgcat.tcl?h=bug_3173086'>log</a><a href='/oss-git/tcl.git/tree/library/msgcat/msgcat.tcl?h=bug_3173086&amp;id=85cce0b8cf9c49a685815514b160d47503d3c78a'>tree</a><a href='/oss-git/tcl.git/commit/library/msgcat/msgcat.tcl?h=bug_3173086&amp;id=85cce0b8cf9c49a685815514b160d47503d3c78a'>commit</a><a href='/oss-git/tcl.git/diff/library/msgcat/msgcat.tcl?h=bug_3173086&amp;id=85cce0b8cf9c49a685815514b160d47503d3c78a'>diff</a><a href='/oss-git/tcl.git/stats/library/msgcat/msgcat.tcl?h=bug_3173086'>stats</a></td><td class='form'><form class='right' method='get' action='/oss-git/tcl.git/log/library/msgcat/msgcat.tcl'>
<input type='hidden' name='h' value='bug_3173086'/><input type='hidden' name='id' value='85cce0b8cf9c49a685815514b160d47503d3c78a'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='text' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/oss-git/tcl.git/log/?h=bug_3173086&amp;id=85cce0b8cf9c49a685815514b160d47503d3c78a'>root</a>/<a href='/oss-git/tcl.git/log/library?h=bug_3173086&amp;id=85cce0b8cf9c49a685815514b160d47503d3c78a'>library</a>/<a href='/oss-git/tcl.git/log/library/msgcat?h=bug_3173086&amp;id=85cce0b8cf9c49a685815514b160d47503d3c78a'>msgcat</a>/<a href='/oss-git/tcl.git/log/library/msgcat/msgcat.tcl?h=bug_3173086&amp;id=85cce0b8cf9c49a685815514b160d47503d3c78a'>msgcat.tcl</a></div><div class='content'><table class='list nowrap'><tr class='nohover'><th></th><th class='left'>Commit message (<a href='/oss-git/tcl.git/log/library/msgcat/msgcat.tcl?h=bug_3173086&amp;id=85cce0b8cf9c49a685815514b160d47503d3c78a&amp;showmsg=1'>Expand</a>)</th><th class='left'>Author</th><th class='left'>Age</th><th class='left'>Files</th><th class='left'>Lines</th></tr>
<tr><td class='commitgraph'>* </td><td><a href='/oss-git/tcl.git/commit/library/msgcat/msgcat.tcl?h=bug_3173086&amp;id=d768d45269fd4e4b6012d73d8c27390cd81c84df'>        * README:               Bumped version number to 8.4b3 to distinguish</a><span class='decoration'></span></td><td>dgp</td><td><span title='2002-08-20 15:33:31 (GMT)'>2002-08-20</span></td><td>1</td><td>-1/+3</td></tr>
<tr class='nohover'><td class='commitgraph'></td>
<td colspan='5'>
</td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/oss-git/tcl.git/commit/library/msgcat/msgcat.tcl?h=bug_3173086&amp;id=5625494c13f92f83294785e3691a89450f40c21a'>Fix a comment that was causing problems for programs (like "mktclapp") that</a><span class='decoration'></span></td><td>drh</td><td><span title='2002-07-17 19:14:47 (GMT)'>2002-07-17</span></td><td>1</td><td>-3/+3</td></tr>
<tr class='nohover'><td class='commitgraph'></td>
<td colspan='5'>
</td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/oss-git/tcl.git/commit/library/msgcat/msgcat.tcl?h=bug_3173086&amp;id=9fa2f8f1252330a70ca8318913affa140208c4db'>	* More Windows Registry locale codes from Bruno Haible.</a><span class='decoration'></span></td><td>dgp</td><td><span title='2002-06-17 16:37:11 (GMT)'>2002-06-17</span></td><td>1</td><td>-15/+127</td></tr>
<tr class='nohover'><td class='commitgraph'></td>
<td colspan='5'>
</td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/oss-git/tcl.git/commit/library/msgcat/msgcat.tcl?h=bug_3173086&amp;id=7a43bd40e805191b59ac6cd750192c6a105e36a7'>	*  Revised locale initialization to interpret</a><span class='decoration'></span></td><td>dgp</td><td><span title='2002-06-17 05:37:39 (GMT)'>2002-06-17</span></td><td>1</td><td>-80/+111</td></tr>
<tr class='nohover'><td class='commitgraph'></td>
<td colspan='5'>
</td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/oss-git/tcl.git/commit/library/msgcat/msgcat.tcl?h=bug_3173086&amp;id=715d8ed46f9b0792841536a10be48c362dddbc05'>	* [mcmax] wasn't using the caller's</a><span class='decoration'></span></td><td>dgp</td><td><span title='2002-04-20 00:35:19 (GMT)'>2002-04-20</span></td><td>1</td><td>-21/+29</td></tr>
<tr class='nohover'><td class='commitgraph'></td>
<td colspan='5'>
</td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/oss-git/tcl.git/commit/library/msgcat/msgcat.tcl?h=bug_3173086&amp;id=2bdca9dfc1dd3565672960643e6e860330bd10fe'>	* Added [mcload] to the export list</a><span class='decoration'></span></td><td>dgp</td><td><span title='2002-04-19 23:09:37 (GMT)'>2002-04-19</span></td><td>1</td><td>-3/+4</td></tr>
<tr class='nohover'><td class='commitgraph'></td>
<td colspan='5'>
</td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/oss-git/tcl.git/commit/library/msgcat/msgcat.tcl?h=bug_3173086&amp;id=d7c342a4ee3392e4a7f62257ef6906bc1c1a3d2f'>	Added checks for package dependencies.</a><span class='decoration'></span></td><td>dgp</td><td><span title='2001-08-09 01:06:42 (GMT)'>2001-08-09</span></td><td>1</td><td>-2/+3</td></tr>
<tr class='nohover'><td class='commitgraph'></td>
<td colspan='5'>
</td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/oss-git/tcl.git/commit/library/msgcat/msgcat.tcl?h=bug_3173086&amp;id=ab4eb3fe6a6e7f494057f9bc9af0c1a4489c5f88'>2000-12-10  Don Porter  &lt;dgp@users.sourceforge.net&gt;</a><span class='decoration'></span></td><td>dgp</td><td><span title='2000-12-11 04:17:38 (GMT)'>2000-12-11</span></td><td>1</td><td>-7/+7</td></tr>
<tr class='nohover'><td class='commitgraph'></td>
<td colspan='5'>
</td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/oss-git/tcl.git/commit/library/msgcat/msgcat.tcl?h=bug_3173086&amp;id=3ba754a2fb35b2f855e2139b0c83e56ff06af171'>* library/msgcat1.0/pkgIndex.tcl: Bumped version number to 1.2</a><span class='decoration'></span></td><td>ericm</td><td><span title='2000-08-11 00:45:31 (GMT)'>2000-08-11</span></td><td>1</td><td>-2/+2</td></tr>
<tr class='nohover'><td class='commitgraph'></td>
<td colspan='5'>
</td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/oss-git/tcl.git/commit/library/msgcat/msgcat.tcl?h=bug_3173086&amp;id=1cc4bea039b454657e105682aff5a00001eb29ab'>* library/msgcat1.0/msgcat.tcl: Removed erroneous [package forget]</a><span class='decoration'></span></td><td>ericm</td><td><span title='2000-08-10 22:24:53 (GMT)'>2000-08-10</span></td><td>1</td><td>-2/+1</td></tr>
<tr class='nohover'><td class='commitgraph'></td>
<td colspan='5'>
</td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/oss-git/tcl.git/commit/library/msgcat/msgcat.tcl?h=bug_3173086&amp;id=e58ac604378b855c137c05576fd796df952cb349'>* library/msgcat1.0/msgcat.tcl:</a><span class='decoration'></span></td><td>ericm</td><td><span title='2000-07-17 22:25:25 (GMT)'>2000-07-17</span></td><td>1</td><td>-4/+84</td></tr>
<tr class='nohover'><td class='commitgraph'></td>
<td colspan='5'>
</td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/oss-git/tcl.git/commit/library/msgcat/msgcat.tcl?h=bug_3173086&amp;id=003f25f16aa9d093b468f4c74a1eece63c929c88'>* tests/msgcat.test:</a><span class='decoration'></span></td><td>ericm</td><td><span title='2000-07-06 21:05:01 (GMT)'>2000-07-06</span></td><td>1</td><td>-4/+11</td></tr>
<tr class='nohover'><td class='commitgraph'></td>
<td colspan='5'>
</td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/oss-git/tcl.git/commit/library/msgcat/msgcat.tcl?h=bug_3173086&amp;id=be8ba4515aaf9da7893bcb0930ca1965e0602cb3'>* doc/msgcat.n: Doc's for mcmax function.</a><span class='decoration'></span></td><td>ericm</td><td><span title='2000-06-30 06:28:26 (GMT)'>2000-06-30</span></td><td>1</td><td>-4/+26</td></tr>
<tr class='nohover'><td class='commitgraph'></td>
<td colspan='5'>
</td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/oss-git/tcl.git/commit/library/msgcat/msgcat.tcl?h=bug_3173086&amp;id=6778b65f1b617527d2402c8b78b3419fb2a7c502'>* msgcat.n: Added docs for new behavior from patch in [Bug: 4158].</a><span class='decoration'></span></td><td>ericm</td><td><span title='2000-04-11 21:16:17 (GMT)'>2000-04-11</span></td><td>1</td><td>-7/+25</td></tr>
<tr class='nohover'><td class='commitgraph'></td>
<td colspan='5'>
</td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/oss-git/tcl.git/commit/library/msgcat/msgcat.tcl?h=bug_3173086&amp;id=827f1718a3c6ad6738473fca1d9ca562ece38f91'>1999-08-18  Jeff Hobbs  &lt;hobbs@scriptics.com&gt;</a><span class='decoration'></span></td><td>hobbs</td><td><span title='1999-08-19 02:59:40 (GMT)'>1999-08-19</span></td><td>1</td><td>-4/+3</td></tr>
<tr class='nohover'><td class='commitgraph'></td>
<td colspan='5'>
</td></tr>
<tr><td class='commitgraph'>* </td><td><a href='/oss-git/tcl.git/commit/library/msgcat/msgcat.tcl?h=bug_3173086&amp;id=97464e6cba8eb0008cf2727c15718671992b913f'>merged tcl 8.1 branch back into the main trunk</a><span class='decoration'></span></td><td>stanton</td><td><span title='1999-04-16 00:46:29 (GMT)'>1999-04-16</span></td><td>1</td><td>-0/+177</td></tr>
<tr class='nohover'><td class='commitgraph'></td>
<td colspan='5'>
</td></tr>
</table><ul class='pager'></ul></div> <!-- class=content -->
<div class='footer'>generated by <a href='http://git.zx2c4.com/cgit/about/'>cgit v0.12</a> at 2024-11-05 11:25:54 (GMT)</div>
</div> <!-- id=cgit -->
</body>
</html>
<a id='n230' href='#n230'>230</a>
<a id='n231' href='#n231'>231</a>
<a id='n232' href='#n232'>232</a>
<a id='n233' href='#n233'>233</a>
<a id='n234' href='#n234'>234</a>
<a id='n235' href='#n235'>235</a>
<a id='n236' href='#n236'>236</a>
<a id='n237' href='#n237'>237</a>
<a id='n238' href='#n238'>238</a>
<a id='n239' href='#n239'>239</a>
<a id='n240' href='#n240'>240</a>
<a id='n241' href='#n241'>241</a>
<a id='n242' href='#n242'>242</a>
<a id='n243' href='#n243'>243</a>
<a id='n244' href='#n244'>244</a>
<a id='n245' href='#n245'>245</a>
<a id='n246' href='#n246'>246</a>
<a id='n247' href='#n247'>247</a>
<a id='n248' href='#n248'>248</a>
<a id='n249' href='#n249'>249</a>
<a id='n250' href='#n250'>250</a>
<a id='n251' href='#n251'>251</a>
<a id='n252' href='#n252'>252</a>
<a id='n253' href='#n253'>253</a>
<a id='n254' href='#n254'>254</a>
<a id='n255' href='#n255'>255</a>
<a id='n256' href='#n256'>256</a>
<a id='n257' href='#n257'>257</a>
<a id='n258' href='#n258'>258</a>
<a id='n259' href='#n259'>259</a>
<a id='n260' href='#n260'>260</a>
<a id='n261' href='#n261'>261</a>
<a id='n262' href='#n262'>262</a>
<a id='n263' href='#n263'>263</a>
<a id='n264' href='#n264'>264</a>
<a id='n265' href='#n265'>265</a>
<a id='n266' href='#n266'>266</a>
<a id='n267' href='#n267'>267</a>
<a id='n268' href='#n268'>268</a>
<a id='n269' href='#n269'>269</a>
<a id='n270' href='#n270'>270</a>
<a id='n271' href='#n271'>271</a>
<a id='n272' href='#n272'>272</a>
<a id='n273' href='#n273'>273</a>
<a id='n274' href='#n274'>274</a>
<a id='n275' href='#n275'>275</a>
<a id='n276' href='#n276'>276</a>
<a id='n277' href='#n277'>277</a>
<a id='n278' href='#n278'>278</a>
<a id='n279' href='#n279'>279</a>
<a id='n280' href='#n280'>280</a>
<a id='n281' href='#n281'>281</a>
<a id='n282' href='#n282'>282</a>
<a id='n283' href='#n283'>283</a>
<a id='n284' href='#n284'>284</a>
<a id='n285' href='#n285'>285</a>
<a id='n286' href='#n286'>286</a>
<a id='n287' href='#n287'>287</a>
<a id='n288' href='#n288'>288</a>
<a id='n289' href='#n289'>289</a>
<a id='n290' href='#n290'>290</a>
<a id='n291' href='#n291'>291</a>
<a id='n292' href='#n292'>292</a>
<a id='n293' href='#n293'>293</a>
<a id='n294' href='#n294'>294</a>
<a id='n295' href='#n295'>295</a>
<a id='n296' href='#n296'>296</a>
<a id='n297' href='#n297'>297</a>
<a id='n298' href='#n298'>298</a>
<a id='n299' href='#n299'>299</a>
<a id='n300' href='#n300'>300</a>
<a id='n301' href='#n301'>301</a>
<a id='n302' href='#n302'>302</a>
<a id='n303' href='#n303'>303</a>
<a id='n304' href='#n304'>304</a>
<a id='n305' href='#n305'>305</a>
<a id='n306' href='#n306'>306</a>
<a id='n307' href='#n307'>307</a>
<a id='n308' href='#n308'>308</a>
<a id='n309' href='#n309'>309</a>
<a id='n310' href='#n310'>310</a>
<a id='n311' href='#n311'>311</a>
<a id='n312' href='#n312'>312</a>
<a id='n313' href='#n313'>313</a>
<a id='n314' href='#n314'>314</a>
<a id='n315' href='#n315'>315</a>
<a id='n316' href='#n316'>316</a>
<a id='n317' href='#n317'>317</a>
<a id='n318' href='#n318'>318</a>
<a id='n319' href='#n319'>319</a>
<a id='n320' href='#n320'>320</a>
<a id='n321' href='#n321'>321</a>
<a id='n322' href='#n322'>322</a>
<a id='n323' href='#n323'>323</a>
<a id='n324' href='#n324'>324</a>
<a id='n325' href='#n325'>325</a>
<a id='n326' href='#n326'>326</a>
<a id='n327' href='#n327'>327</a>
<a id='n328' href='#n328'>328</a>
<a id='n329' href='#n329'>329</a>
<a id='n330' href='#n330'>330</a>
<a id='n331' href='#n331'>331</a>
<a id='n332' href='#n332'>332</a>
<a id='n333' href='#n333'>333</a>
<a id='n334' href='#n334'>334</a>
<a id='n335' href='#n335'>335</a>
<a id='n336' href='#n336'>336</a>
<a id='n337' href='#n337'>337</a>
<a id='n338' href='#n338'>338</a>
<a id='n339' href='#n339'>339</a>
<a id='n340' href='#n340'>340</a>
<a id='n341' href='#n341'>341</a>
<a id='n342' href='#n342'>342</a>
<a id='n343' href='#n343'>343</a>
<a id='n344' href='#n344'>344</a>
<a id='n345' href='#n345'>345</a>
<a id='n346' href='#n346'>346</a>
<a id='n347' href='#n347'>347</a>
<a id='n348' href='#n348'>348</a>
<a id='n349' href='#n349'>349</a>
<a id='n350' href='#n350'>350</a>
<a id='n351' href='#n351'>351</a>
<a id='n352' href='#n352'>352</a>
<a id='n353' href='#n353'>353</a>
<a id='n354' href='#n354'>354</a>
<a id='n355' href='#n355'>355</a>
<a id='n356' href='#n356'>356</a>
<a id='n357' href='#n357'>357</a>
<a id='n358' href='#n358'>358</a>
<a id='n359' href='#n359'>359</a>
<a id='n360' href='#n360'>360</a>
<a id='n361' href='#n361'>361</a>
<a id='n362' href='#n362'>362</a>
<a id='n363' href='#n363'>363</a>
<a id='n364' href='#n364'>364</a>
<a id='n365' href='#n365'>365</a>
<a id='n366' href='#n366'>366</a>
<a id='n367' href='#n367'>367</a>
<a id='n368' href='#n368'>368</a>
<a id='n369' href='#n369'>369</a>
<a id='n370' href='#n370'>370</a>
<a id='n371' href='#n371'>371</a>
<a id='n372' href='#n372'>372</a>
<a id='n373' href='#n373'>373</a>
<a id='n374' href='#n374'>374</a>
<a id='n375' href='#n375'>375</a>
<a id='n376' href='#n376'>376</a>
<a id='n377' href='#n377'>377</a>
<a id='n378' href='#n378'>378</a>
<a id='n379' href='#n379'>379</a>
<a id='n380' href='#n380'>380</a>
<a id='n381' href='#n381'>381</a>
<a id='n382' href='#n382'>382</a>
<a id='n383' href='#n383'>383</a>
<a id='n384' href='#n384'>384</a>
<a id='n385' href='#n385'>385</a>
<a id='n386' href='#n386'>386</a>
<a id='n387' href='#n387'>387</a>
<a id='n388' href='#n388'>388</a>
<a id='n389' href='#n389'>389</a>
<a id='n390' href='#n390'>390</a>
<a id='n391' href='#n391'>391</a>
<a id='n392' href='#n392'>392</a>
<a id='n393' href='#n393'>393</a>
<a id='n394' href='#n394'>394</a>
<a id='n395' href='#n395'>395</a>
<a id='n396' href='#n396'>396</a>
<a id='n397' href='#n397'>397</a>
<a id='n398' href='#n398'>398</a>
<a id='n399' href='#n399'>399</a>
<a id='n400' href='#n400'>400</a>
<a id='n401' href='#n401'>401</a>
<a id='n402' href='#n402'>402</a>
<a id='n403' href='#n403'>403</a>
<a id='n404' href='#n404'>404</a>
<a id='n405' href='#n405'>405</a>
<a id='n406' href='#n406'>406</a>
<a id='n407' href='#n407'>407</a>
<a id='n408' href='#n408'>408</a>
<a id='n409' href='#n409'>409</a>
<a id='n410' href='#n410'>410</a>
<a id='n411' href='#n411'>411</a>
<a id='n412' href='#n412'>412</a>
<a id='n413' href='#n413'>413</a>
<a id='n414' href='#n414'>414</a>
<a id='n415' href='#n415'>415</a>
<a id='n416' href='#n416'>416</a>
<a id='n417' href='#n417'>417</a>
<a id='n418' href='#n418'>418</a>
<a id='n419' href='#n419'>419</a>
<a id='n420' href='#n420'>420</a>
<a id='n421' href='#n421'>421</a>
<a id='n422' href='#n422'>422</a>
<a id='n423' href='#n423'>423</a>
<a id='n424' href='#n424'>424</a>
<a id='n425' href='#n425'>425</a>
<a id='n426' href='#n426'>426</a>
<a id='n427' href='#n427'>427</a>
<a id='n428' href='#n428'>428</a>
<a id='n429' href='#n429'>429</a>
<a id='n430' href='#n430'>430</a>
<a id='n431' href='#n431'>431</a>
<a id='n432' href='#n432'>432</a>
<a id='n433' href='#n433'>433</a>
<a id='n434' href='#n434'>434</a>
<a id='n435' href='#n435'>435</a>
<a id='n436' href='#n436'>436</a>
<a id='n437' href='#n437'>437</a>
<a id='n438' href='#n438'>438</a>
<a id='n439' href='#n439'>439</a>
<a id='n440' href='#n440'>440</a>
<a id='n441' href='#n441'>441</a>
<a id='n442' href='#n442'>442</a>
<a id='n443' href='#n443'>443</a>
<a id='n444' href='#n444'>444</a>
<a id='n445' href='#n445'>445</a>
<a id='n446' href='#n446'>446</a>
<a id='n447' href='#n447'>447</a>
<a id='n448' href='#n448'>448</a>
<a id='n449' href='#n449'>449</a>
<a id='n450' href='#n450'>450</a>
<a id='n451' href='#n451'>451</a>
<a id='n452' href='#n452'>452</a>
<a id='n453' href='#n453'>453</a>
<a id='n454' href='#n454'>454</a>
<a id='n455' href='#n455'>455</a>
<a id='n456' href='#n456'>456</a>
<a id='n457' href='#n457'>457</a>
<a id='n458' href='#n458'>458</a>
<a id='n459' href='#n459'>459</a>
<a id='n460' href='#n460'>460</a>
<a id='n461' href='#n461'>461</a>
<a id='n462' href='#n462'>462</a>
<a id='n463' href='#n463'>463</a>
<a id='n464' href='#n464'>464</a>
<a id='n465' href='#n465'>465</a>
<a id='n466' href='#n466'>466</a>
<a id='n467' href='#n467'>467</a>
<a id='n468' href='#n468'>468</a>
<a id='n469' href='#n469'>469</a>
<a id='n470' href='#n470'>470</a>
<a id='n471' href='#n471'>471</a>
<a id='n472' href='#n472'>472</a>
<a id='n473' href='#n473'>473</a>
<a id='n474' href='#n474'>474</a>
<a id='n475' href='#n475'>475</a>
<a id='n476' href='#n476'>476</a>
<a id='n477' href='#n477'>477</a>
<a id='n478' href='#n478'>478</a>
<a id='n479' href='#n479'>479</a>
<a id='n480' href='#n480'>480</a>
<a id='n481' href='#n481'>481</a>
<a id='n482' href='#n482'>482</a>
<a id='n483' href='#n483'>483</a>
<a id='n484' href='#n484'>484</a>
<a id='n485' href='#n485'>485</a>
<a id='n486' href='#n486'>486</a>
<a id='n487' href='#n487'>487</a>
<a id='n488' href='#n488'>488</a>
<a id='n489' href='#n489'>489</a>
<a id='n490' href='#n490'>490</a>
<a id='n491' href='#n491'>491</a>
<a id='n492' href='#n492'>492</a>
<a id='n493' href='#n493'>493</a>
<a id='n494' href='#n494'>494</a>
<a id='n495' href='#n495'>495</a>
<a id='n496' href='#n496'>496</a>
<a id='n497' href='#n497'>497</a>
<a id='n498' href='#n498'>498</a>
<a id='n499' href='#n499'>499</a>
<a id='n500' href='#n500'>500</a>
<a id='n501' href='#n501'>501</a>
<a id='n502' href='#n502'>502</a>
<a id='n503' href='#n503'>503</a>
<a id='n504' href='#n504'>504</a>
<a id='n505' href='#n505'>505</a>
<a id='n506' href='#n506'>506</a>
<a id='n507' href='#n507'>507</a>
<a id='n508' href='#n508'>508</a>
<a id='n509' href='#n509'>509</a>
<a id='n510' href='#n510'>510</a>
<a id='n511' href='#n511'>511</a>
<a id='n512' href='#n512'>512</a>
<a id='n513' href='#n513'>513</a>
<a id='n514' href='#n514'>514</a>
<a id='n515' href='#n515'>515</a>
<a id='n516' href='#n516'>516</a>
<a id='n517' href='#n517'>517</a>
<a id='n518' href='#n518'>518</a>
<a id='n519' href='#n519'>519</a>
<a id='n520' href='#n520'>520</a>
<a id='n521' href='#n521'>521</a>
<a id='n522' href='#n522'>522</a>
<a id='n523' href='#n523'>523</a>
<a id='n524' href='#n524'>524</a>
<a id='n525' href='#n525'>525</a>
<a id='n526' href='#n526'>526</a>
<a id='n527' href='#n527'>527</a>
<a id='n528' href='#n528'>528</a>
<a id='n529' href='#n529'>529</a>
<a id='n530' href='#n530'>530</a>
<a id='n531' href='#n531'>531</a>
<a id='n532' href='#n532'>532</a>
<a id='n533' href='#n533'>533</a>
<a id='n534' href='#n534'>534</a>
<a id='n535' href='#n535'>535</a>
<a id='n536' href='#n536'>536</a>
<a id='n537' href='#n537'>537</a>
<a id='n538' href='#n538'>538</a>
<a id='n539' href='#n539'>539</a>
<a id='n540' href='#n540'>540</a>
<a id='n541' href='#n541'>541</a>
<a id='n542' href='#n542'>542</a>
<a id='n543' href='#n543'>543</a>
<a id='n544' href='#n544'>544</a>
<a id='n545' href='#n545'>545</a>
<a id='n546' href='#n546'>546</a>
<a id='n547' href='#n547'>547</a>
<a id='n548' href='#n548'>548</a>
<a id='n549' href='#n549'>549</a>
<a id='n550' href='#n550'>550</a>
<a id='n551' href='#n551'>551</a>
<a id='n552' href='#n552'>552</a>
<a id='n553' href='#n553'>553</a>
<a id='n554' href='#n554'>554</a>
<a id='n555' href='#n555'>555</a>
<a id='n556' href='#n556'>556</a>
<a id='n557' href='#n557'>557</a>
<a id='n558' href='#n558'>558</a>
<a id='n559' href='#n559'>559</a>
<a id='n560' href='#n560'>560</a>
<a id='n561' href='#n561'>561</a>
<a id='n562' href='#n562'>562</a>
<a id='n563' href='#n563'>563</a>
<a id='n564' href='#n564'>564</a>
<a id='n565' href='#n565'>565</a>
<a id='n566' href='#n566'>566</a>
<a id='n567' href='#n567'>567</a>
<a id='n568' href='#n568'>568</a>
<a id='n569' href='#n569'>569</a>
<a id='n570' href='#n570'>570</a>
<a id='n571' href='#n571'>571</a>
<a id='n572' href='#n572'>572</a>
<a id='n573' href='#n573'>573</a>
<a id='n574' href='#n574'>574</a>
<a id='n575' href='#n575'>575</a>
<a id='n576' href='#n576'>576</a>
<a id='n577' href='#n577'>577</a>
<a id='n578' href='#n578'>578</a>
<a id='n579' href='#n579'>579</a>
<a id='n580' href='#n580'>580</a>
<a id='n581' href='#n581'>581</a>
<a id='n582' href='#n582'>582</a>
<a id='n583' href='#n583'>583</a>
<a id='n584' href='#n584'>584</a>
<a id='n585' href='#n585'>585</a>
<a id='n586' href='#n586'>586</a>
<a id='n587' href='#n587'>587</a>
<a id='n588' href='#n588'>588</a>
<a id='n589' href='#n589'>589</a>
<a id='n590' href='#n590'>590</a>
<a id='n591' href='#n591'>591</a>
<a id='n592' href='#n592'>592</a>
<a id='n593' href='#n593'>593</a>
<a id='n594' href='#n594'>594</a>
<a id='n595' href='#n595'>595</a>
<a id='n596' href='#n596'>596</a>
<a id='n597' href='#n597'>597</a>
<a id='n598' href='#n598'>598</a>
<a id='n599' href='#n599'>599</a>
<a id='n600' href='#n600'>600</a>
<a id='n601' href='#n601'>601</a>
<a id='n602' href='#n602'>602</a>
<a id='n603' href='#n603'>603</a>
<a id='n604' href='#n604'>604</a>
<a id='n605' href='#n605'>605</a>
<a id='n606' href='#n606'>606</a>
<a id='n607' href='#n607'>607</a>
<a id='n608' href='#n608'>608</a>
<a id='n609' href='#n609'>609</a>
<a id='n610' href='#n610'>610</a>
<a id='n611' href='#n611'>611</a>
<a id='n612' href='#n612'>612</a>
<a id='n613' href='#n613'>613</a>
<a id='n614' href='#n614'>614</a>
<a id='n615' href='#n615'>615</a>
<a id='n616' href='#n616'>616</a>
<a id='n617' href='#n617'>617</a>
<a id='n618' href='#n618'>618</a>
<a id='n619' href='#n619'>619</a>
<a id='n620' href='#n620'>620</a>
<a id='n621' href='#n621'>621</a>
<a id='n622' href='#n622'>622</a>
<a id='n623' href='#n623'>623</a>
<a id='n624' href='#n624'>624</a>
<a id='n625' href='#n625'>625</a>
<a id='n626' href='#n626'>626</a>
<a id='n627' href='#n627'>627</a>
<a id='n628' href='#n628'>628</a>
<a id='n629' href='#n629'>629</a>
<a id='n630' href='#n630'>630</a>
<a id='n631' href='#n631'>631</a>
<a id='n632' href='#n632'>632</a>
<a id='n633' href='#n633'>633</a>
<a id='n634' href='#n634'>634</a>
<a id='n635' href='#n635'>635</a>
<a id='n636' href='#n636'>636</a>
<a id='n637' href='#n637'>637</a>
<a id='n638' href='#n638'>638</a>
<a id='n639' href='#n639'>639</a>
<a id='n640' href='#n640'>640</a>
<a id='n641' href='#n641'>641</a>
<a id='n642' href='#n642'>642</a>
<a id='n643' href='#n643'>643</a>
<a id='n644' href='#n644'>644</a>
<a id='n645' href='#n645'>645</a>
<a id='n646' href='#n646'>646</a>
<a id='n647' href='#n647'>647</a>
<a id='n648' href='#n648'>648</a>
<a id='n649' href='#n649'>649</a>
<a id='n650' href='#n650'>650</a>
<a id='n651' href='#n651'>651</a>
<a id='n652' href='#n652'>652</a>
<a id='n653' href='#n653'>653</a>
<a id='n654' href='#n654'>654</a>
<a id='n655' href='#n655'>655</a>
<a id='n656' href='#n656'>656</a>
<a id='n657' href='#n657'>657</a>
<a id='n658' href='#n658'>658</a>
<a id='n659' href='#n659'>659</a>
<a id='n660' href='#n660'>660</a>
<a id='n661' href='#n661'>661</a>
<a id='n662' href='#n662'>662</a>
<a id='n663' href='#n663'>663</a>
<a id='n664' href='#n664'>664</a>
<a id='n665' href='#n665'>665</a>
<a id='n666' href='#n666'>666</a>
<a id='n667' href='#n667'>667</a>
<a id='n668' href='#n668'>668</a>
<a id='n669' href='#n669'>669</a>
<a id='n670' href='#n670'>670</a>
<a id='n671' href='#n671'>671</a>
<a id='n672' href='#n672'>672</a>
<a id='n673' href='#n673'>673</a>
<a id='n674' href='#n674'>674</a>
<a id='n675' href='#n675'>675</a>
<a id='n676' href='#n676'>676</a>
<a id='n677' href='#n677'>677</a>
<a id='n678' href='#n678'>678</a>
<a id='n679' href='#n679'>679</a>
<a id='n680' href='#n680'>680</a>
<a id='n681' href='#n681'>681</a>
<a id='n682' href='#n682'>682</a>
<a id='n683' href='#n683'>683</a>
<a id='n684' href='#n684'>684</a>
<a id='n685' href='#n685'>685</a>
<a id='n686' href='#n686'>686</a>
<a id='n687' href='#n687'>687</a>
<a id='n688' href='#n688'>688</a>
<a id='n689' href='#n689'>689</a>
<a id='n690' href='#n690'>690</a>
<a id='n691' href='#n691'>691</a>
<a id='n692' href='#n692'>692</a>
<a id='n693' href='#n693'>693</a>
<a id='n694' href='#n694'>694</a>
<a id='n695' href='#n695'>695</a>
<a id='n696' href='#n696'>696</a>
<a id='n697' href='#n697'>697</a>
<a id='n698' href='#n698'>698</a>
<a id='n699' href='#n699'>699</a>
<a id='n700' href='#n700'>700</a>
<a id='n701' href='#n701'>701</a>
<a id='n702' href='#n702'>702</a>
<a id='n703' href='#n703'>703</a>
<a id='n704' href='#n704'>704</a>
<a id='n705' href='#n705'>705</a>
<a id='n706' href='#n706'>706</a>
<a id='n707' href='#n707'>707</a>
<a id='n708' href='#n708'>708</a>
<a id='n709' href='#n709'>709</a>
<a id='n710' href='#n710'>710</a>
<a id='n711' href='#n711'>711</a>
<a id='n712' href='#n712'>712</a>
<a id='n713' href='#n713'>713</a>
<a id='n714' href='#n714'>714</a>
<a id='n715' href='#n715'>715</a>
<a id='n716' href='#n716'>716</a>
<a id='n717' href='#n717'>717</a>
<a id='n718' href='#n718'>718</a>
<a id='n719' href='#n719'>719</a>
<a id='n720' href='#n720'>720</a>
<a id='n721' href='#n721'>721</a>
<a id='n722' href='#n722'>722</a>
<a id='n723' href='#n723'>723</a>
<a id='n724' href='#n724'>724</a>
<a id='n725' href='#n725'>725</a>
<a id='n726' href='#n726'>726</a>
<a id='n727' href='#n727'>727</a>
<a id='n728' href='#n728'>728</a>
<a id='n729' href='#n729'>729</a>
<a id='n730' href='#n730'>730</a>
<a id='n731' href='#n731'>731</a>
<a id='n732' href='#n732'>732</a>
<a id='n733' href='#n733'>733</a>
<a id='n734' href='#n734'>734</a>
<a id='n735' href='#n735'>735</a>
<a id='n736' href='#n736'>736</a>
<a id='n737' href='#n737'>737</a>
<a id='n738' href='#n738'>738</a>
<a id='n739' href='#n739'>739</a>
<a id='n740' href='#n740'>740</a>
<a id='n741' href='#n741'>741</a>
<a id='n742' href='#n742'>742</a>
<a id='n743' href='#n743'>743</a>
<a id='n744' href='#n744'>744</a>
<a id='n745' href='#n745'>745</a>
<a id='n746' href='#n746'>746</a>
<a id='n747' href='#n747'>747</a>
<a id='n748' href='#n748'>748</a>
<a id='n749' href='#n749'>749</a>
<a id='n750' href='#n750'>750</a>
<a id='n751' href='#n751'>751</a>
<a id='n752' href='#n752'>752</a>
<a id='n753' href='#n753'>753</a>
<a id='n754' href='#n754'>754</a>
<a id='n755' href='#n755'>755</a>
<a id='n756' href='#n756'>756</a>
<a id='n757' href='#n757'>757</a>
<a id='n758' href='#n758'>758</a>
<a id='n759' href='#n759'>759</a>
<a id='n760' href='#n760'>760</a>
<a id='n761' href='#n761'>761</a>
<a id='n762' href='#n762'>762</a>
<a id='n763' href='#n763'>763</a>
<a id='n764' href='#n764'>764</a>
<a id='n765' href='#n765'>765</a>
<a id='n766' href='#n766'>766</a>
<a id='n767' href='#n767'>767</a>
<a id='n768' href='#n768'>768</a>
<a id='n769' href='#n769'>769</a>
<a id='n770' href='#n770'>770</a>
<a id='n771' href='#n771'>771</a>
<a id='n772' href='#n772'>772</a>
<a id='n773' href='#n773'>773</a>
<a id='n774' href='#n774'>774</a>
<a id='n775' href='#n775'>775</a>
<a id='n776' href='#n776'>776</a>
<a id='n777' href='#n777'>777</a>
<a id='n778' href='#n778'>778</a>
<a id='n779' href='#n779'>779</a>
<a id='n780' href='#n780'>780</a>
<a id='n781' href='#n781'>781</a>
<a id='n782' href='#n782'>782</a>
<a id='n783' href='#n783'>783</a>
<a id='n784' href='#n784'>784</a>
<a id='n785' href='#n785'>785</a>
<a id='n786' href='#n786'>786</a>
<a id='n787' href='#n787'>787</a>
<a id='n788' href='#n788'>788</a>
<a id='n789' href='#n789'>789</a>
<a id='n790' href='#n790'>790</a>
<a id='n791' href='#n791'>791</a>
<a id='n792' href='#n792'>792</a>
<a id='n793' href='#n793'>793</a>
<a id='n794' href='#n794'>794</a>
<a id='n795' href='#n795'>795</a>
<a id='n796' href='#n796'>796</a>
<a id='n797' href='#n797'>797</a>
<a id='n798' href='#n798'>798</a>
<a id='n799' href='#n799'>799</a>
<a id='n800' href='#n800'>800</a>
<a id='n801' href='#n801'>801</a>
<a id='n802' href='#n802'>802</a>
<a id='n803' href='#n803'>803</a>
<a id='n804' href='#n804'>804</a>
<a id='n805' href='#n805'>805</a>
<a id='n806' href='#n806'>806</a>
<a id='n807' href='#n807'>807</a>
<a id='n808' href='#n808'>808</a>
<a id='n809' href='#n809'>809</a>
<a id='n810' href='#n810'>810</a>
<a id='n811' href='#n811'>811</a>
<a id='n812' href='#n812'>812</a>
<a id='n813' href='#n813'>813</a>
<a id='n814' href='#n814'>814</a>
<a id='n815' href='#n815'>815</a>
<a id='n816' href='#n816'>816</a>
<a id='n817' href='#n817'>817</a>
<a id='n818' href='#n818'>818</a>
<a id='n819' href='#n819'>819</a>
<a id='n820' href='#n820'>820</a>
<a id='n821' href='#n821'>821</a>
<a id='n822' href='#n822'>822</a>
<a id='n823' href='#n823'>823</a>
<a id='n824' href='#n824'>824</a>
<a id='n825' href='#n825'>825</a>
<a id='n826' href='#n826'>826</a>
<a id='n827' href='#n827'>827</a>
<a id='n828' href='#n828'>828</a>
<a id='n829' href='#n829'>829</a>
<a id='n830' href='#n830'>830</a>
<a id='n831' href='#n831'>831</a>
<a id='n832' href='#n832'>832</a>
<a id='n833' href='#n833'>833</a>
<a id='n834' href='#n834'>834</a>
<a id='n835' href='#n835'>835</a>
<a id='n836' href='#n836'>836</a>
<a id='n837' href='#n837'>837</a>
<a id='n838' href='#n838'>838</a>
<a id='n839' href='#n839'>839</a>
<a id='n840' href='#n840'>840</a>
<a id='n841' href='#n841'>841</a>
<a id='n842' href='#n842'>842</a>
<a id='n843' href='#n843'>843</a>
<a id='n844' href='#n844'>844</a>
<a id='n845' href='#n845'>845</a>
<a id='n846' href='#n846'>846</a>
<a id='n847' href='#n847'>847</a>
<a id='n848' href='#n848'>848</a>
<a id='n849' href='#n849'>849</a>
<a id='n850' href='#n850'>850</a>
<a id='n851' href='#n851'>851</a>
<a id='n852' href='#n852'>852</a>
<a id='n853' href='#n853'>853</a>
<a id='n854' href='#n854'>854</a>
<a id='n855' href='#n855'>855</a>
<a id='n856' href='#n856'>856</a>
<a id='n857' href='#n857'>857</a>
<a id='n858' href='#n858'>858</a>
<a id='n859' href='#n859'>859</a>
<a id='n860' href='#n860'>860</a>
<a id='n861' href='#n861'>861</a>
<a id='n862' href='#n862'>862</a>
<a id='n863' href='#n863'>863</a>
<a id='n864' href='#n864'>864</a>
<a id='n865' href='#n865'>865</a>
<a id='n866' href='#n866'>866</a>
<a id='n867' href='#n867'>867</a>
<a id='n868' href='#n868'>868</a>
<a id='n869' href='#n869'>869</a>
<a id='n870' href='#n870'>870</a>
<a id='n871' href='#n871'>871</a>
<a id='n872' href='#n872'>872</a>
<a id='n873' href='#n873'>873</a>
<a id='n874' href='#n874'>874</a>
<a id='n875' href='#n875'>875</a>
<a id='n876' href='#n876'>876</a>
<a id='n877' href='#n877'>877</a>
<a id='n878' href='#n878'>878</a>
<a id='n879' href='#n879'>879</a>
<a id='n880' href='#n880'>880</a>
<a id='n881' href='#n881'>881</a>
<a id='n882' href='#n882'>882</a>
<a id='n883' href='#n883'>883</a>
<a id='n884' href='#n884'>884</a>
<a id='n885' href='#n885'>885</a>
<a id='n886' href='#n886'>886</a>
<a id='n887' href='#n887'>887</a>
<a id='n888' href='#n888'>888</a>
<a id='n889' href='#n889'>889</a>
<a id='n890' href='#n890'>890</a>
<a id='n891' href='#n891'>891</a>
<a id='n892' href='#n892'>892</a>
<a id='n893' href='#n893'>893</a>
<a id='n894' href='#n894'>894</a>
<a id='n895' href='#n895'>895</a>
<a id='n896' href='#n896'>896</a>
<a id='n897' href='#n897'>897</a>
<a id='n898' href='#n898'>898</a>
<a id='n899' href='#n899'>899</a>
<a id='n900' href='#n900'>900</a>
<a id='n901' href='#n901'>901</a>
<a id='n902' href='#n902'>902</a>
<a id='n903' href='#n903'>903</a>
<a id='n904' href='#n904'>904</a>
<a id='n905' href='#n905'>905</a>
<a id='n906' href='#n906'>906</a>
<a id='n907' href='#n907'>907</a>
<a id='n908' href='#n908'>908</a>
<a id='n909' href='#n909'>909</a>
<a id='n910' href='#n910'>910</a>
<a id='n911' href='#n911'>911</a>
<a id='n912' href='#n912'>912</a>
<a id='n913' href='#n913'>913</a>
<a id='n914' href='#n914'>914</a>
<a id='n915' href='#n915'>915</a>
<a id='n916' href='#n916'>916</a>
<a id='n917' href='#n917'>917</a>
<a id='n918' href='#n918'>918</a>
<a id='n919' href='#n919'>919</a>
<a id='n920' href='#n920'>920</a>
<a id='n921' href='#n921'>921</a>
<a id='n922' href='#n922'>922</a>
<a id='n923' href='#n923'>923</a>
<a id='n924' href='#n924'>924</a>
<a id='n925' href='#n925'>925</a>
<a id='n926' href='#n926'>926</a>
<a id='n927' href='#n927'>927</a>
<a id='n928' href='#n928'>928</a>
<a id='n929' href='#n929'>929</a>
<a id='n930' href='#n930'>930</a>
<a id='n931' href='#n931'>931</a>
<a id='n932' href='#n932'>932</a>
<a id='n933' href='#n933'>933</a>
<a id='n934' href='#n934'>934</a>
<a id='n935' href='#n935'>935</a>
<a id='n936' href='#n936'>936</a>
<a id='n937' href='#n937'>937</a>
<a id='n938' href='#n938'>938</a>
<a id='n939' href='#n939'>939</a>
<a id='n940' href='#n940'>940</a>
<a id='n941' href='#n941'>941</a>
<a id='n942' href='#n942'>942</a>
<a id='n943' href='#n943'>943</a>
<a id='n944' href='#n944'>944</a>
<a id='n945' href='#n945'>945</a>
<a id='n946' href='#n946'>946</a>
<a id='n947' href='#n947'>947</a>
<a id='n948' href='#n948'>948</a>
<a id='n949' href='#n949'>949</a>
<a id='n950' href='#n950'>950</a>
<a id='n951' href='#n951'>951</a>
<a id='n952' href='#n952'>952</a>
<a id='n953' href='#n953'>953</a>
<a id='n954' href='#n954'>954</a>
<a id='n955' href='#n955'>955</a>
<a id='n956' href='#n956'>956</a>
<a id='n957' href='#n957'>957</a>
<a id='n958' href='#n958'>958</a>
<a id='n959' href='#n959'>959</a>
<a id='n960' href='#n960'>960</a>
<a id='n961' href='#n961'>961</a>
<a id='n962' href='#n962'>962</a>
<a id='n963' href='#n963'>963</a>
<a id='n964' href='#n964'>964</a>
<a id='n965' href='#n965'>965</a>
<a id='n966' href='#n966'>966</a>
<a id='n967' href='#n967'>967</a>
<a id='n968' href='#n968'>968</a>
<a id='n969' href='#n969'>969</a>
<a id='n970' href='#n970'>970</a>
<a id='n971' href='#n971'>971</a>
<a id='n972' href='#n972'>972</a>
<a id='n973' href='#n973'>973</a>
<a id='n974' href='#n974'>974</a>
<a id='n975' href='#n975'>975</a>
<a id='n976' href='#n976'>976</a>
<a id='n977' href='#n977'>977</a>
<a id='n978' href='#n978'>978</a>
<a id='n979' href='#n979'>979</a>
<a id='n980' href='#n980'>980</a>
<a id='n981' href='#n981'>981</a>
<a id='n982' href='#n982'>982</a>
<a id='n983' href='#n983'>983</a>
<a id='n984' href='#n984'>984</a>
<a id='n985' href='#n985'>985</a>
<a id='n986' href='#n986'>986</a>
<a id='n987' href='#n987'>987</a>
<a id='n988' href='#n988'>988</a>
<a id='n989' href='#n989'>989</a>
<a id='n990' href='#n990'>990</a>
<a id='n991' href='#n991'>991</a>
<a id='n992' href='#n992'>992</a>
<a id='n993' href='#n993'>993</a>
<a id='n994' href='#n994'>994</a>
<a id='n995' href='#n995'>995</a>
<a id='n996' href='#n996'>996</a>
<a id='n997' href='#n997'>997</a>
<a id='n998' href='#n998'>998</a>
<a id='n999' href='#n999'>999</a>
<a id='n1000' href='#n1000'>1000</a>
<a id='n1001' href='#n1001'>1001</a>
<a id='n1002' href='#n1002'>1002</a>
<a id='n1003' href='#n1003'>1003</a>
<a id='n1004' href='#n1004'>1004</a>
<a id='n1005' href='#n1005'>1005</a>
<a id='n1006' href='#n1006'>1006</a>
<a id='n1007' href='#n1007'>1007</a>
<a id='n1008' href='#n1008'>1008</a>
<a id='n1009' href='#n1009'>1009</a>
<a id='n1010' href='#n1010'>1010</a>
<a id='n1011' href='#n1011'>1011</a>
<a id='n1012' href='#n1012'>1012</a>
<a id='n1013' href='#n1013'>1013</a>
<a id='n1014' href='#n1014'>1014</a>
<a id='n1015' href='#n1015'>1015</a>
<a id='n1016' href='#n1016'>1016</a>
<a id='n1017' href='#n1017'>1017</a>
<a id='n1018' href='#n1018'>1018</a>
<a id='n1019' href='#n1019'>1019</a>
<a id='n1020' href='#n1020'>1020</a>
<a id='n1021' href='#n1021'>1021</a>
<a id='n1022' href='#n1022'>1022</a>
<a id='n1023' href='#n1023'>1023</a>
<a id='n1024' href='#n1024'>1024</a>
<a id='n1025' href='#n1025'>1025</a>
<a id='n1026' href='#n1026'>1026</a>
<a id='n1027' href='#n1027'>1027</a>
<a id='n1028' href='#n1028'>1028</a>
<a id='n1029' href='#n1029'>1029</a>
<a id='n1030' href='#n1030'>1030</a>
<a id='n1031' href='#n1031'>1031</a>
<a id='n1032' href='#n1032'>1032</a>
<a id='n1033' href='#n1033'>1033</a>
<a id='n1034' href='#n1034'>1034</a>
<a id='n1035' href='#n1035'>1035</a>
<a id='n1036' href='#n1036'>1036</a>
<a id='n1037' href='#n1037'>1037</a>
<a id='n1038' href='#n1038'>1038</a>
<a id='n1039' href='#n1039'>1039</a>
<a id='n1040' href='#n1040'>1040</a>
<a id='n1041' href='#n1041'>1041</a>
<a id='n1042' href='#n1042'>1042</a>
<a id='n1043' href='#n1043'>1043</a>
<a id='n1044' href='#n1044'>1044</a>
<a id='n1045' href='#n1045'>1045</a>
<a id='n1046' href='#n1046'>1046</a>
<a id='n1047' href='#n1047'>1047</a>
<a id='n1048' href='#n1048'>1048</a>
<a id='n1049' href='#n1049'>1049</a>
<a id='n1050' href='#n1050'>1050</a>
<a id='n1051' href='#n1051'>1051</a>
<a id='n1052' href='#n1052'>1052</a>
<a id='n1053' href='#n1053'>1053</a>
<a id='n1054' href='#n1054'>1054</a>
<a id='n1055' href='#n1055'>1055</a>
<a id='n1056' href='#n1056'>1056</a>
<a id='n1057' href='#n1057'>1057</a>
<a id='n1058' href='#n1058'>1058</a>
<a id='n1059' href='#n1059'>1059</a>
<a id='n1060' href='#n1060'>1060</a>
<a id='n1061' href='#n1061'>1061</a>
<a id='n1062' href='#n1062'>1062</a>
<a id='n1063' href='#n1063'>1063</a>
<a id='n1064' href='#n1064'>1064</a>
<a id='n1065' href='#n1065'>1065</a>
<a id='n1066' href='#n1066'>1066</a>
<a id='n1067' href='#n1067'>1067</a>
<a id='n1068' href='#n1068'>1068</a>
<a id='n1069' href='#n1069'>1069</a>
<a id='n1070' href='#n1070'>1070</a>
<a id='n1071' href='#n1071'>1071</a>
<a id='n1072' href='#n1072'>1072</a>
<a id='n1073' href='#n1073'>1073</a>
<a id='n1074' href='#n1074'>1074</a>
<a id='n1075' href='#n1075'>1075</a>
<a id='n1076' href='#n1076'>1076</a>
<a id='n1077' href='#n1077'>1077</a>
<a id='n1078' href='#n1078'>1078</a>
<a id='n1079' href='#n1079'>1079</a>
<a id='n1080' href='#n1080'>1080</a>
<a id='n1081' href='#n1081'>1081</a>
<a id='n1082' href='#n1082'>1082</a>
<a id='n1083' href='#n1083'>1083</a>
<a id='n1084' href='#n1084'>1084</a>
<a id='n1085' href='#n1085'>1085</a>
<a id='n1086' href='#n1086'>1086</a>
<a id='n1087' href='#n1087'>1087</a>
<a id='n1088' href='#n1088'>1088</a>
<a id='n1089' href='#n1089'>1089</a>
<a id='n1090' href='#n1090'>1090</a>
<a id='n1091' href='#n1091'>1091</a>
<a id='n1092' href='#n1092'>1092</a>
<a id='n1093' href='#n1093'>1093</a>
<a id='n1094' href='#n1094'>1094</a>
<a id='n1095' href='#n1095'>1095</a>
<a id='n1096' href='#n1096'>1096</a>
<a id='n1097' href='#n1097'>1097</a>
<a id='n1098' href='#n1098'>1098</a>
<a id='n1099' href='#n1099'>1099</a>
<a id='n1100' href='#n1100'>1100</a>
<a id='n1101' href='#n1101'>1101</a>
<a id='n1102' href='#n1102'>1102</a>
<a id='n1103' href='#n1103'>1103</a>
<a id='n1104' href='#n1104'>1104</a>
<a id='n1105' href='#n1105'>1105</a>
<a id='n1106' href='#n1106'>1106</a>
<a id='n1107' href='#n1107'>1107</a>
<a id='n1108' href='#n1108'>1108</a>
<a id='n1109' href='#n1109'>1109</a>
<a id='n1110' href='#n1110'>1110</a>
<a id='n1111' href='#n1111'>1111</a>
<a id='n1112' href='#n1112'>1112</a>
<a id='n1113' href='#n1113'>1113</a>
<a id='n1114' href='#n1114'>1114</a>
<a id='n1115' href='#n1115'>1115</a>
<a id='n1116' href='#n1116'>1116</a>
<a id='n1117' href='#n1117'>1117</a>
<a id='n1118' href='#n1118'>1118</a>
<a id='n1119' href='#n1119'>1119</a>
<a id='n1120' href='#n1120'>1120</a>
<a id='n1121' href='#n1121'>1121</a>
<a id='n1122' href='#n1122'>1122</a>
<a id='n1123' href='#n1123'>1123</a>
<a id='n1124' href='#n1124'>1124</a>
<a id='n1125' href='#n1125'>1125</a>
<a id='n1126' href='#n1126'>1126</a>
<a id='n1127' href='#n1127'>1127</a>
<a id='n1128' href='#n1128'>1128</a>
<a id='n1129' href='#n1129'>1129</a>
<a id='n1130' href='#n1130'>1130</a>
<a id='n1131' href='#n1131'>1131</a>
<a id='n1132' href='#n1132'>1132</a>
<a id='n1133' href='#n1133'>1133</a>
<a id='n1134' href='#n1134'>1134</a>
<a id='n1135' href='#n1135'>1135</a>
<a id='n1136' href='#n1136'>1136</a>
<a id='n1137' href='#n1137'>1137</a>
<a id='n1138' href='#n1138'>1138</a>
<a id='n1139' href='#n1139'>1139</a>
<a id='n1140' href='#n1140'>1140</a>
<a id='n1141' href='#n1141'>1141</a>
<a id='n1142' href='#n1142'>1142</a>
<a id='n1143' href='#n1143'>1143</a>
<a id='n1144' href='#n1144'>1144</a>
<a id='n1145' href='#n1145'>1145</a>
<a id='n1146' href='#n1146'>1146</a>
<a id='n1147' href='#n1147'>1147</a>
<a id='n1148' href='#n1148'>1148</a>
<a id='n1149' href='#n1149'>1149</a>
<a id='n1150' href='#n1150'>1150</a>
<a id='n1151' href='#n1151'>1151</a>
<a id='n1152' href='#n1152'>1152</a>
<a id='n1153' href='#n1153'>1153</a>
<a id='n1154' href='#n1154'>1154</a>
<a id='n1155' href='#n1155'>1155</a>
<a id='n1156' href='#n1156'>1156</a>
<a id='n1157' href='#n1157'>1157</a>
<a id='n1158' href='#n1158'>1158</a>
<a id='n1159' href='#n1159'>1159</a>
<a id='n1160' href='#n1160'>1160</a>
<a id='n1161' href='#n1161'>1161</a>
<a id='n1162' href='#n1162'>1162</a>
<a id='n1163' href='#n1163'>1163</a>
<a id='n1164' href='#n1164'>1164</a>
<a id='n1165' href='#n1165'>1165</a>
<a id='n1166' href='#n1166'>1166</a>
<a id='n1167' href='#n1167'>1167</a>
<a id='n1168' href='#n1168'>1168</a>
<a id='n1169' href='#n1169'>1169</a>
<a id='n1170' href='#n1170'>1170</a>
<a id='n1171' href='#n1171'>1171</a>
<a id='n1172' href='#n1172'>1172</a>
<a id='n1173' href='#n1173'>1173</a>
<a id='n1174' href='#n1174'>1174</a>
<a id='n1175' href='#n1175'>1175</a>
<a id='n1176' href='#n1176'>1176</a>
<a id='n1177' href='#n1177'>1177</a>
<a id='n1178' href='#n1178'>1178</a>
<a id='n1179' href='#n1179'>1179</a>
<a id='n1180' href='#n1180'>1180</a>
<a id='n1181' href='#n1181'>1181</a>
<a id='n1182' href='#n1182'>1182</a>
<a id='n1183' href='#n1183'>1183</a>
<a id='n1184' href='#n1184'>1184</a>
<a id='n1185' href='#n1185'>1185</a>
<a id='n1186' href='#n1186'>1186</a>
<a id='n1187' href='#n1187'>1187</a>
<a id='n1188' href='#n1188'>1188</a>
<a id='n1189' href='#n1189'>1189</a>
<a id='n1190' href='#n1190'>1190</a>
<a id='n1191' href='#n1191'>1191</a>
<a id='n1192' href='#n1192'>1192</a>
<a id='n1193' href='#n1193'>1193</a>
<a id='n1194' href='#n1194'>1194</a>
<a id='n1195' href='#n1195'>1195</a>
<a id='n1196' href='#n1196'>1196</a>
<a id='n1197' href='#n1197'>1197</a>
<a id='n1198' href='#n1198'>1198</a>
<a id='n1199' href='#n1199'>1199</a>
<a id='n1200' href='#n1200'>1200</a>
<a id='n1201' href='#n1201'>1201</a>
<a id='n1202' href='#n1202'>1202</a>
<a id='n1203' href='#n1203'>1203</a>
<a id='n1204' href='#n1204'>1204</a>
<a id='n1205' href='#n1205'>1205</a>
<a id='n1206' href='#n1206'>1206</a>
<a id='n1207' href='#n1207'>1207</a>
<a id='n1208' href='#n1208'>1208</a>
<a id='n1209' href='#n1209'>1209</a>
<a id='n1210' href='#n1210'>1210</a>
<a id='n1211' href='#n1211'>1211</a>
<a id='n1212' href='#n1212'>1212</a>
<a id='n1213' href='#n1213'>1213</a>
<a id='n1214' href='#n1214'>1214</a>
<a id='n1215' href='#n1215'>1215</a>
<a id='n1216' href='#n1216'>1216</a>
<a id='n1217' href='#n1217'>1217</a>
<a id='n1218' href='#n1218'>1218</a>
<a id='n1219' href='#n1219'>1219</a>
<a id='n1220' href='#n1220'>1220</a>
<a id='n1221' href='#n1221'>1221</a>
<a id='n1222' href='#n1222'>1222</a>
<a id='n1223' href='#n1223'>1223</a>
<a id='n1224' href='#n1224'>1224</a>
<a id='n1225' href='#n1225'>1225</a>
<a id='n1226' href='#n1226'>1226</a>
<a id='n1227' href='#n1227'>1227</a>
<a id='n1228' href='#n1228'>1228</a>
<a id='n1229' href='#n1229'>1229</a>
<a id='n1230' href='#n1230'>1230</a>
<a id='n1231' href='#n1231'>1231</a>
<a id='n1232' href='#n1232'>1232</a>
<a id='n1233' href='#n1233'>1233</a>
<a id='n1234' href='#n1234'>1234</a>
<a id='n1235' href='#n1235'>1235</a>
<a id='n1236' href='#n1236'>1236</a>
<a id='n1237' href='#n1237'>1237</a>
<a id='n1238' href='#n1238'>1238</a>
<a id='n1239' href='#n1239'>1239</a>
<a id='n1240' href='#n1240'>1240</a>
<a id='n1241' href='#n1241'>1241</a>
<a id='n1242' href='#n1242'>1242</a>
<a id='n1243' href='#n1243'>1243</a>
<a id='n1244' href='#n1244'>1244</a>
<a id='n1245' href='#n1245'>1245</a>
<a id='n1246' href='#n1246'>1246</a>
<a id='n1247' href='#n1247'>1247</a>
<a id='n1248' href='#n1248'>1248</a>
<a id='n1249' href='#n1249'>1249</a>
<a id='n1250' href='#n1250'>1250</a>
<a id='n1251' href='#n1251'>1251</a>
<a id='n1252' href='#n1252'>1252</a>
<a id='n1253' href='#n1253'>1253</a>
<a id='n1254' href='#n1254'>1254</a>
<a id='n1255' href='#n1255'>1255</a>
<a id='n1256' href='#n1256'>1256</a>
<a id='n1257' href='#n1257'>1257</a>
<a id='n1258' href='#n1258'>1258</a>
<a id='n1259' href='#n1259'>1259</a>
<a id='n1260' href='#n1260'>1260</a>
<a id='n1261' href='#n1261'>1261</a>
<a id='n1262' href='#n1262'>1262</a>
<a id='n1263' href='#n1263'>1263</a>
<a id='n1264' href='#n1264'>1264</a>
<a id='n1265' href='#n1265'>1265</a>
<a id='n1266' href='#n1266'>1266</a>
<a id='n1267' href='#n1267'>1267</a>
<a id='n1268' href='#n1268'>1268</a>
<a id='n1269' href='#n1269'>1269</a>
<a id='n1270' href='#n1270'>1270</a>
<a id='n1271' href='#n1271'>1271</a>
<a id='n1272' href='#n1272'>1272</a>
<a id='n1273' href='#n1273'>1273</a>
<a id='n1274' href='#n1274'>1274</a>
<a id='n1275' href='#n1275'>1275</a>
<a id='n1276' href='#n1276'>1276</a>
<a id='n1277' href='#n1277'>1277</a>
<a id='n1278' href='#n1278'>1278</a>
<a id='n1279' href='#n1279'>1279</a>
<a id='n1280' href='#n1280'>1280</a>
<a id='n1281' href='#n1281'>1281</a>
<a id='n1282' href='#n1282'>1282</a>
<a id='n1283' href='#n1283'>1283</a>
<a id='n1284' href='#n1284'>1284</a>
<a id='n1285' href='#n1285'>1285</a>
<a id='n1286' href='#n1286'>1286</a>
<a id='n1287' href='#n1287'>1287</a>
<a id='n1288' href='#n1288'>1288</a>
<a id='n1289' href='#n1289'>1289</a>
<a id='n1290' href='#n1290'>1290</a>
<a id='n1291' href='#n1291'>1291</a>
<a id='n1292' href='#n1292'>1292</a>
<a id='n1293' href='#n1293'>1293</a>
<a id='n1294' href='#n1294'>1294</a>
<a id='n1295' href='#n1295'>1295</a>
<a id='n1296' href='#n1296'>1296</a>
<a id='n1297' href='#n1297'>1297</a>
<a id='n1298' href='#n1298'>1298</a>
<a id='n1299' href='#n1299'>1299</a>
<a id='n1300' href='#n1300'>1300</a>
<a id='n1301' href='#n1301'>1301</a>
<a id='n1302' href='#n1302'>1302</a>
<a id='n1303' href='#n1303'>1303</a>
<a id='n1304' href='#n1304'>1304</a>
<a id='n1305' href='#n1305'>1305</a>
<a id='n1306' href='#n1306'>1306</a>
<a id='n1307' href='#n1307'>1307</a>
<a id='n1308' href='#n1308'>1308</a>
<a id='n1309' href='#n1309'>1309</a>
<a id='n1310' href='#n1310'>1310</a>
<a id='n1311' href='#n1311'>1311</a>
<a id='n1312' href='#n1312'>1312</a>
<a id='n1313' href='#n1313'>1313</a>
<a id='n1314' href='#n1314'>1314</a>
<a id='n1315' href='#n1315'>1315</a>
<a id='n1316' href='#n1316'>1316</a>
<a id='n1317' href='#n1317'>1317</a>
<a id='n1318' href='#n1318'>1318</a>
<a id='n1319' href='#n1319'>1319</a>
<a id='n1320' href='#n1320'>1320</a>
<a id='n1321' href='#n1321'>1321</a>
<a id='n1322' href='#n1322'>1322</a>
<a id='n1323' href='#n1323'>1323</a>
<a id='n1324' href='#n1324'>1324</a>
<a id='n1325' href='#n1325'>1325</a>
<a id='n1326' href='#n1326'>1326</a>
<a id='n1327' href='#n1327'>1327</a>
<a id='n1328' href='#n1328'>1328</a>
<a id='n1329' href='#n1329'>1329</a>
<a id='n1330' href='#n1330'>1330</a>
<a id='n1331' href='#n1331'>1331</a>
<a id='n1332' href='#n1332'>1332</a>
<a id='n1333' href='#n1333'>1333</a>
<a id='n1334' href='#n1334'>1334</a>
<a id='n1335' href='#n1335'>1335</a>
<a id='n1336' href='#n1336'>1336</a>
<a id='n1337' href='#n1337'>1337</a>
<a id='n1338' href='#n1338'>1338</a>
<a id='n1339' href='#n1339'>1339</a>
<a id='n1340' href='#n1340'>1340</a>
<a id='n1341' href='#n1341'>1341</a>
<a id='n1342' href='#n1342'>1342</a>
<a id='n1343' href='#n1343'>1343</a>
<a id='n1344' href='#n1344'>1344</a>
<a id='n1345' href='#n1345'>1345</a>
<a id='n1346' href='#n1346'>1346</a>
<a id='n1347' href='#n1347'>1347</a>
<a id='n1348' href='#n1348'>1348</a>
<a id='n1349' href='#n1349'>1349</a>
<a id='n1350' href='#n1350'>1350</a>
<a id='n1351' href='#n1351'>1351</a>
<a id='n1352' href='#n1352'>1352</a>
<a id='n1353' href='#n1353'>1353</a>
<a id='n1354' href='#n1354'>1354</a>
<a id='n1355' href='#n1355'>1355</a>
<a id='n1356' href='#n1356'>1356</a>
<a id='n1357' href='#n1357'>1357</a>
<a id='n1358' href='#n1358'>1358</a>
<a id='n1359' href='#n1359'>1359</a>
<a id='n1360' href='#n1360'>1360</a>
<a id='n1361' href='#n1361'>1361</a>
<a id='n1362' href='#n1362'>1362</a>
<a id='n1363' href='#n1363'>1363</a>
<a id='n1364' href='#n1364'>1364</a>
<a id='n1365' href='#n1365'>1365</a>
<a id='n1366' href='#n1366'>1366</a>
<a id='n1367' href='#n1367'>1367</a>
<a id='n1368' href='#n1368'>1368</a>
<a id='n1369' href='#n1369'>1369</a>
<a id='n1370' href='#n1370'>1370</a>
<a id='n1371' href='#n1371'>1371</a>
<a id='n1372' href='#n1372'>1372</a>
<a id='n1373' href='#n1373'>1373</a>
<a id='n1374' href='#n1374'>1374</a>
<a id='n1375' href='#n1375'>1375</a>
<a id='n1376' href='#n1376'>1376</a>
<a id='n1377' href='#n1377'>1377</a>
<a id='n1378' href='#n1378'>1378</a>
<a id='n1379' href='#n1379'>1379</a>
<a id='n1380' href='#n1380'>1380</a>
<a id='n1381' href='#n1381'>1381</a>
<a id='n1382' href='#n1382'>1382</a>
<a id='n1383' href='#n1383'>1383</a>
<a id='n1384' href='#n1384'>1384</a>
<a id='n1385' href='#n1385'>1385</a>
<a id='n1386' href='#n1386'>1386</a>
<a id='n1387' href='#n1387'>1387</a>
<a id='n1388' href='#n1388'>1388</a>
<a id='n1389' href='#n1389'>1389</a>
<a id='n1390' href='#n1390'>1390</a>
<a id='n1391' href='#n1391'>1391</a>
<a id='n1392' href='#n1392'>1392</a>
<a id='n1393' href='#n1393'>1393</a>
<a id='n1394' href='#n1394'>1394</a>
<a id='n1395' href='#n1395'>1395</a>
<a id='n1396' href='#n1396'>1396</a>
<a id='n1397' href='#n1397'>1397</a>
<a id='n1398' href='#n1398'>1398</a>
<a id='n1399' href='#n1399'>1399</a>
<a id='n1400' href='#n1400'>1400</a>
<a id='n1401' href='#n1401'>1401</a>
<a id='n1402' href='#n1402'>1402</a>
<a id='n1403' href='#n1403'>1403</a>
<a id='n1404' href='#n1404'>1404</a>
<a id='n1405' href='#n1405'>1405</a>
<a id='n1406' href='#n1406'>1406</a>
<a id='n1407' href='#n1407'>1407</a>
<a id='n1408' href='#n1408'>1408</a>
<a id='n1409' href='#n1409'>1409</a>
<a id='n1410' href='#n1410'>1410</a>
<a id='n1411' href='#n1411'>1411</a>
<a id='n1412' href='#n1412'>1412</a>
<a id='n1413' href='#n1413'>1413</a>
<a id='n1414' href='#n1414'>1414</a>
<a id='n1415' href='#n1415'>1415</a>
<a id='n1416' href='#n1416'>1416</a>
<a id='n1417' href='#n1417'>1417</a>
<a id='n1418' href='#n1418'>1418</a>
<a id='n1419' href='#n1419'>1419</a>
<a id='n1420' href='#n1420'>1420</a>
<a id='n1421' href='#n1421'>1421</a>
<a id='n1422' href='#n1422'>1422</a>
<a id='n1423' href='#n1423'>1423</a>
<a id='n1424' href='#n1424'>1424</a>
<a id='n1425' href='#n1425'>1425</a>
<a id='n1426' href='#n1426'>1426</a>
<a id='n1427' href='#n1427'>1427</a>
<a id='n1428' href='#n1428'>1428</a>
<a id='n1429' href='#n1429'>1429</a>
<a id='n1430' href='#n1430'>1430</a>
<a id='n1431' href='#n1431'>1431</a>
<a id='n1432' href='#n1432'>1432</a>
<a id='n1433' href='#n1433'>1433</a>
<a id='n1434' href='#n1434'>1434</a>
<a id='n1435' href='#n1435'>1435</a>
<a id='n1436' href='#n1436'>1436</a>
<a id='n1437' href='#n1437'>1437</a>
<a id='n1438' href='#n1438'>1438</a>
<a id='n1439' href='#n1439'>1439</a>
<a id='n1440' href='#n1440'>1440</a>
<a id='n1441' href='#n1441'>1441</a>
<a id='n1442' href='#n1442'>1442</a>
<a id='n1443' href='#n1443'>1443</a>
<a id='n1444' href='#n1444'>1444</a>
<a id='n1445' href='#n1445'>1445</a>
<a id='n1446' href='#n1446'>1446</a>
<a id='n1447' href='#n1447'>1447</a>
<a id='n1448' href='#n1448'>1448</a>
<a id='n1449' href='#n1449'>1449</a>
<a id='n1450' href='#n1450'>1450</a>
<a id='n1451' href='#n1451'>1451</a>
<a id='n1452' href='#n1452'>1452</a>
<a id='n1453' href='#n1453'>1453</a>
<a id='n1454' href='#n1454'>1454</a>
<a id='n1455' href='#n1455'>1455</a>
<a id='n1456' href='#n1456'>1456</a>
<a id='n1457' href='#n1457'>1457</a>
<a id='n1458' href='#n1458'>1458</a>
<a id='n1459' href='#n1459'>1459</a>
<a id='n1460' href='#n1460'>1460</a>
<a id='n1461' href='#n1461'>1461</a>
<a id='n1462' href='#n1462'>1462</a>
<a id='n1463' href='#n1463'>1463</a>
<a id='n1464' href='#n1464'>1464</a>
<a id='n1465' href='#n1465'>1465</a>
<a id='n1466' href='#n1466'>1466</a>
<a id='n1467' href='#n1467'>1467</a>
<a id='n1468' href='#n1468'>1468</a>
<a id='n1469' href='#n1469'>1469</a>
<a id='n1470' href='#n1470'>1470</a>
<a id='n1471' href='#n1471'>1471</a>
<a id='n1472' href='#n1472'>1472</a>
<a id='n1473' href='#n1473'>1473</a>
<a id='n1474' href='#n1474'>1474</a>
<a id='n1475' href='#n1475'>1475</a>
<a id='n1476' href='#n1476'>1476</a>
<a id='n1477' href='#n1477'>1477</a>
<a id='n1478' href='#n1478'>1478</a>
<a id='n1479' href='#n1479'>1479</a>
<a id='n1480' href='#n1480'>1480</a>
<a id='n1481' href='#n1481'>1481</a>
<a id='n1482' href='#n1482'>1482</a>
<a id='n1483' href='#n1483'>1483</a>
<a id='n1484' href='#n1484'>1484</a>
<a id='n1485' href='#n1485'>1485</a>
<a id='n1486' href='#n1486'>1486</a>
<a id='n1487' href='#n1487'>1487</a>
<a id='n1488' href='#n1488'>1488</a>
<a id='n1489' href='#n1489'>1489</a>
<a id='n1490' href='#n1490'>1490</a>
<a id='n1491' href='#n1491'>1491</a>
<a id='n1492' href='#n1492'>1492</a>
<a id='n1493' href='#n1493'>1493</a>
<a id='n1494' href='#n1494'>1494</a>
<a id='n1495' href='#n1495'>1495</a>
<a id='n1496' href='#n1496'>1496</a>
<a id='n1497' href='#n1497'>1497</a>
<a id='n1498' href='#n1498'>1498</a>
<a id='n1499' href='#n1499'>1499</a>
<a id='n1500' href='#n1500'>1500</a>
<a id='n1501' href='#n1501'>1501</a>
<a id='n1502' href='#n1502'>1502</a>
<a id='n1503' href='#n1503'>1503</a>
<a id='n1504' href='#n1504'>1504</a>
<a id='n1505' href='#n1505'>1505</a>
<a id='n1506' href='#n1506'>1506</a>
<a id='n1507' href='#n1507'>1507</a>
<a id='n1508' href='#n1508'>1508</a>
<a id='n1509' href='#n1509'>1509</a>
<a id='n1510' href='#n1510'>1510</a>
<a id='n1511' href='#n1511'>1511</a>
<a id='n1512' href='#n1512'>1512</a>
<a id='n1513' href='#n1513'>1513</a>
<a id='n1514' href='#n1514'>1514</a>
<a id='n1515' href='#n1515'>1515</a>
<a id='n1516' href='#n1516'>1516</a>
<a id='n1517' href='#n1517'>1517</a>
<a id='n1518' href='#n1518'>1518</a>
<a id='n1519' href='#n1519'>1519</a>
<a id='n1520' href='#n1520'>1520</a>
<a id='n1521' href='#n1521'>1521</a>
<a id='n1522' href='#n1522'>1522</a>
<a id='n1523' href='#n1523'>1523</a>
<a id='n1524' href='#n1524'>1524</a>
<a id='n1525' href='#n1525'>1525</a>
<a id='n1526' href='#n1526'>1526</a>
<a id='n1527' href='#n1527'>1527</a>
<a id='n1528' href='#n1528'>1528</a>
<a id='n1529' href='#n1529'>1529</a>
<a id='n1530' href='#n1530'>1530</a>
<a id='n1531' href='#n1531'>1531</a>
<a id='n1532' href='#n1532'>1532</a>
<a id='n1533' href='#n1533'>1533</a>
<a id='n1534' href='#n1534'>1534</a>
<a id='n1535' href='#n1535'>1535</a>
<a id='n1536' href='#n1536'>1536</a>
<a id='n1537' href='#n1537'>1537</a>
<a id='n1538' href='#n1538'>1538</a>
<a id='n1539' href='#n1539'>1539</a>
<a id='n1540' href='#n1540'>1540</a>
<a id='n1541' href='#n1541'>1541</a>
<a id='n1542' href='#n1542'>1542</a>
<a id='n1543' href='#n1543'>1543</a>
<a id='n1544' href='#n1544'>1544</a>
<a id='n1545' href='#n1545'>1545</a>
<a id='n1546' href='#n1546'>1546</a>
<a id='n1547' href='#n1547'>1547</a>
<a id='n1548' href='#n1548'>1548</a>
<a id='n1549' href='#n1549'>1549</a>
<a id='n1550' href='#n1550'>1550</a>
<a id='n1551' href='#n1551'>1551</a>
<a id='n1552' href='#n1552'>1552</a>
<a id='n1553' href='#n1553'>1553</a>
<a id='n1554' href='#n1554'>1554</a>
<a id='n1555' href='#n1555'>1555</a>
<a id='n1556' href='#n1556'>1556</a>
<a id='n1557' href='#n1557'>1557</a>
<a id='n1558' href='#n1558'>1558</a>
<a id='n1559' href='#n1559'>1559</a>
<a id='n1560' href='#n1560'>1560</a>
<a id='n1561' href='#n1561'>1561</a>
<a id='n1562' href='#n1562'>1562</a>
<a id='n1563' href='#n1563'>1563</a>
<a id='n1564' href='#n1564'>1564</a>
<a id='n1565' href='#n1565'>1565</a>
<a id='n1566' href='#n1566'>1566</a>
<a id='n1567' href='#n1567'>1567</a>
<a id='n1568' href='#n1568'>1568</a>
<a id='n1569' href='#n1569'>1569</a>
<a id='n1570' href='#n1570'>1570</a>
<a id='n1571' href='#n1571'>1571</a>
<a id='n1572' href='#n1572'>1572</a>
<a id='n1573' href='#n1573'>1573</a>
<a id='n1574' href='#n1574'>1574</a>
<a id='n1575' href='#n1575'>1575</a>
<a id='n1576' href='#n1576'>1576</a>
<a id='n1577' href='#n1577'>1577</a>
<a id='n1578' href='#n1578'>1578</a>
<a id='n1579' href='#n1579'>1579</a>
<a id='n1580' href='#n1580'>1580</a>
<a id='n1581' href='#n1581'>1581</a>
<a id='n1582' href='#n1582'>1582</a>
<a id='n1583' href='#n1583'>1583</a>
<a id='n1584' href='#n1584'>1584</a>
<a id='n1585' href='#n1585'>1585</a>
<a id='n1586' href='#n1586'>1586</a>
<a id='n1587' href='#n1587'>1587</a>
<a id='n1588' href='#n1588'>1588</a>
<a id='n1589' href='#n1589'>1589</a>
<a id='n1590' href='#n1590'>1590</a>
<a id='n1591' href='#n1591'>1591</a>
<a id='n1592' href='#n1592'>1592</a>
<a id='n1593' href='#n1593'>1593</a>
<a id='n1594' href='#n1594'>1594</a>
<a id='n1595' href='#n1595'>1595</a>
<a id='n1596' href='#n1596'>1596</a>
<a id='n1597' href='#n1597'>1597</a>
<a id='n1598' href='#n1598'>1598</a>
<a id='n1599' href='#n1599'>1599</a>
<a id='n1600' href='#n1600'>1600</a>
<a id='n1601' href='#n1601'>1601</a>
<a id='n1602' href='#n1602'>1602</a>
<a id='n1603' href='#n1603'>1603</a>
<a id='n1604' href='#n1604'>1604</a>
<a id='n1605' href='#n1605'>1605</a>
<a id='n1606' href='#n1606'>1606</a>
<a id='n1607' href='#n1607'>1607</a>
<a id='n1608' href='#n1608'>1608</a>
<a id='n1609' href='#n1609'>1609</a>
<a id='n1610' href='#n1610'>1610</a>
<a id='n1611' href='#n1611'>1611</a>
<a id='n1612' href='#n1612'>1612</a>
<a id='n1613' href='#n1613'>1613</a>
<a id='n1614' href='#n1614'>1614</a>
<a id='n1615' href='#n1615'>1615</a>
<a id='n1616' href='#n1616'>1616</a>
<a id='n1617' href='#n1617'>1617</a>
<a id='n1618' href='#n1618'>1618</a>
<a id='n1619' href='#n1619'>1619</a>
<a id='n1620' href='#n1620'>1620</a>
<a id='n1621' href='#n1621'>1621</a>
<a id='n1622' href='#n1622'>1622</a>
<a id='n1623' href='#n1623'>1623</a>
<a id='n1624' href='#n1624'>1624</a>
<a id='n1625' href='#n1625'>1625</a>
<a id='n1626' href='#n1626'>1626</a>
<a id='n1627' href='#n1627'>1627</a>
<a id='n1628' href='#n1628'>1628</a>
<a id='n1629' href='#n1629'>1629</a>
<a id='n1630' href='#n1630'>1630</a>
<a id='n1631' href='#n1631'>1631</a>
<a id='n1632' href='#n1632'>1632</a>
<a id='n1633' href='#n1633'>1633</a>
<a id='n1634' href='#n1634'>1634</a>
<a id='n1635' href='#n1635'>1635</a>
<a id='n1636' href='#n1636'>1636</a>
<a id='n1637' href='#n1637'>1637</a>
<a id='n1638' href='#n1638'>1638</a>
<a id='n1639' href='#n1639'>1639</a>
<a id='n1640' href='#n1640'>1640</a>
<a id='n1641' href='#n1641'>1641</a>
<a id='n1642' href='#n1642'>1642</a>
<a id='n1643' href='#n1643'>1643</a>
<a id='n1644' href='#n1644'>1644</a>
<a id='n1645' href='#n1645'>1645</a>
<a id='n1646' href='#n1646'>1646</a>
<a id='n1647' href='#n1647'>1647</a>
<a id='n1648' href='#n1648'>1648</a>
<a id='n1649' href='#n1649'>1649</a>
<a id='n1650' href='#n1650'>1650</a>
<a id='n1651' href='#n1651'>1651</a>
<a id='n1652' href='#n1652'>1652</a>
<a id='n1653' href='#n1653'>1653</a>
<a id='n1654' href='#n1654'>1654</a>
<a id='n1655' href='#n1655'>1655</a>
<a id='n1656' href='#n1656'>1656</a>
<a id='n1657' href='#n1657'>1657</a>
<a id='n1658' href='#n1658'>1658</a>
<a id='n1659' href='#n1659'>1659</a>
<a id='n1660' href='#n1660'>1660</a>
<a id='n1661' href='#n1661'>1661</a>
<a id='n1662' href='#n1662'>1662</a>
<a id='n1663' href='#n1663'>1663</a>
<a id='n1664' href='#n1664'>1664</a>
<a id='n1665' href='#n1665'>1665</a>
<a id='n1666' href='#n1666'>1666</a>
<a id='n1667' href='#n1667'>1667</a>
<a id='n1668' href='#n1668'>1668</a>
<a id='n1669' href='#n1669'>1669</a>
<a id='n1670' href='#n1670'>1670</a>
<a id='n1671' href='#n1671'>1671</a>
<a id='n1672' href='#n1672'>1672</a>
<a id='n1673' href='#n1673'>1673</a>
<a id='n1674' href='#n1674'>1674</a>
<a id='n1675' href='#n1675'>1675</a>
<a id='n1676' href='#n1676'>1676</a>
<a id='n1677' href='#n1677'>1677</a>
<a id='n1678' href='#n1678'>1678</a>
<a id='n1679' href='#n1679'>1679</a>
<a id='n1680' href='#n1680'>1680</a>
<a id='n1681' href='#n1681'>1681</a>
<a id='n1682' href='#n1682'>1682</a>
<a id='n1683' href='#n1683'>1683</a>
<a id='n1684' href='#n1684'>1684</a>
<a id='n1685' href='#n1685'>1685</a>
<a id='n1686' href='#n1686'>1686</a>
<a id='n1687' href='#n1687'>1687</a>
<a id='n1688' href='#n1688'>1688</a>
<a id='n1689' href='#n1689'>1689</a>
<a id='n1690' href='#n1690'>1690</a>
<a id='n1691' href='#n1691'>1691</a>
<a id='n1692' href='#n1692'>1692</a>
<a id='n1693' href='#n1693'>1693</a>
<a id='n1694' href='#n1694'>1694</a>
<a id='n1695' href='#n1695'>1695</a>
<a id='n1696' href='#n1696'>1696</a>
<a id='n1697' href='#n1697'>1697</a>
<a id='n1698' href='#n1698'>1698</a>
<a id='n1699' href='#n1699'>1699</a>
<a id='n1700' href='#n1700'>1700</a>
<a id='n1701' href='#n1701'>1701</a>
<a id='n1702' href='#n1702'>1702</a>
<a id='n1703' href='#n1703'>1703</a>
<a id='n1704' href='#n1704'>1704</a>
<a id='n1705' href='#n1705'>1705</a>
<a id='n1706' href='#n1706'>1706</a>
<a id='n1707' href='#n1707'>1707</a>
<a id='n1708' href='#n1708'>1708</a>
<a id='n1709' href='#n1709'>1709</a>
<a id='n1710' href='#n1710'>1710</a>
<a id='n1711' href='#n1711'>1711</a>
<a id='n1712' href='#n1712'>1712</a>
<a id='n1713' href='#n1713'>1713</a>
<a id='n1714' href='#n1714'>1714</a>
<a id='n1715' href='#n1715'>1715</a>
<a id='n1716' href='#n1716'>1716</a>
<a id='n1717' href='#n1717'>1717</a>
<a id='n1718' href='#n1718'>1718</a>
<a id='n1719' href='#n1719'>1719</a>
<a id='n1720' href='#n1720'>1720</a>
<a id='n1721' href='#n1721'>1721</a>
<a id='n1722' href='#n1722'>1722</a>
<a id='n1723' href='#n1723'>1723</a>
<a id='n1724' href='#n1724'>1724</a>
<a id='n1725' href='#n1725'>1725</a>
<a id='n1726' href='#n1726'>1726</a>
<a id='n1727' href='#n1727'>1727</a>
<a id='n1728' href='#n1728'>1728</a>
<a id='n1729' href='#n1729'>1729</a>
<a id='n1730' href='#n1730'>1730</a>
<a id='n1731' href='#n1731'>1731</a>
<a id='n1732' href='#n1732'>1732</a>
<a id='n1733' href='#n1733'>1733</a>
<a id='n1734' href='#n1734'>1734</a>
<a id='n1735' href='#n1735'>1735</a>
<a id='n1736' href='#n1736'>1736</a>
<a id='n1737' href='#n1737'>1737</a>
<a id='n1738' href='#n1738'>1738</a>
<a id='n1739' href='#n1739'>1739</a>
<a id='n1740' href='#n1740'>1740</a>
<a id='n1741' href='#n1741'>1741</a>
<a id='n1742' href='#n1742'>1742</a>
<a id='n1743' href='#n1743'>1743</a>
<a id='n1744' href='#n1744'>1744</a>
<a id='n1745' href='#n1745'>1745</a>
<a id='n1746' href='#n1746'>1746</a>
<a id='n1747' href='#n1747'>1747</a>
<a id='n1748' href='#n1748'>1748</a>
<a id='n1749' href='#n1749'>1749</a>
<a id='n1750' href='#n1750'>1750</a>
<a id='n1751' href='#n1751'>1751</a>
<a id='n1752' href='#n1752'>1752</a>
<a id='n1753' href='#n1753'>1753</a>
<a id='n1754' href='#n1754'>1754</a>
<a id='n1755' href='#n1755'>1755</a>
<a id='n1756' href='#n1756'>1756</a>
<a id='n1757' href='#n1757'>1757</a>
<a id='n1758' href='#n1758'>1758</a>
<a id='n1759' href='#n1759'>1759</a>
<a id='n1760' href='#n1760'>1760</a>
<a id='n1761' href='#n1761'>1761</a>
<a id='n1762' href='#n1762'>1762</a>
<a id='n1763' href='#n1763'>1763</a>
<a id='n1764' href='#n1764'>1764</a>
<a id='n1765' href='#n1765'>1765</a>
<a id='n1766' href='#n1766'>1766</a>
<a id='n1767' href='#n1767'>1767</a>
<a id='n1768' href='#n1768'>1768</a>
<a id='n1769' href='#n1769'>1769</a>
<a id='n1770' href='#n1770'>1770</a>
<a id='n1771' href='#n1771'>1771</a>
<a id='n1772' href='#n1772'>1772</a>
<a id='n1773' href='#n1773'>1773</a>
<a id='n1774' href='#n1774'>1774</a>
<a id='n1775' href='#n1775'>1775</a>
<a id='n1776' href='#n1776'>1776</a>
<a id='n1777' href='#n1777'>1777</a>
<a id='n1778' href='#n1778'>1778</a>
<a id='n1779' href='#n1779'>1779</a>
<a id='n1780' href='#n1780'>1780</a>
<a id='n1781' href='#n1781'>1781</a>
<a id='n1782' href='#n1782'>1782</a>
<a id='n1783' href='#n1783'>1783</a>
<a id='n1784' href='#n1784'>1784</a>
<a id='n1785' href='#n1785'>1785</a>
<a id='n1786' href='#n1786'>1786</a>
<a id='n1787' href='#n1787'>1787</a>
<a id='n1788' href='#n1788'>1788</a>
<a id='n1789' href='#n1789'>1789</a>
<a id='n1790' href='#n1790'>1790</a>
<a id='n1791' href='#n1791'>1791</a>
<a id='n1792' href='#n1792'>1792</a>
<a id='n1793' href='#n1793'>1793</a>
<a id='n1794' href='#n1794'>1794</a>
<a id='n1795' href='#n1795'>1795</a>
<a id='n1796' href='#n1796'>1796</a>
<a id='n1797' href='#n1797'>1797</a>
<a id='n1798' href='#n1798'>1798</a>
<a id='n1799' href='#n1799'>1799</a>
<a id='n1800' href='#n1800'>1800</a>
<a id='n1801' href='#n1801'>1801</a>
<a id='n1802' href='#n1802'>1802</a>
<a id='n1803' href='#n1803'>1803</a>
<a id='n1804' href='#n1804'>1804</a>
<a id='n1805' href='#n1805'>1805</a>
<a id='n1806' href='#n1806'>1806</a>
<a id='n1807' href='#n1807'>1807</a>
<a id='n1808' href='#n1808'>1808</a>
<a id='n1809' href='#n1809'>1809</a>
<a id='n1810' href='#n1810'>1810</a>
<a id='n1811' href='#n1811'>1811</a>
<a id='n1812' href='#n1812'>1812</a>
<a id='n1813' href='#n1813'>1813</a>
<a id='n1814' href='#n1814'>1814</a>
<a id='n1815' href='#n1815'>1815</a>
<a id='n1816' href='#n1816'>1816</a>
<a id='n1817' href='#n1817'>1817</a>
<a id='n1818' href='#n1818'>1818</a>
<a id='n1819' href='#n1819'>1819</a>
<a id='n1820' href='#n1820'>1820</a>
<a id='n1821' href='#n1821'>1821</a>
<a id='n1822' href='#n1822'>1822</a>
<a id='n1823' href='#n1823'>1823</a>
<a id='n1824' href='#n1824'>1824</a>
<a id='n1825' href='#n1825'>1825</a>
<a id='n1826' href='#n1826'>1826</a>
<a id='n1827' href='#n1827'>1827</a>
<a id='n1828' href='#n1828'>1828</a>
<a id='n1829' href='#n1829'>1829</a>
<a id='n1830' href='#n1830'>1830</a>
<a id='n1831' href='#n1831'>1831</a>
<a id='n1832' href='#n1832'>1832</a>
<a id='n1833' href='#n1833'>1833</a>
<a id='n1834' href='#n1834'>1834</a>
<a id='n1835' href='#n1835'>1835</a>
<a id='n1836' href='#n1836'>1836</a>
<a id='n1837' href='#n1837'>1837</a>
<a id='n1838' href='#n1838'>1838</a>
<a id='n1839' href='#n1839'>1839</a>
<a id='n1840' href='#n1840'>1840</a>
<a id='n1841' href='#n1841'>1841</a>
<a id='n1842' href='#n1842'>1842</a>
<a id='n1843' href='#n1843'>1843</a>
<a id='n1844' href='#n1844'>1844</a>
<a id='n1845' href='#n1845'>1845</a>
<a id='n1846' href='#n1846'>1846</a>
<a id='n1847' href='#n1847'>1847</a>
<a id='n1848' href='#n1848'>1848</a>
<a id='n1849' href='#n1849'>1849</a>
<a id='n1850' href='#n1850'>1850</a>
<a id='n1851' href='#n1851'>1851</a>
<a id='n1852' href='#n1852'>1852</a>
<a id='n1853' href='#n1853'>1853</a>
<a id='n1854' href='#n1854'>1854</a>
<a id='n1855' href='#n1855'>1855</a>
<a id='n1856' href='#n1856'>1856</a>
<a id='n1857' href='#n1857'>1857</a>
<a id='n1858' href='#n1858'>1858</a>
<a id='n1859' href='#n1859'>1859</a>
<a id='n1860' href='#n1860'>1860</a>
<a id='n1861' href='#n1861'>1861</a>
<a id='n1862' href='#n1862'>1862</a>
<a id='n1863' href='#n1863'>1863</a>
<a id='n1864' href='#n1864'>1864</a>
<a id='n1865' href='#n1865'>1865</a>
<a id='n1866' href='#n1866'>1866</a>
<a id='n1867' href='#n1867'>1867</a>
<a id='n1868' href='#n1868'>1868</a>
<a id='n1869' href='#n1869'>1869</a>
<a id='n1870' href='#n1870'>1870</a>
<a id='n1871' href='#n1871'>1871</a>
<a id='n1872' href='#n1872'>1872</a>
<a id='n1873' href='#n1873'>1873</a>
<a id='n1874' href='#n1874'>1874</a>
<a id='n1875' href='#n1875'>1875</a>
<a id='n1876' href='#n1876'>1876</a>
<a id='n1877' href='#n1877'>1877</a>
<a id='n1878' href='#n1878'>1878</a>
<a id='n1879' href='#n1879'>1879</a>
<a id='n1880' href='#n1880'>1880</a>
<a id='n1881' href='#n1881'>1881</a>
<a id='n1882' href='#n1882'>1882</a>
<a id='n1883' href='#n1883'>1883</a>
<a id='n1884' href='#n1884'>1884</a>
<a id='n1885' href='#n1885'>1885</a>
<a id='n1886' href='#n1886'>1886</a>
<a id='n1887' href='#n1887'>1887</a>
<a id='n1888' href='#n1888'>1888</a>
<a id='n1889' href='#n1889'>1889</a>
<a id='n1890' href='#n1890'>1890</a>
<a id='n1891' href='#n1891'>1891</a>
<a id='n1892' href='#n1892'>1892</a>
<a id='n1893' href='#n1893'>1893</a>
<a id='n1894' href='#n1894'>1894</a>
<a id='n1895' href='#n1895'>1895</a>
<a id='n1896' href='#n1896'>1896</a>
<a id='n1897' href='#n1897'>1897</a>
<a id='n1898' href='#n1898'>1898</a>
<a id='n1899' href='#n1899'>1899</a>
<a id='n1900' href='#n1900'>1900</a>
<a id='n1901' href='#n1901'>1901</a>
<a id='n1902' href='#n1902'>1902</a>
<a id='n1903' href='#n1903'>1903</a>
<a id='n1904' href='#n1904'>1904</a>
<a id='n1905' href='#n1905'>1905</a>
<a id='n1906' href='#n1906'>1906</a>
<a id='n1907' href='#n1907'>1907</a>
<a id='n1908' href='#n1908'>1908</a>
<a id='n1909' href='#n1909'>1909</a>
<a id='n1910' href='#n1910'>1910</a>
<a id='n1911' href='#n1911'>1911</a>
<a id='n1912' href='#n1912'>1912</a>
<a id='n1913' href='#n1913'>1913</a>
<a id='n1914' href='#n1914'>1914</a>
<a id='n1915' href='#n1915'>1915</a>
<a id='n1916' href='#n1916'>1916</a>
<a id='n1917' href='#n1917'>1917</a>
<a id='n1918' href='#n1918'>1918</a>
<a id='n1919' href='#n1919'>1919</a>
<a id='n1920' href='#n1920'>1920</a>
<a id='n1921' href='#n1921'>1921</a>
<a id='n1922' href='#n1922'>1922</a>
<a id='n1923' href='#n1923'>1923</a>
<a id='n1924' href='#n1924'>1924</a>
<a id='n1925' href='#n1925'>1925</a>
<a id='n1926' href='#n1926'>1926</a>
<a id='n1927' href='#n1927'>1927</a>
<a id='n1928' href='#n1928'>1928</a>
<a id='n1929' href='#n1929'>1929</a>
<a id='n1930' href='#n1930'>1930</a>
<a id='n1931' href='#n1931'>1931</a>
<a id='n1932' href='#n1932'>1932</a>
<a id='n1933' href='#n1933'>1933</a>
<a id='n1934' href='#n1934'>1934</a>
<a id='n1935' href='#n1935'>1935</a>
<a id='n1936' href='#n1936'>1936</a>
<a id='n1937' href='#n1937'>1937</a>
<a id='n1938' href='#n1938'>1938</a>
<a id='n1939' href='#n1939'>1939</a>
<a id='n1940' href='#n1940'>1940</a>
<a id='n1941' href='#n1941'>1941</a>
<a id='n1942' href='#n1942'>1942</a>
<a id='n1943' href='#n1943'>1943</a>
<a id='n1944' href='#n1944'>1944</a>
<a id='n1945' href='#n1945'>1945</a>
<a id='n1946' href='#n1946'>1946</a>
<a id='n1947' href='#n1947'>1947</a>
<a id='n1948' href='#n1948'>1948</a>
<a id='n1949' href='#n1949'>1949</a>
<a id='n1950' href='#n1950'>1950</a>
<a id='n1951' href='#n1951'>1951</a>
<a id='n1952' href='#n1952'>1952</a>
<a id='n1953' href='#n1953'>1953</a>
<a id='n1954' href='#n1954'>1954</a>
<a id='n1955' href='#n1955'>1955</a>
<a id='n1956' href='#n1956'>1956</a>
<a id='n1957' href='#n1957'>1957</a>
<a id='n1958' href='#n1958'>1958</a>
<a id='n1959' href='#n1959'>1959</a>
<a id='n1960' href='#n1960'>1960</a>
<a id='n1961' href='#n1961'>1961</a>
<a id='n1962' href='#n1962'>1962</a>
<a id='n1963' href='#n1963'>1963</a>
<a id='n1964' href='#n1964'>1964</a>
<a id='n1965' href='#n1965'>1965</a>
<a id='n1966' href='#n1966'>1966</a>
<a id='n1967' href='#n1967'>1967</a>
<a id='n1968' href='#n1968'>1968</a>
<a id='n1969' href='#n1969'>1969</a>
<a id='n1970' href='#n1970'>1970</a>
<a id='n1971' href='#n1971'>1971</a>
<a id='n1972' href='#n1972'>1972</a>
<a id='n1973' href='#n1973'>1973</a>
<a id='n1974' href='#n1974'>1974</a>
<a id='n1975' href='#n1975'>1975</a>
<a id='n1976' href='#n1976'>1976</a>
<a id='n1977' href='#n1977'>1977</a>
<a id='n1978' href='#n1978'>1978</a>
<a id='n1979' href='#n1979'>1979</a>
<a id='n1980' href='#n1980'>1980</a>
<a id='n1981' href='#n1981'>1981</a>
<a id='n1982' href='#n1982'>1982</a>
<a id='n1983' href='#n1983'>1983</a>
<a id='n1984' href='#n1984'>1984</a>
<a id='n1985' href='#n1985'>1985</a>
<a id='n1986' href='#n1986'>1986</a>
<a id='n1987' href='#n1987'>1987</a>
<a id='n1988' href='#n1988'>1988</a>
<a id='n1989' href='#n1989'>1989</a>
<a id='n1990' href='#n1990'>1990</a>
<a id='n1991' href='#n1991'>1991</a>
<a id='n1992' href='#n1992'>1992</a>
<a id='n1993' href='#n1993'>1993</a>
<a id='n1994' href='#n1994'>1994</a>
<a id='n1995' href='#n1995'>1995</a>
<a id='n1996' href='#n1996'>1996</a>
<a id='n1997' href='#n1997'>1997</a>
<a id='n1998' href='#n1998'>1998</a>
<a id='n1999' href='#n1999'>1999</a>
<a id='n2000' href='#n2000'>2000</a>
<a id='n2001' href='#n2001'>2001</a>
<a id='n2002' href='#n2002'>2002</a>
<a id='n2003' href='#n2003'>2003</a>
<a id='n2004' href='#n2004'>2004</a>
<a id='n2005' href='#n2005'>2005</a>
<a id='n2006' href='#n2006'>2006</a>
<a id='n2007' href='#n2007'>2007</a>
<a id='n2008' href='#n2008'>2008</a>
<a id='n2009' href='#n2009'>2009</a>
<a id='n2010' href='#n2010'>2010</a>
<a id='n2011' href='#n2011'>2011</a>
<a id='n2012' href='#n2012'>2012</a>
<a id='n2013' href='#n2013'>2013</a>
<a id='n2014' href='#n2014'>2014</a>
<a id='n2015' href='#n2015'>2015</a>
<a id='n2016' href='#n2016'>2016</a>
<a id='n2017' href='#n2017'>2017</a>
<a id='n2018' href='#n2018'>2018</a>
<a id='n2019' href='#n2019'>2019</a>
<a id='n2020' href='#n2020'>2020</a>
<a id='n2021' href='#n2021'>2021</a>
<a id='n2022' href='#n2022'>2022</a>
<a id='n2023' href='#n2023'>2023</a>
<a id='n2024' href='#n2024'>2024</a>
<a id='n2025' href='#n2025'>2025</a>
<a id='n2026' href='#n2026'>2026</a>
<a id='n2027' href='#n2027'>2027</a>
<a id='n2028' href='#n2028'>2028</a>
<a id='n2029' href='#n2029'>2029</a>
<a id='n2030' href='#n2030'>2030</a>
<a id='n2031' href='#n2031'>2031</a>
<a id='n2032' href='#n2032'>2032</a>
<a id='n2033' href='#n2033'>2033</a>
<a id='n2034' href='#n2034'>2034</a>
<a id='n2035' href='#n2035'>2035</a>
<a id='n2036' href='#n2036'>2036</a>
<a id='n2037' href='#n2037'>2037</a>
<a id='n2038' href='#n2038'>2038</a>
<a id='n2039' href='#n2039'>2039</a>
<a id='n2040' href='#n2040'>2040</a>
<a id='n2041' href='#n2041'>2041</a>
<a id='n2042' href='#n2042'>2042</a>
<a id='n2043' href='#n2043'>2043</a>
<a id='n2044' href='#n2044'>2044</a>
<a id='n2045' href='#n2045'>2045</a>
<a id='n2046' href='#n2046'>2046</a>
<a id='n2047' href='#n2047'>2047</a>
<a id='n2048' href='#n2048'>2048</a>
<a id='n2049' href='#n2049'>2049</a>
<a id='n2050' href='#n2050'>2050</a>
<a id='n2051' href='#n2051'>2051</a>
<a id='n2052' href='#n2052'>2052</a>
<a id='n2053' href='#n2053'>2053</a>
<a id='n2054' href='#n2054'>2054</a>
<a id='n2055' href='#n2055'>2055</a>
<a id='n2056' href='#n2056'>2056</a>
<a id='n2057' href='#n2057'>2057</a>
<a id='n2058' href='#n2058'>2058</a>
<a id='n2059' href='#n2059'>2059</a>
<a id='n2060' href='#n2060'>2060</a>
<a id='n2061' href='#n2061'>2061</a>
<a id='n2062' href='#n2062'>2062</a>
<a id='n2063' href='#n2063'>2063</a>
<a id='n2064' href='#n2064'>2064</a>
<a id='n2065' href='#n2065'>2065</a>
<a id='n2066' href='#n2066'>2066</a>
<a id='n2067' href='#n2067'>2067</a>
<a id='n2068' href='#n2068'>2068</a>
<a id='n2069' href='#n2069'>2069</a>
<a id='n2070' href='#n2070'>2070</a>
<a id='n2071' href='#n2071'>2071</a>
<a id='n2072' href='#n2072'>2072</a>
<a id='n2073' href='#n2073'>2073</a>
<a id='n2074' href='#n2074'>2074</a>
<a id='n2075' href='#n2075'>2075</a>
<a id='n2076' href='#n2076'>2076</a>
<a id='n2077' href='#n2077'>2077</a>
<a id='n2078' href='#n2078'>2078</a>
<a id='n2079' href='#n2079'>2079</a>
<a id='n2080' href='#n2080'>2080</a>
<a id='n2081' href='#n2081'>2081</a>
<a id='n2082' href='#n2082'>2082</a>
<a id='n2083' href='#n2083'>2083</a>
<a id='n2084' href='#n2084'>2084</a>
<a id='n2085' href='#n2085'>2085</a>
<a id='n2086' href='#n2086'>2086</a>
<a id='n2087' href='#n2087'>2087</a>
<a id='n2088' href='#n2088'>2088</a>
<a id='n2089' href='#n2089'>2089</a>
<a id='n2090' href='#n2090'>2090</a>
<a id='n2091' href='#n2091'>2091</a>
<a id='n2092' href='#n2092'>2092</a>
<a id='n2093' href='#n2093'>2093</a>
<a id='n2094' href='#n2094'>2094</a>
<a id='n2095' href='#n2095'>2095</a>
<a id='n2096' href='#n2096'>2096</a>
<a id='n2097' href='#n2097'>2097</a>
<a id='n2098' href='#n2098'>2098</a>
<a id='n2099' href='#n2099'>2099</a>
<a id='n2100' href='#n2100'>2100</a>
<a id='n2101' href='#n2101'>2101</a>
<a id='n2102' href='#n2102'>2102</a>
<a id='n2103' href='#n2103'>2103</a>
<a id='n2104' href='#n2104'>2104</a>
<a id='n2105' href='#n2105'>2105</a>
<a id='n2106' href='#n2106'>2106</a>
<a id='n2107' href='#n2107'>2107</a>
<a id='n2108' href='#n2108'>2108</a>
<a id='n2109' href='#n2109'>2109</a>
<a id='n2110' href='#n2110'>2110</a>
<a id='n2111' href='#n2111'>2111</a>
<a id='n2112' href='#n2112'>2112</a>
<a id='n2113' href='#n2113'>2113</a>
<a id='n2114' href='#n2114'>2114</a>
<a id='n2115' href='#n2115'>2115</a>
<a id='n2116' href='#n2116'>2116</a>
<a id='n2117' href='#n2117'>2117</a>
<a id='n2118' href='#n2118'>2118</a>
<a id='n2119' href='#n2119'>2119</a>
<a id='n2120' href='#n2120'>2120</a>
<a id='n2121' href='#n2121'>2121</a>
<a id='n2122' href='#n2122'>2122</a>
<a id='n2123' href='#n2123'>2123</a>
<a id='n2124' href='#n2124'>2124</a>
<a id='n2125' href='#n2125'>2125</a>
<a id='n2126' href='#n2126'>2126</a>
<a id='n2127' href='#n2127'>2127</a>
<a id='n2128' href='#n2128'>2128</a>
<a id='n2129' href='#n2129'>2129</a>
<a id='n2130' href='#n2130'>2130</a>
<a id='n2131' href='#n2131'>2131</a>
<a id='n2132' href='#n2132'>2132</a>
<a id='n2133' href='#n2133'>2133</a>
<a id='n2134' href='#n2134'>2134</a>
<a id='n2135' href='#n2135'>2135</a>
<a id='n2136' href='#n2136'>2136</a>
<a id='n2137' href='#n2137'>2137</a>
<a id='n2138' href='#n2138'>2138</a>
<a id='n2139' href='#n2139'>2139</a>
<a id='n2140' href='#n2140'>2140</a>
<a id='n2141' href='#n2141'>2141</a>
<a id='n2142' href='#n2142'>2142</a>
<a id='n2143' href='#n2143'>2143</a>
<a id='n2144' href='#n2144'>2144</a>
<a id='n2145' href='#n2145'>2145</a>
<a id='n2146' href='#n2146'>2146</a>
<a id='n2147' href='#n2147'>2147</a>
<a id='n2148' href='#n2148'>2148</a>
<a id='n2149' href='#n2149'>2149</a>
<a id='n2150' href='#n2150'>2150</a>
<a id='n2151' href='#n2151'>2151</a>
<a id='n2152' href='#n2152'>2152</a>
<a id='n2153' href='#n2153'>2153</a>
<a id='n2154' href='#n2154'>2154</a>
<a id='n2155' href='#n2155'>2155</a>
<a id='n2156' href='#n2156'>2156</a>
<a id='n2157' href='#n2157'>2157</a>
<a id='n2158' href='#n2158'>2158</a>
<a id='n2159' href='#n2159'>2159</a>
<a id='n2160' href='#n2160'>2160</a>
<a id='n2161' href='#n2161'>2161</a>
<a id='n2162' href='#n2162'>2162</a>
<a id='n2163' href='#n2163'>2163</a>
<a id='n2164' href='#n2164'>2164</a>
<a id='n2165' href='#n2165'>2165</a>
<a id='n2166' href='#n2166'>2166</a>
<a id='n2167' href='#n2167'>2167</a>
<a id='n2168' href='#n2168'>2168</a>
<a id='n2169' href='#n2169'>2169</a>
<a id='n2170' href='#n2170'>2170</a>
<a id='n2171' href='#n2171'>2171</a>
<a id='n2172' href='#n2172'>2172</a>
<a id='n2173' href='#n2173'>2173</a>
<a id='n2174' href='#n2174'>2174</a>
<a id='n2175' href='#n2175'>2175</a>
<a id='n2176' href='#n2176'>2176</a>
<a id='n2177' href='#n2177'>2177</a>
<a id='n2178' href='#n2178'>2178</a>
<a id='n2179' href='#n2179'>2179</a>
<a id='n2180' href='#n2180'>2180</a>
<a id='n2181' href='#n2181'>2181</a>
<a id='n2182' href='#n2182'>2182</a>
<a id='n2183' href='#n2183'>2183</a>
<a id='n2184' href='#n2184'>2184</a>
<a id='n2185' href='#n2185'>2185</a>
<a id='n2186' href='#n2186'>2186</a>
<a id='n2187' href='#n2187'>2187</a>
<a id='n2188' href='#n2188'>2188</a>
<a id='n2189' href='#n2189'>2189</a>
<a id='n2190' href='#n2190'>2190</a>
<a id='n2191' href='#n2191'>2191</a>
<a id='n2192' href='#n2192'>2192</a>
<a id='n2193' href='#n2193'>2193</a>
<a id='n2194' href='#n2194'>2194</a>
<a id='n2195' href='#n2195'>2195</a>
<a id='n2196' href='#n2196'>2196</a>
<a id='n2197' href='#n2197'>2197</a>
<a id='n2198' href='#n2198'>2198</a>
<a id='n2199' href='#n2199'>2199</a>
<a id='n2200' href='#n2200'>2200</a>
<a id='n2201' href='#n2201'>2201</a>
<a id='n2202' href='#n2202'>2202</a>
<a id='n2203' href='#n2203'>2203</a>
<a id='n2204' href='#n2204'>2204</a>
<a id='n2205' href='#n2205'>2205</a>
<a id='n2206' href='#n2206'>2206</a>
<a id='n2207' href='#n2207'>2207</a>
<a id='n2208' href='#n2208'>2208</a>
<a id='n2209' href='#n2209'>2209</a>
<a id='n2210' href='#n2210'>2210</a>
<a id='n2211' href='#n2211'>2211</a>
<a id='n2212' href='#n2212'>2212</a>
<a id='n2213' href='#n2213'>2213</a>
<a id='n2214' href='#n2214'>2214</a>
<a id='n2215' href='#n2215'>2215</a>
<a id='n2216' href='#n2216'>2216</a>
<a id='n2217' href='#n2217'>2217</a>
<a id='n2218' href='#n2218'>2218</a>
<a id='n2219' href='#n2219'>2219</a>
<a id='n2220' href='#n2220'>2220</a>
<a id='n2221' href='#n2221'>2221</a>
<a id='n2222' href='#n2222'>2222</a>
<a id='n2223' href='#n2223'>2223</a>
<a id='n2224' href='#n2224'>2224</a>
<a id='n2225' href='#n2225'>2225</a>
<a id='n2226' href='#n2226'>2226</a>
<a id='n2227' href='#n2227'>2227</a>
<a id='n2228' href='#n2228'>2228</a>
<a id='n2229' href='#n2229'>2229</a>
<a id='n2230' href='#n2230'>2230</a>
<a id='n2231' href='#n2231'>2231</a>
<a id='n2232' href='#n2232'>2232</a>
<a id='n2233' href='#n2233'>2233</a>
<a id='n2234' href='#n2234'>2234</a>
<a id='n2235' href='#n2235'>2235</a>
<a id='n2236' href='#n2236'>2236</a>
<a id='n2237' href='#n2237'>2237</a>
<a id='n2238' href='#n2238'>2238</a>
<a id='n2239' href='#n2239'>2239</a>
<a id='n2240' href='#n2240'>2240</a>
<a id='n2241' href='#n2241'>2241</a>
<a id='n2242' href='#n2242'>2242</a>
<a id='n2243' href='#n2243'>2243</a>
<a id='n2244' href='#n2244'>2244</a>
<a id='n2245' href='#n2245'>2245</a>
<a id='n2246' href='#n2246'>2246</a>
<a id='n2247' href='#n2247'>2247</a>
<a id='n2248' href='#n2248'>2248</a>
<a id='n2249' href='#n2249'>2249</a>
<a id='n2250' href='#n2250'>2250</a>
<a id='n2251' href='#n2251'>2251</a>
<a id='n2252' href='#n2252'>2252</a>
<a id='n2253' href='#n2253'>2253</a>
<a id='n2254' href='#n2254'>2254</a>
<a id='n2255' href='#n2255'>2255</a>
<a id='n2256' href='#n2256'>2256</a>
<a id='n2257' href='#n2257'>2257</a>
<a id='n2258' href='#n2258'>2258</a>
<a id='n2259' href='#n2259'>2259</a>
<a id='n2260' href='#n2260'>2260</a>
<a id='n2261' href='#n2261'>2261</a>
<a id='n2262' href='#n2262'>2262</a>
<a id='n2263' href='#n2263'>2263</a>
<a id='n2264' href='#n2264'>2264</a>
<a id='n2265' href='#n2265'>2265</a>
<a id='n2266' href='#n2266'>2266</a>
<a id='n2267' href='#n2267'>2267</a>
<a id='n2268' href='#n2268'>2268</a>
<a id='n2269' href='#n2269'>2269</a>
<a id='n2270' href='#n2270'>2270</a>
<a id='n2271' href='#n2271'>2271</a>
<a id='n2272' href='#n2272'>2272</a>
<a id='n2273' href='#n2273'>2273</a>
<a id='n2274' href='#n2274'>2274</a>
<a id='n2275' href='#n2275'>2275</a>
<a id='n2276' href='#n2276'>2276</a>
<a id='n2277' href='#n2277'>2277</a>
<a id='n2278' href='#n2278'>2278</a>
<a id='n2279' href='#n2279'>2279</a>
<a id='n2280' href='#n2280'>2280</a>
<a id='n2281' href='#n2281'>2281</a>
<a id='n2282' href='#n2282'>2282</a>
<a id='n2283' href='#n2283'>2283</a>
<a id='n2284' href='#n2284'>2284</a>
<a id='n2285' href='#n2285'>2285</a>
<a id='n2286' href='#n2286'>2286</a>
<a id='n2287' href='#n2287'>2287</a>
<a id='n2288' href='#n2288'>2288</a>
<a id='n2289' href='#n2289'>2289</a>
<a id='n2290' href='#n2290'>2290</a>
<a id='n2291' href='#n2291'>2291</a>
<a id='n2292' href='#n2292'>2292</a>
<a id='n2293' href='#n2293'>2293</a>
<a id='n2294' href='#n2294'>2294</a>
<a id='n2295' href='#n2295'>2295</a>
<a id='n2296' href='#n2296'>2296</a>
<a id='n2297' href='#n2297'>2297</a>
<a id='n2298' href='#n2298'>2298</a>
<a id='n2299' href='#n2299'>2299</a>
<a id='n2300' href='#n2300'>2300</a>
<a id='n2301' href='#n2301'>2301</a>
<a id='n2302' href='#n2302'>2302</a>
<a id='n2303' href='#n2303'>2303</a>
<a id='n2304' href='#n2304'>2304</a>
<a id='n2305' href='#n2305'>2305</a>
<a id='n2306' href='#n2306'>2306</a>
<a id='n2307' href='#n2307'>2307</a>
<a id='n2308' href='#n2308'>2308</a>
<a id='n2309' href='#n2309'>2309</a>
<a id='n2310' href='#n2310'>2310</a>
<a id='n2311' href='#n2311'>2311</a>
<a id='n2312' href='#n2312'>2312</a>
<a id='n2313' href='#n2313'>2313</a>
<a id='n2314' href='#n2314'>2314</a>
<a id='n2315' href='#n2315'>2315</a>
<a id='n2316' href='#n2316'>2316</a>
<a id='n2317' href='#n2317'>2317</a>
<a id='n2318' href='#n2318'>2318</a>
<a id='n2319' href='#n2319'>2319</a>
<a id='n2320' href='#n2320'>2320</a>
<a id='n2321' href='#n2321'>2321</a>
<a id='n2322' href='#n2322'>2322</a>
<a id='n2323' href='#n2323'>2323</a>
<a id='n2324' href='#n2324'>2324</a>
<a id='n2325' href='#n2325'>2325</a>
<a id='n2326' href='#n2326'>2326</a>
<a id='n2327' href='#n2327'>2327</a>
<a id='n2328' href='#n2328'>2328</a>
<a id='n2329' href='#n2329'>2329</a>
<a id='n2330' href='#n2330'>2330</a>
<a id='n2331' href='#n2331'>2331</a>
<a id='n2332' href='#n2332'>2332</a>
<a id='n2333' href='#n2333'>2333</a>
<a id='n2334' href='#n2334'>2334</a>
<a id='n2335' href='#n2335'>2335</a>
<a id='n2336' href='#n2336'>2336</a>
<a id='n2337' href='#n2337'>2337</a>
<a id='n2338' href='#n2338'>2338</a>
<a id='n2339' href='#n2339'>2339</a>
<a id='n2340' href='#n2340'>2340</a>
<a id='n2341' href='#n2341'>2341</a>
<a id='n2342' href='#n2342'>2342</a>
<a id='n2343' href='#n2343'>2343</a>
<a id='n2344' href='#n2344'>2344</a>
<a id='n2345' href='#n2345'>2345</a>
<a id='n2346' href='#n2346'>2346</a>
<a id='n2347' href='#n2347'>2347</a>
<a id='n2348' href='#n2348'>2348</a>
<a id='n2349' href='#n2349'>2349</a>
<a id='n2350' href='#n2350'>2350</a>
<a id='n2351' href='#n2351'>2351</a>
<a id='n2352' href='#n2352'>2352</a>
<a id='n2353' href='#n2353'>2353</a>
<a id='n2354' href='#n2354'>2354</a>
<a id='n2355' href='#n2355'>2355</a>
<a id='n2356' href='#n2356'>2356</a>
<a id='n2357' href='#n2357'>2357</a>
<a id='n2358' href='#n2358'>2358</a>
<a id='n2359' href='#n2359'>2359</a>
<a id='n2360' href='#n2360'>2360</a>
<a id='n2361' href='#n2361'>2361</a>
<a id='n2362' href='#n2362'>2362</a>
<a id='n2363' href='#n2363'>2363</a>
<a id='n2364' href='#n2364'>2364</a>
<a id='n2365' href='#n2365'>2365</a>
<a id='n2366' href='#n2366'>2366</a>
<a id='n2367' href='#n2367'>2367</a>
<a id='n2368' href='#n2368'>2368</a>
<a id='n2369' href='#n2369'>2369</a>
<a id='n2370' href='#n2370'>2370</a>
<a id='n2371' href='#n2371'>2371</a>
<a id='n2372' href='#n2372'>2372</a>
<a id='n2373' href='#n2373'>2373</a>
<a id='n2374' href='#n2374'>2374</a>
<a id='n2375' href='#n2375'>2375</a>
<a id='n2376' href='#n2376'>2376</a>
<a id='n2377' href='#n2377'>2377</a>
<a id='n2378' href='#n2378'>2378</a>
<a id='n2379' href='#n2379'>2379</a>
<a id='n2380' href='#n2380'>2380</a>
<a id='n2381' href='#n2381'>2381</a>
<a id='n2382' href='#n2382'>2382</a>
<a id='n2383' href='#n2383'>2383</a>
<a id='n2384' href='#n2384'>2384</a>
<a id='n2385' href='#n2385'>2385</a>
<a id='n2386' href='#n2386'>2386</a>
<a id='n2387' href='#n2387'>2387</a>
<a id='n2388' href='#n2388'>2388</a>
<a id='n2389' href='#n2389'>2389</a>
<a id='n2390' href='#n2390'>2390</a>
<a id='n2391' href='#n2391'>2391</a>
<a id='n2392' href='#n2392'>2392</a>
<a id='n2393' href='#n2393'>2393</a>
<a id='n2394' href='#n2394'>2394</a>
<a id='n2395' href='#n2395'>2395</a>
<a id='n2396' href='#n2396'>2396</a>
<a id='n2397' href='#n2397'>2397</a>
<a id='n2398' href='#n2398'>2398</a>
<a id='n2399' href='#n2399'>2399</a>
<a id='n2400' href='#n2400'>2400</a>
<a id='n2401' href='#n2401'>2401</a>
<a id='n2402' href='#n2402'>2402</a>
<a id='n2403' href='#n2403'>2403</a>
<a id='n2404' href='#n2404'>2404</a>
<a id='n2405' href='#n2405'>2405</a>
<a id='n2406' href='#n2406'>2406</a>
<a id='n2407' href='#n2407'>2407</a>
<a id='n2408' href='#n2408'>2408</a>
<a id='n2409' href='#n2409'>2409</a>
<a id='n2410' href='#n2410'>2410</a>
<a id='n2411' href='#n2411'>2411</a>
<a id='n2412' href='#n2412'>2412</a>
<a id='n2413' href='#n2413'>2413</a>
<a id='n2414' href='#n2414'>2414</a>
<a id='n2415' href='#n2415'>2415</a>
<a id='n2416' href='#n2416'>2416</a>
<a id='n2417' href='#n2417'>2417</a>
<a id='n2418' href='#n2418'>2418</a>
<a id='n2419' href='#n2419'>2419</a>
<a id='n2420' href='#n2420'>2420</a>
<a id='n2421' href='#n2421'>2421</a>
<a id='n2422' href='#n2422'>2422</a>
<a id='n2423' href='#n2423'>2423</a>
<a id='n2424' href='#n2424'>2424</a>
<a id='n2425' href='#n2425'>2425</a>
<a id='n2426' href='#n2426'>2426</a>
<a id='n2427' href='#n2427'>2427</a>
<a id='n2428' href='#n2428'>2428</a>
<a id='n2429' href='#n2429'>2429</a>
<a id='n2430' href='#n2430'>2430</a>
<a id='n2431' href='#n2431'>2431</a>
<a id='n2432' href='#n2432'>2432</a>
<a id='n2433' href='#n2433'>2433</a>
<a id='n2434' href='#n2434'>2434</a>
<a id='n2435' href='#n2435'>2435</a>
<a id='n2436' href='#n2436'>2436</a>
<a id='n2437' href='#n2437'>2437</a>
<a id='n2438' href='#n2438'>2438</a>
<a id='n2439' href='#n2439'>2439</a>
<a id='n2440' href='#n2440'>2440</a>
<a id='n2441' href='#n2441'>2441</a>
<a id='n2442' href='#n2442'>2442</a>
<a id='n2443' href='#n2443'>2443</a>
<a id='n2444' href='#n2444'>2444</a>
<a id='n2445' href='#n2445'>2445</a>
<a id='n2446' href='#n2446'>2446</a>
<a id='n2447' href='#n2447'>2447</a>
<a id='n2448' href='#n2448'>2448</a>
<a id='n2449' href='#n2449'>2449</a>
<a id='n2450' href='#n2450'>2450</a>
<a id='n2451' href='#n2451'>2451</a>
<a id='n2452' href='#n2452'>2452</a>
<a id='n2453' href='#n2453'>2453</a>
<a id='n2454' href='#n2454'>2454</a>
<a id='n2455' href='#n2455'>2455</a>
<a id='n2456' href='#n2456'>2456</a>
<a id='n2457' href='#n2457'>2457</a>
<a id='n2458' href='#n2458'>2458</a>
<a id='n2459' href='#n2459'>2459</a>
<a id='n2460' href='#n2460'>2460</a>
<a id='n2461' href='#n2461'>2461</a>
<a id='n2462' href='#n2462'>2462</a>
<a id='n2463' href='#n2463'>2463</a>
<a id='n2464' href='#n2464'>2464</a>
<a id='n2465' href='#n2465'>2465</a>
<a id='n2466' href='#n2466'>2466</a>
<a id='n2467' href='#n2467'>2467</a>
<a id='n2468' href='#n2468'>2468</a>
<a id='n2469' href='#n2469'>2469</a>
<a id='n2470' href='#n2470'>2470</a>
<a id='n2471' href='#n2471'>2471</a>
<a id='n2472' href='#n2472'>2472</a>
<a id='n2473' href='#n2473'>2473</a>
<a id='n2474' href='#n2474'>2474</a>
<a id='n2475' href='#n2475'>2475</a>
<a id='n2476' href='#n2476'>2476</a>
<a id='n2477' href='#n2477'>2477</a>
<a id='n2478' href='#n2478'>2478</a>
<a id='n2479' href='#n2479'>2479</a>
<a id='n2480' href='#n2480'>2480</a>
<a id='n2481' href='#n2481'>2481</a>
<a id='n2482' href='#n2482'>2482</a>
<a id='n2483' href='#n2483'>2483</a>
<a id='n2484' href='#n2484'>2484</a>
<a id='n2485' href='#n2485'>2485</a>
<a id='n2486' href='#n2486'>2486</a>
<a id='n2487' href='#n2487'>2487</a>
<a id='n2488' href='#n2488'>2488</a>
<a id='n2489' href='#n2489'>2489</a>
<a id='n2490' href='#n2490'>2490</a>
<a id='n2491' href='#n2491'>2491</a>
<a id='n2492' href='#n2492'>2492</a>
<a id='n2493' href='#n2493'>2493</a>
<a id='n2494' href='#n2494'>2494</a>
<a id='n2495' href='#n2495'>2495</a>
<a id='n2496' href='#n2496'>2496</a>
<a id='n2497' href='#n2497'>2497</a>
<a id='n2498' href='#n2498'>2498</a>
<a id='n2499' href='#n2499'>2499</a>
<a id='n2500' href='#n2500'>2500</a>
<a id='n2501' href='#n2501'>2501</a>
<a id='n2502' href='#n2502'>2502</a>
<a id='n2503' href='#n2503'>2503</a>
<a id='n2504' href='#n2504'>2504</a>
<a id='n2505' href='#n2505'>2505</a>
<a id='n2506' href='#n2506'>2506</a>
<a id='n2507' href='#n2507'>2507</a>
<a id='n2508' href='#n2508'>2508</a>
<a id='n2509' href='#n2509'>2509</a>
<a id='n2510' href='#n2510'>2510</a>
<a id='n2511' href='#n2511'>2511</a>
<a id='n2512' href='#n2512'>2512</a>
<a id='n2513' href='#n2513'>2513</a>
<a id='n2514' href='#n2514'>2514</a>
<a id='n2515' href='#n2515'>2515</a>
<a id='n2516' href='#n2516'>2516</a>
<a id='n2517' href='#n2517'>2517</a>
<a id='n2518' href='#n2518'>2518</a>
<a id='n2519' href='#n2519'>2519</a>
<a id='n2520' href='#n2520'>2520</a>
<a id='n2521' href='#n2521'>2521</a>
<a id='n2522' href='#n2522'>2522</a>
<a id='n2523' href='#n2523'>2523</a>
<a id='n2524' href='#n2524'>2524</a>
<a id='n2525' href='#n2525'>2525</a>
<a id='n2526' href='#n2526'>2526</a>
<a id='n2527' href='#n2527'>2527</a>
<a id='n2528' href='#n2528'>2528</a>
<a id='n2529' href='#n2529'>2529</a>
<a id='n2530' href='#n2530'>2530</a>
<a id='n2531' href='#n2531'>2531</a>
<a id='n2532' href='#n2532'>2532</a>
<a id='n2533' href='#n2533'>2533</a>
<a id='n2534' href='#n2534'>2534</a>
<a id='n2535' href='#n2535'>2535</a>
<a id='n2536' href='#n2536'>2536</a>
<a id='n2537' href='#n2537'>2537</a>
<a id='n2538' href='#n2538'>2538</a>
<a id='n2539' href='#n2539'>2539</a>
<a id='n2540' href='#n2540'>2540</a>
<a id='n2541' href='#n2541'>2541</a>
<a id='n2542' href='#n2542'>2542</a>
<a id='n2543' href='#n2543'>2543</a>
<a id='n2544' href='#n2544'>2544</a>
<a id='n2545' href='#n2545'>2545</a>
<a id='n2546' href='#n2546'>2546</a>
<a id='n2547' href='#n2547'>2547</a>
<a id='n2548' href='#n2548'>2548</a>
<a id='n2549' href='#n2549'>2549</a>
<a id='n2550' href='#n2550'>2550</a>
<a id='n2551' href='#n2551'>2551</a>
<a id='n2552' href='#n2552'>2552</a>
<a id='n2553' href='#n2553'>2553</a>
<a id='n2554' href='#n2554'>2554</a>
<a id='n2555' href='#n2555'>2555</a>
<a id='n2556' href='#n2556'>2556</a>
<a id='n2557' href='#n2557'>2557</a>
<a id='n2558' href='#n2558'>2558</a>
<a id='n2559' href='#n2559'>2559</a>
<a id='n2560' href='#n2560'>2560</a>
<a id='n2561' href='#n2561'>2561</a>
<a id='n2562' href='#n2562'>2562</a>
<a id='n2563' href='#n2563'>2563</a>
<a id='n2564' href='#n2564'>2564</a>
<a id='n2565' href='#n2565'>2565</a>
<a id='n2566' href='#n2566'>2566</a>
<a id='n2567' href='#n2567'>2567</a>
<a id='n2568' href='#n2568'>2568</a>
<a id='n2569' href='#n2569'>2569</a>
<a id='n2570' href='#n2570'>2570</a>
<a id='n2571' href='#n2571'>2571</a>
<a id='n2572' href='#n2572'>2572</a>
<a id='n2573' href='#n2573'>2573</a>
<a id='n2574' href='#n2574'>2574</a>
<a id='n2575' href='#n2575'>2575</a>
<a id='n2576' href='#n2576'>2576</a>
<a id='n2577' href='#n2577'>2577</a>
<a id='n2578' href='#n2578'>2578</a>
<a id='n2579' href='#n2579'>2579</a>
<a id='n2580' href='#n2580'>2580</a>
<a id='n2581' href='#n2581'>2581</a>
<a id='n2582' href='#n2582'>2582</a>
<a id='n2583' href='#n2583'>2583</a>
<a id='n2584' href='#n2584'>2584</a>
<a id='n2585' href='#n2585'>2585</a>
<a id='n2586' href='#n2586'>2586</a>
<a id='n2587' href='#n2587'>2587</a>
<a id='n2588' href='#n2588'>2588</a>
<a id='n2589' href='#n2589'>2589</a>
<a id='n2590' href='#n2590'>2590</a>
<a id='n2591' href='#n2591'>2591</a>
<a id='n2592' href='#n2592'>2592</a>
<a id='n2593' href='#n2593'>2593</a>
<a id='n2594' href='#n2594'>2594</a>
<a id='n2595' href='#n2595'>2595</a>
<a id='n2596' href='#n2596'>2596</a>
<a id='n2597' href='#n2597'>2597</a>
<a id='n2598' href='#n2598'>2598</a>
<a id='n2599' href='#n2599'>2599</a>
<a id='n2600' href='#n2600'>2600</a>
<a id='n2601' href='#n2601'>2601</a>
<a id='n2602' href='#n2602'>2602</a>
<a id='n2603' href='#n2603'>2603</a>
<a id='n2604' href='#n2604'>2604</a>
<a id='n2605' href='#n2605'>2605</a>
<a id='n2606' href='#n2606'>2606</a>
<a id='n2607' href='#n2607'>2607</a>
<a id='n2608' href='#n2608'>2608</a>
<a id='n2609' href='#n2609'>2609</a>
<a id='n2610' href='#n2610'>2610</a>
<a id='n2611' href='#n2611'>2611</a>
<a id='n2612' href='#n2612'>2612</a>
<a id='n2613' href='#n2613'>2613</a>
<a id='n2614' href='#n2614'>2614</a>
<a id='n2615' href='#n2615'>2615</a>
<a id='n2616' href='#n2616'>2616</a>
<a id='n2617' href='#n2617'>2617</a>
<a id='n2618' href='#n2618'>2618</a>
<a id='n2619' href='#n2619'>2619</a>
<a id='n2620' href='#n2620'>2620</a>
<a id='n2621' href='#n2621'>2621</a>
<a id='n2622' href='#n2622'>2622</a>
<a id='n2623' href='#n2623'>2623</a>
<a id='n2624' href='#n2624'>2624</a>
<a id='n2625' href='#n2625'>2625</a>
<a id='n2626' href='#n2626'>2626</a>
<a id='n2627' href='#n2627'>2627</a>
<a id='n2628' href='#n2628'>2628</a>
<a id='n2629' href='#n2629'>2629</a>
<a id='n2630' href='#n2630'>2630</a>
<a id='n2631' href='#n2631'>2631</a>
<a id='n2632' href='#n2632'>2632</a>
<a id='n2633' href='#n2633'>2633</a>
<a id='n2634' href='#n2634'>2634</a>
<a id='n2635' href='#n2635'>2635</a>
<a id='n2636' href='#n2636'>2636</a>
<a id='n2637' href='#n2637'>2637</a>
<a id='n2638' href='#n2638'>2638</a>
<a id='n2639' href='#n2639'>2639</a>
<a id='n2640' href='#n2640'>2640</a>
<a id='n2641' href='#n2641'>2641</a>
<a id='n2642' href='#n2642'>2642</a>
<a id='n2643' href='#n2643'>2643</a>
<a id='n2644' href='#n2644'>2644</a>
<a id='n2645' href='#n2645'>2645</a>
<a id='n2646' href='#n2646'>2646</a>
<a id='n2647' href='#n2647'>2647</a>
<a id='n2648' href='#n2648'>2648</a>
<a id='n2649' href='#n2649'>2649</a>
<a id='n2650' href='#n2650'>2650</a>
<a id='n2651' href='#n2651'>2651</a>
<a id='n2652' href='#n2652'>2652</a>
<a id='n2653' href='#n2653'>2653</a>
<a id='n2654' href='#n2654'>2654</a>
<a id='n2655' href='#n2655'>2655</a>
<a id='n2656' href='#n2656'>2656</a>
<a id='n2657' href='#n2657'>2657</a>
<a id='n2658' href='#n2658'>2658</a>
<a id='n2659' href='#n2659'>2659</a>
<a id='n2660' href='#n2660'>2660</a>
<a id='n2661' href='#n2661'>2661</a>
<a id='n2662' href='#n2662'>2662</a>
<a id='n2663' href='#n2663'>2663</a>
<a id='n2664' href='#n2664'>2664</a>
<a id='n2665' href='#n2665'>2665</a>
<a id='n2666' href='#n2666'>2666</a>
<a id='n2667' href='#n2667'>2667</a>
<a id='n2668' href='#n2668'>2668</a>
<a id='n2669' href='#n2669'>2669</a>
<a id='n2670' href='#n2670'>2670</a>
<a id='n2671' href='#n2671'>2671</a>
<a id='n2672' href='#n2672'>2672</a>
<a id='n2673' href='#n2673'>2673</a>
<a id='n2674' href='#n2674'>2674</a>
<a id='n2675' href='#n2675'>2675</a>
<a id='n2676' href='#n2676'>2676</a>
<a id='n2677' href='#n2677'>2677</a>
<a id='n2678' href='#n2678'>2678</a>
<a id='n2679' href='#n2679'>2679</a>
<a id='n2680' href='#n2680'>2680</a>
<a id='n2681' href='#n2681'>2681</a>
<a id='n2682' href='#n2682'>2682</a>
<a id='n2683' href='#n2683'>2683</a>
<a id='n2684' href='#n2684'>2684</a>
<a id='n2685' href='#n2685'>2685</a>
<a id='n2686' href='#n2686'>2686</a>
<a id='n2687' href='#n2687'>2687</a>
<a id='n2688' href='#n2688'>2688</a>
<a id='n2689' href='#n2689'>2689</a>
<a id='n2690' href='#n2690'>2690</a>
<a id='n2691' href='#n2691'>2691</a>
<a id='n2692' href='#n2692'>2692</a>
<a id='n2693' href='#n2693'>2693</a>
<a id='n2694' href='#n2694'>2694</a>
<a id='n2695' href='#n2695'>2695</a>
<a id='n2696' href='#n2696'>2696</a>
<a id='n2697' href='#n2697'>2697</a>
<a id='n2698' href='#n2698'>2698</a>
<a id='n2699' href='#n2699'>2699</a>
<a id='n2700' href='#n2700'>2700</a>
<a id='n2701' href='#n2701'>2701</a>
<a id='n2702' href='#n2702'>2702</a>
<a id='n2703' href='#n2703'>2703</a>
<a id='n2704' href='#n2704'>2704</a>
<a id='n2705' href='#n2705'>2705</a>
<a id='n2706' href='#n2706'>2706</a>
<a id='n2707' href='#n2707'>2707</a>
<a id='n2708' href='#n2708'>2708</a>
<a id='n2709' href='#n2709'>2709</a>
<a id='n2710' href='#n2710'>2710</a>
<a id='n2711' href='#n2711'>2711</a>
<a id='n2712' href='#n2712'>2712</a>
<a id='n2713' href='#n2713'>2713</a>
<a id='n2714' href='#n2714'>2714</a>
<a id='n2715' href='#n2715'>2715</a>
<a id='n2716' href='#n2716'>2716</a>
<a id='n2717' href='#n2717'>2717</a>
<a id='n2718' href='#n2718'>2718</a>
<a id='n2719' href='#n2719'>2719</a>
<a id='n2720' href='#n2720'>2720</a>
<a id='n2721' href='#n2721'>2721</a>
<a id='n2722' href='#n2722'>2722</a>
<a id='n2723' href='#n2723'>2723</a>
<a id='n2724' href='#n2724'>2724</a>
<a id='n2725' href='#n2725'>2725</a>
<a id='n2726' href='#n2726'>2726</a>
<a id='n2727' href='#n2727'>2727</a>
<a id='n2728' href='#n2728'>2728</a>
<a id='n2729' href='#n2729'>2729</a>
<a id='n2730' href='#n2730'>2730</a>
<a id='n2731' href='#n2731'>2731</a>
<a id='n2732' href='#n2732'>2732</a>
<a id='n2733' href='#n2733'>2733</a>
<a id='n2734' href='#n2734'>2734</a>
<a id='n2735' href='#n2735'>2735</a>
<a id='n2736' href='#n2736'>2736</a>
<a id='n2737' href='#n2737'>2737</a>
<a id='n2738' href='#n2738'>2738</a>
<a id='n2739' href='#n2739'>2739</a>
<a id='n2740' href='#n2740'>2740</a>
<a id='n2741' href='#n2741'>2741</a>
<a id='n2742' href='#n2742'>2742</a>
<a id='n2743' href='#n2743'>2743</a>
<a id='n2744' href='#n2744'>2744</a>
<a id='n2745' href='#n2745'>2745</a>
<a id='n2746' href='#n2746'>2746</a>
<a id='n2747' href='#n2747'>2747</a>
<a id='n2748' href='#n2748'>2748</a>
<a id='n2749' href='#n2749'>2749</a>
<a id='n2750' href='#n2750'>2750</a>
<a id='n2751' href='#n2751'>2751</a>
<a id='n2752' href='#n2752'>2752</a>
<a id='n2753' href='#n2753'>2753</a>
<a id='n2754' href='#n2754'>2754</a>
<a id='n2755' href='#n2755'>2755</a>
<a id='n2756' href='#n2756'>2756</a>
<a id='n2757' href='#n2757'>2757</a>
<a id='n2758' href='#n2758'>2758</a>
<a id='n2759' href='#n2759'>2759</a>
<a id='n2760' href='#n2760'>2760</a>
<a id='n2761' href='#n2761'>2761</a>
<a id='n2762' href='#n2762'>2762</a>
<a id='n2763' href='#n2763'>2763</a>
<a id='n2764' href='#n2764'>2764</a>
<a id='n2765' href='#n2765'>2765</a>
<a id='n2766' href='#n2766'>2766</a>
<a id='n2767' href='#n2767'>2767</a>
<a id='n2768' href='#n2768'>2768</a>
<a id='n2769' href='#n2769'>2769</a>
<a id='n2770' href='#n2770'>2770</a>
<a id='n2771' href='#n2771'>2771</a>
<a id='n2772' href='#n2772'>2772</a>
<a id='n2773' href='#n2773'>2773</a>
<a id='n2774' href='#n2774'>2774</a>
<a id='n2775' href='#n2775'>2775</a>
<a id='n2776' href='#n2776'>2776</a>
<a id='n2777' href='#n2777'>2777</a>
<a id='n2778' href='#n2778'>2778</a>
<a id='n2779' href='#n2779'>2779</a>
<a id='n2780' href='#n2780'>2780</a>
<a id='n2781' href='#n2781'>2781</a>
<a id='n2782' href='#n2782'>2782</a>
<a id='n2783' href='#n2783'>2783</a>
<a id='n2784' href='#n2784'>2784</a>
<a id='n2785' href='#n2785'>2785</a>
<a id='n2786' href='#n2786'>2786</a>
<a id='n2787' href='#n2787'>2787</a>
<a id='n2788' href='#n2788'>2788</a>
<a id='n2789' href='#n2789'>2789</a>
<a id='n2790' href='#n2790'>2790</a>
<a id='n2791' href='#n2791'>2791</a>
<a id='n2792' href='#n2792'>2792</a>
<a id='n2793' href='#n2793'>2793</a>
<a id='n2794' href='#n2794'>2794</a>
<a id='n2795' href='#n2795'>2795</a>
<a id='n2796' href='#n2796'>2796</a>
<a id='n2797' href='#n2797'>2797</a>
<a id='n2798' href='#n2798'>2798</a>
<a id='n2799' href='#n2799'>2799</a>
<a id='n2800' href='#n2800'>2800</a>
<a id='n2801' href='#n2801'>2801</a>
<a id='n2802' href='#n2802'>2802</a>
<a id='n2803' href='#n2803'>2803</a>
<a id='n2804' href='#n2804'>2804</a>
<a id='n2805' href='#n2805'>2805</a>
<a id='n2806' href='#n2806'>2806</a>
<a id='n2807' href='#n2807'>2807</a>
<a id='n2808' href='#n2808'>2808</a>
<a id='n2809' href='#n2809'>2809</a>
<a id='n2810' href='#n2810'>2810</a>
<a id='n2811' href='#n2811'>2811</a>
<a id='n2812' href='#n2812'>2812</a>
<a id='n2813' href='#n2813'>2813</a>
<a id='n2814' href='#n2814'>2814</a>
<a id='n2815' href='#n2815'>2815</a>
<a id='n2816' href='#n2816'>2816</a>
<a id='n2817' href='#n2817'>2817</a>
<a id='n2818' href='#n2818'>2818</a>
<a id='n2819' href='#n2819'>2819</a>
<a id='n2820' href='#n2820'>2820</a>
<a id='n2821' href='#n2821'>2821</a>
<a id='n2822' href='#n2822'>2822</a>
<a id='n2823' href='#n2823'>2823</a>
<a id='n2824' href='#n2824'>2824</a>
<a id='n2825' href='#n2825'>2825</a>
<a id='n2826' href='#n2826'>2826</a>
<a id='n2827' href='#n2827'>2827</a>
<a id='n2828' href='#n2828'>2828</a>
<a id='n2829' href='#n2829'>2829</a>
<a id='n2830' href='#n2830'>2830</a>
<a id='n2831' href='#n2831'>2831</a>
<a id='n2832' href='#n2832'>2832</a>
<a id='n2833' href='#n2833'>2833</a>
<a id='n2834' href='#n2834'>2834</a>
<a id='n2835' href='#n2835'>2835</a>
<a id='n2836' href='#n2836'>2836</a>
<a id='n2837' href='#n2837'>2837</a>
<a id='n2838' href='#n2838'>2838</a>
<a id='n2839' href='#n2839'>2839</a>
<a id='n2840' href='#n2840'>2840</a>
<a id='n2841' href='#n2841'>2841</a>
<a id='n2842' href='#n2842'>2842</a>
<a id='n2843' href='#n2843'>2843</a>
<a id='n2844' href='#n2844'>2844</a>
<a id='n2845' href='#n2845'>2845</a>
<a id='n2846' href='#n2846'>2846</a>
<a id='n2847' href='#n2847'>2847</a>
<a id='n2848' href='#n2848'>2848</a>
<a id='n2849' href='#n2849'>2849</a>
<a id='n2850' href='#n2850'>2850</a>
<a id='n2851' href='#n2851'>2851</a>
<a id='n2852' href='#n2852'>2852</a>
<a id='n2853' href='#n2853'>2853</a>
<a id='n2854' href='#n2854'>2854</a>
<a id='n2855' href='#n2855'>2855</a>
<a id='n2856' href='#n2856'>2856</a>
<a id='n2857' href='#n2857'>2857</a>
<a id='n2858' href='#n2858'>2858</a>
<a id='n2859' href='#n2859'>2859</a>
<a id='n2860' href='#n2860'>2860</a>
<a id='n2861' href='#n2861'>2861</a>
<a id='n2862' href='#n2862'>2862</a>
<a id='n2863' href='#n2863'>2863</a>
<a id='n2864' href='#n2864'>2864</a>
<a id='n2865' href='#n2865'>2865</a>
<a id='n2866' href='#n2866'>2866</a>
<a id='n2867' href='#n2867'>2867</a>
<a id='n2868' href='#n2868'>2868</a>
<a id='n2869' href='#n2869'>2869</a>
<a id='n2870' href='#n2870'>2870</a>
<a id='n2871' href='#n2871'>2871</a>
<a id='n2872' href='#n2872'>2872</a>
<a id='n2873' href='#n2873'>2873</a>
<a id='n2874' href='#n2874'>2874</a>
<a id='n2875' href='#n2875'>2875</a>
<a id='n2876' href='#n2876'>2876</a>
<a id='n2877' href='#n2877'>2877</a>
<a id='n2878' href='#n2878'>2878</a>
<a id='n2879' href='#n2879'>2879</a>
<a id='n2880' href='#n2880'>2880</a>
<a id='n2881' href='#n2881'>2881</a>
<a id='n2882' href='#n2882'>2882</a>
<a id='n2883' href='#n2883'>2883</a>
<a id='n2884' href='#n2884'>2884</a>
<a id='n2885' href='#n2885'>2885</a>
<a id='n2886' href='#n2886'>2886</a>
<a id='n2887' href='#n2887'>2887</a>
<a id='n2888' href='#n2888'>2888</a>
<a id='n2889' href='#n2889'>2889</a>
<a id='n2890' href='#n2890'>2890</a>
<a id='n2891' href='#n2891'>2891</a>
<a id='n2892' href='#n2892'>2892</a>
<a id='n2893' href='#n2893'>2893</a>
<a id='n2894' href='#n2894'>2894</a>
<a id='n2895' href='#n2895'>2895</a>
<a id='n2896' href='#n2896'>2896</a>
<a id='n2897' href='#n2897'>2897</a>
<a id='n2898' href='#n2898'>2898</a>
<a id='n2899' href='#n2899'>2899</a>
<a id='n2900' href='#n2900'>2900</a>
<a id='n2901' href='#n2901'>2901</a>
<a id='n2902' href='#n2902'>2902</a>
<a id='n2903' href='#n2903'>2903</a>
<a id='n2904' href='#n2904'>2904</a>
<a id='n2905' href='#n2905'>2905</a>
<a id='n2906' href='#n2906'>2906</a>
<a id='n2907' href='#n2907'>2907</a>
<a id='n2908' href='#n2908'>2908</a>
<a id='n2909' href='#n2909'>2909</a>
<a id='n2910' href='#n2910'>2910</a>
<a id='n2911' href='#n2911'>2911</a>
<a id='n2912' href='#n2912'>2912</a>
<a id='n2913' href='#n2913'>2913</a>
<a id='n2914' href='#n2914'>2914</a>
<a id='n2915' href='#n2915'>2915</a>
<a id='n2916' href='#n2916'>2916</a>
<a id='n2917' href='#n2917'>2917</a>
<a id='n2918' href='#n2918'>2918</a>
<a id='n2919' href='#n2919'>2919</a>
<a id='n2920' href='#n2920'>2920</a>
<a id='n2921' href='#n2921'>2921</a>
<a id='n2922' href='#n2922'>2922</a>
<a id='n2923' href='#n2923'>2923</a>
<a id='n2924' href='#n2924'>2924</a>
<a id='n2925' href='#n2925'>2925</a>
<a id='n2926' href='#n2926'>2926</a>
<a id='n2927' href='#n2927'>2927</a>
<a id='n2928' href='#n2928'>2928</a>
<a id='n2929' href='#n2929'>2929</a>
<a id='n2930' href='#n2930'>2930</a>
<a id='n2931' href='#n2931'>2931</a>
<a id='n2932' href='#n2932'>2932</a>
<a id='n2933' href='#n2933'>2933</a>
<a id='n2934' href='#n2934'>2934</a>
<a id='n2935' href='#n2935'>2935</a>
<a id='n2936' href='#n2936'>2936</a>
<a id='n2937' href='#n2937'>2937</a>
<a id='n2938' href='#n2938'>2938</a>
<a id='n2939' href='#n2939'>2939</a>
<a id='n2940' href='#n2940'>2940</a>
<a id='n2941' href='#n2941'>2941</a>
<a id='n2942' href='#n2942'>2942</a>
<a id='n2943' href='#n2943'>2943</a>
<a id='n2944' href='#n2944'>2944</a>
<a id='n2945' href='#n2945'>2945</a>
<a id='n2946' href='#n2946'>2946</a>
<a id='n2947' href='#n2947'>2947</a>
<a id='n2948' href='#n2948'>2948</a>
<a id='n2949' href='#n2949'>2949</a>
<a id='n2950' href='#n2950'>2950</a>
<a id='n2951' href='#n2951'>2951</a>
<a id='n2952' href='#n2952'>2952</a>
<a id='n2953' href='#n2953'>2953</a>
<a id='n2954' href='#n2954'>2954</a>
<a id='n2955' href='#n2955'>2955</a>
<a id='n2956' href='#n2956'>2956</a>
<a id='n2957' href='#n2957'>2957</a>
<a id='n2958' href='#n2958'>2958</a>
<a id='n2959' href='#n2959'>2959</a>
<a id='n2960' href='#n2960'>2960</a>
<a id='n2961' href='#n2961'>2961</a>
<a id='n2962' href='#n2962'>2962</a>
<a id='n2963' href='#n2963'>2963</a>
<a id='n2964' href='#n2964'>2964</a>
<a id='n2965' href='#n2965'>2965</a>
<a id='n2966' href='#n2966'>2966</a>
<a id='n2967' href='#n2967'>2967</a>
<a id='n2968' href='#n2968'>2968</a>
<a id='n2969' href='#n2969'>2969</a>
<a id='n2970' href='#n2970'>2970</a>
<a id='n2971' href='#n2971'>2971</a>
<a id='n2972' href='#n2972'>2972</a>
<a id='n2973' href='#n2973'>2973</a>
<a id='n2974' href='#n2974'>2974</a>
<a id='n2975' href='#n2975'>2975</a>
<a id='n2976' href='#n2976'>2976</a>
<a id='n2977' href='#n2977'>2977</a>
<a id='n2978' href='#n2978'>2978</a>
<a id='n2979' href='#n2979'>2979</a>
<a id='n2980' href='#n2980'>2980</a>
<a id='n2981' href='#n2981'>2981</a>
<a id='n2982' href='#n2982'>2982</a>
<a id='n2983' href='#n2983'>2983</a>
<a id='n2984' href='#n2984'>2984</a>
<a id='n2985' href='#n2985'>2985</a>
<a id='n2986' href='#n2986'>2986</a>
<a id='n2987' href='#n2987'>2987</a>
<a id='n2988' href='#n2988'>2988</a>
<a id='n2989' href='#n2989'>2989</a>
<a id='n2990' href='#n2990'>2990</a>
<a id='n2991' href='#n2991'>2991</a>
<a id='n2992' href='#n2992'>2992</a>
<a id='n2993' href='#n2993'>2993</a>
<a id='n2994' href='#n2994'>2994</a>
<a id='n2995' href='#n2995'>2995</a>
<a id='n2996' href='#n2996'>2996</a>
<a id='n2997' href='#n2997'>2997</a>
<a id='n2998' href='#n2998'>2998</a>
<a id='n2999' href='#n2999'>2999</a>
<a id='n3000' href='#n3000'>3000</a>
<a id='n3001' href='#n3001'>3001</a>
<a id='n3002' href='#n3002'>3002</a>
<a id='n3003' href='#n3003'>3003</a>
<a id='n3004' href='#n3004'>3004</a>
<a id='n3005' href='#n3005'>3005</a>
<a id='n3006' href='#n3006'>3006</a>
<a id='n3007' href='#n3007'>3007</a>
<a id='n3008' href='#n3008'>3008</a>
<a id='n3009' href='#n3009'>3009</a>
<a id='n3010' href='#n3010'>3010</a>
<a id='n3011' href='#n3011'>3011</a>
<a id='n3012' href='#n3012'>3012</a>
<a id='n3013' href='#n3013'>3013</a>
<a id='n3014' href='#n3014'>3014</a>
<a id='n3015' href='#n3015'>3015</a>
<a id='n3016' href='#n3016'>3016</a>
<a id='n3017' href='#n3017'>3017</a>
<a id='n3018' href='#n3018'>3018</a>
<a id='n3019' href='#n3019'>3019</a>
<a id='n3020' href='#n3020'>3020</a>
<a id='n3021' href='#n3021'>3021</a>
<a id='n3022' href='#n3022'>3022</a>
<a id='n3023' href='#n3023'>3023</a>
<a id='n3024' href='#n3024'>3024</a>
<a id='n3025' href='#n3025'>3025</a>
<a id='n3026' href='#n3026'>3026</a>
<a id='n3027' href='#n3027'>3027</a>
<a id='n3028' href='#n3028'>3028</a>
<a id='n3029' href='#n3029'>3029</a>
<a id='n3030' href='#n3030'>3030</a>
<a id='n3031' href='#n3031'>3031</a>
<a id='n3032' href='#n3032'>3032</a>
<a id='n3033' href='#n3033'>3033</a>
<a id='n3034' href='#n3034'>3034</a>
<a id='n3035' href='#n3035'>3035</a>
<a id='n3036' href='#n3036'>3036</a>
<a id='n3037' href='#n3037'>3037</a>
<a id='n3038' href='#n3038'>3038</a>
<a id='n3039' href='#n3039'>3039</a>
<a id='n3040' href='#n3040'>3040</a>
<a id='n3041' href='#n3041'>3041</a>
<a id='n3042' href='#n3042'>3042</a>
<a id='n3043' href='#n3043'>3043</a>
<a id='n3044' href='#n3044'>3044</a>
<a id='n3045' href='#n3045'>3045</a>
<a id='n3046' href='#n3046'>3046</a>
<a id='n3047' href='#n3047'>3047</a>
<a id='n3048' href='#n3048'>3048</a>
<a id='n3049' href='#n3049'>3049</a>
<a id='n3050' href='#n3050'>3050</a>
<a id='n3051' href='#n3051'>3051</a>
<a id='n3052' href='#n3052'>3052</a>
<a id='n3053' href='#n3053'>3053</a>
<a id='n3054' href='#n3054'>3054</a>
<a id='n3055' href='#n3055'>3055</a>
<a id='n3056' href='#n3056'>3056</a>
<a id='n3057' href='#n3057'>3057</a>
<a id='n3058' href='#n3058'>3058</a>
<a id='n3059' href='#n3059'>3059</a>
<a id='n3060' href='#n3060'>3060</a>
<a id='n3061' href='#n3061'>3061</a>
<a id='n3062' href='#n3062'>3062</a>
<a id='n3063' href='#n3063'>3063</a>
<a id='n3064' href='#n3064'>3064</a>
<a id='n3065' href='#n3065'>3065</a>
<a id='n3066' href='#n3066'>3066</a>
<a id='n3067' href='#n3067'>3067</a>
<a id='n3068' href='#n3068'>3068</a>
<a id='n3069' href='#n3069'>3069</a>
<a id='n3070' href='#n3070'>3070</a>
<a id='n3071' href='#n3071'>3071</a>
<a id='n3072' href='#n3072'>3072</a>
<a id='n3073' href='#n3073'>3073</a>
<a id='n3074' href='#n3074'>3074</a>
<a id='n3075' href='#n3075'>3075</a>
<a id='n3076' href='#n3076'>3076</a>
<a id='n3077' href='#n3077'>3077</a>
<a id='n3078' href='#n3078'>3078</a>
<a id='n3079' href='#n3079'>3079</a>
<a id='n3080' href='#n3080'>3080</a>
<a id='n3081' href='#n3081'>3081</a>
<a id='n3082' href='#n3082'>3082</a>
<a id='n3083' href='#n3083'>3083</a>
<a id='n3084' href='#n3084'>3084</a>
<a id='n3085' href='#n3085'>3085</a>
<a id='n3086' href='#n3086'>3086</a>
<a id='n3087' href='#n3087'>3087</a>
<a id='n3088' href='#n3088'>3088</a>
<a id='n3089' href='#n3089'>3089</a>
<a id='n3090' href='#n3090'>3090</a>
<a id='n3091' href='#n3091'>3091</a>
<a id='n3092' href='#n3092'>3092</a>
<a id='n3093' href='#n3093'>3093</a>
<a id='n3094' href='#n3094'>3094</a>
<a id='n3095' href='#n3095'>3095</a>
<a id='n3096' href='#n3096'>3096</a>
<a id='n3097' href='#n3097'>3097</a>
<a id='n3098' href='#n3098'>3098</a>
<a id='n3099' href='#n3099'>3099</a>
<a id='n3100' href='#n3100'>3100</a>
<a id='n3101' href='#n3101'>3101</a>
<a id='n3102' href='#n3102'>3102</a>
<a id='n3103' href='#n3103'>3103</a>
<a id='n3104' href='#n3104'>3104</a>
<a id='n3105' href='#n3105'>3105</a>
<a id='n3106' href='#n3106'>3106</a>
<a id='n3107' href='#n3107'>3107</a>
<a id='n3108' href='#n3108'>3108</a>
<a id='n3109' href='#n3109'>3109</a>
<a id='n3110' href='#n3110'>3110</a>
<a id='n3111' href='#n3111'>3111</a>
<a id='n3112' href='#n3112'>3112</a>
<a id='n3113' href='#n3113'>3113</a>
<a id='n3114' href='#n3114'>3114</a>
<a id='n3115' href='#n3115'>3115</a>
<a id='n3116' href='#n3116'>3116</a>
<a id='n3117' href='#n3117'>3117</a>
<a id='n3118' href='#n3118'>3118</a>
<a id='n3119' href='#n3119'>3119</a>
<a id='n3120' href='#n3120'>3120</a>
<a id='n3121' href='#n3121'>3121</a>
<a id='n3122' href='#n3122'>3122</a>
<a id='n3123' href='#n3123'>3123</a>
<a id='n3124' href='#n3124'>3124</a>
<a id='n3125' href='#n3125'>3125</a>
<a id='n3126' href='#n3126'>3126</a>
<a id='n3127' href='#n3127'>3127</a>
<a id='n3128' href='#n3128'>3128</a>
<a id='n3129' href='#n3129'>3129</a>
<a id='n3130' href='#n3130'>3130</a>
<a id='n3131' href='#n3131'>3131</a>
<a id='n3132' href='#n3132'>3132</a>
<a id='n3133' href='#n3133'>3133</a>
<a id='n3134' href='#n3134'>3134</a>
<a id='n3135' href='#n3135'>3135</a>
<a id='n3136' href='#n3136'>3136</a>
<a id='n3137' href='#n3137'>3137</a>
<a id='n3138' href='#n3138'>3138</a>
<a id='n3139' href='#n3139'>3139</a>
<a id='n3140' href='#n3140'>3140</a>
<a id='n3141' href='#n3141'>3141</a>
<a id='n3142' href='#n3142'>3142</a>
<a id='n3143' href='#n3143'>3143</a>
<a id='n3144' href='#n3144'>3144</a>
<a id='n3145' href='#n3145'>3145</a>
<a id='n3146' href='#n3146'>3146</a>
<a id='n3147' href='#n3147'>3147</a>
<a id='n3148' href='#n3148'>3148</a>
<a id='n3149' href='#n3149'>3149</a>
<a id='n3150' href='#n3150'>3150</a>
<a id='n3151' href='#n3151'>3151</a>
<a id='n3152' href='#n3152'>3152</a>
<a id='n3153' href='#n3153'>3153</a>
<a id='n3154' href='#n3154'>3154</a>
<a id='n3155' href='#n3155'>3155</a>
<a id='n3156' href='#n3156'>3156</a>
<a id='n3157' href='#n3157'>3157</a>
<a id='n3158' href='#n3158'>3158</a>
<a id='n3159' href='#n3159'>3159</a>
<a id='n3160' href='#n3160'>3160</a>
<a id='n3161' href='#n3161'>3161</a>
<a id='n3162' href='#n3162'>3162</a>
<a id='n3163' href='#n3163'>3163</a>
<a id='n3164' href='#n3164'>3164</a>
<a id='n3165' href='#n3165'>3165</a>
<a id='n3166' href='#n3166'>3166</a>
<a id='n3167' href='#n3167'>3167</a>
<a id='n3168' href='#n3168'>3168</a>
<a id='n3169' href='#n3169'>3169</a>
<a id='n3170' href='#n3170'>3170</a>
<a id='n3171' href='#n3171'>3171</a>
<a id='n3172' href='#n3172'>3172</a>
<a id='n3173' href='#n3173'>3173</a>
<a id='n3174' href='#n3174'>3174</a>
<a id='n3175' href='#n3175'>3175</a>
<a id='n3176' href='#n3176'>3176</a>
<a id='n3177' href='#n3177'>3177</a>
<a id='n3178' href='#n3178'>3178</a>
<a id='n3179' href='#n3179'>3179</a>
<a id='n3180' href='#n3180'>3180</a>
<a id='n3181' href='#n3181'>3181</a>
<a id='n3182' href='#n3182'>3182</a>
<a id='n3183' href='#n3183'>3183</a>
<a id='n3184' href='#n3184'>3184</a>
<a id='n3185' href='#n3185'>3185</a>
<a id='n3186' href='#n3186'>3186</a>
<a id='n3187' href='#n3187'>3187</a>
<a id='n3188' href='#n3188'>3188</a>
<a id='n3189' href='#n3189'>3189</a>
<a id='n3190' href='#n3190'>3190</a>
<a id='n3191' href='#n3191'>3191</a>
<a id='n3192' href='#n3192'>3192</a>
<a id='n3193' href='#n3193'>3193</a>
<a id='n3194' href='#n3194'>3194</a>
<a id='n3195' href='#n3195'>3195</a>
<a id='n3196' href='#n3196'>3196</a>
<a id='n3197' href='#n3197'>3197</a>
<a id='n3198' href='#n3198'>3198</a>
<a id='n3199' href='#n3199'>3199</a>
<a id='n3200' href='#n3200'>3200</a>
<a id='n3201' href='#n3201'>3201</a>
<a id='n3202' href='#n3202'>3202</a>
<a id='n3203' href='#n3203'>3203</a>
<a id='n3204' href='#n3204'>3204</a>
<a id='n3205' href='#n3205'>3205</a>
<a id='n3206' href='#n3206'>3206</a>
<a id='n3207' href='#n3207'>3207</a>
<a id='n3208' href='#n3208'>3208</a>
<a id='n3209' href='#n3209'>3209</a>
<a id='n3210' href='#n3210'>3210</a>
<a id='n3211' href='#n3211'>3211</a>
<a id='n3212' href='#n3212'>3212</a>
<a id='n3213' href='#n3213'>3213</a>
<a id='n3214' href='#n3214'>3214</a>
<a id='n3215' href='#n3215'>3215</a>
<a id='n3216' href='#n3216'>3216</a>
<a id='n3217' href='#n3217'>3217</a>
<a id='n3218' href='#n3218'>3218</a>
<a id='n3219' href='#n3219'>3219</a>
<a id='n3220' href='#n3220'>3220</a>
<a id='n3221' href='#n3221'>3221</a>
<a id='n3222' href='#n3222'>3222</a>
<a id='n3223' href='#n3223'>3223</a>
<a id='n3224' href='#n3224'>3224</a>
<a id='n3225' href='#n3225'>3225</a>
<a id='n3226' href='#n3226'>3226</a>
<a id='n3227' href='#n3227'>3227</a>
<a id='n3228' href='#n3228'>3228</a>
<a id='n3229' href='#n3229'>3229</a>
<a id='n3230' href='#n3230'>3230</a>
<a id='n3231' href='#n3231'>3231</a>
<a id='n3232' href='#n3232'>3232</a>
<a id='n3233' href='#n3233'>3233</a>
<a id='n3234' href='#n3234'>3234</a>
<a id='n3235' href='#n3235'>3235</a>
<a id='n3236' href='#n3236'>3236</a>
<a id='n3237' href='#n3237'>3237</a>
<a id='n3238' href='#n3238'>3238</a>
<a id='n3239' href='#n3239'>3239</a>
<a id='n3240' href='#n3240'>3240</a>
<a id='n3241' href='#n3241'>3241</a>
<a id='n3242' href='#n3242'>3242</a>
<a id='n3243' href='#n3243'>3243</a>
<a id='n3244' href='#n3244'>3244</a>
<a id='n3245' href='#n3245'>3245</a>
<a id='n3246' href='#n3246'>3246</a>
<a id='n3247' href='#n3247'>3247</a>
<a id='n3248' href='#n3248'>3248</a>
<a id='n3249' href='#n3249'>3249</a>
<a id='n3250' href='#n3250'>3250</a>
<a id='n3251' href='#n3251'>3251</a>
<a id='n3252' href='#n3252'>3252</a>
<a id='n3253' href='#n3253'>3253</a>
<a id='n3254' href='#n3254'>3254</a>
<a id='n3255' href='#n3255'>3255</a>
<a id='n3256' href='#n3256'>3256</a>
<a id='n3257' href='#n3257'>3257</a>
<a id='n3258' href='#n3258'>3258</a>
<a id='n3259' href='#n3259'>3259</a>
<a id='n3260' href='#n3260'>3260</a>
<a id='n3261' href='#n3261'>3261</a>
<a id='n3262' href='#n3262'>3262</a>
<a id='n3263' href='#n3263'>3263</a>
<a id='n3264' href='#n3264'>3264</a>
<a id='n3265' href='#n3265'>3265</a>
<a id='n3266' href='#n3266'>3266</a>
<a id='n3267' href='#n3267'>3267</a>
<a id='n3268' href='#n3268'>3268</a>
<a id='n3269' href='#n3269'>3269</a>
<a id='n3270' href='#n3270'>3270</a>
<a id='n3271' href='#n3271'>3271</a>
<a id='n3272' href='#n3272'>3272</a>
<a id='n3273' href='#n3273'>3273</a>
<a id='n3274' href='#n3274'>3274</a>
<a id='n3275' href='#n3275'>3275</a>
<a id='n3276' href='#n3276'>3276</a>
<a id='n3277' href='#n3277'>3277</a>
<a id='n3278' href='#n3278'>3278</a>
<a id='n3279' href='#n3279'>3279</a>
<a id='n3280' href='#n3280'>3280</a>
<a id='n3281' href='#n3281'>3281</a>
<a id='n3282' href='#n3282'>3282</a>
<a id='n3283' href='#n3283'>3283</a>
<a id='n3284' href='#n3284'>3284</a>
<a id='n3285' href='#n3285'>3285</a>
<a id='n3286' href='#n3286'>3286</a>
<a id='n3287' href='#n3287'>3287</a>
<a id='n3288' href='#n3288'>3288</a>
<a id='n3289' href='#n3289'>3289</a>
<a id='n3290' href='#n3290'>3290</a>
<a id='n3291' href='#n3291'>3291</a>
<a id='n3292' href='#n3292'>3292</a>
<a id='n3293' href='#n3293'>3293</a>
<a id='n3294' href='#n3294'>3294</a>
<a id='n3295' href='#n3295'>3295</a>
<a id='n3296' href='#n3296'>3296</a>
<a id='n3297' href='#n3297'>3297</a>
<a id='n3298' href='#n3298'>3298</a>
<a id='n3299' href='#n3299'>3299</a>
<a id='n3300' href='#n3300'>3300</a>
<a id='n3301' href='#n3301'>3301</a>
<a id='n3302' href='#n3302'>3302</a>
<a id='n3303' href='#n3303'>3303</a>
<a id='n3304' href='#n3304'>3304</a>
<a id='n3305' href='#n3305'>3305</a>
<a id='n3306' href='#n3306'>3306</a>
<a id='n3307' href='#n3307'>3307</a>
<a id='n3308' href='#n3308'>3308</a>
<a id='n3309' href='#n3309'>3309</a>
<a id='n3310' href='#n3310'>3310</a>
<a id='n3311' href='#n3311'>3311</a>
<a id='n3312' href='#n3312'>3312</a>
<a id='n3313' href='#n3313'>3313</a>
<a id='n3314' href='#n3314'>3314</a>
<a id='n3315' href='#n3315'>3315</a>
<a id='n3316' href='#n3316'>3316</a>
<a id='n3317' href='#n3317'>3317</a>
<a id='n3318' href='#n3318'>3318</a>
<a id='n3319' href='#n3319'>3319</a>
<a id='n3320' href='#n3320'>3320</a>
<a id='n3321' href='#n3321'>3321</a>
<a id='n3322' href='#n3322'>3322</a>
<a id='n3323' href='#n3323'>3323</a>
<a id='n3324' href='#n3324'>3324</a>
<a id='n3325' href='#n3325'>3325</a>
<a id='n3326' href='#n3326'>3326</a>
<a id='n3327' href='#n3327'>3327</a>
<a id='n3328' href='#n3328'>3328</a>
<a id='n3329' href='#n3329'>3329</a>
<a id='n3330' href='#n3330'>3330</a>
<a id='n3331' href='#n3331'>3331</a>
<a id='n3332' href='#n3332'>3332</a>
<a id='n3333' href='#n3333'>3333</a>
<a id='n3334' href='#n3334'>3334</a>
<a id='n3335' href='#n3335'>3335</a>
<a id='n3336' href='#n3336'>3336</a>
<a id='n3337' href='#n3337'>3337</a>
<a id='n3338' href='#n3338'>3338</a>
<a id='n3339' href='#n3339'>3339</a>
<a id='n3340' href='#n3340'>3340</a>
<a id='n3341' href='#n3341'>3341</a>
<a id='n3342' href='#n3342'>3342</a>
<a id='n3343' href='#n3343'>3343</a>
<a id='n3344' href='#n3344'>3344</a>
<a id='n3345' href='#n3345'>3345</a>
<a id='n3346' href='#n3346'>3346</a>
<a id='n3347' href='#n3347'>3347</a>
<a id='n3348' href='#n3348'>3348</a>
<a id='n3349' href='#n3349'>3349</a>
<a id='n3350' href='#n3350'>3350</a>
<a id='n3351' href='#n3351'>3351</a>
<a id='n3352' href='#n3352'>3352</a>
<a id='n3353' href='#n3353'>3353</a>
<a id='n3354' href='#n3354'>3354</a>
<a id='n3355' href='#n3355'>3355</a>
<a id='n3356' href='#n3356'>3356</a>
<a id='n3357' href='#n3357'>3357</a>
<a id='n3358' href='#n3358'>3358</a>
<a id='n3359' href='#n3359'>3359</a>
<a id='n3360' href='#n3360'>3360</a>
<a id='n3361' href='#n3361'>3361</a>
<a id='n3362' href='#n3362'>3362</a>
<a id='n3363' href='#n3363'>3363</a>
<a id='n3364' href='#n3364'>3364</a>
<a id='n3365' href='#n3365'>3365</a>
<a id='n3366' href='#n3366'>3366</a>
<a id='n3367' href='#n3367'>3367</a>
<a id='n3368' href='#n3368'>3368</a>
<a id='n3369' href='#n3369'>3369</a>
<a id='n3370' href='#n3370'>3370</a>
<a id='n3371' href='#n3371'>3371</a>
<a id='n3372' href='#n3372'>3372</a>
<a id='n3373' href='#n3373'>3373</a>
<a id='n3374' href='#n3374'>3374</a>
<a id='n3375' href='#n3375'>3375</a>
<a id='n3376' href='#n3376'>3376</a>
<a id='n3377' href='#n3377'>3377</a>
<a id='n3378' href='#n3378'>3378</a>
<a id='n3379' href='#n3379'>3379</a>
<a id='n3380' href='#n3380'>3380</a>
<a id='n3381' href='#n3381'>3381</a>
<a id='n3382' href='#n3382'>3382</a>
<a id='n3383' href='#n3383'>3383</a>
<a id='n3384' href='#n3384'>3384</a>
<a id='n3385' href='#n3385'>3385</a>
<a id='n3386' href='#n3386'>3386</a>
<a id='n3387' href='#n3387'>3387</a>
<a id='n3388' href='#n3388'>3388</a>
<a id='n3389' href='#n3389'>3389</a>
<a id='n3390' href='#n3390'>3390</a>
<a id='n3391' href='#n3391'>3391</a>
<a id='n3392' href='#n3392'>3392</a>
<a id='n3393' href='#n3393'>3393</a>
<a id='n3394' href='#n3394'>3394</a>
<a id='n3395' href='#n3395'>3395</a>
<a id='n3396' href='#n3396'>3396</a>
<a id='n3397' href='#n3397'>3397</a>
<a id='n3398' href='#n3398'>3398</a>
<a id='n3399' href='#n3399'>3399</a>
<a id='n3400' href='#n3400'>3400</a>
<a id='n3401' href='#n3401'>3401</a>
<a id='n3402' href='#n3402'>3402</a>
<a id='n3403' href='#n3403'>3403</a>
<a id='n3404' href='#n3404'>3404</a>
<a id='n3405' href='#n3405'>3405</a>
<a id='n3406' href='#n3406'>3406</a>
<a id='n3407' href='#n3407'>3407</a>
<a id='n3408' href='#n3408'>3408</a>
<a id='n3409' href='#n3409'>3409</a>
<a id='n3410' href='#n3410'>3410</a>
<a id='n3411' href='#n3411'>3411</a>
<a id='n3412' href='#n3412'>3412</a>
<a id='n3413' href='#n3413'>3413</a>
<a id='n3414' href='#n3414'>3414</a>
<a id='n3415' href='#n3415'>3415</a>
<a id='n3416' href='#n3416'>3416</a>
<a id='n3417' href='#n3417'>3417</a>
<a id='n3418' href='#n3418'>3418</a>
<a id='n3419' href='#n3419'>3419</a>
<a id='n3420' href='#n3420'>3420</a>
<a id='n3421' href='#n3421'>3421</a>
<a id='n3422' href='#n3422'>3422</a>
<a id='n3423' href='#n3423'>3423</a>
<a id='n3424' href='#n3424'>3424</a>
<a id='n3425' href='#n3425'>3425</a>
<a id='n3426' href='#n3426'>3426</a>
<a id='n3427' href='#n3427'>3427</a>
<a id='n3428' href='#n3428'>3428</a>
<a id='n3429' href='#n3429'>3429</a>
<a id='n3430' href='#n3430'>3430</a>
<a id='n3431' href='#n3431'>3431</a>
<a id='n3432' href='#n3432'>3432</a>
<a id='n3433' href='#n3433'>3433</a>
<a id='n3434' href='#n3434'>3434</a>
<a id='n3435' href='#n3435'>3435</a>
<a id='n3436' href='#n3436'>3436</a>
<a id='n3437' href='#n3437'>3437</a>
<a id='n3438' href='#n3438'>3438</a>
<a id='n3439' href='#n3439'>3439</a>
<a id='n3440' href='#n3440'>3440</a>
<a id='n3441' href='#n3441'>3441</a>
<a id='n3442' href='#n3442'>3442</a>
<a id='n3443' href='#n3443'>3443</a>
<a id='n3444' href='#n3444'>3444</a>
<a id='n3445' href='#n3445'>3445</a>
<a id='n3446' href='#n3446'>3446</a>
<a id='n3447' href='#n3447'>3447</a>
<a id='n3448' href='#n3448'>3448</a>
<a id='n3449' href='#n3449'>3449</a>
<a id='n3450' href='#n3450'>3450</a>
<a id='n3451' href='#n3451'>3451</a>
<a id='n3452' href='#n3452'>3452</a>
<a id='n3453' href='#n3453'>3453</a>
<a id='n3454' href='#n3454'>3454</a>
<a id='n3455' href='#n3455'>3455</a>
<a id='n3456' href='#n3456'>3456</a>
<a id='n3457' href='#n3457'>3457</a>
<a id='n3458' href='#n3458'>3458</a>
<a id='n3459' href='#n3459'>3459</a>
<a id='n3460' href='#n3460'>3460</a>
<a id='n3461' href='#n3461'>3461</a>
<a id='n3462' href='#n3462'>3462</a>
<a id='n3463' href='#n3463'>3463</a>
<a id='n3464' href='#n3464'>3464</a>
<a id='n3465' href='#n3465'>3465</a>
<a id='n3466' href='#n3466'>3466</a>
<a id='n3467' href='#n3467'>3467</a>
<a id='n3468' href='#n3468'>3468</a>
<a id='n3469' href='#n3469'>3469</a>
<a id='n3470' href='#n3470'>3470</a>
<a id='n3471' href='#n3471'>3471</a>
<a id='n3472' href='#n3472'>3472</a>
<a id='n3473' href='#n3473'>3473</a>
<a id='n3474' href='#n3474'>3474</a>
<a id='n3475' href='#n3475'>3475</a>
<a id='n3476' href='#n3476'>3476</a>
<a id='n3477' href='#n3477'>3477</a>
<a id='n3478' href='#n3478'>3478</a>
<a id='n3479' href='#n3479'>3479</a>
<a id='n3480' href='#n3480'>3480</a>
<a id='n3481' href='#n3481'>3481</a>
<a id='n3482' href='#n3482'>3482</a>
<a id='n3483' href='#n3483'>3483</a>
<a id='n3484' href='#n3484'>3484</a>
<a id='n3485' href='#n3485'>3485</a>
<a id='n3486' href='#n3486'>3486</a>
<a id='n3487' href='#n3487'>3487</a>
<a id='n3488' href='#n3488'>3488</a>
<a id='n3489' href='#n3489'>3489</a>
<a id='n3490' href='#n3490'>3490</a>
<a id='n3491' href='#n3491'>3491</a>
<a id='n3492' href='#n3492'>3492</a>
<a id='n3493' href='#n3493'>3493</a>
<a id='n3494' href='#n3494'>3494</a>
<a id='n3495' href='#n3495'>3495</a>
<a id='n3496' href='#n3496'>3496</a>
<a id='n3497' href='#n3497'>3497</a>
<a id='n3498' href='#n3498'>3498</a>
<a id='n3499' href='#n3499'>3499</a>
<a id='n3500' href='#n3500'>3500</a>
<a id='n3501' href='#n3501'>3501</a>
<a id='n3502' href='#n3502'>3502</a>
<a id='n3503' href='#n3503'>3503</a>
<a id='n3504' href='#n3504'>3504</a>
<a id='n3505' href='#n3505'>3505</a>
<a id='n3506' href='#n3506'>3506</a>
<a id='n3507' href='#n3507'>3507</a>
<a id='n3508' href='#n3508'>3508</a>
<a id='n3509' href='#n3509'>3509</a>
<a id='n3510' href='#n3510'>3510</a>
<a id='n3511' href='#n3511'>3511</a>
<a id='n3512' href='#n3512'>3512</a>
<a id='n3513' href='#n3513'>3513</a>
<a id='n3514' href='#n3514'>3514</a>
<a id='n3515' href='#n3515'>3515</a>
<a id='n3516' href='#n3516'>3516</a>
<a id='n3517' href='#n3517'>3517</a>
<a id='n3518' href='#n3518'>3518</a>
<a id='n3519' href='#n3519'>3519</a>
<a id='n3520' href='#n3520'>3520</a>
<a id='n3521' href='#n3521'>3521</a>
<a id='n3522' href='#n3522'>3522</a>
<a id='n3523' href='#n3523'>3523</a>
<a id='n3524' href='#n3524'>3524</a>
<a id='n3525' href='#n3525'>3525</a>
<a id='n3526' href='#n3526'>3526</a>
<a id='n3527' href='#n3527'>3527</a>
<a id='n3528' href='#n3528'>3528</a>
<a id='n3529' href='#n3529'>3529</a>
<a id='n3530' href='#n3530'>3530</a>
<a id='n3531' href='#n3531'>3531</a>
<a id='n3532' href='#n3532'>3532</a>
<a id='n3533' href='#n3533'>3533</a>
<a id='n3534' href='#n3534'>3534</a>
<a id='n3535' href='#n3535'>3535</a>
<a id='n3536' href='#n3536'>3536</a>
<a id='n3537' href='#n3537'>3537</a>
<a id='n3538' href='#n3538'>3538</a>
<a id='n3539' href='#n3539'>3539</a>
<a id='n3540' href='#n3540'>3540</a>
<a id='n3541' href='#n3541'>3541</a>
<a id='n3542' href='#n3542'>3542</a>
<a id='n3543' href='#n3543'>3543</a>
<a id='n3544' href='#n3544'>3544</a>
<a id='n3545' href='#n3545'>3545</a>
<a id='n3546' href='#n3546'>3546</a>
<a id='n3547' href='#n3547'>3547</a>
<a id='n3548' href='#n3548'>3548</a>
<a id='n3549' href='#n3549'>3549</a>
<a id='n3550' href='#n3550'>3550</a>
<a id='n3551' href='#n3551'>3551</a>
<a id='n3552' href='#n3552'>3552</a>
<a id='n3553' href='#n3553'>3553</a>
<a id='n3554' href='#n3554'>3554</a>
<a id='n3555' href='#n3555'>3555</a>
<a id='n3556' href='#n3556'>3556</a>
<a id='n3557' href='#n3557'>3557</a>
<a id='n3558' href='#n3558'>3558</a>
<a id='n3559' href='#n3559'>3559</a>
<a id='n3560' href='#n3560'>3560</a>
<a id='n3561' href='#n3561'>3561</a>
<a id='n3562' href='#n3562'>3562</a>
<a id='n3563' href='#n3563'>3563</a>
<a id='n3564' href='#n3564'>3564</a>
<a id='n3565' href='#n3565'>3565</a>
<a id='n3566' href='#n3566'>3566</a>
<a id='n3567' href='#n3567'>3567</a>
<a id='n3568' href='#n3568'>3568</a>
<a id='n3569' href='#n3569'>3569</a>
<a id='n3570' href='#n3570'>3570</a>
<a id='n3571' href='#n3571'>3571</a>
<a id='n3572' href='#n3572'>3572</a>
<a id='n3573' href='#n3573'>3573</a>
<a id='n3574' href='#n3574'>3574</a>
<a id='n3575' href='#n3575'>3575</a>
<a id='n3576' href='#n3576'>3576</a>
<a id='n3577' href='#n3577'>3577</a>
<a id='n3578' href='#n3578'>3578</a>
<a id='n3579' href='#n3579'>3579</a>
<a id='n3580' href='#n3580'>3580</a>
<a id='n3581' href='#n3581'>3581</a>
<a id='n3582' href='#n3582'>3582</a>
<a id='n3583' href='#n3583'>3583</a>
<a id='n3584' href='#n3584'>3584</a>
<a id='n3585' href='#n3585'>3585</a>
<a id='n3586' href='#n3586'>3586</a>
<a id='n3587' href='#n3587'>3587</a>
<a id='n3588' href='#n3588'>3588</a>
<a id='n3589' href='#n3589'>3589</a>
<a id='n3590' href='#n3590'>3590</a>
<a id='n3591' href='#n3591'>3591</a>
<a id='n3592' href='#n3592'>3592</a>
<a id='n3593' href='#n3593'>3593</a>
<a id='n3594' href='#n3594'>3594</a>
<a id='n3595' href='#n3595'>3595</a>
<a id='n3596' href='#n3596'>3596</a>
<a id='n3597' href='#n3597'>3597</a>
<a id='n3598' href='#n3598'>3598</a>
<a id='n3599' href='#n3599'>3599</a>
<a id='n3600' href='#n3600'>3600</a>
<a id='n3601' href='#n3601'>3601</a>
<a id='n3602' href='#n3602'>3602</a>
<a id='n3603' href='#n3603'>3603</a>
<a id='n3604' href='#n3604'>3604</a>
<a id='n3605' href='#n3605'>3605</a>
<a id='n3606' href='#n3606'>3606</a>
<a id='n3607' href='#n3607'>3607</a>
<a id='n3608' href='#n3608'>3608</a>
<a id='n3609' href='#n3609'>3609</a>
<a id='n3610' href='#n3610'>3610</a>
<a id='n3611' href='#n3611'>3611</a>
<a id='n3612' href='#n3612'>3612</a>
<a id='n3613' href='#n3613'>3613</a>
<a id='n3614' href='#n3614'>3614</a>
<a id='n3615' href='#n3615'>3615</a>
<a id='n3616' href='#n3616'>3616</a>
<a id='n3617' href='#n3617'>3617</a>
<a id='n3618' href='#n3618'>3618</a>
<a id='n3619' href='#n3619'>3619</a>
<a id='n3620' href='#n3620'>3620</a>
<a id='n3621' href='#n3621'>3621</a>
<a id='n3622' href='#n3622'>3622</a>
<a id='n3623' href='#n3623'>3623</a>
<a id='n3624' href='#n3624'>3624</a>
<a id='n3625' href='#n3625'>3625</a>
<a id='n3626' href='#n3626'>3626</a>
<a id='n3627' href='#n3627'>3627</a>
<a id='n3628' href='#n3628'>3628</a>
<a id='n3629' href='#n3629'>3629</a>
<a id='n3630' href='#n3630'>3630</a>
<a id='n3631' href='#n3631'>3631</a>
<a id='n3632' href='#n3632'>3632</a>
<a id='n3633' href='#n3633'>3633</a>
<a id='n3634' href='#n3634'>3634</a>
<a id='n3635' href='#n3635'>3635</a>
<a id='n3636' href='#n3636'>3636</a>
<a id='n3637' href='#n3637'>3637</a>
<a id='n3638' href='#n3638'>3638</a>
<a id='n3639' href='#n3639'>3639</a>
<a id='n3640' href='#n3640'>3640</a>
<a id='n3641' href='#n3641'>3641</a>
<a id='n3642' href='#n3642'>3642</a>
<a id='n3643' href='#n3643'>3643</a>
<a id='n3644' href='#n3644'>3644</a>
<a id='n3645' href='#n3645'>3645</a>
<a id='n3646' href='#n3646'>3646</a>
<a id='n3647' href='#n3647'>3647</a>
<a id='n3648' href='#n3648'>3648</a>
<a id='n3649' href='#n3649'>3649</a>
<a id='n3650' href='#n3650'>3650</a>
<a id='n3651' href='#n3651'>3651</a>
<a id='n3652' href='#n3652'>3652</a>
<a id='n3653' href='#n3653'>3653</a>
<a id='n3654' href='#n3654'>3654</a>
<a id='n3655' href='#n3655'>3655</a>
<a id='n3656' href='#n3656'>3656</a>
<a id='n3657' href='#n3657'>3657</a>
<a id='n3658' href='#n3658'>3658</a>
<a id='n3659' href='#n3659'>3659</a>
<a id='n3660' href='#n3660'>3660</a>
<a id='n3661' href='#n3661'>3661</a>
<a id='n3662' href='#n3662'>3662</a>
<a id='n3663' href='#n3663'>3663</a>
<a id='n3664' href='#n3664'>3664</a>
<a id='n3665' href='#n3665'>3665</a>
<a id='n3666' href='#n3666'>3666</a>
<a id='n3667' href='#n3667'>3667</a>
<a id='n3668' href='#n3668'>3668</a>
<a id='n3669' href='#n3669'>3669</a>
<a id='n3670' href='#n3670'>3670</a>
<a id='n3671' href='#n3671'>3671</a>
<a id='n3672' href='#n3672'>3672</a>
<a id='n3673' href='#n3673'>3673</a>
<a id='n3674' href='#n3674'>3674</a>
<a id='n3675' href='#n3675'>3675</a>
<a id='n3676' href='#n3676'>3676</a>
<a id='n3677' href='#n3677'>3677</a>
<a id='n3678' href='#n3678'>3678</a>
<a id='n3679' href='#n3679'>3679</a>
<a id='n3680' href='#n3680'>3680</a>
<a id='n3681' href='#n3681'>3681</a>
<a id='n3682' href='#n3682'>3682</a>
<a id='n3683' href='#n3683'>3683</a>
<a id='n3684' href='#n3684'>3684</a>
<a id='n3685' href='#n3685'>3685</a>
<a id='n3686' href='#n3686'>3686</a>
<a id='n3687' href='#n3687'>3687</a>
<a id='n3688' href='#n3688'>3688</a>
<a id='n3689' href='#n3689'>3689</a>
<a id='n3690' href='#n3690'>3690</a>
<a id='n3691' href='#n3691'>3691</a>
<a id='n3692' href='#n3692'>3692</a>
<a id='n3693' href='#n3693'>3693</a>
<a id='n3694' href='#n3694'>3694</a>
<a id='n3695' href='#n3695'>3695</a>
<a id='n3696' href='#n3696'>3696</a>
<a id='n3697' href='#n3697'>3697</a>
<a id='n3698' href='#n3698'>3698</a>
<a id='n3699' href='#n3699'>3699</a>
<a id='n3700' href='#n3700'>3700</a>
<a id='n3701' href='#n3701'>3701</a>
<a id='n3702' href='#n3702'>3702</a>
<a id='n3703' href='#n3703'>3703</a>
<a id='n3704' href='#n3704'>3704</a>
<a id='n3705' href='#n3705'>3705</a>
<a id='n3706' href='#n3706'>3706</a>
<a id='n3707' href='#n3707'>3707</a>
<a id='n3708' href='#n3708'>3708</a>
<a id='n3709' href='#n3709'>3709</a>
<a id='n3710' href='#n3710'>3710</a>
<a id='n3711' href='#n3711'>3711</a>
<a id='n3712' href='#n3712'>3712</a>
<a id='n3713' href='#n3713'>3713</a>
<a id='n3714' href='#n3714'>3714</a>
<a id='n3715' href='#n3715'>3715</a>
<a id='n3716' href='#n3716'>3716</a>
<a id='n3717' href='#n3717'>3717</a>
<a id='n3718' href='#n3718'>3718</a>
<a id='n3719' href='#n3719'>3719</a>
<a id='n3720' href='#n3720'>3720</a>
<a id='n3721' href='#n3721'>3721</a>
<a id='n3722' href='#n3722'>3722</a>
<a id='n3723' href='#n3723'>3723</a>
<a id='n3724' href='#n3724'>3724</a>
<a id='n3725' href='#n3725'>3725</a>
<a id='n3726' href='#n3726'>3726</a>
<a id='n3727' href='#n3727'>3727</a>
<a id='n3728' href='#n3728'>3728</a>
<a id='n3729' href='#n3729'>3729</a>
<a id='n3730' href='#n3730'>3730</a>
<a id='n3731' href='#n3731'>3731</a>
<a id='n3732' href='#n3732'>3732</a>
<a id='n3733' href='#n3733'>3733</a>
<a id='n3734' href='#n3734'>3734</a>
<a id='n3735' href='#n3735'>3735</a>
<a id='n3736' href='#n3736'>3736</a>
<a id='n3737' href='#n3737'>3737</a>
<a id='n3738' href='#n3738'>3738</a>
<a id='n3739' href='#n3739'>3739</a>
<a id='n3740' href='#n3740'>3740</a>
<a id='n3741' href='#n3741'>3741</a>
<a id='n3742' href='#n3742'>3742</a>
<a id='n3743' href='#n3743'>3743</a>
<a id='n3744' href='#n3744'>3744</a>
<a id='n3745' href='#n3745'>3745</a>
<a id='n3746' href='#n3746'>3746</a>
<a id='n3747' href='#n3747'>3747</a>
<a id='n3748' href='#n3748'>3748</a>
<a id='n3749' href='#n3749'>3749</a>
<a id='n3750' href='#n3750'>3750</a>
<a id='n3751' href='#n3751'>3751</a>
<a id='n3752' href='#n3752'>3752</a>
<a id='n3753' href='#n3753'>3753</a>
<a id='n3754' href='#n3754'>3754</a>
<a id='n3755' href='#n3755'>3755</a>
<a id='n3756' href='#n3756'>3756</a>
<a id='n3757' href='#n3757'>3757</a>
<a id='n3758' href='#n3758'>3758</a>
<a id='n3759' href='#n3759'>3759</a>
<a id='n3760' href='#n3760'>3760</a>
<a id='n3761' href='#n3761'>3761</a>
<a id='n3762' href='#n3762'>3762</a>
<a id='n3763' href='#n3763'>3763</a>
<a id='n3764' href='#n3764'>3764</a>
<a id='n3765' href='#n3765'>3765</a>
<a id='n3766' href='#n3766'>3766</a>
<a id='n3767' href='#n3767'>3767</a>
<a id='n3768' href='#n3768'>3768</a>
<a id='n3769' href='#n3769'>3769</a>
<a id='n3770' href='#n3770'>3770</a>
<a id='n3771' href='#n3771'>3771</a>
<a id='n3772' href='#n3772'>3772</a>
<a id='n3773' href='#n3773'>3773</a>
<a id='n3774' href='#n3774'>3774</a>
<a id='n3775' href='#n3775'>3775</a>
<a id='n3776' href='#n3776'>3776</a>
<a id='n3777' href='#n3777'>3777</a>
<a id='n3778' href='#n3778'>3778</a>
<a id='n3779' href='#n3779'>3779</a>
<a id='n3780' href='#n3780'>3780</a>
<a id='n3781' href='#n3781'>3781</a>
<a id='n3782' href='#n3782'>3782</a>
<a id='n3783' href='#n3783'>3783</a>
<a id='n3784' href='#n3784'>3784</a>
<a id='n3785' href='#n3785'>3785</a>
<a id='n3786' href='#n3786'>3786</a>
<a id='n3787' href='#n3787'>3787</a>
<a id='n3788' href='#n3788'>3788</a>
<a id='n3789' href='#n3789'>3789</a>
<a id='n3790' href='#n3790'>3790</a>
<a id='n3791' href='#n3791'>3791</a>
<a id='n3792' href='#n3792'>3792</a>
<a id='n3793' href='#n3793'>3793</a>
<a id='n3794' href='#n3794'>3794</a>
<a id='n3795' href='#n3795'>3795</a>
<a id='n3796' href='#n3796'>3796</a>
<a id='n3797' href='#n3797'>3797</a>
<a id='n3798' href='#n3798'>3798</a>
<a id='n3799' href='#n3799'>3799</a>
<a id='n3800' href='#n3800'>3800</a>
<a id='n3801' href='#n3801'>3801</a>
<a id='n3802' href='#n3802'>3802</a>
<a id='n3803' href='#n3803'>3803</a>
<a id='n3804' href='#n3804'>3804</a>
<a id='n3805' href='#n3805'>3805</a>
<a id='n3806' href='#n3806'>3806</a>
<a id='n3807' href='#n3807'>3807</a>
<a id='n3808' href='#n3808'>3808</a>
<a id='n3809' href='#n3809'>3809</a>
<a id='n3810' href='#n3810'>3810</a>
<a id='n3811' href='#n3811'>3811</a>
<a id='n3812' href='#n3812'>3812</a>
<a id='n3813' href='#n3813'>3813</a>
<a id='n3814' href='#n3814'>3814</a>
<a id='n3815' href='#n3815'>3815</a>
<a id='n3816' href='#n3816'>3816</a>
<a id='n3817' href='#n3817'>3817</a>
<a id='n3818' href='#n3818'>3818</a>
<a id='n3819' href='#n3819'>3819</a>
<a id='n3820' href='#n3820'>3820</a>
<a id='n3821' href='#n3821'>3821</a>
<a id='n3822' href='#n3822'>3822</a>
<a id='n3823' href='#n3823'>3823</a>
<a id='n3824' href='#n3824'>3824</a>
<a id='n3825' href='#n3825'>3825</a>
<a id='n3826' href='#n3826'>3826</a>
<a id='n3827' href='#n3827'>3827</a>
<a id='n3828' href='#n3828'>3828</a>
<a id='n3829' href='#n3829'>3829</a>
<a id='n3830' href='#n3830'>3830</a>
<a id='n3831' href='#n3831'>3831</a>
<a id='n3832' href='#n3832'>3832</a>
<a id='n3833' href='#n3833'>3833</a>
<a id='n3834' href='#n3834'>3834</a>
<a id='n3835' href='#n3835'>3835</a>
<a id='n3836' href='#n3836'>3836</a>
<a id='n3837' href='#n3837'>3837</a>
<a id='n3838' href='#n3838'>3838</a>
<a id='n3839' href='#n3839'>3839</a>
<a id='n3840' href='#n3840'>3840</a>
<a id='n3841' href='#n3841'>3841</a>
<a id='n3842' href='#n3842'>3842</a>
<a id='n3843' href='#n3843'>3843</a>
<a id='n3844' href='#n3844'>3844</a>
<a id='n3845' href='#n3845'>3845</a>
<a id='n3846' href='#n3846'>3846</a>
<a id='n3847' href='#n3847'>3847</a>
<a id='n3848' href='#n3848'>3848</a>
<a id='n3849' href='#n3849'>3849</a>
<a id='n3850' href='#n3850'>3850</a>
<a id='n3851' href='#n3851'>3851</a>
<a id='n3852' href='#n3852'>3852</a>
<a id='n3853' href='#n3853'>3853</a>
<a id='n3854' href='#n3854'>3854</a>
<a id='n3855' href='#n3855'>3855</a>
<a id='n3856' href='#n3856'>3856</a>
<a id='n3857' href='#n3857'>3857</a>
<a id='n3858' href='#n3858'>3858</a>
<a id='n3859' href='#n3859'>3859</a>
<a id='n3860' href='#n3860'>3860</a>
<a id='n3861' href='#n3861'>3861</a>
<a id='n3862' href='#n3862'>3862</a>
<a id='n3863' href='#n3863'>3863</a>
<a id='n3864' href='#n3864'>3864</a>
<a id='n3865' href='#n3865'>3865</a>
<a id='n3866' href='#n3866'>3866</a>
<a id='n3867' href='#n3867'>3867</a>
<a id='n3868' href='#n3868'>3868</a>
<a id='n3869' href='#n3869'>3869</a>
<a id='n3870' href='#n3870'>3870</a>
<a id='n3871' href='#n3871'>3871</a>
<a id='n3872' href='#n3872'>3872</a>
<a id='n3873' href='#n3873'>3873</a>
<a id='n3874' href='#n3874'>3874</a>
<a id='n3875' href='#n3875'>3875</a>
<a id='n3876' href='#n3876'>3876</a>
<a id='n3877' href='#n3877'>3877</a>
<a id='n3878' href='#n3878'>3878</a>
<a id='n3879' href='#n3879'>3879</a>
<a id='n3880' href='#n3880'>3880</a>
<a id='n3881' href='#n3881'>3881</a>
<a id='n3882' href='#n3882'>3882</a>
<a id='n3883' href='#n3883'>3883</a>
<a id='n3884' href='#n3884'>3884</a>
<a id='n3885' href='#n3885'>3885</a>
<a id='n3886' href='#n3886'>3886</a>
<a id='n3887' href='#n3887'>3887</a>
<a id='n3888' href='#n3888'>3888</a>
<a id='n3889' href='#n3889'>3889</a>
<a id='n3890' href='#n3890'>3890</a>
<a id='n3891' href='#n3891'>3891</a>
<a id='n3892' href='#n3892'>3892</a>
<a id='n3893' href='#n3893'>3893</a>
<a id='n3894' href='#n3894'>3894</a>
<a id='n3895' href='#n3895'>3895</a>
<a id='n3896' href='#n3896'>3896</a>
<a id='n3897' href='#n3897'>3897</a>
<a id='n3898' href='#n3898'>3898</a>
<a id='n3899' href='#n3899'>3899</a>
<a id='n3900' href='#n3900'>3900</a>
<a id='n3901' href='#n3901'>3901</a>
<a id='n3902' href='#n3902'>3902</a>
<a id='n3903' href='#n3903'>3903</a>
<a id='n3904' href='#n3904'>3904</a>
<a id='n3905' href='#n3905'>3905</a>
<a id='n3906' href='#n3906'>3906</a>
<a id='n3907' href='#n3907'>3907</a>
<a id='n3908' href='#n3908'>3908</a>
<a id='n3909' href='#n3909'>3909</a>
<a id='n3910' href='#n3910'>3910</a>
<a id='n3911' href='#n3911'>3911</a>
<a id='n3912' href='#n3912'>3912</a>
<a id='n3913' href='#n3913'>3913</a>
<a id='n3914' href='#n3914'>3914</a>
<a id='n3915' href='#n3915'>3915</a>
<a id='n3916' href='#n3916'>3916</a>
<a id='n3917' href='#n3917'>3917</a>
<a id='n3918' href='#n3918'>3918</a>
<a id='n3919' href='#n3919'>3919</a>
<a id='n3920' href='#n3920'>3920</a>
<a id='n3921' href='#n3921'>3921</a>
<a id='n3922' href='#n3922'>3922</a>
<a id='n3923' href='#n3923'>3923</a>
<a id='n3924' href='#n3924'>3924</a>
<a id='n3925' href='#n3925'>3925</a>
<a id='n3926' href='#n3926'>3926</a>
<a id='n3927' href='#n3927'>3927</a>
<a id='n3928' href='#n3928'>3928</a>
<a id='n3929' href='#n3929'>3929</a>
<a id='n3930' href='#n3930'>3930</a>
<a id='n3931' href='#n3931'>3931</a>
<a id='n3932' href='#n3932'>3932</a>
<a id='n3933' href='#n3933'>3933</a>
<a id='n3934' href='#n3934'>3934</a>
<a id='n3935' href='#n3935'>3935</a>
<a id='n3936' href='#n3936'>3936</a>
<a id='n3937' href='#n3937'>3937</a>
<a id='n3938' href='#n3938'>3938</a>
<a id='n3939' href='#n3939'>3939</a>
<a id='n3940' href='#n3940'>3940</a>
<a id='n3941' href='#n3941'>3941</a>
<a id='n3942' href='#n3942'>3942</a>
<a id='n3943' href='#n3943'>3943</a>
<a id='n3944' href='#n3944'>3944</a>
<a id='n3945' href='#n3945'>3945</a>
<a id='n3946' href='#n3946'>3946</a>
<a id='n3947' href='#n3947'>3947</a>
<a id='n3948' href='#n3948'>3948</a>
<a id='n3949' href='#n3949'>3949</a>
<a id='n3950' href='#n3950'>3950</a>
<a id='n3951' href='#n3951'>3951</a>
<a id='n3952' href='#n3952'>3952</a>
<a id='n3953' href='#n3953'>3953</a>
<a id='n3954' href='#n3954'>3954</a>
<a id='n3955' href='#n3955'>3955</a>
<a id='n3956' href='#n3956'>3956</a>
<a id='n3957' href='#n3957'>3957</a>
<a id='n3958' href='#n3958'>3958</a>
<a id='n3959' href='#n3959'>3959</a>
<a id='n3960' href='#n3960'>3960</a>
<a id='n3961' href='#n3961'>3961</a>
<a id='n3962' href='#n3962'>3962</a>
<a id='n3963' href='#n3963'>3963</a>
<a id='n3964' href='#n3964'>3964</a>
<a id='n3965' href='#n3965'>3965</a>
<a id='n3966' href='#n3966'>3966</a>
<a id='n3967' href='#n3967'>3967</a>
<a id='n3968' href='#n3968'>3968</a>
<a id='n3969' href='#n3969'>3969</a>
<a id='n3970' href='#n3970'>3970</a>
<a id='n3971' href='#n3971'>3971</a>
<a id='n3972' href='#n3972'>3972</a>
<a id='n3973' href='#n3973'>3973</a>
<a id='n3974' href='#n3974'>3974</a>
<a id='n3975' href='#n3975'>3975</a>
<a id='n3976' href='#n3976'>3976</a>
<a id='n3977' href='#n3977'>3977</a>
<a id='n3978' href='#n3978'>3978</a>
<a id='n3979' href='#n3979'>3979</a>
<a id='n3980' href='#n3980'>3980</a>
<a id='n3981' href='#n3981'>3981</a>
<a id='n3982' href='#n3982'>3982</a>
<a id='n3983' href='#n3983'>3983</a>
<a id='n3984' href='#n3984'>3984</a>
<a id='n3985' href='#n3985'>3985</a>
<a id='n3986' href='#n3986'>3986</a>
<a id='n3987' href='#n3987'>3987</a>
<a id='n3988' href='#n3988'>3988</a>
<a id='n3989' href='#n3989'>3989</a>
<a id='n3990' href='#n3990'>3990</a>
<a id='n3991' href='#n3991'>3991</a>
<a id='n3992' href='#n3992'>3992</a>
<a id='n3993' href='#n3993'>3993</a>
<a id='n3994' href='#n3994'>3994</a>
<a id='n3995' href='#n3995'>3995</a>
<a id='n3996' href='#n3996'>3996</a>
<a id='n3997' href='#n3997'>3997</a>
<a id='n3998' href='#n3998'>3998</a>
<a id='n3999' href='#n3999'>3999</a>
<a id='n4000' href='#n4000'>4000</a>
<a id='n4001' href='#n4001'>4001</a>
<a id='n4002' href='#n4002'>4002</a>
<a id='n4003' href='#n4003'>4003</a>
<a id='n4004' href='#n4004'>4004</a>
<a id='n4005' href='#n4005'>4005</a>
<a id='n4006' href='#n4006'>4006</a>
<a id='n4007' href='#n4007'>4007</a>
<a id='n4008' href='#n4008'>4008</a>
<a id='n4009' href='#n4009'>4009</a>
<a id='n4010' href='#n4010'>4010</a>
<a id='n4011' href='#n4011'>4011</a>
<a id='n4012' href='#n4012'>4012</a>
<a id='n4013' href='#n4013'>4013</a>
<a id='n4014' href='#n4014'>4014</a>
<a id='n4015' href='#n4015'>4015</a>
<a id='n4016' href='#n4016'>4016</a>
<a id='n4017' href='#n4017'>4017</a>
<a id='n4018' href='#n4018'>4018</a>
<a id='n4019' href='#n4019'>4019</a>
<a id='n4020' href='#n4020'>4020</a>
<a id='n4021' href='#n4021'>4021</a>
<a id='n4022' href='#n4022'>4022</a>
<a id='n4023' href='#n4023'>4023</a>
<a id='n4024' href='#n4024'>4024</a>
<a id='n4025' href='#n4025'>4025</a>
<a id='n4026' href='#n4026'>4026</a>
<a id='n4027' href='#n4027'>4027</a>
<a id='n4028' href='#n4028'>4028</a>
<a id='n4029' href='#n4029'>4029</a>
<a id='n4030' href='#n4030'>4030</a>
<a id='n4031' href='#n4031'>4031</a>
<a id='n4032' href='#n4032'>4032</a>
<a id='n4033' href='#n4033'>4033</a>
<a id='n4034' href='#n4034'>4034</a>
<a id='n4035' href='#n4035'>4035</a>
<a id='n4036' href='#n4036'>4036</a>
<a id='n4037' href='#n4037'>4037</a>
<a id='n4038' href='#n4038'>4038</a>
<a id='n4039' href='#n4039'>4039</a>
<a id='n4040' href='#n4040'>4040</a>
<a id='n4041' href='#n4041'>4041</a>
<a id='n4042' href='#n4042'>4042</a>
<a id='n4043' href='#n4043'>4043</a>
<a id='n4044' href='#n4044'>4044</a>
<a id='n4045' href='#n4045'>4045</a>
<a id='n4046' href='#n4046'>4046</a>
<a id='n4047' href='#n4047'>4047</a>
<a id='n4048' href='#n4048'>4048</a>
<a id='n4049' href='#n4049'>4049</a>
<a id='n4050' href='#n4050'>4050</a>
<a id='n4051' href='#n4051'>4051</a>
<a id='n4052' href='#n4052'>4052</a>
<a id='n4053' href='#n4053'>4053</a>
<a id='n4054' href='#n4054'>4054</a>
<a id='n4055' href='#n4055'>4055</a>
<a id='n4056' href='#n4056'>4056</a>
<a id='n4057' href='#n4057'>4057</a>
<a id='n4058' href='#n4058'>4058</a>
<a id='n4059' href='#n4059'>4059</a>
<a id='n4060' href='#n4060'>4060</a>
<a id='n4061' href='#n4061'>4061</a>
<a id='n4062' href='#n4062'>4062</a>
<a id='n4063' href='#n4063'>4063</a>
<a id='n4064' href='#n4064'>4064</a>
<a id='n4065' href='#n4065'>4065</a>
<a id='n4066' href='#n4066'>4066</a>
<a id='n4067' href='#n4067'>4067</a>
<a id='n4068' href='#n4068'>4068</a>
<a id='n4069' href='#n4069'>4069</a>
<a id='n4070' href='#n4070'>4070</a>
<a id='n4071' href='#n4071'>4071</a>
<a id='n4072' href='#n4072'>4072</a>
<a id='n4073' href='#n4073'>4073</a>
<a id='n4074' href='#n4074'>4074</a>
<a id='n4075' href='#n4075'>4075</a>
<a id='n4076' href='#n4076'>4076</a>
<a id='n4077' href='#n4077'>4077</a>
<a id='n4078' href='#n4078'>4078</a>
<a id='n4079' href='#n4079'>4079</a>
<a id='n4080' href='#n4080'>4080</a>
<a id='n4081' href='#n4081'>4081</a>
<a id='n4082' href='#n4082'>4082</a>
<a id='n4083' href='#n4083'>4083</a>
<a id='n4084' href='#n4084'>4084</a>
<a id='n4085' href='#n4085'>4085</a>
<a id='n4086' href='#n4086'>4086</a>
<a id='n4087' href='#n4087'>4087</a>
<a id='n4088' href='#n4088'>4088</a>
<a id='n4089' href='#n4089'>4089</a>
<a id='n4090' href='#n4090'>4090</a>
<a id='n4091' href='#n4091'>4091</a>
<a id='n4092' href='#n4092'>4092</a>
<a id='n4093' href='#n4093'>4093</a>
<a id='n4094' href='#n4094'>4094</a>
<a id='n4095' href='#n4095'>4095</a>
<a id='n4096' href='#n4096'>4096</a>
<a id='n4097' href='#n4097'>4097</a>
<a id='n4098' href='#n4098'>4098</a>
<a id='n4099' href='#n4099'>4099</a>
<a id='n4100' href='#n4100'>4100</a>
<a id='n4101' href='#n4101'>4101</a>
<a id='n4102' href='#n4102'>4102</a>
<a id='n4103' href='#n4103'>4103</a>
<a id='n4104' href='#n4104'>4104</a>
<a id='n4105' href='#n4105'>4105</a>
<a id='n4106' href='#n4106'>4106</a>
<a id='n4107' href='#n4107'>4107</a>
<a id='n4108' href='#n4108'>4108</a>
<a id='n4109' href='#n4109'>4109</a>
<a id='n4110' href='#n4110'>4110</a>
<a id='n4111' href='#n4111'>4111</a>
<a id='n4112' href='#n4112'>4112</a>
<a id='n4113' href='#n4113'>4113</a>
<a id='n4114' href='#n4114'>4114</a>
<a id='n4115' href='#n4115'>4115</a>
<a id='n4116' href='#n4116'>4116</a>
<a id='n4117' href='#n4117'>4117</a>
<a id='n4118' href='#n4118'>4118</a>
<a id='n4119' href='#n4119'>4119</a>
<a id='n4120' href='#n4120'>4120</a>
<a id='n4121' href='#n4121'>4121</a>
<a id='n4122' href='#n4122'>4122</a>
<a id='n4123' href='#n4123'>4123</a>
<a id='n4124' href='#n4124'>4124</a>
<a id='n4125' href='#n4125'>4125</a>
<a id='n4126' href='#n4126'>4126</a>
<a id='n4127' href='#n4127'>4127</a>
<a id='n4128' href='#n4128'>4128</a>
<a id='n4129' href='#n4129'>4129</a>
<a id='n4130' href='#n4130'>4130</a>
<a id='n4131' href='#n4131'>4131</a>
<a id='n4132' href='#n4132'>4132</a>
<a id='n4133' href='#n4133'>4133</a>
<a id='n4134' href='#n4134'>4134</a>
<a id='n4135' href='#n4135'>4135</a>
<a id='n4136' href='#n4136'>4136</a>
<a id='n4137' href='#n4137'>4137</a>
<a id='n4138' href='#n4138'>4138</a>
<a id='n4139' href='#n4139'>4139</a>
<a id='n4140' href='#n4140'>4140</a>
<a id='n4141' href='#n4141'>4141</a>
<a id='n4142' href='#n4142'>4142</a>
<a id='n4143' href='#n4143'>4143</a>
<a id='n4144' href='#n4144'>4144</a>
<a id='n4145' href='#n4145'>4145</a>
<a id='n4146' href='#n4146'>4146</a>
<a id='n4147' href='#n4147'>4147</a>
<a id='n4148' href='#n4148'>4148</a>
<a id='n4149' href='#n4149'>4149</a>
<a id='n4150' href='#n4150'>4150</a>
<a id='n4151' href='#n4151'>4151</a>
<a id='n4152' href='#n4152'>4152</a>
<a id='n4153' href='#n4153'>4153</a>
<a id='n4154' href='#n4154'>4154</a>
<a id='n4155' href='#n4155'>4155</a>
<a id='n4156' href='#n4156'>4156</a>
<a id='n4157' href='#n4157'>4157</a>
<a id='n4158' href='#n4158'>4158</a>
<a id='n4159' href='#n4159'>4159</a>
<a id='n4160' href='#n4160'>4160</a>
<a id='n4161' href='#n4161'>4161</a>
<a id='n4162' href='#n4162'>4162</a>
<a id='n4163' href='#n4163'>4163</a>
<a id='n4164' href='#n4164'>4164</a>
<a id='n4165' href='#n4165'>4165</a>
<a id='n4166' href='#n4166'>4166</a>
<a id='n4167' href='#n4167'>4167</a>
<a id='n4168' href='#n4168'>4168</a>
<a id='n4169' href='#n4169'>4169</a>
<a id='n4170' href='#n4170'>4170</a>
<a id='n4171' href='#n4171'>4171</a>
<a id='n4172' href='#n4172'>4172</a>
<a id='n4173' href='#n4173'>4173</a>
<a id='n4174' href='#n4174'>4174</a>
<a id='n4175' href='#n4175'>4175</a>
<a id='n4176' href='#n4176'>4176</a>
<a id='n4177' href='#n4177'>4177</a>
<a id='n4178' href='#n4178'>4178</a>
<a id='n4179' href='#n4179'>4179</a>
<a id='n4180' href='#n4180'>4180</a>
<a id='n4181' href='#n4181'>4181</a>
<a id='n4182' href='#n4182'>4182</a>
<a id='n4183' href='#n4183'>4183</a>
<a id='n4184' href='#n4184'>4184</a>
<a id='n4185' href='#n4185'>4185</a>
<a id='n4186' href='#n4186'>4186</a>
<a id='n4187' href='#n4187'>4187</a>
<a id='n4188' href='#n4188'>4188</a>
<a id='n4189' href='#n4189'>4189</a>
<a id='n4190' href='#n4190'>4190</a>
<a id='n4191' href='#n4191'>4191</a>
<a id='n4192' href='#n4192'>4192</a>
<a id='n4193' href='#n4193'>4193</a>
<a id='n4194' href='#n4194'>4194</a>
<a id='n4195' href='#n4195'>4195</a>
<a id='n4196' href='#n4196'>4196</a>
<a id='n4197' href='#n4197'>4197</a>
<a id='n4198' href='#n4198'>4198</a>
<a id='n4199' href='#n4199'>4199</a>
<a id='n4200' href='#n4200'>4200</a>
<a id='n4201' href='#n4201'>4201</a>
<a id='n4202' href='#n4202'>4202</a>
<a id='n4203' href='#n4203'>4203</a>
<a id='n4204' href='#n4204'>4204</a>
<a id='n4205' href='#n4205'>4205</a>
<a id='n4206' href='#n4206'>4206</a>
<a id='n4207' href='#n4207'>4207</a>
<a id='n4208' href='#n4208'>4208</a>
<a id='n4209' href='#n4209'>4209</a>
<a id='n4210' href='#n4210'>4210</a>
<a id='n4211' href='#n4211'>4211</a>
<a id='n4212' href='#n4212'>4212</a>
<a id='n4213' href='#n4213'>4213</a>
<a id='n4214' href='#n4214'>4214</a>
<a id='n4215' href='#n4215'>4215</a>
<a id='n4216' href='#n4216'>4216</a>
<a id='n4217' href='#n4217'>4217</a>
<a id='n4218' href='#n4218'>4218</a>
<a id='n4219' href='#n4219'>4219</a>
<a id='n4220' href='#n4220'>4220</a>
<a id='n4221' href='#n4221'>4221</a>
<a id='n4222' href='#n4222'>4222</a>
<a id='n4223' href='#n4223'>4223</a>
<a id='n4224' href='#n4224'>4224</a>
<a id='n4225' href='#n4225'>4225</a>
<a id='n4226' href='#n4226'>4226</a>
<a id='n4227' href='#n4227'>4227</a>
<a id='n4228' href='#n4228'>4228</a>
<a id='n4229' href='#n4229'>4229</a>
<a id='n4230' href='#n4230'>4230</a>
<a id='n4231' href='#n4231'>4231</a>
<a id='n4232' href='#n4232'>4232</a>
<a id='n4233' href='#n4233'>4233</a>
<a id='n4234' href='#n4234'>4234</a>
<a id='n4235' href='#n4235'>4235</a>
<a id='n4236' href='#n4236'>4236</a>
<a id='n4237' href='#n4237'>4237</a>
<a id='n4238' href='#n4238'>4238</a>
<a id='n4239' href='#n4239'>4239</a>
<a id='n4240' href='#n4240'>4240</a>
<a id='n4241' href='#n4241'>4241</a>
<a id='n4242' href='#n4242'>4242</a>
<a id='n4243' href='#n4243'>4243</a>
<a id='n4244' href='#n4244'>4244</a>
<a id='n4245' href='#n4245'>4245</a>
<a id='n4246' href='#n4246'>4246</a>
<a id='n4247' href='#n4247'>4247</a>
<a id='n4248' href='#n4248'>4248</a>
<a id='n4249' href='#n4249'>4249</a>
<a id='n4250' href='#n4250'>4250</a>
<a id='n4251' href='#n4251'>4251</a>
<a id='n4252' href='#n4252'>4252</a>
<a id='n4253' href='#n4253'>4253</a>
<a id='n4254' href='#n4254'>4254</a>
<a id='n4255' href='#n4255'>4255</a>
<a id='n4256' href='#n4256'>4256</a>
<a id='n4257' href='#n4257'>4257</a>
<a id='n4258' href='#n4258'>4258</a>
<a id='n4259' href='#n4259'>4259</a>
<a id='n4260' href='#n4260'>4260</a>
<a id='n4261' href='#n4261'>4261</a>
<a id='n4262' href='#n4262'>4262</a>
<a id='n4263' href='#n4263'>4263</a>
<a id='n4264' href='#n4264'>4264</a>
<a id='n4265' href='#n4265'>4265</a>
<a id='n4266' href='#n4266'>4266</a>
<a id='n4267' href='#n4267'>4267</a>
<a id='n4268' href='#n4268'>4268</a>
<a id='n4269' href='#n4269'>4269</a>
<a id='n4270' href='#n4270'>4270</a>
<a id='n4271' href='#n4271'>4271</a>
<a id='n4272' href='#n4272'>4272</a>
<a id='n4273' href='#n4273'>4273</a>
<a id='n4274' href='#n4274'>4274</a>
<a id='n4275' href='#n4275'>4275</a>
<a id='n4276' href='#n4276'>4276</a>
<a id='n4277' href='#n4277'>4277</a>
<a id='n4278' href='#n4278'>4278</a>
<a id='n4279' href='#n4279'>4279</a>
<a id='n4280' href='#n4280'>4280</a>
<a id='n4281' href='#n4281'>4281</a>
<a id='n4282' href='#n4282'>4282</a>
<a id='n4283' href='#n4283'>4283</a>
<a id='n4284' href='#n4284'>4284</a>
<a id='n4285' href='#n4285'>4285</a>
<a id='n4286' href='#n4286'>4286</a>
<a id='n4287' href='#n4287'>4287</a>
<a id='n4288' href='#n4288'>4288</a>
<a id='n4289' href='#n4289'>4289</a>
<a id='n4290' href='#n4290'>4290</a>
<a id='n4291' href='#n4291'>4291</a>
<a id='n4292' href='#n4292'>4292</a>
<a id='n4293' href='#n4293'>4293</a>
<a id='n4294' href='#n4294'>4294</a>
<a id='n4295' href='#n4295'>4295</a>
<a id='n4296' href='#n4296'>4296</a>
<a id='n4297' href='#n4297'>4297</a>
<a id='n4298' href='#n4298'>4298</a>
<a id='n4299' href='#n4299'>4299</a>
<a id='n4300' href='#n4300'>4300</a>
<a id='n4301' href='#n4301'>4301</a>
<a id='n4302' href='#n4302'>4302</a>
<a id='n4303' href='#n4303'>4303</a>
<a id='n4304' href='#n4304'>4304</a>
<a id='n4305' href='#n4305'>4305</a>
<a id='n4306' href='#n4306'>4306</a>
<a id='n4307' href='#n4307'>4307</a>
<a id='n4308' href='#n4308'>4308</a>
<a id='n4309' href='#n4309'>4309</a>
<a id='n4310' href='#n4310'>4310</a>
<a id='n4311' href='#n4311'>4311</a>
<a id='n4312' href='#n4312'>4312</a>
<a id='n4313' href='#n4313'>4313</a>
<a id='n4314' href='#n4314'>4314</a>
<a id='n4315' href='#n4315'>4315</a>
<a id='n4316' href='#n4316'>4316</a>
<a id='n4317' href='#n4317'>4317</a>
<a id='n4318' href='#n4318'>4318</a>
<a id='n4319' href='#n4319'>4319</a>
<a id='n4320' href='#n4320'>4320</a>
<a id='n4321' href='#n4321'>4321</a>
<a id='n4322' href='#n4322'>4322</a>
<a id='n4323' href='#n4323'>4323</a>
<a id='n4324' href='#n4324'>4324</a>
<a id='n4325' href='#n4325'>4325</a>
<a id='n4326' href='#n4326'>4326</a>
<a id='n4327' href='#n4327'>4327</a>
<a id='n4328' href='#n4328'>4328</a>
<a id='n4329' href='#n4329'>4329</a>
<a id='n4330' href='#n4330'>4330</a>
<a id='n4331' href='#n4331'>4331</a>
<a id='n4332' href='#n4332'>4332</a>
<a id='n4333' href='#n4333'>4333</a>
<a id='n4334' href='#n4334'>4334</a>
<a id='n4335' href='#n4335'>4335</a>
<a id='n4336' href='#n4336'>4336</a>
<a id='n4337' href='#n4337'>4337</a>
<a id='n4338' href='#n4338'>4338</a>
<a id='n4339' href='#n4339'>4339</a>
<a id='n4340' href='#n4340'>4340</a>
<a id='n4341' href='#n4341'>4341</a>
<a id='n4342' href='#n4342'>4342</a>
<a id='n4343' href='#n4343'>4343</a>
<a id='n4344' href='#n4344'>4344</a>
<a id='n4345' href='#n4345'>4345</a>
<a id='n4346' href='#n4346'>4346</a>
<a id='n4347' href='#n4347'>4347</a>
<a id='n4348' href='#n4348'>4348</a>
<a id='n4349' href='#n4349'>4349</a>
<a id='n4350' href='#n4350'>4350</a>
<a id='n4351' href='#n4351'>4351</a>
<a id='n4352' href='#n4352'>4352</a>
<a id='n4353' href='#n4353'>4353</a>
<a id='n4354' href='#n4354'>4354</a>
<a id='n4355' href='#n4355'>4355</a>
<a id='n4356' href='#n4356'>4356</a>
<a id='n4357' href='#n4357'>4357</a>
<a id='n4358' href='#n4358'>4358</a>
<a id='n4359' href='#n4359'>4359</a>
<a id='n4360' href='#n4360'>4360</a>
<a id='n4361' href='#n4361'>4361</a>
<a id='n4362' href='#n4362'>4362</a>
<a id='n4363' href='#n4363'>4363</a>
<a id='n4364' href='#n4364'>4364</a>
<a id='n4365' href='#n4365'>4365</a>
<a id='n4366' href='#n4366'>4366</a>
<a id='n4367' href='#n4367'>4367</a>
<a id='n4368' href='#n4368'>4368</a>
<a id='n4369' href='#n4369'>4369</a>
<a id='n4370' href='#n4370'>4370</a>
<a id='n4371' href='#n4371'>4371</a>
<a id='n4372' href='#n4372'>4372</a>
<a id='n4373' href='#n4373'>4373</a>
<a id='n4374' href='#n4374'>4374</a>
<a id='n4375' href='#n4375'>4375</a>
<a id='n4376' href='#n4376'>4376</a>
<a id='n4377' href='#n4377'>4377</a>
<a id='n4378' href='#n4378'>4378</a>
<a id='n4379' href='#n4379'>4379</a>
<a id='n4380' href='#n4380'>4380</a>
<a id='n4381' href='#n4381'>4381</a>
<a id='n4382' href='#n4382'>4382</a>
<a id='n4383' href='#n4383'>4383</a>
<a id='n4384' href='#n4384'>4384</a>
<a id='n4385' href='#n4385'>4385</a>
<a id='n4386' href='#n4386'>4386</a>
<a id='n4387' href='#n4387'>4387</a>
<a id='n4388' href='#n4388'>4388</a>
<a id='n4389' href='#n4389'>4389</a>
<a id='n4390' href='#n4390'>4390</a>
<a id='n4391' href='#n4391'>4391</a>
<a id='n4392' href='#n4392'>4392</a>
<a id='n4393' href='#n4393'>4393</a>
<a id='n4394' href='#n4394'>4394</a>
<a id='n4395' href='#n4395'>4395</a>
<a id='n4396' href='#n4396'>4396</a>
<a id='n4397' href='#n4397'>4397</a>
<a id='n4398' href='#n4398'>4398</a>
<a id='n4399' href='#n4399'>4399</a>
<a id='n4400' href='#n4400'>4400</a>
<a id='n4401' href='#n4401'>4401</a>
<a id='n4402' href='#n4402'>4402</a>
<a id='n4403' href='#n4403'>4403</a>
<a id='n4404' href='#n4404'>4404</a>
<a id='n4405' href='#n4405'>4405</a>
<a id='n4406' href='#n4406'>4406</a>
<a id='n4407' href='#n4407'>4407</a>
<a id='n4408' href='#n4408'>4408</a>
<a id='n4409' href='#n4409'>4409</a>
<a id='n4410' href='#n4410'>4410</a>
<a id='n4411' href='#n4411'>4411</a>
<a id='n4412' href='#n4412'>4412</a>
<a id='n4413' href='#n4413'>4413</a>
<a id='n4414' href='#n4414'>4414</a>
<a id='n4415' href='#n4415'>4415</a>
<a id='n4416' href='#n4416'>4416</a>
<a id='n4417' href='#n4417'>4417</a>
<a id='n4418' href='#n4418'>4418</a>
<a id='n4419' href='#n4419'>4419</a>
<a id='n4420' href='#n4420'>4420</a>
<a id='n4421' href='#n4421'>4421</a>
<a id='n4422' href='#n4422'>4422</a>
<a id='n4423' href='#n4423'>4423</a>
<a id='n4424' href='#n4424'>4424</a>
<a id='n4425' href='#n4425'>4425</a>
<a id='n4426' href='#n4426'>4426</a>
<a id='n4427' href='#n4427'>4427</a>
<a id='n4428' href='#n4428'>4428</a>
<a id='n4429' href='#n4429'>4429</a>
<a id='n4430' href='#n4430'>4430</a>
<a id='n4431' href='#n4431'>4431</a>
<a id='n4432' href='#n4432'>4432</a>
<a id='n4433' href='#n4433'>4433</a>
<a id='n4434' href='#n4434'>4434</a>
<a id='n4435' href='#n4435'>4435</a>
<a id='n4436' href='#n4436'>4436</a>
<a id='n4437' href='#n4437'>4437</a>
<a id='n4438' href='#n4438'>4438</a>
<a id='n4439' href='#n4439'>4439</a>
<a id='n4440' href='#n4440'>4440</a>
<a id='n4441' href='#n4441'>4441</a>
<a id='n4442' href='#n4442'>4442</a>
<a id='n4443' href='#n4443'>4443</a>
<a id='n4444' href='#n4444'>4444</a>
<a id='n4445' href='#n4445'>4445</a>
<a id='n4446' href='#n4446'>4446</a>
<a id='n4447' href='#n4447'>4447</a>
<a id='n4448' href='#n4448'>4448</a>
<a id='n4449' href='#n4449'>4449</a>
<a id='n4450' href='#n4450'>4450</a>
<a id='n4451' href='#n4451'>4451</a>
<a id='n4452' href='#n4452'>4452</a>
<a id='n4453' href='#n4453'>4453</a>
<a id='n4454' href='#n4454'>4454</a>
<a id='n4455' href='#n4455'>4455</a>
<a id='n4456' href='#n4456'>4456</a>
<a id='n4457' href='#n4457'>4457</a>
<a id='n4458' href='#n4458'>4458</a>
<a id='n4459' href='#n4459'>4459</a>
<a id='n4460' href='#n4460'>4460</a>
<a id='n4461' href='#n4461'>4461</a>
<a id='n4462' href='#n4462'>4462</a>
<a id='n4463' href='#n4463'>4463</a>
<a id='n4464' href='#n4464'>4464</a>
<a id='n4465' href='#n4465'>4465</a>
<a id='n4466' href='#n4466'>4466</a>
<a id='n4467' href='#n4467'>4467</a>
<a id='n4468' href='#n4468'>4468</a>
<a id='n4469' href='#n4469'>4469</a>
<a id='n4470' href='#n4470'>4470</a>
<a id='n4471' href='#n4471'>4471</a>
<a id='n4472' href='#n4472'>4472</a>
<a id='n4473' href='#n4473'>4473</a>
<a id='n4474' href='#n4474'>4474</a>
<a id='n4475' href='#n4475'>4475</a>
<a id='n4476' href='#n4476'>4476</a>
<a id='n4477' href='#n4477'>4477</a>
<a id='n4478' href='#n4478'>4478</a>
<a id='n4479' href='#n4479'>4479</a>
<a id='n4480' href='#n4480'>4480</a>
<a id='n4481' href='#n4481'>4481</a>
<a id='n4482' href='#n4482'>4482</a>
<a id='n4483' href='#n4483'>4483</a>
<a id='n4484' href='#n4484'>4484</a>
<a id='n4485' href='#n4485'>4485</a>
<a id='n4486' href='#n4486'>4486</a>
<a id='n4487' href='#n4487'>4487</a>
<a id='n4488' href='#n4488'>4488</a>
<a id='n4489' href='#n4489'>4489</a>
<a id='n4490' href='#n4490'>4490</a>
<a id='n4491' href='#n4491'>4491</a>
<a id='n4492' href='#n4492'>4492</a>
<a id='n4493' href='#n4493'>4493</a>
<a id='n4494' href='#n4494'>4494</a>
<a id='n4495' href='#n4495'>4495</a>
<a id='n4496' href='#n4496'>4496</a>
<a id='n4497' href='#n4497'>4497</a>
<a id='n4498' href='#n4498'>4498</a>
<a id='n4499' href='#n4499'>4499</a>
<a id='n4500' href='#n4500'>4500</a>
<a id='n4501' href='#n4501'>4501</a>
<a id='n4502' href='#n4502'>4502</a>
<a id='n4503' href='#n4503'>4503</a>
<a id='n4504' href='#n4504'>4504</a>
<a id='n4505' href='#n4505'>4505</a>
<a id='n4506' href='#n4506'>4506</a>
<a id='n4507' href='#n4507'>4507</a>
<a id='n4508' href='#n4508'>4508</a>
<a id='n4509' href='#n4509'>4509</a>
<a id='n4510' href='#n4510'>4510</a>
<a id='n4511' href='#n4511'>4511</a>
<a id='n4512' href='#n4512'>4512</a>
<a id='n4513' href='#n4513'>4513</a>
<a id='n4514' href='#n4514'>4514</a>
<a id='n4515' href='#n4515'>4515</a>
<a id='n4516' href='#n4516'>4516</a>
<a id='n4517' href='#n4517'>4517</a>
<a id='n4518' href='#n4518'>4518</a>
<a id='n4519' href='#n4519'>4519</a>
<a id='n4520' href='#n4520'>4520</a>
<a id='n4521' href='#n4521'>4521</a>
<a id='n4522' href='#n4522'>4522</a>
<a id='n4523' href='#n4523'>4523</a>
<a id='n4524' href='#n4524'>4524</a>
<a id='n4525' href='#n4525'>4525</a>
<a id='n4526' href='#n4526'>4526</a>
<a id='n4527' href='#n4527'>4527</a>
<a id='n4528' href='#n4528'>4528</a>
<a id='n4529' href='#n4529'>4529</a>
<a id='n4530' href='#n4530'>4530</a>
<a id='n4531' href='#n4531'>4531</a>
<a id='n4532' href='#n4532'>4532</a>
<a id='n4533' href='#n4533'>4533</a>
<a id='n4534' href='#n4534'>4534</a>
<a id='n4535' href='#n4535'>4535</a>
<a id='n4536' href='#n4536'>4536</a>
<a id='n4537' href='#n4537'>4537</a>
<a id='n4538' href='#n4538'>4538</a>
<a id='n4539' href='#n4539'>4539</a>
<a id='n4540' href='#n4540'>4540</a>
<a id='n4541' href='#n4541'>4541</a>
<a id='n4542' href='#n4542'>4542</a>
<a id='n4543' href='#n4543'>4543</a>
<a id='n4544' href='#n4544'>4544</a>
<a id='n4545' href='#n4545'>4545</a>
<a id='n4546' href='#n4546'>4546</a>
<a id='n4547' href='#n4547'>4547</a>
<a id='n4548' href='#n4548'>4548</a>
<a id='n4549' href='#n4549'>4549</a>
<a id='n4550' href='#n4550'>4550</a>
<a id='n4551' href='#n4551'>4551</a>
<a id='n4552' href='#n4552'>4552</a>
<a id='n4553' href='#n4553'>4553</a>
<a id='n4554' href='#n4554'>4554</a>
<a id='n4555' href='#n4555'>4555</a>
<a id='n4556' href='#n4556'>4556</a>
<a id='n4557' href='#n4557'>4557</a>
<a id='n4558' href='#n4558'>4558</a>
<a id='n4559' href='#n4559'>4559</a>
<a id='n4560' href='#n4560'>4560</a>
<a id='n4561' href='#n4561'>4561</a>
<a id='n4562' href='#n4562'>4562</a>
<a id='n4563' href='#n4563'>4563</a>
<a id='n4564' href='#n4564'>4564</a>
<a id='n4565' href='#n4565'>4565</a>
<a id='n4566' href='#n4566'>4566</a>
<a id='n4567' href='#n4567'>4567</a>
<a id='n4568' href='#n4568'>4568</a>
<a id='n4569' href='#n4569'>4569</a>
<a id='n4570' href='#n4570'>4570</a>
<a id='n4571' href='#n4571'>4571</a>
<a id='n4572' href='#n4572'>4572</a>
<a id='n4573' href='#n4573'>4573</a>
<a id='n4574' href='#n4574'>4574</a>
<a id='n4575' href='#n4575'>4575</a>
<a id='n4576' href='#n4576'>4576</a>
<a id='n4577' href='#n4577'>4577</a>
<a id='n4578' href='#n4578'>4578</a>
<a id='n4579' href='#n4579'>4579</a>
<a id='n4580' href='#n4580'>4580</a>
<a id='n4581' href='#n4581'>4581</a>
<a id='n4582' href='#n4582'>4582</a>
<a id='n4583' href='#n4583'>4583</a>
<a id='n4584' href='#n4584'>4584</a>
<a id='n4585' href='#n4585'>4585</a>
<a id='n4586' href='#n4586'>4586</a>
<a id='n4587' href='#n4587'>4587</a>
<a id='n4588' href='#n4588'>4588</a>
<a id='n4589' href='#n4589'>4589</a>
<a id='n4590' href='#n4590'>4590</a>
<a id='n4591' href='#n4591'>4591</a>
<a id='n4592' href='#n4592'>4592</a>
<a id='n4593' href='#n4593'>4593</a>
<a id='n4594' href='#n4594'>4594</a>
<a id='n4595' href='#n4595'>4595</a>
<a id='n4596' href='#n4596'>4596</a>
<a id='n4597' href='#n4597'>4597</a>
<a id='n4598' href='#n4598'>4598</a>
<a id='n4599' href='#n4599'>4599</a>
<a id='n4600' href='#n4600'>4600</a>
<a id='n4601' href='#n4601'>4601</a>
<a id='n4602' href='#n4602'>4602</a>
<a id='n4603' href='#n4603'>4603</a>
<a id='n4604' href='#n4604'>4604</a>
<a id='n4605' href='#n4605'>4605</a>
<a id='n4606' href='#n4606'>4606</a>
<a id='n4607' href='#n4607'>4607</a>
<a id='n4608' href='#n4608'>4608</a>
<a id='n4609' href='#n4609'>4609</a>
<a id='n4610' href='#n4610'>4610</a>
<a id='n4611' href='#n4611'>4611</a>
<a id='n4612' href='#n4612'>4612</a>
<a id='n4613' href='#n4613'>4613</a>
<a id='n4614' href='#n4614'>4614</a>
<a id='n4615' href='#n4615'>4615</a>
<a id='n4616' href='#n4616'>4616</a>
<a id='n4617' href='#n4617'>4617</a>
<a id='n4618' href='#n4618'>4618</a>
<a id='n4619' href='#n4619'>4619</a>
<a id='n4620' href='#n4620'>4620</a>
<a id='n4621' href='#n4621'>4621</a>
<a id='n4622' href='#n4622'>4622</a>
<a id='n4623' href='#n4623'>4623</a>
<a id='n4624' href='#n4624'>4624</a>
<a id='n4625' href='#n4625'>4625</a>
<a id='n4626' href='#n4626'>4626</a>
<a id='n4627' href='#n4627'>4627</a>
<a id='n4628' href='#n4628'>4628</a>
<a id='n4629' href='#n4629'>4629</a>
<a id='n4630' href='#n4630'>4630</a>
<a id='n4631' href='#n4631'>4631</a>
<a id='n4632' href='#n4632'>4632</a>
<a id='n4633' href='#n4633'>4633</a>
<a id='n4634' href='#n4634'>4634</a>
<a id='n4635' href='#n4635'>4635</a>
<a id='n4636' href='#n4636'>4636</a>
<a id='n4637' href='#n4637'>4637</a>
<a id='n4638' href='#n4638'>4638</a>
<a id='n4639' href='#n4639'>4639</a>
<a id='n4640' href='#n4640'>4640</a>
<a id='n4641' href='#n4641'>4641</a>
<a id='n4642' href='#n4642'>4642</a>
<a id='n4643' href='#n4643'>4643</a>
<a id='n4644' href='#n4644'>4644</a>
<a id='n4645' href='#n4645'>4645</a>
<a id='n4646' href='#n4646'>4646</a>
<a id='n4647' href='#n4647'>4647</a>
<a id='n4648' href='#n4648'>4648</a>
<a id='n4649' href='#n4649'>4649</a>
<a id='n4650' href='#n4650'>4650</a>
<a id='n4651' href='#n4651'>4651</a>
<a id='n4652' href='#n4652'>4652</a>
<a id='n4653' href='#n4653'>4653</a>
<a id='n4654' href='#n4654'>4654</a>
<a id='n4655' href='#n4655'>4655</a>
<a id='n4656' href='#n4656'>4656</a>
<a id='n4657' href='#n4657'>4657</a>
<a id='n4658' href='#n4658'>4658</a>
<a id='n4659' href='#n4659'>4659</a>
<a id='n4660' href='#n4660'>4660</a>
<a id='n4661' href='#n4661'>4661</a>
<a id='n4662' href='#n4662'>4662</a>
<a id='n4663' href='#n4663'>4663</a>
<a id='n4664' href='#n4664'>4664</a>
<a id='n4665' href='#n4665'>4665</a>
<a id='n4666' href='#n4666'>4666</a>
<a id='n4667' href='#n4667'>4667</a>
<a id='n4668' href='#n4668'>4668</a>
<a id='n4669' href='#n4669'>4669</a>
<a id='n4670' href='#n4670'>4670</a>
<a id='n4671' href='#n4671'>4671</a>
<a id='n4672' href='#n4672'>4672</a>
<a id='n4673' href='#n4673'>4673</a>
<a id='n4674' href='#n4674'>4674</a>
<a id='n4675' href='#n4675'>4675</a>
<a id='n4676' href='#n4676'>4676</a>
<a id='n4677' href='#n4677'>4677</a>
<a id='n4678' href='#n4678'>4678</a>
<a id='n4679' href='#n4679'>4679</a>
<a id='n4680' href='#n4680'>4680</a>
<a id='n4681' href='#n4681'>4681</a>
<a id='n4682' href='#n4682'>4682</a>
<a id='n4683' href='#n4683'>4683</a>
<a id='n4684' href='#n4684'>4684</a>
<a id='n4685' href='#n4685'>4685</a>
<a id='n4686' href='#n4686'>4686</a>
<a id='n4687' href='#n4687'>4687</a>
<a id='n4688' href='#n4688'>4688</a>
<a id='n4689' href='#n4689'>4689</a>
<a id='n4690' href='#n4690'>4690</a>
<a id='n4691' href='#n4691'>4691</a>
<a id='n4692' href='#n4692'>4692</a>
<a id='n4693' href='#n4693'>4693</a>
<a id='n4694' href='#n4694'>4694</a>
<a id='n4695' href='#n4695'>4695</a>
<a id='n4696' href='#n4696'>4696</a>
<a id='n4697' href='#n4697'>4697</a>
<a id='n4698' href='#n4698'>4698</a>
<a id='n4699' href='#n4699'>4699</a>
<a id='n4700' href='#n4700'>4700</a>
<a id='n4701' href='#n4701'>4701</a>
<a id='n4702' href='#n4702'>4702</a>
<a id='n4703' href='#n4703'>4703</a>
<a id='n4704' href='#n4704'>4704</a>
<a id='n4705' href='#n4705'>4705</a>
<a id='n4706' href='#n4706'>4706</a>
<a id='n4707' href='#n4707'>4707</a>
<a id='n4708' href='#n4708'>4708</a>
<a id='n4709' href='#n4709'>4709</a>
<a id='n4710' href='#n4710'>4710</a>
<a id='n4711' href='#n4711'>4711</a>
<a id='n4712' href='#n4712'>4712</a>
<a id='n4713' href='#n4713'>4713</a>
<a id='n4714' href='#n4714'>4714</a>
<a id='n4715' href='#n4715'>4715</a>
<a id='n4716' href='#n4716'>4716</a>
<a id='n4717' href='#n4717'>4717</a>
<a id='n4718' href='#n4718'>4718</a>
<a id='n4719' href='#n4719'>4719</a>
<a id='n4720' href='#n4720'>4720</a>
<a id='n4721' href='#n4721'>4721</a>
<a id='n4722' href='#n4722'>4722</a>
<a id='n4723' href='#n4723'>4723</a>
<a id='n4724' href='#n4724'>4724</a>
<a id='n4725' href='#n4725'>4725</a>
<a id='n4726' href='#n4726'>4726</a>
<a id='n4727' href='#n4727'>4727</a>
<a id='n4728' href='#n4728'>4728</a>
<a id='n4729' href='#n4729'>4729</a>
<a id='n4730' href='#n4730'>4730</a>
<a id='n4731' href='#n4731'>4731</a>
<a id='n4732' href='#n4732'>4732</a>
<a id='n4733' href='#n4733'>4733</a>
<a id='n4734' href='#n4734'>4734</a>
<a id='n4735' href='#n4735'>4735</a>
<a id='n4736' href='#n4736'>4736</a>
<a id='n4737' href='#n4737'>4737</a>
<a id='n4738' href='#n4738'>4738</a>
<a id='n4739' href='#n4739'>4739</a>
<a id='n4740' href='#n4740'>4740</a>
<a id='n4741' href='#n4741'>4741</a>
<a id='n4742' href='#n4742'>4742</a>
<a id='n4743' href='#n4743'>4743</a>
<a id='n4744' href='#n4744'>4744</a>
<a id='n4745' href='#n4745'>4745</a>
<a id='n4746' href='#n4746'>4746</a>
<a id='n4747' href='#n4747'>4747</a>
<a id='n4748' href='#n4748'>4748</a>
<a id='n4749' href='#n4749'>4749</a>
<a id='n4750' href='#n4750'>4750</a>
<a id='n4751' href='#n4751'>4751</a>
<a id='n4752' href='#n4752'>4752</a>
<a id='n4753' href='#n4753'>4753</a>
<a id='n4754' href='#n4754'>4754</a>
<a id='n4755' href='#n4755'>4755</a>
<a id='n4756' href='#n4756'>4756</a>
<a id='n4757' href='#n4757'>4757</a>
<a id='n4758' href='#n4758'>4758</a>
<a id='n4759' href='#n4759'>4759</a>
<a id='n4760' href='#n4760'>4760</a>
<a id='n4761' href='#n4761'>4761</a>
<a id='n4762' href='#n4762'>4762</a>
<a id='n4763' href='#n4763'>4763</a>
<a id='n4764' href='#n4764'>4764</a>
<a id='n4765' href='#n4765'>4765</a>
<a id='n4766' href='#n4766'>4766</a>
<a id='n4767' href='#n4767'>4767</a>
<a id='n4768' href='#n4768'>4768</a>
<a id='n4769' href='#n4769'>4769</a>
<a id='n4770' href='#n4770'>4770</a>
<a id='n4771' href='#n4771'>4771</a>
<a id='n4772' href='#n4772'>4772</a>
<a id='n4773' href='#n4773'>4773</a>
<a id='n4774' href='#n4774'>4774</a>
<a id='n4775' href='#n4775'>4775</a>
<a id='n4776' href='#n4776'>4776</a>
<a id='n4777' href='#n4777'>4777</a>
<a id='n4778' href='#n4778'>4778</a>
<a id='n4779' href='#n4779'>4779</a>
<a id='n4780' href='#n4780'>4780</a>
<a id='n4781' href='#n4781'>4781</a>
<a id='n4782' href='#n4782'>4782</a>
<a id='n4783' href='#n4783'>4783</a>
<a id='n4784' href='#n4784'>4784</a>
<a id='n4785' href='#n4785'>4785</a>
<a id='n4786' href='#n4786'>4786</a>
<a id='n4787' href='#n4787'>4787</a>
<a id='n4788' href='#n4788'>4788</a>
<a id='n4789' href='#n4789'>4789</a>
<a id='n4790' href='#n4790'>4790</a>
<a id='n4791' href='#n4791'>4791</a>
<a id='n4792' href='#n4792'>4792</a>
<a id='n4793' href='#n4793'>4793</a>
<a id='n4794' href='#n4794'>4794</a>
<a id='n4795' href='#n4795'>4795</a>
<a id='n4796' href='#n4796'>4796</a>
<a id='n4797' href='#n4797'>4797</a>
<a id='n4798' href='#n4798'>4798</a>
<a id='n4799' href='#n4799'>4799</a>
<a id='n4800' href='#n4800'>4800</a>
<a id='n4801' href='#n4801'>4801</a>
<a id='n4802' href='#n4802'>4802</a>
<a id='n4803' href='#n4803'>4803</a>
<a id='n4804' href='#n4804'>4804</a>
<a id='n4805' href='#n4805'>4805</a>
<a id='n4806' href='#n4806'>4806</a>
<a id='n4807' href='#n4807'>4807</a>
<a id='n4808' href='#n4808'>4808</a>
<a id='n4809' href='#n4809'>4809</a>
<a id='n4810' href='#n4810'>4810</a>
<a id='n4811' href='#n4811'>4811</a>
<a id='n4812' href='#n4812'>4812</a>
<a id='n4813' href='#n4813'>4813</a>
<a id='n4814' href='#n4814'>4814</a>
<a id='n4815' href='#n4815'>4815</a>
<a id='n4816' href='#n4816'>4816</a>
<a id='n4817' href='#n4817'>4817</a>
<a id='n4818' href='#n4818'>4818</a>
<a id='n4819' href='#n4819'>4819</a>
<a id='n4820' href='#n4820'>4820</a>
<a id='n4821' href='#n4821'>4821</a>
<a id='n4822' href='#n4822'>4822</a>
<a id='n4823' href='#n4823'>4823</a>
<a id='n4824' href='#n4824'>4824</a>
<a id='n4825' href='#n4825'>4825</a>
<a id='n4826' href='#n4826'>4826</a>
<a id='n4827' href='#n4827'>4827</a>
<a id='n4828' href='#n4828'>4828</a>
<a id='n4829' href='#n4829'>4829</a>
<a id='n4830' href='#n4830'>4830</a>
<a id='n4831' href='#n4831'>4831</a>
<a id='n4832' href='#n4832'>4832</a>
<a id='n4833' href='#n4833'>4833</a>
<a id='n4834' href='#n4834'>4834</a>
<a id='n4835' href='#n4835'>4835</a>
<a id='n4836' href='#n4836'>4836</a>
<a id='n4837' href='#n4837'>4837</a>
<a id='n4838' href='#n4838'>4838</a>
<a id='n4839' href='#n4839'>4839</a>
<a id='n4840' href='#n4840'>4840</a>
<a id='n4841' href='#n4841'>4841</a>
<a id='n4842' href='#n4842'>4842</a>
<a id='n4843' href='#n4843'>4843</a>
<a id='n4844' href='#n4844'>4844</a>
<a id='n4845' href='#n4845'>4845</a>
<a id='n4846' href='#n4846'>4846</a>
<a id='n4847' href='#n4847'>4847</a>
<a id='n4848' href='#n4848'>4848</a>
<a id='n4849' href='#n4849'>4849</a>
<a id='n4850' href='#n4850'>4850</a>
<a id='n4851' href='#n4851'>4851</a>
<a id='n4852' href='#n4852'>4852</a>
<a id='n4853' href='#n4853'>4853</a>
<a id='n4854' href='#n4854'>4854</a>
<a id='n4855' href='#n4855'>4855</a>
<a id='n4856' href='#n4856'>4856</a>
<a id='n4857' href='#n4857'>4857</a>
<a id='n4858' href='#n4858'>4858</a>
<a id='n4859' href='#n4859'>4859</a>
<a id='n4860' href='#n4860'>4860</a>
<a id='n4861' href='#n4861'>4861</a>
<a id='n4862' href='#n4862'>4862</a>
<a id='n4863' href='#n4863'>4863</a>
<a id='n4864' href='#n4864'>4864</a>
<a id='n4865' href='#n4865'>4865</a>
<a id='n4866' href='#n4866'>4866</a>
<a id='n4867' href='#n4867'>4867</a>
<a id='n4868' href='#n4868'>4868</a>
<a id='n4869' href='#n4869'>4869</a>
<a id='n4870' href='#n4870'>4870</a>
<a id='n4871' href='#n4871'>4871</a>
<a id='n4872' href='#n4872'>4872</a>
<a id='n4873' href='#n4873'>4873</a>
<a id='n4874' href='#n4874'>4874</a>
<a id='n4875' href='#n4875'>4875</a>
<a id='n4876' href='#n4876'>4876</a>
<a id='n4877' href='#n4877'>4877</a>
<a id='n4878' href='#n4878'>4878</a>
<a id='n4879' href='#n4879'>4879</a>
<a id='n4880' href='#n4880'>4880</a>
<a id='n4881' href='#n4881'>4881</a>
<a id='n4882' href='#n4882'>4882</a>
<a id='n4883' href='#n4883'>4883</a>
<a id='n4884' href='#n4884'>4884</a>
<a id='n4885' href='#n4885'>4885</a>
<a id='n4886' href='#n4886'>4886</a>
<a id='n4887' href='#n4887'>4887</a>
<a id='n4888' href='#n4888'>4888</a>
<a id='n4889' href='#n4889'>4889</a>
<a id='n4890' href='#n4890'>4890</a>
<a id='n4891' href='#n4891'>4891</a>
<a id='n4892' href='#n4892'>4892</a>
<a id='n4893' href='#n4893'>4893</a>
<a id='n4894' href='#n4894'>4894</a>
<a id='n4895' href='#n4895'>4895</a>
<a id='n4896' href='#n4896'>4896</a>
<a id='n4897' href='#n4897'>4897</a>
<a id='n4898' href='#n4898'>4898</a>
<a id='n4899' href='#n4899'>4899</a>
<a id='n4900' href='#n4900'>4900</a>
<a id='n4901' href='#n4901'>4901</a>
<a id='n4902' href='#n4902'>4902</a>
<a id='n4903' href='#n4903'>4903</a>
<a id='n4904' href='#n4904'>4904</a>
<a id='n4905' href='#n4905'>4905</a>
<a id='n4906' href='#n4906'>4906</a>
<a id='n4907' href='#n4907'>4907</a>
<a id='n4908' href='#n4908'>4908</a>
<a id='n4909' href='#n4909'>4909</a>
<a id='n4910' href='#n4910'>4910</a>
<a id='n4911' href='#n4911'>4911</a>
<a id='n4912' href='#n4912'>4912</a>
<a id='n4913' href='#n4913'>4913</a>
<a id='n4914' href='#n4914'>4914</a>
<a id='n4915' href='#n4915'>4915</a>
<a id='n4916' href='#n4916'>4916</a>
<a id='n4917' href='#n4917'>4917</a>
<a id='n4918' href='#n4918'>4918</a>
<a id='n4919' href='#n4919'>4919</a>
<a id='n4920' href='#n4920'>4920</a>
<a id='n4921' href='#n4921'>4921</a>
<a id='n4922' href='#n4922'>4922</a>
<a id='n4923' href='#n4923'>4923</a>
<a id='n4924' href='#n4924'>4924</a>
<a id='n4925' href='#n4925'>4925</a>
<a id='n4926' href='#n4926'>4926</a>
<a id='n4927' href='#n4927'>4927</a>
<a id='n4928' href='#n4928'>4928</a>
<a id='n4929' href='#n4929'>4929</a>
<a id='n4930' href='#n4930'>4930</a>
<a id='n4931' href='#n4931'>4931</a>
<a id='n4932' href='#n4932'>4932</a>
<a id='n4933' href='#n4933'>4933</a>
<a id='n4934' href='#n4934'>4934</a>
<a id='n4935' href='#n4935'>4935</a>
<a id='n4936' href='#n4936'>4936</a>
<a id='n4937' href='#n4937'>4937</a>
<a id='n4938' href='#n4938'>4938</a>
<a id='n4939' href='#n4939'>4939</a>
<a id='n4940' href='#n4940'>4940</a>
<a id='n4941' href='#n4941'>4941</a>
<a id='n4942' href='#n4942'>4942</a>
<a id='n4943' href='#n4943'>4943</a>
<a id='n4944' href='#n4944'>4944</a>
<a id='n4945' href='#n4945'>4945</a>
<a id='n4946' href='#n4946'>4946</a>
<a id='n4947' href='#n4947'>4947</a>
<a id='n4948' href='#n4948'>4948</a>
<a id='n4949' href='#n4949'>4949</a>
<a id='n4950' href='#n4950'>4950</a>
<a id='n4951' href='#n4951'>4951</a>
<a id='n4952' href='#n4952'>4952</a>
<a id='n4953' href='#n4953'>4953</a>
<a id='n4954' href='#n4954'>4954</a>
<a id='n4955' href='#n4955'>4955</a>
<a id='n4956' href='#n4956'>4956</a>
<a id='n4957' href='#n4957'>4957</a>
<a id='n4958' href='#n4958'>4958</a>
<a id='n4959' href='#n4959'>4959</a>
<a id='n4960' href='#n4960'>4960</a>
<a id='n4961' href='#n4961'>4961</a>
<a id='n4962' href='#n4962'>4962</a>
<a id='n4963' href='#n4963'>4963</a>
<a id='n4964' href='#n4964'>4964</a>
<a id='n4965' href='#n4965'>4965</a>
<a id='n4966' href='#n4966'>4966</a>
<a id='n4967' href='#n4967'>4967</a>
<a id='n4968' href='#n4968'>4968</a>
<a id='n4969' href='#n4969'>4969</a>
<a id='n4970' href='#n4970'>4970</a>
<a id='n4971' href='#n4971'>4971</a>
<a id='n4972' href='#n4972'>4972</a>
<a id='n4973' href='#n4973'>4973</a>
<a id='n4974' href='#n4974'>4974</a>
<a id='n4975' href='#n4975'>4975</a>
<a id='n4976' href='#n4976'>4976</a>
<a id='n4977' href='#n4977'>4977</a>
<a id='n4978' href='#n4978'>4978</a>
<a id='n4979' href='#n4979'>4979</a>
<a id='n4980' href='#n4980'>4980</a>
<a id='n4981' href='#n4981'>4981</a>
<a id='n4982' href='#n4982'>4982</a>
<a id='n4983' href='#n4983'>4983</a>
<a id='n4984' href='#n4984'>4984</a>
<a id='n4985' href='#n4985'>4985</a>
<a id='n4986' href='#n4986'>4986</a>
<a id='n4987' href='#n4987'>4987</a>
<a id='n4988' href='#n4988'>4988</a>
<a id='n4989' href='#n4989'>4989</a>
<a id='n4990' href='#n4990'>4990</a>
<a id='n4991' href='#n4991'>4991</a>
<a id='n4992' href='#n4992'>4992</a>
<a id='n4993' href='#n4993'>4993</a>
<a id='n4994' href='#n4994'>4994</a>
<a id='n4995' href='#n4995'>4995</a>
<a id='n4996' href='#n4996'>4996</a>
<a id='n4997' href='#n4997'>4997</a>
<a id='n4998' href='#n4998'>4998</a>
<a id='n4999' href='#n4999'>4999</a>
<a id='n5000' href='#n5000'>5000</a>
<a id='n5001' href='#n5001'>5001</a>
<a id='n5002' href='#n5002'>5002</a>
<a id='n5003' href='#n5003'>5003</a>
<a id='n5004' href='#n5004'>5004</a>
<a id='n5005' href='#n5005'>5005</a>
<a id='n5006' href='#n5006'>5006</a>
<a id='n5007' href='#n5007'>5007</a>
<a id='n5008' href='#n5008'>5008</a>
<a id='n5009' href='#n5009'>5009</a>
<a id='n5010' href='#n5010'>5010</a>
<a id='n5011' href='#n5011'>5011</a>
<a id='n5012' href='#n5012'>5012</a>
<a id='n5013' href='#n5013'>5013</a>
<a id='n5014' href='#n5014'>5014</a>
<a id='n5015' href='#n5015'>5015</a>
<a id='n5016' href='#n5016'>5016</a>
<a id='n5017' href='#n5017'>5017</a>
<a id='n5018' href='#n5018'>5018</a>
<a id='n5019' href='#n5019'>5019</a>
<a id='n5020' href='#n5020'>5020</a>
<a id='n5021' href='#n5021'>5021</a>
<a id='n5022' href='#n5022'>5022</a>
<a id='n5023' href='#n5023'>5023</a>
<a id='n5024' href='#n5024'>5024</a>
<a id='n5025' href='#n5025'>5025</a>
<a id='n5026' href='#n5026'>5026</a>
<a id='n5027' href='#n5027'>5027</a>
<a id='n5028' href='#n5028'>5028</a>
<a id='n5029' href='#n5029'>5029</a>
<a id='n5030' href='#n5030'>5030</a>
<a id='n5031' href='#n5031'>5031</a>
<a id='n5032' href='#n5032'>5032</a>
<a id='n5033' href='#n5033'>5033</a>
<a id='n5034' href='#n5034'>5034</a>
<a id='n5035' href='#n5035'>5035</a>
<a id='n5036' href='#n5036'>5036</a>
<a id='n5037' href='#n5037'>5037</a>
<a id='n5038' href='#n5038'>5038</a>
<a id='n5039' href='#n5039'>5039</a>
<a id='n5040' href='#n5040'>5040</a>
<a id='n5041' href='#n5041'>5041</a>
<a id='n5042' href='#n5042'>5042</a>
<a id='n5043' href='#n5043'>5043</a>
<a id='n5044' href='#n5044'>5044</a>
<a id='n5045' href='#n5045'>5045</a>
<a id='n5046' href='#n5046'>5046</a>
<a id='n5047' href='#n5047'>5047</a>
<a id='n5048' href='#n5048'>5048</a>
<a id='n5049' href='#n5049'>5049</a>
<a id='n5050' href='#n5050'>5050</a>
<a id='n5051' href='#n5051'>5051</a>
<a id='n5052' href='#n5052'>5052</a>
<a id='n5053' href='#n5053'>5053</a>
<a id='n5054' href='#n5054'>5054</a>
<a id='n5055' href='#n5055'>5055</a>
<a id='n5056' href='#n5056'>5056</a>
<a id='n5057' href='#n5057'>5057</a>
<a id='n5058' href='#n5058'>5058</a>
<a id='n5059' href='#n5059'>5059</a>
<a id='n5060' href='#n5060'>5060</a>
<a id='n5061' href='#n5061'>5061</a>
<a id='n5062' href='#n5062'>5062</a>
<a id='n5063' href='#n5063'>5063</a>
<a id='n5064' href='#n5064'>5064</a>
<a id='n5065' href='#n5065'>5065</a>
<a id='n5066' href='#n5066'>5066</a>
<a id='n5067' href='#n5067'>5067</a>
<a id='n5068' href='#n5068'>5068</a>
<a id='n5069' href='#n5069'>5069</a>
<a id='n5070' href='#n5070'>5070</a>
<a id='n5071' href='#n5071'>5071</a>
<a id='n5072' href='#n5072'>5072</a>
<a id='n5073' href='#n5073'>5073</a>
<a id='n5074' href='#n5074'>5074</a>
<a id='n5075' href='#n5075'>5075</a>
<a id='n5076' href='#n5076'>5076</a>
<a id='n5077' href='#n5077'>5077</a>
<a id='n5078' href='#n5078'>5078</a>
<a id='n5079' href='#n5079'>5079</a>
<a id='n5080' href='#n5080'>5080</a>
<a id='n5081' href='#n5081'>5081</a>
<a id='n5082' href='#n5082'>5082</a>
<a id='n5083' href='#n5083'>5083</a>
<a id='n5084' href='#n5084'>5084</a>
<a id='n5085' href='#n5085'>5085</a>
<a id='n5086' href='#n5086'>5086</a>
<a id='n5087' href='#n5087'>5087</a>
<a id='n5088' href='#n5088'>5088</a>
<a id='n5089' href='#n5089'>5089</a>
<a id='n5090' href='#n5090'>5090</a>
<a id='n5091' href='#n5091'>5091</a>
<a id='n5092' href='#n5092'>5092</a>
<a id='n5093' href='#n5093'>5093</a>
<a id='n5094' href='#n5094'>5094</a>
<a id='n5095' href='#n5095'>5095</a>
<a id='n5096' href='#n5096'>5096</a>
<a id='n5097' href='#n5097'>5097</a>
<a id='n5098' href='#n5098'>5098</a>
<a id='n5099' href='#n5099'>5099</a>
<a id='n5100' href='#n5100'>5100</a>
<a id='n5101' href='#n5101'>5101</a>
<a id='n5102' href='#n5102'>5102</a>
<a id='n5103' href='#n5103'>5103</a>
<a id='n5104' href='#n5104'>5104</a>
<a id='n5105' href='#n5105'>5105</a>
<a id='n5106' href='#n5106'>5106</a>
<a id='n5107' href='#n5107'>5107</a>
<a id='n5108' href='#n5108'>5108</a>
<a id='n5109' href='#n5109'>5109</a>
<a id='n5110' href='#n5110'>5110</a>
<a id='n5111' href='#n5111'>5111</a>
<a id='n5112' href='#n5112'>5112</a>
<a id='n5113' href='#n5113'>5113</a>
<a id='n5114' href='#n5114'>5114</a>
<a id='n5115' href='#n5115'>5115</a>
<a id='n5116' href='#n5116'>5116</a>
<a id='n5117' href='#n5117'>5117</a>
<a id='n5118' href='#n5118'>5118</a>
<a id='n5119' href='#n5119'>5119</a>
<a id='n5120' href='#n5120'>5120</a>
<a id='n5121' href='#n5121'>5121</a>
<a id='n5122' href='#n5122'>5122</a>
<a id='n5123' href='#n5123'>5123</a>
<a id='n5124' href='#n5124'>5124</a>
<a id='n5125' href='#n5125'>5125</a>
<a id='n5126' href='#n5126'>5126</a>
<a id='n5127' href='#n5127'>5127</a>
<a id='n5128' href='#n5128'>5128</a>
<a id='n5129' href='#n5129'>5129</a>
<a id='n5130' href='#n5130'>5130</a>
<a id='n5131' href='#n5131'>5131</a>
<a id='n5132' href='#n5132'>5132</a>
<a id='n5133' href='#n5133'>5133</a>
<a id='n5134' href='#n5134'>5134</a>
<a id='n5135' href='#n5135'>5135</a>
<a id='n5136' href='#n5136'>5136</a>
<a id='n5137' href='#n5137'>5137</a>
<a id='n5138' href='#n5138'>5138</a>
<a id='n5139' href='#n5139'>5139</a>
<a id='n5140' href='#n5140'>5140</a>
<a id='n5141' href='#n5141'>5141</a>
<a id='n5142' href='#n5142'>5142</a>
<a id='n5143' href='#n5143'>5143</a>
<a id='n5144' href='#n5144'>5144</a>
<a id='n5145' href='#n5145'>5145</a>
<a id='n5146' href='#n5146'>5146</a>
<a id='n5147' href='#n5147'>5147</a>
<a id='n5148' href='#n5148'>5148</a>
<a id='n5149' href='#n5149'>5149</a>
<a id='n5150' href='#n5150'>5150</a>
<a id='n5151' href='#n5151'>5151</a>
<a id='n5152' href='#n5152'>5152</a>
<a id='n5153' href='#n5153'>5153</a>
<a id='n5154' href='#n5154'>5154</a>
<a id='n5155' href='#n5155'>5155</a>
<a id='n5156' href='#n5156'>5156</a>
<a id='n5157' href='#n5157'>5157</a>
<a id='n5158' href='#n5158'>5158</a>
<a id='n5159' href='#n5159'>5159</a>
<a id='n5160' href='#n5160'>5160</a>
<a id='n5161' href='#n5161'>5161</a>
<a id='n5162' href='#n5162'>5162</a>
<a id='n5163' href='#n5163'>5163</a>
<a id='n5164' href='#n5164'>5164</a>
<a id='n5165' href='#n5165'>5165</a>
<a id='n5166' href='#n5166'>5166</a>
<a id='n5167' href='#n5167'>5167</a>
<a id='n5168' href='#n5168'>5168</a>
<a id='n5169' href='#n5169'>5169</a>
<a id='n5170' href='#n5170'>5170</a>
<a id='n5171' href='#n5171'>5171</a>
<a id='n5172' href='#n5172'>5172</a>
<a id='n5173' href='#n5173'>5173</a>
<a id='n5174' href='#n5174'>5174</a>
<a id='n5175' href='#n5175'>5175</a>
<a id='n5176' href='#n5176'>5176</a>
<a id='n5177' href='#n5177'>5177</a>
<a id='n5178' href='#n5178'>5178</a>
<a id='n5179' href='#n5179'>5179</a>
<a id='n5180' href='#n5180'>5180</a>
<a id='n5181' href='#n5181'>5181</a>
<a id='n5182' href='#n5182'>5182</a>
<a id='n5183' href='#n5183'>5183</a>
<a id='n5184' href='#n5184'>5184</a>
<a id='n5185' href='#n5185'>5185</a>
<a id='n5186' href='#n5186'>5186</a>
<a id='n5187' href='#n5187'>5187</a>
<a id='n5188' href='#n5188'>5188</a>
<a id='n5189' href='#n5189'>5189</a>
<a id='n5190' href='#n5190'>5190</a>
<a id='n5191' href='#n5191'>5191</a>
<a id='n5192' href='#n5192'>5192</a>
<a id='n5193' href='#n5193'>5193</a>
<a id='n5194' href='#n5194'>5194</a>
<a id='n5195' href='#n5195'>5195</a>
<a id='n5196' href='#n5196'>5196</a>
<a id='n5197' href='#n5197'>5197</a>
<a id='n5198' href='#n5198'>5198</a>
<a id='n5199' href='#n5199'>5199</a>
<a id='n5200' href='#n5200'>5200</a>
<a id='n5201' href='#n5201'>5201</a>
<a id='n5202' href='#n5202'>5202</a>
<a id='n5203' href='#n5203'>5203</a>
<a id='n5204' href='#n5204'>5204</a>
<a id='n5205' href='#n5205'>5205</a>
<a id='n5206' href='#n5206'>5206</a>
<a id='n5207' href='#n5207'>5207</a>
<a id='n5208' href='#n5208'>5208</a>
<a id='n5209' href='#n5209'>5209</a>
<a id='n5210' href='#n5210'>5210</a>
<a id='n5211' href='#n5211'>5211</a>
<a id='n5212' href='#n5212'>5212</a>
<a id='n5213' href='#n5213'>5213</a>
<a id='n5214' href='#n5214'>5214</a>
<a id='n5215' href='#n5215'>5215</a>
<a id='n5216' href='#n5216'>5216</a>
<a id='n5217' href='#n5217'>5217</a>
<a id='n5218' href='#n5218'>5218</a>
<a id='n5219' href='#n5219'>5219</a>
<a id='n5220' href='#n5220'>5220</a>
<a id='n5221' href='#n5221'>5221</a>
<a id='n5222' href='#n5222'>5222</a>
<a id='n5223' href='#n5223'>5223</a>
<a id='n5224' href='#n5224'>5224</a>
<a id='n5225' href='#n5225'>5225</a>
<a id='n5226' href='#n5226'>5226</a>
<a id='n5227' href='#n5227'>5227</a>
<a id='n5228' href='#n5228'>5228</a>
<a id='n5229' href='#n5229'>5229</a>
<a id='n5230' href='#n5230'>5230</a>
<a id='n5231' href='#n5231'>5231</a>
<a id='n5232' href='#n5232'>5232</a>
<a id='n5233' href='#n5233'>5233</a>
<a id='n5234' href='#n5234'>5234</a>
<a id='n5235' href='#n5235'>5235</a>
<a id='n5236' href='#n5236'>5236</a>
<a id='n5237' href='#n5237'>5237</a>
<a id='n5238' href='#n5238'>5238</a>
<a id='n5239' href='#n5239'>5239</a>
<a id='n5240' href='#n5240'>5240</a>
<a id='n5241' href='#n5241'>5241</a>
<a id='n5242' href='#n5242'>5242</a>
<a id='n5243' href='#n5243'>5243</a>
<a id='n5244' href='#n5244'>5244</a>
<a id='n5245' href='#n5245'>5245</a>
<a id='n5246' href='#n5246'>5246</a>
<a id='n5247' href='#n5247'>5247</a>
<a id='n5248' href='#n5248'>5248</a>
<a id='n5249' href='#n5249'>5249</a>
<a id='n5250' href='#n5250'>5250</a>
<a id='n5251' href='#n5251'>5251</a>
<a id='n5252' href='#n5252'>5252</a>
<a id='n5253' href='#n5253'>5253</a>
<a id='n5254' href='#n5254'>5254</a>
<a id='n5255' href='#n5255'>5255</a>
<a id='n5256' href='#n5256'>5256</a>
<a id='n5257' href='#n5257'>5257</a>
<a id='n5258' href='#n5258'>5258</a>
<a id='n5259' href='#n5259'>5259</a>
<a id='n5260' href='#n5260'>5260</a>
<a id='n5261' href='#n5261'>5261</a>
<a id='n5262' href='#n5262'>5262</a>
<a id='n5263' href='#n5263'>5263</a>
<a id='n5264' href='#n5264'>5264</a>
<a id='n5265' href='#n5265'>5265</a>
<a id='n5266' href='#n5266'>5266</a>
<a id='n5267' href='#n5267'>5267</a>
<a id='n5268' href='#n5268'>5268</a>
<a id='n5269' href='#n5269'>5269</a>
<a id='n5270' href='#n5270'>5270</a>
<a id='n5271' href='#n5271'>5271</a>
<a id='n5272' href='#n5272'>5272</a>
<a id='n5273' href='#n5273'>5273</a>
<a id='n5274' href='#n5274'>5274</a>
<a id='n5275' href='#n5275'>5275</a>
<a id='n5276' href='#n5276'>5276</a>
<a id='n5277' href='#n5277'>5277</a>
<a id='n5278' href='#n5278'>5278</a>
<a id='n5279' href='#n5279'>5279</a>
<a id='n5280' href='#n5280'>5280</a>
<a id='n5281' href='#n5281'>5281</a>
<a id='n5282' href='#n5282'>5282</a>
<a id='n5283' href='#n5283'>5283</a>
<a id='n5284' href='#n5284'>5284</a>
<a id='n5285' href='#n5285'>5285</a>
<a id='n5286' href='#n5286'>5286</a>
<a id='n5287' href='#n5287'>5287</a>
<a id='n5288' href='#n5288'>5288</a>
<a id='n5289' href='#n5289'>5289</a>
<a id='n5290' href='#n5290'>5290</a>
<a id='n5291' href='#n5291'>5291</a>
<a id='n5292' href='#n5292'>5292</a>
<a id='n5293' href='#n5293'>5293</a>
<a id='n5294' href='#n5294'>5294</a>
<a id='n5295' href='#n5295'>5295</a>
<a id='n5296' href='#n5296'>5296</a>
<a id='n5297' href='#n5297'>5297</a>
<a id='n5298' href='#n5298'>5298</a>
<a id='n5299' href='#n5299'>5299</a>
<a id='n5300' href='#n5300'>5300</a>
<a id='n5301' href='#n5301'>5301</a>
<a id='n5302' href='#n5302'>5302</a>
<a id='n5303' href='#n5303'>5303</a>
<a id='n5304' href='#n5304'>5304</a>
<a id='n5305' href='#n5305'>5305</a>
<a id='n5306' href='#n5306'>5306</a>
<a id='n5307' href='#n5307'>5307</a>
<a id='n5308' href='#n5308'>5308</a>
<a id='n5309' href='#n5309'>5309</a>
<a id='n5310' href='#n5310'>5310</a>
<a id='n5311' href='#n5311'>5311</a>
<a id='n5312' href='#n5312'>5312</a>
<a id='n5313' href='#n5313'>5313</a>
<a id='n5314' href='#n5314'>5314</a>
<a id='n5315' href='#n5315'>5315</a>
<a id='n5316' href='#n5316'>5316</a>
<a id='n5317' href='#n5317'>5317</a>
<a id='n5318' href='#n5318'>5318</a>
<a id='n5319' href='#n5319'>5319</a>
<a id='n5320' href='#n5320'>5320</a>
<a id='n5321' href='#n5321'>5321</a>
<a id='n5322' href='#n5322'>5322</a>
<a id='n5323' href='#n5323'>5323</a>
<a id='n5324' href='#n5324'>5324</a>
<a id='n5325' href='#n5325'>5325</a>
<a id='n5326' href='#n5326'>5326</a>
<a id='n5327' href='#n5327'>5327</a>
<a id='n5328' href='#n5328'>5328</a>
<a id='n5329' href='#n5329'>5329</a>
<a id='n5330' href='#n5330'>5330</a>
<a id='n5331' href='#n5331'>5331</a>
<a id='n5332' href='#n5332'>5332</a>
<a id='n5333' href='#n5333'>5333</a>
<a id='n5334' href='#n5334'>5334</a>
<a id='n5335' href='#n5335'>5335</a>
<a id='n5336' href='#n5336'>5336</a>
<a id='n5337' href='#n5337'>5337</a>
<a id='n5338' href='#n5338'>5338</a>
<a id='n5339' href='#n5339'>5339</a>
<a id='n5340' href='#n5340'>5340</a>
<a id='n5341' href='#n5341'>5341</a>
<a id='n5342' href='#n5342'>5342</a>
<a id='n5343' href='#n5343'>5343</a>
<a id='n5344' href='#n5344'>5344</a>
<a id='n5345' href='#n5345'>5345</a>
<a id='n5346' href='#n5346'>5346</a>
<a id='n5347' href='#n5347'>5347</a>
<a id='n5348' href='#n5348'>5348</a>
<a id='n5349' href='#n5349'>5349</a>
<a id='n5350' href='#n5350'>5350</a>
<a id='n5351' href='#n5351'>5351</a>
<a id='n5352' href='#n5352'>5352</a>
<a id='n5353' href='#n5353'>5353</a>
<a id='n5354' href='#n5354'>5354</a>
<a id='n5355' href='#n5355'>5355</a>
<a id='n5356' href='#n5356'>5356</a>
<a id='n5357' href='#n5357'>5357</a>
<a id='n5358' href='#n5358'>5358</a>
<a id='n5359' href='#n5359'>5359</a>
<a id='n5360' href='#n5360'>5360</a>
<a id='n5361' href='#n5361'>5361</a>
<a id='n5362' href='#n5362'>5362</a>
<a id='n5363' href='#n5363'>5363</a>
<a id='n5364' href='#n5364'>5364</a>
<a id='n5365' href='#n5365'>5365</a>
<a id='n5366' href='#n5366'>5366</a>
<a id='n5367' href='#n5367'>5367</a>
<a id='n5368' href='#n5368'>5368</a>
<a id='n5369' href='#n5369'>5369</a>
<a id='n5370' href='#n5370'>5370</a>
<a id='n5371' href='#n5371'>5371</a>
<a id='n5372' href='#n5372'>5372</a>
<a id='n5373' href='#n5373'>5373</a>
<a id='n5374' href='#n5374'>5374</a>
<a id='n5375' href='#n5375'>5375</a>
<a id='n5376' href='#n5376'>5376</a>
<a id='n5377' href='#n5377'>5377</a>
<a id='n5378' href='#n5378'>5378</a>
<a id='n5379' href='#n5379'>5379</a>
<a id='n5380' href='#n5380'>5380</a>
<a id='n5381' href='#n5381'>5381</a>
<a id='n5382' href='#n5382'>5382</a>
<a id='n5383' href='#n5383'>5383</a>
<a id='n5384' href='#n5384'>5384</a>
<a id='n5385' href='#n5385'>5385</a>
<a id='n5386' href='#n5386'>5386</a>
<a id='n5387' href='#n5387'>5387</a>
<a id='n5388' href='#n5388'>5388</a>
<a id='n5389' href='#n5389'>5389</a>
<a id='n5390' href='#n5390'>5390</a>
<a id='n5391' href='#n5391'>5391</a>
<a id='n5392' href='#n5392'>5392</a>
<a id='n5393' href='#n5393'>5393</a>
<a id='n5394' href='#n5394'>5394</a>
<a id='n5395' href='#n5395'>5395</a>
<a id='n5396' href='#n5396'>5396</a>
<a id='n5397' href='#n5397'>5397</a>
<a id='n5398' href='#n5398'>5398</a>
<a id='n5399' href='#n5399'>5399</a>
<a id='n5400' href='#n5400'>5400</a>
<a id='n5401' href='#n5401'>5401</a>
<a id='n5402' href='#n5402'>5402</a>
<a id='n5403' href='#n5403'>5403</a>
<a id='n5404' href='#n5404'>5404</a>
<a id='n5405' href='#n5405'>5405</a>
<a id='n5406' href='#n5406'>5406</a>
<a id='n5407' href='#n5407'>5407</a>
<a id='n5408' href='#n5408'>5408</a>
<a id='n5409' href='#n5409'>5409</a>
<a id='n5410' href='#n5410'>5410</a>
<a id='n5411' href='#n5411'>5411</a>
<a id='n5412' href='#n5412'>5412</a>
<a id='n5413' href='#n5413'>5413</a>
<a id='n5414' href='#n5414'>5414</a>
<a id='n5415' href='#n5415'>5415</a>
<a id='n5416' href='#n5416'>5416</a>
<a id='n5417' href='#n5417'>5417</a>
<a id='n5418' href='#n5418'>5418</a>
<a id='n5419' href='#n5419'>5419</a>
<a id='n5420' href='#n5420'>5420</a>
<a id='n5421' href='#n5421'>5421</a>
<a id='n5422' href='#n5422'>5422</a>
<a id='n5423' href='#n5423'>5423</a>
<a id='n5424' href='#n5424'>5424</a>
<a id='n5425' href='#n5425'>5425</a>
<a id='n5426' href='#n5426'>5426</a>
<a id='n5427' href='#n5427'>5427</a>
<a id='n5428' href='#n5428'>5428</a>
<a id='n5429' href='#n5429'>5429</a>
<a id='n5430' href='#n5430'>5430</a>
<a id='n5431' href='#n5431'>5431</a>
<a id='n5432' href='#n5432'>5432</a>
<a id='n5433' href='#n5433'>5433</a>
<a id='n5434' href='#n5434'>5434</a>
<a id='n5435' href='#n5435'>5435</a>
<a id='n5436' href='#n5436'>5436</a>
<a id='n5437' href='#n5437'>5437</a>
<a id='n5438' href='#n5438'>5438</a>
<a id='n5439' href='#n5439'>5439</a>
<a id='n5440' href='#n5440'>5440</a>
<a id='n5441' href='#n5441'>5441</a>
<a id='n5442' href='#n5442'>5442</a>
<a id='n5443' href='#n5443'>5443</a>
<a id='n5444' href='#n5444'>5444</a>
<a id='n5445' href='#n5445'>5445</a>
<a id='n5446' href='#n5446'>5446</a>
<a id='n5447' href='#n5447'>5447</a>
<a id='n5448' href='#n5448'>5448</a>
<a id='n5449' href='#n5449'>5449</a>
<a id='n5450' href='#n5450'>5450</a>
<a id='n5451' href='#n5451'>5451</a>
<a id='n5452' href='#n5452'>5452</a>
<a id='n5453' href='#n5453'>5453</a>
<a id='n5454' href='#n5454'>5454</a>
<a id='n5455' href='#n5455'>5455</a>
<a id='n5456' href='#n5456'>5456</a>
<a id='n5457' href='#n5457'>5457</a>
<a id='n5458' href='#n5458'>5458</a>
<a id='n5459' href='#n5459'>5459</a>
<a id='n5460' href='#n5460'>5460</a>
<a id='n5461' href='#n5461'>5461</a>
<a id='n5462' href='#n5462'>5462</a>
<a id='n5463' href='#n5463'>5463</a>
<a id='n5464' href='#n5464'>5464</a>
<a id='n5465' href='#n5465'>5465</a>
<a id='n5466' href='#n5466'>5466</a>
<a id='n5467' href='#n5467'>5467</a>
<a id='n5468' href='#n5468'>5468</a>
<a id='n5469' href='#n5469'>5469</a>
<a id='n5470' href='#n5470'>5470</a>
<a id='n5471' href='#n5471'>5471</a>
<a id='n5472' href='#n5472'>5472</a>
<a id='n5473' href='#n5473'>5473</a>
<a id='n5474' href='#n5474'>5474</a>
<a id='n5475' href='#n5475'>5475</a>
<a id='n5476' href='#n5476'>5476</a>
<a id='n5477' href='#n5477'>5477</a>
<a id='n5478' href='#n5478'>5478</a>
<a id='n5479' href='#n5479'>5479</a>
<a id='n5480' href='#n5480'>5480</a>
<a id='n5481' href='#n5481'>5481</a>
<a id='n5482' href='#n5482'>5482</a>
<a id='n5483' href='#n5483'>5483</a>
<a id='n5484' href='#n5484'>5484</a>
<a id='n5485' href='#n5485'>5485</a>
<a id='n5486' href='#n5486'>5486</a>
<a id='n5487' href='#n5487'>5487</a>
<a id='n5488' href='#n5488'>5488</a>
<a id='n5489' href='#n5489'>5489</a>
<a id='n5490' href='#n5490'>5490</a>
<a id='n5491' href='#n5491'>5491</a>
<a id='n5492' href='#n5492'>5492</a>
<a id='n5493' href='#n5493'>5493</a>
<a id='n5494' href='#n5494'>5494</a>
<a id='n5495' href='#n5495'>5495</a>
<a id='n5496' href='#n5496'>5496</a>
<a id='n5497' href='#n5497'>5497</a>
<a id='n5498' href='#n5498'>5498</a>
<a id='n5499' href='#n5499'>5499</a>
<a id='n5500' href='#n5500'>5500</a>
<a id='n5501' href='#n5501'>5501</a>
<a id='n5502' href='#n5502'>5502</a>
<a id='n5503' href='#n5503'>5503</a>
<a id='n5504' href='#n5504'>5504</a>
<a id='n5505' href='#n5505'>5505</a>
<a id='n5506' href='#n5506'>5506</a>
<a id='n5507' href='#n5507'>5507</a>
<a id='n5508' href='#n5508'>5508</a>
<a id='n5509' href='#n5509'>5509</a>
<a id='n5510' href='#n5510'>5510</a>
<a id='n5511' href='#n5511'>5511</a>
<a id='n5512' href='#n5512'>5512</a>
<a id='n5513' href='#n5513'>5513</a>
<a id='n5514' href='#n5514'>5514</a>
<a id='n5515' href='#n5515'>5515</a>
<a id='n5516' href='#n5516'>5516</a>
<a id='n5517' href='#n5517'>5517</a>
<a id='n5518' href='#n5518'>5518</a>
<a id='n5519' href='#n5519'>5519</a>
<a id='n5520' href='#n5520'>5520</a>
<a id='n5521' href='#n5521'>5521</a>
<a id='n5522' href='#n5522'>5522</a>
<a id='n5523' href='#n5523'>5523</a>
<a id='n5524' href='#n5524'>5524</a>
<a id='n5525' href='#n5525'>5525</a>
<a id='n5526' href='#n5526'>5526</a>
<a id='n5527' href='#n5527'>5527</a>
<a id='n5528' href='#n5528'>5528</a>
<a id='n5529' href='#n5529'>5529</a>
<a id='n5530' href='#n5530'>5530</a>
<a id='n5531' href='#n5531'>5531</a>
<a id='n5532' href='#n5532'>5532</a>
<a id='n5533' href='#n5533'>5533</a>
<a id='n5534' href='#n5534'>5534</a>
<a id='n5535' href='#n5535'>5535</a>
<a id='n5536' href='#n5536'>5536</a>
<a id='n5537' href='#n5537'>5537</a>
<a id='n5538' href='#n5538'>5538</a>
<a id='n5539' href='#n5539'>5539</a>
<a id='n5540' href='#n5540'>5540</a>
<a id='n5541' href='#n5541'>5541</a>
<a id='n5542' href='#n5542'>5542</a>
<a id='n5543' href='#n5543'>5543</a>
<a id='n5544' href='#n5544'>5544</a>
<a id='n5545' href='#n5545'>5545</a>
<a id='n5546' href='#n5546'>5546</a>
<a id='n5547' href='#n5547'>5547</a>
<a id='n5548' href='#n5548'>5548</a>
<a id='n5549' href='#n5549'>5549</a>
<a id='n5550' href='#n5550'>5550</a>
<a id='n5551' href='#n5551'>5551</a>
<a id='n5552' href='#n5552'>5552</a>
<a id='n5553' href='#n5553'>5553</a>
<a id='n5554' href='#n5554'>5554</a>
<a id='n5555' href='#n5555'>5555</a>
<a id='n5556' href='#n5556'>5556</a>
<a id='n5557' href='#n5557'>5557</a>
<a id='n5558' href='#n5558'>5558</a>
<a id='n5559' href='#n5559'>5559</a>
<a id='n5560' href='#n5560'>5560</a>
<a id='n5561' href='#n5561'>5561</a>
<a id='n5562' href='#n5562'>5562</a>
<a id='n5563' href='#n5563'>5563</a>
<a id='n5564' href='#n5564'>5564</a>
<a id='n5565' href='#n5565'>5565</a>
<a id='n5566' href='#n5566'>5566</a>
<a id='n5567' href='#n5567'>5567</a>
<a id='n5568' href='#n5568'>5568</a>
<a id='n5569' href='#n5569'>5569</a>
<a id='n5570' href='#n5570'>5570</a>
<a id='n5571' href='#n5571'>5571</a>
<a id='n5572' href='#n5572'>5572</a>
<a id='n5573' href='#n5573'>5573</a>
<a id='n5574' href='#n5574'>5574</a>
<a id='n5575' href='#n5575'>5575</a>
<a id='n5576' href='#n5576'>5576</a>
<a id='n5577' href='#n5577'>5577</a>
<a id='n5578' href='#n5578'>5578</a>
<a id='n5579' href='#n5579'>5579</a>
<a id='n5580' href='#n5580'>5580</a>
<a id='n5581' href='#n5581'>5581</a>
<a id='n5582' href='#n5582'>5582</a>
<a id='n5583' href='#n5583'>5583</a>
<a id='n5584' href='#n5584'>5584</a>
<a id='n5585' href='#n5585'>5585</a>
<a id='n5586' href='#n5586'>5586</a>
<a id='n5587' href='#n5587'>5587</a>
<a id='n5588' href='#n5588'>5588</a>
<a id='n5589' href='#n5589'>5589</a>
<a id='n5590' href='#n5590'>5590</a>
<a id='n5591' href='#n5591'>5591</a>
<a id='n5592' href='#n5592'>5592</a>
<a id='n5593' href='#n5593'>5593</a>
<a id='n5594' href='#n5594'>5594</a>
<a id='n5595' href='#n5595'>5595</a>
<a id='n5596' href='#n5596'>5596</a>
<a id='n5597' href='#n5597'>5597</a>
<a id='n5598' href='#n5598'>5598</a>
<a id='n5599' href='#n5599'>5599</a>
<a id='n5600' href='#n5600'>5600</a>
<a id='n5601' href='#n5601'>5601</a>
<a id='n5602' href='#n5602'>5602</a>
<a id='n5603' href='#n5603'>5603</a>
<a id='n5604' href='#n5604'>5604</a>
<a id='n5605' href='#n5605'>5605</a>
<a id='n5606' href='#n5606'>5606</a>
<a id='n5607' href='#n5607'>5607</a>
<a id='n5608' href='#n5608'>5608</a>
<a id='n5609' href='#n5609'>5609</a>
<a id='n5610' href='#n5610'>5610</a>
<a id='n5611' href='#n5611'>5611</a>
<a id='n5612' href='#n5612'>5612</a>
<a id='n5613' href='#n5613'>5613</a>
<a id='n5614' href='#n5614'>5614</a>
<a id='n5615' href='#n5615'>5615</a>
<a id='n5616' href='#n5616'>5616</a>
<a id='n5617' href='#n5617'>5617</a>
<a id='n5618' href='#n5618'>5618</a>
<a id='n5619' href='#n5619'>5619</a>
<a id='n5620' href='#n5620'>5620</a>
<a id='n5621' href='#n5621'>5621</a>
<a id='n5622' href='#n5622'>5622</a>
<a id='n5623' href='#n5623'>5623</a>
<a id='n5624' href='#n5624'>5624</a>
<a id='n5625' href='#n5625'>5625</a>
<a id='n5626' href='#n5626'>5626</a>
<a id='n5627' href='#n5627'>5627</a>
<a id='n5628' href='#n5628'>5628</a>
<a id='n5629' href='#n5629'>5629</a>
<a id='n5630' href='#n5630'>5630</a>
<a id='n5631' href='#n5631'>5631</a>
<a id='n5632' href='#n5632'>5632</a>
<a id='n5633' href='#n5633'>5633</a>
<a id='n5634' href='#n5634'>5634</a>
<a id='n5635' href='#n5635'>5635</a>
<a id='n5636' href='#n5636'>5636</a>
<a id='n5637' href='#n5637'>5637</a>
<a id='n5638' href='#n5638'>5638</a>
<a id='n5639' href='#n5639'>5639</a>
<a id='n5640' href='#n5640'>5640</a>
<a id='n5641' href='#n5641'>5641</a>
<a id='n5642' href='#n5642'>5642</a>
<a id='n5643' href='#n5643'>5643</a>
<a id='n5644' href='#n5644'>5644</a>
<a id='n5645' href='#n5645'>5645</a>
<a id='n5646' href='#n5646'>5646</a>
<a id='n5647' href='#n5647'>5647</a>
<a id='n5648' href='#n5648'>5648</a>
<a id='n5649' href='#n5649'>5649</a>
<a id='n5650' href='#n5650'>5650</a>
<a id='n5651' href='#n5651'>5651</a>
<a id='n5652' href='#n5652'>5652</a>
<a id='n5653' href='#n5653'>5653</a>
<a id='n5654' href='#n5654'>5654</a>
<a id='n5655' href='#n5655'>5655</a>
<a id='n5656' href='#n5656'>5656</a>
<a id='n5657' href='#n5657'>5657</a>
<a id='n5658' href='#n5658'>5658</a>
<a id='n5659' href='#n5659'>5659</a>
<a id='n5660' href='#n5660'>5660</a>
<a id='n5661' href='#n5661'>5661</a>
<a id='n5662' href='#n5662'>5662</a>
<a id='n5663' href='#n5663'>5663</a>
<a id='n5664' href='#n5664'>5664</a>
<a id='n5665' href='#n5665'>5665</a>
<a id='n5666' href='#n5666'>5666</a>
<a id='n5667' href='#n5667'>5667</a>
<a id='n5668' href='#n5668'>5668</a>
<a id='n5669' href='#n5669'>5669</a>
<a id='n5670' href='#n5670'>5670</a>
<a id='n5671' href='#n5671'>5671</a>
<a id='n5672' href='#n5672'>5672</a>
<a id='n5673' href='#n5673'>5673</a>
<a id='n5674' href='#n5674'>5674</a>
<a id='n5675' href='#n5675'>5675</a>
<a id='n5676' href='#n5676'>5676</a>
<a id='n5677' href='#n5677'>5677</a>
<a id='n5678' href='#n5678'>5678</a>
<a id='n5679' href='#n5679'>5679</a>
<a id='n5680' href='#n5680'>5680</a>
<a id='n5681' href='#n5681'>5681</a>
<a id='n5682' href='#n5682'>5682</a>
<a id='n5683' href='#n5683'>5683</a>
<a id='n5684' href='#n5684'>5684</a>
<a id='n5685' href='#n5685'>5685</a>
<a id='n5686' href='#n5686'>5686</a>
<a id='n5687' href='#n5687'>5687</a>
<a id='n5688' href='#n5688'>5688</a>
<a id='n5689' href='#n5689'>5689</a>
<a id='n5690' href='#n5690'>5690</a>
<a id='n5691' href='#n5691'>5691</a>
<a id='n5692' href='#n5692'>5692</a>
<a id='n5693' href='#n5693'>5693</a>
<a id='n5694' href='#n5694'>5694</a>
<a id='n5695' href='#n5695'>5695</a>
<a id='n5696' href='#n5696'>5696</a>
<a id='n5697' href='#n5697'>5697</a>
<a id='n5698' href='#n5698'>5698</a>
<a id='n5699' href='#n5699'>5699</a>
<a id='n5700' href='#n5700'>5700</a>
<a id='n5701' href='#n5701'>5701</a>
<a id='n5702' href='#n5702'>5702</a>
<a id='n5703' href='#n5703'>5703</a>
<a id='n5704' href='#n5704'>5704</a>
<a id='n5705' href='#n5705'>5705</a>
<a id='n5706' href='#n5706'>5706</a>
<a id='n5707' href='#n5707'>5707</a>
<a id='n5708' href='#n5708'>5708</a>
<a id='n5709' href='#n5709'>5709</a>
<a id='n5710' href='#n5710'>5710</a>
<a id='n5711' href='#n5711'>5711</a>
<a id='n5712' href='#n5712'>5712</a>
<a id='n5713' href='#n5713'>5713</a>
<a id='n5714' href='#n5714'>5714</a>
<a id='n5715' href='#n5715'>5715</a>
<a id='n5716' href='#n5716'>5716</a>
<a id='n5717' href='#n5717'>5717</a>
<a id='n5718' href='#n5718'>5718</a>
<a id='n5719' href='#n5719'>5719</a>
<a id='n5720' href='#n5720'>5720</a>
<a id='n5721' href='#n5721'>5721</a>
<a id='n5722' href='#n5722'>5722</a>
<a id='n5723' href='#n5723'>5723</a>
<a id='n5724' href='#n5724'>5724</a>
<a id='n5725' href='#n5725'>5725</a>
<a id='n5726' href='#n5726'>5726</a>
<a id='n5727' href='#n5727'>5727</a>
<a id='n5728' href='#n5728'>5728</a>
<a id='n5729' href='#n5729'>5729</a>
<a id='n5730' href='#n5730'>5730</a>
<a id='n5731' href='#n5731'>5731</a>
<a id='n5732' href='#n5732'>5732</a>
<a id='n5733' href='#n5733'>5733</a>
<a id='n5734' href='#n5734'>5734</a>
<a id='n5735' href='#n5735'>5735</a>
<a id='n5736' href='#n5736'>5736</a>
<a id='n5737' href='#n5737'>5737</a>
<a id='n5738' href='#n5738'>5738</a>
<a id='n5739' href='#n5739'>5739</a>
<a id='n5740' href='#n5740'>5740</a>
<a id='n5741' href='#n5741'>5741</a>
<a id='n5742' href='#n5742'>5742</a>
<a id='n5743' href='#n5743'>5743</a>
<a id='n5744' href='#n5744'>5744</a>
<a id='n5745' href='#n5745'>5745</a>
<a id='n5746' href='#n5746'>5746</a>
<a id='n5747' href='#n5747'>5747</a>
<a id='n5748' href='#n5748'>5748</a>
<a id='n5749' href='#n5749'>5749</a>
<a id='n5750' href='#n5750'>5750</a>
<a id='n5751' href='#n5751'>5751</a>
<a id='n5752' href='#n5752'>5752</a>
<a id='n5753' href='#n5753'>5753</a>
<a id='n5754' href='#n5754'>5754</a>
<a id='n5755' href='#n5755'>5755</a>
<a id='n5756' href='#n5756'>5756</a>
<a id='n5757' href='#n5757'>5757</a>
<a id='n5758' href='#n5758'>5758</a>
<a id='n5759' href='#n5759'>5759</a>
<a id='n5760' href='#n5760'>5760</a>
<a id='n5761' href='#n5761'>5761</a>
<a id='n5762' href='#n5762'>5762</a>
<a id='n5763' href='#n5763'>5763</a>
<a id='n5764' href='#n5764'>5764</a>
<a id='n5765' href='#n5765'>5765</a>
<a id='n5766' href='#n5766'>5766</a>
<a id='n5767' href='#n5767'>5767</a>
<a id='n5768' href='#n5768'>5768</a>
<a id='n5769' href='#n5769'>5769</a>
<a id='n5770' href='#n5770'>5770</a>
<a id='n5771' href='#n5771'>5771</a>
<a id='n5772' href='#n5772'>5772</a>
<a id='n5773' href='#n5773'>5773</a>
<a id='n5774' href='#n5774'>5774</a>
<a id='n5775' href='#n5775'>5775</a>
<a id='n5776' href='#n5776'>5776</a>
<a id='n5777' href='#n5777'>5777</a>
<a id='n5778' href='#n5778'>5778</a>
<a id='n5779' href='#n5779'>5779</a>
<a id='n5780' href='#n5780'>5780</a>
<a id='n5781' href='#n5781'>5781</a>
<a id='n5782' href='#n5782'>5782</a>
<a id='n5783' href='#n5783'>5783</a>
<a id='n5784' href='#n5784'>5784</a>
<a id='n5785' href='#n5785'>5785</a>
<a id='n5786' href='#n5786'>5786</a>
<a id='n5787' href='#n5787'>5787</a>
<a id='n5788' href='#n5788'>5788</a>
<a id='n5789' href='#n5789'>5789</a>
<a id='n5790' href='#n5790'>5790</a>
<a id='n5791' href='#n5791'>5791</a>
<a id='n5792' href='#n5792'>5792</a>
<a id='n5793' href='#n5793'>5793</a>
<a id='n5794' href='#n5794'>5794</a>
<a id='n5795' href='#n5795'>5795</a>
<a id='n5796' href='#n5796'>5796</a>
<a id='n5797' href='#n5797'>5797</a>
<a id='n5798' href='#n5798'>5798</a>
<a id='n5799' href='#n5799'>5799</a>
<a id='n5800' href='#n5800'>5800</a>
<a id='n5801' href='#n5801'>5801</a>
<a id='n5802' href='#n5802'>5802</a>
<a id='n5803' href='#n5803'>5803</a>
<a id='n5804' href='#n5804'>5804</a>
<a id='n5805' href='#n5805'>5805</a>
<a id='n5806' href='#n5806'>5806</a>
<a id='n5807' href='#n5807'>5807</a>
<a id='n5808' href='#n5808'>5808</a>
<a id='n5809' href='#n5809'>5809</a>
<a id='n5810' href='#n5810'>5810</a>
<a id='n5811' href='#n5811'>5811</a>
<a id='n5812' href='#n5812'>5812</a>
<a id='n5813' href='#n5813'>5813</a>
<a id='n5814' href='#n5814'>5814</a>
<a id='n5815' href='#n5815'>5815</a>
<a id='n5816' href='#n5816'>5816</a>
<a id='n5817' href='#n5817'>5817</a>
<a id='n5818' href='#n5818'>5818</a>
<a id='n5819' href='#n5819'>5819</a>
<a id='n5820' href='#n5820'>5820</a>
<a id='n5821' href='#n5821'>5821</a>
<a id='n5822' href='#n5822'>5822</a>
<a id='n5823' href='#n5823'>5823</a>
<a id='n5824' href='#n5824'>5824</a>
<a id='n5825' href='#n5825'>5825</a>
<a id='n5826' href='#n5826'>5826</a>
<a id='n5827' href='#n5827'>5827</a>
<a id='n5828' href='#n5828'>5828</a>
<a id='n5829' href='#n5829'>5829</a>
<a id='n5830' href='#n5830'>5830</a>
<a id='n5831' href='#n5831'>5831</a>
<a id='n5832' href='#n5832'>5832</a>
<a id='n5833' href='#n5833'>5833</a>
<a id='n5834' href='#n5834'>5834</a>
<a id='n5835' href='#n5835'>5835</a>
<a id='n5836' href='#n5836'>5836</a>
<a id='n5837' href='#n5837'>5837</a>
<a id='n5838' href='#n5838'>5838</a>
<a id='n5839' href='#n5839'>5839</a>
<a id='n5840' href='#n5840'>5840</a>
<a id='n5841' href='#n5841'>5841</a>
<a id='n5842' href='#n5842'>5842</a>
<a id='n5843' href='#n5843'>5843</a>
<a id='n5844' href='#n5844'>5844</a>
<a id='n5845' href='#n5845'>5845</a>
<a id='n5846' href='#n5846'>5846</a>
<a id='n5847' href='#n5847'>5847</a>
<a id='n5848' href='#n5848'>5848</a>
<a id='n5849' href='#n5849'>5849</a>
<a id='n5850' href='#n5850'>5850</a>
<a id='n5851' href='#n5851'>5851</a>
<a id='n5852' href='#n5852'>5852</a>
<a id='n5853' href='#n5853'>5853</a>
<a id='n5854' href='#n5854'>5854</a>
<a id='n5855' href='#n5855'>5855</a>
<a id='n5856' href='#n5856'>5856</a>
<a id='n5857' href='#n5857'>5857</a>
<a id='n5858' href='#n5858'>5858</a>
<a id='n5859' href='#n5859'>5859</a>
<a id='n5860' href='#n5860'>5860</a>
<a id='n5861' href='#n5861'>5861</a>
<a id='n5862' href='#n5862'>5862</a>
<a id='n5863' href='#n5863'>5863</a>
<a id='n5864' href='#n5864'>5864</a>
<a id='n5865' href='#n5865'>5865</a>
<a id='n5866' href='#n5866'>5866</a>
<a id='n5867' href='#n5867'>5867</a>
<a id='n5868' href='#n5868'>5868</a>
<a id='n5869' href='#n5869'>5869</a>
<a id='n5870' href='#n5870'>5870</a>
<a id='n5871' href='#n5871'>5871</a>
<a id='n5872' href='#n5872'>5872</a>
<a id='n5873' href='#n5873'>5873</a>
<a id='n5874' href='#n5874'>5874</a>
<a id='n5875' href='#n5875'>5875</a>
<a id='n5876' href='#n5876'>5876</a>
<a id='n5877' href='#n5877'>5877</a>
<a id='n5878' href='#n5878'>5878</a>
<a id='n5879' href='#n5879'>5879</a>
<a id='n5880' href='#n5880'>5880</a>
<a id='n5881' href='#n5881'>5881</a>
<a id='n5882' href='#n5882'>5882</a>
<a id='n5883' href='#n5883'>5883</a>
<a id='n5884' href='#n5884'>5884</a>
<a id='n5885' href='#n5885'>5885</a>
<a id='n5886' href='#n5886'>5886</a>
<a id='n5887' href='#n5887'>5887</a>
<a id='n5888' href='#n5888'>5888</a>
<a id='n5889' href='#n5889'>5889</a>
<a id='n5890' href='#n5890'>5890</a>
<a id='n5891' href='#n5891'>5891</a>
<a id='n5892' href='#n5892'>5892</a>
<a id='n5893' href='#n5893'>5893</a>
<a id='n5894' href='#n5894'>5894</a>
<a id='n5895' href='#n5895'>5895</a>
<a id='n5896' href='#n5896'>5896</a>
<a id='n5897' href='#n5897'>5897</a>
<a id='n5898' href='#n5898'>5898</a>
<a id='n5899' href='#n5899'>5899</a>
<a id='n5900' href='#n5900'>5900</a>
<a id='n5901' href='#n5901'>5901</a>
<a id='n5902' href='#n5902'>5902</a>
<a id='n5903' href='#n5903'>5903</a>
<a id='n5904' href='#n5904'>5904</a>
<a id='n5905' href='#n5905'>5905</a>
<a id='n5906' href='#n5906'>5906</a>
<a id='n5907' href='#n5907'>5907</a>
<a id='n5908' href='#n5908'>5908</a>
<a id='n5909' href='#n5909'>5909</a>
<a id='n5910' href='#n5910'>5910</a>
<a id='n5911' href='#n5911'>5911</a>
<a id='n5912' href='#n5912'>5912</a>
<a id='n5913' href='#n5913'>5913</a>
<a id='n5914' href='#n5914'>5914</a>
<a id='n5915' href='#n5915'>5915</a>
<a id='n5916' href='#n5916'>5916</a>
<a id='n5917' href='#n5917'>5917</a>
<a id='n5918' href='#n5918'>5918</a>
<a id='n5919' href='#n5919'>5919</a>
<a id='n5920' href='#n5920'>5920</a>
<a id='n5921' href='#n5921'>5921</a>
<a id='n5922' href='#n5922'>5922</a>
<a id='n5923' href='#n5923'>5923</a>
<a id='n5924' href='#n5924'>5924</a>
<a id='n5925' href='#n5925'>5925</a>
<a id='n5926' href='#n5926'>5926</a>
<a id='n5927' href='#n5927'>5927</a>
<a id='n5928' href='#n5928'>5928</a>
<a id='n5929' href='#n5929'>5929</a>
<a id='n5930' href='#n5930'>5930</a>
<a id='n5931' href='#n5931'>5931</a>
<a id='n5932' href='#n5932'>5932</a>
<a id='n5933' href='#n5933'>5933</a>
<a id='n5934' href='#n5934'>5934</a>
<a id='n5935' href='#n5935'>5935</a>
<a id='n5936' href='#n5936'>5936</a>
<a id='n5937' href='#n5937'>5937</a>
<a id='n5938' href='#n5938'>5938</a>
<a id='n5939' href='#n5939'>5939</a>
<a id='n5940' href='#n5940'>5940</a>
<a id='n5941' href='#n5941'>5941</a>
<a id='n5942' href='#n5942'>5942</a>
<a id='n5943' href='#n5943'>5943</a>
<a id='n5944' href='#n5944'>5944</a>
<a id='n5945' href='#n5945'>5945</a>
<a id='n5946' href='#n5946'>5946</a>
<a id='n5947' href='#n5947'>5947</a>
<a id='n5948' href='#n5948'>5948</a>
<a id='n5949' href='#n5949'>5949</a>
<a id='n5950' href='#n5950'>5950</a>
<a id='n5951' href='#n5951'>5951</a>
<a id='n5952' href='#n5952'>5952</a>
<a id='n5953' href='#n5953'>5953</a>
<a id='n5954' href='#n5954'>5954</a>
<a id='n5955' href='#n5955'>5955</a>
<a id='n5956' href='#n5956'>5956</a>
<a id='n5957' href='#n5957'>5957</a>
<a id='n5958' href='#n5958'>5958</a>
<a id='n5959' href='#n5959'>5959</a>
<a id='n5960' href='#n5960'>5960</a>
<a id='n5961' href='#n5961'>5961</a>
<a id='n5962' href='#n5962'>5962</a>
<a id='n5963' href='#n5963'>5963</a>
<a id='n5964' href='#n5964'>5964</a>
<a id='n5965' href='#n5965'>5965</a>
<a id='n5966' href='#n5966'>5966</a>
<a id='n5967' href='#n5967'>5967</a>
<a id='n5968' href='#n5968'>5968</a>
<a id='n5969' href='#n5969'>5969</a>
<a id='n5970' href='#n5970'>5970</a>
<a id='n5971' href='#n5971'>5971</a>
<a id='n5972' href='#n5972'>5972</a>
<a id='n5973' href='#n5973'>5973</a>
<a id='n5974' href='#n5974'>5974</a>
<a id='n5975' href='#n5975'>5975</a>
<a id='n5976' href='#n5976'>5976</a>
<a id='n5977' href='#n5977'>5977</a>
<a id='n5978' href='#n5978'>5978</a>
<a id='n5979' href='#n5979'>5979</a>
<a id='n5980' href='#n5980'>5980</a>
<a id='n5981' href='#n5981'>5981</a>
<a id='n5982' href='#n5982'>5982</a>
<a id='n5983' href='#n5983'>5983</a>
<a id='n5984' href='#n5984'>5984</a>
<a id='n5985' href='#n5985'>5985</a>
<a id='n5986' href='#n5986'>5986</a>
<a id='n5987' href='#n5987'>5987</a>
<a id='n5988' href='#n5988'>5988</a>
<a id='n5989' href='#n5989'>5989</a>
<a id='n5990' href='#n5990'>5990</a>
<a id='n5991' href='#n5991'>5991</a>
<a id='n5992' href='#n5992'>5992</a>
<a id='n5993' href='#n5993'>5993</a>
<a id='n5994' href='#n5994'>5994</a>
<a id='n5995' href='#n5995'>5995</a>
<a id='n5996' href='#n5996'>5996</a>
<a id='n5997' href='#n5997'>5997</a>
<a id='n5998' href='#n5998'>5998</a>
<a id='n5999' href='#n5999'>5999</a>
<a id='n6000' href='#n6000'>6000</a>
<a id='n6001' href='#n6001'>6001</a>
<a id='n6002' href='#n6002'>6002</a>
<a id='n6003' href='#n6003'>6003</a>
<a id='n6004' href='#n6004'>6004</a>
<a id='n6005' href='#n6005'>6005</a>
<a id='n6006' href='#n6006'>6006</a>
<a id='n6007' href='#n6007'>6007</a>
<a id='n6008' href='#n6008'>6008</a>
<a id='n6009' href='#n6009'>6009</a>
<a id='n6010' href='#n6010'>6010</a>
<a id='n6011' href='#n6011'>6011</a>
<a id='n6012' href='#n6012'>6012</a>
<a id='n6013' href='#n6013'>6013</a>
<a id='n6014' href='#n6014'>6014</a>
<a id='n6015' href='#n6015'>6015</a>
<a id='n6016' href='#n6016'>6016</a>
<a id='n6017' href='#n6017'>6017</a>
<a id='n6018' href='#n6018'>6018</a>
<a id='n6019' href='#n6019'>6019</a>
<a id='n6020' href='#n6020'>6020</a>
<a id='n6021' href='#n6021'>6021</a>
<a id='n6022' href='#n6022'>6022</a>
<a id='n6023' href='#n6023'>6023</a>
<a id='n6024' href='#n6024'>6024</a>
<a id='n6025' href='#n6025'>6025</a>
<a id='n6026' href='#n6026'>6026</a>
<a id='n6027' href='#n6027'>6027</a>
<a id='n6028' href='#n6028'>6028</a>
<a id='n6029' href='#n6029'>6029</a>
<a id='n6030' href='#n6030'>6030</a>
<a id='n6031' href='#n6031'>6031</a>
<a id='n6032' href='#n6032'>6032</a>
<a id='n6033' href='#n6033'>6033</a>
<a id='n6034' href='#n6034'>6034</a>
<a id='n6035' href='#n6035'>6035</a>
<a id='n6036' href='#n6036'>6036</a>
<a id='n6037' href='#n6037'>6037</a>
<a id='n6038' href='#n6038'>6038</a>
<a id='n6039' href='#n6039'>6039</a>
<a id='n6040' href='#n6040'>6040</a>
<a id='n6041' href='#n6041'>6041</a>
<a id='n6042' href='#n6042'>6042</a>
<a id='n6043' href='#n6043'>6043</a>
<a id='n6044' href='#n6044'>6044</a>
<a id='n6045' href='#n6045'>6045</a>
<a id='n6046' href='#n6046'>6046</a>
<a id='n6047' href='#n6047'>6047</a>
<a id='n6048' href='#n6048'>6048</a>
<a id='n6049' href='#n6049'>6049</a>
<a id='n6050' href='#n6050'>6050</a>
<a id='n6051' href='#n6051'>6051</a>
<a id='n6052' href='#n6052'>6052</a>
<a id='n6053' href='#n6053'>6053</a>
<a id='n6054' href='#n6054'>6054</a>
<a id='n6055' href='#n6055'>6055</a>
<a id='n6056' href='#n6056'>6056</a>
<a id='n6057' href='#n6057'>6057</a>
<a id='n6058' href='#n6058'>6058</a>
<a id='n6059' href='#n6059'>6059</a>
<a id='n6060' href='#n6060'>6060</a>
<a id='n6061' href='#n6061'>6061</a>
<a id='n6062' href='#n6062'>6062</a>
<a id='n6063' href='#n6063'>6063</a>
<a id='n6064' href='#n6064'>6064</a>
<a id='n6065' href='#n6065'>6065</a>
<a id='n6066' href='#n6066'>6066</a>
<a id='n6067' href='#n6067'>6067</a>
<a id='n6068' href='#n6068'>6068</a>
<a id='n6069' href='#n6069'>6069</a>
<a id='n6070' href='#n6070'>6070</a>
<a id='n6071' href='#n6071'>6071</a>
<a id='n6072' href='#n6072'>6072</a>
<a id='n6073' href='#n6073'>6073</a>
<a id='n6074' href='#n6074'>6074</a>
<a id='n6075' href='#n6075'>6075</a>
<a id='n6076' href='#n6076'>6076</a>
<a id='n6077' href='#n6077'>6077</a>
<a id='n6078' href='#n6078'>6078</a>
<a id='n6079' href='#n6079'>6079</a>
<a id='n6080' href='#n6080'>6080</a>
<a id='n6081' href='#n6081'>6081</a>
<a id='n6082' href='#n6082'>6082</a>
<a id='n6083' href='#n6083'>6083</a>
<a id='n6084' href='#n6084'>6084</a>
<a id='n6085' href='#n6085'>6085</a>
<a id='n6086' href='#n6086'>6086</a>
<a id='n6087' href='#n6087'>6087</a>
<a id='n6088' href='#n6088'>6088</a>
<a id='n6089' href='#n6089'>6089</a>
<a id='n6090' href='#n6090'>6090</a>
<a id='n6091' href='#n6091'>6091</a>
<a id='n6092' href='#n6092'>6092</a>
<a id='n6093' href='#n6093'>6093</a>
<a id='n6094' href='#n6094'>6094</a>
<a id='n6095' href='#n6095'>6095</a>
<a id='n6096' href='#n6096'>6096</a>
<a id='n6097' href='#n6097'>6097</a>
<a id='n6098' href='#n6098'>6098</a>
<a id='n6099' href='#n6099'>6099</a>
<a id='n6100' href='#n6100'>6100</a>
<a id='n6101' href='#n6101'>6101</a>
<a id='n6102' href='#n6102'>6102</a>
<a id='n6103' href='#n6103'>6103</a>
<a id='n6104' href='#n6104'>6104</a>
<a id='n6105' href='#n6105'>6105</a>
<a id='n6106' href='#n6106'>6106</a>
<a id='n6107' href='#n6107'>6107</a>
<a id='n6108' href='#n6108'>6108</a>
<a id='n6109' href='#n6109'>6109</a>
<a id='n6110' href='#n6110'>6110</a>
<a id='n6111' href='#n6111'>6111</a>
<a id='n6112' href='#n6112'>6112</a>
<a id='n6113' href='#n6113'>6113</a>
<a id='n6114' href='#n6114'>6114</a>
<a id='n6115' href='#n6115'>6115</a>
<a id='n6116' href='#n6116'>6116</a>
<a id='n6117' href='#n6117'>6117</a>
<a id='n6118' href='#n6118'>6118</a>
<a id='n6119' href='#n6119'>6119</a>
<a id='n6120' href='#n6120'>6120</a>
<a id='n6121' href='#n6121'>6121</a>
<a id='n6122' href='#n6122'>6122</a>
<a id='n6123' href='#n6123'>6123</a>
<a id='n6124' href='#n6124'>6124</a>
<a id='n6125' href='#n6125'>6125</a>
<a id='n6126' href='#n6126'>6126</a>
<a id='n6127' href='#n6127'>6127</a>
<a id='n6128' href='#n6128'>6128</a>
<a id='n6129' href='#n6129'>6129</a>
<a id='n6130' href='#n6130'>6130</a>
<a id='n6131' href='#n6131'>6131</a>
<a id='n6132' href='#n6132'>6132</a>
<a id='n6133' href='#n6133'>6133</a>
<a id='n6134' href='#n6134'>6134</a>
<a id='n6135' href='#n6135'>6135</a>
<a id='n6136' href='#n6136'>6136</a>
<a id='n6137' href='#n6137'>6137</a>
<a id='n6138' href='#n6138'>6138</a>
<a id='n6139' href='#n6139'>6139</a>
<a id='n6140' href='#n6140'>6140</a>
<a id='n6141' href='#n6141'>6141</a>
<a id='n6142' href='#n6142'>6142</a>
<a id='n6143' href='#n6143'>6143</a>
<a id='n6144' href='#n6144'>6144</a>
<a id='n6145' href='#n6145'>6145</a>
<a id='n6146' href='#n6146'>6146</a>
<a id='n6147' href='#n6147'>6147</a>
<a id='n6148' href='#n6148'>6148</a>
<a id='n6149' href='#n6149'>6149</a>
<a id='n6150' href='#n6150'>6150</a>
<a id='n6151' href='#n6151'>6151</a>
<a id='n6152' href='#n6152'>6152</a>
<a id='n6153' href='#n6153'>6153</a>
<a id='n6154' href='#n6154'>6154</a>
<a id='n6155' href='#n6155'>6155</a>
<a id='n6156' href='#n6156'>6156</a>
<a id='n6157' href='#n6157'>6157</a>
<a id='n6158' href='#n6158'>6158</a>
<a id='n6159' href='#n6159'>6159</a>
<a id='n6160' href='#n6160'>6160</a>
<a id='n6161' href='#n6161'>6161</a>
<a id='n6162' href='#n6162'>6162</a>
<a id='n6163' href='#n6163'>6163</a>
<a id='n6164' href='#n6164'>6164</a>
<a id='n6165' href='#n6165'>6165</a>
<a id='n6166' href='#n6166'>6166</a>
<a id='n6167' href='#n6167'>6167</a>
<a id='n6168' href='#n6168'>6168</a>
<a id='n6169' href='#n6169'>6169</a>
<a id='n6170' href='#n6170'>6170</a>
<a id='n6171' href='#n6171'>6171</a>
<a id='n6172' href='#n6172'>6172</a>
<a id='n6173' href='#n6173'>6173</a>
<a id='n6174' href='#n6174'>6174</a>
<a id='n6175' href='#n6175'>6175</a>
<a id='n6176' href='#n6176'>6176</a>
<a id='n6177' href='#n6177'>6177</a>
<a id='n6178' href='#n6178'>6178</a>
<a id='n6179' href='#n6179'>6179</a>
<a id='n6180' href='#n6180'>6180</a>
<a id='n6181' href='#n6181'>6181</a>
<a id='n6182' href='#n6182'>6182</a>
<a id='n6183' href='#n6183'>6183</a>
<a id='n6184' href='#n6184'>6184</a>
<a id='n6185' href='#n6185'>6185</a>
<a id='n6186' href='#n6186'>6186</a>
<a id='n6187' href='#n6187'>6187</a>
<a id='n6188' href='#n6188'>6188</a>
<a id='n6189' href='#n6189'>6189</a>
<a id='n6190' href='#n6190'>6190</a>
<a id='n6191' href='#n6191'>6191</a>
<a id='n6192' href='#n6192'>6192</a>
<a id='n6193' href='#n6193'>6193</a>
<a id='n6194' href='#n6194'>6194</a>
<a id='n6195' href='#n6195'>6195</a>
<a id='n6196' href='#n6196'>6196</a>
<a id='n6197' href='#n6197'>6197</a>
<a id='n6198' href='#n6198'>6198</a>
<a id='n6199' href='#n6199'>6199</a>
<a id='n6200' href='#n6200'>6200</a>
<a id='n6201' href='#n6201'>6201</a>
<a id='n6202' href='#n6202'>6202</a>
<a id='n6203' href='#n6203'>6203</a>
<a id='n6204' href='#n6204'>6204</a>
<a id='n6205' href='#n6205'>6205</a>
<a id='n6206' href='#n6206'>6206</a>
<a id='n6207' href='#n6207'>6207</a>
<a id='n6208' href='#n6208'>6208</a>
<a id='n6209' href='#n6209'>6209</a>
<a id='n6210' href='#n6210'>6210</a>
<a id='n6211' href='#n6211'>6211</a>
<a id='n6212' href='#n6212'>6212</a>
<a id='n6213' href='#n6213'>6213</a>
<a id='n6214' href='#n6214'>6214</a>
<a id='n6215' href='#n6215'>6215</a>
<a id='n6216' href='#n6216'>6216</a>
<a id='n6217' href='#n6217'>6217</a>
<a id='n6218' href='#n6218'>6218</a>
<a id='n6219' href='#n6219'>6219</a>
<a id='n6220' href='#n6220'>6220</a>
<a id='n6221' href='#n6221'>6221</a>
<a id='n6222' href='#n6222'>6222</a>
<a id='n6223' href='#n6223'>6223</a>
<a id='n6224' href='#n6224'>6224</a>
<a id='n6225' href='#n6225'>6225</a>
<a id='n6226' href='#n6226'>6226</a>
<a id='n6227' href='#n6227'>6227</a>
<a id='n6228' href='#n6228'>6228</a>
<a id='n6229' href='#n6229'>6229</a>
<a id='n6230' href='#n6230'>6230</a>
<a id='n6231' href='#n6231'>6231</a>
<a id='n6232' href='#n6232'>6232</a>
<a id='n6233' href='#n6233'>6233</a>
<a id='n6234' href='#n6234'>6234</a>
<a id='n6235' href='#n6235'>6235</a>
<a id='n6236' href='#n6236'>6236</a>
<a id='n6237' href='#n6237'>6237</a>
<a id='n6238' href='#n6238'>6238</a>
<a id='n6239' href='#n6239'>6239</a>
<a id='n6240' href='#n6240'>6240</a>
<a id='n6241' href='#n6241'>6241</a>
<a id='n6242' href='#n6242'>6242</a>
<a id='n6243' href='#n6243'>6243</a>
<a id='n6244' href='#n6244'>6244</a>
<a id='n6245' href='#n6245'>6245</a>
<a id='n6246' href='#n6246'>6246</a>
<a id='n6247' href='#n6247'>6247</a>
<a id='n6248' href='#n6248'>6248</a>
<a id='n6249' href='#n6249'>6249</a>
<a id='n6250' href='#n6250'>6250</a>
<a id='n6251' href='#n6251'>6251</a>
<a id='n6252' href='#n6252'>6252</a>
<a id='n6253' href='#n6253'>6253</a>
<a id='n6254' href='#n6254'>6254</a>
<a id='n6255' href='#n6255'>6255</a>
<a id='n6256' href='#n6256'>6256</a>
<a id='n6257' href='#n6257'>6257</a>
<a id='n6258' href='#n6258'>6258</a>
<a id='n6259' href='#n6259'>6259</a>
<a id='n6260' href='#n6260'>6260</a>
<a id='n6261' href='#n6261'>6261</a>
<a id='n6262' href='#n6262'>6262</a>
<a id='n6263' href='#n6263'>6263</a>
<a id='n6264' href='#n6264'>6264</a>
<a id='n6265' href='#n6265'>6265</a>
<a id='n6266' href='#n6266'>6266</a>
<a id='n6267' href='#n6267'>6267</a>
<a id='n6268' href='#n6268'>6268</a>
<a id='n6269' href='#n6269'>6269</a>
<a id='n6270' href='#n6270'>6270</a>
<a id='n6271' href='#n6271'>6271</a>
<a id='n6272' href='#n6272'>6272</a>
<a id='n6273' href='#n6273'>6273</a>
<a id='n6274' href='#n6274'>6274</a>
<a id='n6275' href='#n6275'>6275</a>
<a id='n6276' href='#n6276'>6276</a>
<a id='n6277' href='#n6277'>6277</a>
<a id='n6278' href='#n6278'>6278</a>
<a id='n6279' href='#n6279'>6279</a>
<a id='n6280' href='#n6280'>6280</a>
<a id='n6281' href='#n6281'>6281</a>
<a id='n6282' href='#n6282'>6282</a>
<a id='n6283' href='#n6283'>6283</a>
<a id='n6284' href='#n6284'>6284</a>
<a id='n6285' href='#n6285'>6285</a>
<a id='n6286' href='#n6286'>6286</a>
<a id='n6287' href='#n6287'>6287</a>
<a id='n6288' href='#n6288'>6288</a>
<a id='n6289' href='#n6289'>6289</a>
<a id='n6290' href='#n6290'>6290</a>
<a id='n6291' href='#n6291'>6291</a>
<a id='n6292' href='#n6292'>6292</a>
<a id='n6293' href='#n6293'>6293</a>
<a id='n6294' href='#n6294'>6294</a>
<a id='n6295' href='#n6295'>6295</a>
<a id='n6296' href='#n6296'>6296</a>
<a id='n6297' href='#n6297'>6297</a>
<a id='n6298' href='#n6298'>6298</a>
<a id='n6299' href='#n6299'>6299</a>
<a id='n6300' href='#n6300'>6300</a>
<a id='n6301' href='#n6301'>6301</a>
<a id='n6302' href='#n6302'>6302</a>
<a id='n6303' href='#n6303'>6303</a>
<a id='n6304' href='#n6304'>6304</a>
<a id='n6305' href='#n6305'>6305</a>
<a id='n6306' href='#n6306'>6306</a>
<a id='n6307' href='#n6307'>6307</a>
<a id='n6308' href='#n6308'>6308</a>
<a id='n6309' href='#n6309'>6309</a>
<a id='n6310' href='#n6310'>6310</a>
<a id='n6311' href='#n6311'>6311</a>
<a id='n6312' href='#n6312'>6312</a>
<a id='n6313' href='#n6313'>6313</a>
<a id='n6314' href='#n6314'>6314</a>
<a id='n6315' href='#n6315'>6315</a>
<a id='n6316' href='#n6316'>6316</a>
<a id='n6317' href='#n6317'>6317</a>
<a id='n6318' href='#n6318'>6318</a>
<a id='n6319' href='#n6319'>6319</a>
<a id='n6320' href='#n6320'>6320</a>
<a id='n6321' href='#n6321'>6321</a>
<a id='n6322' href='#n6322'>6322</a>
<a id='n6323' href='#n6323'>6323</a>
<a id='n6324' href='#n6324'>6324</a>
<a id='n6325' href='#n6325'>6325</a>
<a id='n6326' href='#n6326'>6326</a>
<a id='n6327' href='#n6327'>6327</a>
<a id='n6328' href='#n6328'>6328</a>
<a id='n6329' href='#n6329'>6329</a>
<a id='n6330' href='#n6330'>6330</a>
<a id='n6331' href='#n6331'>6331</a>
<a id='n6332' href='#n6332'>6332</a>
<a id='n6333' href='#n6333'>6333</a>
<a id='n6334' href='#n6334'>6334</a>
<a id='n6335' href='#n6335'>6335</a>
<a id='n6336' href='#n6336'>6336</a>
<a id='n6337' href='#n6337'>6337</a>
<a id='n6338' href='#n6338'>6338</a>
<a id='n6339' href='#n6339'>6339</a>
<a id='n6340' href='#n6340'>6340</a>
<a id='n6341' href='#n6341'>6341</a>
<a id='n6342' href='#n6342'>6342</a>
<a id='n6343' href='#n6343'>6343</a>
<a id='n6344' href='#n6344'>6344</a>
<a id='n6345' href='#n6345'>6345</a>
<a id='n6346' href='#n6346'>6346</a>
<a id='n6347' href='#n6347'>6347</a>
<a id='n6348' href='#n6348'>6348</a>
<a id='n6349' href='#n6349'>6349</a>
<a id='n6350' href='#n6350'>6350</a>
<a id='n6351' href='#n6351'>6351</a>
<a id='n6352' href='#n6352'>6352</a>
<a id='n6353' href='#n6353'>6353</a>
<a id='n6354' href='#n6354'>6354</a>
<a id='n6355' href='#n6355'>6355</a>
<a id='n6356' href='#n6356'>6356</a>
<a id='n6357' href='#n6357'>6357</a>
<a id='n6358' href='#n6358'>6358</a>
<a id='n6359' href='#n6359'>6359</a>
<a id='n6360' href='#n6360'>6360</a>
<a id='n6361' href='#n6361'>6361</a>
<a id='n6362' href='#n6362'>6362</a>
<a id='n6363' href='#n6363'>6363</a>
<a id='n6364' href='#n6364'>6364</a>
<a id='n6365' href='#n6365'>6365</a>
<a id='n6366' href='#n6366'>6366</a>
<a id='n6367' href='#n6367'>6367</a>
<a id='n6368' href='#n6368'>6368</a>
<a id='n6369' href='#n6369'>6369</a>
<a id='n6370' href='#n6370'>6370</a>
<a id='n6371' href='#n6371'>6371</a>
<a id='n6372' href='#n6372'>6372</a>
<a id='n6373' href='#n6373'>6373</a>
<a id='n6374' href='#n6374'>6374</a>
<a id='n6375' href='#n6375'>6375</a>
<a id='n6376' href='#n6376'>6376</a>
<a id='n6377' href='#n6377'>6377</a>
<a id='n6378' href='#n6378'>6378</a>
<a id='n6379' href='#n6379'>6379</a>
<a id='n6380' href='#n6380'>6380</a>
<a id='n6381' href='#n6381'>6381</a>
<a id='n6382' href='#n6382'>6382</a>
<a id='n6383' href='#n6383'>6383</a>
<a id='n6384' href='#n6384'>6384</a>
<a id='n6385' href='#n6385'>6385</a>
<a id='n6386' href='#n6386'>6386</a>
<a id='n6387' href='#n6387'>6387</a>
<a id='n6388' href='#n6388'>6388</a>
<a id='n6389' href='#n6389'>6389</a>
<a id='n6390' href='#n6390'>6390</a>
<a id='n6391' href='#n6391'>6391</a>
<a id='n6392' href='#n6392'>6392</a>
<a id='n6393' href='#n6393'>6393</a>
<a id='n6394' href='#n6394'>6394</a>
<a id='n6395' href='#n6395'>6395</a>
<a id='n6396' href='#n6396'>6396</a>
<a id='n6397' href='#n6397'>6397</a>
<a id='n6398' href='#n6398'>6398</a>
<a id='n6399' href='#n6399'>6399</a>
<a id='n6400' href='#n6400'>6400</a>
<a id='n6401' href='#n6401'>6401</a>
<a id='n6402' href='#n6402'>6402</a>
<a id='n6403' href='#n6403'>6403</a>
<a id='n6404' href='#n6404'>6404</a>
<a id='n6405' href='#n6405'>6405</a>
<a id='n6406' href='#n6406'>6406</a>
<a id='n6407' href='#n6407'>6407</a>
<a id='n6408' href='#n6408'>6408</a>
<a id='n6409' href='#n6409'>6409</a>
<a id='n6410' href='#n6410'>6410</a>
<a id='n6411' href='#n6411'>6411</a>
<a id='n6412' href='#n6412'>6412</a>
<a id='n6413' href='#n6413'>6413</a>
<a id='n6414' href='#n6414'>6414</a>
<a id='n6415' href='#n6415'>6415</a>
<a id='n6416' href='#n6416'>6416</a>
<a id='n6417' href='#n6417'>6417</a>
<a id='n6418' href='#n6418'>6418</a>
<a id='n6419' href='#n6419'>6419</a>
<a id='n6420' href='#n6420'>6420</a>
<a id='n6421' href='#n6421'>6421</a>
<a id='n6422' href='#n6422'>6422</a>
<a id='n6423' href='#n6423'>6423</a>
<a id='n6424' href='#n6424'>6424</a>
<a id='n6425' href='#n6425'>6425</a>
<a id='n6426' href='#n6426'>6426</a>
<a id='n6427' href='#n6427'>6427</a>
<a id='n6428' href='#n6428'>6428</a>
<a id='n6429' href='#n6429'>6429</a>
<a id='n6430' href='#n6430'>6430</a>
<a id='n6431' href='#n6431'>6431</a>
<a id='n6432' href='#n6432'>6432</a>
<a id='n6433' href='#n6433'>6433</a>
<a id='n6434' href='#n6434'>6434</a>
<a id='n6435' href='#n6435'>6435</a>
<a id='n6436' href='#n6436'>6436</a>
<a id='n6437' href='#n6437'>6437</a>
<a id='n6438' href='#n6438'>6438</a>
<a id='n6439' href='#n6439'>6439</a>
<a id='n6440' href='#n6440'>6440</a>
<a id='n6441' href='#n6441'>6441</a>
<a id='n6442' href='#n6442'>6442</a>
<a id='n6443' href='#n6443'>6443</a>
<a id='n6444' href='#n6444'>6444</a>
<a id='n6445' href='#n6445'>6445</a>
<a id='n6446' href='#n6446'>6446</a>
<a id='n6447' href='#n6447'>6447</a>
<a id='n6448' href='#n6448'>6448</a>
<a id='n6449' href='#n6449'>6449</a>
<a id='n6450' href='#n6450'>6450</a>
<a id='n6451' href='#n6451'>6451</a>
<a id='n6452' href='#n6452'>6452</a>
<a id='n6453' href='#n6453'>6453</a>
<a id='n6454' href='#n6454'>6454</a>
<a id='n6455' href='#n6455'>6455</a>
<a id='n6456' href='#n6456'>6456</a>
<a id='n6457' href='#n6457'>6457</a>
<a id='n6458' href='#n6458'>6458</a>
<a id='n6459' href='#n6459'>6459</a>
<a id='n6460' href='#n6460'>6460</a>
<a id='n6461' href='#n6461'>6461</a>
<a id='n6462' href='#n6462'>6462</a>
<a id='n6463' href='#n6463'>6463</a>
<a id='n6464' href='#n6464'>6464</a>
<a id='n6465' href='#n6465'>6465</a>
<a id='n6466' href='#n6466'>6466</a>
<a id='n6467' href='#n6467'>6467</a>
<a id='n6468' href='#n6468'>6468</a>
<a id='n6469' href='#n6469'>6469</a>
<a id='n6470' href='#n6470'>6470</a>
<a id='n6471' href='#n6471'>6471</a>
<a id='n6472' href='#n6472'>6472</a>
<a id='n6473' href='#n6473'>6473</a>
<a id='n6474' href='#n6474'>6474</a>
<a id='n6475' href='#n6475'>6475</a>
<a id='n6476' href='#n6476'>6476</a>
<a id='n6477' href='#n6477'>6477</a>
<a id='n6478' href='#n6478'>6478</a>
<a id='n6479' href='#n6479'>6479</a>
<a id='n6480' href='#n6480'>6480</a>
<a id='n6481' href='#n6481'>6481</a>
<a id='n6482' href='#n6482'>6482</a>
<a id='n6483' href='#n6483'>6483</a>
<a id='n6484' href='#n6484'>6484</a>
<a id='n6485' href='#n6485'>6485</a>
<a id='n6486' href='#n6486'>6486</a>
<a id='n6487' href='#n6487'>6487</a>
<a id='n6488' href='#n6488'>6488</a>
<a id='n6489' href='#n6489'>6489</a>
<a id='n6490' href='#n6490'>6490</a>
<a id='n6491' href='#n6491'>6491</a>
<a id='n6492' href='#n6492'>6492</a>
<a id='n6493' href='#n6493'>6493</a>
<a id='n6494' href='#n6494'>6494</a>
<a id='n6495' href='#n6495'>6495</a>
<a id='n6496' href='#n6496'>6496</a>
<a id='n6497' href='#n6497'>6497</a>
<a id='n6498' href='#n6498'>6498</a>
<a id='n6499' href='#n6499'>6499</a>
<a id='n6500' href='#n6500'>6500</a>
<a id='n6501' href='#n6501'>6501</a>
<a id='n6502' href='#n6502'>6502</a>
<a id='n6503' href='#n6503'>6503</a>
<a id='n6504' href='#n6504'>6504</a>
<a id='n6505' href='#n6505'>6505</a>
<a id='n6506' href='#n6506'>6506</a>
<a id='n6507' href='#n6507'>6507</a>
<a id='n6508' href='#n6508'>6508</a>
<a id='n6509' href='#n6509'>6509</a>
<a id='n6510' href='#n6510'>6510</a>
<a id='n6511' href='#n6511'>6511</a>
<a id='n6512' href='#n6512'>6512</a>
<a id='n6513' href='#n6513'>6513</a>
<a id='n6514' href='#n6514'>6514</a>
<a id='n6515' href='#n6515'>6515</a>
<a id='n6516' href='#n6516'>6516</a>
<a id='n6517' href='#n6517'>6517</a>
<a id='n6518' href='#n6518'>6518</a>
<a id='n6519' href='#n6519'>6519</a>
<a id='n6520' href='#n6520'>6520</a>
<a id='n6521' href='#n6521'>6521</a>
<a id='n6522' href='#n6522'>6522</a>
<a id='n6523' href='#n6523'>6523</a>
<a id='n6524' href='#n6524'>6524</a>
<a id='n6525' href='#n6525'>6525</a>
<a id='n6526' href='#n6526'>6526</a>
<a id='n6527' href='#n6527'>6527</a>
<a id='n6528' href='#n6528'>6528</a>
<a id='n6529' href='#n6529'>6529</a>
<a id='n6530' href='#n6530'>6530</a>
<a id='n6531' href='#n6531'>6531</a>
<a id='n6532' href='#n6532'>6532</a>
<a id='n6533' href='#n6533'>6533</a>
<a id='n6534' href='#n6534'>6534</a>
<a id='n6535' href='#n6535'>6535</a>
<a id='n6536' href='#n6536'>6536</a>
<a id='n6537' href='#n6537'>6537</a>
<a id='n6538' href='#n6538'>6538</a>
<a id='n6539' href='#n6539'>6539</a>
<a id='n6540' href='#n6540'>6540</a>
<a id='n6541' href='#n6541'>6541</a>
<a id='n6542' href='#n6542'>6542</a>
<a id='n6543' href='#n6543'>6543</a>
<a id='n6544' href='#n6544'>6544</a>
<a id='n6545' href='#n6545'>6545</a>
<a id='n6546' href='#n6546'>6546</a>
<a id='n6547' href='#n6547'>6547</a>
<a id='n6548' href='#n6548'>6548</a>
<a id='n6549' href='#n6549'>6549</a>
<a id='n6550' href='#n6550'>6550</a>
<a id='n6551' href='#n6551'>6551</a>
<a id='n6552' href='#n6552'>6552</a>
<a id='n6553' href='#n6553'>6553</a>
<a id='n6554' href='#n6554'>6554</a>
<a id='n6555' href='#n6555'>6555</a>
<a id='n6556' href='#n6556'>6556</a>
<a id='n6557' href='#n6557'>6557</a>
<a id='n6558' href='#n6558'>6558</a>
<a id='n6559' href='#n6559'>6559</a>
<a id='n6560' href='#n6560'>6560</a>
<a id='n6561' href='#n6561'>6561</a>
<a id='n6562' href='#n6562'>6562</a>
<a id='n6563' href='#n6563'>6563</a>
<a id='n6564' href='#n6564'>6564</a>
<a id='n6565' href='#n6565'>6565</a>
<a id='n6566' href='#n6566'>6566</a>
<a id='n6567' href='#n6567'>6567</a>
<a id='n6568' href='#n6568'>6568</a>
<a id='n6569' href='#n6569'>6569</a>
<a id='n6570' href='#n6570'>6570</a>
<a id='n6571' href='#n6571'>6571</a>
<a id='n6572' href='#n6572'>6572</a>
<a id='n6573' href='#n6573'>6573</a>
<a id='n6574' href='#n6574'>6574</a>
<a id='n6575' href='#n6575'>6575</a>
<a id='n6576' href='#n6576'>6576</a>
<a id='n6577' href='#n6577'>6577</a>
<a id='n6578' href='#n6578'>6578</a>
<a id='n6579' href='#n6579'>6579</a>
<a id='n6580' href='#n6580'>6580</a>
<a id='n6581' href='#n6581'>6581</a>
<a id='n6582' href='#n6582'>6582</a>
<a id='n6583' href='#n6583'>6583</a>
<a id='n6584' href='#n6584'>6584</a>
<a id='n6585' href='#n6585'>6585</a>
<a id='n6586' href='#n6586'>6586</a>
<a id='n6587' href='#n6587'>6587</a>
<a id='n6588' href='#n6588'>6588</a>
<a id='n6589' href='#n6589'>6589</a>
<a id='n6590' href='#n6590'>6590</a>
<a id='n6591' href='#n6591'>6591</a>
<a id='n6592' href='#n6592'>6592</a>
<a id='n6593' href='#n6593'>6593</a>
<a id='n6594' href='#n6594'>6594</a>
<a id='n6595' href='#n6595'>6595</a>
<a id='n6596' href='#n6596'>6596</a>
<a id='n6597' href='#n6597'>6597</a>
<a id='n6598' href='#n6598'>6598</a>
<a id='n6599' href='#n6599'>6599</a>
<a id='n6600' href='#n6600'>6600</a>
<a id='n6601' href='#n6601'>6601</a>
<a id='n6602' href='#n6602'>6602</a>
<a id='n6603' href='#n6603'>6603</a>
<a id='n6604' href='#n6604'>6604</a>
<a id='n6605' href='#n6605'>6605</a>
<a id='n6606' href='#n6606'>6606</a>
<a id='n6607' href='#n6607'>6607</a>
<a id='n6608' href='#n6608'>6608</a>
<a id='n6609' href='#n6609'>6609</a>
<a id='n6610' href='#n6610'>6610</a>
<a id='n6611' href='#n6611'>6611</a>
<a id='n6612' href='#n6612'>6612</a>
<a id='n6613' href='#n6613'>6613</a>
<a id='n6614' href='#n6614'>6614</a>
<a id='n6615' href='#n6615'>6615</a>
<a id='n6616' href='#n6616'>6616</a>
<a id='n6617' href='#n6617'>6617</a>
<a id='n6618' href='#n6618'>6618</a>
<a id='n6619' href='#n6619'>6619</a>
<a id='n6620' href='#n6620'>6620</a>
<a id='n6621' href='#n6621'>6621</a>
<a id='n6622' href='#n6622'>6622</a>
<a id='n6623' href='#n6623'>6623</a>
<a id='n6624' href='#n6624'>6624</a>
<a id='n6625' href='#n6625'>6625</a>
<a id='n6626' href='#n6626'>6626</a>
<a id='n6627' href='#n6627'>6627</a>
<a id='n6628' href='#n6628'>6628</a>
<a id='n6629' href='#n6629'>6629</a>
<a id='n6630' href='#n6630'>6630</a>
<a id='n6631' href='#n6631'>6631</a>
<a id='n6632' href='#n6632'>6632</a>
<a id='n6633' href='#n6633'>6633</a>
<a id='n6634' href='#n6634'>6634</a>
<a id='n6635' href='#n6635'>6635</a>
<a id='n6636' href='#n6636'>6636</a>
<a id='n6637' href='#n6637'>6637</a>
<a id='n6638' href='#n6638'>6638</a>
<a id='n6639' href='#n6639'>6639</a>
<a id='n6640' href='#n6640'>6640</a>
<a id='n6641' href='#n6641'>6641</a>
<a id='n6642' href='#n6642'>6642</a>
<a id='n6643' href='#n6643'>6643</a>
<a id='n6644' href='#n6644'>6644</a>
<a id='n6645' href='#n6645'>6645</a>
<a id='n6646' href='#n6646'>6646</a>
<a id='n6647' href='#n6647'>6647</a>
<a id='n6648' href='#n6648'>6648</a>
<a id='n6649' href='#n6649'>6649</a>
<a id='n6650' href='#n6650'>6650</a>
<a id='n6651' href='#n6651'>6651</a>
<a id='n6652' href='#n6652'>6652</a>
<a id='n6653' href='#n6653'>6653</a>
<a id='n6654' href='#n6654'>6654</a>
<a id='n6655' href='#n6655'>6655</a>
<a id='n6656' href='#n6656'>6656</a>
<a id='n6657' href='#n6657'>6657</a>
<a id='n6658' href='#n6658'>6658</a>
<a id='n6659' href='#n6659'>6659</a>
<a id='n6660' href='#n6660'>6660</a>
<a id='n6661' href='#n6661'>6661</a>
<a id='n6662' href='#n6662'>6662</a>
<a id='n6663' href='#n6663'>6663</a>
<a id='n6664' href='#n6664'>6664</a>
<a id='n6665' href='#n6665'>6665</a>
<a id='n6666' href='#n6666'>6666</a>
<a id='n6667' href='#n6667'>6667</a>
<a id='n6668' href='#n6668'>6668</a>
<a id='n6669' href='#n6669'>6669</a>
<a id='n6670' href='#n6670'>6670</a>
<a id='n6671' href='#n6671'>6671</a>
<a id='n6672' href='#n6672'>6672</a>
<a id='n6673' href='#n6673'>6673</a>
<a id='n6674' href='#n6674'>6674</a>
<a id='n6675' href='#n6675'>6675</a>
<a id='n6676' href='#n6676'>6676</a>
<a id='n6677' href='#n6677'>6677</a>
<a id='n6678' href='#n6678'>6678</a>
<a id='n6679' href='#n6679'>6679</a>
<a id='n6680' href='#n6680'>6680</a>
<a id='n6681' href='#n6681'>6681</a>
<a id='n6682' href='#n6682'>6682</a>
<a id='n6683' href='#n6683'>6683</a>
<a id='n6684' href='#n6684'>6684</a>
<a id='n6685' href='#n6685'>6685</a>
<a id='n6686' href='#n6686'>6686</a>
<a id='n6687' href='#n6687'>6687</a>
<a id='n6688' href='#n6688'>6688</a>
<a id='n6689' href='#n6689'>6689</a>
<a id='n6690' href='#n6690'>6690</a>
<a id='n6691' href='#n6691'>6691</a>
</pre></td>
<td class='lines'><pre><code><span class="hl kwa">\documentclass</span><span class="hl opt">[</span>b5paper<span class="hl opt">]{</span>book<span class="hl opt">}</span>
<span class="hl kwa">\usepackage</span><span class="hl opt">{</span>hyperref<span class="hl opt">}</span>
<span class="hl kwa">\usepackage</span><span class="hl opt">{</span>makeidx<span class="hl opt">}</span>
<span class="hl kwa">\usepackage</span><span class="hl opt">{</span>amssymb<span class="hl opt">}</span>
<span class="hl kwa">\usepackage</span><span class="hl opt">{</span><span class="hl kwb">color</span><span class="hl opt">}</span>
<span class="hl kwa">\usepackage</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\usepackage</span><span class="hl opt">{</span><span class="hl kwb">graphicx</span><span class="hl opt">}</span>
<span class="hl kwa">\usepackage</span><span class="hl opt">{</span>layout<span class="hl opt">}</span>
<span class="hl kwa">\def\union</span><span class="hl opt">{</span><span class="hl kwa">\cup</span><span class="hl opt">}</span>
<span class="hl kwa">\def\intersect</span><span class="hl opt">{</span><span class="hl kwa">\cap</span><span class="hl opt">}</span>
<span class="hl kwa">\def\getsrandom</span><span class="hl opt">{</span><span class="hl kwa">\stackrel</span><span class="hl opt">{</span><span class="hl kwa">\rm</span> R<span class="hl opt">}{</span><span class="hl kwa">\gets</span><span class="hl opt">}}</span>
<span class="hl kwa">\def\cross</span><span class="hl opt">{</span><span class="hl kwa">\times</span><span class="hl opt">}</span>
<span class="hl kwa">\def\cat</span><span class="hl opt">{</span><span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">0.5</span>em<span class="hl opt">}</span> \| <span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">0.5</span>em<span class="hl opt">}}</span>
<span class="hl kwa">\def\catn</span><span class="hl opt">{</span>$\|$<span class="hl opt">}</span>
<span class="hl kwa">\def\divides</span><span class="hl opt">{</span><span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">0.3</span>em<span class="hl opt">}</span> | <span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">0.3</span>em<span class="hl opt">}}</span>
<span class="hl kwa">\def\nequiv</span><span class="hl opt">{</span><span class="hl kwa">\not\equiv</span><span class="hl opt">}</span>
<span class="hl kwa">\def\approx</span><span class="hl opt">{</span><span class="hl kwa">\raisebox</span><span class="hl opt">{</span><span class="hl num">0.2</span>ex<span class="hl opt">}{</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span><span class="hl kwa">\small</span> $<span class="hl kwa">\sim</span>$<span class="hl opt">}}}</span>
<span class="hl kwa">\def\lcm</span><span class="hl opt">{{</span><span class="hl kwa">\rm</span> lcm<span class="hl opt">}}</span>
<span class="hl kwa">\def\gcd</span><span class="hl opt">{{</span><span class="hl kwa">\rm</span> gcd<span class="hl opt">}}</span>
<span class="hl kwa">\def\log</span><span class="hl opt">{{</span><span class="hl kwa">\rm</span> log<span class="hl opt">}}</span>
<span class="hl kwa">\def\ord</span><span class="hl opt">{{</span><span class="hl kwa">\rm</span> ord<span class="hl opt">}}</span>
<span class="hl kwa">\def\abs</span><span class="hl opt">{{</span><span class="hl kwa">\mathit</span> abs<span class="hl opt">}}</span>
<span class="hl kwa">\def\rep</span><span class="hl opt">{{</span><span class="hl kwa">\mathit</span> rep<span class="hl opt">}}</span>
<span class="hl kwa">\def\mod</span><span class="hl opt">{{</span><span class="hl kwa">\mathit</span>\ mod\ <span class="hl opt">}}</span>
<span class="hl kwa">\renewcommand</span><span class="hl opt">{</span><span class="hl kwa">\pmod</span><span class="hl opt">}[</span><span class="hl num">1</span><span class="hl opt">]{</span>\ (<span class="hl opt">{</span><span class="hl kwa">\rm</span> mod\ <span class="hl opt">}{</span><span class="hl kwc">#1</span><span class="hl opt">}</span>)<span class="hl opt">}</span>
<span class="hl kwa">\newcommand</span><span class="hl opt">{</span><span class="hl kwa">\floor</span><span class="hl opt">}[</span><span class="hl num">1</span><span class="hl opt">]{</span><span class="hl kwa">\left\lfloor</span><span class="hl opt">{</span><span class="hl kwc">#1</span><span class="hl opt">}</span><span class="hl kwa">\right\rfloor</span><span class="hl opt">}</span>
<span class="hl kwa">\newcommand</span><span class="hl opt">{</span><span class="hl kwa">\ceil</span><span class="hl opt">}[</span><span class="hl num">1</span><span class="hl opt">]{</span><span class="hl kwa">\left\lceil</span><span class="hl opt">{</span><span class="hl kwc">#1</span><span class="hl opt">}</span><span class="hl kwa">\right\rceil</span><span class="hl opt">}</span>
<span class="hl kwa">\def\Or</span><span class="hl opt">{{</span><span class="hl kwa">\rm</span>\ or\ <span class="hl opt">}}</span>
<span class="hl kwa">\def\And</span><span class="hl opt">{{</span><span class="hl kwa">\rm</span>\ and\ <span class="hl opt">}}</span>
<span class="hl kwa">\def\iff</span><span class="hl opt">{</span><span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">1</span>em<span class="hl opt">}</span><span class="hl kwa">\Longleftrightarrow\hspace</span><span class="hl opt">{</span><span class="hl num">1</span>em<span class="hl opt">}}</span>
<span class="hl kwa">\def\implies</span><span class="hl opt">{</span><span class="hl kwa">\Rightarrow</span><span class="hl opt">}</span>
<span class="hl kwa">\def\undefined</span><span class="hl opt">{{</span><span class="hl kwa">\rm</span> ``undefined&quot;<span class="hl opt">}}</span>
<span class="hl kwa">\def\Proof</span><span class="hl opt">{</span><span class="hl kwa">\vspace</span><span class="hl opt">{</span><span class="hl num">1</span>ex<span class="hl opt">}</span><span class="hl kwa">\noindent</span> <span class="hl opt">{</span><span class="hl kwa">\bf</span> Proof:<span class="hl opt">}</span><span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">1</span>em<span class="hl opt">}}</span>
<span class="hl kwa">\let\oldphi\phi</span>
<span class="hl kwa">\def\phi</span><span class="hl opt">{</span><span class="hl kwa">\varphi</span><span class="hl opt">}</span>
<span class="hl kwa">\def\Pr</span><span class="hl opt">{{</span><span class="hl kwa">\rm</span> Pr<span class="hl opt">}}</span>
<span class="hl kwa">\newcommand</span><span class="hl opt">{</span><span class="hl kwa">\str</span><span class="hl opt">}[</span><span class="hl num">1</span><span class="hl opt">]{{</span><span class="hl kwa">\mathbf</span><span class="hl opt">{</span><span class="hl kwc">#1</span><span class="hl opt">}}}</span>
<span class="hl kwa">\def\F</span><span class="hl opt">{{</span><span class="hl kwa">\mathbb</span> F<span class="hl opt">}}</span>
<span class="hl kwa">\def\N</span><span class="hl opt">{{</span><span class="hl kwa">\mathbb</span> N<span class="hl opt">}}</span>
<span class="hl kwa">\def\Z</span><span class="hl opt">{{</span><span class="hl kwa">\mathbb</span> Z<span class="hl opt">}}</span>
<span class="hl kwa">\def\R</span><span class="hl opt">{{</span><span class="hl kwa">\mathbb</span> R<span class="hl opt">}}</span>
<span class="hl kwa">\def\C</span><span class="hl opt">{{</span><span class="hl kwa">\mathbb</span> C<span class="hl opt">}}</span>
<span class="hl kwa">\def\Q</span><span class="hl opt">{{</span><span class="hl kwa">\mathbb</span> Q<span class="hl opt">}}</span>
<span class="hl kwa">\definecolor</span><span class="hl opt">{</span>DGray<span class="hl opt">}{</span>gray<span class="hl opt">}{</span><span class="hl num">0.5</span><span class="hl opt">}</span>
<span class="hl kwa">\newcommand</span><span class="hl opt">{</span><span class="hl kwa">\emailaddr</span><span class="hl opt">}[</span><span class="hl num">1</span><span class="hl opt">]{</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>$&lt;$<span class="hl opt">{</span><span class="hl kwc">#1</span><span class="hl opt">}</span>$&gt;$<span class="hl opt">}}</span>
<span class="hl kwa">\def\twiddle</span><span class="hl opt">{</span><span class="hl kwa">\raisebox</span><span class="hl opt">{</span><span class="hl num">0.3</span>ex<span class="hl opt">}{</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span><span class="hl kwa">\tiny</span> $<span class="hl kwa">\sim</span>$<span class="hl opt">}}}</span>
<span class="hl kwa">\def\gap</span><span class="hl opt">{</span><span class="hl kwa">\vspace</span><span class="hl opt">{</span><span class="hl num">0.5</span>ex<span class="hl opt">}}</span>
<span class="hl kwa">\makeindex</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">document</span><span class="hl opt">}</span>
<span class="hl kwa">\frontmatter</span>
<span class="hl kwa">\pagestyle</span><span class="hl opt">{</span>empty<span class="hl opt">}</span>
<span class="hl kwa">\title</span><span class="hl opt">{</span>Multi--Precision Math<span class="hl opt">}</span>
<span class="hl kwa">\author</span><span class="hl opt">{</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>
<span class="hl slc">%\begin{small}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>c<span class="hl opt">}</span>
Tom St Denis \\
Algonquin College \\
\\
Mads Rasmussen \\
Open Communications Security \\
\\
Greg Rose \\
QUALCOMM Australia \\
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl slc">%\end{small}</span>
<span class="hl opt">}</span>
<span class="hl opt">}</span>
<span class="hl kwa">\maketitle</span>
This text has been placed in the public domain.  This text corresponds to the v0.39 release of the 
LibTomMath project.

<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
Tom St Denis
<span class="hl num">111</span> Banning Rd
Ottawa, Ontario
K2L <span class="hl num">1</span>C3
Canada

Phone: <span class="hl num">1</span>-<span class="hl num">613</span>-<span class="hl num">836</span>-<span class="hl num">3160</span>
Email: tomstdenis&#64;gmail.com
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>

This text is formatted to the international B5 paper size of <span class="hl num">176</span>mm wide by <span class="hl num">250</span>mm tall using the <span class="hl kwa">\LaTeX</span><span class="hl opt">{}</span> 
<span class="hl opt">{</span><span class="hl kwa">\em</span> book<span class="hl opt">}</span> macro package and the Perl <span class="hl opt">{</span><span class="hl kwa">\em</span> booker<span class="hl opt">}</span> package.

<span class="hl kwa">\tableofcontents</span>
<span class="hl kwa">\listoffigures</span>
<span class="hl kwa">\chapter</span>*<span class="hl opt">{</span>Prefaces<span class="hl opt">}</span>
When I tell people about my LibTom projects and that I release them as public domain they are often puzzled.  
They ask why I did it and especially why I continue to work on them for free.  The best I can explain it is ``Because I can.''  
Which seems odd and perhaps too terse for adult conversation. I often qualify it with ``I am able, I am willing.'' which 
perhaps explains it better.  I am the first to admit there is not anything that special with what I have done.  Perhaps
others can see that too and then we would have a society to be proud of.  My LibTom projects are what I am doing to give 
back to society in the form of tools and knowledge that can help others in their endeavours.

I started writing this book because it was the most logical task to further my goal of open academia.  The LibTomMath source
code itself was written to be easy to follow and learn from.  There are times, however, where pure C source code does not
explain the algorithms properly.  Hence this book.  The book literally starts with the foundation of the library and works
itself outwards to the more complicated algorithms.  The use of both pseudo--code and verbatim source code provides a duality
of ``theory'' and ``practice'' that the computer science students of the world shall appreciate.  I never deviate too far
from relatively straightforward algebra and I hope that this book can be a valuable learning asset.

This book and indeed much of the LibTom projects would not exist in their current form if it was not for a plethora
of kind people donating their time, resources and kind words to help support my work.  Writing a text of significant
length (along with the source code) is a tiresome and lengthy process.  Currently the LibTom project is four years old,
comprises of literally thousands of users and over <span class="hl num">100</span>,<span class="hl num">000</span> lines of source code, TeX and other material.  People like Mads and Greg 
were there at the beginning to encourage me to work well.  It is amazing how timely validation from others can boost morale to 
continue the project. Definitely my parents were there for me by providing room and board during the many months of work in <span class="hl num">2003</span>.  

To my many friends whom I have met through the years I thank you for the good times and the words of encouragement.  I hope I
honour your kind gestures with this project.

Open Source.  Open Academia.  Open Minds.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>flushright<span class="hl opt">}</span> Tom St Denis <span class="hl kwa">\end</span><span class="hl opt">{</span>flushright<span class="hl opt">}</span>

<span class="hl kwa">\newpage</span>
I found the opportunity to work with Tom appealing for several reasons, not only could I broaden my own horizons, but also 
contribute to educate others facing the problem of having to handle big number mathematical calculations.

This book is Tom's child and he has been caring and fostering the project ever since the beginning with a clear mind of 
how he wanted the project to turn out. I have helped by proofreading the text and we have had several discussions about 
the layout and language used.

I hold a masters degree in cryptography from the University of Southern Denmark and have always been interested in the 
practical aspects of cryptography. 

Having worked in the security consultancy business for several years in S\~<span class="hl opt">{</span>a<span class="hl opt">}</span>o Paulo, Brazil, I have been in touch with a 
great deal of work in which multiple precision mathematics was needed. Understanding the possibilities for speeding up 
multiple precision calculations is often very important since we deal with outdated machine architecture where modular 
reductions, for example, become painfully slow.

This text is for people who stop and wonder when first examining algorithms such as RSA for the first time and asks 
themselves, ``You tell me this is only secure for large numbers, fine; but how do you implement these numbers?''

<span class="hl kwa">\begin</span><span class="hl opt">{</span>flushright<span class="hl opt">}</span>
Mads Rasmussen

S\~<span class="hl opt">{</span>a<span class="hl opt">}</span>o Paulo - SP

Brazil
<span class="hl kwa">\end</span><span class="hl opt">{</span>flushright<span class="hl opt">}</span>

<span class="hl kwa">\newpage</span>
It's all because I broke my leg. That just happened to be at about the same time that Tom asked for someone to review the section of the book about 
Karatsuba multiplication. I was laid up, alone and immobile, and thought ``Why not?'' I vaguely knew what Karatsuba multiplication was, but not 
really, so I thought I could help, learn, and stop myself from watching daytime cable TV, all at once.

At the time of writing this, I've still not met Tom or Mads in meatspace. I've been following Tom's progress since his first splash on the 
sci.crypt Usenet news group. I watched him go from a clueless newbie, to the cryptographic equivalent of a reformed smoker, to a real
contributor to the field, over a period of about two years. I've been impressed with his obvious intelligence, and astounded by his productivity. 
Of course, he's young enough to be my own child, so he doesn't have my problems with staying awake.

When I reviewed that single section of the book, in its very earliest form, I was very pleasantly surprised. So I decided to collaborate more fully, 
and at least review all of it, and perhaps write some bits too. There's still a long way to go with it, and I have watched a number of close 
friends go through the mill of publication, so I think that the way to go is longer than Tom thinks it is. Nevertheless, it's a good effort, 
and I'm pleased to be involved with it.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>flushright<span class="hl opt">}</span>
Greg Rose, Sydney, Australia, June <span class="hl num">2003</span>. 
<span class="hl kwa">\end</span><span class="hl opt">{</span>flushright<span class="hl opt">}</span>

<span class="hl kwa">\mainmatter</span>
<span class="hl kwa">\pagestyle</span><span class="hl opt">{</span>headings<span class="hl opt">}</span>
<span class="hl kwa">\chapter</span><span class="hl opt">{</span>Introduction<span class="hl opt">}</span>
<span class="hl kwa">\section</span><span class="hl opt">{</span>Multiple Precision Arithmetic<span class="hl opt">}</span>

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>What is Multiple Precision Arithmetic?<span class="hl opt">}</span>
When we think of long-hand arithmetic such as addition or multiplication we rarely consider the fact that we instinctively
raise or lower the precision of the numbers we are dealing with.  For example, in decimal we almost immediate can 
reason that $<span class="hl num">7</span>$ times $<span class="hl num">6</span>$ is $<span class="hl num">42</span>$.  However, $<span class="hl num">42</span>$ has two digits of precision as opposed to one digit we started with.  
Further multiplications of say $<span class="hl num">3</span>$ result in a larger precision result $<span class="hl num">126</span>$.  In these few examples we have multiple 
precisions for the numbers we are working with.  Despite the various levels of precision a single subset<span class="hl kwa">\footnote</span><span class="hl opt">{</span>With the occasional optimization.<span class="hl opt">}</span>
 of algorithms can be designed to accomodate them.  

By way of comparison a fixed or single precision operation would lose precision on various operations.  For example, in
the decimal system with fixed precision $<span class="hl num">6</span> <span class="hl kwa">\cdot</span> <span class="hl num">7</span> = <span class="hl num">2</span>$.

Essentially at the heart of computer based multiple precision arithmetic are the same long-hand algorithms taught in
schools to manually add, subtract, multiply and divide.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>The Need for Multiple Precision Arithmetic<span class="hl opt">}</span>
The most prevalent need for multiple precision arithmetic, often referred to as ``bignum'' math, is within the implementation
of public-key cryptography algorithms.   Algorithms such as RSA <span class="hl kwa">\cite</span><span class="hl opt">{</span>RSAREF<span class="hl opt">}</span> and Diffie-Hellman <span class="hl kwa">\cite</span><span class="hl opt">{</span>DHREF<span class="hl opt">}</span> require 
integers of significant magnitude to resist known cryptanalytic attacks.  For example, at the time of this writing a 
typical RSA modulus would be at least greater than $<span class="hl num">10</span>^<span class="hl opt">{</span><span class="hl num">309</span><span class="hl opt">}</span>$.  However, modern programming languages such as ISO C <span class="hl kwa">\cite</span><span class="hl opt">{</span>ISOC<span class="hl opt">}</span> and 
Java <span class="hl kwa">\cite</span><span class="hl opt">{</span>JAVA<span class="hl opt">}</span> only provide instrinsic support for integers which are relatively small and single precision.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>|r|c|<span class="hl opt">}</span>
<span class="hl kwa">\hline \textbf</span><span class="hl opt">{</span>Data Type<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Range<span class="hl opt">}</span> \\
<span class="hl kwa">\hline</span> char  &amp; $-<span class="hl num">128</span> <span class="hl kwa">\ldots</span> <span class="hl num">127</span>$ \\
<span class="hl kwa">\hline</span> short &amp; $-<span class="hl num">32768</span> <span class="hl kwa">\ldots</span> <span class="hl num">32767</span>$ \\
<span class="hl kwa">\hline</span> long  &amp; $-<span class="hl num">2147483648</span> <span class="hl kwa">\ldots</span> <span class="hl num">2147483647</span>$ \\
<span class="hl kwa">\hline</span> long long &amp; $-<span class="hl num">9223372036854775808</span> <span class="hl kwa">\ldots</span> <span class="hl num">9223372036854775807</span>$ \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Typical Data Types for the C Programming Language<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>fig:ISOC<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

The largest data type guaranteed to be provided by the ISO C programming 
language<span class="hl kwa">\footnote</span><span class="hl opt">{</span>As per the ISO C standard.  However, each compiler vendor is allowed to augment the precision as they 
see fit.<span class="hl opt">}</span>  can only represent values up to $<span class="hl num">10</span>^<span class="hl opt">{</span><span class="hl num">19</span><span class="hl opt">}</span>$ as shown in figure <span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:ISOC<span class="hl opt">}</span>. On its own the C language is 
insufficient to accomodate the magnitude required for the problem at hand.  An RSA modulus of magnitude $<span class="hl num">10</span>^<span class="hl opt">{</span><span class="hl num">19</span><span class="hl opt">}</span>$ could be 
trivially factored<span class="hl kwa">\footnote</span><span class="hl opt">{</span>A Pollard-Rho factoring would take only $<span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">16</span><span class="hl opt">}</span>$ time.<span class="hl opt">}</span> on the average desktop computer, 
rendering any protocol based on the algorithm insecure.  Multiple precision algorithms solve this very problem by 
extending the range of representable integers while using single precision data types.

Most advancements in fast multiple precision arithmetic stem from the need for faster and more efficient cryptographic 
primitives.  Faster modular reduction and exponentiation algorithms such as Barrett's algorithm, which have appeared in 
various cryptographic journals, can render algorithms such as RSA and Diffie-Hellman more efficient.  In fact, several 
major companies such as RSA Security, Certicom and Entrust have built entire product lines on the implementation and 
deployment of efficient algorithms.

However, cryptography is not the only field of study that can benefit from fast multiple precision integer routines.  
Another auxiliary use of multiple precision integers is high precision floating point data types.  
The basic IEEE <span class="hl kwa">\cite</span><span class="hl opt">{</span>IEEE<span class="hl opt">}</span> standard floating point type is made up of an integer mantissa $q$, an exponent $e$ and a sign bit $s$.  
Numbers are given in the form $n = q <span class="hl kwa">\cdot</span> b^e <span class="hl kwa">\cdot</span> -<span class="hl num">1</span>^s$ where $b = <span class="hl num">2</span>$ is the most common base for IEEE.  Since IEEE 
floating point is meant to be implemented in hardware the precision of the mantissa is often fairly small 
(<span class="hl kwa">\textit</span><span class="hl opt">{</span><span class="hl num">23</span>, <span class="hl num">48</span> and <span class="hl num">64</span> bits<span class="hl opt">}</span>).  The mantissa is merely an integer and a multiple precision integer could be used to create
a mantissa of much larger precision than hardware alone can efficiently support.  This approach could be useful where 
scientific applications must minimize the total output error over long calculations.

Yet another use for large integers is within arithmetic on polynomials of large characteristic (i.e. $GF(p)<span class="hl opt">[</span>x<span class="hl opt">]</span>$ for large $p$).
In fact the library discussed within this text has already been used to form a polynomial basis library<span class="hl kwa">\footnote</span><span class="hl opt">{</span>See <span class="hl kwa">\url</span><span class="hl opt">{</span>http://poly.libtomcrypt.org<span class="hl opt">}</span> for more details.<span class="hl opt">}</span>.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Benefits of Multiple Precision Arithmetic<span class="hl opt">}</span>
<span class="hl kwa">\index</span><span class="hl opt">{</span>precision<span class="hl opt">}</span>
The benefit of multiple precision representations over single or fixed precision representations is that 
no precision is lost while representing the result of an operation which requires excess precision.  For example, 
the product of two $n$-bit integers requires at least $<span class="hl num">2</span>n$ bits of precision to be represented faithfully.  A multiple 
precision algorithm would augment the precision of the destination to accomodate the result while a single precision system 
would truncate excess bits to maintain a fixed level of precision.

It is possible to implement algorithms which require large integers with fixed precision algorithms.  For example, elliptic
curve cryptography (<span class="hl kwa">\textit</span><span class="hl opt">{</span>ECC<span class="hl opt">}</span>) is often implemented on smartcards by fixing the precision of the integers to the maximum 
size the system will ever need.  Such an approach can lead to vastly simpler algorithms which can accomodate the 
integers required even if the host platform cannot natively accomodate them<span class="hl kwa">\footnote</span><span class="hl opt">{</span>For example, the average smartcard 
processor has an <span class="hl num">8</span> bit accumulator.<span class="hl opt">}</span>.  However, as efficient as such an approach may be, the resulting source code is not
normally very flexible.  It cannot, at runtime, accomodate inputs of higher magnitude than the designer anticipated.

Multiple precision algorithms have the most overhead of any style of arithmetic.  For the the most part the 
overhead can be kept to a minimum with careful planning, but overall, it is not well suited for most memory starved
platforms.  However, multiple precision algorithms do offer the most flexibility in terms of the magnitude of the 
inputs.  That is, the same algorithms based on multiple precision integers can accomodate any reasonable size input 
without the designer's explicit forethought.  This leads to lower cost of ownership for the code as it only has to 
be written and tested once.

<span class="hl kwa">\section</span><span class="hl opt">{</span>Purpose of This Text<span class="hl opt">}</span>
The purpose of this text is to instruct the reader regarding how to implement efficient multiple precision algorithms.  
That is to not only explain a limited subset of the core theory behind the algorithms but also the various ``house keeping'' 
elements that are neglected by authors of other texts on the subject.  Several well reknowned texts <span class="hl kwa">\cite</span><span class="hl opt">{</span>TAOCPV2,HAC<span class="hl opt">}</span> 
give considerably detailed explanations of the theoretical aspects of algorithms and often very little information 
regarding the practical implementation aspects.  

In most cases how an algorithm is explained and how it is actually implemented are two very different concepts.  For 
example, the Handbook of Applied Cryptography (<span class="hl kwa">\textit</span><span class="hl opt">{</span>HAC<span class="hl opt">}</span>), algorithm <span class="hl num">14.7</span> on page <span class="hl num">594</span>, gives a relatively simple 
algorithm for performing multiple precision integer addition.  However, the description lacks any discussion concerning 
the fact that the two integer inputs may be of differing magnitudes.  As a result the implementation is not as simple
as the text would lead people to believe.  Similarly the division routine (<span class="hl kwa">\textit</span><span class="hl opt">{</span>algorithm <span class="hl num">14.20</span>, pp. <span class="hl num">598</span><span class="hl opt">}</span>) does not 
discuss how to handle sign or handle the dividend's decreasing magnitude in the main loop (<span class="hl kwa">\textit</span><span class="hl opt">{</span>step \<span class="hl kwc">#3</span><span class="hl opt">}</span>).

Both texts also do not discuss several key optimal algorithms required such as ``Comba'' and Karatsuba multipliers 
and fast modular inversion, which we consider practical oversights.  These optimal algorithms are vital to achieve 
any form of useful performance in non-trivial applications.  

To solve this problem the focus of this text is on the practical aspects of implementing a multiple precision integer
package.  As a case study the ``LibTomMath''<span class="hl kwa">\footnote</span><span class="hl opt">{</span>Available at <span class="hl kwa">\url</span><span class="hl opt">{</span>http://math.libtomcrypt.com<span class="hl opt">}}</span> package is used 
to demonstrate algorithms with real implementations<span class="hl kwa">\footnote</span><span class="hl opt">{</span>In the ISO C programming language.<span class="hl opt">}</span> that have been field 
tested and work very well.  The LibTomMath library is freely available on the Internet for all uses and this text 
discusses a very large portion of the inner workings of the library.

The algorithms that are presented will always include at least one ``pseudo-code'' description followed 
by the actual C source code that implements the algorithm.  The pseudo-code can be used to implement the same 
algorithm in other programming languages as the reader sees fit.  

This text shall also serve as a walkthrough of the creation of multiple precision algorithms from scratch.  Showing
the reader how the algorithms fit together as well as where to start on various taskings.  

<span class="hl kwa">\section</span><span class="hl opt">{</span>Discussion and Notation<span class="hl opt">}</span>
<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Notation<span class="hl opt">}</span>
A multiple precision integer of $n$-digits shall be denoted as $x = (x_<span class="hl opt">{</span>n-<span class="hl num">1</span><span class="hl opt">}</span>, <span class="hl kwa">\ldots</span>, x_1, x_0)_<span class="hl opt">{</span> <span class="hl kwa">\beta</span> <span class="hl opt">}</span>$ and represent
the integer $x <span class="hl kwa">\equiv \sum_</span><span class="hl opt">{</span>i=<span class="hl num">0</span><span class="hl opt">}</span>^<span class="hl opt">{</span>n-<span class="hl num">1</span><span class="hl opt">}</span> x_i<span class="hl kwa">\beta</span>^i$.  The elements of the array $x$ are said to be the radix $<span class="hl kwa">\beta</span>$ digits 
of the integer.  For example, $x = (<span class="hl num">1</span>,<span class="hl num">2</span>,<span class="hl num">3</span>)_<span class="hl opt">{</span><span class="hl num">10</span><span class="hl opt">}</span>$ would represent the integer 
$<span class="hl num">1</span><span class="hl kwa">\cdot</span> <span class="hl num">10</span>^<span class="hl num">2</span> + <span class="hl num">2</span><span class="hl kwa">\cdot10</span>^<span class="hl num">1</span> + <span class="hl num">3</span><span class="hl kwa">\cdot10</span>^<span class="hl num">0</span> = <span class="hl num">123</span>$.  

<span class="hl kwa">\index</span><span class="hl opt">{</span>mp<span class="hl kwa">\_int</span><span class="hl opt">}</span>
The term ``mp<span class="hl kwa">\_int</span>'' shall refer to a composite structure which contains the digits of the integer it represents, as well 
as auxilary data required to manipulate the data.  These additional members are discussed further in section 
<span class="hl kwa">\ref</span><span class="hl opt">{</span>sec:MPINT<span class="hl opt">}</span>.  For the purposes of this text a ``multiple precision integer'' and an ``mp<span class="hl kwa">\_int</span>'' are assumed to be 
synonymous.  When an algorithm is specified to accept an mp<span class="hl kwa">\_int</span> variable it is assumed the various auxliary data members 
are present as well.  An expression of the type <span class="hl kwa">\textit</span><span class="hl opt">{</span>variablename.item<span class="hl opt">}</span> implies that it should evaluate to the 
member named ``item'' of the variable.  For example, a string of characters may have a member ``length'' which would 
evaluate to the number of characters in the string.  If the string $a$ equals ``hello'' then it follows that 
$a.length = <span class="hl num">5</span>$.  

For certain discussions more generic algorithms are presented to help the reader understand the final algorithm used
to solve a given problem.  When an algorithm is described as accepting an integer input it is assumed the input is 
a plain integer with no additional multiple-precision members.  That is, algorithms that use integers as opposed to 
mp<span class="hl kwa">\_ints</span> as inputs do not concern themselves with the housekeeping operations required such as memory management.  These 
algorithms will be used to establish the relevant theory which will subsequently be used to describe a multiple
precision algorithm to solve the same problem.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Precision Notation<span class="hl opt">}</span>
The variable $<span class="hl kwa">\beta</span>$ represents the radix of a single digit of a multiple precision integer and 
must be of the form $q^p$ for $q, p <span class="hl kwa">\in \Z</span>^+$.  A single precision variable must be able to represent integers in 
the range $<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; q <span class="hl kwa">\beta</span>$ while a double precision variable must be able to represent integers in the range 
$<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; q <span class="hl kwa">\beta</span>^<span class="hl num">2</span>$.  The extra radix-$q$ factor allows additions and subtractions to proceed without truncation of the 
carry.  Since all modern computers are binary, it is assumed that $q$ is two.

<span class="hl kwa">\index</span><span class="hl opt">{</span>mp<span class="hl kwa">\_digit</span><span class="hl opt">}</span> <span class="hl kwa">\index</span><span class="hl opt">{</span>mp<span class="hl kwa">\_word</span><span class="hl opt">}</span>
Within the source code that will be presented for each algorithm, the data type <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_digit</span><span class="hl opt">}</span> will represent 
a single precision integer type, while, the data type <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_word</span><span class="hl opt">}</span> will represent a double precision integer type.  In 
several algorithms (notably the Comba routines) temporary results will be stored in arrays of double precision mp<span class="hl kwa">\_words</span>.  
For the purposes of this text $x_j$ will refer to the $j$'th digit of a single precision array and $<span class="hl kwa">\hat</span> x_j$ will refer to 
the $j$'th digit of a double precision array.  Whenever an expression is to be assigned to a double precision
variable it is assumed that all single precision variables are promoted to double precision during the evaluation.  
Expressions that are assigned to a single precision variable are truncated to fit within the precision of a single
precision data type.

For example, if $<span class="hl kwa">\beta</span> = <span class="hl num">10</span>^<span class="hl num">2</span>$ a single precision data type may represent a value in the 
range $<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; <span class="hl num">10</span>^<span class="hl num">3</span>$, while a double precision data type may represent a value in the range $<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; <span class="hl num">10</span>^<span class="hl num">5</span>$.  Let
$a = <span class="hl num">23</span>$ and $b = <span class="hl num">49</span>$ represent two single precision variables.  The single precision product shall be written
as $c <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\cdot</span> b$ while the double precision product shall be written as $<span class="hl kwa">\hat</span> c <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\cdot</span> b$.
In this particular case, $<span class="hl kwa">\hat</span> c = <span class="hl num">1127</span>$ and $c = <span class="hl num">127</span>$.  The most significant digit of the product would not fit 
in a single precision data type and as a result $c <span class="hl kwa">\ne \hat</span> c$.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Algorithm Inputs and Outputs<span class="hl opt">}</span>
Within the algorithm descriptions all variables are assumed to be scalars of either single or double precision
as indicated.  The only exception to this rule is when variables have been indicated to be of type mp<span class="hl kwa">\_int</span>.  This 
distinction is important as scalars are often used as array indicies and various other counters.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Mathematical Expressions<span class="hl opt">}</span>
The $<span class="hl kwa">\lfloor \mbox</span><span class="hl opt">{ }</span> <span class="hl kwa">\rfloor</span>$ brackets imply an expression truncated to an integer not greater than the expression 
itself.  For example, $<span class="hl kwa">\lfloor</span> <span class="hl num">5.7</span> <span class="hl kwa">\rfloor</span> = <span class="hl num">5</span>$.  Similarly the $<span class="hl kwa">\lceil \mbox</span><span class="hl opt">{ }</span> <span class="hl kwa">\rceil</span>$ brackets imply an expression
rounded to an integer not less than the expression itself.  For example, $<span class="hl kwa">\lceil</span> <span class="hl num">5.1</span> <span class="hl kwa">\rceil</span> = <span class="hl num">6</span>$.  Typically when 
the $/$ division symbol is used the intention is to perform an integer division with truncation.  For example, 
$<span class="hl num">5</span>/<span class="hl num">2</span> = <span class="hl num">2</span>$ which will often be written as $<span class="hl kwa">\lfloor</span> <span class="hl num">5</span>/<span class="hl num">2</span> <span class="hl kwa">\rfloor</span> = <span class="hl num">2</span>$ for clarity.  When an expression is written as a 
fraction a real value division is implied, for example $<span class="hl opt">{</span><span class="hl num">5</span> <span class="hl kwa">\over</span> <span class="hl num">2</span><span class="hl opt">}</span> = <span class="hl num">2.5</span>$.  

The norm of a multiple precision integer, for example $<span class="hl kwa">\vert \vert</span> x <span class="hl kwa">\vert \vert</span>$, will be used to represent the number of digits in the representation
of the integer.  For example, $<span class="hl kwa">\vert \vert</span> <span class="hl num">123</span> <span class="hl kwa">\vert \vert</span> = <span class="hl num">3</span>$ and $<span class="hl kwa">\vert \vert</span> <span class="hl num">79452</span> <span class="hl kwa">\vert \vert</span> = <span class="hl num">5</span>$.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Work Effort<span class="hl opt">}</span>
<span class="hl kwa">\index</span><span class="hl opt">{</span>big-Oh<span class="hl opt">}</span>
To measure the efficiency of the specified algorithms, a modified big-Oh notation is used.  In this system all 
single precision operations are considered to have the same cost<span class="hl kwa">\footnote</span><span class="hl opt">{</span>Except where explicitly noted.<span class="hl opt">}</span>.  
That is a single precision addition, multiplication and division are assumed to take the same time to 
complete.  While this is generally not true in practice, it will simplify the discussions considerably.

Some algorithms have slight advantages over others which is why some constants will not be removed in 
the notation.  For example, a normal baseline multiplication (section <span class="hl kwa">\ref</span><span class="hl opt">{</span>sec:basemult<span class="hl opt">}</span>) requires $O(n^<span class="hl num">2</span>)$ work while a 
baseline squaring (section <span class="hl kwa">\ref</span><span class="hl opt">{</span>sec:basesquare<span class="hl opt">}</span>) requires $O(<span class="hl opt">{{</span>n^<span class="hl num">2</span> + n<span class="hl opt">}</span><span class="hl kwa">\over</span> <span class="hl num">2</span><span class="hl opt">}</span>)$ work.  In standard big-Oh notation these 
would both be said to be equivalent to $O(n^<span class="hl num">2</span>)$.  However, 
in the context of the this text this is not the case as the magnitude of the inputs will typically be rather small.  As a 
result small constant factors in the work effort will make an observable difference in algorithm efficiency.

All of the algorithms presented in this text have a polynomial time work level.  That is, of the form 
$O(n^k)$ for $n, k <span class="hl kwa">\in \Z</span>^<span class="hl opt">{</span>+<span class="hl opt">}</span>$.  This will help make useful comparisons in terms of the speed of the algorithms and how 
various optimizations will help pay off in the long run.

<span class="hl kwa">\section</span><span class="hl opt">{</span>Exercises<span class="hl opt">}</span>
Within the more advanced chapters a section will be set aside to give the reader some challenging exercises related to
the discussion at hand.  These exercises are not designed to be prize winning problems, but instead to be thought 
provoking.  Wherever possible the problems are forward minded, stating problems that will be answered in subsequent 
chapters.  The reader is encouraged to finish the exercises as they appear to get a better understanding of the 
subject material.  

That being said, the problems are designed to affirm knowledge of a particular subject matter.  Students in particular
are encouraged to verify they can answer the problems correctly before moving on.

Similar to the exercises of <span class="hl kwa">\cite</span><span class="hl opt">[</span>pp. ix<span class="hl opt">]{</span>TAOCPV2<span class="hl opt">}</span> these exercises are given a scoring system based on the difficulty of
the problem.  However, unlike <span class="hl kwa">\cite</span><span class="hl opt">{</span>TAOCPV2<span class="hl opt">}</span> the problems do not get nearly as hard.  The scoring of these 
exercises ranges from one (the easiest) to five (the hardest).  The following table sumarizes the 
scoring system used.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>|c|l|<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> $<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">1</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span>$ &amp; An easy problem that should only take the reader a manner of \\
                            &amp; minutes to solve.  Usually does not involve much computer time \\
                            &amp; to solve. \\
<span class="hl kwa">\hline</span> $<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">2</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span>$ &amp; An easy problem that involves a marginal amount of computer \\
                     &amp; time usage.  Usually requires a program to be written to \\
                     &amp; solve the problem. \\
<span class="hl kwa">\hline</span> $<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">3</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span>$ &amp; A moderately hard problem that requires a non-trivial amount \\
                     &amp; of work.  Usually involves trivial research and development of \\
                     &amp; new theory from the perspective of a student. \\
<span class="hl kwa">\hline</span> $<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">4</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span>$ &amp; A moderately hard problem that involves a non-trivial amount \\
                     &amp; of work and research, the solution to which will demonstrate \\
                     &amp; a higher mastery of the subject matter. \\
<span class="hl kwa">\hline</span> $<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">5</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span>$ &amp; A hard problem that involves concepts that are difficult for a \\
                     &amp; novice to solve.  Solutions to these problems will demonstrate a \\
                     &amp; complete mastery of the given subject. \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Exercise Scoring System<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

Problems at the first level are meant to be simple questions that the reader can answer quickly without programming a solution or
devising new theory.  These problems are quick tests to see if the material is understood.  Problems at the second level 
are also designed to be easy but will require a program or algorithm to be implemented to arrive at the answer.  These
two levels are essentially entry level questions.  

Problems at the third level are meant to be a bit more difficult than the first two levels.  The answer is often 
fairly obvious but arriving at an exacting solution requires some thought and skill.  These problems will almost always 
involve devising a new algorithm or implementing a variation of another algorithm previously presented.  Readers who can
answer these questions will feel comfortable with the concepts behind the topic at hand.

Problems at the fourth level are meant to be similar to those of the level three questions except they will require 
additional research to be completed.  The reader will most likely not know the answer right away, nor will the text provide 
the exact details of the answer until a subsequent chapter.  

Problems at the fifth level are meant to be the hardest 
problems relative to all the other problems in the chapter.  People who can correctly answer fifth level problems have a 
mastery of the subject matter at hand.

Often problems will be tied together.  The purpose of this is to start a chain of thought that will be discussed in future chapters.  The reader
is encouraged to answer the follow-up problems and try to draw the relevance of problems.

<span class="hl kwa">\section</span><span class="hl opt">{</span>Introduction to LibTomMath<span class="hl opt">}</span>

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>What is LibTomMath?<span class="hl opt">}</span>
LibTomMath is a free and open source multiple precision integer library written entirely in portable ISO C.  By portable it 
is meant that the library does not contain any code that is computer platform dependent or otherwise problematic to use on 
any given platform.  

The library has been successfully tested under numerous operating systems including Unix<span class="hl kwa">\footnote</span><span class="hl opt">{</span>All of these
trademarks belong to their respective rightful owners.<span class="hl opt">}</span>, MacOS, Windows, Linux, PalmOS and on standalone hardware such 
as the Gameboy Advance.  The library is designed to contain enough functionality to be able to develop applications such 
as public key cryptosystems and still maintain a relatively small footprint.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Goals of LibTomMath<span class="hl opt">}</span>

Libraries which obtain the most efficiency are rarely written in a high level programming language such as C.  However, 
even though this library is written entirely in ISO C, considerable care has been taken to optimize the algorithm implementations within the 
library.  Specifically the code has been written to work well with the GNU C Compiler (<span class="hl kwa">\textit</span><span class="hl opt">{</span>GCC<span class="hl opt">}</span>) on both x86 and ARM 
processors.  Wherever possible, highly efficient algorithms, such as Karatsuba multiplication, sliding window 
exponentiation and Montgomery reduction have been provided to make the library more efficient.  

Even with the nearly optimal and specialized algorithms that have been included the Application Programing Interface 
(<span class="hl kwa">\textit</span><span class="hl opt">{</span>API<span class="hl opt">}</span>) has been kept as simple as possible.  Often generic place holder routines will make use of specialized 
algorithms automatically without the developer's specific attention.  One such example is the generic multiplication 
algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_mul</span>()<span class="hl opt">}</span> which will automatically use Toom--Cook, Karatsuba, Comba or baseline multiplication 
based on the magnitude of the inputs and the configuration of the library.  

Making LibTomMath as efficient as possible is not the only goal of the LibTomMath project.  Ideally the library should 
be source compatible with another popular library which makes it more attractive for developers to use.  In this case the
MPI library was used as a API template for all the basic functions.  MPI was chosen because it is another library that fits 
in the same niche as LibTomMath.  Even though LibTomMath uses MPI as the template for the function names and argument 
passing conventions, it has been written from scratch by Tom St Denis.

The project is also meant to act as a learning tool for students, the logic being that no easy-to-follow ``bignum'' 
library exists which can be used to teach computer science students how to perform fast and reliable multiple precision 
integer arithmetic.  To this end the source code has been given quite a few comments and algorithm discussion points.  

<span class="hl kwa">\section</span><span class="hl opt">{</span>Choice of LibTomMath<span class="hl opt">}</span>
LibTomMath was chosen as the case study of this text not only because the author of both projects is one and the same but
for more worthy reasons.  Other libraries such as GMP <span class="hl kwa">\cite</span><span class="hl opt">{</span>GMP<span class="hl opt">}</span>, MPI <span class="hl kwa">\cite</span><span class="hl opt">{</span>MPI<span class="hl opt">}</span>, LIP <span class="hl kwa">\cite</span><span class="hl opt">{</span>LIP<span class="hl opt">}</span> and OpenSSL 
<span class="hl kwa">\cite</span><span class="hl opt">{</span>OPENSSL<span class="hl opt">}</span> have multiple precision integer arithmetic routines but would not be ideal for this text for 
reasons that will be explained in the following sub-sections.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Code Base<span class="hl opt">}</span>
The LibTomMath code base is all portable ISO C source code.  This means that there are no platform dependent conditional
segments of code littered throughout the source.  This clean and uncluttered approach to the library means that a
developer can more readily discern the true intent of a given section of source code without trying to keep track of
what conditional code will be used.

The code base of LibTomMath is well organized.  Each function is in its own separate source code file 
which allows the reader to find a given function very quickly.  On average there are $<span class="hl num">76</span>$ lines of code per source
file which makes the source very easily to follow.  By comparison MPI and LIP are single file projects making code tracing
very hard.  GMP has many conditional code segments which also hinder tracing.  

When compiled with GCC for the x86 processor and optimized for speed the entire library is approximately $<span class="hl num">100</span>$KiB<span class="hl kwa">\footnote</span><span class="hl opt">{</span>The notation ``KiB'' means $<span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">10</span><span class="hl opt">}</span>$ octets, similarly ``MiB'' means $<span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">20</span><span class="hl opt">}</span>$ octets.<span class="hl opt">}</span>
 which is fairly small compared to GMP (over $<span class="hl num">250</span>$KiB).  LibTomMath is slightly larger than MPI (which compiles to about 
$<span class="hl num">50</span>$KiB) but LibTomMath is also much faster and more complete than MPI.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>API Simplicity<span class="hl opt">}</span>
LibTomMath is designed after the MPI library and shares the API design.  Quite often programs that use MPI will build 
with LibTomMath without change. The function names correlate directly to the action they perform.  Almost all of the 
functions share the same parameter passing convention.  The learning curve is fairly shallow with the API provided 
which is an extremely valuable benefit for the student and developer alike.  

The LIP library is an example of a library with an API that is awkward to work with.  LIP uses function names that are often ``compressed'' to 
illegible short hand.  LibTomMath does not share this characteristic.  

The GMP library also does not return error codes.  Instead it uses a POSIX<span class="hl num">.1</span> <span class="hl kwa">\cite</span><span class="hl opt">{</span>POSIX1<span class="hl opt">}</span> signal system where errors
are signaled to the host application.  This happens to be the fastest approach but definitely not the most versatile.  In
effect a math error (i.e. invalid input, heap error, etc) can cause a program to stop functioning which is definitely 
undersireable in many situations.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Optimizations<span class="hl opt">}</span>
While LibTomMath is certainly not the fastest library (GMP often beats LibTomMath by a factor of two) it does
feature a set of optimal algorithms for tasks such as modular reduction, exponentiation, multiplication and squaring.  GMP 
and LIP also feature such optimizations while MPI only uses baseline algorithms with no optimizations.  GMP lacks a few
of the additional modular reduction optimizations that LibTomMath features<span class="hl kwa">\footnote</span><span class="hl opt">{</span>At the time of this writing GMP
only had Barrett and Montgomery modular reduction algorithms.<span class="hl opt">}</span>.  

LibTomMath is almost always an order of magnitude faster than the MPI library at computationally expensive tasks such as modular
exponentiation.  In the grand scheme of ``bignum'' libraries LibTomMath is faster than the average library and usually  
slower than the best libraries such as GMP and OpenSSL by only a small factor.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Portability and Stability<span class="hl opt">}</span>
LibTomMath will build ``out of the box'' on any platform equipped with a modern version of the GNU C Compiler 
(<span class="hl kwa">\textit</span><span class="hl opt">{</span>GCC<span class="hl opt">}</span>).  This means that without changes the library will build without configuration or setting up any 
variables.  LIP and MPI will build ``out of the box'' as well but have numerous known bugs.  Most notably the author of 
MPI has recently stopped working on his library and LIP has long since been discontinued.  

GMP requires a configuration script to run and will not build out of the box.   GMP and LibTomMath are still in active
development and are very stable across a variety of platforms.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Choice<span class="hl opt">}</span>
LibTomMath is a relatively compact, well documented, highly optimized and portable library which seems only natural for
the case study of this text.  Various source files from the LibTomMath project will be included within the text.  However, 
the reader is encouraged to download their own copy of the library to actually be able to work with the library.  

<span class="hl kwa">\chapter</span><span class="hl opt">{</span>Getting Started<span class="hl opt">}</span>
<span class="hl kwa">\section</span><span class="hl opt">{</span>Library Basics<span class="hl opt">}</span>
The trick to writing any useful library of source code is to build a solid foundation and work outwards from it.  First, 
a problem along with allowable solution parameters should be identified and analyzed.  In this particular case the 
inability to accomodate multiple precision integers is the problem.  Futhermore, the solution must be written
as portable source code that is reasonably efficient across several different computer platforms.

After a foundation is formed the remainder of the library can be designed and implemented in a hierarchical fashion.  
That is, to implement the lowest level dependencies first and work towards the most abstract functions last.  For example, 
before implementing a modular exponentiation algorithm one would implement a modular reduction algorithm.
By building outwards from a base foundation instead of using a parallel design methodology the resulting project is 
highly modular.  Being highly modular is a desirable property of any project as it often means the resulting product
has a small footprint and updates are easy to perform.  

Usually when I start a project I will begin with the header files.  I define the data types I think I will need and 
prototype the initial functions that are not dependent on other functions (within the library).  After I 
implement these base functions I prototype more dependent functions and implement them.   The process repeats until
I implement all of the functions I require.  For example, in the case of LibTomMath I implemented functions such as 
mp<span class="hl kwa">\_init</span>() well before I implemented mp<span class="hl kwa">\_mul</span>() and even further before I implemented mp<span class="hl kwa">\_exptmod</span>().  As an example as to 
why this design works note that the Karatsuba and Toom-Cook multipliers were written <span class="hl kwa">\textit</span><span class="hl opt">{</span>after<span class="hl opt">}</span> the 
dependent function mp<span class="hl kwa">\_exptmod</span>() was written.  Adding the new multiplication algorithms did not require changes to the 
mp<span class="hl kwa">\_exptmod</span>() function itself and lowered the total cost of ownership (<span class="hl kwa">\textit</span><span class="hl opt">{</span>so to speak<span class="hl opt">}</span>) and of development 
for new algorithms.  This methodology allows new algorithms to be tested in a complete framework with relative ease.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\includegraphics</span><span class="hl opt">{</span>pics/design_process.ps<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Design Flow of the First Few Original LibTomMath Functions.<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>pic:design_process<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>

Only after the majority of the functions were in place did I pursue a less hierarchical approach to auditing and optimizing
the source code.  For example, one day I may audit the multipliers and the next day the polynomial basis functions.  

It only makes sense to begin the text with the preliminary data types and support algorithms required as well.  
This chapter discusses the core algorithms of the library which are the dependents for every other algorithm.

<span class="hl kwa">\section</span><span class="hl opt">{</span>What is a Multiple Precision Integer?<span class="hl opt">}</span>
Recall that most programming languages, in particular ISO C <span class="hl kwa">\cite</span><span class="hl opt">{</span>ISOC<span class="hl opt">}</span>, only have fixed precision data types that on their own cannot 
be used to represent values larger than their precision will allow. The purpose of multiple precision algorithms is 
to use fixed precision data types to create and manipulate multiple precision integers which may represent values 
that are very large.  

As a well known analogy, school children are taught how to form numbers larger than nine by prepending more radix ten digits.  In the decimal system
the largest single digit value is $<span class="hl num">9</span>$.  However, by concatenating digits together larger numbers may be represented.  Newly prepended digits 
(<span class="hl kwa">\textit</span><span class="hl opt">{</span>to the left<span class="hl opt">}</span>) are said to be in a different power of ten column.  That is, the number $<span class="hl num">123</span>$ can be described as having a $<span class="hl num">1</span>$ in the hundreds 
column, $<span class="hl num">2</span>$ in the tens column and $<span class="hl num">3</span>$ in the ones column.  Or more formally $<span class="hl num">123</span> = <span class="hl num">1</span> <span class="hl kwa">\cdot</span> <span class="hl num">10</span>^<span class="hl num">2</span> + <span class="hl num">2</span> <span class="hl kwa">\cdot</span> <span class="hl num">10</span>^<span class="hl num">1</span> + <span class="hl num">3</span> <span class="hl kwa">\cdot</span> <span class="hl num">10</span>^<span class="hl num">0</span>$.  Computer based 
multiple precision arithmetic is essentially the same concept.  Larger integers are represented by adjoining fixed 
precision computer words with the exception that a different radix is used.

What most people probably do not think about explicitly are the various other attributes that describe a multiple precision 
integer.  For example, the integer $<span class="hl num">154</span>_<span class="hl opt">{</span><span class="hl num">10</span><span class="hl opt">}</span>$ has two immediately obvious properties.  First, the integer is positive, 
that is the sign of this particular integer is positive as opposed to negative.  Second, the integer has three digits in 
its representation.  There is an additional property that the integer posesses that does not concern pencil-and-paper 
arithmetic.  The third property is how many digits placeholders are available to hold the integer.  

The human analogy of this third property is ensuring there is enough space on the paper to write the integer.  For example,
if one starts writing a large number too far to the right on a piece of paper they will have to erase it and move left.  
Similarly, computer algorithms must maintain strict control over memory usage to ensure that the digits of an integer
will not exceed the allowed boundaries.  These three properties make up what is known as a multiple precision 
integer or mp<span class="hl kwa">\_int</span> for short.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>The mp<span class="hl kwa">\_int</span> Structure<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>sec:MPINT<span class="hl opt">}</span>
The mp<span class="hl kwa">\_int</span> structure is the ISO C based manifestation of what represents a multiple precision integer.  The ISO C standard does not provide for 
any such data type but it does provide for making composite data types known as structures.  The following is the structure definition 
used within LibTomMath.

<span class="hl kwa">\index</span><span class="hl opt">{</span>mp<span class="hl kwa">\_int</span><span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl slc">%\begin{verbatim}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>|l|<span class="hl opt">}</span>
<span class="hl kwa">\hline</span>
typedef struct \<span class="hl opt">{</span> \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span>int used, alloc, sign;\\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span>mp<span class="hl kwa">\_digit</span> *dp;\\
\<span class="hl opt">}</span> <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_int</span><span class="hl opt">}</span>; \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl slc">%\end{verbatim}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>The mp<span class="hl kwa">\_int</span> Structure<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>fig:mpint<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

The mp<span class="hl kwa">\_int</span> structure (fig. <span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:mpint<span class="hl opt">}</span>) can be broken down as follows.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>enumerate<span class="hl opt">}</span>
<span class="hl kwa">\item</span> The <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> parameter denotes how many digits of the array <span class="hl kwa">\textbf</span><span class="hl opt">{</span>dp<span class="hl opt">}</span> contain the digits used to represent
a given integer.  The <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> count must be positive (or zero) and may not exceed the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>alloc<span class="hl opt">}</span> count.  

<span class="hl kwa">\item</span> The <span class="hl kwa">\textbf</span><span class="hl opt">{</span>alloc<span class="hl opt">}</span> parameter denotes how 
many digits are available in the array to use by functions before it has to increase in size.  When the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> count 
of a result would exceed the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>alloc<span class="hl opt">}</span> count all of the algorithms will automatically increase the size of the 
array to accommodate the precision of the result.  

<span class="hl kwa">\item</span> The pointer <span class="hl kwa">\textbf</span><span class="hl opt">{</span>dp<span class="hl opt">}</span> points to a dynamically allocated array of digits that represent the given multiple 
precision integer.  It is padded with $(<span class="hl kwa">\textbf</span><span class="hl opt">{</span>alloc<span class="hl opt">}</span> - <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span>)$ zero digits.  The array is maintained in a least 
significant digit order.  As a pencil and paper analogy the array is organized such that the right most digits are stored
first starting at the location indexed by zero<span class="hl kwa">\footnote</span><span class="hl opt">{</span>In C all arrays begin at zero.<span class="hl opt">}</span> in the array.  For example, 
if <span class="hl kwa">\textbf</span><span class="hl opt">{</span>dp<span class="hl opt">}</span> contains $<span class="hl kwa">\lbrace</span> a, b, c, <span class="hl kwa">\ldots \rbrace</span>$ where <span class="hl kwa">\textbf</span><span class="hl opt">{</span>dp<span class="hl opt">}</span>$_0 = a$, <span class="hl kwa">\textbf</span><span class="hl opt">{</span>dp<span class="hl opt">}</span>$_1 = b$, <span class="hl kwa">\textbf</span><span class="hl opt">{</span>dp<span class="hl opt">}</span>$_2 = c$, $<span class="hl kwa">\ldots</span>$ then 
it would represent the integer $a + b<span class="hl kwa">\beta</span> + c<span class="hl kwa">\beta</span>^<span class="hl num">2</span> + <span class="hl kwa">\ldots</span>$  

<span class="hl kwa">\index</span><span class="hl opt">{</span>MP<span class="hl kwa">\_ZPOS</span><span class="hl opt">}</span> <span class="hl kwa">\index</span><span class="hl opt">{</span>MP<span class="hl kwa">\_NEG</span><span class="hl opt">}</span>
<span class="hl kwa">\item</span> The <span class="hl kwa">\textbf</span><span class="hl opt">{</span>sign<span class="hl opt">}</span> parameter denotes the sign as either zero/positive (<span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_ZPOS</span><span class="hl opt">}</span>) or negative (<span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_NEG</span><span class="hl opt">}</span>).  
<span class="hl kwa">\end</span><span class="hl opt">{</span>enumerate<span class="hl opt">}</span>

<span class="hl kwa">\subsubsection</span><span class="hl opt">{</span>Valid mp<span class="hl kwa">\_int</span> Structures<span class="hl opt">}</span>
Several rules are placed on the state of an mp<span class="hl kwa">\_int</span> structure and are assumed to be followed for reasons of efficiency.  
The only exceptions are when the structure is passed to initialization functions such as mp<span class="hl kwa">\_init</span>() and mp<span class="hl kwa">\_init\_copy</span>().

<span class="hl kwa">\begin</span><span class="hl opt">{</span>enumerate<span class="hl opt">}</span>
<span class="hl kwa">\item</span> The value of <span class="hl kwa">\textbf</span><span class="hl opt">{</span>alloc<span class="hl opt">}</span> may not be less than one.  That is <span class="hl kwa">\textbf</span><span class="hl opt">{</span>dp<span class="hl opt">}</span> always points to a previously allocated
array of digits.
<span class="hl kwa">\item</span> The value of <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> may not exceed <span class="hl kwa">\textbf</span><span class="hl opt">{</span>alloc<span class="hl opt">}</span> and must be greater than or equal to zero.
<span class="hl kwa">\item</span> The value of <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> implies the digit at index $(used - <span class="hl num">1</span>)$ of the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>dp<span class="hl opt">}</span> array is non-zero.  That is, 
leading zero digits in the most significant positions must be trimmed.
   <span class="hl kwa">\begin</span><span class="hl opt">{</span>enumerate<span class="hl opt">}</span>
   <span class="hl kwa">\item</span> Digits in the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>dp<span class="hl opt">}</span> array at and above the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> location must be zero.
   <span class="hl kwa">\end</span><span class="hl opt">{</span>enumerate<span class="hl opt">}</span>
<span class="hl kwa">\item</span> The value of <span class="hl kwa">\textbf</span><span class="hl opt">{</span>sign<span class="hl opt">}</span> must be <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_ZPOS</span><span class="hl opt">}</span> if <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> is zero; 
this represents the mp<span class="hl kwa">\_int</span> value of zero.
<span class="hl kwa">\end</span><span class="hl opt">{</span>enumerate<span class="hl opt">}</span>

<span class="hl kwa">\section</span><span class="hl opt">{</span>Argument Passing<span class="hl opt">}</span>
A convention of argument passing must be adopted early on in the development of any library.  Making the function 
prototypes consistent will help eliminate many headaches in the future as the library grows to significant complexity.  
In LibTomMath the multiple precision integer functions accept parameters from left to right as pointers to mp<span class="hl kwa">\_int</span> 
structures.  That means that the source (input) operands are placed on the left and the destination (output) on the right.   
Consider the following examples.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>verbatim<span class="hl opt">}</span>
   mp_mul(&amp;a, &amp;b, &amp;c);   /* c = a * b */
   mp_add(&amp;a, &amp;b, &amp;a);   /* a = a + b */
   mp_sqr(&amp;a, &amp;b);       /* b = a * a */
<span class="hl kwa">\end</span><span class="hl opt">{</span>verbatim<span class="hl opt">}</span>

The left to right order is a fairly natural way to implement the functions since it lets the developer read aloud the
functions and make sense of them.  For example, the first function would read ``multiply a and b and store in c''.

Certain libraries (<span class="hl kwa">\textit</span><span class="hl opt">{</span>LIP by Lenstra for instance<span class="hl opt">}</span>) accept parameters the other way around, to mimic the order
of assignment expressions.  That is, the destination (output) is on the left and arguments (inputs) are on the right.  In 
truth, it is entirely a matter of preference.  In the case of LibTomMath the convention from the MPI library has been 
adopted.  

Another very useful design consideration, provided for in LibTomMath, is whether to allow argument sources to also be a 
destination.  For example, the second example (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_add</span><span class="hl opt">}</span>) adds $a$ to $b$ and stores in $a$.  This is an important 
feature to implement since it allows the calling functions to cut down on the number of variables it must maintain.  
However, to implement this feature specific care has to be given to ensure the destination is not modified before the 
source is fully read.

<span class="hl kwa">\section</span><span class="hl opt">{</span>Return Values<span class="hl opt">}</span>
A well implemented application, no matter what its purpose, should trap as many runtime errors as possible and return them 
to the caller.  By catching runtime errors a library can be guaranteed to prevent undefined behaviour.  However, the end 
developer can still manage to cause a library to crash.  For example, by passing an invalid pointer an application may
fault by dereferencing memory not owned by the application.

In the case of LibTomMath the only errors that are checked for are related to inappropriate inputs (division by zero for 
instance) and memory allocation errors.  It will not check that the mp<span class="hl kwa">\_int</span> passed to any function is valid nor 
will it check pointers for validity.  Any function that can cause a runtime error will return an error code as an 
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>int<span class="hl opt">}</span> data type with one of the following values (fig <span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:errcodes<span class="hl opt">}</span>).

<span class="hl kwa">\index</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span> <span class="hl kwa">\index</span><span class="hl opt">{</span>MP<span class="hl kwa">\_VAL</span><span class="hl opt">}</span> <span class="hl kwa">\index</span><span class="hl opt">{</span>MP<span class="hl kwa">\_MEM</span><span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>|l|l|<span class="hl opt">}</span>
<span class="hl kwa">\hline \textbf</span><span class="hl opt">{</span>Value<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Meaning<span class="hl opt">}</span> \\
<span class="hl kwa">\hline \textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span> &amp; The function was successful \\
<span class="hl kwa">\hline \textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_VAL</span><span class="hl opt">}</span>  &amp; One of the input value(s) was invalid \\
<span class="hl kwa">\hline \textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_MEM</span><span class="hl opt">}</span>  &amp; The function ran out of heap memory \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>LibTomMath Error Codes<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>fig:errcodes<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

When an error is detected within a function it should free any memory it allocated, often during the initialization of
temporary mp<span class="hl kwa">\_ints</span>, and return as soon as possible.  The goal is to leave the system in the same state it was when the 
function was called.  Error checking with this style of API is fairly simple.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>verbatim<span class="hl opt">}</span>
   int err;
   if ((err = mp_add(&amp;a, &amp;b, &amp;c)) != MP_OKAY) <span class="hl opt">{</span>
      printf(&quot;Error: <span class="hl slc">%s\n&quot;, mp_error_to_string(err));</span>
      exit(EXIT_FAILURE);
   <span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>verbatim<span class="hl opt">}</span>

The GMP <span class="hl kwa">\cite</span><span class="hl opt">{</span>GMP<span class="hl opt">}</span> library uses C style <span class="hl kwa">\textit</span><span class="hl opt">{</span>signals<span class="hl opt">}</span> to flag errors which is of questionable use.  Not all errors are fatal 
and it was not deemed ideal by the author of LibTomMath to force developers to have signal handlers for such cases.

<span class="hl kwa">\section</span><span class="hl opt">{</span>Initialization and Clearing<span class="hl opt">}</span>
The logical starting point when actually writing multiple precision integer functions is the initialization and 
clearing of the mp<span class="hl kwa">\_int</span> structures.  These two algorithms will be used by the majority of the higher level algorithms.

Given the basic mp<span class="hl kwa">\_int</span> structure an initialization routine must first allocate memory to hold the digits of
the integer.  Often it is optimal to allocate a sufficiently large pre-set number of digits even though
the initial integer will represent zero.  If only a single digit were allocated quite a few subsequent re-allocations
would occur when operations are performed on the integers.  There is a tradeoff between how many default digits to allocate
and how many re-allocations are tolerable.  Obviously allocating an excessive amount of digits initially will waste 
memory and become unmanageable.  

If the memory for the digits has been successfully allocated then the rest of the members of the structure must
be initialized.  Since the initial state of an mp<span class="hl kwa">\_int</span> is to represent the zero integer, the allocated digits must be set
to zero.  The <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> count set to zero and <span class="hl kwa">\textbf</span><span class="hl opt">{</span>sign<span class="hl opt">}</span> set to <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_ZPOS</span><span class="hl opt">}</span>.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Initializing an mp<span class="hl kwa">\_int</span><span class="hl opt">}</span>
An mp<span class="hl kwa">\_int</span> is said to be initialized if it is set to a valid, preferably default, state such that all of the members of the
structure are set to valid values.  The mp<span class="hl kwa">\_init</span> algorithm will perform such an action.

<span class="hl kwa">\index</span><span class="hl opt">{</span>mp<span class="hl kwa">\_init</span><span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_init</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   An mp<span class="hl kwa">\_int</span> $a$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  Allocate memory and initialize $a$ to a known valid mp<span class="hl kwa">\_int</span> state.  \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  Allocate memory for <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_PREC</span><span class="hl opt">}</span> digits. \\
<span class="hl num">2</span>.  If the allocation failed return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_MEM</span><span class="hl opt">}</span>) \\
<span class="hl num">3</span>.  for $n$ from $<span class="hl num">0</span>$ to $MP<span class="hl kwa">\_PREC</span> - <span class="hl num">1</span>$ do  \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">3.1</span>  $a_n <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$\\
<span class="hl num">4</span>.  $a.sign <span class="hl kwa">\leftarrow</span> MP<span class="hl kwa">\_ZPOS</span>$\\
<span class="hl num">5</span>.  $a.used <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$\\
<span class="hl num">6</span>.  $a.alloc <span class="hl kwa">\leftarrow</span> MP<span class="hl kwa">\_PREC</span>$\\
<span class="hl num">7</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>)\\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_init</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_init</span>.<span class="hl opt">}</span>
The purpose of this function is to initialize an mp<span class="hl kwa">\_int</span> structure so that the rest of the library can properly
manipulte it.  It is assumed that the input may not have had any of its members previously initialized which is certainly
a valid assumption if the input resides on the stack.  

Before any of the members such as <span class="hl kwa">\textbf</span><span class="hl opt">{</span>sign<span class="hl opt">}</span>, <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> or <span class="hl kwa">\textbf</span><span class="hl opt">{</span>alloc<span class="hl opt">}</span> are initialized the memory for
the digits is allocated.  If this fails the function returns before setting any of the other members.  The <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_PREC</span><span class="hl opt">}</span> 
name represents a constant<span class="hl kwa">\footnote</span><span class="hl opt">{</span>Defined in the ``tommath.h'' header file within LibTomMath.<span class="hl opt">}</span> 
used to dictate the minimum precision of newly initialized mp<span class="hl kwa">\_int</span> integers.  Ideally, it is at least equal to the smallest
precision number you'll be working with.

Allocating a block of digits at first instead of a single digit has the benefit of lowering the number of usually slow
heap operations later functions will have to perform in the future.  If <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_PREC</span><span class="hl opt">}</span> is set correctly the slack 
memory and the number of heap operations will be trivial.

Once the allocation has been made the digits have to be set to zero as well as the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span>, <span class="hl kwa">\textbf</span><span class="hl opt">{</span>sign<span class="hl opt">}</span> and
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>alloc<span class="hl opt">}</span> members initialized.  This ensures that the mp<span class="hl kwa">\_int</span> will always represent the default state of zero regardless
of the original condition of the input.

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Remark.<span class="hl opt">}</span>
This function introduces the idiosyncrasy that all iterative loops, commonly initiated with the ``for'' keyword, iterate incrementally
when the ``to'' keyword is placed between two expressions.  For example, ``for $a$ from $b$ to $c$ do'' means that
a subsequent expression (or body of expressions) are to be evaluated upto $c - b$ times so long as $b <span class="hl kwa">\le</span> c$.  In each
iteration the variable $a$ is substituted for a new integer that lies inclusively between $b$ and $c$.  If $b &gt; c$ occured
the loop would not iterate.  By contrast if the ``downto'' keyword were used in place of ``to'' the loop would iterate 
decrementally.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_init</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

One immediate observation of this initializtion function is that it does not return a pointer to a mp<span class="hl kwa">\_int</span> structure.  It 
is assumed that the caller has already allocated memory for the mp<span class="hl kwa">\_int</span> structure, typically on the application stack.  The 
call to mp<span class="hl kwa">\_init</span>() is used only to initialize the members of the structure to a known default state.  

Here we see (line <span class="hl num">24</span>) the memory allocation is performed first.  This allows us to exit cleanly and quickly
if there is an error.  If the allocation fails the routine will return <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_MEM</span><span class="hl opt">}</span> to the caller to indicate there
was a memory error.  The function XMALLOC is what actually allocates the memory.  Technically XMALLOC is not a function
but a macro defined in ``tommath.h``.  By default, XMALLOC will evaluate to malloc() which is the C library's built--in
memory allocation routine.

In order to assure the mp<span class="hl kwa">\_int</span> is in a known state the digits must be set to zero.  On most platforms this could have been
accomplished by using calloc() instead of malloc().  However,  to correctly initialize a integer type to a given value in a 
portable fashion you have to actually assign the value.  The for loop (line <span class="hl num">30</span>) performs this required
operation.

After the memory has been successfully initialized the remainder of the members are initialized 
(lines <span class="hl num">34</span> through <span class="hl num">35</span>) to their respective default states.  At this point the algorithm has succeeded and
a success code is returned to the calling function.  If this function returns <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span> it is safe to assume the 
mp<span class="hl kwa">\_int</span> structure has been properly initialized and is safe to use with other functions within the library.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Clearing an mp<span class="hl kwa">\_int</span><span class="hl opt">}</span>
When an mp<span class="hl kwa">\_int</span> is no longer required by the application, the memory that has been allocated for its digits must be 
returned to the application's memory pool with the mp<span class="hl kwa">\_clear</span> algorithm.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_clear</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   An mp<span class="hl kwa">\_int</span> $a$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  The memory for $a$ shall be deallocated.  \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  If $a$ has been previously freed then return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl num">2</span>.  for $n$ from <span class="hl num">0</span> to $a.used - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  $a_n <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">3</span>.  Free the memory allocated for the digits of $a$. \\
<span class="hl num">4</span>.  $a.used <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">5</span>.  $a.alloc <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">6</span>.  $a.sign <span class="hl kwa">\leftarrow</span> MP<span class="hl kwa">\_ZPOS</span>$ \\
<span class="hl num">7</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_clear</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_clear</span>.<span class="hl opt">}</span>
This algorithm accomplishes two goals.  First, it clears the digits and the other mp<span class="hl kwa">\_int</span> members.  This ensures that 
if a developer accidentally re-uses a cleared structure it is less likely to cause problems.  The second goal
is to free the allocated memory.

The logic behind the algorithm is extended by marking cleared mp<span class="hl kwa">\_int</span> structures so that subsequent calls to this
algorithm will not try to free the memory multiple times.  Cleared mp<span class="hl kwa">\_ints</span> are detectable by having a pre-defined invalid 
digit pointer <span class="hl kwa">\textbf</span><span class="hl opt">{</span>dp<span class="hl opt">}</span> setting.

Once an mp<span class="hl kwa">\_int</span> has been cleared the mp<span class="hl kwa">\_int</span> structure is no longer in a valid state for any other algorithm
with the exception of algorithms mp<span class="hl kwa">\_init</span>, mp<span class="hl kwa">\_init\_copy</span>, mp<span class="hl kwa">\_init\_size</span> and mp<span class="hl kwa">\_clear</span>.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_clear</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

The algorithm only operates on the mp<span class="hl kwa">\_int</span> if it hasn't been previously cleared.  The if statement (line <span class="hl num">25</span>)
checks to see if the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>dp<span class="hl opt">}</span> member is not <span class="hl kwa">\textbf</span><span class="hl opt">{</span>NULL<span class="hl opt">}</span>.  If the mp<span class="hl kwa">\_int</span> is a valid mp<span class="hl kwa">\_int</span> then <span class="hl kwa">\textbf</span><span class="hl opt">{</span>dp<span class="hl opt">}</span> cannot be
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>NULL<span class="hl opt">}</span> in which case the if statement will evaluate to true.

The digits of the mp<span class="hl kwa">\_int</span> are cleared by the for loop (line <span class="hl num">27</span>) which assigns a zero to every digit.  Similar to mp<span class="hl kwa">\_init</span>()
the digits are assigned zero instead of using block memory operations (such as memset()) since this is more portable.  

The digits are deallocated off the heap via the XFREE macro.  Similar to XMALLOC the XFREE macro actually evaluates to
a standard C library function.  In this case the free() function.  Since free() only deallocates the memory the pointer
still has to be reset to <span class="hl kwa">\textbf</span><span class="hl opt">{</span>NULL<span class="hl opt">}</span> manually (line <span class="hl num">35</span>).  

Now that the digits have been cleared and deallocated the other members are set to their final values (lines <span class="hl num">36</span> and <span class="hl num">37</span>).

<span class="hl kwa">\section</span><span class="hl opt">{</span>Maintenance Algorithms<span class="hl opt">}</span>

The previous sections describes how to initialize and clear an mp<span class="hl kwa">\_int</span> structure.  To further support operations
that are to be performed on mp<span class="hl kwa">\_int</span> structures (such as addition and multiplication) the dependent algorithms must be
able to augment the precision of an mp<span class="hl kwa">\_int</span> and 
initialize mp<span class="hl kwa">\_ints</span> with differing initial conditions.  

These algorithms complete the set of low level algorithms required to work with mp<span class="hl kwa">\_int</span> structures in the higher level
algorithms such as addition, multiplication and modular exponentiation.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Augmenting an mp<span class="hl kwa">\_int</span>'s Precision<span class="hl opt">}</span>
When storing a value in an mp<span class="hl kwa">\_int</span> structure, a sufficient number of digits must be available to accomodate the entire 
result of an operation without loss of precision.  Quite often the size of the array given by the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>alloc<span class="hl opt">}</span> member 
is large enough to simply increase the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> digit count.  However, when the size of the array is too small it 
must be re-sized appropriately to accomodate the result.  The mp<span class="hl kwa">\_grow</span> algorithm will provide this functionality.

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_grow</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   An mp<span class="hl kwa">\_int</span> $a$ and an integer $b$. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $a$ is expanded to accomodate $b$ digits. \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  if $a.alloc <span class="hl kwa">\ge</span> b$ then return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>) \\
<span class="hl num">2</span>.  $u <span class="hl kwa">\leftarrow</span> b<span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>MP<span class="hl kwa">\_PREC\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl num">3</span>.  $v <span class="hl kwa">\leftarrow</span> b + <span class="hl num">2</span> <span class="hl kwa">\cdot</span> MP<span class="hl kwa">\_PREC</span> - u$ \\
<span class="hl num">4</span>.  Re-allocate the array of digits $a$ to size $v$ \\
<span class="hl num">5</span>.  If the allocation failed then return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_MEM</span><span class="hl opt">}</span>). \\
<span class="hl num">6</span>.  for n from a.alloc to $v - <span class="hl num">1</span>$ do  \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.1</span>  $a_n <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">7</span>.  $a.alloc <span class="hl kwa">\leftarrow</span> v$ \\
<span class="hl num">8</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_grow</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_grow</span>.<span class="hl opt">}</span>
It is ideal to prevent re-allocations from being performed if they are not required (step one).  This is useful to 
prevent mp<span class="hl kwa">\_ints</span> from growing excessively in code that erroneously calls mp<span class="hl kwa">\_grow</span>.  

The requested digit count is padded up to next multiple of <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_PREC</span><span class="hl opt">}</span> plus an additional <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_PREC</span><span class="hl opt">}</span> (steps two and three).  
This helps prevent many trivial reallocations that would grow an mp<span class="hl kwa">\_int</span> by trivially small values.  

It is assumed that the reallocation (step four) leaves the lower $a.alloc$ digits of the mp<span class="hl kwa">\_int</span> intact.  This is much 
akin to how the <span class="hl kwa">\textit</span><span class="hl opt">{</span>realloc<span class="hl opt">}</span> function from the standard C library works.  Since the newly allocated digits are 
assumed to contain undefined values they are initially set to zero.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_grow</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

A quick optimization is to first determine if a memory re-allocation is required at all.  The if statement (line <span class="hl num">24</span>) checks
if the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>alloc<span class="hl opt">}</span> member of the mp<span class="hl kwa">\_int</span> is smaller than the requested digit count.  If the count is not larger than <span class="hl kwa">\textbf</span><span class="hl opt">{</span>alloc<span class="hl opt">}</span>
the function skips the re-allocation part thus saving time.

When a re-allocation is performed it is turned into an optimal request to save time in the future.  The requested digit count is
padded upwards to <span class="hl num">2</span>nd multiple of <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_PREC</span><span class="hl opt">}</span> larger than <span class="hl kwa">\textbf</span><span class="hl opt">{</span>alloc<span class="hl opt">}</span> (line <span class="hl num">25</span>).  The XREALLOC function is used
to re-allocate the memory.  As per the other functions XREALLOC is actually a macro which evaluates to realloc by default.  The realloc
function leaves the base of the allocation intact which means the first <span class="hl kwa">\textbf</span><span class="hl opt">{</span>alloc<span class="hl opt">}</span> digits of the mp<span class="hl kwa">\_int</span> are the same as before
the re-allocation.  All	that is left is to clear the newly allocated digits and return.

Note that the re-allocation result is actually stored in a temporary pointer $tmp$.  This is to allow this function to return
an error with a valid pointer.  Earlier releases of the library stored the result of XREALLOC into the mp<span class="hl kwa">\_int</span> $a$.  That would
result in a memory leak if XREALLOC ever failed.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Initializing Variable Precision mp<span class="hl kwa">\_ints</span><span class="hl opt">}</span>
Occasionally the number of digits required will be known in advance of an initialization, based on, for example, the size 
of input mp<span class="hl kwa">\_ints</span> to a given algorithm.  The purpose of algorithm mp<span class="hl kwa">\_init\_size</span> is similar to mp<span class="hl kwa">\_init</span> except that it 
will allocate <span class="hl kwa">\textit</span><span class="hl opt">{</span>at least<span class="hl opt">}</span> a specified number of digits.  

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_init\_size</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   An mp<span class="hl kwa">\_int</span> $a$ and the requested number of digits $b$. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $a$ is initialized to hold at least $b$ digits. \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $u <span class="hl kwa">\leftarrow</span> b <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>MP<span class="hl kwa">\_PREC\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl num">2</span>.  $v <span class="hl kwa">\leftarrow</span> b + <span class="hl num">2</span> <span class="hl kwa">\cdot</span> MP<span class="hl kwa">\_PREC</span> - u$ \\
<span class="hl num">3</span>.  Allocate $v$ digits. \\
<span class="hl num">4</span>.  for $n$ from $<span class="hl num">0</span>$ to $v - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.1</span>  $a_n <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">5</span>.  $a.sign <span class="hl kwa">\leftarrow</span> MP<span class="hl kwa">\_ZPOS</span>$\\
<span class="hl num">6</span>.  $a.used <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$\\
<span class="hl num">7</span>.  $a.alloc <span class="hl kwa">\leftarrow</span> v$\\
<span class="hl num">8</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>)\\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_init\_size</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_init\_size</span>.<span class="hl opt">}</span>
This algorithm will initialize an mp<span class="hl kwa">\_int</span> structure $a$ like algorithm mp<span class="hl kwa">\_init</span> with the exception that the number of 
digits allocated can be controlled by the second input argument $b$.  The input size is padded upwards so it is a 
multiple of <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_PREC</span><span class="hl opt">}</span> plus an additional <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_PREC</span><span class="hl opt">}</span> digits.  This padding is used to prevent trivial 
allocations from becoming a bottleneck in the rest of the algorithms.

Like algorithm mp<span class="hl kwa">\_init</span>, the mp<span class="hl kwa">\_int</span> structure is initialized to a default state representing the integer zero.  This 
particular algorithm is useful if it is known ahead of time the approximate size of the input.  If the approximation is
correct no further memory re-allocations are required to work with the mp<span class="hl kwa">\_int</span>.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_init\_size</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

The number of digits $b$ requested is padded (line <span class="hl num">24</span>) by first augmenting it to the next multiple of 
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_PREC</span><span class="hl opt">}</span> and then adding <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_PREC</span><span class="hl opt">}</span> to the result.  If the memory can be successfully allocated the 
mp<span class="hl kwa">\_int</span> is placed in a default state representing the integer zero.  Otherwise, the error code <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_MEM</span><span class="hl opt">}</span> will be 
returned (line <span class="hl num">29</span>).  

The digits are allocated and set to zero at the same time with the calloc() function (line &#64;<span class="hl num">25</span>,XCALLOC&#64;).  The 
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> count is set to zero, the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>alloc<span class="hl opt">}</span> count set to the padded digit count and the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>sign<span class="hl opt">}</span> flag set 
to <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_ZPOS</span><span class="hl opt">}</span> to achieve a default valid mp<span class="hl kwa">\_int</span> state (lines <span class="hl num">33</span>, <span class="hl num">34</span> and <span class="hl num">35</span>).  If the function 
returns succesfully then it is correct to assume that the mp<span class="hl kwa">\_int</span> structure is in a valid state for the remainder of the 
functions to work with.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Multiple Integer Initializations and Clearings<span class="hl opt">}</span>
Occasionally a function will require a series of mp<span class="hl kwa">\_int</span> data types to be made available simultaneously.  
The purpose of algorithm mp<span class="hl kwa">\_init\_multi</span> is to initialize a variable length array of mp<span class="hl kwa">\_int</span> structures in a single
statement.  It is essentially a shortcut to multiple initializations.

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_init\_multi</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   Variable length array $V_k$ of mp<span class="hl kwa">\_int</span> variables of length $k$. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  The array is initialized such that each mp<span class="hl kwa">\_int</span> of $V_k$ is ready to use. \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  for $n$ from <span class="hl num">0</span> to $k - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.1</span>.  Initialize the mp<span class="hl kwa">\_int</span> $V_n$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_init</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.2</span>.  If initialization failed then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">1.2.1</span>.  for $j$ from $<span class="hl num">0</span>$ to $n$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">9</span>mm<span class="hl opt">}</span><span class="hl num">1.2.1.1</span>.  Free the mp<span class="hl kwa">\_int</span> $V_j$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_clear</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">1.2.2</span>.   Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_MEM</span><span class="hl opt">}</span>) \\
<span class="hl num">2</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_init\_multi</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_init\_multi</span>.<span class="hl opt">}</span>
The algorithm will initialize the array of mp<span class="hl kwa">\_int</span> variables one at a time.  If a runtime error has been detected 
(<span class="hl kwa">\textit</span><span class="hl opt">{</span>step <span class="hl num">1.2</span><span class="hl opt">}</span>) all of the previously initialized variables are cleared.  The goal is an ``all or nothing'' 
initialization which allows for quick recovery from runtime errors.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_init\_multi</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

This function intializes a variable length list of mp<span class="hl kwa">\_int</span> structure pointers.  However, instead of having the mp<span class="hl kwa">\_int</span>
structures in an actual C array they are simply passed as arguments to the function.  This function makes use of the 
``...'' argument syntax of the C programming language.  The list is terminated with a final <span class="hl kwa">\textbf</span><span class="hl opt">{</span>NULL<span class="hl opt">}</span> argument 
appended on the right.  

The function uses the ``stdarg.h'' <span class="hl kwa">\textit</span><span class="hl opt">{</span>va<span class="hl opt">}</span> functions to step portably through the arguments to the function.  A count
$n$ of succesfully initialized mp<span class="hl kwa">\_int</span> structures is maintained (line <span class="hl num">48</span>) such that if a failure does occur,
the algorithm can backtrack and free the previously initialized structures (lines <span class="hl num">28</span> to <span class="hl num">47</span>).  


<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Clamping Excess Digits<span class="hl opt">}</span>
When a function anticipates a result will be $n$ digits it is simpler to assume this is true within the body of 
the function instead of checking during the computation.  For example, a multiplication of a $i$ digit number by a 
$j$ digit produces a result of at most $i + j$ digits.  It is entirely possible that the result is $i + j - <span class="hl num">1</span>$ 
though, with no final carry into the last position.  However, suppose the destination had to be first expanded 
(<span class="hl kwa">\textit</span><span class="hl opt">{</span>via mp<span class="hl kwa">\_grow</span><span class="hl opt">}</span>) to accomodate $i + j - <span class="hl num">1</span>$ digits than further expanded to accomodate the final carry.  
That would be a considerable waste of time since heap operations are relatively slow.

The ideal solution is to always assume the result is $i + j$ and fix up the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> count after the function
terminates.  This way a single heap operation (<span class="hl kwa">\textit</span><span class="hl opt">{</span>at most<span class="hl opt">}</span>) is required.  However, if the result was not checked
there would be an excess high order zero digit.  

For example, suppose the product of two integers was $x_n = (<span class="hl num">0</span>x_<span class="hl opt">{</span>n-<span class="hl num">1</span><span class="hl opt">}</span>x_<span class="hl opt">{</span>n-<span class="hl num">2</span><span class="hl opt">}</span>...x_0)_<span class="hl opt">{</span><span class="hl kwa">\beta</span><span class="hl opt">}</span>$.  The leading zero digit 
will not contribute to the precision of the result.  In fact, through subsequent operations more leading zero digits would
accumulate to the point the size of the integer would be prohibitive.  As a result even though the precision is very 
low the representation is excessively large.  

The mp<span class="hl kwa">\_clamp</span> algorithm is designed to solve this very problem.  It will trim high-order zeros by decrementing the 
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> count until a non-zero most significant digit is found.  Also in this system, zero is considered to be a 
positive number which means that if the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> count is decremented to zero, the sign must be set to 
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_ZPOS</span><span class="hl opt">}</span>.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_clamp</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   An mp<span class="hl kwa">\_int</span> $a$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  Any excess leading zero digits of $a$ are removed \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  while $a.used &gt; <span class="hl num">0</span>$ and $a_<span class="hl opt">{</span>a.used - <span class="hl num">1</span><span class="hl opt">}</span> = <span class="hl num">0</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.1</span>  $a.used <span class="hl kwa">\leftarrow</span> a.used - <span class="hl num">1</span>$ \\
<span class="hl num">2</span>.  if $a.used = <span class="hl num">0</span>$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  $a.sign <span class="hl kwa">\leftarrow</span> MP<span class="hl kwa">\_ZPOS</span>$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_clamp</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_clamp</span>.<span class="hl opt">}</span>
As can be expected this algorithm is very simple.  The loop on step one is expected to iterate only once or twice at
the most.  For example, this will happen in cases where there is not a carry to fill the last position.  Step two fixes the sign for 
when all of the digits are zero to ensure that the mp<span class="hl kwa">\_int</span> is valid at all times.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_clamp</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

Note on line <span class="hl num">28</span> how to test for the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> count is made on the left of the \&amp;\&amp; operator.  In the C programming
language the terms to \&amp;\&amp; are evaluated left to right with a boolean short-circuit if any condition fails.  This is 
important since if the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> is zero the test on the right would fetch below the array.  That is obviously 
undesirable.  The parenthesis on line <span class="hl num">31</span> is used to make sure the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> count is decremented and not
the pointer ``a''.  

<span class="hl kwa">\section</span>*<span class="hl opt">{</span>Exercises<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>cl<span class="hl opt">}</span>
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">1</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span>$ &amp; Discuss the relevance of the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> member of the mp<span class="hl kwa">\_int</span> structure. \\
                     &amp; \\
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">1</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span>$ &amp; Discuss the consequences of not using padding when performing allocations.  \\
                     &amp; \\
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">2</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span>$ &amp; Estimate an ideal value for <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_PREC</span><span class="hl opt">}</span> when performing <span class="hl num">1024</span>-bit RSA \\
                     &amp; encryption when $<span class="hl kwa">\beta</span> = <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">28</span><span class="hl opt">}</span>$.  \\
                     &amp; \\
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">1</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span>$ &amp; Discuss the relevance of the algorithm mp<span class="hl kwa">\_clamp</span>.  What does it prevent? \\
                     &amp; \\
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">1</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span>$ &amp; Give an example of when the algorithm  mp<span class="hl kwa">\_init\_copy</span> might be useful. \\
                     &amp; \\
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>


<span class="hl slc">%%%</span>
<span class="hl slc">% CHAPTER FOUR</span>
<span class="hl slc">%%%</span>

<span class="hl kwa">\chapter</span><span class="hl opt">{</span>Basic Operations<span class="hl opt">}</span>

<span class="hl kwa">\section</span><span class="hl opt">{</span>Introduction<span class="hl opt">}</span>
In the previous chapter a series of low level algorithms were established that dealt with initializing and maintaining
mp<span class="hl kwa">\_int</span> structures.  This chapter will discuss another set of seemingly non-algebraic algorithms which will form the low 
level basis of the entire library.  While these algorithm are relatively trivial it is important to understand how they
work before proceeding since these algorithms will be used almost intrinsically in the following chapters.

The algorithms in this chapter deal primarily with more ``programmer'' related tasks such as creating copies of
mp<span class="hl kwa">\_int</span> structures, assigning small values to mp<span class="hl kwa">\_int</span> structures and comparisons of the values mp<span class="hl kwa">\_int</span> structures
represent.   

<span class="hl kwa">\section</span><span class="hl opt">{</span>Assigning Values to mp<span class="hl kwa">\_int</span> Structures<span class="hl opt">}</span>
<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Copying an mp<span class="hl kwa">\_int</span><span class="hl opt">}</span>
Assigning the value that a given mp<span class="hl kwa">\_int</span> structure represents to another mp<span class="hl kwa">\_int</span> structure shall be known as making
a copy for the purposes of this text.  The copy of the mp<span class="hl kwa">\_int</span> will be a separate entity that represents the same
value as the mp<span class="hl kwa">\_int</span> it was copied from.  The mp<span class="hl kwa">\_copy</span> algorithm provides this functionality. 

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_copy</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.  An mp<span class="hl kwa">\_int</span> $a$ and $b$. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  Store a copy of $a$ in $b$. \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  If $b.alloc &lt; a.used$ then grow $b$ to $a.used$ digits.  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_grow</span><span class="hl opt">}</span>) \\
<span class="hl num">2</span>.  for $n$ from <span class="hl num">0</span> to $a.used - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  $b_<span class="hl opt">{</span>n<span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> a_<span class="hl opt">{</span>n<span class="hl opt">}</span>$ \\
<span class="hl num">3</span>.  for $n$ from $a.used$ to $b.used - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">3.1</span>  $b_<span class="hl opt">{</span>n<span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">4</span>.  $b.used <span class="hl kwa">\leftarrow</span> a.used$ \\
<span class="hl num">5</span>.  $b.sign <span class="hl kwa">\leftarrow</span> a.sign$ \\
<span class="hl num">6</span>.  return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_copy</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_copy</span>.<span class="hl opt">}</span>
This algorithm copies the mp<span class="hl kwa">\_int</span> $a$ such that upon succesful termination of the algorithm the mp<span class="hl kwa">\_int</span> $b$ will
represent the same integer as the mp<span class="hl kwa">\_int</span> $a$.  The mp<span class="hl kwa">\_int</span> $b$ shall be a complete and distinct copy of the 
mp<span class="hl kwa">\_int</span> $a$ meaing that the mp<span class="hl kwa">\_int</span> $a$ can be modified and it shall not affect the value of the mp<span class="hl kwa">\_int</span> $b$.

If $b$ does not have enough room for the digits of $a$ it must first have its precision augmented via the mp<span class="hl kwa">\_grow</span> 
algorithm.  The digits of $a$ are copied over the digits of $b$ and any excess digits of $b$ are set to zero (step two
and three).  The <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> and <span class="hl kwa">\textbf</span><span class="hl opt">{</span>sign<span class="hl opt">}</span> members of $a$ are finally copied over the respective members of
$b$.

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Remark.<span class="hl opt">}</span>  This algorithm also introduces a new idiosyncrasy that will be used throughout the rest of the
text.  The error return codes of other algorithms are not explicitly checked in the pseudo-code presented.  For example, in 
step one of the mp<span class="hl kwa">\_copy</span> algorithm the return of mp<span class="hl kwa">\_grow</span> is not explicitly checked to ensure it succeeded.  Text space is 
limited so it is assumed that if a algorithm fails it will clear all temporarily allocated mp<span class="hl kwa">\_ints</span> and return
the error code itself.  However, the C code presented will demonstrate all of the error handling logic required to 
implement the pseudo-code.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_copy</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

Occasionally a dependent algorithm may copy an mp<span class="hl kwa">\_int</span> effectively into itself such as when the input and output
mp<span class="hl kwa">\_int</span> structures passed to a function are one and the same.  For this case it is optimal to return immediately without 
copying digits (line <span class="hl num">25</span>).  

The mp<span class="hl kwa">\_int</span> $b$ must have enough digits to accomodate the used digits of the mp<span class="hl kwa">\_int</span> $a$.  If $b.alloc$ is less than
$a.used$ the algorithm mp<span class="hl kwa">\_grow</span> is used to augment the precision of $b$ (lines <span class="hl num">30</span> to <span class="hl num">33</span>).  In order to
simplify the inner loop that copies the digits from $a$ to $b$, two aliases $tmpa$ and $tmpb$ point directly at the digits
of the mp<span class="hl kwa">\_ints</span> $a$ and $b$ respectively.  These aliases (lines <span class="hl num">43</span> and <span class="hl num">46</span>) allow the compiler to access the digits without first dereferencing the
mp<span class="hl kwa">\_int</span> pointers and then subsequently the pointer to the digits.  

After the aliases are established the digits from $a$ are copied into $b$ (lines <span class="hl num">49</span> to <span class="hl num">51</span>) and then the excess 
digits of $b$ are set to zero (lines <span class="hl num">54</span> to <span class="hl num">56</span>).  Both ``for'' loops make use of the pointer aliases and in 
fact the alias for $b$ is carried through into the second ``for'' loop to clear the excess digits.  This optimization 
allows the alias to stay in a machine register fairly easy between the two loops.

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Remarks.<span class="hl opt">}</span>  The use of pointer aliases is an implementation methodology first introduced in this function that will
be used considerably in other functions.  Technically, a pointer alias is simply a short hand alias used to lower the 
number of pointer dereferencing operations required to access data.  For example, a for loop may resemble

<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
for (x = <span class="hl num">0</span>; x &lt; <span class="hl num">100</span>; x++) \<span class="hl opt">{</span>
    a-&gt;num<span class="hl opt">[</span><span class="hl num">4</span><span class="hl opt">]</span>-&gt;dp<span class="hl opt">[</span>x<span class="hl opt">]</span> = <span class="hl num">0</span>;
\<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>

This could be re-written using aliases as 

<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
mp_digit *tmpa;
a = a-&gt;num<span class="hl opt">[</span><span class="hl num">4</span><span class="hl opt">]</span>-&gt;dp;
for (x = <span class="hl num">0</span>; x &lt; <span class="hl num">100</span>; x++) \<span class="hl opt">{</span>
    *a++ = <span class="hl num">0</span>;
\<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>

In this case an alias is used to access the 
array of digits within an mp<span class="hl kwa">\_int</span> structure directly.  It may seem that a pointer alias is strictly not required 
as a compiler may optimize out the redundant pointer operations.  However, there are two dominant reasons to use aliases.

The first reason is that most compilers will not effectively optimize pointer arithmetic.  For example, some optimizations 
may work for the Microsoft Visual C++ compiler (MSVC) and not for the GNU C Compiler (GCC).  Also some optimizations may 
work for GCC and not MSVC.  As such it is ideal to find a common ground for as many compilers as possible.  Pointer 
aliases optimize the code considerably before the compiler even reads the source code which means the end compiled code 
stands a better chance of being faster.

The second reason is that pointer aliases often can make an algorithm simpler to read.  Consider the first ``for'' 
loop of the function mp<span class="hl kwa">\_copy</span>() re-written to not use pointer aliases.

<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
    /* copy all the digits */
    for (n = <span class="hl num">0</span>; n &lt; a-&gt;used; n++) \<span class="hl opt">{</span>
      b-&gt;dp<span class="hl opt">[</span>n<span class="hl opt">]</span> = a-&gt;dp<span class="hl opt">[</span>n<span class="hl opt">]</span>;
    \<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>

Whether this code is harder to read depends strongly on the individual.  However, it is quantifiably slightly more 
complicated as there are four variables within the statement instead of just two.

<span class="hl kwa">\subsubsection</span><span class="hl opt">{</span>Nested Statements<span class="hl opt">}</span>
Another commonly used technique in the source routines is that certain sections of code are nested.  This is used in
particular with the pointer aliases to highlight code phases.  For example, a Comba multiplier (discussed in chapter six)
will typically have three different phases.  First the temporaries are initialized, then the columns calculated and 
finally the carries are propagated.  In this example the middle column production phase will typically be nested as it
uses temporary variables and aliases the most.

The nesting also simplies the source code as variables that are nested are only valid for their scope.  As a result
the various temporary variables required do not propagate into other sections of code.


<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Creating a Clone<span class="hl opt">}</span>
Another common operation is to make a local temporary copy of an mp<span class="hl kwa">\_int</span> argument.  To initialize an mp<span class="hl kwa">\_int</span> 
and then copy another existing mp<span class="hl kwa">\_int</span> into the newly intialized mp<span class="hl kwa">\_int</span> will be known as creating a clone.  This is 
useful within functions that need to modify an argument but do not wish to actually modify the original copy.  The 
mp<span class="hl kwa">\_init\_copy</span> algorithm has been designed to help perform this task.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_init\_copy</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   An mp<span class="hl kwa">\_int</span> $a$ and $b$\\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $a$ is initialized to be a copy of $b$. \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  Init $a$.  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_init</span><span class="hl opt">}</span>) \\
<span class="hl num">2</span>.  Copy $b$ to $a$.  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_copy</span><span class="hl opt">}</span>) \\
<span class="hl num">3</span>.  Return the status of the copy operation. \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_init\_copy</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_init\_copy</span>.<span class="hl opt">}</span>
This algorithm will initialize an mp<span class="hl kwa">\_int</span> variable and copy another previously initialized mp<span class="hl kwa">\_int</span> variable into it.  As 
such this algorithm will perform two operations in one step.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_init\_copy</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

This will initialize <span class="hl kwa">\textbf</span><span class="hl opt">{</span>a<span class="hl opt">}</span> and make it a verbatim copy of the contents of <span class="hl kwa">\textbf</span><span class="hl opt">{</span>b<span class="hl opt">}</span>.  Note that 
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>a<span class="hl opt">}</span> will have its own memory allocated which means that <span class="hl kwa">\textbf</span><span class="hl opt">{</span>b<span class="hl opt">}</span> may be cleared after the call
and <span class="hl kwa">\textbf</span><span class="hl opt">{</span>a<span class="hl opt">}</span> will be left intact.  

<span class="hl kwa">\section</span><span class="hl opt">{</span>Zeroing an Integer<span class="hl opt">}</span>
Reseting an mp<span class="hl kwa">\_int</span> to the default state is a common step in many algorithms.  The mp<span class="hl kwa">\_zero</span> algorithm will be the algorithm used to
perform this task.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_zero</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   An mp<span class="hl kwa">\_int</span> $a$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  Zero the contents of $a$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $a.used <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">2</span>.  $a.sign <span class="hl kwa">\leftarrow</span>$ MP<span class="hl kwa">\_ZPOS</span> \\
<span class="hl num">3</span>.  for $n$ from <span class="hl num">0</span> to $a.alloc - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">3.1</span>  $a_n <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_zero</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_zero</span>.<span class="hl opt">}</span>
This algorithm simply resets a mp<span class="hl kwa">\_int</span> to the default state.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_zero</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

After the function is completed, all of the digits are zeroed, the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> count is zeroed and the 
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>sign<span class="hl opt">}</span> variable is set to <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_ZPOS</span><span class="hl opt">}</span>.

<span class="hl kwa">\section</span><span class="hl opt">{</span>Sign Manipulation<span class="hl opt">}</span>
<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Absolute Value<span class="hl opt">}</span>
With the mp<span class="hl kwa">\_int</span> representation of an integer, calculating the absolute value is trivial.  The mp<span class="hl kwa">\_abs</span> algorithm will compute
the absolute value of an mp<span class="hl kwa">\_int</span>.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_abs</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   An mp<span class="hl kwa">\_int</span> $a$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  Computes $b = <span class="hl kwa">\vert</span> a <span class="hl kwa">\vert</span>$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  Copy $a$ to $b$.  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_copy</span><span class="hl opt">}</span>) \\
<span class="hl num">2</span>.  If the copy failed return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_MEM</span><span class="hl opt">}</span>). \\
<span class="hl num">3</span>.  $b.sign <span class="hl kwa">\leftarrow</span> MP<span class="hl kwa">\_ZPOS</span>$ \\
<span class="hl num">4</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_abs</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_abs</span>.<span class="hl opt">}</span>
This algorithm computes the absolute of an mp<span class="hl kwa">\_int</span> input.  First it copies $a$ over $b$.  This is an example of an
algorithm where the check in mp<span class="hl kwa">\_copy</span> that determines if the source and destination are equal proves useful.  This allows,
for instance, the developer to pass the same mp<span class="hl kwa">\_int</span> as the source and destination to this function without addition 
logic to handle it.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_abs</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

This fairly trivial algorithm first eliminates non--required duplications (line <span class="hl num">28</span>) and then sets the
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>sign<span class="hl opt">}</span> flag to <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_ZPOS</span><span class="hl opt">}</span>.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Integer Negation<span class="hl opt">}</span>
With the mp<span class="hl kwa">\_int</span> representation of an integer, calculating the negation is also trivial.  The mp<span class="hl kwa">\_neg</span> algorithm will compute
the negative of an mp<span class="hl kwa">\_int</span> input.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_neg</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   An mp<span class="hl kwa">\_int</span> $a$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  Computes $b = -a$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  Copy $a$ to $b$.  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_copy</span><span class="hl opt">}</span>) \\
<span class="hl num">2</span>.  If the copy failed return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_MEM</span><span class="hl opt">}</span>). \\
<span class="hl num">3</span>.  If $a.used = <span class="hl num">0</span>$ then return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl num">4</span>.  If $a.sign = MP<span class="hl kwa">\_ZPOS</span>$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.1</span>  $b.sign = MP<span class="hl kwa">\_NEG</span>$. \\
<span class="hl num">5</span>.  else do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.1</span>  $b.sign = MP<span class="hl kwa">\_ZPOS</span>$. \\
<span class="hl num">6</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_neg</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_neg</span>.<span class="hl opt">}</span>
This algorithm computes the negation of an input.  First it copies $a$ over $b$.  If $a$ has no used digits then
the algorithm returns immediately.  Otherwise it flips the sign flag and stores the result in $b$.  Note that if 
$a$ had no digits then it must be positive by definition.  Had step three been omitted then the algorithm would return
zero as negative.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_neg</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

Like mp<span class="hl kwa">\_abs</span>() this function avoids non--required duplications (line <span class="hl num">22</span>) and then sets the sign.  We
have to make sure that only non--zero values get a <span class="hl kwa">\textbf</span><span class="hl opt">{</span>sign<span class="hl opt">}</span> of <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_NEG</span><span class="hl opt">}</span>.  If the mp<span class="hl kwa">\_int</span> is zero
than the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>sign<span class="hl opt">}</span> is hard--coded to <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_ZPOS</span><span class="hl opt">}</span>.

<span class="hl kwa">\section</span><span class="hl opt">{</span>Small Constants<span class="hl opt">}</span>
<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Setting Small Constants<span class="hl opt">}</span>
Often a mp<span class="hl kwa">\_int</span> must be set to a relatively small value such as $<span class="hl num">1</span>$ or $<span class="hl num">2</span>$.  For these cases the mp<span class="hl kwa">\_set</span> algorithm is useful.

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_set</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   An mp<span class="hl kwa">\_int</span> $a$ and a digit $b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  Make $a$ equivalent to $b$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  Zero $a$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_zero</span><span class="hl opt">}</span>). \\
<span class="hl num">2</span>.  $a_0 <span class="hl kwa">\leftarrow</span> b <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl num">3</span>.  $a.used <span class="hl kwa">\leftarrow  \left \lbrace \begin</span><span class="hl opt">{</span>array<span class="hl opt">}{</span>ll<span class="hl opt">}</span>
                              <span class="hl num">1</span> &amp;  <span class="hl kwa">\mbox</span><span class="hl opt">{</span>if <span class="hl opt">}</span>a_0 &gt; <span class="hl num">0</span> \\
                              <span class="hl num">0</span> &amp;  <span class="hl kwa">\mbox</span><span class="hl opt">{</span>if <span class="hl opt">}</span>a_0 = <span class="hl num">0</span> 
                              <span class="hl kwa">\end</span><span class="hl opt">{</span>array<span class="hl opt">}</span> <span class="hl kwa">\right</span> .$ \\
<span class="hl kwa">\hline</span>                              
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_set</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_set</span>.<span class="hl opt">}</span>
This algorithm sets a mp<span class="hl kwa">\_int</span> to a small single digit value.  Step number <span class="hl num">1</span> ensures that the integer is reset to the default state.  The
single digit is set (<span class="hl kwa">\textit</span><span class="hl opt">{</span>modulo $<span class="hl kwa">\beta</span>$<span class="hl opt">}</span>) and the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> count is adjusted accordingly.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_set</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

First we zero (line <span class="hl num">21</span>) the mp<span class="hl kwa">\_int</span> to make sure that the other members are initialized for a 
small positive constant.  mp<span class="hl kwa">\_zero</span>() ensures that the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>sign<span class="hl opt">}</span> is positive and the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> count
is zero.  Next we set the digit and reduce it modulo $<span class="hl kwa">\beta</span>$ (line <span class="hl num">22</span>).  After this step we have to 
check if the resulting digit is zero or not.  If it is not then we set the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> count to one, otherwise
to zero.

We can quickly reduce modulo $<span class="hl kwa">\beta</span>$ since it is of the form $<span class="hl num">2</span>^k$ and a quick binary AND operation with 
$<span class="hl num">2</span>^k - <span class="hl num">1</span>$ will perform the same operation.

One important limitation of this function is that it will only set one digit.  The size of a digit is not fixed, meaning source that uses 
this function should take that into account.  Only trivially small constants can be set using this function.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Setting Large Constants<span class="hl opt">}</span>
To overcome the limitations of the mp<span class="hl kwa">\_set</span> algorithm the mp<span class="hl kwa">\_set\_int</span> algorithm is ideal.  It accepts a ``long''
data type as input and will always treat it as a <span class="hl num">32</span>-bit integer.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_set\_int</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   An mp<span class="hl kwa">\_int</span> $a$ and a ``long'' integer $b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  Make $a$ equivalent to $b$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  Zero $a$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_zero</span><span class="hl opt">}</span>) \\
<span class="hl num">2</span>.  for $n$ from <span class="hl num">0</span> to <span class="hl num">7</span> do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  $a <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\cdot</span> <span class="hl num">16</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_mul2d</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.2</span>  $u <span class="hl kwa">\leftarrow \lfloor</span> b / <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">4</span>(<span class="hl num">7</span> - n)<span class="hl opt">}</span> <span class="hl kwa">\rfloor \mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">16</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$\\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.3</span>  $a_0 <span class="hl kwa">\leftarrow</span> a_0 + u$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.4</span>  $a.used <span class="hl kwa">\leftarrow</span> a.used + <span class="hl num">1</span>$ \\
<span class="hl num">3</span>.  Clamp excess used digits (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_clamp</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_set\_int</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_set\_int</span>.<span class="hl opt">}</span>
The algorithm performs eight iterations of a simple loop where in each iteration four bits from the source are added to the 
mp<span class="hl kwa">\_int</span>.  Step <span class="hl num">2.1</span> will multiply the current result by sixteen making room for four more bits in the less significant positions.  In step <span class="hl num">2.2</span> the
next four bits from the source are extracted and are added to the mp<span class="hl kwa">\_int</span>. The <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> digit count is 
incremented to reflect the addition.  The <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> digit counter is incremented since if any of the leading digits were zero the mp<span class="hl kwa">\_int</span> would have
zero digits used and the newly added four bits would be ignored.

Excess zero digits are trimmed in steps <span class="hl num">2.1</span> and <span class="hl num">3</span> by using higher level algorithms mp<span class="hl kwa">\_mul2d</span> and mp<span class="hl kwa">\_clamp</span>.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_set\_int</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

This function sets four bits of the number at a time to handle all practical <span class="hl kwa">\textbf</span><span class="hl opt">{</span>DIGIT<span class="hl kwa">\_BIT</span><span class="hl opt">}</span> sizes.  The weird
addition on line <span class="hl num">39</span> ensures that the newly added in bits are added to the number of digits.  While it may not 
seem obvious as to why the digit counter does not grow exceedingly large it is because of the shift on line <span class="hl num">28</span> 
as well as the  call to mp<span class="hl kwa">\_clamp</span>() on line <span class="hl num">41</span>.  Both functions will clamp excess leading digits which keeps 
the number of used digits low.

<span class="hl kwa">\section</span><span class="hl opt">{</span>Comparisons<span class="hl opt">}</span>
<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Unsigned Comparisions<span class="hl opt">}</span>
Comparing a multiple precision integer is performed with the exact same algorithm used to compare two decimal numbers.  For example,
to compare $<span class="hl num">1</span>,<span class="hl num">234</span>$ to $<span class="hl num">1</span>,<span class="hl num">264</span>$ the digits are extracted by their positions.  That is we compare $<span class="hl num">1</span> <span class="hl kwa">\cdot</span> <span class="hl num">10</span>^<span class="hl num">3</span> + <span class="hl num">2</span> <span class="hl kwa">\cdot</span> <span class="hl num">10</span>^<span class="hl num">2</span> + <span class="hl num">3</span> <span class="hl kwa">\cdot</span> <span class="hl num">10</span>^<span class="hl num">1</span> + <span class="hl num">4</span> <span class="hl kwa">\cdot</span> <span class="hl num">10</span>^<span class="hl num">0</span>$
to $<span class="hl num">1</span> <span class="hl kwa">\cdot</span> <span class="hl num">10</span>^<span class="hl num">3</span> + <span class="hl num">2</span> <span class="hl kwa">\cdot</span> <span class="hl num">10</span>^<span class="hl num">2</span> + <span class="hl num">6</span> <span class="hl kwa">\cdot</span> <span class="hl num">10</span>^<span class="hl num">1</span> + <span class="hl num">4</span> <span class="hl kwa">\cdot</span> <span class="hl num">10</span>^<span class="hl num">0</span>$ by comparing single digits at a time starting with the highest magnitude 
positions.  If any leading digit of one integer is greater than a digit in the same position of another integer then obviously it must be greater.  

The first comparision routine that will be developed is the unsigned magnitude compare which will perform a comparison based on the digits of two
mp<span class="hl kwa">\_int</span> variables alone.  It will ignore the sign of the two inputs.  Such a function is useful when an absolute comparison is required or if the 
signs are known to agree in advance.

To facilitate working with the results of the comparison functions three constants are required.  

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>|r|l|<span class="hl opt">}</span>
<span class="hl kwa">\hline \textbf</span><span class="hl opt">{</span>Constant<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Meaning<span class="hl opt">}</span> \\
<span class="hl kwa">\hline \textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_GT</span><span class="hl opt">}</span> &amp; Greater Than \\
<span class="hl kwa">\hline \textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_EQ</span><span class="hl opt">}</span> &amp; Equal To \\
<span class="hl kwa">\hline \textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_LT</span><span class="hl opt">}</span> &amp; Less Than \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Comparison Return Codes<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_cmp\_mag</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   Two mp<span class="hl kwa">\_ints</span> $a$ and $b$.  \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  Unsigned comparison results ($a$ to the left of $b$). \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  If $a.used &gt; b.used$ then return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_GT</span><span class="hl opt">}</span>) \\
<span class="hl num">2</span>.  If $a.used &lt; b.used$ then return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_LT</span><span class="hl opt">}</span>) \\
<span class="hl num">3</span>.  for n from $a.used - <span class="hl num">1</span>$ to <span class="hl num">0</span> do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">3.1</span>  if $a_n &gt; b_n$ then return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_GT</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">3.2</span>  if $a_n &lt; b_n$ then return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_LT</span><span class="hl opt">}</span>) \\
<span class="hl num">4</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_EQ</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_cmp\_mag</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_cmp\_mag</span>.<span class="hl opt">}</span>
By saying ``$a$ to the left of $b$'' it is meant that the comparison is with respect to $a$, that is if $a$ is greater than $b$ it will return
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_GT</span><span class="hl opt">}</span> and similar with respect to when $a = b$ and $a &lt; b$.  The first two steps compare the number of digits used in both $a$ and $b$.  
Obviously if the digit counts differ there would be an imaginary zero digit in the smaller number where the leading digit of the larger number is.  
If both have the same number of digits than the actual digits themselves must be compared starting at the leading digit.  

By step three both inputs must have the same number of digits so its safe to start from either $a.used - <span class="hl num">1</span>$ or $b.used - <span class="hl num">1</span>$ and count down to
the zero'th digit.  If after all of the digits have been compared, no difference is found, the algorithm returns <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_EQ</span><span class="hl opt">}</span>.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_cmp\_mag</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

The two if statements (lines <span class="hl num">25</span> and <span class="hl num">29</span>) compare the number of digits in the two inputs.  These two are 
performed before all of the digits are compared since it is a very cheap test to perform and can potentially save 
considerable time.  The implementation given is also not valid without those two statements.  $b.alloc$ may be 
smaller than $a.used$, meaning that undefined values will be read from $b$ past the end of the array of digits.



<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Signed Comparisons<span class="hl opt">}</span>
Comparing with sign considerations is also fairly critical in several routines (<span class="hl kwa">\textit</span><span class="hl opt">{</span>division for example<span class="hl opt">}</span>).  Based on an unsigned magnitude 
comparison a trivial signed comparison algorithm can be written.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_cmp</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   Two mp<span class="hl kwa">\_ints</span> $a$ and $b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  Signed Comparison Results ($a$ to the left of $b$) \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  if $a.sign = MP<span class="hl kwa">\_NEG</span>$ and $b.sign = MP<span class="hl kwa">\_ZPOS</span>$ then return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_LT</span><span class="hl opt">}</span>) \\
<span class="hl num">2</span>.  if $a.sign = MP<span class="hl kwa">\_ZPOS</span>$ and $b.sign = MP<span class="hl kwa">\_NEG</span>$ then return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_GT</span><span class="hl opt">}</span>) \\
<span class="hl num">3</span>.  if $a.sign = MP<span class="hl kwa">\_NEG</span>$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">3.1</span>  Return the unsigned comparison of $b$ and $a$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_cmp\_mag</span><span class="hl opt">}</span>) \\
<span class="hl num">4</span>   Otherwise \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.1</span>  Return the unsigned comparison of $a$ and $b$ \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_cmp</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_cmp</span>.<span class="hl opt">}</span>
The first two steps compare the signs of the two inputs.  If the signs do not agree then it can return right away with the appropriate 
comparison code.  When the signs are equal the digits of the inputs must be compared to determine the correct result.  In step 
three the unsigned comparision flips the order of the arguments since they are both negative.  For instance, if $-a &gt; -b$ then 
$<span class="hl kwa">\vert</span> a <span class="hl kwa">\vert</span> &lt; <span class="hl kwa">\vert</span> b <span class="hl kwa">\vert</span>$.  Step number four will compare the two when they are both positive.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_cmp</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

The two if statements (lines <span class="hl num">23</span> and <span class="hl num">24</span>) perform the initial sign comparison.  If the signs are not the equal then which ever
has the positive sign is larger.   The inputs are compared (line <span class="hl num">32</span>) based on magnitudes.  If the signs were both 
negative then the unsigned comparison is performed in the opposite direction (line <span class="hl num">34</span>).  Otherwise, the signs are assumed to 
be both positive and a forward direction unsigned comparison is performed.

<span class="hl kwa">\section</span>*<span class="hl opt">{</span>Exercises<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>cl<span class="hl opt">}</span>
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">2</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span>$ &amp; Modify algorithm mp<span class="hl kwa">\_set\_int</span> to accept as input a variable length array of bits. \\
                     &amp; \\
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">3</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span>$ &amp; Give the probability that algorithm mp<span class="hl kwa">\_cmp\_mag</span> will have to compare $k$ digits  \\
                     &amp; of two random digits (of equal magnitude) before a difference is found. \\
                     &amp; \\
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">1</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span>$ &amp; Suggest a simple method to speed up the implementation of mp<span class="hl kwa">\_cmp\_mag</span> based  \\
                     &amp; on the observations made in the previous problem. \\
                     &amp;
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>

<span class="hl kwa">\chapter</span><span class="hl opt">{</span>Basic Arithmetic<span class="hl opt">}</span>
<span class="hl kwa">\section</span><span class="hl opt">{</span>Introduction<span class="hl opt">}</span>
At this point algorithms for initialization, clearing, zeroing, copying, comparing and setting small constants have been 
established.  The next logical set of algorithms to develop are addition, subtraction and digit shifting algorithms.  These 
algorithms make use of the lower level algorithms and are the cruicial building block for the multiplication algorithms.  It is very important 
that these algorithms are highly optimized.  On their own they are simple $O(n)$ algorithms but they can be called from higher level algorithms 
which easily places them at $O(n^<span class="hl num">2</span>)$ or even $O(n^<span class="hl num">3</span>)$ work levels.  

All of the algorithms within this chapter make use of the logical bit shift operations denoted by $&lt;&lt;$ and $&gt;&gt;$ for left and right 
logical shifts respectively.  A logical shift is analogous to sliding the decimal point of radix-<span class="hl num">10</span> representations.  For example, the real 
number $<span class="hl num">0.9345</span>$ is equivalent to $<span class="hl num">93.45</span>\%$ which is found by sliding the the decimal two places to the right (<span class="hl kwa">\textit</span><span class="hl opt">{</span>multiplying by $<span class="hl kwa">\beta</span>^<span class="hl num">2</span> = <span class="hl num">10</span>^<span class="hl num">2</span>$<span class="hl opt">}</span>).  
Algebraically a binary logical shift is equivalent to a division or multiplication by a power of two.  
For example, $a &lt;&lt; k = a <span class="hl kwa">\cdot</span> <span class="hl num">2</span>^k$ while $a &gt;&gt; k = <span class="hl kwa">\lfloor</span> a/<span class="hl num">2</span>^k <span class="hl kwa">\rfloor</span>$.

One significant difference between a logical shift and the way decimals are shifted is that digits below the zero'th position are removed
from the number.  For example, consider $<span class="hl num">1101</span>_2 &gt;&gt; <span class="hl num">1</span>$ using decimal notation this would produce $<span class="hl num">110.1</span>_2$.  However, with a logical shift the 
result is $<span class="hl num">110</span>_2$.  

<span class="hl kwa">\section</span><span class="hl opt">{</span>Addition and Subtraction<span class="hl opt">}</span>
In common twos complement fixed precision arithmetic negative numbers are easily represented by subtraction from the modulus.  For example, with <span class="hl num">32</span>-bit integers
$a - b<span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">32</span><span class="hl opt">}</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ is the same as $a + (<span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">32</span><span class="hl opt">}</span> - b) <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">32</span><span class="hl opt">}</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$  since $<span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">32</span><span class="hl opt">}</span> <span class="hl kwa">\equiv</span> <span class="hl num">0</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">32</span><span class="hl opt">}</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$.  
As a result subtraction can be performed with a trivial series of logical operations and an addition.

However, in multiple precision arithmetic negative numbers are not represented in the same way.  Instead a sign flag is used to keep track of the
sign of the integer.  As a result signed addition and subtraction are actually implemented as conditional usage of lower level addition or 
subtraction algorithms with the sign fixed up appropriately.

The lower level algorithms will add or subtract integers without regard to the sign flag.  That is they will add or subtract the magnitude of
the integers respectively.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Low Level Addition<span class="hl opt">}</span>
An unsigned addition of multiple precision integers is performed with the same long-hand algorithm used to add decimal numbers.  That is to add the 
trailing digits first and propagate the resulting carry upwards.  Since this is a lower level algorithm the name will have a ``s<span class="hl kwa">\_</span>'' prefix.  
Historically that convention stems from the MPI library where ``s<span class="hl kwa">\_</span>'' stood for static functions that were hidden from the developer entirely.

<span class="hl kwa">\newpage</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>s<span class="hl kwa">\_mp\_add</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   Two mp<span class="hl kwa">\_ints</span> $a$ and $b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  The unsigned addition $c = <span class="hl kwa">\vert</span> a <span class="hl kwa">\vert</span> + <span class="hl kwa">\vert</span> b <span class="hl kwa">\vert</span>$. \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  if $a.used &gt; b.used$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.1</span>  $min <span class="hl kwa">\leftarrow</span> b.used$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.2</span>  $max <span class="hl kwa">\leftarrow</span> a.used$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.3</span>  $x   <span class="hl kwa">\leftarrow</span> a$ \\
<span class="hl num">2</span>.  else  \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  $min <span class="hl kwa">\leftarrow</span> a.used$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.2</span>  $max <span class="hl kwa">\leftarrow</span> b.used$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.3</span>  $x   <span class="hl kwa">\leftarrow</span> b$ \\
<span class="hl num">3</span>.  If $c.alloc &lt; max + <span class="hl num">1</span>$ then grow $c$ to hold at least $max + <span class="hl num">1</span>$ digits (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_grow</span><span class="hl opt">}</span>) \\
<span class="hl num">4</span>.  $oldused <span class="hl kwa">\leftarrow</span> c.used$ \\
<span class="hl num">5</span>.  $c.used <span class="hl kwa">\leftarrow</span> max + <span class="hl num">1</span>$ \\
<span class="hl num">6</span>.  $u <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">7</span>.  for $n$ from $<span class="hl num">0</span>$ to $min - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.1</span>  $c_n <span class="hl kwa">\leftarrow</span> a_n + b_n + u$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.2</span>  $u <span class="hl kwa">\leftarrow</span> c_n &gt;&gt; lg(<span class="hl kwa">\beta</span>)$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.3</span>  $c_n <span class="hl kwa">\leftarrow</span> c_n <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl num">8</span>.  if $min <span class="hl kwa">\ne</span> max$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">8.1</span>  for $n$ from $min$ to $max - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">8.1.1</span>  $c_n <span class="hl kwa">\leftarrow</span> x_n + u$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">8.1.2</span>  $u <span class="hl kwa">\leftarrow</span> c_n &gt;&gt; lg(<span class="hl kwa">\beta</span>)$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">8.1.3</span>  $c_n <span class="hl kwa">\leftarrow</span> c_n <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl num">9</span>.  $c_<span class="hl opt">{</span>max<span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> u$ \\
<span class="hl num">10</span>.  if $olduse &gt; max$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">10.1</span>  for $n$ from $max + <span class="hl num">1</span>$ to $oldused - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>+<span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">10.1.1</span>  $c_n <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">11</span>.  Clamp excess digits in $c$.  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_clamp</span><span class="hl opt">}</span>) \\
<span class="hl num">12</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm s<span class="hl kwa">\_mp\_add</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm s<span class="hl kwa">\_mp\_add</span>.<span class="hl opt">}</span>
This algorithm is loosely based on algorithm <span class="hl num">14.7</span> of HAC <span class="hl kwa">\cite</span><span class="hl opt">[</span>pp. <span class="hl num">594</span><span class="hl opt">]{</span>HAC<span class="hl opt">}</span> but has been extended to allow the inputs to have different magnitudes.  
Coincidentally the description of algorithm A in Knuth <span class="hl kwa">\cite</span><span class="hl opt">[</span>pp. <span class="hl num">266</span><span class="hl opt">]{</span>TAOCPV2<span class="hl opt">}</span> shares the same deficiency as the algorithm from <span class="hl kwa">\cite</span><span class="hl opt">{</span>HAC<span class="hl opt">}</span>.  Even the 
MIX pseudo  machine code presented by Knuth <span class="hl kwa">\cite</span><span class="hl opt">[</span>pp. <span class="hl num">266</span>-<span class="hl num">267</span><span class="hl opt">]{</span>TAOCPV2<span class="hl opt">}</span> is incapable of handling inputs which are of different magnitudes.

The first thing that has to be accomplished is to sort out which of the two inputs is the largest.  The addition logic
will simply add all of the smallest input to the largest input and store that first part of the result in the
destination.  Then it will apply a simpler addition loop to excess digits of the larger input.

The first two steps will handle sorting the inputs such that $min$ and $max$ hold the digit counts of the two 
inputs.  The variable $x$ will be an mp<span class="hl kwa">\_int</span> alias for the largest input or the second input $b$ if they have the
same number of digits.  After the inputs are sorted the destination $c$ is grown as required to accomodate the sum 
of the two inputs.  The original <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> count of $c$ is copied and set to the new used count.  

At this point the first addition loop will go through as many digit positions that both inputs have.  The carry
variable $<span class="hl kwa">\mu</span>$ is set to zero outside the loop.  Inside the loop an ``addition'' step requires three statements to produce
one digit of the summand.  First
two digits from $a$ and $b$ are added together along with the carry $<span class="hl kwa">\mu</span>$.  The carry of this step is extracted and stored
in $<span class="hl kwa">\mu</span>$ and finally the digit of the result $c_n$ is truncated within the range $<span class="hl num">0</span> <span class="hl kwa">\le</span> c_n &lt; <span class="hl kwa">\beta</span>$.

Now all of the digit positions that both inputs have in common have been exhausted.  If $min <span class="hl kwa">\ne</span> max$ then $x$ is an alias
for one of the inputs that has more digits.  A simplified addition loop is then used to essentially copy the remaining digits
and the carry to the destination.

The final carry is stored in $c_<span class="hl opt">{</span>max<span class="hl opt">}</span>$ and digits above $max$ upto $oldused$ are zeroed which completes the addition.


<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_s\_mp\_add</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

We first sort (lines <span class="hl num">28</span> to <span class="hl num">36</span>) the inputs based on magnitude and determine the $min$ and $max$ variables.
Note that $x$ is a pointer to an mp<span class="hl kwa">\_int</span> assigned to the largest input, in effect it is a local alias.  Next we
grow the destination (<span class="hl num">38</span> to <span class="hl num">42</span>) ensure that it can accomodate the result of the addition. 

Similar to the implementation of mp<span class="hl kwa">\_copy</span> this function uses the braced code and local aliases coding style.  The three aliases that are on 
lines <span class="hl num">56</span>, <span class="hl num">59</span> and <span class="hl num">62</span> represent the two inputs and destination variables respectively.  These aliases are used to ensure the
compiler does not have to dereference $a$, $b$ or $c$ (respectively) to access the digits of the respective mp<span class="hl kwa">\_int</span>.

The initial carry $u$ will be cleared (line <span class="hl num">65</span>), note that $u$ is of type mp<span class="hl kwa">\_digit</span> which ensures type 
compatibility within the implementation.  The initial addition (line <span class="hl num">66</span> to <span class="hl num">75</span>) adds digits from
both inputs until the smallest input runs out of digits.  Similarly the conditional addition loop
(line <span class="hl num">81</span> to <span class="hl num">90</span>) adds the remaining digits from the larger of the two inputs.  The addition is finished 
with the final carry being stored in $tmpc$ (line <span class="hl num">94</span>).  Note the ``++'' operator within the same expression.
After line <span class="hl num">94</span>, $tmpc$ will point to the $c.used$'th digit of the mp<span class="hl kwa">\_int</span> $c$.  This is useful
for the next loop (line <span class="hl num">97</span> to <span class="hl num">99</span>) which set any old upper digits to zero.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Low Level Subtraction<span class="hl opt">}</span>
The low level unsigned subtraction algorithm is very similar to the low level unsigned addition algorithm.  The principle difference is that the
unsigned subtraction algorithm requires the result to be positive.  That is when computing $a - b$ the condition $<span class="hl kwa">\vert</span> a <span class="hl kwa">\vert \ge \vert</span> b<span class="hl kwa">\vert</span>$ must 
be met for this algorithm to function properly.  Keep in mind this low level algorithm is not meant to be used in higher level algorithms directly.  
This algorithm as will be shown can be used to create functional signed addition and subtraction algorithms.


For this algorithm a new variable is required to make the description simpler.  Recall from section <span class="hl num">1.3.1</span> that a mp<span class="hl kwa">\_digit</span> must be able to represent
the range $<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; <span class="hl num">2</span><span class="hl kwa">\beta</span>$ for the algorithms to work correctly.  However, it is allowable that a mp<span class="hl kwa">\_digit</span> represent a larger range of values.  For 
this algorithm we will assume that the variable $<span class="hl kwa">\gamma</span>$ represents the number of bits available in a 
mp<span class="hl kwa">\_digit</span> (<span class="hl kwa">\textit</span><span class="hl opt">{</span>this implies $<span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl kwa">\gamma</span><span class="hl opt">}</span> &gt; <span class="hl kwa">\beta</span>$<span class="hl opt">}</span>).  

For example, the default for LibTomMath is to use a ``unsigned long'' for the mp<span class="hl kwa">\_digit</span> ``type'' while $<span class="hl kwa">\beta</span> = <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">28</span><span class="hl opt">}</span>$.  In ISO C an ``unsigned long''
data type must be able to represent $<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">32</span><span class="hl opt">}</span>$ meaning that in this case $<span class="hl kwa">\gamma \ge</span> <span class="hl num">32</span>$.

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>s<span class="hl kwa">\_mp\_sub</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   Two mp<span class="hl kwa">\_ints</span> $a$ and $b$ ($<span class="hl kwa">\vert</span> a <span class="hl kwa">\vert \ge \vert</span> b <span class="hl kwa">\vert</span>$) \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  The unsigned subtraction $c = <span class="hl kwa">\vert</span> a <span class="hl kwa">\vert</span> - <span class="hl kwa">\vert</span> b <span class="hl kwa">\vert</span>$. \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $min <span class="hl kwa">\leftarrow</span> b.used$ \\
<span class="hl num">2</span>.  $max <span class="hl kwa">\leftarrow</span> a.used$ \\
<span class="hl num">3</span>.  If $c.alloc &lt; max$ then grow $c$ to hold at least $max$ digits.  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_grow</span><span class="hl opt">}</span>) \\
<span class="hl num">4</span>.  $oldused <span class="hl kwa">\leftarrow</span> c.used$ \\ 
<span class="hl num">5</span>.  $c.used <span class="hl kwa">\leftarrow</span> max$ \\
<span class="hl num">6</span>.  $u <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">7</span>.  for $n$ from $<span class="hl num">0</span>$ to $min - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.1</span>  $c_n <span class="hl kwa">\leftarrow</span> a_n - b_n - u$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.2</span>  $u   <span class="hl kwa">\leftarrow</span> c_n &gt;&gt; (<span class="hl kwa">\gamma</span> - <span class="hl num">1</span>)$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.3</span>  $c_n <span class="hl kwa">\leftarrow</span> c_n <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl num">8</span>.  if $min &lt; max$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">8.1</span>  for $n$ from $min$ to $max - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">8.1.1</span>  $c_n <span class="hl kwa">\leftarrow</span> a_n - u$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">8.1.2</span>  $u   <span class="hl kwa">\leftarrow</span> c_n &gt;&gt; (<span class="hl kwa">\gamma</span> - <span class="hl num">1</span>)$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">8.1.3</span>  $c_n <span class="hl kwa">\leftarrow</span> c_n <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl num">9</span>. if $oldused &gt; max$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">9.1</span>  for $n$ from $max$ to $oldused - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">9.1.1</span>  $c_n <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">10</span>. Clamp excess digits of $c$.  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_clamp</span><span class="hl opt">}</span>). \\
<span class="hl num">11</span>. Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm s<span class="hl kwa">\_mp\_sub</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm s<span class="hl kwa">\_mp\_sub</span>.<span class="hl opt">}</span>
This algorithm performs the unsigned subtraction of two mp<span class="hl kwa">\_int</span> variables under the restriction that the result must be positive.  That is when
passing variables $a$ and $b$ the condition that $<span class="hl kwa">\vert</span> a <span class="hl kwa">\vert \ge \vert</span> b <span class="hl kwa">\vert</span>$ must be met for the algorithm to function correctly.  This
algorithm is loosely based on algorithm <span class="hl num">14.9</span> <span class="hl kwa">\cite</span><span class="hl opt">[</span>pp. <span class="hl num">595</span><span class="hl opt">]{</span>HAC<span class="hl opt">}</span> and is similar to algorithm S in <span class="hl kwa">\cite</span><span class="hl opt">[</span>pp. <span class="hl num">267</span><span class="hl opt">]{</span>TAOCPV2<span class="hl opt">}</span> as well.  As was the case
of the algorithm s<span class="hl kwa">\_mp\_add</span> both other references lack discussion concerning various practical details such as when the inputs differ in magnitude.

The initial sorting of the inputs is trivial in this algorithm since $a$ is guaranteed to have at least the same magnitude of $b$.  Steps <span class="hl num">1</span> and <span class="hl num">2</span> 
set the $min$ and $max$ variables.  Unlike the addition routine there is guaranteed to be no carry which means that the final result can be at 
most $max$ digits in length as opposed to $max + <span class="hl num">1</span>$.  Similar to the addition algorithm the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> count of $c$ is copied locally and 
set to the maximal count for the operation.

The subtraction loop that begins on step seven is essentially the same as the addition loop of algorithm s<span class="hl kwa">\_mp\_add</span> except single precision 
subtraction is used instead.  Note the use of the $<span class="hl kwa">\gamma</span>$ variable to extract the carry (<span class="hl kwa">\textit</span><span class="hl opt">{</span>also known as the borrow<span class="hl opt">}</span>) within the subtraction 
loops.  Under the assumption that two's complement single precision arithmetic is used this will successfully extract the desired carry.  

For example, consider subtracting $<span class="hl num">0101</span>_2$ from $<span class="hl num">0100</span>_2$ where $<span class="hl kwa">\gamma</span> = <span class="hl num">4</span>$ and $<span class="hl kwa">\beta</span> = <span class="hl num">2</span>$.  The least significant bit will force a carry upwards to 
the third bit which will be set to zero after the borrow.  After the very first bit has been subtracted $<span class="hl num">4</span> - <span class="hl num">1</span> <span class="hl kwa">\equiv</span> <span class="hl num">0011</span>_2$ will remain,  When the 
third bit of $<span class="hl num">0101</span>_2$ is subtracted from the result it will cause another carry.  In this case though the carry will be forced to propagate all the 
way to the most significant bit.  

Recall that $<span class="hl kwa">\beta</span> &lt; <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl kwa">\gamma</span><span class="hl opt">}</span>$.  This means that if a carry does occur just before the $lg(<span class="hl kwa">\beta</span>)$'th bit it will propagate all the way to the most 
significant bit.  Thus, the high order bits of the mp<span class="hl kwa">\_digit</span> that are not part of the actual digit will either be all zero, or all one. All that
is needed is a single zero or one bit for the carry.  Therefore a single logical shift right by $<span class="hl kwa">\gamma</span> - <span class="hl num">1</span>$ positions is sufficient to extract the 
carry.  This method of carry extraction may seem awkward but the reason for it becomes apparent when the implementation is discussed.  

If $b$ has a smaller magnitude than $a$ then step <span class="hl num">9</span> will force the carry and copy operation to propagate through the larger input $a$ into $c$.  Step
<span class="hl num">10</span> will ensure that any leading digits of $c$ above the $max$'th position are zeroed.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_s\_mp\_sub</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

Like low level addition we ``sort'' the inputs.  Except in this case the sorting is hardcoded 
(lines <span class="hl num">25</span> and <span class="hl num">26</span>).  In reality the $min$ and $max$ variables are only aliases and are only 
used to make the source code easier to read.  Again the pointer alias optimization is used 
within this algorithm.  The aliases $tmpa$, $tmpb$ and $tmpc$ are initialized
(lines <span class="hl num">42</span>, <span class="hl num">43</span> and <span class="hl num">44</span>) for $a$, $b$ and $c$ respectively.

The first subtraction loop (lines <span class="hl num">47</span> through <span class="hl num">61</span>) subtract digits from both inputs until the smaller of
the two inputs has been exhausted.  As remarked earlier there is an implementation reason for using the ``awkward'' 
method of extracting the carry (line <span class="hl num">57</span>).  The traditional method for extracting the carry would be to shift 
by $lg(<span class="hl kwa">\beta</span>)$ positions and logically AND the least significant bit.  The AND operation is required because all of 
the bits above the $<span class="hl kwa">\lg</span>(<span class="hl kwa">\beta</span>)$'th bit will be set to one after a carry occurs from subtraction.  This carry 
extraction requires two relatively cheap operations to extract the carry.  The other method is to simply shift the 
most significant bit to the least significant bit thus extracting the carry with a single cheap operation.  This 
optimization only works on twos compliment machines which is a safe assumption to make.

If $a$ has a larger magnitude than $b$ an additional loop (lines <span class="hl num">64</span> through <span class="hl num">73</span>) is required to propagate 
the carry through $a$ and copy the result to $c$.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>High Level Addition<span class="hl opt">}</span>
Now that both lower level addition and subtraction algorithms have been established an effective high level signed addition algorithm can be
established.  This high level addition algorithm will be what other algorithms and developers will use to perform addition of mp<span class="hl kwa">\_int</span> data 
types.  

Recall from section <span class="hl num">5.2</span> that an mp<span class="hl kwa">\_int</span> represents an integer with an unsigned mantissa (<span class="hl kwa">\textit</span><span class="hl opt">{</span>the array of digits<span class="hl opt">}</span>) and a <span class="hl kwa">\textbf</span><span class="hl opt">{</span>sign<span class="hl opt">}</span> 
flag.  A high level addition is actually performed as a series of eight separate cases which can be optimized down to three unique cases.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_add</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   Two mp<span class="hl kwa">\_ints</span> $a$ and $b$  \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  The signed addition $c = a + b$. \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  if $a.sign = b.sign$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.1</span>  $c.sign <span class="hl kwa">\leftarrow</span> a.sign$  \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.2</span>  $c <span class="hl kwa">\leftarrow \vert</span> a <span class="hl kwa">\vert</span> + <span class="hl kwa">\vert</span> b <span class="hl kwa">\vert</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>s<span class="hl kwa">\_mp\_add</span><span class="hl opt">}</span>)\\
<span class="hl num">2</span>.  else do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  if $<span class="hl kwa">\vert</span> a <span class="hl kwa">\vert</span> &lt; <span class="hl kwa">\vert</span> b <span class="hl kwa">\vert</span>$ then do (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_cmp\_mag</span><span class="hl opt">}</span>)  \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">2.1.1</span>  $c.sign <span class="hl kwa">\leftarrow</span> b.sign$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">2.1.2</span>  $c <span class="hl kwa">\leftarrow \vert</span> b <span class="hl kwa">\vert</span> - <span class="hl kwa">\vert</span> a <span class="hl kwa">\vert</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>s<span class="hl kwa">\_mp\_sub</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.2</span>  else do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">2.2.1</span>  $c.sign <span class="hl kwa">\leftarrow</span> a.sign$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">2.2.2</span>  $c <span class="hl kwa">\leftarrow \vert</span> a <span class="hl kwa">\vert</span> - <span class="hl kwa">\vert</span> b <span class="hl kwa">\vert</span>$ \\
<span class="hl num">3</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_add</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_add</span>.<span class="hl opt">}</span>
This algorithm performs the signed addition of two mp<span class="hl kwa">\_int</span> variables.  There is no reference algorithm to draw upon from 
either <span class="hl kwa">\cite</span><span class="hl opt">{</span>TAOCPV2<span class="hl opt">}</span> or <span class="hl kwa">\cite</span><span class="hl opt">{</span>HAC<span class="hl opt">}</span> since they both only provide unsigned operations.  The algorithm is fairly 
straightforward but restricted since subtraction can only produce positive results.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>|c|c|c|c|c|<span class="hl opt">}</span>
<span class="hl kwa">\hline \textbf</span><span class="hl opt">{</span>Sign of $a$<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Sign of $b$<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>$<span class="hl kwa">\vert</span> a <span class="hl kwa">\vert</span> &gt; <span class="hl kwa">\vert</span> b <span class="hl kwa">\vert</span> $<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Unsigned Operation<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Result Sign Flag<span class="hl opt">}</span> \\
<span class="hl kwa">\hline</span> $+$ &amp; $+$ &amp; Yes &amp; $c = a + b$ &amp; $a.sign$ \\
<span class="hl kwa">\hline</span> $+$ &amp; $+$ &amp; No  &amp; $c = a + b$ &amp; $a.sign$ \\
<span class="hl kwa">\hline</span> $-$ &amp; $-$ &amp; Yes &amp; $c = a + b$ &amp; $a.sign$ \\
<span class="hl kwa">\hline</span> $-$ &amp; $-$ &amp; No  &amp; $c = a + b$ &amp; $a.sign$ \\
<span class="hl kwa">\hline</span> &amp;&amp;&amp;&amp;\\

<span class="hl kwa">\hline</span> $+$ &amp; $-$ &amp; No  &amp; $c = b - a$ &amp; $b.sign$ \\
<span class="hl kwa">\hline</span> $-$ &amp; $+$ &amp; No  &amp; $c = b - a$ &amp; $b.sign$ \\

<span class="hl kwa">\hline</span> &amp;&amp;&amp;&amp;\\

<span class="hl kwa">\hline</span> $+$ &amp; $-$ &amp; Yes &amp; $c = a - b$ &amp; $a.sign$ \\
<span class="hl kwa">\hline</span> $-$ &amp; $+$ &amp; Yes &amp; $c = a - b$ &amp; $a.sign$ \\

<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Addition Guide Chart<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>fig:AddChart<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

Figure~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:AddChart<span class="hl opt">}</span> lists all of the eight possible input combinations and is sorted to show that only three 
specific cases need to be handled.  The return code of the unsigned operations at step <span class="hl num">1.2</span>, <span class="hl num">2.1.2</span> and <span class="hl num">2.2.2</span> are 
forwarded to step three to check for errors.  This simplifies the description of the algorithm considerably and best 
follows how the implementation actually was achieved.

Also note how the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>sign<span class="hl opt">}</span> is set before the unsigned addition or subtraction is performed.  Recall from the descriptions of algorithms
s<span class="hl kwa">\_mp\_add</span> and s<span class="hl kwa">\_mp\_sub</span> that the mp<span class="hl kwa">\_clamp</span> function is used at the end to trim excess digits.  The mp<span class="hl kwa">\_clamp</span> algorithm will set the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>sign<span class="hl opt">}</span>
to <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_ZPOS</span><span class="hl opt">}</span> when the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> digit count reaches zero.

For example, consider performing $-a + a$ with algorithm mp<span class="hl kwa">\_add</span>.  By the description of the algorithm the sign is set to <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_NEG</span><span class="hl opt">}</span> which would
produce a result of $-<span class="hl num">0</span>$.  However, since the sign is set first then the unsigned addition is performed the subsequent usage of algorithm mp<span class="hl kwa">\_clamp</span> 
within algorithm s<span class="hl kwa">\_mp\_add</span> will force $-<span class="hl num">0</span>$ to become $<span class="hl num">0</span>$.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_add</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

The source code follows the algorithm fairly closely.  The most notable new source code addition is the usage of the $res$ integer variable which
is used to pass result of the unsigned operations forward.  Unlike in the algorithm, the variable $res$ is merely returned as is without
explicitly checking it and returning the constant <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>.  The observation is this algorithm will succeed or fail only if the lower
level functions do so.  Returning their return code is sufficient.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>High Level Subtraction<span class="hl opt">}</span>
The high level signed subtraction algorithm is essentially the same as the high level signed addition algorithm.  

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_sub</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   Two mp<span class="hl kwa">\_ints</span> $a$ and $b$  \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  The signed subtraction $c = a - b$. \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  if $a.sign <span class="hl kwa">\ne</span> b.sign$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.1</span>  $c.sign <span class="hl kwa">\leftarrow</span> a.sign$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.2</span>  $c <span class="hl kwa">\leftarrow \vert</span> a <span class="hl kwa">\vert</span> + <span class="hl kwa">\vert</span> b <span class="hl kwa">\vert</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>s<span class="hl kwa">\_mp\_add</span><span class="hl opt">}</span>) \\
<span class="hl num">2</span>.  else do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  if $<span class="hl kwa">\vert</span> a <span class="hl kwa">\vert \ge \vert</span> b <span class="hl kwa">\vert</span>$ then do (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_cmp\_mag</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">2.1.1</span>  $c.sign <span class="hl kwa">\leftarrow</span> a.sign$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">2.1.2</span>  $c <span class="hl kwa">\leftarrow \vert</span> a <span class="hl kwa">\vert</span>  - <span class="hl kwa">\vert</span> b <span class="hl kwa">\vert</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>s<span class="hl kwa">\_mp\_sub</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.2</span>  else do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">2.2.1</span>  $c.sign <span class="hl kwa">\leftarrow  \left \lbrace \begin</span><span class="hl opt">{</span>array<span class="hl opt">}{</span>ll<span class="hl opt">}</span>
                              MP<span class="hl kwa">\_ZPOS</span> &amp;  <span class="hl kwa">\mbox</span><span class="hl opt">{</span>if <span class="hl opt">}</span>a.sign = MP<span class="hl kwa">\_NEG</span> \\
                              MP<span class="hl kwa">\_NEG</span>  &amp;  <span class="hl kwa">\mbox</span><span class="hl opt">{</span>otherwise<span class="hl opt">}</span> \\
                              <span class="hl kwa">\end</span><span class="hl opt">{</span>array<span class="hl opt">}</span> <span class="hl kwa">\right</span> .$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">2.2.2</span>  $c <span class="hl kwa">\leftarrow \vert</span> b <span class="hl kwa">\vert</span>  - <span class="hl kwa">\vert</span> a <span class="hl kwa">\vert</span>$ \\
<span class="hl num">3</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_sub</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_sub</span>.<span class="hl opt">}</span>
This algorithm performs the signed subtraction of two inputs.  Similar to algorithm mp<span class="hl kwa">\_add</span> there is no reference in either <span class="hl kwa">\cite</span><span class="hl opt">{</span>TAOCPV2<span class="hl opt">}</span> or 
<span class="hl kwa">\cite</span><span class="hl opt">{</span>HAC<span class="hl opt">}</span>.  Also this algorithm is restricted by algorithm s<span class="hl kwa">\_mp\_sub</span>.  Chart <span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:SubChart<span class="hl opt">}</span> lists the eight possible inputs and
the operations required.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>|c|c|c|c|c|<span class="hl opt">}</span>
<span class="hl kwa">\hline \textbf</span><span class="hl opt">{</span>Sign of $a$<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Sign of $b$<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>$<span class="hl kwa">\vert</span> a <span class="hl kwa">\vert \ge \vert</span> b <span class="hl kwa">\vert</span> $<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Unsigned Operation<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Result Sign Flag<span class="hl opt">}</span> \\
<span class="hl kwa">\hline</span> $+$ &amp; $-$ &amp; Yes &amp; $c = a + b$ &amp; $a.sign$ \\
<span class="hl kwa">\hline</span> $+$ &amp; $-$ &amp; No  &amp; $c = a + b$ &amp; $a.sign$ \\
<span class="hl kwa">\hline</span> $-$ &amp; $+$ &amp; Yes &amp; $c = a + b$ &amp; $a.sign$ \\
<span class="hl kwa">\hline</span> $-$ &amp; $+$ &amp; No  &amp; $c = a + b$ &amp; $a.sign$ \\
<span class="hl kwa">\hline</span> &amp;&amp;&amp;&amp; \\
<span class="hl kwa">\hline</span> $+$ &amp; $+$ &amp; Yes &amp; $c = a - b$ &amp; $a.sign$ \\
<span class="hl kwa">\hline</span> $-$ &amp; $-$ &amp; Yes &amp; $c = a - b$ &amp; $a.sign$ \\
<span class="hl kwa">\hline</span> &amp;&amp;&amp;&amp; \\
<span class="hl kwa">\hline</span> $+$ &amp; $+$ &amp; No  &amp; $c = b - a$ &amp; $<span class="hl kwa">\mbox</span><span class="hl opt">{</span>opposite of <span class="hl opt">}</span>a.sign$ \\
<span class="hl kwa">\hline</span> $-$ &amp; $-$ &amp; No  &amp; $c = b - a$ &amp; $<span class="hl kwa">\mbox</span><span class="hl opt">{</span>opposite of <span class="hl opt">}</span>a.sign$ \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Subtraction Guide Chart<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>fig:SubChart<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

Similar to the case of algorithm mp<span class="hl kwa">\_add</span> the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>sign<span class="hl opt">}</span> is set first before the unsigned addition or subtraction.  That is to prevent the 
algorithm from producing $-a - -a = -<span class="hl num">0</span>$ as a result.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_sub</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

Much like the implementation of algorithm mp<span class="hl kwa">\_add</span> the variable $res$ is used to catch the return code of the unsigned addition or subtraction operations
and forward it to the end of the function.  On line <span class="hl num">39</span> the ``not equal to'' <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_LT</span><span class="hl opt">}</span> expression is used to emulate a 
``greater than or equal to'' comparison.  

<span class="hl kwa">\section</span><span class="hl opt">{</span>Bit and Digit Shifting<span class="hl opt">}</span>
It is quite common to think of a multiple precision integer as a polynomial in $x$, that is $y = f(<span class="hl kwa">\beta</span>)$ where $f(x) = <span class="hl kwa">\sum_</span><span class="hl opt">{</span>i=<span class="hl num">0</span><span class="hl opt">}</span>^<span class="hl opt">{</span>n-<span class="hl num">1</span><span class="hl opt">}</span> a_i x^i$.  
This notation arises within discussion of Montgomery and Diminished Radix Reduction as well as Karatsuba multiplication and squaring.  

In order to facilitate operations on polynomials in $x$ as above a series of simple ``digit'' algorithms have to be established.  That is to shift
the digits left or right as well to shift individual bits of the digits left and right.  It is important to note that not all ``shift'' operations
are on radix-$<span class="hl kwa">\beta</span>$ digits.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Multiplication by Two<span class="hl opt">}</span>

In a binary system where the radix is a power of two multiplication by two not only arises often in other algorithms it is a fairly efficient 
operation to perform.  A single precision logical shift left is sufficient to multiply a single digit by two.  

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_mul\_2</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   One mp<span class="hl kwa">\_int</span> $a$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $b = <span class="hl num">2</span>a$. \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  If $b.alloc &lt; a.used + <span class="hl num">1</span>$ then grow $b$ to hold $a.used + <span class="hl num">1</span>$ digits.  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_grow</span><span class="hl opt">}</span>) \\
<span class="hl num">2</span>.  $oldused <span class="hl kwa">\leftarrow</span> b.used$ \\
<span class="hl num">3</span>.  $b.used <span class="hl kwa">\leftarrow</span> a.used$ \\
<span class="hl num">4</span>.  $r <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">5</span>.  for $n$ from <span class="hl num">0</span> to $a.used - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.1</span>  $rr <span class="hl kwa">\leftarrow</span> a_n &gt;&gt; (lg(<span class="hl kwa">\beta</span>) - <span class="hl num">1</span>)$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.2</span>  $b_n <span class="hl kwa">\leftarrow</span> (a_n &lt;&lt; <span class="hl num">1</span>) + r <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.3</span>  $r <span class="hl kwa">\leftarrow</span> rr$ \\
<span class="hl num">6</span>.  If $r <span class="hl kwa">\ne</span> <span class="hl num">0</span>$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.1</span>  $b_<span class="hl opt">{</span>n + <span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> r$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.2</span>  $b.used <span class="hl kwa">\leftarrow</span> b.used + <span class="hl num">1</span>$ \\
<span class="hl num">7</span>.  If $b.used &lt; oldused - <span class="hl num">1</span>$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.1</span>  for $n$ from $b.used$ to $oldused - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">7.1.1</span>  $b_n <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">8</span>.  $b.sign <span class="hl kwa">\leftarrow</span> a.sign$ \\
<span class="hl num">9</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>).\\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_mul\_2</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_mul\_2</span>.<span class="hl opt">}</span>
This algorithm will quickly multiply a mp<span class="hl kwa">\_int</span> by two provided $<span class="hl kwa">\beta</span>$ is a power of two.  Neither <span class="hl kwa">\cite</span><span class="hl opt">{</span>TAOCPV2<span class="hl opt">}</span> nor <span class="hl kwa">\cite</span><span class="hl opt">{</span>HAC<span class="hl opt">}</span> describe such 
an algorithm despite the fact it arises often in other algorithms.  The algorithm is setup much like the lower level algorithm s<span class="hl kwa">\_mp\_add</span> since 
it is for all intents and purposes equivalent to the operation $b = <span class="hl kwa">\vert</span> a <span class="hl kwa">\vert</span> + <span class="hl kwa">\vert</span> a <span class="hl kwa">\vert</span>$.  

Step <span class="hl num">1</span> and <span class="hl num">2</span> grow the input as required to accomodate the maximum number of <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> digits in the result.  The initial <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> count
is set to $a.used$ at step <span class="hl num">4</span>.  Only if there is a final carry will the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> count require adjustment.

Step <span class="hl num">6</span> is an optimization implementation of the addition loop for this specific case.  That is since the two values being added together 
are the same there is no need to perform two reads from the digits of $a$.  Step <span class="hl num">6.1</span> performs a single precision shift on the current digit $a_n$ to
obtain what will be the carry for the next iteration.  Step <span class="hl num">6.2</span> calculates the $n$'th digit of the result as single precision shift of $a_n$ plus
the previous carry.  Recall from section <span class="hl num">4.1</span> that $a_n &lt;&lt; <span class="hl num">1</span>$ is equivalent to $a_n <span class="hl kwa">\cdot</span> <span class="hl num">2</span>$.  An iteration of the addition loop is finished with 
forwarding the carry to the next iteration.

Step <span class="hl num">7</span> takes care of any final carry by setting the $a.used$'th digit of the result to the carry and augmenting the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> count of $b$.  
Step <span class="hl num">8</span> clears any leading digits of $b$ in case it originally had a larger magnitude than $a$.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_mul\_2</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

This implementation is essentially an optimized implementation of s<span class="hl kwa">\_mp\_add</span> for the case of doubling an input.  The only noteworthy difference
is the use of the logical shift operator on line <span class="hl num">52</span> to perform a single precision doubling.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Division by Two<span class="hl opt">}</span>
A division by two can just as easily be accomplished with a logical shift right as multiplication by two can be with a logical shift left.

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_div\_2</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   One mp<span class="hl kwa">\_int</span> $a$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $b = a/<span class="hl num">2</span>$. \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  If $b.alloc &lt; a.used$ then grow $b$ to hold $a.used$ digits.  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_grow</span><span class="hl opt">}</span>) \\
<span class="hl num">2</span>.  If the reallocation failed return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_MEM</span><span class="hl opt">}</span>). \\
<span class="hl num">3</span>.  $oldused <span class="hl kwa">\leftarrow</span> b.used$ \\
<span class="hl num">4</span>.  $b.used <span class="hl kwa">\leftarrow</span> a.used$ \\
<span class="hl num">5</span>.  $r <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">6</span>.  for $n$ from $b.used - <span class="hl num">1</span>$ to $<span class="hl num">0</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.1</span>  $rr <span class="hl kwa">\leftarrow</span> a_n <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$\\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.2</span>  $b_n <span class="hl kwa">\leftarrow</span> (a_n &gt;&gt; <span class="hl num">1</span>) + (r &lt;&lt; (lg(<span class="hl kwa">\beta</span>) - <span class="hl num">1</span>)) <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.3</span>  $r <span class="hl kwa">\leftarrow</span> rr$ \\
<span class="hl num">7</span>.  If $b.used &lt; oldused - <span class="hl num">1</span>$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.1</span>  for $n$ from $b.used$ to $oldused - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">7.1.1</span>  $b_n <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">8</span>.  $b.sign <span class="hl kwa">\leftarrow</span> a.sign$ \\
<span class="hl num">9</span>.  Clamp excess digits of $b$.  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_clamp</span><span class="hl opt">}</span>) \\
<span class="hl num">10</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>).\\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_div\_2</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_div\_2</span>.<span class="hl opt">}</span>
This algorithm will divide an mp<span class="hl kwa">\_int</span> by two using logical shifts to the right.  Like mp<span class="hl kwa">\_mul\_2</span> it uses a modified low level addition
core as the basis of the algorithm.  Unlike mp<span class="hl kwa">\_mul\_2</span> the shift operations work from the leading digit to the trailing digit.  The algorithm
could be written to work from the trailing digit to the leading digit however, it would have to stop one short of $a.used - <span class="hl num">1</span>$ digits to prevent
reading past the end of the array of digits.

Essentially the loop at step <span class="hl num">6</span> is similar to that of mp<span class="hl kwa">\_mul\_2</span> except the logical shifts go in the opposite direction and the carry is at the 
least significant bit not the most significant bit.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_div\_2</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

<span class="hl kwa">\section</span><span class="hl opt">{</span>Polynomial Basis Operations<span class="hl opt">}</span>
Recall from section <span class="hl num">4.3</span> that any integer can be represented as a polynomial in $x$ as $y = f(<span class="hl kwa">\beta</span>)$.  Such a representation is also known as
the polynomial basis <span class="hl kwa">\cite</span><span class="hl opt">[</span>pp. <span class="hl num">48</span><span class="hl opt">]{</span>ROSE<span class="hl opt">}</span>. Given such a notation a multiplication or division by $x$ amounts to shifting whole digits a single 
place.  The need for such operations arises in several other higher level algorithms such as Barrett and Montgomery reduction, integer
division and Karatsuba multiplication.  

Converting from an array of digits to polynomial basis is very simple.  Consider the integer $y <span class="hl kwa">\equiv</span> (a_2, a_1, a_0)_<span class="hl opt">{</span><span class="hl kwa">\beta</span><span class="hl opt">}</span>$ and recall that
$y = <span class="hl kwa">\sum_</span><span class="hl opt">{</span>i=<span class="hl num">0</span><span class="hl opt">}</span>^<span class="hl opt">{</span><span class="hl num">2</span><span class="hl opt">}</span> a_i <span class="hl kwa">\beta</span>^i$.  Simply replace $<span class="hl kwa">\beta</span>$ with $x$ and the expression is in polynomial basis.  For example, $f(x) = <span class="hl num">8</span>x + <span class="hl num">9</span>$ is the
polynomial basis representation for $<span class="hl num">89</span>$ using radix ten.  That is, $f(<span class="hl num">10</span>) = <span class="hl num">8</span>(<span class="hl num">10</span>) + <span class="hl num">9</span> = <span class="hl num">89</span>$.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Multiplication by $x$<span class="hl opt">}</span>

Given a polynomial in $x$ such as $f(x) = a_n x^n + a_<span class="hl opt">{</span>n-<span class="hl num">1</span><span class="hl opt">}</span> x^<span class="hl opt">{</span>n-<span class="hl num">1</span><span class="hl opt">}</span> + ... + a_0$ multiplying by $x$ amounts to shifting the coefficients up one 
degree.  In this case $f(x) <span class="hl kwa">\cdot</span> x = a_n x^<span class="hl opt">{</span>n+<span class="hl num">1</span><span class="hl opt">}</span> + a_<span class="hl opt">{</span>n-<span class="hl num">1</span><span class="hl opt">}</span> x^n + ... + a_0 x$.  From a scalar basis point of view multiplying by $x$ is equivalent to
multiplying by the integer $<span class="hl kwa">\beta</span>$.  

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_lshd</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   One mp<span class="hl kwa">\_int</span> $a$ and an integer $b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $a <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\cdot \beta</span>^b$ (equivalent to multiplication by $x^b$). \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  If $b <span class="hl kwa">\le</span> <span class="hl num">0</span>$ then return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl num">2</span>.  If $a.alloc &lt; a.used + b$ then grow $a$ to at least $a.used + b$ digits.  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_grow</span><span class="hl opt">}</span>). \\
<span class="hl num">3</span>.  If the reallocation failed return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_MEM</span><span class="hl opt">}</span>). \\
<span class="hl num">4</span>.  $a.used <span class="hl kwa">\leftarrow</span> a.used + b$ \\
<span class="hl num">5</span>.  $i <span class="hl kwa">\leftarrow</span> a.used - <span class="hl num">1</span>$ \\
<span class="hl num">6</span>.  $j <span class="hl kwa">\leftarrow</span> a.used - <span class="hl num">1</span> - b$ \\
<span class="hl num">7</span>.  for $n$ from $a.used - <span class="hl num">1</span>$ to $b$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.1</span>  $a_<span class="hl opt">{</span>i<span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> a_<span class="hl opt">{</span>j<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.2</span>  $i <span class="hl kwa">\leftarrow</span> i - <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.3</span>  $j <span class="hl kwa">\leftarrow</span> j - <span class="hl num">1</span>$ \\
<span class="hl num">8</span>.  for $n$ from <span class="hl num">0</span> to $b - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">8.1</span>  $a_n <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">9</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_lshd</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_lshd</span>.<span class="hl opt">}</span>
This algorithm multiplies an mp<span class="hl kwa">\_int</span> by the $b$'th power of $x$.  This is equivalent to multiplying by $<span class="hl kwa">\beta</span>^b$.  The algorithm differs 
from the other algorithms presented so far as it performs the operation in place instead storing the result in a separate location.  The
motivation behind this change is due to the way this function is typically used.  Algorithms such as mp<span class="hl kwa">\_add</span> store the result in an optionally
different third mp<span class="hl kwa">\_int</span> because the original inputs are often still required.  Algorithm mp<span class="hl kwa">\_lshd</span> (<span class="hl kwa">\textit</span><span class="hl opt">{</span>and similarly algorithm mp<span class="hl kwa">\_rshd</span><span class="hl opt">}</span>) is
typically used on values where the original value is no longer required.  The algorithm will return success immediately if 
$b <span class="hl kwa">\le</span> <span class="hl num">0</span>$ since the rest of algorithm is only valid when $b &gt; <span class="hl num">0</span>$.  

First the destination $a$ is grown as required to accomodate the result.  The counters $i$ and $j$ are used to form a <span class="hl kwa">\textit</span><span class="hl opt">{</span>sliding window<span class="hl opt">}</span> over
the digits of $a$ of length $b$.  The head of the sliding window is at $i$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>the leading digit<span class="hl opt">}</span>) and the tail at $j$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>the trailing digit<span class="hl opt">}</span>).  
The loop on step <span class="hl num">7</span> copies the digit from the tail to the head.  In each iteration the window is moved down one digit.   The last loop on 
step <span class="hl num">8</span> sets the lower $b$ digits to zero.

<span class="hl kwa">\newpage</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\includegraphics</span><span class="hl opt">{</span>pics/sliding_window.ps<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Sliding Window Movement<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>pic:sliding_window<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_lshd</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

The if statement (line <span class="hl num">24</span>) ensures that the $b$ variable is greater than zero since we do not interpret negative
shift counts properly.  The <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> count is incremented by $b$ before the copy loop begins.  This elminates 
the need for an additional variable in the for loop.  The variable $top$ (line <span class="hl num">42</span>) is an alias
for the leading digit while $bottom$ (line <span class="hl num">45</span>) is an alias for the trailing edge.  The aliases form a 
window of exactly $b$ digits over the input.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Division by $x$<span class="hl opt">}</span>

Division by powers of $x$ is easily achieved by shifting the digits right and removing any that will end up to the right of the zero'th digit.  

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_rshd</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   One mp<span class="hl kwa">\_int</span> $a$ and an integer $b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $a <span class="hl kwa">\leftarrow</span> a / <span class="hl kwa">\beta</span>^b$ (Divide by $x^b$). \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  If $b <span class="hl kwa">\le</span> <span class="hl num">0</span>$ then return. \\
<span class="hl num">2</span>.  If $a.used <span class="hl kwa">\le</span> b$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  Zero $a$.  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_zero</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.2</span>  Return. \\
<span class="hl num">3</span>.  $i <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">4</span>.  $j <span class="hl kwa">\leftarrow</span> b$ \\
<span class="hl num">5</span>.  for $n$ from <span class="hl num">0</span> to $a.used - b - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.1</span>  $a_i <span class="hl kwa">\leftarrow</span> a_j$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.2</span>  $i <span class="hl kwa">\leftarrow</span> i + <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.3</span>  $j <span class="hl kwa">\leftarrow</span> j + <span class="hl num">1</span>$ \\
<span class="hl num">6</span>.  for $n$ from $a.used - b$ to $a.used - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.1</span>  $a_n <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">7</span>.  $a.used <span class="hl kwa">\leftarrow</span> a.used - b$ \\
<span class="hl num">8</span>.  Return. \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_rshd</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_rshd</span>.<span class="hl opt">}</span>
This algorithm divides the input in place by the $b$'th power of $x$.  It is analogous to dividing by a $<span class="hl kwa">\beta</span>^b$ but much quicker since
it does not require single precision division.  This algorithm does not actually return an error code as it cannot fail.  

If the input $b$ is less than one the algorithm quickly returns without performing any work.  If the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> count is less than or equal
to the shift count $b$ then it will simply zero the input and return.

After the trivial cases of inputs have been handled the sliding window is setup.  Much like the case of algorithm mp<span class="hl kwa">\_lshd</span> a sliding window that
is $b$ digits wide is used to copy the digits.  Unlike mp<span class="hl kwa">\_lshd</span> the window slides in the opposite direction from the trailing to the leading digit.  
Also the digits are copied from the leading to the trailing edge.

Once the window copy is complete the upper digits must be zeroed and the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> count decremented.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_rshd</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

The only noteworthy element of this routine is the lack of a return type since it cannot fail.  Like mp<span class="hl kwa">\_lshd</span>() we
form a sliding window except we copy in the other direction.  After the window (line <span class="hl num">60</span>) we then zero
the upper digits of the input to make sure the result is correct.

<span class="hl kwa">\section</span><span class="hl opt">{</span>Powers of Two<span class="hl opt">}</span>

Now that algorithms for moving single bits as well as whole digits exist algorithms for moving the ``in between'' distances are required.  For 
example, to quickly multiply by $<span class="hl num">2</span>^k$ for any $k$ without using a full multiplier algorithm would prove useful.  Instead of performing single
shifts $k$ times to achieve a multiplication by $<span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl kwa">\pm</span> k<span class="hl opt">}</span>$ a mixture of whole digit shifting and partial digit shifting is employed.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Multiplication by Power of Two<span class="hl opt">}</span>

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_mul\_2d</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   One mp<span class="hl kwa">\_int</span> $a$ and an integer $b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $c <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\cdot</span> <span class="hl num">2</span>^b$. \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $c <span class="hl kwa">\leftarrow</span> a$.  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_copy</span><span class="hl opt">}</span>) \\
<span class="hl num">2</span>.  If $c.alloc &lt; c.used + <span class="hl kwa">\lfloor</span> b / lg(<span class="hl kwa">\beta</span>) <span class="hl kwa">\rfloor</span> + <span class="hl num">2</span>$ then grow $c$ accordingly. \\
<span class="hl num">3</span>.  If the reallocation failed return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_MEM</span><span class="hl opt">}</span>). \\
<span class="hl num">4</span>.  If $b <span class="hl kwa">\ge</span> lg(<span class="hl kwa">\beta</span>)$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.1</span>  $c <span class="hl kwa">\leftarrow</span> c <span class="hl kwa">\cdot \beta</span>^<span class="hl opt">{</span><span class="hl kwa">\lfloor</span> b / lg(<span class="hl kwa">\beta</span>) <span class="hl kwa">\rfloor</span><span class="hl opt">}</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_lshd</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.2</span>  If step <span class="hl num">4.1</span> failed return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_MEM</span><span class="hl opt">}</span>). \\
<span class="hl num">5</span>.  $d <span class="hl kwa">\leftarrow</span> b <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>lg(<span class="hl kwa">\beta</span>)<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl num">6</span>.  If $d <span class="hl kwa">\ne</span> <span class="hl num">0</span>$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.1</span>  $mask <span class="hl kwa">\leftarrow</span> <span class="hl num">2</span>^d$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.2</span>  $r <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.3</span>  for $n$ from $<span class="hl num">0</span>$ to $c.used - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">6.3.1</span>  $rr <span class="hl kwa">\leftarrow</span> c_n &gt;&gt; (lg(<span class="hl kwa">\beta</span>) - d) <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>mask<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">6.3.2</span>  $c_n <span class="hl kwa">\leftarrow</span> (c_n &lt;&lt; d) + r <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">6.3.3</span>  $r <span class="hl kwa">\leftarrow</span> rr$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.4</span>  If $r &gt; <span class="hl num">0</span>$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">6.4.1</span>  $c_<span class="hl opt">{</span>c.used<span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> r$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">6.4.2</span>  $c.used <span class="hl kwa">\leftarrow</span> c.used + <span class="hl num">1</span>$ \\
<span class="hl num">7</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_mul\_2d</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_mul\_2d</span>.<span class="hl opt">}</span>
This algorithm multiplies $a$ by $<span class="hl num">2</span>^b$ and stores the result in $c$.  The algorithm uses algorithm mp<span class="hl kwa">\_lshd</span> and a derivative of algorithm mp<span class="hl kwa">\_mul\_2</span> to
quickly compute the product.

First the algorithm will multiply $a$ by $x^<span class="hl opt">{</span><span class="hl kwa">\lfloor</span> b / lg(<span class="hl kwa">\beta</span>) <span class="hl kwa">\rfloor</span><span class="hl opt">}</span>$ which will ensure that the remainder multiplicand is less than 
$<span class="hl kwa">\beta</span>$.  For example, if $b = <span class="hl num">37</span>$ and $<span class="hl kwa">\beta</span> = <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">28</span><span class="hl opt">}</span>$ then this step will multiply by $x$ leaving a multiplication by $<span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">37</span> - <span class="hl num">28</span><span class="hl opt">}</span> = <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">9</span><span class="hl opt">}</span>$ 
left.

After the digits have been shifted appropriately at most $lg(<span class="hl kwa">\beta</span>) - <span class="hl num">1</span>$ shifts are left to perform.  Step <span class="hl num">5</span> calculates the number of remaining shifts 
required.  If it is non-zero a modified shift loop is used to calculate the remaining product.  
Essentially the loop is a generic version of algorithm mp<span class="hl kwa">\_mul\_2</span> designed to handle any shift count in the range $<span class="hl num">1</span> <span class="hl kwa">\le</span> x &lt; lg(<span class="hl kwa">\beta</span>)$.  The $mask$
variable is used to extract the upper $d$ bits to form the carry for the next iteration.  

This algorithm is loosely measured as a $O(<span class="hl num">2</span>n)$ algorithm which means that if the input is $n$-digits that it takes $<span class="hl num">2</span>n$ ``time'' to 
complete.  It is possible to optimize this algorithm down to a $O(n)$ algorithm at a cost of making the algorithm slightly harder to follow.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_mul\_2d</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

The shifting is performed in--place which means the first step (line <span class="hl num">25</span>) is to copy the input to the 
destination.  We avoid calling mp<span class="hl kwa">\_copy</span>() by making sure the mp<span class="hl kwa">\_ints</span> are different.  The destination then
has to be grown (line <span class="hl num">32</span>) to accomodate the result.

If the shift count $b$ is larger than $lg(<span class="hl kwa">\beta</span>)$ then a call to mp<span class="hl kwa">\_lshd</span>() is used to handle all of the multiples 
of $lg(<span class="hl kwa">\beta</span>)$.  Leaving only a remaining shift of $lg(<span class="hl kwa">\beta</span>) - <span class="hl num">1</span>$ or fewer bits left.  Inside the actual shift 
loop (lines <span class="hl num">46</span> to <span class="hl num">76</span>) we make use of pre--computed values $shift$ and $mask$.   These are used to
extract the carry bit(s) to pass into the next iteration of the loop.  The $r$ and $rr$ variables form a 
chain between consecutive iterations to propagate the carry.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Division by Power of Two<span class="hl opt">}</span>

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_div\_2d</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   One mp<span class="hl kwa">\_int</span> $a$ and an integer $b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $c <span class="hl kwa">\leftarrow \lfloor</span> a / <span class="hl num">2</span>^b <span class="hl kwa">\rfloor</span>, d <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span>^b<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$. \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  If $b <span class="hl kwa">\le</span> <span class="hl num">0</span>$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.1</span>  $c <span class="hl kwa">\leftarrow</span> a$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_copy</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.2</span>  $d <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_zero</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.3</span>  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl num">2</span>.  $c <span class="hl kwa">\leftarrow</span> a$ \\
<span class="hl num">3</span>.  $d <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span>^b<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_mod\_2d</span><span class="hl opt">}</span>) \\
<span class="hl num">4</span>.  If $b <span class="hl kwa">\ge</span> lg(<span class="hl kwa">\beta</span>)$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.1</span>  $c <span class="hl kwa">\leftarrow \lfloor</span> c/<span class="hl kwa">\beta</span>^<span class="hl opt">{</span><span class="hl kwa">\lfloor</span> b/lg(<span class="hl kwa">\beta</span>) <span class="hl kwa">\rfloor</span><span class="hl opt">}</span> <span class="hl kwa">\rfloor</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_rshd</span><span class="hl opt">}</span>). \\
<span class="hl num">5</span>.  $k <span class="hl kwa">\leftarrow</span> b <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>lg(<span class="hl kwa">\beta</span>)<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl num">6</span>.  If $k <span class="hl kwa">\ne</span> <span class="hl num">0</span>$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.1</span>  $mask <span class="hl kwa">\leftarrow</span> <span class="hl num">2</span>^k$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.2</span>  $r <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.3</span>  for $n$ from $c.used - <span class="hl num">1</span>$ to $<span class="hl num">0</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">6.3.1</span>  $rr <span class="hl kwa">\leftarrow</span> c_n <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>mask<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">6.3.2</span>  $c_n <span class="hl kwa">\leftarrow</span> (c_n &gt;&gt; k) + (r &lt;&lt; (lg(<span class="hl kwa">\beta</span>) - k))$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">6.3.3</span>  $r <span class="hl kwa">\leftarrow</span> rr$ \\
<span class="hl num">7</span>.  Clamp excess digits of $c$.  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_clamp</span><span class="hl opt">}</span>) \\
<span class="hl num">8</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_div\_2d</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_div\_2d</span>.<span class="hl opt">}</span>
This algorithm will divide an input $a$ by $<span class="hl num">2</span>^b$ and produce the quotient and remainder.  The algorithm is designed much like algorithm 
mp<span class="hl kwa">\_mul\_2d</span> by first using whole digit shifts then single precision shifts.  This algorithm will also produce the remainder of the division
by using algorithm mp<span class="hl kwa">\_mod\_2d</span>.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_div\_2d</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

The implementation of algorithm mp<span class="hl kwa">\_div\_2d</span> is slightly different than the algorithm specifies.  The remainder $d$ may be optionally 
ignored by passing <span class="hl kwa">\textbf</span><span class="hl opt">{</span>NULL<span class="hl opt">}</span> as the pointer to the mp<span class="hl kwa">\_int</span> variable.    The temporary mp<span class="hl kwa">\_int</span> variable $t$ is used to hold the 
result of the remainder operation until the end.  This allows $d$ and $a$ to represent the same mp<span class="hl kwa">\_int</span> without modifying $a$ before
the quotient is obtained.

The remainder of the source code is essentially the same as the source code for mp<span class="hl kwa">\_mul\_2d</span>.  The only significant difference is
the direction of the shifts.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Remainder of Division by Power of Two<span class="hl opt">}</span>

The last algorithm in the series of polynomial basis power of two algorithms is calculating the remainder of division by $<span class="hl num">2</span>^b$.  This
algorithm benefits from the fact that in twos complement arithmetic $a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span>^b<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ is the same as $a$ AND $<span class="hl num">2</span>^b - <span class="hl num">1</span>$.  

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_mod\_2d</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   One mp<span class="hl kwa">\_int</span> $a$ and an integer $b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $c <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span>^b<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$. \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  If $b <span class="hl kwa">\le</span> <span class="hl num">0</span>$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.1</span>  $c <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_zero</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.2</span>  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl num">2</span>.  If $b &gt; a.used <span class="hl kwa">\cdot</span> lg(<span class="hl kwa">\beta</span>)$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  $c <span class="hl kwa">\leftarrow</span> a$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_copy</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.2</span>  Return the result of step <span class="hl num">2.1</span>. \\
<span class="hl num">3</span>.  $c <span class="hl kwa">\leftarrow</span> a$ \\
<span class="hl num">4</span>.  If step <span class="hl num">3</span> failed return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_MEM</span><span class="hl opt">}</span>). \\
<span class="hl num">5</span>.  for $n$ from $<span class="hl kwa">\lceil</span> b / lg(<span class="hl kwa">\beta</span>) <span class="hl kwa">\rceil</span>$ to $c.used$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.1</span>  $c_n <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">6</span>.  $k <span class="hl kwa">\leftarrow</span> b <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>lg(<span class="hl kwa">\beta</span>)<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl num">7</span>.  $c_<span class="hl opt">{</span><span class="hl kwa">\lfloor</span> b / lg(<span class="hl kwa">\beta</span>) <span class="hl kwa">\rfloor</span><span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> c_<span class="hl opt">{</span><span class="hl kwa">\lfloor</span> b / lg(<span class="hl kwa">\beta</span>) <span class="hl kwa">\rfloor</span><span class="hl opt">}</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span>^<span class="hl opt">{</span>k<span class="hl opt">}</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$. \\
<span class="hl num">8</span>.  Clamp excess digits of $c$.  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_clamp</span><span class="hl opt">}</span>) \\
<span class="hl num">9</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_mod\_2d</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_mod\_2d</span>.<span class="hl opt">}</span>
This algorithm will quickly calculate the value of $a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span>^b<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$.  First if $b$ is less than or equal to zero the 
result is set to zero.  If $b$ is greater than the number of bits in $a$ then it simply copies $a$ to $c$ and returns.  Otherwise, $a$ 
is copied to $b$, leading digits are removed and the remaining leading digit is trimed to the exact bit count.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_mod\_2d</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

We first avoid cases of $b <span class="hl kwa">\le</span> <span class="hl num">0</span>$ by simply mp<span class="hl kwa">\_zero</span>()'ing the destination in such cases.  Next if $<span class="hl num">2</span>^b$ is larger
than the input we just mp<span class="hl kwa">\_copy</span>() the input and return right away.  After this point we know we must actually
perform some work to produce the remainder.

Recalling that reducing modulo $<span class="hl num">2</span>^k$ and a binary ``and'' with $<span class="hl num">2</span>^k - <span class="hl num">1</span>$ are numerically equivalent we can quickly reduce 
the number.  First we zero any digits above the last digit in $<span class="hl num">2</span>^b$ (line <span class="hl num">42</span>).  Next we reduce the 
leading digit of both (line <span class="hl num">46</span>) and then mp<span class="hl kwa">\_clamp</span>().

<span class="hl kwa">\section</span>*<span class="hl opt">{</span>Exercises<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>cl<span class="hl opt">}</span>
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">3</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span> $ &amp; Devise an algorithm that performs $a <span class="hl kwa">\cdot</span> <span class="hl num">2</span>^b$ for generic values of $b$ \\
                      &amp; in $O(n)$ time. \\
                      &amp;\\
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">3</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span> $ &amp; Devise an efficient algorithm to multiply by small low hamming  \\
                      &amp; weight values such as $<span class="hl num">3</span>$, $<span class="hl num">5</span>$ and $<span class="hl num">9</span>$.  Extend it to handle all values \\
                      &amp; upto $<span class="hl num">64</span>$ with a hamming weight less than three. \\
                      &amp;\\
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">2</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span> $ &amp; Modify the preceding algorithm to handle values of the form \\
                      &amp; $<span class="hl num">2</span>^k - <span class="hl num">1</span>$ as well. \\
                      &amp;\\
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">3</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span> $ &amp; Using only algorithms mp<span class="hl kwa">\_mul\_2</span>, mp<span class="hl kwa">\_div\_2</span> and mp<span class="hl kwa">\_add</span> create an \\
                      &amp; algorithm to multiply two integers in roughly $O(<span class="hl num">2</span>n^<span class="hl num">2</span>)$ time for \\
                      &amp; any $n$-bit input.  Note that the time of addition is ignored in the \\
                      &amp; calculation.  \\
                      &amp; \\
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">5</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span> $ &amp; Improve the previous algorithm to have a working time of at most \\
                      &amp; $O <span class="hl kwa">\left</span> (<span class="hl num">2</span>^<span class="hl opt">{</span>(k-<span class="hl num">1</span>)<span class="hl opt">}</span>n + <span class="hl kwa">\left</span> (<span class="hl opt">{</span><span class="hl num">2</span>n^<span class="hl num">2</span> <span class="hl kwa">\over</span> k<span class="hl opt">}</span> <span class="hl kwa">\right</span> ) <span class="hl kwa">\right</span> )$ for an appropriate choice of $k$.  Again ignore \\
                      &amp; the cost of addition. \\
                      &amp; \\
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">2</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span> $ &amp; Devise a chart to find optimal values of $k$ for the previous problem \\
                      &amp; for $n = <span class="hl num">64</span> <span class="hl kwa">\ldots</span> <span class="hl num">1024</span>$ in steps of $<span class="hl num">64</span>$. \\
                      &amp; \\
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">2</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span> $ &amp; Using only algorithms mp<span class="hl kwa">\_abs</span> and mp<span class="hl kwa">\_sub</span> devise another method for \\
                      &amp; calculating the result of a signed comparison. \\
                      &amp;
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>

<span class="hl kwa">\chapter</span><span class="hl opt">{</span>Multiplication and Squaring<span class="hl opt">}</span>
<span class="hl kwa">\section</span><span class="hl opt">{</span>The Multipliers<span class="hl opt">}</span>
For most number theoretic problems including certain public key cryptographic algorithms, the ``multipliers'' form the most important subset of 
algorithms of any multiple precision integer package.  The set of multiplier algorithms include integer multiplication, squaring and modular reduction 
where in each of the algorithms single precision multiplication is the dominant operation performed.  This chapter will discuss integer multiplication 
and squaring, leaving modular reductions for the subsequent chapter.  

The importance of the multiplier algorithms is for the most part driven by the fact that certain popular public key algorithms are based on modular 
exponentiation, that is computing $d <span class="hl kwa">\equiv</span> a^b <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>c<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ for some arbitrary choice of $a$, $b$, $c$ and $d$.  During a modular
exponentiation the majority<span class="hl kwa">\footnote</span><span class="hl opt">{</span>Roughly speaking a modular exponentiation will spend about <span class="hl num">40</span>\% of the time performing modular reductions, 
<span class="hl num">35</span>\% of the time performing squaring and <span class="hl num">25</span>\% of the time performing multiplications.<span class="hl opt">}</span> of the processor time is spent performing single precision 
multiplications.

For centuries general purpose multiplication has required a lengthly $O(n^<span class="hl num">2</span>)$ process, whereby each digit of one multiplicand has to be multiplied 
against every digit of the other multiplicand.  Traditional long-hand multiplication is based on this process;  while the techniques can differ the 
overall algorithm used is essentially the same.  Only ``recently'' have faster algorithms been studied.  First Karatsuba multiplication was discovered in 
<span class="hl num">1962</span>.  This algorithm can multiply two numbers with considerably fewer single precision multiplications when compared to the long-hand approach.  
This technique led to the discovery of polynomial basis algorithms (<span class="hl kwa">\textit</span><span class="hl opt">{</span>good reference?<span class="hl opt">}</span>) and subquently Fourier Transform based solutions.  

<span class="hl kwa">\section</span><span class="hl opt">{</span>Multiplication<span class="hl opt">}</span>
<span class="hl kwa">\subsection</span><span class="hl opt">{</span>The Baseline Multiplication<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>sec:basemult<span class="hl opt">}</span>
<span class="hl kwa">\index</span><span class="hl opt">{</span>baseline multiplication<span class="hl opt">}</span>
Computing the product of two integers in software can be achieved using a trivial adaptation of the standard $O(n^<span class="hl num">2</span>)$ long-hand multiplication
algorithm that school children are taught.  The algorithm is considered an $O(n^<span class="hl num">2</span>)$ algorithm since for two $n$-digit inputs $n^<span class="hl num">2</span>$ single precision 
multiplications are required.  More specifically for a $m$ and $n$ digit input $m <span class="hl kwa">\cdot</span> n$ single precision multiplications are required.  To 
simplify most discussions, it will be assumed that the inputs have comparable number of digits.  

The ``baseline multiplication'' algorithm is designed to act as the ``catch-all'' algorithm, only to be used when the faster algorithms cannot be 
used.  This algorithm does not use any particularly interesting optimizations and should ideally be avoided if possible.    One important 
facet of this algorithm, is that it has been modified to only produce a certain amount of output digits as resolution.  The importance of this 
modification will become evident during the discussion of Barrett modular reduction.  Recall that for a $n$ and $m$ digit input the product 
will be at most $n + m$ digits.  Therefore, this algorithm can be reduced to a full multiplier by having it produce $n + m$ digits of the product.  

Recall from sub-section <span class="hl num">4.2.2</span> the definition of $<span class="hl kwa">\gamma</span>$ as the number of bits in the type <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_digit</span><span class="hl opt">}</span>.  We shall now extend the variable set to 
include $<span class="hl kwa">\alpha</span>$ which shall represent the number of bits in the type <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_word</span><span class="hl opt">}</span>.  This implies that $<span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl kwa">\alpha</span><span class="hl opt">}</span> &gt; <span class="hl num">2</span> <span class="hl kwa">\cdot \beta</span>^<span class="hl num">2</span>$.  The 
constant $<span class="hl kwa">\delta</span> = <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl kwa">\alpha</span> - <span class="hl num">2l</span>g(<span class="hl kwa">\beta</span>)<span class="hl opt">}</span>$ will represent the maximal weight of any column in a product (<span class="hl kwa">\textit</span><span class="hl opt">{</span>see sub-section <span class="hl num">5.2.2</span> for more information<span class="hl opt">}</span>).

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>s<span class="hl kwa">\_mp\_mul\_digs</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$, mp<span class="hl kwa">\_int</span> $b$ and an integer $digs$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $c <span class="hl kwa">\leftarrow \vert</span> a <span class="hl kwa">\vert \cdot \vert</span> b <span class="hl kwa">\vert \mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta</span>^<span class="hl opt">{</span>digs<span class="hl opt">}</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$. \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  If min$(a.used, b.used) &lt; <span class="hl kwa">\delta</span>$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.1</span>  Calculate $c = <span class="hl kwa">\vert</span> a <span class="hl kwa">\vert \cdot \vert</span> b <span class="hl kwa">\vert</span>$ by the Comba method (<span class="hl kwa">\textit</span><span class="hl opt">{</span>see algorithm~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:COMBAMULT<span class="hl opt">}}</span>).  \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.2</span>  Return the result of step <span class="hl num">1.1</span> \\
\\
Allocate and initialize a temporary mp<span class="hl kwa">\_int</span>. \\
<span class="hl num">2</span>.  Init $t$ to be of size $digs$ \\
<span class="hl num">3</span>.  If step <span class="hl num">2</span> failed return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_MEM</span><span class="hl opt">}</span>). \\
<span class="hl num">4</span>.  $t.used <span class="hl kwa">\leftarrow</span> digs$ \\
\\
Compute the product. \\
<span class="hl num">5</span>.  for $ix$ from $<span class="hl num">0</span>$ to $a.used - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.1</span>  $u <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.2</span>  $pb <span class="hl kwa">\leftarrow \mbox</span><span class="hl opt">{</span>min<span class="hl opt">}</span>(b.used, digs - ix)$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.3</span>  If $pb &lt; <span class="hl num">1</span>$ then goto step <span class="hl num">6</span>. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.4</span>  for $iy$ from $<span class="hl num">0</span>$ to $pb - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">5.4.1</span>  $<span class="hl kwa">\hat</span> r <span class="hl kwa">\leftarrow</span> t_<span class="hl opt">{</span>iy + ix<span class="hl opt">}</span> + a_<span class="hl opt">{</span>ix<span class="hl opt">}</span> <span class="hl kwa">\cdot</span> b_<span class="hl opt">{</span>iy<span class="hl opt">}</span> + u$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">5.4.2</span>  $t_<span class="hl opt">{</span>iy + ix<span class="hl opt">}</span> <span class="hl kwa">\leftarrow \hat</span> r <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">5.4.3</span>  $u <span class="hl kwa">\leftarrow \lfloor \hat</span> r / <span class="hl kwa">\beta \rfloor</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.5</span>  if $ix + pb &lt; digs$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">5.5.1</span>  $t_<span class="hl opt">{</span>ix + pb<span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> u$ \\
<span class="hl num">6</span>.  Clamp excess digits of $t$. \\
<span class="hl num">7</span>.  Swap $c$ with $t$ \\
<span class="hl num">8</span>.  Clear $t$ \\
<span class="hl num">9</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm s<span class="hl kwa">\_mp\_mul\_digs</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm s<span class="hl kwa">\_mp\_mul\_digs</span>.<span class="hl opt">}</span>
This algorithm computes the unsigned product of two inputs $a$ and $b$, limited to an output precision of $digs$ digits.  While it may seem
a bit awkward to modify the function from its simple $O(n^<span class="hl num">2</span>)$ description, the usefulness of partial multipliers will arise in a subsequent 
algorithm.  The algorithm is loosely based on algorithm <span class="hl num">14.12</span> from <span class="hl kwa">\cite</span><span class="hl opt">[</span>pp. <span class="hl num">595</span><span class="hl opt">]{</span>HAC<span class="hl opt">}</span> and is similar to Algorithm M of Knuth <span class="hl kwa">\cite</span><span class="hl opt">[</span>pp. <span class="hl num">268</span><span class="hl opt">]{</span>TAOCPV2<span class="hl opt">}</span>.  
Algorithm s<span class="hl kwa">\_mp\_mul\_digs</span> differs from these cited references since it can produce a variable output precision regardless of the precision of the 
inputs.

The first thing this algorithm checks for is whether a Comba multiplier can be used instead.   If the minimum digit count of either
input is less than $<span class="hl kwa">\delta</span>$, then the Comba method may be used instead.    After the Comba method is ruled out, the baseline algorithm begins.  A 
temporary mp<span class="hl kwa">\_int</span> variable $t$ is used to hold the intermediate result of the product.  This allows the algorithm to be used to 
compute products when either $a = c$ or $b = c$ without overwriting the inputs.  

All of step <span class="hl num">5</span> is the infamous $O(n^<span class="hl num">2</span>)$ multiplication loop slightly modified to only produce upto $digs$ digits of output.  The $pb$ variable
is given the count of digits to read from $b$ inside the nested loop.  If $pb <span class="hl kwa">\le</span> <span class="hl num">1</span>$ then no more output digits can be produced and the algorithm
will exit the loop.  The best way to think of the loops are as a series of $pb <span class="hl kwa">\times</span> <span class="hl num">1</span>$ multiplications.    That is, in each pass of the 
innermost loop $a_<span class="hl opt">{</span>ix<span class="hl opt">}</span>$ is multiplied against $b$ and the result is added (<span class="hl kwa">\textit</span><span class="hl opt">{</span>with an appropriate shift<span class="hl opt">}</span>) to $t$.  

For example, consider multiplying $<span class="hl num">576</span>$ by $<span class="hl num">241</span>$.  That is equivalent to computing $<span class="hl num">10</span>^<span class="hl num">0</span>(<span class="hl num">1</span>)(<span class="hl num">576</span>) + <span class="hl num">10</span>^<span class="hl num">1</span>(<span class="hl num">4</span>)(<span class="hl num">576</span>) + <span class="hl num">10</span>^<span class="hl num">2</span>(<span class="hl num">2</span>)(<span class="hl num">576</span>)$ which is best
visualized in the following table.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>|c|c|c|c|c|c|l|<span class="hl opt">}</span>
<span class="hl kwa">\hline</span>   &amp;&amp;          &amp; <span class="hl num">5</span> &amp; <span class="hl num">7</span> &amp; <span class="hl num">6</span> &amp; \\
<span class="hl kwa">\hline</span>   $<span class="hl kwa">\times</span>$&amp;&amp;  &amp; <span class="hl num">2</span> &amp; <span class="hl num">4</span> &amp; <span class="hl num">1</span> &amp; \\
<span class="hl kwa">\hline</span> &amp;&amp;&amp;&amp;&amp;&amp;\\
  &amp;&amp;          &amp; <span class="hl num">5</span> &amp; <span class="hl num">7</span> &amp; <span class="hl num">6</span> &amp; $<span class="hl num">10</span>^<span class="hl num">0</span>(<span class="hl num">1</span>)(<span class="hl num">576</span>)$ \\
  &amp;<span class="hl num">2</span> &amp;   <span class="hl num">3</span>    &amp; <span class="hl num">6</span> &amp; <span class="hl num">1</span> &amp; <span class="hl num">6</span> &amp; $<span class="hl num">10</span>^<span class="hl num">1</span>(<span class="hl num">4</span>)(<span class="hl num">576</span>) + <span class="hl num">10</span>^<span class="hl num">0</span>(<span class="hl num">1</span>)(<span class="hl num">576</span>)$ \\
  <span class="hl num">1</span> &amp; <span class="hl num">3</span> &amp; <span class="hl num">8</span> &amp; <span class="hl num">8</span> &amp; <span class="hl num">1</span> &amp; <span class="hl num">6</span> &amp;   $<span class="hl num">10</span>^<span class="hl num">2</span>(<span class="hl num">2</span>)(<span class="hl num">576</span>) + <span class="hl num">10</span>^<span class="hl num">1</span>(<span class="hl num">4</span>)(<span class="hl num">576</span>) + <span class="hl num">10</span>^<span class="hl num">0</span>(<span class="hl num">1</span>)(<span class="hl num">576</span>)$ \\
<span class="hl kwa">\hline</span>  
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Long-Hand Multiplication Diagram<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

Each row of the product is added to the result after being shifted to the left (<span class="hl kwa">\textit</span><span class="hl opt">{</span>multiplied by a power of the radix<span class="hl opt">}</span>) by the appropriate 
count.  That is in pass $ix$ of the inner loop the product is added starting at the $ix$'th digit of the reult.

Step <span class="hl num">5.4.1</span> introduces the hat symbol (<span class="hl kwa">\textit</span><span class="hl opt">{</span>e.g. $<span class="hl kwa">\hat</span> r$<span class="hl opt">}</span>) which represents a double precision variable.  The multiplication on that step
is assumed to be a double wide output single precision multiplication.  That is, two single precision variables are multiplied to produce a
double precision result.  The step is somewhat optimized from a long-hand multiplication algorithm because the carry from the addition in step
<span class="hl num">5.4.1</span> is propagated through the nested loop.  If the carry was not propagated immediately it would overflow the single precision digit 
$t_<span class="hl opt">{</span>ix+iy<span class="hl opt">}</span>$ and the result would be lost.  

At step <span class="hl num">5.5</span> the nested loop is finished and any carry that was left over should be forwarded.  The carry does not have to be added to the $ix+pb$'th
digit since that digit is assumed to be zero at this point.  However, if $ix + pb <span class="hl kwa">\ge</span> digs$ the carry is not set as it would make the result
exceed the precision requested.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_s\_mp\_mul\_digs</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

First we determine (line <span class="hl num">31</span>) if the Comba method can be used first since it's faster.  The conditions for 
sing the Comba routine are that min$(a.used, b.used) &lt; <span class="hl kwa">\delta</span>$ and the number of digits of output is less than 
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_WARRAY</span><span class="hl opt">}</span>.  This new constant is used to control the stack usage in the Comba routines.  By default it is 
set to $<span class="hl kwa">\delta</span>$ but can be reduced when memory is at a premium.

If we cannot use the Comba method we proceed to setup the baseline routine.  We allocate the the destination mp<span class="hl kwa">\_int</span>
$t$ (line <span class="hl num">37</span>) to the exact size of the output to avoid further re--allocations.  At this point we now 
begin the $O(n^<span class="hl num">2</span>)$ loop.

This implementation of multiplication has the caveat that it can be trimmed to only produce a variable number of
digits as output.  In each iteration of the outer loop the $pb$ variable is set (line <span class="hl num">49</span>) to the maximum 
number of inner loop iterations.  

Inside the inner loop we calculate $<span class="hl kwa">\hat</span> r$ as the mp<span class="hl kwa">\_word</span> product of the two mp<span class="hl kwa">\_digits</span> and the addition of the
carry from the previous iteration.  A particularly important observation is that most modern optimizing 
C compilers (GCC for instance) can recognize that a $N <span class="hl kwa">\times</span> N <span class="hl kwa">\rightarrow</span> <span class="hl num">2</span>N$ multiplication is all that 
is required for the product.  In x86 terms for example, this means using the MUL instruction.

Each digit of the product is stored in turn (line <span class="hl num">69</span>) and the carry propagated (line <span class="hl num">72</span>) to the 
next iteration.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Faster Multiplication by the ``Comba'' Method<span class="hl opt">}</span>

One of the huge drawbacks of the ``baseline'' algorithms is that at the $O(n^<span class="hl num">2</span>)$ level the carry must be 
computed and propagated upwards.  This makes the nested loop very sequential and hard to unroll and implement 
in parallel.  The ``Comba'' <span class="hl kwa">\cite</span><span class="hl opt">{</span>COMBA<span class="hl opt">}</span> method is named after little known (<span class="hl kwa">\textit</span><span class="hl opt">{</span>in cryptographic venues<span class="hl opt">}</span>) Paul G. 
Comba who described a method of implementing fast multipliers that do not require nested carry fixup operations.  As an 
interesting aside it seems that Paul Barrett describes a similar technique in his <span class="hl num">1986</span> paper <span class="hl kwa">\cite</span><span class="hl opt">{</span>BARRETT<span class="hl opt">}</span> written 
five years before.

At the heart of the Comba technique is once again the long-hand algorithm.  Except in this case a slight 
twist is placed on how the columns of the result are produced.  In the standard long-hand algorithm rows of products 
are produced then added together to form the final result.  In the baseline algorithm the columns are added together 
after each iteration to get the result instantaneously.  

In the Comba algorithm the columns of the result are produced entirely independently of each other.  That is at 
the $O(n^<span class="hl num">2</span>)$ level a simple multiplication and addition step is performed.  The carries of the columns are propagated 
after the nested loop to reduce the amount of work requiored. Succintly the first step of the algorithm is to compute 
the product vector $<span class="hl kwa">\vec</span> x$ as follows. 

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
<span class="hl kwa">\vec</span> x_n = <span class="hl kwa">\sum_</span><span class="hl opt">{</span>i+j = n<span class="hl opt">}</span> a_ib_j, <span class="hl kwa">\forall</span> n <span class="hl kwa">\in \lbrace</span> <span class="hl num">0</span>, <span class="hl num">1</span>, <span class="hl num">2</span>, <span class="hl kwa">\ldots</span>, i + j <span class="hl kwa">\rbrace</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

Where $<span class="hl kwa">\vec</span> x_n$ is the $n'th$ column of the output vector.  Consider the following example which computes the vector $<span class="hl kwa">\vec</span> x$ for the multiplication
of $<span class="hl num">576</span>$ and $<span class="hl num">241</span>$.  

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>|c|c|c|c|c|c|<span class="hl opt">}</span>
  <span class="hl kwa">\hline</span> &amp;          &amp; <span class="hl num">5</span> &amp; <span class="hl num">7</span> &amp; <span class="hl num">6</span> &amp; First Input\\
  <span class="hl kwa">\hline</span> $<span class="hl kwa">\times</span>$ &amp; &amp; <span class="hl num">2</span> &amp; <span class="hl num">4</span> &amp; <span class="hl num">1</span> &amp; Second Input\\
<span class="hl kwa">\hline</span>            &amp;                        &amp; $<span class="hl num">1</span> <span class="hl kwa">\cdot</span> <span class="hl num">5</span> = <span class="hl num">5</span>$   &amp; $<span class="hl num">1</span> <span class="hl kwa">\cdot</span> <span class="hl num">7</span> = <span class="hl num">7</span>$   &amp; $<span class="hl num">1</span> <span class="hl kwa">\cdot</span> <span class="hl num">6</span> = <span class="hl num">6</span>$ &amp; First pass \\
                  &amp;  $<span class="hl num">4</span> <span class="hl kwa">\cdot</span> <span class="hl num">5</span> = <span class="hl num">20</span>$      &amp; $<span class="hl num">4</span> <span class="hl kwa">\cdot</span> <span class="hl num">7</span>+<span class="hl num">5</span>=<span class="hl num">33</span>$  &amp; $<span class="hl num">4</span> <span class="hl kwa">\cdot</span> <span class="hl num">6</span>+<span class="hl num">7</span>=<span class="hl num">31</span>$  &amp; <span class="hl num">6</span>               &amp; Second pass \\
   $<span class="hl num">2</span> <span class="hl kwa">\cdot</span> <span class="hl num">5</span> = <span class="hl num">10</span>$ &amp;  $<span class="hl num">2</span> <span class="hl kwa">\cdot</span> <span class="hl num">7</span> + <span class="hl num">20</span> = <span class="hl num">34</span>$ &amp; $<span class="hl num">2</span> <span class="hl kwa">\cdot</span> <span class="hl num">6</span>+<span class="hl num">33</span>=<span class="hl num">45</span>$ &amp; <span class="hl num">31</span>                &amp; <span class="hl num">6</span>             &amp; Third pass \\
<span class="hl kwa">\hline</span> <span class="hl num">10</span> &amp; <span class="hl num">34</span> &amp; <span class="hl num">45</span> &amp; <span class="hl num">31</span> &amp; <span class="hl num">6</span> &amp; Final Result \\   
<span class="hl kwa">\hline</span>   
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Comba Multiplication Diagram<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

At this point the vector $x = <span class="hl kwa">\left</span> &lt; <span class="hl num">10</span>, <span class="hl num">34</span>, <span class="hl num">45</span>, <span class="hl num">31</span>, <span class="hl num">6</span> <span class="hl kwa">\right</span> &gt;$ is the result of the first step of the Comba multipler.  
Now the columns must be fixed by propagating the carry upwards.  The resultant vector will have one extra dimension over the input vector which is
congruent to adding a leading zero digit.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Comba Fixup<span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   Vector $<span class="hl kwa">\vec</span> x$ of dimension $k$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  Vector $<span class="hl kwa">\vec</span> x$ such that the carries have been propagated. \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  for $n$ from $<span class="hl num">0</span>$ to $k - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.1</span> $<span class="hl kwa">\vec</span> x_<span class="hl opt">{</span>n+<span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\leftarrow \vec</span> x_<span class="hl opt">{</span>n+<span class="hl num">1</span><span class="hl opt">}</span> + <span class="hl kwa">\lfloor \vec</span> x_<span class="hl opt">{</span>n<span class="hl opt">}</span>/<span class="hl kwa">\beta \rfloor</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.2</span> $<span class="hl kwa">\vec</span> x_<span class="hl opt">{</span>n<span class="hl opt">}</span> <span class="hl kwa">\leftarrow \vec</span> x_<span class="hl opt">{</span>n<span class="hl opt">}</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl num">2</span>.  Return($<span class="hl kwa">\vec</span> x$). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm Comba Fixup<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

With that algorithm and $k = <span class="hl num">5</span>$ and $<span class="hl kwa">\beta</span> = <span class="hl num">10</span>$ the following vector is produced $<span class="hl kwa">\vec</span> x= <span class="hl kwa">\left</span> &lt; <span class="hl num">1</span>, <span class="hl num">3</span>, <span class="hl num">8</span>, <span class="hl num">8</span>, <span class="hl num">1</span>, <span class="hl num">6</span> <span class="hl kwa">\right</span> &gt;$.  In this case 
$<span class="hl num">241</span> <span class="hl kwa">\cdot</span> <span class="hl num">576</span>$ is in fact $<span class="hl num">138816</span>$ and the procedure succeeded.  If the algorithm is correct and as will be demonstrated shortly more
efficient than the baseline algorithm why not simply always use this algorithm?

<span class="hl kwa">\subsubsection</span><span class="hl opt">{</span>Column Weight.<span class="hl opt">}</span>
At the nested $O(n^<span class="hl num">2</span>)$ level the Comba method adds the product of two single precision variables to each column of the output 
independently.  A serious obstacle is if the carry is lost, due to lack of precision before the algorithm has a chance to fix
the carries.  For example, in the multiplication of two three-digit numbers the third column of output will be the sum of
three single precision multiplications.  If the precision of the accumulator for the output digits is less then $<span class="hl num">3</span> <span class="hl kwa">\cdot</span> (<span class="hl kwa">\beta</span> - <span class="hl num">1</span>)^<span class="hl num">2</span>$ then
an overflow can occur and the carry information will be lost.  For any $m$ and $n$ digit inputs the maximum weight of any column is 
min$(m, n)$ which is fairly obvious.

The maximum number of terms in any column of a product is known as the ``column weight'' and strictly governs when the algorithm can be used.  Recall
from earlier that a double precision type has $<span class="hl kwa">\alpha</span>$ bits of resolution and a single precision digit has $lg(<span class="hl kwa">\beta</span>)$ bits of precision.  Given these
two quantities we must not violate the following

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
k <span class="hl kwa">\cdot \left</span> (<span class="hl kwa">\beta</span> - <span class="hl num">1</span> <span class="hl kwa">\right</span> )^<span class="hl num">2</span> &lt; <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl kwa">\alpha</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

Which reduces to 

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
k <span class="hl kwa">\cdot \left</span> ( <span class="hl kwa">\beta</span>^<span class="hl num">2</span> - <span class="hl num">2</span><span class="hl kwa">\beta</span> + <span class="hl num">1</span> <span class="hl kwa">\right</span> ) &lt; <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl kwa">\alpha</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

Let $<span class="hl kwa">\rho</span> = lg(<span class="hl kwa">\beta</span>)$ represent the number of bits in a single precision digit.  By further re-arrangement of the equation the final solution is
found.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
k  &lt; <span class="hl opt">{{</span><span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl kwa">\alpha</span><span class="hl opt">}}</span> <span class="hl kwa">\over</span> <span class="hl opt">{</span><span class="hl kwa">\left</span> (<span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">2</span><span class="hl kwa">\rho</span><span class="hl opt">}</span> - <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl kwa">\rho</span> + <span class="hl num">1</span><span class="hl opt">}</span> + <span class="hl num">1</span> <span class="hl kwa">\right</span> )<span class="hl opt">}}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

The defaults for LibTomMath are $<span class="hl kwa">\beta</span> = <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">28</span><span class="hl opt">}</span>$ and $<span class="hl kwa">\alpha</span> = <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">64</span><span class="hl opt">}</span>$ which means that $k$ is bounded by $k &lt; <span class="hl num">257</span>$.  In this configuration 
the smaller input may not have more than $<span class="hl num">256</span>$ digits if the Comba method is to be used.  This is quite satisfactory for most applications since 
$<span class="hl num">256</span>$ digits would allow for numbers in the range of $<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">7168</span><span class="hl opt">}</span>$ which, is much larger than most public key cryptographic algorithms require.  

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>fast<span class="hl kwa">\_s\_mp\_mul\_digs</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$, mp<span class="hl kwa">\_int</span> $b$ and an integer $digs$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $c <span class="hl kwa">\leftarrow \vert</span> a <span class="hl kwa">\vert \cdot \vert</span> b <span class="hl kwa">\vert \mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta</span>^<span class="hl opt">{</span>digs<span class="hl opt">}</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$. \\
<span class="hl kwa">\hline</span> \\
Place an array of <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_WARRAY</span><span class="hl opt">}</span> single precision digits named $W$ on the stack. \\
<span class="hl num">1</span>.  If $c.alloc &lt; digs$ then grow $c$ to $digs$ digits. (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_grow</span><span class="hl opt">}</span>) \\
<span class="hl num">2</span>.  If step <span class="hl num">1</span> failed return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_MEM</span><span class="hl opt">}</span>).\\
\\
<span class="hl num">3</span>.  $pa <span class="hl kwa">\leftarrow \mbox</span><span class="hl opt">{</span>MIN<span class="hl opt">}</span>(digs, a.used + b.used)$ \\
\\
<span class="hl num">4</span>.  $<span class="hl kwa">\_ \hat</span> W <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">5</span>.  for $ix$ from <span class="hl num">0</span> to $pa - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.1</span>  $ty <span class="hl kwa">\leftarrow \mbox</span><span class="hl opt">{</span>MIN<span class="hl opt">}</span>(b.used - <span class="hl num">1</span>, ix)$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.2</span>  $tx <span class="hl kwa">\leftarrow</span> ix - ty$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.3</span>  $iy <span class="hl kwa">\leftarrow \mbox</span><span class="hl opt">{</span>MIN<span class="hl opt">}</span>(a.used - tx, ty + <span class="hl num">1</span>)$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.4</span>  for $iz$ from <span class="hl num">0</span> to $iy - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">5.4.1</span>  $<span class="hl kwa">\_ \hat</span> W <span class="hl kwa">\leftarrow \_ \hat</span> W + a_<span class="hl opt">{</span>tx+iy<span class="hl opt">}</span>b_<span class="hl opt">{</span>ty-iy<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.5</span>  $W_<span class="hl opt">{</span>ix<span class="hl opt">}</span> <span class="hl kwa">\leftarrow \_ \hat</span> W (<span class="hl kwa">\mbox</span><span class="hl opt">{</span>mod <span class="hl opt">}</span><span class="hl kwa">\beta</span>)$\\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.6</span>  $<span class="hl kwa">\_ \hat</span> W <span class="hl kwa">\leftarrow \lfloor \_ \hat</span> W / <span class="hl kwa">\beta \rfloor</span>$ \\
\\
<span class="hl num">6</span>.  $oldused <span class="hl kwa">\leftarrow</span> c.used$ \\
<span class="hl num">7</span>.  $c.used <span class="hl kwa">\leftarrow</span> digs$ \\
<span class="hl num">8</span>.  for $ix$ from $<span class="hl num">0</span>$ to $pa$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">8.1</span>  $c_<span class="hl opt">{</span>ix<span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> W_<span class="hl opt">{</span>ix<span class="hl opt">}</span>$ \\
<span class="hl num">9</span>.  for $ix$ from $pa + <span class="hl num">1</span>$ to $oldused - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">9.1</span> $c_<span class="hl opt">{</span>ix<span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
\\
<span class="hl num">10</span>.  Clamp $c$. \\
<span class="hl num">11</span>.  Return MP<span class="hl kwa">\_OKAY</span>. \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm fast<span class="hl kwa">\_s\_mp\_mul\_digs</span><span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>fig:COMBAMULT<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm fast<span class="hl kwa">\_s\_mp\_mul\_digs</span>.<span class="hl opt">}</span>
This algorithm performs the unsigned multiplication of $a$ and $b$ using the Comba method limited to $digs$ digits of precision.

The outer loop of this algorithm is more complicated than that of the baseline multiplier.  This is because on the inside of the 
loop we want to produce one column per pass.  This allows the accumulator $<span class="hl kwa">\_ \hat</span> W$ to be placed in CPU registers and
reduce the memory bandwidth to two <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_digit</span><span class="hl opt">}</span> reads per iteration.

The $ty$ variable is set to the minimum count of $ix$ or the number of digits in $b$.  That way if $a$ has more digits than
$b$ this will be limited to $b.used - <span class="hl num">1</span>$.  The $tx$ variable is set to the to the distance past $b.used$ the variable
$ix$ is.  This is used for the immediately subsequent statement where we find $iy$.  

The variable $iy$ is the minimum digits we can read from either $a$ or $b$ before running out.  Computing one column at a time
means we have to scan one integer upwards and the other downwards.  $a$ starts at $tx$ and $b$ starts at $ty$.  In each
pass we are producing the $ix$'th output column and we note that $tx + ty = ix$.  As we move $tx$ upwards we have to 
move $ty$ downards so the equality remains valid.  The $iy$ variable is the number of iterations until 
$tx <span class="hl kwa">\ge</span> a.used$ or $ty &lt; <span class="hl num">0</span>$ occurs.

After every inner pass we store the lower half of the accumulator into $W_<span class="hl opt">{</span>ix<span class="hl opt">}</span>$ and then propagate the carry of the accumulator
into the next round by dividing $<span class="hl kwa">\_ \hat</span> W$ by $<span class="hl kwa">\beta</span>$.

To measure the benefits of the Comba method over the baseline method consider the number of operations that are required.  If the 
cost in terms of time of a multiply and addition is $p$ and the cost of a carry propagation is $q$ then a baseline multiplication would require 
$O <span class="hl kwa">\left</span> ((p + q)n^<span class="hl num">2</span> <span class="hl kwa">\right</span> )$ time to multiply two $n$-digit numbers.  The Comba method requires only $O(pn^<span class="hl num">2</span> + qn)$ time, however in practice, 
the speed increase is actually much more.  With $O(n)$ space the algorithm can be reduced to $O(pn + qn)$ time by implementing the $n$ multiply
and addition operations in the nested loop in parallel.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_fast\_s\_mp\_mul\_digs</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

As per the pseudo--code we first calculate $pa$ (line <span class="hl num">48</span>) as the number of digits to output.  Next we begin the outer loop
to produce the individual columns of the product.  We use the two aliases $tmpx$ and $tmpy$ (lines <span class="hl num">62</span>, <span class="hl num">63</span>) to point
inside the two multiplicands quickly.  

The inner loop (lines <span class="hl num">71</span> to <span class="hl num">74</span>) of this implementation is where the tradeoff come into play.  Originally this comba 
implementation was ``row--major'' which means it adds to each of the columns in each pass.  After the outer loop it would then fix 
the carries.  This was very fast except it had an annoying drawback.  You had to read a mp<span class="hl kwa">\_word</span> and two mp<span class="hl kwa">\_digits</span> and write 
one mp<span class="hl kwa">\_word</span> per iteration.  On processors such as the Athlon XP and P4 this did not matter much since the cache bandwidth 
is very high and it can keep the ALU fed with data.  It did, however, matter on older and embedded cpus where cache is often 
slower and also often doesn't exist.  This new algorithm only performs two reads per iteration under the assumption that the 
compiler has aliased $<span class="hl kwa">\_ \hat</span> W$ to a CPU register.

After the inner loop we store the current accumulator in $W$ and shift $<span class="hl kwa">\_ \hat</span> W$ (lines <span class="hl num">77</span>, <span class="hl num">80</span>) to forward it as 
a carry for the next pass.  After the outer loop we use the final carry (line <span class="hl num">77</span>) as the last digit of the product.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Polynomial Basis Multiplication<span class="hl opt">}</span>
To break the $O(n^<span class="hl num">2</span>)$ barrier in multiplication requires a completely different look at integer multiplication.  In the following algorithms
the use of polynomial basis representation for two integers $a$ and $b$ as $f(x) = <span class="hl kwa">\sum_</span><span class="hl opt">{</span>i=<span class="hl num">0</span><span class="hl opt">}</span>^<span class="hl opt">{</span>n<span class="hl opt">}</span> a_i x^i$ and  
$g(x) = <span class="hl kwa">\sum_</span><span class="hl opt">{</span>i=<span class="hl num">0</span><span class="hl opt">}</span>^<span class="hl opt">{</span>n<span class="hl opt">}</span> b_i x^i$ respectively, is required.  In this system both $f(x)$ and $g(x)$ have $n + <span class="hl num">1</span>$ terms and are of the $n$'th degree.
 
The product $a <span class="hl kwa">\cdot</span> b <span class="hl kwa">\equiv</span> f(x)g(x)$ is the polynomial $W(x) = <span class="hl kwa">\sum_</span><span class="hl opt">{</span>i=<span class="hl num">0</span><span class="hl opt">}</span>^<span class="hl opt">{</span><span class="hl num">2</span>n<span class="hl opt">}</span> w_i x^i$.  The coefficients $w_i$ will
directly yield the desired product when $<span class="hl kwa">\beta</span>$ is substituted for $x$.  The direct solution to solve for the $<span class="hl num">2</span>n + <span class="hl num">1</span>$ coefficients
requires $O(n^<span class="hl num">2</span>)$ time and would in practice be slower than the Comba technique.

However, numerical analysis theory indicates that only $<span class="hl num">2</span>n + <span class="hl num">1</span>$ distinct points in $W(x)$ are required to determine the values of the $<span class="hl num">2</span>n + <span class="hl num">1</span>$ unknown 
coefficients.   This means by finding $<span class="hl kwa">\zeta_y</span> = W(y)$ for $<span class="hl num">2</span>n + <span class="hl num">1</span>$ small values of $y$ the coefficients of $W(x)$ can be found with 
Gaussian elimination.  This technique is also occasionally refered to as the <span class="hl kwa">\textit</span><span class="hl opt">{</span>interpolation technique<span class="hl opt">}</span> (<span class="hl kwa">\textit</span><span class="hl opt">{</span>references please...<span class="hl opt">}</span>) since in 
effect an interpolation based on $<span class="hl num">2</span>n + <span class="hl num">1</span>$ points will yield a polynomial equivalent to $W(x)$.  

The coefficients of the polynomial $W(x)$ are unknown which makes finding $W(y)$ for any value of $y$ impossible.  However, since 
$W(x) = f(x)g(x)$ the equivalent $<span class="hl kwa">\zeta_y</span> = f(y) g(y)$ can be used in its place.  The benefit of this technique stems from the 
fact that $f(y)$ and $g(y)$ are much smaller than either $a$ or $b$ respectively.  As a result finding the $<span class="hl num">2</span>n + <span class="hl num">1</span>$ relations required 
by multiplying $f(y)g(y)$ involves multiplying integers that are much smaller than either of the inputs.

When picking points to gather relations there are always three obvious points to choose, $y = <span class="hl num">0</span>, <span class="hl num">1</span>$ and $ <span class="hl kwa">\infty</span>$.  The $<span class="hl kwa">\zeta_0</span>$ term
is simply the product $W(<span class="hl num">0</span>) = w_0 = a_0 <span class="hl kwa">\cdot</span> b_0$.  The $<span class="hl kwa">\zeta_1</span>$ term is the product 
$W(<span class="hl num">1</span>) = <span class="hl kwa">\left</span> (<span class="hl kwa">\sum_</span><span class="hl opt">{</span>i = <span class="hl num">0</span><span class="hl opt">}</span>^<span class="hl opt">{</span>n<span class="hl opt">}</span> a_i <span class="hl kwa">\right</span> ) <span class="hl kwa">\left</span> (<span class="hl kwa">\sum_</span><span class="hl opt">{</span>i = <span class="hl num">0</span><span class="hl opt">}</span>^<span class="hl opt">{</span>n<span class="hl opt">}</span> b_i <span class="hl kwa">\right</span> )$.  The third point $<span class="hl kwa">\zeta_</span><span class="hl opt">{</span><span class="hl kwa">\infty</span><span class="hl opt">}</span>$ is less obvious but rather
simple to explain.  The $<span class="hl num">2</span>n + <span class="hl num">1</span>$'th coefficient of $W(x)$ is numerically equivalent to the most significant column in an integer multiplication.  
The point at $<span class="hl kwa">\infty</span>$ is used symbolically to represent the most significant column, that is $W(<span class="hl kwa">\infty</span>) = w_<span class="hl opt">{</span><span class="hl num">2</span>n<span class="hl opt">}</span> = a_nb_n$.  Note that the 
points at $y = <span class="hl num">0</span>$ and $<span class="hl kwa">\infty</span>$ yield the coefficients $w_0$ and $w_<span class="hl opt">{</span><span class="hl num">2</span>n<span class="hl opt">}</span>$ directly.

If more points are required they should be of small values and powers of two such as $<span class="hl num">2</span>^q$ and the related <span class="hl kwa">\textit</span><span class="hl opt">{</span>mirror points<span class="hl opt">}</span> 
$<span class="hl kwa">\left</span> (<span class="hl num">2</span>^q <span class="hl kwa">\right</span> )^<span class="hl opt">{</span><span class="hl num">2</span>n<span class="hl opt">}</span>  <span class="hl kwa">\cdot \zeta_</span><span class="hl opt">{</span><span class="hl num">2</span>^<span class="hl opt">{</span>-q<span class="hl opt">}}</span>$ for small values of $q$.  The term ``mirror point'' stems from the fact that 
$<span class="hl kwa">\left</span> (<span class="hl num">2</span>^q <span class="hl kwa">\right</span> )^<span class="hl opt">{</span><span class="hl num">2</span>n<span class="hl opt">}</span>  <span class="hl kwa">\cdot \zeta_</span><span class="hl opt">{</span><span class="hl num">2</span>^<span class="hl opt">{</span>-q<span class="hl opt">}}</span>$ can be calculated in the exact opposite fashion as $<span class="hl kwa">\zeta_</span><span class="hl opt">{</span><span class="hl num">2</span>^q<span class="hl opt">}</span>$.  For
example, when $n = <span class="hl num">2</span>$ and $q = <span class="hl num">1</span>$ then following two equations are equivalent to the point $<span class="hl kwa">\zeta_</span><span class="hl opt">{</span><span class="hl num">2</span><span class="hl opt">}</span>$ and its mirror.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>eqnarray<span class="hl opt">}</span>
<span class="hl kwa">\zeta_</span><span class="hl opt">{</span><span class="hl num">2</span><span class="hl opt">}</span>                  = f(<span class="hl num">2</span>)g(<span class="hl num">2</span>) = (<span class="hl num">4</span>a_2 + <span class="hl num">2</span>a_1 + a_0)(<span class="hl num">4</span>b_2 + <span class="hl num">2</span>b_1 + b_0) <span class="hl kwa">\nonumber</span> \\
<span class="hl num">16</span> <span class="hl kwa">\cdot \zeta_</span><span class="hl opt">{</span><span class="hl num">1</span> <span class="hl kwa">\over</span> <span class="hl num">2</span><span class="hl opt">}</span> = <span class="hl num">4</span>f(<span class="hl opt">{</span><span class="hl num">1</span><span class="hl kwa">\over</span> <span class="hl num">2</span><span class="hl opt">}</span>) <span class="hl kwa">\cdot</span> <span class="hl num">4</span>g(<span class="hl opt">{</span><span class="hl num">1</span> <span class="hl kwa">\over</span> <span class="hl num">2</span><span class="hl opt">}</span>) = (a_2 + <span class="hl num">2</span>a_1 + <span class="hl num">4</span>a_0)(b_2 + <span class="hl num">2</span>b_1 + <span class="hl num">4</span>b_0)
<span class="hl kwa">\end</span><span class="hl opt">{</span>eqnarray<span class="hl opt">}</span>

Using such points will allow the values of $f(y)$ and $g(y)$ to be independently calculated using only left shifts.  For example, when $n = <span class="hl num">2</span>$ the
polynomial $f(<span class="hl num">2</span>^q)$ is equal to $<span class="hl num">2</span>^q((<span class="hl num">2</span>^qa_2) + a_1) + a_0$.  This technique of polynomial representation is known as Horner's method.  

As a general rule of the algorithm when the inputs are split into $n$ parts each there are $<span class="hl num">2</span>n - <span class="hl num">1</span>$ multiplications.  Each multiplication is of 
multiplicands that have $n$ times fewer digits than the inputs.  The asymptotic running time of this algorithm is 
$O <span class="hl kwa">\left</span> ( k^<span class="hl opt">{</span>lg_n(<span class="hl num">2</span>n - <span class="hl num">1</span>)<span class="hl opt">}</span> <span class="hl kwa">\right</span> )$ for $k$ digit inputs (<span class="hl kwa">\textit</span><span class="hl opt">{</span>assuming they have the same number of digits<span class="hl opt">}</span>).  Figure~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:exponent<span class="hl opt">}</span>
summarizes the exponents for various values of $n$.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>|c|c|c|<span class="hl opt">}</span>
<span class="hl kwa">\hline \textbf</span><span class="hl opt">{</span>Split into $n$ Parts<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Exponent<span class="hl opt">}</span>  &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Notes<span class="hl opt">}</span>\\
<span class="hl kwa">\hline</span> $<span class="hl num">2</span>$ &amp; $<span class="hl num">1.584962501</span>$ &amp; This is Karatsuba Multiplication. \\
<span class="hl kwa">\hline</span> $<span class="hl num">3</span>$ &amp; $<span class="hl num">1.464973520</span>$ &amp; This is Toom-Cook Multiplication. \\
<span class="hl kwa">\hline</span> $<span class="hl num">4</span>$ &amp; $<span class="hl num">1.403677461</span>$ &amp;\\
<span class="hl kwa">\hline</span> $<span class="hl num">5</span>$ &amp; $<span class="hl num">1.365212389</span>$ &amp;\\
<span class="hl kwa">\hline</span> $<span class="hl num">10</span>$ &amp; $<span class="hl num">1.278753601</span>$ &amp;\\
<span class="hl kwa">\hline</span> $<span class="hl num">100</span>$ &amp; $<span class="hl num">1.149426538</span>$ &amp;\\
<span class="hl kwa">\hline</span> $<span class="hl num">1000</span>$ &amp; $<span class="hl num">1.100270931</span>$ &amp;\\
<span class="hl kwa">\hline</span> $<span class="hl num">10000</span>$ &amp; $<span class="hl num">1.075252070</span>$ &amp;\\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Asymptotic Running Time of Polynomial Basis Multiplication<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>fig:exponent<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

At first it may seem like a good idea to choose $n = <span class="hl num">1000</span>$ since the exponent is approximately $<span class="hl num">1.1</span>$.  However, the overhead
of solving for the <span class="hl num">2001</span> terms of $W(x)$ will certainly consume any savings the algorithm could offer for all but exceedingly large
numbers.  

<span class="hl kwa">\subsubsection</span><span class="hl opt">{</span>Cutoff Point<span class="hl opt">}</span>
The polynomial basis multiplication algorithms all require fewer single precision multiplications than a straight Comba approach.  However, 
the algorithms incur an overhead (<span class="hl kwa">\textit</span><span class="hl opt">{</span>at the $O(n)$ work level<span class="hl opt">}</span>) since they require a system of equations to be solved.  This makes the
polynomial basis approach more costly to use with small inputs.

Let $m$ represent the number of digits in the multiplicands (<span class="hl kwa">\textit</span><span class="hl opt">{</span>assume both multiplicands have the same number of digits<span class="hl opt">}</span>).  There exists a 
point $y$ such that when $m &lt; y$ the polynomial basis algorithms are more costly than Comba, when $m = y$ they are roughly the same cost and 
when $m &gt; y$ the Comba methods are slower than the polynomial basis algorithms.  

The exact location of $y$ depends on several key architectural elements of the computer platform in question.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>enumerate<span class="hl opt">}</span>
<span class="hl kwa">\item</span>  The ratio of clock cycles for single precision multiplication versus other simpler operations such as addition, shifting, etc.  For example
on the AMD Athlon the ratio is roughly $<span class="hl num">17</span> : <span class="hl num">1</span>$ while on the Intel P4 it is $<span class="hl num">29</span> : <span class="hl num">1</span>$.  The higher the ratio in favour of multiplication the lower
the cutoff point $y$ will be.  

<span class="hl kwa">\item</span>  The complexity of the linear system of equations (<span class="hl kwa">\textit</span><span class="hl opt">{</span>for the coefficients of $W(x)$<span class="hl opt">}</span>) is.  Generally speaking as the number of splits
grows the complexity grows substantially.  Ideally solving the system will only involve addition, subtraction and shifting of integers.  This
directly reflects on the ratio previous mentioned.

<span class="hl kwa">\item</span>  To a lesser extent memory bandwidth and function call overheads.  Provided the values are in the processor cache this is less of an
influence over the cutoff point.

<span class="hl kwa">\end</span><span class="hl opt">{</span>enumerate<span class="hl opt">}</span>

A clean cutoff point separation occurs when a point $y$ is found such that all of the cutoff point conditions are met.  For example, if the point
is too low then there will be values of $m$ such that $m &gt; y$ and the Comba method is still faster.  Finding the cutoff points is fairly simple when
a high resolution timer is available.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Karatsuba Multiplication<span class="hl opt">}</span>
Karatsuba <span class="hl kwa">\cite</span><span class="hl opt">{</span>KARA<span class="hl opt">}</span> multiplication when originally proposed in <span class="hl num">1962</span> was among the first set of algorithms to break the $O(n^<span class="hl num">2</span>)$ barrier for
general purpose multiplication.  Given two polynomial basis representations $f(x) = ax + b$ and $g(x) = cx + d$, Karatsuba proved with 
light algebra <span class="hl kwa">\cite</span><span class="hl opt">{</span>KARAP<span class="hl opt">}</span> that the following polynomial is equivalent to multiplication of the two integers the polynomials represent.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
f(x) <span class="hl kwa">\cdot</span> g(x) = acx^<span class="hl num">2</span> + ((a + b)(c + d) - (ac + bd))x + bd
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

Using the observation that $ac$ and $bd$ could be re-used only three half sized multiplications would be required to produce the product.  Applying
this algorithm recursively, the work factor becomes $O(n^<span class="hl opt">{</span>lg(<span class="hl num">3</span>)<span class="hl opt">}</span>)$ which is substantially better than the work factor $O(n^<span class="hl num">2</span>)$ of the Comba technique.  It turns 
out what Karatsuba did not know or at least did not publish was that this is simply polynomial basis multiplication with the points 
$<span class="hl kwa">\zeta_0</span>$, $<span class="hl kwa">\zeta_</span><span class="hl opt">{</span><span class="hl kwa">\infty</span><span class="hl opt">}</span>$ and $<span class="hl kwa">\zeta_</span><span class="hl opt">{</span><span class="hl num">1</span><span class="hl opt">}</span>$.  Consider the resultant system of equations.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>rcrcrcrc<span class="hl opt">}</span>
$<span class="hl kwa">\zeta_</span><span class="hl opt">{</span><span class="hl num">0</span><span class="hl opt">}</span>$ &amp;      $=$ &amp;  &amp;  &amp;  &amp; &amp; $w_0$ \\
$<span class="hl kwa">\zeta_</span><span class="hl opt">{</span><span class="hl num">1</span><span class="hl opt">}</span>$ &amp;      $=$ &amp; $w_2$ &amp; $+$ &amp; $w_1$ &amp; $+$ &amp; $w_0$ \\
$<span class="hl kwa">\zeta_</span><span class="hl opt">{</span><span class="hl kwa">\infty</span><span class="hl opt">}</span>$ &amp; $=$ &amp; $w_2$ &amp;  &amp; &amp;  &amp; \\
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>

By adding the first and last equation to the equation in the middle the term $w_1$ can be isolated and all three coefficients solved for.  The simplicity
of this system of equations has made Karatsuba fairly popular.  In fact the cutoff point is often fairly low<span class="hl kwa">\footnote</span><span class="hl opt">{</span>With LibTomMath <span class="hl num">0.18</span> it is <span class="hl num">70</span> and <span class="hl num">109</span> digits for the Intel P4 and AMD Athlon respectively.<span class="hl opt">}</span>
making it an ideal algorithm to speed up certain public key cryptosystems such as RSA and Diffie-Hellman.  

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_karatsuba\_mul</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$ and mp<span class="hl kwa">\_int</span> $b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $c <span class="hl kwa">\leftarrow \vert</span> a <span class="hl kwa">\vert \cdot \vert</span> b <span class="hl kwa">\vert</span>$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  Init the following mp<span class="hl kwa">\_int</span> variables: $x0$, $x1$, $y0$, $y1$, $t1$, $x0y0$, $x1y1$.\\
<span class="hl num">2</span>.  If step <span class="hl num">2</span> failed then return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_MEM</span><span class="hl opt">}</span>). \\
\\
Split the input.  e.g. $a = x1 <span class="hl kwa">\cdot \beta</span>^B + x0$ \\
<span class="hl num">3</span>.  $B <span class="hl kwa">\leftarrow \mbox</span><span class="hl opt">{</span>min<span class="hl opt">}</span>(a.used, b.used)/<span class="hl num">2</span>$ \\
<span class="hl num">4</span>.  $x0 <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta</span>^B<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_mod\_2d</span><span class="hl opt">}</span>) \\
<span class="hl num">5</span>.  $y0 <span class="hl kwa">\leftarrow</span> b <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta</span>^B<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl num">6</span>.  $x1 <span class="hl kwa">\leftarrow \lfloor</span> a / <span class="hl kwa">\beta</span>^B <span class="hl kwa">\rfloor</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_rshd</span><span class="hl opt">}</span>) \\
<span class="hl num">7</span>.  $y1 <span class="hl kwa">\leftarrow \lfloor</span> b / <span class="hl kwa">\beta</span>^B <span class="hl kwa">\rfloor</span>$ \\
\\
Calculate the three products. \\
<span class="hl num">8</span>.  $x0y0 <span class="hl kwa">\leftarrow</span> x0 <span class="hl kwa">\cdot</span> y0$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_mul</span><span class="hl opt">}</span>) \\
<span class="hl num">9</span>.  $x1y1 <span class="hl kwa">\leftarrow</span> x1 <span class="hl kwa">\cdot</span> y1$ \\
<span class="hl num">10</span>.  $t1 <span class="hl kwa">\leftarrow</span> x1 + x0$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_add</span><span class="hl opt">}</span>) \\
<span class="hl num">11</span>.  $x0 <span class="hl kwa">\leftarrow</span> y1 + y0$ \\
<span class="hl num">12</span>.  $t1 <span class="hl kwa">\leftarrow</span> t1 <span class="hl kwa">\cdot</span> x0$ \\
\\
Calculate the middle term. \\
<span class="hl num">13</span>.  $x0 <span class="hl kwa">\leftarrow</span> x0y0 + x1y1$ \\
<span class="hl num">14</span>.  $t1 <span class="hl kwa">\leftarrow</span> t1 - x0$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>s<span class="hl kwa">\_mp\_sub</span><span class="hl opt">}</span>) \\
\\
Calculate the final product. \\
<span class="hl num">15</span>.  $t1 <span class="hl kwa">\leftarrow</span> t1 <span class="hl kwa">\cdot \beta</span>^B$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_lshd</span><span class="hl opt">}</span>) \\
<span class="hl num">16</span>.  $x1y1 <span class="hl kwa">\leftarrow</span> x1y1 <span class="hl kwa">\cdot \beta</span>^<span class="hl opt">{</span><span class="hl num">2</span>B<span class="hl opt">}</span>$ \\
<span class="hl num">17</span>.  $t1 <span class="hl kwa">\leftarrow</span> x0y0 + t1$ \\
<span class="hl num">18</span>.  $c <span class="hl kwa">\leftarrow</span> t1 + x1y1$ \\
<span class="hl num">19</span>.  Clear all of the temporary variables. \\
<span class="hl num">20</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>).\\
<span class="hl kwa">\hline</span> 
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_karatsuba\_mul</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_karatsuba\_mul</span>.<span class="hl opt">}</span>
This algorithm computes the unsigned product of two inputs using the Karatsuba multiplication algorithm.  It is loosely based on the description
from Knuth <span class="hl kwa">\cite</span><span class="hl opt">[</span>pp. <span class="hl num">294</span>-<span class="hl num">295</span><span class="hl opt">]{</span>TAOCPV2<span class="hl opt">}</span>.  

<span class="hl kwa">\index</span><span class="hl opt">{</span>radix point<span class="hl opt">}</span>
In order to split the two inputs into their respective halves, a suitable <span class="hl kwa">\textit</span><span class="hl opt">{</span>radix point<span class="hl opt">}</span> must be chosen.  The radix point chosen must
be used for both of the inputs meaning that it must be smaller than the smallest input.  Step <span class="hl num">3</span> chooses the radix point $B$ as half of the 
smallest input <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> count.  After the radix point is chosen the inputs are split into lower and upper halves.  Step <span class="hl num">4</span> and <span class="hl num">5</span> 
compute the lower halves.  Step <span class="hl num">6</span> and <span class="hl num">7</span> computer the upper halves.  

After the halves have been computed the three intermediate half-size products must be computed.  Step <span class="hl num">8</span> and <span class="hl num">9</span> compute the trivial products
$x0 <span class="hl kwa">\cdot</span> y0$ and $x1 <span class="hl kwa">\cdot</span> y1$.  The mp<span class="hl kwa">\_int</span> $x0$ is used as a temporary variable after $x1 + x0$ has been computed.  By using $x0$ instead
of an additional temporary variable, the algorithm can avoid an addition memory allocation operation.

The remaining steps <span class="hl num">13</span> through <span class="hl num">18</span> compute the Karatsuba polynomial through a variety of digit shifting and addition operations.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_karatsuba\_mul</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

The new coding element in this routine, not  seen in previous routines, is the usage of goto statements.  The conventional
wisdom is that goto statements should be avoided.  This is generally true, however when every single function call can fail, it makes sense
to handle error recovery with a single piece of code.  Lines <span class="hl num">62</span> to <span class="hl num">76</span> handle initializing all of the temporary variables 
required.  Note how each of the if statements goes to a different label in case of failure.  This allows the routine to correctly free only
the temporaries that have been successfully allocated so far.

The temporary variables are all initialized using the mp<span class="hl kwa">\_init\_size</span> routine since they are expected to be large.  This saves the 
additional reallocation that would have been necessary.  Also $x0$, $x1$, $y0$ and $y1$ have to be able to hold at least their respective
number of digits for the next section of code.

The first algebraic portion of the algorithm is to split the two inputs into their halves.  However, instead of using mp<span class="hl kwa">\_mod\_2d</span> and mp<span class="hl kwa">\_rshd</span>
to extract the halves, the respective code has been placed inline within the body of the function.  To initialize the halves, the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span> and 
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>sign<span class="hl opt">}</span> members are copied first.  The first for loop on line <span class="hl num">96</span> copies the lower halves.  Since they are both the same magnitude it 
is simpler to calculate both lower halves in a single loop.  The for loop on lines <span class="hl num">102</span> and <span class="hl num">107</span> calculate the upper halves $x1$ and 
$y1$ respectively.

By inlining the calculation of the halves, the Karatsuba multiplier has a slightly lower overhead and can be used for smaller magnitude inputs.

When line <span class="hl num">151</span> is reached, the algorithm has completed succesfully.  The ``error status'' variable $err$ is set to <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span> so that
the same code that handles errors can be used to clear the temporary variables and return.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Toom-Cook $<span class="hl num">3</span>$-Way Multiplication<span class="hl opt">}</span>
Toom-Cook $<span class="hl num">3</span>$-Way <span class="hl kwa">\cite</span><span class="hl opt">{</span>TOOM<span class="hl opt">}</span> multiplication is essentially the polynomial basis algorithm for $n = <span class="hl num">2</span>$ except that the points  are 
chosen such that $<span class="hl kwa">\zeta</span>$ is easy to compute and the resulting system of equations easy to reduce.  Here, the points $<span class="hl kwa">\zeta_</span><span class="hl opt">{</span><span class="hl num">0</span><span class="hl opt">}</span>$, 
$<span class="hl num">16</span> <span class="hl kwa">\cdot \zeta_</span><span class="hl opt">{</span><span class="hl num">1</span> <span class="hl kwa">\over</span> <span class="hl num">2</span><span class="hl opt">}</span>$, $<span class="hl kwa">\zeta_1</span>$, $<span class="hl kwa">\zeta_2</span>$ and $<span class="hl kwa">\zeta_</span><span class="hl opt">{</span><span class="hl kwa">\infty</span><span class="hl opt">}</span>$ make up the five required points to solve for the coefficients 
of the $W(x)$.

With the five relations that Toom-Cook specifies, the following system of equations is formed.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>rcrcrcrcrcr<span class="hl opt">}</span>
$<span class="hl kwa">\zeta_0</span>$                    &amp; $=$ &amp; $<span class="hl num">0</span>w_4$ &amp; $+$ &amp; $<span class="hl num">0</span>w_3$ &amp; $+$ &amp; $<span class="hl num">0</span>w_2$ &amp; $+$ &amp; $<span class="hl num">0</span>w_1$ &amp; $+$ &amp; $<span class="hl num">1</span>w_0$  \\
$<span class="hl num">16</span> <span class="hl kwa">\cdot \zeta_</span><span class="hl opt">{</span><span class="hl num">1</span> <span class="hl kwa">\over</span> <span class="hl num">2</span><span class="hl opt">}</span>$ &amp; $=$ &amp; $<span class="hl num">1</span>w_4$ &amp; $+$ &amp; $<span class="hl num">2</span>w_3$ &amp; $+$ &amp; $<span class="hl num">4</span>w_2$ &amp; $+$ &amp; $<span class="hl num">8</span>w_1$ &amp; $+$ &amp; $<span class="hl num">16</span>w_0$  \\
$<span class="hl kwa">\zeta_1</span>$                    &amp; $=$ &amp; $<span class="hl num">1</span>w_4$ &amp; $+$ &amp; $<span class="hl num">1</span>w_3$ &amp; $+$ &amp; $<span class="hl num">1</span>w_2$ &amp; $+$ &amp; $<span class="hl num">1</span>w_1$ &amp; $+$ &amp; $<span class="hl num">1</span>w_0$  \\
$<span class="hl kwa">\zeta_2</span>$                    &amp; $=$ &amp; $<span class="hl num">16</span>w_4$ &amp; $+$ &amp; $<span class="hl num">8</span>w_3$ &amp; $+$ &amp; $<span class="hl num">4</span>w_2$ &amp; $+$ &amp; $<span class="hl num">2</span>w_1$ &amp; $+$ &amp; $<span class="hl num">1</span>w_0$  \\
$<span class="hl kwa">\zeta_</span><span class="hl opt">{</span><span class="hl kwa">\infty</span><span class="hl opt">}</span>$             &amp; $=$ &amp; $<span class="hl num">1</span>w_4$ &amp; $+$ &amp; $<span class="hl num">0</span>w_3$ &amp; $+$ &amp; $<span class="hl num">0</span>w_2$ &amp; $+$ &amp; $<span class="hl num">0</span>w_1$ &amp; $+$ &amp; $<span class="hl num">0</span>w_0$  \\
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>

A trivial solution to this matrix requires $<span class="hl num">12</span>$ subtractions, two multiplications by a small power of two, two divisions by a small power
of two, two divisions by three and one multiplication by three.  All of these $<span class="hl num">19</span>$ sub-operations require less than quadratic time, meaning that
the algorithm can be faster than a baseline multiplication.  However, the greater complexity of this algorithm places the cutoff point
(<span class="hl kwa">\textbf</span><span class="hl opt">{</span>TOOM<span class="hl kwa">\_MUL\_CUTOFF</span><span class="hl opt">}</span>) where Toom-Cook becomes more efficient much higher than the Karatsuba cutoff point.  

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_toom\_mul</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$ and mp<span class="hl kwa">\_int</span> $b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $c <span class="hl kwa">\leftarrow</span>  a  <span class="hl kwa">\cdot</span>  b $ \\
<span class="hl kwa">\hline</span> \\
Split $a$ and $b$ into three pieces.  E.g. $a = a_2 <span class="hl kwa">\beta</span>^<span class="hl opt">{</span><span class="hl num">2</span>k<span class="hl opt">}</span> + a_1 <span class="hl kwa">\beta</span>^<span class="hl opt">{</span>k<span class="hl opt">}</span> + a_0$ \\
<span class="hl num">1</span>.  $k <span class="hl kwa">\leftarrow \lfloor \mbox</span><span class="hl opt">{</span>min<span class="hl opt">}</span>(a.used, b.used) / <span class="hl num">3</span> <span class="hl kwa">\rfloor</span>$ \\
<span class="hl num">2</span>.  $a_0 <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta</span>^<span class="hl opt">{</span>k<span class="hl opt">}</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl num">3</span>.  $a_1 <span class="hl kwa">\leftarrow \lfloor</span> a / <span class="hl kwa">\beta</span>^k <span class="hl kwa">\rfloor</span>$, $a_1 <span class="hl kwa">\leftarrow</span> a_1 <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta</span>^<span class="hl opt">{</span>k<span class="hl opt">}</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl num">4</span>.  $a_2 <span class="hl kwa">\leftarrow \lfloor</span> a / <span class="hl kwa">\beta</span>^<span class="hl opt">{</span><span class="hl num">2</span>k<span class="hl opt">}</span> <span class="hl kwa">\rfloor</span>$, $a_2 <span class="hl kwa">\leftarrow</span> a_2 <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta</span>^<span class="hl opt">{</span>k<span class="hl opt">}</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl num">5</span>.  $b_0 <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta</span>^<span class="hl opt">{</span>k<span class="hl opt">}</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl num">6</span>.  $b_1 <span class="hl kwa">\leftarrow \lfloor</span> a / <span class="hl kwa">\beta</span>^k <span class="hl kwa">\rfloor</span>$, $b_1 <span class="hl kwa">\leftarrow</span> b_1 <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta</span>^<span class="hl opt">{</span>k<span class="hl opt">}</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl num">7</span>.  $b_2 <span class="hl kwa">\leftarrow \lfloor</span> a / <span class="hl kwa">\beta</span>^<span class="hl opt">{</span><span class="hl num">2</span>k<span class="hl opt">}</span> <span class="hl kwa">\rfloor</span>$, $b_2 <span class="hl kwa">\leftarrow</span> b_2 <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta</span>^<span class="hl opt">{</span>k<span class="hl opt">}</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
\\
Find the five equations for $w_0, w_1, ..., w_4$. \\
<span class="hl num">8</span>.  $w_0 <span class="hl kwa">\leftarrow</span> a_0 <span class="hl kwa">\cdot</span> b_0$ \\
<span class="hl num">9</span>.  $w_4 <span class="hl kwa">\leftarrow</span> a_2 <span class="hl kwa">\cdot</span> b_2$ \\
<span class="hl num">10</span>. $tmp_1 <span class="hl kwa">\leftarrow</span> <span class="hl num">2</span> <span class="hl kwa">\cdot</span> a_0$, $tmp_1 <span class="hl kwa">\leftarrow</span> a_1 + tmp_1$, $tmp_1 <span class="hl kwa">\leftarrow</span> <span class="hl num">2</span> <span class="hl kwa">\cdot</span> tmp_1$, $tmp_1 <span class="hl kwa">\leftarrow</span> tmp_1 + a_2$ \\
<span class="hl num">11</span>. $tmp_2 <span class="hl kwa">\leftarrow</span> <span class="hl num">2</span> <span class="hl kwa">\cdot</span> b_0$, $tmp_2 <span class="hl kwa">\leftarrow</span> b_1 + tmp_2$, $tmp_2 <span class="hl kwa">\leftarrow</span> <span class="hl num">2</span> <span class="hl kwa">\cdot</span> tmp_2$, $tmp_2 <span class="hl kwa">\leftarrow</span> tmp_2 + b_2$ \\
<span class="hl num">12</span>. $w_1 <span class="hl kwa">\leftarrow</span> tmp_1 <span class="hl kwa">\cdot</span> tmp_2$ \\
<span class="hl num">13</span>. $tmp_1 <span class="hl kwa">\leftarrow</span> <span class="hl num">2</span> <span class="hl kwa">\cdot</span> a_2$, $tmp_1 <span class="hl kwa">\leftarrow</span> a_1 + tmp_1$, $tmp_1 <span class="hl kwa">\leftarrow</span> <span class="hl num">2</span> <span class="hl kwa">\cdot</span> tmp_1$, $tmp_1 <span class="hl kwa">\leftarrow</span> tmp_1 + a_0$ \\
<span class="hl num">14</span>. $tmp_2 <span class="hl kwa">\leftarrow</span> <span class="hl num">2</span> <span class="hl kwa">\cdot</span> b_2$, $tmp_2 <span class="hl kwa">\leftarrow</span> b_1 + tmp_2$, $tmp_2 <span class="hl kwa">\leftarrow</span> <span class="hl num">2</span> <span class="hl kwa">\cdot</span> tmp_2$, $tmp_2 <span class="hl kwa">\leftarrow</span> tmp_2 + b_0$ \\
<span class="hl num">15</span>. $w_3 <span class="hl kwa">\leftarrow</span> tmp_1 <span class="hl kwa">\cdot</span> tmp_2$ \\
<span class="hl num">16</span>. $tmp_1 <span class="hl kwa">\leftarrow</span> a_0 + a_1$, $tmp_1 <span class="hl kwa">\leftarrow</span> tmp_1 + a_2$, $tmp_2 <span class="hl kwa">\leftarrow</span> b_0 + b_1$, $tmp_2 <span class="hl kwa">\leftarrow</span> tmp_2 + b_2$ \\
<span class="hl num">17</span>. $w_2 <span class="hl kwa">\leftarrow</span> tmp_1 <span class="hl kwa">\cdot</span> tmp_2$ \\
\\
Continued on the next page.\\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_toom\_mul</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_toom\_mul</span><span class="hl opt">}</span> (continued). \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$ and mp<span class="hl kwa">\_int</span> $b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $c <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\cdot</span>  b $ \\
<span class="hl kwa">\hline</span> \\
Now solve the system of equations. \\
<span class="hl num">18</span>. $w_1 <span class="hl kwa">\leftarrow</span> w_4 - w_1$, $w_3 <span class="hl kwa">\leftarrow</span> w_3 - w_0$ \\
<span class="hl num">19</span>. $w_1 <span class="hl kwa">\leftarrow \lfloor</span> w_1 / <span class="hl num">2</span> <span class="hl kwa">\rfloor</span>$, $w_3 <span class="hl kwa">\leftarrow \lfloor</span> w_3 / <span class="hl num">2</span> <span class="hl kwa">\rfloor</span>$ \\
<span class="hl num">20</span>. $w_2 <span class="hl kwa">\leftarrow</span> w_2 - w_0$, $w_2 <span class="hl kwa">\leftarrow</span> w_2 - w_4$ \\
<span class="hl num">21</span>. $w_1 <span class="hl kwa">\leftarrow</span> w_1 - w_2$, $w_3 <span class="hl kwa">\leftarrow</span> w_3 - w_2$ \\
<span class="hl num">22</span>. $tmp_1 <span class="hl kwa">\leftarrow</span> <span class="hl num">8</span> <span class="hl kwa">\cdot</span> w_0$, $w_1 <span class="hl kwa">\leftarrow</span> w_1 - tmp_1$, $tmp_1 <span class="hl kwa">\leftarrow</span> <span class="hl num">8</span> <span class="hl kwa">\cdot</span> w_4$, $w_3 <span class="hl kwa">\leftarrow</span> w_3 - tmp_1$ \\
<span class="hl num">23</span>. $w_2 <span class="hl kwa">\leftarrow</span> <span class="hl num">3</span> <span class="hl kwa">\cdot</span> w_2$, $w_2 <span class="hl kwa">\leftarrow</span> w_2 - w_1$, $w_2 <span class="hl kwa">\leftarrow</span> w_2 - w_3$ \\
<span class="hl num">24</span>. $w_1 <span class="hl kwa">\leftarrow</span> w_1 - w_2$, $w_3 <span class="hl kwa">\leftarrow</span> w_3 - w_2$ \\
<span class="hl num">25</span>. $w_1 <span class="hl kwa">\leftarrow \lfloor</span> w_1 / <span class="hl num">3</span> <span class="hl kwa">\rfloor</span>, w_3 <span class="hl kwa">\leftarrow \lfloor</span> w_3 / <span class="hl num">3</span> <span class="hl kwa">\rfloor</span>$ \\
\\
Now substitute $<span class="hl kwa">\beta</span>^k$ for $x$ by shifting $w_0, w_1, ..., w_4$. \\
<span class="hl num">26</span>. for $n$ from $<span class="hl num">1</span>$ to $<span class="hl num">4</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">26.1</span>  $w_n <span class="hl kwa">\leftarrow</span> w_n <span class="hl kwa">\cdot \beta</span>^<span class="hl opt">{</span>nk<span class="hl opt">}</span>$ \\
<span class="hl num">27</span>. $c <span class="hl kwa">\leftarrow</span> w_0 + w_1$, $c <span class="hl kwa">\leftarrow</span> c + w_2$, $c <span class="hl kwa">\leftarrow</span> c + w_3$, $c <span class="hl kwa">\leftarrow</span> c + w_4$ \\
<span class="hl num">28</span>. Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_toom\_mul</span> (continued)<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_toom\_mul</span>.<span class="hl opt">}</span>
This algorithm computes the product of two mp<span class="hl kwa">\_int</span> variables $a$ and $b$ using the Toom-Cook approach.  Compared to the Karatsuba multiplication, this 
algorithm has a lower asymptotic running time of approximately $O(n^<span class="hl opt">{</span><span class="hl num">1.464</span><span class="hl opt">}</span>)$ but at an obvious cost in overhead.  In this
description, several statements have been compounded to save space.  The intention is that the statements are executed from left to right across
any given step.

The two inputs $a$ and $b$ are first split into three $k$-digit integers $a_0, a_1, a_2$ and $b_0, b_1, b_2$ respectively.  From these smaller
integers the coefficients of the polynomial basis representations $f(x)$ and $g(x)$ are known and can be used to find the relations required.

The first two relations $w_0$ and $w_4$ are the points $<span class="hl kwa">\zeta_</span><span class="hl opt">{</span><span class="hl num">0</span><span class="hl opt">}</span>$ and $<span class="hl kwa">\zeta_</span><span class="hl opt">{</span><span class="hl kwa">\infty</span><span class="hl opt">}</span>$ respectively.  The relation $w_1, w_2$ and $w_3$ correspond
to the points $<span class="hl num">16</span> <span class="hl kwa">\cdot \zeta_</span><span class="hl opt">{</span><span class="hl num">1</span> <span class="hl kwa">\over</span> <span class="hl num">2</span><span class="hl opt">}</span>, <span class="hl kwa">\zeta_</span><span class="hl opt">{</span><span class="hl num">2</span><span class="hl opt">}</span>$ and $<span class="hl kwa">\zeta_</span><span class="hl opt">{</span><span class="hl num">1</span><span class="hl opt">}</span>$ respectively.  These are found using logical shifts to independently find
$f(y)$ and $g(y)$ which significantly speeds up the algorithm.

After the five relations $w_0, w_1, <span class="hl kwa">\ldots</span>, w_4$ have been computed, the system they represent must be solved in order for the unknown coefficients 
$w_1, w_2$ and $w_3$ to be isolated.  The steps <span class="hl num">18</span> through <span class="hl num">25</span> perform the system reduction required as previously described.  Each step of
the reduction represents the comparable matrix operation that would be performed had this been performed by pencil.  For example, step <span class="hl num">18</span> indicates
that row $<span class="hl num">1</span>$ must be subtracted from row $<span class="hl num">4</span>$ and simultaneously row $<span class="hl num">0</span>$ subtracted from row $<span class="hl num">3</span>$.  

Once the coeffients have been isolated, the polynomial $W(x) = <span class="hl kwa">\sum_</span><span class="hl opt">{</span>i=<span class="hl num">0</span><span class="hl opt">}</span>^<span class="hl opt">{</span><span class="hl num">2</span>n<span class="hl opt">}</span> w_i x^i$ is known.  By substituting $<span class="hl kwa">\beta</span>^<span class="hl opt">{</span>k<span class="hl opt">}</span>$ for $x$, the integer 
result $a <span class="hl kwa">\cdot</span> b$ is produced.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_toom\_mul</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

The first obvious thing to note is that this algorithm is complicated.  The complexity is worth it if you are multiplying very 
large numbers.  For example, a <span class="hl num">10</span>,<span class="hl num">000</span> digit multiplication takes approximaly <span class="hl num">99</span>,<span class="hl num">282</span>,<span class="hl num">205</span> fewer single precision multiplications with
Toom--Cook than a Comba or baseline approach (this is a savings of more than <span class="hl num">99</span>$\%$).  For most ``crypto'' sized numbers this
algorithm is not practical as Karatsuba has a much lower cutoff point.

First we split $a$ and $b$ into three roughly equal portions.  This has been accomplished (lines <span class="hl num">41</span> to <span class="hl num">70</span>) with 
combinations of mp<span class="hl kwa">\_rshd</span>() and mp<span class="hl kwa">\_mod\_2d</span>() function calls.  At this point $a = a2 <span class="hl kwa">\cdot \beta</span>^<span class="hl num">2</span> + a1 <span class="hl kwa">\cdot \beta</span> + a0$ and similiarly
for $b$.  

Next we compute the five points $w0, w1, w2, w3$ and $w4$.  Recall that $w0$ and $w4$ can be computed directly from the portions so
we get those out of the way first (lines <span class="hl num">73</span> and <span class="hl num">78</span>).  Next we compute $w1, w2$ and $w3$ using Horners method.

After this point we solve for the actual values of $w1, w2$ and $w3$ by reducing the $<span class="hl num">5</span> <span class="hl kwa">\times</span> <span class="hl num">5</span>$ system which is relatively
straight forward.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Signed Multiplication<span class="hl opt">}</span>
Now that algorithms to handle multiplications of every useful dimensions have been developed, a rather simple finishing touch is required.  So far all
of the multiplication algorithms have been unsigned multiplications which leaves only a signed multiplication algorithm to be established.  

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_mul</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$ and mp<span class="hl kwa">\_int</span> $b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $c <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\cdot</span> b$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  If $a.sign = b.sign$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.1</span>  $sign = MP<span class="hl kwa">\_ZPOS</span>$ \\
<span class="hl num">2</span>.  else \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  $sign = MP<span class="hl kwa">\_ZNEG</span>$ \\
<span class="hl num">3</span>.  If min$(a.used, b.used) <span class="hl kwa">\ge</span> TOOM<span class="hl kwa">\_MUL\_CUTOFF</span>$ then  \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">3.1</span>  $c <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\cdot</span> b$ using algorithm mp<span class="hl kwa">\_toom\_mul</span> \\
<span class="hl num">4</span>.  else if min$(a.used, b.used) <span class="hl kwa">\ge</span> KARATSUBA<span class="hl kwa">\_MUL\_CUTOFF</span>$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.1</span>  $c <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\cdot</span> b$ using algorithm mp<span class="hl kwa">\_karatsuba\_mul</span> \\
<span class="hl num">5</span>.  else \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.1</span>  $digs <span class="hl kwa">\leftarrow</span> a.used + b.used + <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.2</span>  If $digs &lt; MP<span class="hl kwa">\_ARRAY</span>$ and min$(a.used, b.used) <span class="hl kwa">\le \delta</span>$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">5.2.1</span>  $c <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\cdot</span> b <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta</span>^<span class="hl opt">{</span>digs<span class="hl opt">}</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ using algorithm fast<span class="hl kwa">\_s\_mp\_mul\_digs</span>.  \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.3</span>  else \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">5.3.1</span>  $c <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\cdot</span> b <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta</span>^<span class="hl opt">{</span>digs<span class="hl opt">}</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ using algorithm s<span class="hl kwa">\_mp\_mul\_digs</span>.  \\
<span class="hl num">6</span>.  $c.sign <span class="hl kwa">\leftarrow</span> sign$ \\
<span class="hl num">7</span>.  Return the result of the unsigned multiplication performed. \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_mul</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_mul</span>.<span class="hl opt">}</span>
This algorithm performs the signed multiplication of two inputs.  It will make use of any of the three unsigned multiplication algorithms 
available when the input is of appropriate size.  The <span class="hl kwa">\textbf</span><span class="hl opt">{</span>sign<span class="hl opt">}</span> of the result is not set until the end of the algorithm since algorithm
s<span class="hl kwa">\_mp\_mul\_digs</span> will clear it.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_mul</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

The implementation is rather simplistic and is not particularly noteworthy.  Line <span class="hl num">22</span> computes the sign of the result using the ``?'' 
operator from the C programming language.  Line <span class="hl num">48</span> computes $<span class="hl kwa">\delta</span>$ using the fact that $<span class="hl num">1</span> &lt;&lt; k$ is equal to $<span class="hl num">2</span>^k$.  

<span class="hl kwa">\section</span><span class="hl opt">{</span>Squaring<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>sec:basesquare<span class="hl opt">}</span>

Squaring is a special case of multiplication where both multiplicands are equal.  At first it may seem like there is no significant optimization
available but in fact there is.  Consider the multiplication of $<span class="hl num">576</span>$ against $<span class="hl num">241</span>$.  In total there will be nine single precision multiplications
performed which are $<span class="hl num">1</span><span class="hl kwa">\cdot</span> <span class="hl num">6</span>$, $<span class="hl num">1</span> <span class="hl kwa">\cdot</span> <span class="hl num">7</span>$, $<span class="hl num">1</span> <span class="hl kwa">\cdot</span> <span class="hl num">5</span>$, $<span class="hl num">4</span> <span class="hl kwa">\cdot</span> <span class="hl num">6</span>$, $<span class="hl num">4</span> <span class="hl kwa">\cdot</span> <span class="hl num">7</span>$, $<span class="hl num">4</span> <span class="hl kwa">\cdot</span> <span class="hl num">5</span>$, $<span class="hl num">2</span> <span class="hl kwa">\cdot</span>  <span class="hl num">6</span>$, $<span class="hl num">2</span> <span class="hl kwa">\cdot</span> <span class="hl num">7</span>$ and $<span class="hl num">2</span> <span class="hl kwa">\cdot</span> <span class="hl num">5</span>$.  Now consider 
the multiplication of $<span class="hl num">123</span>$ against $<span class="hl num">123</span>$.  The nine products are $<span class="hl num">3</span> <span class="hl kwa">\cdot</span> <span class="hl num">3</span>$, $<span class="hl num">3</span> <span class="hl kwa">\cdot</span> <span class="hl num">2</span>$, $<span class="hl num">3</span> <span class="hl kwa">\cdot</span> <span class="hl num">1</span>$, $<span class="hl num">2</span> <span class="hl kwa">\cdot</span> <span class="hl num">3</span>$, $<span class="hl num">2</span> <span class="hl kwa">\cdot</span> <span class="hl num">2</span>$, $<span class="hl num">2</span> <span class="hl kwa">\cdot</span> <span class="hl num">1</span>$, 
$<span class="hl num">1</span> <span class="hl kwa">\cdot</span> <span class="hl num">3</span>$, $<span class="hl num">1</span> <span class="hl kwa">\cdot</span> <span class="hl num">2</span>$ and $<span class="hl num">1</span> <span class="hl kwa">\cdot</span> <span class="hl num">1</span>$.  On closer inspection some of the products are equivalent.  For example, $<span class="hl num">3</span> <span class="hl kwa">\cdot</span> <span class="hl num">2</span> = <span class="hl num">2</span> <span class="hl kwa">\cdot</span> <span class="hl num">3</span>$ 
and $<span class="hl num">3</span> <span class="hl kwa">\cdot</span> <span class="hl num">1</span> = <span class="hl num">1</span> <span class="hl kwa">\cdot</span> <span class="hl num">3</span>$. 

For any $n$-digit input, there are $<span class="hl opt">{{</span><span class="hl kwa">\left</span> (n^<span class="hl num">2</span> + n <span class="hl kwa">\right</span>)<span class="hl opt">}</span><span class="hl kwa">\over</span> <span class="hl num">2</span><span class="hl opt">}</span>$ possible unique single precision multiplications required compared to the $n^<span class="hl num">2</span>$
required for multiplication.  The following diagram gives an example of the operations required.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>ccccc|c<span class="hl opt">}</span>
&amp;&amp;<span class="hl num">1</span>&amp;<span class="hl num">2</span>&amp;<span class="hl num">3</span>&amp;\\
$<span class="hl kwa">\times</span>$ &amp;&amp;<span class="hl num">1</span>&amp;<span class="hl num">2</span>&amp;<span class="hl num">3</span>&amp;\\
<span class="hl kwa">\hline</span> &amp;&amp; $<span class="hl num">3</span> <span class="hl kwa">\cdot</span> <span class="hl num">1</span>$ &amp; $<span class="hl num">3</span> <span class="hl kwa">\cdot</span> <span class="hl num">2</span>$ &amp; $<span class="hl num">3</span> <span class="hl kwa">\cdot</span> <span class="hl num">3</span>$ &amp; Row <span class="hl num">0</span>\\
       &amp; $<span class="hl num">2</span> <span class="hl kwa">\cdot</span> <span class="hl num">1</span>$  &amp; $<span class="hl num">2</span> <span class="hl kwa">\cdot</span> <span class="hl num">2</span>$ &amp; $<span class="hl num">2</span> <span class="hl kwa">\cdot</span> <span class="hl num">3</span>$ &amp;&amp; Row <span class="hl num">1</span> \\
         $<span class="hl num">1</span> <span class="hl kwa">\cdot</span> <span class="hl num">1</span>$  &amp; $<span class="hl num">1</span> <span class="hl kwa">\cdot</span> <span class="hl num">2</span>$ &amp; $<span class="hl num">1</span> <span class="hl kwa">\cdot</span> <span class="hl num">3</span>$ &amp;&amp;&amp; Row <span class="hl num">2</span> \\
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Squaring Optimization Diagram<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

Starting from zero and numbering the columns from right to left a very simple pattern becomes obvious.  For the purposes of this discussion let $x$
represent the number being squared.  The first observation is that in row $k$ the $<span class="hl num">2</span>k$'th column of the product has a $<span class="hl kwa">\left</span> (x_k <span class="hl kwa">\right</span>)^<span class="hl num">2</span>$ term in it.  

The second observation is that every column $j$ in row $k$ where $j <span class="hl kwa">\ne</span> <span class="hl num">2</span>k$ is part of a double product.  Every non-square term of a column will
appear twice hence the name ``double product''.  Every odd column is made up entirely of double products.  In fact every column is made up of double 
products and at most one square (<span class="hl kwa">\textit</span><span class="hl opt">{</span>see the exercise section<span class="hl opt">}</span>).  

The third and final observation is that for row $k$ the first unique non-square term, that is, one that hasn't already appeared in an earlier row, 
occurs at column $<span class="hl num">2</span>k + <span class="hl num">1</span>$.  For example, on row $<span class="hl num">1</span>$ of the previous squaring, column one is part of the double product with column one from row zero. 
Column two of row one is a square and column three is the first unique column.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>The Baseline Squaring Algorithm<span class="hl opt">}</span>
The baseline squaring algorithm is meant to be a catch-all squaring algorithm.  It will handle any of the input sizes that the faster routines
will not handle.  

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>s<span class="hl kwa">\_mp\_sqr</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $b <span class="hl kwa">\leftarrow</span> a^<span class="hl num">2</span>$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  Init a temporary mp<span class="hl kwa">\_int</span> of at least $<span class="hl num">2</span> <span class="hl kwa">\cdot</span> a.used +<span class="hl num">1</span>$ digits.  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_init\_size</span><span class="hl opt">}</span>) \\
<span class="hl num">2</span>.  If step <span class="hl num">1</span> failed return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_MEM</span><span class="hl opt">}</span>) \\
<span class="hl num">3</span>.  $t.used <span class="hl kwa">\leftarrow</span> <span class="hl num">2</span> <span class="hl kwa">\cdot</span> a.used + <span class="hl num">1</span>$ \\
<span class="hl num">4</span>.  For $ix$ from <span class="hl num">0</span> to $a.used - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span>Calculate the square. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.1</span>  $<span class="hl kwa">\hat</span> r <span class="hl kwa">\leftarrow</span> t_<span class="hl opt">{</span><span class="hl num">2</span>ix<span class="hl opt">}</span> + <span class="hl kwa">\left</span> (a_<span class="hl opt">{</span>ix<span class="hl opt">}</span> <span class="hl kwa">\right</span> )^<span class="hl num">2</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.2</span>  $t_<span class="hl opt">{</span><span class="hl num">2</span>ix<span class="hl opt">}</span> <span class="hl kwa">\leftarrow \hat</span> r <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span>Calculate the double products after the square. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.3</span>  $u <span class="hl kwa">\leftarrow \lfloor \hat</span> r / <span class="hl kwa">\beta \rfloor</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.4</span>  For $iy$ from $ix + <span class="hl num">1</span>$ to $a.used - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">4.4.1</span>  $<span class="hl kwa">\hat</span> r <span class="hl kwa">\leftarrow</span> <span class="hl num">2</span> <span class="hl kwa">\cdot</span> a_<span class="hl opt">{</span>ix<span class="hl opt">}</span>a_<span class="hl opt">{</span>iy<span class="hl opt">}</span> + t_<span class="hl opt">{</span>ix + iy<span class="hl opt">}</span> + u$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">4.4.2</span>  $t_<span class="hl opt">{</span>ix + iy<span class="hl opt">}</span> <span class="hl kwa">\leftarrow \hat</span> r <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">4.4.3</span>  $u <span class="hl kwa">\leftarrow \lfloor \hat</span> r / <span class="hl kwa">\beta \rfloor</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span>Set the last carry. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.5</span>  While $u &gt; <span class="hl num">0</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">4.5.1</span>  $iy <span class="hl kwa">\leftarrow</span> iy + <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">4.5.2</span>  $<span class="hl kwa">\hat</span> r <span class="hl kwa">\leftarrow</span> t_<span class="hl opt">{</span>ix + iy<span class="hl opt">}</span> + u$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">4.5.3</span>  $t_<span class="hl opt">{</span>ix + iy<span class="hl opt">}</span> <span class="hl kwa">\leftarrow \hat</span> r <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">4.5.4</span>  $u <span class="hl kwa">\leftarrow \lfloor \hat</span> r / <span class="hl kwa">\beta \rfloor</span>$ \\
<span class="hl num">5</span>.  Clamp excess digits of $t$.  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_clamp</span><span class="hl opt">}</span>) \\
<span class="hl num">6</span>.  Exchange $b$ and $t$. \\
<span class="hl num">7</span>.  Clear $t$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_clear</span><span class="hl opt">}</span>) \\
<span class="hl num">8</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm s<span class="hl kwa">\_mp\_sqr</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm s<span class="hl kwa">\_mp\_sqr</span>.<span class="hl opt">}</span>
This algorithm computes the square of an input using the three observations on squaring.  It is based fairly faithfully on  algorithm <span class="hl num">14.16</span> of HAC
<span class="hl kwa">\cite</span><span class="hl opt">[</span>pp<span class="hl num">.596</span>-<span class="hl num">597</span><span class="hl opt">]{</span>HAC<span class="hl opt">}</span>.  Similar to algorithm s<span class="hl kwa">\_mp\_mul\_digs</span>, a temporary mp<span class="hl kwa">\_int</span> is allocated to hold the result of the squaring.  This allows the 
destination mp<span class="hl kwa">\_int</span> to be the same as the source mp<span class="hl kwa">\_int</span>.

The outer loop of this algorithm begins on step <span class="hl num">4</span>. It is best to think of the outer loop as walking down the rows of the partial results, while
the inner loop computes the columns of the partial result.  Step <span class="hl num">4.1</span> and <span class="hl num">4.2</span> compute the square term for each row, and step <span class="hl num">4.3</span> and <span class="hl num">4.4</span> propagate
the carry and compute the double products.  

The requirement that a mp<span class="hl kwa">\_word</span> be able to represent the range $<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; <span class="hl num">2</span> <span class="hl kwa">\beta</span>^<span class="hl num">2</span>$ arises from this
very algorithm.  The product $a_<span class="hl opt">{</span>ix<span class="hl opt">}</span>a_<span class="hl opt">{</span>iy<span class="hl opt">}</span>$ will lie in the range $<span class="hl num">0</span> <span class="hl kwa">\le</span> x <span class="hl kwa">\le \beta</span>^<span class="hl num">2</span> - <span class="hl num">2</span><span class="hl kwa">\beta</span> + <span class="hl num">1</span>$ which is obviously less than $<span class="hl kwa">\beta</span>^<span class="hl num">2</span>$ meaning that
when it is multiplied by two, it can be properly represented by a mp<span class="hl kwa">\_word</span>.

Similar to algorithm s<span class="hl kwa">\_mp\_mul\_digs</span>, after every pass of the inner loop, the destination is correctly set to the sum of all of the partial 
results calculated so far.  This involves expensive carry propagation which will be eliminated in the next algorithm.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_s\_mp\_sqr</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

Inside the outer loop (line <span class="hl num">34</span>) the square term is calculated on line <span class="hl num">37</span>.  The carry (line <span class="hl num">44</span>) has been
extracted from the mp<span class="hl kwa">\_word</span> accumulator using a right shift.  Aliases for $a_<span class="hl opt">{</span>ix<span class="hl opt">}</span>$ and $t_<span class="hl opt">{</span>ix+iy<span class="hl opt">}</span>$ are initialized 
(lines <span class="hl num">47</span> and <span class="hl num">50</span>) to simplify the inner loop.  The doubling is performed using two
additions (line <span class="hl num">59</span>) since it is usually faster than shifting, if not at least as fast.  

The important observation is that the inner loop does not begin at $iy = <span class="hl num">0</span>$ like for multiplication.  As such the inner loops
get progressively shorter as the algorithm proceeds.  This is what leads to the savings compared to using a multiplication to
square a number. 

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Faster Squaring by the ``Comba'' Method<span class="hl opt">}</span>
A major drawback to the baseline method is the requirement for single precision shifting inside the $O(n^<span class="hl num">2</span>)$ nested loop.  Squaring has an additional
drawback that it must double the product inside the inner loop as well.  As for multiplication, the Comba technique can be used to eliminate these
performance hazards.

The first obvious solution is to make an array of mp<span class="hl kwa">\_words</span> which will hold all of the columns.  This will indeed eliminate all of the carry
propagation operations from the inner loop.  However, the inner product must still be doubled $O(n^<span class="hl num">2</span>)$ times.  The solution stems from the simple fact
that $<span class="hl num">2</span>a + <span class="hl num">2</span>b + <span class="hl num">2</span>c = <span class="hl num">2</span>(a + b + c)$.  That is the sum of all of the double products is equal to double the sum of all the products.  For example,
$ab + ba + ac + ca = <span class="hl num">2</span>ab + <span class="hl num">2</span>ac = <span class="hl num">2</span>(ab + ac)$.  

However, we cannot simply double all of the columns, since the squares appear only once per row.  The most practical solution is to have two 
mp<span class="hl kwa">\_word</span> arrays.  One array will hold the squares and the other array will hold the double products.  With both arrays the doubling and 
carry propagation can be moved to a $O(n)$ work level outside the $O(n^<span class="hl num">2</span>)$ level.  In this case, we have an even simpler solution in mind.

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>fast<span class="hl kwa">\_s\_mp\_sqr</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $b <span class="hl kwa">\leftarrow</span> a^<span class="hl num">2</span>$ \\
<span class="hl kwa">\hline</span> \\
Place an array of <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_WARRAY</span><span class="hl opt">}</span> mp<span class="hl kwa">\_digits</span> named $W$ on the stack. \\
<span class="hl num">1</span>.  If $b.alloc &lt; <span class="hl num">2</span>a.used + <span class="hl num">1</span>$ then grow $b$ to $<span class="hl num">2</span>a.used + <span class="hl num">1</span>$ digits.  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_grow</span><span class="hl opt">}</span>). \\
<span class="hl num">2</span>.  If step <span class="hl num">1</span> failed return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_MEM</span><span class="hl opt">}</span>). \\
\\
<span class="hl num">3</span>.  $pa <span class="hl kwa">\leftarrow</span> <span class="hl num">2</span> <span class="hl kwa">\cdot</span> a.used$ \\
<span class="hl num">4</span>.  $<span class="hl kwa">\hat</span> W1 <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">5</span>.  for $ix$ from $<span class="hl num">0</span>$ to $pa - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.1</span>  $<span class="hl kwa">\_ \hat</span> W <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.2</span>  $ty <span class="hl kwa">\leftarrow \mbox</span><span class="hl opt">{</span>MIN<span class="hl opt">}</span>(a.used - <span class="hl num">1</span>, ix)$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.3</span>  $tx <span class="hl kwa">\leftarrow</span> ix - ty$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.4</span>  $iy <span class="hl kwa">\leftarrow \mbox</span><span class="hl opt">{</span>MIN<span class="hl opt">}</span>(a.used - tx, ty + <span class="hl num">1</span>)$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.5</span>  $iy <span class="hl kwa">\leftarrow \mbox</span><span class="hl opt">{</span>MIN<span class="hl opt">}</span>(iy, <span class="hl kwa">\lfloor \left</span> (ty - tx + <span class="hl num">1</span> <span class="hl kwa">\right</span> )/<span class="hl num">2</span> <span class="hl kwa">\rfloor</span>)$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.6</span>  for $iz$ from $<span class="hl num">0</span>$ to $iz - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">5.6.1</span>  $<span class="hl kwa">\_ \hat</span> W <span class="hl kwa">\leftarrow \_ \hat</span> W + a_<span class="hl opt">{</span>tx + iz<span class="hl opt">}</span>a_<span class="hl opt">{</span>ty - iz<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.7</span>  $<span class="hl kwa">\_ \hat</span> W <span class="hl kwa">\leftarrow</span> <span class="hl num">2</span> <span class="hl kwa">\cdot \_ \hat</span> W  + <span class="hl kwa">\hat</span> W1$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.8</span>  if $ix$ is even then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">5.8.1</span>  $<span class="hl kwa">\_ \hat</span> W <span class="hl kwa">\leftarrow \_ \hat</span> W + <span class="hl kwa">\left</span> ( a_<span class="hl opt">{</span><span class="hl kwa">\lfloor</span> ix/<span class="hl num">2</span> <span class="hl kwa">\rfloor</span><span class="hl opt">}</span><span class="hl kwa">\right</span> )^<span class="hl num">2</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.9</span>  $W_<span class="hl opt">{</span>ix<span class="hl opt">}</span> <span class="hl kwa">\leftarrow \_ \hat</span> W (<span class="hl kwa">\mbox</span><span class="hl opt">{</span>mod <span class="hl opt">}</span><span class="hl kwa">\beta</span>)$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.10</span>  $<span class="hl kwa">\hat</span> W1 <span class="hl kwa">\leftarrow \lfloor \_ \hat</span> W / <span class="hl kwa">\beta \rfloor</span>$ \\
\\
<span class="hl num">6</span>.  $oldused <span class="hl kwa">\leftarrow</span> b.used$ \\
<span class="hl num">7</span>.  $b.used <span class="hl kwa">\leftarrow</span> <span class="hl num">2</span> <span class="hl kwa">\cdot</span> a.used$ \\
<span class="hl num">8</span>.  for $ix$ from $<span class="hl num">0</span>$ to $pa - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">8.1</span>  $b_<span class="hl opt">{</span>ix<span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> W_<span class="hl opt">{</span>ix<span class="hl opt">}</span>$ \\
<span class="hl num">9</span>.  for $ix$ from $pa$ to $oldused - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">9.1</span>  $b_<span class="hl opt">{</span>ix<span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">10</span>.  Clamp excess digits from $b$.  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_clamp</span><span class="hl opt">}</span>) \\
<span class="hl num">11</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\ 
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm fast<span class="hl kwa">\_s\_mp\_sqr</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm fast<span class="hl kwa">\_s\_mp\_sqr</span>.<span class="hl opt">}</span>
This algorithm computes the square of an input using the Comba technique.  It is designed to be a replacement for algorithm 
s<span class="hl kwa">\_mp\_sqr</span> when the number of input digits is less than <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_WARRAY</span><span class="hl opt">}</span> and less than $<span class="hl kwa">\delta \over</span> <span class="hl num">2</span>$.  
This algorithm is very similar to the Comba multiplier except with a few key differences we shall make note of.

First, we have an accumulator and carry variables $<span class="hl kwa">\_ \hat</span> W$ and $<span class="hl kwa">\hat</span> W1$ respectively.  This is because the inner loop
products are to be doubled.  If we had added the previous carry in we would be doubling too much.  Next we perform an
addition MIN condition on $iy$ (step <span class="hl num">5.5</span>) to prevent overlapping digits.  For example, $a_3 <span class="hl kwa">\cdot</span> a_5$ is equal
$a_5 <span class="hl kwa">\cdot</span> a_3$.  Whereas in the multiplication case we would have $<span class="hl num">5</span> &lt; a.used$ and $<span class="hl num">3</span> <span class="hl kwa">\ge</span> <span class="hl num">0</span>$ is maintained since we double the sum
of the products just outside the inner loop we have to avoid doing this.  This is also a good thing since we perform
fewer multiplications and the routine ends up being faster.

Finally the last difference is the addition of the ``square'' term outside the inner loop (step <span class="hl num">5.8</span>).  We add in the square
only to even outputs and it is the square of the term at the $<span class="hl kwa">\lfloor</span> ix / <span class="hl num">2</span> <span class="hl kwa">\rfloor</span>$ position.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_fast\_s\_mp\_sqr</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

This implementation is essentially a copy of Comba multiplication with the appropriate changes added to make it faster for 
the special case of squaring.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Polynomial Basis Squaring<span class="hl opt">}</span>
The same algorithm that performs optimal polynomial basis multiplication can be used to perform polynomial basis squaring.  The minor exception
is that $<span class="hl kwa">\zeta_y</span> = f(y)g(y)$ is actually equivalent to $<span class="hl kwa">\zeta_y</span> = f(y)^<span class="hl num">2</span>$ since $f(y) = g(y)$.  Instead of performing $<span class="hl num">2</span>n + <span class="hl num">1</span>$
multiplications to find the $<span class="hl kwa">\zeta</span>$ relations, squaring operations are performed instead.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Karatsuba Squaring<span class="hl opt">}</span>
Let $f(x) = ax + b$ represent the polynomial basis representation of a number to square.  
Let $h(x) = <span class="hl kwa">\left</span> ( f(x) <span class="hl kwa">\right</span> )^<span class="hl num">2</span>$ represent the square of the polynomial.  The Karatsuba equation can be modified to square a 
number with the following equation.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
h(x) = a^<span class="hl num">2</span>x^<span class="hl num">2</span> + <span class="hl kwa">\left</span> ((a + b)^<span class="hl num">2</span> - (a^<span class="hl num">2</span> + b^<span class="hl num">2</span>) <span class="hl kwa">\right</span> )x + b^<span class="hl num">2</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

Upon closer inspection this equation only requires the calculation of three half-sized squares: $a^<span class="hl num">2</span>$, $b^<span class="hl num">2</span>$ and $(a + b)^<span class="hl num">2</span>$.  As in 
Karatsuba multiplication, this algorithm can be applied recursively on the input and will achieve an asymptotic running time of 
$O <span class="hl kwa">\left</span> ( n^<span class="hl opt">{</span>lg(<span class="hl num">3</span>)<span class="hl opt">}</span> <span class="hl kwa">\right</span> )$.

If the asymptotic times of Karatsuba squaring and multiplication are the same, why not simply use the multiplication algorithm 
instead?  The answer to this arises from the cutoff point for squaring.  As in multiplication there exists a cutoff point, at which the 
time required for a Comba based squaring and a Karatsuba based squaring meet.  Due to the overhead inherent in the Karatsuba method, the cutoff 
point is fairly high.  For example, on an AMD Athlon XP processor with $<span class="hl kwa">\beta</span> = <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">28</span><span class="hl opt">}</span>$, the cutoff point is around <span class="hl num">127</span> digits.  

Consider squaring a <span class="hl num">200</span> digit number with this technique.  It will be split into two <span class="hl num">100</span> digit halves which are subsequently squared.  
The <span class="hl num">100</span> digit halves will not be squared using Karatsuba, but instead using the faster Comba based squaring algorithm.  If Karatsuba multiplication
were used instead, the <span class="hl num">100</span> digit numbers would be squared with a slower Comba based multiplication.  

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_karatsuba\_sqr</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $b <span class="hl kwa">\leftarrow</span> a^<span class="hl num">2</span>$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  Initialize the following temporary mp<span class="hl kwa">\_ints</span>:  $x0$, $x1$, $t1$, $t2$, $x0x0$ and $x1x1$. \\
<span class="hl num">2</span>.  If any of the initializations on step <span class="hl num">1</span> failed return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_MEM</span><span class="hl opt">}</span>). \\
\\
Split the input.  e.g. $a = x1<span class="hl kwa">\beta</span>^B + x0$ \\
<span class="hl num">3</span>.  $B <span class="hl kwa">\leftarrow \lfloor</span> a.used / <span class="hl num">2</span> <span class="hl kwa">\rfloor</span>$ \\
<span class="hl num">4</span>.  $x0 <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta</span>^B<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_mod\_2d</span><span class="hl opt">}</span>) \\
<span class="hl num">5</span>.  $x1 <span class="hl kwa">\leftarrow \lfloor</span> a / <span class="hl kwa">\beta</span>^B <span class="hl kwa">\rfloor</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_lshd</span><span class="hl opt">}</span>) \\
\\
Calculate the three squares. \\
<span class="hl num">6</span>.  $x0x0 <span class="hl kwa">\leftarrow</span> x0^<span class="hl num">2</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_sqr</span><span class="hl opt">}</span>) \\
<span class="hl num">7</span>.  $x1x1 <span class="hl kwa">\leftarrow</span> x1^<span class="hl num">2</span>$ \\
<span class="hl num">8</span>.  $t1 <span class="hl kwa">\leftarrow</span> x1 + x0$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>s<span class="hl kwa">\_mp\_add</span><span class="hl opt">}</span>) \\
<span class="hl num">9</span>.  $t1 <span class="hl kwa">\leftarrow</span> t1^<span class="hl num">2</span>$ \\
\\
Compute the middle term. \\
<span class="hl num">10</span>.  $t2 <span class="hl kwa">\leftarrow</span> x0x0 + x1x1$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>s<span class="hl kwa">\_mp\_add</span><span class="hl opt">}</span>) \\
<span class="hl num">11</span>.  $t1 <span class="hl kwa">\leftarrow</span> t1 - t2$ \\
\\
Compute final product. \\
<span class="hl num">12</span>.  $t1 <span class="hl kwa">\leftarrow</span> t1<span class="hl kwa">\beta</span>^B$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_lshd</span><span class="hl opt">}</span>) \\
<span class="hl num">13</span>.  $x1x1 <span class="hl kwa">\leftarrow</span> x1x1<span class="hl kwa">\beta</span>^<span class="hl opt">{</span><span class="hl num">2</span>B<span class="hl opt">}</span>$ \\
<span class="hl num">14</span>.  $t1 <span class="hl kwa">\leftarrow</span> t1 + x0x0$ \\
<span class="hl num">15</span>.  $b <span class="hl kwa">\leftarrow</span> t1 + x1x1$ \\
<span class="hl num">16</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_karatsuba\_sqr</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_karatsuba\_sqr</span>.<span class="hl opt">}</span>
This algorithm computes the square of an input $a$ using the Karatsuba technique.  This algorithm is very similar to the Karatsuba based
multiplication algorithm with the exception that the three half-size multiplications have been replaced with three half-size squarings.

The radix point for squaring is simply placed exactly in the middle of the digits when the input has an odd number of digits, otherwise it is
placed just below the middle.  Step <span class="hl num">3</span>, <span class="hl num">4</span> and <span class="hl num">5</span> compute the two halves required using $B$
as the radix point.  The first two squares in steps <span class="hl num">6</span> and <span class="hl num">7</span> are rather straightforward while the last square is of a more compact form.

By expanding $<span class="hl kwa">\left</span> (x1 + x0 <span class="hl kwa">\right</span> )^<span class="hl num">2</span>$, the $x1^<span class="hl num">2</span>$ and $x0^<span class="hl num">2</span>$ terms in the middle disappear, that is $(x0 - x1)^<span class="hl num">2</span> - (x1^<span class="hl num">2</span> + x0^<span class="hl num">2</span>)  = <span class="hl num">2</span> <span class="hl kwa">\cdot</span> x0 <span class="hl kwa">\cdot</span> x1$.
Now if $<span class="hl num">5</span>n$ single precision additions and a squaring of $n$-digits is faster than multiplying two $n$-digit numbers and doubling then
this method is faster.  Assuming no further recursions occur, the difference can be estimated with the following inequality.

Let $p$ represent the cost of a single precision addition and $q$ the cost of a single precision multiplication both in terms of time<span class="hl kwa">\footnote</span><span class="hl opt">{</span>Or
machine clock cycles.<span class="hl opt">}</span>. 

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
<span class="hl num">5</span>pn +<span class="hl opt">{{</span>q(n^<span class="hl num">2</span> + n)<span class="hl opt">}</span> <span class="hl kwa">\over</span> <span class="hl num">2</span><span class="hl opt">}</span> <span class="hl kwa">\le</span> pn + qn^<span class="hl num">2</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

For example, on an AMD Athlon XP processor $p = <span class="hl opt">{</span><span class="hl num">1</span> <span class="hl kwa">\over</span> <span class="hl num">3</span><span class="hl opt">}</span>$ and $q = <span class="hl num">6</span>$.  This implies that the following inequality should hold.
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>rcl<span class="hl opt">}</span>
$<span class="hl opt">{</span><span class="hl num">5</span>n <span class="hl kwa">\over</span> <span class="hl num">3</span><span class="hl opt">}</span> + <span class="hl num">3</span>n^<span class="hl num">2</span> + <span class="hl num">3</span>n$     &amp; $&lt;$ &amp; $<span class="hl opt">{</span>n <span class="hl kwa">\over</span> <span class="hl num">3</span><span class="hl opt">}</span> + <span class="hl num">6</span>n^<span class="hl num">2</span>$ \\
$<span class="hl opt">{</span><span class="hl num">5</span> <span class="hl kwa">\over</span> <span class="hl num">3</span><span class="hl opt">}</span> + <span class="hl num">3</span>n + <span class="hl num">3</span>$     &amp; $&lt;$ &amp; $<span class="hl opt">{</span><span class="hl num">1</span> <span class="hl kwa">\over</span> <span class="hl num">3</span><span class="hl opt">}</span> + <span class="hl num">6</span>n$ \\
$<span class="hl opt">{</span><span class="hl num">13</span> <span class="hl kwa">\over</span> <span class="hl num">9</span><span class="hl opt">}</span>$     &amp; $&lt;$ &amp; $n$ \\
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>

This results in a cutoff point around $n = <span class="hl num">2</span>$.  As a consequence it is actually faster to compute the middle term the ``long way'' on processors
where multiplication is substantially slower<span class="hl kwa">\footnote</span><span class="hl opt">{</span>On the Athlon there is a <span class="hl num">1</span>:<span class="hl num">17</span> ratio between clock cycles for addition and multiplication.  On
the Intel P4 processor this ratio is <span class="hl num">1</span>:<span class="hl num">29</span> making this method even more beneficial.  The only common exception is the ARMv4 processor which has a
ratio of <span class="hl num">1</span>:<span class="hl num">7</span>.  <span class="hl opt">}</span> than simpler operations such as addition.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_karatsuba\_sqr</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

This implementation is largely based on the implementation of algorithm mp<span class="hl kwa">\_karatsuba\_mul</span>.  It uses the same inline style to copy and 
shift the input into the two halves.  The loop from line <span class="hl num">54</span> to line <span class="hl num">70</span> has been modified since only one input exists.  The <span class="hl kwa">\textbf</span><span class="hl opt">{</span>used<span class="hl opt">}</span>
count of both $x0$ and $x1$ is fixed up and $x0$ is clamped before the calculations begin.  At this point $x1$ and $x0$ are valid equivalents
to the respective halves as if mp<span class="hl kwa">\_rshd</span> and mp<span class="hl kwa">\_mod\_2d</span> had been used.  

By inlining the copy and shift operations the cutoff point for Karatsuba multiplication can be lowered.  On the Athlon the cutoff point
is exactly at the point where Comba squaring can no longer be used (<span class="hl kwa">\textit</span><span class="hl opt">{</span><span class="hl num">128</span> digits<span class="hl opt">}</span>).  On slower processors such as the Intel P4
it is actually below the Comba limit (<span class="hl kwa">\textit</span><span class="hl opt">{</span>at <span class="hl num">110</span> digits<span class="hl opt">}</span>).

This routine uses the same error trap coding style as mp<span class="hl kwa">\_karatsuba\_sqr</span>.  As the temporary variables are initialized errors are 
redirected to the error trap higher up.  If the algorithm completes without error the error code is set to <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span> and 
mp<span class="hl kwa">\_clears</span> are executed normally.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Toom-Cook Squaring<span class="hl opt">}</span>
The Toom-Cook squaring algorithm mp<span class="hl kwa">\_toom\_sqr</span> is heavily based on the algorithm mp<span class="hl kwa">\_toom\_mul</span> with the exception that squarings are used
instead of multiplication to find the five relations.  The reader is encouraged to read the description of the latter algorithm and try to 
derive their own Toom-Cook squaring algorithm.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>High Level Squaring<span class="hl opt">}</span>
<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_sqr</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $b <span class="hl kwa">\leftarrow</span> a^<span class="hl num">2</span>$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  If $a.used <span class="hl kwa">\ge</span> TOOM<span class="hl kwa">\_SQR\_CUTOFF</span>$ then  \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.1</span>  $b <span class="hl kwa">\leftarrow</span> a^<span class="hl num">2</span>$ using algorithm mp<span class="hl kwa">\_toom\_sqr</span> \\
<span class="hl num">2</span>.  else if $a.used <span class="hl kwa">\ge</span> KARATSUBA<span class="hl kwa">\_SQR\_CUTOFF</span>$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  $b <span class="hl kwa">\leftarrow</span> a^<span class="hl num">2</span>$ using algorithm mp<span class="hl kwa">\_karatsuba\_sqr</span> \\
<span class="hl num">3</span>.  else \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">3.1</span>  $digs <span class="hl kwa">\leftarrow</span> a.used + b.used + <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">3.2</span>  If $digs &lt; MP<span class="hl kwa">\_ARRAY</span>$ and $a.used <span class="hl kwa">\le \delta</span>$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">3.2.1</span>  $b <span class="hl kwa">\leftarrow</span> a^<span class="hl num">2</span>$ using algorithm fast<span class="hl kwa">\_s\_mp\_sqr</span>.  \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">3.3</span>  else \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">3.3.1</span>  $b <span class="hl kwa">\leftarrow</span> a^<span class="hl num">2</span>$ using algorithm s<span class="hl kwa">\_mp\_sqr</span>.  \\
<span class="hl num">4</span>.  $b.sign <span class="hl kwa">\leftarrow</span> MP<span class="hl kwa">\_ZPOS</span>$ \\
<span class="hl num">5</span>.  Return the result of the unsigned squaring performed. \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_sqr</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_sqr</span>.<span class="hl opt">}</span>
This algorithm computes the square of the input using one of four different algorithms.  If the input is very large and has at least
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>TOOM<span class="hl kwa">\_SQR\_CUTOFF</span><span class="hl opt">}</span> or <span class="hl kwa">\textbf</span><span class="hl opt">{</span>KARATSUBA<span class="hl kwa">\_SQR\_CUTOFF</span><span class="hl opt">}</span> digits then either the Toom-Cook or the Karatsuba Squaring algorithm is used.  If
neither of the polynomial basis algorithms should be used then either the Comba or baseline algorithm is used.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_sqr</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

<span class="hl kwa">\section</span>*<span class="hl opt">{</span>Exercises<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>cl<span class="hl opt">}</span>
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">3</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span> $ &amp; Devise an efficient algorithm for selection of the radix point to handle inputs \\
                      &amp; that have different number of digits in Karatsuba multiplication. \\
                      &amp; \\
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">2</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span> $ &amp; In section <span class="hl num">5.3</span> the fact that every column of a squaring is made up \\
                      &amp; of double products and at most one square is stated.  Prove this statement. \\
                      &amp; \\                      
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">3</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span> $ &amp; Prove the equation for Karatsuba squaring. \\
                      &amp; \\
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">1</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span> $ &amp; Prove that Karatsuba squaring requires $O <span class="hl kwa">\left</span> (n^<span class="hl opt">{</span>lg(<span class="hl num">3</span>)<span class="hl opt">}</span> <span class="hl kwa">\right</span> )$ time. \\
                      &amp; \\ 
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">2</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span> $ &amp; Determine the minimal ratio between addition and multiplication clock cycles \\
                      &amp; required for equation $<span class="hl num">6.7</span>$ to be true.  \\
                      &amp; \\
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">3</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span> $ &amp; Implement a threaded version of Comba multiplication (and squaring) where you \\
                      &amp; compute subsets of the columns in each thread.  Determine a cutoff point where \\
                      &amp; it is effective and add the logic to mp<span class="hl kwa">\_mul</span>() and mp<span class="hl kwa">\_sqr</span>(). \\
                      &amp;\\
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">4</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span> $ &amp; Same as the previous but also modify the Karatsuba and Toom-Cook.  You must \\
                      &amp; increase the throughput of mp<span class="hl kwa">\_exptmod</span>() for random odd moduli in the range \\
                      &amp; $<span class="hl num">512</span> <span class="hl kwa">\ldots</span> <span class="hl num">4096</span>$ bits significantly ($&gt; <span class="hl num">2</span>x$) to complete this challenge. \\
                      &amp; \\
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>

<span class="hl kwa">\chapter</span><span class="hl opt">{</span>Modular Reduction<span class="hl opt">}</span>
<span class="hl kwa">\section</span><span class="hl opt">{</span>Basics of Modular Reduction<span class="hl opt">}</span>
<span class="hl kwa">\index</span><span class="hl opt">{</span>modular residue<span class="hl opt">}</span>
Modular reduction is an operation that arises quite often within public key cryptography algorithms and various number theoretic algorithms, 
such as factoring.  Modular reduction algorithms are the third class of algorithms of the ``multipliers'' set.  A number $a$ is said to be <span class="hl kwa">\textit</span><span class="hl opt">{</span>reduced<span class="hl opt">}</span>
modulo another number $b$ by finding the remainder of the division $a/b$.  Full integer division with remainder is a topic to be covered 
in~<span class="hl kwa">\ref</span><span class="hl opt">{</span>sec:division<span class="hl opt">}</span>.

Modular reduction is equivalent to solving for $r$ in the following equation.  $a = bq + r$ where $q = <span class="hl kwa">\lfloor</span> a/b <span class="hl kwa">\rfloor</span>$.  The result 
$r$ is said to be ``congruent to $a$ modulo $b$'' which is also written as $r <span class="hl kwa">\equiv</span> a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>b<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$.  In other vernacular $r$ is known as the 
``modular residue'' which leads to ``quadratic residue''<span class="hl kwa">\footnote</span><span class="hl opt">{</span>That's fancy talk for $b <span class="hl kwa">\equiv</span> a^<span class="hl num">2</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$.<span class="hl opt">}</span> and
other forms of residues.  

Modular reductions are normally used to create either finite groups, rings or fields.  The most common usage for performance driven modular reductions 
is in modular exponentiation algorithms.  That is to compute $d = a^b <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>c<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ as fast as possible.  This operation is used in the 
RSA and Diffie-Hellman public key algorithms, for example.  Modular multiplication and squaring also appears as a fundamental operation in 
elliptic curve cryptographic algorithms.  As will be discussed in the subsequent chapter there exist fast algorithms for computing modular 
exponentiations without having to perform (<span class="hl kwa">\textit</span><span class="hl opt">{</span>in this example<span class="hl opt">}</span>) $b - <span class="hl num">1</span>$ multiplications.  These algorithms will produce partial results in the 
range $<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; c^<span class="hl num">2</span>$ which can be taken advantage of to create several efficient algorithms.   They have also been used to create redundancy check 
algorithms known as CRCs, error correction codes such as Reed-Solomon and solve a variety of number theoeretic problems.  

<span class="hl kwa">\section</span><span class="hl opt">{</span>The Barrett Reduction<span class="hl opt">}</span>
The Barrett reduction algorithm <span class="hl kwa">\cite</span><span class="hl opt">{</span>BARRETT<span class="hl opt">}</span> was inspired by fast division algorithms which multiply by the reciprocal to emulate
division.  Barretts observation was that the residue $c$ of $a$ modulo $b$ is equal to 

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
c = a - b <span class="hl kwa">\cdot \lfloor</span> a/b <span class="hl kwa">\rfloor</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

Since algorithms such as modular exponentiation would be using the same modulus extensively, typical DSP<span class="hl kwa">\footnote</span><span class="hl opt">{</span>It is worth noting that Barrett's paper 
targeted the DSP56K processor.<span class="hl opt">}</span>  intuition would indicate the next step would be to replace $a/b$ by a multiplication by the reciprocal.  However, 
DSP intuition on its own will not work as these numbers are considerably larger than the precision of common DSP floating point data types.  
It would take another common optimization to optimize the algorithm.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Fixed Point Arithmetic<span class="hl opt">}</span>
The trick used to optimize the above equation is based on a technique of emulating floating point data types with fixed precision integers.  Fixed
point arithmetic would become very popular as it greatly optimize the ``<span class="hl num">3</span>d-shooter'' genre of games in the mid <span class="hl num">1990</span>s when floating point units were 
fairly slow if not unavailable.   The idea behind fixed point arithmetic is to take a normal $k$-bit integer data type and break it into $p$-bit 
integer and a $q$-bit fraction part (<span class="hl kwa">\textit</span><span class="hl opt">{</span>where $p+q = k$<span class="hl opt">}</span>).  

In this system a $k$-bit integer $n$ would actually represent $n/<span class="hl num">2</span>^q$.  For example, with $q = <span class="hl num">4</span>$ the integer $n = <span class="hl num">37</span>$ would actually represent the
value $<span class="hl num">2.3125</span>$.  To multiply two fixed point numbers the integers are multiplied using traditional arithmetic and subsequently normalized by 
moving the implied decimal point back to where it should be.  For example, with $q = <span class="hl num">4</span>$ to multiply the integers $<span class="hl num">9</span>$ and $<span class="hl num">5</span>$ they must be converted 
to fixed point first by multiplying by $<span class="hl num">2</span>^q$.  Let $a = <span class="hl num">9</span>(<span class="hl num">2</span>^q)$ represent the fixed point representation of $<span class="hl num">9</span>$ and $b = <span class="hl num">5</span>(<span class="hl num">2</span>^q)$ represent the 
fixed point representation of $<span class="hl num">5</span>$.  The product $ab$ is equal to $<span class="hl num">45</span>(<span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">2</span>q<span class="hl opt">}</span>)$ which when normalized by dividing by $<span class="hl num">2</span>^q$ produces $<span class="hl num">45</span>(<span class="hl num">2</span>^q)$.  

This technique became popular since a normal integer multiplication and logical shift right are the only required operations to perform a multiplication
of two fixed point numbers.  Using fixed point arithmetic, division can be easily approximated by multiplying by the reciprocal.  If $<span class="hl num">2</span>^q$ is 
equivalent to one than $<span class="hl num">2</span>^q/b$ is equivalent to the fixed point approximation of $<span class="hl num">1</span>/b$ using real arithmetic.  Using this fact dividing an integer 
$a$ by another integer $b$ can be achieved with the following expression.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
<span class="hl kwa">\lfloor</span> a / b <span class="hl kwa">\rfloor \mbox</span><span class="hl opt">{ }</span><span class="hl kwa">\approx\mbox</span><span class="hl opt">{ }</span> <span class="hl kwa">\lfloor</span> (a <span class="hl kwa">\cdot \lfloor</span> <span class="hl num">2</span>^q / b <span class="hl kwa">\rfloor</span>)/<span class="hl num">2</span>^q <span class="hl kwa">\rfloor</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

The precision of the division is proportional to the value of $q$.  If the divisor $b$ is used frequently as is the case with 
modular exponentiation pre-computing $<span class="hl num">2</span>^q/b$ will allow a division to be performed with a multiplication and a right shift.  Both operations
are considerably faster than division on most processors.  

Consider dividing $<span class="hl num">19</span>$ by $<span class="hl num">5</span>$.  The correct result is $<span class="hl kwa">\lfloor</span> <span class="hl num">19</span>/<span class="hl num">5</span> <span class="hl kwa">\rfloor</span> = <span class="hl num">3</span>$.  With $q = <span class="hl num">3</span>$ the reciprocal is $<span class="hl kwa">\lfloor</span> <span class="hl num">2</span>^q/<span class="hl num">5</span> <span class="hl kwa">\rfloor</span> = <span class="hl num">1</span>$ which
leads to a product of $<span class="hl num">19</span>$ which when divided by $<span class="hl num">2</span>^q$ produces $<span class="hl num">2</span>$.  However, with $q = <span class="hl num">4</span>$ the reciprocal is $<span class="hl kwa">\lfloor</span> <span class="hl num">2</span>^q/<span class="hl num">5</span> <span class="hl kwa">\rfloor</span> = <span class="hl num">3</span>$ and
the result of the emulated division is $<span class="hl kwa">\lfloor</span> <span class="hl num">3</span> <span class="hl kwa">\cdot</span> <span class="hl num">19</span> / <span class="hl num">2</span>^q <span class="hl kwa">\rfloor</span> = <span class="hl num">3</span>$ which is correct.  The value of $<span class="hl num">2</span>^q$ must be close to or ideally
larger than the dividend.  In effect if $a$ is the dividend then $q$ should allow $<span class="hl num">0</span> <span class="hl kwa">\le \lfloor</span> a/<span class="hl num">2</span>^q <span class="hl kwa">\rfloor \le</span> <span class="hl num">1</span>$ in order for this approach
to work correctly.  Plugging this form of divison into the original equation the following modular residue equation arises.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
c = a - b <span class="hl kwa">\cdot \lfloor</span> (a <span class="hl kwa">\cdot \lfloor</span> <span class="hl num">2</span>^q / b <span class="hl kwa">\rfloor</span>)/<span class="hl num">2</span>^q <span class="hl kwa">\rfloor</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

Using the notation from <span class="hl kwa">\cite</span><span class="hl opt">{</span>BARRETT<span class="hl opt">}</span> the value of $<span class="hl kwa">\lfloor</span> <span class="hl num">2</span>^q / b <span class="hl kwa">\rfloor</span>$ will be represented by the $<span class="hl kwa">\mu</span>$ symbol.  Using the $<span class="hl kwa">\mu</span>$
variable also helps re-inforce the idea that it is meant to be computed once and re-used.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
c = a - b <span class="hl kwa">\cdot \lfloor</span> (a <span class="hl kwa">\cdot \mu</span>)/<span class="hl num">2</span>^q <span class="hl kwa">\rfloor</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

Provided that $<span class="hl num">2</span>^q <span class="hl kwa">\ge</span> a$ this algorithm will produce a quotient that is either exactly correct or off by a value of one.  In the context of Barrett
reduction the value of $a$ is bound by $<span class="hl num">0</span> <span class="hl kwa">\le</span> a <span class="hl kwa">\le</span> (b - <span class="hl num">1</span>)^<span class="hl num">2</span>$ meaning that $<span class="hl num">2</span>^q <span class="hl kwa">\ge</span> b^<span class="hl num">2</span>$ is sufficient to ensure the reciprocal will have enough
precision.  

Let $n$ represent the number of digits in $b$.  This algorithm requires approximately $<span class="hl num">2</span>n^<span class="hl num">2</span>$ single precision multiplications to produce the quotient and 
another $n^<span class="hl num">2</span>$ single precision multiplications to find the residue.  In total $<span class="hl num">3</span>n^<span class="hl num">2</span>$ single precision multiplications are required to 
reduce the number.  

For example, if $b = <span class="hl num">1179677</span>$ and $q = <span class="hl num">41</span>$ ($<span class="hl num">2</span>^q &gt; b^<span class="hl num">2</span>$), then the reciprocal $<span class="hl kwa">\mu</span>$ is equal to $<span class="hl kwa">\lfloor</span> <span class="hl num">2</span>^q / b <span class="hl kwa">\rfloor</span> = <span class="hl num">1864089</span>$.  Consider reducing
$a = <span class="hl num">180388626447</span>$ modulo $b$ using the above reduction equation.  The quotient using the new formula is $<span class="hl kwa">\lfloor</span> (a <span class="hl kwa">\cdot \mu</span>) / <span class="hl num">2</span>^q <span class="hl kwa">\rfloor</span> = <span class="hl num">152913</span>$.
By subtracting $<span class="hl num">152913</span>b$ from $a$ the correct residue $a <span class="hl kwa">\equiv</span> <span class="hl num">677346</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>b<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ is found.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Choosing a Radix Point<span class="hl opt">}</span>
Using the fixed point representation a modular reduction can be performed with $<span class="hl num">3</span>n^<span class="hl num">2</span>$ single precision multiplications.  If that were the best
that could be achieved a full division<span class="hl kwa">\footnote</span><span class="hl opt">{</span>A division requires approximately $O(<span class="hl num">2</span>cn^<span class="hl num">2</span>)$ single precision multiplications for a small value of $c$.  
See~<span class="hl kwa">\ref</span><span class="hl opt">{</span>sec:division<span class="hl opt">}</span> for further details.<span class="hl opt">}</span> might as well be used in its place.  The key to optimizing the reduction is to reduce the precision of
the initial multiplication that finds the quotient.  

Let $a$ represent the number of which the residue is sought.  Let $b$ represent the modulus used to find the residue.  Let $m$ represent
the number of digits in $b$.  For the purposes of this discussion we will assume that the number of digits in $a$ is $<span class="hl num">2</span>m$, which is generally true if 
two $m$-digit numbers have been multiplied.  Dividing $a$ by $b$ is the same as dividing a $<span class="hl num">2</span>m$ digit integer by a $m$ digit integer.  Digits below the 
$m - <span class="hl num">1</span>$'th digit of $a$ will contribute at most a value of $<span class="hl num">1</span>$ to the quotient because $<span class="hl kwa">\beta</span>^k &lt; b$ for any $<span class="hl num">0</span> <span class="hl kwa">\le</span> k <span class="hl kwa">\le</span> m - <span class="hl num">1</span>$.  Another way to
express this is by re-writing $a$ as two parts.  If $a' <span class="hl kwa">\equiv</span> a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>b^m<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ and $a'' = a - a'$ then 
$<span class="hl opt">{</span>a <span class="hl kwa">\over</span> b<span class="hl opt">}</span> <span class="hl kwa">\equiv</span> <span class="hl opt">{{</span>a' + a''<span class="hl opt">}</span> <span class="hl kwa">\over</span> b<span class="hl opt">}</span>$ which is equivalent to $<span class="hl opt">{</span>a' <span class="hl kwa">\over</span> b<span class="hl opt">}</span> + <span class="hl opt">{</span>a'' <span class="hl kwa">\over</span> b<span class="hl opt">}</span>$.  Since $a'$ is bound to be less than $b$ the quotient
is bound by $<span class="hl num">0</span> <span class="hl kwa">\le</span> <span class="hl opt">{</span>a' <span class="hl kwa">\over</span> b<span class="hl opt">}</span> &lt; <span class="hl num">1</span>$.

Since the digits of $a'$ do not contribute much to the quotient the observation is that they might as well be zero.  However, if the digits 
``might as well be zero'' they might as well not be there in the first place.  Let $q_0 = <span class="hl kwa">\lfloor</span> a/<span class="hl kwa">\beta</span>^<span class="hl opt">{</span>m-<span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\rfloor</span>$ represent the input
with the irrelevant digits trimmed.  Now the modular reduction is trimmed to the almost equivalent equation

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
c = a - b <span class="hl kwa">\cdot \lfloor</span> (q_0 <span class="hl kwa">\cdot \mu</span>) / <span class="hl kwa">\beta</span>^<span class="hl opt">{</span>m+<span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\rfloor</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

Note that the original divisor $<span class="hl num">2</span>^q$ has been replaced with $<span class="hl kwa">\beta</span>^<span class="hl opt">{</span>m+<span class="hl num">1</span><span class="hl opt">}</span>$ where in this case $q$ is a multiple of $lg(<span class="hl kwa">\beta</span>)$. Also note that the 
exponent on the divisor when added to the amount $q_0$ was shifted by equals $<span class="hl num">2</span>m$.  If the optimization had not been performed the divisor 
would have the exponent $<span class="hl num">2</span>m$ so in the end the exponents do ``add up''. Using the above equation the quotient 
$<span class="hl kwa">\lfloor</span> (q_0 <span class="hl kwa">\cdot \mu</span>) / <span class="hl kwa">\beta</span>^<span class="hl opt">{</span>m+<span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\rfloor</span>$ can be off from the true quotient by at most two.  The original fixed point quotient can be off
by as much as one (<span class="hl kwa">\textit</span><span class="hl opt">{</span>provided the radix point is chosen suitably<span class="hl opt">}</span>) and now that the lower irrelevent digits have been trimmed the quotient
can be off by an additional value of one for a total of at most two.  This implies that 
$<span class="hl num">0</span> <span class="hl kwa">\le</span> a - b <span class="hl kwa">\cdot \lfloor</span> (q_0 <span class="hl kwa">\cdot \mu</span>) / <span class="hl kwa">\beta</span>^<span class="hl opt">{</span>m+<span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\rfloor</span> &lt; <span class="hl num">3</span>b$.  By first subtracting $b$ times the quotient and then conditionally subtracting 
$b$ once or twice the residue is found.

The quotient is now found using $(m + <span class="hl num">1</span>)(m) = m^<span class="hl num">2</span> + m$ single precision multiplications and the residue with an additional $m^<span class="hl num">2</span>$ single
precision multiplications, ignoring the subtractions required.  In total $<span class="hl num">2</span>m^<span class="hl num">2</span> + m$ single precision multiplications are required to find the residue.  
This is considerably faster than the original attempt.

For example, let $<span class="hl kwa">\beta</span> = <span class="hl num">10</span>$ represent the radix of the digits.  Let $b = <span class="hl num">9999</span>$ represent the modulus which implies $m = <span class="hl num">4</span>$. Let $a = <span class="hl num">99929878</span>$ 
represent the value of which the residue is desired.  In this case $q = <span class="hl num">8</span>$ since $<span class="hl num">10</span>^<span class="hl num">7</span> &lt; <span class="hl num">9999</span>^<span class="hl num">2</span>$ meaning that $<span class="hl kwa">\mu</span> = <span class="hl kwa">\lfloor \beta</span>^<span class="hl opt">{</span>q<span class="hl opt">}</span>/b <span class="hl kwa">\rfloor</span> = <span class="hl num">10001</span>$.  
With the new observation the multiplicand for the quotient is equal to $q_0 = <span class="hl kwa">\lfloor</span> a / <span class="hl kwa">\beta</span>^<span class="hl opt">{</span>m - <span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\rfloor</span> = <span class="hl num">99929</span>$.  The quotient is then 
$<span class="hl kwa">\lfloor</span> (q_0 <span class="hl kwa">\cdot \mu</span>) / <span class="hl kwa">\beta</span>^<span class="hl opt">{</span>m+<span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\rfloor</span> = <span class="hl num">9993</span>$.  Subtracting $<span class="hl num">9993</span>b$ from $a$ and the correct residue $a <span class="hl kwa">\equiv</span> <span class="hl num">9871</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>b<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ 
is found.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Trimming the Quotient<span class="hl opt">}</span>
So far the reduction algorithm has been optimized from $<span class="hl num">3</span>m^<span class="hl num">2</span>$ single precision multiplications down to $<span class="hl num">2</span>m^<span class="hl num">2</span> + m$ single precision multiplications.  As 
it stands now the algorithm is already fairly fast compared to a full integer division algorithm.  However, there is still room for
optimization.  

After the first multiplication inside the quotient ($q_0 <span class="hl kwa">\cdot \mu</span>$) the value is shifted right by $m + <span class="hl num">1</span>$ places effectively nullifying the lower
half of the product.  It would be nice to be able to remove those digits from the product to effectively cut down the number of single precision 
multiplications.  If the number of digits in the modulus $m$ is far less than $<span class="hl kwa">\beta</span>$ a full product is not required for the algorithm to work properly.  
In fact the lower $m - <span class="hl num">2</span>$ digits will not affect the upper half of the product at all and do not need to be computed.  

The value of $<span class="hl kwa">\mu</span>$ is a $m$-digit number and $q_0$ is a $m + <span class="hl num">1</span>$ digit number.  Using a full multiplier $(m + <span class="hl num">1</span>)(m) = m^<span class="hl num">2</span> + m$ single precision
multiplications would be required.  Using a multiplier that will only produce digits at and above the $m - <span class="hl num">1</span>$'th digit reduces the number
of single precision multiplications to $<span class="hl opt">{</span>m^<span class="hl num">2</span> + m<span class="hl opt">}</span> <span class="hl kwa">\over</span> <span class="hl num">2</span>$ single precision multiplications.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Trimming the Residue<span class="hl opt">}</span>
After the quotient has been calculated it is used to reduce the input.  As previously noted the algorithm is not exact and it can be off by a small
multiple of the modulus, that is $<span class="hl num">0</span> <span class="hl kwa">\le</span> a - b <span class="hl kwa">\cdot \lfloor</span> (q_0 <span class="hl kwa">\cdot \mu</span>) / <span class="hl kwa">\beta</span>^<span class="hl opt">{</span>m+<span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\rfloor</span> &lt; <span class="hl num">3</span>b$.  If $b$ is $m$ digits than the 
result of reduction equation is a value of at most $m + <span class="hl num">1</span>$ digits (<span class="hl kwa">\textit</span><span class="hl opt">{</span>provided $<span class="hl num">3</span> &lt; <span class="hl kwa">\beta</span>$<span class="hl opt">}</span>) implying that the upper $m - <span class="hl num">1</span>$ digits are
implicitly zero.  

The next optimization arises from this very fact.  Instead of computing $b <span class="hl kwa">\cdot \lfloor</span> (q_0 <span class="hl kwa">\cdot \mu</span>) / <span class="hl kwa">\beta</span>^<span class="hl opt">{</span>m+<span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\rfloor</span>$ using a full
$O(m^<span class="hl num">2</span>)$ multiplication algorithm only the lower $m+<span class="hl num">1</span>$ digits of the product have to be computed.  Similarly the value of $a$ can
be reduced modulo $<span class="hl kwa">\beta</span>^<span class="hl opt">{</span>m+<span class="hl num">1</span><span class="hl opt">}</span>$ before the multiple of $b$ is subtracted which simplifes the subtraction as well.  A multiplication that produces 
only the lower $m+<span class="hl num">1</span>$ digits requires $<span class="hl opt">{</span>m^<span class="hl num">2</span> + <span class="hl num">3</span>m - <span class="hl num">2</span><span class="hl opt">}</span> <span class="hl kwa">\over</span> <span class="hl num">2</span>$ single precision multiplications.  

With both optimizations in place the algorithm is the algorithm Barrett proposed.  It requires $m^<span class="hl num">2</span> + <span class="hl num">2</span>m - <span class="hl num">1</span>$ single precision multiplications which
is considerably faster than the straightforward $<span class="hl num">3</span>m^<span class="hl num">2</span>$ method.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>The Barrett Algorithm<span class="hl opt">}</span>
<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_reduce</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$, mp<span class="hl kwa">\_int</span> $b$ and $<span class="hl kwa">\mu</span> = <span class="hl kwa">\lfloor \beta</span>^<span class="hl opt">{</span><span class="hl num">2</span>m<span class="hl opt">}</span>/b <span class="hl kwa">\rfloor</span>, m = <span class="hl kwa">\lceil</span> lg_<span class="hl opt">{</span><span class="hl kwa">\beta</span><span class="hl opt">}</span>(b) <span class="hl kwa">\rceil</span>, (<span class="hl num">0</span> <span class="hl kwa">\le</span> a &lt; b^<span class="hl num">2</span>, b &gt; <span class="hl num">1</span>)$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>b<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hline</span> \\
Let $m$ represent the number of digits in $b$.  \\
<span class="hl num">1</span>.  Make a copy of $a$ and store it in $q$.  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_init\_copy</span><span class="hl opt">}</span>) \\
<span class="hl num">2</span>.  $q <span class="hl kwa">\leftarrow \lfloor</span> q / <span class="hl kwa">\beta</span>^<span class="hl opt">{</span>m - <span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\rfloor</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_rshd</span><span class="hl opt">}</span>) \\
\\
Produce the quotient. \\
<span class="hl num">3</span>.  $q <span class="hl kwa">\leftarrow</span> q <span class="hl kwa">\cdot \mu</span>$  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>note: only produce digits at or above $m-<span class="hl num">1</span>$<span class="hl opt">}</span>) \\
<span class="hl num">4</span>.  $q <span class="hl kwa">\leftarrow \lfloor</span> q / <span class="hl kwa">\beta</span>^<span class="hl opt">{</span>m + <span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\rfloor</span>$ \\
\\
Subtract the multiple of modulus from the input. \\
<span class="hl num">5</span>.  $a <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta</span>^<span class="hl opt">{</span>m+<span class="hl num">1</span><span class="hl opt">}</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_mod\_2d</span><span class="hl opt">}</span>) \\
<span class="hl num">6</span>.  $q <span class="hl kwa">\leftarrow</span> q <span class="hl kwa">\cdot</span> b <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta</span>^<span class="hl opt">{</span>m+<span class="hl num">1</span><span class="hl opt">}</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>s<span class="hl kwa">\_mp\_mul\_digs</span><span class="hl opt">}</span>) \\
<span class="hl num">7</span>.  $a <span class="hl kwa">\leftarrow</span> a - q$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_sub</span><span class="hl opt">}</span>) \\
\\
Add $<span class="hl kwa">\beta</span>^<span class="hl opt">{</span>m+<span class="hl num">1</span><span class="hl opt">}</span>$ if a carry occured. \\
<span class="hl num">8</span>.  If $a &lt; <span class="hl num">0</span>$ then (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_cmp\_d</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">8.1</span>  $q <span class="hl kwa">\leftarrow</span> <span class="hl num">1</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_set</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">8.2</span>  $q <span class="hl kwa">\leftarrow</span> q <span class="hl kwa">\cdot \beta</span>^<span class="hl opt">{</span>m+<span class="hl num">1</span><span class="hl opt">}</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_lshd</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">8.3</span>  $a <span class="hl kwa">\leftarrow</span> a + q$ \\
\\
Now subtract the modulus if the residue is too large (e.g. quotient too small). \\
<span class="hl num">9</span>.  While $a <span class="hl kwa">\ge</span> b$ do (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_cmp</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">9.1</span>  $c <span class="hl kwa">\leftarrow</span> a - b$ \\
<span class="hl num">10</span>.  Clear $q$. \\
<span class="hl num">11</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_reduce</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_reduce</span>.<span class="hl opt">}</span>
This algorithm will reduce the input $a$ modulo $b$ in place using the Barrett algorithm.  It is loosely based on algorithm <span class="hl num">14.42</span> of HAC
<span class="hl kwa">\cite</span><span class="hl opt">[</span>pp.  <span class="hl num">602</span><span class="hl opt">]{</span>HAC<span class="hl opt">}</span> which is based on the paper from Paul Barrett <span class="hl kwa">\cite</span><span class="hl opt">{</span>BARRETT<span class="hl opt">}</span>.  The algorithm has several restrictions and assumptions which must 
be adhered to for the algorithm to work.

First the modulus $b$ is assumed to be positive and greater than one.  If the modulus were less than or equal to one than subtracting
a multiple of it would either accomplish nothing or actually enlarge the input.  The input $a$ must be in the range $<span class="hl num">0</span> <span class="hl kwa">\le</span> a &lt; b^<span class="hl num">2</span>$ in order
for the quotient to have enough precision.  If $a$ is the product of two numbers that were already reduced modulo $b$, this will not be a problem.
Technically the algorithm will still work if $a <span class="hl kwa">\ge</span> b^<span class="hl num">2</span>$ but it will take much longer to finish.  The value of $<span class="hl kwa">\mu</span>$ is passed as an argument to this 
algorithm and is assumed to be calculated and stored before the algorithm is used.  

Recall that the multiplication for the quotient on step <span class="hl num">3</span> must only produce digits at or above the $m-<span class="hl num">1</span>$'th position.  An algorithm called 
$s<span class="hl kwa">\_mp\_mul\_high\_digs</span>$ which has not been presented is used to accomplish this task.  The algorithm is based on $s<span class="hl kwa">\_mp\_mul\_digs</span>$ except that
instead of stopping at a given level of precision it starts at a given level of precision.  This optimal algorithm can only be used if the number
of digits in $b$ is very much smaller than $<span class="hl kwa">\beta</span>$.  

While it is known that 
$a <span class="hl kwa">\ge</span> b <span class="hl kwa">\cdot \lfloor</span> (q_0 <span class="hl kwa">\cdot \mu</span>) / <span class="hl kwa">\beta</span>^<span class="hl opt">{</span>m+<span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\rfloor</span>$ only the lower $m+<span class="hl num">1</span>$ digits are being used to compute the residue, so an implied 
``borrow'' from the higher digits might leave a negative result.  After the multiple of the modulus has been subtracted from $a$ the residue must be 
fixed up in case it is negative.  The invariant $<span class="hl kwa">\beta</span>^<span class="hl opt">{</span>m+<span class="hl num">1</span><span class="hl opt">}</span>$ must be added to the residue to make it positive again.  

The while loop at step <span class="hl num">9</span> will subtract $b$ until the residue is less than $b$.  If the algorithm is performed correctly this step is 
performed at most twice, and on average once. However, if $a <span class="hl kwa">\ge</span> b^<span class="hl num">2</span>$ than it will iterate substantially more times than it should.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_reduce</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

The first multiplication that determines the quotient can be performed by only producing the digits from $m - <span class="hl num">1</span>$ and up.  This essentially halves
the number of single precision multiplications required.  However, the optimization is only safe if $<span class="hl kwa">\beta</span>$ is much larger than the number of digits
in the modulus.  In the source code this is evaluated on lines <span class="hl num">36</span> to <span class="hl num">44</span> where algorithm s<span class="hl kwa">\_mp\_mul\_high\_digs</span> is used when it is
safe to do so.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>The Barrett Setup Algorithm<span class="hl opt">}</span>
In order to use algorithm mp<span class="hl kwa">\_reduce</span> the value of $<span class="hl kwa">\mu</span>$ must be calculated in advance.  Ideally this value should be computed once and stored for
future use so that the Barrett algorithm can be used without delay.  

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_reduce\_setup</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$ ($a &gt; <span class="hl num">1</span>$)  \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $<span class="hl kwa">\mu \leftarrow \lfloor \beta</span>^<span class="hl opt">{</span><span class="hl num">2</span>m<span class="hl opt">}</span>/a <span class="hl kwa">\rfloor</span>$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $<span class="hl kwa">\mu \leftarrow</span> <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">2</span> <span class="hl kwa">\cdot</span> lg(<span class="hl kwa">\beta</span>) <span class="hl kwa">\cdot</span>  m<span class="hl opt">}</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_2expt</span><span class="hl opt">}</span>) \\
<span class="hl num">2</span>.  $<span class="hl kwa">\mu \leftarrow \lfloor \mu</span> / b <span class="hl kwa">\rfloor</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_div</span><span class="hl opt">}</span>) \\
<span class="hl num">3</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_reduce\_setup</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_reduce\_setup</span>.<span class="hl opt">}</span>
This algorithm computes the reciprocal $<span class="hl kwa">\mu</span>$ required for Barrett reduction.  First $<span class="hl kwa">\beta</span>^<span class="hl opt">{</span><span class="hl num">2</span>m<span class="hl opt">}</span>$ is calculated as $<span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">2</span> <span class="hl kwa">\cdot</span> lg(<span class="hl kwa">\beta</span>) <span class="hl kwa">\cdot</span>  m<span class="hl opt">}</span>$ which
is equivalent and much faster.  The final value is computed by taking the integer quotient of $<span class="hl kwa">\lfloor \mu</span> / b <span class="hl kwa">\rfloor</span>$.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_reduce\_setup</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

This simple routine calculates the reciprocal $<span class="hl kwa">\mu</span>$ required by Barrett reduction.  Note the extended usage of algorithm mp<span class="hl kwa">\_div</span> where the variable
which would received the remainder is passed as NULL.  As will be discussed in~<span class="hl kwa">\ref</span><span class="hl opt">{</span>sec:division<span class="hl opt">}</span> the division routine allows both the quotient and the 
remainder to be passed as NULL meaning to ignore the value.  

<span class="hl kwa">\section</span><span class="hl opt">{</span>The Montgomery Reduction<span class="hl opt">}</span>
Montgomery reduction<span class="hl kwa">\footnote</span><span class="hl opt">{</span>Thanks to Niels Ferguson for his insightful explanation of the algorithm.<span class="hl opt">}</span> <span class="hl kwa">\cite</span><span class="hl opt">{</span>MONT<span class="hl opt">}</span> is by far the most interesting 
form of reduction in common use.  It computes a modular residue which is not actually equal to the residue of the input yet instead equal to a 
residue times a constant.  However, as perplexing as this may sound the algorithm is relatively simple and very efficient.  

Throughout this entire section the variable $n$ will represent the modulus used to form the residue.  As will be discussed shortly the value of
$n$ must be odd.  The variable $x$ will represent the quantity of which the residue is sought.  Similar to the Barrett algorithm the input
is restricted to $<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; n^<span class="hl num">2</span>$.  To begin the description some simple number theory facts must be established.

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Fact <span class="hl num">1</span>.<span class="hl opt">}</span>  Adding $n$ to $x$ does not change the residue since in effect it adds one to the quotient $<span class="hl kwa">\lfloor</span> x / n <span class="hl kwa">\rfloor</span>$.  Another way
to explain this is that $n$ is (<span class="hl kwa">\textit</span><span class="hl opt">{</span>or multiples of $n$ are<span class="hl opt">}</span>) congruent to zero modulo $n$.  Adding zero will not change the value of the residue.  

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Fact <span class="hl num">2</span>.<span class="hl opt">}</span>  If $x$ is even then performing a division by two in $<span class="hl kwa">\Z</span>$ is congruent to $x <span class="hl kwa">\cdot</span> <span class="hl num">2</span>^<span class="hl opt">{</span>-<span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>n<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$.  Actually
this is an application of the fact that if $x$ is evenly divisible by any $k <span class="hl kwa">\in \Z</span>$ then division in $<span class="hl kwa">\Z</span>$ will be congruent to 
multiplication by $k^<span class="hl opt">{</span>-<span class="hl num">1</span><span class="hl opt">}</span>$ modulo $n$.  

From these two simple facts the following simple algorithm can be derived.

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Montgomery Reduction<span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   Integer $x$, $n$ and $k$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $<span class="hl num">2</span>^<span class="hl opt">{</span>-k<span class="hl opt">}</span>x <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>n<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  for $t$ from $<span class="hl num">1</span>$ to $k$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.1</span>  If $x$ is odd then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">1.1.1</span>  $x <span class="hl kwa">\leftarrow</span> x + n$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.2</span>  $x <span class="hl kwa">\leftarrow</span> x/<span class="hl num">2</span>$ \\
<span class="hl num">2</span>.  Return $x$. \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm Montgomery Reduction<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

The algorithm reduces the input one bit at a time using the two congruencies stated previously.  Inside the loop $n$, which is odd, is
added to $x$ if $x$ is odd.  This forces $x$ to be even which allows the division by two in $<span class="hl kwa">\Z</span>$ to be congruent to a modular division by two.  Since
$x$ is assumed to be initially much larger than $n$ the addition of $n$ will contribute an insignificant magnitude to $x$.  Let $r$ represent the 
final result of the Montgomery algorithm.  If $k &gt; lg(n)$ and $<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; n^<span class="hl num">2</span>$ then the final result is limited to 
$<span class="hl num">0</span> <span class="hl kwa">\le</span> r &lt; <span class="hl kwa">\lfloor</span> x/<span class="hl num">2</span>^k <span class="hl kwa">\rfloor</span> + n$.  As a result at most a single subtraction is required to get the residue desired.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>|c|l|<span class="hl opt">}</span>
<span class="hl kwa">\hline \textbf</span><span class="hl opt">{</span>Step number ($t$)<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Result ($x$)<span class="hl opt">}</span> \\
<span class="hl kwa">\hline</span> $<span class="hl num">1</span>$ &amp; $x + n = <span class="hl num">5812</span>$, $x/<span class="hl num">2</span> = <span class="hl num">2906</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">2</span>$ &amp; $x/<span class="hl num">2</span> = <span class="hl num">1453</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">3</span>$ &amp; $x + n = <span class="hl num">1710</span>$, $x/<span class="hl num">2</span> = <span class="hl num">855</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">4</span>$ &amp; $x + n = <span class="hl num">1112</span>$, $x/<span class="hl num">2</span> = <span class="hl num">556</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">5</span>$ &amp; $x/<span class="hl num">2</span> = <span class="hl num">278</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">6</span>$ &amp; $x/<span class="hl num">2</span> = <span class="hl num">139</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">7</span>$ &amp; $x + n = <span class="hl num">396</span>$, $x/<span class="hl num">2</span> = <span class="hl num">198</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">8</span>$ &amp; $x/<span class="hl num">2</span> = <span class="hl num">99</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">9</span>$ &amp; $x + n = <span class="hl num">356</span>$, $x/<span class="hl num">2</span> = <span class="hl num">178</span>$ \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Example of Montgomery Reduction (I)<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>fig:MONT1<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

Consider the example in figure~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:MONT1<span class="hl opt">}</span> which reduces $x = <span class="hl num">5555</span>$ modulo $n = <span class="hl num">257</span>$ when $k = <span class="hl num">9</span>$ (note $<span class="hl kwa">\beta</span>^k = <span class="hl num">512</span>$ which is larger than $n$).  The result of 
the algorithm $r = <span class="hl num">178</span>$ is congruent to the value of $<span class="hl num">2</span>^<span class="hl opt">{</span>-<span class="hl num">9</span><span class="hl opt">}</span> <span class="hl kwa">\cdot</span> <span class="hl num">5555</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">257</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$.  When $r$ is multiplied by $<span class="hl num">2</span>^<span class="hl num">9</span>$ modulo $<span class="hl num">257</span>$ the correct residue 
$r <span class="hl kwa">\equiv</span> <span class="hl num">158</span>$ is produced.  

Let $k = <span class="hl kwa">\lfloor</span> lg(n) <span class="hl kwa">\rfloor</span> + <span class="hl num">1</span>$ represent the number of bits in $n$.  The current algorithm requires $<span class="hl num">2</span>k^<span class="hl num">2</span>$ single precision shifts
and $k^<span class="hl num">2</span>$ single precision additions.  At this rate the algorithm is most certainly slower than Barrett reduction and not terribly useful.  
Fortunately there exists an alternative representation of the algorithm.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Montgomery Reduction<span class="hl opt">}</span> (modified I). \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   Integer $x$, $n$ and $k$ ($<span class="hl num">2</span>^k &gt; n$) \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $<span class="hl num">2</span>^<span class="hl opt">{</span>-k<span class="hl opt">}</span>x <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>n<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  for $t$ from $<span class="hl num">1</span>$ to $k$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.1</span>  If the $t$'th bit of $x$ is one then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">1.1.1</span>  $x <span class="hl kwa">\leftarrow</span> x + <span class="hl num">2</span>^tn$ \\
<span class="hl num">2</span>.  Return $x/<span class="hl num">2</span>^k$. \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm Montgomery Reduction (modified I)<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

This algorithm is equivalent since $<span class="hl num">2</span>^tn$ is a multiple of $n$ and the lower $k$ bits of $x$ are zero by step <span class="hl num">2</span>.  The number of single
precision shifts has now been reduced from $<span class="hl num">2</span>k^<span class="hl num">2</span>$ to $k^<span class="hl num">2</span> + k$ which is only a small improvement.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>|c|l|r|<span class="hl opt">}</span>
<span class="hl kwa">\hline \textbf</span><span class="hl opt">{</span>Step number ($t$)<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Result ($x$)<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Result ($x$) in Binary<span class="hl opt">}</span> \\
<span class="hl kwa">\hline</span> -- &amp; $<span class="hl num">5555</span>$ &amp; $<span class="hl num">1010110110011</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">1</span>$ &amp; $x + <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">0</span><span class="hl opt">}</span>n = <span class="hl num">5812</span>$ &amp;  $<span class="hl num">1011010110100</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">2</span>$ &amp; $<span class="hl num">5812</span>$ &amp; $<span class="hl num">1011010110100</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">3</span>$ &amp; $x + <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">2</span><span class="hl opt">}</span>n = <span class="hl num">6840</span>$ &amp; $<span class="hl num">1101010111000</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">4</span>$ &amp; $x + <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">3</span><span class="hl opt">}</span>n = <span class="hl num">8896</span>$ &amp; $<span class="hl num">10001011000000</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">5</span>$ &amp; $<span class="hl num">8896</span>$ &amp; $<span class="hl num">10001011000000</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">6</span>$ &amp; $<span class="hl num">8896</span>$ &amp; $<span class="hl num">10001011000000</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">7</span>$ &amp; $x + <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">6</span><span class="hl opt">}</span>n = <span class="hl num">25344</span>$ &amp; $<span class="hl num">110001100000000</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">8</span>$ &amp; $<span class="hl num">25344</span>$ &amp; $<span class="hl num">110001100000000</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">9</span>$ &amp; $x + <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">7</span><span class="hl opt">}</span>n = <span class="hl num">91136</span>$ &amp; $<span class="hl num">10110010000000000</span>$ \\
<span class="hl kwa">\hline</span> -- &amp; $x/<span class="hl num">2</span>^k = <span class="hl num">178</span>$ &amp; \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Example of Montgomery Reduction (II)<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>fig:MONT2<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

Figure~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:MONT2<span class="hl opt">}</span> demonstrates the modified algorithm reducing $x = <span class="hl num">5555</span>$ modulo $n = <span class="hl num">257</span>$ with $k = <span class="hl num">9</span>$. 
With this algorithm a single shift right at the end is the only right shift required to reduce the input instead of $k$ right shifts inside the 
loop.  Note that for the iterations $t = <span class="hl num">2</span>, <span class="hl num">5</span>, <span class="hl num">6</span>$ and $<span class="hl num">8</span>$ where the result $x$ is not changed.  In those iterations the $t$'th bit of $x$ is 
zero and the appropriate multiple of $n$ does not need to be added to force the $t$'th bit of the result to zero.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Digit Based Montgomery Reduction<span class="hl opt">}</span>
Instead of computing the reduction on a bit-by-bit basis it is actually much faster to compute it on digit-by-digit basis.  Consider the
previous algorithm re-written to compute the Montgomery reduction in this new fashion.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Montgomery Reduction<span class="hl opt">}</span> (modified II). \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   Integer $x$, $n$ and $k$ ($<span class="hl kwa">\beta</span>^k &gt; n$) \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $<span class="hl kwa">\beta</span>^<span class="hl opt">{</span>-k<span class="hl opt">}</span>x <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>n<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  for $t$ from $<span class="hl num">0</span>$ to $k - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.1</span>  $x <span class="hl kwa">\leftarrow</span> x + <span class="hl kwa">\mu</span> n <span class="hl kwa">\beta</span>^t$ \\
<span class="hl num">2</span>.  Return $x/<span class="hl kwa">\beta</span>^k$. \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm Montgomery Reduction (modified II)<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

The value $<span class="hl kwa">\mu</span> n <span class="hl kwa">\beta</span>^t$ is a multiple of the modulus $n$ meaning that it will not change the residue.  If the first digit of 
the value $<span class="hl kwa">\mu</span> n <span class="hl kwa">\beta</span>^t$ equals the negative (modulo $<span class="hl kwa">\beta</span>$) of the $t$'th digit of $x$ then the addition will result in a zero digit.  This
problem breaks down to solving the following congruency.  

<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>rcl<span class="hl opt">}</span>
$x_t + <span class="hl kwa">\mu</span> n_0$ &amp; $<span class="hl kwa">\equiv</span>$ &amp; $<span class="hl num">0</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
$<span class="hl kwa">\mu</span> n_0$ &amp; $<span class="hl kwa">\equiv</span>$ &amp; $-x_t <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
$<span class="hl kwa">\mu</span>$ &amp; $<span class="hl kwa">\equiv</span>$ &amp; $-x_t/n_0 <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>

In each iteration of the loop on step <span class="hl num">1</span> a new value of $<span class="hl kwa">\mu</span>$ must be calculated.  The value of $-<span class="hl num">1</span>/n_0 <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ is used 
extensively in this algorithm and should be precomputed.  Let $<span class="hl kwa">\rho</span>$ represent the negative of the modular inverse of $n_0$ modulo $<span class="hl kwa">\beta</span>$.  

For example, let $<span class="hl kwa">\beta</span> = <span class="hl num">10</span>$ represent the radix.  Let $n = <span class="hl num">17</span>$ represent the modulus which implies $k = <span class="hl num">2</span>$ and $<span class="hl kwa">\rho \equiv</span> <span class="hl num">7</span>$.  Let $x = <span class="hl num">33</span>$ 
represent the value to reduce.

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>|c|c|c|<span class="hl opt">}</span>
<span class="hl kwa">\hline \textbf</span><span class="hl opt">{</span>Step ($t$)<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Value of $x$<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Value of $<span class="hl kwa">\mu</span>$<span class="hl opt">}</span> \\
<span class="hl kwa">\hline</span> --                 &amp; $<span class="hl num">33</span>$ &amp; --\\
<span class="hl kwa">\hline</span> $<span class="hl num">0</span>$                 &amp; $<span class="hl num">33</span> + <span class="hl kwa">\mu</span> n = <span class="hl num">50</span>$ &amp; $<span class="hl num">1</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">1</span>$                 &amp; $<span class="hl num">50</span> + <span class="hl kwa">\mu</span> n <span class="hl kwa">\beta</span> = <span class="hl num">900</span>$ &amp; $<span class="hl num">5</span>$ \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Example of Montgomery Reduction<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

The final result $<span class="hl num">900</span>$ is then divided by $<span class="hl kwa">\beta</span>^k$ to produce the final result $<span class="hl num">9</span>$.  The first observation is that $<span class="hl num">9</span> <span class="hl kwa">\nequiv</span> x <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>n<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ 
which implies the result is not the modular residue of $x$ modulo $n$.  However, recall that the residue is actually multiplied by $<span class="hl kwa">\beta</span>^<span class="hl opt">{</span>-k<span class="hl opt">}</span>$ in
the algorithm.  To get the true residue the value must be multiplied by $<span class="hl kwa">\beta</span>^k$.  In this case $<span class="hl kwa">\beta</span>^k <span class="hl kwa">\equiv</span> <span class="hl num">15</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>n<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ and
the correct residue is $<span class="hl num">9</span> <span class="hl kwa">\cdot</span> <span class="hl num">15</span> <span class="hl kwa">\equiv</span> <span class="hl num">16</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>n<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Baseline Montgomery Reduction<span class="hl opt">}</span>
The baseline Montgomery reduction algorithm will produce the residue for any size input.  It is designed to be a catch-all algororithm for 
Montgomery reductions.  

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_montgomery\_reduce</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $x$, mp<span class="hl kwa">\_int</span> $n$ and a digit $<span class="hl kwa">\rho \equiv</span> -<span class="hl num">1</span>/n_0 <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>n<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">11.5</span>mm<span class="hl opt">}</span>($<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; n^<span class="hl num">2</span>, n &gt; <span class="hl num">1</span>, (n, <span class="hl kwa">\beta</span>) = <span class="hl num">1</span>, <span class="hl kwa">\beta</span>^k &gt; n$) \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $<span class="hl kwa">\beta</span>^<span class="hl opt">{</span>-k<span class="hl opt">}</span>x <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>n<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $digs <span class="hl kwa">\leftarrow</span> <span class="hl num">2</span>n.used + <span class="hl num">1</span>$ \\
<span class="hl num">2</span>.  If $digs &lt; MP<span class="hl kwa">\_ARRAY</span>$ and $m.used &lt; <span class="hl kwa">\delta</span>$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  Use algorithm fast<span class="hl kwa">\_mp\_montgomery\_reduce</span> instead. \\
\\
Setup $x$ for the reduction. \\
<span class="hl num">3</span>.  If $x.alloc &lt; digs$ then grow $x$ to $digs$ digits. \\
<span class="hl num">4</span>.  $x.used <span class="hl kwa">\leftarrow</span> digs$ \\
\\
Eliminate the lower $k$ digits. \\
<span class="hl num">5</span>.  For $ix$ from $<span class="hl num">0</span>$ to $k - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.1</span>  $<span class="hl kwa">\mu \leftarrow</span> x_<span class="hl opt">{</span>ix<span class="hl opt">}</span> <span class="hl kwa">\cdot \rho \mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.2</span>  $u <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.3</span>  For $iy$ from $<span class="hl num">0</span>$ to $k - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">5.3.1</span>  $<span class="hl kwa">\hat</span> r <span class="hl kwa">\leftarrow \mu</span> n_<span class="hl opt">{</span>iy<span class="hl opt">}</span> + x_<span class="hl opt">{</span>ix + iy<span class="hl opt">}</span> + u$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">5.3.2</span>  $x_<span class="hl opt">{</span>ix + iy<span class="hl opt">}</span> <span class="hl kwa">\leftarrow \hat</span> r <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">5.3.3</span>  $u <span class="hl kwa">\leftarrow \lfloor \hat</span> r / <span class="hl kwa">\beta \rfloor</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.4</span>  While $u &gt; <span class="hl num">0</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">5.4.1</span>  $iy <span class="hl kwa">\leftarrow</span> iy + <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">5.4.2</span>  $x_<span class="hl opt">{</span>ix + iy<span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> x_<span class="hl opt">{</span>ix + iy<span class="hl opt">}</span> + u$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">5.4.3</span>  $u <span class="hl kwa">\leftarrow \lfloor</span> x_<span class="hl opt">{</span>ix+iy<span class="hl opt">}</span> / <span class="hl kwa">\beta \rfloor</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">5.4.4</span>  $x_<span class="hl opt">{</span>ix + iy<span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> x_<span class="hl opt">{</span>ix+iy<span class="hl opt">}</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
\\
Divide by $<span class="hl kwa">\beta</span>^k$ and fix up as required. \\
<span class="hl num">6</span>.  $x <span class="hl kwa">\leftarrow \lfloor</span> x / <span class="hl kwa">\beta</span>^k <span class="hl kwa">\rfloor</span>$ \\
<span class="hl num">7</span>.  If $x <span class="hl kwa">\ge</span> n$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.1</span>  $x <span class="hl kwa">\leftarrow</span> x - n$ \\
<span class="hl num">8</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_montgomery\_reduce</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_montgomery\_reduce</span>.<span class="hl opt">}</span>
This algorithm reduces the input $x$ modulo $n$ in place using the Montgomery reduction algorithm.  The algorithm is loosely based
on algorithm <span class="hl num">14.32</span> of <span class="hl kwa">\cite</span><span class="hl opt">[</span>pp<span class="hl num">.601</span><span class="hl opt">]{</span>HAC<span class="hl opt">}</span> except it merges the multiplication of $<span class="hl kwa">\mu</span> n <span class="hl kwa">\beta</span>^t$ with the addition in the inner loop.  The
restrictions on this algorithm are fairly easy to adapt to.  First $<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; n^<span class="hl num">2</span>$ bounds the input to numbers in the same range as 
for the Barrett algorithm.  Additionally if $n &gt; <span class="hl num">1</span>$ and $n$ is odd there will exist a modular inverse $<span class="hl kwa">\rho</span>$.  $<span class="hl kwa">\rho</span>$ must be calculated in
advance of this algorithm.  Finally the variable $k$ is fixed and a pseudonym for $n.used$.  

Step <span class="hl num">2</span> decides whether a faster Montgomery algorithm can be used.  It is based on the Comba technique meaning that there are limits on
the size of the input.  This algorithm is discussed in sub-section <span class="hl num">6.3.3</span>.

Step <span class="hl num">5</span> is the main reduction loop of the algorithm.  The value of $<span class="hl kwa">\mu</span>$ is calculated once per iteration in the outer loop.  The inner loop
calculates $x + <span class="hl kwa">\mu</span> n <span class="hl kwa">\beta</span>^<span class="hl opt">{</span>ix<span class="hl opt">}</span>$ by multiplying $<span class="hl kwa">\mu</span> n$ and adding the result to $x$ shifted by $ix$ digits.  Both the addition and
multiplication are performed in the same loop to save time and memory.  Step <span class="hl num">5.4</span> will handle any additional carries that escape the inner loop.

Using a quick inspection this algorithm requires $n$ single precision multiplications for the outer loop and $n^<span class="hl num">2</span>$ single precision multiplications 
in the inner loop.  In total $n^<span class="hl num">2</span> + n$ single precision multiplications which compares favourably to Barrett at $n^<span class="hl num">2</span> + <span class="hl num">2</span>n - <span class="hl num">1</span>$ single precision
multiplications.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_montgomery\_reduce</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

This is the baseline implementation of the Montgomery reduction algorithm.  Lines <span class="hl num">31</span> to <span class="hl num">36</span> determine if the Comba based
routine can be used instead.  Line <span class="hl num">47</span> computes the value of $<span class="hl kwa">\mu</span>$ for that particular iteration of the outer loop.  

The multiplication $<span class="hl kwa">\mu</span> n <span class="hl kwa">\beta</span>^<span class="hl opt">{</span>ix<span class="hl opt">}</span>$ is performed in one step in the inner loop.  The alias $tmpx$ refers to the $ix$'th digit of $x$ and
the alias $tmpn$ refers to the modulus $n$.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Faster ``Comba'' Montgomery Reduction<span class="hl opt">}</span>

The Montgomery reduction requires fewer single precision multiplications than a Barrett reduction, however it is much slower due to the serial
nature of the inner loop.  The Barrett reduction algorithm requires two slightly modified multipliers which can be implemented with the Comba
technique.  The Montgomery reduction algorithm cannot directly use the Comba technique to any significant advantage since the inner loop calculates
a $k <span class="hl kwa">\times</span> <span class="hl num">1</span>$ product $k$ times. 

The biggest obstacle is that at the $ix$'th iteration of the outer loop the value of $x_<span class="hl opt">{</span>ix<span class="hl opt">}</span>$ is required to calculate $<span class="hl kwa">\mu</span>$.  This means the 
carries from $<span class="hl num">0</span>$ to $ix - <span class="hl num">1</span>$ must have been propagated upwards to form a valid $ix$'th digit.  The solution as it turns out is very simple.  
Perform a Comba like multiplier and inside the outer loop just after the inner loop fix up the $ix + <span class="hl num">1</span>$'th digit by forwarding the carry.  

With this change in place the Montgomery reduction algorithm can be performed with a Comba style multiplication loop which substantially increases
the speed of the algorithm.  

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>fast<span class="hl kwa">\_mp\_montgomery\_reduce</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $x$, mp<span class="hl kwa">\_int</span> $n$ and a digit $<span class="hl kwa">\rho \equiv</span> -<span class="hl num">1</span>/n_0 <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>n<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">11.5</span>mm<span class="hl opt">}</span>($<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; n^<span class="hl num">2</span>, n &gt; <span class="hl num">1</span>, (n, <span class="hl kwa">\beta</span>) = <span class="hl num">1</span>, <span class="hl kwa">\beta</span>^k &gt; n$) \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $<span class="hl kwa">\beta</span>^<span class="hl opt">{</span>-k<span class="hl opt">}</span>x <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>n<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hline</span> \\
Place an array of <span class="hl kwa">\textbf</span><span class="hl opt">{</span>MP<span class="hl kwa">\_WARRAY</span><span class="hl opt">}</span> mp<span class="hl kwa">\_word</span> variables called $<span class="hl kwa">\hat</span> W$ on the stack. \\
<span class="hl num">1</span>.  if $x.alloc &lt; n.used + <span class="hl num">1</span>$ then grow $x$ to $n.used + <span class="hl num">1</span>$ digits. \\
Copy the digits of $x$ into the array $<span class="hl kwa">\hat</span> W$ \\
<span class="hl num">2</span>.  For $ix$ from $<span class="hl num">0</span>$ to $x.used - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  $<span class="hl kwa">\hat</span> W_<span class="hl opt">{</span>ix<span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> x_<span class="hl opt">{</span>ix<span class="hl opt">}</span>$ \\
<span class="hl num">3</span>.  For $ix$ from $x.used$ to $<span class="hl num">2</span>n.used - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">3.1</span>  $<span class="hl kwa">\hat</span> W_<span class="hl opt">{</span>ix<span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
Elimiate the lower $k$ digits. \\
<span class="hl num">4</span>.  for $ix$ from $<span class="hl num">0</span>$ to $n.used - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.1</span>  $<span class="hl kwa">\mu \leftarrow \hat</span> W_<span class="hl opt">{</span>ix<span class="hl opt">}</span> <span class="hl kwa">\cdot \rho \mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.2</span>  For $iy$ from $<span class="hl num">0</span>$ to $n.used - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">4.2.1</span>  $<span class="hl kwa">\hat</span> W_<span class="hl opt">{</span>iy + ix<span class="hl opt">}</span> <span class="hl kwa">\leftarrow \hat</span> W_<span class="hl opt">{</span>iy + ix<span class="hl opt">}</span> + <span class="hl kwa">\mu \cdot</span> n_<span class="hl opt">{</span>iy<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.3</span>  $<span class="hl kwa">\hat</span> W_<span class="hl opt">{</span>ix + <span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\leftarrow \hat</span> W_<span class="hl opt">{</span>ix + <span class="hl num">1</span><span class="hl opt">}</span> + <span class="hl kwa">\lfloor \hat</span> W_<span class="hl opt">{</span>ix<span class="hl opt">}</span> / <span class="hl kwa">\beta \rfloor</span>$ \\
Propagate carries upwards. \\
<span class="hl num">5</span>.  for $ix$ from $n.used$ to $<span class="hl num">2</span>n.used + <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.1</span>  $<span class="hl kwa">\hat</span> W_<span class="hl opt">{</span>ix + <span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\leftarrow \hat</span> W_<span class="hl opt">{</span>ix + <span class="hl num">1</span><span class="hl opt">}</span> + <span class="hl kwa">\lfloor \hat</span> W_<span class="hl opt">{</span>ix<span class="hl opt">}</span> / <span class="hl kwa">\beta \rfloor</span>$ \\
Shift right and reduce modulo $<span class="hl kwa">\beta</span>$ simultaneously. \\
<span class="hl num">6</span>.  for $ix$ from $<span class="hl num">0</span>$ to $n.used + <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.1</span>  $x_<span class="hl opt">{</span>ix<span class="hl opt">}</span> <span class="hl kwa">\leftarrow \hat</span> W_<span class="hl opt">{</span>ix + n.used<span class="hl opt">}</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
Zero excess digits and fixup $x$. \\
<span class="hl num">7</span>.  if $x.used &gt; n.used + <span class="hl num">1</span>$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.1</span>  for $ix$ from $n.used + <span class="hl num">1</span>$ to $x.used - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">7.1.1</span>  $x_<span class="hl opt">{</span>ix<span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">8</span>.  $x.used <span class="hl kwa">\leftarrow</span> n.used + <span class="hl num">1</span>$ \\
<span class="hl num">9</span>.  Clamp excessive digits of $x$. \\
<span class="hl num">10</span>.  If $x <span class="hl kwa">\ge</span> n$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">10.1</span>  $x <span class="hl kwa">\leftarrow</span> x - n$ \\
<span class="hl num">11</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm fast<span class="hl kwa">\_mp\_montgomery\_reduce</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm fast<span class="hl kwa">\_mp\_montgomery\_reduce</span>.<span class="hl opt">}</span>
This algorithm will compute the Montgomery reduction of $x$ modulo $n$ using the Comba technique.  It is on most computer platforms significantly
faster than algorithm mp<span class="hl kwa">\_montgomery\_reduce</span> and algorithm mp<span class="hl kwa">\_reduce</span> (<span class="hl kwa">\textit</span><span class="hl opt">{</span>Barrett reduction<span class="hl opt">}</span>).  The algorithm has the same restrictions
on the input as the baseline reduction algorithm.  An additional two restrictions are imposed on this algorithm.  The number of digits $k$ in the 
the modulus $n$ must not violate $MP<span class="hl kwa">\_WARRAY</span> &gt; <span class="hl num">2</span>k +<span class="hl num">1</span>$ and $n &lt; <span class="hl kwa">\delta</span>$.   When $<span class="hl kwa">\beta</span> = <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">28</span><span class="hl opt">}</span>$ this algorithm can be used to reduce modulo
a modulus of at most $<span class="hl num">3</span>,<span class="hl num">556</span>$ bits in length.  

As in the other Comba reduction algorithms there is a $<span class="hl kwa">\hat</span> W$ array which stores the columns of the product.  It is initially filled with the
contents of $x$ with the excess digits zeroed.  The reduction loop is very similar the to the baseline loop at heart.  The multiplication on step
<span class="hl num">4.1</span> can be single precision only since $ab <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span> <span class="hl kwa">\equiv</span> (a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> mod <span class="hl opt">}</span><span class="hl kwa">\beta</span>)(b <span class="hl kwa">\mbox</span><span class="hl opt">{</span> mod <span class="hl opt">}</span><span class="hl kwa">\beta</span>)$.  Some multipliers such
as those on the ARM processors take a variable length time to complete depending on the number of bytes of result it must produce.  By performing
a single precision multiplication instead half the amount of time is spent.

Also note that digit $<span class="hl kwa">\hat</span> W_<span class="hl opt">{</span>ix<span class="hl opt">}</span>$ must have the carry from the $ix - <span class="hl num">1</span>$'th digit propagated upwards in order for this to work.  That is what step
<span class="hl num">4.3</span> will do.  In effect over the $n.used$ iterations of the outer loop the $n.used$'th lower columns all have the their carries propagated forwards.  Note
how the upper bits of those same words are not reduced modulo $<span class="hl kwa">\beta</span>$.  This is because those values will be discarded shortly and there is no
point.

Step <span class="hl num">5</span> will propagate the remainder of the carries upwards.  On step <span class="hl num">6</span> the columns are reduced modulo $<span class="hl kwa">\beta</span>$ and shifted simultaneously as they are
stored in the destination $x$.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_fast\_mp\_montgomery\_reduce</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

The $<span class="hl kwa">\hat</span> W$ array is first filled with digits of $x$ on line <span class="hl num">48</span> then the rest of the digits are zeroed on line <span class="hl num">55</span>.  Both loops share
the same alias variables to make the code easier to read.  

The value of $<span class="hl kwa">\mu</span>$ is calculated in an interesting fashion.  First the value $<span class="hl kwa">\hat</span> W_<span class="hl opt">{</span>ix<span class="hl opt">}</span>$ is reduced modulo $<span class="hl kwa">\beta</span>$ and cast to a mp<span class="hl kwa">\_digit</span>.  This
forces the compiler to use a single precision multiplication and prevents any concerns about loss of precision.   Line <span class="hl num">110</span> fixes the carry 
for the next iteration of the loop by propagating the carry from $<span class="hl kwa">\hat</span> W_<span class="hl opt">{</span>ix<span class="hl opt">}</span>$ to $<span class="hl kwa">\hat</span> W_<span class="hl opt">{</span>ix+<span class="hl num">1</span><span class="hl opt">}</span>$.

The for loop on line <span class="hl num">109</span> propagates the rest of the carries upwards through the columns.  The for loop on line <span class="hl num">126</span> reduces the columns
modulo $<span class="hl kwa">\beta</span>$ and shifts them $k$ places at the same time.  The alias $<span class="hl kwa">\_ \hat</span> W$ actually refers to the array $<span class="hl kwa">\hat</span> W$ starting at the $n.used$'th
digit, that is $<span class="hl kwa">\_ \hat</span> W_<span class="hl opt">{</span>t<span class="hl opt">}</span> = <span class="hl kwa">\hat</span> W_<span class="hl opt">{</span>n.used + t<span class="hl opt">}</span>$.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Montgomery Setup<span class="hl opt">}</span>
To calculate the variable $<span class="hl kwa">\rho</span>$ a relatively simple algorithm will be required.  

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_montgomery\_setup</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $n$ ($n &gt; <span class="hl num">1</span>$ and $(n, <span class="hl num">2</span>) = <span class="hl num">1</span>$) \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $<span class="hl kwa">\rho \equiv</span> -<span class="hl num">1</span>/n_0 <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $b <span class="hl kwa">\leftarrow</span> n_0$ \\
<span class="hl num">2</span>.  If $b$ is even return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_VAL</span><span class="hl opt">}</span>) \\
<span class="hl num">3</span>.  $x <span class="hl kwa">\leftarrow</span> (((b + <span class="hl num">2</span>) <span class="hl kwa">\mbox</span><span class="hl opt">{</span> AND <span class="hl opt">}</span> <span class="hl num">4</span>) &lt;&lt; <span class="hl num">1</span>) + b$ \\
<span class="hl num">4</span>.  for $k$ from <span class="hl num">0</span> to $<span class="hl kwa">\lceil</span> lg(lg(<span class="hl kwa">\beta</span>)) <span class="hl kwa">\rceil</span> - <span class="hl num">2</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.1</span>  $x <span class="hl kwa">\leftarrow</span> x <span class="hl kwa">\cdot</span> (<span class="hl num">2</span> - bx)$ \\
<span class="hl num">5</span>.  $<span class="hl kwa">\rho \leftarrow \beta</span> - x <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl num">6</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_montgomery\_setup</span><span class="hl opt">}</span> 
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_montgomery\_setup</span>.<span class="hl opt">}</span>
This algorithm will calculate the value of $<span class="hl kwa">\rho</span>$ required within the Montgomery reduction algorithms.  It uses a very interesting trick 
to calculate $<span class="hl num">1</span>/n_0$ when $<span class="hl kwa">\beta</span>$ is a power of two.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_montgomery\_setup</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

This source code computes the value of $<span class="hl kwa">\rho</span>$ required to perform Montgomery reduction.  It has been modified to avoid performing excess
multiplications when $<span class="hl kwa">\beta</span>$ is not the default <span class="hl num">28</span>-bits.  

<span class="hl kwa">\section</span><span class="hl opt">{</span>The Diminished Radix Algorithm<span class="hl opt">}</span>
The Diminished Radix method of modular reduction <span class="hl kwa">\cite</span><span class="hl opt">{</span>DRMET<span class="hl opt">}</span> is a fairly clever technique which can be more efficient than either the Barrett
or Montgomery methods for certain forms of moduli.  The technique is based on the following simple congruence.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
(x <span class="hl kwa">\mbox</span><span class="hl opt">{</span> mod <span class="hl opt">}</span> n) + k <span class="hl kwa">\lfloor</span> x / n <span class="hl kwa">\rfloor \equiv</span> x <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>(n - k)<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

This observation was used in the MMB <span class="hl kwa">\cite</span><span class="hl opt">{</span>MMB<span class="hl opt">}</span> block cipher to create a diffusion primitive.  It used the fact that if $n = <span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">31</span><span class="hl opt">}</span>$ and $k=<span class="hl num">1</span>$ that 
then a x86 multiplier could produce the <span class="hl num">62</span>-bit product and use  the ``shrd'' instruction to perform a double-precision right shift.  The proof
of the above equation is very simple.  First write $x$ in the product form.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
x = qn + r
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

Now reduce both sides modulo $(n - k)$.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
x <span class="hl kwa">\equiv</span> qk + r  <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>(n-k)<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

The variable $n$ reduces modulo $n - k$ to $k$.  By putting $q = <span class="hl kwa">\lfloor</span> x/n <span class="hl kwa">\rfloor</span>$ and $r = x <span class="hl kwa">\mbox</span><span class="hl opt">{</span> mod <span class="hl opt">}</span> n$ 
into the equation the original congruence is reproduced, thus concluding the proof.  The following algorithm is based on this observation.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Diminished Radix Reduction<span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   Integer $x$, $n$, $k$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $x <span class="hl kwa">\mbox</span><span class="hl opt">{</span> mod <span class="hl opt">}</span> (n - k)$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $q <span class="hl kwa">\leftarrow \lfloor</span> x / n <span class="hl kwa">\rfloor</span>$ \\
<span class="hl num">2</span>.  $q <span class="hl kwa">\leftarrow</span> k <span class="hl kwa">\cdot</span> q$ \\
<span class="hl num">3</span>.  $x <span class="hl kwa">\leftarrow</span> x <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>n<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl num">4</span>.  $x <span class="hl kwa">\leftarrow</span> x + q$ \\
<span class="hl num">5</span>.  If $x <span class="hl kwa">\ge</span> (n - k)$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.1</span>  $x <span class="hl kwa">\leftarrow</span> x - (n - k)$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.2</span>  Goto step <span class="hl num">1</span>. \\
<span class="hl num">6</span>.  Return $x$ \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm Diminished Radix Reduction<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>fig:DR<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

This algorithm will reduce $x$ modulo $n - k$ and return the residue.  If $<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; (n - k)^<span class="hl num">2</span>$ then the algorithm will loop almost always
once or twice and occasionally three times.  For simplicity sake the value of $x$ is bounded by the following simple polynomial.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span> 
<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; n^<span class="hl num">2</span> + k^<span class="hl num">2</span> - <span class="hl num">2</span>nk
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

The true bound is  $<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; (n - k - <span class="hl num">1</span>)^<span class="hl num">2</span>$ but this has quite a few more terms.  The value of $q$ after step <span class="hl num">1</span> is bounded by the following.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
q &lt; n - <span class="hl num">2</span>k - k^<span class="hl num">2</span>/n
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

Since $k^<span class="hl num">2</span>$ is going to be considerably smaller than $n$ that term will always be zero.  The value of $x$ after step <span class="hl num">3</span> is bounded trivially as
$<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; n$.  By step four the sum $x + q$ is bounded by 

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
<span class="hl num">0</span> <span class="hl kwa">\le</span> q + x &lt; (k + <span class="hl num">1</span>)n - <span class="hl num">2</span>k^<span class="hl num">2</span> - <span class="hl num">1</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

With a second pass $q$ will be loosely bounded by $<span class="hl num">0</span> <span class="hl kwa">\le</span> q &lt; k^<span class="hl num">2</span>$ after step <span class="hl num">2</span> while $x$ will still be loosely bounded by $<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; n$ after step <span class="hl num">3</span>.  After the second pass it is highly unlike that the
sum in step <span class="hl num">4</span> will exceed $n - k$.  In practice fewer than three passes of the algorithm are required to reduce virtually every input in the 
range $<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; (n - k - <span class="hl num">1</span>)^<span class="hl num">2</span>$.  

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>|l|<span class="hl opt">}</span>
<span class="hl kwa">\hline</span>
$x = <span class="hl num">123456789</span>, n = <span class="hl num">256</span>, k = <span class="hl num">3</span>$ \\
<span class="hl kwa">\hline</span> $q <span class="hl kwa">\leftarrow \lfloor</span> x/n <span class="hl kwa">\rfloor</span> = <span class="hl num">482253</span>$ \\
$q <span class="hl kwa">\leftarrow</span> q*k = <span class="hl num">1446759</span>$ \\
$x <span class="hl kwa">\leftarrow</span> x <span class="hl kwa">\mbox</span><span class="hl opt">{</span> mod <span class="hl opt">}</span> n = <span class="hl num">21</span>$ \\
$x <span class="hl kwa">\leftarrow</span> x + q = <span class="hl num">1446780</span>$ \\
$x <span class="hl kwa">\leftarrow</span> x - (n - k) = <span class="hl num">1446527</span>$ \\
<span class="hl kwa">\hline</span> 
$q <span class="hl kwa">\leftarrow \lfloor</span> x/n <span class="hl kwa">\rfloor</span> = <span class="hl num">5650</span>$ \\
$q <span class="hl kwa">\leftarrow</span> q*k = <span class="hl num">16950</span>$ \\
$x <span class="hl kwa">\leftarrow</span> x <span class="hl kwa">\mbox</span><span class="hl opt">{</span> mod <span class="hl opt">}</span> n = <span class="hl num">127</span>$ \\
$x <span class="hl kwa">\leftarrow</span> x + q = <span class="hl num">17077</span>$ \\
$x <span class="hl kwa">\leftarrow</span> x - (n - k) = <span class="hl num">16824</span>$ \\
<span class="hl kwa">\hline</span> 
$q <span class="hl kwa">\leftarrow \lfloor</span> x/n <span class="hl kwa">\rfloor</span> = <span class="hl num">65</span>$ \\
$q <span class="hl kwa">\leftarrow</span> q*k = <span class="hl num">195</span>$ \\
$x <span class="hl kwa">\leftarrow</span> x <span class="hl kwa">\mbox</span><span class="hl opt">{</span> mod <span class="hl opt">}</span> n = <span class="hl num">184</span>$ \\
$x <span class="hl kwa">\leftarrow</span> x + q = <span class="hl num">379</span>$ \\
$x <span class="hl kwa">\leftarrow</span> x - (n - k) = <span class="hl num">126</span>$ \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Example Diminished Radix Reduction<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>fig:EXDR<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

Figure~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:EXDR<span class="hl opt">}</span> demonstrates the reduction of $x = <span class="hl num">123456789</span>$ modulo $n - k = <span class="hl num">253</span>$ when $n = <span class="hl num">256</span>$ and $k = <span class="hl num">3</span>$.  Note that even while $x$
is considerably larger than $(n - k - <span class="hl num">1</span>)^<span class="hl num">2</span> = <span class="hl num">63504</span>$ the algorithm still converges on the modular residue exceedingly fast.  In this case only
three passes were required to find the residue $x <span class="hl kwa">\equiv</span> <span class="hl num">126</span>$.


<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Choice of Moduli<span class="hl opt">}</span>
On the surface this algorithm looks like a very expensive algorithm.  It requires a couple of subtractions followed by multiplication and other
modular reductions.  The usefulness of this algorithm becomes exceedingly clear when an appropriate modulus is chosen.

Division in general is a very expensive operation to perform.  The one exception is when the division is by a power of the radix of representation used.  
Division by ten for example is simple for pencil and paper mathematics since it amounts to shifting the decimal place to the right.  Similarly division 
by two (<span class="hl kwa">\textit</span><span class="hl opt">{</span>or powers of two<span class="hl opt">}</span>) is very simple for binary computers to perform.  It would therefore seem logical to choose $n$ of the form $<span class="hl num">2</span>^p$ 
which would imply that $<span class="hl kwa">\lfloor</span> x / n <span class="hl kwa">\rfloor</span>$ is a simple shift of $x$ right $p$ bits.  

However, there is one operation related to division of power of twos that is even faster than this.  If $n = <span class="hl kwa">\beta</span>^p$ then the division may be 
performed by moving whole digits to the right $p$ places.  In practice division by $<span class="hl kwa">\beta</span>^p$ is much faster than division by $<span class="hl num">2</span>^p$ for any $p$.  
Also with the choice of $n = <span class="hl kwa">\beta</span>^p$ reducing $x$ modulo $n$ merely requires zeroing the digits above the $p-<span class="hl num">1</span>$'th digit of $x$.  

Throughout the next section the term ``restricted modulus'' will refer to a modulus of the form $<span class="hl kwa">\beta</span>^p - k$ whereas the term ``unrestricted
modulus'' will refer to a modulus of the form $<span class="hl num">2</span>^p - k$.  The word ``restricted'' in this case refers to the fact that it is based on the 
$<span class="hl num">2</span>^p$ logic except $p$ must be a multiple of $lg(<span class="hl kwa">\beta</span>)$.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Choice of $k$<span class="hl opt">}</span>
Now that division and reduction (<span class="hl kwa">\textit</span><span class="hl opt">{</span>step <span class="hl num">1</span> and <span class="hl num">3</span> of figure~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:DR<span class="hl opt">}}</span>) have been optimized to simple digit operations the multiplication by $k$
in step <span class="hl num">2</span> is the most expensive operation.  Fortunately the choice of $k$ is not terribly limited.  For all intents and purposes it might
as well be a single digit.  The smaller the value of $k$ is the faster the algorithm will be.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Restricted Diminished Radix Reduction<span class="hl opt">}</span>
The restricted Diminished Radix algorithm can quickly reduce an input modulo a modulus of the form $n = <span class="hl kwa">\beta</span>^p - k$.  This algorithm can reduce 
an input $x$ within the range $<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; n^<span class="hl num">2</span>$ using only a couple passes of the algorithm demonstrated in figure~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:DR<span class="hl opt">}</span>.  The implementation
of this algorithm has been optimized to avoid additional overhead associated with a division by $<span class="hl kwa">\beta</span>^p$, the multiplication by $k$ or the addition 
of $x$ and $q$.  The resulting algorithm is very efficient and can lead to substantial improvements over Barrett and Montgomery reduction when modular 
exponentiations are performed.

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_dr\_reduce</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $x$, $n$ and a mp<span class="hl kwa">\_digit</span> $k = <span class="hl kwa">\beta</span> - n_0$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">11.5</span>mm<span class="hl opt">}</span>($<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; n^<span class="hl num">2</span>$, $n &gt; <span class="hl num">1</span>$, $<span class="hl num">0</span> &lt; k &lt; <span class="hl kwa">\beta</span>$) \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $x <span class="hl kwa">\mbox</span><span class="hl opt">{</span> mod <span class="hl opt">}</span> n$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $m <span class="hl kwa">\leftarrow</span> n.used$ \\
<span class="hl num">2</span>.  If $x.alloc &lt; <span class="hl num">2</span>m$ then grow $x$ to $<span class="hl num">2</span>m$ digits. \\
<span class="hl num">3</span>.  $<span class="hl kwa">\mu \leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">4</span>.  for $i$ from $<span class="hl num">0</span>$ to $m - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.1</span>  $<span class="hl kwa">\hat</span> r <span class="hl kwa">\leftarrow</span> k <span class="hl kwa">\cdot</span> x_<span class="hl opt">{</span>m+i<span class="hl opt">}</span> + x_<span class="hl opt">{</span>i<span class="hl opt">}</span> + <span class="hl kwa">\mu</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.2</span>  $x_<span class="hl opt">{</span>i<span class="hl opt">}</span> <span class="hl kwa">\leftarrow \hat</span> r <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.3</span>  $<span class="hl kwa">\mu \leftarrow \lfloor \hat</span> r / <span class="hl kwa">\beta \rfloor</span>$ \\
<span class="hl num">5</span>.  $x_<span class="hl opt">{</span>m<span class="hl opt">}</span> <span class="hl kwa">\leftarrow \mu</span>$ \\
<span class="hl num">6</span>.  for $i$ from $m + <span class="hl num">1</span>$ to $x.used - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.1</span>  $x_<span class="hl opt">{</span>i<span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">7</span>.  Clamp excess digits of $x$. \\
<span class="hl num">8</span>.  If $x <span class="hl kwa">\ge</span> n$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">8.1</span>  $x <span class="hl kwa">\leftarrow</span> x - n$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">8.2</span>  Goto step <span class="hl num">3</span>. \\
<span class="hl num">9</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_dr\_reduce</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_dr\_reduce</span>.<span class="hl opt">}</span>
This algorithm will perform the Dimished Radix reduction of $x$ modulo $n$.  It has similar restrictions to that of the Barrett reduction
with the addition that $n$ must be of the form $n = <span class="hl kwa">\beta</span>^m - k$ where $<span class="hl num">0</span> &lt; k &lt;<span class="hl kwa">\beta</span>$.  

This algorithm essentially implements the pseudo-code in figure~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:DR<span class="hl opt">}</span> except with a slight optimization.  The division by $<span class="hl kwa">\beta</span>^m$, multiplication by $k$
and addition of $x <span class="hl kwa">\mbox</span><span class="hl opt">{</span> mod <span class="hl opt">}</span><span class="hl kwa">\beta</span>^m$ are all performed simultaneously inside the loop on step <span class="hl num">4</span>.  The division by $<span class="hl kwa">\beta</span>^m$ is emulated by accessing
the term at the $m+i$'th position which is subsequently multiplied by $k$ and added to the term at the $i$'th position.  After the loop the $m$'th
digit is set to the carry and the upper digits are zeroed.  Steps <span class="hl num">5</span> and <span class="hl num">6</span> emulate the reduction modulo $<span class="hl kwa">\beta</span>^m$ that should have happend to 
$x$ before the addition of the multiple of the upper half.  

At step <span class="hl num">8</span> if $x$ is still larger than $n$ another pass of the algorithm is required.  First $n$ is subtracted from $x$ and then the algorithm resumes
at step <span class="hl num">3</span>.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_dr\_reduce</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

The first step is to grow $x$ as required to $<span class="hl num">2</span>m$ digits since the reduction is performed in place on $x$.  The label on line <span class="hl num">52</span> is where
the algorithm will resume if further reduction passes are required.  In theory it could be placed at the top of the function however, the size of
the modulus and question of whether $x$ is large enough are invariant after the first pass meaning that it would be a waste of time.  

The aliases $tmpx1$ and $tmpx2$ refer to the digits of $x$ where the latter is offset by $m$ digits.  By reading digits from $x$ offset by $m$ digits
a division by $<span class="hl kwa">\beta</span>^m$ can be simulated virtually for free.  The loop on line <span class="hl num">64</span> performs the bulk of the work (<span class="hl kwa">\textit</span><span class="hl opt">{</span>corresponds to step <span class="hl num">4</span> of algorithm <span class="hl num">7.11</span><span class="hl opt">}</span>)
in this algorithm.

By line <span class="hl num">67</span> the pointer $tmpx1$ points to the $m$'th digit of $x$ which is where the final carry will be placed.  Similarly by line <span class="hl num">74</span> the 
same pointer will point to the $m+<span class="hl num">1</span>$'th digit where the zeroes will be placed.  

Since the algorithm is only valid if both $x$ and $n$ are greater than zero an unsigned comparison suffices to determine if another pass is required.  
With the same logic at line <span class="hl num">81</span> the value of $x$ is known to be greater than or equal to $n$ meaning that an unsigned subtraction can be used
as well.  Since the destination of the subtraction is the larger of the inputs the call to algorithm s<span class="hl kwa">\_mp\_sub</span> cannot fail and the return code
does not need to be checked.

<span class="hl kwa">\subsubsection</span><span class="hl opt">{</span>Setup<span class="hl opt">}</span>
To setup the restricted Diminished Radix algorithm the value $k = <span class="hl kwa">\beta</span> - n_0$ is required.  This algorithm is not really complicated but provided for
completeness.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_dr\_setup</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $n$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $k = <span class="hl kwa">\beta</span> - n_0$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $k <span class="hl kwa">\leftarrow \beta</span> - n_0$ \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_dr\_setup</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_dr\_setup</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

<span class="hl kwa">\subsubsection</span><span class="hl opt">{</span>Modulus Detection<span class="hl opt">}</span>
Another algorithm which will be useful is the ability to detect a restricted Diminished Radix modulus.  An integer is said to be
of restricted Diminished Radix form if all of the digits are equal to $<span class="hl kwa">\beta</span> - <span class="hl num">1</span>$ except the trailing digit which may be any value.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_dr\_is\_modulus</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $n$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $<span class="hl num">1</span>$ if $n$ is in D.R form, $<span class="hl num">0</span>$ otherwise \\
<span class="hl kwa">\hline</span>
<span class="hl num">1</span>.  If $n.used &lt; <span class="hl num">2</span>$ then return($<span class="hl num">0</span>$). \\
<span class="hl num">2</span>.  for $ix$ from $<span class="hl num">1</span>$ to $n.used - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  If $n_<span class="hl opt">{</span>ix<span class="hl opt">}</span> <span class="hl kwa">\ne \beta</span> - <span class="hl num">1</span>$ return($<span class="hl num">0</span>$). \\
<span class="hl num">3</span>.  Return($<span class="hl num">1</span>$). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_dr\_is\_modulus</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_dr\_is\_modulus</span>.<span class="hl opt">}</span>
This algorithm determines if a value is in Diminished Radix form.  Step <span class="hl num">1</span> rejects obvious cases where fewer than two digits are
in the mp<span class="hl kwa">\_int</span>.  Step <span class="hl num">2</span> tests all but the first digit to see if they are equal to $<span class="hl kwa">\beta</span> - <span class="hl num">1</span>$.  If the algorithm manages to get to
step <span class="hl num">3</span> then $n$ must be of Diminished Radix form.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_dr\_is\_modulus</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Unrestricted Diminished Radix Reduction<span class="hl opt">}</span>
The unrestricted Diminished Radix algorithm allows modular reductions to be performed when the modulus is of the form $<span class="hl num">2</span>^p - k$.  This algorithm
is a straightforward adaptation of algorithm~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:DR<span class="hl opt">}</span>.

In general the restricted Diminished Radix reduction algorithm is much faster since it has considerably lower overhead.  However, this new
algorithm is much faster than either Montgomery or Barrett reduction when the moduli are of the appropriate form.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_reduce\_2k</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$ and $n$.  mp<span class="hl kwa">\_digit</span> $k$  \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">11.5</span>mm<span class="hl opt">}</span>($a <span class="hl kwa">\ge</span> <span class="hl num">0</span>$, $n &gt; <span class="hl num">1</span>$, $<span class="hl num">0</span> &lt; k &lt; <span class="hl kwa">\beta</span>$, $n + k$ is a power of two) \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>n<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hline</span>
<span class="hl num">1</span>.  $p <span class="hl kwa">\leftarrow \lceil</span> lg(n) <span class="hl kwa">\rceil</span>$  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_count\_bits</span><span class="hl opt">}</span>) \\
<span class="hl num">2</span>.  While $a <span class="hl kwa">\ge</span> n$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  $q <span class="hl kwa">\leftarrow \lfloor</span> a / <span class="hl num">2</span>^p <span class="hl kwa">\rfloor</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_div\_2d</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.2</span>  $a <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span>^p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_mod\_2d</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.3</span>  $q <span class="hl kwa">\leftarrow</span> q <span class="hl kwa">\cdot</span> k$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_mul\_d</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.4</span>  $a <span class="hl kwa">\leftarrow</span> a - q$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>s<span class="hl kwa">\_mp\_sub</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.5</span>  If $a <span class="hl kwa">\ge</span> n$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">2.5.1</span>  $a <span class="hl kwa">\leftarrow</span> a - n$ \\
<span class="hl num">3</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_reduce\_2k</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_reduce\_2k</span>.<span class="hl opt">}</span>
This algorithm quickly reduces an input $a$ modulo an unrestricted Diminished Radix modulus $n$.  Division by $<span class="hl num">2</span>^p$ is emulated with a right
shift which makes the algorithm fairly inexpensive to use.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_reduce\_2k</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

The algorithm mp<span class="hl kwa">\_count\_bits</span> calculates the number of bits in an mp<span class="hl kwa">\_int</span> which is used to find the initial value of $p$.  The call to mp<span class="hl kwa">\_div\_2d</span>
on line <span class="hl num">31</span> calculates both the quotient $q$ and the remainder $a$ required.  By doing both in a single function call the code size
is kept fairly small.  The multiplication by $k$ is only performed if $k &gt; <span class="hl num">1</span>$. This allows reductions modulo $<span class="hl num">2</span>^p - <span class="hl num">1</span>$ to be performed without
any multiplications.  

The unsigned s<span class="hl kwa">\_mp\_add</span>, mp<span class="hl kwa">\_cmp\_mag</span> and s<span class="hl kwa">\_mp\_sub</span> are used in place of their full sign counterparts since the inputs are only valid if they are 
positive.  By using the unsigned versions the overhead is kept to a minimum.  

<span class="hl kwa">\subsubsection</span><span class="hl opt">{</span>Unrestricted Setup<span class="hl opt">}</span>
To setup this reduction algorithm the value of $k = <span class="hl num">2</span>^p - n$ is required.  

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_reduce\_2k\_setup</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $n$   \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $k = <span class="hl num">2</span>^p - n$ \\
<span class="hl kwa">\hline</span>
<span class="hl num">1</span>.  $p <span class="hl kwa">\leftarrow \lceil</span> lg(n) <span class="hl kwa">\rceil</span>$  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_count\_bits</span><span class="hl opt">}</span>) \\
<span class="hl num">2</span>.  $x <span class="hl kwa">\leftarrow</span> <span class="hl num">2</span>^p$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_2expt</span><span class="hl opt">}</span>) \\
<span class="hl num">3</span>.  $x <span class="hl kwa">\leftarrow</span> x - n$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_sub</span><span class="hl opt">}</span>) \\
<span class="hl num">4</span>.  $k <span class="hl kwa">\leftarrow</span> x_0$ \\
<span class="hl num">5</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_reduce\_2k\_setup</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_reduce\_2k\_setup</span>.<span class="hl opt">}</span>
This algorithm computes the value of $k$ required for the algorithm mp<span class="hl kwa">\_reduce\_2k</span>.  By making a temporary variable $x$ equal to $<span class="hl num">2</span>^p$ a subtraction
is sufficient to solve for $k$.  Alternatively if $n$ has more than one digit the value of $k$ is simply $<span class="hl kwa">\beta</span> - n_0$.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_reduce\_2k\_setup</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

<span class="hl kwa">\subsubsection</span><span class="hl opt">{</span>Unrestricted Detection<span class="hl opt">}</span>
An integer $n$ is a valid unrestricted Diminished Radix modulus if either of the following are true.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>enumerate<span class="hl opt">}</span>
<span class="hl kwa">\item</span>  The number has only one digit.
<span class="hl kwa">\item</span>  The number has more than one digit and every bit from the $<span class="hl kwa">\beta</span>$'th to the most significant is one.
<span class="hl kwa">\end</span><span class="hl opt">{</span>enumerate<span class="hl opt">}</span>

If either condition is true than there is a power of two $<span class="hl num">2</span>^p$ such that $<span class="hl num">0</span> &lt; <span class="hl num">2</span>^p - n &lt; <span class="hl kwa">\beta</span>$.   If the input is only
one digit than it will always be of the correct form.  Otherwise all of the bits above the first digit must be one.  This arises from the fact
that there will be value of $k$ that when added to the modulus causes a carry in the first digit which propagates all the way to the most
significant bit.  The resulting sum will be a power of two.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_reduce\_is\_2k</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $n$   \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $<span class="hl num">1</span>$ if of proper form, $<span class="hl num">0</span>$ otherwise \\
<span class="hl kwa">\hline</span>
<span class="hl num">1</span>.  If $n.used = <span class="hl num">0</span>$ then return($<span class="hl num">0</span>$). \\
<span class="hl num">2</span>.  If $n.used = <span class="hl num">1</span>$ then return($<span class="hl num">1</span>$). \\
<span class="hl num">3</span>.  $p <span class="hl kwa">\leftarrow \lceil</span> lg(n) <span class="hl kwa">\rceil</span>$  (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_count\_bits</span><span class="hl opt">}</span>) \\
<span class="hl num">4</span>.  for $x$ from $lg(<span class="hl kwa">\beta</span>)$ to $p$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.1</span>  If the ($x <span class="hl kwa">\mbox</span><span class="hl opt">{</span> mod <span class="hl opt">}</span>lg(<span class="hl kwa">\beta</span>)$)'th bit of the $<span class="hl kwa">\lfloor</span> x / lg(<span class="hl kwa">\beta</span>) <span class="hl kwa">\rfloor</span>$ of $n$ is zero then return($<span class="hl num">0</span>$). \\
<span class="hl num">5</span>.  Return($<span class="hl num">1</span>$). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_reduce\_is\_2k</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_reduce\_is\_2k</span>.<span class="hl opt">}</span>
This algorithm quickly determines if a modulus is of the form required for algorithm mp<span class="hl kwa">\_reduce\_2k</span> to function properly.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_reduce\_is\_2k</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>



<span class="hl kwa">\section</span><span class="hl opt">{</span>Algorithm Comparison<span class="hl opt">}</span>
So far three very different algorithms for modular reduction have been discussed.  Each of the algorithms have their own strengths and weaknesses
that makes having such a selection very useful.  The following table sumarizes the three algorithms along with comparisons of work factors.  Since
all three algorithms have the restriction that $<span class="hl num">0</span> <span class="hl kwa">\le</span> x &lt; n^<span class="hl num">2</span>$ and $n &gt; <span class="hl num">1</span>$ those limitations are not included in the table.  

<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>|c|c|c|c|c|c|<span class="hl opt">}</span>
<span class="hl kwa">\hline \textbf</span><span class="hl opt">{</span>Method<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Work Required<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Limitations<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>$m = <span class="hl num">8</span>$<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>$m = <span class="hl num">32</span>$<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>$m = <span class="hl num">64</span>$<span class="hl opt">}</span> \\
<span class="hl kwa">\hline</span> Barrett    &amp; $m^<span class="hl num">2</span> + <span class="hl num">2</span>m - <span class="hl num">1</span>$ &amp; None              &amp; $<span class="hl num">79</span>$ &amp; $<span class="hl num">1087</span>$ &amp; $<span class="hl num">4223</span>$ \\
<span class="hl kwa">\hline</span> Montgomery &amp; $m^<span class="hl num">2</span> + m$      &amp; $n$ must be odd   &amp; $<span class="hl num">72</span>$ &amp; $<span class="hl num">1056</span>$ &amp; $<span class="hl num">4160</span>$ \\
<span class="hl kwa">\hline</span> D.R.       &amp; $<span class="hl num">2</span>m$           &amp; $n = <span class="hl kwa">\beta</span>^m - k$ &amp; $<span class="hl num">16</span>$ &amp; $<span class="hl num">64</span>$   &amp; $<span class="hl num">128</span>$  \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>

In theory Montgomery and Barrett reductions would require roughly the same amount of time to complete.  However, in practice since Montgomery
reduction can be written as a single function with the Comba technique it is much faster.  Barrett reduction suffers from the overhead of
calling the half precision multipliers, addition and division by $<span class="hl kwa">\beta</span>$ algorithms.

For almost every cryptographic algorithm Montgomery reduction is the algorithm of choice.  The one set of algorithms where Diminished Radix reduction truly
shines are based on the discrete logarithm problem such as Diffie-Hellman <span class="hl kwa">\cite</span><span class="hl opt">{</span>DH<span class="hl opt">}</span> and ElGamal <span class="hl kwa">\cite</span><span class="hl opt">{</span>ELGAMAL<span class="hl opt">}</span>.  In these algorithms
primes of the form $<span class="hl kwa">\beta</span>^m - k$ can be found and shared amongst users.  These primes will allow the Diminished Radix algorithm to be used in
modular exponentiation to greatly speed up the operation.



<span class="hl kwa">\section</span>*<span class="hl opt">{</span>Exercises<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>cl<span class="hl opt">}</span>
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">3</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span>$ &amp; Prove that the ``trick'' in algorithm mp<span class="hl kwa">\_montgomery\_setup</span> actually \\
                     &amp; calculates the correct value of $<span class="hl kwa">\rho</span>$. \\
                     &amp; \\
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">2</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span>$ &amp; Devise an algorithm to reduce modulo $n + k$ for small $k$ quickly.  \\
                     &amp; \\
$<span class="hl kwa">\left</span> <span class="hl opt">[</span> <span class="hl num">4</span> <span class="hl kwa">\right</span> <span class="hl opt">]</span>$ &amp; Prove that the pseudo-code algorithm ``Diminished Radix Reduction'' \\
                     &amp; (<span class="hl kwa">\textit</span><span class="hl opt">{</span>figure~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:DR<span class="hl opt">}}</span>) terminates.  Also prove the probability that it will \\
                     &amp; terminate within $<span class="hl num">1</span> <span class="hl kwa">\le</span> k <span class="hl kwa">\le</span> <span class="hl num">10</span>$ iterations. \\
                     &amp; \\
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>                     


<span class="hl kwa">\chapter</span><span class="hl opt">{</span>Exponentiation<span class="hl opt">}</span>
Exponentiation is the operation of raising one variable to the power of another, for example, $a^b$.  A variant of exponentiation, computed
in a finite field or ring, is called modular exponentiation.  This latter style of operation is typically used in public key 
cryptosystems such as RSA and Diffie-Hellman.  The ability to quickly compute modular exponentiations is of great benefit to any
such cryptosystem and many methods have been sought to speed it up.

<span class="hl kwa">\section</span><span class="hl opt">{</span>Exponentiation Basics<span class="hl opt">}</span>
A trivial algorithm would simply multiply $a$ against itself $b - <span class="hl num">1</span>$ times to compute the exponentiation desired.  However, as $b$ grows in size
the number of multiplications becomes prohibitive.  Imagine what would happen if $b$ $<span class="hl kwa">\approx</span>$ $<span class="hl num">2</span>^<span class="hl opt">{</span><span class="hl num">1024</span><span class="hl opt">}</span>$ as is the case when computing an RSA signature
with a $<span class="hl num">1024</span>$-bit key.  Such a calculation could never be completed as it would take simply far too long.

Fortunately there is a very simple algorithm based on the laws of exponents.  Recall that $lg_a(a^b) = b$ and that $lg_a(a^ba^c) = b + c$ which
are two trivial relationships between the base and the exponent.  Let $b_i$ represent the $i$'th bit of $b$ starting from the least 
significant bit.  If $b$ is a $k$-bit integer than the following equation is true.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
a^b = <span class="hl kwa">\prod_</span><span class="hl opt">{</span>i=<span class="hl num">0</span><span class="hl opt">}</span>^<span class="hl opt">{</span>k-<span class="hl num">1</span><span class="hl opt">}</span> a^<span class="hl opt">{</span><span class="hl num">2</span>^i <span class="hl kwa">\cdot</span> b_i<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

By taking the base $a$ logarithm of both sides of the equation the following equation is the result.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
b = <span class="hl kwa">\sum_</span><span class="hl opt">{</span>i=<span class="hl num">0</span><span class="hl opt">}</span>^<span class="hl opt">{</span>k-<span class="hl num">1</span><span class="hl opt">}</span><span class="hl num">2</span>^i <span class="hl kwa">\cdot</span> b_i
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

The term $a^<span class="hl opt">{</span><span class="hl num">2</span>^i<span class="hl opt">}</span>$ can be found from the $i - <span class="hl num">1</span>$'th term by squaring the term since $<span class="hl kwa">\left</span> ( a^<span class="hl opt">{</span><span class="hl num">2</span>^i<span class="hl opt">}</span> <span class="hl kwa">\right</span> )^<span class="hl num">2</span>$ is equal to
$a^<span class="hl opt">{</span><span class="hl num">2</span>^<span class="hl opt">{</span>i+<span class="hl num">1</span><span class="hl opt">}}</span>$.  This observation forms the basis of essentially all fast exponentiation algorithms.  It requires $k$ squarings and on average
$k <span class="hl kwa">\over</span> <span class="hl num">2</span>$ multiplications to compute the result.  This is indeed quite an improvement over simply multiplying by $a$ a total of $b-<span class="hl num">1</span>$ times.

While this current method is a considerable speed up there are further improvements to be made.  For example, the $a^<span class="hl opt">{</span><span class="hl num">2</span>^i<span class="hl opt">}</span>$ term does not need to 
be computed in an auxilary variable.  Consider the following equivalent algorithm.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Left to Right Exponentiation<span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   Integer $a$, $b$ and $k$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $c = a^b$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $c <span class="hl kwa">\leftarrow</span> <span class="hl num">1</span>$ \\
<span class="hl num">2</span>.  for $i$ from $k - <span class="hl num">1</span>$ to $<span class="hl num">0</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  $c <span class="hl kwa">\leftarrow</span> c^<span class="hl num">2</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.2</span>  $c <span class="hl kwa">\leftarrow</span> c <span class="hl kwa">\cdot</span> a^<span class="hl opt">{</span>b_i<span class="hl opt">}</span>$ \\
<span class="hl num">3</span>.  Return $c$. \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Left to Right Exponentiation<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>fig:LTOR<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

This algorithm starts from the most significant bit and works towards the least significant bit.  When the $i$'th bit of $b$ is set $a$ is
multiplied against the current product.  In each iteration the product is squared which doubles the exponent of the individual terms of the
product.  

For example, let $b = <span class="hl num">101100</span>_2 <span class="hl kwa">\equiv</span> <span class="hl num">44</span>_<span class="hl opt">{</span><span class="hl num">10</span><span class="hl opt">}</span>$.  The following chart demonstrates the actions of the algorithm.

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>|c|c|<span class="hl opt">}</span>
<span class="hl kwa">\hline \textbf</span><span class="hl opt">{</span>Value of $i$<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Value of $c$<span class="hl opt">}</span> \\
<span class="hl kwa">\hline</span> - &amp; $<span class="hl num">1</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">5</span>$ &amp; $a$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">4</span>$ &amp; $a^<span class="hl num">2</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">3</span>$ &amp; $a^<span class="hl num">4</span> <span class="hl kwa">\cdot</span> a$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">2</span>$ &amp; $a^<span class="hl num">8</span> <span class="hl kwa">\cdot</span> a^<span class="hl num">2</span> <span class="hl kwa">\cdot</span> a$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">1</span>$ &amp; $a^<span class="hl opt">{</span><span class="hl num">16</span><span class="hl opt">}</span> <span class="hl kwa">\cdot</span> a^<span class="hl num">4</span> <span class="hl kwa">\cdot</span> a^<span class="hl num">2</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">0</span>$ &amp; $a^<span class="hl opt">{</span><span class="hl num">32</span><span class="hl opt">}</span> <span class="hl kwa">\cdot</span> a^<span class="hl num">8</span> <span class="hl kwa">\cdot</span> a^<span class="hl num">4</span>$ \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Example of Left to Right Exponentiation<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

When the product $a^<span class="hl opt">{</span><span class="hl num">32</span><span class="hl opt">}</span> <span class="hl kwa">\cdot</span> a^<span class="hl num">8</span> <span class="hl kwa">\cdot</span> a^<span class="hl num">4</span>$ is simplified it is equal $a^<span class="hl opt">{</span><span class="hl num">44</span><span class="hl opt">}</span>$ which is the desired exponentiation.  This particular algorithm is 
called ``Left to Right'' because it reads the exponent in that order.  All of the exponentiation algorithms that will be presented are of this nature.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Single Digit Exponentiation<span class="hl opt">}</span>
The first algorithm in the series of exponentiation algorithms will be an unbounded algorithm where the exponent is a single digit.  It is intended 
to be used when a small power of an input is required (<span class="hl kwa">\textit</span><span class="hl opt">{</span>e.g. $a^<span class="hl num">5</span>$<span class="hl opt">}</span>).  It is faster than simply multiplying $b - <span class="hl num">1</span>$ times for all values of 
$b$ that are greater than three.  

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_expt\_d</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$ and mp<span class="hl kwa">\_digit</span> $b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $c = a^b$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $g <span class="hl kwa">\leftarrow</span> a$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_init\_copy</span><span class="hl opt">}</span>) \\
<span class="hl num">2</span>.  $c <span class="hl kwa">\leftarrow</span> <span class="hl num">1</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_set</span><span class="hl opt">}</span>) \\
<span class="hl num">3</span>.  for $x$ from <span class="hl num">1</span> to $lg(<span class="hl kwa">\beta</span>)$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">3.1</span>  $c <span class="hl kwa">\leftarrow</span> c^<span class="hl num">2</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_sqr</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">3.2</span>  If $b$ AND $<span class="hl num">2</span>^<span class="hl opt">{</span>lg(<span class="hl kwa">\beta</span>) - <span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\ne</span> <span class="hl num">0</span>$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">3.2.1</span>  $c <span class="hl kwa">\leftarrow</span> c <span class="hl kwa">\cdot</span> g$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_mul</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">3.3</span>  $b <span class="hl kwa">\leftarrow</span> b &lt;&lt; <span class="hl num">1</span>$ \\
<span class="hl num">4</span>.  Clear $g$. \\
<span class="hl num">5</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_expt\_d</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_expt\_d</span>.<span class="hl opt">}</span>
This algorithm computes the value of $a$ raised to the power of a single digit $b$.  It uses the left to right exponentiation algorithm to
quickly compute the exponentiation.  It is loosely based on algorithm <span class="hl num">14.79</span> of HAC <span class="hl kwa">\cite</span><span class="hl opt">[</span>pp. <span class="hl num">615</span><span class="hl opt">]{</span>HAC<span class="hl opt">}</span> with the difference that the 
exponent is a fixed width.  

A copy of $a$ is made first to allow destination variable $c$ be the same as the source variable $a$.  The result is set to the initial value of 
$<span class="hl num">1</span>$ in the subsequent step.

Inside the loop the exponent is read from the most significant bit first down to the least significant bit.  First $c$ is invariably squared
on step <span class="hl num">3.1</span>.  In the following step if the most significant bit of $b$ is one the copy of $a$ is multiplied against $c$.  The value
of $b$ is shifted left one bit to make the next bit down from the most signficant bit the new most significant bit.  In effect each
iteration of the loop moves the bits of the exponent $b$ upwards to the most significant location.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_expt\_d</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

Line <span class="hl num">29</span> sets the initial value of the result to $<span class="hl num">1</span>$.  Next the loop on line <span class="hl num">31</span> steps through each bit of the exponent starting from
the most significant down towards the least significant. The invariant squaring operation placed on line <span class="hl num">33</span> is performed first.  After 
the squaring the result $c$ is multiplied by the base $g$ if and only if the most significant bit of the exponent is set.  The shift on line
<span class="hl num">47</span> moves all of the bits of the exponent upwards towards the most significant location.  

<span class="hl kwa">\section</span><span class="hl opt">{</span>$k$-ary Exponentiation<span class="hl opt">}</span>
When calculating an exponentiation the most time consuming bottleneck is the multiplications which are in general a small factor
slower than squaring.  Recall from the previous algorithm that $b_<span class="hl opt">{</span>i<span class="hl opt">}</span>$ refers to the $i$'th bit of the exponent $b$.  Suppose instead it referred to
the $i$'th $k$-bit digit of the exponent of $b$.  For $k = <span class="hl num">1</span>$ the definitions are synonymous and for $k &gt; <span class="hl num">1</span>$ algorithm~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:KARY<span class="hl opt">}</span>
computes the same exponentiation.  A group of $k$ bits from the exponent is called a <span class="hl kwa">\textit</span><span class="hl opt">{</span>window<span class="hl opt">}</span>.  That is it is a small window on only a
portion of the entire exponent.  Consider the following modification to the basic left to right exponentiation algorithm.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>$k$-ary Exponentiation<span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   Integer $a$, $b$, $k$ and $t$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $c = a^b$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $c <span class="hl kwa">\leftarrow</span> <span class="hl num">1</span>$ \\
<span class="hl num">2</span>.  for $i$ from $t - <span class="hl num">1</span>$ to $<span class="hl num">0</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  $c <span class="hl kwa">\leftarrow</span> c^<span class="hl opt">{</span><span class="hl num">2</span>^k<span class="hl opt">}</span> $ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.2</span>  Extract the $i$'th $k$-bit word from $b$ and store it in $g$. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.3</span>  $c <span class="hl kwa">\leftarrow</span> c <span class="hl kwa">\cdot</span> a^g$ \\
<span class="hl num">3</span>.  Return $c$. \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>$k$-ary Exponentiation<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>fig:KARY<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

The squaring on step <span class="hl num">2.1</span> can be calculated by squaring the value $c$ successively $k$ times.  If the values of $a^g$ for $<span class="hl num">0</span> &lt; g &lt; <span class="hl num">2</span>^k$ have been
precomputed this algorithm requires only $t$ multiplications and $tk$ squarings.  The table can be generated with $<span class="hl num">2</span>^<span class="hl opt">{</span>k - <span class="hl num">1</span><span class="hl opt">}</span> - <span class="hl num">1</span>$ squarings and
$<span class="hl num">2</span>^<span class="hl opt">{</span>k - <span class="hl num">1</span><span class="hl opt">}</span> + <span class="hl num">1</span>$ multiplications.  This algorithm assumes that the number of bits in the exponent is evenly divisible by $k$.  
However, when it is not the remaining $<span class="hl num">0</span> &lt; x <span class="hl kwa">\le</span> k - <span class="hl num">1</span>$ bits can be handled with algorithm~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:LTOR<span class="hl opt">}</span>.

Suppose $k = <span class="hl num">4</span>$ and $t = <span class="hl num">100</span>$.  This modified algorithm will require $<span class="hl num">109</span>$ multiplications and $<span class="hl num">408</span>$ squarings to compute the exponentiation.  The
original algorithm would on average have required $<span class="hl num">200</span>$ multiplications and $<span class="hl num">400</span>$ squrings to compute the same value.  The total number of squarings
has increased slightly but the number of multiplications has nearly halved.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Optimal Values of $k$<span class="hl opt">}</span>
An optimal value of $k$ will minimize $<span class="hl num">2</span>^<span class="hl opt">{</span>k<span class="hl opt">}</span> + <span class="hl kwa">\lceil</span> n / k <span class="hl kwa">\rceil</span> + n - <span class="hl num">1</span>$ for a fixed number of bits in the exponent $n$.  The simplest
approach is to brute force search amongst the values $k = <span class="hl num">2</span>, <span class="hl num">3</span>, <span class="hl kwa">\ldots</span>, <span class="hl num">8</span>$ for the lowest result.  Table~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:OPTK<span class="hl opt">}</span> lists optimal values of $k$
for various exponent sizes and compares the number of multiplication and squarings required against algorithm~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:LTOR<span class="hl opt">}</span>.  

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>|c|c|c|c|c|c|<span class="hl opt">}</span>
<span class="hl kwa">\hline \textbf</span><span class="hl opt">{</span>Exponent (bits)<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Optimal $k$<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Work at $k$<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Work with ~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:LTOR<span class="hl opt">}}</span> \\
<span class="hl kwa">\hline</span> $<span class="hl num">16</span>$ &amp; $<span class="hl num">2</span>$ &amp; $<span class="hl num">27</span>$ &amp; $<span class="hl num">24</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">32</span>$ &amp; $<span class="hl num">3</span>$ &amp; $<span class="hl num">49</span>$ &amp; $<span class="hl num">48</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">64</span>$ &amp; $<span class="hl num">3</span>$ &amp; $<span class="hl num">92</span>$ &amp; $<span class="hl num">96</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">128</span>$ &amp; $<span class="hl num">4</span>$ &amp; $<span class="hl num">175</span>$ &amp; $<span class="hl num">192</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">256</span>$ &amp; $<span class="hl num">4</span>$ &amp; $<span class="hl num">335</span>$ &amp; $<span class="hl num">384</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">512</span>$ &amp; $<span class="hl num">5</span>$ &amp; $<span class="hl num">645</span>$ &amp; $<span class="hl num">768</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">1024</span>$ &amp; $<span class="hl num">6</span>$ &amp; $<span class="hl num">1257</span>$ &amp; $<span class="hl num">1536</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">2048</span>$ &amp; $<span class="hl num">6</span>$ &amp; $<span class="hl num">2452</span>$ &amp; $<span class="hl num">3072</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">4096</span>$ &amp; $<span class="hl num">7</span>$ &amp; $<span class="hl num">4808</span>$ &amp; $<span class="hl num">6144</span>$ \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Optimal Values of $k$ for $k$-ary Exponentiation<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>fig:OPTK<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Sliding-Window Exponentiation<span class="hl opt">}</span>
A simple modification to the previous algorithm is only generate the upper half of the table in the range $<span class="hl num">2</span>^<span class="hl opt">{</span>k-<span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\le</span> g &lt; <span class="hl num">2</span>^k$.  Essentially
this is a table for all values of $g$ where the most significant bit of $g$ is a one.  However, in order for this to be allowed in the 
algorithm values of $g$ in the range $<span class="hl num">0</span> <span class="hl kwa">\le</span> g &lt; <span class="hl num">2</span>^<span class="hl opt">{</span>k-<span class="hl num">1</span><span class="hl opt">}</span>$ must be avoided.  

Table~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:OPTK2<span class="hl opt">}</span> lists optimal values of $k$ for various exponent sizes and compares the work required against algorithm~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:KARY<span class="hl opt">}</span>.  

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>|c|c|c|c|c|c|<span class="hl opt">}</span>
<span class="hl kwa">\hline \textbf</span><span class="hl opt">{</span>Exponent (bits)<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Optimal $k$<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Work at $k$<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Work with ~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:KARY<span class="hl opt">}}</span> \\
<span class="hl kwa">\hline</span> $<span class="hl num">16</span>$ &amp; $<span class="hl num">3</span>$ &amp; $<span class="hl num">24</span>$ &amp; $<span class="hl num">27</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">32</span>$ &amp; $<span class="hl num">3</span>$ &amp; $<span class="hl num">45</span>$ &amp; $<span class="hl num">49</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">64</span>$ &amp; $<span class="hl num">4</span>$ &amp; $<span class="hl num">87</span>$ &amp; $<span class="hl num">92</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">128</span>$ &amp; $<span class="hl num">4</span>$ &amp; $<span class="hl num">167</span>$ &amp; $<span class="hl num">175</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">256</span>$ &amp; $<span class="hl num">5</span>$ &amp; $<span class="hl num">322</span>$ &amp; $<span class="hl num">335</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">512</span>$ &amp; $<span class="hl num">6</span>$ &amp; $<span class="hl num">628</span>$ &amp; $<span class="hl num">645</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">1024</span>$ &amp; $<span class="hl num">6</span>$ &amp; $<span class="hl num">1225</span>$ &amp; $<span class="hl num">1257</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">2048</span>$ &amp; $<span class="hl num">7</span>$ &amp; $<span class="hl num">2403</span>$ &amp; $<span class="hl num">2452</span>$ \\
<span class="hl kwa">\hline</span> $<span class="hl num">4096</span>$ &amp; $<span class="hl num">8</span>$ &amp; $<span class="hl num">4735</span>$ &amp; $<span class="hl num">4808</span>$ \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Optimal Values of $k$ for Sliding Window Exponentiation<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>fig:OPTK2<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Sliding Window $k$-ary Exponentiation<span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   Integer $a$, $b$, $k$ and $t$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $c = a^b$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $c <span class="hl kwa">\leftarrow</span> <span class="hl num">1</span>$ \\
<span class="hl num">2</span>.  for $i$ from $t - <span class="hl num">1</span>$ to $<span class="hl num">0</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  If the $i$'th bit of $b$ is a zero then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">2.1.1</span>   $c <span class="hl kwa">\leftarrow</span> c^<span class="hl num">2</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.2</span>  else do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">2.2.1</span>  $c <span class="hl kwa">\leftarrow</span> c^<span class="hl opt">{</span><span class="hl num">2</span>^k<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">2.2.2</span>  Extract the $k$ bits from $(b_<span class="hl opt">{</span>i<span class="hl opt">}</span>b_<span class="hl opt">{</span>i-<span class="hl num">1</span><span class="hl opt">}</span><span class="hl kwa">\ldots</span> b_<span class="hl opt">{</span>i-(k-<span class="hl num">1</span>)<span class="hl opt">}</span>)$ and store it in $g$. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">2.2.3</span>  $c <span class="hl kwa">\leftarrow</span> c <span class="hl kwa">\cdot</span> a^g$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">2.2.4</span>  $i <span class="hl kwa">\leftarrow</span> i - k$ \\
<span class="hl num">3</span>.  Return $c$. \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Sliding Window $k$-ary Exponentiation<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

Similar to the previous algorithm this algorithm must have a special handler when fewer than $k$ bits are left in the exponent.  While this
algorithm requires the same number of squarings it can potentially have fewer multiplications.  The pre-computed table $a^g$ is also half
the size as the previous table.  

Consider the exponent $b = <span class="hl num">111101011001000</span>_2 <span class="hl kwa">\equiv</span> <span class="hl num">31432</span>_<span class="hl opt">{</span><span class="hl num">10</span><span class="hl opt">}</span>$ with $k = <span class="hl num">3</span>$ using both algorithms.  The first algorithm will divide the exponent up as 
the following five $<span class="hl num">3</span>$-bit words $b <span class="hl kwa">\equiv \left</span> ( <span class="hl num">111</span>, <span class="hl num">101</span>, <span class="hl num">011</span>, <span class="hl num">001</span>, <span class="hl num">000</span> <span class="hl kwa">\right</span> )_<span class="hl opt">{</span><span class="hl num">2</span><span class="hl opt">}</span>$.  The second algorithm will break the 
exponent as $b <span class="hl kwa">\equiv \left</span> ( <span class="hl num">111</span>, <span class="hl num">101</span>, <span class="hl num">0</span>, <span class="hl num">110</span>, <span class="hl num">0</span>, <span class="hl num">100</span>, <span class="hl num">0</span> <span class="hl kwa">\right</span> )_<span class="hl opt">{</span><span class="hl num">2</span><span class="hl opt">}</span>$.  The single digit $<span class="hl num">0</span>$ in the second representation are where
a single squaring took place instead of a squaring and multiplication.  In total the first method requires $<span class="hl num">10</span>$ multiplications and $<span class="hl num">18</span>$ 
squarings.  The second method requires $<span class="hl num">8</span>$ multiplications and $<span class="hl num">18</span>$ squarings.  

In general the sliding window method is never slower than the generic $k$-ary method and often it is slightly faster.  

<span class="hl kwa">\section</span><span class="hl opt">{</span>Modular Exponentiation<span class="hl opt">}</span>

Modular exponentiation is essentially computing the power of a base within a finite field or ring.  For example, computing 
$d <span class="hl kwa">\equiv</span> a^b <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>c<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ is a modular exponentiation.  Instead of first computing $a^b$ and then reducing it 
modulo $c$ the intermediate result is reduced modulo $c$ after every squaring or multiplication operation.  

This guarantees that any intermediate result is bounded by $<span class="hl num">0</span> <span class="hl kwa">\le</span> d <span class="hl kwa">\le</span> c^<span class="hl num">2</span> - <span class="hl num">2</span>c + <span class="hl num">1</span>$ and can be reduced modulo $c$ quickly using
one of the algorithms presented in chapter six.  

Before the actual modular exponentiation algorithm can be written a wrapper algorithm must be written first.  This algorithm
will allow the exponent $b$ to be negative which is computed as $c <span class="hl kwa">\equiv \left</span> (<span class="hl num">1</span> / a <span class="hl kwa">\right</span> )^<span class="hl opt">{</span><span class="hl kwa">\vert</span> b <span class="hl kwa">\vert</span><span class="hl opt">}</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span>(mod <span class="hl opt">}</span>d<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$. The
value of $(<span class="hl num">1</span>/a) <span class="hl kwa">\mbox</span><span class="hl opt">{</span> mod <span class="hl opt">}</span>c$ is computed using the modular inverse (<span class="hl kwa">\textit</span><span class="hl opt">{</span>see <span class="hl kwa">\ref</span><span class="hl opt">{</span>sec;modinv<span class="hl opt">}}</span>).  If no inverse exists the algorithm
terminates with an error.  

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_exptmod</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$, $b$ and $c$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $y <span class="hl kwa">\equiv</span> g^x <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  If $c.sign = MP<span class="hl kwa">\_NEG</span>$ return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_VAL</span><span class="hl opt">}</span>). \\
<span class="hl num">2</span>.  If $b.sign = MP<span class="hl kwa">\_NEG</span>$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  $g' <span class="hl kwa">\leftarrow</span> g^<span class="hl opt">{</span>-<span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>c<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.2</span>  $x' <span class="hl kwa">\leftarrow \vert</span> x <span class="hl kwa">\vert</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.3</span>  Compute $d <span class="hl kwa">\equiv</span> g'^<span class="hl opt">{</span>x'<span class="hl opt">}</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>c<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ via recursion. \\
<span class="hl num">3</span>.  if $p$ is odd <span class="hl kwa">\textbf</span><span class="hl opt">{</span>OR<span class="hl opt">}</span> $p$ is a D.R. modulus then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">3.1</span>  Compute $y <span class="hl kwa">\equiv</span> g^<span class="hl opt">{</span>x<span class="hl opt">}</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ via algorithm mp<span class="hl kwa">\_exptmod\_fast</span>. \\
<span class="hl num">4</span>.  else \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.1</span>  Compute $y <span class="hl kwa">\equiv</span> g^<span class="hl opt">{</span>x<span class="hl opt">}</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ via algorithm s<span class="hl kwa">\_mp\_exptmod</span>. \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_exptmod</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_exptmod</span>.<span class="hl opt">}</span>
The first algorithm which actually performs modular exponentiation is algorithm s<span class="hl kwa">\_mp\_exptmod</span>.  It is a sliding window $k$-ary algorithm 
which uses Barrett reduction to reduce the product modulo $p$.  The second algorithm mp<span class="hl kwa">\_exptmod\_fast</span> performs the same operation 
except it uses either Montgomery or Diminished Radix reduction.  The two latter reduction algorithms are clumped in the same exponentiation
algorithm since their arguments are essentially the same (<span class="hl kwa">\textit</span><span class="hl opt">{</span>two mp<span class="hl kwa">\_ints</span> and one mp<span class="hl kwa">\_digit</span><span class="hl opt">}</span>).  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_exptmod</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

In order to keep the algorithms in a known state the first step on line <span class="hl num">29</span> is to reject any negative modulus as input.  If the exponent is
negative the algorithm tries to perform a modular exponentiation with the modular inverse of the base $G$.  The temporary variable $tmpG$ is assigned
the modular inverse of $G$ and $tmpX$ is assigned the absolute value of $X$.  The algorithm will recuse with these new values with a positive
exponent.

If the exponent is positive the algorithm resumes the exponentiation.  Line <span class="hl num">77</span> determines if the modulus is of the restricted Diminished Radix 
form.  If it is not line <span class="hl num">70</span> attempts to determine if it is of a unrestricted Diminished Radix form.  The integer $dr$ will take on one
of three values.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>enumerate<span class="hl opt">}</span>
<span class="hl kwa">\item</span> $dr = <span class="hl num">0</span>$ means that the modulus is not of either restricted or unrestricted Diminished Radix form.
<span class="hl kwa">\item</span> $dr = <span class="hl num">1</span>$ means that the modulus is of restricted Diminished Radix form.
<span class="hl kwa">\item</span> $dr = <span class="hl num">2</span>$ means that the modulus is of unrestricted Diminished Radix form.
<span class="hl kwa">\end</span><span class="hl opt">{</span>enumerate<span class="hl opt">}</span>

Line <span class="hl num">69</span> determines if the fast modular exponentiation algorithm can be used.  It is allowed if $dr <span class="hl kwa">\ne</span> <span class="hl num">0</span>$ or if the modulus is odd.  Otherwise,
the slower s<span class="hl kwa">\_mp\_exptmod</span> algorithm is used which uses Barrett reduction.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Barrett Modular Exponentiation<span class="hl opt">}</span>

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>s<span class="hl kwa">\_mp\_exptmod</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$, $b$ and $c$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $y <span class="hl kwa">\equiv</span> g^x <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $k <span class="hl kwa">\leftarrow</span> lg(x)$ \\
<span class="hl num">2</span>.  $winsize <span class="hl kwa">\leftarrow  \left \lbrace \begin</span><span class="hl opt">{</span>array<span class="hl opt">}{</span>ll<span class="hl opt">}</span>
                              <span class="hl num">2</span> &amp;  <span class="hl kwa">\mbox</span><span class="hl opt">{</span>if <span class="hl opt">}</span>k <span class="hl kwa">\le</span> <span class="hl num">7</span> \\
                              <span class="hl num">3</span> &amp;  <span class="hl kwa">\mbox</span><span class="hl opt">{</span>if <span class="hl opt">}</span><span class="hl num">7</span> &lt; k <span class="hl kwa">\le</span> <span class="hl num">36</span> \\
                              <span class="hl num">4</span> &amp;  <span class="hl kwa">\mbox</span><span class="hl opt">{</span>if <span class="hl opt">}</span><span class="hl num">36</span> &lt; k <span class="hl kwa">\le</span> <span class="hl num">140</span> \\
                              <span class="hl num">5</span> &amp;  <span class="hl kwa">\mbox</span><span class="hl opt">{</span>if <span class="hl opt">}</span><span class="hl num">140</span> &lt; k <span class="hl kwa">\le</span> <span class="hl num">450</span> \\
                              <span class="hl num">6</span> &amp;  <span class="hl kwa">\mbox</span><span class="hl opt">{</span>if <span class="hl opt">}</span><span class="hl num">450</span> &lt; k <span class="hl kwa">\le</span> <span class="hl num">1303</span> \\
                              <span class="hl num">7</span> &amp;  <span class="hl kwa">\mbox</span><span class="hl opt">{</span>if <span class="hl opt">}</span><span class="hl num">1303</span> &lt; k <span class="hl kwa">\le</span> <span class="hl num">3529</span> \\
                              <span class="hl num">8</span> &amp;  <span class="hl kwa">\mbox</span><span class="hl opt">{</span>if <span class="hl opt">}</span><span class="hl num">3529</span> &lt; k \\
                              <span class="hl kwa">\end</span><span class="hl opt">{</span>array<span class="hl opt">}</span> <span class="hl kwa">\right</span> .$ \\
<span class="hl num">3</span>.  Initialize $<span class="hl num">2</span>^<span class="hl opt">{</span>winsize<span class="hl opt">}</span>$ mp<span class="hl kwa">\_ints</span> in an array named $M$ and one mp<span class="hl kwa">\_int</span> named $<span class="hl kwa">\mu</span>$ \\
<span class="hl num">4</span>.  Calculate the $<span class="hl kwa">\mu</span>$ required for Barrett Reduction (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_reduce\_setup</span><span class="hl opt">}</span>). \\
<span class="hl num">5</span>.  $M_1 <span class="hl kwa">\leftarrow</span> g <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
\\
Setup the table of small powers of $g$.  First find $g^<span class="hl opt">{</span><span class="hl num">2</span>^<span class="hl opt">{</span>winsize<span class="hl opt">}}</span>$ and then all multiples of it. \\
<span class="hl num">6</span>.  $k <span class="hl kwa">\leftarrow</span> <span class="hl num">2</span>^<span class="hl opt">{</span>winsize - <span class="hl num">1</span><span class="hl opt">}</span>$ \\
<span class="hl num">7</span>.  $M_<span class="hl opt">{</span>k<span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> M_1$ \\
<span class="hl num">8</span>.  for $ix$ from <span class="hl num">0</span> to $winsize - <span class="hl num">2</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">8.1</span>  $M_k <span class="hl kwa">\leftarrow \left</span> ( M_k <span class="hl kwa">\right</span> )^<span class="hl num">2</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_sqr</span><span class="hl opt">}</span>)  \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">8.2</span>  $M_k <span class="hl kwa">\leftarrow</span> M_k <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_reduce</span><span class="hl opt">}</span>) \\
<span class="hl num">9</span>.  for $ix$ from $<span class="hl num">2</span>^<span class="hl opt">{</span>winsize - <span class="hl num">1</span><span class="hl opt">}</span> + <span class="hl num">1</span>$ to $<span class="hl num">2</span>^<span class="hl opt">{</span>winsize<span class="hl opt">}</span> - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">9.1</span>  $M_<span class="hl opt">{</span>ix<span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> M_<span class="hl opt">{</span>ix - <span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\cdot</span> M_<span class="hl opt">{</span><span class="hl num">1</span><span class="hl opt">}</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_mul</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">9.2</span>  $M_<span class="hl opt">{</span>ix<span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> M_<span class="hl opt">{</span>ix<span class="hl opt">}</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_reduce</span><span class="hl opt">}</span>) \\
<span class="hl num">10</span>.  $res <span class="hl kwa">\leftarrow</span> <span class="hl num">1</span>$ \\
\\
Start Sliding Window. \\
<span class="hl num">11</span>.  $mode <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>, bitcnt <span class="hl kwa">\leftarrow</span> <span class="hl num">1</span>, buf <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>, digidx <span class="hl kwa">\leftarrow</span> x.used - <span class="hl num">1</span>, bitcpy <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>, bitbuf <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">12</span>.  Loop \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">12.1</span>  $bitcnt <span class="hl kwa">\leftarrow</span> bitcnt - <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">12.2</span>  If $bitcnt = <span class="hl num">0</span>$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">12.2.1</span>  If $digidx = -<span class="hl num">1</span>$ goto step <span class="hl num">13</span>. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">12.2.2</span>  $buf <span class="hl kwa">\leftarrow</span> x_<span class="hl opt">{</span>digidx<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">12.2.3</span>  $digidx <span class="hl kwa">\leftarrow</span> digidx - <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">12.2.4</span>  $bitcnt <span class="hl kwa">\leftarrow</span> lg(<span class="hl kwa">\beta</span>)$ \\
Continued on next page. \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm s<span class="hl kwa">\_mp\_exptmod</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>s<span class="hl kwa">\_mp\_exptmod</span><span class="hl opt">}</span> (<span class="hl kwa">\textit</span><span class="hl opt">{</span>continued<span class="hl opt">}</span>). \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$, $b$ and $c$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $y <span class="hl kwa">\equiv</span> g^x <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">12.3</span>  $y <span class="hl kwa">\leftarrow</span> (buf &gt;&gt; (lg(<span class="hl kwa">\beta</span>) - <span class="hl num">1</span>))$ AND $<span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">12.4</span>  $buf <span class="hl kwa">\leftarrow</span> buf &lt;&lt; <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">12.5</span>  if $mode = <span class="hl num">0</span>$ and $y = <span class="hl num">0</span>$ then goto step <span class="hl num">12</span>. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">12.6</span>  if $mode = <span class="hl num">1</span>$ and $y = <span class="hl num">0</span>$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">12.6.1</span>  $res <span class="hl kwa">\leftarrow</span> res^<span class="hl num">2</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">12.6.2</span>  $res <span class="hl kwa">\leftarrow</span> res <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">12.6.3</span>  Goto step <span class="hl num">12</span>. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">12.7</span>  $bitcpy <span class="hl kwa">\leftarrow</span> bitcpy + <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">12.8</span>  $bitbuf <span class="hl kwa">\leftarrow</span> bitbuf + (y &lt;&lt; (winsize - bitcpy))$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">12.9</span>  $mode <span class="hl kwa">\leftarrow</span> <span class="hl num">2</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">12.10</span>  If $bitcpy = winsize$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span>Window is full so perform the squarings and single multiplication. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">12.10.1</span>  for $ix$ from $<span class="hl num">0</span>$ to $winsize -<span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">9</span>mm<span class="hl opt">}</span><span class="hl num">12.10.1.1</span>  $res <span class="hl kwa">\leftarrow</span> res^<span class="hl num">2</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">9</span>mm<span class="hl opt">}</span><span class="hl num">12.10.1.2</span>  $res <span class="hl kwa">\leftarrow</span> res <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">12.10.2</span>  $res <span class="hl kwa">\leftarrow</span> res <span class="hl kwa">\cdot</span> M_<span class="hl opt">{</span>bitbuf<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">12.10.3</span>  $res <span class="hl kwa">\leftarrow</span> res <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span>Reset the window. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">12.10.4</span>  $bitcpy <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>, bitbuf <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>, mode <span class="hl kwa">\leftarrow</span> <span class="hl num">1</span>$ \\
\\
No more windows left.  Check for residual bits of exponent. \\
<span class="hl num">13</span>.  If $mode = <span class="hl num">2</span>$ and $bitcpy &gt; <span class="hl num">0</span>$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">13.1</span>  for $ix$ form $<span class="hl num">0</span>$ to $bitcpy - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">13.1.1</span>  $res <span class="hl kwa">\leftarrow</span> res^<span class="hl num">2</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">13.1.2</span>  $res <span class="hl kwa">\leftarrow</span> res <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">13.1.3</span>  $bitbuf <span class="hl kwa">\leftarrow</span> bitbuf &lt;&lt; <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">13.1.4</span>  If $bitbuf$ AND $<span class="hl num">2</span>^<span class="hl opt">{</span>winsize<span class="hl opt">}</span> <span class="hl kwa">\ne</span> <span class="hl num">0</span>$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">9</span>mm<span class="hl opt">}</span><span class="hl num">13.1.4.1</span>  $res <span class="hl kwa">\leftarrow</span> res <span class="hl kwa">\cdot</span> M_<span class="hl opt">{</span><span class="hl num">1</span><span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">9</span>mm<span class="hl opt">}</span><span class="hl num">13.1.4.2</span>  $res <span class="hl kwa">\leftarrow</span> res <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl num">14</span>.  $y <span class="hl kwa">\leftarrow</span> res$ \\
<span class="hl num">15</span>.  Clear $res$, $mu$ and the $M$ array. \\
<span class="hl num">16</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm s<span class="hl kwa">\_mp\_exptmod</span> (continued)<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm s<span class="hl kwa">\_mp\_exptmod</span>.<span class="hl opt">}</span>
This algorithm computes the $x$'th power of $g$ modulo $p$ and stores the result in $y$.  It takes advantage of the Barrett reduction
algorithm to keep the product small throughout the algorithm.

The first two steps determine the optimal window size based on the number of bits in the exponent.  The larger the exponent the 
larger the window size becomes.  After a window size $winsize$ has been chosen an array of $<span class="hl num">2</span>^<span class="hl opt">{</span>winsize<span class="hl opt">}</span>$ mp<span class="hl kwa">\_int</span> variables is allocated.  This
table will hold the values of $g^x <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ for $<span class="hl num">2</span>^<span class="hl opt">{</span>winsize - <span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\le</span> x &lt; <span class="hl num">2</span>^<span class="hl opt">{</span>winsize<span class="hl opt">}</span>$.  

After the table is allocated the first power of $g$ is found.  Since $g <span class="hl kwa">\ge</span> p$ is allowed it must be first reduced modulo $p$ to make
the rest of the algorithm more efficient.  The first element of the table at $<span class="hl num">2</span>^<span class="hl opt">{</span>winsize - <span class="hl num">1</span><span class="hl opt">}</span>$ is found by squaring $M_1$ successively $winsize - <span class="hl num">2</span>$
times.  The rest of the table elements are found by multiplying the previous element by $M_1$ modulo $p$.

Now that the table is available the sliding window may begin.  The following list describes the functions of all the variables in the window.
<span class="hl kwa">\begin</span><span class="hl opt">{</span>enumerate<span class="hl opt">}</span>
<span class="hl kwa">\item</span> The variable $mode$ dictates how the bits of the exponent are interpreted.  
<span class="hl kwa">\begin</span><span class="hl opt">{</span>enumerate<span class="hl opt">}</span>
   <span class="hl kwa">\item</span> When $mode = <span class="hl num">0</span>$ the bits are ignored since no non-zero bit of the exponent has been seen yet.  For example, if the exponent were simply 
         $<span class="hl num">1</span>$ then there would be $lg(<span class="hl kwa">\beta</span>) - <span class="hl num">1</span>$ zero bits before the first non-zero bit.  In this case bits are ignored until a non-zero bit is found.  
   <span class="hl kwa">\item</span> When $mode = <span class="hl num">1</span>$ a non-zero bit has been seen before and a new $winsize$-bit window has not been formed yet.  In this mode leading $<span class="hl num">0</span>$ bits 
         are read and a single squaring is performed.  If a non-zero bit is read a new window is created.  
   <span class="hl kwa">\item</span> When $mode = <span class="hl num">2</span>$ the algorithm is in the middle of forming a window and new bits are appended to the window from the most significant bit
         downwards.
<span class="hl kwa">\end</span><span class="hl opt">{</span>enumerate<span class="hl opt">}</span>
<span class="hl kwa">\item</span> The variable $bitcnt$ indicates how many bits are left in the current digit of the exponent left to be read.  When it reaches zero a new digit
      is fetched from the exponent.
<span class="hl kwa">\item</span> The variable $buf$ holds the currently read digit of the exponent. 
<span class="hl kwa">\item</span> The variable $digidx$ is an index into the exponents digits.  It starts at the leading digit $x.used - <span class="hl num">1</span>$ and moves towards the trailing digit.
<span class="hl kwa">\item</span> The variable $bitcpy$ indicates how many bits are in the currently formed window.  When it reaches $winsize$ the window is flushed and
      the appropriate operations performed.
<span class="hl kwa">\item</span> The variable $bitbuf$ holds the current bits of the window being formed.  
<span class="hl kwa">\end</span><span class="hl opt">{</span>enumerate<span class="hl opt">}</span>

All of step <span class="hl num">12</span> is the window processing loop.  It will iterate while there are digits available form the exponent to read.  The first step
inside this loop is to extract a new digit if no more bits are available in the current digit.  If there are no bits left a new digit is
read and if there are no digits left than the loop terminates.  

After a digit is made available step <span class="hl num">12.3</span> will extract the most significant bit of the current digit and move all other bits in the digit
upwards.  In effect the digit is read from most significant bit to least significant bit and since the digits are read from leading to 
trailing edges the entire exponent is read from most significant bit to least significant bit.

At step <span class="hl num">12.5</span> if the $mode$ and currently extracted bit $y$ are both zero the bit is ignored and the next bit is read.  This prevents the 
algorithm from having to perform trivial squaring and reduction operations before the first non-zero bit is read.  Step <span class="hl num">12.6</span> and <span class="hl num">12.7</span>-<span class="hl num">10</span> handle
the two cases of $mode = <span class="hl num">1</span>$ and $mode = <span class="hl num">2</span>$ respectively.  

<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\includegraphics</span><span class="hl opt">{</span>pics/expt_state.ps<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Sliding Window State Diagram<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>pic:expt_state<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>

By step <span class="hl num">13</span> there are no more digits left in the exponent.  However, there may be partial bits in the window left.  If $mode = <span class="hl num">2</span>$ then 
a Left-to-Right algorithm is used to process the remaining few bits.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_s\_mp\_exptmod</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

Lines <span class="hl num">32</span> through <span class="hl num">46</span> determine the optimal window size based on the length of the exponent in bits.  The window divisions are sorted
from smallest to greatest so that in each <span class="hl kwa">\textbf</span><span class="hl opt">{</span>if<span class="hl opt">}</span> statement only one condition must be tested.  For example, by the <span class="hl kwa">\textbf</span><span class="hl opt">{</span>if<span class="hl opt">}</span> statement 
on line <span class="hl num">38</span> the value of $x$ is already known to be greater than $<span class="hl num">140</span>$.  

The conditional piece of code beginning on line <span class="hl num">48</span> allows the window size to be restricted to five bits.  This logic is used to ensure
the table of precomputed powers of $G$ remains relatively small.  

The for loop on line <span class="hl num">61</span> initializes the $M$ array while lines <span class="hl num">72</span> and <span class="hl num">77</span> through <span class="hl num">86</span> initialize the reduction
function that will be used for this modulus.

-- More later.

<span class="hl kwa">\section</span><span class="hl opt">{</span>Quick Power of Two<span class="hl opt">}</span>
Calculating $b = <span class="hl num">2</span>^a$ can be performed much quicker than with any of the previous algorithms.  Recall that a logical shift left $m &lt;&lt; k$ is
equivalent to $m <span class="hl kwa">\cdot</span> <span class="hl num">2</span>^k$.  By this logic when $m = <span class="hl num">1</span>$ a quick power of two can be achieved.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_2expt</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   integer $b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $a <span class="hl kwa">\leftarrow</span> <span class="hl num">2</span>^b$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $a <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">2</span>.  If $a.alloc &lt; <span class="hl kwa">\lfloor</span> b / lg(<span class="hl kwa">\beta</span>) <span class="hl kwa">\rfloor</span> + <span class="hl num">1</span>$ then grow $a$ appropriately. \\
<span class="hl num">3</span>.  $a.used <span class="hl kwa">\leftarrow \lfloor</span> b / lg(<span class="hl kwa">\beta</span>) <span class="hl kwa">\rfloor</span> + <span class="hl num">1</span>$ \\
<span class="hl num">4</span>.  $a_<span class="hl opt">{</span><span class="hl kwa">\lfloor</span> b / lg(<span class="hl kwa">\beta</span>) <span class="hl kwa">\rfloor</span><span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> <span class="hl num">1</span> &lt;&lt; (b <span class="hl kwa">\mbox</span><span class="hl opt">{</span> mod <span class="hl opt">}</span> lg(<span class="hl kwa">\beta</span>))$ \\
<span class="hl num">5</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_2expt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_2expt</span>.<span class="hl opt">}</span>

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_2expt</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

<span class="hl kwa">\chapter</span><span class="hl opt">{</span>Higher Level Algorithms<span class="hl opt">}</span>

This chapter discusses the various higher level algorithms that are required to complete a well rounded multiple precision integer package.  These
routines are less performance oriented than the algorithms of chapters five, six and seven but are no less important.  

The first section describes a method of integer division with remainder that is universally well known.  It provides the signed division logic
for the package.  The subsequent section discusses a set of algorithms which allow a single digit to be the <span class="hl num">2</span>nd operand for a variety of operations.  
These algorithms serve mostly to simplify other algorithms where small constants are required.  The last two sections discuss how to manipulate 
various representations of integers.  For example, converting from an mp<span class="hl kwa">\_int</span> to a string of character.

<span class="hl kwa">\section</span><span class="hl opt">{</span>Integer Division with Remainder<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>sec:division<span class="hl opt">}</span>

Integer division aside from modular exponentiation is the most intensive algorithm to compute.  Like addition, subtraction and multiplication
the basis of this algorithm is the long-hand division algorithm taught to school children.  Throughout this discussion several common variables
will be used.  Let $x$ represent the divisor and $y$ represent the dividend.  Let $q$ represent the integer quotient $<span class="hl kwa">\lfloor</span> y / x <span class="hl kwa">\rfloor</span>$ and 
let $r$ represent the remainder $r = y - x <span class="hl kwa">\lfloor</span> y / x <span class="hl kwa">\rfloor</span>$.  The following simple algorithm will be used to start the discussion.

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Radix-$<span class="hl kwa">\beta</span>$ Integer Division<span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   integer $x$ and $y$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $q = <span class="hl kwa">\lfloor</span> y/x<span class="hl kwa">\rfloor</span>, r = y - xq$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $q <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">2</span>.  $n <span class="hl kwa">\leftarrow \vert \vert</span> y <span class="hl kwa">\vert \vert</span> - <span class="hl kwa">\vert \vert</span> x <span class="hl kwa">\vert \vert</span>$ \\
<span class="hl num">3</span>.  for $t$ from $n$ down to $<span class="hl num">0</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">3.1</span>  Maximize $k$ such that $kx<span class="hl kwa">\beta</span>^t$ is less than or equal to $y$ and $(k + <span class="hl num">1</span>)x<span class="hl kwa">\beta</span>^t$ is greater. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">3.2</span>  $q <span class="hl kwa">\leftarrow</span> q + k<span class="hl kwa">\beta</span>^t$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">3.3</span>  $y <span class="hl kwa">\leftarrow</span> y - kx<span class="hl kwa">\beta</span>^t$ \\
<span class="hl num">4</span>.  $r <span class="hl kwa">\leftarrow</span> y$ \\
<span class="hl num">5</span>.  Return($q, r$) \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm Radix-$<span class="hl kwa">\beta</span>$ Integer Division<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>fig:raddiv<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

As children we are taught this very simple algorithm for the case of $<span class="hl kwa">\beta</span> = <span class="hl num">10</span>$.  Almost instinctively several optimizations are taught for which
their reason of existing are never explained.  For this example let $y = <span class="hl num">5471</span>$ represent the dividend and $x = <span class="hl num">23</span>$ represent the divisor.

To find the first digit of the quotient the value of $k$ must be maximized such that $kx<span class="hl kwa">\beta</span>^t$ is less than or equal to $y$ and 
simultaneously $(k + <span class="hl num">1</span>)x<span class="hl kwa">\beta</span>^t$ is greater than $y$.  Implicitly $k$ is the maximum value the $t$'th digit of the quotient may have.  The habitual method
used to find the maximum is to ``eyeball'' the two numbers, typically only the leading digits and quickly estimate a quotient.  By only using leading
digits a much simpler division may be used to form an educated guess at what the value must be.  In this case $k = <span class="hl kwa">\lfloor</span> <span class="hl num">54</span>/<span class="hl num">23</span><span class="hl kwa">\rfloor</span> = <span class="hl num">2</span>$ quickly 
arises as a possible  solution.  Indeed $<span class="hl num">2</span>x<span class="hl kwa">\beta</span>^<span class="hl num">2</span> = <span class="hl num">4600</span>$ is less than $y = <span class="hl num">5471</span>$ and simultaneously $(k + <span class="hl num">1</span>)x<span class="hl kwa">\beta</span>^<span class="hl num">2</span> = <span class="hl num">6900</span>$ is larger than $y$.  
As a  result $k<span class="hl kwa">\beta</span>^<span class="hl num">2</span>$ is added to the quotient which now equals $q = <span class="hl num">200</span>$ and $<span class="hl num">4600</span>$ is subtracted from $y$ to give a remainder of $y = <span class="hl num">841</span>$.

Again this process is repeated to produce the quotient digit $k = <span class="hl num">3</span>$ which makes the quotient $q = <span class="hl num">200</span> + <span class="hl num">3</span><span class="hl kwa">\beta</span> = <span class="hl num">230</span>$ and the remainder 
$y = <span class="hl num">841</span> - <span class="hl num">3</span>x<span class="hl kwa">\beta</span> = <span class="hl num">181</span>$.  Finally the last iteration of the loop produces $k = <span class="hl num">7</span>$ which leads to the quotient $q = <span class="hl num">230</span> + <span class="hl num">7</span> = <span class="hl num">237</span>$ and the
remainder $y = <span class="hl num">181</span> - <span class="hl num">7</span>x = <span class="hl num">20</span>$.  The final quotient and remainder found are $q = <span class="hl num">237</span>$ and $r = y = <span class="hl num">20</span>$ which are indeed correct since 
$<span class="hl num">237</span> <span class="hl kwa">\cdot</span> <span class="hl num">23</span> + <span class="hl num">20</span> = <span class="hl num">5471</span>$ is true.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Quotient Estimation<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>sec:divest<span class="hl opt">}</span>
As alluded to earlier the quotient digit $k$ can be estimated from only the leading digits of both the divisor and dividend.  When $p$ leading
digits are used from both the divisor and dividend to form an estimation the accuracy of the estimation rises as $p$ grows.  Technically
speaking the estimation is based on assuming the lower $<span class="hl kwa">\vert \vert</span> y <span class="hl kwa">\vert \vert</span> - p$ and $<span class="hl kwa">\vert \vert</span> x <span class="hl kwa">\vert \vert</span> - p$ lower digits of the
dividend and divisor are zero.  

The value of the estimation may off by a few values in either direction and in general is fairly correct.  A simplification <span class="hl kwa">\cite</span><span class="hl opt">[</span>pp. <span class="hl num">271</span><span class="hl opt">]{</span>TAOCPV2<span class="hl opt">}</span>
of the estimation technique is to use $t + <span class="hl num">1</span>$ digits of the dividend and $t$ digits of the divisor, in particularly when $t = <span class="hl num">1</span>$.  The estimate 
using this technique is never too small.  For the following proof let $t = <span class="hl kwa">\vert \vert</span> y <span class="hl kwa">\vert \vert</span> - <span class="hl num">1</span>$ and $s = <span class="hl kwa">\vert \vert</span> x <span class="hl kwa">\vert \vert</span> - <span class="hl num">1</span>$ 
represent the most significant digits of the dividend and divisor respectively.

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Proof.<span class="hl opt">}</span><span class="hl kwa">\textit</span><span class="hl opt">{</span>  The quotient $<span class="hl kwa">\hat</span> k = <span class="hl kwa">\lfloor</span> (y_t<span class="hl kwa">\beta</span> + y_<span class="hl opt">{</span>t-<span class="hl num">1</span><span class="hl opt">}</span>) / x_s <span class="hl kwa">\rfloor</span>$ is greater than or equal to 
$k = <span class="hl kwa">\lfloor</span> y / (x <span class="hl kwa">\cdot \beta</span>^<span class="hl opt">{</span><span class="hl kwa">\vert \vert</span> y <span class="hl kwa">\vert \vert</span> - <span class="hl kwa">\vert \vert</span> x <span class="hl kwa">\vert \vert</span> - <span class="hl num">1</span><span class="hl opt">}</span>) <span class="hl kwa">\rfloor</span>$. <span class="hl opt">}</span>
The first obvious case is when $<span class="hl kwa">\hat</span> k = <span class="hl kwa">\beta</span> - <span class="hl num">1</span>$ in which case the proof is concluded since the real quotient cannot be larger.  For all other 
cases $<span class="hl kwa">\hat</span> k = <span class="hl kwa">\lfloor</span> (y_t<span class="hl kwa">\beta</span> + y_<span class="hl opt">{</span>t-<span class="hl num">1</span><span class="hl opt">}</span>) / x_s <span class="hl kwa">\rfloor</span>$ and $<span class="hl kwa">\hat</span> k x_s <span class="hl kwa">\ge</span> y_t<span class="hl kwa">\beta</span> + y_<span class="hl opt">{</span>t-<span class="hl num">1</span><span class="hl opt">}</span> - x_s + <span class="hl num">1</span>$.  The latter portion of the inequalility
$-x_s + <span class="hl num">1</span>$ arises from the fact that a truncated integer division will give the same quotient for at most $x_s - <span class="hl num">1</span>$ values.  Next a series of 
inequalities will prove the hypothesis.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
y - <span class="hl kwa">\hat</span> k x <span class="hl kwa">\le</span> y - <span class="hl kwa">\hat</span> k x_s<span class="hl kwa">\beta</span>^s
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

This is trivially true since $x <span class="hl kwa">\ge</span> x_s<span class="hl kwa">\beta</span>^s$.  Next we replace $<span class="hl kwa">\hat</span> kx_s<span class="hl kwa">\beta</span>^s$ by the previous inequality for $<span class="hl kwa">\hat</span> kx_s$.  

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
y - <span class="hl kwa">\hat</span> k x <span class="hl kwa">\le</span> y_t<span class="hl kwa">\beta</span>^t + <span class="hl kwa">\ldots</span> + y_0 - (y_t<span class="hl kwa">\beta</span>^t + y_<span class="hl opt">{</span>t-<span class="hl num">1</span><span class="hl opt">}</span><span class="hl kwa">\beta</span>^<span class="hl opt">{</span>t-<span class="hl num">1</span><span class="hl opt">}</span> - x_s<span class="hl kwa">\beta</span>^t + <span class="hl kwa">\beta</span>^s)
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

By simplifying the previous inequality the following inequality is formed.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
y - <span class="hl kwa">\hat</span> k x <span class="hl kwa">\le</span> y_<span class="hl opt">{</span>t-<span class="hl num">2</span><span class="hl opt">}</span><span class="hl kwa">\beta</span>^<span class="hl opt">{</span>t-<span class="hl num">2</span><span class="hl opt">}</span> + <span class="hl kwa">\ldots</span> + y_0 + x_s<span class="hl kwa">\beta</span>^s - <span class="hl kwa">\beta</span>^s
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

Subsequently,

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
y_<span class="hl opt">{</span>t-<span class="hl num">2</span><span class="hl opt">}</span><span class="hl kwa">\beta</span>^<span class="hl opt">{</span>t-<span class="hl num">2</span><span class="hl opt">}</span> + <span class="hl kwa">\ldots</span> +  y_0  + x_s<span class="hl kwa">\beta</span>^s - <span class="hl kwa">\beta</span>^s &lt; x_s<span class="hl kwa">\beta</span>^s <span class="hl kwa">\le</span> x
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

Which proves that $y - <span class="hl kwa">\hat</span> kx <span class="hl kwa">\le</span> x$ and by consequence $<span class="hl kwa">\hat</span> k <span class="hl kwa">\ge</span> k$ which concludes the proof.  <span class="hl kwa">\textbf</span><span class="hl opt">{</span>QED<span class="hl opt">}</span>


<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Normalized Integers<span class="hl opt">}</span>
For the purposes of division a normalized input is when the divisors leading digit $x_n$ is greater than or equal to $<span class="hl kwa">\beta</span> / <span class="hl num">2</span>$.  By multiplying both
$x$ and $y$ by $j = <span class="hl kwa">\lfloor</span> (<span class="hl kwa">\beta</span> / <span class="hl num">2</span>) / x_n <span class="hl kwa">\rfloor</span>$ the quotient remains unchanged and the remainder is simply $j$ times the original
remainder.  The purpose of normalization is to ensure the leading digit of the divisor is sufficiently large such that the estimated quotient will
lie in the domain of a single digit.  Consider the maximum dividend $(<span class="hl kwa">\beta</span> - <span class="hl num">1</span>) <span class="hl kwa">\cdot \beta</span> + (<span class="hl kwa">\beta</span> - <span class="hl num">1</span>)$ and the minimum divisor $<span class="hl kwa">\beta</span> / <span class="hl num">2</span>$.  

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span> 
<span class="hl opt">{{</span><span class="hl kwa">\beta</span>^<span class="hl num">2</span> - <span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\over</span> <span class="hl opt">{</span> <span class="hl kwa">\beta</span> / <span class="hl num">2</span><span class="hl opt">}}</span> <span class="hl kwa">\le</span> <span class="hl num">2</span><span class="hl kwa">\beta</span> - <span class="hl opt">{</span><span class="hl num">2</span> <span class="hl kwa">\over \beta</span><span class="hl opt">}</span> 
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

At most the quotient approaches $<span class="hl num">2</span><span class="hl kwa">\beta</span>$, however, in practice this will not occur since that would imply the previous quotient digit was too small.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Radix-$<span class="hl kwa">\beta</span>$ Division with Remainder<span class="hl opt">}</span>
<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_div</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a, b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $c = <span class="hl kwa">\lfloor</span> a/b <span class="hl kwa">\rfloor</span>$, $d = a - bc$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  If $b = <span class="hl num">0</span>$ return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_VAL</span><span class="hl opt">}</span>). \\
<span class="hl num">2</span>.  If $<span class="hl kwa">\vert</span> a <span class="hl kwa">\vert</span> &lt; <span class="hl kwa">\vert</span> b <span class="hl kwa">\vert</span>$ then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  $d <span class="hl kwa">\leftarrow</span> a$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.2</span>  $c <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.3</span>  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
\\
Setup the quotient to receive the digits. \\
<span class="hl num">3</span>.  Grow $q$ to $a.used + <span class="hl num">2</span>$ digits. \\
<span class="hl num">4</span>.  $q <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">5</span>.  $x <span class="hl kwa">\leftarrow \vert</span> a <span class="hl kwa">\vert</span> , y <span class="hl kwa">\leftarrow \vert</span> b <span class="hl kwa">\vert</span>$ \\
<span class="hl num">6</span>.  $sign <span class="hl kwa">\leftarrow  \left \lbrace \begin</span><span class="hl opt">{</span>array<span class="hl opt">}{</span>ll<span class="hl opt">}</span>
                              MP<span class="hl kwa">\_ZPOS</span> &amp;  <span class="hl kwa">\mbox</span><span class="hl opt">{</span>if <span class="hl opt">}</span>a.sign = b.sign \\
                              MP<span class="hl kwa">\_NEG</span>  &amp;  <span class="hl kwa">\mbox</span><span class="hl opt">{</span>otherwise<span class="hl opt">}</span> \\
                              <span class="hl kwa">\end</span><span class="hl opt">{</span>array<span class="hl opt">}</span> <span class="hl kwa">\right</span> .$ \\
\\
Normalize the inputs such that the leading digit of $y$ is greater than or equal to $<span class="hl kwa">\beta</span> / <span class="hl num">2</span>$. \\
<span class="hl num">7</span>.  $norm <span class="hl kwa">\leftarrow</span> (lg(<span class="hl kwa">\beta</span>) - <span class="hl num">1</span>) - (<span class="hl kwa">\lceil</span> lg(y) <span class="hl kwa">\rceil \mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>lg(<span class="hl kwa">\beta</span>)<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>)$ \\
<span class="hl num">8</span>.  $x <span class="hl kwa">\leftarrow</span> x <span class="hl kwa">\cdot</span> <span class="hl num">2</span>^<span class="hl opt">{</span>norm<span class="hl opt">}</span>, y <span class="hl kwa">\leftarrow</span> y <span class="hl kwa">\cdot</span> <span class="hl num">2</span>^<span class="hl opt">{</span>norm<span class="hl opt">}</span>$ \\
\\
Find the leading digit of the quotient. \\
<span class="hl num">9</span>.  $n <span class="hl kwa">\leftarrow</span> x.used - <span class="hl num">1</span>, t <span class="hl kwa">\leftarrow</span> y.used - <span class="hl num">1</span>$ \\
<span class="hl num">10</span>.  $y <span class="hl kwa">\leftarrow</span> y <span class="hl kwa">\cdot \beta</span>^<span class="hl opt">{</span>n - t<span class="hl opt">}</span>$ \\
<span class="hl num">11</span>.  While ($x <span class="hl kwa">\ge</span> y$) do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">11.1</span>  $q_<span class="hl opt">{</span>n - t<span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> q_<span class="hl opt">{</span>n - t<span class="hl opt">}</span> + <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">11.2</span>  $x <span class="hl kwa">\leftarrow</span> x - y$ \\
<span class="hl num">12</span>.  $y <span class="hl kwa">\leftarrow \lfloor</span> y / <span class="hl kwa">\beta</span>^<span class="hl opt">{</span>n-t<span class="hl opt">}</span> <span class="hl kwa">\rfloor</span>$ \\
\\
Continued on the next page. \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_div</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_div</span><span class="hl opt">}</span> (continued). \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a, b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $c = <span class="hl kwa">\lfloor</span> a/b <span class="hl kwa">\rfloor</span>$, $d = a - bc$ \\
<span class="hl kwa">\hline</span> \\
Now find the remainder fo the digits. \\
<span class="hl num">13</span>.  for $i$ from $n$ down to $(t + <span class="hl num">1</span>)$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">13.1</span>  If $i &gt; x.used$ then jump to the next iteration of this loop. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">13.2</span>  If $x_<span class="hl opt">{</span>i<span class="hl opt">}</span> = y_<span class="hl opt">{</span>t<span class="hl opt">}</span>$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">13.2.1</span>  $q_<span class="hl opt">{</span>i - t - <span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\leftarrow \beta</span> - <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">13.3</span>  else \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">13.3.1</span>  $<span class="hl kwa">\hat</span> r <span class="hl kwa">\leftarrow</span> x_<span class="hl opt">{</span>i<span class="hl opt">}</span> <span class="hl kwa">\cdot \beta</span> + x_<span class="hl opt">{</span>i - <span class="hl num">1</span><span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">13.3.2</span>  $<span class="hl kwa">\hat</span> r <span class="hl kwa">\leftarrow \lfloor \hat</span> r / y_<span class="hl opt">{</span>t<span class="hl opt">}</span> <span class="hl kwa">\rfloor</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">13.3.3</span>  $q_<span class="hl opt">{</span>i - t - <span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\leftarrow \hat</span> r$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">13.4</span>  $q_<span class="hl opt">{</span>i - t - <span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> q_<span class="hl opt">{</span>i - t - <span class="hl num">1</span><span class="hl opt">}</span> + <span class="hl num">1</span>$ \\
\\
Fixup quotient estimation. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">13.5</span>  Loop \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">13.5.1</span>  $q_<span class="hl opt">{</span>i - t - <span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> q_<span class="hl opt">{</span>i - t - <span class="hl num">1</span><span class="hl opt">}</span> - <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">13.5.2</span>  t$<span class="hl num">1</span> <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">13.5.3</span>  t$<span class="hl num">1</span>_0 <span class="hl kwa">\leftarrow</span> y_<span class="hl opt">{</span>t - <span class="hl num">1</span><span class="hl opt">}</span>, $ t$<span class="hl num">1</span>_1 <span class="hl kwa">\leftarrow</span> y_t,$ t$<span class="hl num">1</span>.used <span class="hl kwa">\leftarrow</span> <span class="hl num">2</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">13.5.4</span>  $t1 <span class="hl kwa">\leftarrow</span> t1 <span class="hl kwa">\cdot</span> q_<span class="hl opt">{</span>i - t - <span class="hl num">1</span><span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">13.5.5</span>  t$<span class="hl num">2</span>_0 <span class="hl kwa">\leftarrow</span> x_<span class="hl opt">{</span>i - <span class="hl num">2</span><span class="hl opt">}</span>, $ t$<span class="hl num">2</span>_1 <span class="hl kwa">\leftarrow</span> x_<span class="hl opt">{</span>i - <span class="hl num">1</span><span class="hl opt">}</span>, $ t$<span class="hl num">2</span>_2 <span class="hl kwa">\leftarrow</span> x_i, $ t$<span class="hl num">2</span>.used <span class="hl kwa">\leftarrow</span> <span class="hl num">3</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">13.5.6</span>  If $<span class="hl kwa">\vert</span> t1 <span class="hl kwa">\vert</span> &gt; <span class="hl kwa">\vert</span> t2 <span class="hl kwa">\vert</span>$ then goto step <span class="hl num">13.5</span>. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">13.6</span>  t$<span class="hl num">1</span> <span class="hl kwa">\leftarrow</span> y <span class="hl kwa">\cdot</span> q_<span class="hl opt">{</span>i - t - <span class="hl num">1</span><span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">13.7</span>  t$<span class="hl num">1</span> <span class="hl kwa">\leftarrow</span> $ t$<span class="hl num">1</span> <span class="hl kwa">\cdot \beta</span>^<span class="hl opt">{</span>i - t - <span class="hl num">1</span><span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">13.8</span>  $x <span class="hl kwa">\leftarrow</span> x - $ t$<span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">13.9</span>  If $x.sign = MP<span class="hl kwa">\_NEG</span>$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">13.10</span>  t$<span class="hl num">1</span> <span class="hl kwa">\leftarrow</span> y$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">13.11</span>  t$<span class="hl num">1</span> <span class="hl kwa">\leftarrow</span> $ t$<span class="hl num">1</span> <span class="hl kwa">\cdot \beta</span>^<span class="hl opt">{</span>i - t - <span class="hl num">1</span><span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">13.12</span>  $x <span class="hl kwa">\leftarrow</span> x + $ t$<span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">13.13</span>  $q_<span class="hl opt">{</span>i - t - <span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> q_<span class="hl opt">{</span>i - t - <span class="hl num">1</span><span class="hl opt">}</span> - <span class="hl num">1</span>$ \\
\\
Finalize the result. \\
<span class="hl num">14</span>.  Clamp excess digits of $q$ \\
<span class="hl num">15</span>.  $c <span class="hl kwa">\leftarrow</span> q, c.sign <span class="hl kwa">\leftarrow</span> sign$ \\
<span class="hl num">16</span>.  $x.sign <span class="hl kwa">\leftarrow</span> a.sign$ \\
<span class="hl num">17</span>.  $d <span class="hl kwa">\leftarrow \lfloor</span> x / <span class="hl num">2</span>^<span class="hl opt">{</span>norm<span class="hl opt">}</span> <span class="hl kwa">\rfloor</span>$ \\
<span class="hl num">18</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_div</span> (continued)<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_div</span>.<span class="hl opt">}</span>
This algorithm will calculate quotient and remainder from an integer division given a dividend and divisor.  The algorithm is a signed
division and will produce a fully qualified quotient and remainder.

First the divisor $b$ must be non-zero which is enforced in step one.  If the divisor is larger than the dividend than the quotient is implicitly 
zero and the remainder is the dividend.  

After the first two trivial cases of inputs are handled the variable $q$ is setup to receive the digits of the quotient.  Two unsigned copies of the
divisor $y$ and dividend $x$ are made as well.  The core of the division algorithm is an unsigned division and will only work if the values are
positive.  Now the two values $x$ and $y$ must be normalized such that the leading digit of $y$ is greater than or equal to $<span class="hl kwa">\beta</span> / <span class="hl num">2</span>$.  
This is performed by shifting both to the left by enough bits to get the desired normalization.  

At this point the division algorithm can begin producing digits of the quotient.  Recall that maximum value of the estimation used is 
$<span class="hl num">2</span><span class="hl kwa">\beta</span> - <span class="hl opt">{</span><span class="hl num">2</span> <span class="hl kwa">\over \beta</span><span class="hl opt">}</span>$ which means that a digit of the quotient must be first produced by another means.  In this case $y$ is shifted
to the left (<span class="hl kwa">\textit</span><span class="hl opt">{</span>step ten<span class="hl opt">}</span>) so that it has the same number of digits as $x$.  The loop on step eleven will subtract multiples of the 
shifted copy of $y$ until $x$ is smaller.  Since the leading digit of $y$ is greater than or equal to $<span class="hl kwa">\beta</span>/<span class="hl num">2</span>$ this loop will iterate at most two
times to produce the desired leading digit of the quotient.  

Now the remainder of the digits can be produced.  The equation $<span class="hl kwa">\hat</span> q = <span class="hl kwa">\lfloor</span> <span class="hl opt">{{</span>x_i <span class="hl kwa">\beta</span> + x_<span class="hl opt">{</span>i-<span class="hl num">1</span><span class="hl opt">}}</span><span class="hl kwa">\over</span> y_t<span class="hl opt">}</span> <span class="hl kwa">\rfloor</span>$ is used to fairly
accurately approximate the true quotient digit.  The estimation can in theory produce an estimation as high as $<span class="hl num">2</span><span class="hl kwa">\beta</span> - <span class="hl opt">{</span><span class="hl num">2</span> <span class="hl kwa">\over \beta</span><span class="hl opt">}</span>$ but by
induction the upper quotient digit is correct (<span class="hl kwa">\textit</span><span class="hl opt">{</span>as established on step eleven<span class="hl opt">}</span>) and the estimate must be less than $<span class="hl kwa">\beta</span>$.  

Recall from section~<span class="hl kwa">\ref</span><span class="hl opt">{</span>sec:divest<span class="hl opt">}</span> that the estimation is never too low but may be too high.  The next step of the estimation process is
to refine the estimation.  The loop on step <span class="hl num">13.5</span> uses $x_i<span class="hl kwa">\beta</span>^<span class="hl num">2</span> + x_<span class="hl opt">{</span>i-<span class="hl num">1</span><span class="hl opt">}</span><span class="hl kwa">\beta</span> + x_<span class="hl opt">{</span>i-<span class="hl num">2</span><span class="hl opt">}</span>$ and $q_<span class="hl opt">{</span>i - t - <span class="hl num">1</span><span class="hl opt">}</span>(y_t<span class="hl kwa">\beta</span> + y_<span class="hl opt">{</span>t-<span class="hl num">1</span><span class="hl opt">}</span>)$ as a higher
order approximation to adjust the quotient digit.

After both phases of estimation the quotient digit may still be off by a value of one<span class="hl kwa">\footnote</span><span class="hl opt">{</span>This is similar to the error introduced
by optimizing Barrett reduction.<span class="hl opt">}</span>.  Steps <span class="hl num">13.6</span> and <span class="hl num">13.7</span> subtract the multiple of the divisor from the dividend (<span class="hl kwa">\textit</span><span class="hl opt">{</span>Similar to step <span class="hl num">3.3</span> of
algorithm~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:raddiv<span class="hl opt">}}</span> and then subsequently add a multiple of the divisor if the quotient was too large.  

Now that the quotient has been determine finializing the result is a matter of clamping the quotient, fixing the sizes and de-normalizing the 
remainder.  An important aspect of this algorithm seemingly overlooked in other descriptions such as that of Algorithm <span class="hl num">14.20</span> HAC <span class="hl kwa">\cite</span><span class="hl opt">[</span>pp. <span class="hl num">598</span><span class="hl opt">]{</span>HAC<span class="hl opt">}</span>
is that when the estimations are being made (<span class="hl kwa">\textit</span><span class="hl opt">{</span>inside the loop on step <span class="hl num">13.5</span><span class="hl opt">}</span>) that the digits $y_<span class="hl opt">{</span>t-<span class="hl num">1</span><span class="hl opt">}</span>$, $x_<span class="hl opt">{</span>i-<span class="hl num">2</span><span class="hl opt">}</span>$ and $x_<span class="hl opt">{</span>i-<span class="hl num">1</span><span class="hl opt">}</span>$ may lie 
outside their respective boundaries.  For example, if $t = <span class="hl num">0</span>$ or $i <span class="hl kwa">\le</span> <span class="hl num">1</span>$ then the digits would be undefined.  In those cases the digits should
respectively be replaced with a zero.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_div</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

The implementation of this algorithm differs slightly from the pseudo code presented previously.  In this algorithm either of the quotient $c$ or
remainder $d$ may be passed as a <span class="hl kwa">\textbf</span><span class="hl opt">{</span>NULL<span class="hl opt">}</span> pointer which indicates their value is not desired.  For example, the C code to call the division
algorithm with only the quotient is 

<span class="hl kwa">\begin</span><span class="hl opt">{</span>verbatim<span class="hl opt">}</span>
mp_div(&amp;a, &amp;b, &amp;c, NULL);  /* c = <span class="hl opt">[</span>a/b<span class="hl opt">]</span> */
<span class="hl kwa">\end</span><span class="hl opt">{</span>verbatim<span class="hl opt">}</span>

Lines <span class="hl num">109</span> and <span class="hl num">113</span> handle the two trivial cases of inputs which are division by zero and dividend smaller than the divisor 
respectively.  After the two trivial cases all of the temporary variables are initialized.  Line <span class="hl num">148</span> determines the sign of 
the quotient and line <span class="hl num">148</span> ensures that both $x$ and $y$ are positive.  

The number of bits in the leading digit is calculated on line <span class="hl num">151</span>.  Implictly an mp<span class="hl kwa">\_int</span> with $r$ digits will require $lg(<span class="hl kwa">\beta</span>)(r-<span class="hl num">1</span>) + k$ bits
of precision which when reduced modulo $lg(<span class="hl kwa">\beta</span>)$ produces the value of $k$.  In this case $k$ is the number of bits in the leading digit which is
exactly what is required.  For the algorithm to operate $k$ must equal $lg(<span class="hl kwa">\beta</span>) - <span class="hl num">1</span>$ and when it does not the inputs must be normalized by shifting
them to the left by $lg(<span class="hl kwa">\beta</span>) - <span class="hl num">1</span> - k$ bits.

Throughout the variables $n$ and $t$ will represent the highest digit of $x$ and $y$ respectively.  These are first used to produce the 
leading digit of the quotient.  The loop beginning on line <span class="hl num">184</span> will produce the remainder of the quotient digits.

The conditional ``continue'' on line <span class="hl num">187</span> is used to prevent the algorithm from reading past the leading edge of $x$ which can occur when the
algorithm eliminates multiple non-zero digits in a single iteration.  This ensures that $x_i$ is always non-zero since by definition the digits
above the $i$'th position $x$ must be zero in order for the quotient to be precise<span class="hl kwa">\footnote</span><span class="hl opt">{</span>Precise as far as integer division is concerned.<span class="hl opt">}</span>.  

Lines <span class="hl num">214</span>, <span class="hl num">216</span> and <span class="hl num">223</span> through <span class="hl num">225</span> manually construct the high accuracy estimations by setting the digits of the two mp<span class="hl kwa">\_int</span> 
variables directly.  

<span class="hl kwa">\section</span><span class="hl opt">{</span>Single Digit Helpers<span class="hl opt">}</span>

This section briefly describes a series of single digit helper algorithms which come in handy when working with small constants.  All of 
the helper functions assume the single digit input is positive and will treat them as such.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Single Digit Addition and Subtraction<span class="hl opt">}</span>

Both addition and subtraction are performed by ``cheating'' and using mp<span class="hl kwa">\_set</span> followed by the higher level addition or subtraction 
algorithms.   As a result these algorithms are subtantially simpler with a slight cost in performance.

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_add\_d</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$ and a mp<span class="hl kwa">\_digit</span> $b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $c = a + b$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $t <span class="hl kwa">\leftarrow</span> b$ (<span class="hl kwa">\textit</span><span class="hl opt">{</span>mp<span class="hl kwa">\_set</span><span class="hl opt">}</span>) \\
<span class="hl num">2</span>.  $c <span class="hl kwa">\leftarrow</span> a + t$ \\
<span class="hl num">3</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>) \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_add\_d</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_add\_d</span>.<span class="hl opt">}</span>
This algorithm initiates a temporary mp<span class="hl kwa">\_int</span> with the value of the single digit and uses algorithm mp<span class="hl kwa">\_add</span> to add the two values together.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_add\_d</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

Clever use of the letter 't'.

<span class="hl kwa">\subsubsection</span><span class="hl opt">{</span>Subtraction<span class="hl opt">}</span>
The single digit subtraction algorithm mp<span class="hl kwa">\_sub\_d</span> is essentially the same except it uses mp<span class="hl kwa">\_sub</span> to subtract the digit from the mp<span class="hl kwa">\_int</span>.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Single Digit Multiplication<span class="hl opt">}</span>
Single digit multiplication arises enough in division and radix conversion that it ought to be implement as a special case of the baseline
multiplication algorithm.  Essentially this algorithm is a modified version of algorithm s<span class="hl kwa">\_mp\_mul\_digs</span> where one of the multiplicands
only has one digit.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_mul\_d</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$ and a mp<span class="hl kwa">\_digit</span> $b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $c = ab$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $pa <span class="hl kwa">\leftarrow</span> a.used$ \\
<span class="hl num">2</span>.  Grow $c$ to at least $pa + <span class="hl num">1</span>$ digits. \\
<span class="hl num">3</span>.  $oldused <span class="hl kwa">\leftarrow</span> c.used$ \\
<span class="hl num">4</span>.  $c.used <span class="hl kwa">\leftarrow</span> pa + <span class="hl num">1</span>$ \\
<span class="hl num">5</span>.  $c.sign <span class="hl kwa">\leftarrow</span> a.sign$ \\
<span class="hl num">6</span>.  $<span class="hl kwa">\mu \leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">7</span>.  for $ix$ from $<span class="hl num">0</span>$ to $pa - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.1</span>  $<span class="hl kwa">\hat</span> r <span class="hl kwa">\leftarrow \mu</span> + a_<span class="hl opt">{</span>ix<span class="hl opt">}</span>b$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.2</span>  $c_<span class="hl opt">{</span>ix<span class="hl opt">}</span> <span class="hl kwa">\leftarrow \hat</span> r <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\beta\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.3</span>  $<span class="hl kwa">\mu \leftarrow \lfloor \hat</span> r / <span class="hl kwa">\beta \rfloor</span>$ \\
<span class="hl num">8</span>.  $c_<span class="hl opt">{</span>pa<span class="hl opt">}</span> <span class="hl kwa">\leftarrow \mu</span>$ \\
<span class="hl num">9</span>.  for $ix$ from $pa + <span class="hl num">1</span>$ to $oldused$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">9.1</span>  $c_<span class="hl opt">{</span>ix<span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">10</span>.  Clamp excess digits of $c$. \\
<span class="hl num">11</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_mul\_d</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_mul\_d</span>.<span class="hl opt">}</span>
This algorithm quickly multiplies an mp<span class="hl kwa">\_int</span> by a small single digit value.  It is specially tailored to the job and has a minimal of overhead.  
Unlike the full multiplication algorithms this algorithm does not require any significnat temporary storage or memory allocations.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_mul\_d</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

In this implementation the destination $c$ may point to the same mp<span class="hl kwa">\_int</span> as the source $a$ since the result is written after the digit is 
read from the source.  This function uses pointer aliases $tmpa$ and $tmpc$ for the digits of $a$ and $c$ respectively.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Single Digit Division<span class="hl opt">}</span>
Like the single digit multiplication algorithm, single digit division is also a fairly common algorithm used in radix conversion.  Since the
divisor is only a single digit a specialized variant of the division algorithm can be used to compute the quotient.  

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_div\_d</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$ and a mp<span class="hl kwa">\_digit</span> $b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $c = <span class="hl kwa">\lfloor</span> a / b <span class="hl kwa">\rfloor</span>, d = a - cb$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  If $b = <span class="hl num">0</span>$ then return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_VAL</span><span class="hl opt">}</span>).\\
<span class="hl num">2</span>.  If $b = <span class="hl num">3</span>$ then use algorithm mp<span class="hl kwa">\_div\_3</span> instead. \\
<span class="hl num">3</span>.  Init $q$ to $a.used$ digits.  \\
<span class="hl num">4</span>.  $q.used <span class="hl kwa">\leftarrow</span> a.used$ \\
<span class="hl num">5</span>.  $q.sign <span class="hl kwa">\leftarrow</span> a.sign$ \\
<span class="hl num">6</span>.  $<span class="hl kwa">\hat</span> w <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">7</span>.  for $ix$ from $a.used - <span class="hl num">1</span>$ down to $<span class="hl num">0</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.1</span>  $<span class="hl kwa">\hat</span> w <span class="hl kwa">\leftarrow \hat</span> w <span class="hl kwa">\beta</span> + a_<span class="hl opt">{</span>ix<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.2</span>  If $<span class="hl kwa">\hat</span> w <span class="hl kwa">\ge</span> b$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">7.2.1</span>  $t <span class="hl kwa">\leftarrow \lfloor \hat</span> w / b <span class="hl kwa">\rfloor</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">7.2.2</span>  $<span class="hl kwa">\hat</span> w <span class="hl kwa">\leftarrow \hat</span> w <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>b<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.3</span>  else\\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">7.3.1</span>  $t <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.4</span>  $q_<span class="hl opt">{</span>ix<span class="hl opt">}</span> <span class="hl kwa">\leftarrow</span> t$ \\
<span class="hl num">8</span>.  $d <span class="hl kwa">\leftarrow \hat</span> w$ \\
<span class="hl num">9</span>.  Clamp excess digits of $q$. \\
<span class="hl num">10</span>.  $c <span class="hl kwa">\leftarrow</span> q$ \\
<span class="hl num">11</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_div\_d</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_div\_d</span>.<span class="hl opt">}</span>
This algorithm divides the mp<span class="hl kwa">\_int</span> $a$ by the single mp<span class="hl kwa">\_digit</span> $b$ using an optimized approach.  Essentially in every iteration of the
algorithm another digit of the dividend is reduced and another digit of quotient produced.  Provided $b &lt; <span class="hl kwa">\beta</span>$ the value of $<span class="hl kwa">\hat</span> w$
after step <span class="hl num">7.1</span> will be limited such that $<span class="hl num">0</span> <span class="hl kwa">\le \lfloor \hat</span> w / b <span class="hl kwa">\rfloor</span> &lt; <span class="hl kwa">\beta</span>$.  

If the divisor $b$ is equal to three a variant of this algorithm is used which is called mp<span class="hl kwa">\_div\_3</span>.  It replaces the division by three with
a multiplication by $<span class="hl kwa">\lfloor \beta</span> / <span class="hl num">3</span> <span class="hl kwa">\rfloor</span>$ and the appropriate shift and residual fixup.  In essence it is much like the Barrett reduction
from chapter seven.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_div\_d</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

Like the implementation of algorithm mp<span class="hl kwa">\_div</span> this algorithm allows either of the quotient or remainder to be passed as a <span class="hl kwa">\textbf</span><span class="hl opt">{</span>NULL<span class="hl opt">}</span> pointer to
indicate the respective value is not required.  This allows a trivial single digit modular reduction algorithm, mp<span class="hl kwa">\_mod\_d</span> to be created.

The division and remainder on lines <span class="hl num">44</span> and &#64;<span class="hl num">45</span>,<span class="hl slc">%&#64; can be replaced often by a single division on most processors.  For example, the 32-bit x86 based </span>
processors can divide a <span class="hl num">64</span>-bit quantity by a <span class="hl num">32</span>-bit quantity and produce the quotient and remainder simultaneously.  Unfortunately the GCC 
compiler does not recognize that optimization and will actually produce two function calls to find the quotient and remainder respectively.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Single Digit Root Extraction<span class="hl opt">}</span>

Finding the $n$'th root of an integer is fairly easy as far as numerical analysis is concerned.  Algorithms such as the Newton-Raphson approximation 
(<span class="hl kwa">\ref</span><span class="hl opt">{</span>eqn:newton<span class="hl opt">}</span>) series will converge very quickly to a root for any continuous function $f(x)$.  

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
x_<span class="hl opt">{</span>i+<span class="hl num">1</span><span class="hl opt">}</span> = x_i - <span class="hl opt">{</span>f(x_i) <span class="hl kwa">\over</span> f'(x_i)<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>eqn:newton<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

In this case the $n$'th root is desired and $f(x) = x^n - a$ where $a$ is the integer of which the root is desired.  The derivative of $f(x)$ is 
simply $f'(x) = nx^<span class="hl opt">{</span>n - <span class="hl num">1</span><span class="hl opt">}</span>$.  Of particular importance is that this algorithm will be used over the integers not over the a more continuous domain
such as the real numbers.  As a result the root found can be above the true root by few and must be manually adjusted.  Ideally at the end of the 
algorithm the $n$'th root $b$ of an integer $a$ is desired such that $b^n <span class="hl kwa">\le</span> a$.  

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_n\_root</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$ and a mp<span class="hl kwa">\_digit</span> $b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $c^b <span class="hl kwa">\le</span> a$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  If $b$ is even and $a.sign = MP<span class="hl kwa">\_NEG</span>$ return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_VAL</span><span class="hl opt">}</span>). \\
<span class="hl num">2</span>.  $sign <span class="hl kwa">\leftarrow</span> a.sign$ \\
<span class="hl num">3</span>.  $a.sign <span class="hl kwa">\leftarrow</span> MP<span class="hl kwa">\_ZPOS</span>$ \\
<span class="hl num">4</span>.  t$<span class="hl num">2</span> <span class="hl kwa">\leftarrow</span> <span class="hl num">2</span>$ \\
<span class="hl num">5</span>.  Loop \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.1</span>  t$<span class="hl num">1</span> <span class="hl kwa">\leftarrow</span> $ t$<span class="hl num">2</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.2</span>  t$<span class="hl num">3</span> <span class="hl kwa">\leftarrow</span> $ t$<span class="hl num">1</span>^<span class="hl opt">{</span>b - <span class="hl num">1</span><span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.3</span>  t$<span class="hl num">2</span> <span class="hl kwa">\leftarrow</span> $ t$<span class="hl num">3</span> $ $<span class="hl kwa">\cdot</span>$ t$<span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.4</span>  t$<span class="hl num">2</span> <span class="hl kwa">\leftarrow</span> $ t$<span class="hl num">2</span> - a$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.5</span>  t$<span class="hl num">3</span> <span class="hl kwa">\leftarrow</span> $ t$<span class="hl num">3</span> <span class="hl kwa">\cdot</span> b$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.6</span>  t$<span class="hl num">3</span> <span class="hl kwa">\leftarrow \lfloor</span> $t$<span class="hl num">2</span> / $t$<span class="hl num">3</span> <span class="hl kwa">\rfloor</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.7</span>  t$<span class="hl num">2</span> <span class="hl kwa">\leftarrow</span> $ t$<span class="hl num">1</span> - $ t$<span class="hl num">3</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.8</span>  If t$<span class="hl num">1</span> <span class="hl kwa">\ne</span> $ t$<span class="hl num">2</span>$ then goto step <span class="hl num">5</span>.  \\
<span class="hl num">6</span>.  Loop \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.1</span>  t$<span class="hl num">2</span> <span class="hl kwa">\leftarrow</span> $ t$<span class="hl num">1</span>^b$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.2</span>  If t$<span class="hl num">2</span> &gt; a$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">6.2.1</span>  t$<span class="hl num">1</span> <span class="hl kwa">\leftarrow</span> $ t$<span class="hl num">1</span> - <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">6.2.2</span>  Goto step <span class="hl num">6</span>. \\
<span class="hl num">7</span>.  $a.sign <span class="hl kwa">\leftarrow</span> sign$ \\
<span class="hl num">8</span>.  $c <span class="hl kwa">\leftarrow</span> $ t$<span class="hl num">1</span>$ \\
<span class="hl num">9</span>.  $c.sign <span class="hl kwa">\leftarrow</span> sign$  \\
<span class="hl num">10</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>).  \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_n\_root</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_n\_root</span>.<span class="hl opt">}</span>
This algorithm finds the integer $n$'th root of an input using the Newton-Raphson approach.  It is partially optimized based on the observation
that the numerator of $<span class="hl opt">{</span>f(x) <span class="hl kwa">\over</span> f'(x)<span class="hl opt">}</span>$ can be derived from a partial denominator.  That is at first the denominator is calculated by finding
$x^<span class="hl opt">{</span>b - <span class="hl num">1</span><span class="hl opt">}</span>$.  This value can then be multiplied by $x$ and have $a$ subtracted from it to find the numerator.  This saves a total of $b - <span class="hl num">1</span>$ 
multiplications by t$<span class="hl num">1</span>$ inside the loop.  

The initial value of the approximation is t$<span class="hl num">2</span> = <span class="hl num">2</span>$ which allows the algorithm to start with very small values and quickly converge on the
root.  Ideally this algorithm is meant to find the $n$'th root of an input where $n$ is bounded by $<span class="hl num">2</span> <span class="hl kwa">\le</span> n <span class="hl kwa">\le</span> <span class="hl num">5</span>$.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_n\_root</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

<span class="hl kwa">\section</span><span class="hl opt">{</span>Random Number Generation<span class="hl opt">}</span>

Random numbers come up in a variety of activities from public key cryptography to simple simulations and various randomized algorithms.  Pollard-Rho 
factoring for example, can make use of random values as starting points to find factors of a composite integer.  In this case the algorithm presented
is solely for simulations and not intended for cryptographic use.  

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_rand</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   An integer $b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  A pseudo-random number of $b$ digits \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $a <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">2</span>.  If $b <span class="hl kwa">\le</span> <span class="hl num">0</span>$ return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>) \\
<span class="hl num">3</span>.  Pick a non-zero random digit $d$. \\
<span class="hl num">4</span>.  $a <span class="hl kwa">\leftarrow</span> a + d$ \\
<span class="hl num">5</span>.  for $ix$ from <span class="hl num">1</span> to $d - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.1</span>  $a <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\cdot \beta</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.2</span>  Pick a random digit $d$. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.3</span>  $a <span class="hl kwa">\leftarrow</span> a + d$ \\
<span class="hl num">6</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_rand</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_rand</span>.<span class="hl opt">}</span>
This algorithm produces a pseudo-random integer of $b$ digits.  By ensuring that the first digit is non-zero the algorithm also guarantees that the
final result has at least $b$ digits.  It relies heavily on a third-part random number generator which should ideally generate uniformly all of
the integers from $<span class="hl num">0</span>$ to $<span class="hl kwa">\beta</span> - <span class="hl num">1</span>$.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_rand</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

<span class="hl kwa">\section</span><span class="hl opt">{</span>Formatted Representations<span class="hl opt">}</span>
The ability to emit a radix-$n$ textual representation of an integer is useful for interacting with human parties.  For example, the ability to
be given a string of characters such as ``<span class="hl num">114585</span>'' and turn it into the radix-$<span class="hl kwa">\beta</span>$ equivalent would make it easier to enter numbers
into a program.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Reading Radix-n Input<span class="hl opt">}</span>
For the purposes of this text we will assume that a simple lower ASCII map (<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:ASC<span class="hl opt">}</span>) is used for the values of from $<span class="hl num">0</span>$ to $<span class="hl num">63</span>$ to 
printable characters.  For example, when the character ``N'' is read it represents the integer $<span class="hl num">23</span>$.  The first $<span class="hl num">16</span>$ characters of the
map are for the common representations up to hexadecimal.  After that they match the ``base64'' encoding scheme which are suitable chosen
such that they are printable.  While outputting as base64 may not be too helpful for human operators it does allow communication via non binary
mediums.

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>cc|cc|cc|cc<span class="hl opt">}</span>
<span class="hl kwa">\hline \textbf</span><span class="hl opt">{</span>Value<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Char<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Value<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Char<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Value<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Char<span class="hl opt">}</span> &amp;  <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Value<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Char<span class="hl opt">}</span> \\
<span class="hl kwa">\hline</span> 
<span class="hl num">0</span> &amp; <span class="hl num">0</span> &amp; <span class="hl num">1</span> &amp; <span class="hl num">1</span> &amp; <span class="hl num">2</span> &amp; <span class="hl num">2</span> &amp; <span class="hl num">3</span> &amp; <span class="hl num">3</span> \\
<span class="hl num">4</span> &amp; <span class="hl num">4</span> &amp; <span class="hl num">5</span> &amp; <span class="hl num">5</span> &amp; <span class="hl num">6</span> &amp; <span class="hl num">6</span> &amp; <span class="hl num">7</span> &amp; <span class="hl num">7</span> \\
<span class="hl num">8</span> &amp; <span class="hl num">8</span> &amp; <span class="hl num">9</span> &amp; <span class="hl num">9</span> &amp; <span class="hl num">10</span> &amp; A &amp; <span class="hl num">11</span> &amp; B \\
<span class="hl num">12</span> &amp; C &amp; <span class="hl num">13</span> &amp; D &amp; <span class="hl num">14</span> &amp; E &amp; <span class="hl num">15</span> &amp; F \\
<span class="hl num">16</span> &amp; G &amp; <span class="hl num">17</span> &amp; H &amp; <span class="hl num">18</span> &amp; I &amp; <span class="hl num">19</span> &amp; J \\
<span class="hl num">20</span> &amp; K &amp; <span class="hl num">21</span> &amp; L &amp; <span class="hl num">22</span> &amp; M &amp; <span class="hl num">23</span> &amp; N \\
<span class="hl num">24</span> &amp; O &amp; <span class="hl num">25</span> &amp; P &amp; <span class="hl num">26</span> &amp; Q &amp; <span class="hl num">27</span> &amp; R \\
<span class="hl num">28</span> &amp; S &amp; <span class="hl num">29</span> &amp; T &amp; <span class="hl num">30</span> &amp; U &amp; <span class="hl num">31</span> &amp; V \\
<span class="hl num">32</span> &amp; W &amp; <span class="hl num">33</span> &amp; X &amp; <span class="hl num">34</span> &amp; Y &amp; <span class="hl num">35</span> &amp; Z \\
<span class="hl num">36</span> &amp; a &amp; <span class="hl num">37</span> &amp; b &amp; <span class="hl num">38</span> &amp; c &amp; <span class="hl num">39</span> &amp; d \\
<span class="hl num">40</span> &amp; e &amp; <span class="hl num">41</span> &amp; f &amp; <span class="hl num">42</span> &amp; g &amp; <span class="hl num">43</span> &amp; h \\
<span class="hl num">44</span> &amp; i &amp; <span class="hl num">45</span> &amp; j &amp; <span class="hl num">46</span> &amp; k &amp; <span class="hl num">47</span> &amp; l \\
<span class="hl num">48</span> &amp; m &amp; <span class="hl num">49</span> &amp; n &amp; <span class="hl num">50</span> &amp; o &amp; <span class="hl num">51</span> &amp; p \\
<span class="hl num">52</span> &amp; q &amp; <span class="hl num">53</span> &amp; r &amp; <span class="hl num">54</span> &amp; s &amp; <span class="hl num">55</span> &amp; t \\
<span class="hl num">56</span> &amp; u &amp; <span class="hl num">57</span> &amp; v &amp; <span class="hl num">58</span> &amp; w &amp; <span class="hl num">59</span> &amp; x \\
<span class="hl num">60</span> &amp; y &amp; <span class="hl num">61</span> &amp; z &amp; <span class="hl num">62</span> &amp; $+$ &amp; <span class="hl num">63</span> &amp; $/$ \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Lower ASCII Map<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>fig:ASC<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_read\_radix</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   A string $str$ of length $sn$ and radix $r$. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  The radix-$<span class="hl kwa">\beta</span>$ equivalent mp<span class="hl kwa">\_int</span>. \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  If $r &lt; <span class="hl num">2</span>$ or $r &gt; <span class="hl num">64</span>$ return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_VAL</span><span class="hl opt">}</span>). \\
<span class="hl num">2</span>.  $ix <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">3</span>.  If $str_0 =$ ``-'' then do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">3.1</span>  $ix <span class="hl kwa">\leftarrow</span> ix + <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">3.2</span>  $sign <span class="hl kwa">\leftarrow</span> MP<span class="hl kwa">\_NEG</span>$ \\
<span class="hl num">4</span>.  else \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.1</span>  $sign <span class="hl kwa">\leftarrow</span> MP<span class="hl kwa">\_ZPOS</span>$ \\
<span class="hl num">5</span>.  $a <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">6</span>.  for $iy$ from $ix$ to $sn - <span class="hl num">1</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.1</span>  Let $y$ denote the position in the map of $str_<span class="hl opt">{</span>iy<span class="hl opt">}</span>$. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.2</span>  If $str_<span class="hl opt">{</span>iy<span class="hl opt">}</span>$ is not in the map or $y <span class="hl kwa">\ge</span> r$ then goto step <span class="hl num">7</span>. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.3</span>  $a <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\cdot</span> r$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.4</span>  $a <span class="hl kwa">\leftarrow</span> a + y$ \\
<span class="hl num">7</span>.  If $a <span class="hl kwa">\ne</span> <span class="hl num">0</span>$ then $a.sign <span class="hl kwa">\leftarrow</span> sign$ \\
<span class="hl num">8</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_read\_radix</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_read\_radix</span>.<span class="hl opt">}</span>
This algorithm will read an ASCII string and produce the radix-$<span class="hl kwa">\beta</span>$ mp<span class="hl kwa">\_int</span> representation of the same integer.  A minus symbol ``-'' may precede the 
string  to indicate the value is negative, otherwise it is assumed to be positive.  The algorithm will read up to $sn$ characters from the input
and will stop when it reads a character it cannot map the algorithm stops reading characters from the string.  This allows numbers to be embedded
as part of larger input without any significant problem.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_read\_radix</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Generating Radix-$n$ Output<span class="hl opt">}</span>
Generating radix-$n$ output is fairly trivial with a division and remainder algorithm.  

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_toradix</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   A mp<span class="hl kwa">\_int</span> $a$ and an integer $r$\\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  The radix-$r$ representation of $a$ \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  If $r &lt; <span class="hl num">2</span>$ or $r &gt; <span class="hl num">64</span>$ return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_VAL</span><span class="hl opt">}</span>). \\
<span class="hl num">2</span>.  If $a = <span class="hl num">0</span>$ then $str = $ ``$<span class="hl num">0</span>$'' and return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>).  \\
<span class="hl num">3</span>.  $t <span class="hl kwa">\leftarrow</span> a$ \\
<span class="hl num">4</span>.  $str <span class="hl kwa">\leftarrow</span>$ ``'' \\
<span class="hl num">5</span>.  if $t.sign = MP<span class="hl kwa">\_NEG</span>$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.1</span>  $str <span class="hl kwa">\leftarrow</span> str + $ ``-'' \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.2</span>  $t.sign = MP<span class="hl kwa">\_ZPOS</span>$ \\
<span class="hl num">6</span>.  While ($t <span class="hl kwa">\ne</span> <span class="hl num">0</span>$) do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.1</span>  $d <span class="hl kwa">\leftarrow</span> t <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>r<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.2</span>  $t <span class="hl kwa">\leftarrow \lfloor</span> t / r <span class="hl kwa">\rfloor</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.3</span>  Look up $d$ in the map and store the equivalent character in $y$. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.4</span>  $str <span class="hl kwa">\leftarrow</span> str + y$ \\
<span class="hl num">7</span>.  If $str_0 = $``$-$'' then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.1</span>  Reverse the digits $str_1, str_2, <span class="hl kwa">\ldots</span> str_n$. \\
<span class="hl num">8</span>.  Otherwise \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">8.1</span>  Reverse the digits $str_0, str_1, <span class="hl kwa">\ldots</span> str_n$. \\
<span class="hl num">9</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>).\\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_toradix</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_toradix</span>.<span class="hl opt">}</span>
This algorithm computes the radix-$r$ representation of an mp<span class="hl kwa">\_int</span> $a$.  The ``digits'' of the representation are extracted by reducing 
successive powers of $<span class="hl kwa">\lfloor</span> a / r^k <span class="hl kwa">\rfloor</span>$ the input modulo $r$ until $r^k &gt; a$.  Note that instead of actually dividing by $r^k$ in
each iteration the quotient $<span class="hl kwa">\lfloor</span> a / r <span class="hl kwa">\rfloor</span>$ is saved for the next iteration.  As a result a series of trivial $n <span class="hl kwa">\times</span> <span class="hl num">1</span>$ divisions
are required instead of a series of $n <span class="hl kwa">\times</span> k$ divisions.  One design flaw of this approach is that the digits are produced in the reverse order 
(see~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:mpradix<span class="hl opt">}</span>).  To remedy this flaw the digits must be swapped or simply ``reversed''.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>|c|c|c|<span class="hl opt">}</span>
<span class="hl kwa">\hline \textbf</span><span class="hl opt">{</span>Value of $a$<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Value of $d$<span class="hl opt">}</span> &amp; <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Value of $str$<span class="hl opt">}</span> \\
<span class="hl kwa">\hline</span> $<span class="hl num">1234</span>$ &amp; -- &amp; -- \\
<span class="hl kwa">\hline</span> $<span class="hl num">123</span>$  &amp; $<span class="hl num">4</span>$ &amp; ``<span class="hl num">4</span>'' \\
<span class="hl kwa">\hline</span> $<span class="hl num">12</span>$   &amp; $<span class="hl num">3</span>$ &amp; ``<span class="hl num">43</span>'' \\
<span class="hl kwa">\hline</span> $<span class="hl num">1</span>$    &amp; $<span class="hl num">2</span>$ &amp; ``<span class="hl num">432</span>'' \\
<span class="hl kwa">\hline</span> $<span class="hl num">0</span>$    &amp; $<span class="hl num">1</span>$ &amp; ``<span class="hl num">4321</span>'' \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Example of Algorithm mp<span class="hl kwa">\_toradix</span>.<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>fig:mpradix<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_toradix</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

<span class="hl kwa">\chapter</span><span class="hl opt">{</span>Number Theoretic Algorithms<span class="hl opt">}</span>
This chapter discusses several fundamental number theoretic algorithms such as the greatest common divisor, least common multiple and Jacobi 
symbol computation.  These algorithms arise as essential components in several key cryptographic algorithms such as the RSA public key algorithm and
various Sieve based factoring algorithms.

<span class="hl kwa">\section</span><span class="hl opt">{</span>Greatest Common Divisor<span class="hl opt">}</span>
The greatest common divisor of two integers $a$ and $b$, often denoted as $(a, b)$ is the largest integer $k$ that is a proper divisor of
both $a$ and $b$.  That is, $k$ is the largest integer such that $<span class="hl num">0</span> <span class="hl kwa">\equiv</span> a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>k<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ and $<span class="hl num">0</span> <span class="hl kwa">\equiv</span> b <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>k<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ occur
simultaneously.

The most common approach (cite) is to reduce one input modulo another.  That is if $a$ and $b$ are divisible by some integer $k$ and if $qa + r = b$ then
$r$ is also divisible by $k$.  The reduction pattern follows $<span class="hl kwa">\left</span> &lt; a , b <span class="hl kwa">\right</span> &gt; <span class="hl kwa">\rightarrow \left</span> &lt; b, a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> mod <span class="hl opt">}</span> b <span class="hl kwa">\right</span> &gt;$.  

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Greatest Common Divisor (I)<span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   Two positive integers $a$ and $b$ greater than zero. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  The greatest common divisor $(a, b)$.  \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  While ($b &gt; <span class="hl num">0</span>$) do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.1</span>  $r <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>b<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.2</span>  $a <span class="hl kwa">\leftarrow</span> b$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.3</span>  $b <span class="hl kwa">\leftarrow</span> r$ \\
<span class="hl num">2</span>.  Return($a$). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm Greatest Common Divisor (I)<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>fig:gcd1<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

This algorithm will quickly converge on the greatest common divisor since the residue $r$ tends diminish rapidly.  However, divisions are
relatively expensive operations to perform and should ideally be avoided.  There is another approach based on a similar relationship of 
greatest common divisors.  The faster approach is based on the observation that if $k$ divides both $a$ and $b$ it will also divide $a - b$.  
In particular, we would like $a - b$ to decrease in magnitude which implies that $b <span class="hl kwa">\ge</span> a$.  

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Greatest Common Divisor (II)<span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   Two positive integers $a$ and $b$ greater than zero. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  The greatest common divisor $(a, b)$.  \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  While ($b &gt; <span class="hl num">0</span>$) do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.1</span>  Swap $a$ and $b$ such that $a$ is the smallest of the two. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.2</span>  $b <span class="hl kwa">\leftarrow</span> b - a$ \\
<span class="hl num">2</span>.  Return($a$). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm Greatest Common Divisor (II)<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>fig:gcd2<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Proof<span class="hl opt">}</span> <span class="hl kwa">\textit</span><span class="hl opt">{</span>Algorithm~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:gcd2<span class="hl opt">}</span> will return the greatest common divisor of $a$ and $b$.<span class="hl opt">}</span>
The algorithm in figure~<span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:gcd2<span class="hl opt">}</span> will eventually terminate since $b <span class="hl kwa">\ge</span> a$ the subtraction in step <span class="hl num">1.2</span> will be a value less than $b$.  In other
words in every iteration that tuple $<span class="hl kwa">\left</span> &lt; a, b <span class="hl kwa">\right</span> &gt;$ decrease in magnitude until eventually $a = b$.  Since both $a$ and $b$ are always 
divisible by the greatest common divisor (<span class="hl kwa">\textit</span><span class="hl opt">{</span>until the last iteration<span class="hl opt">}</span>) and in the last iteration of the algorithm $b = <span class="hl num">0</span>$, therefore, in the 
second to last iteration of the algorithm $b = a$ and clearly $(a, a) = a$ which concludes the proof.  <span class="hl kwa">\textbf</span><span class="hl opt">{</span>QED<span class="hl opt">}</span>.

As a matter of practicality algorithm <span class="hl kwa">\ref</span><span class="hl opt">{</span>fig:gcd1<span class="hl opt">}</span> decreases far too slowly to be useful.  Specially if $b$ is much larger than $a$ such that 
$b - a$ is still very much larger than $a$.  A simple addition to the algorithm is to divide $b - a$ by a power of some integer $p$ which does
not divide the greatest common divisor but will divide $b - a$.  In this case $<span class="hl opt">{</span>b - a<span class="hl opt">}</span> <span class="hl kwa">\over</span> p$ is also an integer and still divisible by
the greatest common divisor.

However, instead of factoring $b - a$ to find a suitable value of $p$ the powers of $p$ can be removed from $a$ and $b$ that are in common first.  
Then inside the loop whenever $b - a$ is divisible by some power of $p$ it can be safely removed.  

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>Greatest Common Divisor (III)<span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   Two positive integers $a$ and $b$ greater than zero. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  The greatest common divisor $(a, b)$.  \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $k <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">2</span>.  While $a$ and $b$ are both divisible by $p$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  $a <span class="hl kwa">\leftarrow \lfloor</span> a / p <span class="hl kwa">\rfloor</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.2</span>  $b <span class="hl kwa">\leftarrow \lfloor</span> b / p <span class="hl kwa">\rfloor</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.3</span>  $k <span class="hl kwa">\leftarrow</span> k + <span class="hl num">1</span>$ \\
<span class="hl num">3</span>.  While $a$ is divisible by $p$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">3.1</span>  $a <span class="hl kwa">\leftarrow \lfloor</span> a / p <span class="hl kwa">\rfloor</span>$ \\
<span class="hl num">4</span>.  While $b$ is divisible by $p$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.1</span>  $b <span class="hl kwa">\leftarrow \lfloor</span> b / p <span class="hl kwa">\rfloor</span>$ \\
<span class="hl num">5</span>.  While ($b &gt; <span class="hl num">0</span>$) do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.1</span>  Swap $a$ and $b$ such that $a$ is the smallest of the two. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.2</span>  $b <span class="hl kwa">\leftarrow</span> b - a$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.3</span>  While $b$ is divisible by $p$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">5.3.1</span>  $b <span class="hl kwa">\leftarrow \lfloor</span> b / p <span class="hl kwa">\rfloor</span>$ \\
<span class="hl num">6</span>.  Return($a <span class="hl kwa">\cdot</span> p^k$). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm Greatest Common Divisor (III)<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>fig:gcd3<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>

This algorithm is based on the first except it removes powers of $p$ first and inside the main loop to ensure the tuple $<span class="hl kwa">\left</span> &lt; a, b <span class="hl kwa">\right</span> &gt;$ 
decreases more rapidly.  The first loop on step two removes powers of $p$ that are in common.  A count, $k$, is kept which will present a common
divisor of $p^k$.  After step two the remaining common divisor of $a$ and $b$ cannot be divisible by $p$.  This means that $p$ can be safely 
divided out of the difference $b - a$ so long as the division leaves no remainder.  

In particular the value of $p$ should be chosen such that the division on step <span class="hl num">5.3.1</span> occur often.  It also helps that division by $p$ be easy
to compute.  The ideal choice of $p$ is two since division by two amounts to a right logical shift.  Another important observation is that by
step five both $a$ and $b$ are odd.  Therefore, the diffrence $b - a$ must be even which means that each iteration removes one bit from the 
largest of the pair.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Complete Greatest Common Divisor<span class="hl opt">}</span>
The algorithms presented so far cannot handle inputs which are zero or negative.  The following algorithm can handle all input cases properly
and will produce the greatest common divisor.

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_gcd</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$ and $b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  The greatest common divisor $c = (a, b)$.  \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  If $a = <span class="hl num">0</span>$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.1</span>  $c <span class="hl kwa">\leftarrow \vert</span> b <span class="hl kwa">\vert</span> $ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.2</span>  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl num">2</span>.  If $b = <span class="hl num">0</span>$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  $c <span class="hl kwa">\leftarrow \vert</span> a <span class="hl kwa">\vert</span> $ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.2</span>  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl num">3</span>.  $u <span class="hl kwa">\leftarrow \vert</span> a <span class="hl kwa">\vert</span>, v <span class="hl kwa">\leftarrow \vert</span> b <span class="hl kwa">\vert</span>$ \\
<span class="hl num">4</span>.  $k <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">5</span>.  While $u.used &gt; <span class="hl num">0</span>$ and $v.used &gt; <span class="hl num">0</span>$ and $u_0 <span class="hl kwa">\equiv</span> v_0 <span class="hl kwa">\equiv</span> <span class="hl num">0</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.1</span>  $k <span class="hl kwa">\leftarrow</span> k + <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.2</span>  $u <span class="hl kwa">\leftarrow \lfloor</span> u / <span class="hl num">2</span> <span class="hl kwa">\rfloor</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.3</span>  $v <span class="hl kwa">\leftarrow \lfloor</span> v / <span class="hl num">2</span> <span class="hl kwa">\rfloor</span>$ \\
<span class="hl num">6</span>.  While $u.used &gt; <span class="hl num">0</span>$ and $u_0 <span class="hl kwa">\equiv</span> <span class="hl num">0</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.1</span>  $u <span class="hl kwa">\leftarrow \lfloor</span> u / <span class="hl num">2</span> <span class="hl kwa">\rfloor</span>$ \\
<span class="hl num">7</span>.  While $v.used &gt; <span class="hl num">0</span>$ and $v_0 <span class="hl kwa">\equiv</span> <span class="hl num">0</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.1</span>  $v <span class="hl kwa">\leftarrow \lfloor</span> v / <span class="hl num">2</span> <span class="hl kwa">\rfloor</span>$ \\
<span class="hl num">8</span>.  While $v.used &gt; <span class="hl num">0</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">8.1</span>  If $<span class="hl kwa">\vert</span> u <span class="hl kwa">\vert</span> &gt; <span class="hl kwa">\vert</span> v <span class="hl kwa">\vert</span>$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">8.1.1</span>  Swap $u$ and $v$. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">8.2</span>  $v <span class="hl kwa">\leftarrow \vert</span> v <span class="hl kwa">\vert</span> - <span class="hl kwa">\vert</span> u <span class="hl kwa">\vert</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">8.3</span>  While $v.used &gt; <span class="hl num">0</span>$ and $v_0 <span class="hl kwa">\equiv</span> <span class="hl num">0</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">8.3.1</span>  $v <span class="hl kwa">\leftarrow \lfloor</span> v / <span class="hl num">2</span> <span class="hl kwa">\rfloor</span>$ \\
<span class="hl num">9</span>.  $c <span class="hl kwa">\leftarrow</span> u <span class="hl kwa">\cdot</span> <span class="hl num">2</span>^k$ \\
<span class="hl num">10</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_gcd</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_gcd</span>.<span class="hl opt">}</span>
This algorithm will produce the greatest common divisor of two mp<span class="hl kwa">\_ints</span> $a$ and $b$.  The algorithm was originally based on Algorithm B of
Knuth <span class="hl kwa">\cite</span><span class="hl opt">[</span>pp. <span class="hl num">338</span><span class="hl opt">]{</span>TAOCPV2<span class="hl opt">}</span> but has been modified to be simpler to explain.  In theory it achieves the same asymptotic working time as
Algorithm B and in practice this appears to be true.  

The first two steps handle the cases where either one of or both inputs are zero.  If either input is zero the greatest common divisor is the 
largest input or zero if they are both zero.  If the inputs are not trivial than $u$ and $v$ are assigned the absolute values of 
$a$ and $b$ respectively and the algorithm will proceed to reduce the pair.

Step five will divide out any common factors of two and keep track of the count in the variable $k$.  After this step, two is no longer a
factor of the remaining greatest common divisor between $u$ and $v$ and can be safely evenly divided out of either whenever they are even.  Step 
six and seven ensure that the $u$ and $v$ respectively have no more factors of two.  At most only one of the while--loops will iterate since 
they cannot both be even.

By step eight both of $u$ and $v$ are odd which is required for the inner logic.  First the pair are swapped such that $v$ is equal to
or greater than $u$.  This ensures that the subtraction on step <span class="hl num">8.2</span> will always produce a positive and even result.  Step <span class="hl num">8.3</span> removes any
factors of two from the difference $u$ to ensure that in the next iteration of the loop both are once again odd.

After $v = <span class="hl num">0</span>$ occurs the variable $u$ has the greatest common divisor of the pair $<span class="hl kwa">\left</span> &lt; u, v <span class="hl kwa">\right</span> &gt;$ just after step six.  The result
must be adjusted by multiplying by the common factors of two ($<span class="hl num">2</span>^k$) removed earlier.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_gcd</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

This function makes use of the macros mp<span class="hl kwa">\_iszero</span> and mp<span class="hl kwa">\_iseven</span>.  The former evaluates to $<span class="hl num">1</span>$ if the input mp<span class="hl kwa">\_int</span> is equivalent to the 
integer zero otherwise it evaluates to $<span class="hl num">0</span>$.  The latter evaluates to $<span class="hl num">1</span>$ if the input mp<span class="hl kwa">\_int</span> represents a non-zero even integer otherwise
it evaluates to $<span class="hl num">0</span>$.  Note that just because mp<span class="hl kwa">\_iseven</span> may evaluate to $<span class="hl num">0</span>$ does not mean the input is odd, it could also be zero.  The three 
trivial cases of inputs are handled on lines <span class="hl num">24</span> through <span class="hl num">30</span>.  After those lines the inputs are assumed to be non-zero.

Lines <span class="hl num">32</span> and <span class="hl num">37</span> make local copies $u$ and $v$ of the inputs $a$ and $b$ respectively.  At this point the common factors of two 
must be divided out of the two inputs.  The block starting at line <span class="hl num">44</span> removes common factors of two by first counting the number of trailing
zero bits in both.  The local integer $k$ is used to keep track of how many factors of $<span class="hl num">2</span>$ are pulled out of both values.  It is assumed that 
the number of factors will not exceed the maximum value of a C ``int'' data type<span class="hl kwa">\footnote</span><span class="hl opt">{</span>Strictly speaking no array in C may have more than 
entries than are accessible by an ``int'' so this is not a limitation.<span class="hl opt">}</span>.  

At this point there are no more common factors of two in the two values.  The divisions by a power of two on lines <span class="hl num">62</span> and <span class="hl num">68</span> remove 
any independent factors of two such that both $u$ and $v$ are guaranteed to be an odd integer before hitting the main body of the algorithm.  The while loop
on line <span class="hl num">73</span> performs the reduction of the pair until $v$ is equal to zero.  The unsigned comparison and subtraction algorithms are used in
place of the full signed routines since both values are guaranteed to be positive and the result of the subtraction is guaranteed to be non-negative.

<span class="hl kwa">\section</span><span class="hl opt">{</span>Least Common Multiple<span class="hl opt">}</span>
The least common multiple of a pair of integers is their product divided by their greatest common divisor.  For two integers $a$ and $b$ the
least common multiple is normally denoted as $<span class="hl opt">[</span> a, b <span class="hl opt">]</span>$ and numerically equivalent to $<span class="hl opt">{</span>ab<span class="hl opt">}</span> <span class="hl kwa">\over</span> <span class="hl opt">{</span>(a, b)<span class="hl opt">}</span>$.  For example, if $a = <span class="hl num">2</span> <span class="hl kwa">\cdot</span> <span class="hl num">2</span> <span class="hl kwa">\cdot</span> <span class="hl num">3</span> = <span class="hl num">12</span>$
and $b = <span class="hl num">2</span> <span class="hl kwa">\cdot</span> <span class="hl num">3</span> <span class="hl kwa">\cdot</span> <span class="hl num">3</span> <span class="hl kwa">\cdot</span> <span class="hl num">7</span> = <span class="hl num">126</span>$ the least common multiple is $<span class="hl opt">{</span><span class="hl num">126</span> <span class="hl kwa">\over</span> <span class="hl opt">{</span>(<span class="hl num">12</span>, <span class="hl num">126</span>)<span class="hl opt">}}</span> = <span class="hl opt">{</span><span class="hl num">126</span> <span class="hl kwa">\over</span> <span class="hl num">6</span><span class="hl opt">}</span> = <span class="hl num">21</span>$.

The least common multiple arises often in coding theory as well as number theory.  If two functions have periods of $a$ and $b$ respectively they will
collide, that is be in synchronous states, after only $<span class="hl opt">[</span> a, b <span class="hl opt">]</span>$ iterations.  This is why, for example, random number generators based on 
Linear Feedback Shift Registers (LFSR) tend to use registers with periods which are co-prime (<span class="hl kwa">\textit</span><span class="hl opt">{</span>e.g. the greatest common divisor is one.<span class="hl opt">}</span>).  
Similarly in number theory if a composite $n$ has two prime factors $p$ and $q$ then maximal order of any unit of $<span class="hl kwa">\Z</span>/n<span class="hl kwa">\Z</span>$ will be $<span class="hl opt">[</span> p - <span class="hl num">1</span>, q - <span class="hl num">1</span><span class="hl opt">]</span> $.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_lcm</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$ and $b$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  The least common multiple $c = <span class="hl opt">[</span>a, b<span class="hl opt">]</span>$.  \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $c <span class="hl kwa">\leftarrow</span> (a, b)$ \\
<span class="hl num">2</span>.  $t <span class="hl kwa">\leftarrow</span> a <span class="hl kwa">\cdot</span> b$ \\
<span class="hl num">3</span>.  $c <span class="hl kwa">\leftarrow \lfloor</span> t / c <span class="hl kwa">\rfloor</span>$ \\
<span class="hl num">4</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_lcm</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_lcm</span>.<span class="hl opt">}</span>
This algorithm computes the least common multiple of two mp<span class="hl kwa">\_int</span> inputs $a$ and $b$.  It computes the least common multiple directly by
dividing the product of the two inputs by their greatest common divisor.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_lcm</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

<span class="hl kwa">\section</span><span class="hl opt">{</span>Jacobi Symbol Computation<span class="hl opt">}</span>
To explain the Jacobi Symbol we shall first discuss the Legendre function<span class="hl kwa">\footnote</span><span class="hl opt">{</span>Arrg.  What is the name of this?<span class="hl opt">}</span> off which the Jacobi symbol is 
defined.  The Legendre function computes whether or not an integer $a$ is a quadratic residue modulo an odd prime $p$.  Numerically it is
equivalent to equation <span class="hl kwa">\ref</span><span class="hl opt">{</span>eqn:legendre<span class="hl opt">}</span>.

<span class="hl kwa">\textit</span><span class="hl opt">{</span>-- Tom, don't be an ass, cite your source here...!<span class="hl opt">}</span>

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
a^<span class="hl opt">{</span>(p-<span class="hl num">1</span>)/<span class="hl num">2</span><span class="hl opt">}</span> <span class="hl kwa">\equiv \begin</span><span class="hl opt">{</span>array<span class="hl opt">}{</span>rl<span class="hl opt">}</span>
                              -<span class="hl num">1</span> &amp;  <span class="hl kwa">\mbox</span><span class="hl opt">{</span>if <span class="hl opt">}</span>a<span class="hl kwa">\mbox</span><span class="hl opt">{</span> is a quadratic non-residue.<span class="hl opt">}</span> \\
                              <span class="hl num">0</span>  &amp;  <span class="hl kwa">\mbox</span><span class="hl opt">{</span>if <span class="hl opt">}</span>a<span class="hl kwa">\mbox</span><span class="hl opt">{</span> divides <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>.<span class="hl opt">}</span> \\
                              <span class="hl num">1</span>  &amp;  <span class="hl kwa">\mbox</span><span class="hl opt">{</span>if <span class="hl opt">}</span>a<span class="hl kwa">\mbox</span><span class="hl opt">{</span> is a quadratic residue<span class="hl opt">}</span>. 
                              <span class="hl kwa">\end</span><span class="hl opt">{</span>array<span class="hl opt">}</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>eqn:legendre<span class="hl opt">}</span>                              
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Proof.<span class="hl opt">}</span> <span class="hl kwa">\textit</span><span class="hl opt">{</span>Equation <span class="hl kwa">\ref</span><span class="hl opt">{</span>eqn:legendre<span class="hl opt">}</span> correctly identifies the residue status of an integer $a$ modulo a prime $p$.<span class="hl opt">}</span>
An integer $a$ is a quadratic residue if the following equation has a solution.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
x^<span class="hl num">2</span> <span class="hl kwa">\equiv</span> a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>eqn:root<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

Consider the following equation.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
<span class="hl num">0</span> <span class="hl kwa">\equiv</span> x^<span class="hl opt">{</span>p-<span class="hl num">1</span><span class="hl opt">}</span> - <span class="hl num">1</span> <span class="hl kwa">\equiv \left \lbrace \left</span> (x^<span class="hl num">2</span> <span class="hl kwa">\right</span> )^<span class="hl opt">{</span>(p-<span class="hl num">1</span>)/<span class="hl num">2</span><span class="hl opt">}</span> - a^<span class="hl opt">{</span>(p-<span class="hl num">1</span>)/<span class="hl num">2</span><span class="hl opt">}</span> <span class="hl kwa">\right \rbrace</span> + <span class="hl kwa">\left</span> ( a^<span class="hl opt">{</span>(p-<span class="hl num">1</span>)/<span class="hl num">2</span><span class="hl opt">}</span> - <span class="hl num">1</span> <span class="hl kwa">\right</span> ) <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>eqn:rooti<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

Whether equation <span class="hl kwa">\ref</span><span class="hl opt">{</span>eqn:root<span class="hl opt">}</span> has a solution or not equation <span class="hl kwa">\ref</span><span class="hl opt">{</span>eqn:rooti<span class="hl opt">}</span> is always true.  If $a^<span class="hl opt">{</span>(p-<span class="hl num">1</span>)/<span class="hl num">2</span><span class="hl opt">}</span> - <span class="hl num">1</span> <span class="hl kwa">\equiv</span> <span class="hl num">0</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$
then the quantity in the braces must be zero.  By reduction,

<span class="hl kwa">\begin</span><span class="hl opt">{</span>eqnarray<span class="hl opt">}</span>
<span class="hl kwa">\left</span> (x^<span class="hl num">2</span> <span class="hl kwa">\right</span> )^<span class="hl opt">{</span>(p-<span class="hl num">1</span>)/<span class="hl num">2</span><span class="hl opt">}</span> - a^<span class="hl opt">{</span>(p-<span class="hl num">1</span>)/<span class="hl num">2</span><span class="hl opt">}</span> <span class="hl kwa">\equiv</span> <span class="hl num">0</span>  <span class="hl kwa">\nonumber</span> \\
<span class="hl kwa">\left</span> (x^<span class="hl num">2</span> <span class="hl kwa">\right</span> )^<span class="hl opt">{</span>(p-<span class="hl num">1</span>)/<span class="hl num">2</span><span class="hl opt">}</span> <span class="hl kwa">\equiv</span> a^<span class="hl opt">{</span>(p-<span class="hl num">1</span>)/<span class="hl num">2</span><span class="hl opt">}</span> <span class="hl kwa">\nonumber</span> \\
x^<span class="hl num">2</span> <span class="hl kwa">\equiv</span> a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span> 
<span class="hl kwa">\end</span><span class="hl opt">{</span>eqnarray<span class="hl opt">}</span>

As a result there must be a solution to the quadratic equation and in turn $a$ must be a quadratic residue.  If $a$ does not divide $p$ and $a$
is not a quadratic residue then the only other value $a^<span class="hl opt">{</span>(p-<span class="hl num">1</span>)/<span class="hl num">2</span><span class="hl opt">}</span>$ may be congruent to is $-<span class="hl num">1</span>$ since
<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
<span class="hl num">0</span> <span class="hl kwa">\equiv</span> a^<span class="hl opt">{</span>p - <span class="hl num">1</span><span class="hl opt">}</span> - <span class="hl num">1</span> <span class="hl kwa">\equiv</span> (a^<span class="hl opt">{</span>(p-<span class="hl num">1</span>)/<span class="hl num">2</span><span class="hl opt">}</span> + <span class="hl num">1</span>)(a^<span class="hl opt">{</span>(p-<span class="hl num">1</span>)/<span class="hl num">2</span><span class="hl opt">}</span> - <span class="hl num">1</span>) <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
One of the terms on the right hand side must be zero.  <span class="hl kwa">\textbf</span><span class="hl opt">{</span>QED<span class="hl opt">}</span>

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Jacobi Symbol<span class="hl opt">}</span>
The Jacobi symbol is a generalization of the Legendre function for any odd non prime moduli $p$ greater than <span class="hl num">2</span>.  If $p = <span class="hl kwa">\prod_</span><span class="hl opt">{</span>i=<span class="hl num">0</span><span class="hl opt">}</span>^n p_i$ then
the Jacobi symbol $<span class="hl kwa">\left</span> ( <span class="hl opt">{</span> a <span class="hl kwa">\over</span> p <span class="hl opt">}</span> <span class="hl kwa">\right</span> )$ is equal to the following equation.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
<span class="hl kwa">\left</span> ( <span class="hl opt">{</span> a <span class="hl kwa">\over</span> p <span class="hl opt">}</span> <span class="hl kwa">\right</span> ) = <span class="hl kwa">\left</span> ( <span class="hl opt">{</span> a <span class="hl kwa">\over</span> p_0<span class="hl opt">}</span> <span class="hl kwa">\right</span> ) <span class="hl kwa">\left</span> ( <span class="hl opt">{</span> a <span class="hl kwa">\over</span> p_1<span class="hl opt">}</span> <span class="hl kwa">\right</span> ) <span class="hl kwa">\ldots \left</span> ( <span class="hl opt">{</span> a <span class="hl kwa">\over</span> p_n<span class="hl opt">}</span> <span class="hl kwa">\right</span> )
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

By inspection if $p$ is prime the Jacobi symbol is equivalent to the Legendre function.  The following facts<span class="hl kwa">\footnote</span><span class="hl opt">{</span>See HAC <span class="hl kwa">\cite</span><span class="hl opt">[</span>pp. <span class="hl num">72</span>-<span class="hl num">74</span><span class="hl opt">]{</span>HAC<span class="hl opt">}</span> for
further details.<span class="hl opt">}</span> will be used to derive an efficient Jacobi symbol algorithm.  Where $p$ is an odd integer greater than two and $a, b <span class="hl kwa">\in \Z</span>$ the
following are true.  

<span class="hl kwa">\begin</span><span class="hl opt">{</span>enumerate<span class="hl opt">}</span>
<span class="hl kwa">\item</span> $<span class="hl kwa">\left</span> ( <span class="hl opt">{</span> a <span class="hl kwa">\over</span> p<span class="hl opt">}</span> <span class="hl kwa">\right</span> )$ equals $-<span class="hl num">1</span>$, $<span class="hl num">0</span>$ or $<span class="hl num">1</span>$. 
<span class="hl kwa">\item</span> $<span class="hl kwa">\left</span> ( <span class="hl opt">{</span> ab <span class="hl kwa">\over</span> p<span class="hl opt">}</span> <span class="hl kwa">\right</span> ) = <span class="hl kwa">\left</span> ( <span class="hl opt">{</span> a <span class="hl kwa">\over</span> p<span class="hl opt">}</span> <span class="hl kwa">\right</span> )<span class="hl kwa">\left</span> ( <span class="hl opt">{</span> b <span class="hl kwa">\over</span> p<span class="hl opt">}</span> <span class="hl kwa">\right</span> )$.
<span class="hl kwa">\item</span> If $a <span class="hl kwa">\equiv</span> b$ then $<span class="hl kwa">\left</span> ( <span class="hl opt">{</span> a <span class="hl kwa">\over</span> p<span class="hl opt">}</span> <span class="hl kwa">\right</span> ) = <span class="hl kwa">\left</span> ( <span class="hl opt">{</span> b <span class="hl kwa">\over</span> p<span class="hl opt">}</span> <span class="hl kwa">\right</span> )$.
<span class="hl kwa">\item</span> $<span class="hl kwa">\left</span> ( <span class="hl opt">{</span> <span class="hl num">2</span> <span class="hl kwa">\over</span> p<span class="hl opt">}</span> <span class="hl kwa">\right</span> )$ equals $<span class="hl num">1</span>$ if $p <span class="hl kwa">\equiv</span> <span class="hl num">1</span>$ or $<span class="hl num">7</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">8</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$.  Otherwise, it equals $-<span class="hl num">1</span>$.
<span class="hl kwa">\item</span> $<span class="hl kwa">\left</span> ( <span class="hl opt">{</span> a <span class="hl kwa">\over</span> p<span class="hl opt">}</span> <span class="hl kwa">\right</span> ) <span class="hl kwa">\equiv \left</span> ( <span class="hl opt">{</span> p <span class="hl kwa">\over</span> a<span class="hl opt">}</span> <span class="hl kwa">\right</span> ) <span class="hl kwa">\cdot</span> (-<span class="hl num">1</span>)^<span class="hl opt">{</span>(p-<span class="hl num">1</span>)(a-<span class="hl num">1</span>)/<span class="hl num">4</span><span class="hl opt">}</span>$.  More specifically 
$<span class="hl kwa">\left</span> ( <span class="hl opt">{</span> a <span class="hl kwa">\over</span> p<span class="hl opt">}</span> <span class="hl kwa">\right</span> ) = <span class="hl kwa">\left</span> ( <span class="hl opt">{</span> p <span class="hl kwa">\over</span> a<span class="hl opt">}</span> <span class="hl kwa">\right</span> )$ if $p <span class="hl kwa">\equiv</span> a <span class="hl kwa">\equiv</span> <span class="hl num">1</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">4</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$.  
<span class="hl kwa">\end</span><span class="hl opt">{</span>enumerate<span class="hl opt">}</span>

Using these facts if $a = <span class="hl num">2</span>^k <span class="hl kwa">\cdot</span> a'$ then

<span class="hl kwa">\begin</span><span class="hl opt">{</span>eqnarray<span class="hl opt">}</span>
<span class="hl kwa">\left</span> ( <span class="hl opt">{</span> a <span class="hl kwa">\over</span> p <span class="hl opt">}</span> <span class="hl kwa">\right</span> ) = <span class="hl kwa">\left</span> ( <span class="hl opt">{{</span><span class="hl num">2</span>^k<span class="hl opt">}</span> <span class="hl kwa">\over</span> p <span class="hl opt">}</span> <span class="hl kwa">\right</span> ) <span class="hl kwa">\left</span> ( <span class="hl opt">{</span>a' <span class="hl kwa">\over</span> p<span class="hl opt">}</span> <span class="hl kwa">\right</span> ) <span class="hl kwa">\nonumber</span> \\
                               = <span class="hl kwa">\left</span> ( <span class="hl opt">{</span><span class="hl num">2</span> <span class="hl kwa">\over</span> p <span class="hl opt">}</span> <span class="hl kwa">\right</span> )^k <span class="hl kwa">\left</span> ( <span class="hl opt">{</span>a' <span class="hl kwa">\over</span> p<span class="hl opt">}</span> <span class="hl kwa">\right</span> ) 
<span class="hl kwa">\label</span><span class="hl opt">{</span>eqn:jacobi<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>eqnarray<span class="hl opt">}</span>

By fact five, 

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
<span class="hl kwa">\left</span> ( <span class="hl opt">{</span> a <span class="hl kwa">\over</span> p <span class="hl opt">}</span> <span class="hl kwa">\right</span> ) = <span class="hl kwa">\left</span> ( <span class="hl opt">{</span> p <span class="hl kwa">\over</span> a <span class="hl opt">}</span> <span class="hl kwa">\right</span> ) <span class="hl kwa">\cdot</span> (-<span class="hl num">1</span>)^<span class="hl opt">{</span>(p-<span class="hl num">1</span>)(a-<span class="hl num">1</span>)/<span class="hl num">4</span><span class="hl opt">}</span> 
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

Subsequently by fact three since $p <span class="hl kwa">\equiv</span> (p <span class="hl kwa">\mbox</span><span class="hl opt">{</span> mod <span class="hl opt">}</span>a) <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>a<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ then 

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
<span class="hl kwa">\left</span> ( <span class="hl opt">{</span> a <span class="hl kwa">\over</span> p <span class="hl opt">}</span> <span class="hl kwa">\right</span> ) = <span class="hl kwa">\left</span> ( <span class="hl opt">{ {</span>p <span class="hl kwa">\mbox</span><span class="hl opt">{</span> mod <span class="hl opt">}</span> a<span class="hl opt">}</span> <span class="hl kwa">\over</span> a <span class="hl opt">}</span> <span class="hl kwa">\right</span> ) <span class="hl kwa">\cdot</span> (-<span class="hl num">1</span>)^<span class="hl opt">{</span>(p-<span class="hl num">1</span>)(a-<span class="hl num">1</span>)/<span class="hl num">4</span><span class="hl opt">}</span> 
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

By putting both observations into equation <span class="hl kwa">\ref</span><span class="hl opt">{</span>eqn:jacobi<span class="hl opt">}</span> the following simplified equation is formed.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
<span class="hl kwa">\left</span> ( <span class="hl opt">{</span> a <span class="hl kwa">\over</span> p <span class="hl opt">}</span> <span class="hl kwa">\right</span> ) = <span class="hl kwa">\left</span> ( <span class="hl opt">{</span><span class="hl num">2</span> <span class="hl kwa">\over</span> p <span class="hl opt">}</span> <span class="hl kwa">\right</span> )^k <span class="hl kwa">\left</span> ( <span class="hl opt">{{</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span> mod <span class="hl opt">}</span>a'<span class="hl opt">}</span> <span class="hl kwa">\over</span> a'<span class="hl opt">}</span> <span class="hl kwa">\right</span> )  <span class="hl kwa">\cdot</span> (-<span class="hl num">1</span>)^<span class="hl opt">{</span>(p-<span class="hl num">1</span>)(a'-<span class="hl num">1</span>)/<span class="hl num">4</span><span class="hl opt">}</span> 
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

The value of $<span class="hl kwa">\left</span> ( <span class="hl opt">{{</span>p <span class="hl kwa">\mbox</span><span class="hl opt">{</span> mod <span class="hl opt">}</span>a'<span class="hl opt">}</span> <span class="hl kwa">\over</span> a'<span class="hl opt">}</span> <span class="hl kwa">\right</span> )$ can be found by using the same equation recursively.  The value of 
$<span class="hl kwa">\left</span> ( <span class="hl opt">{</span><span class="hl num">2</span> <span class="hl kwa">\over</span> p <span class="hl opt">}</span> <span class="hl kwa">\right</span> )^k$ equals $<span class="hl num">1</span>$ if $k$ is even otherwise it equals $<span class="hl kwa">\left</span> ( <span class="hl opt">{</span><span class="hl num">2</span> <span class="hl kwa">\over</span> p <span class="hl opt">}</span> <span class="hl kwa">\right</span> )$.  Using this approach the 
factors of $p$ do not have to be known.  Furthermore, if $(a, p) = <span class="hl num">1</span>$ then the algorithm will terminate when the recursion requests the 
Jacobi symbol computation of $<span class="hl kwa">\left</span> ( <span class="hl opt">{</span><span class="hl num">1</span> <span class="hl kwa">\over</span> a'<span class="hl opt">}</span> <span class="hl kwa">\right</span> )$ which is simply $<span class="hl num">1</span>$.  

<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_jacobi</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$ and $p$, $a <span class="hl kwa">\ge</span> <span class="hl num">0</span>$, $p <span class="hl kwa">\ge</span> <span class="hl num">3</span>$, $p <span class="hl kwa">\equiv</span> <span class="hl num">1</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  The Jacobi symbol $c = <span class="hl kwa">\left</span> ( <span class="hl opt">{</span>a <span class="hl kwa">\over</span> p <span class="hl opt">}</span> <span class="hl kwa">\right</span> )$. \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  If $a = <span class="hl num">0</span>$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.1</span>  $c <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.2</span>  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl num">2</span>.  If $a = <span class="hl num">1</span>$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  $c <span class="hl kwa">\leftarrow</span> <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.2</span>  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl num">3</span>.  $a' <span class="hl kwa">\leftarrow</span> a$ \\
<span class="hl num">4</span>.  $k <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">5</span>.  While $a'.used &gt; <span class="hl num">0</span>$ and $a'_0 <span class="hl kwa">\equiv</span> <span class="hl num">0</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.1</span>  $k <span class="hl kwa">\leftarrow</span> k + <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">5.2</span>  $a' <span class="hl kwa">\leftarrow \lfloor</span> a' / <span class="hl num">2</span> <span class="hl kwa">\rfloor</span>$ \\
<span class="hl num">6</span>.  If $k <span class="hl kwa">\equiv</span> <span class="hl num">0</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.1</span>  $s <span class="hl kwa">\leftarrow</span> <span class="hl num">1</span>$ \\
<span class="hl num">7</span>.  else \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.1</span>  $r <span class="hl kwa">\leftarrow</span> p_0 <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">8</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.2</span>  If $r = <span class="hl num">1</span>$ or $r = <span class="hl num">7</span>$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">7.2.1</span>  $s <span class="hl kwa">\leftarrow</span> <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.3</span>  else \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">7.3.1</span>  $s <span class="hl kwa">\leftarrow</span> -<span class="hl num">1</span>$ \\
<span class="hl num">8</span>.  If $p_0 <span class="hl kwa">\equiv</span> a'_0 <span class="hl kwa">\equiv</span> <span class="hl num">3</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">4</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">8.1</span>  $s <span class="hl kwa">\leftarrow</span> -s$ \\
<span class="hl num">9</span>.  If $a' <span class="hl kwa">\ne</span> <span class="hl num">1</span>$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">9.1</span>  $p' <span class="hl kwa">\leftarrow</span> p <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>a'<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">9.2</span>  $s <span class="hl kwa">\leftarrow</span> s <span class="hl kwa">\cdot \mbox</span><span class="hl opt">{</span>mp<span class="hl kwa">\_jacobi</span><span class="hl opt">}</span>(p', a')$ \\
<span class="hl num">10</span>.  $c <span class="hl kwa">\leftarrow</span> s$ \\
<span class="hl num">11</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_jacobi</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_jacobi</span>.<span class="hl opt">}</span>
This algorithm computes the Jacobi symbol for an arbitrary positive integer $a$ with respect to an odd integer $p$ greater than three.  The algorithm
is based on algorithm <span class="hl num">2.149</span> of HAC <span class="hl kwa">\cite</span><span class="hl opt">[</span>pp. <span class="hl num">73</span><span class="hl opt">]{</span>HAC<span class="hl opt">}</span>.  

Step numbers one and two handle the trivial cases of $a = <span class="hl num">0</span>$ and $a = <span class="hl num">1</span>$ respectively.  Step five determines the number of two factors in the
input $a$.  If $k$ is even than the term $<span class="hl kwa">\left</span> ( <span class="hl opt">{</span> <span class="hl num">2</span> <span class="hl kwa">\over</span> p <span class="hl opt">}</span> <span class="hl kwa">\right</span> )^k$ must always evaluate to one.  If $k$ is odd than the term evaluates to one 
if $p_0$ is congruent to one or seven modulo eight, otherwise it evaluates to $-<span class="hl num">1</span>$. After the the $<span class="hl kwa">\left</span> ( <span class="hl opt">{</span> <span class="hl num">2</span> <span class="hl kwa">\over</span> p <span class="hl opt">}</span> <span class="hl kwa">\right</span> )^k$ term is handled 
the $(-<span class="hl num">1</span>)^<span class="hl opt">{</span>(p-<span class="hl num">1</span>)(a'-<span class="hl num">1</span>)/<span class="hl num">4</span><span class="hl opt">}</span>$ is computed and multiplied against the current product $s$.  The latter term evaluates to one if both $p$ and $a'$ 
are congruent to one modulo four, otherwise it evaluates to negative one.

By step nine if $a'$ does not equal one a recursion is required.  Step <span class="hl num">9.1</span> computes $p' <span class="hl kwa">\equiv</span> p <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>a'<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ and will recurse to compute
$<span class="hl kwa">\left</span> ( <span class="hl opt">{</span>p' <span class="hl kwa">\over</span> a'<span class="hl opt">}</span> <span class="hl kwa">\right</span> )$ which is multiplied against the current Jacobi product.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_jacobi</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

As a matter of practicality the variable $a'$ as per the pseudo-code is reprensented by the variable $a1$ since the $'$ symbol is not valid for a C 
variable name character. 

The two simple cases of $a = <span class="hl num">0</span>$ and $a = <span class="hl num">1</span>$ are handled at the very beginning to simplify the algorithm.  If the input is non-trivial the algorithm
has to proceed compute the Jacobi.  The variable $s$ is used to hold the current Jacobi product.  Note that $s$ is merely a C ``int'' data type since
the values it may obtain are merely $-<span class="hl num">1</span>$, $<span class="hl num">0</span>$ and $<span class="hl num">1</span>$.  

After a local copy of $a$ is made all of the factors of two are divided out and the total stored in $k$.  Technically only the least significant
bit of $k$ is required, however, it makes the algorithm simpler to follow to perform an addition. In practice an exclusive-or and addition have the same 
processor requirements and neither is faster than the other.

Line <span class="hl num">58</span> through <span class="hl num">71</span> determines the value of $<span class="hl kwa">\left</span> ( <span class="hl opt">{</span> <span class="hl num">2</span> <span class="hl kwa">\over</span> p <span class="hl opt">}</span> <span class="hl kwa">\right</span> )^k$.  If the least significant bit of $k$ is zero than
$k$ is even and the value is one.  Otherwise, the value of $s$ depends on which residue class $p$ belongs to modulo eight.  The value of
$(-<span class="hl num">1</span>)^<span class="hl opt">{</span>(p-<span class="hl num">1</span>)(a'-<span class="hl num">1</span>)/<span class="hl num">4</span><span class="hl opt">}</span>$ is compute and multiplied against $s$ on lines <span class="hl num">71</span> through <span class="hl num">74</span>.  

Finally, if $a1$ does not equal one the algorithm must recurse and compute $<span class="hl kwa">\left</span> ( <span class="hl opt">{</span>p' <span class="hl kwa">\over</span> a'<span class="hl opt">}</span> <span class="hl kwa">\right</span> )$.  

<span class="hl kwa">\textit</span><span class="hl opt">{</span>-- Comment about default $s$ and such...<span class="hl opt">}</span>

<span class="hl kwa">\section</span><span class="hl opt">{</span>Modular Inverse<span class="hl opt">}</span>
<span class="hl kwa">\label</span><span class="hl opt">{</span>sec:modinv<span class="hl opt">}</span>
The modular inverse of a number actually refers to the modular multiplicative inverse.  Essentially for any integer $a$ such that $(a, p) = <span class="hl num">1</span>$ there
exist another integer $b$ such that $ab <span class="hl kwa">\equiv</span> <span class="hl num">1</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$.  The integer $b$ is called the multiplicative inverse of $a$ which is
denoted as $b = a^<span class="hl opt">{</span>-<span class="hl num">1</span><span class="hl opt">}</span>$.  Technically speaking modular inversion is a well defined operation for any finite ring or field not just for rings and 
fields of integers.  However, the former will be the matter of discussion.

The simplest approach is to compute the algebraic inverse of the input.  That is to compute $b <span class="hl kwa">\equiv</span> a^<span class="hl opt">{</span><span class="hl kwa">\Phi</span>(p) - <span class="hl num">1</span><span class="hl opt">}</span>$.  If $<span class="hl kwa">\Phi</span>(p)$ is the 
order of the multiplicative subgroup modulo $p$ then $b$ must be the multiplicative inverse of $a$.  The proof of which is trivial.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
ab <span class="hl kwa">\equiv</span> a <span class="hl kwa">\left</span> (a^<span class="hl opt">{</span><span class="hl kwa">\Phi</span>(p) - <span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\right</span> ) <span class="hl kwa">\equiv</span> a^<span class="hl opt">{</span><span class="hl kwa">\Phi</span>(p)<span class="hl opt">}</span> <span class="hl kwa">\equiv</span> a^<span class="hl num">0</span> <span class="hl kwa">\equiv</span> <span class="hl num">1</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>p<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

However, as simple as this approach may be it has two serious flaws.  It requires that the value of $<span class="hl kwa">\Phi</span>(p)$ be known which if $p$ is composite 
requires all of the prime factors.  This approach also is very slow as the size of $p$ grows.  

A simpler approach is based on the observation that solving for the multiplicative inverse is equivalent to solving the linear 
Diophantine<span class="hl kwa">\footnote</span><span class="hl opt">{</span>See LeVeque <span class="hl kwa">\cite</span><span class="hl opt">[</span>pp. <span class="hl num">40</span>-<span class="hl num">43</span><span class="hl opt">]{</span>LeVeque<span class="hl opt">}</span> for more information.<span class="hl opt">}</span> equation.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
ab + pq = <span class="hl num">1</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

Where $a$, $b$, $p$ and $q$ are all integers.  If such a pair of integers $ <span class="hl kwa">\left</span> &lt; b, q <span class="hl kwa">\right</span> &gt;$ exist than $b$ is the multiplicative inverse of 
$a$ modulo $p$.  The extended Euclidean algorithm (Knuth <span class="hl kwa">\cite</span><span class="hl opt">[</span>pp. <span class="hl num">342</span><span class="hl opt">]{</span>TAOCPV2<span class="hl opt">}</span>) can be used to solve such equations provided $(a, p) = <span class="hl num">1</span>$.  
However, instead of using that algorithm directly a variant known as the binary Extended Euclidean algorithm will be used in its place.  The
binary approach is very similar to the binary greatest common divisor algorithm except it will produce a full solution to the Diophantine 
equation.  

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>General Case<span class="hl opt">}</span>
<span class="hl kwa">\newpage\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_invmod</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$ and $b$, $(a, b) = <span class="hl num">1</span>$, $p <span class="hl kwa">\ge</span> <span class="hl num">2</span>$, $<span class="hl num">0</span> &lt; a &lt; p$.  \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  The modular inverse $c <span class="hl kwa">\equiv</span> a^<span class="hl opt">{</span>-<span class="hl num">1</span><span class="hl opt">}</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>b<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$. \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  If $b <span class="hl kwa">\le</span> <span class="hl num">0</span>$ then return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_VAL</span><span class="hl opt">}</span>). \\
<span class="hl num">2</span>.  If $b_0 <span class="hl kwa">\equiv</span> <span class="hl num">1</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ then use algorithm fast<span class="hl kwa">\_mp\_invmod</span>. \\
<span class="hl num">3</span>.  $x <span class="hl kwa">\leftarrow \vert</span> a <span class="hl kwa">\vert</span>, y <span class="hl kwa">\leftarrow</span> b$ \\
<span class="hl num">4</span>.  If $x_0 <span class="hl kwa">\equiv</span> y_0  <span class="hl kwa">\equiv</span> <span class="hl num">0</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ then return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_VAL</span><span class="hl opt">}</span>). \\
<span class="hl num">5</span>.  $B <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>, C <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>, A <span class="hl kwa">\leftarrow</span> <span class="hl num">1</span>, D <span class="hl kwa">\leftarrow</span> <span class="hl num">1</span>$ \\
<span class="hl num">6</span>.  While $u.used &gt; <span class="hl num">0</span>$ and $u_0 <span class="hl kwa">\equiv</span> <span class="hl num">0</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.1</span>  $u <span class="hl kwa">\leftarrow \lfloor</span> u / <span class="hl num">2</span> <span class="hl kwa">\rfloor</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.2</span>  If ($A.used &gt; <span class="hl num">0</span>$ and $A_0 <span class="hl kwa">\equiv</span> <span class="hl num">1</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$) or ($B.used &gt; <span class="hl num">0</span>$ and $B_0 <span class="hl kwa">\equiv</span> <span class="hl num">1</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$) then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">6.2.1</span>  $A <span class="hl kwa">\leftarrow</span> A + y$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">6.2.2</span>  $B <span class="hl kwa">\leftarrow</span> B - x$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.3</span>  $A <span class="hl kwa">\leftarrow \lfloor</span> A / <span class="hl num">2</span> <span class="hl kwa">\rfloor</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.4</span>  $B <span class="hl kwa">\leftarrow \lfloor</span> B / <span class="hl num">2</span> <span class="hl kwa">\rfloor</span>$ \\
<span class="hl num">7</span>.  While $v.used &gt; <span class="hl num">0</span>$ and $v_0 <span class="hl kwa">\equiv</span> <span class="hl num">0</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.1</span>  $v <span class="hl kwa">\leftarrow \lfloor</span> v / <span class="hl num">2</span> <span class="hl kwa">\rfloor</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.2</span>  If ($C.used &gt; <span class="hl num">0</span>$ and $C_0 <span class="hl kwa">\equiv</span> <span class="hl num">1</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$) or ($D.used &gt; <span class="hl num">0</span>$ and $D_0 <span class="hl kwa">\equiv</span> <span class="hl num">1</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$) then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">7.2.1</span>  $C <span class="hl kwa">\leftarrow</span> C + y$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">7.2.2</span>  $D <span class="hl kwa">\leftarrow</span> D - x$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.3</span>  $C <span class="hl kwa">\leftarrow \lfloor</span> C / <span class="hl num">2</span> <span class="hl kwa">\rfloor</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">7.4</span>  $D <span class="hl kwa">\leftarrow \lfloor</span> D / <span class="hl num">2</span> <span class="hl kwa">\rfloor</span>$ \\
<span class="hl num">8</span>.  If $u <span class="hl kwa">\ge</span> v$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">8.1</span>  $u <span class="hl kwa">\leftarrow</span> u - v$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">8.2</span>  $A <span class="hl kwa">\leftarrow</span> A - C$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">8.3</span>  $B <span class="hl kwa">\leftarrow</span> B - D$ \\
<span class="hl num">9</span>.  else \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">9.1</span>  $v <span class="hl kwa">\leftarrow</span> v - u$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">9.2</span>  $C <span class="hl kwa">\leftarrow</span> C - A$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">9.3</span>  $D <span class="hl kwa">\leftarrow</span> D - B$ \\
<span class="hl num">10</span>.  If $u <span class="hl kwa">\ne</span> <span class="hl num">0</span>$ goto step <span class="hl num">6</span>. \\
<span class="hl num">11</span>.  If $v <span class="hl kwa">\ne</span> <span class="hl num">1</span>$ return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_VAL</span><span class="hl opt">}</span>). \\
<span class="hl num">12</span>.  While $C <span class="hl kwa">\le</span> <span class="hl num">0</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">12.1</span>  $C <span class="hl kwa">\leftarrow</span> C + b$ \\
<span class="hl num">13</span>.  While $C <span class="hl kwa">\ge</span> b$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">13.1</span>  $C <span class="hl kwa">\leftarrow</span> C - b$ \\
<span class="hl num">14</span>.  $c <span class="hl kwa">\leftarrow</span> C$ \\
<span class="hl num">15</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_invmod</span>.<span class="hl opt">}</span>
This algorithm computes the modular multiplicative inverse of an integer $a$ modulo an integer $b$.  This algorithm is a variation of the 
extended binary Euclidean algorithm from HAC <span class="hl kwa">\cite</span><span class="hl opt">[</span>pp. <span class="hl num">608</span><span class="hl opt">]{</span>HAC<span class="hl opt">}</span>.  It has been modified to only compute the modular inverse and not a complete
Diophantine solution.  

If $b <span class="hl kwa">\le</span> <span class="hl num">0</span>$ than the modulus is invalid and MP<span class="hl kwa">\_VAL</span> is returned.  Similarly if both $a$ and $b$ are even then there cannot be a multiplicative
inverse for $a$ and the error is reported.  

The astute reader will observe that steps seven through nine are very similar to the binary greatest common divisor algorithm mp<span class="hl kwa">\_gcd</span>.  In this case
the other variables to the Diophantine equation are solved.  The algorithm terminates when $u = <span class="hl num">0</span>$ in which case the solution is

<span class="hl kwa">\begin</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>
Ca + Db = v
<span class="hl kwa">\end</span><span class="hl opt">{</span>equation<span class="hl opt">}</span>

If $v$, the greatest common divisor of $a$ and $b$ is not equal to one then the algorithm will <span class="hl kwb">report</span> an error as no inverse exists.  Otherwise, $C$
is the modular inverse of $a$.  The actual value of $C$ is congruent to, but not necessarily equal to, the ideal modular inverse which should lie 
within $<span class="hl num">1</span> <span class="hl kwa">\le</span> a^<span class="hl opt">{</span>-<span class="hl num">1</span><span class="hl opt">}</span> &lt; b$.  Step numbers twelve and thirteen adjust the inverse until it is in range.  If the original input $a$ is within $<span class="hl num">0</span> &lt; a &lt; p$ 
then only a couple of additions or subtractions will be required to adjust the inverse.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_invmod</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

<span class="hl kwa">\subsubsection</span><span class="hl opt">{</span>Odd Moduli<span class="hl opt">}</span>

When the modulus $b$ is odd the variables $A$ and $C$ are fixed and are not required to compute the inverse.  In particular by attempting to solve
the Diophantine $Cb + Da = <span class="hl num">1</span>$ only $B$ and $D$ are required to find the inverse of $a$.  

The algorithm fast<span class="hl kwa">\_mp\_invmod</span> is a direct adaptation of algorithm mp<span class="hl kwa">\_invmod</span> with all all steps involving either $A$ or $C$ removed.  This 
optimization will halve the time required to compute the modular inverse.

<span class="hl kwa">\section</span><span class="hl opt">{</span>Primality Tests<span class="hl opt">}</span>

A non-zero integer $a$ is said to be prime if it is not divisible by any other integer excluding one and itself.  For example, $a = <span class="hl num">7</span>$ is prime 
since the integers $<span class="hl num">2</span> <span class="hl kwa">\ldots</span> <span class="hl num">6</span>$ do not evenly divide $a$.  By contrast, $a = <span class="hl num">6</span>$ is not prime since $a = <span class="hl num">6</span> = <span class="hl num">2</span> <span class="hl kwa">\cdot</span> <span class="hl num">3</span>$. 

Prime numbers arise in cryptography considerably as they allow finite fields to be formed.  The ability to determine whether an integer is prime or
not quickly has been a viable subject in cryptography and number theory for considerable time.  The algorithms that will be presented are all
probablistic algorithms in that when they <span class="hl kwb">report</span> an integer is composite it must be composite.  However, when the algorithms <span class="hl kwb">report</span> an integer is
prime the algorithm may be incorrect.  

As will be discussed it is possible to limit the probability of error so well that for practical purposes the probablity of error might as 
well be zero.  For the purposes of these discussions let $n$ represent the candidate integer of which the primality is in question.

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>Trial Division<span class="hl opt">}</span>

Trial division means to attempt to evenly divide a candidate integer by small prime integers.  If the candidate can be evenly divided it obviously
cannot be prime.  By dividing by all primes $<span class="hl num">1</span> &lt; p <span class="hl kwa">\le \sqrt</span><span class="hl opt">{</span>n<span class="hl opt">}</span>$ this test can actually prove whether an integer is prime.  However, such a test
would require a prohibitive amount of time as $n$ grows.

Instead of dividing by every prime, a smaller, more mangeable set of primes may be used instead.  By performing trial division with only a subset
of the primes less than $<span class="hl kwa">\sqrt</span><span class="hl opt">{</span>n<span class="hl opt">}</span> + <span class="hl num">1</span>$ the algorithm cannot prove if a candidate is prime.  However, often it can prove a candidate is not prime.

The benefit of this test is that trial division by small values is fairly efficient.  Specially compared to the other algorithms that will be
discussed shortly.  The probability that this approach correctly identifies a composite candidate when tested with all primes upto $q$ is given by
$<span class="hl num">1</span> - <span class="hl opt">{</span><span class="hl num">1.12</span> <span class="hl kwa">\over</span> ln(q)<span class="hl opt">}</span>$.  The graph (<span class="hl kwa">\ref</span><span class="hl opt">{</span>pic:primality<span class="hl opt">}</span>, will be added later) demonstrates the probability of success for the range 
$<span class="hl num">3</span> <span class="hl kwa">\le</span> q <span class="hl kwa">\le</span> <span class="hl num">100</span>$.  

At approximately $q = <span class="hl num">30</span>$ the gain of performing further tests diminishes fairly quickly.  At $q = <span class="hl num">90</span>$ further testing is generally not going to 
be of any practical use.  In the case of LibTomMath the default limit $q = <span class="hl num">256</span>$ was chosen since it is not too high and will eliminate 
approximately $<span class="hl num">80</span>\%$ of all candidate integers.  The constant <span class="hl kwa">\textbf</span><span class="hl opt">{</span>PRIME<span class="hl kwa">\_SIZE</span><span class="hl opt">}</span> is equal to the number of primes in the test base.  The 
array <span class="hl kwa">\_\_prime\_tab</span> is an array of the first <span class="hl kwa">\textbf</span><span class="hl opt">{</span>PRIME<span class="hl kwa">\_SIZE</span><span class="hl opt">}</span> prime numbers.  

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_prime\_is\_divisible</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$ \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $c = <span class="hl num">1</span>$ if $n$ is divisible by a small prime, otherwise $c = <span class="hl num">0</span>$.  \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  for $ix$ from $<span class="hl num">0</span>$ to $PRIME<span class="hl kwa">\_SIZE</span>$ do \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.1</span>  $d <span class="hl kwa">\leftarrow</span> n <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl kwa">\_\_prime\_tab_</span><span class="hl opt">{</span>ix<span class="hl opt">}</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">1.2</span>  If $d = <span class="hl num">0</span>$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">1.2.1</span>  $c <span class="hl kwa">\leftarrow</span> <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">1.2.2</span>  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl num">2</span>.  $c <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">3</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_prime\_is\_divisible</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_prime\_is\_divisible</span>.<span class="hl opt">}</span>
This algorithm attempts to determine if a candidate integer $n$ is composite by performing trial divisions.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_prime\_is\_divisible</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

The algorithm defaults to a return of $<span class="hl num">0</span>$ in case an error occurs.  The values in the prime table are all specified to be in the range of a 
mp<span class="hl kwa">\_digit</span>.  The table <span class="hl kwa">\_\_prime\_tab</span> is defined in the following file.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_prime\_tab</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

Note that there are two possible tables.  When an mp<span class="hl kwa">\_digit</span> is <span class="hl num">7</span>-bits long only the primes upto $<span class="hl num">127</span>$ may be included, otherwise the primes
upto $<span class="hl num">1619</span>$ are used.  Note that the value of <span class="hl kwa">\textbf</span><span class="hl opt">{</span>PRIME<span class="hl kwa">\_SIZE</span><span class="hl opt">}</span> is a constant dependent on the size of a mp<span class="hl kwa">\_digit</span>. 

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>The Fermat Test<span class="hl opt">}</span>
The Fermat test is probably one the oldest tests to have a non-trivial probability of success.  It is based on the fact that if $n$ is in 
fact prime then $a^<span class="hl opt">{</span>n<span class="hl opt">}</span> <span class="hl kwa">\equiv</span> a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>n<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ for all $<span class="hl num">0</span> &lt; a &lt; n$.  The reason being that if $n$ is prime than the order of
the multiplicative sub group is $n - <span class="hl num">1</span>$.  Any base $a$ must have an order which divides $n - <span class="hl num">1</span>$ and as such $a^n$ is equivalent to 
$a^<span class="hl num">1</span> = a$.  

If $n$ is composite then any given base $a$ does not have to have a period which divides $n - <span class="hl num">1</span>$.  In which case 
it is possible that $a^n <span class="hl kwa">\nequiv</span> a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>n<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$.  However, this test is not absolute as it is possible that the order
of a base will divide $n - <span class="hl num">1</span>$ which would then be reported as prime.  Such a base yields what is known as a Fermat pseudo-prime.  Several 
integers known as Carmichael numbers will be a pseudo-prime to all valid bases.  Fortunately such numbers are extremely rare as $n$ grows
in size.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_prime\_fermat</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$ and $b$, $a <span class="hl kwa">\ge</span> <span class="hl num">2</span>$, $<span class="hl num">0</span> &lt; b &lt; a$.  \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $c = <span class="hl num">1</span>$ if $b^a <span class="hl kwa">\equiv</span> b <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>a<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$, otherwise $c = <span class="hl num">0</span>$.  \\
<span class="hl kwa">\hline</span> \\
<span class="hl num">1</span>.  $t <span class="hl kwa">\leftarrow</span> b^a <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>a<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl num">2</span>.  If $t = b$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">2.1</span>  $c = <span class="hl num">1</span>$ \\
<span class="hl num">3</span>.  else \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">3.1</span>  $c = <span class="hl num">0</span>$ \\
<span class="hl num">4</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_prime\_fermat</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_prime\_fermat</span>.<span class="hl opt">}</span>
This algorithm determines whether an mp<span class="hl kwa">\_int</span> $a$ is a Fermat prime to the base $b$ or not.  It uses a single modular exponentiation to
determine the result.  

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_prime\_fermat</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>

<span class="hl kwa">\subsection</span><span class="hl opt">{</span>The Miller-Rabin Test<span class="hl opt">}</span>
The Miller-Rabin (citation) test is another primality test which has tighter error bounds than the Fermat test specifically with sequentially chosen 
candidate  integers.  The algorithm is based on the observation that if $n - <span class="hl num">1</span> = <span class="hl num">2</span>^kr$ and if $b^r <span class="hl kwa">\nequiv \pm</span> <span class="hl num">1</span>$ then after upto $k - <span class="hl num">1</span>$ squarings the 
value must be equal to $-<span class="hl num">1</span>$.  The squarings are stopped as soon as $-<span class="hl num">1</span>$ is observed.  If the value of $<span class="hl num">1</span>$ is observed first it means that
some value not congruent to $<span class="hl kwa">\pm</span> <span class="hl num">1</span>$ when squared equals one which cannot occur if $n$ is prime.

<span class="hl kwa">\begin</span><span class="hl opt">{</span>figure<span class="hl opt">}[</span>!here<span class="hl opt">]</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>tabular<span class="hl opt">}{</span>l<span class="hl opt">}</span>
<span class="hl kwa">\hline</span> Algorithm <span class="hl kwa">\textbf</span><span class="hl opt">{</span>mp<span class="hl kwa">\_prime\_miller\_rabin</span><span class="hl opt">}</span>. \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Input<span class="hl opt">}</span>.   mp<span class="hl kwa">\_int</span> $a$ and $b$, $a <span class="hl kwa">\ge</span> <span class="hl num">2</span>$, $<span class="hl num">0</span> &lt; b &lt; a$.  \\
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Output<span class="hl opt">}</span>.  $c = <span class="hl num">1</span>$ if $a$ is a Miller-Rabin prime to the base $a$, otherwise $c = <span class="hl num">0</span>$.  \\
<span class="hl kwa">\hline</span>
<span class="hl num">1</span>.  $a' <span class="hl kwa">\leftarrow</span> a - <span class="hl num">1</span>$ \\
<span class="hl num">2</span>.  $r  <span class="hl kwa">\leftarrow</span> n1$    \\
<span class="hl num">3</span>.  $c <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>, s  <span class="hl kwa">\leftarrow</span> <span class="hl num">0</span>$ \\
<span class="hl num">4</span>.  While $r.used &gt; <span class="hl num">0</span>$ and $r_0 <span class="hl kwa">\equiv</span> <span class="hl num">0</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span><span class="hl num">2</span><span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.1</span>  $s <span class="hl kwa">\leftarrow</span> s + <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">4.2</span>  $r <span class="hl kwa">\leftarrow \lfloor</span> r / <span class="hl num">2</span> <span class="hl kwa">\rfloor</span>$ \\
<span class="hl num">5</span>.  $y <span class="hl kwa">\leftarrow</span> b^r <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>a<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl num">6</span>.  If $y <span class="hl kwa">\nequiv \pm</span> <span class="hl num">1</span>$ then \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.1</span>  $j <span class="hl kwa">\leftarrow</span> <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.2</span>  While $j <span class="hl kwa">\le</span> (s - <span class="hl num">1</span>)$ and $y <span class="hl kwa">\nequiv</span> a'$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">6.2.1</span>  $y <span class="hl kwa">\leftarrow</span> y^<span class="hl num">2</span> <span class="hl kwa">\mbox</span><span class="hl opt">{</span> (mod <span class="hl opt">}</span>a<span class="hl kwa">\mbox</span><span class="hl opt">{</span>)<span class="hl opt">}</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">6.2.2</span>  If $y = <span class="hl num">1</span>$ then goto step <span class="hl num">8</span>. \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">6</span>mm<span class="hl opt">}</span><span class="hl num">6.2.3</span>  $j <span class="hl kwa">\leftarrow</span> j + <span class="hl num">1</span>$ \\
<span class="hl kwa">\hspace</span><span class="hl opt">{</span><span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl num">6.3</span>  If $y <span class="hl kwa">\nequiv</span> a'$ goto step <span class="hl num">8</span>. \\
<span class="hl num">7</span>.  $c <span class="hl kwa">\leftarrow</span> <span class="hl num">1</span>$\\
<span class="hl num">8</span>.  Return(<span class="hl kwa">\textit</span><span class="hl opt">{</span>MP<span class="hl kwa">\_OKAY</span><span class="hl opt">}</span>). \\
<span class="hl kwa">\hline</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>tabular<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>center<span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\caption</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_prime\_miller\_rabin</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>figure<span class="hl opt">}</span>
<span class="hl kwa">\textbf</span><span class="hl opt">{</span>Algorithm mp<span class="hl kwa">\_prime\_miller\_rabin</span>.<span class="hl opt">}</span>
This algorithm performs one trial round of the Miller-Rabin algorithm to the base $b$.  It will set $c = <span class="hl num">1</span>$ if the algorithm cannot determine
if $b$ is composite or $c = <span class="hl num">0</span>$ if $b$ is provably composite.  The values of $s$ and $r$ are computed such that $a' = a - <span class="hl num">1</span> = <span class="hl num">2</span>^sr$.  

If the value $y <span class="hl kwa">\equiv</span> b^r$ is congruent to $<span class="hl kwa">\pm</span> <span class="hl num">1</span>$ then the algorithm cannot prove if $a$ is composite or not.  Otherwise, the algorithm will
square $y$ upto $s - <span class="hl num">1</span>$ times stopping only when $y <span class="hl kwa">\equiv</span> -<span class="hl num">1</span>$.  If $y^<span class="hl num">2</span> <span class="hl kwa">\equiv</span> <span class="hl num">1</span>$ and $y <span class="hl kwa">\nequiv \pm</span> <span class="hl num">1</span>$ then the algorithm can <span class="hl kwb">report</span> that $a$
is provably composite.  If the algorithm performs $s - <span class="hl num">1</span>$ squarings and $y <span class="hl kwa">\nequiv</span> -<span class="hl num">1</span>$ then $a$ is provably composite.  If $a$ is not provably 
composite then it is <span class="hl kwa">\textit</span><span class="hl opt">{</span>probably<span class="hl opt">}</span> prime.

<span class="hl kwa">\vspace</span><span class="hl opt">{</span>+<span class="hl num">3</span>mm<span class="hl opt">}</span><span class="hl kwa">\begin</span><span class="hl opt">{</span>small<span class="hl opt">}</span>
<span class="hl kwa">\hspace</span><span class="hl opt">{</span>-<span class="hl num">5.1</span>mm<span class="hl opt">}{</span><span class="hl kwa">\bf</span> File<span class="hl opt">}</span>: bn<span class="hl kwa">\_mp\_prime\_miller\_rabin</span>.c
<span class="hl kwa">\vspace</span><span class="hl opt">{</span>-<span class="hl num">3</span>mm<span class="hl opt">}</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">alltt</span><span class="hl opt">}</span>
<span class="hl kwa">\end</span><span class="hl opt">{</span>small<span class="hl opt">}</span>




<span class="hl kwa">\backmatter</span>
<span class="hl kwa">\appendix</span>
<span class="hl kwa">\begin</span><span class="hl opt">{</span>thebibliography<span class="hl opt">}{</span>ABCDEF<span class="hl opt">}</span>
<span class="hl kwa">\bibitem</span><span class="hl opt">[</span><span class="hl num">1</span><span class="hl opt">]{</span>TAOCPV2<span class="hl opt">}</span>
Donald Knuth, <span class="hl kwa">\textit</span><span class="hl opt">{</span>The Art of Computer Programming<span class="hl opt">}</span>, Third Edition, Volume Two, Seminumerical Algorithms, Addison-Wesley, <span class="hl num">1998</span>

<span class="hl kwa">\bibitem</span><span class="hl opt">[</span><span class="hl num">2</span><span class="hl opt">]{</span>HAC<span class="hl opt">}</span>
A. Menezes, P. van Oorschot, S. Vanstone, <span class="hl kwa">\textit</span><span class="hl opt">{</span>Handbook of Applied Cryptography<span class="hl opt">}</span>, CRC Press, <span class="hl num">1996</span>

<span class="hl kwa">\bibitem</span><span class="hl opt">[</span><span class="hl num">3</span><span class="hl opt">]{</span>ROSE<span class="hl opt">}</span>
Michael Rosing, <span class="hl kwa">\textit</span><span class="hl opt">{</span>Implementing Elliptic Curve Cryptography<span class="hl opt">}</span>, Manning Publications, <span class="hl num">1999</span>

<span class="hl kwa">\bibitem</span><span class="hl opt">[</span><span class="hl num">4</span><span class="hl opt">]{</span>COMBA<span class="hl opt">}</span>
Paul G. Comba, <span class="hl kwa">\textit</span><span class="hl opt">{</span>Exponentiation Cryptosystems on the IBM PC<span class="hl opt">}</span>. IBM Systems Journal <span class="hl num">29</span>(<span class="hl num">4</span>): <span class="hl num">526</span>-<span class="hl num">538</span> (<span class="hl num">1990</span>)

<span class="hl kwa">\bibitem</span><span class="hl opt">[</span><span class="hl num">5</span><span class="hl opt">]{</span>KARA<span class="hl opt">}</span>
A. Karatsuba, Doklay Akad. Nauk SSSR <span class="hl num">145</span> (<span class="hl num">1962</span>), pp<span class="hl num">.293</span>-<span class="hl num">294</span>

<span class="hl kwa">\bibitem</span><span class="hl opt">[</span><span class="hl num">6</span><span class="hl opt">]{</span>KARAP<span class="hl opt">}</span>
Andre Weimerskirch and Christof Paar, <span class="hl kwa">\textit</span><span class="hl opt">{</span>Generalizations of the Karatsuba Algorithm for Polynomial Multiplication<span class="hl opt">}</span>, Submitted to Design, Codes and Cryptography, March <span class="hl num">2002</span>

<span class="hl kwa">\bibitem</span><span class="hl opt">[</span><span class="hl num">7</span><span class="hl opt">]{</span>BARRETT<span class="hl opt">}</span>
Paul Barrett, <span class="hl kwa">\textit</span><span class="hl opt">{</span>Implementing the Rivest Shamir and Adleman Public Key Encryption Algorithm on a Standard Digital Signal Processor<span class="hl opt">}</span>, Advances in Cryptology, Crypto '<span class="hl num">86</span>, Springer-Verlag.

<span class="hl kwa">\bibitem</span><span class="hl opt">[</span><span class="hl num">8</span><span class="hl opt">]{</span>MONT<span class="hl opt">}</span>
P.L.Montgomery. <span class="hl kwa">\textit</span><span class="hl opt">{</span>Modular multiplication without trial division<span class="hl opt">}</span>. Mathematics of Computation, <span class="hl num">44</span>(<span class="hl num">170</span>):<span class="hl num">519</span>-<span class="hl num">521</span>, April <span class="hl num">1985</span>.

<span class="hl kwa">\bibitem</span><span class="hl opt">[</span><span class="hl num">9</span><span class="hl opt">]{</span>DRMET<span class="hl opt">}</span>
Chae Hoon Lim and Pil Joong Lee, <span class="hl kwa">\textit</span><span class="hl opt">{</span>Generating Efficient Primes for Discrete Log Cryptosystems<span class="hl opt">}</span>, POSTECH Information Research Laboratories

<span class="hl kwa">\bibitem</span><span class="hl opt">[</span><span class="hl num">10</span><span class="hl opt">]{</span>MMB<span class="hl opt">}</span>
J. Daemen and R. Govaerts and J. Vandewalle, <span class="hl kwa">\textit</span><span class="hl opt">{</span>Block ciphers based on Modular Arithmetic<span class="hl opt">}</span>, State and <span class="hl opt">{</span>P<span class="hl opt">}</span>rogress in the <span class="hl opt">{</span>R<span class="hl opt">}</span>esearch of <span class="hl opt">{</span>C<span class="hl opt">}</span>ryptography, <span class="hl num">1993</span>, pp. <span class="hl num">80</span>-<span class="hl num">89</span>

<span class="hl kwa">\bibitem</span><span class="hl opt">[</span><span class="hl num">11</span><span class="hl opt">]{</span>RSAREF<span class="hl opt">}</span>
R.L. Rivest, A. Shamir, L. Adleman, <span class="hl kwa">\textit</span><span class="hl opt">{</span>A Method for Obtaining Digital Signatures and Public-Key Cryptosystems<span class="hl opt">}</span>

<span class="hl kwa">\bibitem</span><span class="hl opt">[</span><span class="hl num">12</span><span class="hl opt">]{</span>DHREF<span class="hl opt">}</span>
Whitfield Diffie, Martin E. Hellman, <span class="hl kwa">\textit</span><span class="hl opt">{</span>New Directions in Cryptography<span class="hl opt">}</span>, IEEE Transactions on Information Theory, <span class="hl num">1976</span>

<span class="hl kwa">\bibitem</span><span class="hl opt">[</span><span class="hl num">13</span><span class="hl opt">]{</span>IEEE<span class="hl opt">}</span>
IEEE Standard for Binary Floating-Point Arithmetic (ANSI/IEEE Std <span class="hl num">754</span>-<span class="hl num">1985</span>)

<span class="hl kwa">\bibitem</span><span class="hl opt">[</span><span class="hl num">14</span><span class="hl opt">]{</span>GMP<span class="hl opt">}</span>
GNU Multiple Precision (GMP), <span class="hl kwa">\url</span><span class="hl opt">{</span>http://www.swox.com/gmp/<span class="hl opt">}</span>

<span class="hl kwa">\bibitem</span><span class="hl opt">[</span><span class="hl num">15</span><span class="hl opt">]{</span>MPI<span class="hl opt">}</span>
Multiple Precision Integer Library (MPI), Michael Fromberger, <span class="hl kwa">\url</span><span class="hl opt">{</span>http://thayer.dartmouth.edu/~sting/mpi/<span class="hl opt">}</span>

<span class="hl kwa">\bibitem</span><span class="hl opt">[</span><span class="hl num">16</span><span class="hl opt">]{</span>OPENSSL<span class="hl opt">}</span>
OpenSSL Cryptographic Toolkit, <span class="hl kwa">\url</span><span class="hl opt">{</span>http://openssl.org<span class="hl opt">}</span>

<span class="hl kwa">\bibitem</span><span class="hl opt">[</span><span class="hl num">17</span><span class="hl opt">]{</span>LIP<span class="hl opt">}</span>
Large Integer Package, <span class="hl kwa">\url</span><span class="hl opt">{</span>http://home.hetnet.nl/~ecstr/LIP.zip<span class="hl opt">}</span>

<span class="hl kwa">\bibitem</span><span class="hl opt">[</span><span class="hl num">18</span><span class="hl opt">]{</span>ISOC<span class="hl opt">}</span>
JTC1/SC22/WG14, ISO/IEC <span class="hl num">9899</span>:<span class="hl num">1999</span>, ``A draft rationale for the C99 standard.''

<span class="hl kwa">\bibitem</span><span class="hl opt">[</span><span class="hl num">19</span><span class="hl opt">]{</span>JAVA<span class="hl opt">}</span>
The Sun Java Website, <span class="hl kwa">\url</span><span class="hl opt">{</span>http://java.sun.com/<span class="hl opt">}</span>

<span class="hl kwa">\end</span><span class="hl opt">{</span>thebibliography<span class="hl opt">}</span>

<span class="hl kwa">\input</span><span class="hl opt">{</span>tommath.ind<span class="hl opt">}</span>

<span class="hl kwa">\end</span><span class="hl opt">{</span><span class="hl kwb">document</span><span class="hl opt">}</span>
</code></pre></td></tr></table>
</div> <!-- class=content -->
<div class='footer'>generated by <a href='http://git.zx2c4.com/cgit/about/'>cgit v0.12</a> at 2024-11-05 11:25:55 (GMT)</div>
</div> <!-- id=cgit -->
</body>
</html>
