
(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
(let* ((t_0 (* x (- z))))
(if (<= z -2.4e-16)
t_0
(if (<= z 5.2e-10)
x
(if (<= z 8e+156) (* y z) (if (<= z 4.25e+238) t_0 (* y z)))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -2.4e-16) {
tmp = t_0;
} else if (z <= 5.2e-10) {
tmp = x;
} else if (z <= 8e+156) {
tmp = y * z;
} else if (z <= 4.25e+238) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = x * -z
if (z <= (-2.4d-16)) then
tmp = t_0
else if (z <= 5.2d-10) then
tmp = x
else if (z <= 8d+156) then
tmp = y * z
else if (z <= 4.25d+238) then
tmp = t_0
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -2.4e-16) {
tmp = t_0;
} else if (z <= 5.2e-10) {
tmp = x;
} else if (z <= 8e+156) {
tmp = y * z;
} else if (z <= 4.25e+238) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -2.4e-16: tmp = t_0 elif z <= 5.2e-10: tmp = x elif z <= 8e+156: tmp = y * z elif z <= 4.25e+238: tmp = t_0 else: tmp = y * z return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -2.4e-16) tmp = t_0; elseif (z <= 5.2e-10) tmp = x; elseif (z <= 8e+156) tmp = Float64(y * z); elseif (z <= 4.25e+238) tmp = t_0; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (z <= -2.4e-16) tmp = t_0; elseif (z <= 5.2e-10) tmp = x; elseif (z <= 8e+156) tmp = y * z; elseif (z <= 4.25e+238) tmp = t_0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[z, -2.4e-16], t$95$0, If[LessEqual[z, 5.2e-10], x, If[LessEqual[z, 8e+156], N[(y * z), $MachinePrecision], If[LessEqual[z, 4.25e+238], t$95$0, N[(y * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -2.4 \cdot 10^{-16}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 5.2 \cdot 10^{-10}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 8 \cdot 10^{+156}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 4.25 \cdot 10^{+238}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -2.40000000000000005e-16 or 7.9999999999999999e156 < z < 4.24999999999999999e238Initial program 100.0%
Taylor expanded in z around inf 96.8%
Taylor expanded in y around 0 67.3%
mul-1-neg67.3%
distribute-rgt-neg-out67.3%
Simplified67.3%
if -2.40000000000000005e-16 < z < 5.19999999999999962e-10Initial program 100.0%
Taylor expanded in z around 0 72.6%
if 5.19999999999999962e-10 < z < 7.9999999999999999e156 or 4.24999999999999999e238 < z Initial program 99.9%
Taylor expanded in z around inf 98.8%
Taylor expanded in y around inf 73.4%
*-commutative73.4%
Simplified73.4%
Final simplification71.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.35e-94) (not (<= x 7e-125))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.35e-94) || !(x <= 7e-125)) {
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 <= (-2.35d-94)) .or. (.not. (x <= 7d-125))) 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 <= -2.35e-94) || !(x <= 7e-125)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.35e-94) or not (x <= 7e-125): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.35e-94) || !(x <= 7e-125)) 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 <= -2.35e-94) || ~((x <= 7e-125))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.35e-94], N[Not[LessEqual[x, 7e-125]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.35 \cdot 10^{-94} \lor \neg \left(x \leq 7 \cdot 10^{-125}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -2.35000000000000002e-94 or 6.99999999999999995e-125 < x Initial program 100.0%
Taylor expanded in x around inf 79.2%
distribute-rgt1-in79.2%
mul-1-neg79.2%
cancel-sign-sub-inv79.2%
Simplified79.2%
Taylor expanded in x around 0 79.2%
if -2.35000000000000002e-94 < x < 6.99999999999999995e-125Initial program 100.0%
Taylor expanded in z around inf 76.3%
Taylor expanded in y around inf 69.9%
*-commutative69.9%
Simplified69.9%
Final simplification76.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.8e+24) (not (<= z 1.1e-6))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.8e+24) || !(z <= 1.1e-6)) {
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 <= (-4.8d+24)) .or. (.not. (z <= 1.1d-6))) 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 <= -4.8e+24) || !(z <= 1.1e-6)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.8e+24) or not (z <= 1.1e-6): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.8e+24) || !(z <= 1.1e-6)) 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 <= -4.8e+24) || ~((z <= 1.1e-6))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.8e+24], N[Not[LessEqual[z, 1.1e-6]], $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 -4.8 \cdot 10^{+24} \lor \neg \left(z \leq 1.1 \cdot 10^{-6}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -4.8000000000000001e24 or 1.1000000000000001e-6 < z Initial program 99.9%
Taylor expanded in z around inf 99.5%
if -4.8000000000000001e24 < z < 1.1000000000000001e-6Initial program 100.0%
Taylor expanded in x around inf 73.1%
distribute-rgt1-in73.1%
mul-1-neg73.1%
cancel-sign-sub-inv73.1%
Simplified73.1%
Taylor expanded in x around 0 73.1%
Final simplification84.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.0))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
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 <= (-1.0d0)) .or. (.not. (z <= 1.0d0))) 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 <= -1.0) || !(z <= 1.0)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 1.0): tmp = (y - x) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.0)) 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 <= -1.0) || ~((z <= 1.0))) tmp = (y - x) * z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 1.0]], $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 -1 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 99.9%
Taylor expanded in z around inf 97.8%
if -1 < z < 1Initial program 100.0%
Taylor expanded in y around inf 99.9%
*-commutative30.2%
Simplified99.9%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (<= z -2.4e-17) (* y z) (if (<= z 2.85e-12) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.4e-17) {
tmp = y * z;
} else if (z <= 2.85e-12) {
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 <= (-2.4d-17)) then
tmp = y * z
else if (z <= 2.85d-12) 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 <= -2.4e-17) {
tmp = y * z;
} else if (z <= 2.85e-12) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.4e-17: tmp = y * z elif z <= 2.85e-12: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.4e-17) tmp = Float64(y * z); elseif (z <= 2.85e-12) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.4e-17) tmp = y * z; elseif (z <= 2.85e-12) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.4e-17], N[(y * z), $MachinePrecision], If[LessEqual[z, 2.85e-12], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{-17}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 2.85 \cdot 10^{-12}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -2.39999999999999986e-17 or 2.8500000000000002e-12 < z Initial program 99.9%
Taylor expanded in z around inf 97.7%
Taylor expanded in y around inf 51.0%
*-commutative51.0%
Simplified51.0%
if -2.39999999999999986e-17 < z < 2.8500000000000002e-12Initial program 100.0%
Taylor expanded in z around 0 72.6%
Final simplification62.8%
(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 41.3%
Final simplification41.3%
herbie shell --seed 2023238
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))