
(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 5 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 (+ 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 (if (or (<= x -1.6e+62) (not (<= x 1.85e+52))) (- x (* x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.6e+62) || !(x <= 1.85e+52)) {
tmp = x - (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 ((x <= (-1.6d+62)) .or. (.not. (x <= 1.85d+52))) then
tmp = x - (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 ((x <= -1.6e+62) || !(x <= 1.85e+52)) {
tmp = x - (x * z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.6e+62) or not (x <= 1.85e+52): tmp = x - (x * z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.6e+62) || !(x <= 1.85e+52)) tmp = Float64(x - Float64(x * z)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.6e+62) || ~((x <= 1.85e+52))) tmp = x - (x * z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.6e+62], N[Not[LessEqual[x, 1.85e+52]], $MachinePrecision]], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{+62} \lor \neg \left(x \leq 1.85 \cdot 10^{+52}\right):\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -1.59999999999999992e62 or 1.85e52 < x Initial program 100.0%
Taylor expanded in y around 0 91.2%
mul-1-neg91.2%
distribute-rgt-neg-out91.2%
Simplified91.2%
Taylor expanded in x around 0 91.2%
neg-mul-191.2%
distribute-rgt1-in91.2%
cancel-sign-sub-inv91.2%
Simplified91.2%
if -1.59999999999999992e62 < x < 1.85e52Initial program 100.0%
Taylor expanded in y around inf 87.1%
*-commutative87.1%
Simplified87.1%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -8.5e-5) (not (<= z 1.0))) (* x (- z)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8.5e-5) || !(z <= 1.0)) {
tmp = x * -z;
} else {
tmp = x;
}
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.5d-5)) .or. (.not. (z <= 1.0d0))) then
tmp = x * -z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -8.5e-5) || !(z <= 1.0)) {
tmp = x * -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8.5e-5) or not (z <= 1.0): tmp = x * -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8.5e-5) || !(z <= 1.0)) tmp = Float64(x * Float64(-z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -8.5e-5) || ~((z <= 1.0))) tmp = x * -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8.5e-5], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(x * (-z)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.5 \cdot 10^{-5} \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -8.500000000000001e-5 or 1 < z Initial program 100.0%
Taylor expanded in y around 0 50.0%
mul-1-neg50.0%
distribute-rgt-neg-out50.0%
Simplified50.0%
Taylor expanded in z around inf 48.8%
mul-1-neg48.8%
distribute-rgt-neg-in48.8%
Simplified48.8%
if -8.500000000000001e-5 < z < 1Initial program 100.0%
Taylor expanded in y around 0 65.7%
mul-1-neg65.7%
distribute-rgt-neg-out65.7%
Simplified65.7%
Taylor expanded in z around 0 65.7%
Final simplification57.3%
(FPCore (x y z) :precision binary64 (if (<= z 1.45e+196) (+ x (* y z)) (* x (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.45e+196) {
tmp = x + (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.45d+196) then
tmp = x + (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.45e+196) {
tmp = x + (y * z);
} else {
tmp = x * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.45e+196: tmp = x + (y * z) else: tmp = x * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.45e+196) tmp = Float64(x + 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.45e+196) tmp = x + (y * z); else tmp = x * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.45e+196], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.45 \cdot 10^{+196}:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < 1.45e196Initial program 100.0%
Taylor expanded in y around inf 80.6%
*-commutative80.6%
Simplified80.6%
if 1.45e196 < z Initial program 100.0%
Taylor expanded in y around 0 64.5%
mul-1-neg64.5%
distribute-rgt-neg-out64.5%
Simplified64.5%
Taylor expanded in z around inf 64.5%
mul-1-neg64.5%
distribute-rgt-neg-in64.5%
Simplified64.5%
Final simplification78.7%
(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 y around 0 57.9%
mul-1-neg57.9%
distribute-rgt-neg-out57.9%
Simplified57.9%
Taylor expanded in z around 0 34.2%
Final simplification34.2%
herbie shell --seed 2023196
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))