
(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 7 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%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- x) z)))
(if (<= z -1.65e+72)
t_0
(if (<= z -3.3e-89)
(* z y)
(if (<= z 1.75e-31) (* 1.0 x) (if (<= z 1.25e+154) (* z y) t_0))))))
double code(double x, double y, double z) {
double t_0 = -x * z;
double tmp;
if (z <= -1.65e+72) {
tmp = t_0;
} else if (z <= -3.3e-89) {
tmp = z * y;
} else if (z <= 1.75e-31) {
tmp = 1.0 * x;
} else if (z <= 1.25e+154) {
tmp = z * y;
} 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.65d+72)) then
tmp = t_0
else if (z <= (-3.3d-89)) then
tmp = z * y
else if (z <= 1.75d-31) then
tmp = 1.0d0 * x
else if (z <= 1.25d+154) then
tmp = z * y
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.65e+72) {
tmp = t_0;
} else if (z <= -3.3e-89) {
tmp = z * y;
} else if (z <= 1.75e-31) {
tmp = 1.0 * x;
} else if (z <= 1.25e+154) {
tmp = z * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -x * z tmp = 0 if z <= -1.65e+72: tmp = t_0 elif z <= -3.3e-89: tmp = z * y elif z <= 1.75e-31: tmp = 1.0 * x elif z <= 1.25e+154: tmp = z * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) * z) tmp = 0.0 if (z <= -1.65e+72) tmp = t_0; elseif (z <= -3.3e-89) tmp = Float64(z * y); elseif (z <= 1.75e-31) tmp = Float64(1.0 * x); elseif (z <= 1.25e+154) tmp = Float64(z * y); 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.65e+72) tmp = t_0; elseif (z <= -3.3e-89) tmp = z * y; elseif (z <= 1.75e-31) tmp = 1.0 * x; elseif (z <= 1.25e+154) tmp = z * y; 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.65e+72], t$95$0, If[LessEqual[z, -3.3e-89], N[(z * y), $MachinePrecision], If[LessEqual[z, 1.75e-31], N[(1.0 * x), $MachinePrecision], If[LessEqual[z, 1.25e+154], N[(z * y), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-x\right) \cdot z\\
\mathbf{if}\;z \leq -1.65 \cdot 10^{+72}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -3.3 \cdot 10^{-89}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 1.75 \cdot 10^{-31}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;z \leq 1.25 \cdot 10^{+154}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.65e72 or 1.25000000000000001e154 < z Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites63.5%
if -1.65e72 < z < -3.2999999999999997e-89 or 1.74999999999999993e-31 < z < 1.25000000000000001e154Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6457.3
Applied rewrites57.3%
if -3.2999999999999997e-89 < z < 1.74999999999999993e-31Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6475.6
Applied rewrites75.6%
Taylor expanded in z around 0
Applied rewrites75.6%
Final simplification65.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (- y x)))) (if (<= z -115.0) t_0 (if (<= z 0.00088) (+ (* z y) x) t_0))))
double code(double x, double y, double z) {
double t_0 = z * (y - x);
double tmp;
if (z <= -115.0) {
tmp = t_0;
} else if (z <= 0.00088) {
tmp = (z * y) + x;
} 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 * (y - x)
if (z <= (-115.0d0)) then
tmp = t_0
else if (z <= 0.00088d0) then
tmp = (z * y) + x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * (y - x);
double tmp;
if (z <= -115.0) {
tmp = t_0;
} else if (z <= 0.00088) {
tmp = (z * y) + x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * (y - x) tmp = 0 if z <= -115.0: tmp = t_0 elif z <= 0.00088: tmp = (z * y) + x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(y - x)) tmp = 0.0 if (z <= -115.0) tmp = t_0; elseif (z <= 0.00088) tmp = Float64(Float64(z * y) + x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * (y - x); tmp = 0.0; if (z <= -115.0) tmp = t_0; elseif (z <= 0.00088) tmp = (z * y) + x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -115.0], t$95$0, If[LessEqual[z, 0.00088], N[(N[(z * y), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(y - x\right)\\
\mathbf{if}\;z \leq -115:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 0.00088:\\
\;\;\;\;z \cdot y + x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -115 or 8.80000000000000031e-4 < z Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6499.1
Applied rewrites99.1%
if -115 < z < 8.80000000000000031e-4Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6497.1
Applied rewrites97.1%
Final simplification98.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (- y x)))) (if (<= z -3.3e-89) t_0 (if (<= z 0.00042) (* (- 1.0 z) x) t_0))))
double code(double x, double y, double z) {
double t_0 = z * (y - x);
double tmp;
if (z <= -3.3e-89) {
tmp = t_0;
} else if (z <= 0.00042) {
tmp = (1.0 - z) * x;
} 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 * (y - x)
if (z <= (-3.3d-89)) then
tmp = t_0
else if (z <= 0.00042d0) then
tmp = (1.0d0 - z) * x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * (y - x);
double tmp;
if (z <= -3.3e-89) {
tmp = t_0;
} else if (z <= 0.00042) {
tmp = (1.0 - z) * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * (y - x) tmp = 0 if z <= -3.3e-89: tmp = t_0 elif z <= 0.00042: tmp = (1.0 - z) * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(y - x)) tmp = 0.0 if (z <= -3.3e-89) tmp = t_0; elseif (z <= 0.00042) tmp = Float64(Float64(1.0 - z) * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * (y - x); tmp = 0.0; if (z <= -3.3e-89) tmp = t_0; elseif (z <= 0.00042) tmp = (1.0 - z) * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -3.3e-89], t$95$0, If[LessEqual[z, 0.00042], N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(y - x\right)\\
\mathbf{if}\;z \leq -3.3 \cdot 10^{-89}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 0.00042:\\
\;\;\;\;\left(1 - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -3.2999999999999997e-89 or 4.2000000000000002e-4 < z Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6490.7
Applied rewrites90.7%
if -3.2999999999999997e-89 < z < 4.2000000000000002e-4Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6474.2
Applied rewrites74.2%
Final simplification84.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- 1.0 z) x))) (if (<= x -0.8) t_0 (if (<= x 2.3e-98) (* z y) t_0))))
double code(double x, double y, double z) {
double t_0 = (1.0 - z) * x;
double tmp;
if (x <= -0.8) {
tmp = t_0;
} else if (x <= 2.3e-98) {
tmp = z * y;
} 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 = (1.0d0 - z) * x
if (x <= (-0.8d0)) then
tmp = t_0
else if (x <= 2.3d-98) then
tmp = z * y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (1.0 - z) * x;
double tmp;
if (x <= -0.8) {
tmp = t_0;
} else if (x <= 2.3e-98) {
tmp = z * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (1.0 - z) * x tmp = 0 if x <= -0.8: tmp = t_0 elif x <= 2.3e-98: tmp = z * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(1.0 - z) * x) tmp = 0.0 if (x <= -0.8) tmp = t_0; elseif (x <= 2.3e-98) tmp = Float64(z * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (1.0 - z) * x; tmp = 0.0; if (x <= -0.8) tmp = t_0; elseif (x <= 2.3e-98) tmp = z * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -0.8], t$95$0, If[LessEqual[x, 2.3e-98], N[(z * y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - z\right) \cdot x\\
\mathbf{if}\;x \leq -0.8:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.3 \cdot 10^{-98}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -0.80000000000000004 or 2.30000000000000001e-98 < x Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6486.0
Applied rewrites86.0%
if -0.80000000000000004 < x < 2.30000000000000001e-98Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6473.5
Applied rewrites73.5%
Final simplification80.7%
(FPCore (x y z) :precision binary64 (if (<= z -3.3e-89) (* z y) (if (<= z 1.75e-31) (* 1.0 x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.3e-89) {
tmp = z * y;
} else if (z <= 1.75e-31) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
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 <= (-3.3d-89)) then
tmp = z * y
else if (z <= 1.75d-31) then
tmp = 1.0d0 * x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -3.3e-89) {
tmp = z * y;
} else if (z <= 1.75e-31) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.3e-89: tmp = z * y elif z <= 1.75e-31: tmp = 1.0 * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.3e-89) tmp = Float64(z * y); elseif (z <= 1.75e-31) tmp = Float64(1.0 * x); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3.3e-89) tmp = z * y; elseif (z <= 1.75e-31) tmp = 1.0 * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.3e-89], N[(z * y), $MachinePrecision], If[LessEqual[z, 1.75e-31], N[(1.0 * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.3 \cdot 10^{-89}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 1.75 \cdot 10^{-31}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -3.2999999999999997e-89 or 1.74999999999999993e-31 < z Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6451.9
Applied rewrites51.9%
if -3.2999999999999997e-89 < z < 1.74999999999999993e-31Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6475.6
Applied rewrites75.6%
Taylor expanded in z around 0
Applied rewrites75.6%
Final simplification60.5%
(FPCore (x y z) :precision binary64 (* z y))
double code(double x, double y, double z) {
return z * y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z * y
end function
public static double code(double x, double y, double z) {
return z * y;
}
def code(x, y, z): return z * y
function code(x, y, z) return Float64(z * y) end
function tmp = code(x, y, z) tmp = z * y; end
code[x_, y_, z_] := N[(z * y), $MachinePrecision]
\begin{array}{l}
\\
z \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6442.5
Applied rewrites42.5%
Final simplification42.5%
herbie shell --seed 2024257
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))