Showing posts with label Google. Show all posts
Showing posts with label Google. Show all posts

Monday, 2 June 2025

Google AI Studio and Related Disasters

I created a program in a Jupyter notebook that accepts a single number as input and then displays various properties of the number as a simple text output. I put the following prompt to Google's AI Studio:

The following code is what I created using SageMath. It is designed to accept a single number as input. Typically the number has five digits corresponding to my age in days (I'm currently 27819 days old). I'm using the program to find out interesting numerical facts about this number associated with my diurnal age. By trial and error I've had to limit the number of iterations for various tasks or else the program is too slow or crashes. For example, in finding the home prime for a number I've limited the iterations to just 10. What I want is to improve the output of this code to make it more readable and more informative in terms of additional graphs or charts? Feel free to modify the code to make it more efficient, informative or comprehensible. The code modifications can be in Python or SageMath, whatever is easier for you. I just need the program to run in a Jupyter notebook using an M1 Macbook Air and execute within say a minute or so. Any annotations, charts or tables that will enhance the output of the program will be appreciated. Any additional fun facts about the input number can be added to the program as you see fit. The key challenge is to enhance the output which is currently quite basic and limited to simple text. It's important that spacing between the different sections be consistent and that the various sections are clearly identified. I've added some commentary to each section but this can be expanded or modified if desired. 

What followed was something of a nightmare as the resulting code that was produced was full of bugs that AI Studio was never able to fix. Once I did get the code to run but many of the number properties that were displayed in my original code were no longer there. To be fair, it did produce a much improved output for the sections where it did work as can be seen in Figure 1. However, the attempts to get the code to run properly were frustrating and ultimately futile. 


Figure 1

There are numerous alternatives out there and I'll have to turn to them if I want to generate code that works. I tried ChatGPT and it revised the faulty AI Studio code but stopped at line 106 (there are about 875 lines of code) probably because I'd exceeded my free allowance of tokens. So dead end there.

Grok 3 failed to understand that the Jupyter notebook can be set to SageMath 10.3 not just Python 3 and gave the following comments:

The code you provided appears to be written for SageMath, but you're trying to run it in a Jupyter notebook, which typically uses a Python kernel with libraries like Matplotlib. This mismatch is likely causing some of the errors, as SageMath-specific functions and syntax (e.g., latex(), N(), Integer(), and certain mathematical operations) aren't directly compatible with a standard Python environment. Additionally, there are a few other issues that could lead to errors, such as undefined variables, plotting issues, and missing imports.

I'll modify the code to make it compatible with a standard Jupyter notebook environment using Python 3, while preserving its core functionality. I'll replace SageMath-specific functions with equivalent Python alternatives, ensure proper imports, and fix potential glitches.

After Grok 3 turned all the code to Python 3, it was still full of bugs and never managed to execute all the code. I'm getting the feeling that my original code, written in SageMath, is possibly at the core of the problem. When an AI tries to improve the code, using SageMath or Python, then all sorts of glitches arise because of the modifications to my original code. It would be better to build the whole code base from scratch using Python only and indicating exactly what I want. One thing I've realised is that LaTeX can be applied to the Jupyter notebook output to greatly improve readability.

It occurred to me that I lot of my code just reproduces what a site like Numbers Aplenty always publicly provides. I asked Gemini 2.5 Flash the following question:

Is it possible to create Python code that draws on the content of a site like Numbers Aplenty. For example, let's say I enter 27819 into my program. Can I get the program to then access https://www.numbersaplenty.com/27819 and extract some or all of the information from it. For example, one of the properties of the number that the site displays is "It is a junction number, because it is equal to n+sod(n) for n = 27792 and 27801". Can I get this information to show up as output in my code? If it is feasible then could you create the necessary code to do this or explain why this is not possible.

The response was encouraging:

Yes, it is absolutely possible to create Python code that draws on the content of a site like Numbers Aplenty and extracts specific information. This process is commonly known as web scraping. Numbers Aplenty doesn't seem to offer a public API (Application Programming Interface) for directly accessing its data in a structured format. This means we'll need to use web scraping techniques. 

It then went on to confidently provide code for doing this but of course it didn't work. Excuses were made and additional programs and drivers were recommended for download to remedy the problem. In short, no go. I should try other AI tools but frankly the whole process has exhausted me. I need a rest.

Friday, 8 March 2024

Quaternary Number System

The number associated with my diurnal age today, 27368, has the property that its prime factors contain only the digits 1, 2 and 3. Specifically:$$27368=2 \times 2 \times 2 \times 11 \times 311$$This got me thinking about what numbers in the range up to 333,321 contain only the digits 1, 2, 3 and have prime factors that also only contain the digits 1, 2, 3. It turns out that there are only seven such numbers and they are (permalink):$$ \begin{align} 132 &= 2^2 \times 3 \times 11\\312 &= 2^3 \times 3 \times 13\\11132 &= 2^2 \times 11^2 \times 23\\11232 &= 2^5 \times 3^3 \times 13\\13312 &= 2^{10} \times 13\\123132 &= 2^2 \times 3 \times 31 \times 331\\132122 &= 2 \times 31 \times 2131 \end{align}$$For brevity, I've written the factorisation in base-index format and so digits greater than 1, 2, 3 appear but these of course disappear when the factorisation is not written in base-index format.

The appearance of the digits 1, 2, 3 only is reminiscent of the quaternary number system even though what is written previously is in base 10. The quaternary equivalents of the previous decimal numbers are:$$ \begin{align} 132 &= 2010_{4}\\312 &= 10320_4\\11132 &= 2231330_4\\11232 &= 2233200_4\\13312 &= 3100000\\123132 &= 132003330_4\\132122 &= 200100122_4 \end{align} $$The factorisation of the quaternary numbers will contain the same number of factors and single digit factors will remain the same but multidigit factors will appear as their quaternary equivalents. Thus:$$ \begin{align} 13312 &= 2^{10} \times 13 \text{ and}\\3100000_4 &=2_4^{22_4} \times 31_4 \end{align} $$Of course, the quaternary number system also contains the digit 0 and so it's fair to ask what numbers up to 333,210 contain all the digits 0, 1, 2 and 3 (multiplicity allowed) and have prime factors that also contain only these digits (again with multiplicity allowed). It turns out that there is only one such number in the range up to one million. It is:$$133012 = 2^2 \times 11 \times 3023$$I thought I'd ask Google's Gemini about the quaternary number system.
Can you give me some interesting facts about and uses of the quaternary or base 4 number system?

The quaternary (base-4) system, while not as common as binary or decimal, holds some interesting properties and potential uses. Here are some fun facts and applications:

Interesting Facts:
  • Fewer Digits: Compared to binary, quaternary uses fewer digits to represent the same numerical value. For example, 10 in binary is 1010, while in quaternary it's simply 22.
  • DNA Connection: The four building blocks of DNA (Adenine, Guanine, Cytosine, and Thymine) can be seen as a quaternary system, with each combination representing a specific unit of genetic information.
  • Error Detection: Quaternary finds some niche applications in fault-tolerant computer systems. By using 4 possible states (0, 1, 2, 3) instead of 2 in binary, it allows for additional error detection and correction mechanisms.
Potential Uses:
  • Educational Tool: Quaternary can be a stepping stone for learning binary. Due to its simplicity (using only 4 digits), it can be easier to grasp the concept of positional number systems before moving to binary's base-2 system.
  • Space Exploration: Some proposals for future spacefaring computers suggest using quaternary systems due to their potential radiation hardness. Quaternary systems might be more resistant to the corrupting effects of cosmic radiation compared to traditional binary systems. (This is an area of ongoing research)
  • Signal Processing: Quaternary can be used in certain signal processing applications where reducing the number of states while maintaining some level of complexity compared to binary might be beneficial. However, extensive binary infrastructure makes widespread adoption less likely.
Overall, the quaternary number system offers a unique perspective on representing numbers. While not as widely used as binary or decimal, it has interesting properties and potential applications in specific areas like education, fault-tolerant systems, and possibly even future space exploration.

Here is some further information about the connection with DNA taken from this source:

Parallels can be drawn between quaternary numerals and the way genetic code is represented by DNA. The four DNA nucleotides in alphabetical order, abbreviated A, C, G and T, can be taken to represent the quaternary digits in numerical order 0, 1, 2, and 3. With this encoding, the complementary digit pairs 0↔3, and 1↔2 (binary 00↔11 and 01↔10) match the complementation of the base pairs: A↔T and C↔G and can be stored as data in DNA sequence. For example, the nucleotide sequence GATTACA can be represented by the quaternary number 2033010 (= decimal 9156 or binary 10 00 11 11 00 01 00).