Questions tagged [assertion]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers

Can I avoid FindMinimum ruining my Asserts with symbolic stuff?

I am new with Mathematica, so forgive me if I completely misunderstood the nature of the problem... Problem description I want to optimize a fairly complex function bypassing explicit derivative ...
WaterFox's user avatar
  • 185
1 vote
0 answers

How to print local variable when assertion failed

Given the following code: func[i_] := Module[{k}, k = i; Assert[k > 0, k]]; func[-1] The output is: ...
Chris Guo's user avatar
  • 149
20 votes
1 answer

Confirm vs Throw

Version 12.2 brought us Confirm and Enclose. What's the point? Is it just that it's a slightly more convenient syntax than ...
Patrick Stevens's user avatar
2 votes
2 answers

Assert that prints message and aborts computation?

I'd like to add asserts which check for condition, print useful message and abort computation on failure. IE, ...
Yaroslav Bulatov's user avatar
3 votes
1 answer

Improving `$AssertFunction` to always tell what the assertion test resulted in

I really like this form of assertion failure: On[Assert]; Assert[1 + 1 == True]; Assert::asrttf: Assertion test 1+1==True evaluated to 2==True that is neither ...
masterxilo's user avatar
  • 5,679
17 votes
4 answers

stop notebook evaluation when Assert fails

I would like a notebook evaluation to entirely stop when an Assert fails, without quitting the kernel. Is this possible (e.g., by setting ...
Alan's user avatar
  • 13.5k
4 votes
1 answer

How to get Mathematica to abort the current evaluation if an assertion fails?

I can turn on assertions, but they don't terminate the current evaluation. For example: ...
kjo's user avatar
  • 11.7k
34 votes
1 answer

which is better, using Assert[] or manual checks on arguments and other computations?

I never used Asserts in Mathematica, but trying to see what advantage they have over just argument check and additional definitions of the function to capture unwanted input. For example, which one ...
Nasser's user avatar
  • 135k