
(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%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- y x) z))) (if (<= z -5.6e-50) t_0 (if (<= z 0.000115) (+ x (+ x (- y x))) t_0))))
double code(double x, double y, double z) {
double t_0 = (y - x) * z;
double tmp;
if (z <= -5.6e-50) {
tmp = t_0;
} else if (z <= 0.000115) {
tmp = x + (x + (y - x));
} 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 <= (-5.6d-50)) then
tmp = t_0
else if (z <= 0.000115d0) then
tmp = x + (x + (y - x))
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 <= -5.6e-50) {
tmp = t_0;
} else if (z <= 0.000115) {
tmp = x + (x + (y - x));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y - x) * z tmp = 0 if z <= -5.6e-50: tmp = t_0 elif z <= 0.000115: tmp = x + (x + (y - x)) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(y - x) * z) tmp = 0.0 if (z <= -5.6e-50) tmp = t_0; elseif (z <= 0.000115) tmp = Float64(x + Float64(x + Float64(y - x))); 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 <= -5.6e-50) tmp = t_0; elseif (z <= 0.000115) tmp = x + (x + (y - x)); 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, -5.6e-50], t$95$0, If[LessEqual[z, 0.000115], N[(x + N[(x + N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y - x\right) \cdot z\\
\mathbf{if}\;z \leq -5.6 \cdot 10^{-50}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 0.000115:\\
\;\;\;\;x + \left(x + \left(y - x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -5.5999999999999996e-50 or 1.15e-4 < z Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites96.8%
if -5.5999999999999996e-50 < z < 1.15e-4Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites3.7%
Taylor expanded in x around 0
Applied rewrites51.3%
(FPCore (x y z) :precision binary64 (* (- y x) z))
double code(double x, double y, double z) {
return (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 = (y - x) * z
end function
public static double code(double x, double y, double z) {
return (y - x) * z;
}
def code(x, y, z): return (y - x) * z
function code(x, y, z) return Float64(Float64(y - x) * z) end
function tmp = code(x, y, z) tmp = (y - x) * z; end
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]
\begin{array}{l}
\\
\left(y - x\right) \cdot z
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites64.0%
(FPCore (x y z) :precision binary64 (+ x (- y x)))
double code(double x, double y, double z) {
return x + (y - 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 + (y - x)
end function
public static double code(double x, double y, double z) {
return x + (y - x);
}
def code(x, y, z): return x + (y - x)
function code(x, y, z) return Float64(x + Float64(y - x)) end
function tmp = code(x, y, z) tmp = x + (y - x); end
code[x_, y_, z_] := N[(x + N[(y - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites3.3%
(FPCore (x y z) :precision binary64 (- y x))
double code(double x, double y, double z) {
return y - x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y - x
end function
public static double code(double x, double y, double z) {
return y - x;
}
def code(x, y, z): return y - x
function code(x, y, z) return Float64(y - x) end
function tmp = code(x, y, z) tmp = y - x; end
code[x_, y_, z_] := N[(y - x), $MachinePrecision]
\begin{array}{l}
\\
y - x
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites64.0%
Taylor expanded in x around 0
Applied rewrites3.3%
herbie shell --seed 2024321
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
:pre (TRUE)
(+ x (* (- y x) z)))