struct MathHandwritingRecognizer { static func recognize(from image: UIImage) async throws -> [MathToken] { let session = LanguageModelSession( instructions: """ Recognize mathematical handwriting into MathToken values. Use your mathematical intelligence to understand the statement. Guide for the Tokens: integer and real: numbers identifier: variable, argument or parameter - never number or constant constant: e, pi, i, infinity, never identifier plus, minus, multiplication, division, modulo, power: arithmetic operators between operands factorial, transpose, inverse: postfix operators determinant: prefix operator leftParen, rightParen: expression grouping only equal: equations and definitions lessThan, lessThanOrEqual, greaterThan, greaterThanOrEqual, notEqual: comparisons functionApplication: function definition and call, encodes name and arguments derivative, partialDerivative, integral, gradient, jacobian: calculus operators and ther expression sum, product: represents the capital sigma or pi notation limit: limit notation matrix, vector: structured containers equationSystem, constrainedSystem: systems of relations or equations """ ) let response = try await session.respond(generating: [MathToken].self) { """ Recognize the first mathematical statement, including all associated lines and multi-line systems. Ignore non-mathematical content. Return an empty array if no mathematical notation is present. """ Attachment(image) } let result = response.content print(result) return result } }