
(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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- x))))
(if (<= z -5e+214)
t_0
(if (<= z -9.2e+141)
(* y z)
(if (<= z -9.5e+44)
t_0
(if (<= z -1.235e-89)
(* y z)
(if (<= z 1.0)
x
(if (or (<= z 8.5e+54) (not (<= z 2.8e+150))) t_0 (* y z)))))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (z <= -5e+214) {
tmp = t_0;
} else if (z <= -9.2e+141) {
tmp = y * z;
} else if (z <= -9.5e+44) {
tmp = t_0;
} else if (z <= -1.235e-89) {
tmp = y * z;
} else if (z <= 1.0) {
tmp = x;
} else if ((z <= 8.5e+54) || !(z <= 2.8e+150)) {
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 = z * -x
if (z <= (-5d+214)) then
tmp = t_0
else if (z <= (-9.2d+141)) then
tmp = y * z
else if (z <= (-9.5d+44)) then
tmp = t_0
else if (z <= (-1.235d-89)) then
tmp = y * z
else if (z <= 1.0d0) then
tmp = x
else if ((z <= 8.5d+54) .or. (.not. (z <= 2.8d+150))) 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 = z * -x;
double tmp;
if (z <= -5e+214) {
tmp = t_0;
} else if (z <= -9.2e+141) {
tmp = y * z;
} else if (z <= -9.5e+44) {
tmp = t_0;
} else if (z <= -1.235e-89) {
tmp = y * z;
} else if (z <= 1.0) {
tmp = x;
} else if ((z <= 8.5e+54) || !(z <= 2.8e+150)) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if z <= -5e+214: tmp = t_0 elif z <= -9.2e+141: tmp = y * z elif z <= -9.5e+44: tmp = t_0 elif z <= -1.235e-89: tmp = y * z elif z <= 1.0: tmp = x elif (z <= 8.5e+54) or not (z <= 2.8e+150): tmp = t_0 else: tmp = y * z return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-x)) tmp = 0.0 if (z <= -5e+214) tmp = t_0; elseif (z <= -9.2e+141) tmp = Float64(y * z); elseif (z <= -9.5e+44) tmp = t_0; elseif (z <= -1.235e-89) tmp = Float64(y * z); elseif (z <= 1.0) tmp = x; elseif ((z <= 8.5e+54) || !(z <= 2.8e+150)) tmp = t_0; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -x; tmp = 0.0; if (z <= -5e+214) tmp = t_0; elseif (z <= -9.2e+141) tmp = y * z; elseif (z <= -9.5e+44) tmp = t_0; elseif (z <= -1.235e-89) tmp = y * z; elseif (z <= 1.0) tmp = x; elseif ((z <= 8.5e+54) || ~((z <= 2.8e+150))) tmp = t_0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[z, -5e+214], t$95$0, If[LessEqual[z, -9.2e+141], N[(y * z), $MachinePrecision], If[LessEqual[z, -9.5e+44], t$95$0, If[LessEqual[z, -1.235e-89], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.0], x, If[Or[LessEqual[z, 8.5e+54], N[Not[LessEqual[z, 2.8e+150]], $MachinePrecision]], t$95$0, N[(y * z), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;z \leq -5 \cdot 10^{+214}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -9.2 \cdot 10^{+141}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -9.5 \cdot 10^{+44}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -1.235 \cdot 10^{-89}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 8.5 \cdot 10^{+54} \lor \neg \left(z \leq 2.8 \cdot 10^{+150}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -4.99999999999999953e214 or -9.2000000000000006e141 < z < -9.5000000000000004e44 or 1 < z < 8.4999999999999995e54 or 2.80000000000000009e150 < z Initial program 100.0%
Taylor expanded in z around inf 97.6%
Taylor expanded in y around 0 68.7%
associate-*r*68.7%
neg-mul-168.7%
*-commutative68.7%
Simplified68.7%
if -4.99999999999999953e214 < z < -9.2000000000000006e141 or -9.5000000000000004e44 < z < -1.235e-89 or 8.4999999999999995e54 < z < 2.80000000000000009e150Initial program 100.0%
Taylor expanded in x around 0 66.2%
if -1.235e-89 < z < 1Initial program 100.0%
Taylor expanded in z around 0 72.0%
Final simplification69.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.2e-22) (not (<= x 5.2e-75))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.2e-22) || !(x <= 5.2e-75)) {
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 <= (-3.2d-22)) .or. (.not. (x <= 5.2d-75))) 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 <= -3.2e-22) || !(x <= 5.2e-75)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.2e-22) or not (x <= 5.2e-75): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.2e-22) || !(x <= 5.2e-75)) 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 <= -3.2e-22) || ~((x <= 5.2e-75))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.2e-22], N[Not[LessEqual[x, 5.2e-75]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.2 \cdot 10^{-22} \lor \neg \left(x \leq 5.2 \cdot 10^{-75}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -3.19999999999999987e-22 or 5.2e-75 < x Initial program 100.0%
Taylor expanded in x around inf 85.3%
mul-1-neg85.3%
unsub-neg85.3%
Simplified85.3%
if -3.19999999999999987e-22 < x < 5.2e-75Initial program 100.0%
Taylor expanded in x around 0 72.1%
Final simplification80.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.235e-89) (not (<= z 12000000000000.0))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.235e-89) || !(z <= 12000000000000.0)) {
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 <= (-1.235d-89)) .or. (.not. (z <= 12000000000000.0d0))) 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 <= -1.235e-89) || !(z <= 12000000000000.0)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.235e-89) or not (z <= 12000000000000.0): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.235e-89) || !(z <= 12000000000000.0)) 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 <= -1.235e-89) || ~((z <= 12000000000000.0))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.235e-89], N[Not[LessEqual[z, 12000000000000.0]], $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 -1.235 \cdot 10^{-89} \lor \neg \left(z \leq 12000000000000\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -1.235e-89 or 1.2e13 < z Initial program 100.0%
Taylor expanded in z around inf 95.1%
if -1.235e-89 < z < 1.2e13Initial program 100.0%
Taylor expanded in x around inf 75.6%
mul-1-neg75.6%
unsub-neg75.6%
Simplified75.6%
Final simplification85.9%
(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 96.9%
if -1 < z < 1Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-lft-in100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 97.8%
*-commutative97.8%
Simplified97.8%
Final simplification97.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.235e-89) (not (<= z 3.5e-140))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.235e-89) || !(z <= 3.5e-140)) {
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.235d-89)) .or. (.not. (z <= 3.5d-140))) 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.235e-89) || !(z <= 3.5e-140)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.235e-89) or not (z <= 3.5e-140): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.235e-89) || !(z <= 3.5e-140)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.235e-89) || ~((z <= 3.5e-140))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.235e-89], N[Not[LessEqual[z, 3.5e-140]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.235 \cdot 10^{-89} \lor \neg \left(z \leq 3.5 \cdot 10^{-140}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.235e-89 or 3.4999999999999998e-140 < z Initial program 100.0%
Taylor expanded in x around 0 47.6%
if -1.235e-89 < z < 3.4999999999999998e-140Initial program 100.0%
Taylor expanded in z around 0 84.1%
Final simplification58.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%
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 36.3%
Final simplification36.3%
herbie shell --seed 2024059
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))