Source code formal reasoning copilot

Your “math PhD sidekick” for mathematically reasoning about your code, ensuring its correctness and generating test cases powered by LLMs, LangGraph and automated logical reasoning.

Available now via Imandra Universe!

Get Started
Imandra Universe Interface
Get StartedThere is no better time than now!

Features

Automated Formal Verification

Translate Python (and more languages soon) programs into formal mathematical models and verify their properties with ImandraX.

State-space Exploration

Understand the model's edge cases via Imandra's Region Decomposition feature for state-space analysis.

Math-based Test Case Generation

Use ImandraX to automatically synthesize test cases using systematic analysis of the model's state-space.

VS Code Extension

Access all of the features of the CodeLogician agent from within VS Code, including recommendations and ImandraX analysis of the generated model.

API Access

CodeLogician is a LangGraph application which means that you can access it via standardized APIs and add it as a “RemoteGraph” into your agent.

Industrial-grade Reasoning

CodeLogician is powered by ImandraX - our award-winning automated reasoning engine relied upon for verifying correctness of some of the most complex safety-critical applications in the world.

Get started

VS Code Extension vs Python API

Your first step is to obtain Imandra Universe API key

Get API Key

VS Code Extension

Install VS Code Extension:

Get Extension

Python API

View the agent at Imandra Universe:

View agent

Step 1

Install Imandra Library

Step 2

Run CodeLogician agent

Python Examples

Python library for CodeLogician

  • Step 1
    Install Python library

    > pip install imandra[universe]
  • Step 2
    Start up Python and import Imandra libs (check out example below)

    > python
    # Python 3.9.5 (default, May 18 2021, 12:31:01)
    # [Clang 10.0.0] :: Anaconda, Inc. on darwin
    #Type “help”, “copyright”, “credits” or “license” for more information

    > from imandra.u.agents import code_logician_python

Example

from imandra.u.agents import get_remote_graph, create_thread_sync
from imandra.u.agents.code_logician_formalizer import InputState as FInput
from imandra.u.agents.code_logician_reasoner import InputState as RInput, ReasonerAction
# Convert Python code to IML code
code_logician_formalizer = get_remote_graph(agent_name='code_logician_python')
create_thread_sync(code_logician_formalizer)
src_code = """
# verify that the result of g(x) is always larger than 0
def g(x: int):
    if x > 22:
        return 9
    else:
        return 100 + x
"""
res = code_logician_formalizer.invoke(FInput(src_lang='python', src_code=src_code))
print(res['end_result']['result'])
# 'success'
iml_code = res['formalizations'][-1]['iml_code']
print(iml_code)
# let g (x : int) : int =
#   if x > 22 then
#     9
#   else
#     100 + x
# Verify some property about the code, or find a counter-example if the property does not hold.
code_logician_reasoner = get_remote_graph(agent_name='code_logician_reasoner')
create_thread_sync(code_logician_reasoner)
res = code_logician_reasoner.invoke(
    RInput(
        src_code=src_code,
        iml_code=iml_code,
        action=ReasonerAction(type="extract_verify_reqs"),
    )
)
create_thread_sync(code_logician_reasoner)
res = code_logician_reasoner.invoke(
    RInput(
        src_code=src_code,
        iml_code=iml_code,
        verify_req=res["verify_req"],
        action=ReasonerAction(type="run_verify"),
    )
)
print(res['verify_req'][0]['extra']['instance_res']['sat']['model']['src'])
# module M = struct
#
#   let x = (-100.0)
#
#  end

Get in touch