
(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 6 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%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- y x) z))) (if (<= z -1.0) t_0 (if (<= z 0.00052) (+ x (* y z)) t_0))))
double code(double x, double y, double z) {
double t_0 = (y - x) * z;
double tmp;
if (z <= -1.0) {
tmp = t_0;
} else if (z <= 0.00052) {
tmp = x + (y * z);
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = (y - x) * z
if (z <= (-1.0d0)) then
tmp = t_0
else if (z <= 0.00052d0) then
tmp = x + (y * z)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y - x) * z;
double tmp;
if (z <= -1.0) {
tmp = t_0;
} else if (z <= 0.00052) {
tmp = x + (y * z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y - x) * z tmp = 0 if z <= -1.0: tmp = t_0 elif z <= 0.00052: tmp = x + (y * z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(y - x) * z) tmp = 0.0 if (z <= -1.0) tmp = t_0; elseif (z <= 0.00052) tmp = Float64(x + Float64(y * z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y - x) * z; tmp = 0.0; if (z <= -1.0) tmp = t_0; elseif (z <= 0.00052) tmp = x + (y * z); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -1.0], t$95$0, If[LessEqual[z, 0.00052], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y - x\right) \cdot z\\
\mathbf{if}\;z \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 0.00052:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1 or 5.19999999999999954e-4 < z Initial program 99.9%
Taylor expanded in z around inf
*-lowering-*.f64N/A
--lowering--.f6497.8%
Simplified97.8%
if -1 < z < 5.19999999999999954e-4Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6498.9%
Simplified98.9%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- y x) z))) (if (<= y -3.7e+20) t_0 (if (<= y 2.3e+28) (* x (- 1.0 z)) t_0))))
double code(double x, double y, double z) {
double t_0 = (y - x) * z;
double tmp;
if (y <= -3.7e+20) {
tmp = t_0;
} else if (y <= 2.3e+28) {
tmp = x * (1.0 - z);
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = (y - x) * z
if (y <= (-3.7d+20)) then
tmp = t_0
else if (y <= 2.3d+28) then
tmp = x * (1.0d0 - z)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y - x) * z;
double tmp;
if (y <= -3.7e+20) {
tmp = t_0;
} else if (y <= 2.3e+28) {
tmp = x * (1.0 - z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y - x) * z tmp = 0 if y <= -3.7e+20: tmp = t_0 elif y <= 2.3e+28: tmp = x * (1.0 - z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(y - x) * z) tmp = 0.0 if (y <= -3.7e+20) tmp = t_0; elseif (y <= 2.3e+28) tmp = Float64(x * Float64(1.0 - z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y - x) * z; tmp = 0.0; if (y <= -3.7e+20) tmp = t_0; elseif (y <= 2.3e+28) tmp = x * (1.0 - z); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[y, -3.7e+20], t$95$0, If[LessEqual[y, 2.3e+28], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y - x\right) \cdot z\\
\mathbf{if}\;y \leq -3.7 \cdot 10^{+20}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.3 \cdot 10^{+28}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.7e20 or 2.29999999999999984e28 < y Initial program 100.0%
Taylor expanded in z around inf
*-lowering-*.f64N/A
--lowering--.f6480.5%
Simplified80.5%
if -3.7e20 < y < 2.29999999999999984e28Initial program 99.9%
Taylor expanded in x around inf
*-lowering-*.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f6484.1%
Simplified84.1%
Final simplification82.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- 1.0 z)))) (if (<= x -6.5e-74) t_0 (if (<= x 6e-99) (* y z) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (1.0 - z);
double tmp;
if (x <= -6.5e-74) {
tmp = t_0;
} else if (x <= 6e-99) {
tmp = y * z;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = x * (1.0d0 - z)
if (x <= (-6.5d-74)) then
tmp = t_0
else if (x <= 6d-99) then
tmp = y * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (1.0 - z);
double tmp;
if (x <= -6.5e-74) {
tmp = t_0;
} else if (x <= 6e-99) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (1.0 - z) tmp = 0 if x <= -6.5e-74: tmp = t_0 elif x <= 6e-99: tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(1.0 - z)) tmp = 0.0 if (x <= -6.5e-74) tmp = t_0; elseif (x <= 6e-99) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (1.0 - z); tmp = 0.0; if (x <= -6.5e-74) tmp = t_0; elseif (x <= 6e-99) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -6.5e-74], t$95$0, If[LessEqual[x, 6e-99], N[(y * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - z\right)\\
\mathbf{if}\;x \leq -6.5 \cdot 10^{-74}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 6 \cdot 10^{-99}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -6.5000000000000002e-74 or 6.00000000000000012e-99 < x Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f6481.6%
Simplified81.6%
if -6.5000000000000002e-74 < x < 6.00000000000000012e-99Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6473.4%
Simplified73.4%
(FPCore (x y z) :precision binary64 (if (<= y -3.8e-134) (* y z) (if (<= y 1.75e+28) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.8e-134) {
tmp = y * z;
} else if (y <= 1.75e+28) {
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 (y <= (-3.8d-134)) then
tmp = y * z
else if (y <= 1.75d+28) 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 (y <= -3.8e-134) {
tmp = y * z;
} else if (y <= 1.75e+28) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.8e-134: tmp = y * z elif y <= 1.75e+28: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.8e-134) tmp = Float64(y * z); elseif (y <= 1.75e+28) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.8e-134) tmp = y * z; elseif (y <= 1.75e+28) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.8e-134], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.75e+28], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{-134}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.75 \cdot 10^{+28}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -3.80000000000000003e-134 or 1.75e28 < y Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6462.2%
Simplified62.2%
if -3.80000000000000003e-134 < y < 1.75e28Initial program 100.0%
Taylor expanded in z around 0
Simplified46.3%
(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
Simplified32.3%
herbie shell --seed 2024145
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))