When he reached the age of twenty, his father decided to send him to Istanbul to his maternal family to study mathematics with scholars in the capital of the Ottoman Empire.
Ibn Hamza remained in Istanbul until the death of his father, when he resigned from his post to return to Algiers in order to take care of his widowed mother.
Once in Algeria, Ibn Hamza worked in his father's stalls for some time before deciding to resell them all as well as the family house to move with his mother to Mecca to make his Hajj pilgrimage and subsequently settle in the city.
During his stay in Mecca, during the Hijri year 999 (1591), his main work, a 512-page treatise on mathematics entitled Tohfat al-a'dad li-dwi al-rusd we-al-sedad (literally in Arabic: The treasury of numbers for those with reason and common sense) and written mainly in Ottoman Turkish (despite a title in Arabic).
[9] Pierre Ageron, studying superficially8 a copy of Ibn Hamza's manuscript in Ottoman Turkish, kept at the Süleymaniye Kütüphanesi library, and dated to the Hijri year 1013, highlights an example linking geometric progression and arithmetic progression: the first written in oriental Arabic numerals (۱ ۲ ٤ ۸ ۱٦ ۳۲ ٦٤ ۱۲۸), and the second in alphabetical numbers (ا ب ج د ه و ز ح).
Nevertheless we can note that, in the text in Ottoman Turkish, where Pierre Agero identifies the Arabic words us (exponent), dil'ayn (two sides) and a series of powers of 2 in oriental Arabic numerals and that of the corresponding exponents in numerals alphabetic, he was unable to read the actual text of the book because he did not master Ottoman Turkish.
[8]His treasure of numbers is known in Egypt and notably famous for the "problem of the palm trees", posed by an Indian scholar who was named Mollah Muhammad on the occasion of the great pilgrimage to Mecca in the year 998 of the Hijrah.
This problem can be solved by means of a magic square of order n, the properties of which were still known in the Muslim world at the time as shown in the treatise drawn up by the Egyptian Muhammad Shabrâmallisî in the 17th century.