P
Prompt Master
Prompt Engineering 教程与提示词实战

从任务定义、示例和工作流到评测与安全边界

Prompt Engineering 教程与提示词实战Prompt Library

Composite functions

function composition prompt example

本章 Prompt 决定
01要解决的 Prompt 问题

function composition prompt example

02完成后带走

一份保留任务边界的可复用 Prompt、示例集、评测记录或安全规则。

03做到什么算完成

至少跑一个代表性样本,检查结果,并记录仍需人工复核的部分。

TL;DR(中文)

  • 这是一个 function composition 的测试:给 g(x)=f^{-1}(x) 与若干映射点,反推出 f 的对应关系,再计算 f(f(f(6)))
  • 适合用来测:模型是否能把 inverse mapping 处理正确、是否会在多次 composition 时出错。
  • 落地建议:要求模型输出 mapping table,并在每一步 composition 后输出中间值。

Background

This prompt tests an LLM's mathematical capabilities by prompting it to evaluate a function composition.

How to Apply(中文)

建议按 “先建立映射,再逐步计算” 的流程:

  1. g(x)=f^{-1}(x) 得到:f(g(x)) = x(也就是把 g 的 pairs 反向得到 f 的 pairs)
  2. 用表格列出 f 的 mapping(例如 f(5)=0, f(7)=4 等)
  3. 依次计算 f(6) → f(f(6)) → f(f(f(6)))

How to Iterate(中文)

  1. 强制输出 mapping table(结构化)后再给最终答案
  2. self-check:把 fg 互相验证(检查 g(f(x)) = x 在给定点是否成立)
  3. 对抗测试:增加更多点、加入干扰点、或让 f 非单射的情况看模型是否能发现矛盾

Self-check rubric(中文)

  • 是否正确理解 inverse 关系并构造了 f 的映射?
  • composition 是否逐步计算且中间值正确?
  • 是否检查了映射是否一致(无冲突)?

Practice(中文)

练习:把问题改成 f(f(2))f(f(f(9))) 等不同目标,并要求模型输出:

  • mapping table
  • 每一步中间值
  • 简短的 consistency check

Prompt

Suppose g(x) = f^{-1}(x), g(0) = 5, g(4) = 7, g(3) = 2, g(7) = 9, g(9) = 6.
What is f(f(f(6)))?

Code / API

OpenAI (Python)

from openai import OpenAI

client = OpenAI()

response = client.chat.completions.create(
    model="gpt-4",
    messages=[
        {
            "role": "user",
            "content": "Suppose g(x) = f^{-1}(x), g(0) = 5, g(4) = 7, g(3) = 2, g(7) = 9, g(9) = 6. What is f(f(f(6)))?",
        }
    ],
    temperature=1,
    max_tokens=256,
    top_p=1,
    frequency_penalty=0,
    presence_penalty=0,
)

Fireworks (Python)

import fireworks.client

fireworks.client.api_key = "<FIREWORKS_API_KEY>"

completion = fireworks.client.ChatCompletion.create(
    model="accounts/fireworks/models/mixtral-8x7b-instruct",
    messages=[
        {
            "role": "user",
            "content": "Suppose g(x) = f^{-1}(x), g(0) = 5, g(4) = 7, g(3) = 2, g(7) = 9, g(9) = 6. What is f(f(f(6)))?",
        }
    ],
    stop=["<|im_start|>", "<|im_end|>", "<|endoftext|>"],
    stream=True,
    n=1,
    top_p=1,
    top_k=40,
    presence_penalty=0,
    frequency_penalty=0,
    prompt_truncate_len=1024,
    context_length_exceeded_behavior="truncate",
    temperature=0.9,
    max_tokens=4000,
)

Reference

📚 相关资源