
(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 (* z (- x))))
(if (<= z -4.2e+158)
t_0
(if (<= z -3.6e-30)
(* y z)
(if (<= z 6.2e-65) x (if (<= z 7.5e+169) (* y z) t_0))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (z <= -4.2e+158) {
tmp = t_0;
} else if (z <= -3.6e-30) {
tmp = y * z;
} else if (z <= 6.2e-65) {
tmp = x;
} else if (z <= 7.5e+169) {
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 = z * -x
if (z <= (-4.2d+158)) then
tmp = t_0
else if (z <= (-3.6d-30)) then
tmp = y * z
else if (z <= 6.2d-65) then
tmp = x
else if (z <= 7.5d+169) 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 = z * -x;
double tmp;
if (z <= -4.2e+158) {
tmp = t_0;
} else if (z <= -3.6e-30) {
tmp = y * z;
} else if (z <= 6.2e-65) {
tmp = x;
} else if (z <= 7.5e+169) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if z <= -4.2e+158: tmp = t_0 elif z <= -3.6e-30: tmp = y * z elif z <= 6.2e-65: tmp = x elif z <= 7.5e+169: tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-x)) tmp = 0.0 if (z <= -4.2e+158) tmp = t_0; elseif (z <= -3.6e-30) tmp = Float64(y * z); elseif (z <= 6.2e-65) tmp = x; elseif (z <= 7.5e+169) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -x; tmp = 0.0; if (z <= -4.2e+158) tmp = t_0; elseif (z <= -3.6e-30) tmp = y * z; elseif (z <= 6.2e-65) tmp = x; elseif (z <= 7.5e+169) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[z, -4.2e+158], t$95$0, If[LessEqual[z, -3.6e-30], N[(y * z), $MachinePrecision], If[LessEqual[z, 6.2e-65], x, If[LessEqual[z, 7.5e+169], N[(y * z), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;z \leq -4.2 \cdot 10^{+158}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -3.6 \cdot 10^{-30}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 6.2 \cdot 10^{-65}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 7.5 \cdot 10^{+169}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -4.1999999999999998e158 or 7.49999999999999992e169 < z Initial program 100.0%
Taylor expanded in x around inf 65.6%
mul-1-neg65.6%
unsub-neg65.6%
Simplified65.6%
Taylor expanded in z around inf 65.6%
associate-*r*65.6%
mul-1-neg65.6%
Simplified65.6%
if -4.1999999999999998e158 < z < -3.6000000000000003e-30 or 6.20000000000000032e-65 < z < 7.49999999999999992e169Initial program 100.0%
Taylor expanded in y around inf 61.0%
*-commutative61.0%
Simplified61.0%
Taylor expanded in x around 0 57.6%
*-commutative57.6%
Simplified57.6%
if -3.6000000000000003e-30 < z < 6.20000000000000032e-65Initial program 100.0%
Taylor expanded in z around 0 80.2%
Final simplification70.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.8e+57) (not (<= y 2.6e+50))) (* y z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.8e+57) || !(y <= 2.6e+50)) {
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 <= (-3.8d+57)) .or. (.not. (y <= 2.6d+50))) 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 <= -3.8e+57) || !(y <= 2.6e+50)) {
tmp = y * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.8e+57) or not (y <= 2.6e+50): tmp = y * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.8e+57) || !(y <= 2.6e+50)) 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 <= -3.8e+57) || ~((y <= 2.6e+50))) tmp = y * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.8e+57], N[Not[LessEqual[y, 2.6e+50]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{+57} \lor \neg \left(y \leq 2.6 \cdot 10^{+50}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -3.7999999999999999e57 or 2.6000000000000002e50 < y Initial program 100.0%
Taylor expanded in y around inf 93.7%
*-commutative93.7%
Simplified93.7%
Taylor expanded in x around 0 74.5%
*-commutative74.5%
Simplified74.5%
if -3.7999999999999999e57 < y < 2.6000000000000002e50Initial program 100.0%
Taylor expanded in x around inf 86.2%
mul-1-neg86.2%
unsub-neg86.2%
Simplified86.2%
Final simplification81.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -9.5e-32) (not (<= z 8.4e-33))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -9.5e-32) || !(z <= 8.4e-33)) {
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 <= (-9.5d-32)) .or. (.not. (z <= 8.4d-33))) 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 <= -9.5e-32) || !(z <= 8.4e-33)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -9.5e-32) or not (z <= 8.4e-33): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -9.5e-32) || !(z <= 8.4e-33)) 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 <= -9.5e-32) || ~((z <= 8.4e-33))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -9.5e-32], N[Not[LessEqual[z, 8.4e-33]], $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 -9.5 \cdot 10^{-32} \lor \neg \left(z \leq 8.4 \cdot 10^{-33}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -9.4999999999999999e-32 or 8.4e-33 < z Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
fma-udef100.0%
+-commutative100.0%
*-commutative100.0%
sub-neg100.0%
distribute-lft-in97.6%
associate-+r+97.6%
*-commutative97.6%
Applied egg-rr97.6%
Taylor expanded in z around inf 98.4%
distribute-lft-in96.0%
*-commutative96.0%
mul-1-neg96.0%
cancel-sign-sub-inv96.0%
*-commutative96.0%
distribute-lft-out--98.4%
Simplified98.4%
if -9.4999999999999999e-32 < z < 8.4e-33Initial program 100.0%
Taylor expanded in x around inf 79.3%
mul-1-neg79.3%
unsub-neg79.3%
Simplified79.3%
Final simplification88.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.9e-32))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.9e-32)) {
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.9d-32))) 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.9e-32)) {
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.9e-32): 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.9e-32)) 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.9e-32))) 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.9e-32]], $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.9 \cdot 10^{-32}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -1 or 1.90000000000000004e-32 < z Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
fma-udef100.0%
+-commutative100.0%
*-commutative100.0%
sub-neg100.0%
distribute-lft-in97.6%
associate-+r+97.6%
*-commutative97.6%
Applied egg-rr97.6%
Taylor expanded in z around inf 98.3%
distribute-lft-in95.9%
*-commutative95.9%
mul-1-neg95.9%
cancel-sign-sub-inv95.9%
*-commutative95.9%
distribute-lft-out--98.3%
Simplified98.3%
if -1 < z < 1.90000000000000004e-32Initial program 100.0%
Taylor expanded in y around inf 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.7e-31) (not (<= z 3.7e-65))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.7e-31) || !(z <= 3.7e-65)) {
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 <= (-1.7d-31)) .or. (.not. (z <= 3.7d-65))) 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 <= -1.7e-31) || !(z <= 3.7e-65)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.7e-31) or not (z <= 3.7e-65): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.7e-31) || !(z <= 3.7e-65)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.7e-31) || ~((z <= 3.7e-65))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.7e-31], N[Not[LessEqual[z, 3.7e-65]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{-31} \lor \neg \left(z \leq 3.7 \cdot 10^{-65}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.7000000000000001e-31 or 3.7e-65 < z Initial program 100.0%
Taylor expanded in y around inf 54.7%
*-commutative54.7%
Simplified54.7%
Taylor expanded in x around 0 52.6%
*-commutative52.6%
Simplified52.6%
if -1.7000000000000001e-31 < z < 3.7e-65Initial program 100.0%
Taylor expanded in z around 0 80.2%
Final simplification66.0%
(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.4%
Final simplification41.4%
herbie shell --seed 2023326
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))