
(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-define100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z))))
(if (<= z -8e+75)
t_0
(if (<= z -1.8e-11)
(* y z)
(if (<= z 1.15e-34)
x
(if (or (<= z 1.46e+31) (not (<= z 1.6e+126))) (* y z) t_0))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -8e+75) {
tmp = t_0;
} else if (z <= -1.8e-11) {
tmp = y * z;
} else if (z <= 1.15e-34) {
tmp = x;
} else if ((z <= 1.46e+31) || !(z <= 1.6e+126)) {
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 * -z
if (z <= (-8d+75)) then
tmp = t_0
else if (z <= (-1.8d-11)) then
tmp = y * z
else if (z <= 1.15d-34) then
tmp = x
else if ((z <= 1.46d+31) .or. (.not. (z <= 1.6d+126))) 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 * -z;
double tmp;
if (z <= -8e+75) {
tmp = t_0;
} else if (z <= -1.8e-11) {
tmp = y * z;
} else if (z <= 1.15e-34) {
tmp = x;
} else if ((z <= 1.46e+31) || !(z <= 1.6e+126)) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -8e+75: tmp = t_0 elif z <= -1.8e-11: tmp = y * z elif z <= 1.15e-34: tmp = x elif (z <= 1.46e+31) or not (z <= 1.6e+126): tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -8e+75) tmp = t_0; elseif (z <= -1.8e-11) tmp = Float64(y * z); elseif (z <= 1.15e-34) tmp = x; elseif ((z <= 1.46e+31) || !(z <= 1.6e+126)) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (z <= -8e+75) tmp = t_0; elseif (z <= -1.8e-11) tmp = y * z; elseif (z <= 1.15e-34) tmp = x; elseif ((z <= 1.46e+31) || ~((z <= 1.6e+126))) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[z, -8e+75], t$95$0, If[LessEqual[z, -1.8e-11], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.15e-34], x, If[Or[LessEqual[z, 1.46e+31], N[Not[LessEqual[z, 1.6e+126]], $MachinePrecision]], N[(y * z), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -8 \cdot 10^{+75}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -1.8 \cdot 10^{-11}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{-34}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.46 \cdot 10^{+31} \lor \neg \left(z \leq 1.6 \cdot 10^{+126}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -7.99999999999999941e75 or 1.46e31 < z < 1.5999999999999999e126Initial program 100.0%
Taylor expanded in x around inf 65.3%
mul-1-neg65.3%
unsub-neg65.3%
Simplified65.3%
Taylor expanded in z around inf 65.3%
neg-mul-165.3%
Simplified65.3%
if -7.99999999999999941e75 < z < -1.79999999999999992e-11 or 1.15000000000000006e-34 < z < 1.46e31 or 1.5999999999999999e126 < z Initial program 100.0%
Taylor expanded in y around inf 66.1%
*-commutative66.1%
Simplified66.1%
Taylor expanded in z around inf 65.0%
Taylor expanded in z around inf 64.6%
*-commutative64.6%
Simplified64.6%
if -1.79999999999999992e-11 < z < 1.15000000000000006e-34Initial program 100.0%
Taylor expanded in z around 0 78.4%
Final simplification70.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -900.0) (not (<= z 1.0))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -900.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 <= (-900.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 <= -900.0) || !(z <= 1.0)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -900.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 <= -900.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 <= -900.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, -900.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 -900 \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 < -900 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around inf 100.0%
if -900 < z < 1Initial program 100.0%
Taylor expanded in y around inf 99.8%
*-commutative99.8%
Simplified99.8%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.3e-12) (not (<= z 1.15e-34))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.3e-12) || !(z <= 1.15e-34)) {
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 <= (-2.3d-12)) .or. (.not. (z <= 1.15d-34))) 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 <= -2.3e-12) || !(z <= 1.15e-34)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.3e-12) or not (z <= 1.15e-34): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.3e-12) || !(z <= 1.15e-34)) 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 <= -2.3e-12) || ~((z <= 1.15e-34))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.3e-12], N[Not[LessEqual[z, 1.15e-34]], $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 -2.3 \cdot 10^{-12} \lor \neg \left(z \leq 1.15 \cdot 10^{-34}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -2.29999999999999989e-12 or 1.15000000000000006e-34 < z Initial program 100.0%
Taylor expanded in z around inf 99.4%
Taylor expanded in y around inf 99.2%
if -2.29999999999999989e-12 < z < 1.15000000000000006e-34Initial program 100.0%
Taylor expanded in x around inf 78.6%
mul-1-neg78.6%
unsub-neg78.6%
Simplified78.6%
Final simplification90.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.6e+110) (not (<= y 3.5e+104))) (* y z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.6e+110) || !(y <= 3.5e+104)) {
tmp = y * 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 ((y <= (-2.6d+110)) .or. (.not. (y <= 3.5d+104))) then
tmp = y * 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 ((y <= -2.6e+110) || !(y <= 3.5e+104)) {
tmp = y * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.6e+110) or not (y <= 3.5e+104): tmp = y * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.6e+110) || !(y <= 3.5e+104)) tmp = Float64(y * z); else tmp = Float64(x * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.6e+110) || ~((y <= 3.5e+104))) tmp = y * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.6e+110], N[Not[LessEqual[y, 3.5e+104]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.6 \cdot 10^{+110} \lor \neg \left(y \leq 3.5 \cdot 10^{+104}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -2.6e110 or 3.5000000000000002e104 < y Initial program 100.0%
Taylor expanded in y around inf 97.8%
*-commutative97.8%
Simplified97.8%
Taylor expanded in z around inf 86.5%
Taylor expanded in z around inf 79.6%
*-commutative79.6%
Simplified79.6%
if -2.6e110 < y < 3.5000000000000002e104Initial program 100.0%
Taylor expanded in x around inf 80.4%
mul-1-neg80.4%
unsub-neg80.4%
Simplified80.4%
Final simplification80.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.8e-12) (not (<= z 1.15e-34))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.8e-12) || !(z <= 1.15e-34)) {
tmp = y * 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 <= (-5.8d-12)) .or. (.not. (z <= 1.15d-34))) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -5.8e-12) || !(z <= 1.15e-34)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.8e-12) or not (z <= 1.15e-34): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.8e-12) || !(z <= 1.15e-34)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -5.8e-12) || ~((z <= 1.15e-34))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.8e-12], N[Not[LessEqual[z, 1.15e-34]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.8 \cdot 10^{-12} \lor \neg \left(z \leq 1.15 \cdot 10^{-34}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.8000000000000003e-12 or 1.15000000000000006e-34 < z Initial program 100.0%
Taylor expanded in y around inf 51.9%
*-commutative51.9%
Simplified51.9%
Taylor expanded in z around inf 51.3%
Taylor expanded in z around inf 50.8%
*-commutative50.8%
Simplified50.8%
if -5.8000000000000003e-12 < z < 1.15000000000000006e-34Initial program 100.0%
Taylor expanded in z around 0 78.4%
Final simplification62.9%
(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 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 36.3%
herbie shell --seed 2024182
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))