Interface IProgramSynthesizer<T>
- Namespace
- AiDotNet.ProgramSynthesis.Interfaces
- Assembly
- AiDotNet.dll
Represents a program synthesis engine capable of automatically generating programs.
public interface IProgramSynthesizer<T> : IFullModel<T, Tensor<T>, Tensor<T>>, IModel<Tensor<T>, Tensor<T>, ModelMetadata<T>>, IModelSerializer, ICheckpointableModel, IParameterizable<T, Tensor<T>, Tensor<T>>, IFeatureAware, IFeatureImportance<T>, ICloneable<IFullModel<T, Tensor<T>, Tensor<T>>>, IGradientComputable<T, Tensor<T>, Tensor<T>>, IJitCompilable<T>
Type Parameters
TThe numeric type used for calculations (e.g., double, float).
- Inherited Members
- Extension Methods
Remarks
IProgramSynthesizer defines the interface for models that can automatically generate programs from specifications, examples, or natural language descriptions. This is a key component of automated programming and AI-assisted development.
For Beginners: A program synthesizer is like an AI programmer.
Imagine describing what you want a program to do, and an AI writes the code for you. That's what a program synthesizer does. You provide:
- Examples of inputs and desired outputs
- A description in plain English
- Or formal specifications
And the synthesizer creates a working program that meets your requirements. This is like having an AI assistant that can code for you!
Properties
MaxProgramLength
Gets the maximum allowed length for synthesized programs.
int MaxProgramLength { get; }
Property Value
Remarks
This limits the complexity and size of generated programs, measured in tokens or abstract syntax tree nodes.
For Beginners: This limits how long/complex the generated code can be.
Like a word limit on an essay, this prevents the AI from generating programs that are too large or complex. Helps ensure the code stays manageable.
SynthesisType
Gets the type of synthesis approach used by this synthesizer.
SynthesisType SynthesisType { get; }
Property Value
Remarks
Different synthesis approaches have different strengths. Neural methods are creative, symbolic methods are precise, and hybrid methods combine both.
For Beginners: This tells you how the AI generates programs.
Different approaches are like different problem-solving strategies:
- Neural: Learns from examples (like learning by watching)
- Symbolic: Uses logic and rules (like following instructions)
- Genetic: Evolves solutions (like natural selection)
TargetLanguage
Gets the target programming language for synthesis.
ProgramLanguage TargetLanguage { get; }
Property Value
Remarks
Specifies which programming language the synthesized programs will be written in.
For Beginners: This is the language the AI will write code in.
Just like you choose whether to write in English or Spanish, this specifies which programming language the generated code will use (Python, Java, etc.).
Methods
EvaluateProgram(Program<T>, ProgramInput<T>)
Evaluates how well a program satisfies the input specification.
double EvaluateProgram(Program<T> program, ProgramInput<T> testCases)
Parameters
programProgram<T>The program to evaluate.
testCasesProgramInput<T>Test cases to evaluate the program against.
Returns
- double
A fitness score indicating how well the program meets requirements (0-1, higher is better).
Remarks
Evaluation tests the program against provided test cases and returns a score indicating how well it performs. This is crucial for iterative refinement.
For Beginners: This grades how well the generated program works.
Just like a teacher grades homework, this checks how well the program solves the problem. It runs tests and gives a score (like a percentage):
- 1.0 = Perfect, passes all tests
- 0.5 = Passes half the tests
- 0.0 = Doesn't work at all
RefineProgram(Program<T>, ProgramInput<T>)
Refines an existing program to better meet the specification.
Program<T> RefineProgram(Program<T> program, ProgramInput<T> feedback)
Parameters
programProgram<T>The program to refine.
feedbackProgramInput<T>Feedback or test cases that failed.
Returns
- Program<T>
A refined version of the program.
Remarks
Refinement takes an existing program and improves it based on feedback, such as failed test cases or user corrections. This enables iterative improvement.
For Beginners: This improves a program based on feedback.
If the first version isn't quite right, this method improves it. Like editing a draft based on reviewer comments - it takes the feedback and creates a better version. Keeps the good parts and fixes the problems.
SynthesizeProgram(ProgramInput<T>)
Synthesizes a program from the given input specification.
Program<T> SynthesizeProgram(ProgramInput<T> input)
Parameters
inputProgramInput<T>The input specification containing requirements or examples.
Returns
- Program<T>
A synthesized program that meets the specification.
Remarks
This is the core synthesis method that generates a complete program from the provided input specification. The input can contain examples, natural language descriptions, or formal specifications.
For Beginners: This is where the magic happens - it creates a program for you!
You provide what you want (examples, description, etc.), and this method generates actual working code that does what you asked for. Like asking an AI chef for a recipe and getting step-by-step cooking instructions.
ValidateProgram(Program<T>)
Validates whether a synthesized program is correct and well-formed.
bool ValidateProgram(Program<T> program)
Parameters
programProgram<T>The program to validate.
Returns
- bool
True if the program is valid, false otherwise.
Remarks
Validation checks syntactic correctness, semantic validity, and whether the program compiles or can be executed.
For Beginners: This checks if the generated code is valid and will work.
Before using generated code, we need to check:
- Is the syntax correct? (no typos or grammar errors)
- Does it make sense? (logical consistency)
- Will it compile/run? (can the computer execute it)
Like proofreading before submitting an essay.