
(FPCore (x y z) :precision binary64 (+ x (* (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + ((y - x) * z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) * z);
}
def code(x, y, z): return x + ((y - x) * z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) * z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) * z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + ((y - x) * z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) * z);
}
def code(x, y, z): return x + ((y - x) * z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) * z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) * z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma (- y x) z x))
double code(double x, double y, double z) {
return fma((y - x), z, x);
}
function code(x, y, z) return fma(Float64(y - x), z, x) end
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * z + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - x, z, x\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= z -1.26e-117)
(* y z)
(if (<= z 2.3e-75)
x
(if (or (<= z 1.72e+112) (and (not (<= z 2e+207)) (<= z 1.1e+247)))
(* y z)
(* x (- z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.26e-117) {
tmp = y * z;
} else if (z <= 2.3e-75) {
tmp = x;
} else if ((z <= 1.72e+112) || (!(z <= 2e+207) && (z <= 1.1e+247))) {
tmp = y * z;
} else {
tmp = x * -z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-1.26d-117)) then
tmp = y * z
else if (z <= 2.3d-75) then
tmp = x
else if ((z <= 1.72d+112) .or. (.not. (z <= 2d+207)) .and. (z <= 1.1d+247)) then
tmp = y * z
else
tmp = x * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.26e-117) {
tmp = y * z;
} else if (z <= 2.3e-75) {
tmp = x;
} else if ((z <= 1.72e+112) || (!(z <= 2e+207) && (z <= 1.1e+247))) {
tmp = y * z;
} else {
tmp = x * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.26e-117: tmp = y * z elif z <= 2.3e-75: tmp = x elif (z <= 1.72e+112) or (not (z <= 2e+207) and (z <= 1.1e+247)): tmp = y * z else: tmp = x * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.26e-117) tmp = Float64(y * z); elseif (z <= 2.3e-75) tmp = x; elseif ((z <= 1.72e+112) || (!(z <= 2e+207) && (z <= 1.1e+247))) tmp = Float64(y * z); else tmp = Float64(x * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.26e-117) tmp = y * z; elseif (z <= 2.3e-75) tmp = x; elseif ((z <= 1.72e+112) || (~((z <= 2e+207)) && (z <= 1.1e+247))) tmp = y * z; else tmp = x * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.26e-117], N[(y * z), $MachinePrecision], If[LessEqual[z, 2.3e-75], x, If[Or[LessEqual[z, 1.72e+112], And[N[Not[LessEqual[z, 2e+207]], $MachinePrecision], LessEqual[z, 1.1e+247]]], N[(y * z), $MachinePrecision], N[(x * (-z)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.26 \cdot 10^{-117}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{-75}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.72 \cdot 10^{+112} \lor \neg \left(z \leq 2 \cdot 10^{+207}\right) \land z \leq 1.1 \cdot 10^{+247}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < -1.2599999999999999e-117 or 2.3e-75 < z < 1.71999999999999997e112 or 2.0000000000000001e207 < z < 1.10000000000000006e247Initial program 100.0%
Taylor expanded in z around inf 89.3%
Taylor expanded in y around inf 64.4%
*-commutative64.4%
Simplified64.4%
if -1.2599999999999999e-117 < z < 2.3e-75Initial program 100.0%
Taylor expanded in z around 0 75.1%
if 1.71999999999999997e112 < z < 2.0000000000000001e207 or 1.10000000000000006e247 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around 0 83.5%
mul-1-neg83.5%
distribute-rgt-neg-out83.5%
Simplified83.5%
Final simplification69.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -7e-110) (not (<= x 6.8e-88))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7e-110) || !(x <= 6.8e-88)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x <= (-7d-110)) .or. (.not. (x <= 6.8d-88))) then
tmp = x * (1.0d0 - z)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -7e-110) || !(x <= 6.8e-88)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7e-110) or not (x <= 6.8e-88): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7e-110) || !(x <= 6.8e-88)) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7e-110) || ~((x <= 6.8e-88))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7e-110], N[Not[LessEqual[x, 6.8e-88]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{-110} \lor \neg \left(x \leq 6.8 \cdot 10^{-88}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -6.99999999999999947e-110 or 6.79999999999999949e-88 < x Initial program 100.0%
Taylor expanded in x around inf 77.2%
distribute-rgt1-in77.1%
mul-1-neg77.1%
cancel-sign-sub-inv77.1%
Simplified77.1%
Taylor expanded in x around 0 77.2%
if -6.99999999999999947e-110 < x < 6.79999999999999949e-88Initial program 100.0%
Taylor expanded in z around inf 83.7%
Taylor expanded in y around inf 80.8%
*-commutative80.8%
Simplified80.8%
Final simplification78.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -8.6e-118) (not (<= z 1.25e-71))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8.6e-118) || !(z <= 1.25e-71)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-8.6d-118)) .or. (.not. (z <= 1.25d-71))) then
tmp = (y - x) * z
else
tmp = x * (1.0d0 - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -8.6e-118) || !(z <= 1.25e-71)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8.6e-118) or not (z <= 1.25e-71): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8.6e-118) || !(z <= 1.25e-71)) tmp = Float64(Float64(y - x) * z); else tmp = Float64(x * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -8.6e-118) || ~((z <= 1.25e-71))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8.6e-118], N[Not[LessEqual[z, 1.25e-71]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.6 \cdot 10^{-118} \lor \neg \left(z \leq 1.25 \cdot 10^{-71}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -8.60000000000000036e-118 or 1.24999999999999999e-71 < z Initial program 100.0%
Taylor expanded in z around inf 90.9%
if -8.60000000000000036e-118 < z < 1.24999999999999999e-71Initial program 100.0%
Taylor expanded in x around inf 75.1%
distribute-rgt1-in75.1%
mul-1-neg75.1%
cancel-sign-sub-inv75.1%
Simplified75.1%
Taylor expanded in x around 0 75.1%
Final simplification86.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.1) (not (<= z 1.76e-19))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.1) || !(z <= 1.76e-19)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-2.1d0)) .or. (.not. (z <= 1.76d-19))) then
tmp = (y - x) * z
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.1) || !(z <= 1.76e-19)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.1) or not (z <= 1.76e-19): tmp = (y - x) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.1) || !(z <= 1.76e-19)) tmp = Float64(Float64(y - x) * z); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.1) || ~((z <= 1.76e-19))) tmp = (y - x) * z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.1], N[Not[LessEqual[z, 1.76e-19]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.1 \lor \neg \left(z \leq 1.76 \cdot 10^{-19}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -2.10000000000000009 or 1.75999999999999993e-19 < z Initial program 100.0%
Taylor expanded in z around inf 99.3%
if -2.10000000000000009 < z < 1.75999999999999993e-19Initial program 100.0%
Taylor expanded in y around inf 99.5%
*-commutative37.0%
Simplified99.5%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (<= z -1.3e-117) (* y z) (if (<= z 1.6e-73) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.3e-117) {
tmp = y * z;
} else if (z <= 1.6e-73) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-1.3d-117)) then
tmp = y * z
else if (z <= 1.6d-73) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.3e-117) {
tmp = y * z;
} else if (z <= 1.6e-73) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.3e-117: tmp = y * z elif z <= 1.6e-73: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.3e-117) tmp = Float64(y * z); elseif (z <= 1.6e-73) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.3e-117) tmp = y * z; elseif (z <= 1.6e-73) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.3e-117], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.6e-73], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.3 \cdot 10^{-117}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.6 \cdot 10^{-73}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.29999999999999992e-117 or 1.59999999999999993e-73 < z Initial program 100.0%
Taylor expanded in z around inf 90.9%
Taylor expanded in y around inf 57.6%
*-commutative57.6%
Simplified57.6%
if -1.29999999999999992e-117 < z < 1.59999999999999993e-73Initial program 100.0%
Taylor expanded in z around 0 75.1%
Final simplification63.1%
(FPCore (x y z) :precision binary64 (+ x (* (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + ((y - x) * z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) * z);
}
def code(x, y, z): return x + ((y - x) * z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) * z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) * z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot z
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in z around 0 30.8%
Final simplification30.8%
herbie shell --seed 2023229
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))