rramadass
Joined 8 years ago
Joined 8 years ago
AI understands "negative constraints" very well and so you should explicitly tell it "what not to do" at every stage as much as possible.
Use Top-Down and Stepwise-Refinement methodology to first generate the "Interface" and then the "Implementation" like so;
1) Ask it to produce only the "Skeleton App with well-defined Interfaces" directly 1:1 from the UML with stubs/mocks. It maybe better to use UML in text form which will allow you to annotate it easily with hints/notes for AI. The "Skeleton App" should include a) System Modules with narrow public interfaces like LKM/ioctl b) Directory structure with one module per subdirectory as a DAG with no cycles c) Explicit list of third-party libraries/frameworks to be used d) Classes/Abstract/Interfaces e) Free Functions and Class Methods with full type signatures etc.
2) Check the above and iterate until you have the UML and generated code synced up at the sufficient level of detail of Interfaces you are comfortable with. This should be compilable and is your absolute baseline which cannot be changed until you get a functional MVP.
3) Using the above skeleton, with strictly no change to any interfaces, ask it to fill in only the implementations the simplest possible way (i.e. "naive" linear, brute force etc.) with no optimizations whatsoever. Here you explicitly ask it to add runtime assertions for preconditions/postconditions/invariants. Make explicit that assertions should not have any side-effects whatsoever. This should now compile to give you the "naive" MVP.
4) Generate comprehensive test suites and test the above.
5) Now have it optimize everything, without changing the interfaces and assertions, but honouring them strictly. Compile and test against the above test suites. This should give you the "optimized" MVP.
6) Once the above passes, if performance is critical, have it comment out all assertions except "preconditions"; leave this in always. This is the minimal "sanity check".
7) Finally, for every "usecase" (i.e. feature) in the UML, have it generate the control flow graph annotated with preconditions/postconditions/invariants (which form the specification) from the previously generated code individually one per usecase. This is your "whitebox" verification documentation to make sure the implementation call graph satisfies the usecase i.e. feature specification.
Note that the above process gives you two implementations viz. the "naive" one and the "optimized" one. It is very helpful to always keep it that way as you modify/add features going forward so you can check one against the other.
You could use the same process using a textual Requirements Document etc. instead of UML. Also, if needed you can have AI generate the UML from the requirements, so you have a graphical specification of the system too.
This is the "Correctness-by-Construction" (CbC) approach using "Design-by-Contract" (DbC) methodology.
Additionally, If you generate for a strongly-typed language you can ask AI to explicitly exploit the type system fully with an eye to proving the code correct by suitable use of dependent types etc. to establish constraints for code correctness in step-1 itself as part of the interface. This is "Type-Driven Design". However, this is somewhat advanced and hence only do this if you have a good grasp of the implementation language since AI will try to be too clever and implement "typing hijinks" which can make the code incomprehensible.
Think of it as how you used wizards in older IDEs (Visual Studio MFC etc.) to first generate default skeleton app code with stubs/mocks, got it to compile and then started adding your code to it with testing and verifying at every stage. You want AI to behave in such a deterministic manner.
PS: To get started, feed my comment to AI and have it generate the necessary prompts for your AI interface ;-)
Do you have a detailed paper/article written on this?
> I think the royal combo is Lean 4/TLA+/etc. plus AI plus a deterministic generator. For large systems formal method assertions need to be compressed down to a human comprehensible size. This can happen when the assertions are confirming the accuracy of a model and its attached code generators. The generator can generate proofs of the generated code and a human only needs to ensure that the generator provably generates the correct mass scale assertions.
This is not completely clear; would you mind elaborating on that in more detail?
There is no "global time clock" and hence in a philosophical sense there is no "common now".
However, the speed of light is constant in the universe and so you can calculate time based on distance traveled by light to you provided you are not moving at speeds comparable to speed of light. This means you can suppose a "common lightyear clock" for measurement.
But when the speeds are comparable to that of light, you have time dilation and length contraction and so even the "common lightyear clock" is invalid. This is the principle of "Relativity of Simultaneity".
The way to think about it is, Events happen in a Space-Time fabric and so in order to measure the interval between two events you have to consider both Space and Time w.r.t. object speed vs. speed of light. The universal invariant here is the "Space-Time Interval" between two events which will be the same for everybody whatever be their mass or speed.
1) Understanding Formal Methods by Jean-Francois Monin - This is the absolute best for getting a grip on the breadth, concepts and sample tools for Formal Mathematics/Specification/Verification. Fire-hose of information (not a step-by-step textbook) so use this as a map for everything "Formal". The S/N ratio is very high (~250 pages only!) so use AI/Textbooks to help explain concepts you find difficult to understand.
Practical:
1) Software Abstractions: Logic, Language, and Analysis by Daniel Jackson - Uses "Alloy" language to teach Structural (i.e. Data) Modeling.
2) Specifying Systems: The TLA+ Language and Tools for Hardware and Software Engineers by Leslie Lamport - Uses "TLA+" language to teach Behavioural (i.e. State Machine) modeling.
The above two are for "System Modeling" i.e. everything needed to formally build complete systems.
3) Finally, You should also look at the bunch of free books on the Lean4 website which can be studied parallely for "code-level" proofs and verification.
PS: There are a few more (eg. Event-B method etc.) but you can get to those if/when you need to.
Here, the noun "elegance" should be understood in the sense of the second meaning of "elegant", as given in the Concise Oxford Dictionary (6th Edition, 1976): "ingeniously simple and effective".
we shall stress that in sophisticated designs, elegance is not a dispensable luxury, but a factor that often decides between success and failure.
Everyone playing around with AI today, needs to read, understand, reflect and assimilate the advice given in EWD619 ;-)
I also observe a widespread underestimation of what can be achieved by thinking properly, and sometimes an unwillingness to admit that, for certain goals, proper thinking is an indispensable prerequisite, an unwillingness of which a sad waste of effort, and ultimately, undeniable failure are the certain results.
I regard the obvious consequences of these attitudes and assumptions as regrettable. We have surrounded ourselves by arteifacts of needlessly clumsy designs, which make them cumbersome to develop and to maintain, and dangerous to rely upon; nevertheless they are relied upon, partly because we have the feeling that we have no choice, partly -- and that is where I protest -- their imperfections have been raised to the status of a Law of Nature. Secondly we observe -- mainly, but not exclusively, under the auspices of that branch of human activity and aspiration called "Artificial Intelligence" -- a great amount of research and development effort spent on trying to reduce the need for (what I am now forced to call) Natural Intelligence; I have reasons to expect these efforts to be in vain. Thirdly, we see our educational systems affected: they are getting geared to "Otto Normalverbraucher" [trans. Average Person] to the extent that it is now regarded as an indecency to require from a university graduate that he expresses himself adequately.
The rise of "Artificial Intelligence" today does not preclude the necessity of training our "Natural Intelligence" to think clearly and simply i.e. elegantly, in our problem-solving endeavours. None of the bazillion tools/techniques/methodologies (eg. crazy agentic loops, humongous prompt chaining, bloated codebases etc.) hoisted upon us to interface with AI is a substitute for thinking. If anything, simplicity, precision, formal methods, managed abstractions, separation of concerns are more vital today in the age of AI.
PS: My HN handle is based on my real name and not because i am a follower of "Ram Dass" (American) ;-)
The essay itself is highly thought-provoking and an evisceration of Mankind. I especially like his indictment of "Moral Sense";
One is obliged to concede that in true loftiness of character, Man cannot claim to approach even the meanest of the Higher Animals. It is plain that he is constitutionally incapable of approaching that altitude; that he is constitutionally afflicted with a Defect which must make such approach forever impossible, for it is manifest that this defect is permanent in him, indestructible, ineradicable.
I find this Defect to be the Moral Sense. He is the only animal that has it. It is the secret of his degradation. It is the quality which enables him to do wrong. It has no other office. It is incapable of performing any other function. It could never have been intended to perform any other. Without it, man could do no wrong. He would rise at once to the level of the Higher Animals.
Since the Moral Sense has but the one office, the one capacity -- to enable man to do wrong – it is plainly without value to him. It is as valueless to him as is disease. In fact, it manifestly is a disease.
The Moral Sense enables a man to do wrong. It enables him to do wrong in a thousand ways. Rabies is an innocent disease, compared to the Moral Sense. No one, then, can be the better man for having the Moral Sense. What now, do we find the Primal Curse to have been? Plainly what it was in the beginning: the infliction upon man of the Moral Sense; the ability to distinguish good from evil; and with it, necessarily, the ability to do evil; for there can be no evil act without the presence of consciousness of it in the doer of it.
The point is that moral sense enables one to distinguish right from wrong and so when you do wrong to others you are fully conscious of the suffering it causes. And yet mankind does it in a thousand different ways.
If the Chinese and Indian govts. sort out their differences allowing their EV companies to better share technologies and production, thus bringing prices down drastically, the entire planet's environment will be changed!.
Their core technology (batteries, inverters, electric motors, drive trains, thermal management, software etc.) are all pretty similar (not too much essential variation) across brands and hence the main differentiator becomes price and cosmetics.
In the developing world cost is king, you don't need too much power, smaller size, maneuverability and comfort are the key parameters. Their EV market is for the taking and China is doing it easily with US/Europe not even in the race.
But this leads us to consider the Neuroscience/Cognitive effects of Typing by itself which is quite relevant today. More people type (Keyboard/Tablet/Smartphone) than write nowadays.
A Google search brought up a few studies;
1) Functional and cognitive correlates of typing speed in a large U.S. panel study - https://www.nature.com/articles/s41598-026-36500-7
2) Typing expertise in a large student population - https://link.springer.com/article/10.1186/s41235-022-00424-3
3) The Neuroscience Behind Writing: Handwriting vs. Typing—Who Wins the Battle? - https://pmc.ncbi.nlm.nih.gov/articles/PMC11943480/
4) Using Typing to Decode Language Production - https://www.cmu.edu/dietrich/psychology/news/2019/nozar-typi...
W.r.t. typos, from (4) above;
Interestingly, they found that typing errors were not just a result of clumsy fingers slipping on the keys. No. According to Nozari, the errors were similar to errors in speech production. Mistyping was akin to misspeaking. Instead of saying ‘red bag,’ you say “bed rag,” switching the first sounds of the words. Many typing errors are very similar, switching the ‘r’ and the ‘b,’ which are not next to each other on the keyboard.
===== The Problem: Realism vs. Idealism =====
“Do you know, I sometimes catch myself wishing that I, too, were blind to the facts of life and only knew its fancies and illusions. They’re wrong, all wrong, of course, and contrary to reason; but in the face of them my reason tells me, wrong and most wrong, that to dream and live illusions gives greater delight. And after all, delight is the wage for living. Without delight, living is a worthless act. To labour at living and be unpaid is worse than to be dead. He who delights the most lives the most, and your dreams and unrealities are less disturbing to you and more gratifying than are my facts to me.”
He shook his head slowly, pondering.
“I often doubt, I often doubt, the worthwhileness of reason. Dreams must be more substantial and satisfying. Emotional delight is more filling and lasting than intellectual delight; and, besides, you pay for your moments of intellectual delight by having the blues. Emotional delight is followed by no more than jaded senses which speedily recuperate. I envy you, I envy you.”
He stopped abruptly, and then on his lips formed one of his strange quizzical smiles, as he added:
“It’s from my brain I envy you, take notice, and not from my heart. My reason dictates it. The envy is an intellectual product. I am like a sober man looking upon drunken men, and, greatly weary, wishing he, too, were drunk.”
“Or like a wise man looking upon fools and wishing he, too, were a fool,” I laughed.
“Quite so,” he said. “You are a blessed, bankrupt pair of fools. You have no facts in your pocketbook.”
“Yet we spend as freely as you,” was Maud Brewster’s contribution.
“More freely, because it costs you nothing.”
“And because we draw upon eternity,” she retorted.
“Whether you do or think you do, it’s the same thing. You spend what you haven’t got, and in return you get greater value from spending what you haven’t got than I get from spending what I have got, and what I have sweated to get.”
-- Wolf Larsen from The Sea-Wolf by Jack London.
===== The Solution: Egoless engagement with every moment =====
One should become aware of one’s deluded notion in which one thinks that "I belong to these objects of the world and my life depends upon them. I cannot live without them and they cannot exist without me, either" [here objects can be anything that the mind latches onto i.e. animate/inanimate/thoughts/memories/etc.]. Then by profound enquiry, one contemplates "I do not belong to these objects, nor do these objects belong to me" [i.e. the difference between the experiencer, the object experienced and the experience itself]. Thus abandoning the ego-sense through intense contemplation, one should playfully engage oneself in the [everyday] actions that happen naturally [whether due to environment or self-initiated], but with the heart and mind ever cool and tranquil. Such an abandonment of the ego-sense and the conditioning is known as the contemplative egolessness.
Live in the present, with your consciousness externalized momentarily [i.e. egolessly immersed in the current activity for however short/long a time period] but without any effort [i.e. without fixating on the outcome]; when the mind stops linking itself to the past and to the future, it becomes no-mind. If from moment to moment your mind dwells [only] on what is [currently being done] and drops it effortlessly at once [when it is done but before moving on to something else], the mind becomes no-mind, full of purity.
They who, though remaining established in equilibrium, do not let their organs function naturally as long as the body is alive, are obstinate and stubborn people. As long as there is sesame there is oil; as long as there is the body, there are the different moods also. He who rebels against the states that the body is naturally subject to, cuts space to pieces with a sword [i.e. a futile and foolish endeavour]. The equilibrium of yoga is for the mind, not for the organs of action and their states. As long as the body lasts, one should let the organs of action perform their proper function [naturally; without desire/intent/volition], though the intellect and the senses remain in a state of equanimity. Such is the law of nature, to which even the gods are subject.
-- The Yoga Vasistha translated by Swami Venkatesananda.
=====