
(FPCore (x y z) :precision binary64 :pre TRUE (+ x (* (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) * z);
}
real(8) function code(x, y, z)
use fmin_fmax_functions
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]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = x + ((y - x) * z) END code
x + \left(y - x\right) \cdot z
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 :pre TRUE (+ x (* (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) * z);
}
real(8) function code(x, y, z)
use fmin_fmax_functions
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]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = x + ((y - x) * z) END code
x + \left(y - x\right) \cdot z
(FPCore (x y z) :precision binary64 :pre TRUE (fma z (- y x) x))
double code(double x, double y, double z) {
return fma(z, (y - x), x);
}
function code(x, y, z) return fma(z, Float64(y - x), x) end
code[x_, y_, z_] := N[(z * N[(y - x), $MachinePrecision] + x), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (z * (y - x)) + x END code
\mathsf{fma}\left(z, y - x, x\right)
Initial program 100.0%
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
:pre TRUE
(let* ((t_0 (* z (- y x))))
(if (<= z -28165673201.033638)
t_0
(if (<= z 7.845250112058621e-9) (fma z y x) t_0))))double code(double x, double y, double z) {
double t_0 = z * (y - x);
double tmp;
if (z <= -28165673201.033638) {
tmp = t_0;
} else if (z <= 7.845250112058621e-9) {
tmp = fma(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 <= -28165673201.033638) tmp = t_0; elseif (z <= 7.845250112058621e-9) tmp = fma(z, y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -28165673201.033638], t$95$0, If[LessEqual[z, 7.845250112058621e-9], N[(z * y + x), $MachinePrecision], t$95$0]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET t_0 = (z * (y - x)) IN LET tmp_1 = IF (z <= (78452501120586211901078397558915999976392185999429784715175628662109375e-79)) THEN ((z * y) + x) ELSE t_0 ENDIF IN LET tmp = IF (z <= (-2816567320103363800048828125e-17)) THEN t_0 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := z \cdot \left(y - x\right)\\
\mathbf{if}\;z \leq -28165673201.033638:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 7.845250112058621 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if z < -28165673201.033638 or 7.8452501120586212e-9 < z Initial program 100.0%
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites41.4%
Taylor expanded in z around inf
Applied rewrites65.0%
if -28165673201.033638 < z < 7.8452501120586212e-9Initial program 100.0%
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites75.7%
(FPCore (x y z)
:precision binary64
:pre TRUE
(let* ((t_0 (* x (- 1.0 z))))
(if (<= x -1.9574573609995736e+91)
t_0
(if (<= x 0.0005660629841236394) (fma z y x) t_0))))double code(double x, double y, double z) {
double t_0 = x * (1.0 - z);
double tmp;
if (x <= -1.9574573609995736e+91) {
tmp = t_0;
} else if (x <= 0.0005660629841236394) {
tmp = fma(z, y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * Float64(1.0 - z)) tmp = 0.0 if (x <= -1.9574573609995736e+91) tmp = t_0; elseif (x <= 0.0005660629841236394) tmp = fma(z, y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.9574573609995736e+91], t$95$0, If[LessEqual[x, 0.0005660629841236394], N[(z * y + x), $MachinePrecision], t$95$0]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET t_0 = (x * ((1) - z)) IN LET tmp_1 = IF (x <= (566062984123639448448550570702764161978848278522491455078125e-63)) THEN ((z * y) + x) ELSE t_0 ENDIF IN LET tmp = IF (x <= (-19574573609995735600635967846953792076791839711159263895675501474379448978998529820238807040)) THEN t_0 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := x \cdot \left(1 - z\right)\\
\mathbf{if}\;x \leq -1.9574573609995736 \cdot 10^{+91}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 0.0005660629841236394:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if x < -1.9574573609995736e91 or 5.6606298412363945e-4 < x Initial program 100.0%
Applied rewrites98.9%
Taylor expanded in x around inf
Applied rewrites62.4%
if -1.9574573609995736e91 < x < 5.6606298412363945e-4Initial program 100.0%
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites75.7%
(FPCore (x y z) :precision binary64 :pre TRUE (fma z y x))
double code(double x, double y, double z) {
return fma(z, y, x);
}
function code(x, y, z) return fma(z, y, x) end
code[x_, y_, z_] := N[(z * y + x), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (z * y) + x END code
\mathsf{fma}\left(z, y, x\right)
Initial program 100.0%
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites75.7%
(FPCore (x y z) :precision binary64 :pre TRUE (if (<= z -1.5998878487717716e-87) (* y z) (if (<= z 1.4132947115915006e-40) (* x 1.0) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.5998878487717716e-87) {
tmp = y * z;
} else if (z <= 1.4132947115915006e-40) {
tmp = x * 1.0;
} else {
tmp = y * z;
}
return tmp;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-1.5998878487717716d-87)) then
tmp = y * z
else if (z <= 1.4132947115915006d-40) then
tmp = x * 1.0d0
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.5998878487717716e-87) {
tmp = y * z;
} else if (z <= 1.4132947115915006e-40) {
tmp = x * 1.0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.5998878487717716e-87: tmp = y * z elif z <= 1.4132947115915006e-40: tmp = x * 1.0 else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.5998878487717716e-87) tmp = Float64(y * z); elseif (z <= 1.4132947115915006e-40) tmp = Float64(x * 1.0); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.5998878487717716e-87) tmp = y * z; elseif (z <= 1.4132947115915006e-40) tmp = x * 1.0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.5998878487717716e-87], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.4132947115915006e-40], N[(x * 1.0), $MachinePrecision], N[(y * z), $MachinePrecision]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET tmp_1 = IF (z <= (14132947115915006468182910235642061199906833362565967651395812855413318177857125598375794078304482317867511731446228395725484006106853485107421875e-185)) THEN (x * (1)) ELSE (y * z) ENDIF IN LET tmp = IF (z <= (-159988784877177164685523371169830722870522374072384409119026858684832480050318864005140114871679013601761552483193181404403016128515199488354968070059220853336754264519220820635743157089849151568897638446024723319315030689580225953250192105770111083984375e-341)) THEN (y * z) ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;z \leq -1.5998878487717716 \cdot 10^{-87}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.4132947115915006 \cdot 10^{-40}:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
if z < -1.5998878487717716e-87 or 1.4132947115915006e-40 < z Initial program 100.0%
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites41.4%
if -1.5998878487717716e-87 < z < 1.4132947115915006e-40Initial program 100.0%
Applied rewrites98.9%
Taylor expanded in x around inf
Applied rewrites62.4%
Taylor expanded in z around 0
Applied rewrites36.6%
(FPCore (x y z) :precision binary64 :pre TRUE (* x 1.0))
double code(double x, double y, double z) {
return x * 1.0;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * 1.0d0
end function
public static double code(double x, double y, double z) {
return x * 1.0;
}
def code(x, y, z): return x * 1.0
function code(x, y, z) return Float64(x * 1.0) end
function tmp = code(x, y, z) tmp = x * 1.0; end
code[x_, y_, z_] := N[(x * 1.0), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = x * (1) END code
x \cdot 1
Initial program 100.0%
Applied rewrites98.9%
Taylor expanded in x around inf
Applied rewrites62.4%
Taylor expanded in z around 0
Applied rewrites36.6%
herbie shell --seed 2026092
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))