Class ProgramInput<T>
- Namespace
- AiDotNet.ProgramSynthesis.Models
- Assembly
- AiDotNet.dll
Represents the input specification for program synthesis.
public class ProgramInput<T>
Type Parameters
TThe numeric type used for calculations (e.g., double, float).
- Inheritance
-
ProgramInput<T>
- Inherited Members
Remarks
ProgramInput encapsulates all the information needed to synthesize a program, including natural language descriptions, input-output examples, formal specifications, and constraints.
For Beginners: This class describes what you want the program to do.
When you want AI to create a program for you, you need to tell it what you want. This class lets you provide that information in different ways:
- Describe it in plain English
- Give examples of inputs and expected outputs
- Specify constraints (like "must run in under 1 second")
Think of it like ordering at a restaurant - you tell the chef what you want, and they create the dish. This is how you tell the AI what program you want.
Constructors
ProgramInput()
Initializes a new instance of the ProgramInput<T> class with default values.
public ProgramInput()
Remarks
Creates an empty ProgramInput that can be populated later.
For Beginners: Creates an empty specification to fill in later.
Sometimes you want to create the object first and add details later. This creates an empty form you can fill in step by step.
ProgramInput(string?, ProgramLanguage, List<ProgramInputOutputExample>?, List<string>?)
Initializes a new instance of the ProgramInput<T> class.
public ProgramInput(string? description = null, ProgramLanguage targetLanguage = ProgramLanguage.Generic, List<ProgramInputOutputExample>? examples = null, List<string>? constraints = null)
Parameters
descriptionstringThe natural language description.
targetLanguageProgramLanguageThe target programming language.
examplesList<ProgramInputOutputExample>Optional input-output examples.
constraintsList<string>Optional constraints.
Remarks
Creates a new ProgramInput with the essential information needed for synthesis. Additional properties can be set after construction.
For Beginners: This creates a new specification for what program you want.
Provide at minimum:
- A description of what you want
- Which language to use
- Optionally: examples and constraints
Like filling out an order form for a custom program.
Properties
Constraints
Gets or sets constraints that the synthesized program must satisfy.
public List<string>? Constraints { get; set; }
Property Value
Remarks
A list of constraints or requirements for the program, such as: - Performance requirements ("must run in O(n) time") - Resource limits ("must use less than 1MB memory") - Style requirements ("must use functional programming style")
For Beginners: These are rules the program must follow.
Beyond just working correctly, you might have specific requirements:
- "Must be fast"
- "Should be easy to read"
- "Can't use certain functions"
Like telling a chef: "Make it vegetarian and gluten-free." These constraints ensure the program meets your specific needs.
Description
Gets or sets the natural language description of the desired program.
public string? Description { get; set; }
Property Value
Remarks
A plain-English description of what the program should do. This can be used by neural synthesis methods to understand the user's intent.
For Beginners: This is where you describe what you want in plain English.
Just like telling someone: "I need a function that takes a list of numbers and returns the average"
No programming knowledge needed - just explain what you want the program to accomplish.
Encoding
Gets or sets an encoded representation of the input for neural processing.
public Tensor<T>? Encoding { get; set; }
Property Value
- Tensor<T>
Remarks
An optional numerical encoding of the input specification that can be directly processed by neural networks.
For Beginners: This is a numerical version for AI processing.
Neural networks work with numbers, not text. This is an optional field where the input can be pre-converted to numbers. Usually generated automatically - you don't need to provide this yourself.
Examples
Gets or sets the input-output examples for inductive synthesis.
public List<ProgramInputOutputExample>? Examples { get; set; }
Property Value
Remarks
A list of example inputs and their expected outputs. The synthesizer learns from these examples to generate a program that generalizes to new inputs. Each example includes an input and the expected output.
For Beginners: These are examples showing what the program should do.
Instead of explaining, you can show examples:
- Input: [1, 2, 3] → Output: 6 (sum)
- Input: [4, 5] → Output: 9 (sum)
- Input: [10] → Output: 10 (sum)
The AI figures out the pattern from your examples. Like teaching by example rather than explaining - show what you want, and the AI learns the rule.
FormalSpecification
Gets or sets the formal specification in logic or a domain-specific language.
public string? FormalSpecification { get; set; }
Property Value
Remarks
A formal, mathematical specification of the program's behavior. This is used by deductive synthesis methods to construct provably correct programs.
For Beginners: This is a precise mathematical description (advanced).
This is more advanced - it's a very precise, formal way to describe what the program should do using mathematical logic. Like a detailed blueprint with exact specifications. Most users will use Description or Examples instead.
MaxComplexity
Gets or sets the maximum allowed complexity for the synthesized program.
public int? MaxComplexity { get; set; }
Property Value
- int?
Remarks
Limits how complex the generated program can be. This helps ensure the synthesizer produces simple, understandable code when possible.
For Beginners: This limits how complicated the program can be.
Sometimes simple is better. This sets a maximum complexity level:
- Low value: Forces simple solutions
- High value: Allows complex solutions if needed
Like asking for a simple recipe instead of a gourmet one - both might work, but simple is often better for learning and maintaining.
Tags
Gets or sets metadata tags for categorizing or filtering synthesis tasks.
public List<string>? Tags { get; set; }
Property Value
Remarks
Optional tags that can be used to categorize the synthesis task, track experiments, or provide additional context to the synthesizer.
For Beginners: These are labels for organizing synthesis tasks.
Like hashtags or folders, these help organize and categorize:
- "sorting", "algorithm", "beginner"
- "web-scraping", "python", "advanced"
Useful for tracking different types of synthesis tasks and experiments.
TargetLanguage
Gets or sets the target programming language for synthesis.
public ProgramLanguage TargetLanguage { get; set; }
Property Value
Remarks
Specifies which programming language the synthesized program should be written in.
For Beginners: This is which programming language you want the code in.
Like choosing whether you want instructions in English or Spanish, this tells the AI whether to generate code in Python, Java, C#, etc.
TestCases
Gets or sets the test cases for program validation.
public List<ProgramInputOutputExample>? TestCases { get; set; }
Property Value
Remarks
Additional test cases (beyond the examples) used to validate the correctness of synthesized programs. Each test case includes an input and the expected output.
For Beginners: These are additional tests to verify the program works.
While Examples teach the AI, TestCases verify the result:
- Examples: "Learn from these"
- TestCases: "Prove you got it right with these"
Like the difference between practice problems and an exam - test cases help ensure the program truly works correctly.
TimeoutMs
Gets or sets the timeout for program synthesis in milliseconds.
public int? TimeoutMs { get; set; }
Property Value
- int?
Remarks
Specifies how long the synthesizer should attempt to find a solution before giving up. Prevents indefinite computation on difficult problems.
For Beginners: This is how long the AI has to find a solution.
Measured in milliseconds (1000ms = 1 second). Sometimes finding the perfect program takes too long. This sets a time limit:
- 5000ms (5 seconds): Quick attempt, might not find best solution
- 60000ms (1 minute): More thorough search
Like giving up on a crossword puzzle after 10 minutes - sometimes you need to move on even if you haven't finished.
Methods
AddConstraint(string)
Adds a constraint to the Constraints list.
public void AddConstraint(string constraint)
Parameters
constraintstringThe constraint to add.
Remarks
Convenience method to add constraints one at a time.
For Beginners: This adds one constraint at a time.
Add requirements one by one: programInput.AddConstraint("Must run in O(n) time"); programInput.AddConstraint("Should not use recursion");
AddExample(string, string)
Adds an input-output example to the Examples list.
public void AddExample(string input, string expectedOutput)
Parameters
Remarks
Convenience method to add examples one at a time instead of creating the entire list upfront.
For Beginners: This adds one example at a time.
Instead of providing all examples at once, you can add them one by one: programInput.AddExample("[1,2,3]", "6"); programInput.AddExample("[4,5]", "9");
Easier than creating the list yourself.
AddTestCase(string, string)
Adds a test case to the TestCases list.
public void AddTestCase(string input, string expectedOutput)
Parameters
Remarks
Convenience method to add test cases one at a time.
For Beginners: This adds one test case at a time.
Similar to AddExample, but for test cases that verify correctness: programInput.AddTestCase("[10,20]", "30");