Products
  • Wolfram|One

    The definitive Wolfram Language and notebook experience

  • Mathematica

    The original technical computing environment

  • System Modeler

    Multidomain modeling and simulation of complex systems

  • Compute ServicesUse with Mathematica and Wolfram|One
  • AI AccessUse with Mathematica and Wolfram|One
  • Finance Platform
  • Wolfram|Alpha Notebook Edition
  • Application Server
  • Enterprise Private Cloud
  • Wolfram Engine
  • Wolfram Player
  • Wolfram Cloud App
  • Wolfram Player App

More mobile apps

Wolfram|Alpha

  • Wolfram|Alpha Website
  • Wolfram|Alpha APIs

AI Products

  • Wolfram AI Ecosystem
  • Wolfram Foundation Tool
  • Wolfram Cloud MCP
  • Wolfram Local MCP
  • Agent One API
  • CAG Component APIs

Core Technologies of Wolfram Products

  • Wolfram Language
  • Computable Data
  • Wolfram Notebooks
  • Linguistic Understanding

Additional Deployment Options

  • Wolfram Cloud
  • Wolfram Web Engine
  • wolframscript
  • WSTPServer
  • Group & Organizational Licensing
  • All Products
Consulting & Solutions

We deliver solutions for the AI era—combining symbolic computation, data-driven insights and deep technical expertise

Wolfram Consulting

Data Science, Finance & Business

  • Artificial Intelligence
  • Data Science
  • Healthcare
  • Real Estate

Engineering

  • Civil Engineering
  • Automotive Engineering
  • Sustainable Energy

Science & Technology

  • AgTech
  • Biosciences
  • Environmental Science
  • Food Science
  • Quantum Computation
  • Social and Behavioral Sciences

More Wolfram Solutions

Technology for Education

  • Research Universities
  • Colleges & Teaching Universities
  • High Schools
  • Resources for Students

Education Initiatives

  • Next-Gen EdTech
  • Computer-Based Math

More Solutions for Education

  • Contact Us
Learning & Support

Get Started

  • Wolfram Language Introduction
  • Fast Intro for Programmers
  • Fast Intro for Math Students
  • Wolfram Language Documentation

More Learning

  • Highlighted Core Areas
  • Demonstrations
  • YouTube
  • Daily Study Groups
  • Wolfram Schools and Programs
  • Books

Grow Your Skills

  • Wolfram U

    Courses in computing, science, life and more

  • Community

    Learn, solve problems and share ideas.

  • Blog

    News, views and insights from Wolfram

  • Resources for

    Software Developers

Tech Support

  • Contact Us
  • Support FAQs
  • Support FAQs
  • Contact Us
Company
  • About Wolfram
  • Career Center
  • All Sites & Resources
  • Connect & Follow
  • Contact Us

Work with Us

  • Student Ambassador Initiative
  • Wolfram for Startups
  • Student Opportunities
  • Jobs Using Wolfram Language

Educational Programs for Adults

  • Summer School
  • Winter School

Educational Programs for Youth

  • Middle School Camp
  • High School Research Program
  • Computational Adventures

Read

  • Stephen Wolfram's Writings
  • Wolfram Blog
  • Wolfram Tech | Books
  • Wolfram Media
  • Complex Systems

Educational Resources

  • Wolfram MathWorld
  • Wolfram in STEM
  • Wolfram Challenges
  • Wolfram Problem Generator

Wolfram Initiatives

  • Wolfram Science
  • Wolfram Foundation
  • History of Mathematics Project

Events

  • Stephen Wolfram Livestreams
  • Online & In-Person Events
  • Contact Us
  • Connect & Follow
For AIs
  • Your Account
  • User Portal
  • Wolfram Cloud
  • Products
    • Wolfram|One
    • Mathematica
    • System Modeler
    • Compute ServicesUse with Mathematica and Wolfram|One
    • AI AccessUse with Mathematica and Wolfram|One
    • Finance Platform
    • Wolfram|Alpha Notebook Edition
    • Application Server
    • Enterprise Private Cloud
    • Wolfram Engine
    • Wolfram Player
    • Wolfram Cloud App
    • Wolfram Player App

    More mobile apps

    • Wolfram|Alpha
      • Wolfram|Alpha Website
      • Wolfram|Alpha APIs
    • AI Products
      • Wolfram AI Ecosystem
      • Wolfram Foundation Tool
      • Wolfram Cloud MCP
      • Wolfram Local MCP
      • Agent One API
      • CAG Component APIs
    • Core Technologies
      • Wolfram Language
      • Computable Data
      • Wolfram Notebooks
      • Linguistic Understanding
    • Additional Deployment Options
      • Wolfram Cloud
      • Wolfram Web Engine
      • wolframscript
      • WSTPServer
    • Group & Organizational Licensing
    • All Products
  • Consulting & Solutions
    • Wolfram Consulting

    Data Science, Finance & Business

    • Artificial Intelligence
    • Data Science
    • Healthcare
    • Real Estate

    Engineering

    • Civil Engineering
    • Automotive Engineering
    • Sustainable Energy

    Science & Technology

    • AgTech
    • Biosciences
    • Environmental Science
    • Food Science
    • Quantum Computation
    • Social and Behavioral Sciences

    More Wolfram Solutions

    Technology for Education

    • Research Universities
    • Colleges & Teaching Universities
    • High Schools
    • Resources for Students

    Education Initiatives

    • Next-Gen EdTech
    • Computer-Based Math

    More Solutions for Education

    • Contact Us
  • Learning & Support

    Get Started

    • Wolfram Language Introduction
    • Fast Intro for Programmers
    • Fast Intro for Math Students
    • Wolfram Language Documentation

    Grow Your Skills

    • Wolfram U

      Courses in computing, science, life and more

    • Community

      Learn, solve problems and share ideas.

    • Blog

      News, views and insights from Wolfram

    • Resources for

      Software Developers
    • Tech Support
      • Contact Us
      • Support FAQs
    • More Learning
      • Highlighted Core Areas
      • Demonstrations
      • YouTube
      • Daily Study Groups
      • Wolfram Schools and Programs
      • Books
    • Support FAQs
    • Contact Us
  • Company
    • About Wolfram
    • Career Center
    • All Sites & Resources
    • Connect & Follow
    • Contact Us

    Work with Us

    • Student Ambassador Initiative
    • Wolfram for Startups
    • Student Opportunities
    • Jobs Using Wolfram Language

    Educational Programs for Adults

    • Summer School
    • Winter School

    Educational Programs for Youth

    • Middle School Camp
    • High School Research Program
    • Computational Adventures

    Read

    • Stephen Wolfram's Writings
    • Wolfram Blog
    • Wolfram Tech | Books
    • Wolfram Media
    • Complex Systems
    • Educational Resources
      • Wolfram MathWorld
      • Wolfram in STEM
      • Wolfram Challenges
      • Wolfram Problem Generator
    • Wolfram Initiatives
      • Wolfram Science
      • Wolfram Foundation
      • History of Mathematics Project
    • Events
      • Stephen Wolfram Livestreams
      • Online & In-Person Events
    • Contact Us
    • Connect & Follow
  • For AIs
  • Wolfram Cloud
  • Your Account
  • User Portal
Wolfram Language & System Documentation Center
With
  • See Also
    • Module
    • Block
    • ReplaceAll
  • Related Guides
    • Scoping Constructs
    • Evaluation Control
    • Language Overview
    • Procedural Programming
  • Workflows
    • Substitute Values of Variables in Functions That Hold Their Arguments
  • Tech Notes
    • Local Constants
    • Some General Notations and Conventions
    • Variables in Pure Functions and Rules
    • See Also
      • Module
      • Block
      • ReplaceAll
    • Related Guides
      • Scoping Constructs
      • Evaluation Control
      • Language Overview
      • Procedural Programming
    • Workflows
      • Substitute Values of Variables in Functions That Hold Their Arguments
    • Tech Notes
      • Local Constants
      • Some General Notations and Conventions
      • Variables in Pure Functions and Rules

With[{x=x0,y=y0,…},expr]

specifies that all occurrences of the symbols x, y, … in expr should be replaced by x0, y0, ….

With[{a1=…,a2=…,…},{b1=…},…,expr]

replaces the ai followed by the bi etc. in such a way that the values of the bi can depend on the ai etc.

Details
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Applications  
Properties & Relations  
Possible Issues  
Neat Examples  
See Also
Tech Notes
Related Guides
Related Workflows
Related Links
History
Cite this Page
BUILT-IN SYMBOL
  • See Also
    • Module
    • Block
    • ReplaceAll
  • Related Guides
    • Scoping Constructs
    • Evaluation Control
    • Language Overview
    • Procedural Programming
  • Workflows
    • Substitute Values of Variables in Functions That Hold Their Arguments
  • Tech Notes
    • Local Constants
    • Some General Notations and Conventions
    • Variables in Pure Functions and Rules
    • See Also
      • Module
      • Block
      • ReplaceAll
    • Related Guides
      • Scoping Constructs
      • Evaluation Control
      • Language Overview
      • Procedural Programming
    • Workflows
      • Substitute Values of Variables in Functions That Hold Their Arguments
    • Tech Notes
      • Local Constants
      • Some General Notations and Conventions
      • Variables in Pure Functions and Rules

With

With[{x=x0,y=y0,…},expr]

specifies that all occurrences of the symbols x, y, … in expr should be replaced by x0, y0, ….

With[{a1=…,a2=…,…},{b1=…},…,expr]

replaces the ai followed by the bi etc. in such a way that the values of the bi can depend on the ai etc.

Details

  • With allows you to define local constants.
  • With replaces symbols in expr only when they do not occur as local variables inside scoping constructs.
  • With[{x:=x0,…},expr] inserts the unevaluated form x0 into expr.
  • You can use With[{vars},body/;cond] as the right‐hand side of a transformation rule with a condition attached. »
  • With has attribute HoldAll.
  • With constructs can be nested in any way, with inner variables being renamed if necessary.
  • With[def1,def2,expr] is equivalent to With[def1,With[def2,expr]]. »
  • With is a scoping construct that implements read‐only lexical variables.

Examples

open all close all

Basic Examples  (4)

Evaluate an expression with x locally set to 7:

Wolfram Language code: With[{x = 7}, x ^ 2]

Locally set both x and y:

Wolfram Language code: With[{x = 7, y = a + 1}, x / y]

With works even without evaluation:

Wolfram Language code: With[{x = a}, HoldComplete[1 + x ^ 2]]

Define the local variable y in terms of the earlier local variable x:

Wolfram Language code: With[{x = 5}, {y = x + 1}, y ^ 2]

Scope  (5)

Use With to insert values into held expressions:

Wolfram Language code: With[{x = y}, Hold[x]]
Wolfram Language code: Table[With[{i = j}, Hold[i]], {j, 5}]

Use := to insert the unevaluated form of an expression into the result:

Wolfram Language code: With[{x := 2 + 2}, Hold[x]]

Compare with the following:

Wolfram Language code: With[{x = 2 + 2}, Hold[x]]

The variable names can be the same:

Wolfram Language code: x = 5; With[{x = x}, Hold[x]]

Use a constant for a value that is needed more than once:

Wolfram Language code: With[{y = Sin[1.0]}, Sum[y ^ i, {i, 0, 10}]]

Set multiple variables with independent values:

Wolfram Language code: With[{x = y + 1, y = x - 1}, {x, y}]

Set multiple variables with later values depending on earlier values:

Wolfram Language code: With[{x = y + 1}, {y = x - 1}, {x, y}]

Applications  (1)

With allows inserting values into unevaluated expressions:

Wolfram Language code: With[{v = {a, b, c}, w = {x, y, z}}, Thread[Unevaluated[Dot[v, w]]]]
Wolfram Language code: Thread[Dot[{a, b, c}, {x, y, z}]]

Properties & Relations  (7)

Local variables declared within a single list are independent of each other:

Wolfram Language code: With[{x = 5, y = x + 3}, {x, y}]

Local variables declared in subsequent lists depend on the variables declared in earlier lists:

Wolfram Language code: With[{x = 5}, {y = x + 3}, {x, y}]

With[def1,def2,expr] is equivalent to With[def1,With[def2,expr]]:

Wolfram Language code: With[{x = 5}, {y = Hold[x ^ 2]}, y]
Wolfram Language code: % === With[{x = 5}, With[{y = Hold[x ^ 2]}, y]]

Using x:=x0 inserts the unevaluated form of x0, which then evaluates based on its surroundings:

Wolfram Language code: With[{x := RandomReal[]}, {x, x, Hold[x]}]

Using x=x0 evaluates x0 once and inserts the result everywhere x appears:

Wolfram Language code: With[{x = RandomReal[]}, {x, x, Hold[x]}]

Module introduces local variables to which values can be assigned:

Wolfram Language code: Module[{x = 2.0}, While[x > 0, x = Log[x]];x]

With variables are read only:

Wolfram Language code: With[{x = 2.0}, x = x]

With is faster than Module:

Wolfram Language code: Timing[Do[Module[{x = 5}, x;], {10 ^ 5}]]
Wolfram Language code: Timing[Do[With[{x = 5}, x;], {10 ^ 5}]]

Block localizes values only; it does not substitute values. Module creates new symbols:

Wolfram Language code: {Block[{x = 5}, Hold[x]], With[{x = 5}, Hold[x]], Module[{x = 5}, Hold[x]]}
Wolfram Language code: ReleaseHold[%]

With allows substitution inside an unevaluated expression, preserving nested scopes:

Wolfram Language code: With[{e = x}, Function[x, e]]

Ordinary substitution does not preserve scoping:

Wolfram Language code: Function[x, e] /. e :> x

Possible Issues  (2)

With is a scoping construct; variables are renamed in nested scopes:

Wolfram Language code: With[{e = Expand[(1 + x) ^ 5]}, Function[x, e]]
Wolfram Language code: %[10]

Build the function from its elements to avoid the renaming:

Wolfram Language code: With[{e = Expand[(1 + x) ^ 5]}, Function@@{x, e}]
Wolfram Language code: %[10]

The notebook interface by default warns if a variable is declared at multiple levels:

Wolfram Language code: With[{x = 1}, {x = x + 1}, HoldComplete[x]]

This valid syntax uses the last value in the function body, as would be the case with literal nesting:

Wolfram Language code: With[{x = 1}, With[{x = x + 1}, HoldComplete[x]]]

Neat Examples  (2)

Find a zero of an arbitrary function using Newton's method:

Wolfram Language code: newton[f_, x0_] := With[{fp = f'}, FixedPoint[# - f[#] / fp[#]&, x0]]
Wolfram Language code: newton[Cos, 1`20]

Find a fixed point:

Wolfram Language code: newton[Cos[#] - #&, 1`20]

A version of With where the initializer is within the scope of the local variable:

Wolfram Language code: SetAttributes[letrec, HoldAll]; letrec[{var_ = val_}, body_] := Module[{var}, var = val;body]
Wolfram Language code: letrec[{f = Function[n, If[n == 0, 1, n * f[n - 1]]]}, f[10]]

Here the f inside the function definition is not inside its own scope:

Wolfram Language code: With[{f = Function[n, If[n == 0, 1, n * f[n - 1]]]}, f[10]]

See Also

Module  Block  ReplaceAll

Function Repository: Inline  LocalizedByRules

Tech Notes

    ▪
  • Local Constants
  • ▪
  • Some General Notations and Conventions
  • ▪
  • Variables in Pure Functions and Rules

Related Guides

    ▪
  • Scoping Constructs
  • ▪
  • Evaluation Control
  • ▪
  • Language Overview
  • ▪
  • Procedural Programming

Related Workflows

    Related Workflows
    ▪
  • Substitute Values of Variables in Functions That Hold Their Arguments

Related Links

  • An Elementary Introduction to the Wolfram Language : Debugging Your Code

History

Introduced in 1991 (2.0) | Updated in 2025 (14.3)

Wolfram Research (1991), With, Wolfram Language function, https://reference.wolfram.com/language/ref/With.html (updated 2025).

Text

Wolfram Research (1991), With, Wolfram Language function, https://reference.wolfram.com/language/ref/With.html (updated 2025).

CMS

Wolfram Language. 1991. "With." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/With.html.

APA

Wolfram Language. (1991). With. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/With.html

BibTeX

@misc{reference.wolfram_2026_with, author="Wolfram Research", title="{With}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/With.html}", note=[Accessed: 01-September-2026]}

BibLaTeX

@online{reference.wolfram_2026_with, organization={Wolfram Research}, title={With}, year={2025}, url={https://reference.wolfram.com/language/ref/With.html}, note=[Accessed: 01-September-2026]}

Top
Introduction for Programmers
Introductory Book
Wolfram Function Repository | Wolfram Data Repository | Wolfram Data Drop | Wolfram Language Products
Top
  • Products
  • Wolfram|One
  • Mathematica
  • AI Access
  • Compute Services
  • System Modeler

  • Wolfram|Alpha Notebook Edition
  • Wolfram|Alpha Pro
  • Mobile Apps

  • Wolfram Engine
  • Wolfram Player

  • Volume & Site Licensing
  • Server Deployment Options
  • Consulting
  • Wolfram Consulting
  • Repositories
  • Data Repository
  • Function Repository
  • Community Paclet Repository
  • Neural Net Repository
  • Prompt Repository

  • Wolfram Language Example Repository
  • Notebook Archive
  • Wolfram GitHub
  • Learning
  • Wolfram U
  • Wolfram Language Documentation
  • Webinars & Training
  • Educational Programs

  • Wolfram Language Introduction
  • Fast Introduction for Programmers
  • Fast Introduction for Math Students
  • Books

  • Wolfram Community
  • Wolfram Blog
  • Public Resources
  • Wolfram|Alpha
  • Wolfram Problem Generator
  • Wolfram Challenges

  • Computer-Based Math
  • Computational Thinking
  • Computational Adventures

  • Demonstrations Project
  • Wolfram Data Drop
  • MathWorld
  • Wolfram Science
  • Wolfram Media Publishing
  • Customer Resources
  • Store
  • Product Downloads
  • User Portal
  • Your Account
  • Organization Access

  • Support FAQ
  • Contact Support
  • Company
  • About Wolfram
  • Careers
  • Contact
  • Events
Wolfram Community Wolfram Blog
Legal & Privacy Policy
WolframAlpha.com | WolframCloud.com
© 2026 Wolfram
© 2026 Wolfram | Legal & Privacy Policy |
English