
(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 -1.5e+156)
(* y z)
(if (<= z -4.2e+43)
t_0
(if (<= z -2.9e-25)
(* y z)
(if (<= z 9.5e-95) x (if (<= z 3.2e+66) (* y z) t_0)))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -1.5e+156) {
tmp = y * z;
} else if (z <= -4.2e+43) {
tmp = t_0;
} else if (z <= -2.9e-25) {
tmp = y * z;
} else if (z <= 9.5e-95) {
tmp = x;
} else if (z <= 3.2e+66) {
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 <= (-1.5d+156)) then
tmp = y * z
else if (z <= (-4.2d+43)) then
tmp = t_0
else if (z <= (-2.9d-25)) then
tmp = y * z
else if (z <= 9.5d-95) then
tmp = x
else if (z <= 3.2d+66) 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 <= -1.5e+156) {
tmp = y * z;
} else if (z <= -4.2e+43) {
tmp = t_0;
} else if (z <= -2.9e-25) {
tmp = y * z;
} else if (z <= 9.5e-95) {
tmp = x;
} else if (z <= 3.2e+66) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -1.5e+156: tmp = y * z elif z <= -4.2e+43: tmp = t_0 elif z <= -2.9e-25: tmp = y * z elif z <= 9.5e-95: tmp = x elif z <= 3.2e+66: 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 <= -1.5e+156) tmp = Float64(y * z); elseif (z <= -4.2e+43) tmp = t_0; elseif (z <= -2.9e-25) tmp = Float64(y * z); elseif (z <= 9.5e-95) tmp = x; elseif (z <= 3.2e+66) 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 <= -1.5e+156) tmp = y * z; elseif (z <= -4.2e+43) tmp = t_0; elseif (z <= -2.9e-25) tmp = y * z; elseif (z <= 9.5e-95) tmp = x; elseif (z <= 3.2e+66) 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, -1.5e+156], N[(y * z), $MachinePrecision], If[LessEqual[z, -4.2e+43], t$95$0, If[LessEqual[z, -2.9e-25], N[(y * z), $MachinePrecision], If[LessEqual[z, 9.5e-95], x, If[LessEqual[z, 3.2e+66], N[(y * z), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -1.5 \cdot 10^{+156}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -4.2 \cdot 10^{+43}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -2.9 \cdot 10^{-25}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 9.5 \cdot 10^{-95}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.2 \cdot 10^{+66}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.5e156 or -4.20000000000000003e43 < z < -2.9000000000000001e-25 or 9.49999999999999998e-95 < z < 3.2e66Initial program 100.0%
Taylor expanded in y around inf 68.4%
*-commutative68.4%
Simplified68.4%
Taylor expanded in z around inf 68.4%
Taylor expanded in y around inf 59.2%
if -1.5e156 < z < -4.20000000000000003e43 or 3.2e66 < z Initial program 100.0%
Taylor expanded in x around inf 64.3%
mul-1-neg64.3%
unsub-neg64.3%
Simplified64.3%
Taylor expanded in z around inf 64.3%
neg-mul-164.3%
Simplified64.3%
if -2.9000000000000001e-25 < z < 9.49999999999999998e-95Initial program 100.0%
Taylor expanded in z around 0 74.0%
Final simplification66.7%
(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 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around inf 98.7%
if -1 < z < 1Initial program 100.0%
Taylor expanded in y around inf 98.4%
*-commutative98.4%
Simplified98.4%
Final simplification98.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -2e-26) (not (<= z 5.8e-96))) (* (- y x) z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2e-26) || !(z <= 5.8e-96)) {
tmp = (y - x) * 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 <= (-2d-26)) .or. (.not. (z <= 5.8d-96))) then
tmp = (y - x) * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2e-26) || !(z <= 5.8e-96)) {
tmp = (y - x) * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2e-26) or not (z <= 5.8e-96): tmp = (y - x) * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2e-26) || !(z <= 5.8e-96)) tmp = Float64(Float64(y - x) * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2e-26) || ~((z <= 5.8e-96))) tmp = (y - x) * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2e-26], N[Not[LessEqual[z, 5.8e-96]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2 \cdot 10^{-26} \lor \neg \left(z \leq 5.8 \cdot 10^{-96}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.0000000000000001e-26 or 5.79999999999999987e-96 < z Initial program 100.0%
Taylor expanded in z around inf 99.9%
Taylor expanded in y around inf 92.7%
if -2.0000000000000001e-26 < z < 5.79999999999999987e-96Initial program 100.0%
Taylor expanded in z around 0 74.0%
Final simplification84.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.5e+74) (not (<= y 1.25e+114))) (* y z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.5e+74) || !(y <= 1.25e+114)) {
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 <= (-5.5d+74)) .or. (.not. (y <= 1.25d+114))) 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 <= -5.5e+74) || !(y <= 1.25e+114)) {
tmp = y * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.5e+74) or not (y <= 1.25e+114): tmp = y * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.5e+74) || !(y <= 1.25e+114)) 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 <= -5.5e+74) || ~((y <= 1.25e+114))) tmp = y * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.5e+74], N[Not[LessEqual[y, 1.25e+114]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.5 \cdot 10^{+74} \lor \neg \left(y \leq 1.25 \cdot 10^{+114}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -5.5000000000000003e74 or 1.25e114 < y Initial program 100.0%
Taylor expanded in y around inf 90.5%
*-commutative90.5%
Simplified90.5%
Taylor expanded in z around inf 78.1%
Taylor expanded in y around inf 72.8%
if -5.5000000000000003e74 < y < 1.25e114Initial program 100.0%
Taylor expanded in x around inf 81.0%
mul-1-neg81.0%
unsub-neg81.0%
Simplified81.0%
Final simplification77.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.75e-25) (not (<= z 9.5e-95))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.75e-25) || !(z <= 9.5e-95)) {
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.75d-25)) .or. (.not. (z <= 9.5d-95))) 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.75e-25) || !(z <= 9.5e-95)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.75e-25) or not (z <= 9.5e-95): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.75e-25) || !(z <= 9.5e-95)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.75e-25) || ~((z <= 9.5e-95))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.75e-25], N[Not[LessEqual[z, 9.5e-95]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.75 \cdot 10^{-25} \lor \neg \left(z \leq 9.5 \cdot 10^{-95}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.7500000000000001e-25 or 9.49999999999999998e-95 < z Initial program 100.0%
Taylor expanded in y around inf 54.7%
*-commutative54.7%
Simplified54.7%
Taylor expanded in z around inf 54.7%
Taylor expanded in y around inf 49.7%
if -1.7500000000000001e-25 < z < 9.49999999999999998e-95Initial program 100.0%
Taylor expanded in z around 0 74.0%
Final simplification59.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%
(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 35.3%
herbie shell --seed 2024129
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))