You could argue that 'thinking about thinking' is the core of what philosophy is.
First I would caution against a view that 'flawed thinking' can be understood entirely in relation to solving mathematical or coding challenges. Mathematics is unusual in there often being a single correct or most correct solution. In coding there are often multiple ways to achieve practical (ie complex) tasks, and multiple criteria other than purely solving the problem usually apply - I have heard it put that skill in coding is about having more things to try when you, inevitably, get stuck sometimes. That seems a better model, how to get unstuck and think creatively, rather than being annoyed you didn't see one particular answer.
Thinking well in philosophy involves two extra crucial dynamics. Uncertainty. And situating yourself, in relation to what you know. I would identify relative freedom of will, as about responding to both of these. Specifically, that wisdom is about the skill of making good decisions despite limited information, and with self-knowledge. Discussed here: Wisdom and John Vervaeke's awakening from the meaning crises? I like Vervaeke's point also that knowledge is not just information but also the arrangement of that for our use, which he calls 'salience landscapes', and considers in regard to giving us 'cognitive grip' of an area in regard to the tasks we undertake.
It's important to think about what intelligence is. I give my wider discussion of that here: Do IQ tests measure intelligence? I'd highlight from that the model from the paper A dynamical model of general intelligence: the positive manifold of intelligence by mutualism. We can think of intelligence as a kind of 'ecology of algorithms', that seek to strike a balance between efficiency for a very defined task, and versatility for open or novel tasks. Research on writing stories has linked originality to a quiet mind, and embellishing good ideas to a busy mind - best then is to be able to switch, by choice.
What helps people truly excel in original thinking is a fascinating topic. Ramanujan was doing mathematics at least half a century ahead of his field, as his lost notebook contained work not recapitulated before it's rediscovery. Einstein not only developed our best theory of gravity, he gave the first accurate estimate of the size of an atom, and provided two of the three pillars quantum mechanics was built on, and worked on the conundrum that led to understanding entanglement and non-locality that got the recent physics Nobel, and as ER = EPR is arguably the most promising basis for a quantum-gravity theory. Emmy Noether revolutionised mathematics with her work on algebraic group theory despite never having a paid academic role, and in her brief detour into physics provided probably the deepest insight in the subject, that conservation laws are directly equivalent to stating continuous symmetries under transformation. Feynman is another interesting candidate, because he left a lot more material about his thinking process - I love his lecture on Hardware Software and Heuristics, as an example of his clarity of approach. I am less of an admirer though because many criticised him, like Murray Gell-Man talks about him being a bit of a nightmare to work with, although maybe largely for the same reasons that made him a larger-than-life science communicator. Roger Penrose has been doing consistently original, interesting and wide-ranging work over an incredibly long career, adding fundamentally to the understanding of electrons, blackholes, working with Escher and developing ideas about non-repeating tilings, a serious proposal for a theory of consciousness with OrchOR, and proposed Conformal Cyclic Cosmology which provides a falsifiable model that can account for a high entropy Big Bang in an eternalist Cosmology. I think it is incumbent on us to try and understand not just intelligence in terms of speed at solving established problems, but intelligence involving this kind of original creative thought. As Popper pointed out there can be no universal algorithm for theorem generation, so there can be no final answer on thinking better, only guidance. True intelligence, is deeply connected to original thinking, but our measurement of it, is not.
An approach that can account for high-functioning mathematical savantism of the kind Ramanujan seems to have possessed, is the idea our neocortex evolved primarily for social purposes (as evidenced by the Dunbar Number), and this way of thinking may involve repurposing social brain functions towards holding in mind mathematical relationships, driven by obsessive counting behaviours (also relatable to OCD). Some mathematical savants have described numbers as having textures and colours, allowing many more relations to be held in mind by harnessing visual processes that use far more of our brain, than language processing. This is anecdotally evidenced by the story of Ramanujan and the Taxi Number. Calendrical savantism points to these skill resulting from practice. Ramanujan's wife describes him working so obsessively she had to make food he could eat with one hand so he could continue his work while eating. Techniques like Memory Theatres suggest with practice and sufficient motivation, many people could improve at these kinds of skills.
There are indications Einstein may have been dyslexic, including struggling with reading out loud, and struggling sometimes with word retrieval, and being a strongly visual thinker - dyslexia has been linked to better spotting items out of place. It's also thought he was on the autistic spectrum, with delayed language onset, social defecits, and hypersensitivity to stimuli. He said:
“I am truly a lone traveler and have never belonged to my country, my
home, my friends, or even my immediate family, with my whole heart; in
the face of all these ties, I have never lost a sense of distance and
a need for solitude…”
And
“I very rarely think in words at all. A thought comes, and I may try
to express in words afterwards.”
He was described by his colleagues as sometimes sitting without moving for long periods of time, and he seems to have had an extraordinary capacity of concentration. He said:
"I think 99 times and find nothing. I stop thinking, swim in silence,
and the truth comes to me."
Analysis of his brain suggested he had characteristics that meditative practices have on the brains of others.
I take from both of these examples, a high importance to support people with neurodiversity issues. An original thinker builds a tool-kit of mental algorithms, and goes beyond the ones we are all expected to learn, into developing their own skills, routines, or approaches. It is exactly that dyslexia involves thinking and learning differently, that it has positive as well as negative outcome associations. Around 1 in 4 engineers have someone in their family on the autistic spectrum, versus 1 in 10 on average, and there is a similar high degree of correlation among computer coders. Unusual thinking can support unusual skills, given the chance.
Neurodiversity also means being positive about learning about how others think differently. That Aphantasia had only started to be seriously studied in 2015 is an interesting case, as is the only very recent proof of functional tetrachromatism in humans. What divergences are we still missing? Traits alone don't lead to special advantages in creative thinking, they must also be harnessed, by someone motivated, and meet with social support. Academia and scholarship can be thought about as originating with supporting some to develop skills beyond the demands of survival, and I kind of see supporting neurodiversity and people who want to explore and develop new ways of thinking, as part of the direction of progress of that same kind of development. Oddballs and eccentrics have been revolutionising our understanding of the world since at least Archimedes.
Biologist Robert Sapolsky has a great lecture on the neurology of religious behaviours, that can help understand possible social functionality of mild OCD and schizo disorders. My thinking on Autism Spectrum Disorders is that similarly an impairment for an individual (social skills), may have critical advantages for their society (in STEM); understanding the intentions of others may be less important in modern times, at least for those able to focus on designing machines, in a society that won't exploit their trust. Societies that recognise tradeoffs, rather than demand each individual be competant at everything, should be more likely to flourish.
You say:
I was also wondering if I am making a false assumption of reality and
that's causing me to make errors.
Donald Hoffman makes very interesting points about why we can't rely on the results of evolution, to shape our perceptions so as to see the world as it is - or, for evolution at large to have our personal best interests in mind. See his TED Talk Do We See Reality As It Is? and his longform discussion Reality is an Illusion - His Evolution Hid the Truth.
Another approach to understanding a flawed perception of reality, is the Buddhist picture of the Links of Dependent Origination, and failure to recognise the Three Marks of Existence. I would summarise these as about, losing attention of what we can do in the present moment, and grasping for what cannot be held. The aim of Buddhism is to become awake to things as they are.
Daniel Kahneman's book 'Thinking Fast and Slow' gives interesting insights on how we use our minds, in relation to familiar and novel. There are summary videos here, and his own discussion of, in his Talk At Google.
You can certainly study to improve your memory. It was very normal until extremely recent times to practice memorising poetry, or even entire religious texts. You can study the skills of competative memory competition champions. These include mnemonic methods, visual imagery methods to shift verbal or numeric information into visual, and above all the Method of Loci or Theatre of Memory. Lynne Kelly is an academic who has studied these, and wrote 'Memory Craft: Improve your memory using the most powerful methods from around the world' and some other accessible texts, as well as 'Knowledge and Power in Prehistoric Societies: Orality, Memory and the Transmission of Culture' on the role of memory systems in the Ancient world. She also did this Mindscape podcast episode.
Improving your concentration is a key skill. Meditation can help, if you can find the right teacher, school, or practice. It is something we all do naturally, resting our presence in the moment. Meditation is simply the development of skillfulness in returning to it, in the face of provocation from our minds, and the world. Practices like music making, the flow state involved in skill at sports, or repetitive tasks like knitting or weaving, can help develop concentration, attention, and help refresh your brain by switching which parts are being used.
You can develop your visual imagination through study and practice, or more generally through visualisation skills. I like this list of tips. In the Buddhist tradition, they distinguish samatha or dhyana (the origin of the word Zen) for mental focus, but also have the Vipassana method, for exploring topics and visualising solutions. Personally I feel this latter aspect of meditation is underemphasised in modern Buddhism. Aphantasia shows there are some fundamental differences in ability to visualise, but anyone can strengthen their abilities to. Here are some applied exercises.
There are approaches to thinking about how our mindset shapes our ability to learn, like the idea of having a growth-mindset. See
Growing a growth mindset: characterizing how and why undergraduate students' mindsets change for discussion.
Motivation is an interesting question. How people get, and stay motivated. I feel that philosophy can help, like Aristotle on 'eudaimonia', cultivating good-spiritedness; Nietzsche on turning towards life and the conditions to cultivate our 'will to power' (I prefer 'lifeliness'); Stoicism for how to do what we can even in the face of insoluble problems; and Existentialism and Absurdism for practices of seeing through the motivations we are told we should have into understanding the real personal challenge of constructing why to do anything in a brief and meaningless world. Above all, motivation is about entering into discourse with ourselves, and defining our own meaning-cosmology, which will shape our goals and how strongly we pursue them.
I think your question of how to improve how we think, is very interesting and important. Our education system would look very different if more people took it seriously, support far more interdisciplinarity, and curiosity-driven research. As computing power and AI automate many repetative or clearly formulatable mental tasks, we exactly need to focus on our capacities for creative intelligence, and how to support and develop that.
We all benefit from increasing the scope and resolution of our intersubjective reality, the space of minds engaging with each other's experiences. These answers address the philosophy of that:
And wisdom, is the other half: 'Know Thyself'. Internal dialogue, using visualisations, and meditation, can all help to understand and observe our own minds.
"Mind precedes all mental states. Mind is their chief; they are all
mind-wrought." - opening of The Dhammapada