What function yields a generalized pyramid surface in high dimensions? I was trying to have a mathematical surface with the shape of a pyramid in high dimensions (i.e. generalizes from 2D to 3D, 4D, ...etc). First to guid my intuition I tried playing around and form first a triangle surface. I figured that one can form such a surface with the subtraction of a step function offseted with another step function. Let me share it with some mathematica code:

then I tried generalizing this by adding two triangle functions in 2D. This yielded:

by which I noticed I had a very good candidate, I just had the make sure the lower part was flat. To do that I essentially noticed that the max function was very good at flattening things out so I shifted the figure down by 1 and then flatten it with the max function:

This was really useful because I was able to obtain the Pyramid that I wanted in one higher dimension! However, with this approach I wasn't quite sure how to generalize it so that I can get a function:
$$ prism(x_1,x_2,x_3,x_4, ... , x_D) = z$$
so that the $z$ value (i.e. the surface of the function) was the shape of a pyramid. With this playing around I hypothesize that the function that yields the pyramid that I want is:
$$ prism(x_1,x_2,x_3,x_4, ...,x_D) = max\left( 0, \sum^D_{i=1} triangle(x_i) - (D -1) \right)$$
however, I wasn't sure I knew how to confirm if this intuition was correct. How does one prove this is the correct shape of the surface that I want? Essentially I want to prove $$ prism(x_1,x_2,x_3,x_4, ...,x_D) $$ satisfies the definition of pyramid that I want. Unfortunately, I do not know how to formulate the definition of high D-pyramid so that I can check it.
Though I did try by referencing standard definitions of pyramid in high D. For this I went to wikipedia on n-dimensional pyramids however it seems that most definitions that I saw usually define the shape the shape was "surrounded by defining boundaries" (very tempting to use the word closed but that already means something in topology/real analysis, I just mean its surrounded by some defining region). However, my shape seems to not share that property with the wikipedia definitions which threw me off. Does someone have a suggestion on how I could even do such a proof or correct my function so that it actually defines the shape I want it to define? Ideally I'd like to be convinced that whatever $f$ we have does indeed define the shape of the pyramid I want.

To give some context to the problem the goal of this to be able to model a surface that some general D dimensional "person" could walk on and either go up hills or go down dips (these being modeled by the pyramid definition we have).
Therefore, given a specific vector $[x_1,...,x_D]$ there should only be one value of $f(x_1,...,x_D) = z$ (the reason for this rule is that these are models for bumps and dips of a loss function and given a specific parameter set we can only have one value of (the pyramid) surface function $f(x_1,...x_D) = z$. I think this idea is more important to conserve when trying to do this question. 
 A: I will show how to solve this problem when the base is an $n$-dimensional cube and the apex is directly above a point in the base. Then I will show how the procedure can be generalized if the cube is replaced with an arbitrary convex polyhedral figure. I would suggest you draw pictures for the arguments below in the case $n = 2$.
Say the $n$-dimensional cube is defined by $2n$ inequalities $x_i \geq - 1, x_i \leq 1$, for $i = 1, \dots, n$, and the apex is located at $c = (c_1,\dots,c_n,c_{n+1})$, where $\hat{c} = (c_1,\dots,c_n,0)$ is a point in the interior of the base. That means we're assuming the $c_i$'s satisfy the strict inequalities corresponding to the lax ones above, i.e., $c_i > -1, c_i < 1$ for all $i = 1, \dots, n$. 
Now we let $\hat{x} = (x_1,\dots,x_n,0)$ be any point in the base and our problem is to find the value of $x_{n+1}$ such that the point $x = (x_1,\dots,x_n,x_{n+1})$ will belong to the pyramid.
The pyramid has one $n$-dimensional face for each $(n-1)$-dimensional face of the base cube. Our first task is to determine which face corresponds to the face $x$ is located on. To do this, we draw the ray originating at $\hat{c}$ and passing through $\hat{x}$. That ray hits one of the faces. That face is the one we want, or at least the point on it where the ray meets it. The ray consists of all points $\hat{c} + t(\hat{x} - \hat{c})$ as $t$ ranges through values $t \geq 0$ (assuming $\hat{x} \ne \hat{c}$). The ray hits a face when $t$ is the smallest possible positive value for which one of the inequalities defining the cube becomes an equality. In other words, we look at the $2n$ equations $c_i + t(x_i - c_i) = \pm 1$, we solve them all for $t$, and whichever one has the smallest positive solution for $t$, which we'll name $T$, is the face we want. (We must in fact have $T \geq 1$.) Now we write $y$ for the point where the ray first meets a face. We have $y = (c_1 + T(x_1 - c_1),\dots,c_n + T(x_n - c_n),0)$.
Now it's easy to find $x$. If we draw the triangle whose vertices are $c$, $\hat{c}$ and $y$, we see that it's a right triangle with a right angle at $\hat{c}$, with the side from $\hat{c}$ to $c$ vertical and from $\hat{c}$ to $y$ horizontal. Then $\hat{x}$ is a point on the horizontal leg of the triangle, $1/T$ of the way from $\hat{c}$ to $y$, and $x$ lies directly above it on the hypotenuse. We therefore have $x = c + (1/T)(y - c)$, so $x_{n+1} = (1 - 1/T)c_{n+1}$.

In summary, solve all the equations $c_i + t(x_i - c_i) = \pm 1$ for $i = 1,\dots, n$, and let $t = T$ be the smallest solution that is positive. Then we have $x_{n+1} = (1 - 1/T)c_{n+1}$. An exceptional case occurs when $\hat{x} = \hat{c}$, and then $x_{n+1} = c_{n+1}$. 

More generally, we can repeat the above arguments and procedure almost exactly when we have a convex base defined by several linear inequalities of the form $a_1 x_1 + \dots a_n x_n \leq b$, and the apex is directly above a point in the interior of the base. Geometrically, the convexity condition means that if you take any $(n-1)$-dimensional face of the base, then the entire base lies on the same side of that face. There are only two major differences with the special case above. 
The first difference is that some of the inequalities may be superfluous. That is, if we remove those conditions, we still obtain the same set. In that case the "face" corresponding to that particular inequality will have dimension lower than $n$ and will be contained in one or more of the real $n$-dimensional faces. This makes no difference in how you calculate $x_{n+1}$.
The other difference is that it may happen that you don't have enough linear inequalities to make the set defined by them bounded. In other words, the set might not be contained within a region of space that has finite dimensions. In this situation, I don't think the concept of a pyramid would make sense. At the very least, it would be very different, and the above procedure wouldn't work. 
Edit: Here are the formulas for the general case. I'll simplify the formula a bit by going straight to $1-1/T$ rather than going through the step of calculating $T$. Assume your $n$-dimensional base is defined by several linear inequalities $a_1 x_1 + \dots a_n x_n \leq b$, and that the coordinates of the apex $(c_1,\dots,c_n,c_{n+1})$ satisfy each inequality $a_1 c_1 + \dots a_n c_n < b$. Now let a point $\hat{x} = (x_1,\dots,x_n,0)$ be given in the base (i.e, all the lax inequalities are satisfied by its coordinates). Now, for each inequality defining the base, calculate the quantity
$$s = 1 - 1/t = \frac{b-a_1 x_1 - \dots - a_n x_n}{b - a_1 c_1 - \dots - a_n c_n},$$
and let the smallest of these numbers (which are all nonnegative) be $S = 1 - 1/T$. Then $x_{n+1} = Sc_{n+1}$. ($\hat{x} = \hat{c}$ is no longer an exceptional case.)
In the special case of a cube, the $2n$ values are $s = \frac{1 + x_i}{1 + c_i}$ and $s = \frac{1 - x_i}{1 - c_i}$ for $i = 1,\dots,n$, and $S$ is the minimum of these.
Edit: Here is an illustration of the right triangle mentioned in the solution. Ray $a$ starts at $\hat{c}$ when $t = 0$, passes through $\hat{x}$ when $t = 1$, and meets the boundary of the base at $y$ when $t = T$. Hence the distance from $\hat{c}$ to $\hat{x}$ is $1/T$ times the distance from $\hat{c}$ to $y$. The points $c, \hat{c}, y$ form a right triangle, and the points $x, \hat{x}, y$ form a similar right triangle. The distance from $c$ to $\hat{c}$ is $c_{n+1}$ (provided $c_{n+1} > 0$), and the distance from $x$ to $\hat{x}$ is $x_{n+1}$. It follows that $x_{n+1}/c_{n+1} = 1 - 1/T$.

